feat: auto-save on scene change + resume from auto-save

- useGameEngine: auto-save to slot 0 on every sceneChange event
- useGameEngine: add resumeAutoSave() for continuing from auto-save
- useGameEngine: extract registerEvents() to share between start and resume
- SaveLoadMenu: show slot 0 as '自动存档' with distinct styling and read-only button
- App.vue: check auto-save on load, show '继续上次进度' button if available
This commit is contained in:
2026-06-07 18:42:34 +08:00
parent 2de9f99a81
commit c61826e87c
3 changed files with 56 additions and 6 deletions

View File

@@ -20,14 +20,12 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide
engine.stateManager.init(data.variables)
}
function start() {
const [elA, elB] = videoEls()
engine.videoManager.attach(elA!, elB!)
function registerEvents() {
engine.on('sceneChange', (scene) => {
store.setScene(scene)
store.clearChoices()
store.clearTimer()
saveGame(0)
})
engine.on('choiceRequest', (choiceList) => {
@@ -49,10 +47,22 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide
store.setGameEnded(true)
engine.choiceSystem.stop()
})
}
function start() {
const [elA, elB] = videoEls()
engine.videoManager.attach(elA!, elB!)
registerEvents()
engine.start()
}
async function resumeAutoSave(): Promise<boolean> {
const [elA, elB] = videoEls()
engine.videoManager.attach(elA!, elB!)
registerEvents()
return await loadGameFromSlot(0)
}
function makeChoice(index: number) {
const scene = store.currentScene
if (!scene?.choices) return
@@ -99,5 +109,5 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide
destroy()
})
return { loadGame, start, makeChoice, saveGame, loadGameFromSlot, refreshSaves, engine, saveSystem }
return { loadGame, start, resumeAutoSave, makeChoice, saveGame, loadGameFromSlot, refreshSaves, engine, saveSystem }
}