From 94e0ea9c240a9abffa0448c9f8157735c5835af9 Mon Sep 17 00:00:00 2001 From: cocos02 Date: Sun, 14 Jun 2026 21:16:33 +0800 Subject: [PATCH] chore: NodeEditor.vue update --- editor/components/NodeEditor.vue | 34 +++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/editor/components/NodeEditor.vue b/editor/components/NodeEditor.vue index 3c3e22b..b7c35e3 100644 --- a/editor/components/NodeEditor.vue +++ b/editor/components/NodeEditor.vue @@ -18,19 +18,29 @@ const jsonText = ref('') const errorMsg = ref('') const saved = ref(false) -watch(() => props.scene, (s) => { - if (!s) { jsonText.value = ''; errorMsg.value = ''; return } - jsonText.value = JSON.stringify(s, null, 2) +watch(() => [props.scene, store.gameData] as const, () => { errorMsg.value = '' saved.value = false -}, { immediate: true }) + if (props.scene) { + jsonText.value = JSON.stringify(props.scene, null, 2) + } else if (Object.keys(store.gameData.scenes).length > 0) { + const { scenes, ...rest } = store.gameData + jsonText.value = JSON.stringify(rest, null, 2) + } else { + jsonText.value = '' + } +}, { immediate: true, deep: true }) function onBlur() { - if (!props.scene) return errorMsg.value = '' try { const parsed = JSON.parse(jsonText.value) - store.updateScene(props.scene.id, parsed) + if (props.scene) { + store.updateScene(props.scene.id, parsed) + } else { + const { scenes } = store.gameData + store.gameData = { ...parsed, scenes } + } saved.value = true setTimeout(() => { saved.value = false }, 2000) } catch (e: any) { @@ -40,14 +50,14 @@ function onBlur() {