feat: chapter select system, multi-chapter support, scene manager refactor, and docs update
This commit is contained in:
@@ -20,9 +20,18 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide
|
||||
const data: GameData = await resp.json()
|
||||
engine.sceneManager.load(data)
|
||||
engine.stateManager.init(data.variables)
|
||||
store.setChapters(data.chapters || [])
|
||||
|
||||
const unlocked = await saveSystem.getUnlockedChapters()
|
||||
store.setUnlockedChapters(unlocked)
|
||||
}
|
||||
|
||||
function registerEvents() {
|
||||
engine.setChapterUnlockHandler(async (chapterId) => {
|
||||
await saveSystem.unlockChapter(chapterId)
|
||||
store.addUnlockedChapter(chapterId)
|
||||
})
|
||||
|
||||
engine.on('sceneChange', (scene) => {
|
||||
store.setScene(scene)
|
||||
store.clearChoices()
|
||||
@@ -122,6 +131,13 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide
|
||||
}
|
||||
}
|
||||
|
||||
function startChapter(chapterId: string) {
|
||||
const [elA, elB] = videoEls()
|
||||
if (elA && elB) engine.videoManager.attach(elA, elB)
|
||||
store.setGameEnded(false)
|
||||
engine.startChapter(chapterId)
|
||||
}
|
||||
|
||||
async function saveGame(slot: number) {
|
||||
const state = engine.stateManager
|
||||
const currentScene = store.currentScene
|
||||
@@ -163,5 +179,6 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide
|
||||
destroy()
|
||||
})
|
||||
|
||||
return { loadGame, start, resumeAutoSave, makeChoice, clickHotspot, saveGame, loadGameFromSlot, refreshSaves, engine, saveSystem }
|
||||
return { loadGame, start, resumeAutoSave, makeChoice, clickHotspot, startChapter,
|
||||
saveGame, loadGameFromSlot, refreshSaves, engine, saveSystem }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user