Files
pixelheros/extensions/pixelhero-config-editor/src/main/index.ts
panFD bfa434634c 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').
2026-06-21 16:30:39 +08:00

49 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { store } from './store';
/**
* 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() {
// 进程级单例随扩展卸载自然销毁,无需显式清理。
}
const methods: Record<string, (...args: any[]) => 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 };