From 96e8a883a43ef913d54b4a9fc740cdecaa980654 Mon Sep 17 00:00:00 2001 From: xyf-mac Date: Fri, 12 Nov 2021 21:20:57 +0800 Subject: [PATCH] bugfix --- source/package.json | 4 ++-- source/src/inject/index.ts | 27 +++++++++++++++++---------- source/src/inject/util.ts | 19 +++++++++++++++++-- source/src/manifest.json | 2 +- source/src/popup/index.vue | 6 ++++-- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/source/package.json b/source/package.json index fcb123f..a8d4a54 100644 --- a/source/package.json +++ b/source/package.json @@ -1,6 +1,6 @@ { - "name": "app", - "version": "0.2.0", + "name": "cc-inspector", + "version": "2.0.0", "private": true, "scripts": { "serve": "vue-cli-service serve", diff --git a/source/src/inject/index.ts b/source/src/inject/index.ts index 28b6554..5956139 100644 --- a/source/src/inject/index.ts +++ b/source/src/inject/index.ts @@ -22,6 +22,7 @@ import {BuildArrayOptions, BuildImageOptions, BuildObjectOptions, BuildVecOption // @ts-ignore import {uniq} from "lodash" import {trySetValueWithConfig, getValue} from "@/inject/setValue"; +import {isHasProperty} from "@/inject/util"; declare const cc: any; @@ -507,15 +508,25 @@ class CCInspector { return comp.constructor.name; } + // 校验keys的有效性,3.x有position,没有x,y,z + _checkKeysValid(obj: any, keys: string[]) { + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + if (!isHasProperty(obj, key)) { + return false; + } + } + return true; + } + _getGroupData(node: any) { const name = this.getCompName(node); let nodeGroup = new Group(name); let keys = this._getNodeKeys(node); for (let i = 0; i < keys.length;) { let key = keys[i]; - let propertyValue = node[key]; let pair = this._getPairProperty(key); - if (pair) { + if (pair && this._checkKeysValid(node, pair.values)) { let bSplice = false; // 把这个成对的属性剔除掉 pair.values.forEach((item: string) => { @@ -538,14 +549,10 @@ class CCInspector { } // todo path pairValues.forEach((el: string) => { - if (el in node) { - let propertyPath = [node.uuid, el]; - let vecData = this._genInfoData(node, el, propertyPath); - if (vecData) { - info && info.add(new Property(el, vecData)); - } - } else { - console.warn(`属性异常,节点丢失属性: ${el},请检查 pairProperty的设置`); + let propertyPath = [node.uuid, el]; + let vecData = this._genInfoData(node, el, propertyPath); + if (vecData) { + info && info.add(new Property(el, vecData)); } }); if (info) { diff --git a/source/src/inject/util.ts b/source/src/inject/util.ts index ee24c07..f78746b 100644 --- a/source/src/inject/util.ts +++ b/source/src/inject/util.ts @@ -1,8 +1,23 @@ -declare const cc:any; -export function isVersion3() { +declare const cc: any; + +export function isVersion3() { if (typeof cc.ENGINE_VERSION === "string") { const version: string = cc.ENGINE_VERSION; return version.startsWith("3.") } return false; } + +export function isHasProperty(base: Object, key: string): boolean { + let ret = Object.getOwnPropertyDescriptor(base, key) + if (ret) { + return true; + } else { + let proto = Object.getPrototypeOf(base); + if (proto) { + return isHasProperty(proto, key) + } else { + return false; + } + } +} diff --git a/source/src/manifest.json b/source/src/manifest.json index 84fbc8e..cab1fe0 100644 --- a/source/src/manifest.json +++ b/source/src/manifest.json @@ -1,6 +1,6 @@ { "manifest_version": 2, - "version": "1.1.0", + "version": "2.0.0", "name": "Cocos Creator Inspector", "description": "Cocos Creator Inspector", "permissions": [ diff --git a/source/src/popup/index.vue b/source/src/popup/index.vue index ca9a6af..5f05eee 100644 --- a/source/src/popup/index.vue +++ b/source/src/popup/index.vue @@ -20,7 +20,6 @@
-
@@ -30,6 +29,8 @@ +
+
ver:{{ version }}
@@ -38,6 +39,7 @@