1 line
28 KiB
JavaScript
1 line
28 KiB
JavaScript
|
|
var __reflect=this&&this.__reflect||function(e,r,t){e.__class__=r,t?t.push(r):t=[r],e.__types__=e.__types__?t.concat(e.__types__):t},__extends=this&&this.__extends||function(e,r){function t(){this.constructor=e}for(var o in r)r.hasOwnProperty(o)&&(e[o]=r[o]);t.prototype=r.prototype,e.prototype=new t},__decorate=this&&this.__decorate||function(e,r,t,o){var n,i=arguments.length,a=3>i?r:null===o?o=Object.getOwnPropertyDescriptor(r,t):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,r,t,o);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(a=(3>i?n(a):i>3?n(r,t,a):n(r,t))||a);return i>3&&a&&Object.defineProperty(r,t,a),a},RES;!function(e){}(RES||(RES={}));var RES;!function(e){var r=function(){function r(){this.groupTotalDic={},this.numLoadedDic={},this.groupErrorDic={},this.retryTimesDic={},this.maxRetryTimes=3,this.reporterDic={},this.dispatcherDic={},this.failedList=new Array,this.loadItemErrorDic={},this.errorDic={},this.itemListPriorityDic={},this.itemLoadDic={},this.promiseHash={},this.lazyLoadList=new Array,this.loadingCount=0,this.thread=4}return r.prototype.pushResItem=function(e){if(this.promiseHash[e.root+e.name])return this.promiseHash[e.root+e.name];this.lazyLoadList.push(e),this.itemListPriorityDic[Number.NEGATIVE_INFINITY]=this.lazyLoadList,this.updatelistPriority(this.lazyLoadList,Number.NEGATIVE_INFINITY);var r=new egret.EventDispatcher;this.dispatcherDic[e.root+e.name]=r;var t=new Promise(function(e,t){r.addEventListener("complete",function(r){e(r.data)},null),r.addEventListener("error",function(e){t(e.data)},null)});return this.promiseHash[e.root+e.name]=t,this.loadNextResource(),t},r.prototype.pushResGroup=function(e,r,t,o){if(this.promiseHash[r])return this.promiseHash[r];for(var n=e.length,i=0;n>i;i++){var a=e[i];a.groupNames||(a.groupNames=[]),a.groupNames.push(r)}this.groupTotalDic[r]=e.length,this.numLoadedDic[r]=0,this.updatelistPriority(e,t),this.reporterDic[r]=o;var s=new egret.EventDispatcher;this.dispatcherDic[r]=s;var u=new Promise(function(e,r){s.addEventListener("complete",e,null),s.addEventListener("error",function(e){r(e.data)},null)});return this.promiseHash[r]=u,this.loadNextResource(),u},r.prototype.updatelistPriority=function(e,r){void 0==this.itemListPriorityDic[r]&&(this.itemListPriorityDic[r]=[]);for(var t=0,o=e;t<o.length;t++){var n=o[t];if(1!=this.itemLoadDic[n.root+n.name]){var i=this.findPriorityInDic(n);if(void 0==i)this.itemListPriorityDic[r].push(n);else if(r>i){this.itemListPriorityDic[r].push(n);var a=this.itemListPriorityDic[i].indexOf(n);this.itemListPriorityDic[i].splice(a,1)}}}},r.prototype.findPriorityInDic=function(e){for(var r in this.itemListPriorityDic)if(this.itemListPriorityDic[r].indexOf(e)>-1)return parseInt(r)},r.prototype.loadNextResource=function(){for(;this.loadingCount<this.thread;){var e=this.loadSingleResource();if(!e)break}},r.prototype.loadSingleResource=function(){var r=this,t=this.getOneResourceInfoInGroup();return t?(this.itemLoadDic[t.root+t.name]=1,this.loadingCount++,this.loadResource(t).then(function(o){if(r.loadingCount--,delete r.itemLoadDic[t.root+t.name],e.host.save(t,o),r.promiseHash[t.root+t.name]){var n=r.deleteDispatcher(t.root+t.name);n.dispatchEventWith("complete",!1,o)}var i=t.groupNames;if(i){delete t.groupNames;for(var a=0,s=i;a<s.length;a++){var u=s[a];r.setGroupProgress(u,t)&&r.loadGroupEnd(u)}}r.loadNextResource()})["catch"](function(o){if(!o)throw t.name+" load fail";if(!o.__resource_manager_error__)throw o;delete r.itemLoadDic[t.root+t.name],r.loadingCount--,delete e.host.state[t.root+t.name];var n=r.retryTimesDic[t.name]||1;if(!(n>r.maxRetryTimes))return r.retryTimesDic[t.name]=n+1,r.failedList.push(t),void r.loadNextResource();if(delete r.retryTimesDic[t.name],r.promiseHash[t.root+t.name]){var i=r.deleteDispatcher(t.root+t.name);i.dispatchEventWith("error",!1,{r:t,error:o})}var a=t.groupNames;if(a){delete t.groupNames;for(var s=0,u=a;s<u.length;s++){var c=u[s];r.loadItemErrorDic[c]||(r.loadItemErrorDic[c]=[]),-1==r.loadItemErrorDic[c].indexOf(t)&&r.loadItemErrorDic[c].push(t),r.groupErrorDic[c
|