From bb657b3547ec499eef0d1cefa5539d815badce55 Mon Sep 17 00:00:00 2001 From: cocos02 Date: Sun, 7 Jun 2026 21:11:18 +0800 Subject: [PATCH] fix: capture save thumbnail on videoEnd instead of sceneChange Previously thumbnail was captured during sceneChange (before video starts playing), so readyState was low and capture was skipped. Now capture on videoEnd when frame is guaranteed visible, store in lastThumbnail, and reuse for both auto-save (slot 0) and manual save. --- src/composables/useGameEngine.ts | 35 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/composables/useGameEngine.ts b/src/composables/useGameEngine.ts index e35d7ab..f396292 100644 --- a/src/composables/useGameEngine.ts +++ b/src/composables/useGameEngine.ts @@ -8,6 +8,7 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide const engine = new Engine() const saveSystem = new SaveSystem() const store = useGameStore() + let lastThumbnail: string | undefined if (import.meta.env.DEV) { ;(window as any).__sm = engine.stateManager @@ -42,7 +43,21 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide store.clearTimer() }) - engine.on('videoEnd', () => {}) + engine.on('videoEnd', () => { + try { + const video = engine.videoManager.getActiveVideoElement() + if (video && video.readyState >= 2) { + const canvas = document.createElement('canvas') + canvas.width = 320 + canvas.height = 180 + const ctx = canvas.getContext('2d') + if (ctx) { + ctx.drawImage(video, 0, 0, 320, 180) + lastThumbnail = canvas.toDataURL('image/jpeg', 0.6) + } + } + } catch { /* ignore */ } + }) engine.on('gameEnd', () => { store.setGameEnded(true) @@ -92,29 +107,13 @@ export function useGameEngine(videoEls: () => [HTMLVideoElement | null, HTMLVide const state = engine.stateManager const currentScene = store.currentScene - // Capture thumbnail from active video - let thumbnail: string | undefined - try { - const video = engine.videoManager.getActiveVideoElement() - if (video && video.readyState >= 2) { - const canvas = document.createElement('canvas') - canvas.width = 320 - canvas.height = 180 - const ctx = canvas.getContext('2d') - if (ctx) { - ctx.drawImage(video, 0, 0, 320, 180) - thumbnail = canvas.toDataURL('image/jpeg', 0.6) - } - } - } catch { /* ignore canvas errors */ } - await saveSystem.save(slot, { timestamp: Date.now(), currentScene: currentScene?.id ?? '', variables: state.variables, flags: [...state.flags], history: state.history, - thumbnail, + thumbnail: lastThumbnail, }) await refreshSaves() }