<commit_before>
(function(){Object.defineProperty(Array.prototype,"shuffle",{enumerable:false,configurable:true,writable:true,value:function(){var i=this.length,r=0,swap=null;if(!i){return;}
while(--i){r=Math.floor(Math.random()*(i+1));swap=this[r];this[r]=this[i];this[i]=swap;}}});Object.defineProperty(Object.prototype,"extend",{enumerable:false,configurable:true,writable:true,value:function(){"use strict";var i=0,length=arguments.length,deep=false,merge=function(target,source){for(var p in source){if(source.hasOwnProperty(p)){if(deep&&Object.prototype.toString.call(source[p])==="[object Object]"){if(!target[p]){target[p]={};}
target[p].extend(true,source[p]);}else{target[p]=source[p];}}}};if(typeof arguments[0]=="boolean"){deep=arguments[0];i++;}
for(;i<length;i++){var o=arguments[i];merge(this,o);}
return this;}});if(!Object.keys){Object.defineProperty(Object.prototype,"keys",{enumerable:false,configurable:true,writable:true,value:function(object){var keys=[];for(var i in object){if(object.hasOwnProperty(i)){keys.push(i);}}
return keys;}});}
if(!Array.prototype.findIndex){Object.defineProperty(Array.prototype,"findIndex",{enumerable:false,configurable:true,writable:true,value:function(f){var value=null;for(var i=0,length=this.length;i<length;i++){value=this[i];if(f(value,i,this)){return i;}}
return-1;}});}
if(!String.prototype.trim){Object.defineProperty(String.prototype,"trim",{enumerable:false,configurable:true,writable:true,value:function(){return this.replace(/^\s+|\s+$/g,"");}});}
Math.clamp=function(a,min,max){if(min===undefined){min=0;};if(max===undefined){max=1;};return(a<min?min:(a>max?max:a));};Math.lerp=function(a,b,i){return a*(1-i)+b*i;};Math.quadraticInterpolate=function(a,b,c,i){var b0=(1-i)*(1-i),b1=2*i*(1-i),b2=i*i;return b0*a+b1*b+b2*c;};Math.cubicInterpolate=function(a,b,c,d,i){var b0=(1-i)*(1-i)*(1-i),b1=3*i*((1-i)*(1-i)),b2=3*(i*i)*(1-i),b3=(i*i*i);return b0*a+b1*b+b2*c+b3*d;};Math.radians=function(degrees){return(Math.PI/180)*degrees;};Math.degrees=function(radians){return(180/Math.PI)*radians;};Math.randomBetween=function(min,max){return Math.random()*(max-min)+min;};Math.randomIntBetween=function(min,max){return Math.floor(Math.random()*(max-min+1))+min;};Math.cltRandom=function(mu,sigma,samples){"use strict";mu=mu||0.5;sigma=sigma||0.5;samples=samples||2;var total=0;for(var i=samples;i--;){total+=Math.random();}
return mu+(total-samples/2)/(samples/2)*sigma;};Math.cltRandomInt=function(min,max){return min+Math.cltRandom(0.5,0.5,2)*(max-min);};"use strict";var vec2=function(x,y){if(arguments.length==1){if(x instanceof Array&&x.length>1){return{x:x[0],y:x[1]};}else if(x.x!==undefined&&x.y!==undefined){return{x:x.x,y:x.y};}
return{x:0,y:0};}
return{x:x||0,y:y||0};};vec2.map=function(v,f){var args=arguments.length==1?[arguments[0]]:Array.apply(null,arguments);args=Array.prototype.slice.call(args,2);return vec2(f.apply(this,[v.x].concat(args)),f.apply(this,[v.y].concat(args)));};vec2.len=function(v){return Math.sqrt(v.x*v.x+v.y*v.y);};vec2.rad=function(v){return Math.atan2(v.y,v.x);};vec2.dot=function(v1,v2){return v1.x*v2.x+v1.y*v2.y;};vec2.norm=function(v){var length=vec2.len(v);if(length){return vec2.div(v,length);}
return vec2();};vec2.reflect=function(v,n){return vec2.add(v,vec2.mul(vec2.mul(n,vec2.dot(v,n)),-2));};vec2.cross=function(v1,v2){return v1.x*v2.y-v1.y*v2.x;};vec2.rot=function(v,r){var sinAngle=Math.sin(r),cosAngle=Math.cos(r),x=cosAngle*v.x-sinAngle*v.y,y=sinAngle*v.x+cosAngle*v.y;return vec2(x,y);};vec2.add=function(v1,v2){if(v2.x!==undefined&&v2.y!==undefined){return vec2(v1.x+v2.x,v1.y+v2.y);}else{return vec2(v1.x+v2,v1.y+v2);}};vec2.sub=function(v1,v2){if(v2.x!==undefined&&v2.y!==undefined){return vec2(v1.x-v2.x,v1.y-v2.y);}else{return vec2(v1.x-v2,v1.y-v2);}};vec2.mul=function(v1,v2){if(v2.x!==undefined&&v2.y!==undefined){return vec2(v1.x*v2.x,v1.y*v2.y);}else{return vec2(v1.x*v2,v1.y*v2);}};vec2.div=function(v1,v2){if(v2.x!==undefined&&v2.y!==undefined){return vec2(v1.x/v2.x,v1.y/v2.y);}else{return vec2(v1.x/v2,v1.y/v2);}};vec2.eq=function(v1,v2){return(v1.x==v2.x&&v1.y==v2.y);};vec2.fromString=function(s){var values=s.split(",",2);if(values.length==2){var x=parseFloat(values[0]),y=parseFloat(values[1]);return vec2(x,y);}
return vec2(0,0);};vec2.toString=function(v,s){return v.x+(s!==undefined?s:",")+v.y;};const parseColor=(function(){const names={"aliceblue":"f0f8ff","antiquewhite":"faebd7","aqua":"0ff","aquamarine":"7fffd4","azure":"f0ffff","beige":"f5f5dc","bisque":"ffe4c4","black":"000","blanchedalmond":"ffebcd","blue":"00f","blueviolet":"8a2be2","brown":"a52a2a","burlywood":"deb887","cadetblue":"5f9ea0","chartreuse":"7fff00","chocolate":"d2691e","coral":"ff7f50","cornflowerblue":"6495ed","cornsilk":"fff8dc","crimson":"dc143c","cyan":"0ff","darkblue":"00008b","darkcyan":"008b8b","darkgoldenrod":"b8860b","darkgray":"a9a9a9","darkgreen":"006400","darkgrey":"a9a9a9","darkkhaki":"bdb76b","darkmagenta":"8b008b","darkolivegreen":"556b2f","darkorange":"ff8c00","darkorchid":"9932cc","darkred":"8b0000","darksalmon":"e9967a","darkseagreen":"8fbc8f","darkslateblue":"483d8b","darkslategray":"2f4f4f","darkslategrey":"2f4f4f","darkturquoise":"00ced1","darkviolet":"9400d3","deeppink":"ff1493","deepskyblue":"00bfff","dimgray":"696969","dimgrey":"696969","dodgerblue":"1e90ff","firebrick":"b22222","floralwhite":"fffaf0","forestgreen":"228b22","fuchsia":"f0f","gainsboro":"dcdcdc","ghostwhite":"f8f8ff","gold":"ffd700","goldenrod":"daa520","gray":"808080","green":"008000","greenyellow":"adff2f","grey":"808080","honeydew":"f0fff0","hotpink":"ff69b4","indianred":"cd5c5c","indigo":"4b0082","ivory":"fffff0","khaki":"f0e68c","lavender":"e6e6fa","lavenderblush":"fff0f5","lawngreen":"7cfc00","lemonchiffon":"fffacd","lightblue":"add8e6","lightcoral":"f08080","lightcyan":"e0ffff","lightgoldenrodyellow":"fafad2","lightgray":"d3d3d3","lightgreen":"90ee90","lightgrey":"d3d3d3","lightpink":"ffb6c1","lightsalmon":"ffa07a","lightseagreen":"20b2aa","lightskyblue":"87cefa","lightslategray":"789","lightslategrey":"789","lightsteelblue":"b0c4de","lightyellow":"ffffe0","lime":"0f0","limegreen":"32cd32","linen":"faf0e6","magenta":"f0f","maroon":"800000","mediumaquamarine":"66cdaa","mediumblue":"0000cd","mediumorchid":"ba55d3","mediumpurple":"9370db","mediumseagreen":"3cb371","mediumslateblue":"7b68ee","mediumspringgreen":"00fa9a","mediumturquoise":"48d1cc","mediumvioletred":"c71585","midnightblue":"191970","mintcream":"f5fffa","mistyrose":"ffe4e1","moccasin":"ffe4b5","navajowhite":"ffdead","navy":"000080","oldlace":"fdf5e6","olive":"808000","olivedrab":"6b8e23","orange":"ffa500","orangered":"ff4500","orchid":"da70d6","palegoldenrod":"eee8aa","palegreen":"98fb98","paleturquoise":"afeeee","palevioletred":"db7093","papayawhip":"ffefd5","peachpuff":"ffdab9","peru":"cd853f","pink":"ffc0cb","plum":"dda0dd","powderblue":"b0e0e6","purple":"800080","rebeccapurple":"639","red":"f00","rosybrown":"bc8f8f","royalblue":"4169e1","saddlebrown":"8b4513","salmon":"fa8072","sandybrown":"f4a460","seagreen":"2e8b57","seashell":"fff5ee","sienna":"a0522d","silver":"c0c0c0","skyblue":"87ceeb","slateblue":"6a5acd","slategray":"708090","slategrey":"708090","snow":"fffafa","springgreen":"00ff7f","steelblue":"4682b4","tan":"d2b48c","teal":"008080","thistle":"d8bfd8","tomato":"ff6347","turquoise":"40e0d0","violet":"ee82ee","wheat":"f5deb3","white":"fff","whitesmoke":"f5f5f5","yellow":"ff0","yellowgreen":"9acd32","transparent":"00000000"};const clamp=(n,a,b)=>n<a?a:(n>b?b:n),round=(n,d)=>{var p=Math.pow(10,d||0);return Math.round(n*p)/p;},hi=n=>clamp(parseInt(n,16),0,255),hf=n=>clamp(round(parseInt(n,16)/255,2),0,1),si=n=>clamp(round(parseFloat(n)),0,255),sf=n=>clamp(round(parseFloat(n),2),0,1),pi=n=>clamp(round(parseFloat(n)/100*255),0,255),uf=n=>clamp(parseFloat(n)/360,0,1),pf=n=>clamp(parseFloat(n)/100,0,1);function hslToRgb(h,s,l,a){var r,g,b,hue=function(p,q,t){if(t<0){t+=1;}
if(t>1){t-=1;}
if(t<1/6){return p+(q-p)*6*t};if(t<1/2){return q;}
if(t<2/3){return p+(q-p)*(2/3-t)*6};return p;};if(s==0){r=g=b=l;}else{var q=l<0.5?l*(1+s):l+s-l*s,p=2*l-q;r=hue(p,q,h+1/3);g=hue(p,q,h);b=hue(p,q,h-1/3);}
return{r:round(r*255),g:round(g*255),b:round(b*255),a:a};}
return function(c){var o={r:0,g:0,b:0,a:0},m=null;if(typeof c=="string"){if(c in names){c="#"+names[c];}
if((m=c.match(/#([a-f0-9])([a-f0-9])([a-f0-9])$/i))!==null){o={r:hi(m[1]+m[1]),g:hi(m[2]+m[2]),b:hi(m[3]+m[3]),a:1};}else if((m=c.match(/#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i))!==null){o={r:hi(m[1]),g:hi(m[2]),b:hi(m[3]),a:1};}else if((m=c.match(/#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i))!==null){o={r:hi(m[1]),g:hi(m[2]),b:hi(m[3]),a:hf(m[4])};}else if((m=c.match(/rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/))!==null){o={r:si(m[1]),g:si(m[2]),b:si(m[3]),a:1};}else if((m=c.match(/rgb\(\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*\)/))!==null){o={r:pi(m[1]),g:pi(m[2]),b:pi(m[3]),a:1};}else if((m=c.match(/rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d?\.?\d*?)?\s*\)/))!==null){o={r:si(m[1]),g:si(m[2]),b:si(m[3]),a:sf(m[4])};}else if((m=c.match(/rgba\(\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d?\.?\d*?)?\s*\)/))!==null){o={r:pi(m[1]),g:pi(m[2]),b:pi(m[3]),a:sf(m[4])};}else if((m=c.match(/hsl\(\s*(\d{1,3}\.?\d?)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*\)/))!==null){o=hslToRgb(uf(m[1]),pf(m[2]),pf(m[3]),1);}else if((m=c.match(/hsla\(\s*(\d{1,3}\.?\d?)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d?\.?\d*?)?\s*\)/))!==null){o=hslToRgb(uf(m[1]),pf(m[2]),pf(m[3]),sf(m[4]));}}else if(typeof c=="object"){if(c.r!==undefined&&c.g!=undefined&&c.b!==undefined){o={r:si(c.r),g:si(c.g),b:si(c.b),a:sf(c.a||1)};}else if(c.h!==undefined&&c.s!==undefined&&c.l!==undefined){o=hslToRgb(uf(c.h),pf(c.s),pf(c.l),sf(c.a||1));}}
return o;};}());var debug=(function(){"use strict";const MARGIN={top:10,left:10},PADDING=4,LINE_HEIGHT=12,FONT="10pt Lucida Console, monospace",TEXT_COLOUR="white",BACKGROUND_COLOUR="rgba(0, 0, 0, 0.5)",MARKER_FONT="9pt Lucida Console, monospace",MARKER_CROSS_SIZE=6,MARKER_CROSS_LINEWIDTH=2,MARKER_LABEL_OFFSET={x:12,y:-6};var values={},markers=[];function drawText(context,x,y,text,font,colour,backgroundColour){context.save();context.font=font;context.textBaseline="top";var bgWidth=context.measureText(text).width+PADDING*2,bgHeight=LINE_HEIGHT+PADDING*2;context.fillStyle=backgroundColour;context.fillRect(x-PADDING,y-PADDING,bgWidth,bgHeight);context.fillStyle=colour;context.fillText(text,x,y);context.restore();}
function drawCross(context,x,y,colour){var halfCrossSize=Math.floor(MARKER_CROSS_SIZE/2);context.save();context.strokeStyle=colour;context.lineWidth=MARKER_CROSS_LINEWIDTH;context.translate(x,y);context.beginPath();context.moveTo(-halfCrossSize,-halfCrossSize);context.lineTo(halfCrossSize,halfCrossSize);context.moveTo(-halfCrossSize,halfCrossSize);context.lineTo(halfCrossSize,-halfCrossSize);context.stroke();context.restore();};return{enabled:true,show:function(name,value,options){var data=Object.assign({value:value,showName:true,showValue:true,font:FONT,colour:TEXT_COLOUR,backgroundColour:BACKGROUND_COLOUR},options);values[name]=data;},marker:function(x,y,name,value,options){var data=Object.assign({position:{x:x,y:y},name:name||"",value:value||"",showName:true,showValue:true,showMarker:true,size:MARKER_CROSS_SIZE,font:MARKER_FONT,colour:TEXT_COLOUR,backgroundColour:BACKGROUND_COLOUR,persistent:false},options);if(name){for(var i=0,length=markers.length;i<length;i++){if(markers[i].name==name){markers[i]=data;return;}}}
markers.push(data);},draw:function(context){if(this.enabled){for(var i=0,length=markers.length;i<length;i++){name=(markers[i].showName&&markers[i].name)?markers[i].name+": ":"";value=markers[i].showValue?markers[i].value:"";context.save();context.translate(markers[i].position.x,markers[i].position.y);if(markers[i].showMarker){drawCross(context,0,0,markers[i].colour);}
if(markers[i].shownName||markers[i].showValue){drawText(context,MARKER_LABEL_OFFSET.x,MARKER_LABEL_OFFSET.y,name+value,markers[i].font,markers[i].colour,markers[i].backgroundColour);}
context.restore();}
context.save();context.setTransform(1,0,0,1,0,0);var y=MARGIN.top,name="",value="";for(var i in values){if(!values.hasOwnProperty(i)){continue;}
if(!values[i].showName&&!values[i].showValue){continue;}
name=values[i].showName?i+": ":"";value=values[i].showValue?values[i].value:"";drawText(context,MARGIN.left,y,name+value,values[i].font,values[i].colour,values[i].backgroundColour);y+=(LINE_HEIGHT+PADDING*2);}
context.restore();}
values={};markers=markers.filter(i=>i.persistent);}};}());var __extends=(this&&this.__extends)||function(d,b){for(var p in b){if(b.hasOwnProperty(p)){d[p]=b[p];}}
function __(){this.constructor=d;}
d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __());};const Tily={};Tily.Main=(function(){"use strict";const _defaultTilyOptions={size:null,handleResize:true,showFPS:false,renderLoop:true};function Main(canvas,options){if(!window){console.log("Couldn't find window. Tily.Main can only be created in the browser!");return}
if(!canvas.getContext){console.log("Canvas not supported!");return;}
this.options={}.extend(_defaultTilyOptions,options||{});this.canvas=canvas;this.context=canvas.getContext("2d");this.width=0;this.height=0;this.activeBuffer=null;this.bufferTransition=null;this.loop=null;this.lastFrameTime=new Date();this.frameCount=0;this.frameTime=0;this.frameRate=0;if(!this.options.size||this.options.handleResize){const self=this;function resize(){self.canvas.width=self.width=canvas.clientWidth*window.devicePixelRatio;self.canvas.height=self.height=canvas.clientHeight*window.devicePixelRatio;}
window.addEventListener("resize",resize,false);resize();}else{this.canvas.width=this.width=this.options.size.width;this.canvas.height=this.height=this.options.size.height;}
if(this.options.renderLoop){loop(this);}}
function loop(t){const now=new Date(),elapsedTime=(now-t.lastFrameTime)/1000;t.lastFrameTime=now;t.frameTime+=elapsedTime;t.frameCount++;if(t.frameTime>1){t.frameRate=t.frameCount;t.frameTime=0;t.frameCount=0;}
t.draw(elapsedTime);t.loop=window.requestAnimationFrame(function(){loop(t)});}
Main.prototype.draw=function(elapsedTime){this.context.save();this.context.clearRect(0,0,this.width,this.height);if(this.options.showFPS){debug.show("FPS",this.frameRate);}
const width=this.width,height=this.height;if(this.bufferTransition){const alpha=this.bufferTransition.update(elapsedTime);if(this.bufferTransition.start){this.context.globalAlpha=1-alpha;this.bufferTransition.start.draw(this.context,elapsedTime,width,height);}
if(this.bufferTransition.finish){this.context.globalAlpha=alpha;this.bufferTransition.finish.draw(this.context,elapsedTime,width,height);}
if(this.bufferTransition.finished){this.bufferTransition=null;}}else if(this.activeBuffer){this.context.globalAlpha=1;this.activeBuffer.draw(this.context,elapsedTime,width,height);}
debug.draw(this.context);this.context.restore();};Main.prototype.activateBuffer=function(buffer,options){const transition=new Tily.BufferTransition(this.activeBuffer,buffer,options);this.bufferTransition=transition;this.activeBuffer=buffer;return new Promise(function(resolve,reject){transition.finishedCallback=resolve;});};Object.defineProperty(Main.prototype,"size",{get:function(){return{width:this.width,height:this.height};}});return Main;}());Tily.Transition=(function(){"use strict";const _defaultTransitionOptions={time:0,easeFunction:null,finishedCallback:null};function Transition(start,finish,options){options={}.extend(_defaultTransitionOptions,options||{});this.start=start;this.finish=finish;this.totalTime=options.time;this.currentTime=0;this.easeFunction=options.easeFunction||Math.lerp;this.finishedCallback=options.finishedCallback||function(start,finish){};this.finished=false;}
Transition.prototype.update=function(elapsedTime){this.currentTime+=elapsedTime;if(this.currentTime<this.totalTime){return this.easeFunction(this.start,this.finish,this.amount);}
if(this.finishedCallback&&!this.finished){this.finishedCallback(this.start,this.finish);}
this.finished=true;return this.finish;};Object.defineProperty(Transition.prototype,"amount",{get:function(){return Math.clamp(this.currentTime/this.totalTime);}});return Transition;}());Tily.BufferTransition=(function(_super){"use strict";__extends(BufferTransition,_super);function BufferTransition(start,finish,options){_super.call(this,start,finish,options);}
BufferTransition.prototype.update=function(elapsedTime){this.currentTime+=elapsedTime;if(this.currentTime<this.totalTime){return this.easeFunction(0,1,this.amount);}
if(this.finishedCallback&&!this.finished){this.finishedCallback(this.start,this.finish);}
this.finished=true;return 1;};return BufferTransition;}(Tily.Transition));Tily.OffsetTransition=(function(_super){"use strict";__extends(OffsetTransition,_super);function OffsetTransition(start,finish,options){_super.call(this,start,finish,options);}
OffsetTransition.prototype.update=function(elapsedTime){this.currentTime+=elapsedTime;if(this.currentTime<this.totalTime){const amount=this.amount;return vec2(this.easeFunction(this.start.x,this.finish.x,amount),this.easeFunction(this.start.y,this.finish.y,amount));}
if(this.finishedCallback&&!this.finished){this.finishedCallback(this.start,this.finish);}
this.finished=true;return this.finish;};return OffsetTransition;}(Tily.Transition));Tily.ScaleTransition=(function(_super){"use strict";__extends(ScaleTransition,_super);function ScaleTransition(start,finish,options){_super.call(this,start,finish,options);}
ScaleTransition.prototype.update=function(elapsedTime){return _super.prototype.update.call(this,elapsedTime);};return ScaleTransition;}(Tily.Transition));Tily.BufferBase=(function(){"use strict";const _defaultBufferOptions={lockedAxis:"x",initialOffsetX:0,initialOffsetY:0,initialScale:16,maximumScale:32,minimumScale:4,clampCamera:false};function BufferBase(options){this.canvas=document.createElement("canvas");this.context=this.canvas.getContext("2d");this.activeTiles=[];this.activeTilesMap={};this.options={}.extend(_defaultBufferOptions,options||{});this.offset=vec2(this.options.initialOffsetX,this.options.initialOffsetY);this.offsetTransition=null;this.scale=this.options.initialScale;this.scaleTransition=null;this.size={width:0,height:0};this.tileSize=0;this.viewSize={width:0,height:0};}
function checkBounds(p,tl,br){return(p.x>=tl.x&&p.x<=br.x&&p.y>=tl.y&&p.y<=br.y);}
function hash(p){return vec2.toString(p,"_");}
BufferBase.prototype.addActiveTile=function(tile){for(let i=0,length=arguments.length;i<length;i++){this.activeTiles.push(arguments[i]);}};BufferBase.prototype.removeActiveTile=function(tile){tile.destroyed=true;};BufferBase.prototype.removeAllActiveTiles=function(){this.activeTiles=[];};BufferBase.prototype.moveOffset=function(x,y,options){var offset=vec2(x,y);if(options.unit=="px"){offset=vec2.div(offset,this.tileSize);}
if(this.offsetTransition){this.offset=this.offsetTransition.update(0);}
if(options.relative===true){offset=vec2.add(this.offset,offset);}
const transition=new Tily.OffsetTransition(vec2(this.offset),vec2(offset),options);this.offsetTransition=transition;this.offset=offset;return new Promise(function(resolve,reject){transition.finishedCallback=resolve;});};Object.defineProperty(BufferBase.prototype,"offsetPixels",{get:function(){return vec2.mul(this.offset,this.tileSize);}});BufferBase.prototype.zoom=function(scale,options){if(this.scaleTransition){this.scale=this.scaleTransition.update(0);}
const transition=new Tily.ScaleTransition(this.scale,scale,options);this.scaleTransition=transition;this.scale=scale;return new Promise(function(resolve,reject){transition.finishedCallback=resolve;});};BufferBase.prototype.getPosition=function(x,y){const tl=vec2.sub(vec2.add(this.offset,0.5),vec2.div(vec2(this.viewSize.width,this.viewSize.height),2));return vec2.map(vec2.add(tl,vec2.div(vec2(x,y),this.tileSize)),Math.floor);};BufferBase.prototype.getTileInfo=function(x,y){const p=vec2(x,y);return{position:p,activeTiles:this.activeTilesMap[hash(p)]||[]};};BufferBase.prototype.updateTransitions=function(elapsedTime){var offset=this.offset;if(this.offsetTransition){offset=this.offsetTransition.update(elapsedTime);if(this.offsetTransition.finished){this.offsetTransition=null;}}
if(this.scaleTransition){this.scale=this.scaleTransition.update(elapsedTime);if(this.scaleTransition.finished){this.scaleTransition=null;}}
return offset;};BufferBase.prototype.updateActiveTilesMap=function(tl,br){const activeTiles=[];var h=null;this.activeTilesMap={};this.activeTiles=this.activeTiles.filter(i=>!i.destroyed);for(let i=0,length=this.activeTiles.length;i<length;i++){if(checkBounds(vec2.add(this.activeTiles[i].position,this.activeTiles[i].offset),tl,br)){activeTiles.push(this.activeTiles[i]);}
h=hash(this.activeTiles[i].position);if(this.activeTilesMap[h]===undefined){this.activeTilesMap[h]=[];}
this.activeTilesMap[h].push(this.activeTiles[i]);}
activeTiles.sort((a,b)=>a.zIndex-b.zIndex);return activeTiles;};return BufferBase;}());Tily.Buffer=(function(_super){"use strict";__extends(Buffer,_super);function Buffer(width,height,options){_super.call(this,options);this.layers=[];this.size.width=width;this.size.height=height;}
Buffer.prototype.addLayer=function(layer,z){layer.container=this;if(z===undefined){this.layers.push(layer);}else if(z==-1){this.layers.unshift(layer);}else{this.layers.splice(z,0,layer);}};Buffer.prototype.removeLayer=function(z){if(this.layers.length<1){return null;}
if(z===undefined){return this.layers.pop();}else if(z==-1){return this.layers.shift();}
return this.layers.splice(z,1)[0];};Buffer.prototype.removeAllLayers=function(){this.layers=[];};Buffer.prototype.moveLayer=function(zFrom,zTo,relative){if(this.layers.length<2){return false;}
if(zFrom<0||zFrom>=this.layers.length){return false;}
const layer=this.layers.splice(zFrom,1)[0],toIndex=Math.clamp(relative?zFrom+zTo:zTo,0,this.layers.length);this.layers.splice(toIndex,0,layer);return true;};Buffer.prototype.resize=function(width,height){for(let i=this.layers.length;i--;){this.layers[i].resize(width,height);}
this.size.width=width;this.size.height=height;};Buffer.prototype.getTileInfo=function(x,y){const tileInfo=_super.prototype.getTileInfo.call(this,x,y);tileInfo.layers=this.layers.map(i=>i.getTile(x,y));return tileInfo;};Buffer.prototype.draw=function(context,elapsedTime,width,height){this.canvas.width=width;this.canvas.height=height;this.context.save();this.context.textBaseline="top";this.context.clearRect(0,0,width,height);var offset=this.updateTransitions(elapsedTime);var lockedAxis=this.options.lockedAxis,maximumScale=this.options.maximumScale;if(this.options.clampCamera){maximumScale=Math.min(maximumScale,this.size.width,this.size.height);if(width>height){lockedAxis="x";}else if(height>width){lockedAxis="y";}}
this.scale=Math.clamp(this.scale,Math.max(this.options.minimumScale,1),maximumScale);this.tileSize=(lockedAxis=="y"?height:width)/this.scale;this.viewSize.width=width/this.tileSize;this.viewSize.height=height/this.tileSize;if(this.options.clampCamera){const centerX=this.viewSize.width*0.5-0.5,centerY=this.viewSize.height*0.5-0.5;this.offset=offset=vec2(Math.clamp(offset.x,centerX,this.size.width-centerX-1),Math.clamp(offset.y,centerY,this.size.height-centerY-1));}
this.context.translate(width*0.5-offset.x*this.tileSize-this.tileSize*0.5,height*0.5-offset.y*this.tileSize-this.tileSize*0.5);const halfSize=vec2(this.viewSize.width*0.5+1,this.viewSize.height*0.5+1),tl=vec2.map(vec2.sub(offset,halfSize),Math.floor),br=vec2.map(vec2.add(offset,halfSize),Math.ceil),activeTiles=this.updateActiveTilesMap(tl,br);var j=0;for(let i=0,length=this.layers.length;i<length;i++){this.layers[i].draw(this.context,this.tileSize,tl,br);while(j<activeTiles.length&&activeTiles[j].zIndex<i+1){activeTiles[j].draw(this.context,elapsedTime,this.tileSize);j++;}}
while(j<activeTiles.length){activeTiles[j].draw(this.context,elapsedTime,this.tileSize);j++;}
this.context.restore();context.drawImage(this.canvas,0,0);};Buffer.prototype.getData=function(){return{layers:this.layers.map(i=>i.getData()),activeTiles:this.activeTiles.map(i=>i.getData()),options:this.options,size:this.size,offset:this.offset,scale:this.scale};};Buffer.fromData=function(data){const buffer=new Tily.Buffer(data.size.width,data.size.height,data.options);buffer.size=data.size;buffer.offset=data.offset;buffer.scale=data.scale;buffer.layers=data.layers.map(i=>Tily.TileLayer.fromData(buffer,i));buffer.activeTiles=data.activeTiles.map(i=>Tily.ActiveTile.fromData(i));return buffer;};Buffer.prototype.serialize=function(){return JSON.stringify(this.getData());};Buffer.deserialize=function(s){var data=null;try{data=JSON.parse(s);}catch(e){console.log("Couldn't deserialize data: %O",e);return null;}
return Tily.Buffer.fromData(data);};return Buffer;}(Tily.BufferBase));Tily.CellBuffer=(function(_super){"use strict";__extends(CellBuffer,_super);const _defaultCellBufferOptions={cellWidth:16,cellHeight:16,minimumX:null,minimumY:null,maximumX:null,maximumY:null,cellFunction:null};function CellBuffer(options){_super.call(this,options);this.cellCache={};this.options=this.options.extend(_defaultCellBufferOptions,options||{});}
function hash(p){return vec2.toString(p,"_");}
CellBuffer.prototype.getTileInfo=function(x,y){const tileInfo=_super.prototype.getTileInfo.call(this,x,y),cell=vec2.map(vec2(x/this.options.cellWidth,y/this.options.cellHeight),Math.floor),cellOffset=vec2(x-cell.x*this.options.cellWidth,y-cell.y*this.options.cellHeight),h=hash(cell);var layers=[];if(this.cellCache[h]){layers=this.cellCache[h].layers.map(i=>i.getTile(cellOffset.x,cellOffset.y));}
tileInfo.cell=cell;tileInfo.layers=layers;return tileInfo;};CellBuffer.prototype.draw=function(context,elapsedTime,width,height){this.canvas.width=width;this.canvas.height=height;this.context.save();this.context.textBaseline="top";this.context.clearRect(0,0,width,height);const offset=this.updateTransitions(elapsedTime);var lockedAxis=this.options.lockedAxis,maximumScale=this.options.maximumScale;const size={width:Infinity,height:Infinity};if(this.options.minimumX&&this.options.maximumX){size.width=(this.options.maximumX-this.options.minimumX)*this.options.cellWidth;}
if(this.options.minimumY&&this.options.maximumY){size.height=(this.options.maximumY-this.options.minimumY)*this.options.cellHeight;}
if(this.options.clampCamera){maximumScale=Math.min(maximumScale,size.width,size.height);if(width>height){lockedAxis="x";}else if(height>width){lockedAxis="y";}}
this.scale=Math.clamp(this.scale,Math.max(this.options.minimumScale,1),maximumScale);this.tileSize=(lockedAxis=="y"?height:width)/this.scale;this.viewSize.width=width/this.tileSize;this.viewSize.height=height/this.tileSize;if(this.options.clampCamera){const centerX=this.viewSize.width*0.5-0.5,centerY=this.viewSize.height*0.5-0.5;if(isFinite(size.width)){this.offset.x=offset.x=Math.clamp(offset.x,centerX,size.width-centerX-1);}
if(isFinite(size.height)){this.offset.y=offset.y=Math.clamp(offset.y,centerY,size.height-centerY-1);}}
this.context.translate(width*0.5-offset.x*this.tileSize-this.tileSize*0.5,height*0.5-offset.y*this.tileSize-this.tileSize*0.5);const halfSize=vec2(this.viewSize.width*0.5+1,this.viewSize.height*0.5+1),tl=vec2.map(vec2.sub(offset,halfSize),Math.floor),br=vec2.map(vec2.add(offset,halfSize),Math.ceil),activeTiles=this.updateActiveTilesMap(tl,br);const cellSize=vec2(this.options.cellWidth,this.options.cellHeight),tlCell=vec2.map(vec2.div(tl,cellSize),Math.floor),brCell=vec2.map(vec2.div(br,cellSize),Math.ceil),cache=this.cellCache,getResolve=function(x,y){return function(cell){cache[hash(vec2(x,y))]=cell;};},getReject=function(x,y){return function(reason){console.log("Couldn't generate cell (%i, %i): %s",x,y,reason);};};var h=null;for(let x=tlCell.x;x<brCell.x;x++){for(let y=tlCell.y;y<brCell.y;y++){h=hash(vec2(x,y));if(this.cellCache[h]===undefined){if(this.options.cellFunction){this.options.cellFunction(this,x,y,getResolve(x,y),getReject(x,y));}
this.cellCache[h]=true;}else if(this.cellCache[h]!==true){this.cellCache[h].draw(this.context,elapsedTime,x,y,this.tileSize,tl,br,activeTiles);}}}
this.context.restore();context.drawImage(this.canvas,0,0);};CellBuffer.prototype.serialize=function(){const cellCache={};for(let i in this.cellCache){if(!this.cellCache.hasOwnProperty(i)){continue;}
cellCache[i]=this.cellCache[i].getData();}
return JSON.stringify({cellCache:cellCache,activeTiles:this.activeTiles.map(i=>i.getData()),options:this.options,offset:this.offset,scale:this.scale});};CellBuffer.deserialize=function(s){var data=null;const cellCache={};try{data=JSON.parse(s);}catch(e){console.log("Couldn't deserialize data: %O",e);return null;}
for(let i in data.cellCache){if(!data.cellCache.hasOwnProperty(i)){continue;}
cellCache[i]=Tily.Cell.fromData(data.cellCache[i]);}
const buffer=new Tily.CellBuffer(data.options);buffer.offset=data.offset;buffer.scale=data.scale;buffer.cellCache=cellCache;buffer.activeTiles=data.activeTiles.map(i=>Tily.ActiveTile.fromData(i));return buffer;};return CellBuffer;}(Tily.BufferBase));Tily.Cell=(function(){"use strict";function Cell(buffer){this.buffer=buffer;this.layers=[];}
function checkBounds(p,tl,br){return(p.x>=tl.x&&p.x<=br.x&&p.y>=tl.y&&p.y<=br.y);}
Cell.prototype.addLayer=function(layer,z){layer.container=this;if(z===undefined){this.layers.push(layer);}else if(z==-1){this.layers.unshift(layer);}else{this.layers.splice(z,0,layer);}};Cell.prototype.removeLayer=function(z){if(this.layers.length<1){return null;}
if(z===undefined){return this.layers.pop();}else if(z==-1){return this.layers.shift();}
return this.layers.splice(z,1)[0];};Cell.prototype.removeAllLayers=function(){this.layers=[];};Cell.prototype.moveLayer=function(zFrom,zTo,relative){if(this.layers.length<2){return false;}<commit_msg>Rebuild after fixing cell loading bug<commit_after>
(function(){Object.defineProperty(Array.prototype,"shuffle",{enumerable:false,configurable:true,writable:true,value:function(){var i=this.length,r=0,swap=null;if(!i){return;}
while(--i){r=Math.floor(Math.random()*(i+1));swap=this[r];this[r]=this[i];this[i]=swap;}}});Object.defineProperty(Object.prototype,"extend",{enumerable:false,configurable:true,writable:true,value:function(){"use strict";var i=0,length=arguments.length,deep=false,merge=function(target,source){for(var p in source){if(source.hasOwnProperty(p)){if(deep&&Object.prototype.toString.call(source[p])==="[object Object]"){if(!target[p]){target[p]={};}
target[p].extend(true,source[p]);}else{target[p]=source[p];}}}};if(typeof arguments[0]=="boolean"){deep=arguments[0];i++;}
for(;i<length;i++){var o=arguments[i];merge(this,o);}
return this;}});if(!Object.keys){Object.defineProperty(Object.prototype,"keys",{enumerable:false,configurable:true,writable:true,value:function(object){var keys=[];for(var i in object){if(object.hasOwnProperty(i)){keys.push(i);}}
return keys;}});}
if(!Array.prototype.findIndex){Object.defineProperty(Array.prototype,"findIndex",{enumerable:false,configurable:true,writable:true,value:function(f){var value=null;for(var i=0,length=this.length;i<length;i++){value=this[i];if(f(value,i,this)){return i;}}
return-1;}});}
if(!String.prototype.trim){Object.defineProperty(String.prototype,"trim",{enumerable:false,configurable:true,writable:true,value:function(){return this.replace(/^\s+|\s+$/g,"");}});}
Math.clamp=function(a,min,max){if(min===undefined){min=0;};if(max===undefined){max=1;};return(a<min?min:(a>max?max:a));};Math.lerp=function(a,b,i){return a*(1-i)+b*i;};Math.quadraticInterpolate=function(a,b,c,i){var b0=(1-i)*(1-i),b1=2*i*(1-i),b2=i*i;return b0*a+b1*b+b2*c;};Math.cubicInterpolate=function(a,b,c,d,i){var b0=(1-i)*(1-i)*(1-i),b1=3*i*((1-i)*(1-i)),b2=3*(i*i)*(1-i),b3=(i*i*i);return b0*a+b1*b+b2*c+b3*d;};Math.radians=function(degrees){return(Math.PI/180)*degrees;};Math.degrees=function(radians){return(180/Math.PI)*radians;};Math.randomBetween=function(min,max){return Math.random()*(max-min)+min;};Math.randomIntBetween=function(min,max){return Math.floor(Math.random()*(max-min+1))+min;};Math.cltRandom=function(mu,sigma,samples){"use strict";mu=mu||0.5;sigma=sigma||0.5;samples=samples||2;var total=0;for(var i=samples;i--;){total+=Math.random();}
return mu+(total-samples/2)/(samples/2)*sigma;};Math.cltRandomInt=function(min,max){return min+Math.cltRandom(0.5,0.5,2)*(max-min);};"use strict";var vec2=function(x,y){if(arguments.length==1){if(x instanceof Array&&x.length>1){return{x:x[0],y:x[1]};}else if(x.x!==undefined&&x.y!==undefined){return{x:x.x,y:x.y};}
return{x:0,y:0};}
return{x:x||0,y:y||0};};vec2.map=function(v,f){var args=arguments.length==1?[arguments[0]]:Array.apply(null,arguments);args=Array.prototype.slice.call(args,2);return vec2(f.apply(this,[v.x].concat(args)),f.apply(this,[v.y].concat(args)));};vec2.len=function(v){return Math.sqrt(v.x*v.x+v.y*v.y);};vec2.rad=function(v){return Math.atan2(v.y,v.x);};vec2.dot=function(v1,v2){return v1.x*v2.x+v1.y*v2.y;};vec2.norm=function(v){var length=vec2.len(v);if(length){return vec2.div(v,length);}
return vec2();};vec2.reflect=function(v,n){return vec2.add(v,vec2.mul(vec2.mul(n,vec2.dot(v,n)),-2));};vec2.cross=function(v1,v2){return v1.x*v2.y-v1.y*v2.x;};vec2.rot=function(v,r){var sinAngle=Math.sin(r),cosAngle=Math.cos(r),x=cosAngle*v.x-sinAngle*v.y,y=sinAngle*v.x+cosAngle*v.y;return vec2(x,y);};vec2.add=function(v1,v2){if(v2.x!==undefined&&v2.y!==undefined){return vec2(v1.x+v2.x,v1.y+v2.y);}else{return vec2(v1.x+v2,v1.y+v2);}};vec2.sub=function(v1,v2){if(v2.x!==undefined&&v2.y!==undefined){return vec2(v1.x-v2.x,v1.y-v2.y);}else{return vec2(v1.x-v2,v1.y-v2);}};vec2.mul=function(v1,v2){if(v2.x!==undefined&&v2.y!==undefined){return vec2(v1.x*v2.x,v1.y*v2.y);}else{return vec2(v1.x*v2,v1.y*v2);}};vec2.div=function(v1,v2){if(v2.x!==undefined&&v2.y!==undefined){return vec2(v1.x/v2.x,v1.y/v2.y);}else{return vec2(v1.x/v2,v1.y/v2);}};vec2.eq=function(v1,v2){return(v1.x==v2.x&&v1.y==v2.y);};vec2.fromString=function(s){var values=s.split(",",2);if(values.length==2){var x=parseFloat(values[0]),y=parseFloat(values[1]);return vec2(x,y);}
return vec2(0,0);};vec2.toString=function(v,s){return v.x+(s!==undefined?s:",")+v.y;};const parseColor=(function(){const names={"aliceblue":"f0f8ff","antiquewhite":"faebd7","aqua":"0ff","aquamarine":"7fffd4","azure":"f0ffff","beige":"f5f5dc","bisque":"ffe4c4","black":"000","blanchedalmond":"ffebcd","blue":"00f","blueviolet":"8a2be2","brown":"a52a2a","burlywood":"deb887","cadetblue":"5f9ea0","chartreuse":"7fff00","chocolate":"d2691e","coral":"ff7f50","cornflowerblue":"6495ed","cornsilk":"fff8dc","crimson":"dc143c","cyan":"0ff","darkblue":"00008b","darkcyan":"008b8b","darkgoldenrod":"b8860b","darkgray":"a9a9a9","darkgreen":"006400","darkgrey":"a9a9a9","darkkhaki":"bdb76b","darkmagenta":"8b008b","darkolivegreen":"556b2f","darkorange":"ff8c00","darkorchid":"9932cc","darkred":"8b0000","darksalmon":"e9967a","darkseagreen":"8fbc8f","darkslateblue":"483d8b","darkslategray":"2f4f4f","darkslategrey":"2f4f4f","darkturquoise":"00ced1","darkviolet":"9400d3","deeppink":"ff1493","deepskyblue":"00bfff","dimgray":"696969","dimgrey":"696969","dodgerblue":"1e90ff","firebrick":"b22222","floralwhite":"fffaf0","forestgreen":"228b22","fuchsia":"f0f","gainsboro":"dcdcdc","ghostwhite":"f8f8ff","gold":"ffd700","goldenrod":"daa520","gray":"808080","green":"008000","greenyellow":"adff2f","grey":"808080","honeydew":"f0fff0","hotpink":"ff69b4","indianred":"cd5c5c","indigo":"4b0082","ivory":"fffff0","khaki":"f0e68c","lavender":"e6e6fa","lavenderblush":"fff0f5","lawngreen":"7cfc00","lemonchiffon":"fffacd","lightblue":"add8e6","lightcoral":"f08080","lightcyan":"e0ffff","lightgoldenrodyellow":"fafad2","lightgray":"d3d3d3","lightgreen":"90ee90","lightgrey":"d3d3d3","lightpink":"ffb6c1","lightsalmon":"ffa07a","lightseagreen":"20b2aa","lightskyblue":"87cefa","lightslategray":"789","lightslategrey":"789","lightsteelblue":"b0c4de","lightyellow":"ffffe0","lime":"0f0","limegreen":"32cd32","linen":"faf0e6","magenta":"f0f","maroon":"800000","mediumaquamarine":"66cdaa","mediumblue":"0000cd","mediumorchid":"ba55d3","mediumpurple":"9370db","mediumseagreen":"3cb371","mediumslateblue":"7b68ee","mediumspringgreen":"00fa9a","mediumturquoise":"48d1cc","mediumvioletred":"c71585","midnightblue":"191970","mintcream":"f5fffa","mistyrose":"ffe4e1","moccasin":"ffe4b5","navajowhite":"ffdead","navy":"000080","oldlace":"fdf5e6","olive":"808000","olivedrab":"6b8e23","orange":"ffa500","orangered":"ff4500","orchid":"da70d6","palegoldenrod":"eee8aa","palegreen":"98fb98","paleturquoise":"afeeee","palevioletred":"db7093","papayawhip":"ffefd5","peachpuff":"ffdab9","peru":"cd853f","pink":"ffc0cb","plum":"dda0dd","powderblue":"b0e0e6","purple":"800080","rebeccapurple":"639","red":"f00","rosybrown":"bc8f8f","royalblue":"4169e1","saddlebrown":"8b4513","salmon":"fa8072","sandybrown":"f4a460","seagreen":"2e8b57","seashell":"fff5ee","sienna":"a0522d","silver":"c0c0c0","skyblue":"87ceeb","slateblue":"6a5acd","slategray":"708090","slategrey":"708090","snow":"fffafa","springgreen":"00ff7f","steelblue":"4682b4","tan":"d2b48c","teal":"008080","thistle":"d8bfd8","tomato":"ff6347","turquoise":"40e0d0","violet":"ee82ee","wheat":"f5deb3","white":"fff","whitesmoke":"f5f5f5","yellow":"ff0","yellowgreen":"9acd32","transparent":"00000000"};const clamp=(n,a,b)=>n<a?a:(n>b?b:n),round=(n,d)=>{var p=Math.pow(10,d||0);return Math.round(n*p)/p;},hi=n=>clamp(parseInt(n,16),0,255),hf=n=>clamp(round(parseInt(n,16)/255,2),0,1),si=n=>clamp(round(parseFloat(n)),0,255),sf=n=>clamp(round(parseFloat(n),2),0,1),pi=n=>clamp(round(parseFloat(n)/100*255),0,255),uf=n=>clamp(parseFloat(n)/360,0,1),pf=n=>clamp(parseFloat(n)/100,0,1);function hslToRgb(h,s,l,a){var r,g,b,hue=function(p,q,t){if(t<0){t+=1;}
if(t>1){t-=1;}
if(t<1/6){return p+(q-p)*6*t};if(t<1/2){return q;}
if(t<2/3){return p+(q-p)*(2/3-t)*6};return p;};if(s==0){r=g=b=l;}else{var q=l<0.5?l*(1+s):l+s-l*s,p=2*l-q;r=hue(p,q,h+1/3);g=hue(p,q,h);b=hue(p,q,h-1/3);}
return{r:round(r*255),g:round(g*255),b:round(b*255),a:a};}
return function(c){var o={r:0,g:0,b:0,a:0},m=null;if(typeof c=="string"){if(c in names){c="#"+names[c];}
if((m=c.match(/#([a-f0-9])([a-f0-9])([a-f0-9])$/i))!==null){o={r:hi(m[1]+m[1]),g:hi(m[2]+m[2]),b:hi(m[3]+m[3]),a:1};}else if((m=c.match(/#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i))!==null){o={r:hi(m[1]),g:hi(m[2]),b:hi(m[3]),a:1};}else if((m=c.match(/#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i))!==null){o={r:hi(m[1]),g:hi(m[2]),b:hi(m[3]),a:hf(m[4])};}else if((m=c.match(/rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/))!==null){o={r:si(m[1]),g:si(m[2]),b:si(m[3]),a:1};}else if((m=c.match(/rgb\(\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*\)/))!==null){o={r:pi(m[1]),g:pi(m[2]),b:pi(m[3]),a:1};}else if((m=c.match(/rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d?\.?\d*?)?\s*\)/))!==null){o={r:si(m[1]),g:si(m[2]),b:si(m[3]),a:sf(m[4])};}else if((m=c.match(/rgba\(\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d?\.?\d*?)?\s*\)/))!==null){o={r:pi(m[1]),g:pi(m[2]),b:pi(m[3]),a:sf(m[4])};}else if((m=c.match(/hsl\(\s*(\d{1,3}\.?\d?)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*\)/))!==null){o=hslToRgb(uf(m[1]),pf(m[2]),pf(m[3]),1);}else if((m=c.match(/hsla\(\s*(\d{1,3}\.?\d?)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d{1,3}\.?\d?%)\s*,\s*(\d?\.?\d*?)?\s*\)/))!==null){o=hslToRgb(uf(m[1]),pf(m[2]),pf(m[3]),sf(m[4]));}}else if(typeof c=="object"){if(c.r!==undefined&&c.g!=undefined&&c.b!==undefined){o={r:si(c.r),g:si(c.g),b:si(c.b),a:sf(c.a||1)};}else if(c.h!==undefined&&c.s!==undefined&&c.l!==undefined){o=hslToRgb(uf(c.h),pf(c.s),pf(c.l),sf(c.a||1));}}
return o;};}());var debug=(function(){"use strict";const MARGIN={top:10,left:10},PADDING=4,LINE_HEIGHT=12,FONT="10pt Lucida Console, monospace",TEXT_COLOUR="white",BACKGROUND_COLOUR="rgba(0, 0, 0, 0.5)",MARKER_FONT="9pt Lucida Console, monospace",MARKER_CROSS_SIZE=6,MARKER_CROSS_LINEWIDTH=2,MARKER_LABEL_OFFSET={x:12,y:-6};var values={},markers=[];function drawText(context,x,y,text,font,colour,backgroundColour){context.save();context.font=font;context.textBaseline="top";var bgWidth=context.measureText(text).width+PADDING*2,bgHeight=LINE_HEIGHT+PADDING*2;context.fillStyle=backgroundColour;context.fillRect(x-PADDING,y-PADDING,bgWidth,bgHeight);context.fillStyle=colour;context.fillText(text,x,y);context.restore();}
function drawCross(context,x,y,colour){var halfCrossSize=Math.floor(MARKER_CROSS_SIZE/2);context.save();context.strokeStyle=colour;context.lineWidth=MARKER_CROSS_LINEWIDTH;context.translate(x,y);context.beginPath();context.moveTo(-halfCrossSize,-halfCrossSize);context.lineTo(halfCrossSize,halfCrossSize);context.moveTo(-halfCrossSize,halfCrossSize);context.lineTo(halfCrossSize,-halfCrossSize);context.stroke();context.restore();};return{enabled:true,show:function(name,value,options){var data=Object.assign({value:value,showName:true,showValue:true,font:FONT,colour:TEXT_COLOUR,backgroundColour:BACKGROUND_COLOUR},options);values[name]=data;},marker:function(x,y,name,value,options){var data=Object.assign({position:{x:x,y:y},name:name||"",value:value||"",showName:true,showValue:true,showMarker:true,size:MARKER_CROSS_SIZE,font:MARKER_FONT,colour:TEXT_COLOUR,backgroundColour:BACKGROUND_COLOUR,persistent:false},options);if(name){for(var i=0,length=markers.length;i<length;i++){if(markers[i].name==name){markers[i]=data;return;}}}
markers.push(data);},draw:function(context){if(this.enabled){for(var i=0,length=markers.length;i<length;i++){name=(markers[i].showName&&markers[i].name)?markers[i].name+": ":"";value=markers[i].showValue?markers[i].value:"";context.save();context.translate(markers[i].position.x,markers[i].position.y);if(markers[i].showMarker){drawCross(context,0,0,markers[i].colour);}
if(markers[i].shownName||markers[i].showValue){drawText(context,MARKER_LABEL_OFFSET.x,MARKER_LABEL_OFFSET.y,name+value,markers[i].font,markers[i].colour,markers[i].backgroundColour);}
context.restore();}
context.save();context.setTransform(1,0,0,1,0,0);var y=MARGIN.top,name="",value="";for(var i in values){if(!values.hasOwnProperty(i)){continue;}
if(!values[i].showName&&!values[i].showValue){continue;}
name=values[i].showName?i+": ":"";value=values[i].showValue?values[i].value:"";drawText(context,MARGIN.left,y,name+value,values[i].font,values[i].colour,values[i].backgroundColour);y+=(LINE_HEIGHT+PADDING*2);}
context.restore();}
values={};markers=markers.filter(i=>i.persistent);}};}());var __extends=(this&&this.__extends)||function(d,b){for(var p in b){if(b.hasOwnProperty(p)){d[p]=b[p];}}
function __(){this.constructor=d;}
d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __());};const Tily={};Tily.Main=(function(){"use strict";const _defaultTilyOptions={size:null,handleResize:true,showFPS:false,renderLoop:true};function Main(canvas,options){if(!window){console.log("Couldn't find window. Tily.Main can only be created in the browser!");return}
if(!canvas.getContext){console.log("Canvas not supported!");return;}
this.options={}.extend(_defaultTilyOptions,options||{});this.canvas=canvas;this.context=canvas.getContext("2d");this.width=0;this.height=0;this.activeBuffer=null;this.bufferTransition=null;this.loop=null;this.lastFrameTime=new Date();this.frameCount=0;this.frameTime=0;this.frameRate=0;if(!this.options.size||this.options.handleResize){const self=this;function resize(){self.canvas.width=self.width=canvas.clientWidth*window.devicePixelRatio;self.canvas.height=self.height=canvas.clientHeight*window.devicePixelRatio;}
window.addEventListener("resize",resize,false);resize();}else{this.canvas.width=this.width=this.options.size.width;this.canvas.height=this.height=this.options.size.height;}
if(this.options.renderLoop){loop(this);}}
function loop(t){const now=new Date(),elapsedTime=(now-t.lastFrameTime)/1000;t.lastFrameTime=now;t.frameTime+=elapsedTime;t.frameCount++;if(t.frameTime>1){t.frameRate=t.frameCount;t.frameTime=0;t.frameCount=0;}
t.draw(elapsedTime);t.loop=window.requestAnimationFrame(function(){loop(t)});}
Main.prototype.draw=function(elapsedTime){this.context.save();this.context.clearRect(0,0,this.width,this.height);if(this.options.showFPS){debug.show("FPS",this.frameRate);}
const width=this.width,height=this.height;if(this.bufferTransition){const alpha=this.bufferTransition.update(elapsedTime);if(this.bufferTransition.start){this.context.globalAlpha=1-alpha;this.bufferTransition.start.draw(this.context,elapsedTime,width,height);}
if(this.bufferTransition.finish){this.context.globalAlpha=alpha;this.bufferTransition.finish.draw(this.context,elapsedTime,width,height);}
if(this.bufferTransition.finished){this.bufferTransition=null;}}else if(this.activeBuffer){this.context.globalAlpha=1;this.activeBuffer.draw(this.context,elapsedTime,width,height);}
debug.draw(this.context);this.context.restore();};Main.prototype.activateBuffer=function(buffer,options){const transition=new Tily.BufferTransition(this.activeBuffer,buffer,options);this.bufferTransition=transition;this.activeBuffer=buffer;return new Promise(function(resolve,reject){transition.finishedCallback=resolve;});};Object.defineProperty(Main.prototype,"size",{get:function(){return{width:this.width,height:this.height};}});return Main;}());Tily.Transition=(function(){"use strict";const _defaultTransitionOptions={time:0,easeFunction:null,finishedCallback:null};function Transition(start,finish,options){options={}.extend(_defaultTransitionOptions,options||{});this.start=start;this.finish=finish;this.totalTime=options.time;this.currentTime=0;this.easeFunction=options.easeFunction||Math.lerp;this.finishedCallback=options.finishedCallback||function(start,finish){};this.finished=false;}
Transition.prototype.update=function(elapsedTime){this.currentTime+=elapsedTime;if(this.currentTime<this.totalTime){return this.easeFunction(this.start,this.finish,this.amount);}
if(this.finishedCallback&&!this.finished){this.finishedCallback(this.start,this.finish);}
this.finished=true;return this.finish;};Object.defineProperty(Transition.prototype,"amount",{get:function(){return Math.clamp(this.currentTime/this.totalTime);}});return Transition;}());Tily.BufferTransition=(function(_super){"use strict";__extends(BufferTransition,_super);function BufferTransition(start,finish,options){_super.call(this,start,finish,options);}
BufferTransition.prototype.update=function(elapsedTime){this.currentTime+=elapsedTime;if(this.currentTime<this.totalTime){return this.easeFunction(0,1,this.amount);}
if(this.finishedCallback&&!this.finished){this.finishedCallback(this.start,this.finish);}
this.finished=true;return 1;};return BufferTransition;}(Tily.Transition));Tily.OffsetTransition=(function(_super){"use strict";__extends(OffsetTransition,_super);function OffsetTransition(start,finish,options){_super.call(this,start,finish,options);}
OffsetTransition.prototype.update=function(elapsedTime){this.currentTime+=elapsedTime;if(this.currentTime<this.totalTime){const amount=this.amount;return vec2(this.easeFunction(this.start.x,this.finish.x,amount),this.easeFunction(this.start.y,this.finish.y,amount));}
if(this.finishedCallback&&!this.finished){this.finishedCallback(this.start,this.finish);}
this.finished=true;return this.finish;};return OffsetTransition;}(Tily.Transition));Tily.ScaleTransition=(function(_super){"use strict";__extends(ScaleTransition,_super);function ScaleTransition(start,finish,options){_super.call(this,start,finish,options);}
ScaleTransition.prototype.update=function(elapsedTime){return _super.prototype.update.call(this,elapsedTime);};return ScaleTransition;}(Tily.Transition));Tily.BufferBase=(function(){"use strict";const _defaultBufferOptions={lockedAxis:"x",initialOffsetX:0,initialOffsetY:0,initialScale:16,maximumScale:32,minimumScale:4,clampCamera:false};function BufferBase(options){this.canvas=document.createElement("canvas");this.context=this.canvas.getContext("2d");this.activeTiles=[];this.activeTilesMap={};this.options={}.extend(_defaultBufferOptions,options||{});this.offset=vec2(this.options.initialOffsetX,this.options.initialOffsetY);this.offsetTransition=null;this.scale=this.options.initialScale;this.scaleTransition=null;this.size={width:0,height:0};this.tileSize=0;this.viewSize={width:0,height:0};}
function checkBounds(p,tl,br){return(p.x>=tl.x&&p.x<=br.x&&p.y>=tl.y&&p.y<=br.y);}
function hash(p){return vec2.toString(p,"_");}
BufferBase.prototype.addActiveTile=function(tile){for(let i=0,length=arguments.length;i<length;i++){this.activeTiles.push(arguments[i]);}};BufferBase.prototype.removeActiveTile=function(tile){tile.destroyed=true;};BufferBase.prototype.removeAllActiveTiles=function(){this.activeTiles=[];};BufferBase.prototype.moveOffset=function(x,y,options){var offset=vec2(x,y);if(options.unit=="px"){offset=vec2.div(offset,this.tileSize);}
if(this.offsetTransition){this.offset=this.offsetTransition.update(0);}
if(options.relative===true){offset=vec2.add(this.offset,offset);}
const transition=new Tily.OffsetTransition(vec2(this.offset),vec2(offset),options);this.offsetTransition=transition;this.offset=offset;return new Promise(function(resolve,reject){transition.finishedCallback=resolve;});};Object.defineProperty(BufferBase.prototype,"offsetPixels",{get:function(){return vec2.mul(this.offset,this.tileSize);}});BufferBase.prototype.zoom=function(scale,options){if(this.scaleTransition){this.scale=this.scaleTransition.update(0);}
const transition=new Tily.ScaleTransition(this.scale,scale,options);this.scaleTransition=transition;this.scale=scale;return new Promise(function(resolve,reject){transition.finishedCallback=resolve;});};BufferBase.prototype.getPosition=function(x,y){const tl=vec2.sub(vec2.add(this.offset,0.5),vec2.div(vec2(this.viewSize.width,this.viewSize.height),2));return vec2.map(vec2.add(tl,vec2.div(vec2(x,y),this.tileSize)),Math.floor);};BufferBase.prototype.getTileInfo=function(x,y){const p=vec2(x,y);return{position:p,activeTiles:this.activeTilesMap[hash(p)]||[]};};BufferBase.prototype.updateTransitions=function(elapsedTime){var offset=this.offset;if(this.offsetTransition){offset=this.offsetTransition.update(elapsedTime);if(this.offsetTransition.finished){this.offsetTransition=null;}}
if(this.scaleTransition){this.scale=this.scaleTransition.update(elapsedTime);if(this.scaleTransition.finished){this.scaleTransition=null;}}
return offset;};BufferBase.prototype.updateActiveTilesMap=function(tl,br){const activeTiles=[];var h=null;this.activeTilesMap={};this.activeTiles=this.activeTiles.filter(i=>!i.destroyed);for(let i=0,length=this.activeTiles.length;i<length;i++){if(checkBounds(vec2.add(this.activeTiles[i].position,this.activeTiles[i].offset),tl,br)){activeTiles.push(this.activeTiles[i]);}
h=hash(this.activeTiles[i].position);if(this.activeTilesMap[h]===undefined){this.activeTilesMap[h]=[];}
this.activeTilesMap[h].push(this.activeTiles[i]);}
activeTiles.sort((a,b)=>a.zIndex-b.zIndex);return activeTiles;};return BufferBase;}());Tily.Buffer=(function(_super){"use strict";__extends(Buffer,_super);function Buffer(width,height,options){_super.call(this,options);this.layers=[];this.size.width=width;this.size.height=height;}
Buffer.prototype.addLayer=function(layer,z){layer.container=this;if(z===undefined){this.layers.push(layer);}else if(z==-1){this.layers.unshift(layer);}else{this.layers.splice(z,0,layer);}};Buffer.prototype.removeLayer=function(z){if(this.layers.length<1){return null;}
if(z===undefined){return this.layers.pop();}else if(z==-1){return this.layers.shift();}
return this.layers.splice(z,1)[0];};Buffer.prototype.removeAllLayers=function(){this.layers=[];};Buffer.prototype.moveLayer=function(zFrom,zTo,relative){if(this.layers.length<2){return false;}
if(zFrom<0||zFrom>=this.layers.length){return false;}
const layer=this.layers.splice(zFrom,1)[0],toIndex=Math.clamp(relative?zFrom+zTo:zTo,0,this.layers.length);this.layers.splice(toIndex,0,layer);return true;};Buffer.prototype.resize=function(width,height){for(let i=this.layers.length;i--;){this.layers[i].resize(width,height);}
this.size.width=width;this.size.height=height;};Buffer.prototype.getTileInfo=function(x,y){const tileInfo=_super.prototype.getTileInfo.call(this,x,y);tileInfo.layers=this.layers.map(i=>i.getTile(x,y));return tileInfo;};Buffer.prototype.draw=function(context,elapsedTime,width,height){this.canvas.width=width;this.canvas.height=height;this.context.save();this.context.textBaseline="top";this.context.clearRect(0,0,width,height);var offset=this.updateTransitions(elapsedTime);var lockedAxis=this.options.lockedAxis,maximumScale=this.options.maximumScale;if(this.options.clampCamera){maximumScale=Math.min(maximumScale,this.size.width,this.size.height);if(width>height){lockedAxis="x";}else if(height>width){lockedAxis="y";}}
this.scale=Math.clamp(this.scale,Math.max(this.options.minimumScale,1),maximumScale);this.tileSize=(lockedAxis=="y"?height:width)/this.scale;this.viewSize.width=width/this.tileSize;this.viewSize.height=height/this.tileSize;if(this.options.clampCamera){const centerX=this.viewSize.width*0.5-0.5,centerY=this.viewSize.height*0.5-0.5;this.offset=offset=vec2(Math.clamp(offset.x,centerX,this.size.width-centerX-1),Math.clamp(offset.y,centerY,this.size.height-centerY-1));}
this.context.translate(width*0.5-offset.x*this.tileSize-this.tileSize*0.5,height*0.5-offset.y*this.tileSize-this.tileSize*0.5);const halfSize=vec2(this.viewSize.width*0.5+1,this.viewSize.height*0.5+1),tl=vec2.map(vec2.sub(offset,halfSize),Math.floor),br=vec2.map(vec2.add(offset,halfSize),Math.ceil),activeTiles=this.updateActiveTilesMap(tl,br);var j=0;for(let i=0,length=this.layers.length;i<length;i++){this.layers[i].draw(this.context,this.tileSize,tl,br);while(j<activeTiles.length&&activeTiles[j].zIndex<i+1){activeTiles[j].draw(this.context,elapsedTime,this.tileSize);j++;}}
while(j<activeTiles.length){activeTiles[j].draw(this.context,elapsedTime,this.tileSize);j++;}
this.context.restore();context.drawImage(this.canvas,0,0);};Buffer.prototype.getData=function(){return{layers:this.layers.map(i=>i.getData()),activeTiles:this.activeTiles.map(i=>i.getData()),options:this.options,size:this.size,offset:this.offset,scale:this.scale};};Buffer.fromData=function(data){const buffer=new Tily.Buffer(data.size.width,data.size.height,data.options);buffer.size=data.size;buffer.offset=data.offset;buffer.scale=data.scale;buffer.layers=data.layers.map(i=>Tily.TileLayer.fromData(buffer,i));buffer.activeTiles=data.activeTiles.map(i=>Tily.ActiveTile.fromData(i));return buffer;};Buffer.prototype.serialize=function(){return JSON.stringify(this.getData());};Buffer.deserialize=function(s){var data=null;try{data=JSON.parse(s);}catch(e){console.log("Couldn't deserialize data: %O",e);return null;}
return Tily.Buffer.fromData(data);};return Buffer;}(Tily.BufferBase));Tily.CellBuffer=(function(_super){"use strict";__extends(CellBuffer,_super);const _defaultCellBufferOptions={cellWidth:16,cellHeight:16,minimumX:null,minimumY:null,maximumX:null,maximumY:null,cellFunction:null};function CellBuffer(options){_super.call(this,options);this.cellCache={};this.options=this.options.extend(_defaultCellBufferOptions,options||{});}
function hash(p){return vec2.toString(p,"_");}
CellBuffer.prototype.getTileInfo=function(x,y){const tileInfo=_super.prototype.getTileInfo.call(this,x,y),cell=vec2.map(vec2(x/this.options.cellWidth,y/this.options.cellHeight),Math.floor),cellOffset=vec2(x-cell.x*this.options.cellWidth,y-cell.y*this.options.cellHeight),h=hash(cell);var layers=[];if(this.cellCache[h]){layers=this.cellCache[h].layers.map(i=>i.getTile(cellOffset.x,cellOffset.y));}
tileInfo.cell=cell;tileInfo.layers=layers;return tileInfo;};CellBuffer.prototype.draw=function(context,elapsedTime,width,height){this.canvas.width=width;this.canvas.height=height;this.context.save();this.context.textBaseline="top";this.context.clearRect(0,0,width,height);const offset=this.updateTransitions(elapsedTime);var lockedAxis=this.options.lockedAxis,maximumScale=this.options.maximumScale;const size={width:Infinity,height:Infinity};if(this.options.minimumX&&this.options.maximumX){size.width=(this.options.maximumX-this.options.minimumX)*this.options.cellWidth;}
if(this.options.minimumY&&this.options.maximumY){size.height=(this.options.maximumY-this.options.minimumY)*this.options.cellHeight;}
if(this.options.clampCamera){maximumScale=Math.min(maximumScale,size.width,size.height);if(width>height){lockedAxis="x";}else if(height>width){lockedAxis="y";}}
this.scale=Math.clamp(this.scale,Math.max(this.options.minimumScale,1),maximumScale);this.tileSize=(lockedAxis=="y"?height:width)/this.scale;this.viewSize.width=width/this.tileSize;this.viewSize.height=height/this.tileSize;if(this.options.clampCamera){const centerX=this.viewSize.width*0.5-0.5,centerY=this.viewSize.height*0.5-0.5;if(isFinite(size.width)){this.offset.x=offset.x=Math.clamp(offset.x,centerX,size.width-centerX-1);}
if(isFinite(size.height)){this.offset.y=offset.y=Math.clamp(offset.y,centerY,size.height-centerY-1);}}
this.context.translate(width*0.5-offset.x*this.tileSize-this.tileSize*0.5,height*0.5-offset.y*this.tileSize-this.tileSize*0.5);const halfSize=vec2(this.viewSize.width*0.5+1,this.viewSize.height*0.5+1),tl=vec2.map(vec2.sub(offset,halfSize),Math.floor),br=vec2.map(vec2.add(offset,halfSize),Math.ceil),activeTiles=this.updateActiveTilesMap(tl,br);const cellSize=vec2(this.options.cellWidth,this.options.cellHeight),tlCell=vec2.map(vec2.div(tl,cellSize),Math.floor),brCell=vec2.map(vec2.div(br,cellSize),Math.ceil),cache=this.cellCache,getResolve=function(x,y){return function(cell){cache[hash(vec2(x,y))]=cell;};},getReject=function(x,y){return function(reason){console.log("Couldn't generate cell (%i, %i): %s",x,y,reason);};};var h=null;for(let x=tlCell.x;x<brCell.x;x++){for(let y=tlCell.y;y<brCell.y;y++){h=hash(vec2(x,y));if(this.cellCache[h]===undefined){this.cellCache[h]=true;if(this.options.cellFunction){this.options.cellFunction(this,x,y,getResolve(x,y),getReject(x,y));}}else if(this.cellCache[h]!==true){this.cellCache[h].draw(this.context,elapsedTime,x,y,this.tileSize,tl,br,activeTiles);}}}
this.context.restore();context.drawImage(this.canvas,0,0);};CellBuffer.prototype.serialize=function(){const cellCache={};for(let i in this.cellCache){if(!this.cellCache.hasOwnProperty(i)){continue;}
cellCache[i]=this.cellCache[i].getData();}
return JSON.stringify({cellCache:cellCache,activeTiles:this.activeTiles.map(i=>i.getData()),options:this.options,offset:this.offset,scale:this.scale});};CellBuffer.deserialize=function(s){var data=null;const cellCache={};try{data=JSON.parse(s);}catch(e){console.log("Couldn't deserialize data: %O",e);return null;}
for(let i in data.cellCache){if(!data.cellCache.hasOwnProperty(i)){continue;}
cellCache[i]=Tily.Cell.fromData(data.cellCache[i]);}
const buffer=new Tily.CellBuffer(data.options);buffer.offset=data.offset;buffer.scale=data.scale;buffer.cellCache=cellCache;buffer.activeTiles=data.activeTiles.map(i=>Tily.ActiveTile.fromData(i));return buffer;};return CellBuffer;}(Tily.BufferBase));Tily.Cell=(function(){"use strict";function Cell(buffer){this.buffer=buffer;this.layers=[];}
function checkBounds(p,tl,br){return(p.x>=tl.x&&p.x<=br.x&&p.y>=tl.y&&p.y<=br.y);}
Cell.prototype.addLayer=function(layer,z){layer.container=this;if(z===undefined){this.layers.push(layer);}else if(z==-1){this.layers.unshift(layer);}else{this.layers.splice(z,0,layer);}};Cell.prototype.removeLayer=function(z){if(this.layers.length<1){return null;}
if(z===undefined){return this.layers.pop();}else if(z==-1){return this.layers.shift();}
return this.layers.splice(z,1)[0];};Cell.prototype.removeAllLayers=function(){this.layers=[];};Cell.prototype.moveLayer=function(zFrom,zTo,relative){if(this.layers.length<2){return false;}
{'fraction_non_alphanumeric': 0.23609326234624564, 'fraction_numerical': 0.03364654438640119, 'mean_word_length': 16.701033973412112, 'pattern_counts': {'":': 306, '<': 65, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3651794', 'n_tokens_mistral': 23594, 'n_tokens_neox': 22891, 'n_words': 775}