Engine state rewind via replay, not snapshot
The story-maker's preview tab supports clicking a history breadcrumb to rewind to that scene. The implementation creates a fresh Engine instance and replays engine.start() then engine.processCommand(choice) for each prior choice up to (but not including) the target index. The resulting EngineResponse becomes the current state.
Why replay over snapshot:
GameStatekeeps growing (variables, completedEvents, unlockedConversations, scene fields, …). A snapshot/restore approach would silently drift out of sync as the engine adds new state fields — the snapshot would miss them and rewinds would produce stale results.- Replay is correct-by-construction: it uses the same code path as live play, so any state the live engine produces, the replayed engine produces. Adding a new state field requires no rewind-side change.
- Trade-off: replay is O(history-length) per rewind. Acceptable for editor preview (history is short, choices are cheap). For runtime undo in a long game this could matter — but that's not the use case here.
How to apply:
- Any future "jump to past scene", "branch from here", or "what-if" preview feature: replay from start, don't try to snapshot/clone the engine.
- The
Engineconstructor +start()+processCommand()are sufficient to reach any state — keep them deterministic so replay stays correct. - If we ever need fast scrubbing for very long histories, consider memoizing engine snapshots alongside the choice list, but always treat replay as the source of truth.