diff --git a/extensions/pixelhero-config-editor/package.json b/extensions/pixelhero-config-editor/package.json index b66181fb..8be767e8 100644 --- a/extensions/pixelhero-config-editor/package.json +++ b/extensions/pixelhero-config-editor/package.json @@ -2,7 +2,7 @@ "package_version": 2, "name": "pixelhero-config-editor", "version": "0.1.0", - "description": "i18n:pixelhero-config-editor.description", + "description": "英雄/技能配置编辑器", "main": "./dist/main.js", "author": "pixelhero", "editor": ">=3.8.0", @@ -13,7 +13,7 @@ }, "panels": { "default": { - "title": "i18n:pixelhero-config-editor.title", + "title": "英雄/技能配置", "type": "dockable", "main": "./dist/panels/default.js", "size": { "width": 960, "height": 640, "min-width": 640, "min-height": 480 } @@ -21,7 +21,7 @@ }, "contributions": { "menu": [ - { "path": "i18n:menu.panel/英雄技能配置", "message": "open-panel" } + { "path": "PixelHero/英雄技能配置", "message": "open-panel" } ], "messages": { "open-panel": { "methods": ["open-panel"] }, diff --git a/extensions/pixelhero-config-editor/src/main/index.ts b/extensions/pixelhero-config-editor/src/main/index.ts index 1db7d716..797efba4 100644 --- a/extensions/pixelhero-config-editor/src/main/index.ts +++ b/extensions/pixelhero-config-editor/src/main/index.ts @@ -1,16 +1,48 @@ import { store } from './store'; -module.exports = { - onLoad() { store.reloadAll(); }, +/** + * Cocos Creator 3.8 扩展主进程入口。 + * 关键约定(与官方 first/message 文档一致): + * - 处理函数必须挂在 `methods` 对象里(Cocos 读取 module.exports.methods), + * methods 的 key 必须与 package.json 中 contributions.messages[*].methods 引用的名字一致。 + * - 生命周期钩子为 `load`/`unload`(不是 onLoad)。 + * - 处理函数直接接收消息参数(无 event),返回值即 Editor.Message.request 的 resolve 结果。 + */ +function load() { + store.reloadAll(); +} +function unload() { + // 进程级单例随扩展卸载自然销毁,无需显式清理。 +} - '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); }, +const methods: Record any> = { + 'open-panel'() { + Editor.Panel.open('pixelhero-config-editor'); + }, + 'query-schema'(id?: string) { + return store.querySchema(id as any); + }, + 'query-enums'() { + return store.queryEnums(); + }, + 'query-keys'(id: string) { + return store.queryKeys(id as any); + }, + 'query-record'(id: string, key: string) { + return store.queryRecord(id as any, key); + }, + 'query-preview-desc'(hero: any) { + return store.queryPreviewDesc(hero); + }, + 'validate'(id: string) { + return store.validate(id as any); + }, + 'save-record'(id: string, key: string, value: any) { + return store.saveRecord(id as any, key, value); + }, + 'revert-record'(id: string, key: string) { + return store.revertRecord(id as any, key); + }, }; + +module.exports = { methods, load, unload };