diff --git a/editor/stores/editorStore.ts b/editor/stores/editorStore.ts index c72f9c1..8f49277 100644 --- a/editor/stores/editorStore.ts +++ b/editor/stores/editorStore.ts @@ -161,6 +161,19 @@ export const useEditorStore = defineStore('editor', () => { function clearAISession() { aiSessionId.value = ''; localStorage.removeItem('editor_ai_session') } + let saveVersionTimer: ReturnType | null = null + let lastSavedContent = '' + + function debouncedSaveVersion() { + const current = JSON.stringify(gameData.value) + if (current === lastSavedContent) return + if (saveVersionTimer) clearTimeout(saveVersionTimer) + saveVersionTimer = setTimeout(async () => { + lastSavedContent = current + await saveVersion('手动编辑') + }, 3000) + } + async function autoSave() { try { await fetch('/api/save', { @@ -169,6 +182,7 @@ export const useEditorStore = defineStore('editor', () => { body: JSON.stringify({ path: sourcePath.value, data: gameData.value }), }) } catch { /* dev server not running */ } + debouncedSaveVersion() } async function saveVersion(label: string) {