Files
esengine/demo/libs/framework_tiled/framework_tiled.min.js

1 line
32 KiB
JavaScript

window.es={},window.__extends=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])};return function(t,i){function r(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}();var __awaiter=this&&this.__awaiter||function(e,t,i,r){return new(i||(i=Promise))(function(n,a){function o(e){try{l(r.next(e))}catch(e){a(e)}}function s(e){try{l(r.throw(e))}catch(e){a(e)}}function l(e){e.done?n(e.value):new i(function(t){t(e.value)}).then(o,s)}l((r=r.apply(e,t||[])).next())})},__generator=this&&this.__generator||function(e,t){var i,r,n,a,o={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(i)throw new TypeError("Generator is already executing.");for(;o;)try{if(i=1,r&&(n=2&a[0]?r.return:a[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,a[1])).done)return n;switch(r=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(n=(n=o.trys).length>0&&n[n.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){o.label=a[1];break}if(6===a[0]&&o.label<n[1]){o.label=n[1],n=a;break}if(n&&o.label<n[2]){o.label=n[2],o.ops.push(a);break}n[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],r=0}finally{i=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}};!function(e){var t=function(t){function i(i,r,n){void 0===r&&(r=null),void 0===n&&(n=!0);var a=t.call(this)||this;return a.physicsLayer=new e.Ref(1),a.toContainer=!1,a.tiledMap=i,a._shouldCreateColliders=n,a.displayObject=new egret.DisplayObjectContainer,r&&(a.collisionLayer=i.tileLayers.find(function(e){return e.name==r})),a}return __extends(i,t),Object.defineProperty(i.prototype,"width",{get:function(){return this.tiledMap.width*this.tiledMap.tileWidth},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"height",{get:function(){return this.tiledMap.height*this.tiledMap.tileHeight},enumerable:!0,configurable:!0}),i.prototype.setLayerToRender=function(e){this.layerIndicesToRender=[],this.layerIndicesToRender[0]=this.getLayerIndex(e)},i.prototype.setLayersToRender=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.layerIndicesToRender=[];for(var i=0;i<e.length;i++)this.layerIndicesToRender[i]=this.getLayerIndex(e[i])},i.prototype.getLayerIndex=function(e){var t=this.tiledMap.getLayer(e);for(var i in this.tiledMap.layers)if(this.tiledMap.layers.hasOwnProperty(i)&&this.tiledMap.layers[i]==t)return 0;return-1},i.prototype.getRowAtWorldPosition=function(e){return e-=this.entity.transform.position.y+this._localOffset.y,this.tiledMap.worldToTilePositionY(e)},i.prototype.getColumnAtWorldPosition=function(e){return e-=this.entity.transform.position.x+this._localOffset.x,this.tiledMap.worldToTilePositionX(e)},i.prototype.onEntityTransformChanged=function(e){this._shouldCreateColliders&&e==transform.Component.position&&(this.removeColliders(),this.addColliders())},i.prototype.onAddedToEntity=function(){this.addColliders()},i.prototype.onRemovedFromEntity=function(){this.removeColliders()},i.prototype.update=function(){this.tiledMap.update()},i.prototype.render=function(t){if(this.sync(t),this.layerIndicesToRender)for(var i=0;i<this.tiledMap.layers.length;i++)this.tiledMap.layers[i].visible&&this.layerIndicesToRender.contains(i)&&e.TiledRendering.renderLayerRenderCamera(this.tiledMap.layers[i],this.toContainer?null:this.displayObject,e.Vector2.add(this.entity.transform.position,this._localOffset),this.transform.scale,this.renderLayer,t.bounds);else e.TiledRendering.renderMap(this.tiledMap,this.toContainer?null:this.displayObject,e.Vector2.add(this.entity.transform.position,this._localOffset),this.transform.scale,this.renderLayer);this.toContainer||(this.displayObject.cacheAsBitmap=!0,this.toContainer=!0)},i.prototype.addColliders=function(){if(this.collisionLayer&&this._shouldCreateColliders){var t=this.collisionLayer.getCollisionRectangles();this._colliders=[];for(var i=0;i<t.length;i++){var r=new e.BoxCollider(t[i].x+this._localOffset.x,t[i].y+this._localOffset.y,t[i].width,t[i].height);r.physicsLayer=this.physicsLayer,r.entity=this.entity,this._colliders[i]=r,e.Physics.addCollider(r)}}},i.prototype.removeColliders=function(){if(null!=this._colliders){for(var t=0,i=this._colliders;t<i.length;t++){var r=i[t];e.Physics.removeCollider(r)}this._colliders=null}},i}(e.RenderableComponent);e.TiledMapRenderer=t}(es||(es={})),function(e){var t=function(){return function(){}}();e.TmxGroup=t}(es||(es={})),function(e){var t=function(){return function(){}}();e.TmxImageLayer=t}(es||(es={})),function(e){var t=function(){function t(){}return Object.defineProperty(t.prototype,"offset",{get:function(){return new e.Vector2(this.offsetX,this.offsetY)},enumerable:!0,configurable:!0}),t.prototype.getTileWithGid=function(e){for(var t=0;t<this.tiles.length;t++)if(this.tiles[t]&&this.tiles[t].gid==e)return this.tiles[t];return null},t.prototype.getTile=function(e,t){return this.tiles[e+t*this.width]},t.prototype.getCollisionRectangles=function(){for(var e=new Array(this.tiles.length),t=[],i=-1,r=-1,n=0;n<this.map.height;n++){for(var a=0;a<this.map.width;a++){r=n*this.map.width+a;var o=this.getTile(a,n);o&&!e[r]?(i<0&&(i=a),e[r]=!0):o&&1!=e[r]||i>=0&&(t.push(this.findBoundsRect(i,a,n,e)),i=-1)}i>=0&&(t.push(this.findBoundsRect(i,this.map.width,n,e)),i=-1)}return t},t.prototype.findBoundsRect=function(t,i,r,n){for(var a=-1,o=r+1;o<this.map.height;o++)for(var s=t;s<i;s++){if(a=o*this.map.width+s,!this.getTile(s,o)||n[a]){for(var l=t;l<s;l++)n[a=o*this.map.width+l]=!1;return new e.Rectangle(t*this.map.tileWidth,r*this.map.tileHeight,(i-t)*this.map.tileWidth,(o-r)*this.map.tileHeight)}n[a]=!0}return new e.Rectangle(t*this.map.tileWidth,r*this.map.tileHeight,(i-t)*this.map.tileWidth,(this.map.height-r)*this.map.tileHeight)},t}();e.TmxLayer=t;var i=function(){function t(e,i,r,n){this.x=r,this.y=n;var a,o=i;a=0!=(o&t.FLIPPED_HORIZONTALLY_FLAG),this.horizontalFlip=a,a=0!=(o&t.FLIPPED_VERTICALLY_FLAG),this.verticalFlip=a,o&=~(t.FLIPPED_HORIZONTALLY_FLAG|t.FLIPPED_VERTICALLY_FLAG),this.gid=Math.floor(o),this.tileset=e.getTilesetForTileGid(this.gid)}return Object.defineProperty(t.prototype,"position",{get:function(){return new e.Vector2(this.x,this.y)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"tilesetTile",{get:function(){this._tilesetTileIndex||(this._tilesetTileIndex=-1,this.tileset.firstGid<=this.gid&&this.tileset.tiles.get(this.gid-this.tileset.firstGid)&&(this._tilesetTileIndex=this.gid-this.tileset.firstGid));return this._tilesetTileIndex<0?null:this.tileset.tiles.get(this._tilesetTileIndex)},enumerable:!0,configurable:!0}),t.FLIPPED_HORIZONTALLY_FLAG=2147483648,t.FLIPPED_VERTICALLY_FLAG=1073741824,t}();e.TmxLayerTile=i}(es||(es={})),function(e){var t=function(){return function(){this.tmxDirectory="resource/assets/"}}();e.TmxDocument=t;var i=function(){function e(){}return e.prototype.dispose=function(){this.bitmap&&(this.bitmap.dispose(),this.bitmap=null)},e}();e.TmxImage=i}(es||(es={})),function(e){var t=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return __extends(i,t),Object.defineProperty(i.prototype,"worldWidth",{get:function(){return this.width*this.tileWidth},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"worldHeight",{get:function(){return this.height*this.tileHeight},enumerable:!0,configurable:!0}),Object.defineProperty(i.prototype,"requiresLargeTileCulling",{get:function(){return this.maxTileHeight>this.tileHeight||this.maxTileWidth>this.tileWidth},enumerable:!0,configurable:!0}),i.prototype.getTilesetForTileGid=function(e){if(0==e)return null;for(var t=this.tilesets.length-1;t>=0;t--)if(this.tilesets[t].firstGid<=e)return this.tilesets[t];console.error("tile gid"+e+"未在任何tileset中找到")},i.prototype.worldToTilePositionX=function(t,i){void 0===i&&(i=!0);var r=Math.floor(t/this.tileWidth);return i?e.MathHelper.clamp(r,0,this.width-1):r},i.prototype.worldToTilePositionY=function(t,i){void 0===i&&(i=!0);var r=Math.floor(t/this.tileHeight);return i?e.MathHelper.clamp(r,0,this.height-1):r},i.prototype.getLayer=function(e){return this.layers[e]},i.prototype.update=function(){this.tilesets.forEach(function(e){e.update()})},i.prototype.dispose=function(e){void 0===e&&(e=!0),this._isDisposed||(e&&(this.tilesets.forEach(function(e){e.image&&e.image.dispose()}),this.imageLayers.forEach(function(e){e.image&&e.image.dispose()})),this._isDisposed=!0)},i}(e.TmxDocument);e.TmxMap=t,function(e){e[e.unknown=0]="unknown",e[e.orthogonal=1]="orthogonal",e[e.isometric=2]="isometric",e[e.staggered=3]="staggered",e[e.hexagonal=4]="hexagonal"}(e.OrientationType||(e.OrientationType={})),function(e){e[e.x=0]="x",e[e.y=1]="y"}(e.StaggerAxisType||(e.StaggerAxisType={})),function(e){e[e.odd=0]="odd",e[e.even=1]="even"}(e.StaggerIndexType||(e.StaggerIndexType={})),function(e){e[e.rightDown=0]="rightDown",e[e.rightUp=1]="rightUp",e[e.leftDown=2]="leftDown",e[e.leftUp=3]="leftUp"}(e.RenderOrderType||(e.RenderOrderType={}))}(es||(es={})),function(e){var t=function(){return function(){}}();e.TmxObjectGroup=t;var i=function(){return function(){this.shape=new egret.Shape,this.textField=new egret.TextField}}();e.TmxObject=i;var r=function(){return function(){}}();e.TmxText=r;var n=function(){return function(){}}();e.TmxAlignment=n,function(e){e[e.basic=0]="basic",e[e.point=1]="point",e[e.tile=2]="tile",e[e.ellipse=3]="ellipse",e[e.polygon=4]="polygon",e[e.polyline=5]="polyline",e[e.text=6]="text"}(e.TmxObjectType||(e.TmxObjectType={})),function(e){e[e.unkownOrder=-1]="unkownOrder",e[e.TopDown=0]="TopDown",e[e.IndexOrder=1]="IndexOrder"}(e.DrawOrderType||(e.DrawOrderType={})),function(e){e[e.left=0]="left",e[e.center=1]="center",e[e.right=2]="right",e[e.justify=3]="justify"}(e.TmxHorizontalAlignment||(e.TmxHorizontalAlignment={})),function(e){e[e.top=0]="top",e[e.center=1]="center",e[e.bottom=2]="bottom"}(e.TmxVerticalAlignment||(e.TmxVerticalAlignment={}))}(es||(es={})),function(e){var t=function(){function t(){}return t.loadTmxMap=function(e,t){var i=RES.getRes(t);return this.loadTmxMapData(e,i,RES.getResourceInfo(t))},t.loadTmxMapData=function(t,i,r){return __awaiter(this,void 0,void 0,function(){var n,a,o,s;return __generator(this,function(l){switch(l.label){case 0:t.version=i.version,t.tiledVersion=i.tiledversion,t.width=i.width,t.height=i.height,t.tileWidth=i.tilewidth,t.tileHeight=i.tileheight,t.hexSideLength=i.hexsidelength,t.orientation=this.parseOrientationType(i.orientation),t.staggerAxis=this.parseStaggerAxisType(i.staggeraxis),t.staggerIndex=this.parseStaggerIndexType(i.staggerindex),t.renderOrder=this.parseRenderOrderType(i.renderorder),t.nextObjectID=i.nextobjectid,t.backgroundColor=e.TmxUtils.color16ToUnit(i.color),t.properties=this.parsePropertyDict(i.properties),t.maxTileWidth=t.tileWidth,t.maxTileHeight=t.tileHeight,t.tmxDirectory=r.root+r.url.replace(".","_").replace(r.name,""),t.tilesets=[],n=0,a=i.tilesets,l.label=1;case 1:return n<a.length?(o=a[n],[4,this.parseTmxTileset(t,o)]):[3,4];case 2:s=l.sent(),t.tilesets.push(s),this.updateMaxTileSizes(s),l.label=3;case 3:return n++,[3,1];case 4:return t.layers=[],t.tileLayers=[],t.objectGroups=[],t.imageLayers=[],t.groups=[],this.parseLayers(t,i,t,t.width,t.height,t.tmxDirectory),[2,t]}})})},t.parseLayers=function(t,i,r,n,a,o){return __awaiter(this,void 0,void 0,function(){var s,l,h,p,c,u,d,g;return __generator(this,function(m){switch(m.label){case 0:s=0,l=ObjectUtils.elements(i).where(function(e){return"tilelayer"==e.type||"objectgroup"==e.type||"imagelayer"==e.type||"group"==e.type}),m.label=1;case 1:if(!(s<l.length))return[3,11];switch(h=l[s],p=void 0,h.type){case"tilelayer":return[3,2];case"objectgroup":return[3,3];case"imagelayer":return[3,4];case"group":return[3,6]}return[3,8];case 2:return c=this.loadTmxLayer(new e.TmxLayer,r,h,n,a),p=c,(t instanceof e.TmxMap||t instanceof e.TmxGroup)&&t.tileLayers.push(c),[3,9];case 3:return u=this.loadTmxObjectGroup(new e.TmxObjectGroup,r,h),p=u,(t instanceof e.TmxMap||t instanceof e.TmxGroup)&&t.objectGroups.push(u),[3,9];case 4:return[4,this.loadTmxImageLayer(new e.TmxImageLayer,r,h,o)];case 5:return d=m.sent(),p=d,(t instanceof e.TmxMap||t instanceof e.TmxGroup)&&t.imageLayers.push(d),[3,9];case 6:return[4,this.loadTmxGroup(new e.TmxGroup,r,h,n,a,o)];case 7:return g=m.sent(),p=g,(t instanceof e.TmxMap||t instanceof e.TmxGroup)&&t.groups.push(g),[3,9];case 8:throw new Error("无效的操作");case 9:(t instanceof e.TmxMap||t instanceof e.TmxGroup)&&t.layers.push(p),m.label=10;case 10:return s++,[3,1];case 11:return[2]}})})},t.loadTmxGroup=function(e,t,i,r,n,a){return __awaiter(this,void 0,void 0,function(){return __generator(this,function(o){switch(o.label){case 0:return e.map=t,e.name=null!=i.name?i.name:"",e.opacity=null!=i.opacity?i.opacity:1,e.visible=null==i.visible||i.visible,e.offsetX=null!=i.offsetx?i.offsetx:0,e.offsetY=null!=i.offsety?i.offsety:0,e.properties=this.parsePropertyDict(i.properties),e.layers=[],e.tileLayers=[],e.objectGroups=[],e.imageLayers=[],e.groups=[],[4,this.parseLayers(e,i,t,r,n,a)];case 1:return o.sent(),[2,e]}})})},t.loadTmxImageLayer=function(t,i,r,n){return __awaiter(this,void 0,void 0,function(){var a,o;return __generator(this,function(s){switch(s.label){case 0:return t.map=i,t.name=r.name,t.width=r.width,t.height=r.height,t.visible=null==r.visible||r.visible,t.opacity=null!=r.opacity?r.opacity:1,t.offsetX=null!=r.offsetx?r.offsetx:0,t.offsetY=null!=r.offsety?r.offsety:0,(a=r.image)?(o=t,[4,this.loadTmxImage(new e.TmxImage,a,n)]):[3,2];case 1:o.image=s.sent(),s.label=2;case 2:return t.properties=this.parsePropertyDict(r.properties),[2,t]}})})},t.loadTmxLayer=function(i,r,n,a,o){i.map=r,i.name=n.name,i.opacity=null!=n.opacity?n.opacity:1,i.visible=null==n.visible||n.visible,i.offsetX=null!=n.offsetx?n.offsetx:0,i.offsetY=null!=n.offsety?n.offsety:0,i.width=n.width,i.height=n.height;var s=n.data,l=null!=s.encoding?s.encoding:"csv";if(i.tiles=new Array(a*o),"base64"==l)for(var h=e.TmxUtils.decode(s.toString(),l,s.compression),p=0,c=0;c<o;c++)for(var u=0;u<a;u++){var d=h[p];i.tiles[p++]=0!=d?new e.TmxLayerTile(r,d,u,c):null}else if("csv"==l)for(var g=0,m=0,f=s;m<f.length;m++){d=f[m];var x=g%a,y=g/a;i.tiles[g++]=0!=d?new e.TmxLayerTile(r,d,x,y):null}else{if(l)throw new Error("TmxLayer:未知编码");g=0;for(var T=0,b=s.tile;T<b.length;T++){var w=b[T];d=null!=w.gid?w.gid:0,x=g%a,y=g/a;i.tiles[g++]=0!=d?new e.TmxLayerTile(r,d,x,y):null}}return i.properties=t.parsePropertyDict(n.properties),i},t.updateMaxTileSizes=function(e){e.tiles.forEach(function(t){t.image&&(t.image.width>e.map.maxTileWidth&&(e.map.maxTileWidth=t.image.width),t.image.height>e.map.maxTileHeight&&(e.map.maxTileHeight=t.image.height))}),e.tileRegions.forEach(function(t){var i=t.width,r=t.height;i>e.map.maxTileWidth&&(e.map.maxTileWidth=i),i>e.map.maxTileHeight&&(e.map.maxTileHeight=r)})},t.parseOrientationType=function(t){return"unknown"==t?e.OrientationType.unknown:"orthogonal"==t?e.OrientationType.orthogonal:"isometric"==t?e.OrientationType.isometric:"staggered"==t?e.OrientationType.staggered:"hexagonal"==t?e.OrientationType.hexagonal:e.OrientationType.unknown},t.parseStaggerAxisType=function(t){return"y"==t?e.StaggerAxisType.y:e.StaggerAxisType.x},t.parseStaggerIndexType=function(t){return"even"==t?e.StaggerIndexType.even:e.StaggerIndexType.odd},t.parseRenderOrderType=function(t){return"right-up"==t?e.RenderOrderType.rightUp:"left-down"==t?e.RenderOrderType.leftDown:"left-up"==t?e.RenderOrderType.leftUp:e.RenderOrderType.rightDown},t.parsePropertyDict=function(t){if(!t)return null;for(var i=new Map,r=0,n=t;r<n.length;r++){var a=n[r],o=a.name,s=a.value;"color"==a.type?i.set(o,e.TmxUtils.color16ToUnit(s).toString()):i.set(o,s)}return i},t.parseTmxTileset=function(t,i){return __awaiter(this,void 0,void 0,function(){var r,n,a,o;return __generator(this,function(s){switch(s.label){case 0:return r=i.firstgid,n=r,null==(a=i.source)?[3,2]:(a=t.tmxDirectory+a,[4,RES.getResByUrl(a).catch(function(e){throw new Error(e)})]);case 1:return o=s.sent(),[2,this.loadTmxTileset(new e.TmxTileset,t,o.tileset,n)];case 2:return[2,this.loadTmxTileset(new e.TmxTileset,t,i,n)]}})})},t.loadTmxTileset=function(t,i,r,n){return __awaiter(this,void 0,void 0,function(){var a,o,s,l,h,p,c,u,d,g,m,f,x;return __generator(this,function(y){switch(y.label){case 0:return t.map=i,t.firstGid=n,t.name=r.name,t.tileWidth=r.tilewidth,t.tileHeight=r.tileheight,t.spacing=null!=r.spacing?r.spacing:0,t.margin=null!=r.margin?r.margin:0,t.columns=r.columns,t.tileCount=r.tilecount,t.tileOffset=this.parseTmxTileOffset(r.tileoffset),r.image?[4,this.loadTmxImage(new e.TmxImage,r,i.tmxDirectory).then(function(e){t.image=e}).catch(function(e){throw new Error(e)})]:[3,2];case 1:y.sent(),y.label=2;case 2:if(t.terrains=[],r.terrains)for(a=0,o=r.terrains;a<o.length;a++)s=o[a],t.terrains.push(this.parseTmxTerrain(s));for(h in t.tiles=new Map,l=[],r.tiles)l.push(h);p=0,y.label=3;case 3:return p<l.length?(c=l[p],r.tiles.hasOwnProperty(c)?(u=r.tiles[c],[4,this.loadTmxTilesetTile(new e.TmxTilesetTile,t,u,t.terrains,i.tmxDirectory)]):[3,5]):[3,6];case 4:d=y.sent(),t.tiles.set(null==d.id?Number(c)+1:d.id,d),y.label=5;case 5:return p++,[3,3];case 6:if(t.properties=this.parsePropertyDict(r.properties),t.tileRegions=new Map,t.image)for(g=n,m=t.margin;m<t.image.height-t.margin;m+=t.tileHeight+t.spacing)for(f=0,x=t.margin;x<t.image.width-t.margin&&(t.tileRegions.set(g++,new e.Rectangle(x,m,t.tileWidth,t.tileHeight)),!(++f>=t.columns));x+=t.tileWidth+t.spacing);else t.tiles.forEach(function(i,r){t.tileRegions.set(r,new e.Rectangle(0,0,i.image.width,i.image.height))});return[2,t]}})})},t.loadTmxTilesetTile=function(t,i,r,n,a){return __awaiter(this,void 0,void 0,function(){var o,s,l,h,p,c,u,d,g,m,f,x,y;return __generator(this,function(T){switch(T.label){case 0:if(t.tileset=i,t.id=r.id,o=r.terrain)for(t.terrainEdges=new Array(4),s=0,l=0,h=o;l<h.length;l++)p=h[l],c=n[p],t.terrainEdges[s++]=c;return t.probability=null!=r.probability?r.probability:1,t.type=r.type,(u=r.image)?(d=t,[4,this.loadTmxImage(new e.TmxImage,u,a)]):[3,2];case 1:d.image=T.sent(),T.label=2;case 2:if(t.objectGroups=[],r.objectgroup)for(g=0,m=r.objectgroup;g<m.length;g++)y=m[g],t.objectGroups.push(this.loadTmxObjectGroup(new e.TmxObjectGroup,i.map,y));if(t.animationFrames=[],r.animation)for(f=0,x=r.animation.frame;f<x.length;f++)y=x[f],t.animationFrames.push(this.loadTmxAnimationFrame(new e.TmxAnimationFrame,y));return t.properties=this.parsePropertyDict(r.properties),t.properties&&t.processProperties(),[2,t]}})})},t.loadTmxAnimationFrame=function(e,t){return e.gid=t.tileid,e.duration=t.duration/1e3,e},t.loadTmxObjectGroup=function(t,i,r){t.map=i,t.name=null!=r.name?r.name:"",t.color=e.TmxUtils.color16ToUnit(r.color),t.opacity=null!=r.opacity?r.opacity:1,t.visible=null==r.visible||r.visible,t.offsetX=null!=r.offsetx?r.offsetx:0,t.offsetY=null!=r.offsety?r.offsety:0;var n=new Map;n.set("unknown",e.DrawOrderType.unkownOrder),n.set("topdown",e.DrawOrderType.IndexOrder),n.set("index",e.DrawOrderType.TopDown);var a=r.draworder;a&&(t.drawOrder=n.get(a)),t.objects=[];for(var o=0,s=r.objects;o<s.length;o++){var l=s[o];t.objects.push(this.loadTmxObject(new e.TmxObject,i,l))}return t.properties=this.parsePropertyDict(r.properties),t},t.loadTmxObject=function(t,i,r){t.id=null!=r.id?r.id:0,t.name=null!=r.name?r.name:"",t.x=r.x,t.y=r.y,t.width=null!=r.width?r.width:0,t.height=null!=r.height?r.height:0,t.type=null!=r.type?r.type:"",t.visible=null==r.visible||r.visible,t.rotation=null!=r.rotation?r.rotation:0;var n=r.gid,a=r.ellipse,o=r.polygon,s=r.polyline,l=r.text,h=r.point;return n?(t.tile=new e.TmxLayerTile(i,n,Math.round(t.x),Math.round(t.y)),t.objectType=e.TmxObjectType.tile):a?t.objectType=e.TmxObjectType.ellipse:o?(t.points=this.parsePoints(o),t.objectType=e.TmxObjectType.polygon):s?(t.points=this.parsePoints(s),t.objectType=e.TmxObjectType.polyline):l?(t.text=this.loadTmxText(new e.TmxText,l),t.objectType=e.TmxObjectType.text):t.objectType=h?e.TmxObjectType.point:e.TmxObjectType.basic,t.properties=this.parsePropertyDict(r.properties),t},t.loadTmxText=function(t,i){return t.fontFamily=null!=i.fontfamily?i.fontfamily:"sans-serif",t.pixelSize=null!=i.pixelsize?i.pixelsize:16,t.wrap=null!=i.wrap&&i.wrap,t.color=e.TmxUtils.color16ToUnit(i.color),t.bold=!!i.bold&&i.bold,t.italic=!!i.italic&&i.italic,t.underline=!!i.underline&&i.underline,t.strikeout=!!i.strikeout&&i.strikeout,t.kerning=!i.kerning||i.kerning,t.alignment=this.loadTmxAlignment(new e.TmxAlignment,i),t.value=i,t},t.loadTmxAlignment=function(t,i){function r(e){return e&&""!=e?e[0].toString().toUpperCase()+e.substr(1):e}var n=null!=i.halign?i.halign:"left";t.horizontal=e.TmxHorizontalAlignment[r(n)];var a=null!=i.valign?i.valign:"top";return t.vertical=e.TmxVerticalAlignment[r(a)],t},t.parsePoints=function(e){for(var t=[],i=0,r=0,n=e;r<n.length;r++){var a=n[r];t[i++]=this.parsePoint(a)}return t},t.parsePoint=function(t){return new e.Vector2(t.x,t.y)},t.parseTmxTerrain=function(t){var i=new e.TmxTerrain;return i.name=t.name,i.tile=t.tile,i.properties=this.parsePropertyDict(t.properties),i},t.parseTmxTileOffset=function(t){var i=new e.TmxTileOffset;return t?(i.x=t.x,i.y=t.y,i):(i.x=0,i.y=0,i)},t.loadTmxImage=function(t,i,r){return __awaiter(this,void 0,void 0,function(){var n,a;return __generator(this,function(o){switch(o.label){case 0:return n=i.image,t.source=null!=n?r+n:r+i,[4,RES.getResByUrl(t.source,null,this,RES.ResourceItem.TYPE_IMAGE).catch(function(e){throw new Error(e)})];case 1:return a=o.sent(),t.bitmap=new egret.SpriteSheet(a),t.trans=e.TmxUtils.color16ToUnit(i.trans),t.width=null!=i.imagewidth?i.imagewidth:a.textureWidth,t.height=null!=i.imageheight?i.imageheight:a.textureHeight,[2,t]}})})},t}();e.TiledMapLoader=t}(es||(es={})),function(e){var t=egret.Bitmap,i=function(){function i(){}return i.renderMap=function(t,i,r,n,a){var o=this;t.layers.forEach(function(t){t instanceof e.TmxLayer&&t.visible?o.renderLayer(t,i,r,n,a):t instanceof e.TmxImageLayer&&t.visible?o.renderImageLayer(t,i,r,n,a):t instanceof e.TmxGroup&&t.visible?o.renderGroup(t,i,r,n,a):t instanceof e.TmxObjectGroup&&t.visible&&o.renderObjectGroup(t,i,r,n,a)})},i.renderLayer=function(t,i,r,n,a){if(t.visible)for(var o=t.map.tileWidth*n.x,s=t.map.tileHeight*n.y,l=e.DrawUtils.getColorMatrix(16777215),h=0;h<t.tiles.length;h++){var p=t.tiles[h];p&&this.renderTile(p,i,r,n,o,s,l,a)}},i.renderLayerRenderCamera=function(t,i,r,n,a,o){t instanceof e.TmxLayer&&t.visible?this.renderLayerCamera(t,i,r,n,a,o):t instanceof e.TmxImageLayer&&t.visible?this.renderImageLayer(t,i,r,n,a):t instanceof e.TmxGroup&&t.visible?this.renderGroup(t,i,r,n,a):t instanceof e.TmxObjectGroup&&t.visible&&this.renderObjectGroup(t,i,r,n,a)},i.renderLayerCamera=function(t,i,r,n,a,o){if(t.visible){r=r.add(t.offset),o.location=o.location.subtract(r);var s,l,h,p=t.map.tileWidth*n.x,c=t.map.tileHeight*n.y,u=0;t.map.requiresLargeTileCulling?(s=t.map.worldToTilePositionX(o.left-(t.map.maxTileWidth*n.x-p)),l=t.map.worldToTilePositionY(o.top-(t.map.maxTileHeight*n.y-c)),h=t.map.worldToTilePositionX(o.right+(t.map.maxTileWidth*n.x-p)),u=t.map.worldToTilePositionY(o.bottom+(t.map.maxTileHeight*n.y-c))):(s=t.map.worldToTilePositionX(o.left),l=t.map.worldToTilePositionY(o.top),h=t.map.worldToTilePositionX(o.right),u=t.map.worldToTilePositionY(o.bottom));for(var d=e.DrawUtils.getColorMatrix(16777215),g=l;g<=u;g++)for(var m=s;m<=h;m++){var f=t.getTile(m,g);f&&this.renderTile(f,i,r,n,p,c,d,a)}}},i.renderImageLayer=function(t,i,r,n,a){if(t.visible){var o=e.DrawUtils.getColorMatrix(16777215),s=e.Vector2.add(r,new e.Vector2(t.offsetX,t.offsetY).multiply(n));t.image.texture.parent||i.addChild(t.image.texture),t.image.texture.x=s.x,t.image.texture.y=s.y,t.image.texture.scaleX=n.x,t.image.texture.scaleY=n.y,t.image.texture.filters=[o]}},i.renderObjectGroup=function(t,i,r,n,a){if(t.visible)for(var o in t.objects){var s=t.objects[o];if(s.visible&&(e.Core.debugRenderEndabled||s.objectType==e.TmxObjectType.tile||s.objectType==e.TmxObjectType.text)){var l=e.Vector2.add(r,new e.Vector2(s.x,s.y).multiply(n));switch(s.objectType){case e.TmxObjectType.basic:s.shape.parent||(s.shape.x=s.x,s.shape.y=s.y,i.addChild(s.shape),s.shape.graphics.clear(),s.shape.graphics.lineStyle(1,10526884),s.shape.graphics.beginFill(9934744,.5),s.shape.graphics.drawRect(0,0,s.width*n.x,s.height*n.y),s.shape.graphics.endFill(),u(s,l));break;case e.TmxObjectType.point:var h=.5*t.map.tileWidth;l.x-=.5*h,l.y-=.5*h,s.shape.parent||(s.shape.x=l.x,s.shape.y=l.y,i.addChild(s.shape),s.shape.graphics.clear(),s.shape.graphics.lineStyle(1,10526884),s.shape.graphics.beginFill(9934744,.5),s.shape.graphics.drawCircle(0,0,1),s.shape.graphics.endFill(),u(s,l));break;case e.TmxObjectType.tile:this.renderTilesetTile(t,s,i,l,n,u);break;case e.TmxObjectType.ellipse:l=new e.Vector2(s.x+.5*s.width,s.y+.5*s.height).multiply(n),s.shape.parent||(s.shape.x=l.x,s.shape.y=l.y,i.addChild(s.shape),s.shape.graphics.clear(),s.shape.graphics.lineStyle(1,10526884),s.shape.graphics.beginFill(9934744,.5),s.shape.graphics.drawCircle(0,0,.5*s.width),s.shape.graphics.endFill(),u(s,l));break;case e.TmxObjectType.polygon:case e.TmxObjectType.polyline:for(var p=[],c=0;c<s.points.length;c++)p[c]=e.Vector2.multiply(s.points[c],n);if(!s.shape.parent&&p.length>0){s.shape.x=l.x,s.shape.y=l.y,i.addChild(s.shape),s.shape.graphics.clear(),s.shape.graphics.lineStyle(1,10526884);for(c=0;c<p.length;c++)0==c?s.shape.graphics.moveTo(p[c].x,p[c].y):s.shape.graphics.lineTo(p[c].x,p[c].y);s.shape.graphics.endFill(),u(s,l)}break;case e.TmxObjectType.text:s.textField.parent||(s.textField.x=l.x,s.textField.y=l.y,i.addChild(s.textField),s.textField.text=s.text.value,s.textField.textColor=s.text.color,s.textField.bold=null!=s.text.bold&&s.text.bold,s.textField.italic=null!=s.text.italic&&s.text.italic,s.textField.size=s.text.pixelSize,s.textField.fontFamily=s.text.fontFamily)}}}function u(t,r){i&&e.Core.debugRenderEndabled&&!t.textField.parent&&t.name&&(t.textField.text=t.name,t.textField.size=12,t.textField.fontFamily="sans-serif",t.shape?(t.textField.x=r.x+(t.shape.getBounds().width-t.textField.width)/2+t.shape.getBounds().x,t.textField.y=r.y-t.textField.height-5+t.shape.getBounds().y):(t.textField.x=r.x+(t.width-t.textField.width)/2,t.textField.y=r.y-t.textField.height-5),t.textField.background=!0,t.textField.backgroundColor=10526884,t.textField.textColor=16777215,i.addChild(t.textField))}},i.renderTilesetTile=function(e,i,r,n,a,o){var s=e.map.getTilesetForTileGid(i.tile.gid),l=s.tileRegions.get(i.tile.gid);if(r)if(s.image){i.tile.horizontalFlip&&i.tile.verticalFlip?(n.x+=s.tileHeight+(l.height*a.y-s.tileHeight),n.y-=l.width*a.x-s.tileWidth):i.tile.horizontalFlip?n.x+=s.tileWidth+(l.height*a.y-s.tileHeight):i.tile.verticalFlip?n.y+=s.tileWidth-l.width*a.x:n.y+=s.tileHeight-l.height*a.y,(h=s.image.bitmap.getTexture(""+i.tile.gid))||(h=s.image.bitmap.createTexture(""+i.tile.gid,l.x,l.y,l.width,l.height)),s.image.texture=new t(h),r.addChild(s.image.texture),s.image.texture.x=n.x,s.image.texture.y=n.y,i.tile.verticalFlip&&i.tile.horizontalFlip?(s.image.texture.scaleX=-1,s.image.texture.scaleY=-1):i.tile.verticalFlip?(s.image.texture.scaleX=a.x,s.image.texture.scaleY=-1):i.tile.horizontalFlip?(s.image.texture.scaleX=-1,s.image.texture.scaleY=a.y):(s.image.texture.scaleX=a.x,s.image.texture.scaleY=a.y),s.image.texture.anchorOffsetX=0,s.image.texture.anchorOffsetY=0,o(i,n)}else{var h,p=s.tiles.get(i.tile.gid);(h=p.image.bitmap.getTexture(""+i.tile.gid))||(h=p.image.bitmap.createTexture(""+i.tile.gid,l.x,l.y,l.width,l.height)),n.y-=i.height,p.image.texture=new t(h),r.addChild(p.image.texture),p.image.texture.width=i.width,p.image.texture.height=i.height,p.image.texture.x=n.x,p.image.texture.y=n.y,i.tile.verticalFlip&&i.tile.horizontalFlip?(p.image.texture.scaleX=-1,p.image.texture.scaleY=-1):i.tile.verticalFlip?(p.image.texture.scaleX=a.x,p.image.texture.scaleY=-1):i.tile.horizontalFlip?(p.image.texture.scaleX=-1,p.image.texture.scaleY=a.y):(p.image.texture.scaleX=a.x,p.image.texture.scaleY=a.y),p.image.texture.anchorOffsetX=0,p.image.texture.anchorOffsetY=0}},i.renderGroup=function(t,i,r,n,a){var o=this;t.visible&&t.layers.forEach(function(t){t instanceof e.TmxGroup&&o.renderGroup(t,i,r,n,a),t instanceof e.TmxObjectGroup&&o.renderObjectGroup(t,i,r,n,a),t instanceof e.TmxLayer&&o.renderLayer(t,i,r,n,a),t instanceof e.TmxImageLayer&&o.renderImageLayer(t,i,r,n,a)})},i.renderTile=function(i,r,n,a,o,s,l,h){var p=i.gid,c=i.tilesetTile;c&&c.animationFrames.length>0&&(p=c.currentAnimationFrameGid);var u=i.tileset.tileRegions.get(p),d=Math.floor(i.x)*o,g=Math.floor(i.y)*s;i.horizontalFlip&&i.verticalFlip?(d+=s+(u.height*a.y-s),g-=u.width*a.x-o):i.horizontalFlip?d+=o+(u.height*a.y-s):i.verticalFlip?g+=o-u.width*a.x:g+=s-u.height*a.y;var m=new e.Vector2(d,g).add(n);if(i.tileset.image){if(r){var f=i.tileset.image.bitmap.getTexture(""+p);f||(f=i.tileset.image.bitmap.createTexture(""+p,u.x,u.y,u.width,u.height)),i.tileset.image.texture=new t(f),r.addChild(i.tileset.image.texture),i.tileset.image.texture.x!=m.x&&(i.tileset.image.texture.x=m.x),i.tileset.image.texture.y!=m.y&&(i.tileset.image.texture.y=m.y),i.verticalFlip&&i.horizontalFlip?(i.tileset.image.texture.scaleX=-1,i.tileset.image.texture.scaleY=-1):i.verticalFlip?(i.tileset.image.texture.scaleX=a.x,i.tileset.image.texture.scaleY=-1):i.horizontalFlip?(i.tileset.image.texture.scaleX=-1,i.tileset.image.texture.scaleY=a.y):(i.tileset.image.texture.scaleX=a.x,i.tileset.image.texture.scaleY=a.y),0!=i.tileset.image.texture.rotation&&(i.tileset.image.texture.rotation=0),0!=i.tileset.image.texture.anchorOffsetX&&(i.tileset.image.texture.anchorOffsetX=0),0!=i.tileset.image.texture.anchorOffsetY&&(i.tileset.image.texture.anchorOffsetY=0)}}else c.image.texture&&(c.image.bitmap.getTexture(p.toString())||(c.image.texture=new t(c.image.bitmap.createTexture(p.toString(),u.x,u.y,u.width,u.height)),r.addChild(c.image.texture)),c.image.texture.x=m.x,c.image.texture.y=m.y,c.image.texture.scaleX=a.x,c.image.texture.scaleY=a.y,c.image.texture.rotation=0,c.image.texture.anchorOffsetX=0,c.image.texture.anchorOffsetY=0,c.image.texture.filters=[l])},i}();e.TiledRendering=i}(es||(es={})),function(e){var t=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.update=function(){this.tiles.forEach(function(e){e.updateAnimatedTiles()})},t}(e.TmxDocument);e.TmxTileset=t;var i=function(){return function(){}}();e.TmxTileOffset=i;var r=function(){return function(){}}();e.TmxTerrain=r}(es||(es={})),function(e){var t=function(){function t(){}return Object.defineProperty(t.prototype,"currentAnimationFrameGid",{get:function(){return this.animationFrames[this._animationCurrentFrame].gid+this.tileset.firstGid},enumerable:!0,configurable:!0}),t.prototype.processProperties=function(){var e;(e=this.properties.get("engine.isDestructable"))&&(this.isDestructable=Boolean(e)),(e=this.properties.get("engine:isSlope"))&&(this.isSlope=Boolean(e)),(e=this.properties.get("engine:isOneWayPlatform"))&&(this.isOneWayPlatform=Boolean(e)),(e=this.properties.get("engine:slopeTopLeft"))&&(this.slopeTopLeft=Number(e)),(e=this.properties.get("engine:slopeTopRight"))&&(this.slopeTopRight=Number(e))},t.prototype.updateAnimatedTiles=function(){0!=this.animationFrames.length&&(this._animationElapsedTime+=e.Time.deltaTime,this._animationElapsedTime>this.animationFrames[this._animationCurrentFrame].duration&&(this._animationCurrentFrame=e.MathHelper.incrementWithWrap(this._animationCurrentFrame,this.animationFrames.length),this._animationElapsedTime=0))},t}();e.TmxTilesetTile=t;var i=function(){return function(){}}();e.TmxAnimationFrame=i}(es||(es={})),function(e){var t=function(){function t(){}return t.decode=function(t,i,r){switch(r=r||"none",i=i||"none"){case"base64":var n=e.Base64Utils.decodeBase64AsArray(t,4);return"none"===r?n:e.Base64Utils.decompress(t,n,r);case"csv":return e.Base64Utils.decodeCSV(t);case"none":for(var a=[],o=0;o<t.length;o++)a[o]=+t[o].gid;return a;default:throw new Error("未定义的编码:"+i)}},t.color16ToUnit=function(e){if(!e)return 16777215;var t="0x"+e.slice(1);return parseInt(t,16)},t}();e.TmxUtils=t}(es||(es={}));