Let the restart action undo a death #345

Merged
nelsong6 merged 1 commit from claude/undo-death-restart into main 2026-10-10 21:59:40 -07:00
nelsong6 commented 2026-10-10 21:37:30 -07:00 (Migrated from github.com)

The gap

Dying is the one room ending that destroys what the restart action replays.
RunManager.OnEnded(isVictory: false) — called synchronously from
CreatureCmd.Kill once every player is dead — runs DeleteCurrentRun(), so
RoomResetter.Describe() found no run save and the row could only say the
restart was unavailable. A death from carelessness while multitasking had no
recovery, even though the save it needed existed moments earlier.

The same call records the loss everywhere the game keeps score, which is why
putting the save back is not enough on its own:

  • UpdateProgressWithRunData — TotalLosses++, CurrentWinStreak = 0,
    playtime, floors climbed, per-card TimesLost, per-encounter and per-enemy
    losses;
  • CreateRunHistoryEntry — writes history/{StartTime}.run (SpireLens'
    RunTracker.OnRunEnded hangs off this as a postfix, stamping
    outcome=loss);
  • the game-over screen then banks the run's score into Progress.CurrentScore
    and may ObtainEpoch a score unlock.

Restoring only the run save would leave a loss counted, a streak broken and a
history entry for a death that no longer happened — a recorded outcome that
never occurred.

The fix

  • RunManagerOnEndedDeathRestorePatch, a prefix on RunManager.OnEnded,
    so it is ahead of all of the above. RoomResetter.CaptureDeathRestorePoint
    keeps current_run.save (still the room's opening state),
    Progress.ToSerializable(), and the run id whose rewind snapshot matches, in
    user://SpireLens/death-restore.json. Singleplayer, non-abandoned, once per
    run, and skipped when there is no rewind snapshot to restore the record from —
    refusing beats half-undoing.
  • Describe() offers the restart while the run is over (IsGameOver, the
    game-over screen) or absent (the main menu), reading the kept point. The row
    names the room and where the replay lands, as it already does live.
  • Restarting restores the progress object and rewrites progress.save, deletes
    {StartTime}.run, and calls the new
    RunTracker.RollBackEndedRunToLastRunSave, which reloads the rewind snapshot
    from disk (OnRunEnded clears the statics but leaves the file) and un-ends
    the record. Then the ordinary Continue path runs and writes the run save back.
  • The kept point is dropped as stale once a run save exists again or a newer
    history entry appears: restoring it then would roll progress back over runs
    played since. Profile-scoped.

Not reversible, and documented as such: the run metrics already uploaded and
any Steam achievement unlocked on the way out.

Notes

  • docs/sts2-runtime-primer.md gains a "Death Deletes The Save" section under
    the run-save write points.
  • Nothing new is persisted into RunData, so no Fixtures/RunSchema fixture is
    needed; the restore point is its own transient file.
  • Deployed and hot-reloaded (436 patch classes, 0 failed). No live behavioural
    verification was run.
## The gap Dying is the one room ending that destroys what the restart action replays. `RunManager.OnEnded(isVictory: false)` — called synchronously from `CreatureCmd.Kill` once every player is dead — runs `DeleteCurrentRun()`, so `RoomResetter.Describe()` found no run save and the row could only say the restart was unavailable. A death from carelessness while multitasking had no recovery, even though the save it needed existed moments earlier. The same call records the loss everywhere the game keeps score, which is why putting the save back is not enough on its own: - `UpdateProgressWithRunData` — `TotalLosses++`, `CurrentWinStreak = 0`, playtime, floors climbed, per-card `TimesLost`, per-encounter and per-enemy losses; - `CreateRunHistoryEntry` — writes `history/{StartTime}.run` (SpireLens' `RunTracker.OnRunEnded` hangs off this as a postfix, stamping `outcome=loss`); - the game-over screen then banks the run's score into `Progress.CurrentScore` and may `ObtainEpoch` a score unlock. Restoring only the run save would leave a loss counted, a streak broken and a history entry for a death that no longer happened — a recorded outcome that never occurred. ## The fix - `RunManagerOnEndedDeathRestorePatch`, a **prefix** on `RunManager.OnEnded`, so it is ahead of all of the above. `RoomResetter.CaptureDeathRestorePoint` keeps `current_run.save` (still the room's opening state), `Progress.ToSerializable()`, and the run id whose rewind snapshot matches, in `user://SpireLens/death-restore.json`. Singleplayer, non-abandoned, once per run, and skipped when there is no rewind snapshot to restore the record from — refusing beats half-undoing. - `Describe()` offers the restart while the run is over (`IsGameOver`, the game-over screen) or absent (the main menu), reading the kept point. The row names the room and where the replay lands, as it already does live. - Restarting restores the progress object and rewrites `progress.save`, deletes `{StartTime}.run`, and calls the new `RunTracker.RollBackEndedRunToLastRunSave`, which reloads the rewind snapshot from disk (`OnRunEnded` clears the statics but leaves the file) and un-ends the record. Then the ordinary Continue path runs and writes the run save back. - The kept point is dropped as stale once a run save exists again or a newer history entry appears: restoring it then would roll progress back over runs played since. Profile-scoped. Not reversible, and documented as such: the run metrics already uploaded and any Steam achievement unlocked on the way out. ## Notes - `docs/sts2-runtime-primer.md` gains a "Death Deletes The Save" section under the run-save write points. - Nothing new is persisted into `RunData`, so no `Fixtures/RunSchema` fixture is needed; the restore point is its own transient file. - Deployed and hot-reloaded (436 patch classes, 0 failed). No live behavioural verification was 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!345
No description provided.