fix: chapter list follows JSON order, remember last selected chapter
This commit is contained in:
@@ -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<string>('')
|
||||
|
||||
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))
|
||||
<div class="picker-panel">
|
||||
<div class="picker-grid">
|
||||
<div
|
||||
v-for="ch in chaptersByProgress()"
|
||||
v-for="ch in chapters"
|
||||
:key="ch.id"
|
||||
class="picker-card"
|
||||
:class="{ locked: !unlockedChapterIds.has(ch.id), active: ch.id === currentChapterId }"
|
||||
|
||||
Reference in New Issue
Block a user