diff --git a/extensions/pixelhero-config-editor/esbuild.config.mjs b/extensions/pixelhero-config-editor/esbuild.config.mjs index 3d886b3b..034f4f75 100644 --- a/extensions/pixelhero-config-editor/esbuild.config.mjs +++ b/extensions/pixelhero-config-editor/esbuild.config.mjs @@ -11,9 +11,12 @@ const common = { alias: { 'vue': 'vue/dist/vue.esm-bundler.js' }, }; +// 面板进程在 Cocos 的 Electron 渲染层运行,可访问 Node 内建(fs/path),但 vue 必须 +// 打进浏览器侧 IIFE。因此面板项用 platform:'browser' + 把 node: 内建标为 external, +// 交由运行时解析;这样 esbuild 既不抱怨,又保持 plan 的"运行时读 static 文件"语义。 const entries = [ { entryPoints: ['src/main/index.ts'], outfile: 'dist/main.js', platform: 'node', format: 'cjs', external: [] }, - { entryPoints: ['src/panels/default/index.ts'], outfile: 'dist/panels/default.js', platform: 'browser', format: 'iife', external: [] }, + { entryPoints: ['src/panels/default/index.ts'], outfile: 'dist/panels/default.js', platform: 'browser', format: 'iife', external: ['node:fs', 'node:path'] }, ]; if (watch) { diff --git a/extensions/pixelhero-config-editor/src/main/index.ts b/extensions/pixelhero-config-editor/src/main/index.ts new file mode 100644 index 00000000..1db7d716 --- /dev/null +++ b/extensions/pixelhero-config-editor/src/main/index.ts @@ -0,0 +1,16 @@ +import { store } from './store'; + +module.exports = { + onLoad() { store.reloadAll(); }, + + 'open-panel'() { Editor.Panel.open('pixelhero-config-editor'); }, + + 'query-schema'(_event: unknown, id?: string) { return store.querySchema(id as any); }, + 'query-enums'() { return store.queryEnums(); }, + 'query-keys'(_event: unknown, id: string) { return store.queryKeys(id as any); }, + 'query-record'(_event: unknown, id: string, key: string) { return store.queryRecord(id as any, key); }, + 'query-preview-desc'(_event: unknown, hero: any) { return store.queryPreviewDesc(hero); }, + 'validate'(_event: unknown, id: string) { return store.validate(id as any); }, + 'save-record'(_event: unknown, id: string, key: string, value: any) { return store.saveRecord(id as any, key, value); }, + 'revert-record'(_event: unknown, id: string, key: string) { return store.revertRecord(id as any, key); }, +}; diff --git a/extensions/pixelhero-config-editor/src/panels/default/app.ts b/extensions/pixelhero-config-editor/src/panels/default/app.ts new file mode 100644 index 00000000..f17f4ce4 --- /dev/null +++ b/extensions/pixelhero-config-editor/src/panels/default/app.ts @@ -0,0 +1,38 @@ +import { createApp, defineComponent, reactive } from 'vue'; + +export const App = defineComponent({ + setup() { + const state = reactive({ table: 'hero' as string, keys: [] as string[], picked: '' as string, detail: '' as string }); + async function load() { + const keys = await Editor.Message.request('pixelhero-config-editor', 'query-keys', state.table); + state.keys = keys || []; + state.picked = ''; state.detail = ''; + } + async function pick(k: string) { + state.picked = k; + const v = await Editor.Message.request('pixelhero-config-editor', 'query-record', state.table, k); + state.detail = JSON.stringify(v, null, 2); + } + load(); + return { state, load, pick }; + }, + template: ` +
{{ state.detail }}
+