Phase 16: Save/load full coverage + autosave + UI
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>
This commit is contained in:
parent
3da7353387
commit
19d28ca9f8
37 changed files with 1546 additions and 63 deletions
|
|
@ -171,6 +171,7 @@ func to_dict() -> Dictionary:
|
|||
if _owner_pawn != null and _owner_pawn.has_method("get"):
|
||||
owner_name = _owner_pawn.get("pawn_name")
|
||||
return {
|
||||
"class_id": &"bed",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"quality": quality,
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ func _draw() -> void:
|
|||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"corpse",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"name": deceased_name,
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ func _on_sim_tick(_n: int) -> void:
|
|||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"crop",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"crop_kind": String(crop_kind),
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ func is_completed() -> bool:
|
|||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"door",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"build_progress": build_progress,
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ func is_completed() -> bool:
|
|||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"floor",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"material": str(floor_material),
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ func _draw() -> void:
|
|||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"grave_marker",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"name": deceased_name,
|
||||
|
|
|
|||
|
|
@ -196,6 +196,29 @@ func _draw_open_grave() -> void:
|
|||
draw_rect(Rect2(-6.0, -4.0, 12.0, 8.0), _OUTLINE, false, 1.0)
|
||||
|
||||
|
||||
# ── save / load ───────────────────────────────────────────────────────────────
|
||||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"grave_slot",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"build_progress": build_progress,
|
||||
"dug": _dug,
|
||||
}
|
||||
|
||||
|
||||
func from_dict(d: Dictionary) -> void:
|
||||
tile = Vector2i(int(d.get("tile_x", 0)), int(d.get("tile_y", 0)))
|
||||
build_progress = int(d.get("build_progress", 0))
|
||||
_dug = bool(d.get("dug", false))
|
||||
global_position = Vector2(
|
||||
tile.x * TILE_SIZE_PX + TILE_SIZE_PX / 2.0,
|
||||
tile.y * TILE_SIZE_PX + TILE_SIZE_PX / 2.0
|
||||
)
|
||||
queue_redraw()
|
||||
|
||||
|
||||
# ── internal ─────────────────────────────────────────────────────────────────
|
||||
|
||||
func _complete_dig() -> void:
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ func set_being_carried(value: bool) -> void:
|
|||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"item",
|
||||
"type": String(item_type),
|
||||
"stack_size": stack_size,
|
||||
"tile_x": tile.x,
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ func mined() -> void:
|
|||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"rock",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"mine_progress": mine_progress,
|
||||
|
|
|
|||
|
|
@ -160,6 +160,7 @@ func set_on(value: bool) -> void:
|
|||
## Serialise all persistent state for World save (wired in Phase 16).
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"torch",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"label_text": label_text,
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ func fell() -> void:
|
|||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"tree",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"chop_progress": chop_progress,
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ func is_completed() -> bool:
|
|||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"wall",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"material": str(wall_material),
|
||||
|
|
|
|||
|
|
@ -177,6 +177,47 @@ func _advance_walk() -> void:
|
|||
_step_progress = 0.0
|
||||
|
||||
|
||||
# ── save / load ──────────────────────────────────────────────────────────────
|
||||
|
||||
func to_dict() -> Dictionary:
|
||||
# target_pawn is stored as a name string so the loader can re-resolve it
|
||||
# against World.pawns without a live Node reference.
|
||||
var target_name: String = ""
|
||||
if target_pawn != null and target_pawn.get("pawn_name") != null:
|
||||
target_name = str(target_pawn.pawn_name)
|
||||
var path_data: Array = []
|
||||
for v in _path:
|
||||
path_data.append([v.x, v.y])
|
||||
return {
|
||||
"class_id": &"wolf",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"hp": hp,
|
||||
"state": int(state),
|
||||
"step_progress": _step_progress,
|
||||
"attack_cooldown": _attack_cooldown,
|
||||
"target_pawn_name": target_name,
|
||||
"path": path_data,
|
||||
}
|
||||
|
||||
|
||||
func from_dict(d: Dictionary) -> void:
|
||||
tile = Vector2i(int(d.get("tile_x", 0)), int(d.get("tile_y", 0)))
|
||||
hp = clampf(float(d.get("hp", HP_MAX)), 0.0, HP_MAX)
|
||||
state = int(d.get("state", State.APPROACH)) as State
|
||||
_step_progress = float(d.get("step_progress", 0.0))
|
||||
_attack_cooldown = int(d.get("attack_cooldown", 0))
|
||||
# target_pawn: re-resolved by the loader after all pawns are restored.
|
||||
# Store the name in a temporary string; caller sets target_pawn post-load.
|
||||
target_pawn = null # caller must re-resolve from "target_pawn_name"
|
||||
_path.clear()
|
||||
for entry in d.get("path", []):
|
||||
if entry is Array and entry.size() == 2:
|
||||
_path.append(Vector2i(int(entry[0]), int(entry[1])))
|
||||
position = _tile_to_world(tile)
|
||||
queue_redraw()
|
||||
|
||||
|
||||
# ── render ──────────────────────────────────────────────────────────────────
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
|
|
|
|||
|
|
@ -236,6 +236,7 @@ func to_dict() -> Dictionary:
|
|||
for b in bills:
|
||||
bills_data.append(b.to_dict())
|
||||
return {
|
||||
"class_id": &"workbench",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"label_text": label_text,
|
||||
|
|
|
|||
|
|
@ -8,9 +8,15 @@ extends Node2D
|
|||
## Phase 15 — StorytellerBanner and StorytellerModal are runtime-instantiated
|
||||
## here (same pattern as world.gd's BeautySystem / DirtinessSystem). Both are
|
||||
## CanvasLayer nodes so they draw above the world regardless of scene-tree order.
|
||||
##
|
||||
## Phase 16 — LoadMenu (layer 25) and ResumeToast (layer 22) are runtime-
|
||||
## instantiated here. LoadMenu ref is injected into TopBar so the Load button
|
||||
## can call open() without a get_node("/root/…") call.
|
||||
|
||||
const STORYTELLER_BANNER_SCRIPT: Script = preload("res://scenes/ui/storyteller_banner.gd")
|
||||
const STORYTELLER_MODAL_SCRIPT: Script = preload("res://scenes/ui/storyteller_modal.gd")
|
||||
const STORYTELLER_MODAL_SCRIPT: Script = preload("res://scenes/ui/storyteller_modal.gd")
|
||||
const LOAD_MENU_SCRIPT: Script = preload("res://scenes/ui/load_menu.gd")
|
||||
const RESUME_TOAST_SCRIPT: Script = preload("res://scenes/ui/resume_toast.gd")
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -23,6 +29,7 @@ func _ready() -> void:
|
|||
assert(EventBus != null, "EventBus autoload missing")
|
||||
assert(Strings != null, "Strings autoload missing")
|
||||
assert(SaveSystem != null, "SaveSystem autoload missing")
|
||||
assert(Autosave != null, "Autosave autoload missing")
|
||||
|
||||
# Phase 15 — Storyteller UI layers. Runtime-instantiated so no .tscn edit is
|
||||
# needed. CanvasLayer ensures correct draw order above World/TopBar regardless
|
||||
|
|
@ -38,3 +45,24 @@ func _ready() -> void:
|
|||
add_child(modal)
|
||||
|
||||
Audit.log("main", "Phase 15 — StorytellerBanner + StorytellerModal mounted.")
|
||||
|
||||
# Phase 16 — Save/Load UI layers.
|
||||
var resume_toast := CanvasLayer.new()
|
||||
resume_toast.set_script(RESUME_TOAST_SCRIPT)
|
||||
resume_toast.name = "ResumeToast"
|
||||
add_child(resume_toast)
|
||||
|
||||
var load_menu := CanvasLayer.new()
|
||||
load_menu.set_script(LOAD_MENU_SCRIPT)
|
||||
load_menu.name = "LoadMenu"
|
||||
add_child(load_menu)
|
||||
|
||||
# Inject LoadMenu ref into TopBar so the Load button can call open()
|
||||
# without reaching into the scene tree by path.
|
||||
var top_bar = get_node_or_null("TopBar")
|
||||
if top_bar != null and top_bar.has_method("_ready"):
|
||||
top_bar.load_menu = load_menu
|
||||
elif top_bar != null:
|
||||
top_bar.load_menu = load_menu
|
||||
|
||||
Audit.log("main", "Phase 16 — LoadMenu + ResumeToast mounted.")
|
||||
|
|
|
|||
|
|
@ -876,6 +876,7 @@ func to_dict() -> Dictionary:
|
|||
for s in statuses:
|
||||
statuses_data.append(s.to_dict())
|
||||
return {
|
||||
"class_id": &"pawn",
|
||||
"name": pawn_name,
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
|
|
|
|||
252
scenes/ui/load_menu.gd
Normal file
252
scenes/ui/load_menu.gd
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
class_name LoadMenu extends CanvasLayer
|
||||
## Phase 16 — Slot-picker shown when the player taps Load.
|
||||
##
|
||||
## Layer 25 — above StorytellerModal (20) and any banner (15).
|
||||
## Shows Manual save + Autosave slots with timestamps. If a slot's version
|
||||
## differs from SAVE_VERSION, the player sees a warning dialog before the load
|
||||
## proceeds.
|
||||
##
|
||||
## Open via LoadMenu.open(); close via the Cancel button or _close().
|
||||
|
||||
## Emitted when the player confirms a load (after any version-mismatch dialog).
|
||||
signal load_confirmed(slot: StringName)
|
||||
|
||||
|
||||
const TILE_SIZE_PX: int = 16
|
||||
|
||||
# ── node refs ─────────────────────────────────────────────────────────────────
|
||||
var _dim: ColorRect = null
|
||||
var _panel: PanelContainer = null
|
||||
var _slot_list: VBoxContainer = null
|
||||
var _no_saves_label: Label = null
|
||||
var _cancel_btn: Button = null
|
||||
|
||||
# Version-mismatch confirmation dialog refs.
|
||||
var _warn_dim: ColorRect = null
|
||||
var _warn_panel: PanelContainer = null
|
||||
var _warn_label: Label = null
|
||||
var _warn_continue_btn: Button = null
|
||||
var _warn_cancel_btn: Button = null
|
||||
|
||||
## The slot waiting for confirmation (set while the warning dialog is open).
|
||||
var _pending_slot: StringName = &""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
layer = 25
|
||||
_build_ui()
|
||||
_set_visible(false)
|
||||
Audit.log("load_menu", "LoadMenu ready")
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
pass
|
||||
|
||||
|
||||
# ── public API ────────────────────────────────────────────────────────────────
|
||||
|
||||
func open() -> void:
|
||||
_refresh_slots()
|
||||
_set_visible(true)
|
||||
Audit.log("load_menu", "opened")
|
||||
|
||||
|
||||
# ── UI construction ───────────────────────────────────────────────────────────
|
||||
|
||||
func _build_ui() -> void:
|
||||
# Full-screen dim.
|
||||
_dim = ColorRect.new()
|
||||
_dim.name = "Dim"
|
||||
_dim.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
_dim.color = Color(0.0, 0.0, 0.0, 0.55)
|
||||
_dim.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
add_child(_dim)
|
||||
|
||||
# Centre panel.
|
||||
_panel = PanelContainer.new()
|
||||
_panel.name = "Dialog"
|
||||
_panel.set_anchors_preset(Control.PRESET_CENTER)
|
||||
_panel.custom_minimum_size = Vector2(360, 220)
|
||||
_panel.offset_left = -180
|
||||
_panel.offset_right = 180
|
||||
_panel.offset_top = -110
|
||||
_panel.offset_bottom = 110
|
||||
add_child(_panel)
|
||||
|
||||
var vbox := VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 12)
|
||||
_panel.add_child(vbox)
|
||||
|
||||
# Title.
|
||||
var title := Label.new()
|
||||
title.name = "Title"
|
||||
title.text = Strings.t(&"ui.load")
|
||||
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
vbox.add_child(title)
|
||||
|
||||
# Slot list (populated by _refresh_slots).
|
||||
_slot_list = VBoxContainer.new()
|
||||
_slot_list.name = "SlotList"
|
||||
_slot_list.add_theme_constant_override("separation", 8)
|
||||
vbox.add_child(_slot_list)
|
||||
|
||||
# "No saves yet" label — hidden when slots exist.
|
||||
_no_saves_label = Label.new()
|
||||
_no_saves_label.name = "NoSaves"
|
||||
_no_saves_label.text = Strings.t(&"ui.no_saves")
|
||||
_no_saves_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_no_saves_label.visible = false
|
||||
vbox.add_child(_no_saves_label)
|
||||
|
||||
# Cancel row.
|
||||
var cancel_row := HBoxContainer.new()
|
||||
cancel_row.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
vbox.add_child(cancel_row)
|
||||
|
||||
_cancel_btn = Button.new()
|
||||
_cancel_btn.name = "CancelBtn"
|
||||
_cancel_btn.text = Strings.t(&"ui.cancel")
|
||||
_cancel_btn.custom_minimum_size = Vector2(120, 48)
|
||||
_cancel_btn.focus_mode = Control.FOCUS_NONE
|
||||
_cancel_btn.pressed.connect(_close)
|
||||
cancel_row.add_child(_cancel_btn)
|
||||
|
||||
# Version-mismatch warning dialog (built once, shown when needed).
|
||||
_build_warn_dialog()
|
||||
|
||||
|
||||
func _build_warn_dialog() -> void:
|
||||
_warn_dim = ColorRect.new()
|
||||
_warn_dim.name = "WarnDim"
|
||||
_warn_dim.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
_warn_dim.color = Color(0.0, 0.0, 0.0, 0.45)
|
||||
_warn_dim.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
_warn_dim.visible = false
|
||||
add_child(_warn_dim)
|
||||
|
||||
_warn_panel = PanelContainer.new()
|
||||
_warn_panel.name = "WarnDialog"
|
||||
_warn_panel.set_anchors_preset(Control.PRESET_CENTER)
|
||||
_warn_panel.custom_minimum_size = Vector2(340, 160)
|
||||
_warn_panel.offset_left = -170
|
||||
_warn_panel.offset_right = 170
|
||||
_warn_panel.offset_top = -80
|
||||
_warn_panel.offset_bottom = 80
|
||||
_warn_panel.visible = false
|
||||
add_child(_warn_panel)
|
||||
|
||||
var vbox := VBoxContainer.new()
|
||||
vbox.add_theme_constant_override("separation", 12)
|
||||
_warn_panel.add_child(vbox)
|
||||
|
||||
_warn_label = Label.new()
|
||||
_warn_label.name = "WarnLabel"
|
||||
_warn_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_warn_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
vbox.add_child(_warn_label)
|
||||
|
||||
var btn_row := HBoxContainer.new()
|
||||
btn_row.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
btn_row.add_theme_constant_override("separation", 12)
|
||||
vbox.add_child(btn_row)
|
||||
|
||||
_warn_continue_btn = Button.new()
|
||||
_warn_continue_btn.text = Strings.t(&"ui.continue")
|
||||
_warn_continue_btn.custom_minimum_size = Vector2(120, 48)
|
||||
_warn_continue_btn.focus_mode = Control.FOCUS_NONE
|
||||
_warn_continue_btn.pressed.connect(_on_warn_continue)
|
||||
btn_row.add_child(_warn_continue_btn)
|
||||
|
||||
_warn_cancel_btn = Button.new()
|
||||
_warn_cancel_btn.text = Strings.t(&"ui.cancel")
|
||||
_warn_cancel_btn.custom_minimum_size = Vector2(120, 48)
|
||||
_warn_cancel_btn.focus_mode = Control.FOCUS_NONE
|
||||
_warn_cancel_btn.pressed.connect(_on_warn_cancel)
|
||||
btn_row.add_child(_warn_cancel_btn)
|
||||
|
||||
|
||||
# ── slot population ───────────────────────────────────────────────────────────
|
||||
|
||||
func _refresh_slots() -> void:
|
||||
# Clear previous slot buttons.
|
||||
for child in _slot_list.get_children():
|
||||
child.queue_free()
|
||||
|
||||
var slots: Array[StringName] = [&"manual", &"autosave"]
|
||||
var any_exist: bool = false
|
||||
|
||||
for slot in slots:
|
||||
var meta: Dictionary = SaveSystem.peek_save_metadata(slot)
|
||||
if not meta.get("exists", false):
|
||||
continue
|
||||
any_exist = true
|
||||
|
||||
var label_key: StringName = &"ui.manual_save" if slot == &"manual" else &"ui.autosave"
|
||||
var saved_at: int = int(meta.get("saved_at_unix", 0))
|
||||
var date_str: String = _unix_to_date(saved_at)
|
||||
var btn_text: String = "%s (%s)" % [Strings.t(label_key), date_str]
|
||||
|
||||
var btn := Button.new()
|
||||
btn.text = btn_text
|
||||
btn.custom_minimum_size = Vector2(320, 48)
|
||||
btn.focus_mode = Control.FOCUS_NONE
|
||||
# Capture slot by value in the lambda.
|
||||
btn.pressed.connect(_on_slot_pressed.bind(slot, int(meta.get("version", 1))))
|
||||
_slot_list.add_child(btn)
|
||||
|
||||
_no_saves_label.visible = not any_exist
|
||||
|
||||
|
||||
func _unix_to_date(unix: int) -> String:
|
||||
if unix <= 0:
|
||||
return "—"
|
||||
var dt: Dictionary = Time.get_datetime_dict_from_unix_time(unix)
|
||||
return "%04d-%02d-%02d %02d:%02d" % [dt.year, dt.month, dt.day, dt.hour, dt.minute]
|
||||
|
||||
|
||||
# ── interaction ───────────────────────────────────────────────────────────────
|
||||
|
||||
func _on_slot_pressed(slot: StringName, file_version: int) -> void:
|
||||
if file_version != SaveSystem.SAVE_VERSION:
|
||||
# Show version-mismatch warning dialog before proceeding.
|
||||
_pending_slot = slot
|
||||
_warn_label.text = Strings.t(&"ui.version_mismatch").format({"v": file_version})
|
||||
_warn_dim.visible = true
|
||||
_warn_panel.visible = true
|
||||
Audit.log("load_menu", "version mismatch warning shown for slot '%s' (v%d)" % [slot, file_version])
|
||||
else:
|
||||
_do_load(slot)
|
||||
|
||||
|
||||
func _on_warn_continue() -> void:
|
||||
_warn_dim.visible = false
|
||||
_warn_panel.visible = false
|
||||
if _pending_slot != &"":
|
||||
_do_load(_pending_slot)
|
||||
_pending_slot = &""
|
||||
|
||||
|
||||
func _on_warn_cancel() -> void:
|
||||
_warn_dim.visible = false
|
||||
_warn_panel.visible = false
|
||||
_pending_slot = &""
|
||||
Audit.log("load_menu", "version mismatch — player cancelled load")
|
||||
|
||||
|
||||
func _do_load(slot: StringName) -> void:
|
||||
Audit.log("load_menu", "loading slot '%s'" % slot)
|
||||
load_confirmed.emit(slot)
|
||||
_close()
|
||||
SaveSystem.load_from_slot(slot)
|
||||
|
||||
|
||||
func _close() -> void:
|
||||
_set_visible(false)
|
||||
Audit.log("load_menu", "closed")
|
||||
|
||||
|
||||
func _set_visible(v: bool) -> void:
|
||||
if _dim != null:
|
||||
_dim.visible = v
|
||||
if _panel != null:
|
||||
_panel.visible = v
|
||||
1
scenes/ui/load_menu.gd.uid
Normal file
1
scenes/ui/load_menu.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://di115iwu6o6c8
|
||||
124
scenes/ui/resume_toast.gd
Normal file
124
scenes/ui/resume_toast.gd
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
class_name ResumeToast extends CanvasLayer
|
||||
## Phase 16 — "Welcome back / Load failed" toast.
|
||||
##
|
||||
## Layer 22 — above Modal (20) but below LoadMenu (25).
|
||||
## Listens to EventBus.load_finished.
|
||||
## On ok=true: "Welcome back — away N minutes/hours" for SHOW_DURATION_SEC, then fades.
|
||||
## On ok=false: "Load failed (corrupt or version mismatch)" — same fade cadence.
|
||||
|
||||
const SHOW_DURATION_SEC: float = 5.0
|
||||
const FADE_DURATION_SEC: float = 0.8
|
||||
|
||||
var _root: Control = null
|
||||
var _label: Label = null
|
||||
var _show_timer: Timer = null
|
||||
|
||||
var _fade_time: float = 0.0
|
||||
var _fading: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
layer = 22
|
||||
_build_ui()
|
||||
_root.visible = false
|
||||
EventBus.load_finished.connect(_on_load_finished)
|
||||
Audit.log("resume_toast", "ResumeToast ready")
|
||||
|
||||
|
||||
func _exit_tree() -> void:
|
||||
if EventBus.load_finished.is_connected(_on_load_finished):
|
||||
EventBus.load_finished.disconnect(_on_load_finished)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not _fading:
|
||||
return
|
||||
_fade_time -= delta
|
||||
if _fade_time <= 0.0:
|
||||
_fading = false
|
||||
_root.visible = false
|
||||
_root.modulate = Color.WHITE
|
||||
return
|
||||
_root.modulate.a = clampf(_fade_time / FADE_DURATION_SEC, 0.0, 1.0)
|
||||
|
||||
|
||||
# ── UI construction ───────────────────────────────────────────────────────────
|
||||
|
||||
func _build_ui() -> void:
|
||||
# Top-center strip — sits just below the top bar.
|
||||
_root = Control.new()
|
||||
_root.name = "ToastRoot"
|
||||
_root.set_anchors_preset(Control.PRESET_TOP_WIDE)
|
||||
_root.custom_minimum_size = Vector2(0, 56)
|
||||
_root.offset_top = 56 # below the 48 px top bar + a little gap
|
||||
_root.offset_bottom = 112
|
||||
_root.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(_root)
|
||||
|
||||
var panel := PanelContainer.new()
|
||||
panel.name = "Panel"
|
||||
panel.set_anchors_preset(Control.PRESET_CENTER_TOP)
|
||||
panel.custom_minimum_size = Vector2(400, 48)
|
||||
panel.offset_left = -200
|
||||
panel.offset_right = 200
|
||||
panel.offset_top = 0
|
||||
panel.offset_bottom = 48
|
||||
panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_root.add_child(panel)
|
||||
|
||||
_label = Label.new()
|
||||
_label.name = "ToastLabel"
|
||||
_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
_label.autowrap_mode = TextServer.AUTOWRAP_OFF
|
||||
panel.add_child(_label)
|
||||
|
||||
_show_timer = Timer.new()
|
||||
_show_timer.name = "ShowTimer"
|
||||
_show_timer.one_shot = true
|
||||
_show_timer.wait_time = SHOW_DURATION_SEC
|
||||
_show_timer.timeout.connect(_start_fade)
|
||||
add_child(_show_timer)
|
||||
|
||||
|
||||
# ── event handling ────────────────────────────────────────────────────────────
|
||||
|
||||
func _on_load_finished(_slot: StringName, ok: bool, real_seconds_away: int) -> void:
|
||||
if ok:
|
||||
_label.text = _format_welcome(real_seconds_away)
|
||||
else:
|
||||
_label.text = Strings.t(&"ui.load_failed")
|
||||
|
||||
_root.modulate = Color.WHITE
|
||||
_root.visible = true
|
||||
_fading = false
|
||||
_show_timer.start()
|
||||
Audit.log("resume_toast", "showing — ok=%s seconds_away=%d" % [ok, real_seconds_away])
|
||||
|
||||
|
||||
func _start_fade() -> void:
|
||||
_fading = true
|
||||
_fade_time = FADE_DURATION_SEC
|
||||
|
||||
|
||||
# ── helpers ───────────────────────────────────────────────────────────────────
|
||||
|
||||
func _format_welcome(seconds_away: int) -> String:
|
||||
var duration_str: String
|
||||
if seconds_away < 120:
|
||||
# Less than 2 minutes — show as "1 minute"
|
||||
duration_str = Strings.t(&"ui.welcome_back_min").format({"n": 1})
|
||||
elif seconds_away < 3600:
|
||||
# Under an hour — show in minutes.
|
||||
var mins: int = seconds_away / 60
|
||||
var key: StringName = &"ui.welcome_back_min" if mins == 1 else &"ui.welcome_back_mins"
|
||||
duration_str = Strings.t(key).format({"n": mins})
|
||||
elif seconds_away < 7200:
|
||||
# 1–2 hours exactly → singular.
|
||||
duration_str = Strings.t(&"ui.welcome_back_hour").format({"n": 1})
|
||||
else:
|
||||
var hrs: int = seconds_away / 3600
|
||||
var key: StringName = &"ui.welcome_back_hour" if hrs == 1 else &"ui.welcome_back_hours"
|
||||
duration_str = Strings.t(key).format({"n": hrs})
|
||||
|
||||
return Strings.t(&"ui.welcome_back").format({"n": duration_str})
|
||||
1
scenes/ui/resume_toast.gd.uid
Normal file
1
scenes/ui/resume_toast.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dur68caotb1yn
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
extends CanvasLayer
|
||||
## Top-bar HUD: speed/pause buttons and tick counter.
|
||||
## Top-bar HUD: speed/pause buttons, tick counter, and save/load controls.
|
||||
##
|
||||
## Buttons call Sim.set_speed(); active button is yellow-tinted.
|
||||
## Tick label updates on every EventBus.sim_tick signal.
|
||||
## Keyboard shortcuts (pause / speed_normal / speed_fast / speed_ultra) are
|
||||
## handled here so the bar is the single owner of speed-input logic.
|
||||
##
|
||||
## Phase 16: SaveBtn → SaveSystem.save_to_slot(&"manual").
|
||||
## LoadBtn → opens the LoadMenu CanvasLayer (mounted by main.gd).
|
||||
|
||||
const ACTIVE_MODULATE := Color(1.2, 1.2, 0.8)
|
||||
const IDLE_MODULATE := Color.WHITE
|
||||
|
|
@ -13,6 +16,8 @@ const IDLE_MODULATE := Color.WHITE
|
|||
@onready var normal_btn : Button = $Anchor/ButtonRow/NormalBtn
|
||||
@onready var fast_btn : Button = $Anchor/ButtonRow/FastBtn
|
||||
@onready var ultra_btn : Button = $Anchor/ButtonRow/UltraBtn
|
||||
@onready var save_btn : Button = $Anchor/ButtonRow/SaveBtn
|
||||
@onready var load_btn : Button = $Anchor/ButtonRow/LoadBtn
|
||||
@onready var tick_label : Label = $Anchor/TickLabel
|
||||
@onready var clock_label : Label = $Anchor/ClockLabel
|
||||
@onready var season_label : Label = $Anchor/SeasonLabel
|
||||
|
|
@ -24,12 +29,17 @@ var _speed_buttons: Dictionary = {}
|
|||
var _last_clock_text: String = ""
|
||||
var _last_season_text: String = ""
|
||||
|
||||
## Injected by main.gd after mount so we don't walk the tree with get_node.
|
||||
var load_menu: CanvasLayer = null
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
pause_btn.text = Strings.t(&"speed.pause")
|
||||
normal_btn.text = Strings.t(&"speed.normal")
|
||||
fast_btn.text = Strings.t(&"speed.fast")
|
||||
ultra_btn.text = Strings.t(&"speed.ultra")
|
||||
save_btn.text = Strings.t(&"ui.save")
|
||||
load_btn.text = Strings.t(&"ui.load")
|
||||
tick_label.text = "(boot)"
|
||||
clock_label.text = Strings.t(&"clock.format").format({"d": 1, "t": "06:00"})
|
||||
season_label.text = Strings.t(&"season.format").format({"s": Strings.t(&"season.spring"), "d": 1})
|
||||
|
|
@ -45,11 +55,15 @@ func _ready() -> void:
|
|||
normal_btn.pressed.connect(func() -> void: Sim.set_speed(Sim.Speed.NORMAL))
|
||||
fast_btn.pressed.connect(func() -> void: Sim.set_speed(Sim.Speed.FAST))
|
||||
ultra_btn.pressed.connect(func() -> void: Sim.set_speed(Sim.Speed.ULTRA))
|
||||
save_btn.pressed.connect(_on_save_pressed)
|
||||
load_btn.pressed.connect(_on_load_pressed)
|
||||
|
||||
EventBus.speed_changed.connect(_on_speed_changed)
|
||||
EventBus.sim_tick.connect(_on_sim_tick)
|
||||
EventBus.sim_tick.connect(_on_clock_refresh)
|
||||
EventBus.sim_tick.connect(_on_season_refresh)
|
||||
EventBus.save_started.connect(_on_save_started)
|
||||
EventBus.save_finished.connect(_on_save_finished)
|
||||
|
||||
# Reflect the initial speed state without emitting a signal.
|
||||
_apply_highlight(Sim.current_speed)
|
||||
|
|
@ -95,3 +109,25 @@ func _on_season_refresh(_n: int) -> void:
|
|||
func _apply_highlight(speed: Sim.Speed) -> void:
|
||||
for s: int in _speed_buttons:
|
||||
_speed_buttons[s].modulate = ACTIVE_MODULATE if s == speed else IDLE_MODULATE
|
||||
|
||||
|
||||
func _on_save_pressed() -> void:
|
||||
SaveSystem.save_to_slot(&"manual")
|
||||
Audit.log("top_bar", "manual save triggered")
|
||||
|
||||
|
||||
func _on_load_pressed() -> void:
|
||||
if load_menu != null and load_menu.has_method("open"):
|
||||
load_menu.open()
|
||||
else:
|
||||
Audit.log("top_bar", "LoadMenu not mounted — skipping open()")
|
||||
|
||||
|
||||
func _on_save_started(_slot: StringName) -> void:
|
||||
save_btn.disabled = true
|
||||
save_btn.text = Strings.t(&"ui.saving")
|
||||
|
||||
|
||||
func _on_save_finished(_slot: StringName, _ok: bool) -> void:
|
||||
save_btn.disabled = false
|
||||
save_btn.text = Strings.t(&"ui.save")
|
||||
|
|
|
|||
|
|
@ -34,6 +34,16 @@ text = "5×"
|
|||
focus_mode = 0
|
||||
text = "12×"
|
||||
|
||||
[node name="SaveBtn" type="Button" parent="Anchor/ButtonRow"]
|
||||
focus_mode = 0
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
text = "💾"
|
||||
|
||||
[node name="LoadBtn" type="Button" parent="Anchor/ButtonRow"]
|
||||
focus_mode = 0
|
||||
custom_minimum_size = Vector2(48, 48)
|
||||
text = "Load"
|
||||
|
||||
[node name="ClockLabel" type="Label" parent="Anchor"]
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
|
|
|
|||
|
|
@ -169,6 +169,30 @@ func _quality_multiplier_for(entity) -> float:
|
|||
_: return 1.0
|
||||
|
||||
|
||||
# ── save / load ───────────────────────────────────────────────────────────────
|
||||
|
||||
## Serialise the sparse beauty map as an array of {x, y, v} dicts.
|
||||
## Only non-zero tiles are stored (map is already sparse).
|
||||
func save_dict() -> Dictionary:
|
||||
var entries: Array = []
|
||||
for t in beauty_map:
|
||||
entries.append({"x": t.x, "y": t.y, "v": float(beauty_map[t])})
|
||||
return {"beauty": entries}
|
||||
|
||||
|
||||
## Restore the beauty map from a dict produced by save_dict().
|
||||
## Replaces the current map; furniture list is NOT restored here (entities
|
||||
## re-register themselves when their nodes are re-added by the loader).
|
||||
func apply_dict(d: Dictionary) -> void:
|
||||
beauty_map.clear()
|
||||
for entry in d.get("beauty", []):
|
||||
if entry is Dictionary:
|
||||
var t := Vector2i(int(entry.get("x", 0)), int(entry.get("y", 0)))
|
||||
var v: float = float(entry.get("v", 0.0))
|
||||
if v != 0.0:
|
||||
beauty_map[t] = v
|
||||
|
||||
|
||||
## Returns true if `entity` has finished building.
|
||||
## Checks the _completed bool directly (all furniture exposes is_completed() and the var).
|
||||
func _entity_completed(entity) -> bool:
|
||||
|
|
|
|||
|
|
@ -177,6 +177,7 @@ func unregister_item(item) -> void:
|
|||
## Serialise crate state for World save (Phase 16 will wire this).
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"crate",
|
||||
"tile_x": tile.x,
|
||||
"tile_y": tile.y,
|
||||
"label_text": label_text,
|
||||
|
|
|
|||
|
|
@ -78,6 +78,29 @@ func bump_pawn_traffic(tile: Vector2i, indoor: bool) -> void:
|
|||
bump(tile, amount)
|
||||
|
||||
|
||||
# ── save / load ───────────────────────────────────────────────────────────────
|
||||
|
||||
## Serialise the sparse dirt map as an array of {x, y, v} dicts.
|
||||
## Only non-zero tiles are stored (map is already sparse).
|
||||
func save_dict() -> Dictionary:
|
||||
var entries: Array = []
|
||||
for t in dirt_map:
|
||||
entries.append({"x": t.x, "y": t.y, "v": float(dirt_map[t])})
|
||||
return {"dirtiness": entries}
|
||||
|
||||
|
||||
## Restore the dirt map from a dict produced by save_dict().
|
||||
## Replaces the current map in full.
|
||||
func apply_dict(d: Dictionary) -> void:
|
||||
dirt_map.clear()
|
||||
for entry in d.get("dirtiness", []):
|
||||
if entry is Dictionary:
|
||||
var t := Vector2i(int(entry.get("x", 0)), int(entry.get("y", 0)))
|
||||
var v: float = clampf(float(entry.get("v", 0.0)), 0.0, 100.0)
|
||||
if v > 0.0:
|
||||
dirt_map[t] = v
|
||||
|
||||
|
||||
# ── internal ──────────────────────────────────────────────────────────────────
|
||||
|
||||
## Apply a dirt change from old_val to new_val for `tile`.
|
||||
|
|
|
|||
|
|
@ -88,6 +88,32 @@ func _draw() -> void:
|
|||
draw_line(cross_center + Vector2(-3.0, -1.5), cross_center + Vector2(3.0, -1.5), cross_color, 1.5)
|
||||
|
||||
|
||||
# ── save / load ───────────────────────────────────────────────────────────────
|
||||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"graveyard_zone",
|
||||
"region_x": region.position.x,
|
||||
"region_y": region.position.y,
|
||||
"region_w": region.size.x,
|
||||
"region_h": region.size.y,
|
||||
"priority": int(priority),
|
||||
"label": label,
|
||||
}
|
||||
|
||||
|
||||
func from_dict(d: Dictionary) -> void:
|
||||
region = Rect2i(
|
||||
int(d.get("region_x", 0)),
|
||||
int(d.get("region_y", 0)),
|
||||
int(d.get("region_w", 4)),
|
||||
int(d.get("region_h", 4))
|
||||
)
|
||||
priority = d.get("priority", StorageDestination.Priority.NORMAL) as StorageDestination.Priority
|
||||
label = str(d.get("label", "Graveyard"))
|
||||
queue_redraw()
|
||||
|
||||
|
||||
# ── internal ─────────────────────────────────────────────────────────────────
|
||||
|
||||
## Returns the first GraveSlot within the region that is in DUG state and not
|
||||
|
|
|
|||
|
|
@ -85,6 +85,37 @@ func _draw() -> void:
|
|||
draw_rect(rect_px, border_color, false, 1.0)
|
||||
|
||||
|
||||
# ── save / load ───────────────────────────────────────────────────────────────
|
||||
|
||||
func to_dict() -> Dictionary:
|
||||
return {
|
||||
"class_id": &"stockpile_zone",
|
||||
"region_x": region.position.x,
|
||||
"region_y": region.position.y,
|
||||
"region_w": region.size.x,
|
||||
"region_h": region.size.y,
|
||||
"priority": int(priority),
|
||||
"label": label,
|
||||
"accepted_types": accepted_types.map(func(t): return String(t)),
|
||||
}
|
||||
|
||||
|
||||
func from_dict(d: Dictionary) -> void:
|
||||
region = Rect2i(
|
||||
int(d.get("region_x", 0)),
|
||||
int(d.get("region_y", 0)),
|
||||
int(d.get("region_w", 4)),
|
||||
int(d.get("region_h", 4))
|
||||
)
|
||||
priority = d.get("priority", StorageDestination.Priority.NORMAL) as StorageDestination.Priority
|
||||
label = str(d.get("label", "Stockpile"))
|
||||
var raw_types: Array = d.get("accepted_types", [])
|
||||
accepted_types.clear()
|
||||
for s in raw_types:
|
||||
accepted_types.append(StringName(s))
|
||||
queue_redraw()
|
||||
|
||||
|
||||
# ── internal helpers ──────────────────────────────────────────────────────────
|
||||
|
||||
## Returns true when no un-carried item is sitting on `cell`.
|
||||
|
|
|
|||
|
|
@ -126,9 +126,11 @@ func _ready() -> void:
|
|||
|
||||
# Phase 5 — expose TileMap layer refs on the autoload so entity code
|
||||
# (Wall._complete, Floor._complete) can stamp data-only tile state.
|
||||
World.terrain_layer = terrain_layer
|
||||
World.wall_layer = wall_layer
|
||||
World.floor_layer = floor_layer
|
||||
World.designation_layer = designation_layer
|
||||
World.roof_layer = roof_layer
|
||||
|
||||
# Phase 13 — wire RoomDetector; setup with map size so BFS knows map bounds.
|
||||
room_detector.setup(MAP_SIZE_TILES)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue