papercats/public/bundle.js

2 lines
151 KiB
JavaScript
Raw Normal View History

2019-01-15 10:42:15 -05:00
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){function Rolling(value,frames){var lag=0;if(!frames)frames=24;this.value=value;Object.defineProperty(this,"lag",{get:function(){return lag},enumerable:true});this.update=function(){var delta=this.value-lag;var dir=Math.sign(delta);var speed=Math.abs(delta)/frames;var mag=Math.min(Math.abs(speed),Math.abs(delta));lag+=mag*dir;return lag}}module.exports=Rolling},{}],2:[function(require,module,exports){var core=require("../game-core");var client=require("../client");var Rolling=require("./rolling");var GRID_SIZE=core.GRID_SIZE;var CELL_WIDTH=core.CELL_WIDTH;var SPEED=core.SPEED;var BORDER_WIDTH=core.BORDER_WIDTH;var SHADOW_OFFSET=5;var ANIMATE_FRAMES=24;var BOUNCE_FRAMES=[8,4];var DROP_HEIGHT=24;var DROP_SPEED=2;var MIN_BAR_WIDTH=65;var BAR_HEIGHT=SHADOW_OFFSET+CELL_WIDTH;var BAR_WIDTH=400;var canvas,canvasWidth,canvasHeight,gameWidth,gameHeight,ctx,offctx,offscreenCanvas;$(function(){canvas=$("#main-ui")[0];ctx=canvas.getContext("2d");offscreenCanvas=document.createElement("canvas");offctx=offscreenCanvas.getContext("2d");canvas.style.marginTop=10;updateSize()});var animateGrid,playerPortion,portionsRolling,barProportionRolling,animateTo,offset,user,zoom,showedDead;var grid=client.grid;function updateSize(){var changed=false;if(canvasWidth!=window.innerWidth){gameWidth=canvasWidth=offscreenCanvas.width=canvas.width=window.innerWidth;changed=true}if(canvasHeight!=window.innerHeight-20){canvasHeight=offscreenCanvas.height=canvas.height=window.innerHeight-20;gameHeight=canvasHeight-BAR_HEIGHT;changed=true}if(changed&&user)centerOnPlayer(user,offset)}function reset(){animateGrid=new core.Grid(GRID_SIZE);playerPortion=[];portionsRolling=[];barProportionRolling=[];animateTo=[0,0];offset=[0,0];user=null;zoom=1;showedDead=false}reset();function paintGridBorder(ctx){ctx.fillStyle="lightgray";var gridWidth=CELL_WIDTH*GRID_SIZE;ctx.fillRect(-BORDER_WIDTH,0,BORDER_WIDTH,gridWidth);ctx.fillRect(-BORDER_WIDTH,-BORDER_WIDTH,gridWidth+BORDER_WIDTH*2,BORDER_WIDTH);ctx.fillRect(gridWidth,0,BORDER_WIDTH,gridWidth);ctx.fillRect(-BORDER_WIDTH,gridWidth,gridWidth+BORDER_WIDTH*2,BORDER_WIDTH)}function paintGrid(ctx){ctx.fillStyle="rgb(211, 225, 237)";ctx.fillRect(0,0,CELL_WIDTH*GRID_SIZE,CELL_WIDTH*GRID_SIZE);paintGridBorder(ctx);var offsetX=offset[0]-BORDER_WIDTH;var offsetY=offset[1]-BORDER_WIDTH;var minRow=Math.max(Math.floor(offsetY/CELL_WIDTH),0);var minCol=Math.max(Math.floor(offsetX/CELL_WIDTH),0);var maxRow=Math.min(Math.ceil((offsetY+gameHeight/zoom)/CELL_WIDTH),grid.size);var maxCol=Math.min(Math.ceil((offsetX+gameWidth/zoom)/CELL_WIDTH),grid.size);for(var r=minRow;r<maxRow;r++){for(var c=minCol;c<maxCol;c++){var p=grid.get(r,c);var x=c*CELL_WIDTH,y=r*CELL_WIDTH,baseColor,shadowColor;var animateSpec=animateGrid.get(r,c);if(client.allowAnimation&&animateSpec){if(animateSpec.before){var frac=animateSpec.frame/ANIMATE_FRAMES;var back=new core.Color(.58,.41,.92,1);baseColor=animateSpec.before.lightBaseColor.interpolateToString(back,frac);shadowColor=animateSpec.before.shadowColor.interpolateToString(back,frac)}else continue}else if(p){baseColor=p.lightBaseColor;shadowColor=p.shadowColor}else continue;var hasBottom=!grid.isOutOfBounds(r+1,c);var bottomAnimate=hasBottom&&animateGrid.get(r+1,c);var totalStatic=!bottomAnimate&&!animateSpec;var bottomEmpty=totalStatic?hasBottom&&!grid.get(r+1,c):!bottomAnimate||bottomAnimate.after&&bottomAnimate.before;if(hasBottom&&(!!bottomAnimate^!!animateSpec||bottomEmpty)){ctx.fillStyle=shadowColor.rgbString();ctx.fillRect(x,y+CELL_WIDTH,CELL_WIDTH+1,SHADOW_OFFSET)}ctx.fillStyle=baseColor.rgbString();ctx.fillRect(x,y,