-
-
Notifications
You must be signed in to change notification settings - Fork 261
/
rot.min.js
136 lines (136 loc) · 67.1 KB
/
rot.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
function _assertThisInitialized(r){if(void 0===r)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return r}
function _createForOfIteratorHelperLoose(r,y){var x="undefined"!==typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(x)return(x=x.call(r)).next.bind(x);if(Array.isArray(r)||(x=_unsupportedIterableToArray(r))||y&&r&&"number"===typeof r.length){x&&(r=x);var E=0;return function(){return E>=r.length?{done:!0}:{done:!1,value:r[E++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}
function _unsupportedIterableToArray(r,y){if(r){if("string"===typeof r)return _arrayLikeToArray(r,y);var x=Object.prototype.toString.call(r).slice(8,-1);"Object"===x&&r.constructor&&(x=r.constructor.name);if("Map"===x||"Set"===x)return Array.from(r);if("Arguments"===x||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(x))return _arrayLikeToArray(r,y)}}function _arrayLikeToArray(r,y){if(null==y||y>r.length)y=r.length;for(var x=0,E=Array(y);x<y;x++)E[x]=r[x];return E}
function _inheritsLoose(r,y){r.prototype=Object.create(y.prototype);r.prototype.constructor=r;_setPrototypeOf(r,y)}function _setPrototypeOf(r,y){_setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(x,E){x.__proto__=E;return x};return _setPrototypeOf(r,y)}
(function(r,y){"object"===typeof exports&&"undefined"!==typeof module?y(exports):"function"===typeof define&&define.amd?define(["exports"],y):(r="undefined"!==typeof globalThis?globalThis:r||self,y(r.ROT={}))})(this,function(r){function y(k,h){return(k%h+h)%h}function x(k,h,d){void 0===h&&(h=0);void 0===d&&(d=1);return k<h?h:k>d?d:k}function E(k){return k.charAt(0).toUpperCase()+k.substring(1)}function U(k){for(var h=arguments.length,d=Array(1<h?h-1:0),a=1;a<h;a++)d[a-1]=arguments[a];var b=U.map;
return k.replace(/%(?:([a-z]+)|(?:{([^}]+)}))/gi,function(c,e,f,g){if("%"==k.charAt(g-1))return c.substring(1);if(!d.length)return c;f=(e||f).split(",");e=f.shift()||"";g=b[e.toLowerCase()];if(!g)return c;c=d.shift();c=c[g].apply(c,f);e=e.charAt(0);e!=e.toLowerCase()&&(c=E(c));return c})}function P(k){var h;if(k in V)var d=V[k];else{if("#"==k.charAt(0))if(d=(k.match(/[0-9a-f]/gi)||[]).map(function(a){return parseInt(a,16)}),3==d.length)d=d.map(function(a){return 17*a});else for(h=0;3>h;h++)d[h+1]+=
16*d[h],d.splice(h,1);else d=(h=k.match(/rgb\(([0-9, ]+)\)/i))?h[1].split(/\s*,\s*/).map(function(a){return parseInt(a)}):[0,0,0];V[k]=d}return d.slice()}function ea(k){for(var h=arguments.length,d=Array(1<h?h-1:0),a=1;a<h;a++)d[a-1]=arguments[a];for(h=0;3>h;h++)for(a=0;a<d.length;a++)k[h]+=d[a][h];return k}function fa(k,h,d){void 0===d&&(d=.5);for(var a=k.slice(),b=0;3>b;b++)a[b]=Math.round(a[b]+d*(h[b]-k[b]));return a}function ha(k,h,d){void 0===d&&(d=.5);k=W(k);h=W(h);for(var a=0;3>a;a++)k[a]+=
d*(h[a]-k[a]);return ia(k)}function W(k){var h=k[0]/255,d=k[1]/255;k=k[2]/255;var a=Math.max(h,d,k),b=Math.min(h,d,k),c=0,e=(a+b)/2;if(a==b)b=0;else{var f=a-b;b=.5<e?f/(2-a-b):f/(a+b);switch(a){case h:c=(d-k)/f+(d<k?6:0);break;case d:c=(k-h)/f+2;break;case k:c=(h-d)/f+4}c/=6}return[c,b,e]}function X(k,h,d){0>d&&(d+=1);1<d&&--d;return d<1/6?k+6*(h-k)*d:.5>d?h:d<2/3?k+(h-k)*(2/3-d)*6:k}function ia(k){var h=k[2];if(0==k[1])return h=Math.round(255*h),[h,h,h];var d=k[1];d=.5>h?h*(1+d):h+d-h*d;var a=2*
h-d;h=X(a,d,k[0]+1/3);var b=X(a,d,k[0]);k=X(a,d,k[0]-1/3);return[Math.round(255*h),Math.round(255*b),Math.round(255*k)]}function oa(k,h,d){var a=k.createShader(k.VERTEX_SHADER);k.shaderSource(a,h);k.compileShader(a);if(!k.getShaderParameter(a,k.COMPILE_STATUS))throw Error(k.getShaderInfoLog(a)||"");h=k.createShader(k.FRAGMENT_SHADER);k.shaderSource(h,d);k.compileShader(h);if(!k.getShaderParameter(h,k.COMPILE_STATUS))throw Error(k.getShaderInfoLog(h)||"");d=k.createProgram();k.attachShader(d,a);k.attachShader(d,
h);k.linkProgram(d);if(!k.getProgramParameter(d,k.LINK_STATUS))throw Error(k.getProgramInfoLog(d)||"");return d}function pa(k){var h=new Float32Array([0,0,1,0,0,1,1,1]),d=k.createBuffer();k.bindBuffer(k.ARRAY_BUFFER,d);k.bufferData(k.ARRAY_BUFFER,h,k.STATIC_DRAW);k.enableVertexAttribArray(0);k.vertexAttribPointer(0,2,k.FLOAT,!1,0,0)}function Q(k){if(!(k in Y)){if("transparent"==k)var h=[0,0,0,0];else if(-1<k.indexOf("rgba")){h=(k.match(/[\d.]+/g)||[]).map(Number);for(var d=0;3>d;d++)h[d]/=255}else h=
P(k).map(function(a){return a/255}),h.push(1);Y[k]=h}return Y[k]}function Z(k){k=P(k);return 36*Math.floor(.0234375*k[0])+6*Math.floor(.0234375*k[1])+1*Math.floor(.0234375*k[2])+16}function aa(k,h){var d=[],a=0;k.replace(qa,function(c,e,f,g){var l=k.substring(a,g);l.length&&d.push({type:0,value:l});d.push({type:"c"==e?2:3,value:f.trim()});a=g+c.length;return""});var b=k.substring(a);b.length&&d.push({type:0,value:b});return ra(d,h)}function ra(k,h){h||=Infinity;for(var d=0,a=0,b=-1;d<k.length;){var c=
k[d];1==c.type&&(a=0,b=-1);if(0!=c.type)d++;else{for(;0==a&&" "==c.value.charAt(0);)c.value=c.value.substring(1);var e=c.value.indexOf("\n");if(-1!=e){c.value=R(k,d,e,!0);for(e=c.value.split("");e.length&&" "==e[e.length-1];)e.pop();c.value=e.join("")}if(c.value.length){if(a+c.value.length>h){for(e=-1;;){var f=c.value.indexOf(" ",e+1);if(-1==f)break;if(a+f>h)break;e=f}-1!=e?c.value=R(k,d,e,!0):-1!=b?(d=k[b],c=d.value.lastIndexOf(" "),d.value=R(k,b,c,!0),d=b):c.value=R(k,d,h-a,!1)}else a+=c.value.length,
-1!=c.value.indexOf(" ")&&(b=d);d++}else k.splice(d,1)}}k.push({type:1});h=null;for(a=0;a<k.length;a++)switch(b=k[a],b.type){case 0:h=b;break;case 1:if(h){for(b=h.value.split("");b.length&&" "==b[b.length-1];)b.pop();h.value=b.join("")}h=null}k.pop();return k}function R(k,h,d,a){a={type:0,value:k[h].value.substring(d+(a?1:0))};k.splice(h+1,0,{type:1},a);return k[h].value.substring(0,d)}function ja(k,h,d){d[h[k+1]]=d[k];h[d[k]]=h[k+1];d[k]=k+1;h[k+1]=k}function ka(k,h,d){d[h[k]]=d[k];h[d[k]]=h[k];
d[k]=k;h[k]=k}var t=(new (function(){function k(){this._c=this._s2=this._s1=this._s0=this._seed=0}var h=k.prototype;h.getSeed=function(){return this._seed};h.setSeed=function(d){this._seed=d=1>d?1/d:d;this._s0=2.3283064365386963E-10*(d>>>0);d=69069*d+1>>>0;this._s1=2.3283064365386963E-10*d;this._s2=2.3283064365386963E-10*(69069*d+1>>>0);this._c=1;return this};h.getUniform=function(){var d=2091639*this._s0+2.3283064365386963E-10*this._c;this._s0=this._s1;this._s1=this._s2;this._c=d|0;return this._s2=
d-this._c};h.getUniformInt=function(d,a){var b=Math.max(d,a);d=Math.min(d,a);return Math.floor(this.getUniform()*(b-d+1))+d};h.getNormal=function(d,a){void 0===d&&(d=0);void 0===a&&(a=1);do{var b=2*this.getUniform()-1;var c=2*this.getUniform()-1;c=b*b+c*c}while(1<c||0==c);return d+b*Math.sqrt(-2*Math.log(c)/c)*a};h.getPercentage=function(){return 1+Math.floor(100*this.getUniform())};h.getItem=function(d){return d.length?d[Math.floor(this.getUniform()*d.length)]:null};h.shuffle=function(d){var a=[];
for(d=d.slice();d.length;){var b=d.indexOf(this.getItem(d));a.push(d.splice(b,1)[0])}return a};h.getWeightedValue=function(d){var a=0;for(c in d)a+=d[c];a*=this.getUniform();var b;var c=0;for(b in d)if(c+=d[b],a<c)break;return b};h.getState=function(){return[this._s0,this._s1,this._s2,this._c]};h.setState=function(d){this._s0=d[0];this._s1=d[1];this._s2=d[2];this._c=d[3];return this};h.clone=function(){return(new k).setState(this.getState())};return k}())).setSeed(Date.now()),M=function(){function k(){}
var h=k.prototype;h.getContainer=function(){return null};h.setOptions=function(d){this._options=d};return k}(),N=function(k){function h(){var a=k.call(this)||this;a._ctx=document.createElement("canvas").getContext("2d");return a}_inheritsLoose(h,k);var d=h.prototype;d.schedule=function(a){requestAnimationFrame(a)};d.getContainer=function(){return this._ctx.canvas};d.setOptions=function(a){k.prototype.setOptions.call(this,a);a=(a.fontStyle?a.fontStyle+" ":"")+" "+a.fontSize+"px "+a.fontFamily;this._ctx.font=
a;this._updateSize();this._ctx.font=a;this._ctx.textAlign="center";this._ctx.textBaseline="middle"};d.clear=function(){var a=this._ctx.globalCompositeOperation;this._ctx.globalCompositeOperation="copy";this._ctx.fillStyle=this._options.bg;this._ctx.fillRect(0,0,this._ctx.canvas.width,this._ctx.canvas.height);this._ctx.globalCompositeOperation=a};d.eventToPosition=function(a,b){var c=this._ctx.canvas,e=c.getBoundingClientRect();a-=e.left;b-=e.top;a*=c.width/e.width;b*=c.height/e.height;return 0>a||
0>b||a>=c.width||b>=c.height?[-1,-1]:this._normalizedEventToPosition(a,b)};return h}(M);U.map={s:"toString"};var sa=Object.freeze({__proto__:null,mod:y,clamp:x,capitalize:E,format:U}),S=function(k){function h(){var a=k.call(this)||this;a._spacingX=0;a._spacingY=0;a._hexSize=0;return a}_inheritsLoose(h,k);var d=h.prototype;d.draw=function(a,b){var c=a[2],e=a[3],f=a[4];a=[(a[0]+1)*this._spacingX,a[1]*this._spacingY+this._hexSize];this._options.transpose&&a.reverse();b&&(this._ctx.fillStyle=f,this._fill(a[0],
a[1]));if(c)for(this._ctx.fillStyle=e,b=[].concat(c),c=0;c<b.length;c++)this._ctx.fillText(b[c],a[0],Math.ceil(a[1]))};d.computeSize=function(a,b){this._options.transpose&&(a+=b,b=a-b,a-=b);return[Math.floor(a/this._spacingX)-1,Math.floor((b-2*this._hexSize)/this._spacingY+1)]};d.computeFontSize=function(a,b){this._options.transpose&&(a+=b,b=a-b,a-=b);a=Math.min(2*a/((this._options.width+1)*Math.sqrt(3))-1,b/(2+1.5*(this._options.height-1)));b=this._ctx.font;this._ctx.font="100px "+this._options.fontFamily;
var c=Math.ceil(this._ctx.measureText("W").width);this._ctx.font=b;a=Math.floor(a)+1;return Math.ceil(2*a/(this._options.spacing*(1+c/100/Math.sqrt(3))))-1};d._normalizedEventToPosition=function(a,b){if(this._options.transpose){a+=b;b=a-b;a-=b;var c=this._ctx.canvas.width}else c=this._ctx.canvas.height;b=Math.floor(b/(c/this._options.height));y(b,2)?(a-=this._spacingX,a=1+2*Math.floor(a/(2*this._spacingX))):a=2*Math.floor(a/(2*this._spacingX));return[a,b]};d._fill=function(a,b){var c=this._hexSize,
e=this._options.border,f=this._ctx;f.beginPath();this._options.transpose?(f.moveTo(a-c+e,b),f.lineTo(a-c/2+e,b+this._spacingX-e),f.lineTo(a+c/2-e,b+this._spacingX-e),f.lineTo(a+c-e,b),f.lineTo(a+c/2-e,b-this._spacingX+e),f.lineTo(a-c/2+e,b-this._spacingX+e),f.lineTo(a-c+e,b)):(f.moveTo(a,b-c+e),f.lineTo(a+this._spacingX-e,b-c/2+e),f.lineTo(a+this._spacingX-e,b+c/2-e),f.lineTo(a,b+c-e),f.lineTo(a-this._spacingX+e,b+c/2-e),f.lineTo(a-this._spacingX+e,b-c/2+e),f.lineTo(a,b-c+e));f.fill()};d._updateSize=
function(){var a=this._options,b=Math.ceil(this._ctx.measureText("W").width);this._hexSize=Math.floor(a.spacing*(a.fontSize+b/Math.sqrt(3))/2);this._spacingX=this._hexSize*Math.sqrt(3)/2;this._spacingY=1.5*this._hexSize;if(a.transpose){b="height";var c="width"}else b="width",c="height";this._ctx.canvas[b]=Math.ceil((a.width+1)*this._spacingX);this._ctx.canvas[c]=Math.ceil((a.height-1)*this._spacingY+2*this._hexSize)};return h}(N),J=function(k){function h(){var a=k.call(this)||this;a._spacingX=0;a._spacingY=
0;a._canvasCache={};return a}_inheritsLoose(h,k);var d=h.prototype;d.setOptions=function(a){k.prototype.setOptions.call(this,a);this._canvasCache={}};d.draw=function(a,b){h.cache?this._drawWithCache(a):this._drawNoCache(a,b)};d._drawWithCache=function(a){var b=a[0],c=a[1],e=a[2],f=a[3],g=a[4];a=""+e+f+g;if(a in this._canvasCache)var l=this._canvasCache[a];else{var m=this._options.border;l=document.createElement("canvas");var n=l.getContext("2d");l.width=this._spacingX;l.height=this._spacingY;n.fillStyle=
g;n.fillRect(m,m,l.width-m,l.height-m);if(e)for(n.fillStyle=f,n.font=this._ctx.font,n.textAlign="center",n.textBaseline="middle",e=[].concat(e),f=0;f<e.length;f++)n.fillText(e[f],this._spacingX/2,Math.ceil(this._spacingY/2));this._canvasCache[a]=l}this._ctx.drawImage(l,b*this._spacingX,c*this._spacingY)};d._drawNoCache=function(a,b){var c=a[0],e=a[1],f=a[2],g=a[3];a=a[4];b&&(b=this._options.border,this._ctx.fillStyle=a,this._ctx.fillRect(c*this._spacingX+b,e*this._spacingY+b,this._spacingX-b,this._spacingY-
b));if(f)for(this._ctx.fillStyle=g,f=[].concat(f),g=0;g<f.length;g++)this._ctx.fillText(f[g],(c+.5)*this._spacingX,Math.ceil((e+.5)*this._spacingY))};d.computeSize=function(a,b){return[Math.floor(a/this._spacingX),Math.floor(b/this._spacingY)]};d.computeFontSize=function(a,b){a=Math.floor(a/this._options.width);b=Math.floor(b/this._options.height);var c=this._ctx.font;this._ctx.font="100px "+this._options.fontFamily;var e=Math.ceil(this._ctx.measureText("W").width);this._ctx.font=c;a=e/100*b/a;1<
a&&(b=Math.floor(b/a));return Math.floor(b/this._options.spacing)};d._normalizedEventToPosition=function(a,b){return[Math.floor(a/this._spacingX),Math.floor(b/this._spacingY)]};d._updateSize=function(){var a=this._options,b=Math.ceil(this._ctx.measureText("W").width);this._spacingX=Math.ceil(a.spacing*b);this._spacingY=Math.ceil(a.spacing*a.fontSize);a.forceSquareRatio&&(this._spacingX=this._spacingY=Math.max(this._spacingX,this._spacingY));this._ctx.canvas.width=a.width*this._spacingX;this._ctx.canvas.height=
a.height*this._spacingY};return h}(N);J.cache=!1;var F=function(k){function h(){var a=k.call(this)||this;a._colorCanvas=document.createElement("canvas");return a}_inheritsLoose(h,k);var d=h.prototype;d.draw=function(a,b){var c=a[0],e=a[1],f=a[2],g=a[3],l=a[4];a=this._options.tileWidth;var m=this._options.tileHeight;b&&(this._options.tileColorize?this._ctx.clearRect(c*a,e*m,a,m):(this._ctx.fillStyle=l,this._ctx.fillRect(c*a,e*m,a,m)));if(f)for(b=[].concat(f),g=[].concat(g),l=[].concat(l),f=0;f<b.length;f++){var n=
this._options.tileMap[b[f]];if(!n)throw Error('Char "'+b[f]+'" not found in tileMap');if(this._options.tileColorize){var p=this._colorCanvas,q=p.getContext("2d");q.globalCompositeOperation="source-over";q.clearRect(0,0,a,m);var u=g[f],v=l[f];q.drawImage(this._options.tileSet,n[0],n[1],a,m,0,0,a,m);"transparent"!=u&&(q.fillStyle=u,q.globalCompositeOperation="source-atop",q.fillRect(0,0,a,m));"transparent"!=v&&(q.fillStyle=v,q.globalCompositeOperation="destination-over",q.fillRect(0,0,a,m));this._ctx.drawImage(p,
c*a,e*m,a,m)}else this._ctx.drawImage(this._options.tileSet,n[0],n[1],a,m,c*a,e*m,a,m)}};d.computeSize=function(a,b){return[Math.floor(a/this._options.tileWidth),Math.floor(b/this._options.tileHeight)]};d.computeFontSize=function(){throw Error("Tile backend does not understand font size");};d._normalizedEventToPosition=function(a,b){return[Math.floor(a/this._options.tileWidth),Math.floor(b/this._options.tileHeight)]};d._updateSize=function(){var a=this._options;this._ctx.canvas.width=a.width*a.tileWidth;
this._ctx.canvas.height=a.height*a.tileHeight;this._colorCanvas.width=a.tileWidth;this._colorCanvas.height=a.tileHeight};return h}(N),V={black:[0,0,0],navy:[0,0,128],darkblue:[0,0,139],mediumblue:[0,0,205],blue:[0,0,255],darkgreen:[0,100,0],green:[0,128,0],teal:[0,128,128],darkcyan:[0,139,139],deepskyblue:[0,191,255],darkturquoise:[0,206,209],mediumspringgreen:[0,250,154],lime:[0,255,0],springgreen:[0,255,127],aqua:[0,255,255],cyan:[0,255,255],midnightblue:[25,25,112],dodgerblue:[30,144,255],forestgreen:[34,
139,34],seagreen:[46,139,87],darkslategray:[47,79,79],darkslategrey:[47,79,79],limegreen:[50,205,50],mediumseagreen:[60,179,113],turquoise:[64,224,208],royalblue:[65,105,225],steelblue:[70,130,180],darkslateblue:[72,61,139],mediumturquoise:[72,209,204],indigo:[75,0,130],darkolivegreen:[85,107,47],cadetblue:[95,158,160],cornflowerblue:[100,149,237],mediumaquamarine:[102,205,170],dimgray:[105,105,105],dimgrey:[105,105,105],slateblue:[106,90,205],olivedrab:[107,142,35],slategray:[112,128,144],slategrey:[112,
128,144],lightslategray:[119,136,153],lightslategrey:[119,136,153],mediumslateblue:[123,104,238],lawngreen:[124,252,0],chartreuse:[127,255,0],aquamarine:[127,255,212],maroon:[128,0,0],purple:[128,0,128],olive:[128,128,0],gray:[128,128,128],grey:[128,128,128],skyblue:[135,206,235],lightskyblue:[135,206,250],blueviolet:[138,43,226],darkred:[139,0,0],darkmagenta:[139,0,139],saddlebrown:[139,69,19],darkseagreen:[143,188,143],lightgreen:[144,238,144],mediumpurple:[147,112,216],darkviolet:[148,0,211],palegreen:[152,
251,152],darkorchid:[153,50,204],yellowgreen:[154,205,50],sienna:[160,82,45],brown:[165,42,42],darkgray:[169,169,169],darkgrey:[169,169,169],lightblue:[173,216,230],greenyellow:[173,255,47],paleturquoise:[175,238,238],lightsteelblue:[176,196,222],powderblue:[176,224,230],firebrick:[178,34,34],darkgoldenrod:[184,134,11],mediumorchid:[186,85,211],rosybrown:[188,143,143],darkkhaki:[189,183,107],silver:[192,192,192],mediumvioletred:[199,21,133],indianred:[205,92,92],peru:[205,133,63],chocolate:[210,105,
30],tan:[210,180,140],lightgray:[211,211,211],lightgrey:[211,211,211],palevioletred:[216,112,147],thistle:[216,191,216],orchid:[218,112,214],goldenrod:[218,165,32],crimson:[220,20,60],gainsboro:[220,220,220],plum:[221,160,221],burlywood:[222,184,135],lightcyan:[224,255,255],lavender:[230,230,250],darksalmon:[233,150,122],violet:[238,130,238],palegoldenrod:[238,232,170],lightcoral:[240,128,128],khaki:[240,230,140],aliceblue:[240,248,255],honeydew:[240,255,240],azure:[240,255,255],sandybrown:[244,164,
96],wheat:[245,222,179],beige:[245,245,220],whitesmoke:[245,245,245],mintcream:[245,255,250],ghostwhite:[248,248,255],salmon:[250,128,114],antiquewhite:[250,235,215],linen:[250,240,230],lightgoldenrodyellow:[250,250,210],oldlace:[253,245,230],red:[255,0,0],fuchsia:[255,0,255],magenta:[255,0,255],deeppink:[255,20,147],orangered:[255,69,0],tomato:[255,99,71],hotpink:[255,105,180],coral:[255,127,80],darkorange:[255,140,0],lightsalmon:[255,160,122],orange:[255,165,0],lightpink:[255,182,193],pink:[255,
192,203],gold:[255,215,0],peachpuff:[255,218,185],navajowhite:[255,222,173],moccasin:[255,228,181],bisque:[255,228,196],mistyrose:[255,228,225],blanchedalmond:[255,235,205],papayawhip:[255,239,213],lavenderblush:[255,240,245],seashell:[255,245,238],cornsilk:[255,248,220],lemonchiffon:[255,250,205],floralwhite:[255,250,240],snow:[255,250,250],yellow:[255,255,0],lightyellow:[255,255,224],ivory:[255,255,240],white:[255,255,255]};N=Object.freeze({__proto__:null,fromString:P,add:function(k){for(var h=
k.slice(),d=arguments.length,a=Array(1<d?d-1:0),b=1;b<d;b++)a[b-1]=arguments[b];for(d=0;3>d;d++)for(b=0;b<a.length;b++)h[d]+=a[b][d];return h},add_:ea,multiply:function(k){for(var h=k.slice(),d=arguments.length,a=Array(1<d?d-1:0),b=1;b<d;b++)a[b-1]=arguments[b];for(d=0;3>d;d++){for(b=0;b<a.length;b++)h[d]*=a[b][d]/255;h[d]=Math.round(h[d])}return h},multiply_:function(k){for(var h=arguments.length,d=Array(1<h?h-1:0),a=1;a<h;a++)d[a-1]=arguments[a];for(h=0;3>h;h++){for(a=0;a<d.length;a++)k[h]*=d[a][h]/
255;k[h]=Math.round(k[h])}return k},interpolate:fa,lerp:fa,interpolateHSL:ha,lerpHSL:ha,randomize:function(k,h){h instanceof Array||(h=Math.round(t.getNormal(0,h)));k=k.slice();for(var d=0;3>d;d++)k[d]+=h instanceof Array?Math.round(t.getNormal(0,h[d])):h;return k},rgb2hsl:W,hsl2rgb:ia,toRGB:function(k){return"rgb("+k.map(function(h){return x(h,0,255)}).join(",")+")"},toHex:function(k){return"#"+k.map(function(h){return x(h,0,255).toString(16).padStart(2,"0")}).join("")}});var D=function(k){function h(){var a=
k.call(this)||this;a._uniforms={};try{a._gl=a._initWebGL()}catch(b){"string"===typeof b?alert(b):b instanceof Error&&alert(b.message)}return a}_inheritsLoose(h,k);h.isSupported=function(){return!!document.createElement("canvas").getContext("webgl2",{preserveDrawingBuffer:!0})};var d=h.prototype;d.schedule=function(a){requestAnimationFrame(a)};d.getContainer=function(){return this._gl.canvas};d.setOptions=function(a){var b=this;k.prototype.setOptions.call(this,a);this._updateSize();var c=this._options.tileSet;
c&&"complete"in c&&!c.complete?c.addEventListener("load",function(){return b._updateTexture(c)}):this._updateTexture(c)};d.draw=function(a,b){var c=this._gl,e=this._options,f=a[0],g=a[1],l=a[2],m=a[3];a=a[4];c.scissor(f*e.tileWidth,c.canvas.height-(g+1)*e.tileHeight,e.tileWidth,e.tileHeight);b&&(e.tileColorize?c.clearColor(0,0,0,0):c.clearColor.apply(c,Q(a)),c.clear(c.COLOR_BUFFER_BIT));if(l)for(b=[].concat(l),l=[].concat(a),m=[].concat(m),c.uniform2fv(this._uniforms.targetPosRel,[f,g]),f=0;f<b.length;f++){g=
this._options.tileMap[b[f]];if(!g)throw Error('Char "'+b[f]+'" not found in tileMap');c.uniform1f(this._uniforms.colorize,e.tileColorize?1:0);c.uniform2fv(this._uniforms.tilesetPosAbs,g);e.tileColorize&&(c.uniform4fv(this._uniforms.tint,Q(m[f])),c.uniform4fv(this._uniforms.bg,Q(l[f])));c.drawArrays(c.TRIANGLE_STRIP,0,4)}};d.clear=function(){var a=this._gl;a.clearColor.apply(a,Q(this._options.bg));a.scissor(0,0,a.canvas.width,a.canvas.height);a.clear(a.COLOR_BUFFER_BIT)};d.computeSize=function(a,b){return[Math.floor(a/
this._options.tileWidth),Math.floor(b/this._options.tileHeight)]};d.computeFontSize=function(){throw Error("Tile backend does not understand font size");};d.eventToPosition=function(a,b){var c=this._gl.canvas,e=c.getBoundingClientRect();a-=e.left;b-=e.top;a*=c.width/e.width;b*=c.height/e.height;return 0>a||0>b||a>=c.width||b>=c.height?[-1,-1]:this._normalizedEventToPosition(a,b)};d._initWebGL=function(){var a=this,b=document.createElement("canvas").getContext("webgl2",{preserveDrawingBuffer:!0});
window.gl=b;var c=oa(b,ta,ua);b.useProgram(c);pa(b);va.forEach(function(e){return a._uniforms[e]=b.getUniformLocation(c,e)});this._program=c;b.enable(b.BLEND);b.blendFuncSeparate(b.SRC_ALPHA,b.ONE_MINUS_SRC_ALPHA,b.ONE,b.ONE_MINUS_SRC_ALPHA);b.enable(b.SCISSOR_TEST);return b};d._normalizedEventToPosition=function(a,b){return[Math.floor(a/this._options.tileWidth),Math.floor(b/this._options.tileHeight)]};d._updateSize=function(){var a=this._gl,b=this._options,c=[b.width*b.tileWidth,b.height*b.tileHeight];
a.canvas.width=c[0];a.canvas.height=c[1];a.viewport(0,0,c[0],c[1]);a.uniform2fv(this._uniforms.tileSize,[b.tileWidth,b.tileHeight]);a.uniform2fv(this._uniforms.targetSize,c)};d._updateTexture=function(a){var b=this._gl,c=b.createTexture();b.bindTexture(b.TEXTURE_2D,c);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.NEAREST);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.NEAREST);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,b.REPEAT);b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,b.REPEAT);
b.pixelStorei(b.UNPACK_FLIP_Y_WEBGL,0);b.texImage2D(b.TEXTURE_2D,0,b.RGBA,b.RGBA,b.UNSIGNED_BYTE,a)};return h}(M),va="targetPosRel tilesetPosAbs tileSize targetSize colorize bg tint".split(" "),ta="#version 300 es\n\nin vec2 tilePosRel;\nout vec2 tilesetPosPx;\n\nuniform vec2 tilesetPosAbs;\nuniform vec2 tileSize;\nuniform vec2 targetSize;\nuniform vec2 targetPosRel;\n\nvoid main() {\n\tvec2 targetPosPx = (targetPosRel + tilePosRel) * tileSize;\n\tvec2 targetPosNdc = ((targetPosPx / targetSize)-0.5)*2.0;\n\ttargetPosNdc.y *= -1.0;\n\n\tgl_Position = vec4(targetPosNdc, 0.0, 1.0);\n\ttilesetPosPx = tilesetPosAbs + tilePosRel * tileSize;\n}",
ua="#version 300 es\nprecision highp float;\n\nin vec2 tilesetPosPx;\nout vec4 fragColor;\nuniform sampler2D image;\nuniform bool colorize;\nuniform vec4 bg;\nuniform vec4 tint;\n\nvoid main() {\n\tfragColor = vec4(0, 0, 0, 1);\n\n\tvec4 texel = texelFetch(image, ivec2(tilesetPosPx), 0);\n\n\tif (colorize) {\n\t\ttexel.rgb = tint.a * tint.rgb + (1.0-tint.a) * texel.rgb;\n\t\tfragColor.rgb = texel.a*texel.rgb + (1.0-texel.a)*bg.rgb;\n\t\tfragColor.a = texel.a + (1.0-texel.a)*bg.a;\n\t} else {\n\t\tfragColor = texel;\n\t}\n}",
Y={},z=function(k){function h(){var a=k.call(this)||this;a._offset=[0,0];a._cursor=[-1,-1];a._lastColor="";return a}_inheritsLoose(h,k);var d=h.prototype;d.schedule=function(a){setTimeout(a,1E3/60)};d.setOptions=function(a){k.prototype.setOptions.call(this,a);var b=[a.width,a.height];this._offset=this.computeSize().map(function(c,e){return Math.floor((c-b[e])/2)})};d.clear=function(){process.stdout.write("\u001b[0;48;5;"+Z(this._options.bg)+"m\u001b[2J")};d.draw=function(a,b){var c=a[2],e=a[3],f=
a[4],g=this._offset[0]+a[0],l=this._offset[1]+a[1];a=this.computeSize();if(!(0>g||g>=a[0]||0>l||l>=a[1])){if(g!==this._cursor[0]||l!==this._cursor[1])process.stdout.write("\u001b["+(l+1)+";"+(g+1)+"H"),this._cursor[0]=g,this._cursor[1]=l;b&&(c||=" ");c&&(b="\u001b[0;38;5;"+Z(e)+";48;5;"+Z(f)+"m",b!==this._lastColor&&(process.stdout.write(b),this._lastColor=b),"\t"!=c&&(c=[].concat(c),process.stdout.write(c[0])),this._cursor[0]++,this._cursor[0]>=a[0]&&(this._cursor[0]=0,this._cursor[1]++))}};d.computeFontSize=
function(){throw Error("Terminal backend has no notion of font size");};d.eventToPosition=function(a,b){return[a,b]};d.computeSize=function(){return[process.stdout.columns,process.stdout.rows]};return h}(M),qa=/%([bc]){([^}]*)}/g;M=Object.freeze({__proto__:null,TYPE_TEXT:0,TYPE_NEWLINE:1,TYPE_FG:2,TYPE_BG:3,measure:function(k,h){var d={width:0,height:1};k=aa(k,h);for(var a=h=0;a<k.length;a++){var b=k[a];switch(b.type){case 0:h+=b.value.length;break;case 1:d.height++,d.width=Math.max(d.width,h),h=
0}}d.width=Math.max(d.width,h);return d},tokenize:aa});var C={4:[[0,-1],[1,0],[0,1],[-1,0]],8:[[0,-1],[1,-1],[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1]],6:[[-1,-1],[1,-1],[2,0],[1,1],[-1,1],[-2,0]]},wa={hex:S,rect:J,tile:F,"tile-gl":D,term:z},xa={width:80,height:25,transpose:!1,layout:"rect",fontSize:15,spacing:1,border:0,forceSquareRatio:!1,fontFamily:"monospace",fontStyle:"",fg:"#ccc",bg:"#000",tileWidth:32,tileHeight:32,tileMap:{},tileSet:null,tileColorize:!1},K=function(){function k(d){void 0===
d&&(d={});this._data={};this._dirty=!1;this._options={};d=Object.assign({},xa,d);this.setOptions(d);this.DEBUG=this.DEBUG.bind(this);this._tick=this._tick.bind(this);this._backend.schedule(this._tick)}var h=k.prototype;h.DEBUG=function(d,a,b){var c=[this._options.bg,this._options.fg];this.draw(d,a,null,null,c[b%c.length])};h.clear=function(){this._data={};this._dirty=!0};h.setOptions=function(d){Object.assign(this._options,d);if(d.width||d.height||d.fontSize||d.fontFamily||d.spacing||d.layout)d.layout&&
(this._backend=new wa[d.layout]),this._backend.setOptions(this._options),this._dirty=!0;return this};h.getOptions=function(){return this._options};h.getContainer=function(){return this._backend.getContainer()};h.computeSize=function(d,a){return this._backend.computeSize(d,a)};h.computeFontSize=function(d,a){return this._backend.computeFontSize(d,a)};h.computeTileSize=function(d,a){return[Math.floor(d/this._options.width),Math.floor(a/this._options.height)]};h.eventToPosition=function(d){if("touches"in
d){var a=d.touches[0].clientX;d=d.touches[0].clientY}else a=d.clientX,d=d.clientY;return this._backend.eventToPosition(a,d)};h.draw=function(d,a,b,c,e){c||(c=this._options.fg);e||(e=this._options.bg);var f=d+","+a;this._data[f]=[d,a,b,c,e];!0!==this._dirty&&(this._dirty||(this._dirty={}),this._dirty[f]=!0)};h.drawOver=function(d,a,b,c,e){var f=this._data[d+","+a];f?(f[2]=b||f[2],f[3]=c||f[3],f[4]=e||f[4]):this.draw(d,a,b,c,e)};h.drawText=function(d,a,b,c){var e=null,f=null,g=d,l=1;c||=this._options.width-
d;for(b=aa(b,c);b.length;)switch(c=b.shift(),c.type){case 0:for(var m,n=!1,p,q=!1,u=0;u<c.value.length;u++){m=c.value.charCodeAt(u);var v=c.value.charAt(u);if("term"===this._options.layout&&(p=m>>8,17===p||46<=p&&159>=p||172<=p&&215>=p||43360<=m&&43391>=m)){this.draw(g+0,a,v,e,f);this.draw(g+1,a,"\t",e,f);g+=2;continue}p=65280<m&&65377>m||65500<m&&65512>m||65518<m;m=32==v.charCodeAt(0)||12288==v.charCodeAt(0);!q||p||m||g++;p&&!n&&g++;this.draw(g++,a,v,e,f);n=m;q=p}break;case 2:e=c.value||null;break;
case 3:f=c.value||null;break;case 1:g=d,a++,l++}return l};h._tick=function(){this._backend.schedule(this._tick);if(this._dirty){if(!0===this._dirty){this._backend.clear();for(var d in this._data)this._draw(d,!1)}else for(var a in this._dirty)this._draw(a,!0);this._dirty=!1}};h._draw=function(d,a){d=this._data[d];d[4]!=this._options.bg&&(a=!0);this._backend.draw(d,a)};return k}();K.Rect=J;K.Hex=S;K.Tile=F;K.TileGL=D;K.Term=z;S=function(){function k(d){this._options={words:!1,order:3,prior:.001};Object.assign(this._options,
d);this._suffix=this._boundary=String.fromCharCode(0);this._prefix=[];for(d=0;d<this._options.order;d++)this._prefix.push(this._boundary);this._priorValues={};this._priorValues[this._boundary]=this._options.prior;this._data={}}var h=k.prototype;h.clear=function(){this._data={};this._priorValues={}};h.generate=function(){for(var d=[this._sample(this._prefix)];d[d.length-1]!=this._boundary;)d.push(this._sample(d));return this._join(d.slice(0,-1))};h.observe=function(d){d=this._split(d);for(var a=0;a<
d.length;a++)this._priorValues[d[a]]=this._options.prior;d=this._prefix.concat(d).concat(this._suffix);for(a=this._options.order;a<d.length;a++)for(var b=d.slice(a-this._options.order,a),c=d[a],e=0;e<b.length;e++){var f=b.slice(e);this._observeEvent(f,c)}};h.getStats=function(){var d=[],a=Object.keys(this._priorValues).length;a--;d.push("distinct samples: "+a);a=Object.keys(this._data).length;var b=0,c;for(c in this._data)b+=Object.keys(this._data[c]).length;d.push("dictionary size (contexts): "+
a);d.push("dictionary size (events): "+b);return d.join(", ")};h._split=function(d){return d.split(this._options.words?/\s+/:"")};h._join=function(d){return d.join(this._options.words?" ":"")};h._observeEvent=function(d,a){d=this._join(d);d in this._data||(this._data[d]={});d=this._data[d];a in d||(d[a]=0);d[a]++};h._sample=function(d){d=this._backoff(d);d=this._join(d);d=this._data[d];var a={};if(this._options.prior){for(var b in this._priorValues)a[b]=this._priorValues[b];for(var c in d)a[c]+=d[c]}else a=
d;return t.getWeightedValue(a)};h._backoff=function(d){for(d.length>this._options.order?d=d.slice(-this._options.order):d.length<this._options.order&&(d=this._prefix.slice(0,this._options.order-d.length).concat(d));!(this._join(d)in this._data)&&0<d.length;)d=d.slice(1);return d};return k}();var la=function(){function k(){this.heap=[];this.timestamp=0}var h=k.prototype;h.lessThan=function(d,a){return d.key==a.key?d.timestamp<a.timestamp:d.key<a.key};h.shift=function(d){this.heap=this.heap.map(function(a){return{key:a.key+
d,value:a.value,timestamp:a.timestamp}})};h.len=function(){return this.heap.length};h.push=function(d,a){this.timestamp+=1;var b=this.len();this.heap.push({value:d,timestamp:this.timestamp,key:a});this.updateUp(b)};h.pop=function(){if(0==this.len())throw Error("no element to pop");var d=this.heap[0];1<this.len()?(this.heap[0]=this.heap.pop(),this.updateDown(0)):this.heap.pop();return d};h.find=function(d){for(var a=0;a<this.len();a++)if(d==this.heap[a].value)return this.heap[a];return null};h.remove=
function(d){for(var a=null,b=0;b<this.len();b++)d==this.heap[b].value&&(a=b);if(null===a)return!1;1<this.len()?(b=this.heap.pop(),b.value!=d&&(this.heap[a]=b,this.updateDown(a))):this.heap.pop();return!0};h.parentNode=function(d){return Math.floor((d-1)/2)};h.leftChildNode=function(d){return 2*d+1};h.rightChildNode=function(d){return 2*d+2};h.existNode=function(d){return 0<=d&&d<this.heap.length};h.swap=function(d,a){var b=this.heap[d];this.heap[d]=this.heap[a];this.heap[a]=b};h.minNode=function(d){var a=
d.filter(this.existNode.bind(this));d=a[0];a=_createForOfIteratorHelperLoose(a);for(var b;!(b=a()).done;)b=b.value,this.lessThan(this.heap[b],this.heap[d])&&(d=b);return d};h.updateUp=function(d){if(0!=d){var a=this.parentNode(d);this.existNode(a)&&this.lessThan(this.heap[d],this.heap[a])&&(this.swap(d,a),this.updateUp(a))}};h.updateDown=function(d){var a=this.leftChildNode(d),b=this.rightChildNode(d);this.existNode(a)&&(a=this.minNode([d,a,b]),a!=d&&(this.swap(d,a),this.updateDown(a)))};h.debugPrint=
function(){console.log(this.heap)};return k}(),ma=function(){function k(){this._time=0;this._events=new la}var h=k.prototype;h.getTime=function(){return this._time};h.clear=function(){this._events=new la;return this};h.add=function(d,a){this._events.push(d,a)};h.get=function(){if(!this._events.len())return null;var d=this._events.pop(),a=d.key;d=d.value;0<a&&(this._time+=a,this._events.shift(-a));return d};h.getEventTime=function(d){if(d=this._events.find(d))return d.key};h.remove=function(d){return this._events.remove(d)};
return k}();D=function(){function k(){this._queue=new ma;this._repeat=[];this._current=null}var h=k.prototype;h.getTime=function(){return this._queue.getTime()};h.add=function(d,a){a&&this._repeat.push(d);return this};h.getTimeOf=function(d){return this._queue.getEventTime(d)};h.clear=function(){this._queue.clear();this._repeat=[];this._current=null;return this};h.remove=function(d){var a=this._queue.remove(d),b=this._repeat.indexOf(d);-1!=b&&this._repeat.splice(b,1);this._current==d&&(this._current=
null);return a};h.next=function(){return this._current=this._queue.get()};return k}();J=function(k){function h(){return k.apply(this,arguments)||this}_inheritsLoose(h,k);var d=h.prototype;d.add=function(a,b){this._queue.add(a,0);return k.prototype.add.call(this,a,b)};d.next=function(){null!==this._current&&-1!=this._repeat.indexOf(this._current)&&this._queue.add(this._current,0);return k.prototype.next.call(this)};return h}(D);F=function(k){function h(){return k.apply(this,arguments)||this}_inheritsLoose(h,
k);var d=h.prototype;d.add=function(a,b,c){this._queue.add(a,void 0!==c?c:1/a.getSpeed());return k.prototype.add.call(this,a,b)};d.next=function(){this._current&&-1!=this._repeat.indexOf(this._current)&&this._queue.add(this._current,1/this._current.getSpeed());return k.prototype.next.call(this)};return h}(D);D=function(k){function h(){var a=k.call(this)||this;a._defaultDuration=1;a._duration=a._defaultDuration;return a}_inheritsLoose(h,k);var d=h.prototype;d.add=function(a,b,c){this._queue.add(a,
c||this._defaultDuration);return k.prototype.add.call(this,a,b)};d.clear=function(){this._duration=this._defaultDuration;return k.prototype.clear.call(this)};d.remove=function(a){a==this._current&&(this._duration=this._defaultDuration);return k.prototype.remove.call(this,a)};d.next=function(){null!==this._current&&-1!=this._repeat.indexOf(this._current)&&(this._queue.add(this._current,this._duration||this._defaultDuration),this._duration=this._defaultDuration);return k.prototype.next.call(this)};
d.setDuration=function(a){this._current&&(this._duration=a);return this};return h}(D);J={Simple:J,Speed:F,Action:D};z=function(){function k(h,d){void 0===d&&(d={});this._lightPasses=h;this._options=Object.assign({topology:8},d)}k.prototype._getCircle=function(h,d,a){var b=[];switch(this._options.topology){case 4:var c=1;var e=[0,1];var f=[C[8][7],C[8][1],C[8][3],C[8][5]];break;case 6:f=C[6];c=1;e=[-1,1];break;case 8:f=C[4];c=2;e=[-1,1];break;default:throw Error("Incorrect topology for FOV computation");
}h+=e[0]*a;d+=e[1]*a;for(e=0;e<f.length;e++)for(var g=0;g<a*c;g++)b.push([h,d]),h+=f[e][0],d+=f[e][1];return b};return k}();F=function(k){function h(){return k.apply(this,arguments)||this}_inheritsLoose(h,k);var d=h.prototype;d.compute=function(a,b,c,e){e(a,b,0,1);if(this._lightPasses(a,b))for(var f=[],g,l,m,n,p,q=1;q<=c;q++)for(var u=this._getCircle(a,b,q),v=360/u.length,w=0;w<u.length;w++)if(m=u[w][0],n=u[w][1],g=v*(w-.5),l=g+v,p=!this._lightPasses(m,n),this._visibleCoords(Math.floor(g),Math.ceil(l),
p,f)&&e(m,n,q,1),2==f.length&&0==f[0]&&360==f[1])return};d._visibleCoords=function(a,b,c,e){if(0>a)return b=this._visibleCoords(0,b,c,e),a=this._visibleCoords(360+a,360,c,e),b||a;for(var f=0;f<e.length&&e[f]<a;)f++;if(f==e.length)return c&&e.push(a,b),!0;var g=0;if(f%2){for(;f<e.length&&e[f]<b;)f++,g++;if(0==g)return!1;c&&(g%2?e.splice(f-g,g,b):e.splice(f-g,g))}else{for(;f<e.length&&e[f]<b;)f++,g++;if(a==e[f-g]&&1==g)return!1;c&&(g%2?e.splice(f-g,g,a):e.splice(f-g,g,a,b))}return!0};return h}(z);D=
function(k){function h(){return k.apply(this,arguments)||this}_inheritsLoose(h,k);var d=h.prototype;d.compute=function(a,b,c,e){e(a,b,0,1);if(this._lightPasses(a,b))for(var f=[],g,l,m,n,p,q=1;q<=c;q++)for(var u=this._getCircle(a,b,q),v=u.length,w=0;w<v;w++)if(g=u[w][0],l=u[w][1],n=[w?2*w-1:2*v-1,2*v],p=[2*w+1,2*v],m=!this._lightPasses(g,l),(m=this._checkVisibility(n,p,m,f))&&e(g,l,q,m),2==f.length&&0==f[0][0]&&f[1][0]==f[1][1])return};d._checkVisibility=function(a,b,c,e){if(a[0]>b[0])return a=this._checkVisibility(a,
[a[1],a[1]],c,e),b=this._checkVisibility([0,1],b,c,e),(a+b)/2;for(var f=0,g=!1;f<e.length;){var l=e[f];l=l[0]*a[1]-a[0]*l[1];if(0<=l){0!=l||f%2||(g=!0);break}f++}l=e.length;for(var m=!1;l--;){var n=e[l];n=b[0]*n[1]-n[0]*b[1];if(0<=n){0==n&&l%2&&(m=!0);break}}n=!0;f==l&&(g||m)?n=!1:g&&m&&f+1==l&&l%2?n=!1:f>l&&f%2&&(n=!1);if(!n)return 0;g=l-f+1;if(g%2)f%2?(l=e[f],l=(b[0]*l[1]-l[0]*b[1])/(l[1]*b[1]),c&&e.splice(f,g,b)):(l=e[l],l=(l[0]*a[1]-a[0]*l[1])/(a[1]*l[1]),c&&e.splice(f,g,a));else if(f%2)m=e[f],
l=e[l],l=(l[0]*m[1]-m[0]*l[1])/(m[1]*l[1]),c&&e.splice(f,g);else return c&&e.splice(f,g,a,b),1;return l/((b[0]*a[1]-a[0]*b[1])/(a[1]*b[1]))};return h}(z);var G=[[-1,0,0,1],[0,-1,1,0],[0,-1,-1,0],[-1,0,0,-1],[1,0,0,-1],[0,1,-1,0],[0,1,1,0],[1,0,0,1]];z=function(k){function h(){return k.apply(this,arguments)||this}_inheritsLoose(h,k);var d=h.prototype;d.compute=function(a,b,c,e){e(a,b,0,1);for(var f=0;f<G.length;f++)this._renderOctant(a,b,G[f],c,e)};d.compute180=function(a,b,c,e,f){f(a,b,0,1);var g=
(e-1+8)%8,l=(e+1+8)%8;this._renderOctant(a,b,G[(e-2+8)%8],c,f);this._renderOctant(a,b,G[g],c,f);this._renderOctant(a,b,G[e],c,f);this._renderOctant(a,b,G[l],c,f)};d.compute90=function(a,b,c,e,f){f(a,b,0,1);var g=(e-1+8)%8;this._renderOctant(a,b,G[e],c,f);this._renderOctant(a,b,G[g],c,f)};d._renderOctant=function(a,b,c,e,f){this._castVisibility(a,b,1,1,0,e+1,c[0],c[1],c[2],c[3],f)};d._castVisibility=function(a,b,c,e,f,g,l,m,n,p,q){if(!(e<f))for(;c<=g;c++){for(var u=-c-1,v=-c,w=!1,A=0;0>=u;){u+=1;var B=
a+u*l+v*m,ba=b+u*n+v*p,na=(u-.5)/(v+.5),ca=(u+.5)/(v-.5);if(!(ca>e)){if(na<f)break;u*u+v*v<g*g&&q(B,ba,c,1);w?this._lightPasses(B,ba)?(w=!1,e=A):A=ca:!this._lightPasses(B,ba)&&c<g&&(w=!0,this._castVisibility(a,b,c+1,e,na,g,l,m,n,p,q),A=ca)}}if(w)break}};return h}(z);F={DiscreteShadowcasting:F,PreciseShadowcasting:D,RecursiveShadowcasting:z};z=function(){function k(h,d){void 0===h&&(h=80);void 0===d&&(d=25);this._width=h;this._height=d}k.prototype._fillMap=function(h){for(var d=[],a=0;a<this._width;a++){d.push([]);
for(var b=0;b<this._height;b++)d[a].push(h)}return d};return k}();D=function(k){function h(){return k.apply(this,arguments)||this}_inheritsLoose(h,k);h.prototype.create=function(d){for(var a=this._width-1,b=this._height-1,c=0;c<=a;c++)for(var e=0;e<=b;e++)d(c,e,c&&e&&c<a&&e<b?0:1);return this};return h}(z);var L=function(k){function h(a,b){a=k.call(this,a,b)||this;a._rooms=[];a._corridors=[];return a}_inheritsLoose(h,k);var d=h.prototype;d.getRooms=function(){return this._rooms};d.getCorridors=function(){return this._corridors};
return h}(z),H=function(){},T=function(k){function h(a,b,c,e,f,g){var l=k.call(this)||this;l._x1=a;l._y1=b;l._x2=c;l._y2=e;l._doors={};void 0!==f&&void 0!==g&&l.addDoor(f,g);return l}_inheritsLoose(h,k);h.createRandomAt=function(a,b,c,e,f){var g=f.roomWidth[0],l=f.roomWidth[1],m=t.getUniformInt(g,l);g=f.roomHeight[0];l=f.roomHeight[1];f=t.getUniformInt(g,l);if(1==c)return c=b-Math.floor(t.getUniform()*f),new this(a+1,c,a+m,c+f-1,a,b);if(-1==c)return c=b-Math.floor(t.getUniform()*f),new this(a-m,c,
a-1,c+f-1,a,b);if(1==e)return c=a-Math.floor(t.getUniform()*m),new this(c,b+1,c+m-1,b+f,a,b);if(-1==e)return c=a-Math.floor(t.getUniform()*m),new this(c,b-f,c+m-1,b-1,a,b);throw Error("dx or dy must be 1 or -1");};h.createRandomCenter=function(a,b,c){var e=c.roomWidth[0],f=c.roomWidth[1],g=t.getUniformInt(e,f);e=c.roomHeight[0];f=c.roomHeight[1];c=t.getUniformInt(e,f);a-=Math.floor(t.getUniform()*g);b-=Math.floor(t.getUniform()*c);return new this(a,b,a+g-1,b+c-1)};h.createRandom=function(a,b,c){var e=
c.roomWidth[0],f=c.roomWidth[1],g=t.getUniformInt(e,f);e=c.roomHeight[0];f=c.roomHeight[1];c=t.getUniformInt(e,f);a=a-g-1;b=b-c-1;a=1+Math.floor(t.getUniform()*a);b=1+Math.floor(t.getUniform()*b);return new this(a,b,a+g-1,b+c-1)};var d=h.prototype;d.addDoor=function(a,b){this._doors[a+","+b]=1;return this};d.getDoors=function(a){for(var b in this._doors){var c=b.split(",");a(parseInt(c[0]),parseInt(c[1]))}return this};d.clearDoors=function(){this._doors={};return this};d.addDoors=function(a){for(var b=
this._x1-1,c=this._x2+1,e=this._y1-1,f=this._y2+1,g=b;g<=c;g++)for(var l=e;l<=f;l++)if(g==b||g==c||l==e||l==f)a(g,l)||this.addDoor(g,l);return this};d.debug=function(){console.log("room",this._x1,this._y1,this._x2,this._y2)};d.isValid=function(a,b){for(var c=this._x1-1,e=this._x2+1,f=this._y1-1,g=this._y2+1,l=c;l<=e;l++)for(var m=f;m<=g;m++)if(l==c||l==e||m==f||m==g){if(!a(l,m))return!1}else if(!b(l,m))return!1;return!0};d.create=function(a){for(var b=this._x1-1,c=this._x2+1,e=this._y1-1,f=this._y2+
1,g,l=b;l<=c;l++)for(var m=e;m<=f;m++)g=l+","+m in this._doors?2:l==b||l==c||m==e||m==f?1:0,a(l,m,g)};d.getCenter=function(){return[Math.round((this._x1+this._x2)/2),Math.round((this._y1+this._y2)/2)]};d.getLeft=function(){return this._x1};d.getRight=function(){return this._x2};d.getTop=function(){return this._y1};d.getBottom=function(){return this._y2};return h}(H),da=function(k){function h(a,b,c,e){var f=k.call(this)||this;f._startX=a;f._startY=b;f._endX=c;f._endY=e;f._endsWithAWall=!0;return f}
_inheritsLoose(h,k);h.createRandomAt=function(a,b,c,e,f){f=t.getUniformInt(f.corridorLength[0],f.corridorLength[1]);return new this(a,b,a+c*f,b+e*f)};var d=h.prototype;d.debug=function(){console.log("corridor",this._startX,this._startY,this._endX,this._endY)};d.isValid=function(a,b){var c=this._startX,e=this._startY,f=this._endX-c,g=this._endY-e,l=1+Math.max(Math.abs(f),Math.abs(g));f&&(f/=Math.abs(f));g&&(g/=Math.abs(g));for(var m=g,n=-f,p=!0,q=0;q<l;q++){var u=c+q*f,v=e+q*g;b(u,v)||(p=!1);a(u+m,
v+n)||(p=!1);a(u-m,v-n)||(p=!1);if(!p){l=q;this._endX=u-f;this._endY=v-g;break}}if(0==l||1==l&&a(this._endX+f,this._endY+g))return!1;b=!a(this._endX+f+m,this._endY+g+n);m=!a(this._endX+f-m,this._endY+g-n);this._endsWithAWall=a(this._endX+f,this._endY+g);return(b||m)&&this._endsWithAWall?!1:!0};d.create=function(a){var b=this._startX,c=this._startY,e=this._endX-b,f=this._endY-c,g=1+Math.max(Math.abs(e),Math.abs(f));e&&(e/=Math.abs(e));f&&(f/=Math.abs(f));for(var l=0;l<g;l++)a(b+l*e,c+l*f,0);return!0};
d.createPriorityWalls=function(a){if(this._endsWithAWall){var b=this._endX-this._startX,c=this._endY-this._startY;b&&(b/=Math.abs(b));c&&(c/=Math.abs(c));var e=c,f=-b;a(this._endX+b,this._endY+c);a(this._endX+e,this._endY+f);a(this._endX-e,this._endY-f)}};return h}(H);H=function(k){function h(a,b,c){a=k.call(this,a,b)||this;a._options={roomWidth:[3,9],roomHeight:[3,5],roomDugPercentage:.1,timeLimit:1E3};Object.assign(a._options,c);a._map=[];a._dug=0;a._roomAttempts=20;a._corridorAttempts=20;a._connected=
[];a._unconnected=[];a._digCallback=a._digCallback.bind(_assertThisInitialized(a));a._canBeDugCallback=a._canBeDugCallback.bind(_assertThisInitialized(a));a._isWallCallback=a._isWallCallback.bind(_assertThisInitialized(a));return a}_inheritsLoose(h,k);var d=h.prototype;d.create=function(a){for(var b=Date.now();;){if(Date.now()-b>this._options.timeLimit)return null;this._map=this._fillMap(1);this._dug=0;this._rooms=[];this._unconnected=[];this._generateRooms();if(!(2>this._rooms.length)&&this._generateCorridors())break}if(a)for(b=
0;b<this._width;b++)for(var c=0;c<this._height;c++)a(b,c,this._map[b][c]);return this};d._generateRooms=function(){var a=this._width-2,b=this._height-2;do{var c=this._generateRoom();if(this._dug/(a*b)>this._options.roomDugPercentage)break}while(c)};d._generateRoom=function(){for(var a=0;a<this._roomAttempts;){a++;var b=T.createRandom(this._width,this._height,this._options);if(b.isValid(this._isWallCallback,this._canBeDugCallback))return b.create(this._digCallback),this._rooms.push(b),b}return null};
d._generateCorridors=function(){for(var a=0;a<this._corridorAttempts;){a++;this._corridors=[];this._map=this._fillMap(1);for(var b=0;b<this._rooms.length;b++){var c=this._rooms[b];c.clearDoors();c.create(this._digCallback)}this._unconnected=t.shuffle(this._rooms.slice());this._connected=[];for(this._unconnected.length&&this._connected.push(this._unconnected.pop());;){b=t.getItem(this._connected);if(!b)break;b=this._closestRoom(this._unconnected,b);if(!b)break;c=this._closestRoom(this._connected,b);
if(!c)break;if(!this._connectRooms(b,c))break;if(!this._unconnected.length)return!0}}return!1};d._closestRoom=function(a,b){var c=Infinity;b=b.getCenter();for(var e=null,f=0;f<a.length;f++){var g=a[f],l=g.getCenter(),m=l[0]-b[0];l=l[1]-b[1];m=m*m+l*l;m<c&&(c=m,e=g)}return e};d._connectRooms=function(a,b){var c=a.getCenter(),e=b.getCenter(),f=e[0]-c[0];c=e[1]-c[1];if(Math.abs(f)<Math.abs(c)){f=0<c?2:0;var g=(f+2)%4;var l=b.getLeft();var m=b.getRight();c=0}else f=0<f?1:3,g=(f+2)%4,l=b.getTop(),m=b.getBottom(),
c=1;f=this._placeInWall(a,f);if(!f)return!1;if(f[c]>=l&&f[c]<=m){e=f.slice();l=0;switch(g){case 0:l=b.getTop()-1;break;case 1:l=b.getRight()+1;break;case 2:l=b.getBottom()+1;break;case 3:l=b.getLeft()-1}e[(c+1)%2]=l;this._digLine([f,e])}else if(f[c]<l-1||f[c]>m+1){e=f[c]-e[c];l=0;switch(g){case 0:case 1:l=0>e?3:1;break;case 2:case 3:l=0>e?1:3}e=this._placeInWall(b,(g+l)%4);if(!e)return!1;g=[0,0];g[c]=f[c];c=(c+1)%2;g[c]=e[c];this._digLine([f,g,e])}else{l=(c+1)%2;e=this._placeInWall(b,g);if(!e)return!1;
g=Math.round((e[l]+f[l])/2);m=[0,0];var n=[0,0];m[c]=f[c];m[l]=g;n[c]=e[c];n[l]=g;this._digLine([f,m,n,e])}a.addDoor(f[0],f[1]);b.addDoor(e[0],e[1]);c=this._unconnected.indexOf(a);-1!=c&&(this._unconnected.splice(c,1),this._connected.push(a));c=this._unconnected.indexOf(b);-1!=c&&(this._unconnected.splice(c,1),this._connected.push(b));return!0};d._placeInWall=function(a,b){var c=[0,0],e=[0,0],f=0;switch(b){case 0:e=[1,0];c=[a.getLeft(),a.getTop()-1];f=a.getRight()-a.getLeft()+1;break;case 1:e=[0,
1];c=[a.getRight()+1,a.getTop()];f=a.getBottom()-a.getTop()+1;break;case 2:e=[1,0];c=[a.getLeft(),a.getBottom()+1];f=a.getRight()-a.getLeft()+1;break;case 3:e=[0,1],c=[a.getLeft()-1,a.getTop()],f=a.getBottom()-a.getTop()+1}a=[];b=-2;for(var g=0;g<f;g++){var l=c[0]+g*e[0],m=c[1]+g*e[1];a.push(null);1==this._map[l][m]?b!=g-1&&(a[g]=[l,m]):(b=g)&&(a[g-1]=null)}for(c=a.length-1;0<=c;c--)a[c]||a.splice(c,1);return a.length?t.getItem(a):null};d._digLine=function(a){for(var b=1;b<a.length;b++){var c=a[b-
1],e=a[b];c=new da(c[0],c[1],e[0],e[1]);c.create(this._digCallback);this._corridors.push(c)}};d._digCallback=function(a,b,c){this._map[a][b]=c;0==c&&this._dug++};d._isWallCallback=function(a,b){return 0>a||0>b||a>=this._width||b>=this._height?!1:1==this._map[a][b]};d._canBeDugCallback=function(a,b){return 1>a||1>b||a+1>=this._width||b+1>=this._height?!1:1==this._map[a][b]};return h}(L);var I=function(k){function h(a,b,c){void 0===c&&(c={});a=k.call(this,a,b)||this;a._options={born:[5,6,7,8],survive:[4,
5,6,7,8],topology:8};a.setOptions(c);a._dirs=C[a._options.topology];a._map=a._fillMap(0);return a}_inheritsLoose(h,k);var d=h.prototype;d.randomize=function(a){for(var b=0;b<this._width;b++)for(var c=0;c<this._height;c++)this._map[b][c]=t.getUniform()<a?1:0;return this};d.setOptions=function(a){Object.assign(this._options,a)};d.set=function(a,b,c){this._map[a][b]=c};d.create=function(a){for(var b=this._fillMap(0),c=this._options.born,e=this._options.survive,f=0;f<this._height;f++){var g=1,l=0;6==
this._options.topology&&(g=2,l=f%2);for(;l<this._width;l+=g){var m=this._map[l][f],n=this._getNeighbors(l,f);m&&-1!=e.indexOf(n)?b[l][f]=1:m||-1==c.indexOf(n)||(b[l][f]=1)}}this._map=b;a&&this._serviceCallback(a)};d._serviceCallback=function(a){for(var b=0;b<this._height;b++){var c=1,e=0;6==this._options.topology&&(c=2,e=b%2);for(;e<this._width;e+=c)a(e,b,this._map[e][b])}};d._getNeighbors=function(a,b){for(var c=0,e=0;e<this._dirs.length;e++){var f=this._dirs[e],g=a+f[0];f=b+f[1];0>g||g>=this._width||
0>f||f>=this._height||(c+=1==this._map[g][f]?1:0)}return c};d.connect=function(a,b,c){b||=0;var e=[],f={},g=1,l=[0,0];6==this._options.topology&&(g=2,l=[0,1]);for(var m=0;m<this._height;m++)for(var n=l[m%2];n<this._width;n+=g)if(this._freeSpace(n,m,b)){var p=[n,m];f[this._pointKey(p)]=p;e.push([n,m])}g=e[t.getUniformInt(0,e.length-1)];l=this._pointKey(g);e={};e[l]=g;delete f[l];for(this._findConnected(e,f,[g],!1,b);0<Object.keys(f).length;){l=this._getFromTo(e,f);g=l[0];m=l[1];l={};l[this._pointKey(g)]=
g;this._findConnected(l,f,[g],!0,b);(6==this._options.topology?this._tunnelToConnected6:this._tunnelToConnected).call(this,m,g,e,f,b,c);for(var q in l)g=l[q],this._map[g[0]][g[1]]=b,e[q]=g,delete f[q]}a&&this._serviceCallback(a)};d._getFromTo=function(a,b){for(var c=[0,0],e=[0,0],f,g=Object.keys(a),l=Object.keys(b),m=0;5>m&&!(g.length<l.length?(c=g,e=a[c[t.getUniformInt(0,c.length-1)]],c=this._getClosest(e,b)):(c=l,c=b[c[t.getUniformInt(0,c.length-1)]],e=this._getClosest(c,a)),f=(c[0]-e[0])*(c[0]-
e[0])+(c[1]-e[1])*(c[1]-e[1]),64>f);m++);return[c,e]};d._getClosest=function(a,b){var c=null,e=null,f;for(f in b){var g=b[f],l=(g[0]-a[0])*(g[0]-a[0])+(g[1]-a[1])*(g[1]-a[1]);if(null==e||l<e)e=l,c=g}return c};d._findConnected=function(a,b,c,e,f){for(;0<c.length;){var g=c.splice(0,1)[0];g=6==this._options.topology?[[g[0]+2,g[1]],[g[0]+1,g[1]-1],[g[0]-1,g[1]-1],[g[0]-2,g[1]],[g[0]-1,g[1]+1],[g[0]+1,g[1]+1]]:[[g[0]+1,g[1]],[g[0]-1,g[1]],[g[0],g[1]+1],[g[0],g[1]-1]];for(var l=0;l<g.length;l++){var m=
this._pointKey(g[l]);null==a[m]&&this._freeSpace(g[l][0],g[l][1],f)&&(a[m]=g[l],e||delete b[m],c.push(g[l]))}}};d._tunnelToConnected=function(a,b,c,e,f,g){if(b[0]<a[0]){var l=b;var m=a}else l=a,m=b;for(var n=l[0];n<=m[0];n++){this._map[n][l[1]]=f;var p=[n,l[1]],q=this._pointKey(p);c[q]=p;delete e[q]}g&&l[0]<m[0]&&g(l,[m[0],l[1]]);n=m[0];b[1]<a[1]?(l=b,m=a):(l=a,m=b);for(a=l[1];a<m[1];a++)this._map[n][a]=f,b=[n,a],p=this._pointKey(b),c[p]=b,delete e[p];g&&l[1]<m[1]&&g([m[0],l[1]],[m[0],m[1]])};d._tunnelToConnected6=
function(a,b,c,e,f,g){if(b[0]<a[0]){var l=b;var m=a}else l=a,m=b;var n=l[0];for(l=l[1];n!=m[0]||l!=m[1];){var p=2;l<m[1]?(l++,p=1):l>m[1]&&(l--,p=1);n=n<m[0]?n+p:n>m[0]?n-p:m[1]%2?n-p:n+p;this._map[n][l]=f;p=[n,l];var q=this._pointKey(p);c[q]=p;delete e[q]}g&&g(b,a)};d._freeSpace=function(a,b,c){return 0<=a&&a<this._width&&0<=b&&b<this._height&&this._map[a][b]==c};d._pointKey=function(a){return a[0]+"."+a[1]};return h}(z),ya={room:T,corridor:da};L=function(k){function h(a,b,c){void 0===c&&(c={});
a=k.call(this,a,b)||this;a._options=Object.assign({roomWidth:[3,9],roomHeight:[3,5],corridorLength:[3,10],dugPercentage:.2,timeLimit:1E3},c);a._features={room:4,corridor:4};a._map=[];a._featureAttempts=20;a._walls={};a._dug=0;a._digCallback=a._digCallback.bind(_assertThisInitialized(a));a._canBeDugCallback=a._canBeDugCallback.bind(_assertThisInitialized(a));a._isWallCallback=a._isWallCallback.bind(_assertThisInitialized(a));a._priorityWallCallback=a._priorityWallCallback.bind(_assertThisInitialized(a));
return a}_inheritsLoose(h,k);var d=h.prototype;d.create=function(a){this._rooms=[];this._corridors=[];this._map=this._fillMap(1);this._walls={};this._dug=0;var b=(this._width-2)*(this._height-2);this._firstRoom();var c=Date.now();do{var e=0;if(Date.now()-c>this._options.timeLimit)break;var f=this._findWall();if(!f)break;var g=f.split(",");f=parseInt(g[0]);g=parseInt(g[1]);var l=this._getDiggingDirection(f,g);if(l){var m=0;do if(m++,this._tryFeature(f,g,l[0],l[1])){this._removeSurroundingWalls(f,g);
this._removeSurroundingWalls(f-l[0],g-l[1]);break}while(m<this._featureAttempts);for(var n in this._walls)1<this._walls[n]&&e++}}while(this._dug/b<this._options.dugPercentage||e);this._addDoors();if(a)for(b=0;b<this._width;b++)for(c=0;c<this._height;c++)a(b,c,this._map[b][c]);this._walls={};this._map=[];return this};d._digCallback=function(a,b,c){0==c||2==c?(this._map[a][b]=0,this._dug++):this._walls[a+","+b]=1};d._isWallCallback=function(a,b){return 0>a||0>b||a>=this._width||b>=this._height?!1:1==
this._map[a][b]};d._canBeDugCallback=function(a,b){return 1>a||1>b||a+1>=this._width||b+1>=this._height?!1:1==this._map[a][b]};d._priorityWallCallback=function(a,b){this._walls[a+","+b]=2};d._firstRoom=function(){var a=T.createRandomCenter(Math.floor(this._width/2),Math.floor(this._height/2),this._options);this._rooms.push(a);a.create(this._digCallback)};d._findWall=function(){var a=[],b=[],c;for(c in this._walls)2==this._walls[c]?b.push(c):a.push(c);a=b.length?b:a;if(!a.length)return null;a=t.getItem(a.sort());
delete this._walls[a];return a};d._tryFeature=function(a,b,c,e){var f=t.getWeightedValue(this._features);a=ya[f].createRandomAt(a,b,c,e,this._options);if(!a.isValid(this._isWallCallback,this._canBeDugCallback))return!1;a.create(this._digCallback);a instanceof T&&this._rooms.push(a);a instanceof da&&(a.createPriorityWalls(this._priorityWallCallback),this._corridors.push(a));return!0};d._removeSurroundingWalls=function(a,b){for(var c=C[4],e=0;e<c.length;e++){var f=c[e],g=a+f[0],l=b+f[1];delete this._walls[g+
","+l];g=a+2*f[0];l=b+2*f[1];delete this._walls[g+","+l]}};d._getDiggingDirection=function(a,b){if(0>=a||0>=b||a>=this._width-1||b>=this._height-1)return null;for(var c=null,e=C[4],f=0;f<e.length;f++){var g=e[f];if(!this._map[a+g[0]][b+g[1]]){if(c)return null;c=g}}return c?[-c[0],-c[1]]:null};d._addDoors=function(){function a(f,g){return 1==b[f][g]}for(var b=this._map,c=0;c<this._rooms.length;c++){var e=this._rooms[c];e.clearDoors();e.addDoors(a)}};return h}(L);var za=function(k){function h(){return k.apply(this,
arguments)||this}_inheritsLoose(h,k);h.prototype.create=function(d){for(var a=this._fillMap(1),b=Math.ceil((this._width-2)/2),c=[],e=[],f=0;f<b;f++)c.push(f),e.push(f);c.push(b-1);for(f=1;f+3<this._height;f+=2)for(var g=0;g<b;g++){var l=2*g+1,m=f;a[l][m]=0;g!=c[g+1]&&.375<t.getUniform()&&(ja(g,c,e),a[l+1][m]=0);g!=c[g]&&.375<t.getUniform()?ka(g,c,e):a[l][m+1]=0}for(g=0;g<b;g++)l=2*g+1,m=f,a[l][m]=0,g!=c[g+1]&&(g==c[g]||.375<t.getUniform())&&(ja(g,c,e),a[l+1][m]=0),ka(g,c,e);for(b=0;b<this._width;b++)for(c=
0;c<this._height;c++)d(b,c,a[b][c]);return this};return h}(z),Aa=function(k){function h(){var a=k.apply(this,arguments)||this;a._stack=[];a._map=[];return a}_inheritsLoose(h,k);var d=h.prototype;d.create=function(a){var b=this._width,c=this._height;this._map=[];for(var e=0;e<b;e++){this._map.push([]);for(var f=0;f<c;f++)this._map[e].push(0==e||0==f||e+1==b||f+1==c?1:0)}this._stack=[[1,1,b-2,c-2]];this._process();for(e=0;e<b;e++)for(f=0;f<c;f++)a(e,f,this._map[e][f]);this._map=[];return this};d._process=
function(){for(;this._stack.length;){var a=this._stack.shift();this._partitionRoom(a)}};d._partitionRoom=function(a){for(var b=[],c=[],e=a[0]+1;e<a[2];e++){var f=this._map[e][a[3]+1];!this._map[e][a[1]-1]||!f||e%2||b.push(e)}for(e=a[1]+1;e<a[3];e++)f=this._map[a[2]+1][e],!this._map[a[0]-1][e]||!f||e%2||c.push(e);if(b.length&&c.length){b=t.getItem(b);c=t.getItem(c);this._map[b][c]=1;e=[];f=[];e.push(f);for(var g=a[0];g<b;g++)this._map[g][c]=1,g%2&&f.push([g,c]);f=[];e.push(f);for(g=b+1;g<=a[2];g++)this._map[g][c]=
1,g%2&&f.push([g,c]);f=[];e.push(f);for(g=a[1];g<c;g++)this._map[b][g]=1,g%2&&f.push([b,g]);f=[];e.push(f);for(g=c+1;g<=a[3];g++)this._map[b][g]=1,g%2&&f.push([b,g]);f=t.getItem(e);for(g=0;g<e.length;g++){var l=e[g];l!=f&&(l=t.getItem(l),this._map[l[0]][l[1]]=0)}this._stack.push([a[0],a[1],b-1,c-1]);this._stack.push([b+1,a[1],a[2],c-1]);this._stack.push([a[0],c+1,b-1,a[3]]);this._stack.push([b+1,c+1,a[2],a[3]])}};return h}(z),Ba=function(k){function h(a,b,c){void 0===c&&(c=0);a=k.call(this,a,b)||
this;a._regularity=c;a._map=[];return a}_inheritsLoose(h,k);var d=h.prototype;d.create=function(a){var b=this._width,c=this._height,e=this._fillMap(1);b-=b%2?1:2;c-=c%2?1:2;var f=0,g=[[0,0],[0,0],[0,0],[0,0]];do{var l=1+2*Math.floor(t.getUniform()*(b-1)/2);var m=1+2*Math.floor(t.getUniform()*(c-1)/2);f||(e[l][m]=0);if(!e[l][m]){this._randomize(g);do{0==Math.floor(t.getUniform()*(this._regularity+1))&&this._randomize(g);var n=!0;for(var p=0;4>p;p++){var q=l+2*g[p][0];var u=m+2*g[p][1];if(this._isFree(e,
q,u,b,c)){e[q][u]=0;e[l+g[p][0]][m+g[p][1]]=0;l=q;m=u;n=!1;f++;break}}}while(!n)}}while(f+1<b*c/4);for(b=0;b<this._width;b++)for(c=0;c<this._height;c++)a(b,c,e[b][c]);this._map=[];return this};d._randomize=function(a){for(var b=0;4>b;b++)a[b][0]=0,a[b][1]=0;switch(Math.floor(4*t.getUniform())){case 0:a[0][0]=-1;a[1][0]=1;a[2][1]=-1;a[3][1]=1;break;case 1:a[3][0]=-1;a[2][0]=1;a[1][1]=-1;a[0][1]=1;break;case 2:a[2][0]=-1;a[3][0]=1;a[0][1]=-1;a[1][1]=1;break;case 3:a[1][0]=-1,a[0][0]=1,a[3][1]=-1,a[2][1]=
1}};d._isFree=function(a,b,c,e,f){return 1>b||1>c||b>=e||c>=f?!1:a[b][c]};return h}(z);z=function(k){function h(a,b,c){a=k.call(this,a,b)||this;a.map=[];a.rooms=[];a.connectedCells=[];c=Object.assign({cellWidth:3,cellHeight:3},c);c.hasOwnProperty("roomWidth")||(c.roomWidth=a._calculateRoomSize(a._width,c.cellWidth));c.hasOwnProperty("roomHeight")||(c.roomHeight=a._calculateRoomSize(a._height,c.cellHeight));a._options=c;return a}_inheritsLoose(h,k);var d=h.prototype;d.create=function(a){this.map=this._fillMap(1);
this.rooms=[];this.connectedCells=[];this._initRooms();this._connectRooms();this._connectUnconnectedRooms();this._createRandomRoomConnections();this._createRooms();this._createCorridors();if(a)for(var b=0;b<this._width;b++)for(var c=0;c<this._height;c++)a(b,c,this.map[b][c]);return this};d._calculateRoomSize=function(a,b){var c=Math.floor(a/b*.8);a=Math.floor(a/b*.25);2>a&&(a=2);2>c&&(c=2);return[a,c]};d._initRooms=function(){for(var a=0;a<this._options.cellWidth;a++){this.rooms.push([]);for(var b=
0;b<this._options.cellHeight;b++)this.rooms[a].push({x:0,y:0,width:0,height:0,connections:[],cellx:a,celly:b})}};d._connectRooms=function(){var a=t.getUniformInt(0,this._options.cellWidth-1),b=t.getUniformInt(0,this._options.cellHeight-1);do{var c=[0,2,4,6];c=t.shuffle(c);do{var e=!1;var f=c.pop();var g=a+C[8][f][0];f=b+C[8][f][1];if(!(0>g||g>=this._options.cellWidth||0>f||f>=this._options.cellHeight)){var l=this.rooms[a][b];if(0<l.connections.length&&l.connections[0][0]==g&&l.connections[0][1]==
f)break;l=this.rooms[g][f];0==l.connections.length&&(l.connections.push([a,b]),this.connectedCells.push([g,f]),a=g,b=f,e=!0)}}while(0<c.length&&0==e)}while(0<c.length)};d._connectUnconnectedRooms=function(){var a=this._options.cellWidth,b=this._options.cellHeight;this.connectedCells=t.shuffle(this.connectedCells);for(var c,e,f,g=0;g<this._options.cellWidth;g++)for(var l=0;l<this._options.cellHeight;l++)if(c=this.rooms[g][l],0==c.connections.length){var m=[0,2,4,6];m=t.shuffle(m);f=!1;do{var n=m.pop(),
p=g+C[8][n][0];n=l+C[8][n][1];if(!(0>p||p>=a||0>n||n>=b)){e=this.rooms[p][n];f=!0;if(0==e.connections.length)break;for(p=0;p<e.connections.length;p++)if(e.connections[p][0]==g&&e.connections[p][1]==l){f=!1;break}if(f)break}}while(m.length);f?c.connections.push([e.cellx,e.celly]):console.log("-- Unable to connect room.")}};d._createRandomRoomConnections=function(){};d._createRooms=function(){for(var a=this._width,b=this._height,c=this._options.cellWidth,e=this._options.cellHeight,f=Math.floor(this._width/
c),g=Math.floor(this._height/e),l,m,n=this._options.roomWidth,p=this._options.roomHeight,q,u,v,w=0;w<c;w++)for(var A=0;A<e;A++){q=f*w;u=g*A;0==q&&(q=1);0==u&&(u=1);l=t.getUniformInt(n[0],n[1]);m=t.getUniformInt(p[0],p[1]);if(0<A)for(v=this.rooms[w][A-1];3>u-(v.y+v.height);)u++;if(0<w)for(v=this.rooms[w-1][A];3>q-(v.x+v.width);)q++;v=Math.round(t.getUniformInt(0,f-l)/2);for(var B=Math.round(t.getUniformInt(0,g-m)/2);q+v+l>=a;)v?v--:l--;for(;u+B+m>=b;)B?B--:m--;q+=v;u+=B;this.rooms[w][A].x=q;this.rooms[w][A].y=
u;this.rooms[w][A].width=l;this.rooms[w][A].height=m;for(v=q;v<q+l;v++)for(B=u;B<u+m;B++)this.map[v][B]=0}};d._getWallPosition=function(a,b){if(1==b||3==b){var c=t.getUniformInt(a.x+1,a.x+a.width-2);if(1==b){var e=a.y-2;a=e+1}else e=a.y+a.height+1,a=e-1;this.map[c][a]=0}else e=t.getUniformInt(a.y+1,a.y+a.height-2),2==b?(c=a.x+a.width+1,a=c-1):(c=a.x-2,a=c+1),this.map[a][e]=0;return[c,e]};d._drawCorridor=function(a,b){var c=b[0]-a[0],e=b[1]-a[1];b=a[0];a=a[1];var f=[];var g=Math.abs(c);var l=Math.abs(e);
var m=t.getUniform();var n=1-m;c=0<c?2:6;e=0<e?4:0;g<l?(m=Math.ceil(l*m),f.push([e,m]),f.push([c,g]),m=Math.floor(l*n),f.push([e,m])):(m=Math.ceil(g*m),f.push([c,m]),f.push([e,l]),m=Math.floor(g*n),f.push([c,m]));for(this.map[b][a]=0;0<f.length;)for(g=f.pop();0<g[1];)b+=C[8][g[0]][0],a+=C[8][g[0]][1],this.map[b][a]=0,--g[1]};d._createCorridors=function(){for(var a=this._options.cellWidth,b=this._options.cellHeight,c,e,f,g,l=0;l<a;l++)for(var m=0;m<b;m++){c=this.rooms[l][m];for(var n=0;n<c.connections.length;n++)e=
c.connections[n],e=this.rooms[e[0]][e[1]],e.cellx>c.cellx?(f=2,g=4):e.cellx<c.cellx?(f=4,g=2):e.celly>c.celly?(f=3,g=1):(f=1,g=3),this._drawCorridor(this._getWallPosition(c,f),this._getWallPosition(e,g))}};return h}(z);D={Arena:D,Uniform:H,Cellular:I,Digger:L,EllerMaze:za,DividedMaze:Aa,IceyMaze:Ba,Rogue:z};var Ca=.5*(Math.sqrt(3)-1),O=(3-Math.sqrt(3))/6;z={Simplex:function(k){function h(d){void 0===d&&(d=256);var a=k.call(this)||this;a._gradients=[[0,-1],[1,-1],[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,
-1]];for(var b=[],c=0;c<d;c++)b.push(c);b=t.shuffle(b);a._perms=[];a._indexes=[];for(c=0;c<2*d;c++)a._perms.push(b[c%d]),a._indexes.push(a._perms[c]%a._gradients.length);return a}_inheritsLoose(h,k);h.prototype.get=function(d,a){var b=this._perms,c=this._indexes,e=b.length/2,f=0,g=0,l=0,m=(d+a)*Ca,n=Math.floor(d+m);var p=Math.floor(a+m);var q=(n+p)*O;m=d-(n-q);var u=a-(p-q);if(m>u){var v=1;var w=0}else v=0,w=1;q=m-v+O;var A=u-w+O;a=m-1+2*O;d=u-1+2*O;n=y(n,e);e=y(p,e);var B=.5-m*m-u*u;0<=B&&(B*=B,
p=c[n+b[e]],f=this._gradients[p],f=B*B*(f[0]*m+f[1]*u));m=.5-q*q-A*A;0<=m&&(m*=m,p=c[n+v+b[e+w]],g=this._gradients[p],g=m*m*(g[0]*q+g[1]*A));m=.5-a*a-d*d;0<=m&&(m*=m,p=c[n+1+b[e+1]],b=this._gradients[p],l=m*m*(b[0]*a+b[1]*d));return 70*(f+g+l)};return h}(function(){})};I=function(){function k(h,d,a,b){void 0===b&&(b={});this._toX=h;this._toY=d;this._passableCallback=a;this._options=Object.assign({topology:8},b);this._dirs=C[this._options.topology];8==this._options.topology&&(this._dirs=[this._dirs[0],
this._dirs[2],this._dirs[4],this._dirs[6],this._dirs[1],this._dirs[3],this._dirs[5],this._dirs[7]])}k.prototype._getNeighbors=function(h,d){for(var a=[],b=0;b<this._dirs.length;b++){var c=this._dirs[b],e=h+c[0];c=d+c[1];this._passableCallback(e,c)&&a.push([e,c])}return a};return k}();H=function(k){function h(a,b,c,e){c=k.call(this,a,b,c,e)||this;c._computed={};c._todo=[];c._add(a,b,null);return c}_inheritsLoose(h,k);var d=h.prototype;d.compute=function(a,b,c){var e=a+","+b;e in this._computed||this._compute(a,
b);if(e in this._computed)for(a=this._computed[e];a;)c(a.x,a.y),a=a.prev};d._compute=function(a,b){for(;this._todo.length;){var c=this._todo.shift();if(c.x==a&&c.y==b)break;for(var e=this._getNeighbors(c.x,c.y),f=0;f<e.length;f++){var g=e[f],l=g[0];g=g[1];l+","+g in this._computed||this._add(l,g,c)}}};d._add=function(a,b,c){c={x:a,y:b,prev:c};this._computed[a+","+b]=c;this._todo.push(c)};return h}(I);I=function(k){function h(a,b,c,e){void 0===e&&(e={});a=k.call(this,a,b,c,e)||this;a._todo=[];a._done=
{};return a}_inheritsLoose(h,k);var d=h.prototype;d.compute=function(a,b,c){this._todo=[];this._done={};this._fromX=a;this._fromY=b;for(this._add(this._toX,this._toY,null);this._todo.length;){var e=this._todo.shift(),f=e.x+","+e.y;if(!(f in this._done)){this._done[f]=e;if(e.x==a&&e.y==b)break;f=this._getNeighbors(e.x,e.y);for(var g=0;g<f.length;g++){var l=f[g],m=l[0];l=l[1];m+","+l in this._done||this._add(m,l,e)}}}if(a=this._done[a+","+b])for(;a;)c(a.x,a.y),a=a.prev};d._add=function(a,b,c){var e=
this._distance(a,b);a={x:a,y:b,prev:c,g:c?c.g+1:0,h:e};b=a.g+a.h;for(c=0;c<this._todo.length;c++){var f=this._todo[c],g=f.g+f.h;if(b<g||b==g&&e<f.h){this._todo.splice(c,0,a);return}}this._todo.push(a)};d._distance=function(a,b){switch(this._options.topology){case 4:return Math.abs(a-this._fromX)+Math.abs(b-this._fromY);case 6:return b=Math.abs(b-this._fromY),b+Math.max(0,(Math.abs(a-this._fromX)-b)/2);case 8:return Math.max(Math.abs(a-this._fromX),Math.abs(b-this._fromY))}};return h}(I);H={Dijkstra:H,
AStar:I};I=function(){function k(d){this._scheduler=d;this._lock=1}var h=k.prototype;h.start=function(){return this.unlock()};h.lock=function(){this._lock++;return this};h.unlock=function(){if(!this._lock)throw Error("Cannot unlock unlocked engine");for(this._lock--;!this._lock;){var d=this._scheduler.next();if(!d)return this.lock();(d=d.act())&&d.then&&(this.lock(),d.then(this.unlock.bind(this)))}return this};return k}();L=function(){function k(d,a){void 0===a&&(a={});this._reflectivityCallback=
d;this._options={};a=Object.assign({passes:1,emissionThreshold:100,range:10},a);this._lights={};this._reflectivityCache={};this._fovCache={};this.setOptions(a)}var h=k.prototype;h.setOptions=function(d){Object.assign(this._options,d);d&&d.range&&this.reset();return this};h.setFOV=function(d){this._fov=d;this._fovCache={};return this};h.setLight=function(d,a,b){d=d+","+a;b?this._lights[d]="string"==typeof b?P(b):b:delete this._lights[d];return this};h.clearLights=function(){this._lights={}};h.reset=
function(){this._reflectivityCache={};this._fovCache={};return this};h.compute=function(d){var a={},b={},c={},e;for(e in this._lights){var f=this._lights[e];b[e]=[0,0,0];ea(b[e],f)}for(e=0;e<this._options.passes;e++)this._emitLight(b,c,a),e+1!=this._options.passes&&(b=this._computeEmitters(c,a));for(var g in c)b=g.split(","),a=parseInt(b[0]),b=parseInt(b[1]),d(a,b,c[g]);return this};h._emitLight=function(d,a,b){for(var c in d){var e=c.split(","),f=parseInt(e[0]);e=parseInt(e[1]);this._emitLightFromCell(f,
e,d[c],a);b[c]=1}return this};h._computeEmitters=function(d,a){var b={},c;for(c in d)if(!(c in a)){var e=d[c];if(c in this._reflectivityCache)var f=this._reflectivityCache[c];else{var g=c.split(",");f=parseInt(g[0]);g=parseInt(g[1]);f=this._reflectivityCallback(f,g);this._reflectivityCache[c]=f}if(0!=f){g=[0,0,0];for(var l=0,m=0;3>m;m++){var n=Math.round(e[m]*f);g[m]=n;l+=n}l>this._options.emissionThreshold&&(b[c]=g)}}return b};h._emitLightFromCell=function(d,a,b,c){var e=d+","+a;d=e in this._fovCache?
this._fovCache[e]:this._updateFOV(d,a);for(var f in d){a=d[f];f in c?e=c[f]:(e=[0,0,0],c[f]=e);for(var g=0;3>g;g++)e[g]+=Math.round(b[g]*a)}return this};h._updateFOV=function(d,a){var b={};this._fovCache[d+","+a]=b;var c=this._options.range;this._fov.compute(d,a,c,function(e,f,g,l){g=l*(1-g/c);0!=g&&(b[e+","+f]=g)}.bind(this));return b};return k}();r.Color=N;r.DEFAULT_HEIGHT=25;r.DEFAULT_WIDTH=80;r.DIRS=C;r.Display=K;r.Engine=I;r.EventQueue=ma;r.FOV=F;r.KEYS={VK_CANCEL:3,VK_HELP:6,VK_BACK_SPACE:8,
VK_TAB:9,VK_CLEAR:12,VK_RETURN:13,VK_ENTER:14,VK_SHIFT:16,VK_CONTROL:17,VK_ALT:18,VK_PAUSE:19,VK_CAPS_LOCK:20,VK_ESCAPE:27,VK_SPACE:32,VK_PAGE_UP:33,VK_PAGE_DOWN:34,VK_END:35,VK_HOME:36,VK_LEFT:37,VK_UP:38,VK_RIGHT:39,VK_DOWN:40,VK_PRINTSCREEN:44,VK_INSERT:45,VK_DELETE:46,VK_0:48,VK_1:49,VK_2:50,VK_3:51,VK_4:52,VK_5:53,VK_6:54,VK_7:55,VK_8:56,VK_9:57,VK_COLON:58,VK_SEMICOLON:59,VK_LESS_THAN:60,VK_EQUALS:61,VK_GREATER_THAN:62,VK_QUESTION_MARK:63,VK_AT:64,VK_A:65,VK_B:66,VK_C:67,VK_D:68,VK_E:69,VK_F:70,
VK_G:71,VK_H:72,VK_I:73,VK_J:74,VK_K:75,VK_L:76,VK_M:77,VK_N:78,VK_O:79,VK_P:80,VK_Q:81,VK_R:82,VK_S:83,VK_T:84,VK_U:85,VK_V:86,VK_W:87,VK_X:88,VK_Y:89,VK_Z:90,VK_CONTEXT_MENU:93,VK_NUMPAD0:96,VK_NUMPAD1:97,VK_NUMPAD2:98,VK_NUMPAD3:99,VK_NUMPAD4:100,VK_NUMPAD5:101,VK_NUMPAD6:102,VK_NUMPAD7:103,VK_NUMPAD8:104,VK_NUMPAD9:105,VK_MULTIPLY:106,VK_ADD:107,VK_SEPARATOR:108,VK_SUBTRACT:109,VK_DECIMAL:110,VK_DIVIDE:111,VK_F1:112,VK_F2:113,VK_F3:114,VK_F4:115,VK_F5:116,VK_F6:117,VK_F7:118,VK_F8:119,VK_F9:120,
VK_F10:121,VK_F11:122,VK_F12:123,VK_F13:124,VK_F14:125,VK_F15:126,VK_F16:127,VK_F17:128,VK_F18:129,VK_F19:130,VK_F20:131,VK_F21:132,VK_F22:133,VK_F23:134,VK_F24:135,VK_NUM_LOCK:144,VK_SCROLL_LOCK:145,VK_CIRCUMFLEX:160,VK_EXCLAMATION:161,VK_DOUBLE_QUOTE:162,VK_HASH:163,VK_DOLLAR:164,VK_PERCENT:165,VK_AMPERSAND:166,VK_UNDERSCORE:167,VK_OPEN_PAREN:168,VK_CLOSE_PAREN:169,VK_ASTERISK:170,VK_PLUS:171,VK_PIPE:172,VK_HYPHEN_MINUS:173,VK_OPEN_CURLY_BRACKET:174,VK_CLOSE_CURLY_BRACKET:175,VK_TILDE:176,VK_COMMA:188,
VK_PERIOD:190,VK_SLASH:191,VK_BACK_QUOTE:192,VK_OPEN_BRACKET:219,VK_BACK_SLASH:220,VK_CLOSE_BRACKET:221,VK_QUOTE:222,VK_META:224,VK_ALTGR:225,VK_WIN:91,VK_KANA:21,VK_HANGUL:21,VK_EISU:22,VK_JUNJA:23,VK_FINAL:24,VK_HANJA:25,VK_KANJI:25,VK_CONVERT:28,VK_NONCONVERT:29,VK_ACCEPT:30,VK_MODECHANGE:31,VK_SELECT:41,VK_PRINT:42,VK_EXECUTE:43,VK_SLEEP:95};r.Lighting=L;r.Map=D;r.Noise=z;r.Path=H;r.RNG=t;r.Scheduler=J;r.StringGenerator=S;r.Text=M;r.Util=sa;Object.defineProperty(r,"__esModule",{value:!0})});