fix(config-editor): main entry exports methods object + load/unload (Cocos 3.8)

Root cause of 'Method does not exist / The methods of the module is undefined':
Cocos 3.8 expects handlers inside a 'methods' export (plus load/unload hooks),
not flat on module.exports. Handlers receive args directly (no event); return
value is the request reply. Verified vs official 3.8 first/messages docs.
Also: menu path + panel title switched to literal strings (i18n showed 'undefined').
This commit is contained in:
panFD
2026-06-21 16:30:39 +08:00
parent fb65fa79c8
commit bfa434634c
2 changed files with 47 additions and 15 deletions

View File

@@ -2,7 +2,7 @@
"package_version": 2, "package_version": 2,
"name": "pixelhero-config-editor", "name": "pixelhero-config-editor",
"version": "0.1.0", "version": "0.1.0",
"description": "i18n:pixelhero-config-editor.description", "description": "英雄/技能配置编辑器",
"main": "./dist/main.js", "main": "./dist/main.js",
"author": "pixelhero", "author": "pixelhero",
"editor": ">=3.8.0", "editor": ">=3.8.0",
@@ -13,7 +13,7 @@
}, },
"panels": { "panels": {
"default": { "default": {
"title": "i18n:pixelhero-config-editor.title", "title": "英雄/技能配置",
"type": "dockable", "type": "dockable",
"main": "./dist/panels/default.js", "main": "./dist/panels/default.js",
"size": { "width": 960, "height": 640, "min-width": 640, "min-height": 480 } "size": { "width": 960, "height": 640, "min-width": 640, "min-height": 480 }
@@ -21,7 +21,7 @@
}, },
"contributions": { "contributions": {
"menu": [ "menu": [
{ "path": "i18n:menu.panel/英雄技能配置", "message": "open-panel" } { "path": "PixelHero/英雄技能配置", "message": "open-panel" }
], ],
"messages": { "messages": {
"open-panel": { "methods": ["open-panel"] }, "open-panel": { "methods": ["open-panel"] },

View File

@@ -1,16 +1,48 @@
import { store } from './store'; 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'); }, const methods: Record<string, (...args: any[]) => any> = {
'open-panel'() {
'query-schema'(_event: unknown, id?: string) { return store.querySchema(id as any); }, Editor.Panel.open('pixelhero-config-editor');
'query-enums'() { return store.queryEnums(); }, },
'query-keys'(_event: unknown, id: string) { return store.queryKeys(id as any); }, 'query-schema'(id?: string) {
'query-record'(_event: unknown, id: string, key: string) { return store.queryRecord(id as any, key); }, return store.querySchema(id as any);
'query-preview-desc'(_event: unknown, hero: any) { return store.queryPreviewDesc(hero); }, },
'validate'(_event: unknown, id: string) { return store.validate(id as any); }, 'query-enums'() {
'save-record'(_event: unknown, id: string, key: string, value: any) { return store.saveRecord(id as any, key, value); }, return store.queryEnums();
'revert-record'(_event: unknown, id: string, key: string) { return store.revertRecord(id as any, key); }, },
'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 };