!function(t,i){"use strict";class e extends i.Sprite{constructor(){super(...arguments),this.relativeX=0,this.relativeY=0,this.isAloneObject=!1,this.isHaveAnimation=!1,this.drawImageNum=0,this._map=null}initData(t,i=!1){this._map=t,this.isAloneObject=i}addAniSprite(t){null==this.aniSpriteArray&&(this.aniSpriteArray=[]),this.aniSpriteArray.push(t)}show(){if(!this.visible){if(this.visible=!0,null==this.aniSpriteArray)return;for(var t=0;tthis._map.viewPortWidth||this.y<0||this.y>this._map.viewPortHeight?this.hide():this.show()):this._map&&(this.x=this.relativeX-this._map._viewPortX,this.y=this.relativeY-this._map._viewPortY)}clearAll(){if(this._map&&(this._map=null),this.visible=!1,null!=this.aniSpriteArray)for(var t=0;t0&&(this._objDic={},this._dataDic={});for(var n=0;n=0&&i=0&&t0&&t.updatePos()}drawTileTexture(t,i,e){if(e>=0&&e=0&&i0&&this.durationTimeArray&&this.durationTimeArray.length>0){var t=i.ILaya.Browser.now();this._interval=t-this._preFrameTime,this._preFrameTime=t,this._interval>this.animationTotalTime&&(this._interval=this._interval%this.animationTotalTime),this._time+=this._interval;for(var e=this.durationTimeArray[this._frameIndex];this._time>e;){this._time-=e,this._frameIndex++,(this._frameIndex>=this.durationTimeArray.length||this._frameIndex>=this.textureArray.length)&&(this._frameIndex=0);var r,h=this.textureArray[this._frameIndex];for(var a in this._aniDic)r=this._aniDic[a],this.drawTexture(r,h);e=this.durationTimeArray[this._frameIndex]}}}drawTexture(t,i){t.graphics.clear(!0),t.graphics.drawImage(i.texture,i.offX,i.offY)}removeAniSprite(t){this._aniDic&&this._aniDic[t]&&(delete this._aniDic[t],this._spriteNum--,0==this._spriteNum&&i.ILaya.timer.clear(this,this.animate))}showDebugInfo(){var t=null;return this._spriteNum>0&&(t="TileTextureSet::gid:"+this.gid.toString()+" 动画数:"+this._spriteNum.toString()),t}clearAll(){this.gid=-1,this.texture&&(this.texture.destroy(),this.texture=null),this.offX=0,this.offY=0,this.textureArray=null,this.durationTimeArray=null,this.isAnimation=!1,this._spriteNum=0,this._aniDic=null,this._frameIndex=0,this._preFrameTime=0,this._time=0,this._interval=0}}class l{constructor(){this._tileTexSetArr=[],this._texArray=[],this._x=0,this._y=0,this._width=0,this._height=0,this._mapW=0,this._mapH=0,this._mapTileW=0,this._mapTileH=0,this._rect=new i.Rectangle,this._paddingRect=new i.Rectangle,this._mapSprite=null,this._layerArray=[],this._renderLayerArray=[],this._gridArray=[],this._showGridKey=!1,this._totalGridNum=0,this._gridW=0,this._gridH=0,this._gridWidth=450,this._gridHeight=450,this._jsonLoader=null,this._loader=null,this._tileSetArray=[],this._currTileSet=null,this._completeHandler=null,this._mapRect=new _,this._mapLastRect=new _,this._index=0,this._animationDic={},this._tileProperties={},this._tileProperties2={},this._orientation="orthogonal",this._renderOrder="right-down",this._colorArray=["FF","00","33","66"],this._scale=1,this._pivotScaleX=.5,this._pivotScaleY=.5,this._centerX=0,this._centerY=0,this._viewPortX=0,this._viewPortY=0,this._viewPortWidth=0,this._viewPortHeight=0,this._enableLinear=!0,this._limitRange=!1,this.autoCache=!0,this.autoCacheType="normal",this.enableMergeLayer=!1,this.removeCoveredTile=!1,this.showGridTextureCount=!1,this.antiCrack=!0,this.cacheAllAfterInit=!1,this._texutreStartDic={}}createMap(t,e,r,h=null,a=null,s=!0,l=!1){this._enableLinear=s,this._limitRange=l,this._rect.x=e.x,this._rect.y=e.y,this._rect.width=e.width,this._rect.height=e.height,this._viewPortWidth=e.width/this._scale,this._viewPortHeight=e.height/this._scale,this._completeHandler=r,h?this._paddingRect.copyFrom(h):this._paddingRect.setTo(0,0,0,0),a&&(this._gridWidth=a.x,this._gridHeight=a.y);var _=t.lastIndexOf("/");_>-1?(this._resPath=t.substr(0,_),this._pathArray=this._resPath.split("/")):(this._resPath="",this._pathArray=[]),this._jsonLoader=new i.Loader,this._jsonLoader.once("complete",this,this.onJsonComplete),this._jsonLoader.load(t,i.Loader.JSON,!1)}onJsonComplete(t){this._mapSprite=new i.Sprite,i.ILaya.stage.addChild(this._mapSprite);var e=this._jsonData=t;this._properties=e.properties,this._orientation=e.orientation,this._renderOrder=e.renderorder,this._mapW=e.width,this._mapH=e.height,this._mapTileW=e.tilewidth,this._mapTileH=e.tileheight,this._width=this._mapTileW*this._mapW,this._height=this._mapTileH*this._mapH,this._orientation==l.ORIENTATION_STAGGERED&&(this._height=(.5+.5*this._mapH)*this._mapTileH),this._mapLastRect.top=this._mapLastRect.bottom=this._mapLastRect.left=this._mapLastRect.right=-1;var r,h,a=e.tilesets,s=0;for(s=0;s0){h=this._currTileSet=this._tileSetArray.shift(),this._loader=new i.Loader,this._loader.once("complete",this,this.onTextureComplete);var u=this.mergePath(this._resPath,h.image);this._loader.load(u,i.Loader.IMAGE,!1)}}mergePath(t,i){var e="",r=i.split("/"),h=0,a=0;for(a=r.length-1;a>=0;a--)".."==r[a]&&h++;if(0==h)return e=this._pathArray.length>0?t+"/"+i:i;var s=this._pathArray.length-h;for(s<0&&console.log("[error]path does not exist",this._pathArray,r,t,i),a=0;a0){r=this._currTileSet=this._tileSetArray.shift(),this._loader.once("complete",this,this.onTextureComplete);var g=this.mergePath(this._resPath,r.image);this._loader.load(g,i.Loader.IMAGE,!1)}else this._currTileSet=null,this.initMap()}adptTexture(t){if(t){var i=t.uv[0],e=t.uv[2],r=t.uv[1],h=t.uv[7],a=1/t.bitmap.width,s=1/t.bitmap.height,l=t;l.uv[0]=l.uv[6]=i+a,l.uv[2]=l.uv[4]=e-a,l.uv[1]=l.uv[3]=r+s,l.uv[5]=l.uv[7]=h-s}}initMap(){var t,i;for(var e in this._animationDic){var r,h=this._animationDic[e];r=this._texutreStartDic[h.image];var s=this.getTexture(parseInt(e)+r);if(h.mAniIdArray.length>0){for(s.textureArray=[],s.durationTimeArray=h.mDurationTimeArray,s.isAnimation=!0,s.animationTotalTime=0,t=0,i=s.durationTimeArray.length;t=0;t--)(i=this._layerArray[t]._mapData)&&(this.removeCoverd(i,e),this.collectCovers(i,e,t))}removeCoverd(t,i){var e,r;for(r=t.length,e=0;e0&&this.getTileUserData(a-1,"type",0)>0&&(i[r]=a)}getTexture(t){return tthis._width&&(this._viewPortX=this._width-this._viewPortWidth),this._viewPortY+this._viewPortHeight>this._height&&(this._viewPortY=this._height-this._viewPortHeight),this._viewPortX<0&&(this._viewPortX=0),this._viewPortY<0&&(this._viewPortY=0));var e=this._paddingRect;if(this._mapRect.top=Math.floor((this._viewPortY-e.y)/this._gridHeight),this._mapRect.bottom=Math.floor((this._viewPortY+this._viewPortHeight+e.height+e.y)/this._gridHeight),this._mapRect.left=Math.floor((this._viewPortX-e.x)/this._gridWidth),this._mapRect.right=Math.floor((this._viewPortX+this._viewPortWidth+e.width+e.x)/this._gridWidth),this._mapRect.top==this._mapLastRect.top&&this._mapRect.bottom==this._mapLastRect.bottom&&this._mapRect.left==this._mapLastRect.left&&this._mapRect.right==this._mapLastRect.right||(this.clipViewPort(),this._mapLastRect.top=this._mapRect.top,this._mapLastRect.bottom=this._mapRect.bottom,this._mapLastRect.left=this._mapRect.left,this._mapLastRect.right=this._mapRect.right,t=!0),t)for(var r,h=this._renderLayerArray.length,a=0;a0&&r.updateGridPos()}clipViewPort(){var t,i,e=0,r=0;if(this._mapRect.left>this._mapLastRect.left){if((e=this._mapRect.left-this._mapLastRect.left)>0)for(i=this._mapLastRect.left;i0)for(i=this._mapRect.left;ithis._mapLastRect.right){if((r=this._mapRect.right-this._mapLastRect.right)>0)for(i=Math.max(this._mapLastRect.right+1,this._mapRect.left);i<=this._mapLastRect.right+r;i++)for(t=this._mapRect.top;t<=this._mapRect.bottom;t++)this.showGrid(i,t)}else if((e=this._mapLastRect.right-this._mapRect.right)>0)for(i=this._mapRect.right+1;i<=this._mapRect.right+e;i++)for(t=this._mapLastRect.top;t<=this._mapLastRect.bottom;t++)this.hideGrid(i,t);if(this._mapRect.top>this._mapLastRect.top){if((e=this._mapRect.top-this._mapLastRect.top)>0)for(t=this._mapLastRect.top;t0)for(t=this._mapRect.top;tthis._mapLastRect.bottom){if((r=this._mapRect.bottom-this._mapLastRect.bottom)>0)for(t=Math.max(this._mapLastRect.bottom+1,this._mapRect.top);t<=this._mapLastRect.bottom+r;t++)for(i=this._mapRect.left;i<=this._mapRect.right;i++)this.showGrid(i,t)}else if((e=this._mapLastRect.bottom-this._mapRect.bottom)>0)for(t=this._mapRect.bottom+1;t<=this._mapRect.bottom+e;t++)for(i=this._mapLastRect.left;i<=this._mapLastRect.right;i++)this.hideGrid(i,t)}showGrid(t,i){if(!(t<0||t>=this._gridW||i<0||i>=this._gridH)){var e,r,h=this._gridArray[i][t];if(null==h)h=this.getGridArray(t,i);else for(e=0;e0&&r.show()}}}cacheAllGrid(){var t,i,e;for(t=0;t=N&&(c=N-1),u<0&&(n=0),u>=N&&(u=N-1),h.zOrder=this._totalGridNum*v+i*this._gridW+t,e=c;ed&&I<=g&&A.drawTileTexture(h,S,O)&&h.drawImageNum++}break;case l.ORIENTATION_STAGGERED:for(h.zOrder=v*this._totalGridNum+i*this._gridW+t,e=o;e=o;e--)for(r=s;r<_;r++)A.drawTileTexture(h,r,e)&&h.drawImageNum++;break;case l.RENDERORDER_LEFTDOWN:for(h.zOrder=v*this._totalGridNum+i*this._gridW+(this._gridW-1-t),e=o;e=s;r--)A.drawTileTexture(h,r,e)&&h.drawImageNum++;break;case l.RENDERORDER_LEFTUP:for(h.zOrder=v*this._totalGridNum+(this._gridH-1-i)*this._gridW+(this._gridW-1-t),e=n-1;e>=o;e--)for(r=_-1;r>=s;r--)A.drawTileTexture(h,r,e)&&h.drawImageNum++}}h.isHaveAnimation||(h.autoSize=!0,this.autoCache&&(h.cacheAs=this.autoCacheType),h.autoSize=!1),this.enableMergeLayer?T&&T.drawImageNum>0&&y&&y.addChild(T):(h.drawImageNum>0&&A.addChild(h),this._showGridKey&&h.graphics.drawRect(0,0,p,m,null,w))}this.enableMergeLayer&&this.showGridTextureCount&&T&&T.graphics.fillText(T.drawImageNum+"",20,20,null,"#ff0000","left")}return a}hideGrid(t,i){if(!(t<0||t>=this._gridW||i<0||i>=this._gridH)){var e=this._gridArray[i][t];if(e)for(var r,h=0;h0&&null!=r&&r.hide()}}getLayerObject(t,i){for(var e=null,r=0;r