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

@@ -12,13 +12,15 @@ const videoElB = ref<HTMLVideoElement | null>(null)
const loading = ref(true)
const started = ref(false)
const showMenu = ref(false)
const hasAutoSave = ref(false)
const { loadGame, start, makeChoice, saveGame, loadGameFromSlot, refreshSaves } =
const { loadGame, start, resumeAutoSave, makeChoice, saveGame, loadGameFromSlot, refreshSaves, saveSystem } =
useGameEngine(() => [videoElA.value, videoElB.value])
async function init() {
await loadGame('/scenes/demo.json')
loading.value = false
hasAutoSave.value = (await saveSystem.load(0)) !== null
}
function handleStart() {
@@ -26,6 +28,11 @@ function handleStart() {
start()
}
async function handleResume() {
started.value = true
await resumeAutoSave()
}
function onVideoReady(elA: HTMLVideoElement, elB: HTMLVideoElement) {
videoElA.value = elA
videoElB.value = elB
@@ -72,6 +79,7 @@ init()
</div>
<div v-if="!started" class="start-overlay">
<button class="start-btn" @click="handleStart">开始游戏</button>
<button v-if="hasAutoSave" class="start-btn resume-btn" @click="handleResume">继续上次进度</button>
</div>
<div v-if="store.gameEnded" class="game-end-overlay">
<div class="game-end-text">游戏结束</div>
@@ -190,4 +198,10 @@ html, body {
.start-btn:hover {
background: rgba(255, 255, 255, 0.25);
}
.resume-btn {
margin-top: 16px;
border-color: rgba(100, 200, 255, 0.3);
color: #8cf;
}
</style>