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 ?? '')
|
return props.visitedIds.has(props.endings.find(e => e.id === endingId)?.sceneId ?? '')
|
||||||
}
|
}
|
||||||
|
|
||||||
function chaptersByProgress() {
|
function resolveInitialChapter(): string {
|
||||||
return [...props.chapters].sort((a, b) => {
|
const saved = localStorage.getItem('story_chapter')
|
||||||
const pa = chapterProgress(a.id).pct
|
if (saved && props.chapters.some(c => c.id === saved)) return saved
|
||||||
const pb = chapterProgress(b.id).pct
|
const first = props.chapters[0]
|
||||||
return pb - pa
|
return first?.id ?? ''
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultChapter = computed(() => {
|
const currentChapterId = ref(resolveInitialChapter())
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
function selectChapter(chapterId: string) {
|
function selectChapter(chapterId: string) {
|
||||||
if (!props.unlockedChapterIds.has(chapterId)) return
|
if (!props.unlockedChapterIds.has(chapterId)) return
|
||||||
currentChapterId.value = chapterId
|
currentChapterId.value = chapterId
|
||||||
|
localStorage.setItem('story_chapter', chapterId)
|
||||||
showChapterPicker.value = false
|
showChapterPicker.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +244,7 @@ const tree = computed(() => buildTreeForChapter(currentChapterId.value))
|
|||||||
<div class="picker-panel">
|
<div class="picker-panel">
|
||||||
<div class="picker-grid">
|
<div class="picker-grid">
|
||||||
<div
|
<div
|
||||||
v-for="ch in chaptersByProgress()"
|
v-for="ch in chapters"
|
||||||
:key="ch.id"
|
:key="ch.id"
|
||||||
class="picker-card"
|
class="picker-card"
|
||||||
:class="{ locked: !unlockedChapterIds.has(ch.id), active: ch.id === currentChapterId }"
|
:class="{ locked: !unlockedChapterIds.has(ch.id), active: ch.id === currentChapterId }"
|
||||||
|
|||||||
Reference in New Issue
Block a user