refactor: simplify AI panel workflow - direct file modification and reload from disk
This commit is contained in:
@@ -10,7 +10,6 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
const sourcePath = ref('/scenes/demo.json')
|
||||
const deepseekKey = ref(localStorage.getItem('deepseek_key') || '')
|
||||
const showAIPanel = ref(false)
|
||||
const aiResult = ref('')
|
||||
const aiSessionId = ref('')
|
||||
|
||||
const selectedScene = computed(() => {
|
||||
@@ -142,8 +141,6 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
|
||||
function clearAISession() { aiSessionId.value = ''; localStorage.removeItem('editor_ai_session') }
|
||||
|
||||
function setAIResult(r: string) { aiResult.value = r }
|
||||
|
||||
async function autoSave() {
|
||||
try {
|
||||
await fetch('/api/save', {
|
||||
@@ -154,11 +151,21 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
} catch { /* dev server not running */ }
|
||||
}
|
||||
|
||||
async function reloadFromDisk() {
|
||||
try {
|
||||
const resp = await fetch(sourcePath.value)
|
||||
const data = await resp.json()
|
||||
gameData.value = data
|
||||
selectedNodeId.value = null
|
||||
clearAISession()
|
||||
} catch { /* failed to reload */ }
|
||||
}
|
||||
|
||||
return {
|
||||
gameData, selectedNodeId, selectedScene, startSceneId, dirty, sourcePath,
|
||||
deepseekKey, showAIPanel, aiResult, aiSessionId,
|
||||
deepseekKey, showAIPanel, aiSessionId,
|
||||
markDirty, loadJSON, exportJSON, addScene, deleteScene,
|
||||
updateScene, addChoice, updateChoice, deleteChoice, generateId,
|
||||
setSourcePath, setDeepseekKey, setAISessionId, clearAISession, setAIResult, autoSave,
|
||||
setSourcePath, setDeepseekKey, setAISessionId, clearAISession, autoSave, reloadFromDisk,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user