Let the restart action replay shops and events, and rewind the run record with it #324
No reviewers
Labels
No labels
4-29
bug
documentation
duplicate
enhancement
flow improvement
good first issue
help wanted
invalid
investigating
issue-agent
issue-agent-blocked
issue-agent-complete
issue-agent-pr-open
issue-agent-runner-nelsonlaptop
issue-agent-runner-nelsonpc
issue-agent-runner-nelsonpc-user
issue-agent-running
needs-verification
next to do
question
queue
recon
relics-stats-onboarding
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
romaine-life/spirelens!324
Loading…
Reference in a new issue
No description provided.
Delete branch "claude/restart-events-shops-a4138a"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The options-menu restart was combat-only. It never needed to be: it replays
the run save, and that save is a room-boundary snapshot for every room type.
Why shops and events are replayable
The whole game assembly has three gameplay-path
SaveRuncalls:RunManager.EnterMapPointInternal—SaveRun(null)on map-node entry,written before the room type is even rolled.
CombatManagerat victory —MarkPreFinished()thenSaveRun(room, …).EventRoom.OnEventStateChanged— the same, but only forAncientEventModel.MerchantRoom,RestSiteRoomandTreasureRoomnever save, and nothing iswritten during a fight or an ordinary event. So for the duration of a shop or an
event,
current_run.saveis that room's opening state, and replaying it restoresthe same stock or the same event because the RNG comes back with it.
What changed
CombatResetterbecomesRoomResetter, andBlockedReason()becomesDescribe()— returning either the noun of the room a restart would replay orthe reason none can be. Availability keys off those save write points rather than
room type alone:
RunState.BaseRoom, notCurrentRoom. An event option that starts afight pushes a
CombatRoomon top, but the save replays the map point, so whatcomes back is the event. The row now says so instead of offering to "restart
this combat".
state: a combat room with no fight running (won, on rewards), an
EventRoomwith
IsPreFinished(Ancient, done), or an event whose map point has hosted acombat room that is no longer running. Those replay into the saved aftermath
and would undo nothing.
Rest sites and treasure rooms are replayable by the same mechanism and are
deliberately not offered here.
The record has to rewind too
Combat survived a restart on its own — stats sit in
_pendingCombatuntilpromotion and the adopt path drops the buffer. Shops and events have no such
buffer.
RecordGoldLosswrites straight to_currentRun.GoldStatswheneverinCombatis false and drags the map-legend category, the gold room-visitcounters and the Maw Bank / Old Coin / Golden Pearl aggregates with it. Replaying
a shop without rewinding banked every purchase twice — in the exact stats the
room exists to produce, per-relic attribution included.
So the record rewinds with the game:
RunTracker.CaptureRoomEntrySnapshotserializes_currentRunthroughRunStorage.Optionsas a room opens, ridingSignetRingStatsPatch— theexisting shared observer on
Hook.AfterRoomEntered, so no new Harmonytarget. That hook fires just after
EnterMapPointInternalwrote the save,which makes snapshot and save the same instant by construction. Taken last in
that patch, and skipped when
CurrentRoomCount > 1so an event-spawned combatcannot clobber the event's snapshot.
RunTracker.RollBackToRoomEntryrestores it.RoomResettercalls it afterevery abort path and immediately before
CleanUp(), the point of no return, soa corrupt-save abort still leaves both the game and the record untouched. It
persists via
RunStorage.SaveAsyncrather thanSaveCurrentRun, since thelatter would re-stamp the live post-purchase instance numbers over the restored
ones; the identity maps are left for
AdoptRunLockedto rebuild.Side effect: combat restart is now exactly clean as well. Cards acquired
mid-combat commit immediately like shop purchases do, and the snapshot covers
that without enumerating every such path.
The snapshot is in memory, so a hot reload mid-room drops it and the row blocks
with
no room-entry snapshotuntil the next room re-arms it. Refusing a restartis cheap; silently inflating a run is not.
Notes
RunDatain the existing on-disk shape, so no new fixture orSchemaLoadingTestsassertion is needed.were not run in this session.