diff --git a/source/src/devtools/inject.ts b/source/src/inject/index.ts similarity index 94% rename from source/src/devtools/inject.ts rename to source/src/inject/index.ts index 590c8be..da70556 100644 --- a/source/src/devtools/inject.ts +++ b/source/src/inject/index.ts @@ -14,13 +14,12 @@ import { TreeData, Vec2Data, Vec3Data -} from "./data"; +} from "@/devtools/data"; import {Msg, Page, PluginEvent} from "@/core/types" +import {BuildDataOptions, BuildImageOptions, BuildVecOptions} from "@/inject/types"; + +declare var cc: any; -// @ts-ignore typescript-eslint/no-namespace -declare namespace cc { - export function v2(x: number, y: number): any; -} class CCInspector { inspectorGameMemoryStorage: Record = {} @@ -207,7 +206,7 @@ class CCInspector { return null; } - _buildVecData(options: any) { + _buildVecData(options: BuildVecOptions) { const ctor: Function = options.ctor; const keys: Array = options.keys; const value: Object = options.value; @@ -233,7 +232,7 @@ class CCInspector { return null; } - _buildImageData(options: any) { + _buildImageData(options: BuildImageOptions) { const ctor: Function = options.ctor; const value: Object = options.value; const data: ImageData = options.data; @@ -249,7 +248,7 @@ class CCInspector { return null; } - _genInfoData(node: any, key: string, path: Array) { + _genInfoData(node: any, key: string | number, path: Array) { let propertyValue = node[key]; let info = null; switch (typeof propertyValue) { @@ -270,11 +269,11 @@ class CCInspector { let hex = propertyValue.toHEX(); info = new ColorData(`#${hex}`); } else if (Array.isArray(propertyValue)) { - let keys = []; + let keys: number[] = []; for (let i = 0; i < propertyValue.length; i++) { keys.push(i); } - info = this._buildObjectOrArrayData({ + info = this._buildArrayData({ data: new ArrayData(), path: path, value: propertyValue, @@ -313,7 +312,7 @@ class CCInspector { info.engineName = propertyValue.name; info.engineUUID = propertyValue.uuid; } else { - info = this._buildObjectOrArrayData({ + info = this._buildObjectData({ data: new ObjectData(), path: path, value: propertyValue, @@ -334,11 +333,20 @@ class CCInspector { return info; } - _buildObjectOrArrayData(options: any) { + _buildArrayData(options: BuildDataOptions) { + return this._buildObjectOrArrayData(options); + } + + _buildObjectData(options: BuildDataOptions) { + // todo 只返回一级key,更深层级的key需要的时候,再获取,防止circle object导致的死循环 + + } + + _buildObjectOrArrayData(options: BuildDataOptions) { let propertyValue: Object = options.value; let path: Array = options.path; let data: ObjectData | ArrayData = options.data; - let keys: Array = options.keys; + let keys: Array = options.keys; // 剔除_开头的属性 keys = keys.filter(key => !key.toString().startsWith("_")); for (let i = 0; i < keys.length; i++) { @@ -423,7 +431,7 @@ class CCInspector { return nodeGroup; } - // 获取节点信息 + // 获取节点信息,只获取一级key即可,后续 getNodeInfo(uuid: string) { let node = this.inspectorGameMemoryStorage[uuid]; if (node) { @@ -453,7 +461,7 @@ class CCInspector { } } - _isReadonly(base: Object, key: string): boolean { + _isReadonly(base: Object, key: string | number): boolean { let ret = Object.getOwnPropertyDescriptor(base, key) if (ret) { return !(ret.set || ret.writable); diff --git a/source/src/inject/types.ts b/source/src/inject/types.ts new file mode 100644 index 0000000..0d9fdf2 --- /dev/null +++ b/source/src/inject/types.ts @@ -0,0 +1,23 @@ +import {ArrayData, ImageData, ObjectData, Vec2Data, Vec3Data} from "@/devtools/data"; + +export interface BuildDataOptions { + path: string[]; + value: Object; + data: ObjectData | ArrayData; + keys: string[] | number[]; +} + +export interface BuildVecOptions { + path: string[]; + keys: string[]; + ctor: Function; + value: Object; + data: Vec3Data | Vec2Data; +} + +export interface BuildImageOptions { + path: string[]; + ctor: Function; + value: Object; + data: ImageData; +} diff --git a/source/vue.config.js b/source/vue.config.js index 22d0966..e334c7c 100644 --- a/source/vue.config.js +++ b/source/vue.config.js @@ -18,7 +18,7 @@ module.exports = { contentScripts: { entries: { content: "src/content.ts", - inject: "src/devtools/inject.ts", + inject: "src/inject/index.ts", }, }, background: {