Add storage-backed story history

This commit is contained in:
2026-05-15 21:58:30 +02:00
parent f2e786d5bc
commit 42582352d6
16 changed files with 1048 additions and 113 deletions
+18 -2
View File
@@ -83,11 +83,27 @@ class InkEngine {
if (!this.story) {
throw new Error('No active Ink story to save');
}
return this.story.state.toJson();
return JSON.stringify({
inkState: this.story.state.toJson(),
nextTurnId: this.nextTurnId,
});
}
loadGame(savedState) {
this.story = this.loadStory();
this.story.state.LoadJson(savedState);
let inkState = savedState;
try {
const parsed = JSON.parse(savedState);
if (parsed && typeof parsed.inkState === 'string') {
inkState = parsed.inkState;
if (Number.isInteger(parsed.nextTurnId)) {
this.nextTurnId = Math.max(1, parsed.nextTurnId);
}
}
}
catch {
// Backward compatibility with raw Ink state JSON.
}
this.story.state.LoadJson(inkState);
return this.continueStory();
}
loadStory() {
+1 -1
View File
File diff suppressed because one or more lines are too long