"use strict";var En=Object.defineProperty;var Ma=Object.getOwnPropertyDescriptor;var Da=Object.getOwnPropertyNames;var Ba=Object.prototype.hasOwnProperty;var i=(t,e)=>En(t,"name",{value:e,configurable:!0});var Fa=(t,e)=>{for(var n in e)En(t,n,{get:e[n],enumerable:!0})},La=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Da(e))!Ba.call(t,o)&&o!==n&&En(t,o,{get:()=>e[o],enumerable:!(r=Ma(e,o))||r.enumerable});return t};var Ka=t=>La(En({},"__esModule",{value:!0}),t);var lo=(()=>{for(var t=new Uint8Array(128),e=0;e<64;e++)t[e<26?e+65:e<52?e+71:e<62?e-4:e*4-205]=e;return n=>{for(var r=n.length,o=new Uint8Array((r-(n[r-1]=="=")-(n[r-2]=="="))*3/4|0),s=0,a=0;s>4,o[a++]=u<<4|p>>2,o[a++]=p<<6|c}return o}})();var Hu={};Fa(Hu,{default:()=>Uu});module.exports=Ka(Hu);var I=class t{static{i(this,"Color")}r=255;g=255;b=255;constructor(e,n,r){this.r=Me(e,0,255),this.g=Me(n,0,255),this.b=Me(r,0,255)}static fromArray(e){return new t(e[0],e[1],e[2])}static fromHex(e){if(typeof e=="number")return new t(e>>16&255,e>>8&255,e>>0&255);if(typeof e=="string"){let n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(!n)throw new Error("Invalid hex color format");return new t(parseInt(n[1],16),parseInt(n[2],16),parseInt(n[3],16))}else throw new Error("Invalid hex color format")}static fromHSL(e,n,r){if(n==0)return new t(255*r,255*r,255*r);let o=i((c,f,d)=>(d<0&&(d+=1),d>1&&(d-=1),d<1/6?c+(f-c)*6*d:d<1/2?f:d<2/3?c+(f-c)*(2/3-d)*6:c),"hue2rgb"),s=r<.5?r*(1+n):r+n-r*n,a=2*r-s,m=o(a,s,e+1/3),u=o(a,s,e),p=o(a,s,e-1/3);return new t(Math.round(m*255),Math.round(u*255),Math.round(p*255))}static RED=new t(255,0,0);static GREEN=new t(0,255,0);static BLUE=new t(0,0,255);static YELLOW=new t(255,255,0);static MAGENTA=new t(255,0,255);static CYAN=new t(0,255,255);static WHITE=new t(255,255,255);static BLACK=new t(0,0,0);clone(){return new t(this.r,this.g,this.b)}lighten(e){return new t(this.r+e,this.g+e,this.b+e)}darken(e){return this.lighten(-e)}invert(){return new t(255-this.r,255-this.g,255-this.b)}mult(e){return new t(this.r*e.r/255,this.g*e.g/255,this.b*e.b/255)}lerp(e,n){return new t(fe(this.r,e.r,n),fe(this.g,e.g,n),fe(this.b,e.b,n))}toHSL(){let e=this.r/255,n=this.g/255,r=this.b/255,o=Math.max(e,n,r),s=Math.min(e,n,r),a=(o+s)/2,m=a,u=a;if(o==s)a=m=0;else{let p=o-s;switch(m=u>.5?p/(2-o-s):p/(o+s),o){case e:a=(n-r)/p+(nI.fromHSL(t,e,n),"hsl2rgb");function se(t){return t*Math.PI/180}i(se,"deg2rad");function ct(t){return t*180/Math.PI}i(ct,"rad2deg");function Me(t,e,n){return e>n?Me(t,n,e):Math.min(Math.max(t,e),n)}i(Me,"clamp");function fe(t,e,n){if(typeof t=="number"&&typeof e=="number")return t+(e-t)*n;if(t instanceof C&&e instanceof C)return t.lerp(e,n);if(t instanceof I&&e instanceof I)return t.lerp(e,n);throw new Error(`Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.`)}i(fe,"lerp");function Se(t,e,n,r,o){return r+(t-e)/(n-e)*(o-r)}i(Se,"map");function fo(t,e,n,r,o){return Me(Se(t,e,n,r,o),r,o)}i(fo,"mapc");var C=class t{static{i(this,"Vec2")}x=0;y=0;constructor(e=0,n=e){this.x=e,this.y=n}static fromAngle(e){let n=se(e);return new t(Math.cos(n),Math.sin(n))}static fromArray(e){return new t(e[0],e[1])}static LEFT=new t(-1,0);static RIGHT=new t(1,0);static UP=new t(0,-1);static DOWN=new t(0,1);clone(){return new t(this.x,this.y)}add(...e){let n=x(...e);return new t(this.x+n.x,this.y+n.y)}sub(...e){let n=x(...e);return new t(this.x-n.x,this.y-n.y)}scale(...e){let n=x(...e);return new t(this.x*n.x,this.y*n.y)}dist(...e){let n=x(...e);return this.sub(n).len()}sdist(...e){let n=x(...e);return this.sub(n).slen()}len(){return Math.sqrt(this.dot(this))}slen(){return this.dot(this)}unit(){let e=this.len();return e===0?new t(0):this.scale(1/e)}normal(){return new t(this.y,-this.x)}reflect(e){return this.sub(e.scale(2*this.dot(e)))}project(e){return e.scale(e.dot(this)/e.len())}reject(e){return this.sub(this.project(e))}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}angle(...e){let n=x(...e);return ct(Math.atan2(this.y-n.y,this.x-n.x))}angleBetween(...e){let n=x(...e);return ct(Math.atan2(this.cross(n),this.dot(n)))}lerp(e,n){return new t(fe(this.x,e.x,n),fe(this.y,e.y,n))}slerp(e,n){let r=this.dot(e),o=this.cross(e),s=Math.atan2(o,r);return this.scale(Math.sin((1-n)*s)).add(e.scale(Math.sin(n*s))).scale(1/o)}isZero(){return this.x===0&&this.y===0}toFixed(e){return new t(Number(this.x.toFixed(e)),Number(this.y.toFixed(e)))}transform(e){return e.multVec2(this)}eq(e){return this.x===e.x&&this.y===e.y}bbox(){return new W(this,0,0)}toString(){return`vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`}toArray(){return[this.x,this.y]}};function x(...t){if(t.length===1){if(t[0]instanceof C)return new C(t[0].x,t[0].y);if(Array.isArray(t[0])&&t[0].length===2)return new C(...t[0])}return new C(...t)}i(x,"vec2");var z=class t{static{i(this,"Quad")}x=0;y=0;w=1;h=1;constructor(e,n,r,o){this.x=e,this.y=n,this.w=r,this.h=o}scale(e){return new t(this.x+this.w*e.x,this.y+this.h*e.y,this.w*e.w,this.h*e.h)}pos(){return new C(this.x,this.y)}clone(){return new t(this.x,this.y,this.w,this.h)}eq(e){return this.x===e.x&&this.y===e.y&&this.w===e.w&&this.h===e.h}toString(){return`quad(${this.x}, ${this.y}, ${this.w}, ${this.h})`}};function le(t,e,n,r){return new z(t,e,n,r)}i(le,"quad");var Mt=class t{static{i(this,"Mat2")}a;b;c;d;constructor(e,n,r,o){this.a=e,this.b=n,this.c=r,this.d=o}mul(e){return new t(this.a*e.a+this.b*e.c,this.a*e.b+this.b*e.d,this.c*e.a+this.d*e.c,this.c*e.b+this.d*e.d)}transform(e){return x(this.a*e.x+this.b*e.y,this.c*e.x+this.d*e.y)}get inverse(){let e=this.det;return new t(this.d/e,-this.b/e,-this.c/e,this.a/e)}get transpose(){return new t(this.a,this.c,this.b,this.d)}get eigenvalues(){let e=this.trace/2,n=this.det,r=e+Math.sqrt(e*e-n),o=e-Math.sqrt(e*e-n);return[r,o]}eigenvectors(e,n){return this.c!=0?[[e-this.d,this.c],[n-this.d,this.c]]:this.b!=0?[[this.b,e-this.a],[this.b,n-this.a]]:Math.abs(this.transform(x(1,0)).x-e)0?Math.acos(this.m[0]/e):-Math.acos(this.m[0]/e))}else if(this.m[4]!=0||this.m[5]!=0){let e=Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]);return ct(Math.PI/2-(this.m[5]>0?Math.acos(-this.m[4]/e):-Math.acos(this.m[4]/e)))}else return 0}getSkew(){if(this.m[0]!=0||this.m[1]!=0){let e=Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]);return new C(Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e),0)}else if(this.m[4]!=0||this.m[5]!=0){let e=Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]);return new C(0,Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e))}else return new C(0,0)}invert(){let e=[],n=this.m[10]*this.m[15]-this.m[14]*this.m[11],r=this.m[9]*this.m[15]-this.m[13]*this.m[11],o=this.m[9]*this.m[14]-this.m[13]*this.m[10],s=this.m[8]*this.m[15]-this.m[12]*this.m[11],a=this.m[8]*this.m[14]-this.m[12]*this.m[10],m=this.m[8]*this.m[13]-this.m[12]*this.m[9],u=this.m[6]*this.m[15]-this.m[14]*this.m[7],p=this.m[5]*this.m[15]-this.m[13]*this.m[7],c=this.m[5]*this.m[14]-this.m[13]*this.m[6],f=this.m[4]*this.m[15]-this.m[12]*this.m[7],d=this.m[4]*this.m[14]-this.m[12]*this.m[6],v=this.m[5]*this.m[15]-this.m[13]*this.m[7],h=this.m[4]*this.m[13]-this.m[12]*this.m[5],O=this.m[6]*this.m[11]-this.m[10]*this.m[7],y=this.m[5]*this.m[11]-this.m[9]*this.m[7],w=this.m[5]*this.m[10]-this.m[9]*this.m[6],V=this.m[4]*this.m[11]-this.m[8]*this.m[7],R=this.m[4]*this.m[10]-this.m[8]*this.m[6],P=this.m[4]*this.m[9]-this.m[8]*this.m[5];e[0]=this.m[5]*n-this.m[6]*r+this.m[7]*o,e[4]=-(this.m[4]*n-this.m[6]*s+this.m[7]*a),e[8]=this.m[4]*r-this.m[5]*s+this.m[7]*m,e[12]=-(this.m[4]*o-this.m[5]*a+this.m[6]*m),e[1]=-(this.m[1]*n-this.m[2]*r+this.m[3]*o),e[5]=this.m[0]*n-this.m[2]*s+this.m[3]*a,e[9]=-(this.m[0]*r-this.m[1]*s+this.m[3]*m),e[13]=this.m[0]*o-this.m[1]*a+this.m[2]*m,e[2]=this.m[1]*u-this.m[2]*p+this.m[3]*c,e[6]=-(this.m[0]*u-this.m[2]*f+this.m[3]*d),e[10]=this.m[0]*v-this.m[1]*f+this.m[3]*h,e[14]=-(this.m[0]*c-this.m[1]*d+this.m[2]*h),e[3]=-(this.m[1]*O-this.m[2]*y+this.m[3]*w),e[7]=this.m[0]*O-this.m[2]*V+this.m[3]*R,e[11]=-(this.m[0]*y-this.m[1]*V+this.m[3]*P),e[15]=this.m[0]*w-this.m[1]*R+this.m[2]*P;let D=this.m[0]*e[0]+this.m[1]*e[4]+this.m[2]*e[8]+this.m[3]*e[12];for(let b=0;b<4;b++)for(let E=0;E<4;E++)e[b*4+E]*=1/D;return new t(e)}clone(){return new t([...this.m])}toString(){return this.m.toString()}};function Sn(t,e,n,r=o=>-Math.cos(o)){return t+(r(n)+1)/2*(e-t)}i(Sn,"wave");var Ia=1103515245,ja=12345,po=2147483648,$t=class{static{i(this,"RNG")}seed;constructor(e){this.seed=e}gen(){return this.seed=(Ia*this.seed+ja)%po,this.seed/po}genNumber(e,n){return e+this.gen()*(n-e)}genVec2(e,n){return new C(this.genNumber(e.x,n.x),this.genNumber(e.y,n.y))}genColor(e,n){return new I(this.genNumber(e.r,n.r),this.genNumber(e.g,n.g),this.genNumber(e.b,n.b))}genAny(...e){if(e.length===0)return this.gen();if(e.length===1){if(typeof e[0]=="number")return this.genNumber(0,e[0]);if(e[0]instanceof C)return this.genVec2(x(0,0),e[0]);if(e[0]instanceof I)return this.genColor(_(0,0,0),e[0])}else if(e.length===2){if(typeof e[0]=="number"&&typeof e[1]=="number")return this.genNumber(e[0],e[1]);if(e[0]instanceof C&&e[1]instanceof C)return this.genVec2(e[0],e[1]);if(e[0]instanceof I&&e[1]instanceof I)return this.genColor(e[0],e[1])}throw new Error("More than 2 arguments not supported")}},xr=new $t(Date.now());function ho(t){return t!=null&&(xr.seed=t),xr.seed}i(ho,"randSeed");function ge(...t){return xr.genAny(...t)}i(ge,"rand");function vr(...t){return Math.floor(ge(...t.length>0?t:[2]))}i(vr,"randi");function go(t){return ge()<=t}i(go,"chance");function wr(t){for(let e=t.length-1;e>0;e--){let n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t}i(wr,"shuffle");function bo(t,e){return t.length<=e?t.slice():wr(t.slice()).slice(0,e)}i(bo,"chooseMultiple");function yo(t){return t[vr(t.length)]}i(yo,"choose");function Cr(t,e){return t.pos.x+t.width>e.pos.x&&t.pos.xe.pos.y&&t.pos.y1||o<0||o>1?null:r}i(ka,"testLineLineT");function Vn(t,e){let n=ka(t,e);return n?x(t.p1.x+n*(t.p2.x-t.p1.x),t.p1.y+n*(t.p2.y-t.p1.y)):null}i(Vn,"testLineLine");function Pn(t,e){let n=e.p2.sub(e.p1),r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY;if(n.x!=0){let s=(t.pos.x-e.p1.x)/n.x,a=(t.pos.x+t.width-e.p1.x)/n.x;r=Math.max(r,Math.min(s,a)),o=Math.min(o,Math.max(s,a))}if(n.y!=0){let s=(t.pos.y-e.p1.y)/n.y,a=(t.pos.y+t.height-e.p1.y)/n.y;r=Math.max(r,Math.min(s,a)),o=Math.min(o,Math.max(s,a))}return o>=r&&o>=0&&r<=1}i(Pn,"testRectLine");function Dt(t,e){return e.x>t.pos.x&&e.xt.pos.y&&e.yNumber.EPSILON)return!1;let o=n.dot(r)/r.dot(r);return o>=0&&o<=1}i(Gn,"testLinePoint");function Bt(t,e){let n=t.p2.sub(t.p1),r=n.dot(n),o=t.p1.sub(e.center),s=2*n.dot(o),a=o.dot(o)-e.radius*e.radius,m=s*s-4*r*a;if(r<=Number.EPSILON||m<0)return!1;if(m==0){let u=-s/(2*r);if(u>=0&&u<=1)return!0}else{let u=(-s+Math.sqrt(m))/(2*r),p=(-s-Math.sqrt(m))/(2*r);if(u>=0&&u<=1||p>=0&&p<=1)return!0}return Rn(e,t.p1)}i(Bt,"testLineCircle");function Or(t,e){if(et(e,t.p1)||et(e,t.p2))return!0;for(let n=0;net(e,n))||e.pts.some(n=>et(t,n)))}i(wo,"testPolygonPolygon");function et(t,e){let n=!1,r=t.pts;for(let o=0,s=r.length-1;oe.y!=r[s].y>e.y&&e.x<(r[s].x-r[o].x)*(e.y-r[o].y)/(r[s].y-r[o].y)+r[o].x&&(n=!n);return n}i(et,"testPolygonPoint");function Er(t,e){e=e.sub(t.center);let n=se(t.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,a=-e.x*o+e.y*r;return s*s/(t.radiusX*t.radiusX)+a*a/(t.radiusY*t.radiusY)<1}i(Er,"testEllipsePoint");function Tn(t,e){let n=e.center.sub(t.center),r=se(t.angle),o=Math.cos(r),s=Math.sin(r),a=n.x*o+n.y*s,m=-n.x*s+n.y*o;return Er(new je(x(),t.radiusX+e.radius,t.radiusY+e.radius,0),x(a,m))}i(Tn,"testEllipseCircle");function Co(t,e){let n=t.toMat2().inverse;return e=new Te(n.transform(e.p1.sub(t.center)),n.transform(e.p2.sub(t.center))),Bt(e,new Ce(x(),1))}i(Co,"testEllipseLine");function Na(t,e){if(t.radiusX===t.radiusY)return Tn(e,new Ce(t.center,t.radiusX));if(e.radiusX===e.radiusY)return Tn(t,new Ce(e.center,e.radiusX));let n=new ht(1/t.radiusX**2,0,0,0,1/t.radiusY**2,0,0,0,-1),r=new ht(1/e.radiusX**2,0,0,0,1/e.radiusY**2,0,0,0,-1),o=t.center.x,s=t.center.y,a=e.center.x,m=e.center.y,u=se(t.angle),p=se(e.angle),c=new ht(Math.cos(u),-Math.sin(u),o,Math.sin(u),Math.cos(u),s,0,0,1),f=new ht(Math.cos(p),-Math.sin(p),a,Math.sin(p),Math.cos(p),m,0,0,1),d=c.inverse,v=f.inverse,h=d.transpose.mul(n).mul(d),O=v.transpose.mul(r).mul(v),y=h.m11,w=h.m12,V=h.m13,R=h.m21,P=h.m22,D=h.m23,b=h.m31,E=h.m32,A=h.m33,G=O.m11,M=O.m12,F=O.m13,K=O.m21,H=O.m22,q=O.m23,Y=O.m31,N=O.m32,j=O.m33,Z=y*P*A-y*D*E-w*R*A+w*D*b+V*R*E-V*P*b,$=(y*P*j-y*D*N-y*E*q+y*A*H-w*R*j+w*D*Y+w*b*q-w*A*K+V*R*N-V*P*Y-V*b*H+V*E*K+R*E*F-R*A*M-P*b*F+P*A*G+D*b*M-D*E*G)/Z,ee=(y*H*j-y*q*N-w*K*j+w*q*Y+V*K*N-V*H*Y-R*M*j+R*F*N+P*G*j-P*F*Y-D*G*N+D*M*Y+b*M*q-b*F*H-E*G*q+E*F*K+A*G*H-A*M*K)/Z,Ee=(G*H*j-G*q*N-M*K*j+M*q*Y+F*K*N-F*H*Y)/Z;if($>=0){let k=-3*ee+$**2,ft=3*$*Ee+ee*$**2-4*ee**2,Pt=-27*Ee**2+18*Ee*$*ee+$**2*ee**2-4*$**3*Ee-4*ee**3;return!(k>0&&ft<0&&Pt>0)}else{let k=-3*ee+$**2,ft=-27*Ee**2+18*Ee*$*ee+$**2*ee**2-4*$**3*Ee-4*ee**3;return!(k>0&&ft>0)}}i(Na,"testEllipseEllipse");function Oo(t,e){return Tr(t,new ye(e.points()))}i(Oo,"testEllipseRect");function Tr(t,e){let n=t.toMat2().inverse;return e=new ye(e.pts.map(r=>n.transform(r.sub(t.center)))),Xt(new Ce(x(),1),e)}i(Tr,"testEllipsePolygon");function Ua(t,e){return t.x===e.x&&t.y===e.y}i(Ua,"testPointPoint");function Ha(t,e){return e instanceof C?Ua(e,t.pt):e instanceof Ce?Rn(e,t.pt):e instanceof Te?Gn(e,t.pt):e instanceof W?Dt(e,t.pt):e instanceof ye?et(e,t.pt):e instanceof je?Er(e,t.pt):!1}i(Ha,"testPointShape");function qa(t,e){return e instanceof C?Gn(t,e):e instanceof Ce?Bt(t,e):e instanceof Te?Vn(t,e)!=null:e instanceof W?Pn(e,t):e instanceof ye?Or(t,e):e instanceof je?Co(e,t):!1}i(qa,"testLineShape");function za(t,e){return e instanceof C?Rn(t,e):e instanceof Ce?_a(t,e):e instanceof Te?Bt(e,t):e instanceof W?xo(e,t):e instanceof ye?Xt(t,e):e instanceof je?Tn(e,t):!1}i(za,"testCircleShape");function Ya(t,e){return e instanceof C?Dt(t,e):e instanceof Ce?xo(t,e):e instanceof Te?Pn(t,e):e instanceof W?Cr(t,e):e instanceof ye?vo(t,e):e instanceof je?Oo(e,t):!1}i(Ya,"testRectShape");function Wa(t,e){return e instanceof C?et(t,e):e instanceof Ce?Xt(e,t):e instanceof Te?Or(e,t):e instanceof W?vo(e,t):e instanceof ye?wo(e,t):e instanceof je?Tr(e,t):!1}i(Wa,"testPolygonShape");function $a(t,e){return e instanceof C?Er(t,e):e instanceof Ce?Tn(t,e):e instanceof Te?Co(t,e):e instanceof W?Oo(t,e):e instanceof ye?Tr(t,e):e instanceof je?Na(e,t):!1}i($a,"testEllipseShape");function Eo(t,e,n){let r=t,o=n.p1,s=n.p2,a=e,m=s.sub(o),u=a.cross(m);if(Math.abs(u)=1)return null;let f=p.cross(a)/u;if(f<=0||f>=1)return null;let d=m.normal().unit();return e.dot(d)>0&&(d.x*=-1,d.y*=-1),{point:r.add(a.scale(c)),normal:d,fraction:c}}i(Eo,"raycastLine");function Xa(t,e,n){let r=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,s;if(t.x!=0){let a=(n.pos.x-t.x)/e.x,m=(n.pos.x+n.width-t.x)/e.x;s=x(-Math.sign(e.x),0),r=Math.max(r,Math.min(a,m)),o=Math.min(o,Math.max(a,m))}if(t.y!=0){let a=(n.pos.y-t.y)/e.y,m=(n.pos.y+n.height-t.y)/e.y;Math.min(a,m)>r&&(s=x(0,-Math.sign(e.y))),r=Math.max(r,Math.min(a,m)),o=Math.min(o,Math.max(a,m))}return o>=r&&r>=0&&r<=1?{point:t.add(e.scale(r)),normal:s,fraction:r}:null}i(Xa,"raycastRect");function To(t,e,n){let r=t,o=n.center,s=e,a=s.dot(s),m=r.sub(o),u=2*s.dot(m),p=m.dot(m)-n.radius*n.radius,c=u*u-4*a*p;if(a<=Number.EPSILON||c<0)return null;if(c==0){let f=-u/(2*a);if(f>=0&&f<=1){let d=r.add(s.scale(f));return{point:d,normal:d.sub(o),fraction:f}}}else{let f=(-u+Math.sqrt(c))/(2*a),d=(-u-Math.sqrt(c))/(2*a),v=null;if(f>=0&&f<=1&&(v=f),d>=0&&d<=1&&(v=Math.min(d,v??d)),v!=null){let h=r.add(s.scale(v));return{point:h,normal:h.sub(o).unit(),fraction:v}}}return null}i(To,"raycastCircle");function Qa(t,e,n){let r=n.pts,o=null,s=r[r.length-1];for(let a=0;au.fraction)&&(o=u),s=m}return o}i(Qa,"raycastPolygon");function Ja(t,e,n){let r=n.toMat2(),o=r.inverse,s=o.transform(t.sub(n.center)),a=o.transform(e),m=To(s,a,new Ce(x(),1));if(m){let u=Mt.rotation(se(-n.angle)),c=Mt.scale(n.radiusX,n.radiusY).transform(m.point),f=r.transform(m.point).add(n.center),d=f.dist(t)/e.len();return{point:f,normal:u.transform(x(n.radiusY**2*c.x,n.radiusX**2*c.y)).unit(),fraction:d}}return m}i(Ja,"raycastEllipse");function Ao(t,e,n,r=64){let o=t,s=e.len(),a=e.scale(1/s),m=0,u=x(Math.floor(t.x),Math.floor(t.y)),p=x(a.x>0?1:-1,a.y>0?1:-1),c=x(Math.abs(1/a.x),Math.abs(1/a.y)),f=x(p.x>0?u.x+1-t.x:t.x-u.x,p.y>0?u.y+1-t.y:t.y-u.y),d=x(c.x<1/0?c.x*f.x:1/0,c.y<1/0?c.y*f.y:1/0),v=-1;for(;m<=r;){let h=n(u);if(h===!0)return{point:o.add(a.scale(m)),normal:x(v===0?-p.x:0,v===1?-p.y:0),fraction:m/s,gridPos:u};if(h)return h;d.xe.multVec2(n)))}bbox(){return this.clone()}area(){return this.width*this.height}clone(){return new t(this.pos.clone(),this.width,this.height)}distToPoint(e){return Math.sqrt(this.sdistToPoint(e))}sdistToPoint(e){let n=this.pos,r=this.pos.add(this.width,this.height),o=Math.max(n.x-e.x,0,e.x-r.x),s=Math.max(n.y-e.y,0,e.y-r.y);return o*o+s*s}collides(e){return Ya(this,e)}contains(e){return this.collides(e)}raycast(e,n){return Xa(e,n,this)}random(){return this.pos.add(ge(this.width),ge(this.height))}},Ce=class t{static{i(this,"Circle")}center;radius;constructor(e,n){this.center=e.clone(),this.radius=n}transform(e){return new je(this.center,this.radius,this.radius).transform(e)}bbox(){return W.fromPoints(this.center.sub(x(this.radius)),this.center.add(x(this.radius)))}area(){return this.radius*this.radius*Math.PI}clone(){return new t(this.center,this.radius)}collides(e){return za(this,e)}contains(e){return this.collides(e)}raycast(e,n){return To(e,n,this)}random(){return this.center.add(C.fromAngle(ge(360)).scale(ge(this.radius)))}},je=class t{static{i(this,"Ellipse")}center;radiusX;radiusY;angle;constructor(e,n,r,o=0){this.center=e.clone(),this.radiusX=n,this.radiusY=r,this.angle=o}static fromMat2(e){let n=e.inverse,r=n.transpose.mul(n),[o,s]=r.eigenvalues,[a,m]=r.eigenvectors(o,s),[u,p]=[1/Math.sqrt(o),1/Math.sqrt(s)];return u>p?new t(x(),u,p,ct(Math.atan2(-a[1],a[0]))):new t(x(),p,u,ct(Math.atan2(-m[1],m[0])))}toMat2(){let e=se(this.angle),n=Math.cos(e),r=Math.sin(e);return new Mt(n*this.radiusX,-r*this.radiusY,r*this.radiusX,n*this.radiusY)}transform(e){if(this.angle==0&&e.getRotation()==0)return new t(e.multVec2(this.center),e.m[0]*this.radiusX,e.m[5]*this.radiusY);{let n=this.toMat2(),r=e.getRotation(),o=e.getScale();n=ht.fromMat2(n).scale(o.x,o.y).rotate(r).toMat2();let a=t.fromMat2(n);return a.center=e.multVec2(this.center),a}}bbox(){if(this.angle==0)return W.fromPoints(this.center.sub(x(this.radiusX,this.radiusY)),this.center.add(x(this.radiusX,this.radiusY)));{let e=se(this.angle),n=Math.cos(e),r=Math.sin(e),o=this.radiusX*n,s=this.radiusX*r,a=this.radiusY*r,m=this.radiusY*n,u=Math.sqrt(o*o+a*a),p=Math.sqrt(s*s+m*m);return W.fromPoints(this.center.sub(x(u,p)),this.center.add(x(u,p)))}}area(){return this.radiusX*this.radiusY*Math.PI}clone(){return new t(this.center,this.radiusX,this.radiusY,this.angle)}collides(e){return $a(this,e)}contains(e){e=e.sub(this.center);let n=se(this.angle),r=Math.cos(n),o=Math.sin(n),s=e.x*r+e.y*o,a=-e.x*o+e.y*r;return s*s/(this.radiusX*this.radiusX)+a*a/(this.radiusY*this.radiusY)<1}raycast(e,n){return Ja(e,n,this)}random(){return this.center}};function Za(t,e,n,r){let o=e.sub(t),s=r.sub(n),a=o.cross(s);return a<1e-5&&a>-1e-5||(a=n.sub(t).cross(s)/a,a<0||a>1)?null:t.add(o.scale(a))}i(Za,"segmentLineIntersection");var ye=class t{static{i(this,"Polygon")}pts;constructor(e){if(e.length<3)throw new Error("Polygons should have at least 3 vertices");this.pts=e}transform(e){return new t(this.pts.map(n=>e.multVec2(n)))}bbox(){let e=x(Number.MAX_VALUE),n=x(-Number.MAX_VALUE);for(let r of this.pts)e.x=Math.min(e.x,r.x),n.x=Math.max(n.x,r.x),e.y=Math.min(e.y,r.y),n.y=Math.max(n.y,r.y);return W.fromPoints(e,n)}area(){let e=0,n=this.pts.length;for(let r=0;re.clone()))}collides(e){return Wa(this,e)}contains(e){return this.collides(e)}raycast(e,n){return Qa(e,n,this)}random(){return x()}cut(e,n){let r=new Te(e,n),o=[],s=[],a=n.sub(e),m=this.pts[this.pts.length-1],u=m.sub(e),p=a.cross(u)>0;return this.pts.forEach(c=>{u=c.sub(e);let f=a.cross(u)>0;if(p!=f){let d=Za(m,c,e,n);o.push(d),s.push(d),p=f}(f?o:s).push(c),m=c}),[o.length?new t(o):null,s.length?new t(s):null]}};function So(t,e,n,r){let o=r*r,s=1-r,a=s*s;return t.scale(a).add(e.scale(2*s*r)).add(n.scale(o))}i(So,"evaluateQuadratic");function Vo(t,e,n,r){let o=1-r;return e.sub(t).scale(2*o).add(n.sub(e).scale(2*r))}i(Vo,"evaluateQuadraticFirstDerivative");function Po(t,e,n,r){return n.sub(e.scale(2)).add(t).scale(2)}i(Po,"evaluateQuadraticSecondDerivative");function Qt(t,e,n,r,o){let s=o*o,a=s*o,m=1-o,u=m*m,p=u*m;return t.scale(p).add(e.scale(3*u*o)).add(n.scale(3*m*s)).add(r.scale(a))}i(Qt,"evaluateBezier");function Go(t,e,n,r,o){let s=o*o,a=1-o,m=a*a;return e.sub(t).scale(3*m).add(n.sub(e).scale(6*a*o)).add(r.sub(n).scale(3*s))}i(Go,"evaluateBezierFirstDerivative");function Ro(t,e,n,r,o){let s=1-o;return n.sub(e.scale(2)).add(t).scale(6*s).add(r.sub(n.scale(2)).add(e).scale(6*o))}i(Ro,"evaluateBezierSecondDerivative");function Mo(t,e,n,r,o){let s=.5*(((-o+2)*o-1)*o),a=.5*((3*o-5)*o*o+2),m=.5*(((-3*o+4)*o+1)*o),u=.5*((o-1)*o*o);return t.scale(s).add(e.scale(a)).add(n.scale(m)).add(r.scale(u))}i(Mo,"evaluateCatmullRom");function Do(t,e,n,r,o){let s=.5*((-3*o+4)*o-1),a=.5*((9*o-10)*o),m=.5*((-9*o+8)*o+1),u=.5*((3*o-2)*o);return t.scale(s).add(e.scale(a)).add(n.scale(m)).add(r.scale(u))}i(Do,"evaluateCatmullRomFirstDerivative");function Bo(t){let e=Ar(t),n=e(1);return r=>{let o=r*n,s=e(o,!0);return t(s)}}i(Bo,"normalizedCurve");function Ar(t,e=10,n=10){let r=[0],o=[0],a=1/(e-1)/n,m=0,u=t(0),p=0;for(let c=1;c{if(f){let d=c;if(d<=0)return 0;if(d>=m)return 1;let v=0;for(;r[v+1]=1)return r[e-1];let d=0;for(;o[d+1]{let p=u*u,c=p*u;return o*c+s*p+a*u+m}}i(Ft,"hermite");function Sr(t,e,n,r,o,s=Ft){let a=s(e.x,(1-o)*(n.x-t.x),(1-o)*(r.x-e.x),n.x),m=s(e.y,(1-o)*(n.y-t.y),(1-o)*(r.y-e.y),n.y);return u=>new C(a(u),m(u))}i(Sr,"cardinal");function Lt(t,e,n,r,o=Ft){return Sr(t,e,n,r,.5,o)}i(Lt,"catmullRom");function Fo(t,e,n,r,o=Ft){return Lt(r.add(t.sub(e).scale(6)),t,r,t.add(r.sub(n).scale(6)),o)}i(Fo,"bezier");function Lo(t,e,n,r,o,s,a,m=Ft){let u=m(e.x,.5*(1-o)*(1+a)*(1+s)*(e.x-t.x)+.5*(1-o)*(1-a)*(1-s)*(n.x-e.x),.5*(1-o)*(1+a)*(1-s)*(n.x-e.x)+.5*(1-o)*(1-a)*(1+s)*(r.x-n.x),n.x),p=m(e.y,.5*(1-o)*(1+a)*(1+s)*(e.y-t.y)+.5*(1-o)*(1-a)*(1-s)*(n.y-e.y),.5*(1-o)*(1+a)*(1-s)*(n.y-e.y)+.5*(1-o)*(1-a)*(1+s)*(r.y-n.y),n.y);return c=>new C(u(c),p(c))}i(Lo,"kochanekBartels");function Ko(t,e,n,r){let o=2*t+e-2*r+n,s=-3*t+3*r-2*e+n,a=e;return m=>{let u=m*m;return 3*o*u+2*s*m+a}}i(Ko,"hermiteFirstDerivative");function Yt(t){return 0<=t&&t<=1}i(Yt,"inZeroOneDomain");function br(t,e){return Math.abs(t-e)<=Number.EPSILON}i(br,"approximately");function Wt(t){return t<0?-Math.pow(-t,1/3):Math.pow(t,1/3)}i(Wt,"cubeRoot");function eu(t,e,n,r){let o=3*t-6*e+3*n,s=-3*t+3*e,a=t,m=-t+3*e-3*n+r;if(br(m,0)){if(br(o,0))return br(s,0)?[]:[-a/s].filter(Yt);let w=Math.sqrt(s*s-4*o*a),V=2*o;return[(w-s)/V,(-s-w)/V].filter(Yt)}o/=m,s/=m,a/=m;let u=(3*s-o*o)/3,p=u/3,c=(2*o*o*o-9*o*s+27*a)/27,f=c/2,d=f*f+p*p*p;if(d<0){let w=-u/3,V=w*w*w,R=Math.sqrt(V),P=-c/(2*R),D=P<-1?-1:P>1?1:P,b=Math.acos(D),A=2*Wt(R),G=A*Math.cos(b/3)-o/3,M=A*Math.cos((b+2*Math.PI)/3)-o/3,F=A*Math.cos((b+4*Math.PI)/3)-o/3;return[G,M,F].filter(Yt)}if(d===0){let w=f<0?Wt(-f):-Wt(f),V=2*w-o/3,R=-w-o/3;return[V,R].filter(Yt)}let v=Math.sqrt(d),h=Wt(v-f),O=Wt(v+f);return[h-O-o/3].filter(Yt)}i(eu,"getCubicRoots");function tu(t,e,n,r,o){let s=eu(t.x-o,e.x-o,n.x-o,r.x-o);return s.length>0?Qt(t,e,n,r,s[0]).y:NaN}i(tu,"cubicBezierYforX");function Io(t){if(!t||t.length==0)throw new Error("Need at least one point for easingLinear.");let e=t.length;return n=>{if(n<=0||t.length==1||n<=t[0].x)return t[0].y;for(let r=0;r=n)return Se(n,t[r-1].x,t[r].x,t[r-1].y,t[r].y);return t[t.length-1].y}}i(Io,"easingLinear");function jo(t,e){return n=>tu(x(0,0),t,e,x(1,1),n)}i(jo,"easingCubicBezier");function ko(t,e="jump-end"){let n=1/t,r=e=="jump-start"||e=="jump-both",o=e=="jump-end"||e=="jump-both",s=1/(t+(o?1:0)),a=r?s:0;return m=>{let u=Math.floor(m/n);return a+u*s}}i(ko,"easingSteps");function _o(t,e){let n=Number.MAX_VALUE,r={normal:x(0),distance:0};for(let o of[t,e])for(let s=0;s=0}i(No,"isOrientedCcw");function nu(t){let e=0,n=t[t.length-1];for(let r=0;r=0}i(yr,"onSameSide");function ru(t,e,n,r){return yr(t,e,n,r)&&yr(t,n,e,r)&&yr(t,r,e,n)}i(ru,"pointInTriangle");function ou(t,e,n,r){for(let o of t)if(o!==e&&o!==n&&o!==r&&ru(o,e,n,r))return!0;return!1}i(ou,"someInTriangle");function iu(t,e,n,r){return No(t,e,n)&&!ou(r,t,e,n)}i(iu,"isEar");function Mn(t){if(t.length<3)return[];if(t.length==3)return[t];let e=[],n=[],r=0;for(let f=0;f3;){p=e[m],c=n[m];let f=t[c],d=t[m],v=t[p];if(iu(f,d,v,o))s.push([f,d,v]),e[c]=p,n[p]=c,o.splice(o.indexOf(d),1),--a,u=0;else if(++u>a)return[];m=p}return p=e[m],c=n[m],s.push([t[c],t[m],t[p]]),s}i(Mn,"triangulate");function Uo(t){if(t.length<3)return!1;let e=t.length-2,n=t.length-1,r=0,o=t[n].sub(t[e]),s=t[r].sub(t[n]),a=o.cross(s);for(;r+1t[0]instanceof I,"arrayIsColor"),qo=i(t=>t[0]instanceof C,"arrayIsVec2"),zo=i(t=>typeof t[0]=="number","arrayIsNumber");var Kt=class{static{i(this,"BinaryHeap")}_items;_compareFn;constructor(e=(n,r)=>n0;){let n=Math.floor((e-1)/2);if(!this._compareFn(this._items[e],this._items[n])&&this._items[e]>=this._items[n])break;this.swap(e,n),e=n}}moveDown(e){for(;et.match(/^data:\w+\/\w+;base64,.+/),"isDataURL");var $o=i(t=>t.split(".").slice(0,-1).join("."),"getFileName");function Fn(t,e){if(t===e)return!0;let n=typeof t,r=typeof e;if(n!==r)return!1;if(n==="object"&&r==="object"&&t!==null&&e!==null){if(Array.isArray(t)!==Array.isArray(e))return!1;let o=Object.keys(t),s=Object.keys(e);if(o.length!==s.length)return!1;for(let a of o){let m=t[a],u=e[a];if(!Fn(m,u))return!1}return!0}return!1}i(Fn,"deepEq");var Jt=class extends Map{static{i(this,"Registry")}lastID=0;push(e){let n=this.lastID;return this.set(n,e),this.lastID++,n}pushd(e){let n=this.push(e);return()=>this.delete(n)}},ke=class t{static{i(this,"KEventController")}paused=!1;cancel;constructor(e){this.cancel=e}static join(e){let n=new t(()=>e.forEach(r=>r.cancel()));return Object.defineProperty(n,"paused",{get:i(()=>e[0].paused,"get"),set:i(r=>e.forEach(o=>o.paused=r),"set")}),n.paused=!1,n}static replace(e,n){return e.cancel=()=>n.cancel(),n.paused=e.paused,Object.defineProperty(e,"paused",{get:i(()=>n.paused,"get"),set:i(r=>n.paused=r,"set")}),e}},ae=class{static{i(this,"KEvent")}handlers=new Jt;add(e){let n=this.handlers.pushd((...o)=>{r.paused||e(...o)}),r=new ke(n);return r}addOnce(e){let n=this.add((...r)=>{n.cancel(),e(...r)});return n}next(){return new Promise(e=>this.addOnce(e))}trigger(...e){this.handlers.forEach(n=>n(...e))}numListeners(){return this.handlers.size}clear(){this.handlers.clear()}},ze=class{static{i(this,"KEventHandler")}handlers={};registers={};on(e,n){return this.handlers[e]||(this.handlers[e]=new ae),this.handlers[e].add(n)}onOnce(e,n){let r=this.on(e,(...o)=>{r.cancel(),n(...o)});return r}next(e){return new Promise(n=>{this.onOnce(e,(...r)=>n(r[0]))})}trigger(e,...n){this.handlers[e]&&this.handlers[e].trigger(...n)}remove(e){delete this.handlers[e]}clear(){this.handlers={}}numListeners(e){return this.handlers[e]?.numListeners()??0}};var Xo=i(t=>t instanceof Error?t.message:String(t),"getErrorMessage");function Zt(t,e){return Number(t.toFixed(e))}i(Zt,"toFixed");function me(t,e){return(...n)=>{let r=n.length;if(r===t.length)return t(...n);if(r===e.length)return e(...n)}}i(me,"overload2");var au=Object.freeze([776,2359,2367,2984,3007,3021,3633,3635,3648,3657,4352,4449,4520]);function Jo(t){if(typeof t!="string")throw new TypeError("string cannot be undefined or null");let e=[],n=0,r=0;for(;n=e&&t<=n}i(gt,"betweenInclusive");var De=i((t,e)=>Array.isArray(t)?t?.includes(e):t===e,"isEqOrIncludes"),Ye=i((t,e)=>Array.isArray(e)?e.some(n=>t.has(n)):t.has(e),"setHasOrIncludes"),en=i((t,e,n)=>{t.has(e)?t.get(e)?.push(n):t.set(e,[n])},"mapAddOrPush");var Zo=(()=>{let t=0;return()=>t++})();var ei={"Joy-Con L+R (STANDARD GAMEPAD Vendor: 057e Product: 200e)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","6":"ltrigger","7":"rtrigger","8":"select","9":"start","10":"lstick","11":"rstick","12":"dpad-up","13":"dpad-down","14":"dpad-left","15":"dpad-right","16":"home","17":"capture"},sticks:{left:{x:0,y:1},right:{x:2,y:3}}},"Joy-Con (L) (STANDARD GAMEPAD Vendor: 057e Product: 2006)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","9":"select","10":"lstick","16":"start"},sticks:{left:{x:0,y:1}}},"Joy-Con (R) (STANDARD GAMEPAD Vendor: 057e Product: 2007)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","9":"start","10":"lstick","16":"select"},sticks:{left:{x:0,y:1}}},"Pro Controller (STANDARD GAMEPAD Vendor: 057e Product: 2009)":{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","6":"ltrigger","7":"rtrigger","8":"select","9":"start","10":"lstick","11":"rstick","12":"dpad-up","13":"dpad-down","14":"dpad-left","15":"dpad-right","16":"home","17":"capture"},sticks:{left:{x:0,y:1},right:{x:2,y:3}}},default:{buttons:{"0":"south","1":"east","2":"west","3":"north","4":"lshoulder","5":"rshoulder","6":"ltrigger","7":"rtrigger","8":"select","9":"start","10":"lstick","11":"rstick","12":"dpad-up","13":"dpad-down","14":"dpad-left","15":"dpad-right","16":"home"},sticks:{left:{x:0,y:1},right:{x:2,y:3}}}};var ti=i(()=>lt.lastInputDevice,"getLastInputDeviceType"),ni=i(()=>{let t=lt.buttons;for(let e in t){let n=t[e].keyboard&&[t[e].keyboard].flat(),r=t[e].keyboardCode&&[t[e].keyboardCode].flat(),o=t[e].gamepad&&[t[e].gamepad].flat(),s=t[e].mouse&&[t[e].mouse].flat();n&&n.forEach(a=>{en(lt.buttonsByKey,a,e)}),r&&r.forEach(a=>{en(lt.buttonsByKeyCode,a,e)}),o&&o.forEach(a=>{en(lt.buttonsByGamepad,a,e)}),s&&s.forEach(a=>{en(lt.buttonsByMouse,a,e)})}},"parseButtonBindings");var bt=class{static{i(this,"ButtonState")}pressed=new Set([]);pressedRepeat=new Set([]);released=new Set([]);down=new Set([]);update(){this.pressed.clear(),this.released.clear(),this.pressedRepeat.clear()}press(e){this.pressed.add(e),this.pressedRepeat.add(e),this.down.add(e)}pressRepeat(e){this.pressedRepeat.add(e)}release(e){this.down.delete(e),this.pressed.delete(e),this.released.add(e)}},Rr=class{static{i(this,"GamepadState")}buttonState=new bt;stickState=new Map},Mr=class{static{i(this,"FPSCounter")}dts=[];timer=0;fps=0;tick(e){this.dts.push(e),this.timer+=e,this.timer>=1&&(this.timer=0,this.fps=Math.round(1/(this.dts.reduce((n,r)=>n+r)/this.dts.length)),this.dts=[])}},lt,ri=ei,yu=i(t=>{let e=t.buttons??{};return{canvas:t.canvas,buttons:e,buttonsByKey:new Map,buttonsByMouse:new Map,buttonsByGamepad:new Map,buttonsByKeyCode:new Map,loopID:null,stopped:!1,dt:0,fixedDt:1/50,restDt:0,time:0,realTime:0,fpsCounter:new Mr,timeScale:1,skipTime:!1,isHidden:!1,numFrames:0,mousePos:new C(0),mouseDeltaPos:new C(0),keyState:new bt,mouseState:new bt,mergedGamepadState:new Rr,gamepadStates:new Map,lastInputDevice:null,buttonState:new bt,gamepads:[],charInputted:[],isMouseMoved:!1,lastWidth:t.canvas.offsetWidth,lastHeight:t.canvas.offsetHeight,events:new ze}},"initAppState"),oi=i(t=>{if(!t.canvas)throw new Error("Please provide a canvas");let e=yu(t);lt=e,ni();function n(){return e.dt*e.timeScale}i(n,"dt");function r(){return e.fixedDt*e.timeScale}i(r,"fixedDt");function o(){return e.restDt*e.timeScale}i(o,"restDt");function s(){return e.isHidden}i(s,"isHidden");function a(){return e.time}i(a,"time");function m(){return e.fpsCounter.fps}i(m,"fps");function u(){return e.numFrames}i(u,"numFrames");function p(){return e.canvas.toDataURL()}i(p,"screenshot");function c(g){e.canvas.style.cursor=g}i(c,"setCursor");function f(){return e.canvas.style.cursor}i(f,"getCursor");function d(g){if(g)try{let T=e.canvas.requestPointerLock();T.catch&&T.catch(S=>console.error(S))}catch(T){console.error(T)}else document.exitPointerLock()}i(d,"setCursorLocked");function v(){return!!document.pointerLockElement}i(v,"isCursorLocked");function h(g){g.requestFullscreen?g.requestFullscreen():g.webkitRequestFullscreen&&g.webkitRequestFullscreen()}i(h,"enterFullscreen");function O(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullScreen&&document.webkitExitFullScreen()}i(O,"exitFullscreen");function y(g=!0){g?h(e.canvas):O()}i(y,"setFullscreen");function w(){return document.fullscreenElement===e.canvas||document.webkitFullscreenElement===e.canvas}i(w,"isFullscreen");function V(){e.stopped=!0;let g=Object.entries(Ge),T=Object.entries(hr),S=Object.entries(On);for(let[B,ne]of g)e.canvas.removeEventListener(B,ne);for(let[B,ne]of T)document.removeEventListener(B,ne);for(let[B,ne]of S)window.removeEventListener(B,ne);co.disconnect()}i(V,"quit");function R(g,T){e.loopID!==null&&cancelAnimationFrame(e.loopID);let S=0,B=0,ne=i(Ae=>{if(e.stopped)return;if(document.visibilityState!=="visible"){e.loopID=requestAnimationFrame(ne);return}let oe=Ae/1e3,Ze=Math.min(oe-e.realTime,.25),Rt=t.maxFPS?1/t.maxFPS:0;if(e.realTime=oe,B+=Ze,B>Rt){if(!e.skipTime){for(S+=B,e.dt=e.fixedDt,e.restDt=0;S>e.fixedDt;)S-=e.fixedDt,S0}i(P,"isTouchscreen");function D(){return e.mousePos.clone()}i(D,"mousePos");function b(){return e.mouseDeltaPos.clone()}i(b,"mouseDeltaPos");function E(g="left"){return e.mouseState.pressed.has(g)}i(E,"isMousePressed");function A(g="left"){return e.mouseState.down.has(g)}i(A,"isMouseDown");function G(g="left"){return e.mouseState.released.has(g)}i(G,"isMouseReleased");function M(){return e.isMouseMoved}i(M,"isMouseMoved");function F(g){return g===void 0?e.keyState.pressed.size>0:Ye(e.keyState.pressed,g)}i(F,"isKeyPressed");function K(g){return g===void 0?e.keyState.pressedRepeat.size>0:Ye(e.keyState.pressedRepeat,g)}i(K,"isKeyPressedRepeat");function H(g){return g===void 0?e.keyState.down.size>0:Ye(e.keyState.down,g)}i(H,"isKeyDown");function q(g){return g===void 0?e.keyState.released.size>0:Ye(e.keyState.released,g)}i(q,"isKeyReleased");function Y(g){return g===void 0?e.mergedGamepadState.buttonState.pressed.size>0:Ye(e.mergedGamepadState.buttonState.pressed,g)}i(Y,"isGamepadButtonPressed");function N(g){return g===void 0?e.mergedGamepadState.buttonState.down.size>0:Ye(e.mergedGamepadState.buttonState.down,g)}i(N,"isGamepadButtonDown");function j(g){return g===void 0?e.mergedGamepadState.buttonState.released.size>0:Ye(e.mergedGamepadState.buttonState.released,g)}i(j,"isGamepadButtonReleased");function Z(g){return g===void 0?e.buttonState.pressed.size>0:Ye(e.buttonState.pressed,g)}i(Z,"isButtonPressed");function $(g){return g===void 0?e.buttonState.down.size>0:Ye(e.buttonState.down,g)}i($,"isButtonDown");function ee(g){return g===void 0?e.buttonState.released.size>0:Ye(e.buttonState.released,g)}i(ee,"isButtonReleased");function Ee(g){return e.buttons?.[g]}i(Ee,"getButton");function k(g,T){e.buttons[g]={...e.buttons[g],...T}}i(k,"setButton");function ft(g){e.buttonState.press(g),e.events.trigger("buttonPress",g)}i(ft,"pressButton");function Pt(g){e.buttonState.release(g),e.events.trigger("buttonRelease",g)}i(Pt,"releaseButton");function Ut(g){return e.events.on("resize",g)}i(Ut,"onResize");let yn=me(g=>e.events.on("keyDown",g),(g,T)=>e.events.on("keyDown",S=>De(g,S)&&T(S))),xn=me(g=>e.events.on("keyPress",T=>g(T)),(g,T)=>e.events.on("keyPress",S=>De(g,S)&&T(S))),cr=me(g=>e.events.on("keyPressRepeat",g),(g,T)=>e.events.on("keyPressRepeat",S=>De(g,S)&&T(S))),lr=me(g=>e.events.on("keyRelease",g),(g,T)=>e.events.on("keyRelease",S=>De(g,S)&&T(S))),Gt=me(g=>e.events.on("mouseDown",T=>g(T)),(g,T)=>e.events.on("mouseDown",S=>De(g,S)&&T(S))),$e=me(g=>e.events.on("mousePress",T=>g(T)),(g,T)=>e.events.on("mousePress",S=>De(g,S)&&T(S))),vn=me(g=>e.events.on("mouseRelease",T=>g(T)),(g,T)=>e.events.on("mouseRelease",S=>S===g&&T(S)));function L(g){return e.events.on("mouseMove",()=>g(D(),b()))}i(L,"onMouseMove");function U(g){return e.events.on("charInput",g)}i(U,"onCharInput");function X(g){return e.events.on("touchStart",g)}i(X,"onTouchStart");function re(g){return e.events.on("touchMove",g)}i(re,"onTouchMove");function xe(g){return e.events.on("touchEnd",g)}i(xe,"onTouchEnd");function J(g){return e.events.on("scroll",g)}i(J,"onScroll");function we(g){return e.events.on("hide",g)}i(we,"onHide");function Ht(g){return e.events.on("show",g)}i(Ht,"onShow");let at=me(g=>e.events.on("gamepadButtonPress",(T,S)=>g(T,S)),(g,T)=>e.events.on("gamepadButtonPress",(S,B)=>De(g,S)&&T(S,B))),mr=me(g=>e.events.on("gamepadButtonDown",(T,S)=>g(T,S)),(g,T)=>e.events.on("gamepadButtonDown",(S,B)=>De(g,S)&&T(S,B))),pr=me(g=>e.events.on("gamepadButtonRelease",(T,S)=>g(T,S)),(g,T)=>e.events.on("gamepadButtonRelease",(S,B)=>De(g,S)&&T(S,B)));function dr(g,T){return e.events.on("gamepadStick",(S,B,ne)=>S===g&&T(B,ne))}i(dr,"onGamepadStick");function fr(g){e.events.on("gamepadConnect",g)}i(fr,"onGamepadConnect");function wn(g){e.events.on("gamepadDisconnect",g)}i(wn,"onGamepadDisconnect");function Xe(g){return e.mergedGamepadState.stickState.get(g)||new C(0)}i(Xe,"getGamepadStick");function ut(){return[...e.charInputted]}i(ut,"charInputted");function qt(){return[...e.gamepads]}i(qt,"getGamepads");let Ie=me(g=>e.events.on("buttonPress",T=>g(T)),(g,T)=>e.events.on("buttonPress",S=>De(g,S)&&T(S))),zt=me(g=>e.events.on("buttonDown",T=>g(T)),(g,T)=>e.events.on("buttonDown",S=>De(g,S)&&T(S))),Je=me(g=>e.events.on("buttonRelease",T=>g(T)),(g,T)=>e.events.on("buttonRelease",S=>De(g,S)&&T(S)));function Cn(){e.events.trigger("input"),e.keyState.down.forEach(g=>e.events.trigger("keyDown",g)),e.mouseState.down.forEach(g=>e.events.trigger("mouseDown",g)),e.buttonState.down.forEach(g=>{e.events.trigger("buttonDown",g)}),Ga()}i(Cn,"processInput");function Va(){e.keyState.update(),e.mouseState.update(),e.buttonState.update(),e.mergedGamepadState.buttonState.update(),e.mergedGamepadState.stickState.forEach((g,T)=>{e.mergedGamepadState.stickState.set(T,new C(0))}),e.charInputted=[],e.isMouseMoved=!1,e.mouseDeltaPos=new C(0),e.gamepadStates.forEach(g=>{g.buttonState.update(),g.stickState.forEach((T,S)=>{g.stickState.set(S,new C(0))})})}i(Va,"resetInput");function io(g){let T={index:g.index,isPressed:i(S=>e.gamepadStates.get(g.index)?.buttonState.pressed.has(S)||!1,"isPressed"),isDown:i(S=>e.gamepadStates.get(g.index)?.buttonState.down.has(S)||!1,"isDown"),isReleased:i(S=>e.gamepadStates.get(g.index)?.buttonState.released.has(S)||!1,"isReleased"),getStick:i(S=>e.gamepadStates.get(g.index)?.stickState.get(S)||x(),"getStick")};return e.gamepads.push(T),e.gamepadStates.set(g.index,{buttonState:new bt,stickState:new Map([["left",new C(0)],["right",new C(0)]])}),T}i(io,"registerGamepad");function Pa(g){e.gamepads=e.gamepads.filter(T=>T.index!==g.index),e.gamepadStates.delete(g.index)}i(Pa,"removeGamepad");function Ga(){for(let g of navigator.getGamepads())g&&!e.gamepadStates.has(g.index)&&io(g);for(let g of e.gamepads){let T=navigator.getGamepads()[g.index];if(!T)continue;let B=(t.gamepads??{})[T.id]||ri[T.id]||ri.default,ne=e.gamepadStates.get(g.index);if(ne){for(let Ae=0;Ae{e.buttonState.press(Re),e.events.trigger("buttonPress",Re)}),e.mergedGamepadState.buttonState.press(oe),ne.buttonState.press(oe),e.events.trigger("gamepadButtonPress",oe,g)}else ne.buttonState.down.has(oe)&&(Rt&&e.buttonsByGamepad.get(oe)?.forEach(Re=>{e.buttonState.release(Re),e.events.trigger("buttonRelease",Re)}),e.mergedGamepadState.buttonState.release(oe),ne.buttonState.release(oe),e.events.trigger("gamepadButtonRelease",oe,g))}for(let Ae in B.sticks){let oe=B.sticks[Ae];if(!oe)continue;let Ze=new C(T.axes[oe.x],T.axes[oe.y]);ne.stickState.set(Ae,Ze),e.mergedGamepadState.stickState.set(Ae,Ze),e.events.trigger("gamepadStick",Ae,Ze,g)}}}}i(Ga,"processGamepad");let Ge={},hr={},On={},so=t.pixelDensity||1;Ge.mousemove=g=>{let T=new C(g.offsetX,g.offsetY),S=new C(g.movementX,g.movementY);if(w()){let B=e.canvas.width/so,ne=e.canvas.height/so,Ae=window.innerWidth,oe=window.innerHeight,Ze=Ae/oe,Rt=B/ne;if(Ze>Rt){let Re=oe/ne,gr=(Ae-B*Re)/2;T.x=Se(g.offsetX-gr,0,B*Re,0,B),T.y=Se(g.offsetY,0,ne*Re,0,ne)}else{let Re=Ae/B,gr=(oe-ne*Re)/2;T.x=Se(g.offsetX,0,B*Re,0,B),T.y=Se(g.offsetY-gr,0,ne*Re,0,ne)}}e.events.onOnce("input",()=>{e.isMouseMoved=!0,e.mousePos=T,e.mouseDeltaPos=S,e.events.trigger("mouseMove")})};let ao=["left","middle","right","back","forward"];Ge.mousedown=g=>{e.events.onOnce("input",()=>{let T=ao[g.button];T&&(e.lastInputDevice="mouse",e.buttonsByMouse.has(T)&&e.buttonsByMouse.get(T)?.forEach(S=>{e.buttonState.press(S),e.events.trigger("buttonPress",S)}),e.mouseState.press(T),e.events.trigger("mousePress",T))})},Ge.mouseup=g=>{e.events.onOnce("input",()=>{let T=ao[g.button];T&&(e.buttonsByMouse.has(T)&&e.buttonsByMouse.get(T)?.forEach(S=>{e.buttonState.release(S),e.events.trigger("buttonRelease",S)}),e.mouseState.release(T),e.events.trigger("mouseRelease",T))})};let Ra=new Set([" ","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Tab"]),uo={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down"," ":"space"};Ge.keydown=g=>{Ra.has(g.key)&&g.preventDefault(),e.events.onOnce("input",()=>{let T=uo[g.key]||g.key.toLowerCase(),S=g.code;if(T===void 0)throw new Error(`Unknown key: ${g.key}`);T.length===1?(e.events.trigger("charInput",T),e.charInputted.push(T)):T==="space"&&(e.events.trigger("charInput"," "),e.charInputted.push(" ")),g.repeat?(e.keyState.pressRepeat(T),e.events.trigger("keyPressRepeat",T)):(e.lastInputDevice="keyboard",e.buttonsByKey.has(T)&&e.buttonsByKey.get(T)?.forEach(B=>{e.buttonState.press(B),e.events.trigger("buttonPress",B)}),e.buttonsByKeyCode.has(S)&&e.buttonsByKeyCode.get(S)?.forEach(B=>{e.buttonState.press(B),e.events.trigger("buttonPress",B)}),e.keyState.press(T),e.events.trigger("keyPressRepeat",T),e.events.trigger("keyPress",T))})},Ge.keyup=g=>{e.events.onOnce("input",()=>{let T=uo[g.key]||g.key.toLowerCase(),S=g.code;e.buttonsByKey.has(T)&&e.buttonsByKey.get(T)?.forEach(B=>{e.buttonState.release(B),e.events.trigger("buttonRelease",B)}),e.buttonsByKeyCode.has(S)&&e.buttonsByKeyCode.get(S)?.forEach(B=>{e.buttonState.release(B),e.events.trigger("buttonRelease",B)}),e.keyState.release(T),e.events.trigger("keyRelease",T)})},Ge.touchstart=g=>{g.preventDefault(),e.events.onOnce("input",()=>{let T=[...g.changedTouches],S=e.canvas.getBoundingClientRect();t.touchToMouse!==!1&&(e.mousePos=new C(T[0].clientX-S.x,T[0].clientY-S.y),e.lastInputDevice="mouse",e.buttonsByMouse.has("left")&&e.buttonsByMouse.get("left")?.forEach(B=>{e.buttonState.press(B),e.events.trigger("buttonPress",B)}),e.mouseState.press("left"),e.events.trigger("mousePress","left")),T.forEach(B=>{e.events.trigger("touchStart",new C(B.clientX-S.x,B.clientY-S.y),B)})})},Ge.touchmove=g=>{g.preventDefault(),e.events.onOnce("input",()=>{let T=[...g.changedTouches],S=e.canvas.getBoundingClientRect();if(t.touchToMouse!==!1){let B=e.mousePos;e.mousePos=new C(T[0].clientX-S.x,T[0].clientY-S.y),e.mouseDeltaPos=e.mousePos.sub(B),e.events.trigger("mouseMove")}T.forEach(B=>{e.events.trigger("touchMove",new C(B.clientX-S.x,B.clientY-S.y),B)})})},Ge.touchend=g=>{e.events.onOnce("input",()=>{let T=[...g.changedTouches],S=e.canvas.getBoundingClientRect();t.touchToMouse!==!1&&(e.mousePos=new C(T[0].clientX-S.x,T[0].clientY-S.y),e.mouseDeltaPos=new C(0,0),e.buttonsByMouse.has("left")&&e.buttonsByMouse.get("left")?.forEach(B=>{e.buttonState.release(B),e.events.trigger("buttonRelease",B)}),e.mouseState.release("left"),e.events.trigger("mouseRelease","left")),T.forEach(B=>{e.events.trigger("touchEnd",new C(B.clientX-S.x,B.clientY-S.y),B)})})},Ge.touchcancel=g=>{e.events.onOnce("input",()=>{let T=[...g.changedTouches],S=e.canvas.getBoundingClientRect();t.touchToMouse!==!1&&(e.mousePos=new C(T[0].clientX-S.x,T[0].clientY-S.y),e.mouseState.release("left"),e.events.trigger("mouseRelease","left")),T.forEach(B=>{e.events.trigger("touchEnd",new C(B.clientX-S.x,B.clientY-S.y),B)})})},Ge.wheel=g=>{g.preventDefault(),e.events.onOnce("input",()=>{e.events.trigger("scroll",new C(g.deltaX,g.deltaY))})},Ge.contextmenu=g=>g.preventDefault(),hr.visibilitychange=()=>{document.visibilityState==="visible"?(e.skipTime=!0,e.isHidden=!1,e.events.trigger("show")):(e.isHidden=!0,e.events.trigger("hide"))},On.gamepadconnected=g=>{let T=io(g.gamepad);e.events.onOnce("input",()=>{e.events.trigger("gamepadConnect",T)})},On.gamepaddisconnected=g=>{let T=qt().filter(S=>S.index===g.gamepad.index)[0];Pa(g.gamepad),e.events.onOnce("input",()=>{e.events.trigger("gamepadDisconnect",T)})};for(let[g,T]of Object.entries(Ge))e.canvas.addEventListener(g,T);for(let[g,T]of Object.entries(hr))document.addEventListener(g,T);for(let[g,T]of Object.entries(On))window.addEventListener(g,T);let co=new ResizeObserver(g=>{for(let T of g)if(T.target===e.canvas){if(e.lastWidth===e.canvas.offsetWidth&&e.lastHeight===e.canvas.offsetHeight)return;e.lastWidth=e.canvas.offsetWidth,e.lastHeight=e.canvas.offsetHeight,e.events.onOnce("input",()=>{e.events.trigger("resize")})}});return co.observe(e.canvas),{state:e,dt:n,fixedDt:r,restDt:o,time:a,run:R,canvas:e.canvas,fps:m,numFrames:u,quit:V,isHidden:s,setFullscreen:y,isFullscreen:w,setCursor:c,screenshot:p,getGamepads:qt,getCursor:f,setCursorLocked:d,isCursorLocked:v,isTouchscreen:P,mousePos:D,mouseDeltaPos:b,isKeyDown:H,isKeyPressed:F,isKeyPressedRepeat:K,isKeyReleased:q,isMouseDown:A,isMousePressed:E,isMouseReleased:G,isMouseMoved:M,isGamepadButtonPressed:Y,isGamepadButtonDown:N,isGamepadButtonReleased:j,getGamepadStick:Xe,isButtonPressed:Z,isButtonDown:$,isButtonReleased:ee,setButton:k,getButton:Ee,pressButton:ft,releaseButton:Pt,charInputted:ut,onResize:Ut,onKeyDown:yn,onKeyPress:xn,onKeyPressRepeat:cr,onKeyRelease:lr,onMouseDown:Gt,onMousePress:$e,onMouseRelease:vn,onMouseMove:L,onCharInput:U,onTouchStart:X,onTouchMove:re,onTouchEnd:xe,onScroll:J,onHide:we,onShow:Ht,onGamepadButtonDown:mr,onGamepadButtonPress:at,onGamepadButtonRelease:pr,onGamepadStick:dr,onGamepadConnect:fr,onGamepadDisconnect:wn,onButtonPress:Ie,onButtonDown:zt,onButtonRelease:Je,getLastInputDeviceType:ti,events:e.events}},"initApp");function te(){return l.app.dt()}i(te,"dt");function tn(){return l.app.fixedDt()}i(tn,"fixedDt");function nn(){return l.app.restDt()}i(nn,"restDt");var xu=new C(-1,-1),vu=new C(0,-1),wu=new C(1,-1),Cu=new C(-1,0),Ou=new C(0,0),Eu=new C(1,0),Tu=new C(-1,1),Au=new C(0,1),Su=new C(1,1);function _e(t){switch(t){case"topleft":return xu;case"top":return vu;case"topright":return wu;case"left":return Cu;case"center":return Ou;case"right":return Eu;case"botleft":return Tu;case"bot":return Au;case"botright":return Su;default:return t}}i(_e,"anchorPt");function ii(t){switch(t){case"left":return 0;case"center":return .5;case"right":return 1;default:return 0}}i(ii,"alignPt");function si(t){return t.createBuffer(1,1,44100)}i(si,"createEmptyAudioBuffer");var Ln=2.5949095,ai=1.70158+1,ui=2*Math.PI/3,ci=2*Math.PI/4.5,Kn={linear:i(t=>t,"linear"),easeInSine:i(t=>1-Math.cos(t*Math.PI/2),"easeInSine"),easeOutSine:i(t=>Math.sin(t*Math.PI/2),"easeOutSine"),easeInOutSine:i(t=>-(Math.cos(Math.PI*t)-1)/2,"easeInOutSine"),easeInQuad:i(t=>t*t,"easeInQuad"),easeOutQuad:i(t=>1-(1-t)*(1-t),"easeOutQuad"),easeInOutQuad:i(t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,"easeInOutQuad"),easeInCubic:i(t=>t*t*t,"easeInCubic"),easeOutCubic:i(t=>1-Math.pow(1-t,3),"easeOutCubic"),easeInOutCubic:i(t=>t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2,"easeInOutCubic"),easeInQuart:i(t=>t*t*t*t,"easeInQuart"),easeOutQuart:i(t=>1-Math.pow(1-t,4),"easeOutQuart"),easeInOutQuart:i(t=>t<.5?8*t*t*t*t:1-Math.pow(-2*t+2,4)/2,"easeInOutQuart"),easeInQuint:i(t=>t*t*t*t*t,"easeInQuint"),easeOutQuint:i(t=>1-Math.pow(1-t,5),"easeOutQuint"),easeInOutQuint:i(t=>t<.5?16*t*t*t*t*t:1-Math.pow(-2*t+2,5)/2,"easeInOutQuint"),easeInExpo:i(t=>t===0?0:Math.pow(2,10*t-10),"easeInExpo"),easeOutExpo:i(t=>t===1?1:1-Math.pow(2,-10*t),"easeOutExpo"),easeInOutExpo:i(t=>t===0?0:t===1?1:t<.5?Math.pow(2,20*t-10)/2:(2-Math.pow(2,-20*t+10))/2,"easeInOutExpo"),easeInCirc:i(t=>1-Math.sqrt(1-Math.pow(t,2)),"easeInCirc"),easeOutCirc:i(t=>Math.sqrt(1-Math.pow(t-1,2)),"easeOutCirc"),easeInOutCirc:i(t=>t<.5?(1-Math.sqrt(1-Math.pow(2*t,2)))/2:(Math.sqrt(1-Math.pow(-2*t+2,2))+1)/2,"easeInOutCirc"),easeInBack:i(t=>ai*t*t*t-1.70158*t*t,"easeInBack"),easeOutBack:i(t=>1+ai*Math.pow(t-1,3)+1.70158*Math.pow(t-1,2),"easeOutBack"),easeInOutBack:i(t=>t<.5?Math.pow(2*t,2)*((Ln+1)*2*t-Ln)/2:(Math.pow(2*t-2,2)*((Ln+1)*(t*2-2)+Ln)+2)/2,"easeInOutBack"),easeInElastic:i(t=>t===0?0:t===1?1:-Math.pow(2,10*t-10)*Math.sin((t*10-10.75)*ui),"easeInElastic"),easeOutElastic:i(t=>t===0?0:t===1?1:Math.pow(2,-10*t)*Math.sin((t*10-.75)*ui)+1,"easeOutElastic"),easeInOutElastic:i(t=>t===0?0:t===1?1:t<.5?-(Math.pow(2,20*t-10)*Math.sin((20*t-11.125)*ci))/2:Math.pow(2,-20*t+10)*Math.sin((20*t-11.125)*ci)/2+1,"easeInOutElastic"),easeInBounce:i(t=>1-Kn.easeOutBounce(1-t),"easeInBounce"),easeOutBounce:i(t=>t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375,"easeOutBounce"),easeInOutBounce:i(t=>t<.5?(1-Kn.easeOutBounce(1-2*t))/2:(1+Kn.easeOutBounce(2*t-1))/2,"easeInOutBounce")},tt=Kn;function Vu(t,e,n){let r=[],o=e;for(r.push(o);o!==t;){if(o=n.get(o),o==null)return null;r.push(o)}return r.reverse()}i(Vu,"buildPath");function Dr(t,e,n){let r=new Kt((a,m)=>a.coste.y!=r.a.y>e.y&&e.x<(r.a.x-r.b.x)*(e.y-r.b.y)/(r.a.y-r.b.y)+r.b.x&&(n=!n);return n}},In=class{static{i(this,"NavMesh")}_polygons;_pointCache;_edgeCache;constructor(){this._polygons=[],this._pointCache={},this._edgeCache={}}_addPoint(e){let n=this._pointCache[`${e.x}_${e.y}`];return n||(n=e.clone(),this._pointCache[`${e.x}_${e.y}`]=n,n)}_addEdge(e){let n=`${e.a.x}_${e.a.y}-${e.b.x}_${e.b.y}`;return this._edgeCache[n]=e,e}_findEdge(e,n){let r=`${e.x}_${e.y}-${n.x}_${n.y}`;return this._edgeCache[r]}_findCommonEdge(e,n){for(let r of e.edges){let o=this._findEdge(r.b,r.a);if(o&&o.polygon.deref().id===n.id)return o}return null}addPolygon(e){let n=new Fr(this._polygons.length),r=e.map((o,s)=>new Br(o,e[(s+1)%e.length],n));n.edges=r,this._polygons.push(n);for(let o of n.edges)this._addEdge(o);return n}addRect(e,n){let r=this._addPoint(e),o=this._addPoint(e.add(n.x,0)),s=this._addPoint(e.add(n)),a=this._addPoint(e.add(0,n.y));return this.addPolygon([r,o,s,a])}_getLocation(e){for(let n of this._polygons)if(n.contains(e))return n;return null}getNeighbours(e){let n=[];for(let r of this._polygons[e].edges){let o=this._findEdge(r.b,r.a);if(o){let s=o.polygon.deref();s&&n.push(s.id)}}return n}getCost(e,n){return 1}getHeuristic(e,n){let r=this._polygons[e],o=this._polygons[n],s=r.centroid.x-o.centroid.x,a=r.centroid.y-o.centroid.y;return Math.sqrt(s*s+a*a)}getPath(e,n){return e===void 0||n===void 0?[]:e===n?[e,n]:Dr(this,e,n)}getWaypointPath(e,n,r){let o=r?.type||"centroids",s=this._getLocation(e),a=this._getLocation(n);if(s===void 0||a===void 0)return[];let m=this.getPath(s.id,a.id);if(!m)return[];if(o==="edges"){let u=[];for(let p=1;pthis._polygons[u].centroid),n]}};function mt(t){let e=new he;return t.pos&&e.translate(t.pos),t.scale&&e.scale(t.scale),t.angle&&e.rotate(t.angle),t.parent?e.mult(t.parent.transform):e}i(mt,"calcTransform");function li(t){return new C(t.x/ie()*2-1,-t.y/ue()*2+1)}i(li,"screen2ndc");function yt(t,e,n,r,o,s=1){r=se(r%360),o=se(o%360),o<=r&&(o+=Math.PI*2);let a=[],m=Math.ceil((o-r)/se(8)*s),u=(o-r)/m,p=x(Math.cos(r),Math.sin(r)),c=x(Math.cos(u),Math.sin(u));for(let f=0;f<=m;f++)a.push(t.add(e*p.x,n*p.y)),p=x(p.x*c.x-p.y*c.y,p.x*c.y+p.y*c.x);return a}i(yt,"getArcPts");function mi(...t){let e=_(...t),n=t[3]??1;l.gfx.bgColor=e,l.gfx.bgAlpha=n,l.gfx.ggl.gl.clearColor(e.r/255,e.g/255,e.b/255,n)}i(mi,"setBackground");function pi(){return l.gfx.bgColor?.clone?.()??null}i(pi,"getBackground");function Q(...t){if(t[0]===void 0)return;let e=x(...t);e.x===0&&e.y===0||l.gfx.transform.translate(e)}i(Q,"pushTranslate");function be(){l.gfx.transformStack.push(l.gfx.transform.clone())}i(be,"pushTransform");function di(t){l.gfx.transform=t.clone()}i(di,"pushMatrix");function nt(...t){if(t[0]===void 0)return;let e=x(...t);e.x===1&&e.y===1||l.gfx.transform.scale(e)}i(nt,"pushScale");function We(t){t&&l.gfx.transform.rotate(t)}i(We,"pushRotate");function pe(){l.gfx.transformStack.length>0&&(l.gfx.transform=l.gfx.transformStack.pop())}i(pe,"popTransform");function Oe(){l.gfx.renderer.flush()}i(Oe,"flush");function ie(){return l.gfx.width}i(ie,"width");function ue(){return l.gfx.height}i(ue,"height");function jn(){return(l.gfx.viewport.width+l.gfx.viewport.height)/(l.gfx.width+l.gfx.height)}i(jn,"getViewportScale");function fi(t){return new C(t.x*l.gfx.viewport.width/l.gfx.width,t.y*l.gfx.viewport.height/l.gfx.height)}i(fi,"contentToView");function Pu(t){return new C((t.x-l.gfx.viewport.x)*ie()/l.gfx.viewport.width,(t.y-l.gfx.viewport.y)*ue()/l.gfx.viewport.height)}i(Pu,"windowToContent");function kn(){return Pu(l.app.mousePos())}i(kn,"mousePos");function xt(){return x(ie()/2,ue()/2)}i(xt,"center");var _n=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",pt="topleft";var hi="monospace",vt="monospace";var rn="linear";var on=[{name:"a_pos",size:2},{name:"a_uv",size:2},{name:"a_color",size:4}],Gu=on.reduce((t,e)=>t+e.size,0),gi=2048,bi=gi*4*Gu,yi=gi*6,xi=` attribute vec2 a_pos; attribute vec2 a_uv; attribute vec4 a_color; varying vec2 v_pos; varying vec2 v_uv; varying vec4 v_color; vec4 def_vert() { return vec4(a_pos, 0.0, 1.0); } {{user}} void main() { vec4 pos = vert(a_pos, a_uv, a_color); v_pos = a_pos; v_uv = a_uv; v_color = a_color; gl_Position = pos; } `,vi=` precision mediump float; varying vec2 v_pos; varying vec2 v_uv; varying vec4 v_color; uniform sampler2D u_tex; vec4 def_frag() { return v_color * texture2D(u_tex, v_uv); } {{user}} void main() { gl_FragColor = frag(v_pos, v_uv, v_color, u_tex); if (gl_FragColor.a == 0.0) { discard; } } `,sn=` vec4 vert(vec2 pos, vec2 uv, vec4 color) { return def_vert(); } `,an=` vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) { return def_frag(); } `,wi=new Set(["id","require"]),Ci=new Set(["add","fixedUpdate","update","draw","destroy","inspect","drawInspect"]),Oi=200,Ei=640,Ti=65536;var un=class{static{i(this,"TexPacker")}textures=[];bigTextures=[];canvas;c2d;x=0;y=0;curHeight=0;gfx;constructor(e,n,r){this.gfx=e,this.canvas=document.createElement("canvas"),this.canvas.width=n,this.canvas.height=r,this.textures=[Ve.fromImage(e,this.canvas)],this.bigTextures=[];let o=this.canvas.getContext("2d");if(!o)throw new Error("Failed to get 2d context");this.c2d=o}add(e){if(e.width>this.canvas.width||e.height>this.canvas.height){let o=Ve.fromImage(this.gfx,e);return this.bigTextures.push(o),[o,new z(0,0,1,1)]}this.x+e.width>this.canvas.width&&(this.x=0,this.y+=this.curHeight,this.curHeight=0),this.y+e.height>this.canvas.height&&(this.c2d.clearRect(0,0,this.canvas.width,this.canvas.height),this.textures.push(Ve.fromImage(this.gfx,this.canvas)),this.x=0,this.y=0,this.curHeight=0);let n=this.textures[this.textures.length-1],r=new C(this.x,this.y);return this.x+=e.width,e.height>this.curHeight&&(this.curHeight=e.height),e instanceof ImageData?this.c2d.putImageData(e,r.x,r.y):this.c2d.drawImage(e,r.x,r.y),n.update(this.canvas),[n,new z(r.x/this.canvas.width,r.y/this.canvas.height,e.width/this.canvas.width,e.height/this.canvas.height)]}free(){for(let e of this.textures)e.free();for(let e of this.bigTextures)e.free()}};function de(t){return typeof t!="string"||Bn(t)?t:l.assets.urlPrefix+t}i(de,"fixURL");var ce=class t{static{i(this,"Asset")}loaded=!1;data=null;error=null;onLoadEvents=new ae;onErrorEvents=new ae;onFinishEvents=new ae;constructor(e){e.then(n=>{this.loaded=!0,this.data=n,this.onLoadEvents.trigger(n)}).catch(n=>{if(this.error=n,this.onErrorEvents.numListeners()>0)this.onErrorEvents.trigger(n);else throw n}).finally(()=>{this.onFinishEvents.trigger(),this.loaded=!0})}static loaded(e){let n=new t(Promise.resolve(e));return n.data=e,n.loaded=!0,n}onLoad(e){return this.loaded&&this.data?e(this.data):this.onLoadEvents.add(e),this}onError(e){return this.loaded&&this.error?e(this.error):this.onErrorEvents.add(e),this}onFinish(e){return this.loaded?e():this.onFinishEvents.add(e),this}then(e){return this.onLoad(e)}catch(e){return this.onError(e)}finally(e){return this.onFinish(e)}},dt=class{static{i(this,"AssetBucket")}assets=new Map;lastUID=0;add(e,n){let r=e??this.lastUID+++"",o=new ce(n);return this.assets.set(r,o),o}addLoaded(e,n){let r=e??this.lastUID+++"",o=ce.loaded(n);return this.assets.set(r,o),o}get(e){return this.assets.get(e)}progress(){if(this.assets.size===0)return 1;let e=0;return this.assets.forEach(n=>{n.loaded&&e++}),e/this.assets.size}};function Ir(t){return fetch(t).then(e=>{if(!e.ok)throw new Error(`Failed to fetch "${t}"`);return e})}i(Ir,"fetchURL");function wt(t){return Ir(t).then(e=>e.json())}i(wt,"fetchJSON");function Ai(t){return Ir(t).then(e=>e.text())}i(Ai,"fetchText");function Si(t){return Ir(t).then(e=>e.arrayBuffer())}i(Si,"fetchArrayBuffer");function Vi(t){return t!==void 0&&(l.assets.urlPrefix=t),l.assets.urlPrefix}i(Vi,"loadRoot");function Pi(t,e){return l.assets.custom.add(t,wt(de(e)))}i(Pi,"loadJSON");function Ct(t){let e=new Image;return e.crossOrigin="anonymous",e.src=t,new Promise((n,r)=>{e.onload=()=>n(e),e.onerror=()=>r(new Error(`Failed to load image from "${t}"`))})}i(Ct,"loadImg");function Be(){let t=[l.assets.sprites,l.assets.sounds,l.assets.shaders,l.assets.fonts,l.assets.bitmapFonts,l.assets.custom];return t.reduce((e,n)=>e+n.progress(),0)/t.length}i(Be,"loadProgress");function Gi(t){return l.assets.custom.get(t)??null}i(Gi,"getAsset");function cn(t){return l.assets.custom.add(null,t)}i(cn,"load");var Ri=i(t=>({urlPrefix:"",sprites:new dt,fonts:new dt,bitmapFonts:new dt,sounds:new dt,shaders:new dt,custom:new dt,music:{},packer:new un(t,2048,2048),loaded:!1}),"initAssets");var Mi="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD0AAAA1CAYAAADyMeOEAAAAAXNSR0IArs4c6QAAAoVJREFUaIHdm7txwkAQhheGAqACiCHzOKQDQrqgILpwSAeEDBnEUAF0gCMxZ7G72qce/mec2Lpf9+3unaS78wgSNZ8uX5729+d1FNWXUuGmXlBOUUEIMckEpeQJgBu6C+BSFngztBR2vd+ovY+7g+p6LbgaWgJrAeUkDYIUXgXdBBwNi6kpABJwMTQH3AZsXRR8GHTfgEth8E3gjdAUcNewpbTgY85sCMCUuOokozE0YM0YRzM9NGAAXd8+omAF5h4lnmBRvpSnZHyLoLEbaN+aKB9KWv/KWw0tAbbANnlG+UvB2dm77NxxdwgBpjrF/d7rW9cbmpvio2A5z8iAYpVU8pGZlo6/2+MSco2lHfd3rv9jAP038e1xef9o2mjvYb2OqpqKE81028/jeietlSEVO5FRWsxWsJit1G3aFpW8iWe5RwpiCZAk25QvV6nz6fIlynRGuTd5WqpJ4guAlDfVKBK87hXljflgv1ON6fV+4+5gVlA17SfeG0heKqQd4l4jI/wrmaA9N9R4ar+wpHJDZyrrfcH0nB66PqAzPi76pn+faSyJk/vzOorYhGurQrzj/P68jtBMawHaHBIR9xoD5O34dy0qQOSYHvqExq2TpT2nf76+w7y251OYF0CRaU+J920TwLUa6inx6OxE6g80lu2ux7Y2eJLF/rCXE6zEPdnenk9o+4ih9AEdnW2q81HXl5LuU6OTl2fXUhqganbXAGq3g6jJOWV/OnoesO6YqqEB/GdNsjf7uHtwj2DzmRNpp7iOZfm6D9oAxB6Yi1gC4oIYeo4MIPdopEQRB+cAko5J1tW386HpB2Kz1eop4Epdwls/kgZ1sh8gZsEjdcWkr//D8Qu3Z3l5Nl1NtAAAAABJRU5ErkJggg==";var Fe=class t{static{i(this,"SpriteData")}tex;frames=[new z(0,0,1,1)];anims={};slice9=null;constructor(e,n,r={},o=null){this.tex=e,n&&(this.frames=n),this.anims=r,this.slice9=o}get width(){return this.tex.width*this.frames[0].w}get height(){return this.tex.height*this.frames[0].h}static from(e,n={}){return typeof e=="string"?t.fromURL(e,n):Promise.resolve(t.fromImage(e,n))}static fromImage(e,n={}){let[r,o]=l.assets.packer.add(e),s=n.frames?n.frames.map(a=>new z(o.x+a.x*o.w,o.y+a.y*o.h,a.w*o.w,a.h*o.h)):kr(n.sliceX||1,n.sliceY||1,o.x,o.y,o.w,o.h);return new t(r,s,n.anims,n.slice9)}static fromURL(e,n={}){return Ct(e).then(r=>t.fromImage(r,n))}};function It(t){if(typeof t=="string"){let e=jr(t);if(e)return e;if(Be()<1)return null;throw new Error(`Sprite not found: ${t}`)}else{if(t instanceof Fe)return ce.loaded(t);if(t instanceof ce)return t;throw new Error(`Invalid sprite: ${t}`)}}i(It,"resolveSprite");function jr(t){return l.assets.sprites.get(t)??null}i(jr,"getSprite");function Ot(t,e,n={sliceX:1,sliceY:1,anims:{}}){return e=de(e),Array.isArray(e)?e.some(r=>typeof r=="string")?l.assets.sprites.add(t,Promise.all(e.map(r=>typeof r=="string"?Ct(r):Promise.resolve(r))).then(r=>Di(r,n))):l.assets.sprites.addLoaded(t,Di(e,n)):typeof e=="string"?l.assets.sprites.add(t,Fe.from(e,n)):l.assets.sprites.addLoaded(t,Fe.fromImage(e,n))}i(Ot,"loadSprite");function kr(t=1,e=1,n=0,r=0,o=1,s=1){let a=[],m=o/t,u=s/e;for(let p=0;p{m instanceof ImageData?s.putImageData(m,u*r,0):s.drawImage(m,u*r,0)});let a=s.getImageData(0,0,t.length*r,o);return Fe.fromImage(a,{...e,sliceX:t.length,sliceY:1})}i(Di,"createSpriteSheet");function Bi(t="bean"){return Ot(t,Mi)}i(Bi,"loadBean");function Fi(t,e,n){e=de(e),n=de(n),typeof e=="string"&&!n&&(n=$o(e)+".json");let r=typeof n=="string"?wt(n):Promise.resolve(n);return l.assets.sprites.add(t,r.then(o=>{let s=o.meta.size,a=o.frames.map(u=>new z(u.frame.x/s.w,u.frame.y/s.h,u.frame.w/s.w,u.frame.h/s.h)),m={};for(let u of o.meta.frameTags)u.from===u.to?m[u.name]=u.from:m[u.name]={from:u.from,to:u.to,speed:10,loop:!0,pingpong:u.direction==="pingpong"};return Fe.from(e,{frames:a,anims:m})}))}i(Fi,"loadAseprite");var Et=class{static{i(this,"FontData")}fontface;filter=rn;outline=null;size=64;constructor(e,n={}){if(this.fontface=e,this.filter=n.filter??rn,this.size=n.size??64,this.size>256)throw new Error(`Max font size: ${256}`);n.outline&&(this.outline={width:1,color:_(0,0,0)},typeof n.outline=="number"?this.outline.width=n.outline:typeof n.outline=="object"&&(n.outline.width&&(this.outline.width=n.outline.width),n.outline.color&&(this.outline.color=n.outline.color)))}};function _r(t){if(!t)return _r(l.globalOpt.font??hi);if(typeof t=="string"){let e=Nn(t),n=Nr(t);if(e)return e.data??e;if(n)return n.data??n;if(document.fonts.check(`${64}px ${t}`))return t;if(Be()<1)return null;throw new Error(`Font not found: ${t}`)}else if(t instanceof ce)return t.data?t.data:t;return t}i(_r,"resolveFont");function Nr(t){return l.assets.fonts.get(t)??null}i(Nr,"getFont");function Li(t,e,n={}){let r=de(e),o=new FontFace(t,typeof e=="string"?`url(${r})`:r);return document.fonts.add(o),l.assets.fonts.add(t,o.load().catch(s=>{throw new Error(`Failed to load font from "${r}": ${s}`)}).then(s=>new Et(s,n)))}i(Li,"loadFont");function Ki(t,e,n,r){let o=t.width/e,s={},a=r.split("").entries();for(let[m,u]of a)s[u]=new z(m%o*e,Math.floor(m/o)*n,e,n);return{tex:t,map:s,size:n}}i(Ki,"makeFont");function Nn(t){return l.assets.bitmapFonts.get(t)??null}i(Nn,"getBitmapFont");function Ii(t,e,n,r,o={}){let s=de(e);return l.assets.bitmapFonts.add(t,Ct(s).then(a=>Ki(Ve.fromImage(l.gfx.ggl,a,o),n,r,o.chars??_n)))}i(Ii,"loadBitmapFont");function ji(t,e){return e=de(e),l.assets.sprites.add(t,new Promise(async n=>{let r=typeof e=="string"?await wt(e):e,o=await Promise.all(r.frames.map(Ct)),s=document.createElement("canvas");s.width=r.width,s.height=r.height*r.frames.length;let a=s.getContext("2d");if(!a)throw new Error("Failed to create canvas context");o.forEach((u,p)=>{a.drawImage(u,0,p*r.height)});let m=await Ot(null,s,{sliceY:r.frames.length,anims:r.anims});n(m)}))}i(ji,"loadPedit");var Ur=class{static{i(this,"Shader")}ctx;glProgram;constructor(e,n,r,o){this.ctx=e,e.onDestroy(()=>this.free());let s=e.gl,a=s.createShader(s.VERTEX_SHADER),m=s.createShader(s.FRAGMENT_SHADER);if(!a||!m)throw new Error("Failed to create shader");s.shaderSource(a,n),s.shaderSource(m,r),s.compileShader(a),s.compileShader(m);let u=s.createProgram();if(this.glProgram=u,s.attachShader(u,a),s.attachShader(u,m),o.forEach((p,c)=>s.bindAttribLocation(u,c,p)),s.linkProgram(u),!s.getProgramParameter(u,s.LINK_STATUS)){let p=s.getShaderInfoLog(a);if(p)throw new Error("VERTEX SHADER "+p);let c=s.getShaderInfoLog(m);if(c)throw new Error("FRAGMENT SHADER "+c)}s.deleteShader(a),s.deleteShader(m)}bind(){this.ctx.pushProgram(this.glProgram)}unbind(){this.ctx.popProgram()}send(e){let n=this.ctx.gl;for(let r in e){let o=e[r],s=n.getUniformLocation(this.glProgram,r);if(typeof o=="number")n.uniform1f(s,o);else if(o instanceof he)n.uniformMatrix4fv(s,!1,new Float32Array(o.m));else if(o instanceof I)n.uniform3f(s,o.r,o.g,o.b);else if(o instanceof C)n.uniform2f(s,o.x,o.y);else if(Array.isArray(o)){let a=o[0];zo(o)?n.uniform1fv(s,o):qo(o)?n.uniform2fv(s,o.map(m=>[m.x,m.y]).flat()):Ho(o)&&n.uniform3fv(s,o.map(m=>[m.r,m.g,m.b]).flat())}else throw new Error("Unsupported uniform data type")}}free(){this.ctx.gl.deleteProgram(this.glProgram)}};function Un(t,e=sn,n=an){let r=xi.replace("{{user}}",e??sn),o=vi.replace("{{user}}",n??an);try{return new Ur(t,r,o,on.map(s=>s.name))}catch(s){let m=/(?^\w+) SHADER ERROR: 0:(?\d+): (?.+)/,u=Xo(s).match(m);if(!u?.groups)throw s;let p=Number(u.groups.line)-14,c=u.groups.msg.trim(),f=u.groups.type.toLowerCase();throw new Error(`${f} shader line ${p}: ${c}`)}}i(Un,"makeShader");function ki(t){if(!t)return l.gfx.defShader;if(typeof t=="string"){let e=Hr(t);if(e)return e.data??e;if(Be()<1)return null;throw new Error(`Shader not found: ${t}`)}else if(t instanceof ce)return t.data?t.data:t;return t}i(ki,"resolveShader");function Hr(t){return l.assets.shaders.get(t)??null}i(Hr,"getShader");function _i(t,e,n){return l.assets.shaders.addLoaded(t,Un(l.gfx.ggl,e,n))}i(_i,"loadShader");function Ni(t,e,n){e=de(e),n=de(n);let r=i(s=>s?Ai(s):Promise.resolve(null),"resolveUrl"),o=Promise.all([r(e),r(n)]).then(([s,a])=>Un(l.gfx.ggl,s,a));return l.assets.shaders.add(t,o)}i(Ni,"loadShaderURL");var rt=class t{static{i(this,"SoundData")}buf;constructor(e){this.buf=e}static fromArrayBuffer(e){return new Promise((n,r)=>l.audio.ctx.decodeAudioData(e,n,r)).then(n=>new t(n))}static fromURL(e){return Bn(e)?t.fromArrayBuffer(Yo(e)):Si(e).then(n=>t.fromArrayBuffer(n))}};function Ui(t){if(typeof t=="string"){let e=qr(t);if(e)return e;if(Be()<1)return null;throw new Error(`Sound not found: ${t}`)}else{if(t instanceof rt)return ce.loaded(t);if(t instanceof ce)return t;throw new Error(`Invalid sound: ${t}`)}}i(Ui,"resolveSound");function qr(t){return l.assets.sounds.get(t)??null}i(qr,"getSound");function Hi(t,e){return e=de(e),l.assets.sounds.add(t,typeof e=="string"?rt.fromURL(e):rt.fromArrayBuffer(e))}i(Hi,"loadSound");function qi(t,e){let n=de(e),r=new Audio(n);return r.preload="auto",l.assets.music[t]=n}i(qi,"loadMusic");function zr(t,e){return t=de(t),typeof e=="string"?cn(new Promise((n,r)=>{wt(e).then(o=>{zr(t,o).then(n).catch(r)})})):cn(Fe.from(t).then(n=>{let r={};for(let o in e){let s=e[o],a=n.frames[0],m=2048*a.w,u=2048*a.h,p=s.frames?s.frames.map(f=>new z(a.x+(s.x+f.x)/m*a.w,a.y+(s.y+f.y)/u*a.h,f.w/m*a.w,f.h/u*a.h)):kr(s.sliceX||1,s.sliceY||1,a.x+s.x/m*a.w,a.y+s.y/u*a.h,s.width/m*a.w,s.height/u*a.h),c=new Fe(n.tex,p,s.anims);l.assets.sprites.addLoaded(o,c),r[o]=c}return r}))}i(zr,"loadSpriteAtlas");function Le(t,e,n=!1,r,o,s={}){let a=r??l.gfx.defTex,m=o??l.gfx.defShader,u=ki(m);if(!u||u instanceof ce)return;let p=l.gfx.fixed||n?l.gfx.transform:l.game.cam.transform.mult(l.gfx.transform),c=[];for(let f of t){let d=li(p.multVec2(f.pos));c.push(d.x,d.y,f.uv.x,f.uv.y,f.color.r/255,f.color.g/255,f.color.b/255,f.opacity)}l.gfx.renderer.push(l.gfx.ggl.gl.TRIANGLES,c,e,u,a,s)}i(Le,"drawRaw");function Pe(t){if(!t.pts)throw new Error('drawPolygon() requires property "pts".');let e=t.pts.length;if(!(e<3)){if(be(),Q(t.pos),nt(t.scale),We(t.angle),Q(t.offset),t.fill!==!1){let n=t.color??I.WHITE,r=t.pts.map((s,a)=>({pos:new C(s.x,s.y),uv:t.uv?t.uv[a]:new C(0,0),color:t.colors&&t.colors[a]?t.colors[a].mult(n):n,opacity:t.opacity??1})),o;t.triangulate?o=Mn(t.pts).map(a=>a.map(m=>t.pts.indexOf(m))).flat():o=[...Array(e-2).keys()].map(s=>[0,s+1,s+2]).flat(),Le(r,t.indices??o,t.fixed,t.uv?t.tex:l.gfx.defTex,t.shader,t.uniform??void 0)}t.outline&&jt({pts:[...t.pts,t.pts[0]],radius:t.radius,width:t.outline.width,color:t.outline.color,join:t.outline.join,uniform:t.uniform,fixed:t.fixed,opacity:t.opacity??t.outline.opacity}),pe()}}i(Pe,"drawPolygon");function Hn(t){if(t.radiusX===void 0||t.radiusY===void 0)throw new Error('drawEllipse() requires properties "radiusX" and "radiusY".');if(t.radiusX===0||t.radiusY===0)return;let e=t.start??0,n=t.end??360,r=_e(t.anchor??"center").scale(new C(-t.radiusX,-t.radiusY)),o=yt(r,t.radiusX,t.radiusY,e,n,t.resolution);o.unshift(r);let s=Object.assign({},t,{pts:o,radius:0,...t.gradient?{colors:[t.gradient[0],...Array(o.length-1).fill(t.gradient[1])]}:{}});if(n-e>=360&&t.outline){t.fill!==!1&&Pe(Object.assign({},s,{outline:null})),Pe(Object.assign({},s,{pts:o.slice(1),fill:!1}));return}Pe(s)}i(Hn,"drawEllipse");function Ne(t){if(typeof t.radius!="number")throw new Error('drawCircle() requires property "radius".');t.radius!==0&&Hn(Object.assign({},t,{radiusX:t.radius,radiusY:t.radius,angle:0}))}i(Ne,"drawCircle");function kt(t){let{p1:e,p2:n}=t;if(!e||!n)throw new Error('drawLine() requires properties "p1" and "p2".');let r=t.width||1,o=n.sub(e).unit().normal().scale(r*.5),s=[e.sub(o),e.add(o),n.add(o),n.sub(o)].map(a=>({pos:new C(a.x,a.y),uv:new C(0),color:t.color??I.WHITE,opacity:t.opacity??1}));Le(s,[0,1,3,1,2,3],t.fixed,l.gfx.defTex,t.shader,t.uniform??void 0)}i(kt,"drawLine");function Mu(t){let e=t.pts,n=[],r=(t.width||1)*.5,o=e[0]===e[e.length-1]||e[0].eq(e[e.length-1]),s=t.pos||x(0,0),a;o?a=e[0].sub(e[e.length-2]):a=e[1].sub(e[0]);let m=a.len(),u=a.normal().scale(-r/m),p,c=e[0];if(!o)switch(t.cap){case"square":{let h=a.scale(-r/m);n.push(c.add(h).add(u)),n.push(c.add(h).sub(u));break}case"round":{let h=Math.max(r,10),O=Math.PI/h,y=u.scale(-1),w=Math.cos(O),V=Math.sin(O);for(let R=0;R0?(n.push(p.add(P)),n.push(p.sub(u)),n.push(p.add(P)),n.push(p.sub(w))):(n.push(p.add(u)),n.push(p.sub(P)),n.push(p.add(w)),n.push(p.sub(P))),a=O,m=y,u=w}if(!o)switch(n.push(c.add(u)),n.push(c.sub(u)),t.cap){case"square":{let h=a.scale(r/m);n.push(c.add(h).add(u)),n.push(c.add(h).sub(u));break}case"round":{let h=Math.max(r,10),O=Math.PI/h,y=u.scale(1),w=Math.cos(O),V=Math.sin(O);for(let R=0;R({pos:s.add(h),uv:x(),color:t.color||I.WHITE,opacity:t.opacity??1})),d=[],v=0;for(let h=0;h0){let D=p.add(P),b=Math.max(r,10),E=se(u.angleBetween(w)/b),A=u,G=Math.cos(E),M=Math.sin(E);for(let F=0;F({pos:s.add(h),uv:x(),color:t.color||I.WHITE,opacity:t.opacity??1})),d=[],v=0;for(let h=0;h({pos:s.add(h),uv:x(),color:t.color||I.WHITE,opacity:t.opacity??1})),d=[],v=0;for(let h=0;h2)switch(t.join){case"bevel":return Mu(t);case"round":return Du(t);case"miter":return Bu(t)}if(t.radius&&e.length>=3){kt(Object.assign({},t,{p1:e[0],p2:e[1]}));for(let r=1;rQt(t.pt1,t.pt2,t.pt3,t.pt4,e),t)}i(zi,"drawBezier");var Ve=class t{static{i(this,"Texture")}ctx;src=null;glTex;width;height;constructor(e,n,r,o={}){this.ctx=e;let s=e.gl,a=e.gl.createTexture();if(!a)throw new Error("Failed to create texture");this.glTex=a,e.onDestroy(()=>this.free()),this.width=n,this.height=r;let m={linear:s.LINEAR,nearest:s.NEAREST}[o.filter??e.opts.texFilter??"nearest"],u={repeat:s.REPEAT,clampToEdge:s.CLAMP_TO_EDGE}[o.wrap??"clampToEdge"];this.bind(),n&&r&&s.texImage2D(s.TEXTURE_2D,0,s.RGBA,n,r,0,s.RGBA,s.UNSIGNED_BYTE,null),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,m),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,m),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,u),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,u),this.unbind()}static fromImage(e,n,r={}){let o=new t(e,n.width,n.height,r);return o.update(n),o.src=n,o}update(e,n=0,r=0){let o=this.ctx.gl;this.bind(),o.texSubImage2D(o.TEXTURE_2D,0,n,r,o.RGBA,o.UNSIGNED_BYTE,e),this.unbind()}bind(){this.ctx.pushTexture2D(this.glTex)}unbind(){this.ctx.popTexture2D()}free(){this.ctx.gl.deleteTexture(this.glTex)}},ot=class{static{i(this,"FrameBuffer")}ctx;tex;glFramebuffer;glRenderbuffer;constructor(e,n,r,o={}){this.ctx=e;let s=e.gl;e.onDestroy(()=>this.free()),this.tex=new Ve(e,n,r,o);let a=s.createFramebuffer(),m=s.createRenderbuffer();if(!a||!m)throw new Error("Failed to create framebuffer");this.glFramebuffer=a,this.glRenderbuffer=m,this.bind(),s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,n,r),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,this.tex.glTex,0),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,this.glRenderbuffer),this.unbind()}get width(){return this.tex.width}get height(){return this.tex.height}toImageData(){let e=this.ctx.gl,n=new Uint8ClampedArray(this.width*this.height*4);this.bind(),e.readPixels(0,0,this.width,this.height,e.RGBA,e.UNSIGNED_BYTE,n),this.unbind();let r=this.width*4,o=new Uint8Array(r);for(let s=0;s<(this.height/2|0);s++){let a=s*r,m=(this.height-s-1)*r;o.set(n.subarray(a,a+r)),n.copyWithin(a,m,m+r),n.set(o,m)}return new ImageData(n,this.width,this.height)}toDataURL(){let e=document.createElement("canvas"),n=e.getContext("2d");if(e.width=this.width,e.height=this.height,!n)throw new Error("Failed to get 2d context");return n.putImageData(this.toImageData(),0,0),e.toDataURL()}clear(){let e=this.ctx.gl;e.clear(e.COLOR_BUFFER_BIT)}draw(e){this.bind(),e(),this.unbind()}bind(){this.ctx.pushFramebuffer(this.glFramebuffer),this.ctx.pushRenderbuffer(this.glRenderbuffer),this.ctx.pushViewport({x:0,y:0,w:this.width,h:this.height})}unbind(){this.ctx.popFramebuffer(),this.ctx.popRenderbuffer(),this.ctx.popViewport()}free(){let e=this.ctx.gl;e.deleteFramebuffer(this.glFramebuffer),e.deleteRenderbuffer(this.glRenderbuffer),this.tex.free()}},zn=class{static{i(this,"BatchRenderer")}ctx;glVBuf;glIBuf;vqueue=[];iqueue=[];stride;maxVertices;maxIndices;vertexFormat;numDraws=0;curPrimitive=null;curTex=null;curShader=null;curUniform={};constructor(e,n,r,o){let s=e.gl;this.vertexFormat=n,this.ctx=e,this.stride=n.reduce((m,u)=>m+u.size,0),this.maxVertices=r,this.maxIndices=o;let a=s.createBuffer();if(!a)throw new Error("Failed to create vertex buffer");this.glVBuf=a,e.pushArrayBuffer(this.glVBuf),s.bufferData(s.ARRAY_BUFFER,r*4,s.DYNAMIC_DRAW),e.popArrayBuffer(),this.glIBuf=s.createBuffer(),e.pushElementArrayBuffer(this.glIBuf),s.bufferData(s.ELEMENT_ARRAY_BUFFER,o*4,s.DYNAMIC_DRAW),e.popElementArrayBuffer()}push(e,n,r,o,s=null,a={}){(e!==this.curPrimitive||s!==this.curTex||o!==this.curShader||!Fn(this.curUniform,a)||this.vqueue.length+n.length*this.stride>this.maxVertices||this.iqueue.length+r.length>this.maxIndices)&&this.flush();let m=this.vqueue.length/this.stride;for(let u of n)this.vqueue.push(u);for(let u of r)this.iqueue.push(u+m);this.curPrimitive=e,this.curShader=o,this.curTex=s,this.curUniform=a}flush(){if(!this.curPrimitive||!this.curShader||this.vqueue.length===0||this.iqueue.length===0)return;let e=this.ctx.gl;this.ctx.pushArrayBuffer(this.glVBuf),e.bufferSubData(e.ARRAY_BUFFER,0,new Float32Array(this.vqueue)),this.ctx.pushElementArrayBuffer(this.glIBuf),e.bufferSubData(e.ELEMENT_ARRAY_BUFFER,0,new Uint16Array(this.iqueue)),this.ctx.setVertexFormat(this.vertexFormat),this.curShader.bind(),this.curShader.send(this.curUniform),this.curTex?.bind(),e.drawElements(this.curPrimitive,this.iqueue.length,e.UNSIGNED_SHORT,0),this.curTex?.unbind(),this.curShader.unbind(),this.ctx.popArrayBuffer(),this.ctx.popElementArrayBuffer(),this.vqueue=[],this.iqueue=[],this.numDraws++}free(){let e=this.ctx.gl;e.deleteBuffer(this.glVBuf),e.deleteBuffer(this.glIBuf)}};function Tt(t){let e=[],n=i(s=>{e.push(s),t(s)},"push"),r=i(()=>{e.pop(),t(o()??null)},"pop"),o=i(()=>e[e.length-1],"cur");return[n,r,o]}i(Tt,"genStack");function Yi(t,e={}){let n=[];function r(D){n.push(D)}i(r,"onDestroy");function o(){n.forEach(b=>b());let D=t.getExtension("WEBGL_lose_context");D&&D.loseContext()}i(o,"destroy");let s=null;function a(D){if(Fn(D,s))return;s=D;let b=D.reduce((E,A)=>E+A.size,0);D.reduce((E,A,G)=>(t.vertexAttribPointer(G,A.size,t.FLOAT,!1,b*4,E),t.enableVertexAttribArray(G),E+A.size*4),0)}i(a,"setVertexFormat");let[m,u]=Tt(D=>t.bindTexture(t.TEXTURE_2D,D)),[p,c]=Tt(D=>t.bindBuffer(t.ARRAY_BUFFER,D)),[f,d]=Tt(D=>t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,D)),[v,h]=Tt(D=>t.bindFramebuffer(t.FRAMEBUFFER,D)),[O,y]=Tt(D=>t.bindRenderbuffer(t.RENDERBUFFER,D)),[w,V]=Tt(D=>{if(!D)return;let{x:b,y:E,w:A,h:G}=D;t.viewport(b,E,A,G)}),[R,P]=Tt(D=>t.useProgram(D));return w({x:0,y:0,w:t.drawingBufferWidth,h:t.drawingBufferHeight}),{gl:t,opts:e,onDestroy:r,destroy:o,pushTexture2D:m,popTexture2D:u,pushArrayBuffer:p,popArrayBuffer:c,pushElementArrayBuffer:f,popElementArrayBuffer:d,pushFramebuffer:v,popFramebuffer:h,pushRenderbuffer:O,popRenderbuffer:y,pushViewport:w,popViewport:V,pushProgram:R,popProgram:P,setVertexFormat:a}}i(Yi,"initGfx");var Yr={};function Xi(t,e){e.pos&&(t.pos=t.pos.add(e.pos)),e.scale&&(t.scale=t.scale.scale(x(e.scale))),e.angle&&(t.angle+=e.angle),e.color&&t.ch.length===1&&(t.color=t.color.mult(e.color)),e.opacity!=null&&(t.opacity*=e.opacity)}i(Xi,"applyCharTransform");function Yn(t){let e={},n="",r=[],o=String(t),s=i(a=>{r.length>0&&(e[n.length]=r.slice()),n+=a},"emit");for(;o!=="";){if(o[0]==="\\"){if(o.length===1)throw new Error("Styled text error: \\ at end of string");s(o[1]),o=o.slice(2);continue}if(o[0]==="["){let a=/^\[(\/)?(\w+?)\]/.exec(o);if(!a){s(o[0]),o=o.slice(1);continue}let[m,u,p]=a;if(u!==void 0){let c=r.pop();if(c!==p)throw c!==void 0?new Error(`Styled text error: mismatched tags. Expected [/${c}], got [/${p}]`):new Error(`Styled text error: stray end tag [/${p}]`)}else r.push(p);o=o.slice(m.length);continue}s(o[0]),o=o.slice(1)}if(r.length>0)throw new Error(`Styled text error: unclosed tags ${r}`);return{charStyleMap:e,text:n}}i(Yn,"compileStyledText");function Ue(t){if(t.text===void 0)throw new Error('formatText() requires property "text".');let e=_r(t.font);if(!t.text||t.text===""||e instanceof ce||!e)return{width:0,height:0,chars:[],opt:t,renderedText:""};let{charStyleMap:n,text:r}=Yn(t.text+""),o=Jo(r);if(e instanceof Et||typeof e=="string"){let V=e instanceof Et?e.fontface.family:e,R=e instanceof Et?{outline:e.outline,filter:e.filter}:{outline:null,filter:rn},P=Yr[V]??{font:{tex:new Ve(l.gfx.ggl,2048,2048,{filter:R.filter}),map:{},size:64},cursor:new C(0),outline:R.outline};Yr[V]||(Yr[V]=P),e=P.font;for(let D of o)if(!P.font.map[D]){let b=l.fontCacheC2d;if(!b)throw new Error("fontCacheC2d is not defined.");if(!l.fontCacheCanvas)throw new Error("fontCacheCanvas is not defined.");b.clearRect(0,0,l.fontCacheCanvas.width,l.fontCacheCanvas.height),b.font=`${e.size}px ${V}`,b.textBaseline="top",b.textAlign="left",b.fillStyle="#ffffff";let E=b.measureText(D),A=Math.ceil(E.width);if(!A)continue;let G=E.fontBoundingBoxAscent+E.fontBoundingBoxDescent;P.outline&&P.outline.width&&P.outline.color&&(b.lineJoin="round",b.lineWidth=P.outline.width*2,b.strokeStyle=P.outline.color.toHex(),b.strokeText(D,P.outline.width,P.outline.width),A+=P.outline.width*2,G+=P.outline.width*3),b.fillText(D,P.outline?.width??0,P.outline?.width??0);let M=b.getImageData(0,0,A,G);if(P.cursor.x+A>2048&&(P.cursor.x=0,P.cursor.y+=G,P.cursor.y>2048))throw new Error("Font atlas exceeds character limit");e.tex.update(M,P.cursor.x,P.cursor.y),e.map[D]=new z(P.cursor.x,P.cursor.y,A,G),P.cursor.x+=A}}let s=t.size||e.size,a=x(t.scale??1).scale(s/e.size),m=t.lineSpacing??0,u=t.letterSpacing??0,p=0,c=0,f=0,d=[],v=[],h=0,O=null,y=0;for(;ht.width&&(f+=s+m,O!=null&&(h-=v.length-O,V=o[h],R=e.map[V],P=R.w*a.x,v=v.slice(0,O-1),p=y),O=null,y=0,d.push({width:p-u,chars:v}),p=0,v=[]),v.push({tex:e.tex,width:R.w,height:R.h,quad:new z(R.x/e.tex.width,R.y/e.tex.height,R.w/e.tex.width,R.h/e.tex.height),ch:V,pos:new C(p,f),opacity:t.opacity??1,color:t.color??I.WHITE,scale:x(a),angle:0}),V===" "&&(O=v.length,y=p),p+=P,c=Math.max(c,p),p+=u}}h++}d.push({width:p-u,chars:v}),f+=s,t.width&&(c=t.width);let w=[];for(let V=0;V{it({tex:e.tex,width:e.width,height:e.height,pos:e.pos,scale:e.scale,angle:e.angle,color:e.color,opacity:e.opacity,quad:e.quad,anchor:"center",uniform:t.opt.uniform,shader:t.opt.shader,fixed:t.opt.fixed})}),pe()}i(He,"drawFormattedText");function ve(t){if(t.width===void 0||t.height===void 0)throw new Error('drawRect() requires property "width" and "height".');if(t.width<=0||t.height<=0)return;let e=t.width,n=t.height,o=_e(t.anchor||pt).add(1,1).scale(new C(e,n).scale(-.5)),s=[new C(0,0),new C(e,0),new C(e,n),new C(0,n)];if(t.radius){let a=Math.min(e,n)/2,m=Array.isArray(t.radius)?t.radius.map(u=>Math.min(a,u)):new Array(4).fill(Math.min(a,t.radius));s=[new C(m[0],0),...m[1]?yt(new C(e-m[1],m[1]),m[1],m[1],270,360):[x(e,0)],...m[2]?yt(new C(e-m[2],n-m[2]),m[2],m[2],0,90):[x(e,n)],...m[3]?yt(new C(m[3],n-m[3]),m[3],m[3],90,180):[x(0,n)],...m[0]?yt(new C(m[0],m[0]),m[0],m[0],180,270):[]]}Pe(Object.assign({},t,{offset:o,pts:s,...t.gradient?{colors:t.horizontal?[t.gradient[0],t.gradient[1],t.gradient[1],t.gradient[0]]:[t.gradient[0],t.gradient[0],t.gradient[1],t.gradient[1]]}:{}}))}i(ve,"drawRect");function qe(t){Oe();let e=l.gfx.width,n=l.gfx.height;l.gfx.width=l.gfx.viewport.width,l.gfx.height=l.gfx.viewport.height,t(),Oe(),l.gfx.width=e,l.gfx.height=n}i(qe,"drawUnscaled");function Wr(t,e){qe(()=>{let n=x(8);be(),Q(t);let r=Ue({text:e,font:vt,size:16,pos:n,color:_(255,255,255),fixed:!0}),o=r.width+n.x*2,s=r.height+n.x*2;t.x+o>=ie()&&Q(x(-o,0)),t.y+s>=ue()&&Q(x(0,-s)),ve({width:o,height:s,color:_(0,0,0),radius:4,opacity:.8,fixed:!0}),He(r),pe()})}i(Wr,"drawInspectText");function Wn(t){if(!t.p1||!t.p2||!t.p3)throw new Error('drawTriangle() requires properties "p1", "p2" and "p3".');return Pe(Object.assign({},t,{pts:[t.p1,t.p2,t.p3]}))}i(Wn,"drawTriangle");function Ji(){if(l.debug.inspect){let t=null;for(let e of l.game.root.get("*",{recursive:!0}))if(e.c("area")&&e.isHovering()){t=e;break}if(l.game.root.drawInspect(),t){let e=[],n=t.inspect();for(let r in n)n[r]?e.push(`${n[r]}`):e.push(`${r}`);Wr(fi(kn()),e.join(` `))}Wr(x(8),`FPS: ${l.debug.fps()}`)}l.debug.paused&&qe(()=>{be(),Q(ie(),0),Q(-8,8);let t=32;ve({width:t,height:t,anchor:"topright",color:_(0,0,0),opacity:.8,radius:4,fixed:!0});for(let e=1;e<=2;e++)ve({width:4,height:t*.6,anchor:"center",pos:x(-t/3*e,t*.5),color:_(255,255,255),radius:2,fixed:!0});pe()}),l.debug.timeScale!==1&&qe(()=>{be(),Q(ie(),ue()),Q(-8,-8);let t=8,e=Ue({text:l.debug.timeScale.toFixed(1),font:vt,size:16,color:_(255,255,255),pos:x(-t),anchor:"botright",fixed:!0});ve({width:e.width+t*2+t*4,height:e.height+t*2,anchor:"botright",color:_(0,0,0),opacity:.8,radius:4,fixed:!0});for(let n=0;n<2;n++){let r=l.debug.timeScale<1;Wn({p1:x(-e.width-t*(r?2:3.5),-t),p2:x(-e.width-t*(r?2:3.5),-t-e.height),p3:x(-e.width-t*(r?3.5:2),-t-e.height/2),pos:x(-n*t*1+(r?-t*.5:0),0),color:_(255,255,255),fixed:!0})}He(e),pe()}),l.debug.curRecording&&qe(()=>{be(),Q(0,ue()),Q(24,-24),Ne({radius:12,color:_(255,0,0),opacity:Sn(0,1,l.app.time()*4),fixed:!0}),pe()}),l.debug.showLog&&l.game.logs.length>0&&qe(()=>{be(),Q(0,ue()),Q(8,-8);let t=8,e=[];for(let r of l.game.logs){let o="",s=r.msg instanceof Error?"error":"info";o+=`[time]${r.time.toFixed(2)}[/time]`,o+=" ",o+=`[${s}]${$r(r.msg)}[/${s}]`,e.push(o)}l.game.logs=l.game.logs.filter(r=>l.app.time()-r.time<(l.globalOpt.logTime||4));let n=Ue({text:e.join(` `),font:vt,pos:x(t,-t),anchor:"botleft",size:16,width:ie()*.6,lineSpacing:t/2,fixed:!0,styles:{time:{color:_(127,127,127)},info:{color:_(255,255,255)},error:{color:_(255,0,127)}}});ve({width:n.width+t*2,height:n.height+t*2,anchor:"botleft",color:_(0,0,0),radius:4,opacity:.8,fixed:!0}),He(n),pe()})}i(Ji,"drawDebug");function $r(t,e=!1){var n="",r;return e&&typeof t=="string"&&(t=JSON.stringify(t)),Array.isArray(t)&&(n=["[",t.map(o=>$r(o,!0)).join(", "),"]"].join(""),t=n),typeof t=="object"&&t.toString===Object.prototype.toString&&(t.constructor!==Object&&(n+=t.constructor.name+" "),n+=["{",(r=Object.getOwnPropertyNames(t).map(o=>`${/^\w+$/.test(o)?o:JSON.stringify(o)}: ${$r(t[o],!0)}`).join(", "))?` ${r} `:"","}"].join(""),t=n),String(t).replaceAll(/(?0?l.game.events.trigger("loading",t):qe(()=>{let e=ie()/2,n=24,r=x(ie()/2,ue()/2).sub(x(e/2,n/2));ve({pos:x(0),width:ie(),height:ue(),color:_(0,0,0)}),ve({pos:r,width:e,height:n,fill:!1,outline:{width:4}}),ve({pos:r,width:e*t,height:n})})}i(es,"drawLoadScreen");function $n(t,e,n){let r=l.gfx.ggl.gl;Oe(),r.clear(r.STENCIL_BUFFER_BIT),r.enable(r.STENCIL_TEST),r.stencilFunc(r.NEVER,1,255),r.stencilOp(r.REPLACE,r.REPLACE,r.REPLACE),e(),Oe(),r.stencilFunc(n,1,255),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),t(),Oe(),r.disable(r.STENCIL_TEST)}i($n,"drawStenciled");function ts(t,e){let n=l.gfx.ggl.gl;$n(t,e,n.EQUAL)}i(ts,"drawMasked");function At(t){if(!t.tex)throw new Error('drawTexture() requires property "tex".');let e=t.quad??new z(0,0,1,1),n=t.tex.width*e.w,r=t.tex.height*e.h,o=new C(1);if(t.tiled){let a=_e(t.anchor||pt).add(new C(1,1)).scale(.5).scale(t.width||n,t.height||r),m=(t.width||n)/n,u=(t.height||r)/r,p=Math.floor(m),c=Math.floor(u),f=m-p,d=u-c,v=(p+f?1:0)*(c+d?1:0),h=new Array(v*6),O=new Array(v*4),y=0,w=i((V,R,P,D,b)=>{h[y*6+0]=y*4+0,h[y*6+1]=y*4+1,h[y*6+2]=y*4+3,h[y*6+3]=y*4+1,h[y*6+4]=y*4+2,h[y*6+5]=y*4+3,O[y*4+0]={pos:new C(V-a.x,R-a.y),uv:new C(b.x,b.y),color:t.color||I.WHITE,opacity:t.opacity||1},O[y*4+1]={pos:new C(V+P-a.x,R-a.y),uv:new C(b.x+b.w,b.y),color:t.color||I.WHITE,opacity:t.opacity||1},O[y*4+2]={pos:new C(V+P-a.x,R+D-a.y),uv:new C(b.x+b.w,b.y+b.h),color:t.color||I.WHITE,opacity:t.opacity||1},O[y*4+3]={pos:new C(V-a.x,R+D-a.y),uv:new C(b.x,b.y+b.h),color:t.color||I.WHITE,opacity:t.opacity||1},y++},"addQuad");for(let V=0;V{let n=Un(e,sn,an),r=t.pixelDensity??1,o=t.scale??1,{gl:s}=e,a=Ve.fromImage(e,new ImageData(new Uint8ClampedArray([255,255,255,255]),1,1)),m=t.width&&t.height?new ot(e,t.width*r*o,t.height*r*o):new ot(e,s.drawingBufferWidth,s.drawingBufferHeight),u=null,p=1;t.background&&(typeof t.background=="string"?u=_(t.background):(u=_(...t.background),p=t.background[3]??1),s.clearColor(u.r/255,u.g/255,u.b/255,p??1)),s.enable(s.BLEND),s.blendFuncSeparate(s.SRC_ALPHA,s.ONE_MINUS_SRC_ALPHA,s.ONE,s.ONE_MINUS_SRC_ALPHA);let c=new zn(e,on,bi,yi),f=Ve.fromImage(e,new ImageData(new Uint8ClampedArray([128,128,128,255,190,190,190,255,190,190,190,255,128,128,128,255]),2,2),{wrap:"repeat",filter:"nearest"});return{lastDrawCalls:0,ggl:e,defShader:n,defTex:a,frameBuffer:m,postShader:null,postShaderUniform:null,renderer:c,transform:new he,transformStack:[],bgTex:f,bgColor:u,bgAlpha:p,width:t.width??s.drawingBufferWidth/r/o,height:t.height??s.drawingBufferHeight/r/o,viewport:{x:0,y:0,width:s.drawingBufferWidth,height:s.drawingBufferHeight},fixed:!1}},"initAppGfx");function Xn(){let t=l.pixelDensity,e=l.gfx.ggl.gl.drawingBufferWidth/t,n=l.gfx.ggl.gl.drawingBufferHeight/t;if(l.globalOpt.letterbox){if(!l.globalOpt.width||!l.globalOpt.height)throw new Error("Letterboxing requires width and height defined.");let r=e/n,o=l.globalOpt.width/l.globalOpt.height;if(r>o){let s=n*o,a=(e-s)/2;l.gfx.viewport={x:a,y:0,width:s,height:n}}else{let s=e/o,a=(n-s)/2;l.gfx.viewport={x:0,y:a,width:e,height:s}}return}if(l.globalOpt.stretch&&(!l.globalOpt.width||!l.globalOpt.height))throw new Error("Stretching requires width and height defined.");l.gfx.viewport={x:0,y:0,width:e,height:n}}i(Xn,"updateViewport");function st(t){return t.fixed?!0:t.parent?st(t.parent):!1}i(st,"isFixed");function Ke(t){return{color:t.color,opacity:t.opacity,anchor:t.anchor,outline:t.outline,shader:t.shader,uniform:t.uniform}}i(Ke,"getRenderProps");function is(t,e={}){return{id:"circle",radius:t,draw(){Ne(Object.assign(Ke(this),{radius:this.radius,fill:e.fill}))},renderArea(){return new W(new C(this.anchor?0:-this.radius),this.radius*2,this.radius*2)},inspect(){return`radius: ${Math.ceil(this.radius)}`}}}i(is,"circle");function Qn(...t){return{id:"color",color:_(...t),inspect(){return`color: ${this.color.toString()}`}}}i(Qn,"color");function ss(t){return{add(){this.canvas=t}}}i(ss,"drawon");function as(t=1){let e,n=0,r=!1;return{require:["opacity"],add(){e=this.opacity,this.opacity=0},update(){r||(n+=te(),this.opacity=Se(n,0,t,0,e),n>=t&&(this.opacity=e,r=!0))}}}i(as,"fadeIn");function us(t="intersect"){return{id:"mask",mask:t}}i(us,"mask");function Jn(t){return{id:"opacity",opacity:t??1,fadeIn(e=1,n=l.k.easings.linear){return l.game.root.tween(0,this.opacity,e,r=>this.opacity=r,n)},fadeOut(e=1,n=l.k.easings.linear){return l.game.root.tween(this.opacity,0,e,r=>this.opacity=r,n)},inspect(){return`opacity: ${Zt(this.opacity,1)}`}}}i(Jn,"opacity");function cs(t=1,e=_(0,0,0),n=1,r="miter",o=10,s="butt"){return{id:"outline",outline:{width:t,color:e,opacity:n,join:r,miterLimit:o,cap:s},inspect(){return`outline: ${this.outline.width}px, ${this.outline.color}`}}}i(cs,"outline");var Qr=class{static{i(this,"Particle")}pos=x(0);vel=x(0);acc=x(0);angle=0;angularVelocity=0;damping=0;t;lt=null;gc;constructor(){this.t=0,this.gc=!0}get progress(){return this.lt?this.t/this.lt:this.t}};function ls(t,e){let n=e.lifetime,r=[],o=t.colors||[I.WHITE],s=t.opacities||[1],a=t.quads||[new z(0,0,1,1)],m=t.scales||[1],u=t.lifeTime,p=e.direction,c=e.spread,f=t.speed||[0,0],d=t.angle||[0,0],v=t.angularVelocity||[0,0],h=t.acceleration||[x(0),x(0)],O=t.damping||[0,0],y=[],w=new Array(t.max),V=0,R=0;for(let b=0;b=E.lt){E.gc=!0,V--;continue}E.vel=E.vel.add(E.acc.scale(b)).scale(1-E.damping*b),E.pos=E.pos.add(E.vel.scale(b)),E.angle+=E.angularVelocity*b}for(n!==void 0&&(n-=b,n<=0&&P.trigger()),R+=b;Ve.rate;)this.emit(1),V++,R-=e.rate},draw(){if(!(n!==void 0&&n<=0)){for(let b=0;b`[${n.x},${n.y}]`).join(",")}`}}}i(ms,"polygon");function Zn(t,e,n){let r;return l.game.root.get("area").forEach(s=>{if(n&&n.some(u=>s.is(u)))return;let m=s.worldArea().raycast(t,e);m&&(r?m.fraction0&&(l.game.cam.pos=x(...t)),l.game.cam.pos?l.game.cam.pos.clone():xt()}i(ds,"camPos");function fs(...t){return t.length>0&&(l.game.cam.scale=x(...t)),l.game.cam.scale.clone()}i(fs,"camScale");function hs(t){return t!==void 0&&(l.game.cam.angle=t),l.game.cam.angle}i(hs,"camRot");function gs(t=_(255,255,255),e=1){let n=l.game.root.add([er(ie(),ue()),Qn(t),Jn(1),rr()]),r=n.fadeOut(e);return r.onEnd(()=>nr(n)),r}i(gs,"camFlash");function bs(){return l.game.cam.transform.clone()}i(bs,"camTransform");function ys(t=12){l.game.cam.shake+=t}i(ys,"shake");function pn(t){return l.game.cam.transform.multVec2(t)}i(pn,"toScreen");function tr(t){return l.game.cam.transform.invert().multVec2(t)}i(tr,"toWorld");function xs(t,e){if(!e.tileWidth||!e.tileHeight)throw new Error("Must provide tileWidth and tileHeight.");let n=l.game.root.add([St(e.pos??x(0))]),r=t.length,o=0,s=null,a=null,m=null,u=null,p=i(b=>b.x+b.y*o,"tile2Hash"),c=i(b=>x(Math.floor(b%o),Math.floor(b/o)),"hash2Tile"),f=i(()=>{s=[];for(let b of n.children)d(b)},"createSpatialMap"),d=i(b=>{let E=p(b.tilePos);s[E]?s[E].push(b):s[E]=[b]},"insertIntoSpatialMap"),v=i(b=>{let E=p(b.tilePos);if(s[E]){let A=s[E].indexOf(b);A>=0&&s[E].splice(A,1)}},"removeFromSpatialMap"),h=i(()=>{let b=!1;for(let E of n.children){let A=n.pos2Tile(E.pos);(E.tilePos.x!=A.x||E.tilePos.y!=A.y)&&(b=!0,v(E),E.tilePos.x=A.x,E.tilePos.y=A.y,d(E))}b&&n.trigger("spatialMapChanged")},"updateSpatialMap"),O=i(()=>{let b=n.getSpatialMap(),E=n.numRows()*n.numColumns();a?a.length=E:a=new Array(E),a.fill(1,0,E);for(let A=0;A{let b=n.getSpatialMap(),E=n.numRows()*n.numColumns();m?m.length=E:m=new Array(E),m.fill(15,0,E);for(let A=0;A{let b=n.numRows()*n.numColumns(),E=i((G,M)=>{let F=[];for(F.push(G);F.length>0;){let K=F.pop();P(K).forEach(H=>{u[H]<0&&(u[H]=M,F.push(H))})}},"traverse");u?u.length=b:u=new Array(b),u.fill(-1,0,b);let A=0;for(let G=0;G=0){A++;continue}E(G,A),A++}},"createConnectivityMap"),V=i((b,E)=>a[E],"getCost"),R=i((b,E)=>{let A=c(b),G=c(E);return A.dist(G)},"getHeuristic"),P=i((b,E)=>{let A=[],G=Math.floor(b%o),M=G>0&&m[b]&1&&a[b-1]!==1/0,F=b>=o&&m[b]&2&&a[b-o]!==1/0,K=G{if(typeof b=="string"){if(e.tiles[b]){if(typeof e.tiles[b]!="function")throw new Error("Level symbol def must be a function returning a component list");return e.tiles[b](A)}else if(e.wildcardTile)return e.wildcardTile(b,A)}else{if(Array.isArray(b))return b;throw new Error("Expected a symbol or a component list")}})();if(!G)return null;let M=!1,F=!1;for(let H of G)H.id==="tile"&&(F=!0),H.id==="pos"&&(M=!0);M||G.push(St(this.tile2Pos(A))),F||G.push(or());let K=n.add(G);return M&&(K.tilePosOffset=K.pos.clone()),K.tilePos=A,K.transform=mt(K),s&&(d(K),this.trigger("spatialMapChanged"),this.trigger("navigationMapInvalid")),K},numColumns(){return o},numRows(){return r},levelWidth(){return o*this.tileWidth()},levelHeight(){return r*this.tileHeight()},tile2Pos(...b){return x(...b).scale(this.tileWidth(),this.tileHeight())},pos2Tile(...b){let E=x(...b);return x(Math.floor(E.x/this.tileWidth()),Math.floor(E.y/this.tileHeight()))},getSpatialMap(){return s||f(),s},onSpatialMapChanged(b){return this.on("spatialMapChanged",b)},onNavigationMapInvalid(b){return this.on("navigationMapInvalid",b)},getAt(b){s||f();let E=p(b);return s[E]||[]},raycast(b,E){let A=this.toWorld(b),G=this.toWorld(b.add(E)).sub(A),M=1/this.tileWidth(),F=b.scale(M),K=Ao(F,E,H=>{let q=this.getAt(H);if(q.some(N=>N.isObstacle))return!0;let Y=null;for(let N of q)if(N.is("area")){let Z=N.worldArea().raycast(A,G);Z&&(Y?Z.fraction=o||b.y<0||b.y>=r||E.x<0||E.x>=o||E.y<0||E.y>=r)return null;let G=p(b),M=p(E);if(a[M]===1/0)return null;if(G===M)return[];if(u[G]!=-1&&u[G]!==u[M])return null;let F=new Kt((j,Z)=>j.costK.scale(G,M).add(G/2,M/2)),E]:null}};return n.use(D),n.onNavigationMapInvalid(()=>{n.invalidateNavigationMap(),n.trigger("navigationMapChanged")}),t.forEach((b,E)=>{let A=b.split("");o=Math.max(A.length,o),A.forEach((G,M)=>{n.spawn(G,x(M,E))})}),n}i(xs,"addLevel");function Qe(t,e,n){return l.game.objEvents.registers[t]||(l.game.objEvents.registers[t]=new Jt),l.game.objEvents.on(t,(r,...o)=>{r.is(e)&&n(r,...o)})}i(Qe,"on");var vs=me(t=>{let e=l.game.root.add([{fixedUpdate:t}]);return{get paused(){return e.paused},set paused(n){e.paused=n},cancel:i(()=>e.destroy(),"cancel")}},(t,e)=>Qe("fixedUpdate",t,e)),ws=me(t=>{let e=l.game.root.add([{update:t}]);return{get paused(){return e.paused},set paused(n){e.paused=n},cancel:i(()=>e.destroy(),"cancel")}},(t,e)=>Qe("update",t,e)),Cs=me(t=>{let e=l.game.root.add([{draw:t}]);return{get paused(){return e.hidden},set paused(n){e.hidden=n},cancel:i(()=>e.destroy(),"cancel")}},(t,e)=>Qe("draw",t,e)),Jr=me(t=>l.game.events.on("add",t),(t,e)=>Qe("add",t,e)),Os=me(t=>l.game.events.on("destroy",t),(t,e)=>Qe("destroy",t,e));function Es(t,e,n){return Qe("collide",t,(r,o,s)=>o.is(e)&&n(r,o,s))}i(Es,"onCollide");function Ts(t,e,n){return Qe("collideUpdate",t,(r,o,s)=>o.is(e)&&n(r,o,s))}i(Ts,"onCollideUpdate");function As(t,e,n){return Qe("collideEnd",t,(r,o,s)=>o.is(e)&&n(r,o,s))}i(As,"onCollideEnd");function ir(t,e){l.game.root.get(t,{recursive:!0}).forEach(e),Jr(t,e)}i(ir,"forAllCurrentAndFuture");var Ss=me(t=>l.app.onMousePress(t),(t,e)=>{let n=[];return ir(t,r=>{if(!r.area)throw new Error("onClick() requires the object to have area() component");n.push(r.onClick(()=>e(r)))}),ke.join(n)});function Vs(t,e){let n=[];return ir(t,r=>{if(!r.area)throw new Error("onHover() requires the object to have area() component");n.push(r.onHover(()=>e(r)))}),ke.join(n)}i(Vs,"onHover");function Ps(t,e){let n=[];return ir(t,r=>{if(!r.area)throw new Error("onHoverUpdate() requires the object to have area() component");n.push(r.onHoverUpdate(()=>e(r)))}),ke.join(n)}i(Ps,"onHoverUpdate");function Gs(t,e){let n=[];return ir(t,r=>{if(!r.area)throw new Error("onHoverEnd() requires the object to have area() component");n.push(r.onHoverEnd(()=>e(r)))}),ke.join(n)}i(Gs,"onHoverEnd");function Rs(t){l.game.events.on("loading",t)}i(Rs,"onLoading");function Ms(t){l.app.onResize(t)}i(Ms,"onResize");function Ds(t){l.game.events.on("error",t)}i(Ds,"onError");function _t(t){l.assets.loaded?t():l.game.events.on("load",t)}i(_t,"onLoad");function dn(t=[]){let e=new Map,n=[],r={},o=new ze,s=[],a=null,m=!1,u={id:Zo(),hidden:!1,transform:new he,children:[],parent:null,set paused(c){if(c!==m){m=c;for(let f of s)f.paused=c}},get paused(){return m},get tags(){let c=[];for(let[f,d]of e.entries())Object.keys(d).length==1&&c.push(f);return c},add(c){let f=Array.isArray(c)?dn(c):c;if(f.parent)throw new Error("Cannot add a game obj that already has a parent.");return f.parent=this,f.transform=mt(f),this.children.push(f),f.trigger("add",f),l.game.events.trigger("add",f),f},readd(c){let f=this.children.indexOf(c);return f!==-1&&(this.children.splice(f,1),this.children.push(c)),c},remove(c){let f=this.children.indexOf(c);if(f!==-1){c.parent=null,this.children.splice(f,1);let d=i(v=>{v.trigger("destroy"),l.game.events.trigger("destroy",v),v.children.forEach(h=>d(h))},"trigger");d(c)}},removeAll(c){if(c)this.get(c).forEach(f=>this.remove(f));else for(let f of[...this.children])this.remove(f)},fixedUpdate(){this.paused||(this.children.forEach(c=>c.fixedUpdate()),this.trigger("fixedUpdate"))},update(){this.paused||(this.children.forEach(c=>c.update()),this.trigger("update"))},draw(){if(this.hidden)return;this.canvas&&(Oe(),this.canvas.bind());let c=l.gfx.fixed;this.fixed&&(l.gfx.fixed=!0),be(),Q(this.pos),nt(this.scale),We(this.angle);let f=this.children.sort((d,v)=>{let h=d.layerIndex??l.game.defaultLayerIndex,O=v.layerIndex??l.game.defaultLayerIndex;return h-O||(d.z??0)-(v.z??0)});if(this.mask){let d={intersect:l.k.drawMasked,subtract:l.k.drawSubtracted}[this.mask];if(!d)throw new Error(`Invalid mask func: "${this.mask}"`);d(()=>{f.forEach(v=>v.draw())},()=>{this.trigger("draw")})}else this.trigger("draw"),f.forEach(d=>d.draw());pe(),l.gfx.fixed=c,this.canvas&&(Oe(),this.canvas.unbind())},drawInspect(){this.hidden||(be(),Q(this.pos),nt(this.scale),We(this.angle),this.children.forEach(c=>c.drawInspect()),this.trigger("drawInspect"),pe())},use(c){if(!c)return;if(typeof c=="string")return this.use({id:c});let f=[];c.id?(this.unuse(c.id),r[c.id]=[],f=r[c.id],e.set(c.id,c)):n.push(c);for(let v in c){if(wi.has(v))continue;let h=Object.getOwnPropertyDescriptor(c,v);if(h)if(typeof h.value=="function"&&(c[v]=c[v].bind(this)),h.set&&Object.defineProperty(c,v,{set:h.set.bind(this)}),h.get&&Object.defineProperty(c,v,{get:h.get.bind(this)}),Ci.has(v)){let O=v==="add"?()=>{a=i(y=>f.push(y),"onCurCompCleanup"),c[v]?.(),a=null}:c[v];f.push(this.on(v,O).cancel)}else if(this[v]===void 0)Object.defineProperty(this,v,{get:i(()=>c[v],"get"),set:i(O=>c[v]=O,"set"),configurable:!0,enumerable:!0}),f.push(()=>delete this[v]);else throw new Error(`Duplicate component property: "${v}"`)}let d=i(()=>{if(c.require){for(let v of c.require)if(!this.c(v))throw new Error(`Component "${c.id}" requires component "${v}"`)}},"checkDeps");c.destroy&&f.push(c.destroy.bind(this)),this.exists()?(d(),c.add&&(a=i(v=>f.push(v),"onCurCompCleanup"),c.add.call(this),a=null)):c.require&&f.push(this.on("add",d).cancel)},unuse(c){if(e.has(c)){for(let f of e.values())if(f.require&&f.require.includes(c))throw new Error(`Can't unuse. Component "${f.id}" requires component "${c}"`);e.delete(c)}r[c]&&(r[c].forEach(f=>f()),delete r[c])},c(c){return e.get(c)??null},get(c,f={}){let d=f.recursive?this.children.flatMap(i(function v(h){return[h,...h.children.flatMap(v)]},"recurse")):this.children;if(d=d.filter(v=>c?v.is(c):!0),f.liveUpdate){let v=i(O=>f.recursive?this.isAncestorOf(O):O.parent===this,"isChild"),h=[];h.push(l.k.onAdd(O=>{v(O)&&O.is(c)&&d.push(O)})),h.push(l.k.onDestroy(O=>{if(v(O)&&O.is(c)){let y=d.findIndex(w=>w.id===O.id);y!==-1&&d.splice(y,1)}})),this.onDestroy(()=>{for(let O of h)O.cancel()})}return d},query(c){let f=c.hierarchy||"children",d=c.include,v=c.exclude,h=[];switch(f){case"children":h=this.children;break;case"siblings":h=this.parent?this.parent.children.filter(y=>y!==this):[];break;case"ancestors":let O=this.parent;for(;O;)h.push(O),O=O.parent;break;case"descendants":h=this.children.flatMap(i(function y(w){return[w,...w.children.flatMap(y)]},"recurse"));break}if(d&&((c.includeOp||"and")==="and"||!Array.isArray(c.include)?h=h.filter(y=>y.is(d)):h=h.filter(y=>c.include.some(w=>y.is(w)))),v&&((c.includeOp||"and")==="and"||!Array.isArray(c.include)?h=h.filter(y=>!y.is(v)):h=h.filter(y=>!c.exclude.some(w=>y.is(w)))),c.visible===!0&&(h=h.filter(O=>O.visible)),c.distance){if(!this.pos)throw Error("Can't do a distance query from an object without pos");let O=c.distanceOp||"near",y=c.distance*c.distance;O==="near"?h=h.filter(w=>w.pos&&this.pos.sdist(w.pos)<=y):h=h.filter(w=>w.pos&&this.pos.sdist(w.pos)>y)}return c.name&&(h=h.filter(O=>O.name===c.name)),h},isAncestorOf(c){return c.parent?c.parent===this||this.isAncestorOf(c.parent):!1},exists(){return l.game.root.isAncestorOf(this)},is(c){if(c==="*")return!0;if(Array.isArray(c)){for(let f of c)if(!this.c(f))return!1;return!0}else return this.c(c)!=null},on(c,f){let d=o.on(c,f.bind(this));return a&&a(()=>d.cancel()),d},trigger(c,...f){o.trigger(c,...f),l.game.objEvents.trigger(c,this,...f)},destroy(){this.parent&&this.parent.remove(this)},inspect(){let c={};for(let[f,d]of e)c[f]=d.inspect?.()??null;for(let[f,d]of n.entries()){if(d.inspect){c[f]=d.inspect();continue}for(let[v,h]of Object.entries(d))typeof h!="function"&&(c[v]=`${v}: ${h}`)}return c},onAdd(c){return this.on("add",c)},onFixedUpdate(c){return this.on("fixedUpdate",c)},onUpdate(c){return this.on("update",c)},onDraw(c){return this.on("draw",c)},onDestroy(c){return this.on("destroy",c)},clearEvents(){o.clear()}},p=["onKeyPress","onKeyPressRepeat","onKeyDown","onKeyRelease","onMousePress","onMouseDown","onMouseRelease","onMouseMove","onCharInput","onMouseMove","onTouchStart","onTouchMove","onTouchEnd","onScroll","onGamepadButtonPress","onGamepadButtonDown","onGamepadButtonRelease","onGamepadStick","onButtonPress","onButtonDown","onButtonRelease"];for(let c of p)u[c]=(...f)=>{let d=l.app[c]?.(...f);return s.push(d),u.onDestroy(()=>d.cancel()),u.on("sceneEnter",()=>{s.splice(s.indexOf(d),1);let v=l.app[c]?.(...f);ke.replace(d,v),s.push(d)}),d};for(let c of t)u.use(c);return u}i(dn,"make");var Bs=i(()=>({events:new ze,objEvents:new ze,root:dn([]),gravity:null,scenes:{},currentScene:null,layers:null,defaultLayerIndex:0,logs:[],cam:{pos:null,scale:new C(1),angle:0,shake:0,transform:new he}}),"initGame");function Fs(t){l.game.gravity=t?(l.game.gravity||x(0,1)).unit().scale(t):null}i(Fs,"setGravity");function Ls(){return l.game.gravity?l.game.gravity.len():0}i(Ls,"getGravity");function Ks(t){l.game.gravity=t.unit().scale(l.game.gravity?l.game.gravity.len():1)}i(Ks,"setGravityDirection");function Vt(){return l.game.gravity?l.game.gravity.unit():x(0,1)}i(Vt,"getGravityDirection");var Is=lo("//uUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAATAAAeAAANDQ0NDRoaGhoaKCgoKCg1NTU1NTVDQ0NDQ1BQUFBQXl5eXl5ra2tra2t5eXl5eYaGhoaGlJSUlJShoaGhoaGvr6+vr7y8vLy8ysrKysrX19fX19fl5eXl5fLy8vLy//////8AAAA5TEFNRTM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qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");var js=i(()=>(()=>{let e=new(window.AudioContext||window.webkitAudioContext),n=e.createGain();n.connect(e.destination);let r=new rt(si(e));return e.decodeAudioData(Is.buffer.slice(0)).then(o=>{r.buf=o}).catch(o=>{console.error("Failed to load burp: ",o)}),{ctx:e,masterNode:n,burpSnd:r}})(),"initAudio");function ks(t,e={}){let n=new ae,r=new Audio(t);r.crossOrigin="anonymous",l.audio.ctx.createMediaElementSource(r).connect(l.audio.masterNode);function s(){l.debug.paused||l.app.isHidden()&&!l.globalOpt.backgroundAudio||l.audio.ctx.resume()}i(s,"resumeAudioCtx");function a(){s(),r.play()}return i(a,"play"),e.paused||a(),r.onended=()=>n.trigger(),{play(){a()},seek(m){r.currentTime=m},stop(){r.pause(),this.seek(0)},set loop(m){r.loop=m},get loop(){return r.loop},set paused(m){m?r.pause():a()},get paused(){return r.paused},time(){return r.currentTime},duration(){return r.duration},set volume(m){r.volume=Me(m,0,1)},get volume(){return r.volume},set speed(m){r.playbackRate=Math.max(m,0)},get speed(){return r.playbackRate},set detune(m){},get detune(){return 0},onEnd(m){return n.add(m)},then(m){return this.onEnd(m)}}}i(ks,"playMusic");function _s(t,e={}){if(typeof t=="string"&&l.assets.music[t])return ks(l.assets.music[t],e);let n=l.audio.ctx,r=e.paused??!1,o=n.createBufferSource(),s=new ae,a=n.createGain(),m=n.createStereoPanner(),u=e.seek??0,p=0,c=0,f=!1;o.loop=!!e.loop,o.detune.value=e.detune??0,o.playbackRate.value=e.speed??1,o.connect(m),o.onended=()=>{h()>=(o.buffer?.duration??Number.POSITIVE_INFINITY)&&s.trigger()},m.pan.value=e.pan??0,m.connect(a),a.connect(l.audio.masterNode),a.gain.value=e.volume??1;let d=i(y=>{o.buffer=y.buf,r||(p=n.currentTime,o.start(0,u),f=!0)},"start"),v=Ui(t);v instanceof ce&&v.onLoad(d);let h=i(()=>{if(!o.buffer)return 0;let y=r?c-p:n.currentTime-p,w=o.buffer.duration;return o.loop?y%w:Math.min(y,w)},"getTime"),O=i(y=>{let w=n.createBufferSource();return w.buffer=y.buffer,w.loop=y.loop,w.playbackRate.value=y.playbackRate.value,w.detune.value=y.detune.value,w.onended=y.onended,w.connect(m),w},"cloneNode");return{stop(){this.paused=!0,this.seek(0)},set paused(y){if(r!==y)if(r=y,y)f&&(o.stop(),f=!1),c=n.currentTime;else{o=O(o);let w=c-p;o.start(0,w),f=!0,p=n.currentTime-w,c=0}},get paused(){return r},play(y=0){this.seek(y),this.paused=!1},seek(y){o.buffer?.duration&&(y>o.buffer.duration||(r?(o=O(o),p=c-y):(o.stop(),o=O(o),p=n.currentTime-y,o.start(0,y),f=!0,c=0)))},set speed(y){o.playbackRate.value=y},get speed(){return o.playbackRate.value},set detune(y){o.detune.value=y},get detune(){return o.detune.value},set volume(y){a.gain.value=Math.max(y,0)},get volume(){return a.gain.value},set pan(y){m.pan.value=y},get pan(){return m.pan.value},set loop(y){o.loop=y},get loop(){return o.loop},duration(){return o.buffer?.duration??0},time(){return h()%this.duration()},onEnd(y){return s.add(y)},then(y){return this.onEnd(y)}}}i(_s,"play");function sr(t){return l.k.play(l.audio.burpSnd,t)}i(sr,"burp");function Ns(t){return t!==void 0&&(l.audio.masterNode.gain.value=t),l.audio.masterNode.gain.value}i(Ns,"volume");function ar(){l.app.onHide(()=>{l.globalOpt.backgroundAudio||l.audio.ctx.suspend()}),l.app.onShow(()=>{!l.globalOpt.backgroundAudio&&!l.debug.paused&&l.audio.ctx.resume()}),l.app.onResize(()=>{if(l.app.isFullscreen())return;let t=l.globalOpt.width&&l.globalOpt.height;t&&!l.globalOpt.stretch&&!l.globalOpt.letterbox||(l.canvas.width=l.canvas.offsetWidth*l.pixelDensity,l.canvas.height=l.canvas.offsetHeight*l.pixelDensity,Xn(),t||(l.gfx.frameBuffer.free(),l.gfx.frameBuffer=new ot(l.gfx.ggl,l.gfx.ggl.gl.drawingBufferWidth,l.gfx.ggl.gl.drawingBufferHeight),l.gfx.width=l.gfx.ggl.gl.drawingBufferWidth/l.pixelDensity/l.gscale,l.gfx.height=l.gfx.ggl.gl.drawingBufferHeight/l.pixelDensity/l.gscale))}),l.globalOpt.debug!==!1&&(l.app.onKeyPress(l.globalOpt.debugKey??"f1",()=>l.debug.inspect=!l.debug.inspect),l.app.onKeyPress("f2",()=>l.debug.clearLog()),l.app.onKeyPress("f8",()=>l.debug.paused=!l.debug.paused),l.app.onKeyPress("f7",()=>{l.debug.timeScale=Zt(Me(l.debug.timeScale-.2,0,2),1)}),l.app.onKeyPress("f9",()=>{l.debug.timeScale=Zt(Me(l.debug.timeScale+.2,0,2),1)}),l.app.onKeyPress("f10",()=>l.debug.stepFrame())),l.globalOpt.burp&&l.app.onKeyPress("b",()=>sr())}i(ar,"initEvents");function Us(t,e={}){let n=l.game.root.add([St(t),ur()]),r=(e.speed||1)*5,o=e.scale||1;n.add([fn(l.boomSprite),Nt(0),hn("center"),Zr(r,o),...e.comps??[]]);let s=n.add([fn(l.kaSprite),Nt(0),hn("center"),gn(),...e.comps??[]]);return s.wait(.4/r,()=>s.use(Zr(r,o))),s.onDestroy(()=>n.destroy()),n}i(Us,"addKaboom");var Hs=i(function(t,e){if(l.game.layers)throw Error("Layers can only be assigned once.");let n=t.indexOf(e);if(n==-1)throw Error("The default layer name should be present in the layers list.");l.game.layers=t,l.game.defaultLayerIndex=n},"layers");function nr(t){t.destroy()}i(nr,"destroy");function qs(){return l.game.root}i(qs,"getTreeRoot");function zs(t,e){l.game.scenes[t]=e}i(zs,"scene");function Ys(t,...e){if(!l.game.scenes[t])throw new Error(`Scene not found: ${t}`);l.game.events.onOnce("frameEnd",()=>{l.game.events.trigger("sceneLeave",t),l.app.events.clear(),l.game.events.clear(),l.game.objEvents.clear(),[...l.game.root.children].forEach(n=>{!n.stay||n.scenesToStay&&!n.scenesToStay.includes(t)?l.game.root.remove(n):n.trigger("sceneEnter",t)}),l.game.root.clearEvents(),ar(),l.game.cam={pos:null,scale:x(1),angle:0,shake:0,transform:new he},l.game.scenes[t](...e)}),l.game.currentScene=t}i(Ys,"go");function Ws(t){return l.game.events.on("sceneLeave",t)}i(Ws,"onSceneLeave");function $s(){return l.game.currentScene}i($s,"getSceneName");function fn(t,e={}){let n=null,r=null,o=null,s=new ae;if(!t)throw new Error("Please pass the resource name or data to sprite()");let a=i((u,p,c,f)=>{let d=x(1,1);return c&&f?(d.x=c/(u.width*p.w),d.y=f/(u.height*p.h)):c?(d.x=c/(u.width*p.w),d.y=d.x):f&&(d.y=f/(u.height*p.h),d.x=d.y),d},"calcTexScale"),m=i((u,p)=>{if(!p)return;let c=p.frames[0].clone();e.quad&&(c=c.scale(e.quad));let f=a(p.tex,c,e.width,e.height);u.width=p.tex.width*c.w*f.x,u.height=p.tex.height*c.h*f.y,e.anim&&u.play(e.anim),n=p,s.trigger(n)},"setSpriteData");return{id:"sprite",width:0,height:0,frame:e.frame||0,quad:e.quad||new z(0,0,1,1),animSpeed:e.animSpeed??1,flipX:e.flipX??!1,flipY:e.flipY??!1,get sprite(){return t.toString()},set sprite(u){let p=It(u);p&&p.onLoad(c=>m(this,c))},get animFrame(){if(!n||!r||o===null)return this.frame;let u=n.anims[r.name];return typeof u=="number"?u:this.frame-Math.min(u.from,u.to)},draw(){if(!n)return;let u=n.frames[this.frame??0];if(!u)throw new Error(`Frame not found: ${this.frame??0}`);if(n.slice9){let{left:p,right:c,top:f,bottom:d}=n.slice9,v=n.tex.width*u.w,h=n.tex.height*u.h,O=this.width-p-c,y=this.height-f-d,w=p/v,V=c/v,R=1-w-V,P=f/h,D=d/h,b=1-P-D,E=[le(0,0,w,P),le(w,0,R,P),le(w+R,0,V,P),le(0,P,w,b),le(w,P,R,b),le(w+R,P,V,b),le(0,P+b,w,D),le(w,P+b,R,D),le(w+R,P+b,V,D),le(0,0,p,f),le(p,0,O,f),le(p+O,0,c,f),le(0,f,p,y),le(p,f,O,y),le(p+O,f,c,y),le(0,f+y,p,d),le(p,f+y,O,d),le(p+O,f+y,c,d)];for(let A=0;A<9;A++){let G=E[A],M=E[A+9];At(Object.assign(Ke(this),{pos:M.pos(),tex:n.tex,quad:u.scale(G),flipX:this.flipX,flipY:this.flipY,tiled:e.tiled,width:M.w,height:M.h}))}}else At(Object.assign(Ke(this),{tex:n.tex,quad:u.scale(this.quad??new z(0,0,1,1)),flipX:this.flipX,flipY:this.flipY,tiled:e.tiled,width:this.width,height:this.height}))},add(){let u=It(t);u?u.onLoad(p=>m(this,p)):_t(()=>m(this,It(t).data))},update(){if(!n||!r||o===null)return;let u=n.anims[r.name];if(typeof u=="number"){this.frame=u;return}if(u.speed===0)throw new Error("Sprite anim speed cannot be 0");r.timer+=te()*this.animSpeed,r.timer>=1/r.speed&&(r.timer=0,this.frame+=o,(this.frameMath.max(u.from,u.to))&&(r.loop?r.pingpong?(this.frame-=o,o*=-1,this.frame+=o):this.frame=u.from:r.pingpong?o===Math.sign(u.to-u.from)?(this.frame=u.to,o*=-1,this.frame+=o):(this.frame=u.from,r.onEnd(),this.stop()):(this.frame=u.to,r.onEnd(),this.stop())))},play(u,p={}){if(!n){s.add(()=>this.play(u,p));return}let c=n.anims[u];if(c===void 0)throw new Error(`Anim not found: ${u}`);r&&this.stop(),r=typeof c=="number"?{name:u,timer:0,loop:!1,pingpong:!1,speed:0,onEnd:i(()=>{},"onEnd")}:{name:u,timer:0,loop:p.loop??c.loop??!1,pingpong:p.pingpong??c.pingpong??!1,speed:p.speed??c.speed??10,onEnd:p.onEnd??(()=>{})},o=typeof c=="number"?null:c.fromn(this))},draw(){He(n(this))},renderArea(){return new W(x(0),this.width,this.height)}};return n(r),r}i(Xs,"text");function Qs(t,e){return{id:"rect",width:t,height:e,draw(){it(Object.assign(Ke(this),{width:this.width,height:this.height}))},renderArea(){return new W(x(0),this.width,this.height)},inspect(){return`uvquad: (${Math.ceil(this.width)}w, ${Math.ceil(this.height)})h`}}}i(Qs,"uvquad");function Js(t={}){let e=null,n=null,r=null,o=null;return{id:"agent",require:["pos","tile"],agentSpeed:t.speed??100,allowDiagonals:t.allowDiagonals??!0,getDistanceToTarget(){return e?this.pos.dist(e):0},getNextLocation(){return n&&r?n[r]:null},getPath(){return n?n.slice():null},getTarget(){return e},isNavigationFinished(){return n?r===null:!0},isTargetReachable(){return n!==null},isTargetReached(){return e?this.pos.eq(e):!0},setTarget(s){e=s,n=this.getLevel().getPath(this.pos,e,{allowDiagonals:this.allowDiagonals}),r=n?0:null,n&&r!==null?(o||(o=this.getLevel().onNavigationMapChanged(()=>{e&&n&&r!==null&&(n=this.getLevel().getPath(this.pos,e,{allowDiagonals:this.allowDiagonals}),n?(r=0,this.trigger("navigationNext",this,n[r])):(r=null,this.trigger("navigationEnded",this)))}),this.onDestroy(()=>o?.cancel())),this.trigger("navigationStarted",this),this.trigger("navigationNext",this,n[r])):this.trigger("navigationEnded",this)},update(){if(e&&n&&r!==null){if(this.pos.sdist(n[r])<2)if(r===n.length-1){this.pos=e.clone(),r=null,this.trigger("navigationEnded",this),this.trigger("targetReached",this);return}else r++,this.trigger("navigationNext",this,n[r]);this.moveTo(n[r],this.agentSpeed)}},onNavigationStarted(s){return this.on("navigationStarted",s)},onNavigationNext(s){return this.on("navigationNext",s)},onNavigationEnded(s){return this.on("navigationEnded",s)},onTargetReached(s){return this.on("targetReached",s)},inspect(){return"agent: "+JSON.stringify({target:JSON.stringify(e),path:JSON.stringify(n)})}}}i(Js,"agent");function Zs(t){let e=t.graph;return{id:"pathfinder",require:["pos"],navigateTo(n){return this.graph?.getWaypointPath(this.pos,n,t.navigationOpt)},get graph(){if(e)return e;let n=this.parent;for(;n;){if(n.is("pathfinderMap"))return n.graph;n=n.parent}},set graph(n){e=n}}}i(Zs,"pathfinder");function ea(t={}){let e=t.waypoints,n=t.speed||100,r=t.endBehavior||"stop",o=0,s=e!=null;return{id:"patrol",require:["pos"],get patrolSpeed(){return n},set patrolSpeed(a){n=a},get waypoints(){return e},set waypoints(a){e=a,o=0,s=!1},get nextLocation(){return e?e[o]:void 0},update(){let a=this.nextLocation;if(!(!e||!a||s)&&(this.moveTo(a,n),this.pos.sdist(a)<9))switch(r){case"loop":o=(o+1)%e.length;break;case"ping-pong":o=o+1,o==e.length&&(e.reverse(),o=0);break;case"stop":o=Math.min(o+1,e.length-1),o==e.length-1&&(s=!0,this.trigger("patrolFinished"));break}},onPatrolFinished(a){return this.on("patrolFinished",a)}}}i(ea,"patrol");function ta(t,e={}){let n=typeof t=="function"?t:()=>l.game.root.query(t),r=e.checkFrequency||1,o=typeof e.direction=="number"?C.fromAngle(e.direction):e.direction,s=0;return{id:"sentry",require:["pos"],direction:typeof e.direction=="number"?C.fromAngle(e.direction):e.direction,spotted:[],set directionAngle(a){this.direction=a!==void 0?C.fromAngle(a):void 0},get directionAngle(){return this.direction?this.direction.angle():void 0},fieldOfView:e.fieldOfView||200,isWithinFieldOfView(a,m,u){let p=(typeof m=="number"?C.fromAngle(m):m)||o,c=u||e.fieldOfView;if(!p||!c||c>=360)return!0;let f=c/2;return a.pos&&p.angleBetween(a.pos.sub(this.pos))<=f},hasLineOfSight(a){let m=Zn(this.pos,a.pos.sub(this.pos),e.raycastExclude);return m!=null&&m.object===a},update(){if(s+=te(),s>r){s-=r;let a=n();if(a.length&&o&&this.fieldOfView&&this.fieldOfView<360){let m=this.fieldOfView/2;a=a.filter(u=>u.pos&&o.angleBetween(u.pos.sub(this.pos))<=m)}a.length&&e.lineOfSight&&(a=a.filter(m=>m.pos&&this.hasLineOfSight(m))),a.length>0&&(this.spotted=a,this.trigger("objectSpotted",a))}},onObjectsSpotted(a){return this.on("objectSpotted",a)}}}i(ta,"sentry");function or(t={}){let e=x(0),n=t.isObstacle??!1,r=t.cost??0,o=t.edges??[],s=i(()=>{let m={left:1,top:2,right:4,bottom:8};return o.map(u=>m[u]||0).reduce((u,p)=>u|p,0)},"getEdgeMask"),a=s();return{id:"tile",tilePosOffset:t.offset??x(0),set tilePos(m){let u=this.getLevel();e=m.clone(),this.pos=x(this.tilePos.x*u.tileWidth(),this.tilePos.y*u.tileHeight()).add(this.tilePosOffset)},get tilePos(){return e},set isObstacle(m){n!==m&&(n=m,this.getLevel().invalidateNavigationMap())},get isObstacle(){return n},set cost(m){r!==m&&(r=m,this.getLevel().invalidateNavigationMap())},get cost(){return r},set edges(m){o=m,a=s(),this.getLevel().invalidateNavigationMap()},get edges(){return o},get edgeMask(){return a},getLevel(){return this.parent},moveLeft(){this.tilePos=this.tilePos.add(x(-1,0))},moveRight(){this.tilePos=this.tilePos.add(x(1,0))},moveUp(){this.tilePos=this.tilePos.add(x(0,-1))},moveDown(){this.tilePos=this.tilePos.add(x(0,1))}}}i(or,"tile");var bn=class{static{i(this,"AnimateChannel")}name;duration;loops;direction;easing;interpolation;isFinished;timing;easings;relative;constructor(e,n,r){this.name=e,this.duration=n.duration,this.loops=n.loops||0,this.direction=n.direction||"forward",this.easing=n.easing||tt.linear,this.interpolation=n.interpolation||"linear",this.isFinished=!1,this.timing=n.timing,this.easings=n.easings,this.relative=r}update(e,n){return!0}getLowerKeyIndexAndRelativeTime(e,n,r){let o=n-1,s=e/this.duration;if(this.loops!==0&&s>=this.loops)return[o,0];let a=Math.trunc(s);if(s-=a,(this.direction=="reverse"||this.direction=="ping-pong"&&a&1)&&(s=1-s),r){let m=0;for(;r[m+1]!==void 0&&r[m+1]=o?[o,0]:[m,(s-r[m])/(r[m+1]-r[m])]}else{let m=Math.floor((n-1)*s);return[m,(s-m/o)*o]}}setValue(e,n,r){if(this.relative)switch(n){case"pos":e.pos=e.base.pos.add(r);break;case"angle":e.angle=e.base.angle+r;break;case"scale":e.scale=e.base.scale.scale(r);break;case"opacity":e.opacity=e.base.opacity*r;break;default:e[n]=r}else e[n]=r}serialize(){let e={duration:this.duration,keys:[]};return this.loops&&(e.loops=this.loops),this.direction!=="forward"&&(e.direction=this.direction),this.easing!=tt.linear&&(e.easing=this.easing.name),this.interpolation!=="linear"&&(e.interpolation=this.interpolation),this.timing&&(e.timing=this.timing),this.easings&&(e.easings=this.easings.map(n=>this.easing.name)),e}};function na(t,e){return e.add(e.sub(t))}i(na,"reflect");var eo=class extends bn{static{i(this,"AnimateChannelNumber")}keys;constructor(e,n,r,o){super(e,r,o),this.keys=n}update(e,n){let[r,o]=this.getLowerKeyIndexAndRelativeTime(n,this.keys.length,this.timing);if(o==0||this.interpolation==="none")this.setValue(e,this.name,this.keys[r]);else{let s=this.easings?this.easings[r]:this.easing;this.setValue(e,this.name,fe(this.keys[r],this.keys[r+1],s(o)))}return o==1}serialize(){return Object.assign(super.serialize(),{keys:this.keys})}},to=class extends bn{static{i(this,"AnimateChannelVec2")}keys;curves;dcurves;constructor(e,n,r,o,s){if(super(e,r,o),this.keys=n,this.interpolation==="spline"){this.curves=[],s&&(this.dcurves=[]);for(let a=0;a0?this.keys[a-1]:na(p,m),f=u[e.x,e.y])})}},no=class extends bn{static{i(this,"AnimateChannelColor")}keys;constructor(e,n,r,o){super(e,r,o),this.keys=n}update(e,n){let[r,o]=this.getLowerKeyIndexAndRelativeTime(n,this.keys.length,this.timing);if(o==0||this.interpolation=="none")this.setValue(e,this.name,this.keys[r]);else{let s=this.easings?this.easings[r]:this.easing;this.setValue(e,this.name,this.keys[r].lerp(this.keys[r+1],s(o)))}return o==1}serialize(){return Object.assign(super.serialize(),{keys:this.keys})}};function ra(t={}){let e=[],n=0,r=!1;return{id:"animate",require:t.followMotion?["rotate"]:void 0,base:{pos:x(0,0),angle:0,scale:x(1,1),opacity:1},add(){t.relative&&(this.is("pos")&&(this.base.pos=this.pos.clone()),this.is("rotate")&&(this.base.angle=this.angle),this.is("scale")&&(this.base.scale=this.scale),this.is("opacity")&&(this.base.opacity=this.opacity))},update(){let o=!0,s;n+=te();for(let a of e)s=a.update(this,n),s&&!a.isFinished&&(a.isFinished=!0,this.trigger("animateChannelFinished",a.name)),o&&=s;o&&!r&&(r=!0,this.trigger("animateFinished"))},animate(o,s,a){r=!1,this.unanimate(o),typeof s[0]=="number"?e.push(new eo(o,s,a,t.relative||!1)):s[0]instanceof C?e.push(new to(o,s,a,t.relative||!1,o==="pos"&&(t.followMotion||!1))):s[0]instanceof I&&e.push(new no(o,s,a,t.relative||!1))},unanimate(o){let s=e.findIndex(a=>a.name===o);s>=0&&e.splice(s,1)},unanimateAll(){e.splice(0,e.length)},onAnimateFinished(o){return this.on("animateFinished",o)},onAnimateChannelFinished(o){return this.on("animateChannelFinished",o)},serializeAnimationChannels(){return e.reduce((o,s)=>(o[s.name]=s.serialize(),o),{})},serializeAnimationOptions(){let o={};return t.followMotion&&(o.followMotion=!0),t.relative&&(o.relative=!0),o}}}i(ra,"animate");function ro(t,e){let n={name:t.name};return t.is("animate")&&(n.channels=t.serializeAnimationChannels(),Object.assign(n,t.serializeAnimationOptions())),t.children.length>0&&(n.children=t.children.filter(r=>r.is("named")).map(r=>ro(r,r.name))),n}i(ro,"serializeAnimation");function Zr(t=2,e=1){let n=0;return{require:["scale"],update(){let r=Math.sin(n*t)*e;r<0&&this.destroy(),this.scale=x(r),n+=te()}}}i(Zr,"boom");function oa(t,e){if(t==null)throw new Error("health() requires the initial amount of hp");return{id:"health",hurt(n=1){this.setHP(t-n),this.trigger("hurt",n)},heal(n=1){let r=t;this.setHP(t+n),this.trigger("heal",t-r)},hp(){return t},maxHP(){return e??null},setMaxHP(n){e=n},setHP(n){t=e?Math.min(e,n):n,t<=0&&this.trigger("death")},onHurt(n){return this.on("hurt",n)},onHeal(n){return this.on("heal",n)},onDeath(n){return this.on("death",n)},inspect(){return`health: ${t}`}}}i(oa,"health");function ia(t,e={}){if(t==null)throw new Error("lifespan() requires time");let n=e.fade??0;return{id:"lifespan",require:["opacity"],async add(){await l.game.root.wait(t),this.opacity=this.opacity??1,n>0&&await l.game.root.tween(this.opacity,0,n,r=>this.opacity=r,tt.linear),this.destroy()}}}i(ia,"lifespan");function sa(t){return{id:"named",name:t}}i(sa,"named");function aa(t,e,n){if(!t)throw new Error("state() requires an initial state");let r={};function o(u){r[u]||(r[u]={enter:new ae,end:new ae,update:new ae,draw:new ae})}i(o,"initStateEvents");function s(u,p,c){return o(p),r[p][u].add(c)}i(s,"on");function a(u,p,...c){o(p),r[p][u].trigger(...c)}i(a,"trigger");let m=!1;return{id:"state",state:t,enterState(u,...p){if(m=!0,e&&!e.includes(u))throw new Error(`State not found: ${u}`);let c=this.state;if(n){if(!n?.[c])return;let f=typeof n[c]=="string"?[n[c]]:n[c];if(!f.includes(u))throw new Error(`Cannot transition state from "${c}" to "${u}". Available transitions: ${f.map(d=>`"${d}"`).join(", ")}`)}a("end",c,...p),this.state=u,a("enter",u,...p),a("enter",`${c} -> ${u}`,...p)},onStateTransition(u,p,c){return s("enter",`${u} -> ${p}`,c)},onStateEnter(u,p){return s("enter",u,p)},onStateUpdate(u,p){return s("update",u,p)},onStateDraw(u,p){return s("draw",u,p)},onStateEnd(u,p){return s("end",u,p)},update(){m||(a("enter",t),m=!0),a("update",this.state)},draw(){a("draw",this.state)},inspect(){return`state: ${this.state}`}}}i(aa,"state");function ur(t){return{id:"stay",stay:!0,scenesToStay:t}}i(ur,"stay");function ua(t=!0,e){let n,r;return{id:"textInput",hasFocus:t,require:["text"],add(){n=l.k.onCharInput(o=>{this.hasFocus&&(!e||this.text.length{this.hasFocus&&(this.text=this.text.slice(0,-1))})},destroy(){n.cancel(),r.cancel()}}}i(ua,"textInput");function gn(){return{id:"timer",wait(t,e){let n=[];e&&n.push(e);let r=0,o=this.onUpdate(()=>{r+=l.app.state.dt,r>=t&&(n.forEach(s=>s()),o.cancel())});return{get paused(){return o.paused},set paused(s){o.paused=s},cancel:o.cancel,onEnd(s){n.push(s)},then(s){return this.onEnd(s),this}}},loop(t,e){let n=null,r=i(()=>{n=this.wait(t,r),e()},"newAction");return n=this.wait(0,r),{get paused(){return n?.paused??!1},set paused(o){n&&(n.paused=o)},cancel:i(()=>n?.cancel(),"cancel")}},tween(t,e,n,r,o=tt.linear){let s=0,a=[],m=this.onUpdate(()=>{s+=l.app.state.dt;let u=Math.min(s/n,1);r(fe(t,e,o(u))),u===1&&(m.cancel(),r(e),a.forEach(p=>p()))});return{get paused(){return m.paused},set paused(u){m.paused=u},onEnd(u){a.push(u)},then(u){return this.onEnd(u),this},cancel(){m.cancel()},finish(){m.cancel(),r(e),a.forEach(u=>u())}}}}}i(gn,"timer");var oo=0;function ca(){return oo>0}i(ca,"usesArea");function la(t={}){let e={},n=new Set;return{id:"area",collisionIgnore:t.collisionIgnore??[],add(){oo++,this.area.cursor&&this.onHover(()=>l.app.setCursor(this.area.cursor)),this.onCollideUpdate((r,o)=>{if(!r.id)throw new Error("area() requires the object to have an id");e[r.id]||this.trigger("collide",r,o),o&&(e[r.id]=o,n.add(r.id))})},destroy(){oo--},fixedUpdate(){for(let r in e)n.has(Number(r))||(this.trigger("collideEnd",e[r].target),delete e[r]);n.clear()},drawInspect(){let r=this.localArea();be(),Q(this.area.offset);let o={outline:{width:4/jn(),color:_(0,0,255)},anchor:this.anchor,fill:!1,fixed:st(this)};r instanceof W?ve({...o,pos:r.pos,width:r.width*this.area.scale.x,height:r.height*this.area.scale.y}):r instanceof ye?Pe({...o,pts:r.pts,scale:this.area.scale}):r instanceof Ce&&Ne({...o,pos:r.center,radius:r.radius}),pe()},area:{shape:t.shape??null,scale:t.scale?x(t.scale):x(1),offset:t.offset??x(0),cursor:t.cursor??null},isClicked(){return l.app.isMousePressed()&&this.isHovering()},isHovering(){let r=st(this)?l.k.mousePos():l.k.toWorld(l.k.mousePos());return this.hasPoint(r)},checkCollision(r){if(!r.id)throw new Error("checkCollision() requires the object to have an id");return e[r.id]??null},getCollisions(){return Object.values(e)},isColliding(r){if(!r.id)throw new Error("isColliding() requires the object to have an id");return!!e[r.id]},isOverlapping(r){if(!r.id)throw new Error("isOverlapping() requires the object to have an id");let o=e[r.id];return o&&o.hasOverlap()},onClick(r,o="left"){let s=l.app.onMousePress(o,()=>{this.isHovering()&&r()});return this.onDestroy(()=>s.cancel()),s},onHover(r){let o=!1;return this.onUpdate(()=>{o?o=this.isHovering():this.isHovering()&&(o=!0,r())})},onHoverUpdate(r){return this.onUpdate(()=>{this.isHovering()&&r()})},onHoverEnd(r){let o=!1;return this.onUpdate(()=>{o?this.isHovering()||(o=!1,r()):o=this.isHovering()})},onCollide(r,o){if(typeof r=="function"&&o===void 0)return this.on("collide",r);if(typeof r=="string")return this.onCollide((s,a)=>{s.is(r)&&o?.(s,a)});throw new Error("onCollide() requires either a function or a tag")},onCollideUpdate(r,o){if(typeof r=="function"&&o===void 0)return this.on("collideUpdate",r);if(typeof r=="string")return this.on("collideUpdate",(s,a)=>s.is(r)&&o?.(s,a));throw new Error("onCollideUpdate() requires either a function or a tag")},onCollideEnd(r,o){if(typeof r=="function"&&o===void 0)return this.on("collideEnd",r);if(typeof r=="string")return this.on("collideEnd",s=>s.is(r)&&o?.(s));throw new Error("onCollideEnd() requires either a function or a tag")},hasPoint(r){return et(this.worldArea(),r)},resolveCollision(r){let o=this.checkCollision(r);o&&!o.resolved&&(this.pos=this.pos.add(o.displacement),o.resolved=!0)},localArea(){return this.area.shape?this.area.shape:this.renderArea()},worldArea(){let r=this.localArea();if(!(r instanceof ye||r instanceof W))throw new Error("Only support polygon and rect shapes for now");let o=this.transform.clone().translate(this.area.offset).scale(x(this.area.scale??1));if(r instanceof W){let s=_e(this.anchor||pt).add(1,1).scale(-.5).scale(r.width,r.height);o.translate(s)}return r.transform(o)},screenArea(){let r=this.worldArea();return st(this)?r:r.transform(l.game.cam.transform)},inspect(){return this.area.scale?.x==this.area.scale?.y?`area: ${this.area.scale?.x?.toFixed(1)}x`:`area: (${this.area.scale?.x?.toFixed(1)}x, ${this.area.scale.y?.toFixed(1)}y)`}}}i(la,"area");function ma(t={}){let e=null,n=null,r=!1,o=x(0),s=null,a=null,m;return{id:"body",require:["pos"],vel:x(0),drag:t.drag??0,jumpForce:t.jumpForce??Ei,gravityScale:t.gravityScale??1,isStatic:t.isStatic??!1,mass:t.mass??1,add(){if(s=this.pos.clone(),a=this.pos.clone(),m=this.pos.clone(),this.mass===0)throw new Error("Can't set body mass to 0");this.is("area")&&(this.onCollideUpdate((u,p)=>{if(!p||!u.is("body")||p.resolved)return;this.trigger("beforePhysicsResolve",p);let c=p.reverse();if(u.trigger("beforePhysicsResolve",c),!(p.resolved||c.resolved)&&!(this.isStatic&&u.isStatic)){if(!this.isStatic&&!u.isStatic){let f=this.mass+u.mass;this.pos=this.pos.add(p.displacement.scale(u.mass/f)),u.pos=u.pos.add(p.displacement.scale(-this.mass/f)),this.transform=mt(this),u.transform=mt(u)}else{let f=!this.isStatic&&u.isStatic?p:p.reverse();f.source.pos=f.source.pos.add(f.displacement),f.source.transform=mt(f.source)}p.resolved=!0,this.trigger("physicsResolve",p),u.trigger("physicsResolve",p.reverse())}}),this.onPhysicsResolve(u=>{if(l.game.gravity)if(u.isBottom()&&this.isFalling()){this.vel=this.vel.reject(l.game.gravity.unit());let p=e;e=u.target,p!=e&&(n=u.target.pos),r?r=!1:p||(this.trigger("ground",e),u.target.trigger("land",this))}else u.isTop()&&this.isJumping()&&(this.vel=this.vel.reject(l.game.gravity.unit()),this.trigger("headbutt",u.target),u.target.trigger("headbutted",this))}))},update(){e&&this.isColliding(e)&&e.exists()&&e.is("body")&&(n&&!e.pos.eq(n)&&t.stickToPlatform!==!1&&this.moveBy(e.pos.sub(n)),n=e.pos);let u=nn();u&&(this.pos.x==m.x&&(this.pos.x=fe(s.x,a.x,u/tn()),m.x=this.pos.x),this.pos.y==m.y&&(this.pos.y=fe(s.y,a.y,u/tn()),m.y=this.pos.y))},fixedUpdate(){if(s&&(this.pos.x==m.x&&(this.pos.x=s.x),this.pos.y==m.y&&(this.pos.y=s.y),s=null),l.game.gravity&&!this.isStatic){r&&(e=null,n=null,this.trigger("fallOff"),r=!1),e&&(!this.isColliding(e)||!e.exists()||!e.is("body"))&&(r=!0);let p=this.vel.clone();this.vel=this.vel.add(l.game.gravity.scale(this.gravityScale*te()));let c=t.maxVelocity??Ti;this.vel.slen()>c*c&&(this.vel=this.vel.unit().scale(c)),p.dot(l.game.gravity)<0&&this.vel.dot(l.game.gravity)>=0&&this.trigger("fall")}if(this.vel.x+=o.x*te(),this.vel.y+=o.y*te(),this.vel.x*=1-this.drag*te(),this.vel.y*=1-this.drag*te(),this.move(this.vel),nn()){s=this.pos.clone();let p=this.vel.add(o.scale(te()));a=this.pos.add(p.scale(te())),m=this.pos.clone()}o.x=0,o.y=0},onPhysicsResolve(u){return this.on("physicsResolve",u)},onBeforePhysicsResolve(u){return this.on("beforePhysicsResolve",u)},curPlatform(){return e},isGrounded(){return e!==null},isFalling(){return this.vel.dot(Vt())>0},isJumping(){return this.vel.dot(Vt())<0},applyImpulse(u){this.vel=this.vel.add(u)},addForce(u){o.x+=u.x/this.mass,o.y+=u.y/this.mass},jump(u){e=null,n=null,this.vel=Vt().scale(-u||-this.jumpForce)},onGround(u){return this.on("ground",u)},onFall(u){return this.on("fall",u)},onFallOff(u){return this.on("fallOff",u)},onHeadbutt(u){return this.on("headbutt",u)},onLand(u){return this.on("land",u)},onHeadbutted(u){return this.on("headbutted",u)},inspect(){return`gravityScale: ${this.gravityScale}x`}}}i(ma,"body");function pa(t=2){let e=t;return{id:"doubleJump",require:["body"],numJumps:t,add(){this.onGround(()=>{e=this.numJumps})},doubleJump(n){e<=0||(e{let r=n?.normal.normal(),o=e.vel.project(r),a=r?.scale(this.speed)?.sub(o);e.addForce(a?.scale(e.mass*this.forceScale))})}}}i(da,"surfaceEffector");function fa(t){return{id:"areaEffector",require:["area"],useGlobalAngle:t.useGlobalAngle||!1,forceAngle:t.forceAngle,forceMagnitude:t.forceMagnitude,forceVariation:t.forceVariation??0,linearDrag:t.linearDrag??0,add(){this.onCollideUpdate("body",(e,n)=>{let o=C.fromAngle(this.forceAngle).scale(this.forceMagnitude);e.addForce(o),this.linearDrag&&e.addForce(e.vel.scale(-this.linearDrag))})}}}i(fa,"areaEffector");function ha(t){return{id:"pointEffector",require:["area","pos"],forceMagnitude:t.forceMagnitude,forceVariation:t.forceVariation??0,distanceScale:t.distanceScale??1,forceMode:t.forceMode||"inverseLinear",linearDrag:t.linearDrag??0,add(){this.onCollideUpdate("body",(e,n)=>{let r=this.pos.sub(e.pos),o=r.len(),s=o*this.distanceScale/10,a=this.forceMode==="constant"?1:this.forceMode==="inverseLinear"?1/s:1/s**2,m=r.scale(this.forceMagnitude*a/o);e.addForce(m),this.linearDrag&&e.addForce(e.vel.scale(-this.linearDrag))})}}}i(ha,"pointEffector");function ga(t){return{id:"constantForce",require:["body"],force:t.force,update(){this.force&&this.addForce(this.force)}}}i(ga,"constantForce");function ba(t){return{id:"buoyancyEffector",require:["area"],surfaceLevel:t.surfaceLevel,density:t.density??1,linearDrag:t.linearDrag??1,angularDrag:t.angularDrag??.2,flowAngle:t.flowAngle??0,flowMagnitude:t.flowMagnitude??0,flowVariation:t.flowVariation??0,add(){this.onCollideUpdate("body",(e,n)=>{let r=e,o=r.worldArea(),[s,a]=o.cut(x(-100,this.surfaceLevel),x(100,this.surfaceLevel));s&&(this.applyBuoyancy(r,s),this.applyDrag(r,s)),this.flowMagnitude&&r.addForce(C.fromAngle(this.flowAngle).scale(this.flowMagnitude))})},applyBuoyancy(e,n){let r=this.density*n.area(),o=x(0,1).scale(-r);e.addForce(o)},applyDrag(e,n){let r=e.vel,o=this.density*this.linearDrag,s=r.scale(-o);e.addForce(s)}}}i(ba,"buoyancyEffector");function hn(t){if(!t)throw new Error("Please define an anchor");return{id:"anchor",anchor:t,inspect(){return typeof this.anchor=="string"?"anchor: "+this.anchor:"anchor: "+this.anchor.toString()}}}i(hn,"anchor");function rr(){return{id:"fixed",fixed:!0}}i(rr,"fixed");function ya(t,e){return{id:"follow",require:["pos"],follow:{obj:t,offset:e??x(0)},add(){t.exists()&&(this.pos=this.follow.obj.pos.add(this.follow.offset))},update(){t.exists()&&(this.pos=this.follow.obj.pos.add(this.follow.offset))}}}i(ya,"follow");function xa(t){let e=l.game.layers?.indexOf(t);return{id:"layer",get layerIndex(){return e??null},get layer(){return e?l.game.layers?.[e]??null:null},set layer(n){if(e=l.game.layers?.indexOf(n),e==-1)throw Error("Invalid layer name")},inspect(){return`layer: ${this.layer}`}}}i(xa,"layer");function va(t,e){let n=typeof t=="number"?C.fromAngle(t):t.unit();return{id:"move",require:["pos"],update(){this.move(n.scale(e))}}}i(va,"move");function wa(t={}){let e=t.distance??Oi,n=!1;return{id:"offscreen",require:["pos"],isOffScreen(){let r=this.screenPos();if(!r)return!1;let o=new W(x(0),ie(),ue());return!Dt(o,r)&&o.sdistToPoint(r)>e*e},onExitScreen(r){return this.on("exitView",r)},onEnterScreen(r){return this.on("enterView",r)},update(){this.isOffScreen()?(n||(this.trigger("exitView"),n=!0),t.hide&&(this.hidden=!0),t.pause&&(this.paused=!0),t.destroy&&this.destroy()):(n&&(this.trigger("enterView"),n=!1),t.hide&&(this.hidden=!1),t.pause&&(this.paused=!1))}}}i(wa,"offscreen");function St(...t){return{id:"pos",pos:x(...t),moveBy(...e){this.pos=this.pos.add(x(...e))},move(...e){this.moveBy(x(...e).scale(te()))},moveTo(...e){if(typeof e[0]=="number"&&typeof e[1]=="number")return this.moveTo(x(e[0],e[1]),e[2]);let n=e[0],r=e[1];if(r===void 0){this.pos=x(n);return}let o=n.sub(this.pos);if(o.len()<=r*te()){this.pos=x(n);return}this.move(o.unit().scale(r))},worldPos(e=null){return e?(this.pos=this.pos.add(this.fromWorld(e)),null):this.parent?this.parent.transform.multVec2(this.pos):this.pos},toWorld(e){return this.parent?this.parent.transform.multVec2(this.pos.add(e)):this.pos.add(e)},fromWorld(e){return this.parent?this.parent.transform.invert().multVec2(e).sub(this.pos):e.sub(this.pos)},screenPos(e=null){if(e)return this.pos=this.pos.add(this.fromScreen(e)),null;{let n=this.worldPos();return n?st(this)?n:pn(n):null}},toScreen(e){let n=this.toWorld(e);return st(this)?n:pn(n)},fromScreen(e){return st(this)?this.fromWorld(e):this.fromWorld(tr(e))},toOther(e,n){return e.fromWorld(this.toWorld(n))},fromOther(e,n){return e.toOther(this,n)},inspect(){return`pos: (${Math.round(this.pos.x)}x, ${Math.round(this.pos.y)}y)`},drawInspect(){Ne({color:_(255,0,0),radius:4/jn()})}}}i(St,"pos");function Ca(t){return{id:"rotate",angle:t??0,rotateBy(e){this.angle+=e},rotateTo(e){this.angle=e},inspect(){return`angle: ${Math.round(this.angle)}`}}}i(Ca,"rotate");function Nt(...t){if(t.length===0)return Nt(1);let e=x(...t);return{id:"scale",set scale(n){if(!(n instanceof C))throw Error("The scale property on scale is a vector. Use scaleTo or scaleBy to set the scale with a number.");e=x(n)},get scale(){return e},scaleTo(...n){e=x(...n)},scaleBy(...n){e=e.scale(x(...n))},inspect(){return e.x==e.y?`scale: ${e.x.toFixed(1)}x`:`scale: (${e.x.toFixed(1)}x, ${e.y.toFixed(1)}y)`}}}i(Nt,"scale");function Oa(t){return{id:"z",z:t,inspect(){return`z: ${this.z}`}}}i(Oa,"z");var Ea="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAACDCAYAAAB2kQxsAAAAAXNSR0IArs4c6QAABqxJREFUeJztnU1yFDkQRtMEB+AG7Fk6fBPO6ZsQLGc/N5gbMAtosJvqKv2kpPxS763A0W5XSXqVqZ+SngzgF58/fflx/7N///vnacW1gBkFD2Z2LOYNBF3Dx9UXAGs5kxLWwhNxU2qlJHrOhwLfkNZoiaBzIa3dCFJYLXgSboKXmETPeVDQyamR8vX55fe/v37/9vBzCDoH0tqktEpZ+t0IOh4KOBm16euZmETPtVDAiRgRLRF0HRRuEkrFrE1hzR4Lipxj+bD6AqCPz5++/Bgp5tXfdv1CeAdPPmFmSkn0nE+a0drdFm6XiOkdKWEuKRptTXqlLuqqFNaM6Dkb+T5nbb+npo8WjZVinqFant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jINUEqFcAS4+rV480WlwRWXe07dLa0YGvfl9kmbTvPZJ1TXGvn4t4yuRp+2aMgk27wkm63DIztU3vOVfueC8wK4zKWtK0M+nvJXmOdlt65MgFFCva06qsKz044SvjIiN5TjLaaHxhtNyyouXBGZ1WSn66Ivt+M7pRZAWoZsDq+t2emeM1am/WtHxFG9runrO1/n1CxLK7CilxJM/H4bwuTJJBvWtgvm0gcNu01uvpd8la1soLE7xkpYDea4Ot6W3GOSzRc3o/qHw2M9qmXWA+uw+jbd0hyO9Yz0+vJ9QGcO/8ZV2YUqYVPN8dImXp3aJ/w1XTGGYfKZN+P7IXiXqO1uINLzFOm/Pz+BV4C03PNEqpZl//ELXP1ro8nhLyKLPHMyAiXyvh4cMFZ2uyAJXc62gzgJl1nhrSLMEzcLx+5qQnIhgqv6qhTHC2Zmus1tUuowCVDkRU6j0jgiJqhLPSSq2q7wMtMSBkdbcQWjNCq2nMlRrTnajAPP/t+c5Sj3K8VNueQ+pGzaa2MyOb2sZseW2dpL6ZnjMzfeQFt/Fe3XP2WIfGvRY6a569jCJ9TaIlcCS9KQE5p1TP2VrMbwLNDlZEvpE5AkGxh9f2nLO/QOetytIwAnMf6SfS2ns+jaZ6B4i2sWvSvF0HWOAj/aRGNFAaPXbw2rS2Rzr0T/ChshKNM3qd4135BCaqK9VAKy+lAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/4DBC0k0jFtF9wAAAAASUVORK5CYII=";var Nu="3001.0.0",l={k:null,globalOpt:null,gfx:null,game:null,app:null,assets:null,fontCacheCanvas:null,fontCacheC2d:null,debug:null,audio:null,pixelDensity:null,canvas:null,gscale:null,kaSprite:null,boomSprite:null},Sa=i((t={})=>{l.k&&(console.warn("KAPLAY already initialized, you are calling kaplay() multiple times, it may lead bugs!"),l.k.quit()),l.globalOpt=t;let e=t.root??document.body;e===document.body&&(document.body.style.width="100%",document.body.style.height="100%",document.body.style.margin="0px",document.documentElement.style.width="100%",document.documentElement.style.height="100%");let n=t.canvas??e.appendChild(document.createElement("canvas"));l.canvas=n;let r=t.scale??1;l.gscale=r;let o=t.width&&t.height&&!t.stretch&&!t.letterbox;o?(n.width=t.width*r,n.height=t.height*r):(n.width=n.parentElement.offsetWidth,n.height=n.parentElement.offsetHeight);let s=["outline: none","cursor: default"];if(o){let L=n.width,U=n.height;s.push(`width: ${L}px`),s.push(`height: ${U}px`)}else s.push("width: 100%"),s.push("height: 100%");t.crisp&&(s.push("image-rendering: pixelated"),s.push("image-rendering: crisp-edges")),n.style.cssText=s.join(";");let a=t.pixelDensity||1;l.pixelDensity=a,n.width*=a,n.height*=a,n.tabIndex=0;let m=document.createElement("canvas");m.width=256,m.height=256,l.fontCacheCanvas=m;let u=m.getContext("2d",{willReadFrequently:!0});l.fontCacheC2d=u;let p=oi({canvas:n,touchToMouse:t.touchToMouse,gamepads:t.gamepads,pixelDensity:t.pixelDensity,maxFPS:t.maxFPS,buttons:t.buttons});l.app=p;let c=[],f=p.canvas.getContext("webgl",{antialias:!0,depth:!0,stencil:!0,alpha:!0,preserveDrawingBuffer:!0});if(!f)throw new Error("WebGL not supported");let d=f,v=Yi(d,{texFilter:t.texFilter}),h=os(t,v);l.gfx=h;let O=js();l.audio=O;let y=Ri(v);l.assets=y;let w=Bs();l.game=w,w.root.use(gn());function V(L,U){let X=new ot(v,L,U);return{clear:i(()=>X.clear(),"clear"),free:i(()=>X.free(),"free"),toDataURL:i(()=>X.toDataURL(),"toDataURL"),toImageData:i(()=>X.toImageData(),"toImageData"),width:X.width,height:X.height,draw:i(re=>{Oe(),X.bind(),re(),Oe(),X.unbind()},"draw")}}i(V,"makeCanvas");function R(){d.clear(d.COLOR_BUFFER_BIT),h.frameBuffer.bind(),d.clear(d.COLOR_BUFFER_BIT),h.bgColor||qe(()=>{it({width:ie(),height:ue(),quad:new z(0,0,ie()/64,ue()/64),tex:h.bgTex,fixed:!0})}),h.renderer.numDraws=0,h.fixed=!1,h.transformStack.length=0,h.transform=new he}i(R,"frameStart");function P(L,U){h.postShader=L,h.postShaderUniform=U??null}i(P,"usePostEffect");function D(){Oe(),h.lastDrawCalls=h.renderer.numDraws,h.frameBuffer.unbind(),d.viewport(0,0,d.drawingBufferWidth,d.drawingBufferHeight);let L=h.width,U=h.height;h.width=d.drawingBufferWidth/a,h.height=d.drawingBufferHeight/a,At({flipY:!0,tex:h.frameBuffer.tex,pos:new C(h.viewport.x,h.viewport.y),width:h.viewport.width,height:h.viewport.height,shader:h.postShader,uniform:typeof h.postShaderUniform=="function"?h.postShaderUniform():h.postShaderUniform,fixed:!0}),Oe(),h.width=L,h.height=U}i(D,"frameEnd");let b=!1,E={inspect:!1,timeScale:1,showLog:!0,fps:i(()=>p.fps(),"fps"),numFrames:i(()=>p.numFrames(),"numFrames"),stepFrame:Pt,drawCalls:i(()=>h.lastDrawCalls,"drawCalls"),clearLog:i(()=>w.logs=[],"clearLog"),log:i((...L)=>{let U=t.logMax??8,X=L.length>1?L.concat(" ").join(" "):L[0];w.logs.unshift({msg:X,time:p.time()}),w.logs.length>U&&(w.logs=w.logs.slice(0,U))},"log"),error:i(L=>E.log(new Error(L.toString?L.toString():L)),"error"),curRecording:null,numObjects:i(()=>N("*",{recursive:!0}).length,"numObjects"),get paused(){return b},set paused(L){b=L,L?O.ctx.suspend():O.ctx.resume()}};l.debug=E;function A(L,U){try{return JSON.parse(window.localStorage[L])}catch{return U?(G(L,U),U):null}}i(A,"getData");function G(L,U){window.localStorage[L]=JSON.stringify(U)}i(G,"setData");function M(L,...U){let X=L($e),re;typeof X=="function"?re=X(...U)($e):re=X;for(let xe in re)$e[xe]=re[xe],t.global!==!1&&(window[xe]=re[xe]);return $e}i(M,"plug");function F(L){let U=p.canvas.captureStream(L),X=O.ctx.createMediaStreamDestination();O.masterNode.connect(X);let re=new MediaRecorder(U),xe=[];return re.ondataavailable=J=>{J.data.size>0&&xe.push(J.data)},re.onerror=()=>{O.masterNode.disconnect(X),U.getTracks().forEach(J=>J.stop())},re.start(),{resume(){re.resume()},pause(){re.pause()},stop(){return re.stop(),O.masterNode.disconnect(X),U.getTracks().forEach(J=>J.stop()),new Promise(J=>{re.onstop=()=>{J(new Blob(xe,{type:"video/mp4"}))}})},download(J="kaboom.mp4"){this.stop().then(we=>Pr(J,we))}}}i(F,"record");function K(){return document.activeElement===p.canvas}i(K,"isFocused");let H=w.root.add.bind(w.root),q=w.root.readd.bind(w.root),Y=w.root.removeAll.bind(w.root),N=w.root.get.bind(w.root),j=w.root.wait.bind(w.root),Z=w.root.loop.bind(w.root),$=w.root.query.bind(w.root),ee=w.root.tween.bind(w.root),Ee=Ot(null,Ta),k=Ot(null,Ea);l.kaSprite=Ee,l.boomSprite=k;function ft(){w.root.fixedUpdate()}i(ft,"fixedUpdateFrame");function Pt(){w.root.update()}i(Pt,"updateFrame");class Ut{static{i(this,"Collision")}source;target;normal;distance;resolved=!1;constructor(U,X,re,xe,J=!1){this.source=U,this.target=X,this.normal=re,this.distance=xe,this.resolved=J}get displacement(){return this.normal.scale(this.distance)}reverse(){return new Ut(this.target,this.source,this.normal.scale(-1),this.distance,this.resolved)}hasOverlap(){return!this.displacement.isZero()}isLeft(){return this.displacement.cross(w.gravity||x(0,1))>0}isRight(){return this.displacement.cross(w.gravity||x(0,1))<0}isTop(){return this.displacement.dot(w.gravity||x(0,1))>0}isBottom(){return this.displacement.dot(w.gravity||x(0,1))<0}preventResolution(){this.resolved=!0}}function yn(){if(!ca())return;let L={},U=t.hashGridSize||64,X=new he,re=[];function xe(J){if(re.push(X.clone()),J.pos&&X.translate(J.pos),J.scale&&X.scale(J.scale),J.angle&&X.rotate(J.angle),J.transform=X.clone(),J.c("area")&&!J.paused){let we=J,at=we.worldArea().bbox(),mr=Math.floor(at.pos.x/U),pr=Math.floor(at.pos.y/U),dr=Math.ceil((at.pos.x+at.width)/U),fr=Math.ceil((at.pos.y+at.height)/U),wn=new Set;for(let Xe=mr;Xe<=dr;Xe++)for(let ut=pr;ut<=fr;ut++)if(!L[Xe])L[Xe]={},L[Xe][ut]=[we];else if(!L[Xe][ut])L[Xe][ut]=[we];else{let qt=L[Xe][ut];e:for(let Ie of qt){if(Ie.paused||!Ie.exists()||wn.has(Ie.id))continue;for(let Je of we.collisionIgnore)if(Ie.is(Je))continue e;for(let Je of Ie.collisionIgnore)if(we.is(Je))continue e;let zt=_o(we.worldArea(),Ie.worldArea());if(zt){let Je=new Ut(we,Ie,zt.normal,zt.distance);we.trigger("collideUpdate",Ie,Je);let Cn=Je.reverse();Cn.resolved=Je.resolved,Ie.trigger("collideUpdate",we,Cn)}wn.add(Ie.id)}qt.push(we)}}J.children.forEach(xe),X=re.pop()}i(xe,"checkObj"),xe(w.root)}i(yn,"checkFrame");function xn(L){console.error(L),O.ctx.suspend();let U=L.message??String(L)??"Unknown error, check console for more info";p.run(()=>{},()=>{R(),qe(()=>{let xe=ie(),J=ue(),we={size:36,width:xe-32*2,letterSpacing:4,lineSpacing:4,font:vt,fixed:!0};ve({width:xe,height:J,color:_(0,0,255),fixed:!0});let Ht=Ue({...we,text:"Error",pos:x(32),color:_(255,128,0),fixed:!0});He(Ht),Xr({...we,text:U,pos:x(32,32+Ht.height+16),fixed:!0}),pe(),w.events.trigger("error",L)}),D()})}i(xn,"handleErr");function cr(L){c.push(L)}i(cr,"onCleanup");function lr(){w.events.onOnce("frameEnd",()=>{p.quit(),d.clear(d.COLOR_BUFFER_BIT|d.DEPTH_BUFFER_BIT|d.STENCIL_BUFFER_BIT);let L=d.getParameter(d.MAX_TEXTURE_IMAGE_UNITS);for(let U=0;UU())})}i(lr,"quit");let Gt=!0;p.run(()=>{try{y.loaded&&(E.paused||ft(),yn())}catch(L){xn(L)}},(L,U)=>{try{L(),y.loaded||Be()===1&&!Gt&&(y.loaded=!0,w.events.trigger("load")),!y.loaded&&t.loadingScreen!==!1||Gt?(R(),es(),D()):(E.paused||Pt(),yn(),R(),Zi(),t.debug!==!1&&Ji(),D()),Gt&&(Gt=!1),w.events.trigger("frameEnd"),U()}catch(X){xn(X)}}),Xn(),ar();let $e={_k:l,VERSION:Nu,loadRoot:Vi,loadProgress:Be,loadSprite:Ot,loadSpriteAtlas:zr,loadSound:Hi,loadMusic:qi,loadBitmapFont:Ii,loadFont:Li,loadShader:_i,loadShaderURL:Ni,loadAseprite:Fi,loadPedit:ji,loadBean:Bi,loadJSON:Pi,load:cn,getSound:qr,getFont:Nr,getBitmapFont:Nn,getSprite:jr,getShader:Hr,getAsset:Gi,Asset:ce,SpriteData:Fe,SoundData:rt,width:ie,height:ue,center:xt,dt:te,fixedDt:tn,restDt:nn,time:p.time,screenshot:p.screenshot,record:F,isFocused:K,setCursor:p.setCursor,getCursor:p.getCursor,setCursorLocked:p.setCursorLocked,isCursorLocked:p.isCursorLocked,setFullscreen:p.setFullscreen,isFullscreen:p.isFullscreen,isTouchscreen:p.isTouchscreen,onLoad:_t,onLoading:Rs,onResize:Ms,onGamepadConnect:p.onGamepadConnect,onGamepadDisconnect:p.onGamepadDisconnect,onError:Ds,onCleanup:cr,camPos:ds,camScale:fs,camFlash:gs,camRot:hs,camTransform:bs,shake:ys,toScreen:pn,toWorld:tr,setGravity:Fs,getGravity:Ls,setGravityDirection:Ks,getGravityDirection:Vt,setBackground:mi,getBackground:pi,getGamepads:p.getGamepads,getTreeRoot:qs,add:H,make:dn,destroy:nr,destroyAll:Y,get:N,query:$,readd:q,pos:St,scale:Nt,rotate:Ca,color:Qn,opacity:Jn,anchor:hn,area:la,sprite:fn,text:Xs,polygon:ms,rect:er,circle:is,uvquad:Qs,outline:cs,particles:ls,body:ma,surfaceEffector:da,areaEffector:fa,pointEffector:ha,buoyancyEffector:ba,constantForce:ga,doubleJump:pa,shader:ps,textInput:ua,timer:gn,fixed:rr,stay:ur,health:oa,lifespan:ia,named:sa,state:aa,z:Oa,layer:xa,move:va,offscreen:wa,follow:ya,fadeIn:as,mask:us,drawon:ss,raycast:Zn,tile:or,animate:ra,serializeAnimation:ro,agent:Js,sentry:ta,patrol:ea,pathfinder:Zs,on:Qe,onFixedUpdate:vs,onUpdate:ws,onDraw:Cs,onAdd:Jr,onDestroy:Os,onClick:Ss,onCollide:Es,onCollideUpdate:Ts,onCollideEnd:As,onHover:Vs,onHoverUpdate:Ps,onHoverEnd:Gs,onKeyDown:p.onKeyDown,onKeyPress:p.onKeyPress,onKeyPressRepeat:p.onKeyPressRepeat,onKeyRelease:p.onKeyRelease,onMouseDown:p.onMouseDown,onMousePress:p.onMousePress,onMouseRelease:p.onMouseRelease,onMouseMove:p.onMouseMove,onCharInput:p.onCharInput,onTouchStart:p.onTouchStart,onTouchMove:p.onTouchMove,onTouchEnd:p.onTouchEnd,onScroll:p.onScroll,onHide:p.onHide,onShow:p.onShow,onGamepadButtonDown:p.onGamepadButtonDown,onGamepadButtonPress:p.onGamepadButtonPress,onGamepadButtonRelease:p.onGamepadButtonRelease,onGamepadStick:p.onGamepadStick,onButtonPress:p.onButtonPress,onButtonDown:p.onButtonDown,onButtonRelease:p.onButtonRelease,mousePos:kn,mouseDeltaPos:p.mouseDeltaPos,isKeyDown:p.isKeyDown,isKeyPressed:p.isKeyPressed,isKeyPressedRepeat:p.isKeyPressedRepeat,isKeyReleased:p.isKeyReleased,isMouseDown:p.isMouseDown,isMousePressed:p.isMousePressed,isMouseReleased:p.isMouseReleased,isMouseMoved:p.isMouseMoved,isGamepadButtonPressed:p.isGamepadButtonPressed,isGamepadButtonDown:p.isGamepadButtonDown,isGamepadButtonReleased:p.isGamepadButtonReleased,getGamepadStick:p.getGamepadStick,isButtonPressed:p.isButtonPressed,isButtonDown:p.isButtonDown,isButtonReleased:p.isButtonReleased,setButton:p.setButton,getButton:p.getButton,pressButton:p.pressButton,releaseButton:p.releaseButton,getLastInputDeviceType:p.getLastInputDeviceType,charInputted:p.charInputted,loop:Z,wait:j,play:_s,volume:Ns,burp:sr,audioCtx:O.ctx,Line:Te,Rect:W,Circle:Ce,Ellipse:je,Point:An,Polygon:ye,Vec2:C,Color:I,Mat4:he,Quad:z,RNG:$t,rand:ge,randi:vr,randSeed:ho,vec2:x,rgb:_,hsl2rgb:mo,quad:le,choose:yo,chooseMultiple:bo,shuffle:wr,chance:go,lerp:fe,tween:ee,easings:tt,map:Se,mapc:fo,wave:Sn,deg2rad:se,rad2deg:ct,clamp:Me,evaluateQuadratic:So,evaluateQuadraticFirstDerivative:Vo,evaluateQuadraticSecondDerivative:Po,evaluateBezier:Qt,evaluateBezierFirstDerivative:Go,evaluateBezierSecondDerivative:Ro,evaluateCatmullRom:Mo,evaluateCatmullRomFirstDerivative:Do,curveLengthApproximation:Ar,normalizedCurve:Bo,hermite:Ft,cardinal:Sr,catmullRom:Lt,bezier:Fo,kochanekBartels:Lo,easingSteps:ko,easingLinear:Io,easingCubicBezier:jo,testLineLine:Vn,testRectRect:Cr,testRectLine:Pn,testRectPoint:Dt,testCirclePolygon:Xt,testLinePoint:Gn,testLineCircle:Bt,isConvex:Uo,triangulate:Mn,NavMesh:In,drawSprite:ns,drawText:Xr,formatText:Ue,drawRect:ve,drawLine:kt,drawLines:jt,drawTriangle:Wn,drawCircle:Ne,drawEllipse:Hn,drawUVQuad:it,drawPolygon:Pe,drawCurve:qn,drawBezier:zi,drawFormattedText:He,drawMasked:ts,drawSubtracted:rs,pushTransform:be,popTransform:pe,pushTranslate:Q,pushScale:nt,pushRotate:We,pushMatrix:di,usePostEffect:P,makeCanvas:V,debug:E,scene:zs,getSceneName:$s,go:Ys,onSceneLeave:Ws,layers:Hs,addLevel:xs,getData:A,setData:G,download:Dn,downloadJSON:Wo,downloadText:Vr,downloadBlob:Pr,plug:M,ASCII_CHARS:_n,canvas:p.canvas,addKaboom:Us,LEFT:C.LEFT,RIGHT:C.RIGHT,UP:C.UP,DOWN:C.DOWN,RED:I.RED,GREEN:I.GREEN,BLUE:I.BLUE,YELLOW:I.YELLOW,MAGENTA:I.MAGENTA,CYAN:I.CYAN,WHITE:I.WHITE,BLACK:I.BLACK,quit:lr,KEvent:ae,KEventHandler:ze,KEventController:ke};l.k=$e;let vn=t.plugins;if(vn&&vn.forEach(M),t.global!==!1)for(let L in $e)window[L]=$e[L];return t.focus!==!1&&p.canvas.focus(),$e},"kaplay");var Uu=Sa; //# sourceMappingURL=kaplay.cjs.map