diff --git a/src/components/StoryGallery.vue b/src/components/StoryGallery.vue index ed8a705..2d694aa 100644 --- a/src/components/StoryGallery.vue +++ b/src/components/StoryGallery.vue @@ -109,31 +109,19 @@ function endingStatus(endingId: string) { return props.visitedIds.has(props.endings.find(e => e.id === endingId)?.sceneId ?? '') } -function chaptersByProgress() { - return [...props.chapters].sort((a, b) => { - const pa = chapterProgress(a.id).pct - const pb = chapterProgress(b.id).pct - return pb - pa - }) +function resolveInitialChapter(): string { + const saved = localStorage.getItem('story_chapter') + if (saved && props.chapters.some(c => c.id === saved)) return saved + const first = props.chapters[0] + return first?.id ?? '' } -const defaultChapter = computed(() => { - const sorted = chaptersByProgress() - for (const ch of sorted) { - if (chapterProgress(ch.id).pct > 0) return ch - } - return sorted[0] ?? null -}) - -const currentChapterId = ref('') - -if (defaultChapter.value) { - currentChapterId.value = defaultChapter.value.id -} +const currentChapterId = ref(resolveInitialChapter()) function selectChapter(chapterId: string) { if (!props.unlockedChapterIds.has(chapterId)) return currentChapterId.value = chapterId + localStorage.setItem('story_chapter', chapterId) showChapterPicker.value = false } @@ -256,7 +244,7 @@ const tree = computed(() => buildTreeForChapter(currentChapterId.value))