Skip to content

[UI/UX] Implement Mid-Run Save & Crash Recovery System - #607

Merged
niyazmft merged 4 commits into
mainfrom
feat/mid-run-save-crash-recovery
Jul 13, 2026
Merged

[UI/UX] Implement Mid-Run Save & Crash Recovery System#607
niyazmft merged 4 commits into
mainfrom
feat/mid-run-save-crash-recovery

Conversation

@niyazmft

Copy link
Copy Markdown
Owner

Summary

Adds atomic auto-save with rotating FIFO backups, enabling players to resume runs after crashes, alt-tabs, or quitting mid-session.

Problem

Emberfall runs last 30–90 minutes. A crash, alt-tab, or system sleep currently loses all progress — a major pain point for modern PC gamers who expect session resumption.

Changes

SaveManager extensions

  • auto_save_run(run_state): Serializes run state and writes to user://saves/auto.json
    • Atomic write: Writes to .tmp first, then renames to final path. If the game crashes during write, the existing save remains intact.
    • Rotating FIFO: Keeps 3 backup slots (auto_1.jsonauto_3.json). Older backups are pushed out automatically.
    • Steam Cloud sync: Automatically syncs to Steam Remote Storage after each successful write (silently skipped on non-Steam builds).
  • load_auto_save(): Reads auto-save JSON; returns empty Dictionary on any error (corrupt file, missing file, parse failure).
  • has_auto_save(): Checks if auto-save exists on disk.
  • delete_auto_save(): Clears all auto-save slots.

RunManager integration

  • save_run_state() now captures:
    • Run seed, room index, room queue, biome index
    • Player entity snapshot (full Entity serialization via ActionHistory.serialize_entity)
    • Burden run snapshot (trigger count + noun index)
  • load_run_state() restores player entity and burden snapshots on resume.
  • _auto_save_current_run() helper called from:
    • _enter_room() — auto-save at start of each room
    • _enter_moral_eval() — auto-save after combat resolved

GameCoordinator / TitleScreen

  • TitleScreen: Continue button is enabled if either a main save OR an auto-save exists.
  • GameCoordinator.cmd_continue_game(): Tries auto-save first, falls back to main save. This means players can resume even if they never manually saved.

BurdenManager

  • Added get_trigger_count_this_run() and get_last_noun_index() getters for serialization.

AutoloadHelper

  • Added steam_manager() accessor for Steam Cloud sync.

Edge Cases Handled

Scenario Behavior
Crash during save Existing save untouched (atomic rename)
Corrupt auto-save file Graceful empty-Dictionary fallback; no crash
Resume on Steam Deck Steam Cloud syncs save; resume proceeds normally
No auto-save exists Continue falls back to main save
No saves at all Continue button disabled

Tests

  • tests/test_auto_save.gd: 4 cases
    • Atomic write / load round-trip
    • FIFO rotation (4 writes → oldest evicted)
    • Corrupt file graceful handling
    • Empty state save/load

Testing

  • 400 tests | 0 errors | 0 failures | 74/74 suites
  • Headless editor scan: clean

Related Issues

Closes #604

niyazmft added 4 commits July 12, 2026 23:31
## Summary

Implements deterministic hover preview showing combat outcomes before
committing an action. Color-coded by severity.

## Changes

### New: HoverPreviewManager
- scripts/ui/hover_preview_manager.gd: Tooltip panel that follows mouse
- Shows damage preview, HP after hit, AP cost when hovering enemies
- Shows move cost, elevation bonus, cover info when hovering tiles
- Color-coded severity: green (safe), yellow (warning), red (lethal)
- Panel keeps itself inside viewport bounds

### CombatRoom integration
- Instantiates HoverPreviewManager in UIOverlay during _setup_hud()
- _input() detects mouse motion and updates preview via _update_hover_preview()
- Checks _enemies_node for entity at hovered tile, falls back to tile info
- Only active during PLAYER_TURN; hidden during enemy turn

### Tests
- test_hover_preview.gd: 2 cases for severity display and clear behavior

## Testing

- 392 tests | 0 errors | 0 failures | 72/72 suites
- Headless editor scan: clean

Closes #597
## Summary

Adds a deterministic undo/rewind system for player actions within a turn.
Players can now undo misclicks or re-experiment with tactics.

## Changes

### New: ActionHistory
- scripts/core/action_history.gd: LIFO stack of state snapshots
- serialize_entity() / restore_entity(): Full entity state capture and restore
- Configurable depth limit (default unlimited per turn)
- Lightweight RefCounted — no autoload needed

### CombatInput signals
- Added action_about_to_execute signal, emitted before attack/move mutations
- Emitted in _execute_attack() and _execute_move_to()

### CombatRoom integration
- Instantiates ActionHistory during _ready
- _push_snapshot() captures player + all enemy states before each action
- _undo_last_action() restores most recent snapshot on Ctrl+Z or Backspace
- Snapshot captured for: keyboard moves, mouse moves, attacks
- History cleared at start of each player turn (fresh stack)
- Visual feedback: brief camera shake + toast message on undo

### Tests
- test_action_history.gd: 4 cases for serialize round-trip, LIFO stack,
  empty noop, and depth limit trimming

## Testing

- 396 tests | 0 errors | 0 failures | 73/73 suites
- Headless editor scan: clean

Closes #596
## Summary

Adds atomic auto-save with rotating FIFO backups, enabling players to
resume runs after crashes or quitting mid-session.

## Changes

### SaveManager extensions
- AUTO_SAVE_DIR, AUTO_SAVE_PATH, AUTO_SAVE_SLOTS constants
- auto_save_run(run_state): Atomic write with tmp→rename, then Steam Cloud sync
- load_auto_save(): Reads auto-save JSON, returns empty Dict on error
- has_auto_save(): Checks if auto-save exists
- delete_auto_save(): Clears all slots
- _rotate_auto_saves(): FIFO rotation (auto→auto_1→auto_2→auto_3)
- _atomic_write_json(): Writes to .tmp then renames to prevent corruption
- _load_json_file(): Graceful JSON parsing (empty Dict on error)

### RunManager integration
- save_run_state() now includes player_entity_snapshot and burden_run_snapshot
- load_run_state() restores player entity and burden snapshots
- _auto_save_current_run() helper called from _enter_room and _enter_moral_eval
- Auto-save triggers at phase boundaries: room entry and moral eval entry

### GameCoordinator / TitleScreen
- TitleScreen: Continue button enabled if main save OR auto-save exists
- GameCoordinator.cmd_continue_game(): Tries auto-save first, falls back to main save

### BurdenManager
- Added get_trigger_count_this_run() and get_last_noun_index() getters

### AutoloadHelper
- Added steam_manager() accessor for Steam Cloud sync

### Tests
- test_auto_save.gd: 4 cases for atomic write, FIFO rotation, corrupt
  file handling, and empty state

## Testing

- 400 tests | 0 errors | 0 failures | 74/74 suites
- Headless editor scan: clean

Closes #604
@niyazmft
niyazmft merged commit 2e783a1 into main Jul 13, 2026
5 checks passed
@niyazmft
niyazmft deleted the feat/mid-run-save-crash-recovery branch July 13, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UI/UX] Implement Mid-Run Save & Crash Recovery System (SYS-SAVE-1)

1 participant