2020-04-03 12:34:13 +00:00
|
|
|
|
const app = new Vue({
|
|
|
|
|
el: '#app',
|
|
|
|
|
vuetify: new Vuetify({
|
|
|
|
|
theme: { dark: true }
|
|
|
|
|
}),
|
|
|
|
|
data: {
|
2020-07-16 07:01:40 +00:00
|
|
|
|
isShowTop: true,
|
2020-04-03 12:34:13 +00:00
|
|
|
|
drawer: false,
|
2020-04-12 08:56:00 +00:00
|
|
|
|
cacheDialog: false,
|
|
|
|
|
cacheTitle: '',
|
|
|
|
|
cacheHeaders: [
|
|
|
|
|
{ text: 'Type', value: 'type' },
|
|
|
|
|
{ text: 'Name', value: 'name' },
|
|
|
|
|
{ text: 'Preivew', value: 'preview' },
|
|
|
|
|
{ text: 'ID', value: 'id' },
|
|
|
|
|
{ text: 'Content', value: 'content' },
|
|
|
|
|
{ text: 'Size', value: 'size' },
|
|
|
|
|
],
|
|
|
|
|
cacheRawData: [],
|
|
|
|
|
cacheData: [],
|
|
|
|
|
cacheSearchText: null,
|
|
|
|
|
cacheOnlyTexture: true,
|
2020-04-06 16:51:08 +00:00
|
|
|
|
treeData: [],
|
|
|
|
|
selectedNodes: [],
|
2020-04-03 12:34:13 +00:00
|
|
|
|
intervalId: -1,
|
2020-04-06 16:51:08 +00:00
|
|
|
|
treeSearchText: null,
|
2020-04-03 12:34:13 +00:00
|
|
|
|
nodeSchema: {},
|
|
|
|
|
componentsSchema: [],
|
|
|
|
|
},
|
|
|
|
|
created() {
|
2020-07-16 07:01:40 +00:00
|
|
|
|
if (window.innerHeight === window.outerHeight) { // 手机端,chrome device模式
|
|
|
|
|
this.isShowTop = false;
|
|
|
|
|
}
|
2020-04-07 12:45:38 +00:00
|
|
|
|
this.waitCCInit().then(() => {
|
2020-07-16 07:01:40 +00:00
|
|
|
|
if (this.isShowTop) {
|
|
|
|
|
this.startUpdateTree();
|
|
|
|
|
}
|
2020-04-07 12:45:38 +00:00
|
|
|
|
initConsoleUtil();
|
|
|
|
|
});
|
2020-04-03 12:34:13 +00:00
|
|
|
|
},
|
2020-04-12 08:56:00 +00:00
|
|
|
|
watch: {
|
|
|
|
|
cacheOnlyTexture() {
|
|
|
|
|
this.updateCacheData();
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-04-03 12:34:13 +00:00
|
|
|
|
computed: {
|
2020-04-06 16:51:08 +00:00
|
|
|
|
treeFilter() {
|
2020-04-03 12:34:13 +00:00
|
|
|
|
return (item, search, textKey) => item[textKey].indexOf(search) > -1;
|
|
|
|
|
},
|
2020-04-06 16:51:08 +00:00
|
|
|
|
selectedNode() {
|
|
|
|
|
if (!this.selectedNodes.length) return undefined
|
|
|
|
|
let node = getNodeById(this.selectedNodes[0]);
|
2020-04-03 12:34:13 +00:00
|
|
|
|
if (node) {
|
|
|
|
|
if (!node.hex_color) {
|
|
|
|
|
cc.js.getset(node, 'hex_color', () => {
|
|
|
|
|
return '#' + node.color.toHEX('#rrggbb');
|
|
|
|
|
}, (hex) => {
|
|
|
|
|
node.color = new cc.Color().fromHEX(hex);
|
|
|
|
|
}, false, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let superPreLoad = node._onPreDestroy;
|
|
|
|
|
node._onPreDestroy = () => {
|
|
|
|
|
superPreLoad.apply(node);
|
2020-04-06 16:51:08 +00:00
|
|
|
|
if (this.selectedNodes.length > 0 && this.selectedNodes[0] === node._id) {
|
|
|
|
|
this.selectedNodes.pop();
|
2020-04-03 12:34:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-06 16:51:08 +00:00
|
|
|
|
this.nodeSchema = NEX_CONFIG.nodeSchema.node2d;
|
2020-04-03 12:34:13 +00:00
|
|
|
|
let componentsSchema = [];
|
|
|
|
|
for (let component of node._components) {
|
|
|
|
|
let schema = NEX_CONFIG.componentsSchema[component.__classname__];
|
|
|
|
|
if (schema) {
|
|
|
|
|
node[schema.key] = node.getComponent(schema.key);
|
|
|
|
|
for (let i = 0; i < schema.rows.length; i++) {
|
2020-04-06 16:51:08 +00:00
|
|
|
|
if (schema.rows[i].type === 'color') {
|
|
|
|
|
if (!node[schema.key][schema.rows[i].key]) {
|
|
|
|
|
cc.js.getset(node[schema.key], schema.rows[i].key, () => {
|
|
|
|
|
return '#' + node.getComponent(schema.key)[schema.rows[i].rawKey].toHEX('#rrggbb');
|
|
|
|
|
}, (hex) => {
|
|
|
|
|
node.getComponent(schema.key)[schema.rows[i].rawKey] = new cc.Color().fromHEX(hex);
|
|
|
|
|
}, false, true);
|
2020-04-03 12:34:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
schema = {
|
|
|
|
|
title: component.__classname__,
|
|
|
|
|
key: component.__classname__
|
|
|
|
|
};
|
|
|
|
|
node[schema.key] = node.getComponent(schema.key);
|
|
|
|
|
}
|
|
|
|
|
componentsSchema.push(schema);
|
|
|
|
|
}
|
2020-04-06 16:51:08 +00:00
|
|
|
|
this.componentsSchema = componentsSchema;
|
2020-04-03 12:34:13 +00:00
|
|
|
|
}
|
2020-04-06 16:51:08 +00:00
|
|
|
|
return node;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2020-04-07 12:45:38 +00:00
|
|
|
|
waitCCInit() {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
let id = setInterval(() => {
|
|
|
|
|
if (window.cc) {
|
|
|
|
|
resolve();
|
|
|
|
|
clearInterval(id);
|
|
|
|
|
}
|
|
|
|
|
}, 500);
|
|
|
|
|
});
|
|
|
|
|
},
|
2020-04-06 16:51:08 +00:00
|
|
|
|
refreshTree: function () {
|
|
|
|
|
if (!this.$data.drawer || !window.cc || !cc.director.getScene() || !cc.director.getScene().children) return;
|
|
|
|
|
this.$data.treeData = getChildren(cc.director.getScene());
|
|
|
|
|
},
|
|
|
|
|
startUpdateTree: function () {
|
|
|
|
|
this.$data.intervalId = setInterval(() => {
|
|
|
|
|
this.refreshTree();
|
|
|
|
|
}, 200);
|
|
|
|
|
},
|
|
|
|
|
stopUpdateTree: function () {
|
|
|
|
|
clearInterval(this.$data.intervalId);
|
2020-04-03 12:34:13 +00:00
|
|
|
|
},
|
2020-04-07 12:45:38 +00:00
|
|
|
|
outputNodeHandler(id) {
|
|
|
|
|
let i = 1;
|
|
|
|
|
while (window['temp' + i] !== undefined) {
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
window['temp' + i] = this.selectedNode;
|
|
|
|
|
console.log('temp' + i);
|
|
|
|
|
console.log(window['temp' + i]);
|
|
|
|
|
},
|
|
|
|
|
outputComponentHandler(component) {
|
|
|
|
|
let i = 1;
|
|
|
|
|
while (window['temp' + i] !== undefined) {
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
window['temp' + i] = this.selectedNode.getComponent(component);
|
|
|
|
|
console.log('temp' + i);
|
|
|
|
|
console.log(window['temp' + i]);
|
|
|
|
|
},
|
|
|
|
|
drawNodeRect() {
|
|
|
|
|
cc.where(this.selectedNode);
|
|
|
|
|
},
|
2020-04-12 08:56:00 +00:00
|
|
|
|
updateCacheData() {
|
|
|
|
|
if (this.$data.cacheOnlyTexture) {
|
|
|
|
|
this.$data.cacheData = this.$data.cacheRawData.filter(item => item.content === 'cc.Texture2D');
|
|
|
|
|
} else {
|
|
|
|
|
this.$data.cacheData = this.$data.cacheRawData;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
openCacheDialog() {
|
|
|
|
|
[this.$data.cacheRawData, this.$data.cacheTitle] = cc.cache();
|
|
|
|
|
this.updateCacheData();
|
|
|
|
|
this.$data.cacheDialog = true;
|
|
|
|
|
},
|
2020-04-07 12:45:38 +00:00
|
|
|
|
openGithub() {
|
|
|
|
|
window.open('https://github.com/potato47/ccc-devtools');
|
|
|
|
|
},
|
2020-04-10 12:45:25 +00:00
|
|
|
|
openCocosForum() {
|
|
|
|
|
window.open('https://forum.cocos.com/');
|
|
|
|
|
},
|
|
|
|
|
openCocosDocs() {
|
|
|
|
|
window.open('https://docs.cocos.com/');
|
|
|
|
|
}
|
2020-04-03 12:34:13 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function getChildren(node) {
|
|
|
|
|
return node.children.map(child => {
|
|
|
|
|
let children = (child.children && child.children.length > 0) ? getChildren(child) : [];
|
|
|
|
|
return { id: child._id, name: child.name, active: child.activeInHierarchy, children };
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-04-06 16:51:08 +00:00
|
|
|
|
|
|
|
|
|
function getNodeById(id) {
|
|
|
|
|
let target;
|
|
|
|
|
const search = function (node) {
|
|
|
|
|
if (node._id === id) {
|
|
|
|
|
target = node;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (node.childrenCount) {
|
|
|
|
|
for (let i = 0; i < node.childrenCount; i++) {
|
|
|
|
|
if (!target) {
|
|
|
|
|
search(node.children[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const scene = cc.director.getScene();
|
|
|
|
|
search(scene);
|
|
|
|
|
return target;
|
|
|
|
|
}
|