格式化代码

This commit is contained in:
xu_yanfeng 2024-12-27 14:23:27 +08:00
parent ae59ee5a10
commit f7937a5c8b
23 changed files with 215 additions and 210 deletions

View File

@ -1,10 +1,5 @@
// @ts-ignore
import {
CocosPluginManifest,
CocosPluginOptions,
Panel,
PluginType,
} from "cc-plugin/src/declare";
import { CocosPluginManifest, CocosPluginOptions, Panel } from "cc-plugin/src/declare";
const pkgName = "cc-inspector";

View File

@ -1,19 +1,17 @@
import CCP from 'cc-plugin/src/ccp/entry-main';
import { BuilderOptions } from 'cc-plugin/src/declare';
import pluginConfig from '../cc-plugin.config';
import CCP from "cc-plugin/src/ccp/entry-main";
import { BuilderOptions } from "cc-plugin/src/declare";
import pluginConfig from "../cc-plugin.config";
CCP.init(pluginConfig, {
load: () => {
console.log('plugin load')
console.log("plugin load");
},
builder: {
onAfterBuild(target: BuilderOptions) {
}
onAfterBuild(target: BuilderOptions) {},
},
messages: {
showPanel() {
CCP.Adaptation.Panel.open('self.main')
}
}
})
CCP.Adaptation.Panel.open("self.main");
},
},
});

View File

@ -1,9 +1,8 @@
import { ChromeConst } from "cc-plugin/src/chrome/const";
import { Msg, Page, PluginEvent } from "../../core/types";
import { FrameDetails } from "../../views/devtools/data";
import { PortMan } from "./portMan";
import { PortMgr, portMgr } from "./portMgr";
import { Terminal } from "../terminal";
import { PortMan } from "./portMan";
import { portMgr } from "./portMgr";
const terminal = new Terminal(Page.Background);
console.log(...terminal.init());
function isDevtools(port: chrome.runtime.Port) {
@ -16,7 +15,7 @@ function onTabConnect(tab: chrome.tabs.Tab, port: chrome.runtime.Port) {
debugger;
return;
}
let portMan = portMgr.findPort(tab.id)
let portMan = portMgr.findPort(tab.id);
if (portMan) {
// 一个port发起多次发起链接以最后一次的为数据通讯基准
// portMgr.removePort(portMan);
@ -30,7 +29,7 @@ chrome.runtime.onConnect.addListener((port: chrome.runtime.Port) => {
chrome.tabs.query({ active: true }, (tabs: chrome.tabs.Tab[]) => {
tabs.forEach((tab) => {
onTabConnect(tab, port);
})
});
});
} else {
const tab: chrome.tabs.Tab | undefined = port.sender?.tab;
@ -52,7 +51,7 @@ chrome.runtime.onMessage.addListener((request: PluginEvent, sender: any, sendRes
}
}
});
chrome.tabs.onActivated.addListener(({ tabId, windowId }) => { });
chrome.tabs.onActivated.addListener(({ tabId, windowId }) => {});
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
// 页面发生刷新,通知重新生成数据
if (changeInfo.status === "complete") {

View File

@ -1,7 +1,6 @@
import { Msg, Page, PluginEvent } from "../../core/types";
import { PluginEvent } from "../../core/types";
import { PortMan } from "./portMan";
import { portMgr } from "./portMgr";
import { FrameDetails } from "views/devtools/data";
export class PortContent extends PortMan {
init(): void {
@ -28,4 +27,4 @@ export class PortContent extends PortMan {
}
};
}
}
}

View File

@ -8,7 +8,7 @@ export class PortDevtools extends PortMan {
portMgr._updateFrames();
this.onDisconnect = () => {
portMgr.removePort(this);
}
};
this.onMessage = (data: PluginEvent) => {
if (data.msg === Msg.UseFrame) {
portMgr.useFrame(data.data);
@ -29,8 +29,6 @@ export class PortDevtools extends PortMan {
port.postMessage(data);
}
}
}
};
}
}
}

View File

@ -1,8 +1,5 @@
import { ChromeConst } from "cc-plugin/src/chrome/const";
import { Msg, Page, PluginEvent } from "../../core/types";
import { FrameDetails } from "../../views/devtools/data";
import { Page, PluginEvent } from "../../core/types";
import { Terminal } from "../terminal";
import { portMgr } from "./portMgr";
export abstract class PortMan {
/**
@ -32,13 +29,13 @@ export abstract class PortMan {
this.terminal = new Terminal(`Port-${this.name}`);
port.onMessage.addListener((data: any, port: chrome.runtime.Port) => {
const event = PluginEvent.create(data);
console.log(... this.terminal.chunkMessage(event.toChunk()));
console.log(...this.terminal.chunkMessage(event.toChunk()));
// 如果多个页面都监听 onMessage 事件,对于某一次事件只有第一次调用 sendResponse() 能成功发出回应,所有其他回应将被忽略。
// port.postMessage(data);
if (event.valid && this.onMessage) {
this.onMessage(event);
} else {
console.log(... this.terminal.log(JSON.stringify(data)));
console.log(...this.terminal.log(JSON.stringify(data)));
}
});
port.onDisconnect.addListener((port: chrome.runtime.Port) => {
@ -56,4 +53,4 @@ export abstract class PortMan {
isDevtoolsPort() {
return this.name === Page.Devtools;
}
}
}

View File

@ -1,9 +1,9 @@
import { Msg, Page, PluginEvent } from "../../core/types";
import { PortMan } from "./portMan";
import { PortDevtools } from "./portDevtools";
import { PortContent } from "./portContent";
import { FrameDetails } from "views/devtools/data";
import { Msg, Page, PluginEvent } from "../../core/types";
import { Terminal } from "../terminal";
import { PortContent } from "./portContent";
import { PortDevtools } from "./portDevtools";
import { PortMan } from "./portMan";
export class PortMgr {
/**
@ -15,7 +15,7 @@ export class PortMgr {
* frameIDiframe嵌套
*/
private currentUseContentFrameID = 0;
private terminal = new Terminal('PortMgr');
private terminal = new Terminal("PortMgr");
public findDevtoolsPort() {
return this.portArray.find((el) => el.name === Page.Devtools);
}
@ -25,14 +25,14 @@ export class PortMgr {
public _updateFrames() {
// 将content类型的port收集起来同步到devtools
const data: FrameDetails[] = [];
this.portArray.forEach(item => {
this.portArray.forEach((item) => {
if (item.isConnectPort()) {
data.push({
url: item.port.sender?.url || "",
frameID: item.port.sender?.frameId || 0,
})
});
}
})
});
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.UpdateFrames, data);
this.sendDevtoolMsg(event);
}
@ -49,7 +49,7 @@ export class PortMgr {
break;
}
default: {
debugger
debugger;
break;
}
}
@ -61,23 +61,23 @@ export class PortMgr {
return null;
}
public logState() {
let arr: Array<{ name: string, id: number, url: string }> = [];
let arr: Array<{ name: string; id: number; url: string }> = [];
let str: string[] = [];
for (let i = 0; i < this.portArray.length; i++) {
const port = this.portArray[i];
arr.push({
name: port.name,
id: port.id,
url: port.url
url: port.url,
});
str.push(`[${i + 1}] time:${new Date(port.timestamp).toLocaleString()}, name:${port.name}, id:${port.id}, url:${port.url}`);
}
if (arr.length) {
// console.table(arr)
console.log(... this.terminal.log(str.join('\n'), true));
console.log(...this.terminal.log(str.join("\n"), true));
} else {
console.log(... this.terminal.log("no port connected"));
console.log(...this.terminal.log("no port connected"));
}
}
public removePort(item: PortMan) {
@ -92,22 +92,22 @@ export class PortMgr {
this.getCurrentUseContent()?.postMessage(data);
}
sendDevtoolMsg(data: PluginEvent) {
const portManArray = this.portArray.filter(el => el.isDevtoolsPort());
const portManArray = this.portArray.filter((el) => el.isDevtoolsPort());
if (portManArray.length) {
portManArray.forEach(portMan => {
portManArray.forEach((portMan) => {
portMan.port.postMessage(data);
})
});
} else {
console.log('not find devtools port');
console.log("not find devtools port");
}
}
getCurrentUseContent(): chrome.runtime.Port | null {
const portMan = this.portArray.find((portMan: PortMan) => {
const el = portMan.port;
const b1 = el.sender?.frameId !== undefined;
const b2 = el.sender.frameId === this.currentUseContentFrameID
return b1 && b2
})
const b2 = el.sender.frameId === this.currentUseContentFrameID;
return b1 && b2;
});
if (portMan) {
return portMan.port;
} else {
@ -121,7 +121,7 @@ export class PortMgr {
this.getCurrentUseContent()?.postMessage(sendData);
}
isCurrentFrme(id: number) {
return this.currentUseContentFrameID === id
return this.currentUseContentFrameID === id;
}
}
export const portMgr = new PortMgr();
export const portMgr = new PortMgr();

View File

@ -7,4 +7,4 @@ export enum DocumentEvent {
* content到inject的事件
*/
Content2Inject = "content2inject",
}
}

View File

@ -1,10 +1,10 @@
import CCP from "cc-plugin/src/ccp/entry-render";
import { Msg, Page, PluginEvent } from "../../core/types";
import { TestClient, testServer, TestServer } from "./test/server";
import { Terminal } from "../../scripts/terminal";
import { TestClient, testServer } from "./test/server";
export type BridgeCallback = (data: PluginEvent, sender: chrome.runtime.Port) => void;
if (chrome.devtools) {
console.log("chrome devtools")
console.log("chrome devtools");
}
class Bridge implements TestClient {
/**
@ -25,9 +25,9 @@ class Bridge implements TestClient {
if (CCP.Adaptation.Env.isChromeRuntime) {
this.connect = chrome.runtime.connect({ name: Page.Devtools });
this.connect.onDisconnect.addListener(() => {
console.log(...this.terminal.disconnect(""))
console.log(...this.terminal.disconnect(""));
this.connect = null;
})
});
this.connect.onMessage.addListener((event, sender: chrome.runtime.Port) => {
const data = PluginEvent.create(event);
@ -38,7 +38,6 @@ class Bridge implements TestClient {
console.log(JSON.stringify(event));
}
});
} else {
testServer.add(this);
}
@ -55,12 +54,12 @@ class Bridge implements TestClient {
send(msg: Msg, data?: any) {
if (CCP.Adaptation.Env.isChromeDevtools) {
if (this.connect) {
let sendData = new PluginEvent(Page.Devtools, Page.Background, msg, data)
this.connect.postMessage(sendData)
let sendData = new PluginEvent(Page.Devtools, Page.Background, msg, data);
this.connect.postMessage(sendData);
} else {
console.warn(...this.terminal.log("重新和background建立链接"))
console.warn(...this.terminal.log("重新和background建立链接"));
this.init();
this.send(msg, data)
this.send(msg, data);
}
} else {
testServer.recv(msg, data);

View File

@ -1,4 +1,4 @@
import { TinyEmitter } from 'tiny-emitter';
import { TinyEmitter } from "tiny-emitter";
export enum BusMsg {
ShowPlace = "ShowPlace",

View File

@ -1,4 +1,3 @@
function createPluginMenus() {
const menus = [];

View File

@ -1,21 +1,21 @@
import { ITreeData } from '@xuyanfeng/cc-ui/types/cc-tree/const';
import { ITreeData } from "@xuyanfeng/cc-ui/types/cc-tree/const";
import { v4 } from "uuid";
export enum DataType {
Number = 'Number',
String = 'String',
Text = 'Text',
Vec2 = 'Vec2',
Vec3 = 'Vec3',
Vec4 = 'Vec4',
Enum = 'Enum',
Bool = 'Bool',
Color = 'Color',
Invalid = 'Invalid',
Array = 'Array', // 暂时在控制台打印下
Object = 'Object',
ObjectItem = 'ObjectItem',
Image = 'Image', // 图片
Engine = 'Engine',// 引擎的类型cc.Node, cc.Sprite, cc.Label等。。。
Number = "Number",
String = "String",
Text = "Text",
Vec2 = "Vec2",
Vec3 = "Vec3",
Vec4 = "Vec4",
Enum = "Enum",
Bool = "Bool",
Color = "Color",
Invalid = "Invalid",
Array = "Array", // 暂时在控制台打印下
Object = "Object",
ObjectItem = "ObjectItem",
Image = "Image", // 图片
Engine = "Engine", // 引擎的类型cc.Node, cc.Sprite, cc.Label等。。。
}
export class Info {
@ -23,7 +23,7 @@ export class Info {
public type: DataType = DataType.Number;
public data: any;
public readonly: boolean = false;
public path: Array<string> = [];// 属性对应的路径
public path: Array<string> = []; // 属性对应的路径
constructor(id: string = "") {
this.id = id || v4();
}
@ -32,21 +32,51 @@ export class Info {
this.path = data.path;
this.readonly = data.readonly;
}
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; }
public isColor(): boolean { return false; }
public isInvalid(): boolean { return false; }
public isNumber(): boolean { return false; }
public isArrayOrObject(): boolean { return false; }
public isArray(): boolean { return false; }
public isObject(): boolean { return false; }
public isImage(): boolean { return false; }
public isEngine(): boolean { return false; }
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;
}
public isColor(): boolean {
return false;
}
public isInvalid(): boolean {
return false;
}
public isNumber(): boolean {
return false;
}
public isArrayOrObject(): boolean {
return false;
}
public isArray(): boolean {
return false;
}
public isObject(): boolean {
return false;
}
public isImage(): boolean {
return false;
}
public isEngine(): boolean {
return false;
}
}
export class TextData extends Info {
@ -61,7 +91,9 @@ export class TextData extends Info {
this.data = data.data;
return this;
}
public isText(): boolean { return true; }
public isText(): boolean {
return true;
}
}
export interface ObjectItemRequestData {
@ -102,7 +134,9 @@ export class EngineData extends Info {
this.engineUUID = uuid;
return this;
}
public isEngine(): boolean { return true; }
public isEngine(): boolean {
return true;
}
}
export class ArrayData extends Info {
@ -135,16 +169,18 @@ export class ArrayData extends Info {
this.add(new Property("item1", new TextData("text")));
const sub = new ArrayData();
sub.add(new Property("sub", new StringData("sub")));
this.add(new Property('arr', sub));
this.add(new Property("arr", sub));
return this;
}
public isArray(): boolean { return true; }
public isArrayOrObject(): boolean { return true; }
public isArray(): boolean {
return true;
}
public isArrayOrObject(): boolean {
return true;
}
}
export class ObjectDataItem extends Info {
}
export class ObjectDataItem extends Info {}
export class ObjectData extends Info {
/**
@ -163,25 +199,29 @@ export class ObjectData extends Info {
}
test() {
this.data = JSON.stringify({ fack: 'test' });
this.data = JSON.stringify({ fack: "test" });
return this;
}
testProperty(): Property[] {
const obj: Object = JSON.parse(this.data);
const properties: Property[] = [];
for (let key in obj) {
if (typeof obj[key] === 'string') {
if (typeof obj[key] === "string") {
properties.push(new Property(key, new StringData(obj[key])));
} else if (typeof obj[key] === 'number') {
} else if (typeof obj[key] === "number") {
properties.push(new Property(key, new NumberData(obj[key])));
} else if (typeof obj[key] === 'boolean') {
} else if (typeof obj[key] === "boolean") {
properties.push(new Property(key, new BoolData(obj[key])));
}
}
return properties;
}
public isObject(): boolean { return true; }
public isArrayOrObject(): boolean { return true; }
public isObject(): boolean {
return true;
}
public isArrayOrObject(): boolean {
return true;
}
}
export class InvalidData extends Info {
@ -197,7 +237,9 @@ export class InvalidData extends Info {
this.data = data.data;
return this;
}
public isInvalid(): boolean { return true; }
public isInvalid(): boolean {
return true;
}
}
export class ColorData extends Info {
@ -212,7 +254,9 @@ export class ColorData extends Info {
this.data = data.data;
return this;
}
public isColor(): boolean { return true; }
public isColor(): boolean {
return true;
}
}
export class StringData extends Info {
@ -227,7 +271,9 @@ export class StringData extends Info {
this.data = data.data;
return this;
}
public isString(): boolean { return true; }
public isString(): boolean {
return true;
}
}
export class NumberData extends Info {
@ -242,7 +288,9 @@ export class NumberData extends Info {
this.data = data.data;
return this;
}
public isNumber(): boolean { return true; }
public isNumber(): boolean {
return true;
}
}
export class BoolData extends Info {
@ -257,7 +305,9 @@ export class BoolData extends Info {
this.data = data.data;
return this;
}
public isBool(): boolean { return true; }
public isBool(): boolean {
return true;
}
}
export class Vec2Data extends Info {
@ -265,7 +315,7 @@ export class Vec2Data extends Info {
constructor() {
super();
this.type = DataType.Vec2
this.type = DataType.Vec2;
this.data = [];
return this;
}
@ -376,15 +426,18 @@ export class ImageData extends Info {
return this;
}
test() {
const cocos = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAABz1JREFUaEO9WXuMHVUZ/32zfbHSQkDa3pkukALb7N6ZUjFGjBFjopCUBA1PRYyJaVIVMVTF3rlbhAh7z922EB8oVRKNlUcgSAwCMWAQlKg0msjOzPYFwdCdMy3U2tqy7Xbvzmfm7t7dO/fO7Jx799b5c77X73fOd77znXMIHfx04e6TttnbQZeZrihTowWFXMnbSRqulIX8/41ERwkYD7zVyxMn94B5WNrWuha4t63aUQIRCr3svQfmDzLwWmCbn2gbmaJhxwnkhrznKeT1UXxmeiEo5q9VxNKWWucJDA6/SpoWjXzVtwbtiVG7/9a20CkYdZSAIbztDP4SwEsBOmsmPk8+LIuXf10BT8sqHSPQUx65qsL8cnCJtxQ333zSEO5pBhbWEBHhfr9g3t0ywgyDjhBY9eBfzgrHlx0i0FHfzl8YxTSEV2KwXR9/krHpUNH8QSdJdISAUXLfZPAlXUsnjAN3XCFrAHXh+QDrdYAZC7puk3f1Pd4pEvMmkCt5zxPxegYOBraZiwH72d+79f8sOQGeWtDVj7mCicp6ec+HXuoEiXkRWFX2CiGziICMn72w7993rNnTCEoveb8H8TXRf6pFYzpVCSsfOTRwuTtfEm0TuFDsW13B6b0AFgD0nrTzy9PAGCX3fSZ018sZON61+JyLR7/Vc6T+v36/c4vcYj2pSqxtAkbJOcpE51Rr/YJFV47e1ft6WtAVg7tv7dImH2uW02Fp5y+o/58Tzh8D2/rUGSWgC2cEoL5qEKLDshAHkRRcF85+gC5NkI1K2+yZXfjuCWmbZ58xAnrJeRREX6wF6OpafM2B7172okpAXbiT1c256aN90s6vWbl9f782Me5J21TODGXFKObyoeHPLWB6Bjy9HBlHZNE8XwV8pGOUnB1MtDFZn97gEH8ljb/KpN0ZFPp/qOI3kUDP1v1XJ42qLpy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htkJSF94egNck2oQI5IBZvdXIDf3z+mBzc+ebUoW8pwh8U4PTM1KFdOFG6ZNc3QjHu/13LhjTL3qdWNvtF/u+0Eg0eR8ouQ+BcHv1GoFnN0oKsdEfMH/eyghn6erC4VijWGfAQIU4ul4Fpe0JiQQM4d7NwPcbgzNjJCia+SxQqnJj0LmWNXquWX/m/mVaxH+TtvWx5IWe8De3dWQDTSZ0iqRNykJ/agusCrymlys7TxPTDRl2FWmbM3esSilklJ0iQIN12TNjx4SdQcH8cqtgk/R14f0L4IuqsihTE/KBQE/6dv7zafFSt+pc2b2PGFuaDBn/lXWntfkQMYR7koElVR/NjW908tgRZBxq5uw19LK3DczfaQSpTeLG0S3mb+YDPrLVhTcJcGLDxuCdgW1lznRms6QL98cAGnug3dI2+9slYAztuZHDyk40dqA1h0RPyUL+FhX/mQSqI1Xyfgri2fMp81ECXvaLVtYCbMKgl4b3grTexJypZhL9zrfz16mAr2Wekq5ecraBKJ5OzBUCnlUhogtnOxF9M36+jocm8B982/qMEqBpJaUZqDnUB517odE9zQGqRB73E3I2N7Svj8LxFwGKH5Aaqg4Dfw5s86pWwLc0AzMkhLMdoG8nB+IKCL+SBWvDVOo5L4Ho01mgmGlXUGyvz2ppBmpAjLK3g5k3phZvILqQGgeg0oK/IW2z7Vf9tghMja77GAhN779N5Txlg5oejHlVs7ZSqD4d9JI7/XxEaUVlVr2eSPVym9+SBTPpvSAr42Lytmcg8rJi25vLuyZO7gVRi5e8fFjaVuxlpiXUdcr/A3Hqok9HdvAQAAAAAElFTkSuQmCC";
this.data = cocos;
return this;
}
public isImage(): boolean { return true; }
public isImage(): boolean {
return true;
}
}
export class EnumData extends Info {
public values: Array<{ name: string, value: any }> = [];
public values: Array<{ name: string; value: any }> = [];
constructor() {
super();
this.type = DataType.Enum;
@ -474,7 +527,7 @@ export class Property {
break;
case DataType.ObjectItem:
default:
throw new Error(`not support type: ${typeof data === 'string' ? data : JSON.stringify(data)}`);
throw new Error(`not support type: ${typeof data === "string" ? data : JSON.stringify(data)}`);
}
return this;
}
@ -490,7 +543,7 @@ export class Group {
constructor(name: string, id?: string) {
this.name = name;
this.id = id || '';
this.id = id || "";
}
parse(data: Group) {
this.id = data.id;
@ -504,7 +557,7 @@ export class Group {
return this;
}
addProperty(property: Property) {
this.data.push(property)
this.data.push(property);
}
buildProperty(name: string, info: Info) {
const property = new Property(name, info);
@ -516,16 +569,16 @@ export class Group {
let order = ["name", "active", "enabled", "uuid", "position", "rotation", "scale", "anchor", "size", "color", "opacity", "skew", "group"];
let orderKeys: Array<Property> = [];
let otherKeys: Array<Property> = [];
this.data.forEach(property => {
if (order.find(el => el === property.name)) {
orderKeys.push(property)
this.data.forEach((property) => {
if (order.find((el) => el === property.name)) {
orderKeys.push(property);
} else {
otherKeys.push(property);
}
})
});
orderKeys.sort((a, b) => {
return order.indexOf(a.name) - order.indexOf(b.name);
})
});
otherKeys.sort();
this.data = orderKeys.concat(otherKeys);
}

View File

@ -2,12 +2,12 @@ import ccui from "@xuyanfeng/cc-ui";
import "@xuyanfeng/cc-ui/dist/ccui.css";
import "@xuyanfeng/cc-ui/iconfont/iconfont.css";
import CCP from "cc-plugin/src/ccp/entry-render";
import { createPinia } from 'pinia';
import { createPinia } from "pinia";
import { createApp } from "vue";
import pluginConfig from "../../../cc-plugin.config";
import "../global.less";
import App from "./index.vue";
import { init } from './register-panel';
import { init } from "./register-panel";
export default CCP.init(pluginConfig, {
ready: function (rootElement: any, args: any) {
init();

View File

@ -42,13 +42,12 @@
import ccui from "@xuyanfeng/cc-ui";
import { ButtonGroupItem } from "@xuyanfeng/cc-ui/types/cc-button-group/const";
import { Option } from "@xuyanfeng/cc-ui/types/cc-select/const";
import { ITreeData } from "@xuyanfeng/cc-ui/types/cc-tree/const";
import { _UnwrapAll, Store, storeToRefs } from "pinia";
import { defineComponent, nextTick, onMounted, PropType, reactive, Ref, ref, toRaw, watch } from "vue";
import { storeToRefs } from "pinia";
import { defineComponent, nextTick, onMounted, reactive, ref, toRaw, watch } from "vue";
import PluginConfig from "../../../cc-plugin.config";
import { Msg, Page, PluginEvent } from "../../core/types";
import Bus, { BusMsg } from "./bus";
import { Msg, PluginEvent } from "../../core/types";
import { bridge } from "./bridge";
import Bus, { BusMsg } from "./bus";
import { EngineData, FrameDetails, Info, NodeInfoData, ObjectData, ObjectItemRequestData, TreeData } from "./data";
import { appStore, RefreshType } from "./store";
import Test from "./test/test.vue";

View File

@ -1,7 +1,5 @@
import CCP from "cc-plugin/src/ccp/entry-render";
import { ChromeConst } from "cc-plugin/src/chrome/const";
import { bridge } from "./bridge";
import { Msg } from "../../core/types";
export function init() {
if (chrome && chrome.devtools) {
// 对应的是Elements面板的边栏
@ -12,8 +10,8 @@ export function init() {
// 创建devtools-panel
let iconPath = "";
const { icon } = CCP.manifest;
if (icon && icon['48']) {
iconPath = icon['48'];
if (icon && icon["48"]) {
iconPath = icon["48"];
}
chrome.devtools.panels.create(CCP.manifest.name, iconPath, ChromeConst.html.devtools, (panel: chrome.devtools.panels.ExtensionPanel) => {
console.log("[CC-Inspector] Dev Panel Created!");
@ -30,7 +28,6 @@ export function init() {
// ctrl+f 查找触发
console.log("panel search!");
});
}
);
});
}
}
}

View File

@ -36,5 +36,5 @@ export const appStore = defineStore("app", () => {
const cfg = toRaw(config.value);
profile.save(cfg);
},
}
});
};
});

View File

@ -2,9 +2,7 @@ import { v4 } from "uuid";
import { Msg, Page, PluginEvent } from "../../../core/types";
import { ArrayData, BoolData, ColorData, EngineData, EnumData, Group, ImageData, Info, InvalidData, NodeInfoData, NumberData, ObjectData, ObjectItemRequestData, Property, StringData, TextData, TreeData, Vec2Data, Vec3Data, Vec4Data } from "../data";
export class TestClient {
recv(event: PluginEvent) {
}
recv(event: PluginEvent) {}
}
class Node {
active: boolean = true;
@ -19,7 +17,7 @@ class Node {
this.children = [];
}
buildComponent(name: string) {
const info = new Group(name)
const info = new Group(name);
this.components.push(info);
return info;
}
@ -43,17 +41,17 @@ class Node {
private allNodes(): Node[] {
const nodes: Node[] = [];
function circle(node: Node) {
node.children.forEach(child => {
node.children.forEach((child) => {
nodes.push(child);
circle(child);
})
});
}
circle(this);
return nodes;
}
findNode(id: string): Node | null {
const nodes: Node[] = this.allNodes();
return nodes.find(node => node.id === id) || null;
return nodes.find((node) => node.id === id) || null;
}
findInfo(id: string): Info | null {
const nodes: Node[] = this.allNodes();
@ -83,42 +81,19 @@ export class TestServer {
private clients: TestClient[] = [];
private testData: Node = new Node("scene");
constructor() {
this.testData.buildChild("base").buildComponent("group1")
.buildProperty('bool', new BoolData(true))
.buildProperty("text", new TextData("text"))
.buildProperty("number", new NumberData(100))
.buildProperty("string", new StringData("string"))
.buildProperty("enum", new EnumData().test())
.buildProperty("color", new ColorData('#f00'))
.buildProperty("image", new ImageData().test())
this.testData.buildChild('vec').buildComponent('group2')
.buildProperty("number", new NumberData(200))
.buildProperty("vec2", new Vec2Data().test())
.buildProperty("vec3", new Vec3Data().test())
.buildProperty("vec4", new Vec4Data().test())
this.testData.buildChild("obj/arr").buildComponent("group3")
.buildProperty("array", new ArrayData().test())
.buildProperty("object", new ObjectData().test())
.buildProperty("arr_arr", new ArrayData().testSub())
this.testData.buildChild("engine").buildComponent("group4")
.buildProperty("node", new EngineData().init('name', 'cc_Node', 'uuid'))
.buildProperty("sprite", new EngineData().init('name', 'cc_Sprite', 'uuid'))
.buildProperty("label", new EngineData().init('name', 'cc_Label', 'uuid'))
.buildProperty("un_known", new EngineData().init('name', 'un_known', 'uuid'))
this.testData.buildChild("base").buildComponent("group1").buildProperty("bool", new BoolData(true)).buildProperty("text", new TextData("text")).buildProperty("number", new NumberData(100)).buildProperty("string", new StringData("string")).buildProperty("enum", new EnumData().test()).buildProperty("color", new ColorData("#f00")).buildProperty("image", new ImageData().test());
this.testData.buildChild("vec").buildComponent("group2").buildProperty("number", new NumberData(200)).buildProperty("vec2", new Vec2Data().test()).buildProperty("vec3", new Vec3Data().test()).buildProperty("vec4", new Vec4Data().test());
this.testData.buildChild("obj/arr").buildComponent("group3").buildProperty("array", new ArrayData().test()).buildProperty("object", new ObjectData().test()).buildProperty("arr_arr", new ArrayData().testSub());
this.testData.buildChild("engine").buildComponent("group4").buildProperty("node", new EngineData().init("name", "cc_Node", "uuid")).buildProperty("sprite", new EngineData().init("name", "cc_Sprite", "uuid")).buildProperty("label", new EngineData().init("name", "cc_Label", "uuid")).buildProperty("un_known", new EngineData().init("name", "un_known", "uuid"));
const c = this.testData.buildChild("str1")
const c = this.testData.buildChild("str1");
c.active = false;
c.buildComponent("group51").buildProperty("str1", new StringData("str1"))
c.buildComponent("group52").buildProperty("num", new NumberData(200))
c.buildComponent("group51").buildProperty("str1", new StringData("str1"));
c.buildComponent("group52").buildProperty("num", new NumberData(200));
this.testData.buildChild("str2").buildComponent("group6")
.buildProperty("str2", new StringData("str2"))
this.testData.buildChild("str2").buildComponent("group6").buildProperty("str2", new StringData("str2"));
this.testData.buildChild("Invalid").buildComponent("group7")
.buildProperty("NaN", new InvalidData(NaN))
.buildProperty("null", new InvalidData(null))
.buildProperty("Infinity", new InvalidData(Infinity))
.buildProperty("undefined", new InvalidData(undefined))
this.testData.buildChild("Invalid").buildComponent("group7").buildProperty("NaN", new InvalidData(NaN)).buildProperty("null", new InvalidData(null)).buildProperty("Infinity", new InvalidData(Infinity)).buildProperty("undefined", new InvalidData(undefined));
}
add(client: TestClient) {
this.clients.push(client);
@ -158,9 +133,9 @@ export class TestServer {
const ret: ObjectItemRequestData = {
id: objData.id,
data: info.testProperty(),
}
};
const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.GetObjectItemData, ret);
this.send(event)
this.send(event);
} else {
console.warn("not found data: ", objData.id);
}
@ -176,8 +151,8 @@ export class TestServer {
}
send(event: PluginEvent) {
this.clients.forEach((client) => {
client.recv(event)
client.recv(event);
});
}
}
export const testServer = new TestServer();
export const testServer = new TestServer();

View File

@ -13,15 +13,14 @@
</template>
<script lang="ts">
import ccui from "@xuyanfeng/cc-ui";
import { ITreeData } from "@xuyanfeng/cc-ui/types/cc-tree/const";
import { storeToRefs } from "pinia";
import { defineComponent, ref } from "vue";
import { Msg, Page, PluginEvent } from "../../../core/types";
import { bridge } from "../bridge";
import { appStore, RefreshType } from "../store";
import { storeToRefs } from "pinia";
import { FrameDetails, Group, Info, InvalidData, NodeInfoData, TreeData } from "../data";
import { testServer, TestServer } from "./server";
import { Terminal } from "../../../scripts/terminal";
import { bridge } from "../bridge";
import { FrameDetails, Group, InvalidData, NodeInfoData, TreeData } from "../data";
import { appStore } from "../store";
import { testServer } from "./server";
const { CCButton, CCSection } = ccui.components;
export default defineComponent({
name: "test",

View File

@ -10,10 +10,9 @@
</template>
<script lang="ts">
import ccui from "@xuyanfeng/cc-ui";
import { defineComponent, PropType, ref } from "vue";
import { defineComponent, PropType } from "vue";
import Bus, { BusMsg } from "../bus";
import { EngineData, NumberData, Property } from "../data";
import { EngineData } from "../data";
export default defineComponent({
name: "property-engine",
components: {},

View File

@ -7,7 +7,7 @@
<script lang="ts">
import { defineComponent, PropType, watch } from "vue";
import Bus, { BusMsg } from "../bus";
import { Group, NodeInfoData } from "../data";
import { NodeInfoData } from "../data";
import PropertyGroup from "../ui/property-group.vue";
import UiProp from "./ui-prop.vue";

View File

@ -14,7 +14,7 @@
import ccui from "@xuyanfeng/cc-ui";
import { Option } from "@xuyanfeng/cc-ui/types/cc-select/const";
import { storeToRefs } from "pinia";
import { defineComponent, onMounted, ref, toRaw } from "vue";
import { defineComponent, ref } from "vue";
import bus, { BusMsg } from "../bus";
import { appStore, RefreshType } from "../store";
const { CCInput, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCProp, CCColor } = ccui.components;

View File

@ -31,12 +31,11 @@
<script lang="ts">
import ccui from "@xuyanfeng/cc-ui";
import { Option } from "@xuyanfeng/cc-ui/types/cc-select/const";
import { nextTick } from "process";
import { defineComponent, onMounted, onUnmounted, PropType, ref, toRaw, watch } from "vue";
import { defineComponent, onMounted, PropType, ref, toRaw, watch } from "vue";
import { Msg } from "../../../core/types";
import Bus, { BusMsg } from "../bus";
import { bridge } from "../bridge";
import { DataType, EngineData, EnumData, ImageData, Info, NumberData, Property, StringData, TextData, Vec2Data, Vec3Data } from "../data";
import Bus, { BusMsg } from "../bus";
import { EngineData, EnumData, ImageData, Info, NumberData, Property, StringData, TextData, Vec2Data, Vec3Data } from "../data";
import Engine from "./property-engine.vue";
import PropertyImage from "./property-image.vue";
const { CCInput, CCTextarea, CCProp, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCColor } = ccui.components;

View File

@ -5,7 +5,7 @@
</div>
</template>
<script lang="ts">
import { defineComponent, nextTick, onMounted, provide, ref } from "vue";
import { defineComponent } from "vue";
export default defineComponent({
name: "options",
components: {},