Add a combat restart action to the SpireLens options menu #314

Merged
nelsong6 merged 2 commits from claude/combat-reset-feasibility-731162 into main 2026-08-12 20:31:09 -07:00
nelsong6 commented 2026-08-12 20:31:03 -07:00 (Migrated from github.com)

Adds a Restart this combat action under a new "Practice" section in the SpireLens options menu. It replays the fight in progress from the state it began with.

Why this needs no snapshot logic

STS2's run save is a room-boundary snapshot. SerializableRun carries no combat state at all — no hand, no piles, no enemies, no powers, no turn number. The write points are what make that coherent:

  • RunManager.EnterMapPointInternal calls SaveRun(null) on map-node entry, before the room type is rolled.
  • CombatManager saves again at victory, with room.MarkPreFinished().
  • Nothing is written during a fight.

So for the whole duration of a combat, current_run.save on disk is that combat's opening state, RNG included. Restarting is a replay of the save the game already wrote.

How

CombatResetter mirrors the main menu's Continue sequence (FromSerializable -> SetUpSavedSingleplayer -> LoadRun) with RunManager.CleanUp() inserted first, since SetUpSavedSingleplayer throws while RunManager.State is non-null.

CleanUp is the Save-and-Quit/Abandon teardown: it sets ShouldSave = false (so the half-played fight can never overwrite the save), calls CombatManager.Reset(graceful), and nulls State — but does not call RunManager.OnEnded, so no run outcome is stamped and no RunEnded fires.

The save is read and deserialized before any teardown, so a missing or corrupt save aborts with the live run untouched.

Tracking correctness

The result is the Continue path, so RunStarted re-fires with the same _startTime and RunTracker's existing run adoption handles it — including the _pendingCombat discard. The abandoned attempt is not promoted and the replayed fight is counted once. No new persisted fields, so no schema fixture.

UI

The row is guarded (in combat, singleplayer, run save present) and names its own reason when unavailable rather than silently doing nothing. Because it discards a fight in progress it uses a two-step confirm that disarms when focus moves off the row. Action rows now dispatch through a table instead of a hardcoded index.

Timing

Transitions run at 0.12s/0.18s rather than NTransition's 0.8s default, which is tuned for a deliberate main-menu Continue. Not zero: the run scene is rebuilt in between and an uncovered swap shows a half-destroyed frame. Per-phase stopwatch logging is included so the remaining cost — the disk write in IncrementNumReloads, and the preload/scene-rebuild/room-entry inside LoadRun — is measurable before anything further is cut.

Notes

  • No new Harmony target. Reached from the existing HotReloadInputNode._Input postfix.
  • SetUpSavedSingleplayer awaits IncrementNumReloads, so each restart increments the save's num_reloads.
  • Singleplayer only; the multiplayer equivalent needs a LoadRunLobby that cannot be rebuilt here.
  • docs/sts2-runtime-primer.md gains a section on the room-boundary save model.

Verification

Built, deployed, and hot-reloaded (Patch install: 428 classes patched, 0 failed/skipped, Core.Initialize complete). Per the repo's user-owned verification rule, unit tests and live behavioral verification were not run.

Adds a **Restart this combat** action under a new "Practice" section in the SpireLens options menu. It replays the fight in progress from the state it began with. ## Why this needs no snapshot logic STS2's run save is a room-boundary snapshot. `SerializableRun` carries no combat state at all — no hand, no piles, no enemies, no powers, no turn number. The write points are what make that coherent: - `RunManager.EnterMapPointInternal` calls `SaveRun(null)` on map-node entry, *before* the room type is rolled. - `CombatManager` saves again at victory, with `room.MarkPreFinished()`. - Nothing is written during a fight. So for the whole duration of a combat, `current_run.save` on disk **is** that combat's opening state, RNG included. Restarting is a replay of the save the game already wrote. ## How `CombatResetter` mirrors the main menu's Continue sequence (`FromSerializable` -> `SetUpSavedSingleplayer` -> `LoadRun`) with `RunManager.CleanUp()` inserted first, since `SetUpSavedSingleplayer` throws while `RunManager.State` is non-null. `CleanUp` is the Save-and-Quit/Abandon teardown: it sets `ShouldSave = false` (so the half-played fight can never overwrite the save), calls `CombatManager.Reset(graceful)`, and nulls `State` — but does **not** call `RunManager.OnEnded`, so no run outcome is stamped and no `RunEnded` fires. The save is read and deserialized *before* any teardown, so a missing or corrupt save aborts with the live run untouched. ## Tracking correctness The result is the Continue path, so `RunStarted` re-fires with the same `_startTime` and `RunTracker`'s existing run adoption handles it — including the `_pendingCombat` discard. The abandoned attempt is not promoted and the replayed fight is counted once. No new persisted fields, so no schema fixture. ## UI The row is guarded (in combat, singleplayer, run save present) and names its own reason when unavailable rather than silently doing nothing. Because it discards a fight in progress it uses a two-step confirm that disarms when focus moves off the row. Action rows now dispatch through a table instead of a hardcoded index. ## Timing Transitions run at 0.12s/0.18s rather than `NTransition`'s 0.8s default, which is tuned for a deliberate main-menu Continue. Not zero: the run scene is rebuilt in between and an uncovered swap shows a half-destroyed frame. Per-phase stopwatch logging is included so the remaining cost — the disk write in `IncrementNumReloads`, and the preload/scene-rebuild/room-entry inside `LoadRun` — is measurable before anything further is cut. ## Notes - No new Harmony target. Reached from the existing `HotReloadInputNode._Input` postfix. - `SetUpSavedSingleplayer` awaits `IncrementNumReloads`, so each restart increments the save's `num_reloads`. - Singleplayer only; the multiplayer equivalent needs a `LoadRunLobby` that cannot be rebuilt here. - `docs/sts2-runtime-primer.md` gains a section on the room-boundary save model. ## Verification Built, deployed, and hot-reloaded (`Patch install: 428 classes patched, 0 failed/skipped`, `Core.Initialize complete`). Per the repo's user-owned verification rule, unit tests and live behavioral verification were not run.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/spirelens!314
No description provided.