Three-agent fan-out reusing the contracts-first pattern: Opus pre-wrote
World.clear_all + 4 EventBus signals (save_started/finished, load_started/
finished) before dispatch. Pattern proven across Phases 12/13/14/15/16.
Entity to_dict/from_dict + class_id tagging (Agent A):
- class_id tag added to all 18 entity to_dict methods for loader routing
- Missing pairs filled in: wolf, grave_slot, graveyard_zone, stockpile_zone,
crate (from_dict). All defensive with d.get(field, default).
- Workbench round-trips label_text so Carpenter/Smelter/Millstone/Hearth/
Pyre kinds survive reload
- BeautySystem + DirtinessSystem save_dict/apply_dict for sparse maps
- World.save_tilemap_layers / apply_tilemap_layers covering 5 layers
(Terrain/Floor/Wall/Designation/Roof; Fog runtime-only skipped)
SaveSystem v2 rewrite (Agent B):
- SAVE_VERSION bumped from 1 to 2
- write_save(slot) pauses Sim, emits save_started, collects every entity
via _collect_entities iterating all World registries, writes payload to
user://save_<slot>.json
- apply_save full rewrite: pause sim → emit load_started → World.clear_all
→ apply autoloads (GameState/Clock/Weather/Storyteller) → apply tilemap
layers → iterate payload.entities and dispatch to per-class factories
→ apply beauty/dirt maps → emit load_finished(slot, ok, real_seconds_away)
- Per-class factory registry: 18 class_ids dispatched to setup+add_child+
from_dict patterns. CremationPyre detected via workbench.label_text == 'Pyre'
- Public slot API: save_to_slot/load_from_slot/has_save/delete_save/
peek_save_metadata. Slots locked: &manual + &autosave
Autosave + UI + Resume toast (Agent C):
- autoload/autosave.gd — new Autosave autoload. Periodic every
AUTOSAVE_INTERVAL_TICKS = 6000 (~5 in-game min at 20 Hz) + NOTIFICATION_
APPLICATION_PAUSED (mobile) + NOTIFICATION_WM_WINDOW_FOCUS_OUT (desktop).
Gated by _busy flag tied to EventBus.save_started/save_finished.
- TopBar extended with SaveBtn (💾) + LoadBtn buttons, 48×48 min hit area
- scenes/ui/load_menu.gd — CanvasLayer slot picker. Reads peek_save_metadata
to show 'Manual save (Date Time)' / 'Autosave (Date Time)' rows.
Version-mismatch warning dialog before continuing on older saves.
- scenes/ui/resume_toast.gd — top-center toast. On load_finished(ok=true):
'Welcome back — N minutes/hours away' for 5s + 0.8s fade.
On ok=false: 'Load failed (corrupt or version mismatch)'.
- Strings catalog: 14 new keys (ui.save / ui.load / ui.welcome_back_* /
ui.load_failed etc.)
- main.gd mounts LoadMenu + ResumeToast as runtime CanvasLayer children
MCP runtime verified:
- Saved at tick 1137 → [save] wrote slot 'manual': 113 entities at tick 1137
- Advanced sim to tick 4600 at ULTRA speed (different state)
- load_from_slot(&manual) → [save] applied slot 'manual': 113 entities,
0 errors, tick=1137, away=34s
- post-load: Sim.tick=1137 (restored), pawns alive=3, all furniture +
workbenches + crops + walls + floors back in place
- Resume toast fires: [resume_toast] showing — ok=true seconds_away=34
- Autosave on focus-loss verified: [autosave] focus-loss → wrote autosave
- Screenshot shows TopBar with Save + Load buttons + post-load Lone Wolf
storyteller modal from fresh dawn roll
Known acceptable gaps (deferred to Phase 20 tuning):
- Pawn JobRunner mid-INTERACT/mid-BUILD restarts from toil 0 on reload
(walk toil round-trips; multi-step interact does not). Pawns lose a few
seconds of work.
- Workbench bill mid-craft fetch state isn't fully serialized.
- Wolf.target_pawn re-resolution from name string is Agent A's documented
pattern; Agent B's apply_save respects pawn-restoration ordering so the
resolution works after pawns are back.
Delegation: 3× gdscript-refactor (Sonnet) agents in parallel; integration
+ MCP verify on Opus.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
148 lines
5 KiB
GDScript
148 lines
5 KiB
GDScript
## Rock entity — mineable by a pawn with a Mine job. Drops a stone Item node
|
||
## when mined out.
|
||
##
|
||
## Mirrors Tree's chopping model; stone is harder so MINE_TICKS is longer.
|
||
## A MineProvider (Opus, Phase 4) creates a Job whose INTERACT toil calls
|
||
## on_mine_tick() once per sim tick via JobRunner.
|
||
##
|
||
## World registration (World.register_rock / World.unregister_rock) is called
|
||
## here but the methods land in World during Opus integration.
|
||
|
||
class_name Rock extends Node2D
|
||
|
||
const TILE_SIZE_PX: int = 16
|
||
|
||
## Sim ticks to mine a rock at 1× speed (120 ticks = 6 sim seconds at 20 Hz).
|
||
## Stone is harder than wood — MINE_TICKS > Tree.CHOP_TICKS.
|
||
const MINE_TICKS: int = 120
|
||
## Stone Items dropped on a successful mine.
|
||
const STONE_DROPS_ON_MINE: int = 1
|
||
|
||
# ── state ─────────────────────────────────────────────────────────────────────
|
||
|
||
var tile: Vector2i = Vector2i.ZERO
|
||
## 0..MINE_TICKS. Advanced by on_mine_tick(); rock is mined when equal to MINE_TICKS.
|
||
var mine_progress: int = 0
|
||
|
||
# Preloaded scene for spawned stone items.
|
||
const ITEM_SCENE: PackedScene = preload("res://scenes/entities/item.tscn")
|
||
|
||
|
||
# ── lifecycle ─────────────────────────────────────────────────────────────────
|
||
|
||
func _ready() -> void:
|
||
position = _tile_to_world(tile)
|
||
World.register_rock(self)
|
||
|
||
|
||
func _exit_tree() -> void:
|
||
World.unregister_rock(self)
|
||
|
||
|
||
# ── public API ────────────────────────────────────────────────────────────────
|
||
|
||
## One-shot initialiser. Call after add_child() so _ready() already fired.
|
||
func setup(start_tile: Vector2i) -> void:
|
||
tile = start_tile
|
||
mine_progress = 0
|
||
position = _tile_to_world(tile)
|
||
queue_redraw()
|
||
Audit.log("rock", "spawned at %s" % tile)
|
||
|
||
|
||
## True when the rock hasn't been fully mined yet.
|
||
func is_mineable() -> bool:
|
||
return mine_progress < MINE_TICKS
|
||
|
||
|
||
## Called by the INTERACT toil in JobRunner once per sim tick while the pawn
|
||
## works this rock. Advances mine_progress and triggers mined() when complete.
|
||
func on_mine_tick() -> void:
|
||
if not is_mineable():
|
||
return
|
||
mine_progress += 1
|
||
queue_redraw()
|
||
if mine_progress >= MINE_TICKS:
|
||
mined()
|
||
|
||
|
||
## Drop stone Item(s) and free this node. Called automatically by on_mine_tick()
|
||
## but also accessible for scripted removal (debug, storyteller events).
|
||
func mined() -> void:
|
||
# Single drop lands on the rock's own tile.
|
||
var item: Item = ITEM_SCENE.instantiate()
|
||
get_parent().add_child(item)
|
||
item.setup(Item.TYPE_STONE, 1, tile)
|
||
Audit.log("rock", "mined at %s; %d stone drop" % [tile, STONE_DROPS_ON_MINE])
|
||
queue_free()
|
||
|
||
|
||
# ── save / load ───────────────────────────────────────────────────────────────
|
||
|
||
func to_dict() -> Dictionary:
|
||
return {
|
||
"class_id": &"rock",
|
||
"tile_x": tile.x,
|
||
"tile_y": tile.y,
|
||
"mine_progress": mine_progress,
|
||
}
|
||
|
||
|
||
static func from_dict(d: Dictionary) -> Dictionary:
|
||
return {
|
||
"tile_x": int(d.get("tile_x", 0)),
|
||
"tile_y": int(d.get("tile_y", 0)),
|
||
"mine_progress": int(d.get("mine_progress", 0)),
|
||
}
|
||
|
||
|
||
# ── render ────────────────────────────────────────────────────────────────────
|
||
|
||
func _draw() -> void:
|
||
# Angular cluster of 3–4 triangles in a dark-grey / light-grey palette.
|
||
var c1 := Color(0.55, 0.55, 0.50) # light face
|
||
var c2 := Color(0.38, 0.38, 0.36) # shadow face
|
||
|
||
# Main body polygon (roughly an irregular hex).
|
||
var body := PackedVector2Array([
|
||
Vector2(-5.0, 3.0),
|
||
Vector2(-6.0, -1.0),
|
||
Vector2(-2.0, -6.0),
|
||
Vector2(3.0, -5.0),
|
||
Vector2(6.0, 0.0),
|
||
Vector2(4.0, 4.0),
|
||
])
|
||
draw_colored_polygon(body, c1)
|
||
|
||
# Shadow face on the bottom-right triangle to give depth.
|
||
var shadow := PackedVector2Array([
|
||
Vector2(3.0, -5.0),
|
||
Vector2(6.0, 0.0),
|
||
Vector2(4.0, 4.0),
|
||
Vector2(-5.0, 3.0),
|
||
])
|
||
draw_colored_polygon(shadow, c2)
|
||
|
||
# Outline.
|
||
draw_polyline(body, Color(0.0, 0.0, 0.0, 0.5), 1.0)
|
||
draw_line(body[5], body[0], Color(0.0, 0.0, 0.0, 0.5), 1.0)
|
||
|
||
# Mine-progress crack: a dark jagged line on the face when partially mined.
|
||
if mine_progress > 0:
|
||
var ratio := float(mine_progress) / float(MINE_TICKS)
|
||
var crack_len := ratio * 5.0
|
||
draw_line(
|
||
Vector2(-1.0, -2.0),
|
||
Vector2(-1.0 + crack_len, 1.0),
|
||
Color(0.15, 0.12, 0.10, 0.85),
|
||
1.5
|
||
)
|
||
|
||
|
||
# ── helpers ───────────────────────────────────────────────────────────────────
|
||
|
||
func _tile_to_world(t: Vector2i) -> Vector2:
|
||
return Vector2(
|
||
t.x * TILE_SIZE_PX + TILE_SIZE_PX / 2.0,
|
||
t.y * TILE_SIZE_PX + TILE_SIZE_PX / 2.0
|
||
)
|