find-assets/panel/index.js

13 lines
5.8 KiB
JavaScript
Raw Normal View History

2022-03-31 01:00:38 +00:00
var FS=require("fire-fs"),PATH=require("fire-path"),fse=require("fs-extra"),Scene=Editor.require("packages://find-assets/panel/scene"),$jscomp$compprop0={};
Editor.Panel.extend({style:FS.readFileSync(Editor.url("packages://find-assets/panel/less.css","utf8")),template:FS.readFileSync(Editor.url("packages://find-assets/panel/index.html","utf8")),$:{},ready:function(){window.plugin=new window.Vue({el:this.shadowRoot,created:function(){Editor.assetdb.queryAssets("db://assets/**/*","javascript",function(a,b){for(a=0;a<b.length;a++){var c=b[a].url.replace("db://assets/","");this.scriptsArr.push(c)}this.systemScripts="cc.Scene cc.Node cc.Sprite cc.Label cc.RichText cc.Layout cc.Button cc.ParticleSystem cc.ScrollView cc.PageView cc.ProgressBar cc.Toggle cc.EditBox cc.WebView cc.VideoPlayer".split(" ");
this.scriptsArr.push.apply(this.scriptsArr,this.systemScripts)}.bind(this))},data:{prefabUuid:"",compName:"",compNames:[],inputName:"",scriptsArr:[],systemScripts:[],assetUuid:"",nodeId:null,item:null,items:[],assetItems:[],nameItems:[],resultTip:"\u641c\u7d22\u7ed3\u679c",tips:"",isNeedParam:!1,paramName:"",paramValue:""},watch:{assetUuid:function(){this.searchByAsset()}},methods:{onNeedParam:function(){this.isNeedParam=!this.isNeedParam;this.paramValue=this.paramName=""},onRefresh:function(){this.inputName?
this.searchByName():this.assetUuid&&this.searchByAsset()},onSelected:function(){this.inputName=this.compName;this.searchByName()},onInputName:function(){this.inputName&&(this.compNames=this.fuzzyQuery(this.scriptsArr,this.inputName))},fuzzyQuery:function(a,b){b=new RegExp(b);for(var c=[],e=0;e<a.length;e++)b.test(a[e])&&c.push(a[e]);return c},onClean:function(){this.items=[];this.item=null;this.compName="";this.compNames=[];this.prefabUuid=this.tips=this.resultTip=this.assetUuid=this.inputName="";
this.isNeedParam=!1;this.paramValue=this.paramName=""},onDoubleSearch:function(){for(var a=[],b=0;b<this.assetItems.length;b++)for(var c=0;c<this.nameItems.length;c++)this.nameItems[c].scene==this.assetItems[b].scene&&this.nameItems[c].path==this.assetItems[b].path&&a.push(this.nameItems[c]);this.items=a;this.tips=this.getTips(this.assetName+" \u548c "+this.scriptName);this.resultTip=this.tips+" \u7684\u641c\u7d22\u7ed3\u679c";Editor.success(this.tips+"\u7684\u53cc\u6761\u4ef6\u67e5\u8be2\u7ed3\u675f")},
getTips:function(a){if(this.prefabUuid){var b=Editor.remote.assetdb.uuidToUrl(this.prefabUuid).split("/");return"\u5728"+b[b.length-1]+"\u4e0b"+a}return a},searchByAsset:function(){if(this.assetUuid){var a=Editor.assetdb.remote.uuidToUrl(this.assetUuid).split("/");this.assetName=a[a.length-1];this.tips=this.getTips(this.assetName);this.resultTip=this.tips+" \u7684\u641c\u7d22\u7ed3\u679c";this.assetItems=this.resourcePath(this.assetUuid)}},searchByName:function(){if(this.inputName)if(-1==this.systemScripts.indexOf(this.inputName)){var a=
this.inputName.split("/");this.scriptName=a[a.length-1];this.tips=this.getTips(this.scriptName);this.resultTip=this.tips+" \u7684\u641c\u7d22\u7ed3\u679c";this.nameItems=this.resourcePath(Editor.assetdb.remote.urlToUuid("db://assets/"+this.inputName))}else this.tips=this.getTips(this.inputName),this.resultTip=this.tips+" \u7684\u641c\u7d22\u7ed3\u679c",this.nameItems=this.resourcePath(this.inputName)},resourcePath:function(a){this.item=this.nodeId=null;var b=this.items=[],c=this.paramName,e=this.paramValue;
if(this.prefabUuid){var d=Editor.assetdb.remote.assetInfoByUuid(this.prefabUuid);d.destPath=Editor.assetdb.remote.loadMetaByUuid(this.prefabUuid).dests()[0];var h=Scene.search(d,a,c,e);0<h.length&&h.forEach(function(a){b.push({scene:PATH.basename(d.path),path:a.path,uuid:d.uuid,nodeId:a.uuid})});Editor.success(this.tips+"\u67e5\u8be2\u7ed3\u675f");return b}Editor.assetdb.queryAssets("db://assets/**/*","scene",function(d,g){g.forEach(function(d){var f=Scene.search(d,a,c,e);0<f.length&&f.forEach(function(a){b.push({scene:PATH.basename(d.path),
path:a.path,uuid:d.uuid,nodeId:a.uuid})})})});Editor.assetdb.queryAssets("db://assets/**/*","prefab",function(d,g){g.forEach(function(d){var f=Scene.search(d,a,c,e);0<f.length&&f.forEach(function(a){b.push({scene:PATH.basename(d.path),path:a.path,uuid:d.uuid,nodeId:a.uuid})})});Editor.success(this.tips+"\u67e5\u8be2\u7ed3\u675f")}.bind(this));return b},jumpRes:function(a){Editor.Ipc.sendToAll("assets:hint",a)},jumpScene:function(a){this.nodeId=a.nodeId;var b=a.uuid,c=Editor.remote.assetdb.uuidToUrl(b).split(".");
c=c[c.length-1];"prefab"==c?(this.item=a,Editor.Ipc.sendToAll("scene:enter-prefab-edit-mode",b)):"fire"==c&&Editor.Ipc.sendToMain("scene:open-by-uuid",b)},highlight:function(a){var b=this;a.nodeId?(Editor.Selection.select("node",a.nodeId),Editor.Ipc.sendToAll("hierarchy:hint",a.nodeId)):Editor.Ipc.sendToPanel("scene","scene:query-hierarchy",function(c,e,d){if(c)return Editor.error(c);if(c=a.path==d[0].name?d[0].id:b.getNodeIdByPath(a.path,d[0]))Editor.Selection.select("node",c),Editor.Ipc.sendToAll("hierarchy:hint",
c)})},getNodeIdByPath:function(a,b){var c=null,e=[],d=function(b,k){for(var g=k.children,l=0;l<g.length;l++){var f=g[l],h=b+k.name+"/"+f.name;e.push(h);if(a==h){c=f.id;break}f.children&&d(b+k.name+"/",f)}};d("",b);return c}}})},messages:($jscomp$compprop0.addLog=function(a,b){window.plugin.addLog(b)},$jscomp$compprop0["scene:ready"]=function(){var a=window.plugin.nodeId;a&&setTimeout(function(){Editor.Selection.select("node",a);Editor.Ipc.sendToAll("hierarchy:hint",a)},500);window.plugin.nodeId=null},
$jscomp$compprop0["scene:enter-prefab-edit-mode"]=function(){if(window.plugin&&window.plugin.item){var a=window.plugin.item;a&&setTimeout(function(){Editor.Ipc.sendToPanel("scene","scene:query-hierarchy",function(b,c,e){if(b)return Editor.error(b);if(b=a.path==e[0].name?e[0].id:window.plugin.getNodeIdByPath(a.path,e[0]))Editor.Selection.select("node",b),Editor.Ipc.sendToAll("hierarchy:hint",b)})},1E3);window.plugin.item=null}},$jscomp$compprop0)});