diff --git a/panel/panel.html b/panel/panel.html index 8e14e93..97325b7 100644 --- a/panel/panel.html +++ b/panel/panel.html @@ -1,8 +1,11 @@
+
{{items.length}} +
+
刷新中...
diff --git a/panel/panel.js b/panel/panel.js index 65da770..9c32c97 100644 --- a/panel/panel.js +++ b/panel/panel.js @@ -3,7 +3,6 @@ const Fs = require('fs'); const FFs = require('fire-fs'); -const Path = require('path'); const cp = require('child_process'); var PATH = { @@ -17,6 +16,7 @@ var createVM = function (elem) { el: elem, data: { resources: true, + isDone: false, input: "", items: [], ignore: null, @@ -30,9 +30,10 @@ var createVM = function (elem) { methods: { refresh() { + this.isDone = false; let adb = Editor.assetdb; let self = this; - let custIngnore = this.splitInput(this.input) + let custIngnore = this.splitInput(this.input); this.items.length = 0; this.items = []; @@ -42,70 +43,92 @@ var createVM = function (elem) { return; } - let json = null; - if (obj.type != 'bitmap-font') { - json = FFs.readJsonSync(obj.path); - } - else { - json = FFs.readFileSync(obj.path, 'utf-8'); + if (!obj.destPath) { + return; } + + let json = FFs.readFileSync(obj.destPath, 'utf-8'); - results.forEach(function (result) { - if (result.url.indexOf('/default_') !== -1) { + for (let i = 0; i < results.length; ++i) { + let result = results[i]; + if (result.hidden) { result.contain = true; - return; + continue; } for (let i = 0; i < custIngnore.length; i++) { if (result.url.indexOf(custIngnore[i]) !== -1) { result.contain = true; - return; + continue; } } - if ( - self.resources && - result.url.indexOf('db://assets/resources') !== -1 - ) { + if (self.resources && + result.url.indexOf('db://assets/resources') !== -1) { result.contain = true; - return; + continue; } - - if ( - (typeof json) === 'string' && - self.searchBf(json, result.url) - ) { - result.contain = true; - return; + + if (!result.jsonObj) { + result.jsonObj = FFs.readJsonSync(result.destPath); } - if ( - json['__type__'] === 'cc.AnimationClip' && - self.searchClip(json, result.uuid) - ) { - result.contain = true; - return; + if (result.jsonObj && result.jsonObj.content) { + if (result.jsonObj.content.atlas) { + result.contain = true; + continue; + } } + if (result.jsonObj && result.jsonObj.content) { + if (result.jsonObj.content.texture) { + if (json.indexOf(result.jsonObj.content.texture) > -1 && obj.type == 'spine') { + result.contain = true; + } + } + } - result.contain = - result.contain ? - true : - self.search(json, result.uuid); - }); + let isContain = json.indexOf(result.uuid) > -1; + result.contain = result.contain ? true : isContain; + } }); + let excludeSpriteFramesTexture = []; results.forEach(function (result) { - result.contain == true ? '' : self.items.push({ - url: result.url, - uuid: result.uuid - }); + if (result.contain) { + if (result.jsonObj) { + if (result.jsonObj.content) { + let atlasUuid = result.jsonObj.content.atlas; + let textureUuid =result.jsonObj.content.texture; + if (atlasUuid) { + if (excludeSpriteFramesTexture.indexOf(textureUuid) === -1) { + excludeSpriteFramesTexture.push(textureUuid); + } + } + } + } + } }); + + results.forEach(function (result) { + if (!result.contain) { + if (result.jsonObj) { + let uuid = result.jsonObj.content.texture; + if (excludeSpriteFramesTexture.indexOf(uuid) !== -1) { + console.error('exclude texture atlas ' + result.url); + return; + } + } + self.items.push({url: result.url, uuid: result.uuid}); + } + }); + + self.isDone = true; }; adb.queryAssets( null, - ['scene', 'prefab', 'animation-clip', 'bitmap-font'], + ['scene', 'prefab', 'animation-clip', 'bitmap-font', 'sprite-atlas', 'texture-packer', 'spine'], function (err, objs) { adb.queryAssets( null, @@ -114,143 +137,7 @@ var createVM = function (elem) { callback(objs, results); } ); - } - ); - }, - - /** - * Recursive - * @argument {JSON | Array} json - * @argument {String} uuid - */ - search(json, uuid) { - let self = this; - if (json instanceof Array) { - for (let i = 0; i < json.length; i++) { - if (self.search(json[i], uuid)) { - return true; - } - } - } - else if (json instanceof Object) { - if (json['__type__'] === 'cc.Sprite' && json._spriteFrame) { - return json._spriteFrame.__uuid__ == uuid; - } - else if (json['__type__'] === 'cc.Button') { - return self.searchButton(json, uuid); - } - else if (json['__type__'] && json['__type__'].length > 20) { - if (Editor.Utils.UuidUtils.isUuid( - Editor.Utils.UuidUtils.decompressUuid(json['__type__']) - )) { - return self.searchScript(json, uuid); - } - } - } - }, - - searchButton(json, uuid) { - return (json.pressedSprite && json.pressedSprite.__uuid__ == uuid) || - (json.hoverSprite && json.hoverSprite.__uuid__ == uuid) || - (json._N$normalSprite && json._N$normalSprite.__uuid__ == uuid) || - (json._N$disabledSprite && json._N$disabledSprite.__uuid__ == uuid); - }, - - /** - * Recursive - * - * Search for the script (cc.Class) in the scene file (.fire). - * - * @argument {JSON} json cc.Class - * @argument {String} uuid target.uuid - */ - searchScript(json, uuid) { - let result = []; - - for (let i in json) { - if (json[i] && json[i].__uuid__ && json[i].__uuid__ == uuid) { - return true; - } - } - - return false; - }, - - /** - * Recursive - * - * Search for the animation clip (cc.Animation). - * - * @argument {JSON} json cc.Animation - * @argument {String} uuid target.uuid - */ - searchClip(json, uuid) { - let self = this; - let spriteFrame = []; - let paths = this.getValue(json, 'paths'); - if (paths) { - for (let i in paths) { - spriteFrame = this.getValue(paths[i], 'spriteFrame'); - if (spriteFrame) { - for (let i = 0; i < spriteFrame.length; i++) { - if (spriteFrame[i] && spriteFrame[i].value && spriteFrame[i].value.__uuid__ && spriteFrame[i].value.__uuid__ === uuid) { - return true; - } - } - } - } - } - else { - spriteFrame = this.getValue(json, 'spriteFrame'); - if (spriteFrame) { - for (let i = 0; i < spriteFrame.length; i++) { - if (spriteFrame[i].value && spriteFrame[i].value.__uuid__ === uuid) { - return true; - } - } - } - } - - return false; - }, - - searchBf(str, url) { - let start = url.lastIndexOf('/') + 1; - // let end = url.lastIndexOf('.'); - let textureName = url.slice(start, url.length); - - if (str.indexOf(textureName) == -1) { - return false; - } - - return true; - }, - - /** - * .. - * @param {JSON} json - * @param {String} key - * @param {Boolean} pan 泛查询开关,因为这样叫比较酷 - */ - getValue(json, key, pan) { - key = key ? key : 'spriteFrame'; - if (typeof json !== 'object') { - return null; - } - - for (let i in json) { - if (i === key) { - return json[i]; - } - else { - let value = this.getValue(json[i], key); - if (value) { - return value; - } - } - - } - return null; + }); }, jumpRes(uuid) { @@ -302,7 +189,7 @@ var createVM = function (elem) { this.refresh(); } else { - let index = items.findIndex(function (item, index, array) { + let index = items.findIndex(function (item, index) { return self.getPicUrl(item.url) == url[0]; }); index == -1 ? '' : items.splice(index, 1); @@ -333,4 +220,4 @@ Editor.Panel.extend({ 'scene:ready'() { } } -}); \ No newline at end of file +});