dragonbones-runtime
Version:
the tools to build dragonbones file for diffrent framework
3 lines (2 loc) • 34 kB
JavaScript
var __extends=this&&this.__extends||function(d,b){for(var p in b)if(b.hasOwnProperty(p))d[p]=b[p];function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)};var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))(function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator["throw"](value))}catch(e){reject(e)}}function step(result){result.done?resolve(result.value):new P(function(resolve){resolve(result.value)}).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())})};var __generator=this&&this.__generator||function(thisArg,body){var _={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},f,y,t;return{next:verb(0),"throw":verb(1),"return":verb(2)};function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(_)try{if(f=1,y&&(t=y[op[0]&2?"return":op[0]?"throw":"next"])&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[0,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e];y=0}finally{f=t=0}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true}}};var __decorate=this&&this.__decorate||function(decorators,target,key,desc){var c=arguments.length,r=c<3?target:desc===null?desc=Object.getOwnPropertyDescriptor(target,key):desc,d;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)if(d=decorators[i])r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r;return c>3&&r&&Object.defineProperty(target,key,r),r};var RES;(function(RES){var ResourceNodeType;(function(ResourceNodeType){ResourceNodeType[ResourceNodeType["FILE"]=0]="FILE";ResourceNodeType[ResourceNodeType["DICTIONARY"]=1]="DICTIONARY"})(ResourceNodeType||(ResourceNodeType={}));function getResourceInfo(path){return FileSystem.getFile(path)}RES.getResourceInfo=getResourceInfo;var FileSystem;(function(FileSystem){FileSystem.data={};function addFile(filename,type){if(!type)type="";filename=normalize(filename);var basefilename=basename(filename);var folder=dirname(filename);if(!exists(folder)){mkdir(folder)}var d=reslove(folder);d[basefilename]={url:filename,type:type}}FileSystem.addFile=addFile;function getFile(filename){var result=reslove(filename);if(result){result.name=filename}return result}FileSystem.getFile=getFile;function basename(filename){return filename.substr(filename.lastIndexOf("/")+1)}function normalize(filename){return filename.split("/").filter(function(d){return!!d}).join("/")}function dirname(path){return path.substr(0,path.lastIndexOf("/"))}function reslove(dirpath){if(dirpath==""){return FileSystem.data}dirpath=normalize(dirpath);var list=dirpath.split("/");var current=FileSystem.data;for(var _i=0,list_1=list;_i<list_1.length;_i++){var f=list_1[_i];if(current){current=current[f]}else{return current}}return current}function mkdir(dirpath){dirpath=normalize(dirpath);var list=dirpath.split("/");var current=FileSystem.data;for(var _i=0,list_2=list;_i<list_2.length;_i++){var f=list_2[_i];if(!current[f]){current[f]={}}current=current[f]}}FileSystem.mkdir=mkdir;function exists(dirpath){if(dirpath=="")return true;dirpath=normalize(dirpath);var list=dirpath.split("/");var current=FileSystem.data;for(var _i=0,list_3=list;_i<list_3.length;_i++){var f=list_3[_i];if(!current[f]){return false}current=current[f]}return true}FileSystem.exists=exists})(FileSystem=RES.FileSystem||(RES.FileSystem={}))})(RES||(RES={}));var RES;(function(RES){var resourceTypeSelector;function mapConfig(url,rootSelector,typeSelector){return function(target){var type=typeSelector(url);if(typeof rootSelector=="string"){RES.resourceRoot=rootSelector}else{RES.resourceRoot=rootSelector()}if(RES.resourceRoot.lastIndexOf("/")!=0){RES.resourceRoot=RES.resourceRoot+"/"}RES.configItem={url:url,resourceRoot:RES.resourceRoot,type:type,name:url};resourceTypeSelector=typeSelector}}RES.mapConfig=mapConfig;var ResourceConfig=function(){function ResourceConfig(){RES["configInstance"]=this}ResourceConfig.prototype.getGroupByName=function(name,shouldNotBeNull){var group=this.config.groups[name];var result=[];if(!group){if(shouldNotBeNull){throw"none group "+name}return null}for(var _i=0,group_1=group;_i<group_1.length;_i++){var key=group_1[_i];var r=this.getResource(key,true);result.push(r)}return result};ResourceConfig.prototype.__temp__get__type__via__url=function(url_or_alias){var url=this.config.alias[url_or_alias];if(!url){url=url_or_alias}var ext=url.substr(url.lastIndexOf(".")+1);if(ext){ext=ext.toLowerCase()}if(resourceTypeSelector){var type=resourceTypeSelector(url);if(!type){throw new RES.ResourceManagerError(2004,url)}return type}else{console.warn("RES.mapConfig 并未设置 typeSelector");return"unknown"}};ResourceConfig.prototype.parseResKey=function(key){key=this.getKeyByAlias(key);var index=key.indexOf("#");if(index>=0){return{key:key.substr(0,index),subkey:key.substr(index+1)}}else{return{key:key,subkey:""}}};ResourceConfig.prototype.getKeyByAlias=function(aliasName){if(this.config.alias[aliasName]){return this.config.alias[aliasName]}else{return aliasName}};ResourceConfig.prototype.getResource=function(path_or_alias,shouldNotBeNull){var path=this.config.alias[path_or_alias];if(!path){path=path_or_alias}var r=RES.getResourceInfo(path);if(!r){if(shouldNotBeNull){throw"none resource url or alias : "+path_or_alias}return null}return r};ResourceConfig.prototype.getGroup=function(name){return this.getGroupByName(name)};ResourceConfig.prototype.createGroup=function(name,keys,override){if(override===void 0){override=false}if(!override&&this.config.groups[name]||!keys||keys.length==0){return false}var group=[];for(var _i=0,keys_1=keys;_i<keys_1.length;_i++){var key=keys_1[_i];if(this.config.groups[key]){var groupInfo=this.config.groups[key];group=group.concat(groupInfo)}else if(this.config.alias[key]||this.config.resources[key]){group=group.concat(key)}else{group=group.concat(key);console.warn("resource not exist : "+key)}}this.config.groups[name]=group;return true};ResourceConfig.prototype.parseConfig=function(data){var _this=this;this.config=data;var resource=data.resources;var loop=function(r,prefix,walk){for(var key in r){var p=prefix?prefix+"/"+key:key;var f=r[key];if(isFile(f)){if(typeof f==="string"){f={url:f,name:p};r[key]=f}else{f["name"]=p}walk(f)}else{loop(f,p,walk)}}};var isFile=function(r){return typeof r==="string"||r.url!=null};loop(resource,"",function(value){if(!value.type){value.type=_this.__temp__get__type__via__url(value.url)}});RES.FileSystem.data=data.resources};ResourceConfig.prototype.addSubkey=function(subkey,name){this.addAlias(subkey,name+"#"+subkey)};ResourceConfig.prototype.addAlias=function(alias,key){if(this.config.alias[key]){key=this.config.alias[key]}this.config.alias[alias]=key};ResourceConfig.prototype.getType=function(key){return this.getResource(key,true).type};ResourceConfig.prototype.addResourceData=function(data){if(!data.type){data.type=this.__temp__get__type__via__url(data.url)}RES.FileSystem.addFile(data.url,data.type);if(data.name){this.config.alias[data.name]=data.url}};ResourceConfig.prototype.destory=function(){this.config={groups:{},alias:{},resources:{}};RES.FileSystem.data={}};return ResourceConfig}();RES.ResourceConfig=ResourceConfig})(RES||(RES={}));var RES;(function(RES){var PromiseQueue=function(){function PromiseQueue(){}PromiseQueue.prototype.load=function(list,reporter){var current=0;var total=1;var mapper=function(r){return RES.host.load(r).then(function(response){RES.host.save(r,response);current++;if(reporter&&reporter.onProgress){reporter.onProgress(current,total)}return response})};if(list instanceof Array){total=list.length;return Promise.all(list.map(mapper))}else{return mapper(list)}};return PromiseQueue}();RES.PromiseQueue=PromiseQueue})(RES||(RES={}));var RES;(function(RES){var __tempCache={};var systemPid=0;RES.checkCancelation=function(target,propertyKey,descriptor){var method=descriptor.value;descriptor.value=function(){var arg=[];for(var _i=0;_i<arguments.length;_i++){arg[_i]=arguments[_i]}var currentPid=systemPid;var result=method.apply(this,arg);return result.then(function(value){if(systemPid!=currentPid){throw new ResourceManagerError(1005,arg[0])}else{return value}})}};function profile(){console.log(RES.FileSystem.data);console.log(__tempCache);var totalImageSize=0;for(var key in __tempCache){var img=__tempCache[key];if(img instanceof egret.Texture){totalImageSize+=img._bitmapWidth*img._bitmapHeight*4}}console.log("gpu size : "+(totalImageSize/1024).toFixed(3)+"kb")}RES.profile=profile;RES.host={get resourceConfig(){return manager.config},load:function(r,processor){if(!processor){processor=RES.host.isSupport(r)}if(!processor){throw new ResourceManagerError(2001,r.name,r.type)}return processor.onLoadStart(RES.host,r)},unload:function(r){var data=RES.host.get(r);if(!data){console.warn("尝试释放不存在的资源:",r.name);return Promise.resolve()}var processor=RES.host.isSupport(r);if(processor){return processor.onRemoveStart(RES.host,r).then(function(result){RES.host.remove(r);return result})}else{return Promise.resolve()}},save:function(resource,data){__tempCache[resource.url]=data},get:function(resource){return __tempCache[resource.url]},remove:function(resource){delete __tempCache[resource.url]},isSupport:function(resource){return RES.processor.isSupport(resource)}};var manager;(function(manager){manager.config=new RES.ResourceConfig;var queue=new RES.PromiseQueue;function init(){return RES.host.load(RES.configItem).then(function(data){manager.config.parseConfig(data)}).catch(function(e){if(!e.__resource_manager_error__){console.error(e.stack);e=new ResourceManagerError(1002)}return Promise.reject(e)})}manager.init=init;function load(resources,reporter){return queue.load(resources,reporter)}manager.load=load;function destory(){manager.config.destory();systemPid++}manager.destory=destory})(manager=RES.manager||(RES.manager={}));var ResourceManagerError=function(_super){__extends(ResourceManagerError,_super);function ResourceManagerError(code,replacer,replacer2){var _this=_super.call(this)||this;_this.__resource_manager_error__=true;_this.name=code.toString();_this.message=ResourceManagerError.errorMessage[code].replace("{0}",replacer).replace("{1}",replacer2);return _this}return ResourceManagerError}(Error);ResourceManagerError.errorMessage={1001:"文件加载失败:{0}",1002:"ResourceManager 初始化失败:配置文件加载失败",1005:"ResourceManager 已被销毁,文件加载失败:{0}",2001:"{0}解析失败,不支持指定解析类型:'{1}',请编写自定义 Processor ,更多内容请参见 https://github.com/egret-labs/resourcemanager/blob/master/docs/README.md#processor",2002:"Analyzer 相关API 在 ResourceManager 中不再支持,请编写自定义 Processor ,更多内容请参见 https://github.com/egret-labs/resourcemanager/blob/master/docs/README.md#processor",2003:"{0}解析失败,错误原因:{1}",2004:"无法找到文件类型:{0}"};RES.ResourceManagerError=ResourceManagerError})(RES||(RES={}));var RES;(function(RES){var processor;(function(processor_1){function isSupport(resource){return _map[resource.type]}processor_1.isSupport=isSupport;function map(type,processor){_map[type]=processor}processor_1.map=map;function promisify(loader,resource){return __awaiter(this,void 0,void 0,function(){var _this=this;return __generator(this,function(_a){return[2,new Promise(function(reslove,reject){var onSuccess=function(){var texture=loader["data"]?loader["data"]:loader["response"];reslove(texture)};var onError=function(){var e=new RES.ResourceManagerError(1001,resource.url);reject(e)};loader.addEventListener(egret.Event.COMPLETE,onSuccess,_this);loader.addEventListener(egret.IOErrorEvent.IO_ERROR,onError,_this)})]})})}function getRelativePath(url,file){url=url.split("\\").join("/");var params=url.match(/#.*|\?.*/);var paramUrl="";if(params){paramUrl=params[0]}var index=url.lastIndexOf("/");if(index!=-1){url=url.substring(0,index+1)+file}else{url=file}return url+paramUrl}processor_1.getRelativePath=getRelativePath;processor_1.ImageProcessor={onLoadStart:function(host,resource){return __awaiter(this,void 0,void 0,function(){var loader,prefix,bitmapData,texture;return __generator(this,function(_a){switch(_a.label){case 0:loader=new egret.ImageLoader;prefix=resource.extra?"":RES.resourceRoot;loader.load(prefix+resource.url);return[4,promisify(loader,resource)];case 1:bitmapData=_a.sent();texture=new egret.Texture;texture._setBitmapData(bitmapData);return[2,texture]}})})},onRemoveStart:function(host,resource){var texture=host.get(resource);texture.dispose();return Promise.resolve()}};processor_1.BinaryProcessor={onLoadStart:function(host,resource){return __awaiter(this,void 0,void 0,function(){var request,prefix,arraybuffer;return __generator(this,function(_a){switch(_a.label){case 0:request=new egret.HttpRequest;request.responseType=egret.HttpResponseType.ARRAY_BUFFER;prefix=resource.extra?"":RES.resourceRoot;request.open(prefix+resource.url,"get");request.send();return[4,promisify(request,resource)];case 1:arraybuffer=_a.sent();return[2,arraybuffer]}})})},onRemoveStart:function(host,resource){return Promise.resolve()}};processor_1.TextProcessor={onLoadStart:function(host,resource){return __awaiter(this,void 0,void 0,function(){var request,prefix,text;return __generator(this,function(_a){switch(_a.label){case 0:request=new egret.HttpRequest;request.responseType=egret.HttpResponseType.TEXT;prefix=resource.extra?"":RES.resourceRoot;request.open(prefix+resource.url,"get");request.send();return[4,promisify(request,resource)];case 1:text=_a.sent();return[2,text]}})})},onRemoveStart:function(host,resource){return Promise.resolve()}};processor_1.JsonProcessor={onLoadStart:function(host,resource){return __awaiter(this,void 0,void 0,function(){var text,data;return __generator(this,function(_a){switch(_a.label){case 0:return[4,host.load(resource,processor_1.TextProcessor)];case 1:text=_a.sent();data=JSON.parse(text);return[2,data]}})})},onRemoveStart:function(host,request){return Promise.resolve()}};processor_1.XMLProcessor={onLoadStart:function(host,resource){return __awaiter(this,void 0,void 0,function(){var text,data;return __generator(this,function(_a){switch(_a.label){case 0:return[4,host.load(resource,processor_1.TextProcessor)];case 1:text=_a.sent();data=egret.XML.parse(text);return[2,data]}})})},onRemoveStart:function(host,resource){return Promise.resolve()}};processor_1.CommonJSProcessor={onLoadStart:function(host,resource){return __awaiter(this,void 0,void 0,function(){var text,f,require,exports;return __generator(this,function(_a){switch(_a.label){case 0:return[4,host.load(resource,processor_1.TextProcessor)];case 1:text=_a.sent();f=new Function("require","exports",text);require=function(){};exports={};try{f(require,exports)}catch(e){throw new RES.ResourceManagerError(2003,resource.name,e.message)}return[2,exports]}})})},onRemoveStart:function(host,resource){return Promise.resolve()}};processor_1.SheetProcessor={onLoadStart:function(host,resource){return __awaiter(this,void 0,void 0,function(){var data,imagePath,r,texture,frames,spriteSheet,subkey,config,texture;return __generator(this,function(_a){switch(_a.label){case 0:return[4,host.load(resource,processor_1.JsonProcessor)];case 1:data=_a.sent();imagePath=getRelativePath(resource.name,data.file);r=host.resourceConfig.getResource(imagePath);if(!r){throw new RES.ResourceManagerError(1001,imagePath)}return[4,host.load(r)];case 2:texture=_a.sent();frames=data.frames;spriteSheet=new egret.SpriteSheet(texture);for(subkey in frames){config=frames[subkey];texture=spriteSheet.createTexture(subkey,config.x,config.y,config.w,config.h,config.offX,config.offY,config.sourceW,config.sourceH)}return[2,spriteSheet]}})})},getData:function(host,resource,key,subkey){var data=host.get(resource);if(data){return data.getTexture(subkey)}else{console.error("missing resource :"+resource.name);return null}},onRemoveStart:function(host,resource){return Promise.resolve()}};processor_1.FontProcessor={onLoadStart:function(host,resource){return __awaiter(this,void 0,void 0,function(){var getTexturePath,data,imageUrl,config,r,texture,font;return __generator(this,function(_a){switch(_a.label){case 0:getTexturePath=function(url,fntText){var file="";var lines=fntText.split("\n");var pngLine=lines[2];var index=pngLine.indexOf('file="');if(index!=-1){pngLine=pngLine.substring(index+6);index=pngLine.indexOf('"');file=pngLine.substring(0,index)}url=url.split("\\").join("/");var index=url.lastIndexOf("/");if(index!=-1){url=url.substring(0,index+1)+file}else{url=file}return url};return[4,host.load(resource,processor_1.TextProcessor)];case 1:data=_a.sent();imageUrl="";try{config=JSON.parse(data);imageUrl=getRelativePath(resource.name,config.file)}catch(e){config=data;imageUrl=getTexturePath(resource.name,data)}r=host.resourceConfig.getResource(imageUrl);if(!r)return[3,3];return[4,host.load(r)];case 2:texture=_a.sent();font=new egret.BitmapFont(texture,config);return[2,font];case 3:return[2,null]}})})},onRemoveStart:function(host,resource){return Promise.resolve()}};processor_1.SoundProcessor={onLoadStart:function(host,resource){return __awaiter(this,void 0,void 0,function(){var prefix,sound;return __generator(this,function(_a){switch(_a.label){case 0:prefix=resource.extra?"":RES.resourceRoot;sound=new egret.Sound;sound.load(prefix+resource.url);return[4,promisify(sound,resource)];case 1:_a.sent();return[2,sound]}})})},onRemoveStart:function(host,resource){return Promise.resolve()}};processor_1.MovieClipProcessor={onLoadStart:function(host,resource){return __awaiter(this,void 0,void 0,function(){var mcData,jsonPath,imagePath,r,mcTexture,mcDataFactory;return __generator(this,function(_a){switch(_a.label){case 0:return[4,host.load(resource,processor_1.JsonProcessor)];case 1:mcData=_a.sent();jsonPath=resource.name;imagePath=jsonPath.substring(0,jsonPath.lastIndexOf("."))+".png";r=host.resourceConfig.getResource(imagePath);if(!r){throw new RES.ResourceManagerError(1001,imagePath)}return[4,host.load(r)];case 2:mcTexture=_a.sent();mcDataFactory=new egret.MovieClipDataFactory(mcData,mcTexture);return[2,mcDataFactory]}})})},onRemoveStart:function(host,resource){return Promise.resolve()}};var PVRParser=function(){function PVRParser(){}PVRParser.parse=function(arrayBuffer,callback,errorCallback){var headerIntLength=13;var header=new Uint32Array(arrayBuffer,0,headerIntLength);var pvrDatas={buffer:arrayBuffer,header:header};if(header[0]===55727696){PVRParser._parseV3(pvrDatas,callback,errorCallback)}else if(header[11]===559044176){PVRParser._parseV2(pvrDatas,callback,errorCallback)}else{errorCallback(pvrDatas,"pvr parse error!")}};PVRParser._parseV2=function(pvrDatas,callback,errorCallback){var header=pvrDatas.header;var headerLength=header[0],height=header[1],width=header[2],numMipmaps=header[3],flags=header[4],dataLength=header[5],bpp=header[6],bitmaskRed=header[7],bitmaskGreen=header[8],bitmaskBlue=header[9],bitmaskAlpha=header[10],pvrTag=header[11],numSurfs=header[12];var TYPE_MASK=255;var PVRTC_2=24,PVRTC_4=25;var formatFlags=flags&TYPE_MASK;var bpp,format;var _hasAlpha=bitmaskAlpha>0;if(formatFlags===PVRTC_4){format=_hasAlpha?PVRParser.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:PVRParser.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;bpp=4}else if(formatFlags===PVRTC_2){format=_hasAlpha?PVRParser.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:PVRParser.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;bpp=2}else{errorCallback(pvrDatas,"pvr v2 parse error");console.log("unknow format flags::"+formatFlags)}var dataOffset=headerLength;pvrDatas.pvrtcData=new Uint8Array(pvrDatas.buffer,dataOffset);pvrDatas.bpp=bpp;pvrDatas.format=format;pvrDatas.width=width;pvrDatas.height=height;pvrDatas.surfacesCount=numSurfs;pvrDatas.mipmapsCount=numMipmaps+1;pvrDatas.isCubemap=pvrDatas.surfacesCount===6;callback(pvrDatas)};PVRParser._parseV3=function(pvrDatas,callback,errorCallback){var header=pvrDatas.header;var bpp,format;var pixelFormat=header[2];switch(pixelFormat){case 0:bpp=2;format=PVRParser.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;break;case 1:bpp=2;format=PVRParser.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;break;case 2:bpp=4;format=PVRParser.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;break;case 3:bpp=4;format=PVRParser.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;break;default:errorCallback(pvrDatas,"pvr v3 parse error");console.log("unknow pixel format::"+pixelFormat)}var dataOffset=52+header[12];pvrDatas.pvrtcData=new Uint8Array(pvrDatas.buffer,dataOffset);pvrDatas.bpp=bpp;pvrDatas.format=format;pvrDatas.width=header[7];pvrDatas.height=header[6];pvrDatas.surfacesCount=header[10];pvrDatas.mipmapsCount=header[11];pvrDatas.isCubemap=pvrDatas.surfacesCount===6;callback(pvrDatas)};return PVRParser}();PVRParser.COMPRESSED_RGB_PVRTC_4BPPV1_IMG=35840;PVRParser.COMPRESSED_RGB_PVRTC_2BPPV1_IMG=35841;PVRParser.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG=35842;PVRParser.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG=35843;if(egret&&egret["web"]&&egret["web"].WebGLRenderContext){function textureLevelSize(format,width,height){switch(format){case PVRParser.COMPRESSED_RGB_PVRTC_4BPPV1_IMG:case PVRParser.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:return Math.floor((Math.max(width,8)*Math.max(height,8)*4+7)/8);case PVRParser.COMPRESSED_RGB_PVRTC_2BPPV1_IMG:case PVRParser.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:return Math.floor((Math.max(width,16)*Math.max(height,8)*2+7)/8);default:return 0}}egret["web"].WebGLRenderContext.prototype.createTextureFromCompressedData=function(data,width,height,levels,internalFormat){var gl=this.context;if(!this.pvrtcExt){this.pvrtcExt=gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc")}var texture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,texture);var offset=0;for(var i=0;i<levels;++i){var levelSize=textureLevelSize(internalFormat,width,height);var dxtLevel=new Uint8Array(data.buffer,data.byteOffset+offset,levelSize);gl.compressedTexImage2D(gl.TEXTURE_2D,i,internalFormat,width,height,0,dxtLevel);width=width>>1;if(width<1)width=1;height=height>>1;if(height<1)height=1;offset+=levelSize}gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.LINEAR);gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR);return texture}}processor_1.PVRProcessor={onLoadStart:function(host,resource){return __awaiter(this,void 0,void 0,function(){var arraybuffer,width,height,borderWidth,borderHeight,byteArray,list,pvrDataBuffer,i,buffer,dataLength,self,texture;return __generator(this,function(_a){switch(_a.label){case 0:return[4,host.load(resource,processor_1.BinaryProcessor)];case 1:arraybuffer=_a.sent();width=512;height=512;borderWidth=0;borderHeight=0;byteArray=new egret.ByteArray(arraybuffer);byteArray.position=7;list=["body","ext"];for(i=0;i<list.length;i++){buffer=void 0;switch(list[i]){case"body":byteArray.position+=2;dataLength=byteArray.readUnsignedInt();pvrDataBuffer=byteArray.buffer.slice(byteArray.position,byteArray.position+dataLength);byteArray.position+=dataLength;break;case"ext":byteArray.position+=6;width=byteArray.readUnsignedShort();height=byteArray.readUnsignedShort();borderWidth=byteArray.readUnsignedShort();borderHeight=byteArray.readUnsignedShort();break}}self=this;PVRParser.parse(pvrDataBuffer,function(pvrData){var bitmapData=new egret.BitmapData(pvrData);bitmapData.format="pvr";texture=new egret.Texture;texture._setBitmapData(bitmapData);texture.$initData(borderWidth,borderHeight,width,height,0,0,width,height,bitmapData.width,bitmapData.height)},function(){console.log("pvr error")});return[2,texture]}})})},onRemoveStart:function(host,resource){return Promise.resolve()}};var _map={image:processor_1.ImageProcessor,json:processor_1.JsonProcessor,text:processor_1.TextProcessor,xml:processor_1.XMLProcessor,sheet:processor_1.SheetProcessor,font:processor_1.FontProcessor,bin:processor_1.BinaryProcessor,commonjs:processor_1.CommonJSProcessor,sound:processor_1.SoundProcessor,movieclip:processor_1.MovieClipProcessor,pvr:processor_1.PVRProcessor}})(processor=RES.processor||(RES.processor={}))})(RES||(RES={}));var RES;(function(RES){var ResourceEvent=function(_super){__extends(ResourceEvent,_super);function ResourceEvent(type,bubbles,cancelable){if(bubbles===void 0){bubbles=false}if(cancelable===void 0){cancelable=false}var _this=_super.call(this,type,bubbles,cancelable)||this;_this.itemsLoaded=0;_this.itemsTotal=0;_this.groupName="";return _this}ResourceEvent.dispatchResourceEvent=function(target,type,groupName,resItem,itemsLoaded,itemsTotal){if(groupName===void 0){groupName=""}if(resItem===void 0){resItem=undefined}if(itemsLoaded===void 0){itemsLoaded=0}if(itemsTotal===void 0){itemsTotal=0}var event=egret.Event.create(ResourceEvent,type);event.groupName=groupName;if(resItem){event.resItem=RES.ResourceItem.convertToResItem(resItem)}event.itemsLoaded=itemsLoaded;event.itemsTotal=itemsTotal;var result=target.dispatchEvent(event);egret.Event.release(event);return result};return ResourceEvent}(egret.Event);ResourceEvent.ITEM_LOAD_ERROR="itemLoadError";ResourceEvent.CONFIG_COMPLETE="configComplete";ResourceEvent.CONFIG_LOAD_ERROR="configLoadError";ResourceEvent.GROUP_PROGRESS="groupProgress";ResourceEvent.GROUP_COMPLETE="groupComplete";ResourceEvent.GROUP_LOAD_ERROR="groupLoadError";RES.ResourceEvent=ResourceEvent})(RES||(RES={}));var RES;(function(RES){var ResourceItem;(function(ResourceItem){ResourceItem.TYPE_XML="xml";ResourceItem.TYPE_IMAGE="image";ResourceItem.TYPE_BIN="bin";ResourceItem.TYPE_TEXT="text";ResourceItem.TYPE_JSON="json";ResourceItem.TYPE_SHEET="sheet";ResourceItem.TYPE_FONT="font";ResourceItem.TYPE_SOUND="sound";function convertToResItem(r){var name="";var config=RES["configInstance"];if(!config.config){name=r.url}else{for(var aliasName in config.config.alias){if(config.config.alias[aliasName]==r.url){name=aliasName}}}var result={name:name,url:r.url,type:r.type,data:r};return result}ResourceItem.convertToResItem=convertToResItem})(ResourceItem=RES.ResourceItem||(RES.ResourceItem={}))})(RES||(RES={}));var RES;(function(RES){RES.checkNull=function(target,propertyKey,descriptor){var method=descriptor.value;descriptor.value=function(){var arg=[];for(var _i=0;_i<arguments.length;_i++){arg[_i]=arguments[_i]}if(!arg[0]){console.warn("方法"+propertyKey+"的参数不能为null");return null}else{return method.apply(this,arg)}}};var upgrade;(function(upgrade){var _level="warning";function setUpgradeGuideLevel(level){_level=level}upgrade.setUpgradeGuideLevel=setUpgradeGuideLevel;upgrade.checkDecorator=function(target,propertyKey,descriptor){var method=descriptor.value;descriptor.value=function(){if(!RES["configItem"]){var url="config.resjs";RES.resourceRoot="resource/";RES["configItem"]={url:url,resourceRoot:RES.resourceRoot,type:"commonjs",name:url};if(_level=="warning"){console.warn("RES.loadConfig() 不再接受参数,强制访问 resource/config.resjs 文件\n","请访问以下站点了解更多细节\n","https://github.com/egret-labs/resourcemanager/blob/master/docs/README.md#upgrade-decorator ")}}return method.apply(this)}}})(upgrade=RES.upgrade||(RES.upgrade={}))})(RES||(RES={}));var RES;(function(RES){function registerAnalyzer(type,analyzerClass){throw new RES.ResourceManagerError(2002)}RES.registerAnalyzer=registerAnalyzer;function loadConfig(url,resourceRoot){return instance.loadConfig()}RES.loadConfig=loadConfig;function loadGroup(name,priority,reporter){if(priority===void 0){priority=0}return instance.loadGroup(name,priority,reporter)}RES.loadGroup=loadGroup;function isGroupLoaded(name){return instance.isGroupLoaded(name)}RES.isGroupLoaded=isGroupLoaded;function getGroupByName(name){return instance.getGroupByName(name).map(function(r){return RES.ResourceItem.convertToResItem(r)})}RES.getGroupByName=getGroupByName;function createGroup(name,keys,override){if(override===void 0){override=false}return instance.createGroup(name,keys,override)}RES.createGroup=createGroup;function hasRes(key){return instance.hasRes(key)}RES.hasRes=hasRes;function getRes(key){return instance.getRes(key)}RES.getRes=getRes;function getResAsync(key,compFunc,thisObject){return instance.getResAsync.apply(instance,arguments)}RES.getResAsync=getResAsync;function getResByUrl(url,compFunc,thisObject,type){if(type===void 0){type=""}instance.getResByUrl(url,compFunc,thisObject,type)}RES.getResByUrl=getResByUrl;function destroyRes(name,force){return instance.destroyRes(name,force)}RES.destroyRes=destroyRes;function setMaxLoadingThread(thread){instance.setMaxLoadingThread(thread)}RES.setMaxLoadingThread=setMaxLoadingThread;function setMaxRetryTimes(retry){instance.setMaxRetryTimes(retry)}RES.setMaxRetryTimes=setMaxRetryTimes;function addEventListener(type,listener,thisObject,useCapture,priority){if(useCapture===void 0){useCapture=false}if(priority===void 0){priority=0}instance.addEventListener(type,listener,thisObject,useCapture,priority)}RES.addEventListener=addEventListener;function removeEventListener(type,listener,thisObject,useCapture){if(useCapture===void 0){useCapture=false}instance.removeEventListener(type,listener,thisObject,useCapture)}RES.removeEventListener=removeEventListener;function $addResourceData(data){instance.addResourceData(data)}RES.$addResourceData=$addResourceData;var Resource=function(_super){__extends(Resource,_super);function Resource(){var _this=_super.call(this)||this;_this.loadedGroups=[];return _this}Resource.prototype.loadConfig=function(){var _this=this;return RES.manager.init().then(function(data){RES.ResourceEvent.dispatchResourceEvent(_this,RES.ResourceEvent.CONFIG_COMPLETE)},function(error){RES.ResourceEvent.dispatchResourceEvent(_this,RES.ResourceEvent.CONFIG_LOAD_ERROR);return Promise.reject(error)})};Resource.prototype.isGroupLoaded=function(name){return this.loadedGroups.indexOf(name)!=-1};Resource.prototype.getGroupByName=function(name){return RES.manager.config.getGroupByName(name)};Resource.prototype.loadGroup=function(name,priority,reporter){var _this=this;if(priority===void 0){priority=0}var reporterDelegate={onProgress:function(current,total){if(reporter&&reporter.onProgress){reporter.onProgress(current,total)}RES.ResourceEvent.dispatchResourceEvent(_this,RES.ResourceEvent.GROUP_PROGRESS,name,undefined,current,total)}};return this._loadGroup(name,priority,reporterDelegate).then(function(data){RES.ResourceEvent.dispatchResourceEvent(_this,RES.ResourceEvent.GROUP_COMPLETE,name)},function(error){RES.ResourceEvent.dispatchResourceEvent(_this,RES.ResourceEvent.GROUP_LOAD_ERROR,name);return Promise.reject(error)})};Resource.prototype._loadGroup=function(name,priority,reporter){if(priority===void 0){priority=0}var resources=RES.manager.config.getGroupByName(name);return RES.manager.load(resources,reporter)};Resource.prototype.createGroup=function(name,keys,override){if(override===void 0){override=false}return RES.manager.config.createGroup(name,keys,override)};Resource.prototype.hasRes=function(key){var name=RES.manager.config.parseResKey(key).key;return RES.manager.config.getResource(name)!=null};Resource.prototype.getRes=function(resKey){var _a=RES.manager.config.parseResKey(resKey),key=_a.key,subkey=_a.subkey;var r=RES.manager.config.getResource(key);if(r){var processor_2=RES.host.isSupport(r);if(processor_2&&processor_2.getData&&subkey){return processor_2.getData(RES.host,r,key,subkey)}else{return RES.host.get(r)}}};Resource.prototype.getResAsync=function(key,compFunc,thisObject){var paramKey=key;var _a=RES.manager.config.parseResKey(key),key=_a.key,subkey=_a.subkey;var r=RES.manager.config.getResource(key,true);return RES.manager.load(r).then(function(value){var processor=RES.host.isSupport(r);if(processor&&processor.getData&&subkey){value=processor.getData(RES.host,r,key,subkey);
}if(compFunc){compFunc.call(thisObject,value,paramKey)}return value})};Resource.prototype.getResByUrl=function(url,compFunc,thisObject,type){if(type===void 0){type=""}var r=RES.manager.config.getResource(url);if(!r){if(!type){type=RES.manager.config.__temp__get__type__via__url(url)}r={name:url,url:url,type:type,extra:true}}return RES.manager.load(r).then(function(value){if(compFunc&&r){compFunc.call(thisObject,value,r.url)}return value})};Resource.prototype.destroyRes=function(name,force){if(force===void 0){force=true}var group=RES.manager.config.getGroup(name);var remove=function(r){RES.host.unload(r)};if(group&&group.length>0){for(var _i=0,group_2=group;_i<group_2.length;_i++){var item=group_2[_i];remove(item)}return true}else{var item=RES.manager.config.getResource(name);if(item){remove(item);return true}else{console.warn("无法删除指定组:"+name);return false}}};Resource.prototype.setMaxLoadingThread=function(thread){if(thread<1){thread=1}};Resource.prototype.setMaxRetryTimes=function(retry){retry=Math.max(retry,0)};Resource.prototype.addResourceData=function(data){RES.manager.config.addResourceData(data)};return Resource}(egret.EventDispatcher);__decorate([RES.upgrade.checkDecorator,RES.checkCancelation],Resource.prototype,"loadConfig",null);__decorate([RES.checkCancelation],Resource.prototype,"_loadGroup",null);__decorate([RES.checkNull],Resource.prototype,"hasRes",null);__decorate([RES.checkNull],Resource.prototype,"getRes",null);__decorate([RES.checkNull,RES.checkCancelation],Resource.prototype,"getResAsync",null);__decorate([RES.checkNull,RES.checkCancelation],Resource.prototype,"getResByUrl",null);RES.Resource=Resource;var instance=new Resource})(RES||(RES={}));