diff --git a/CocosCreatorInspector/img.png b/cc-inspector/doc/chrome-message.png similarity index 100% rename from CocosCreatorInspector/img.png rename to cc-inspector/doc/chrome-message.png diff --git a/cc-inspector/src/core/types.ts b/cc-inspector/src/core/types.ts index a4c2c00..ae06af6 100644 --- a/cc-inspector/src/core/types.ts +++ b/cc-inspector/src/core/types.ts @@ -8,22 +8,52 @@ export enum Page { } export enum Msg { - NodeInfo = "node-info",// 具体的节点信息 - TreeInfo = "tree-info",// 节点树信息 - Support = "game-support",// 游戏支持信息 + /** + * 具体的节点信息 + */ + NodeInfo = "node-info", + /** + * 节点树信息 + */ + TreeInfo = "tree-info", + /** + * 游戏支持信息 + */ + Support = "game-support",// MemoryInfo = "memory-info",// - TabsInfo = "tabs_info", // 当前页面信息 - GetTabID = "GetTabID", // 获取页面ID - UpdateFrames = "UpdateFrames", // 更新页面的frame + /** + * 当前页面信息 + */ + TabsInfo = "tabs_info", + /** + * 获取页面ID + */ + GetTabID = "GetTabID", + /** + * 更新页面的frame + */ + UpdateFrames = "UpdateFrames", UseFrame = "UseFrame", GetObjectItemData = "GetObjectItemData", LogData = "LogData", - SetProperty = "set-property", // 设置node属性 - UpdateProperty = "update-property", // 更新属性 + /** + * 设置node属性 + */ + SetProperty = "set-property", + /** + * 更新属性 + */ + UpdateProperty = "update-property", } export class PluginEvent { + /** + * 消息的类型 + */ msg: Msg | null = null; + /** + * 携带的数据 + */ data: any = null; /** diff --git a/cc-inspector/src/scripts/inject/index.ts b/cc-inspector/src/scripts/inject/index.ts index c757a54..2e7ab59 100644 --- a/cc-inspector/src/scripts/inject/index.ts +++ b/cc-inspector/src/scripts/inject/index.ts @@ -191,8 +191,8 @@ class CCInspector { // 收集节点信息 getNodeChildren(node: any, data: TreeData) { - data.uuid = node.uuid; - data.name = node.name; + data.id = node.uuid; + data.text = node.name; // @ts-ignore if (node instanceof cc.Scene) { // 场景不允许获取active,引擎会报错 diff --git a/cc-inspector/src/views/devtools/connectBackground.ts b/cc-inspector/src/views/devtools/connectBackground.ts index e372324..262ee85 100644 --- a/cc-inspector/src/views/devtools/connectBackground.ts +++ b/cc-inspector/src/views/devtools/connectBackground.ts @@ -1,5 +1,5 @@ import { Msg, Page, PluginEvent } from "../../core/types"; - +export type BackgroundCallback = (data: PluginEvent, sender: any) => void; class ConnectBackground { connect: chrome.runtime.Port | null = null; @@ -16,17 +16,25 @@ class ConnectBackground { }) } } - - onBackgroundMessage(cb: Function) { + /** + * 把callback保存为变量,方便测试 + */ + private callback: BackgroundCallback | null = null; + onBackgroundMessage(cb: BackgroundCallback) { + this.callback = cb; if (this.connect) { this.connect.onMessage.addListener((event, sender) => { cb && cb(event, sender) }); } } + testMessage(data: PluginEvent) { + if (this.callback) { + this.callback(data, null); + } + } sendMsgToContentScript(msg: Msg, data?: any) { if (!chrome || !chrome.devtools) { - console.log("环境异常,无法执行函数"); return; } this.postMessageToBackground(msg, data); diff --git a/cc-inspector/src/views/devtools/data.ts b/cc-inspector/src/views/devtools/data.ts index f74c090..ecec723 100644 --- a/cc-inspector/src/views/devtools/data.ts +++ b/cc-inspector/src/views/devtools/data.ts @@ -1,5 +1,5 @@ +import { ITreeData } from '@xuyanfeng/cc-ui/types/cc-tree/const'; import { v4 } from "uuid"; - export enum DataType { Number = 'Number', String = 'String', @@ -208,11 +208,11 @@ export class EnumData extends Info { } } -export class TreeData { +export class TreeData implements ITreeData { + id: string = ""; active: boolean = true; - uuid: string = ""; - name: string = ""; - children: Array = []; + text: string = ""; + children: TreeData[] = []; } export class Property { diff --git a/cc-inspector/src/views/devtools/index.vue b/cc-inspector/src/views/devtools/index.vue index 7657e41..17c4451 100644 --- a/cc-inspector/src/views/devtools/index.vue +++ b/cc-inspector/src/views/devtools/index.vue @@ -23,7 +23,7 @@
- +