逻辑优化

This commit is contained in:
xu_yanfeng
2025-01-06 19:46:38 +08:00
parent 250155cd35
commit 82215235d9
12 changed files with 150 additions and 53 deletions

View File

@@ -1,6 +1,6 @@
import CCP from "cc-plugin/src/ccp/entry-render";
import { TinyEmitter } from "tiny-emitter";
import { Msg, Page, PluginEvent } from "../../core/types";
import { debugLog, Msg, Page, PluginEvent } from "../../core/types";
import { Terminal } from "../../scripts/terminal";
import { TestClient, testServer } from "./test/server";
export type BridgeCallback = (data: PluginEvent, sender: chrome.runtime.Port) => void;
@@ -22,13 +22,13 @@ 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(""));
debugLog && console.log(...this.terminal.disconnect(""));
this.connect = null;
});
this.connect.onMessage.addListener((event, sender: chrome.runtime.Port) => {
const data = PluginEvent.create(event);
console.log(...this.terminal.chunkMessage(data.toChunk()));
debugLog && console.log(...this.terminal.chunkMessage(data.toChunk()));
if (data.valid && data.isTargetDevtools()) {
this.emitter.emit(data.msg, data);
} else {

View File

@@ -1,18 +1,74 @@
export enum CompType {
Node2 = "node-2",
Spirte2 = "sprite-2",
Label2 = "label-2",
Node3 = "node-3",
Spirte3 = "sprite-3",
Label3 = "label-3",
Node = "cc.Node",
Spirte = "cc.Sprite",
Label = "cc.Label",
Widget = "cc.Widget",
Camera = "cc.Camera",
UITransform = "cc.UITransform",
}
export function getSimpleProperties(typeName: string): string[] {
const config = {};
config[CompType.Node2] = ["position", "rotation", "scale", "anchor", "size", "color", "opacity", "skew", "group"];
config[CompType.Label2] = ["string", "horizontalAlign", "verticalAlign", "fontSize", "lineHeight", "overflow", "font", "fontFamily", "ebableBold", "enableItalic", "enableUnderline", "underlineHeight", "cacheMode", "useSystemFont"];
config[CompType.Spirte2] = ["atlas", "spriteFrame", "type", "sizeMode"];
config[CompType.Node] = [
"position", //
"rotation",
"scale",
"anchor",
"size",
"color",
"opacity",
"skew",
"group",
//----------
"worldPosition",
"worldScale",
// "worldRotation",// 渲染有问题,暂时先不支持这个属性
];
config[CompType.UITransform] = ["anchor", "size"];
config[CompType.Widget] = [
"left",
"right",
"top",
"bottom",
"alignMode", //
"isAlignLeft",
"isAlignRight",
"isAlignTop",
"isAlignBottom",
];
config[CompType.Label] = [
"string", //
"horizontalAlign",
"verticalAlign",
"fontSize",
"lineHeight",
"overflow",
"font",
"fontFamily",
"ebableBold",
"enableItalic",
"enableUnderline",
"underlineHeight",
"cacheMode",
"useSystemFont",
];
config[CompType.Camera] = ["clearColor", "clearFlags", "cullingMask", "depth", "zoomRatio", "alignWithScreen"];
config[CompType.Spirte] = [
"atlas",
"spriteFrame",
"type",
"sizeMode", //
"fillCenter",
"fillRange",
"fillRange",
"fillStart",
"fillType",
"grayscale",
"color",
"spriteAtlas",
"trim",
"type",
];
return config[typeName] || [];
}
export const VisibleProp = {

View File

@@ -13,6 +13,7 @@
<script lang="ts">
import ccui from "@xuyanfeng/cc-ui";
import { IUiMenuItem } from "@xuyanfeng/cc-ui/types/cc-menu/const";
import Mousetrap, { MousetrapInstance } from "mousetrap";
import { storeToRefs } from "pinia";
import { defineComponent, nextTick, onMounted, onUnmounted, ref, toRaw, watch } from "vue";
import { Msg, PluginEvent, RequestTreeInfoData, ResponseSetPropertyData } from "../../core/types";
@@ -26,7 +27,6 @@ export default defineComponent({
name: "hierarchy",
components: { CCButtonGroup, CCInput, CCTree, CCDock },
setup() {
onMounted(() => {});
const funcShowPlace = (data: EngineData) => {
console.log(toRaw(data));
_expand(data.engineUUID);
@@ -41,12 +41,27 @@ export default defineComponent({
const timer: Timer = new Timer(() => {
updateTree();
});
let ins: MousetrapInstance | null = null;
function onQuickVisible() {
console.log("onQuickVisible");
if (selectedUUID) {
bridge.send(Msg.RequestVisible, selectedUUID);
}
}
onMounted(() => {
if (elTree.value) {
const el = toRaw(elTree.value);
ins = new Mousetrap(el.treeElement);
ins.bind(["space"], onQuickVisible, "keydown");
}
Bus.on(BusMsg.ShowPlace, funcShowPlace);
Bus.on(BusMsg.EnableSchedule, funcEnableSchedule);
timer.create();
});
onUnmounted(() => {
if (ins) {
ins.unbind(["space"], "keydown");
}
Bus.off(BusMsg.ShowPlace, funcShowPlace);
Bus.off(BusMsg.EnableSchedule, funcEnableSchedule);
timer.clean();
@@ -96,7 +111,7 @@ export default defineComponent({
});
const { config, frameID } = storeToRefs(appStore());
const matchCase = ref<boolean>(false);
const elTree = ref<typeof CCTree>();
const elTree = ref<typeof CCTree>(null);
const treeData = ref<TreeData[]>([]);
let selectedUUID: string | null = null;
bridge.on(Msg.ResponseTreeInfo, (event: PluginEvent) => {
@@ -199,17 +214,17 @@ export default defineComponent({
});
if (selectedUUID) {
menus.push({
name: "visible",
name: "visible (sapce)",
enabled: true,
callback: () => {
console.log("visible");
onQuickVisible();
},
});
menus.push({
name: "destroy",
enabled: false,
enabled: true,
callback: () => {
console.log("destroy");
bridge.send(Msg.RequestDestroy, selectedUUID);
},
});
}

View File

@@ -186,6 +186,13 @@ export class TestServer {
console.log(data);
break;
}
case Msg.RequestVisible: {
const node: Node = this.testData.findNode(data);
if (node) {
node.active = !node.active;
}
break;
}
default:
break;
}

View File

@@ -26,7 +26,7 @@
import ccui from "@xuyanfeng/cc-ui";
import { storeToRefs } from "pinia";
import { defineComponent, ref } from "vue";
import { Msg, Page, PluginEvent, ResponseUpdateFramesData } from "../../../core/types";
import { debugLog, Msg, Page, PluginEvent, ResponseUpdateFramesData } from "../../../core/types";
import { Terminal } from "../../../scripts/terminal";
import { bridge } from "../bridge";
import { Bus, BusMsg } from "../bus";
@@ -89,15 +89,15 @@ export default defineComponent({
onTerminal() {
const t = new Terminal("flag");
const event = new PluginEvent(Page.Background, Page.Background, Msg.ResponseTreeInfo, "");
console.log(...t.message("1"));
console.log(...t.log("newline", true));
console.log(...t.log("oneline", false));
console.log(...t.disconnect("disconnect"));
console.log(...t.connect("connect"));
console.log(...t.red("red"));
console.log(...t.green("green"));
console.log(...t.blue("blue"));
console.log(...t.chunkMessage(event.toChunk()));
debugLog && console.log(...t.message("1"));
debugLog && console.log(...t.log("newline", true));
debugLog && console.log(...t.log("oneline", false));
debugLog && console.log(...t.disconnect("disconnect"));
debugLog && console.log(...t.connect("connect"));
debugLog && console.log(...t.red("red"));
debugLog && console.log(...t.green("green"));
debugLog && console.log(...t.blue("blue"));
debugLog && console.log(...t.chunkMessage(event.toChunk()));
},
onTestTree1() {
const data: TreeData = {