mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-20 17:08:41 +00:00
优化设置值和readonly的判断逻辑
This commit is contained in:
parent
459bd643e6
commit
837649c15d
@ -64,19 +64,14 @@ class CCInspector {
|
||||
}
|
||||
case Msg.SetProperty: {
|
||||
const data: Info = pluginEvent.data;
|
||||
// path的设计有优化空间
|
||||
const uuid = data.path[0];
|
||||
const key = data.path[1];
|
||||
let value = data.data;
|
||||
if (data.type === DataType.Color) {
|
||||
// @ts-ignore
|
||||
value = cc.color().fromHEX(value);
|
||||
}
|
||||
|
||||
if (uuid && key) {
|
||||
this.setValue(uuid, key, value);
|
||||
this.setValue(data.path, value);
|
||||
this.sendMsgToContent(Msg.UpdateProperty, data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -431,26 +426,31 @@ class CCInspector {
|
||||
}
|
||||
|
||||
_isReadonly(base: Object, key: string): boolean {
|
||||
let obj = Object.getPrototypeOf(base);
|
||||
if (obj) {
|
||||
let ret = Object.getOwnPropertyDescriptor(obj, key)
|
||||
if (ret && ret.set) {
|
||||
return false;
|
||||
let ret = Object.getOwnPropertyDescriptor(base, key)
|
||||
if (ret) {
|
||||
return !(ret.set || ret.writable);
|
||||
} else {
|
||||
return this._isReadonly(obj, key)
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
let proto = Object.getPrototypeOf(base);
|
||||
return this._isReadonly(proto, key)
|
||||
}
|
||||
}
|
||||
|
||||
setValue(uuid: string, key: string, value: string) {
|
||||
let nodeOrComp = this.inspectorGameMemoryStorage[uuid];
|
||||
if (nodeOrComp && key in nodeOrComp) {
|
||||
if (this._isReadonly(nodeOrComp, key)) {
|
||||
setValue(pathArray: Array<string>, value: string) {
|
||||
let target = this.inspectorGameMemoryStorage;
|
||||
|
||||
for (let i = 0; i < pathArray.length; i++) {
|
||||
let path = pathArray[i];
|
||||
if (i === pathArray.length - 1) {
|
||||
// 到最后的key了
|
||||
if (this._isReadonly(target, path)) {
|
||||
console.warn(`值不允许修改`);
|
||||
} else {
|
||||
nodeOrComp[key] = value;
|
||||
target[path] = value;
|
||||
}
|
||||
} else {
|
||||
if (target.hasOwnProperty(path)) {
|
||||
target = target[path];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user