Raspsnir/public_html/browserquest/js/renderer.js

1 line
12 KiB
JavaScript
Raw Normal View History

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;t<e.length;t+=1)for(var n=0;n<e[t].length;n+=1)_.isNull(e[t][n])||this.drawCellHighlight(t,n,"rgba(50, 50, 255, 0.5)")},drawPathingCells:function(){var e=this.game.pathingGrid;if(e&&this.game.debugPathing)for(var t=0;t<e.length;t+=1)for(var n=0;n<e[t].length;n+=1)e[t][n]===1&&this.game.camera.isVisiblePosition(n,t)&&this.drawCellHighlight(n,t,"rgba(50, 50, 255, 0.5)")},drawSelectedCell:function(){var e=this.game.cursors.target,t=this.game.targetAnimation,n=this.upscaledRendering?1:this.scale,r=this.upscaledRendering?this.scale:1;if(this.game.selectedCellVisible)if(this.mobile||this.tablet){if(this.game.drawTarget){var i=this.game.selectedX,s=this.game.selectedY;