define(["camera","item","character","player","timer"],function(e,t,n,r,i){var s=Class.extend({init:function(e,t,n,r){this.game=e,this.context=t&&t.getContext?t.getContext("2d"):null,this.background=n&&n.getContext?n.getContext("2d"):null,this.foreground=r&&r.getContext?r.getContext("2d"):null,this.canvas=t,this.backcanvas=n,this.forecanvas=r,this.initFPS(),this.tilesize=16,this.upscaledRendering=this.context.mozImageSmoothingEnabled!==undefined,this.supportsSilhouettes=this.upscaledRendering,this.rescale(this.getScaleFactor()),this.lastTime=new Date,this.frameCount=0,this.maxFPS=this.FPS,this.realFPS=0,this.isDebugInfoVisible=!1,this.animatedTileCount=0,this.highTileCount=0,this.tablet=Detect.isTablet(window.innerWidth),this.fixFlickeringTimer=new i(100)},getWidth:function(){return this.canvas.width},getHeight:function(){return this.canvas.height},setTileset:function(e){this.tileset=e},getScaleFactor:function(){var e=window.innerWidth,t=window.innerHeight,n;return this.mobile=!1,e<=1e3?(n=2,this.mobile=!0):e<=1500||t<=870?n=2:n=3,n},rescale:function(e){this.scale=this.getScaleFactor(),this.createCamera(),this.context.mozImageSmoothingEnabled=!1,this.background.mozImageSmoothingEnabled=!1,this.foreground.mozImageSmoothingEnabled=!1,this.initFont(),this.initFPS(),!this.upscaledRendering&&this.game.map&&this.game.map.tilesets&&this.setTileset(this.game.map.tilesets[this.scale-1]),this.game.renderer&&this.game.setSpriteScale(this.scale)},createCamera:function(){this.camera=new e(this),this.camera.rescale(),this.canvas.width=this.camera.gridW*this.tilesize*this.scale,this.canvas.height=this.camera.gridH*this.tilesize*this.scale,log.debug("#entities set to "+this.canvas.width+" x "+this.canvas.height),this.backcanvas.width=this.canvas.width,this.backcanvas.height=this.canvas.height,log.debug("#background set to "+this.backcanvas.width+" x "+this.backcanvas.height),this.forecanvas.width=this.canvas.width,this.forecanvas.height=this.canvas.height,log.debug("#foreground set to "+this.forecanvas.width+" x "+this.forecanvas.height)},initFPS:function(){this.FPS=this.mobile?50:50},initFont:function(){var e;switch(this.scale){case 1:e=10;break;case 2:e=Detect.isWindows()?10:13;break;case 3:e=20}this.setFontSize(e)},setFontSize:function(e){var t=e+"px GraphicPixel";this.context.font=t,this.background.font=t},drawText:function(e,t,n,r,i,s){var o=this.context,u;switch(this.scale){case 1:u=3;break;case 2:u=3;break;case 3:u=5}e&&t&&n&&(o.save(),r&&(o.textAlign="center"),o.strokeStyle=s||"#373737",o.lineWidth=u,o.strokeText(e,t,n),o.fillStyle=i||"white",o.fillText(e,t,n),o.restore())},drawCellRect:function(e,t,n){this.context.save(),this.context.lineWidth=2*this.scale,this.context.strokeStyle=n,this.context.translate(e+2,t+2),this.context.strokeRect(0,0,this.tilesize*this.scale-4,this.tilesize*this.scale-4),this.context.restore()},drawCellHighlight:function(e,t,n){var r=this.scale,i=this.tilesize,s=e*i*r,o=t*i*r;this.drawCellRect(s,o,n)},drawTargetCell:function(){var e=this.game.getMouseGridPosition();this.game.targetCellVisible&&(e.x!==this.game.selectedX||e.y!==this.game.selectedY)&&this.drawCellHighlight(e.x,e.y,this.game.targetColor)},drawAttackTargetCell:function(){var e=this.game.getMouseGridPosition(),t=this.game.getEntityAt(e.x,e.y),n=this.scale;t&&this.drawCellRect(t.x*n,t.y*n,"rgba(255, 0, 0, 0.5)")},drawOccupiedCells:function(){var e=this.game.entityGrid;if(e)for(var t=0;t0},getEntityBoundingRect:function(e){var t={},n=this.scale,i;if(e instanceof r&&e.hasWeapon()){var s=this.game.sprites[e.getWeaponName()];i=s}else i=e.sprite;return i&&(t.x=(e.x+i.offsetX-this.camera.x)*n,t.y=(e.y+i.offsetY-this.camera.y)*n,t.w=i.width*n,t.h=i.height*n,t.left=t.x,t.right=t.x+t.w,t.top=t.y,t.bottom=t.y+t.h),t},getTileBoundingRect:function(e){var t={},n=this.game.map.width,r=this.scale,i=this.tilesize,s=e.index;return t.x=(o(s+1,n)*i-this.camera.x)*r,t.y=(Math.floor(s/n)*i-this.camera.y)*r,t.w=i*r,t.h=i*r,t.left=t.x,t.right=t.x+t.w,t.top=t.y,t.bottom=t.y+t.h,t},getTargetBoundingRect:function(e,t){var n={},r=this.scale,i=this.tilesize,s=e||this.game.selectedX,o=t||this.game.selectedY;return n.x=(s*i-this.camera.x)*r,n.y=(o*i-this.camera.y)*r,n.w=i*r,n.h=i*r,n.left=n.x,n.right=n.x+n.w,n.top=n.y,n.bottom=n.y+n.h,n},isIntersecting:function(e,t){return!(t.left>e.right||t.righte.bottom||t.bottom=1e3&&(this.realFPS=this.frameCount,this.frameCount=0,this.lastTime=e),this.frameCount++,this.drawText("FPS: "+this.realFPS,30,30,!1)},drawDebugInfo:function(){this.isDebugInfoVisible&&(this.drawFPS(),this.drawText("A: "+this.animatedTileCount,100,30,!1),this.drawText("H: "+this.highTileCount,140,30,!1))},drawCombatInfo:function(){var e=this;switch(this.scale){case 2:this.setFontSize(20);break;case 3:this.setFontSize(30)}this.game.infoManager.forEachInfo(function(t){e.context.save(),e.context.globalAlpha=t.opacity,e.drawText(t.value,(t.x+8)*e.scale,Math.floor(t.y*e.scale),!0,t.fillColor,t.strokeColor),e.context.restore()}),this.initFont()},setCameraView:function(e){e.translate(-this.camera.x*this.scale,-this.camera.y*this.scale)},clearScreen:function(e){e.clearRect(0,0,this.canvas.width,this.canvas.height)},getPlayerImage:function(){var e=document.createElement("canvas"),t=e.getContext("2d"),n=this.upscaledRendering?1:this.scale,r=this.game.player,i=r.getArmorSprite(),s=i.animationData.idle_down,o=s.row,u=i.width*n,a=i.height*n,f=o*a,l=this.game.sprites[this.game.player.getWeaponName()],c=l.width*n,h=l.height*n,p=h*o,d=(l.offsetX-i.offsetX)*n,v=(l.offsetY-i.offsetY)*n,m=this.game.shadows.small,g=m.width*n,y=m.height*n,b=-i.offsetX*n;return oy=-i.offsetY*n,e.width=u,e.height=a,t.clearRect(0,0,u,a),t.drawImage(m.image,0,0,g,y,b,oy,g,y),t.drawImage(i.image,0,f,u,a,0,0,u,a),t.drawImage(l.image,0,p,c,h,d,v,c,h),e.toDataURL("image/png")},renderStaticCanvases:function(){this.background.save(),this.setCameraView(this.background),this.drawTerrain(),this.background.restore();if(this.mobile||this.tablet)this.clearScreen(this.foreground),this.foreground.save(),this.setCameraView(this.foreground),this.drawHighTiles(this.foreground),this.foreground.restore()},renderFrame:function(){this.mobile||this.tablet?this.renderFrameMobile():this.renderFrameDesktop()},renderFrameDesktop:function(){this.clearScreen(this.context),this.context.save(),this.setCameraView(this.context),this.drawAnimatedTiles(),this.game.started&&(this.drawSelectedCell(),this.drawTargetCell()),this.drawPathingCells(),this.drawEntities(),this.drawCombatInfo(),this.drawHighTiles(this.context),this.context.restore(),this.drawCursor(),this.drawDebugInfo()},renderFrameMobile:function(){this.clearDirtyRects(),this.preventFlickeringBug(),this.context.save(),this.setCameraView(this.context),this.drawDirtyAnimatedTiles(),this.drawSelectedCell(),this.drawDirtyEntities(),this.context.restore()},preventFlickeringBug:function(){this.fixFlickeringTimer.isOver(this.game.currentTime)&&(this.background.fillRect(0,0,0,0),this.context.fillRect(0,0,0,0),this.foreground.fillRect(0,0,0,0))}}),o=function(e,t){return e==0?0:e%t==0?t-1:e%t-1};return s});