mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-11-10 13:25:24 +00:00
.github
.idea
CocosCreatorInspector
cc-inspector
.vscode
doc
icons
src
core
ga
i18n
panel
scripts
background
content
inject
event.ts
index.ts
inspector.ts
setValue.ts
types.ts
util.ts
const.ts
terminal.ts
views
main.ts
test
.gitignore
README.en.md
README.md
README.zh.md
cc-plugin.config.ts
cc-plugin.json
crx-key.pem
package.json
tsconfig.json
yarn.lock
electron-app
hello-chrome
.gitignore
README.md
100 lines
2.2 KiB
TypeScript
100 lines
2.2 KiB
TypeScript
import { isVersion3 } from "./util";
|
||
|
||
interface ConfigItem {
|
||
path: string[],
|
||
func: Function;
|
||
}
|
||
|
||
const config: ConfigItem[] = [
|
||
{
|
||
path: ["position", "x"],
|
||
func: (target: any, value: any) => {
|
||
let pos = target.getPosition();
|
||
pos.x = value;
|
||
target.setPosition(pos);
|
||
}
|
||
},
|
||
{
|
||
path: ["position", "y"],
|
||
func: (target: any, value: any) => {
|
||
let pos = target.getPosition();
|
||
pos.y = value;
|
||
target.setPosition(pos);
|
||
}
|
||
},
|
||
{
|
||
path: ["position", "z"],
|
||
func: (target: any, value: any) => {
|
||
let pos = target.getPosition();
|
||
pos.z = value;
|
||
target.setPosition(pos);
|
||
}
|
||
},
|
||
{
|
||
path: ["scale", "x"],
|
||
func: ((target: any, value: any) => {
|
||
let scale = target.getScale();
|
||
scale.x = value;
|
||
target.setScale(scale);
|
||
})
|
||
},
|
||
{
|
||
path: ["scale", "y"],
|
||
func: ((target: any, value: any) => {
|
||
let scale = target.getScale();
|
||
scale.y = value;
|
||
target.setScale(scale);
|
||
})
|
||
},
|
||
{
|
||
path: ["scale", "z"],
|
||
func: ((target: any, value: any) => {
|
||
let scale = target.getScale();
|
||
scale.z = value;
|
||
target.setScale(scale);
|
||
})
|
||
}
|
||
]
|
||
|
||
// 3.x不允许直接设置xyz,需要走setPosition
|
||
export function trySetValueWithConfig(pathArray: string[], targetObject: any, targetValue: any) {
|
||
if (isVersion3()) {
|
||
let fullPath: string = pathArray.toString()
|
||
let item = config.find(el => {
|
||
return fullPath.endsWith(el.path.toString())
|
||
});
|
||
if (item) {
|
||
// 将多余的path去掉
|
||
let leftPathArray = [];
|
||
let max = pathArray.length - item.path.length;
|
||
for (let i = 0; i < max; i++) {
|
||
leftPathArray.push(pathArray[i])
|
||
}
|
||
|
||
let pathObjectValue = getValue(targetObject, leftPathArray);
|
||
if (pathObjectValue) {
|
||
try {
|
||
item.func(pathObjectValue, targetValue);
|
||
return true;
|
||
} catch (e) {
|
||
console.error(e);
|
||
return false
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
export function getValue(target: any, path: string[]) {
|
||
for (let i = 0; i < path.length; i++) {
|
||
let key = path[i];
|
||
if (target[key] !== undefined || target.hasOwnProperty(key)) {
|
||
target = target[key]
|
||
} else {
|
||
return null;
|
||
}
|
||
}
|
||
return target;
|
||
}
|