diff --git a/src/components/StoryGallery.vue b/src/components/StoryGallery.vue index 7720168..720dc56 100644 --- a/src/components/StoryGallery.vue +++ b/src/components/StoryGallery.vue @@ -22,34 +22,6 @@ const emit = defineEmits<{ const showChapterPicker = ref(false) -function chaptersByProgress() { - return [...props.chapters].sort((a, b) => { - const pa = chapterProgress(a.id).pct - const pb = chapterProgress(b.id).pct - return pb - pa - }) -} - -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 -} - -function selectChapter(chapterId: string) { - if (!props.unlockedChapterIds.has(chapterId)) return - currentChapterId.value = chapterId - showChapterPicker.value = false -} - function collectReachable(startId: string): Set { const visited = new Set() const queue = [startId] @@ -94,10 +66,6 @@ const chapterEndings = computed(() => { return result }) -function endingStatus(endingId: string) { - return props.visitedIds.has(props.endings.find(e => e.id === endingId)?.sceneId ?? '') -} - function chapterProgress(chapterId: string) { const reachable = chapterReachable.value[chapterId] if (!reachable || reachable.size === 0) return { count: 0, total: 0, pct: 0 } @@ -128,6 +96,38 @@ function lockHint(sceneId: string): string { return '' } +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 + }) +} + +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 +} + +function selectChapter(chapterId: string) { + if (!props.unlockedChapterIds.has(chapterId)) return + currentChapterId.value = chapterId + showChapterPicker.value = false +} + function buildPlayerTree(sceneId: string, depth: number, pathSet: Set): PlayerTreeNode | null { if (depth > 10) return null if (pathSet.has(sceneId)) return null