Fix autosave resume choice restoration

This commit is contained in:
2026-05-19 15:44:40 +02:00
parent 90f81ee1b7
commit 256cc2c7a7
+29 -7
View File
@@ -43,6 +43,8 @@ class GameLoopModule extends BaseModule {
'queueUnrenderedHistoryBlocks', 'queueUnrenderedHistoryBlocks',
'autoSaveCurrentSession', 'autoSaveCurrentSession',
'restoreBrowserSave', 'restoreBrowserSave',
'restoreInputStateFromSave',
'hasUnrenderedHistory',
'resumeAutosaveIfAvailable', 'resumeAutosaveIfAvailable',
'requestStartGame', 'requestStartGame',
'requestSaveGame', 'requestSaveGame',
@@ -214,17 +216,14 @@ class GameLoopModule extends BaseModule {
return false; return false;
} }
await this.restoreBrowserSave(browserSave, 'autosave-resume', { resetDisplay: true });
this.gameState.started = Boolean(response.running); this.gameState.started = Boolean(response.running);
this.gameState.startedOnce = true; this.gameState.startedOnce = true;
this.gameState.ended = !response.running && browserSave.inputMode === 'end'; this.gameState.ended = !response.running && browserSave.inputMode === 'end';
this.gameState.canSave = this.gameState.started; this.gameState.canSave = this.gameState.started;
this.gameState.canLoad = true; this.gameState.canLoad = true;
this.currentChoices = Array.isArray(browserSave.choices) ? browserSave.choices : [];
this.currentInputMode = browserSave.inputMode || 'none';
document.dispatchEvent(new CustomEvent('story:choices', { detail: this.currentChoices }));
document.dispatchEvent(new CustomEvent('story:input-mode', { detail: this.currentInputMode }));
this.updateUIState(); this.updateUIState();
await this.restoreBrowserSave(browserSave, 'autosave-resume', { resetDisplay: true });
this.restoreInputStateFromSave(browserSave, 'autosave-resume');
return true; return true;
} }
@@ -393,8 +392,7 @@ class GameLoopModule extends BaseModule {
if (browserSave?.musicState && audioManager?.restoreMusicState) { if (browserSave?.musicState && audioManager?.restoreMusicState) {
await audioManager.restoreMusicState(browserSave.musicState); await audioManager.restoreMusicState(browserSave.musicState);
} }
const hasUnrenderedHistory = browserSave && const hasUnrenderedHistory = this.hasUnrenderedHistory(browserSave);
Number(browserSave.latestBlockId || 0) > Number(browserSave.latestRenderedBlockId || 0);
if (hasUnrenderedHistory) { if (hasUnrenderedHistory) {
const sentenceQueue = this.getModule('sentence-queue'); const sentenceQueue = this.getModule('sentence-queue');
sentenceQueue?.pauseBeforeNext?.('load-resume'); sentenceQueue?.pauseBeforeNext?.('load-resume');
@@ -420,6 +418,30 @@ class GameLoopModule extends BaseModule {
} }
} }
restoreInputStateFromSave(browserSave, reason = 'load-game') {
const choices = Array.isArray(browserSave?.choices) ? browserSave.choices : [];
const savedMode = ['text', 'choice', 'end', 'none'].includes(browserSave?.inputMode)
? browserSave.inputMode
: null;
const inputMode = savedMode || (choices.length > 0 ? 'choice' : 'none');
this.currentChoices = choices;
this.currentInputMode = inputMode;
document.dispatchEvent(new CustomEvent('story:choices', { detail: choices }));
document.dispatchEvent(new CustomEvent('story:input-mode', { detail: inputMode }));
if (!this.hasUnrenderedHistory(browserSave)) {
document.dispatchEvent(new CustomEvent('story:process-state', {
detail: { state: 'ready', reason: `${reason}-input-restored`, inputMode }
}));
}
}
hasUnrenderedHistory(browserSave) {
return Boolean(browserSave) &&
Number(browserSave.latestBlockId || 0) > Number(browserSave.latestRenderedBlockId || 0);
}
async hasSaveGame(slot = 1) { async hasSaveGame(slot = 1) {
const storyHistory = this.getModule('story-history'); const storyHistory = this.getModule('story-history');
if (storyHistory && typeof storyHistory.hasSaveSlot === 'function') { if (storyHistory && typeof storyHistory.hasSaveSlot === 'function') {