mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-20 00:48:43 +00:00
inject重构
This commit is contained in:
parent
cff5edf263
commit
57a3b8a39c
@ -14,13 +14,12 @@ import {
|
|||||||
TreeData,
|
TreeData,
|
||||||
Vec2Data,
|
Vec2Data,
|
||||||
Vec3Data
|
Vec3Data
|
||||||
} from "./data";
|
} from "@/devtools/data";
|
||||||
import {Msg, Page, PluginEvent} from "@/core/types"
|
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 {
|
class CCInspector {
|
||||||
inspectorGameMemoryStorage: Record<string, any> = {}
|
inspectorGameMemoryStorage: Record<string, any> = {}
|
||||||
@ -207,7 +206,7 @@ class CCInspector {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_buildVecData(options: any) {
|
_buildVecData(options: BuildVecOptions) {
|
||||||
const ctor: Function = options.ctor;
|
const ctor: Function = options.ctor;
|
||||||
const keys: Array<string> = options.keys;
|
const keys: Array<string> = options.keys;
|
||||||
const value: Object = options.value;
|
const value: Object = options.value;
|
||||||
@ -233,7 +232,7 @@ class CCInspector {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_buildImageData(options: any) {
|
_buildImageData(options: BuildImageOptions) {
|
||||||
const ctor: Function = options.ctor;
|
const ctor: Function = options.ctor;
|
||||||
const value: Object = options.value;
|
const value: Object = options.value;
|
||||||
const data: ImageData = options.data;
|
const data: ImageData = options.data;
|
||||||
@ -249,7 +248,7 @@ class CCInspector {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_genInfoData(node: any, key: string, path: Array<string>) {
|
_genInfoData(node: any, key: string | number, path: Array<string>) {
|
||||||
let propertyValue = node[key];
|
let propertyValue = node[key];
|
||||||
let info = null;
|
let info = null;
|
||||||
switch (typeof propertyValue) {
|
switch (typeof propertyValue) {
|
||||||
@ -270,11 +269,11 @@ class CCInspector {
|
|||||||
let hex = propertyValue.toHEX();
|
let hex = propertyValue.toHEX();
|
||||||
info = new ColorData(`#${hex}`);
|
info = new ColorData(`#${hex}`);
|
||||||
} else if (Array.isArray(propertyValue)) {
|
} else if (Array.isArray(propertyValue)) {
|
||||||
let keys = [];
|
let keys: number[] = [];
|
||||||
for (let i = 0; i < propertyValue.length; i++) {
|
for (let i = 0; i < propertyValue.length; i++) {
|
||||||
keys.push(i);
|
keys.push(i);
|
||||||
}
|
}
|
||||||
info = this._buildObjectOrArrayData({
|
info = this._buildArrayData({
|
||||||
data: new ArrayData(),
|
data: new ArrayData(),
|
||||||
path: path,
|
path: path,
|
||||||
value: propertyValue,
|
value: propertyValue,
|
||||||
@ -313,7 +312,7 @@ class CCInspector {
|
|||||||
info.engineName = propertyValue.name;
|
info.engineName = propertyValue.name;
|
||||||
info.engineUUID = propertyValue.uuid;
|
info.engineUUID = propertyValue.uuid;
|
||||||
} else {
|
} else {
|
||||||
info = this._buildObjectOrArrayData({
|
info = this._buildObjectData({
|
||||||
data: new ObjectData(),
|
data: new ObjectData(),
|
||||||
path: path,
|
path: path,
|
||||||
value: propertyValue,
|
value: propertyValue,
|
||||||
@ -334,11 +333,20 @@ class CCInspector {
|
|||||||
return info;
|
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 propertyValue: Object = options.value;
|
||||||
let path: Array<string> = options.path;
|
let path: Array<string> = options.path;
|
||||||
let data: ObjectData | ArrayData = options.data;
|
let data: ObjectData | ArrayData = options.data;
|
||||||
let keys: Array<string> = options.keys;
|
let keys: Array<string | number> = options.keys;
|
||||||
// 剔除_开头的属性
|
// 剔除_开头的属性
|
||||||
keys = keys.filter(key => !key.toString().startsWith("_"));
|
keys = keys.filter(key => !key.toString().startsWith("_"));
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
@ -423,7 +431,7 @@ class CCInspector {
|
|||||||
return nodeGroup;
|
return nodeGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取节点信息
|
// 获取节点信息,只获取一级key即可,后续
|
||||||
getNodeInfo(uuid: string) {
|
getNodeInfo(uuid: string) {
|
||||||
let node = this.inspectorGameMemoryStorage[uuid];
|
let node = this.inspectorGameMemoryStorage[uuid];
|
||||||
if (node) {
|
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)
|
let ret = Object.getOwnPropertyDescriptor(base, key)
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return !(ret.set || ret.writable);
|
return !(ret.set || ret.writable);
|
23
source/src/inject/types.ts
Normal file
23
source/src/inject/types.ts
Normal file
@ -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;
|
||||||
|
}
|
@ -18,7 +18,7 @@ module.exports = {
|
|||||||
contentScripts: {
|
contentScripts: {
|
||||||
entries: {
|
entries: {
|
||||||
content: "src/content.ts",
|
content: "src/content.ts",
|
||||||
inject: "src/devtools/inject.ts",
|
inject: "src/inject/index.ts",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
background: {
|
background: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user