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
+25 -1
View File
@@ -21,6 +21,8 @@ class SentenceQueueModule extends BaseModule {
this.prefetchingCache = new Map();
this.activeImageWrap = null;
this.autoplay = true;
this.inputMode = 'text';
this.lastContinueAt = 0;
// Bind methods
this.bindMethods([
@@ -79,6 +81,14 @@ class SentenceQueueModule extends BaseModule {
this.autoplay = value !== false;
}
});
this.addEventListener(document, 'story:input-mode', (event) => {
this.inputMode = ['text', 'choice', 'end'].includes(event.detail) ? event.detail : 'text';
});
this.addEventListener(document, 'ui:command', (event) => {
if (event.detail?.type === 'continue') {
this.lastContinueAt = performance.now();
}
});
return true;
} catch (error) {
console.error("Error initializing Sentence Queue:", error);
@@ -139,6 +149,7 @@ class SentenceQueueModule extends BaseModule {
if (this.onSentenceReadyCallback) {
await new Promise(resolve => {
sentence.onComplete = resolve;
sentence.playbackStartedAt = performance.now();
this.onSentenceReadyCallback(sentence, resolve);
});
}
@@ -148,7 +159,7 @@ class SentenceQueueModule extends BaseModule {
await this.waitForSkippableMediaPause(mediaPauseSeconds, sentence.kind, sentence.id);
}
if (sentence.kind === 'paragraph' && !this.shouldAutoplay()) {
if (this.shouldPauseAfterSentence(sentence)) {
await this.waitForManualContinue(sentence.id);
}
@@ -495,6 +506,19 @@ class SentenceQueueModule extends BaseModule {
}
}
shouldPauseAfterSentence(sentence) {
if (sentence.kind !== 'paragraph' || this.shouldAutoplay()) {
return false;
}
if (this.lastContinueAt >= (sentence.playbackStartedAt || 0)) {
return false;
}
if (this.sentenceQueue.length <= 1 && this.inputMode === 'choice') {
return false;
}
return this.sentenceQueue.length > 1;
}
shouldAutoplay() {
const persistenceManager = this.getModule('persistence-manager');
if (persistenceManager && typeof persistenceManager.getPreference === 'function') {