chore: editor store, graph, and vite config updates

This commit is contained in:
2026-06-14 20:38:12 +08:00
parent 48da10147b
commit 59f6956b50
4 changed files with 49 additions and 2 deletions

View File

@@ -49,7 +49,7 @@ function importJSON() {
}
function testScene(id: string) {
window.open('/?scene=/scenes/demo.json&startScene=' + id, '_blank')
window.open('/?scene=' + store.sourcePath + '&startScene=' + id, '_blank')
}
async function onFileSelected(e: Event) {

View File

@@ -18,6 +18,7 @@ export function useGraphEditor() {
scenes: { ...store.gameData.scenes, [source]: { ...scene, choices: newChoices } },
}
store.markDirty()
store.autoSave()
}
return {

View File

@@ -7,6 +7,7 @@ export const useEditorStore = defineStore('editor', () => {
const selectedNodeId = ref<string | null>(null)
const startSceneId = ref('')
const dirty = ref(false)
const sourcePath = ref('/scenes/demo.json')
const selectedScene = computed(() => {
if (!selectedNodeId.value) return null
@@ -44,6 +45,7 @@ export const useEditorStore = defineStore('editor', () => {
}
triggerRef(gameData)
dirty.value = true
autoSave()
return id
}
@@ -71,6 +73,7 @@ export const useEditorStore = defineStore('editor', () => {
triggerRef(gameData)
dirty.value = true
if (selectedNodeId.value === id) selectedNodeId.value = null
autoSave()
}
function updateScene(id: string, partial: Partial<SceneNode>) {
@@ -82,6 +85,7 @@ export const useEditorStore = defineStore('editor', () => {
}
triggerRef(gameData)
dirty.value = true
autoSave()
}
function addChoice(sourceId: string) {
@@ -96,6 +100,7 @@ export const useEditorStore = defineStore('editor', () => {
}
triggerRef(gameData)
dirty.value = true
autoSave()
}
function updateChoice(sourceId: string, index: number, partial: Partial<Choice>) {
@@ -108,6 +113,7 @@ export const useEditorStore = defineStore('editor', () => {
}
triggerRef(gameData)
dirty.value = true
autoSave()
}
function deleteChoice(sourceId: string, index: number) {
@@ -124,9 +130,22 @@ export const useEditorStore = defineStore('editor', () => {
dirty.value = true
}
function setSourcePath(p: string) { sourcePath.value = p }
async function autoSave() {
try {
await fetch('/api/save', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path: sourcePath.value, data: gameData.value }),
})
} catch { /* dev server not running */ }
}
return {
gameData, selectedNodeId, selectedScene, startSceneId, dirty,
gameData, selectedNodeId, selectedScene, startSceneId, dirty, sourcePath,
markDirty, loadJSON, exportJSON, addScene, deleteScene,
updateScene, addChoice, updateChoice, deleteChoice, generateId,
setSourcePath, autoSave,
}
})