From b7dbec512ad85f28a7f7fc5c03dc465e3a16a9ab Mon Sep 17 00:00:00 2001 From: xu_yanfeng Date: Wed, 11 Dec 2024 14:56:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=88=E4=BA=8E=E6=8A=8A=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E5=AE=8C=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cc-inspector/src/views/devtools/bus.ts | 3 +- .../src/views/devtools/connectBackground.ts | 16 +- cc-inspector/src/views/devtools/data.ts | 33 +- cc-inspector/src/views/devtools/index.vue | 6 +- .../src/views/devtools/test/server.ts | 122 ++++- .../src/views/devtools/ui/property-engine.vue | 111 +++++ .../src/views/devtools/ui/ui-prop.vue | 418 +++++------------- 7 files changed, 390 insertions(+), 319 deletions(-) create mode 100644 cc-inspector/src/views/devtools/ui/property-engine.vue diff --git a/cc-inspector/src/views/devtools/bus.ts b/cc-inspector/src/views/devtools/bus.ts index 7a1352b..a242ca8 100644 --- a/cc-inspector/src/views/devtools/bus.ts +++ b/cc-inspector/src/views/devtools/bus.ts @@ -4,7 +4,8 @@ export enum BusMsg { ShowPlace = "ShowPlace", RequestObjectData = "RequestObjectData", LogData = "LogData", - FoldAllGroup = "FoldAllGroup" + FoldAllGroup = "FoldAllGroup", + UpdateSettings = "UpdateSettings", } export default new TinyEmitter(); diff --git a/cc-inspector/src/views/devtools/connectBackground.ts b/cc-inspector/src/views/devtools/connectBackground.ts index 7f9c2f2..42f4c7a 100644 --- a/cc-inspector/src/views/devtools/connectBackground.ts +++ b/cc-inspector/src/views/devtools/connectBackground.ts @@ -47,13 +47,17 @@ class ConnectBackground implements TestClient { } } postMessageToBackground(msg: Msg, data?: any) { - if (this.connect) { - let sendData = new PluginEvent(Page.Devtools, Page.Background, msg, data) - this.connect.postMessage(sendData) + if (CCP.Adaptation.Env.isChromeDevtools) { + if (this.connect) { + let sendData = new PluginEvent(Page.Devtools, Page.Background, msg, data) + this.connect.postMessage(sendData) + } else { + console.warn("重新和background建立链接") + this._initConnect(); + this.postMessageToBackground(msg, data) + } } else { - console.warn("重新和background建立链接") - this._initConnect(); - this.postMessageToBackground(msg, data) + testServer.recv(msg, data); } } diff --git a/cc-inspector/src/views/devtools/data.ts b/cc-inspector/src/views/devtools/data.ts index ddc765f..3a8abf2 100644 --- a/cc-inspector/src/views/devtools/data.ts +++ b/cc-inspector/src/views/devtools/data.ts @@ -6,6 +6,7 @@ export enum DataType { Text = 'Text', Vec2 = 'Vec2', Vec3 = 'Vec3', + Vec4 = 'Vec4', Enum = 'Enum', Bool = 'Bool', Color = 'Color', @@ -29,6 +30,7 @@ export class Info { public isEnum(): boolean { return false; } public isVec2(): boolean { return false; } public isVec3(): boolean { return false; } + public isVec4(): boolean { return false; } public isBool(): boolean { return false; } public isText(): boolean { return false; } public isString(): boolean { return false; } @@ -43,15 +45,19 @@ export class Info { } export class TextData extends Info { - constructor() { + constructor(data: string = "") { super(); this.type = DataType.Text; + this.data = data; } public isText(): boolean { return true; } } export interface ObjectItemRequestData { id: string | null; + /** + * 该对象拥有的所有属性 + */ data: Property[]; } @@ -60,6 +66,9 @@ export interface FrameDetails { url: string; } +/** + * 组件里面定义了引擎类型的数据,比如 `@property(cc.Label)` + */ export class EngineData extends Info { public engineType: string = ""; public engineUUID: string = ""; @@ -85,6 +94,7 @@ export class ArrayData extends Info { return this; } public isArray(): boolean { return true; } + public isArrayOrObject(): boolean { return true; } } export class ObjectDataItem extends Info { @@ -98,6 +108,7 @@ export class ObjectData extends Info { this.type = DataType.Object; } public isObject(): boolean { return true; } + public isArrayOrObject(): boolean { return true; } } export class InvalidData extends Info { @@ -184,7 +195,24 @@ export class Vec3Data extends Info { return true; } } +export class Vec4Data extends Vec2Data { + data: Array = []; + constructor() { + super(); + this.type = DataType.Vec4; + this.data = []; + return this; + } + + add(info: Property) { + this.data.push(info); + return this; + } + public isVec4(): boolean { + return true; + } +} export class ImageData extends Info { data: string | null = null; @@ -226,6 +254,9 @@ export class Property { } export class Group { + /** + * 节点的UUID + */ public id: string = ""; public name: string = "group"; public data: Array = []; diff --git a/cc-inspector/src/views/devtools/index.vue b/cc-inspector/src/views/devtools/index.vue index 8f1d7a5..9dc95b0 100644 --- a/cc-inspector/src/views/devtools/index.vue +++ b/cc-inspector/src/views/devtools/index.vue @@ -137,7 +137,7 @@ export default defineComponent({ if (item.id === targetUUID) { return true; } - if (circle(item.children)) { + if (circle(item.children || [])) { return true; } } @@ -147,6 +147,9 @@ export default defineComponent({ return circle(data); } + /** + * 请求属性的列表,如果一个属性请求失败,会阻断后续的相同请求,因为都已经失败了,就没必要再响应请求了 + */ const requestList: Array<{ id: string; cb: Function }> = []; function _expand(uuid: string) { @@ -205,7 +208,6 @@ export default defineComponent({ if (!Array.isArray(data)) { data = [data]; } - console.log(data); treeData.value = data; if (_checkSelectedUUID()) { updateNodeInfo(); diff --git a/cc-inspector/src/views/devtools/test/server.ts b/cc-inspector/src/views/devtools/test/server.ts index d3f2991..c14a3cc 100644 --- a/cc-inspector/src/views/devtools/test/server.ts +++ b/cc-inspector/src/views/devtools/test/server.ts @@ -1,5 +1,5 @@ import { Msg, Page, PluginEvent } from "../../../core/types"; -import { NodeInfoData, TreeData } from "../data"; +import { ArrayData, BoolData, ColorData, EngineData, EnumData, Group, Info, NodeInfoData, NumberData, ObjectData, ObjectItemRequestData, Property, StringData, TextData, TreeData, Vec2Data, Vec3Data, Vec4Data } from "../data"; export class TestClient { recv(event: PluginEvent) { @@ -13,26 +13,134 @@ export class TestServer { recv(msg: string, data: any) { switch (msg) { case Msg.NodeInfo: { - console.log(data); + const id: string = data as string; + + const group = new Group("test"); + { + const text = new TextData("text1"); + group.addProperty(new Property("text", text)) + } + { + const number = new NumberData(100); + group.addProperty(new Property("number", number)) + } + { + const str = new StringData("str"); + group.addProperty(new Property("str", str)) + } + { + const v2 = new Vec2Data(); + v2.add(new Property("x", new NumberData(100))); + v2.add(new Property("y", new NumberData(200))); + group.addProperty(new Property("v2", v2)) + } + { + const v3 = new Vec3Data(); + v3.add(new Property("x", new NumberData(100))); + v3.add(new Property("y", new NumberData(200))); + v3.add(new Property("z", new NumberData(300))); + group.addProperty(new Property("v3", v3)) + } + { + const v4 = new Vec4Data(); + v4.add(new Property("x", new NumberData(100))); + v4.add(new Property("y", new NumberData(200))); + v4.add(new Property("z", new NumberData(300))); + v4.add(new Property("w", new NumberData(400))); + group.addProperty(new Property("v4", v4)) + } + { + const b = new BoolData(true); + group.addProperty(new Property("bool", b)) + } + { + const e = new EnumData(); + e.values.push({ name: "a", value: 1 }); + e.values.push({ name: "b", value: 2 }); + group.addProperty(new Property("enum", e)) + } + { + const c = new ColorData('#f00'); + group.addProperty(new Property("color", c)) + } + { + const arr = new ArrayData(); + arr.add(new Property("item1", new TextData("text"))); + arr.add(new Property("item2", new BoolData(true))); + group.addProperty(new Property("arr", arr)) + } + { + const obj = new ObjectData(); + obj.data = JSON.stringify({ fack: 'test' }); + group.addProperty(new Property("obj", obj)); + } + { + const engine = new EngineData(); + engine.engineName = "engineName"; + engine.engineType = "engineType"; + engine.engineUUID = "engineUUID"; + group.addProperty(new Property("engine", engine)) + } + { + const engine = new EngineData(); + engine.engineName = "engineName"; + engine.engineType = "cc_Node"; + engine.engineUUID = "engineUUID"; + group.addProperty(new Property("engine", engine)) + } + { + const engine = new EngineData(); + engine.engineName = "engineName"; + engine.engineType = "cc_Srpite"; + engine.engineUUID = "engineUUID"; + group.addProperty(new Property("engine", engine)) + } + { + const engine = new EngineData(); + engine.engineName = "engineName"; + engine.engineType = "cc_Label"; + engine.engineUUID = "engineUUID"; + group.addProperty(new Property("engine", engine)) + } const ret: NodeInfoData = { - uuid: "1", - group: [] + uuid: id, + group: [group,] }; const event = new PluginEvent(Page.Background, Page.Devtools, Msg.NodeInfo, ret); this.send(event); break; } case Msg.TreeInfo: { - const data: TreeData = { - id: "1", + const ret: TreeData = { + id: "root", text: "root", active: true, children: [], }; - const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.TreeInfo, data); + const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.TreeInfo, ret); this.send(event); break; } + case Msg.SetProperty: { + console.log(data); + break; + } + case Msg.GetObjectItemData: { + const d = data as ObjectData; + const property = []; + property.push(new Property("fake", new TextData('test'))); + const ret: ObjectItemRequestData = { + id: d.id, + data: property, + } + const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.GetObjectItemData, ret); + this.send(event) + break; + } + case Msg.LogData: { + console.log(data); + break; + } default: break; } diff --git a/cc-inspector/src/views/devtools/ui/property-engine.vue b/cc-inspector/src/views/devtools/ui/property-engine.vue new file mode 100644 index 0000000..7bd5b66 --- /dev/null +++ b/cc-inspector/src/views/devtools/ui/property-engine.vue @@ -0,0 +1,111 @@ + + + + + diff --git a/cc-inspector/src/views/devtools/ui/ui-prop.vue b/cc-inspector/src/views/devtools/ui/ui-prop.vue index 7fcd2b7..7da54b2 100644 --- a/cc-inspector/src/views/devtools/ui/ui-prop.vue +++ b/cc-inspector/src/views/devtools/ui/ui-prop.vue @@ -1,48 +1,19 @@