PageSourceSearch

https://thevacuumapproaches.netlify.app/assets/index-Bg8hXbQ9.js

js thevacuumapproaches.netlify.app collected 2026-10-03 11:30:14 UTC 222,716 bytes, 64 lines download raw bytes

1(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e=(()=>{for(var e=new Uint8Array(128),t=0;t<64;t++)e[t<26?t+65:t<52?t+71:t<62?t-4:t*4-205]=t;return t=>{for(var n=t.length,r=new Uint8Array((n-(t[n-1]==`=`)-(t[n-2]==`=`))*3/4|0),i=0,a=0;i<n;){var o=e[t.charCodeAt(i++)],s=e[t.charCodeAt(i++)],c=e[t.charCodeAt(i++)],l=e[t.charCodeAt(i++)];r[a++]=o<<2|s>>4,r[a++]=s<<4|c>>2,r[a++]=c<<6|l}return r}})(),t={name:`kaplay`,description:`KAPLAY is a JavaScript & TypeScript game library that helps you make games fast and fun! (formerly known as Kaboom.js)`,version:`3001.0.19`,license:`MIT`,homepage:`https://kaplayjs.com/`,bugs:{url:`https://github.com/kaplayjs/kaplay/issues`},funding:{type:`opencollective`,url:`https://opencollective.com/kaplay`},repository:{type:`git`,url:`git+https://github.com/kaplayjs/kaplay.git`},type:`module`,main:`./dist/kaplay.cjs`,module:`./dist/kaplay.mjs`,types:`./dist/doc.d.ts`,readme:`./README.md`,exports:{".":{import:{types:`./dist/doc.d.ts`,default:`./dist/kaplay.mjs`},require:{types:`./dist/doc.d.ts`,default:`./dist/kaplay.cjs`}},"./global":`./dist/declaration/global.js`},typesVersions:{"*":{global:[`./dist/declaration/global.d.ts`]}},keywords:[`game development`,`javascript`,`typescript`,`game engine`,`2d games`,`physics engine`,`webgl`,`canvas`,`game library`,`kaplay`,`kaboom`,`kaboomjs`,`kaboom.js`],files:[`dist/`,`kaplay.webp`,`CHANGELOG.md`],scripts:{dev:`NODE_ENV=development node scripts/dev.js`,"win:dev":`set NODE_ENV=development && node scripts/dev.js`,build:`node scripts/generateIndex.js && npm run doc-dts && node scripts/build.js`,"build:fast":`node scripts/buildFast.js`,check:`tsc`,fmt:`dprint fmt`,test:`node scripts/test.js`,"doc-dts":`dts-bundle-generator -o dist/doc.d.ts src/index.ts`,"test:vite":`vitest --typecheck`,desktop:`tauri dev`,prepare:`npm run build`,"publish:next":`npm publish --tag next`},devDependencies:{"@kaplayjs/dprint-config":`^1.2.0`,"@types/jest":`^29.5.14`,dprint:`^0.49.1`,"dts-bundle-generator":`^9.5.1`,ejs:`^3.1.10`,esbuild:`^0.25.2`,express:`^5.1.0`,puppeteer:`^22.15.0`,"tar-fs":`3.0.8`,typescript:`5.6.3`,vite:`5.4.16`,vitest:`^3.1.1`,"vitest-environment-puppeteer":`^11.0.3`,"vitest-puppeteer":`^11.0.3`},engines:{node:`>=20.0.0`},packageManager:`[email protected]+sha512.60c18acd138bff695d339be6ad13f7e936eea6745660d4cc4a776d5247c540d0edee1a563695c183a66eb917ef88f2b4feb1fc25f32a7adcadc7aaf3438e99c1`};function n(e,t,r){return t>r?n(e,r,t):Math.min(Math.max(e,t),r)}var r=class e{r=255;g=255;b=255;constructor(e,t,r){this.r=n(e,0,255),this.g=n(t,0,255),this.b=n(r,0,255)}static fromArray(t){return new e(t[0],t[1],t[2])}static fromHex(t){if(typeof t==`number`)return new e(t>>16&255,t>>8&255,t>>0&255);if(typeof t==`string`){let n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);if(!n)throw Error(`Invalid hex color format`);return new e(parseInt(n[1],16),parseInt(n[2],16),parseInt(n[3],16))}throw Error(`Invalid hex color format`)}static fromHSL(t,n,r){if(n==0)return new e(255*r,255*r,255*r);let i=(e,t,n)=>(n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e),a=r<.5?r*(1+n):r+n-r*n,o=2*r-a,s=i(o,a,t+1/3),c=i(o,a,t),l=i(o,a,t-1/3);return new e(Math.round(s*255),Math.round(c*255),Math.round(l*255))}static RED=new e(255,0,0);static GREEN=new e(0,255,0);static BLUE=new e(0,0,255);static YELLOW=new e(255,255,0);static MAGENTA=new e(255,0,255);static CYAN=new e(0,255,255);static WHITE=new e(255,255,255);static BLACK=new e(0,0,0);clone(){return new e(this.r,this.g,this.b)}lighten(t){return new e(this.r+t,this.g+t,this.b+t)}darken(e){return this.lighten(-e)}invert(){return new e(255-this.r,255-this.g,255-this.b)}mult(t){return new e(this.r*t.r/255,this.g*t.g/255,this.b*t.b/255)}lerp(t,n){return new e(c(this.r,t.r,n),c(this.g,t.g,n),c(this.b,t.b,n))}toHSL(){let e=this.r/255,t=this.g/255,n=this.b/255,r=Math.max(e,t,n
1),i=Math.min(e,t,n),a=(r+i)/2,o=a,s=a;if(r==i)a=o=0;else{let c=r-i;switch(o=s>.5?c/(2-r-i):c/(r+i),r){case e:a=(t-n)/c+(t<n?6:0);break;case t:a=(n-e)/c+2;break;case n:a=(e-t)/c+4}a/=6}return[a,o,s]}eq(e){return this.r===e.r&&this.g===e.g&&this.b===e.b}toString(){return`rgb(${this.r}, ${this.g}, ${this.b})`}toHex(){return`#`+((1<<24)+(this.r<<16)+(this.g<<8)+this.b).toString(16).slice(1)}toArray(){return[this.r,this.g,this.b]}};function i(...e){if(e.length===0)return new r(255,255,255);if(e.length===1){if(e[0]instanceof r)return e[0].clone();if(typeof e[0]==`string`)return r.fromHex(e[0]);if(Array.isArray(e[0])&&e[0].length===3)return r.fromArray(e[0])}else if(e.length===2){if(e[0]instanceof r)return e[0].clone()}else if(e.length===3||e.length===4)return new r(e[0],e[1],e[2]);throw Error(`Invalid color arguments`)}var a=(e,t,n)=>r.fromHSL(e,t,n);function o(e){return e*Math.PI/180}function s(e){return e*180/Math.PI}function c(e,t,n){if(typeof e==`number`&&typeof t==`number`)return e+(t-e)*n;if(e instanceof d&&t instanceof d||e instanceof r&&t instanceof r)return e.lerp(t,n);throw Error(`Bad value for lerp(): ${e}, ${t}. Only number, Vec2 and Color is supported.`)}function l(e,t,n,r,i){return r+(e-t)/(n-t)*(i-r)}function u(e,t,r,i,a){return n(l(e,t,r,i,a),i,a)}var d=class e{x=0;y=0;constructor(e=0,t=e){this.x=e,this.y=t}static fromAngle(t){let n=o(t);return new e(Math.cos(n),Math.sin(n))}static fromArray(t){return new e(t[0],t[1])}static ZERO=new e(0,0);static ONE=new e(1,1);static LEFT=new e(-1,0);static RIGHT=new e(1,0);static UP=new e(0,-1);static DOWN=new e(0,1);clone(){return new e(this.x,this.y)}add(...t){let n=f(...t);return new e(this.x+n.x,this.y+n.y)}sub(...t){let n=f(...t);return new e(this.x-n.x,this.y-n.y)}scale(...t){let n=f(...t);return new e(this.x*n.x,this.y*n.y)}dist(...e){let t=f(...e);return this.sub(t).len()}sdist(...e){let t=f(...e);return this.sub(t).slen()}static sdist(e,t){let n=e.x-t.x,r=e.y-t.y;return n*n+r*r}len(){return Math.sqrt(this.dot(this))}slen(){return this.dot(this)}unit(){let t=this.len();return t===0?new e(0):this.scale(1/t)}normal(){return new e(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}static dot(e,t){return e.x*t.x+e.y*t.y}cross(e){return this.x*e.y-this.y*e.x}static cross(e,t){return e.x*t.y-e.y*t.x}angle(...e){let t=f(...e);return s(Math.atan2(this.y-t.y,this.x-t.x))}angleBetween(...e){let t=f(...e);return s(Math.atan2(this.cross(t),this.dot(t)))}lerp(t,n){return new e(c(this.x,t.x,n),c(this.y,t.y,n))}slerp(e,t){let n=this.dot(e),r=this.cross(e),i=Math.atan2(r,n);return this.scale(Math.sin((1-t)*i)).add(e.scale(Math.sin(t*i))).scale(1/r)}isZero(){return this.x===0&&this.y===0}toFixed(t){return new e(Number(this.x.toFixed(t)),Number(this.y.toFixed(t)))}transform(e){return e.multVec2(this)}eq(e){return this.x===e.x&&this.y===e.y}bbox(){return new R(this,0,0)}toString(){return`vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`}toArray(){return[this.x,this.y]}};function f(...e){if(e.length===1){if(e[0]instanceof d)return new d(e[0].x,e[0].y);if(Array.isArray(e[0])&&e[0].length===2)return new d(...e[0])}return new d(...e)}var p=class e{x=0;y=0;w=1;h=1;constructor(e,t,n,r){this.x=e,this.y=t,this.w=n,this.h=r}scale(t){return new e(this.x+this.w*t.x,this.y+this.h*t.y,this.w*t.w,this.h*t.h)}pos(){return new d(this.x,this.y)}clone(){return new e(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 m(e,t,n,r){return new p(e,t,n,r)}var h=class e{a;b;c;d;constructor(e,t,n,r){this.a=e,this.b=t,this.c=n,this.d=r}mul(t){return new e(this.a*t.a+this.b*t.c,this.a*t.b+this.b*t.d,this.c*t.a+this.d*t.c,this.c*t.b+this.d*t.d)}transform(e){return f(this.a*e.x+this.b*e.y,this.c*e.x+this.d*e.y)}get inverse(){let t=this.det;return new e(this.d/t,-this.b/t,-this.c/t,this.a/t)}get transpose(){return new e(this.a,this.c,this.b,this.d)}get eigenvalues(){let e=this.trace/2,t=this.det;return[e+Math.sqrt(e*e-t),e-Math.sqrt(e*e-t)]}eigenvectors(e,t){return this.c==0?this.b==0?Math.abs(this.transform(f(1,0)).x-e)<2**-52?[[1,0],[0,1]]:[[0,1],[1,0]]:[[this.b,e-this.a],[this.b,t-this.a]]:[[e-this.d,this.c],[t-this.d,this.c]]}get det(){return this.a*this.d-this.b*this.c}get trace(){return this.a+this.d}static rotation(t){let n=Math.cos(t),r=Math.sin(t);return new e(n,r,-r,n)}static scale(t,n){return new e(t,0,0,n)}},g=class e{m11;m12;m13;m21;m22;m23;m31;m32;m33;constructor(e,t,n,r,i,a,o,s,c){this.m11=e,this.m12=t,this.m13=n,this.m21=r,this.m22=i,this.m23=a,this.m31=o,this.m32=s,this.m33=c}static fromMat2(t){return new e(t.a,t.b,0,t.c,t.d,0,0,0,1)}toMat2(){return new h(this.m11,this.m12,this.m21,this.m22)}mul(t){return new e(this.m11*t.m11+this.m12*t.m21+this.m13*t.m31,this.m11*t.m12+this.m12*t.m22+this.m13*t.m32,this.m11*t.m13+this.m12*t.m23+this.m13*t.m33,this.m21*t.m11+this.m22*t.m21+this.m23*t.m31,this.m21*t.m12+this.m22*t.m22+this.m23*t.m32,this.m21*t.m13+this.m22*t.m23+this.m23*t.m33,this.m31*t.m11+this.m32*t.m21+this.m33*t.m31,this.m31*t.m12+this.m32*t.m22+this.m33*t.m32,this.m31*t.m13+this.m32*t.m23+this.m33*t.m33)}get det(){return this.m11*this.m22*this.m33+this.m12*this.m23*this.m31+this.m13*this.m21*this.m32-this.m13*this.m22*this.m31-this.m12*this.m21*this.m33-this.m11*this.m23*this.m32}rotate(e){let t=Math.cos(e),n=Math.sin(e),r=this.m11,i=this.m12;return this.m11=t*this.m11+n*this.m21,this.m12=t*this.m12+n*this.m22,this.m21=t*this.m21-n*r,this.m22=t*this.m22-n*i,this}scale(e,t){return this.m11*=e,this.m12*=e,this.m21*=t,this.m22*=t,this}get inverse(){let t=this.det;return new e((this.m22*this.m33-this.m23*this.m32)/t,(this.m13*this.m32-this.m12*this.m33)/t,(this.m12*this.m23-this.m13*this.m22)/t,(this.m23*this.m31-this.m21*this.m33)/t,(this.m11*this.m33-this.m13*this.m31)/t,(this.m13*this.m21-this.m11*this.m23)/t,(this.m21*this.m32-this.m22*this.m31)/t,(this.m12*this.m31-this.m11*this.m32)/t,(this.m11*this.m22-this.m12*this.m21)/t)}get transpose(){return new e(this.m11,this.m21,this.m31,this.m12,this.m22,this.m32,this.m13,this.m23,this.m33)}},_=class e{m=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];constructor(e){e&&(this.m=e)}static translate(t){return new e([1,0,0,0,0,1,0,0,0,0,1,0,t.x,t.y,0,1])}static scale(t){return new e([t.x,0,0,0,0,t.y,0,0,0,0,1,0,0,0,0,1])}static rotateX(t){t=o(-t);let n=Math.cos(t),r=Math.sin(t);return new e([1,0,0,0,0,n,-r,0,0,r,n,0,0,0,0,1])}static rotateY(t){t=o(-t);let n=Math.cos(t),r=Math.sin(t);return new e([n,0,r,0,0,1,0,0,-r,0,n,0,0,0,0,1])}static rotateZ(t){t=o(-t);let n=Math.cos(t),r=Math.sin(t);return new e([n,-r,0,0,r,n,0,0,0,0,1,0,0,0,0,1])}translate(e){return this.m[12]+=this.m[0]*e.x+this.m[4]*e.y,this.m[13]+=this.m[1]*e.x+this.m[5]*e.y,this.m[14]+=this.m[2]*e.x+this.m[6]*e.y,this.m[15]+=this.m[3]*e.x+this.m[7]*e.y,this}scale(e){return this.m[0]*=e.x,this.m[4]*=e.y,this.m[1]*=e.x,this.m[5]*=e.y,this.m[2]*=e.x,this.m[6]*=e.y,this.m[3]*=e.x,this.m[7]*=e.y,this}rotate(e){e=o(-e);let t=Math.cos(e),n=Math.sin(e),r=this.m[0],i=this.m[1],a=this.m[4],s=this.m[5];return this.m[0]=r*t+i*n,this.m[1]=-r*n+i*t,this.m[4]=a*t+s*n,this.m[5]=-a*n+s*t,this}mult(t){let n=[];for(let e=0;e<4;e++)for(let r=0;r<4;r++)n[e*4+r]=this.m[0+r]*t.m[e*4+0]+this.m[4+r]*t.m[e*4+1]+this.m[8+r]*t.m[e*4+2]+this.m[12+r]*t.m[e*4+3];return new e(n)}multVec2(e){return new d(e.x*this.m[0]+e.y*this.m[4]+this.m[12],e.x*this.m[1]+e.y*this.m[5]+this.m[13])}getTranslation(){return new d(this.m[12],this.m[13])}getScale(){if(this.m[0]!=0||this.m[1]!=0){let e=this.m[0]*this.m[5]-this.m[1]*this.m[4],t=Math.sqrt(this.m[0]*this.m[0]+this.m[1]*this.m[1]);return new d(t,e/t)}if(this.m[4]!=0||this.m[5]!=0){let e=this.m[0]*this.m[5]-this.m[1]*this.m[4],t=Math.sqrt(this.m[4]*this.m[4]+this.m[5]*this.m[5]);return new d(e/t,t)}return new d(0,0)}getRotation(){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 s(this.m[1]>0?Math.acos(this.m[0]/e):-Math.acos(this.m[0]/e))}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 s(Math.PI/2-(this.m[5]>0?Math.acos(-this.m[4]/e):-Math.acos(this.m[4]/e)))}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 d(Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e),0)}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 d(0,Math.atan(this.m[0]*this.m[4]+this.m[1]*this.m[5])/(e*e))}return new d(0,0)}invert(){let t=[],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],i=this.m[9]*this.m[14]-this.m[13]*this.m[10],a=this.m[8]*this.m[15]-this.m[12]*this.m[11],o=this.m[8]*this.m[14]-this.m[12]*this.m[10],s=this.m[8]*this.m[13]-this.m[12]*this.m[9],c=this.m[6]*this.m[15]-this.m[14]*this.m[7],l=this.m[5]*this.m[15]-this.m[13]*this.m[7],u=this.m[5]*this.m[14]-this.m[13]*this.m[6],d=this.m[4]*this.m[15]-this.m[12]*this.m[7],f=this.m[4]*this.m[14]-this.m[12]*this.m[6],p=this.m[5]*this.m[15]-this.m[13]*this.m[7],m=this.m[4]*this.m[13]-this.m[12]*this.m[5],h=this.m[6]*this.m[11]-this.m[10]*this.m[7],g=this.m[5]*this.m[11]-this.m[9]*this.m[7],_=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],y=this.m[4]*this.m[10]-this.m[8]*this.m[6],b=this.m[4]*this.m[9]-this.m[8]*this.m[5];t[0]=this.m[5]*n-this.m[6]*r+this.m[7]*i,t[4]=-(this.m[4]*n-this.m[6]*a+this.m[7]*o),t[8]=this.m[4]*r-this.m[5]*a+this.m[7]*s,t[12]=-(this.m[4]*i-this.m[5]*o+this.m[6]*s),t[1]=-(this.m[1]*n-this.m[2]*r+this.m[3]*i),t[5]=this.m[0]*n-this.m[2]*a+this.m[3]*o,t[9]=-(this.m[0]*r-this.m[1]*a+this.m[3]*s),t[13]=this.m[0]*i-this.m[1]*o+this.m[2]*s,t[2]=this.m[1]*c-this.m[2]*l+this.m[3]*u,t[6]=-(this.m[0]*c-this.m[2]*d+this.m[3]*f),t[10]=this.m[0]*p-this.m[1]*d+this.m[3]*m,t[14]=-(this.m[0]*u-this.m[1]*f+this.m[2]*m),t[3]=-(this.m[1]*h-this.m[2]*g+this.m[3]*_),t[7]=this.m[0]*h-this.m[2]*v+this.m[3]*y,t[11]=-(this.m[0]*g-this.m[1]*v+this.m[3]*b),t[15]=this.m[0]*_-this.m[1]*y+this.m[2]*b;let x=this.m[0]*t[0]+this.m[1]*t[4]+this.m[2]*t[8]+this.m[3]*t[12];for(let e=0;e<4;e++)for(let n=0;n<4;n++)t[e*4+n]*=1/x;return new e(t)}clone(){return new e([...this.m])}toString(){return this.m.toString()}};function v(e,t,n,r=e=>-Math.cos(e)){return e+(r(n)+1)/2*(t-e)}var y=1103515245,b=12345,x=2147483648,S=class{seed;constructor(e){this.seed=e}gen(){return this.seed=(y*this.seed+b)%x,this.seed/x}genNumber(e,t){return e+this.gen()*(t-e)}genVec2(e,t){return new d(this.genNumber(e.x,t.x),this.genNumber(e.y,t.y))}genColor(e,t){return new r(this.genNumber(e.r,t.r),this.genNumber(e.g,t.g),this.genNumber(e.b,t.b))}genAny(...e){if(e.length===0)return this.gen();
1if(e.length===1){if(typeof e[0]==`number`)return this.genNumber(0,e[0]);if(e[0]instanceof d)return this.genVec2(f(0,0),e[0]);if(e[0]instanceof r)return this.genColor(i(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 d&&e[1]instanceof d)return this.genVec2(e[0],e[1]);if(e[0]instanceof r&&e[1]instanceof r)return this.genColor(e[0],e[1])}throw Error(`More than 2 arguments not supported`)}},C=new S(Date.now());function w(e){return e!=null&&(C.seed=e),C.seed}function T(...e){return C.genAny(...e)}function E(...e){return Math.floor(T(...e.length>0?e:[2]))}function D(e){return T()<=e}function O(e){for(let t=e.length-1;t>0;t--){let n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}return e}function ee(e,t){return e.length<=t?e.slice():O(e.slice()).slice(0,t)}function te(e){return e[E(e.length)]}function ne(e,t){return e.pos.x+e.width>t.pos.x&&e.pos.x<t.pos.x+t.width&&e.pos.y+e.height>t.pos.y&&e.pos.y<t.pos.y+t.height}function k(e,t){if(e.p1.x===e.p2.x&&e.p1.y===e.p2.y||t.p1.x===t.p2.x&&t.p1.y===t.p2.y)return null;let n=(t.p2.y-t.p1.y)*(e.p2.x-e.p1.x)-(t.p2.x-t.p1.x)*(e.p2.y-e.p1.y);if(n===0)return null;let r=((t.p2.x-t.p1.x)*(e.p1.y-t.p1.y)-(t.p2.y-t.p1.y)*(e.p1.x-t.p1.x))/n,i=((e.p2.x-e.p1.x)*(e.p1.y-t.p1.y)-(e.p2.y-e.p1.y)*(e.p1.x-t.p1.x))/n;return r<0||r>1||i<0||i>1?null:r}function re(e,t){let n=k(e,t);return n?f(e.p1.x+n*(e.p2.x-e.p1.x),e.p1.y+n*(e.p2.y-e.p1.y)):null}function ie(e,t){let n=t.p2.sub(t.p1),r=-1/0,i=1/0;if(n.x!=0){let a=(e.pos.x-t.p1.x)/n.x,o=(e.pos.x+e.width-t.p1.x)/n.x;r=Math.max(r,Math.min(a,o)),i=Math.min(i,Math.max(a,o))}if(n.y!=0){let a=(e.pos.y-t.p1.y)/n.y,o=(e.pos.y+e.height-t.p1.y)/n.y;r=Math.max(r,Math.min(a,o)),i=Math.min(i,Math.max(a,o))}return i>=r&&i>=0&&r<=1}function A(e,t){return t.x>e.pos.x&&t.x<e.pos.x+e.width&&t.y>e.pos.y&&t.y<e.pos.y+e.height}
1function ae(e,t){return f(Math.max(e.pos.x,Math.min(t.center.x,e.pos.x+e.width)),Math.max(e.pos.y,Math.min(t.center.y,e.pos.y+e.height))).sdist(t.center)<=t.radius*t.radius}function j(e,t){return le(t,new B(e.points()))}function M(e,t){let n=t.sub(e.p1),r=e.p2.sub(e.p1);if(Math.abs(n.cross(r))>2**-52)return!1;let i=n.dot(r)/r.dot(r);return i>=0&&i<=1}function oe(e,t){let n=e.p2.sub(e.p1),r=n.dot(n),i=e.p1.sub(t.center),a=2*n.dot(i),o=i.dot(i)-t.radius*t.radius,s=a*a-4*r*o;if(r<=2**-52||s<0)return!1;if(s==0){let e=-a/(2*r);if(e>=0&&e<=1)return!0}else{let e=(-a+Math.sqrt(s))/(2*r),t=(-a-Math.sqrt(s))/(2*r);if(e>=0&&e<=1||t>=0&&t<=1)return!0}return se(t,e.p1)}function N(e,t){if(F(t,e.p1)||F(t,e.p2))return!0;for(let n=0;n<t.pts.length;n++){let r=t.pts[n],i=t.pts[(n+1)%t.pts.length];if(re(e,new L(r,i)))return!0}return!1}function se(e,t){return e.center.sdist(t)<e.radius*e.radius}function P(e,t){return e.center.sdist(t.center)<(e.radius+t.radius)*(e.radius+t.radius)}function ce(e,t){let n=t.pts[t.pts.length-1];for(let r of t.pts){if(oe(new L(n,r),e))return!0;n=r}return se(e,t.pts[0])?!0:F(t,e.center)}function le(e,t){for(let n=0;n<e.pts.length;n++)if(N(new L(e.pts[n],e.pts[(n+1)%e.pts.length]),t))return!0;return!!(e.pts.some(e=>F(t,e))||t.pts.some(t=>F(e,t)))}function F(e,t){let n=!1,r=e.pts;for(let e=0,i=r.length-1;e<r.length;i=e++)r[e].y>t.y!=r[i].y>t.y&&t.x<(r[i].x-r[e].x)*(t.y-r[e].y)/(r[i].y-r[e].y)+r[e].x&&(n=!n);return n}function I(e,t){t=t.sub(e.center);let n=o(e.angle),r=Math.cos(n),i=Math.sin(n),a=t.x*r+t.y*i,s=-t.x*i+t.y*r;return a*a/(e.radiusX*e.radiusX)+s*s/(e.radiusY*e.radiusY)<1}function ue(e,t){let n=t.center.sub(e.center),r=o(e.angle),i=Math.cos(r),a=Math.sin(r),s=n.x*i+n.y*a,c=-n.x*a+n.y*i;return I(new ke(f(),e.radiusX+t.radius,e.radiusY+t.radius,0),f(s,c))}function de(e,t){let n=e.toMat2().inverse;return t=new L(n.transform(t.p1.sub(e.center)),n.transform(t.p2.sub(e.center))),oe(t,new z(f(),1))}function fe(e,t){if(e.radiusX===e.radiusY)return ue(t,new z(e.center,e.radiusX));if(t.radiusX===t.radiusY)return ue(e,new z(t.center,t.radiusX));let n=new g(1/e.radiusX**2,0,0,0,1/e.radiusY**2,0,0,0,-1),r=new g(1/t.radiusX**2,0,0,0,1/t.radiusY**2,0,0,0,-1),i=e.center.x,a=e.center.y,s=t.center.x,c=t.center.y,l=o(e.angle),u=o(t.angle),d=new g(Math.cos(l),-Math.sin(l),i,Math.sin(l),Math.cos(l),a,0,0,1),f=new g(Math.cos(u),-Math.sin(u),s,Math.sin(u),Math.cos(u),c,0,0,1),p=d.inverse,m=f.inverse,h=p.transpose.mul(n).mul(p),_=m.transpose.mul(r).mul(m),v=h.m11,y=h.m12,b=h.m13,x=h.m21,S=h.m22,C=h.m23,w=h.m31,T=h.m32,E=h.m33,D=_.m11,O=_.m12,ee=_.m13,te=_.m21,ne=_.m22,k=_.m23,re=_.m31,ie=_.m32,A=_.m33,ae=v*S*E-v*C*T-y*x*E+y*C*w+b*x*T-b*S*w,j=(v*S*A-v*C*ie-v*T*k+v*E*ne-y*x*A+y*C*re+y*w*k-y*E*te+b*x*ie-b*S*re-b*w*ne+b*T*te+x*T*ee-x*E*O-S*w*ee+S*E*D+C*w*O-C*T*D)/ae,M=(v*ne*A-v*k*ie-y*te*A+y*k*re+b*te*ie-b*ne*re-x*O*A+x*ee*ie+S*D*A-S*ee*re-C*D*ie+C*O*re+w*O*k-w*ee*ne-T*D*k+T*ee*te+E*D*ne-E*O*te)/ae,oe=(D*ne*A-D*k*ie-O*te*A+O*k*re+ee*te*ie-ee*ne*re)/ae;if(j>=0){let e=-3*M+j**2,t=3*j*oe+M*j**2-4*M**2,n=-27*oe**2+18*oe*j*M+j**2*M**2-4*j**3*oe-4*M**3;return!(e>0&&t<0&&n>0)}{let e=-3*M+j**2,t=-27*oe**2+18*oe*j*M+j**2*M**2-4*j**3*oe-4*M**3;return!(e>0&&t>0)}}function pe(e,t){return me(e,new B(t.points()))}function me(e,t){let n=e.toMat2().inverse;return t=new B(t.pts.map(t=>n.transform(t.sub(e.center)))),ce(new z(f(),1),t)}function he(e,t){return e.x===t.x&&e.y===t.y}function ge(e,t){return t instanceof d?he(t,e.pt):t instanceof z?se(t,e.pt):t instanceof L?M(t,e.pt):t instanceof R?A(t,e.pt):t instanceof B?F(t,e.pt):t instanceof ke&&I(t,e.pt)}function _e(e,t){return t instanceof d?M(e,t):t instanceof z?oe(e,t):t instanceof L?re(e,t)!=null:t instanceof R?ie(t,e):t instanceof B?N(e,t):t instanceof ke&&de(t,e)}function ve(e,t){return t instanceof d?se(e,t):t instanceof z?P(e,t):t instanceof L?oe(t,e):t instanceof R?ae(t,e):t instanceof B?ce(e,t):t instanceof ke&&ue(t,e)}function ye(e,t){return t instanceof d?A(e,t):t instanceof z?ae(e,t):t instanceof L?ie(e,t):t instanceof R?ne(e,t):t instanceof B?j(e,t):t instanceof ke&&pe(t,e)}function be(e,t){return t instanceof d?F(e,t):t instanceof z?ce(t,e):t instanceof L?N(t,e):t instanceof R?j(t,e):t instanceof B?le(t,e):t instanceof ke&&me(t,e)}function xe(e,t){return t instanceof d?I(e,t):t instanceof z?ue(e,t):t instanceof L?de(e,t):t instanceof R?pe(e,t):t instanceof B?me(e,t):t instanceof ke&&fe(t,e)}
1function Se(e,t,n){let r=e,i=n.p1,a=n.p2,o=t,s=a.sub(i),c=o.cross(s);if(Math.abs(c)<2**-52)return null;let l=i.sub(r),u=l.cross(s)/c;if(u<=0||u>=1)return null;let d=l.cross(o)/c;if(d<=0||d>=1)return null;let f=s.normal().unit();return t.dot(f)>0&&(f.x*=-1,f.y*=-1),{point:r.add(o.scale(u)),normal:f,fraction:u}}function Ce(e,t,n){let r=-1/0,i=1/0,a;if(e.x!=0){let o=(n.pos.x-e.x)/t.x,s=(n.pos.x+n.width-e.x)/t.x;a=f(-Math.sign(t.x),0),r=Math.max(r,Math.min(o,s)),i=Math.min(i,Math.max(o,s))}if(e.y!=0){let o=(n.pos.y-e.y)/t.y,s=(n.pos.y+n.height-e.y)/t.y;Math.min(o,s)>r&&(a=f(0,-Math.sign(t.y))),r=Math.max(r,Math.min(o,s)),i=Math.min(i,Math.max(o,s))}return i>=r&&r>=0&&r<=1?{point:e.add(t.scale(r)),normal:a,fraction:r}:null}function we(e,t,n){let r=e,i=n.center,a=t,o=a.dot(a),s=r.sub(i),c=2*a.dot(s),l=s.dot(s)-n.radius*n.radius,u=c*c-4*o*l;if(o<=2**-52||u<0)return null;if(u==0){let e=-c/(2*o);if(e>=0&&e<=1){let t=r.add(a.scale(e));return{point:t,normal:t.sub(i),fraction:e}}}else{let e=(-c+Math.sqrt(u))/(2*o),t=(-c-Math.sqrt(u))/(2*o),n=null;if(e>=0&&e<=1&&(n=e),t>=0&&t<=1&&(n=Math.min(t,n??t)),n!=null){let e=r.add(a.scale(n));return{point:e,normal:e.sub(i).unit(),fraction:n}}}return null}function Te(e,t,n){let r=n.pts,i=null,a=r[r.length-1];for(let n=0;n<r.length;n++){let o=r[n],s=Se(e,t,new L(a,o));s&&(!i||i.fraction>s.fraction)&&(i=s),a=o}return i}function Ee(e,t,n){let r=n.toMat2(),i=r.inverse,a=we(i.transform(e.sub(n.center)),i.transform(t),new z(f(),1));if(a){let i=h.rotation(o(-n.angle)),s=h.scale(n.radiusX,n.radiusY).transform(a.point),c=r.transform(a.point).add(n.center),l=c.dist(e)/t.len();return{point:c,normal:i.transform(f(n.radiusY**2*s.x,n.radiusX**2*s.y)).unit(),fraction:l}}return a}function De(e,t,n,r=64){let i=e,a=t.len(),o=t.scale(1/a),s=0,c=f(Math.floor(e.x),Math.floor(e.y)),l=f(o.x>0?1:-1,o.y>0?1:-1),u=f(Math.abs(1/o.x),Math.abs(1/o.y)),d=f(l.x>0?c.x+1-e.x:e.x-c.x,l.y>0?c.y+1-e.y:e.y-c.y),p=f(u.x<1/0?u.x*d.x:1/0,u.y<1/0?u.y*d.y:1/0),m=-1;for(;s<=r;){let e=n(c);if(e===!0)return{point:i.add(o.scale(s)),normal:f(m===0?-l.x:0,m===1?-l.y:0),fraction:s/a,gridPos:c};if(e)return e;p.x<p.y?(c.x+=l.x,s=p.x,p.x+=u.x,m=0):(c.y+=l.y,s=p.y,p.y+=u.y,m=1)}return null}var Oe=class e{pt;constructor(e){this.pt=e.clone()}transform(t){return new e(t.multVec2(this.pt))}bbox(){return new R(this.pt,0,0)}area(){return 0}clone(){return new e(this.pt)}collides(e){return ge(this,e)}contains(e){return this.pt.eq(e)}raycast(e,t){return null}random(){return this.pt.clone()}},L=class e{p1;p2;constructor(e,t){this.p1=e.clone(),this.p2=t.clone()}transform(t){return new e(t.multVec2(this.p1),t.multVec2(this.p2))}bbox(){return R.fromPoints(this.p1,this.p2)}area(){return this.p1.dist(this.p2)}clone(){return new e(this.p1,this.p2)}collides(e){return _e(this,e)}contains(e){return this.collides(e)}raycast(e,t){return Se(e,t,this)}random(){return this.p1.add(this.p2.sub(this.p1).scale(T(1)))}},R=class e{pos;width;height;constructor(e,t,n){this.pos=e.clone(),this.width=t,this.height=n}static fromPoints(t,n){return new e(t.clone(),n.x-t.x,n.y-t.y)}center(){return new d(this.pos.x+this.width/2,this.pos.y+this.height/2)}points(){return[this.pos,this.pos.add(this.width,0),this.pos.add(this.width,this.height),this.pos.add(0,this.height)]}transform(e){return new B(this.points().map(t=>e.multVec2(t)))}bbox(){return this.clone()}area(){return this.width*this.height}clone(){return new e(this.pos.clone(),this.width,this.height)}distToPoint(e){return Math.sqrt(this.sdistToPoint(e))}sdistToPoint(e){let t=this.pos,n=this.pos.add(this.width,this.height),r=Math.max(t.x-e.x,0,e.x-n.x),i=Math.max(t.y-e.y,0,e.y-n.y);return r*r+i*i}collides(e){return ye(this,e)}contains(e){return this.collides(e)}raycast(e,t){return Ce(e,t,this)}random(){return this.pos.add(T(this.width),T(this.height))}},z=class e{center;radius;constructor(e,t){this.center=e.clone(),this.radius=t}transform(e){return new ke(this.center,this.radius,this.radius).transform(e)}bbox(){return R.fromPoints(this.center.sub(f(this.radius)),this.center.add(f(this.radius)))}area(){return this.radius*this.radius*Math.PI}clone(){return new e(this.center,this.radius)}collides(e){return ve(this,e)}contains(e){return this.collides(e)}raycast(e,t){return we(e,t,this)}random(){return this.center.add(d.fromAngle(T(360)).scale(T(this.radius)))}},ke=class e{center;radiusX;radiusY;angle;constructor(e,t,n,r=0){this.center=e.clone(),this.radiusX=t,this.radiusY=n,this.angle=r}static fromMat2(t){let n=t.inverse,r=n.transpose.mul(n),[i,a]=r.eigenvalues,[o,c]=r.eigenvectors(i,a),[l,u]=[1/Math.sqrt(i),1/Math.sqrt(a)];return l>u?new e(f(),l,u,s(Math.atan2(-o[1],o[0]))):new e(f(),u,l,s(Math.atan2(-c[1],c[0])))}toMat2(){let e=o(this.angle),t=Math.cos(e),n=Math.sin(e);return new h(t*this.radiusX,-n*this.radiusY,n*this.radiusX,t*this.radiusY)}transform(t){if(this.angle==0&&t.getRotation()==0)return new e(t.multVec2(this.center),t.m[0]*this.radiusX,t.m[5]*this.radiusY);
1{let n=this.toMat2(),r=t.getRotation(),i=t.getScale();n=g.fromMat2(n).scale(i.x,i.y).rotate(r).toMat2();let a=e.fromMat2(n);return a.center=t.multVec2(this.center),a}}bbox(){if(this.angle==0)return R.fromPoints(this.center.sub(f(this.radiusX,this.radiusY)),this.center.add(f(this.radiusX,this.radiusY)));{let e=o(this.angle),t=Math.cos(e),n=Math.sin(e),r=this.radiusX*t,i=this.radiusX*n,a=this.radiusY*n,s=this.radiusY*t,c=Math.sqrt(r*r+a*a),l=Math.sqrt(i*i+s*s);return R.fromPoints(this.center.sub(f(c,l)),this.center.add(f(c,l)))}}area(){return this.radiusX*this.radiusY*Math.PI}clone(){return new e(this.center,this.radiusX,this.radiusY,this.angle)}collides(e){return xe(this,e)}contains(e){e=e.sub(this.center);let t=o(this.angle),n=Math.cos(t),r=Math.sin(t),i=e.x*n+e.y*r,a=-e.x*r+e.y*n;return i*i/(this.radiusX*this.radiusX)+a*a/(this.radiusY*this.radiusY)<1}raycast(e,t){return Ee(e,t,this)}random(){return this.center}};function Ae(e,t,n,r){let i=t.sub(e),a=r.sub(n),o=i.cross(a);return o<1e-5&&o>-1e-5||(o=n.sub(e).cross(a)/o,o<0||o>1)?null:e.add(i.scale(o))}var B=class e{pts;constructor(e){if(e.length<3)throw Error(`Polygons should have at least 3 vertices`);this.pts=e}transform(t){return new e(this.pts.map(e=>t.multVec2(e)))}bbox(){let e=f(Number.MAX_VALUE),t=f(-Number.MAX_VALUE);for(let n of this.pts)e.x=Math.min(e.x,n.x),t.x=Math.max(t.x,n.x),e.y=Math.min(e.y,n.y),t.y=Math.max(t.y,n.y);return R.fromPoints(e,t)}area(){let e=0,t=this.pts.length;for(let n=0;n<t;n++){let r=this.pts[n],i=this.pts[(n+1)%t];e+=r.x*i.y*.5,e-=i.x*r.y*.5}return Math.abs(e)}clone(){return new e(this.pts.map(e=>e.clone()))}collides(e){return be(this,e)}contains(e){return this.collides(e)}raycast(e,t){return Te(e,t,this)}random(){return f()}cut(t,n){new L(t,n);let r=[],i=[],a=n.sub(t),o=this.pts[this.pts.length-1],s=o.sub(t),c=a.cross(s)>0;return this.pts.forEach(e=>{s=e.sub(t);let l=a.cross(s)>0;if(c!=l){let a=Ae(o,e,t,n);r.push(a),i.push(a),c=l}(l?r:i).push(e),o=e}),[r.length?new e(r):null,i.length?new e(i):null]}};function je(e,t,n,r){let i=r*r,a=1-r,o=a*a;return e.scale(o).add(t.scale(2*a*r)).add(n.scale(i))}function Me(e,t,n,r){let i=1-r;return t.sub(e).scale(2*i).add(n.sub(t).scale(2*r))}function Ne(e,t,n,r){return n.sub(t.scale(2)).add(e).scale(2)}function Pe(e,t,n,r,i){let a=i*i,o=a*i,s=1-i,c=s*s,l=c*s;return e.scale(l).add(t.scale(3*c*i)).add(n.scale(3*s*a)).add(r.scale(o))}function Fe(e,t,n,r,i){let a=i*i,o=1-i,s=o*o;return t.sub(e).scale(3*s).add(n.sub(t).scale(6*o*i)).add(r.sub(n).scale(3*a))}function V(e,t,n,r,i){let a=1-i;return n.sub(t.scale(2)).add(e).scale(6*a).add(r.sub(n.scale(2)).add(t).scale(6*i))}function Ie(e,t,n,r,i){let a=.5*(((-i+2)*i-1)*i),o=.5*((3*i-5)*i*i+2),s=.5*(((-3*i+4)*i+1)*i),c=.5*((i-1)*i*i);return e.scale(a).add(t.scale(o)).add(n.scale(s)).add(r.scale(c))}function Le(e,t,n,r,i){let a=.5*((-3*i+4)*i-1),o=.5*((9*i-10)*i),s=.5*((-9*i+8)*i+1),c=.5*((3*i-2)*i);return e.scale(a).add(t.scale(o)).add(n.scale(s)).add(r.scale(c))}function Re(e){let t=ze(e),n=t(1);return r=>{let i=r*n;return e(t(i,!0))}}function ze(e,t=10,n=10){let r=[0],i=[0],a=1/(t-1)/n,o=0,s=e(0),c=0;for(let l=1;l<t;l++){for(let t=0;t<n;t++){c+=a;let t=e(c),n=t.dist(s);o+=n,s=t}r[l]=o,i[l]=c}return i[t-1]=1,(e,n=!1)=>
1{if(n){let t=e;if(t<=0)return 0;if(t>=o)return 1;let n=0;for(;r[n+1]<t;)n++;let a=i[n],s=i[n+1],c=r[n],l=r[n+1],u=(t-c)/(l-c);return a+(s-a)*u}{if(e<=0)return 0;if(e>=1)return r[t-1];let n=0;for(;i[n+1]<e;)n++;let a=i[n],o=i[n+1],s=r[n],c=r[n+1],l=(e-a)/(o-a);return s+(c-s)*l}}}function Be(e,t,n,r){let i=2*e+t-2*r+n,a=-3*e+3*r-2*t-n,o=t,s=e;return e=>{let t=e*e,n=t*e;return i*n+a*t+o*e+s}}function Ve(e,t,n,r,i,a=Be){let o=a(t.x,(1-i)*(n.x-e.x),(1-i)*(r.x-t.x),n.x),s=a(t.y,(1-i)*(n.y-e.y),(1-i)*(r.y-t.y),n.y);return e=>new d(o(e),s(e))}function He(e,t,n,r,i=Be){return Ve(e,t,n,r,.5,i)}function Ue(e,t,n,r,i=Be){return He(r.add(e.sub(t).scale(6)),e,r,e.add(r.sub(n).scale(6)),i)}function We(e,t,n,r,i,a,o,s=Be){let c=s(t.x,.5*(1-i)*(1+o)*(1+a)*(t.x-e.x)+.5*(1-i)*(1-o)*(1-a)*(n.x-t.x),.5*(1-i)*(1+o)*(1-a)*(n.x-t.x)+.5*(1-i)*(1-o)*(1+a)*(r.x-n.x),n.x),l=s(t.y,.5*(1-i)*(1+o)*(1+a)*(t.y-e.y)+.5*(1-i)*(1-o)*(1-a)*(n.y-t.y),.5*(1-i)*(1+o)*(1-a)*(n.y-t.y)+.5*(1-i)*(1-o)*(1+a)*(r.y-n.y),n.y);return e=>new d(c(e),l(e))}function Ge(e,t,n,r){let i=2*e+t-2*r+n,a=-3*e+3*r-2*t+n,o=t;return e=>{let t=e*e;return 3*i*t+2*a*e+o}}function Ke(e){return 0<=e&&e<=1}function qe(e,t){return Math.abs(e-t)<=2**-52}function Je(e){return e<0?-((-e)**(1/3)):e**(1/3)}function Ye(e,t,n,r){let i=3*e-6*t+3*n,a=-3*e+3*t,o=e,s=-e+3*t-3*n+r;if(qe(s,0)){if(qe(i,0))return qe(a,0)?[]:[-o/a].filter(Ke);let e=Math.sqrt(a*a-4*i*o),t=2*i;return[(e-a)/t,(-a-e)/t].filter(Ke)}i/=s,a/=s,o/=s;let c=(3*a-i*i)/3,l=c/3,u=(2*i*i*i-9*i*a+27*o)/27,d=u/2,f=d*d+l*l*l;if(f<0){let e=-c/3,t=e*e*e,n=Math.sqrt(t),r=-u/(2*n),a=Math.acos(r<-1?-1:r>1?1:r),o=2*Je(n);return[o*Math.cos(a/3)-i/3,o*Math.cos((a+2*Math.PI)/3)-i/3,o*Math.cos((a+4*Math.PI)/3)-i/3].filter(Ke)}if(f===0){let e=d<0?Je(-d):-Je(d);return[2*e-i/3,-e-i/3].filter(Ke)}let p=Math.sqrt(f);return[Je(p-d)-Je(p+d)-i/3].filter(Ke)}function Xe(e,t,n,r,i){let a=Ye(e.x-i,t.x-i,n.x-i,r.x-i);return a.length>0?Pe(e,t,n,r,a[0]).y:NaN}function Ze(e){if(!e||e.length==0)throw Error(`Need at least one point for easingLinear.`);let t=e.length;return n=>{if(n<=0||e.length==1||n<=e[0].x)return e[0].y;for(let r=0;r<t;r++)if(e[r].x>=n)return l(n,e[r-1].x,e[r].x,e[r-1].y,e[r].y);return e[e.length-1].y}}function Qe(e,t){return n=>Xe(f(0,0),e,t,f(1,1),n)}function $e(e,t=`jump-end`){let n=1/e,r=t==`jump-start`||t==`jump-both`,i=1/(e+ +(t==`jump-end`||t==`jump-both`)),a=r?i:0;return e=>{let t=Math.floor(e/n);return a+t*i}}function et(e,t){let n=Number.MAX_VALUE,r={normal:f(0),distance:0};for(let i of[e,t])for(let a=0;a<i.pts.length;a++){let o=i.pts[a],s=i.pts[(a+1)%i.pts.length].sub(o).normal().unit(),c=Number.MAX_VALUE,l=-Number.MAX_VALUE;for(let t=0;t<e.pts.length;t++){let n=e.pts[t].dot(s);c=Math.min(c,n),l=Math.max(l,n)}let u=Number.MAX_VALUE,d=-Number.MAX_VALUE;for(let e=0;e<t.pts.length;e++){let n=t.pts[e].dot(s);u=Math.min(u,n),d=Math.max(d,n)}let f=Math.min(l,d)-Math.max(c,u);if(f<0)return null;if(f<Math.abs(n)){let e=d-c,t=u-l;n=Math.abs(e)<Math.abs(t)?e:t,r.normal=s,r.distance=n}}return r}function tt(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)>=0}function nt(e){let t=0,n=e[e.length-1];for(let r=0;r<e.length;r++)t+=(e[r].x-n.x)*(e[r].y+n.y),n=e[r];return t<0}function rt(e,t,n,r){let i=r.x-n.x,a=r.y-n.y;return(i*(e.y-n.y)-a*(e.x-n.x))*(i*(t.y-n.y)-a*(t.x-n.x))>=0}function it(e,t,n,r){return rt(e,t,n,r)&&rt(e,n,t,r)&&rt(e,r,t,n)}function at(e,t,n,r){for(let i of e)if(i!==t&&i!==n&&i!==r&&it(i,t,n,r))return!0;return!1}function ot(e,t,n,r){return tt(e,t,n)&&!at(r,e,t,n)}function st(e){if(e.length<3)return[];if(e.length==3)return[e];let t=[],n=[],r=0;for(let i=0;i<e.length;i++){let a=e[r],o=e[i];(o.x<a.x||o.x==a.x&&o.y<a.y)&&(r=r),t[i]=i+1,n[i]=i-1}t[t.length-1]=0,n[0]=n.length-1,nt(e)||([t,n]=[n,t]);let i=[];for(let r=0;r<e.length;++r)tt(e[n[r]],e[r],e[t[r]])||i.push(e[r]);let a=[],o=e.length,s=1,c=0,l,u;for(;o>3;){l=t[s],u=n[s];let r=e[u],d=e[s],f=e[l];if(ot(r,d,f,i))a.push([r,d,f]),t[u]=l,n[l]=u,i.splice(i.indexOf(d),1),--o,c=0;else if(++c>o)return[];s=l}return l=t[s],u=n[s],a.push([e[u],e[s],e[l]]),a}function ct(e){if(e.length<3)return!1;let t=e.length-2,n=e.length-1,r=0,i=e[n].sub(e[t]),a=e[r].sub(e[n]),o=i.cross(a);for(;r+1<e.length;)if(t=n,n=r,r++,i=e[n].sub(e[t]),a=e[r].sub(e[n]),i.cross(a)*o<0)return!1;return!0}var lt=` !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\`abcdefghijklmnopqrstuvwxyz{|}~`,ut=`topleft`,dt=`monospace`,ft=`monospace`,pt=`linear`,mt=[{name:`a_pos`,size:2},{name:`a_uv`,size:2},{name:`a_color`,size:4}],ht=mt.reduce((e,t)=>
1e+t.size,0),gt=2048,_t=gt*4*ht,vt=gt*6,yt=`
2attribute vec2 a_pos;
3attribute vec2 a_uv;
4attribute vec4 a_color;
5
6varying vec2 v_pos;
7varying vec2 v_uv;
8varying vec4 v_color;
9
10vec4 def_vert() {
11	return vec4(a_pos, 0.0, 1.0);
12}
13
14{{user}}
15
16void main() {
17	vec4 pos = vert(a_pos, a_uv, a_color);
18	v_pos = a_pos;
19	v_uv = a_uv;
20	v_color = a_color;
21	gl_Position = pos;
22}
23`,bt=`
24precision mediump float;
25
26varying vec2 v_pos;
27varying vec2 v_uv;
28varying vec4 v_color;
29
30uniform sampler2D u_tex;
31
32vec4 def_frag() {
33	vec4 texColor = texture2D(u_tex, v_uv);
34	return vec4((v_color.rgb * texColor.rgb), texColor.a) * v_color.a;
35}
36
37{{user}}
38
39void main() {
40	gl_FragColor = frag(v_pos, v_uv, v_color, u_tex);
41	if (gl_FragColor.a == 0.0) {
42		discard;
43	}
44}
45`,xt=`
46vec4 vert(vec2 pos, vec2 uv, vec4 color) {
47	return def_vert();
48}
49`,St=`
50vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) {
51	return def_frag();
52}
53`,Ct=new Set([`id`,`require`]),wt=new Set([`add`,`fixedUpdate`,`update`,`draw`,`destroy`,`inspect`,`drawInspect`]),Tt=200,Et=640,Dt=65536,Ot=Symbol.for(`kaplay.cancel`),kt=class extends Map{lastID=0;push(e){let t=this.lastID;return this.set(t,e),this.lastID++,t}pushd(e){let t=this.push(e);return()=>this.delete(t)}},At=class e{paused=!1;cancel;constructor(e){this.cancel=e}static join(t){let n=new e(()=>t.forEach(e=>e.cancel()));return Object.defineProperty(n,"paused",{get:()=>t[0].paused,set:e=>t.forEach(t=>t.paused=e)}),n.paused=!1,n}static replace(e,t){return e.cancel=()=>t.cancel(),t.paused=e.paused,Object.defineProperty(e,"paused",{get:()=>t.paused,set:e=>t.paused=e}),e}},H=class{cancellers=new WeakMap;handlers=new kt;add(e){function t(...t){if(!r.paused)return e(...t)}let n=this.handlers.pushd(t),r=new At(n);return this.cancellers.set(t,n),r}addOnce(e){let t=this.add((...n)=>{t.cancel(),e(...n)});return t}next(){return new Promise(e=>this.addOnce(e))}trigger(...e){this.handlers.forEach(t=>{let n=t(...e),r;n===Ot&&(r=this.cancellers.get(t))&&r()})}numListeners(){return this.handlers.size}clear(){this.handlers.clear()}},jt=class{handlers={};registers={};on(e,t){return this.handlers[e]||(this.handlers[e]=new H),this.handlers[e].add(t)}onOnce(e,t){let n=this.on(e,(...e)=>{n.cancel(),t(...e)});return n}next(e){return new Promise(t=>{this.onOnce(e,(...e)=>t(e[0]))})}trigger(e,...t){this.handlers[e]&&this.handlers[e].trigger(...t)}remove(e){delete this.handlers[e]}clear(){this.handlers={}}numListeners(e){return this.handlers[e]?.numListeners()??0}},Mt=e=>e[0]instanceof r,Nt=e=>e[0]instanceof d,Pt=e=>typeof e[0]==`number`,Ft=class{_items;_compareFn;constructor(e=(e,t)=>e<t){this._compareFn=e,this._items=[]}insert(e){this._items.push(e),this.moveUp(this._items.length-1)}remove(){if(this._items.length===0)return null;let e=this._items[0],t=this._items.pop();return this._items.length!==0&&(this._items[0]=t,this.moveDown(0)),e}clear(){this._items.splice(0,this._items.length)}moveUp(e){for(;e>0;){let t=Math.floor((e-1)/2);if(!this._compareFn(this._items[e],this._items[t])&&this._items[e]>=this._items[t])break;this.swap(e,t),e=t}}moveDown(e){for(;e<Math.floor(this._items.length/2);){let t=2*e+1;if(t<this._items.length-1&&!this._compareFn(this._items[t],this._items[t+1])&&++t,this._compareFn(this._items[e],this._items[t]))break;this.swap(e,t),e=t}}swap(e,t){[this._items[e],this._items[t]]=[this._items[t],this._items[e]]}get length(){return this._items.length}};function It(e){let t=window.atob(e),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.charCodeAt(e);return r.buffer}function Lt(e){return It(e.split(`,`)[1])}function Rt(e,t){let n=document.createElement(`a`);n.href=t,n.download=e,n.click()}function zt(e,t){Rt(e,`data:text/plain;charset=utf-8,`+t)}function Bt(e,t){zt(e,JSON.stringify(t))}function Vt(e,t){let n=URL.createObjectURL(t);Rt(e,n),URL.revokeObjectURL(n)}var Ht=e=>e.match(/^data:\w+\/\w+;base64,.+/),Ut=e=>e.split(`.`).slice(0,-1).join(`.`);function Wt(e,t){if(e===t)return!0;let n=typeof e,r=typeof t;if(n!==r)return!1;if(n===`object`&&r===`object`&&e!==null&&t!==null){if(Array.isArray(e)!==Array.isArray(t))return!1;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n){let n=e[r],i=t[r];
53if(!Wt(n,i))return!1}return!0}return!1}var Gt=new Set,Kt=e=>e instanceof Error?e.message:String(e);function qt(e){Gt.has(e)||(Gt.add(e),console.warn(e))}function Jt(e,t){qt(`${e} is deprecated. Use ${t} instead.`)}function Yt(e,t){return Number(e.toFixed(t))}function U(e,t){return(...n)=>{let r=n.length;if(r===e.length)return e(...n);if(r===t.length)return t(...n)}}var Xt=Object.freeze([776,2359,2367,2984,3007,3021,3633,3635,3648,3657,4352,4449,4520]);function Zt(e){if(typeof e!=`string`)throw TypeError(`string cannot be undefined or null`);let t=[],n=0,r=0;for(;n<e.length;){if(r+=Qt(n+r,e),sn(e[n+r])&&r++,rn(e[n+r])&&r++,an(e[n+r])&&r++,cn(e[n+r])){r++;continue}t.push(e.substring(n,n+r)),n+=r,r=0}return t}function Qt(e,t){let n=t[e];if(!$t(n)||e===t.length-1)return 1;let r=n+t[e+1],i=t.substring(e+2,e+5);return en(r)&&en(i)?4:tn(r)&&on(i)?t.slice(e).indexOf(String.fromCodePoint(917631))+2:nn(i)?4:2}function $t(e){return e&&un(e[0].charCodeAt(0),55296,56319)}function en(e){return un(ln(e),127462,127487)}function tn(e){return un(ln(e),127988,127988)}function nn(e){return un(ln(e),127995,127999)}function rn(e){return typeof e==`string`&&un(e.charCodeAt(0),65024,65039)}function an(e){return typeof e==`string`&&un(e.charCodeAt(0),8400,8447)}function on(e){let t=e.codePointAt(0);return typeof e==`string`&&typeof t==`number`&&un(t,917504,917631)}function sn(e){return typeof e==`string`&&Xt.includes(e.charCodeAt(0))}function cn(e){return typeof e==`string`&&e.charCodeAt(0)===8205}function ln(e){let t=e.charCodeAt(0)-55296,n=e.charCodeAt(1)-56320;return(t<<10)+n+65536}function un(e,t,n){return e>=t&&e<=n}var dn=(e,t)=>Array.isArray(e)?e?.includes(t):e===t,fn=(e,t)=>Array.isArray(t)?t.some(t=>e.has(t)):e.has(t),pn=(e,t,n)=>{e.has(t)?e.get(t)?.push(n):e.set(t,[n])},mn=(()=>{let e=0;return()=>e++})(),hn={"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}}}};function gn(){let e=J.globalOpt.pixelDensity??1,t=J.globalOpt.width,n=J.globalOpt.height,r=J.gfx.ggl.gl.drawingBufferWidth,i=J.gfx.ggl.gl.drawingBufferHeight,a=r/e,o=i/e,s=0,c=0,l=a,u=o;if(J.globalOpt.letterbox){if(!t||!n)throw Error(`Letterboxing requires width and height defined.`);let e=a/o,r=t/n;if(e>r){let e=o*r;s=(a-e)/2,l=e}else{let e=a/r;u=e,c=(o-e)/2}}if(J.globalOpt.stretch&&(!J.globalOpt.width||!J.globalOpt.height))throw Error(`Stretching requires width and height defined.`);J.gfx.viewport={x:s,y:c,width:l,height:u,scale:(J.gfx.viewport.width+J.gfx.viewport.height)/(J.gfx.width+J.gfx.height)}}function _n(e){return new d(e.x*J.gfx.viewport.width/J.gfx.width,e.y*J.gfx.viewport.height/J.gfx.height)}function vn(e){return new d((e.x-J.gfx.viewport.x)*J.gfx.width/J.gfx.viewport.width,(e.y-J.gfx.viewport.y)*J.gfx.height/J.gfx.viewport.height)}var yn=()=>wn.lastInputDevice,bn=()=>{let e=wn.buttons;for(let t in e){let n=e[t].keyboard&&[e[t].keyboard].flat(),r=e[t].keyboardCode&&[e[t].keyboardCode].flat(),i=e[t].gamepad&&[e[t].gamepad].flat(),a=e[t].mouse&&[e[t].mouse].flat();
53n&&n.forEach(e=>{pn(wn.buttonsByKey,e,t)}),r&&r.forEach(e=>{pn(wn.buttonsByKeyCode,e,t)}),i&&i.forEach(e=>{pn(wn.buttonsByGamepad,e,t)}),a&&a.forEach(e=>{pn(wn.buttonsByMouse,e,t)})}},xn=class{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)}},Sn=class{buttonState=new xn;stickState=new Map},Cn=class{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((e,t)=>e+t)/this.dts.length)),this.dts=[])}},wn,Tn=hn,En=e=>{let t=e.buttons??{};return{canvas:e.canvas,buttons:t,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 Cn,timeScale:1,skipTime:!1,isHidden:!1,numFrames:0,mousePos:new d(0),mouseDeltaPos:new d(0),keyState:new xn,mouseState:new xn,mergedGamepadState:new Sn,gamepadStates:new Map,lastInputDevice:null,buttonState:new xn,gamepads:[],charInputted:[],isMouseMoved:!1,lastWidth:e.canvas.offsetWidth,lastHeight:e.canvas.offsetHeight,events:new jt}},Dn=e=>{if(!e.canvas)throw Error(`Please provide a canvas`);let t=En(e);wn=t,bn();function n(){return t.dt*t.timeScale}function r(){return t.fixedDt*t.timeScale}function i(){return t.restDt*t.timeScale}function a(){return t.isHidden}function o(){return t.time}function s(){return t.fpsCounter.fps}function c(){return t.numFrames}function u(){return t.canvas.toDataURL()}function p(e){t.canvas.style.cursor=e}function m(){return t.canvas.style.cursor}function h(e){if(e)try{let e=t.canvas.requestPointerLock();e?.catch&&e.catch(e=>console.error(e))}catch(e){console.error(e)}else document.exitPointerLock()}function g(){return!!document.pointerLockElement}function _(e){e.requestFullscreen?e.requestFullscreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen()}function v(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullScreen&&document.webkitExitFullScreen()}function y(e=!0){e?_(t.canvas):v()}function b(){return document.fullscreenElement===t.canvas||document.webkitFullscreenElement===t.canvas}function x(){t.stopped=!0;let e=Object.entries(V),n=Object.entries(Ie),r=Object.entries(Le);for(let[n,r]of e)t.canvas.removeEventListener(n,r);for(let[e,t]of n)document.removeEventListener(e,t);for(let[e,t]of r)window.removeEventListener(e,t);He.disconnect()}function S(r,i){t.loopID!==null&&cancelAnimationFrame(t.loopID);let a=0,o=0,s=c=>{if(t.stopped)return;if(document.visibilityState!==`visible`){t.loopID=requestAnimationFrame(s);return}let l=c/1e3,u=Math.min(l-t.realTime,.25),d=e.maxFPS?1/e.maxFPS:0;if(t.realTime=l,o+=u,o>d){if(!t.skipTime){for(a+=o,t.dt=t.fixedDt,t.restDt=0;a>t.fixedDt;)a-=t.fixedDt,a<t.fixedDt&&(t.restDt=a),r();t.restDt=a,t.dt=o,t.time+=n(),t.fpsCounter.tick(t.dt)}o=0,t.skipTime=!1,t.numFrames++,i(je,Me)}t.loopID=requestAnimationFrame(s)};s(0)}function C(){return`ontouchstart`in window||navigator.maxTouchPoints>0}function w(){return t.mousePos.clone()}function T(){return t.mouseDeltaPos.clone()}function E(e=`left`){return t.mouseState.pressed.has(e)}function D(e=`left`){return t.mouseState.down.has(e)}function O(e=`left`){return t.mouseState.released.has(e)}function ee(){return t.isMouseMoved}function te(e){return e===void 0?t.keyState.pressed.size>0:fn(t.keyState.pressed,e)}function ne(e){return e===void 0?t.keyState.pressedRepeat.size>0:fn(t.keyState.pressedRepeat,e)}function k(e){return e===void 0?t.keyState.down.size>0:fn(t.keyState.down,e)}function re(e){return e===void 0?t.keyState.released.size>0:fn(t.keyState.released,e)}function ie(e){return e===void 0?t.mergedGamepadState.buttonState.pressed.size>0:fn(t.mergedGamepadState.buttonState.pressed,e)}function A(e){return e===void 0?t.mergedGamepadState.buttonState.down.size>0:fn(t.mergedGamepadState.buttonState.down,e)}function ae(e){return e===void 0?t.mergedGamepadState.buttonState.released.size>0:fn(t.mergedGamepadState.buttonState.released,e)}function j(e){return e===void 0?t.buttonState.pressed.size>0:fn(t.buttonState.pressed,e)}function M(e){return e===void 0?t.buttonState.down.size>0:fn(t.buttonState.down,e)}function oe(e){return e===void 0?t.buttonState.released.size>0:fn(t.buttonState.released,e)}function N(e){return t.buttons?.[e]}function se(e,n){t.buttons[e]={...t.buttons[e],...n}}function P(e){t.buttonState.press(e),t.events.trigger(`buttonPress`,e)}function ce(e){t.buttonState.release(e),t.events.trigger(`buttonRelease`,e)}function le(e){return t.events.on(`resize`,e)}let F=U(e=>t.events.on(`keyDown`,e),(e,n)=>t.events.on(`keyDown`,t=>dn(e,t)&&n(t))),I=U(e=>t.events.on(`keyPress`,t=>e(t)),(e,n)=>t.events.on(`keyPress`,t=>dn(e,t)&&n(t))),ue=U(e=>t.events.on(`keyPressRepeat`,e),(e,n)=>t.events.on(`keyPressRepeat`,t=>dn(e,t)&&n(t))),de=U(e=>t.events.on(`keyRelease`,e),(e,n)=>t.events.on(`keyRelease`,t=>dn(e,t)&&n(t))),fe=U(e=>t.events.on(`mouseDown`,t=>e(t)),(e,n)=>t.events.on(`mouseDown`,t=>dn(e,t)&&n(t))),pe=U(e=>t.events.on(`mousePress`,t=>e(t)),(e,n)=>t.events.on(`mousePress`,t=>dn(e,t)&&n(t))),me=U(e=>t.events.on(`mouseRelease`,t=>e(t)),(e,n)=>t.events.on(`mouseRelease`,t=>t===e&&n(t)));function he(e){return t.events.on(`mouseMove`,()=>e(w(),T()))}function ge(e){return t.events.on(`charInput`,e)}function _e(e){return t.events.on(`touchStart`,e)}function ve(e){return t.events.on(`touchMove`,e)}function ye(e){return t.events.on(`touchEnd`,e)}function be(e){return t.events.on(`scroll`,e)}function xe(e){return t.events.on(`hide`,e)}function Se(e){return t.events.on(`show`,e)}let Ce=U(e=>t.events.on(`gamepadButtonPress`,(t,n)=>e(t,n)),(e,n)=>t.events.on(`gamepadButtonPress`,(t,r)=>dn(e,t)&&n(t,r))),we=U(e=>t.events.on(`gamepadButtonDown`,(t,n)=>e(t,n)),(e,n)=>t.events.on(`gamepadButtonDown`,(t,r)=>dn(e,t)&&n(t,r))),Te=U(e=>t.events.on(`gamepadButtonRelease`,(t,n)=>e(t,n)),(e,n)=>t.events.on(`gamepadButtonRelease`,(t,r)=>dn(e,t)&&n(t,r)));function Ee(e,n){return t.events.on(`gamepadStick`,(t,r,i)=>t===e&&n(r,i))}function De(e){t.events.on(`gamepadConnect`,e)}function Oe(e){t.events.on(`gamepadDisconnect`,e)}function L(e){return t.mergedGamepadState.stickState.get(e)||new d(0)}function R(){return[...t.charInputted]}function z(){return[...t.gamepads]}let ke=U(e=>t.events.on(`buttonPress`,t=>e(t)),(e,n)=>t.events.on(`buttonPress`,t=>dn(e,t)&&n(t))),Ae=U(e=>t.events.on(`buttonDown`,t=>e(t)),(e,n)=>t.events.on(`buttonDown`,t=>dn(e,t)&&n(t))),B=U(e=>t.events.on(`buttonRelease`,t=>e(t)),(e,n)=>t.events.on(`buttonRelease`,t=>dn(e,t)&&n(t)));function je(){t.events.trigger(`input`),t.keyState.down.forEach(e
53=>t.events.trigger(`keyDown`,e)),t.mouseState.down.forEach(e=>t.events.trigger(`mouseDown`,e)),t.buttonState.down.forEach(e=>{t.events.trigger(`buttonDown`,e)}),Fe()}function Me(){t.keyState.update(),t.mouseState.update(),t.buttonState.update(),t.mergedGamepadState.buttonState.update(),t.mergedGamepadState.stickState.forEach((e,n)=>{t.mergedGamepadState.stickState.set(n,new d(0))}),t.charInputted=[],t.isMouseMoved=!1,t.mouseDeltaPos=new d(0),t.gamepadStates.forEach(e=>{e.buttonState.update(),e.stickState.forEach((t,n)=>{e.stickState.set(n,new d(0))})})}function Ne(e){let n={index:e.index,isPressed:n=>t.gamepadStates.get(e.index)?.buttonState.pressed.has(n)||!1,isDown:n=>t.gamepadStates.get(e.index)?.buttonState.down.has(n)||!1,isReleased:n=>t.gamepadStates.get(e.index)?.buttonState.released.has(n)||!1,getStick:n=>t.gamepadStates.get(e.index)?.stickState.get(n)||f()};return t.gamepads.push(n),t.gamepadStates.set(e.index,{buttonState:new xn,stickState:new Map([[`left`,new d(0)],[`right`,new d(0)]])}),n}function Pe(e){t.gamepads=t.gamepads.filter(t=>t.index!==e.index),t.gamepadStates.delete(e.index)}function Fe(){for(let e of navigator.getGamepads())e&&!t.gamepadStates.has(e.index)&&Ne(e);for(let n of t.gamepads){let r=navigator.getGamepads()[n.index];if(!r)continue;let i=(e.gamepads??{})[r.id]||Tn[r.id]||Tn.default,a=t.gamepadStates.get(n.index);if(a){for(let e=0;e<r.buttons.length;e++){let o=i.buttons[e],s=r.buttons[e],c=t.buttonsByGamepad.has(o);if(s.pressed){if(a.buttonState.down.has(o)){t.events.trigger(`gamepadButtonDown`,o,n);continue}t.lastInputDevice=`gamepad`,c&&t.buttonsByGamepad.get(o)?.forEach(e=>{t.buttonState.press(e),t.events.trigger(`buttonPress`,e)}),t.mergedGamepadState.buttonState.press(o),a.buttonState.press(o),t.events.trigger(`gamepadButtonPress`,o,n)}else a.buttonState.down.has(o)&&(c&&t.buttonsByGamepad.get(o)?.forEach(e=>{t.buttonState.release(e),t.events.trigger(`buttonRelease`,e)}),t.mergedGamepadState.buttonState.release(o),a.buttonState.release(o),t.events.trigger(`gamepadButtonRelease`,o,n))}for(let e in i.sticks){let o=i.sticks[e];if(!o)continue;let s=new d(r.axes[o.x],r.axes[o.y]);a.stickState.set(e,s),t.mergedGamepadState.stickState.set(e,s),t.events.trigger(`gamepadStick`,e,s,n)}}}}let V={},Ie={},Le={},Re=e.pixelDensity||1;V.mousemove=e=>{let n=vn(new d(e.offsetX,e.offsetY)),r=new d(e.movementX,e.movementY);if(b()){let r=t.canvas.width/Re,i=t.canvas.height/Re,a=window.innerWidth,o=window.innerHeight;if(a/o>r/i){let t=o/i,s=(a-r*t)/2;n.x=l(e.offsetX-s,0,r*t,0,r),n.y=l(e.offsetY,0,i*t,0,i)}else{let t=a/r,s=(o-i*t)/2;n.x=l(e.offsetX,0,r*t,0,r),n.y=l(e.offsetY-s,0,i*t,0,i)}}t.events.onOnce(`input`,()=>{t.isMouseMoved=!0,t.mousePos=n,t.mouseDeltaPos=r,t.events.trigger(`mouseMove`)})};let ze=[`left`,`middle`,`right`,`back`,`forward`];V.mousedown=e=>{t.events.onOnce(`input`,()=>{let n=ze[e.button];n&&(t.lastInputDevice=`mouse`,t.buttonsByMouse.has(n)&&t.buttonsByMouse.get(n)?.forEach(e=>{t.buttonState.press(e),t.events.trigger(`buttonPress`,e)}),t.mouseState.press(n),t.events.trigger(`mousePress`,n))})},V.mouseup=e=>{t.events.onOnce(`input`,()=>{let n=ze[e.button];n&&(t.buttonsByMouse.has(n)&&t.buttonsByMouse.get(n)?.forEach(e=>{t.buttonState.release(e),t.events.trigger(`buttonRelease`,e)}),t.mouseState.release(n),t.events.trigger(`mouseRelease`,n))})};let Be=new Set([` `,`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Tab`]),Ve={ArrowLeft:`left`,ArrowRight:`right`,ArrowUp:`up`,ArrowDown:`down`," ":`space`};V.keydown=e=>{Be.has(e.key)&&e.preventDefault(),t.events.onOnce(`input`,()=>{let n=Ve[e.key]||e.key.toLowerCase(),r=e.code;if(n===void 0)throw Error(`Unknown key: ${e.key}`);n.length===1?(t.events.trigger(`charInput`,n),t.charInputted.push(n)):n===`space`&&(t.events.trigger(`charInput`,` `),t.charInputted.push(` `)),e.repeat?(t.keyState.pressRepeat(n),t.events.trigger(`keyPressRepeat`,n)):(t.lastInputDevice=`keyboard`,t.buttonsByKey.has(n)&&t.buttonsByKey.get(n)?.forEach(e=>{t.buttonState.press(e),t.events.trigger(`buttonPress`,e)}),t.buttonsByKeyCode.has(r)&&t.buttonsByKeyCode.get(r)?.forEach(e
53=>{t.buttonState.press(e),t.events.trigger(`buttonPress`,e)}),t.keyState.press(n),t.events.trigger(`keyPressRepeat`,n),t.events.trigger(`keyPress`,n))})},V.keyup=e=>{t.events.onOnce(`input`,()=>{let n=Ve[e.key]||e.key.toLowerCase(),r=e.code;t.buttonsByKey.has(n)&&t.buttonsByKey.get(n)?.forEach(e=>{t.buttonState.release(e),t.events.trigger(`buttonRelease`,e)}),t.buttonsByKeyCode.has(r)&&t.buttonsByKeyCode.get(r)?.forEach(e=>{t.buttonState.release(e),t.events.trigger(`buttonRelease`,e)}),t.keyState.release(n),t.events.trigger(`keyRelease`,n)})},V.touchstart=n=>{n.preventDefault(),t.events.onOnce(`input`,()=>{let r=[...n.changedTouches],i=t.canvas.getBoundingClientRect();e.touchToMouse!==!1&&(t.mousePos=vn(new d(r[0].clientX-i.x,r[0].clientY-i.y)),t.lastInputDevice=`mouse`,t.buttonsByMouse.has(`left`)&&t.buttonsByMouse.get(`left`)?.forEach(e=>{t.buttonState.press(e),t.events.trigger(`buttonPress`,e)}),t.mouseState.press(`left`),t.events.trigger(`mousePress`,`left`)),r.forEach(e=>{t.events.trigger(`touchStart`,vn(new d(e.clientX-i.x,e.clientY-i.y)),e)})})},V.touchmove=n=>{n.preventDefault(),t.events.onOnce(`input`,()=>{let r=[...n.changedTouches],i=t.canvas.getBoundingClientRect();if(e.touchToMouse!==!1){let e=t.mousePos;t.mousePos=vn(new d(r[0].clientX-i.x,r[0].clientY-i.y)),t.mouseDeltaPos=t.mousePos.sub(e),t.events.trigger(`mouseMove`)}r.forEach(e=>{t.events.trigger(`touchMove`,vn(new d(e.clientX-i.x,e.clientY-i.y)),e)})})},V.touchend=n=>{t.events.onOnce(`input`,()=>{let r=[...n.changedTouches],i=t.canvas.getBoundingClientRect();e.touchToMouse!==!1&&(t.mousePos=vn(new d(r[0].clientX-i.x,r[0].clientY-i.y)),t.mouseDeltaPos=new d(0,0),t.buttonsByMouse.has(`left`)&&t.buttonsByMouse.get(`left`)?.forEach(e=>{t.buttonState.release(e),t.events.trigger(`buttonRelease`,e)}),t.mouseState.release(`left`),t.events.trigger(`mouseRelease`,`left`)),r.forEach(e=>{t.events.trigger(`touchEnd`,vn(new d(e.clientX-i.x,e.clientY-i.y)),e)})})},V.touchcancel=n=>{t.events.onOnce(`input`,()=>{let r=[...n.changedTouches],i=t.canvas.getBoundingClientRect();e.touchToMouse!==!1&&(t.mousePos=vn(new d(r[0].clientX-i.x,r[0].clientY-i.y)),t.mouseState.release(`left`),t.events.trigger(`mouseRelease`,`left`)),r.forEach(e=>{t.events.trigger(`touchEnd`,vn(new d(e.clientX-i.x,e.clientY-i.y)),e)})})},V.wheel=e=>{e.preventDefault(),t.events.onOnce(`input`,()=>{t.events.trigger(`scroll`,new d(e.deltaX,e.deltaY))})},V.contextmenu=e=>e.preventDefault(),Ie.visibilitychange=()=>{document.visibilityState===`visible`?(t.skipTime=!0,t.isHidden=!1,t.events.trigger(`show`)):(t.isHidden=!0,t.events.trigger(`hide`))},Le.gamepadconnected=e=>{let n=Ne(e.gamepad);t.events.onOnce(`input`,()=>{t.events.trigger(`gamepadConnect`,n)})},Le.gamepaddisconnected=e=>{let n=z().filter(t=>t.index===e.gamepad.index)[0];Pe(e.gamepad),t.events.onOnce(`input`,()=>{t.events.trigger(`gamepadDisconnect`,n)})};for(let[e,n]of Object.entries(V))t.canvas.addEventListener(e,n);for(let[e,t]of Object.entries(Ie))document.addEventListener(e,t);for(let[e,t]of Object.entries(Le))window.addEventListener(e,t);let He=new ResizeObserver(e=>{for(let n of e)if(n.target===t.canvas){if(t.lastWidth===t.canvas.offsetWidth&&t.lastHeight===t.canvas.offsetHeight)return;t.lastWidth=t.canvas.offsetWidth,t.lastHeight=t.canvas.offsetHeight,t.events.onOnce(`input`,()=>{t.events.trigger(`resize`)})}});return He.observe(t.canvas),{state:t,dt:n,fixedDt:r,restDt:i,time:o,run:S,canvas:t.canvas,fps:s,numFrames:c,quit:x,isHidden:a,setFullscreen:y,isFullscreen:b,setCursor:p,screenshot:u,getGamepads:z,getCursor:m,setCursorLocked:h,isCursorLocked:g,isTouchscreen:C,mousePos:w,mouseDeltaPos:T,isKeyDown:k,isKeyPressed:te,isKeyPressedRepeat:ne,isKeyReleased:re,isMouseDown:D,isMousePressed:E,isMouseReleased:O,isMouseMoved:ee,isGamepadButtonPressed:ie,isGamepadButtonDown:A,isGamepadButtonReleased:ae,getGamepadStick:L,isButtonPressed:j,isButtonDown:M,isButtonReleased:oe,setButton:se,getButton:N,pressButton:P,releaseButton:ce,charInputted:R,onResize:le,onKeyDown:F,onKeyPress:I,onKeyPressRepeat:ue,onKeyRelease:de,onMouseDown:fe,onMousePress:pe,onMouseRelease:me,onMouseMove:he,onCh
53arInput:ge,onTouchStart:_e,onTouchMove:ve,onTouchEnd:ye,onScroll:be,onHide:xe,onShow:Se,onGamepadButtonDown:we,onGamepadButtonPress:Ce,onGamepadButtonRelease:Te,onGamepadStick:Ee,onGamepadConnect:De,onGamepadDisconnect:Oe,onButtonPress:ke,onButtonDown:Ae,onButtonRelease:B,getLastInputDeviceType:yn,events:t.events}};function W(){return J.app.dt()}function On(){return J.app.fixedDt()}function kn(){return J.app.restDt()}var An=new d(-1,-1),jn=new d(0,-1),Mn=new d(1,-1),Nn=new d(-1,0),Pn=new d(0,0),Fn=new d(1,0),In=new d(-1,1),Ln=new d(0,1),Rn=new d(1,1);function zn(e){switch(e){case`topleft`:return An;case`top`:return jn;case`topright`:return Mn;case`left`:return Nn;case`center`:return Pn;case`right`:return Fn;case`botleft`:return In;case`bot`:return Ln;case`botright`:return Rn;default:return e}}function Bn(e){switch(e){case`left`:return 0;case`center`:return .5;case`right`:return 1;default:return 0}}function Vn(e){return e.createBuffer(1,1,44100)}var Hn=2.5949095,Un=2.70158,Wn=2*Math.PI/3,Gn=2*Math.PI/4.5,Kn={linear:e=>e,easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,easeInQuad:e=>e*e,easeOutQuad:e=>1-(1-e)*(1-e),easeInOutQuad:e=>e<.5?2*e*e:1-(-2*e+2)**2/2,easeInCubic:e=>e*e*e,easeOutCubic:e=>1-(1-e)**3,easeInOutCubic:e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,easeInQuart:e=>e*e*e*e,easeOutQuart:e=>1-(1-e)**4,easeInOutQuart:e=>e<.5?8*e*e*e*e:1-(-2*e+2)**4/2,easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>1-(1-e)**5,easeInOutQuint:e=>e<.5?16*e*e*e*e*e:1-(-2*e+2)**5/2,easeInExpo:e=>e===0?0:2**(10*e-10),easeOutExpo:e=>e===1?1:1-2**(-10*e),easeInOutExpo:e=>e===0?0:e===1?1:e<.5?2**(20*e-10)/2:(2-2**(-20*e+10))/2,easeInCirc:e=>1-Math.sqrt(1-e**2),easeOutCirc:e=>Math.sqrt(1-(e-1)**2),easeInOutCirc:e=>e<.5?(1-Math.sqrt(1-(2*e)**2))/2:(Math.sqrt(1-(-2*e+2)**2)+1)/2,easeInBack:e=>Un*e*e*e-1.70158*e*e,easeOutBack:e=>1+Un*(e-1)**3+1.70158*(e-1)**2,easeInOutBack:e=>e<.5?(2*e)**2*((Hn+1)*2*e-Hn)/2:((2*e-2)**2*((Hn+1)*(e*2-2)+Hn)+2)/2,easeInElastic:e=>e===0?0:e===1?1:-(2**(10*e-10))*Math.sin((e*10-10.75)*Wn),easeOutElastic:e=>e===0?0:e===1?1:2**(-10*e)*Math.sin((e*10-.75)*Wn)+1,easeInOutElastic:e=>e===0?0:e===1?1:e<.5?-(2**(20*e-10)*Math.sin((20*e-11.125)*Gn))/2:2**(-20*e+10)*Math.sin((20*e-11.125)*Gn)/2+1,easeInBounce:e=>1-Kn.easeOutBounce(1-e),easeOutBounce:e=>e<1/2.75?7.5625*e*e:e<2/2.75?7.5625*(e-=1.5/2.75)*e+.75:e<2.5/2.75?7.5625*(e-=2.25/2.75)*e+.9375:7.5625*(e-=2.625/2.75)*e+.984375,easeInOutBounce:e=>e<.5?(1-Kn.easeOutBounce(1-2*e))/2:(1+Kn.easeOutBounce(2*e-1))/2},qn=Kn;function Jn(e,t,n){let r=[],i=t;for(r.push(i);i!==e;){if(i=n.get(i),i==null)return null;r.push(i)}return r.reverse()}function Yn(e,t,n){let r=new Ft((e,t)=>e.cost<t.cost);r.insert({cost:0,node:t});let i=new Map;i.set(t,t);let a=new Map;for(a.set(t,0);r.length!==0;){let t=r.remove()?.node;if(t===n)break;let o=e.getNeighbours(t);for(let s of o){let o=(a.get(t)||0)+e.getCost(t,s)+e.getHeuristic(s,n);(!a.has(s)||o<a.get(s))&&(a.set(s,o),r.insert({cost:o,node:s}),i.set(s,t))}}return Jn(t,n,i)}var Xn=class{a;b;polygon;constructor(e,t,n){this.a=e,this.b=t,this.polygon=new WeakRef(n)}isLeft(e,t){return(this.b.x-this.a.x)*(t-this.a.y)-(e-this.a.x)*(this.b.y-this.a.y)}get middle(){return this.a.add(this.b).scale(.5)}},Zn=class{_edges;_centroid;_id;constructor(e){this._id=e}get id(){return this._id}set edges(e){this._edges=e;let t=0,n=0,r=0;for(let e of this._edges){e.polygon=new WeakRef(this);let i=e.a.x*e.b.y-e.a.y*e.b.x;t+=(e.a.x+e.b.x)*i,n+=(e.a.y+e.b.y)*i,r+=i}r/=2,this._centroid=f(t/(6*r),n/(6*r))}get edges(){return this._edges}get centroid(){return this._centroid}contains(e){let t=!1;for(let n of this.edges)n.b.y>e.y!=n.a.y>e.y&&e.x<(n.a.x-n.b.x)*(e.y-n.b.y)/(n.a.y-n.b.y)+n.b.x&&(t=!t);return t}},Qn=class{_polygons;_pointCache;_edgeCache;constructor(){this._polygons=[],this._pointCache={},this._edgeCache={}}_addPoint(e){let t=this._pointCache[`${e.x}_${e.y}`];return t||(t=e.clone(),this._pointCache[`${e.x}_${e.y}`]=t,t)}_addEdge(e){let t=`${e.a.x}_${e.a.y}-${e.b.x}_${e.b.y}`;return this._edgeCache[t]=e,e}_findEdge(e,t){let n=`${e.x}_${e.y}-${t.x}_${t.y}`;return this._edgeCache[n]}_findCommonEdge(e,t){for(let n of e.edges){let e=this._findEdge(n.b,n.a);if(e&&e.polygon.deref().id===t.id)return e}return null}addPolygon(e){let t=new Zn(this._polygons.length);t.edges=e.map((n,r)=>new Xn(n,e[(r+1)%e.length],t)),this._polygons.push(t);for(let e of t.edges)this._addEdge(e);return t}addRect(e,t){let n=this._addPoint(e),r=this._addPoint(e.add(t.x,0)),i=this._addPoint(e.add(t)),a=this._addPoint(e.add(0,t.y));return this.addPolygon([n,r,i,a])}_getLocation(e){for(let t of this._polygons)if(t.contains(e))return t;return null}getNeighbours(e){let t=[];for(let n of this._polygons[e].edges){let e=this._findEdge(n.b,n.a);if(e){let n=e.polygon.deref();
53n&&t.push(n.id)}}return t}getCost(e,t){return 1}getHeuristic(e,t){let n=this._polygons[e],r=this._polygons[t],i=n.centroid.x-r.centroid.x,a=n.centroid.y-r.centroid.y;return Math.sqrt(i*i+a*a)}getPath(e,t){return e===void 0||t===void 0?[]:e===t?[e,t]:Yn(this,e,t)}getWaypointPath(e,t,n){let r=n?.type||`centroids`,i=this._getLocation(e),a=this._getLocation(t);if(i===void 0||a===void 0)return[];let o=this.getPath(i.id,a.id);if(!o)return[];if(r===`edges`){let n=[];for(let e=1;e<o.length;e++){let t=this._polygons[o[e-1]],r=this._polygons[o[e]],i=this._findCommonEdge(t,r);n.push(i.middle.add(r.centroid.sub(i.middle).unit().scale(4)))}return[e,...n,t]}return[e,...o.slice(1,-1).map(e=>this._polygons[e].centroid),t]}};function $n(e){let t=new _;return e.pos&&t.translate(e.pos),e.scale&&t.scale(e.scale),e.angle&&t.rotate(e.angle),e.parent?t.mult(e.parent.transform):t}function er(e){return new d(e.x/K()*2-1,-e.y/q()*2+1)}function tr(e,t,n,r,i,a=1){r=o(r%360),i=o(i%360),i<=r&&(i+=Math.PI*2);let s=[],c=Math.ceil((i-r)/o(8)*a),l=(i-r)/c,u=f(Math.cos(r),Math.sin(r)),d=f(Math.cos(l),Math.sin(l));for(let r=0;r<=c;r++)s.push(e.add(t*u.x,n*u.y)),u=f(u.x*d.x-u.y*d.y,u.x*d.y+u.y*d.x);return s}function nr(...e){let t=i(...e),n=e[3]??1;J.gfx.bgColor=t,J.gfx.bgAlpha=n,J.gfx.ggl.gl.clearColor(t.r/255,t.g/255,t.b/255,n)}function rr(){return J.gfx.bgColor?.clone?.()??null}function G(...e){if(e[0]===void 0)return;let t=f(...e);t.x===0&&t.y===0||J.gfx.transform.translate(t)}function ir(){J.gfx.transformStack.push(J.gfx.transform.clone())}function ar(e){J.gfx.transform=e.clone()}function or(...e){if(e[0]===void 0)return;let t=f(...e);t.x===1&&t.y===1||J.gfx.transform.scale(t)}function sr(e){e&&J.gfx.transform.rotate(e)}function cr(){J.gfx.transformStack.length>0&&(J.gfx.transform=J.gfx.transformStack.pop())}function lr(){J.gfx.renderer.flush()}function K(){return J.gfx.width}function q(){return J.gfx.height}function ur(){return(J.gfx.viewport.width+J.gfx.viewport.height)/(J.gfx.width+J.gfx.height)}function dr(){return f(K()/2,q()/2)}var fr=class{lastTextureId=0;textures=[];bigTextures=[];texturesPosition=new Map;canvas;c2d;x=0;y=0;curHeight=0;gfx;padding;constructor(e,t,n,r){this.gfx=e,this.canvas=document.createElement(`canvas`),this.canvas.width=t,this.canvas.height=n,this.textures=[mi.fromImage(e,this.canvas)],this.bigTextures=[],this.padding=r;let i=this.canvas.getContext(`2d`);if(!i)throw Error(`Failed to get 2d context`);this.c2d=i}addSingle(e){let t=mi.fromImage(this.gfx,e);return this.bigTextures.push(t),[t,new p(0,0,1,1),0]}
53add(e){let t=e.width+this.padding*2,n=e.height+this.padding*2;if(t>this.canvas.width||n>this.canvas.height)return this.addSingle(e);this.x+t>this.canvas.width&&(this.x=0,this.y+=this.curHeight,this.curHeight=0),this.y+n>this.canvas.height&&(this.c2d.clearRect(0,0,this.canvas.width,this.canvas.height),this.textures.push(mi.fromImage(this.gfx,this.canvas)),this.x=0,this.y=0,this.curHeight=0);let r=this.textures[this.textures.length-1],i=new d(this.x+this.padding,this.y+this.padding);return this.x+=t,n>this.curHeight&&(this.curHeight=n),e instanceof ImageData?this.c2d.putImageData(e,i.x,i.y):this.c2d.drawImage(e,i.x,i.y),r.update(this.canvas),this.texturesPosition.set(this.lastTextureId,{position:i,size:new d(e.width,e.height),texture:r}),this.lastTextureId++,[r,new p(i.x/this.canvas.width,i.y/this.canvas.height,e.width/this.canvas.width,e.height/this.canvas.height),this.lastTextureId-1]}free(){for(let e of this.textures)e.free();for(let e of this.bigTextures)e.free()}};function pr(e){return typeof e!=`string`||Ht(e)?e:J.assets.urlPrefix+e}var mr=class e{loaded=!1;data=null;error=null;onLoadEvents=new H;onErrorEvents=new H;onFinishEvents=new H;constructor(e){e.then(e=>{this.loaded=!0,this.data=e,this.onLoadEvents.trigger(e)}).catch(e=>{if(this.error=e,this.onErrorEvents.numListeners()>0)this.onErrorEvents.trigger(e);else throw e}).finally(()=>{this.onFinishEvents.trigger(),this.loaded=!0})}static loaded(t){let n=new e(Promise.resolve(t));return n.data=t,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)}},hr=class{assets=new Map;lastUID=0;add(e,t){let n=e??this.lastUID+++``,r=new mr(t);return this.assets.set(n,r),r}addLoaded(e,t){let n=e??this.lastUID+++``,r=mr.loaded(t);return this.assets.set(n,r),r}get(e){return this.assets.get(e)}progress(){if(this.assets.size===0)return 1;let e=0;return this.assets.forEach(t=>{t.loaded&&e++}),e/this.assets.size}getFailedAssets(){return Array.from(this.assets.keys()).filter(e=>this.assets.get(e).error!==null).map(e=>[e,this.assets.get(e)])}};function gr(e){return fetch(e).then(t=>{if(!t.ok)throw Error(`Failed to fetch "${e}"`);return t})}function _r(e){return gr(e).then(e=>e.json())}function vr(e){return gr(e).then(e=>e.text())}function yr(e){return gr(e).then(e=>e.arrayBuffer())}function br(e){return e!==void 0&&(J.assets.urlPrefix=e),J.assets.urlPrefix}function xr(e,t){return J.assets.custom.add(e,_r(pr(t)))}function Sr(e){let t=new Image;return t.crossOrigin=`anonymous`,t.src=e,new Promise((n,r)=>{t.onload=()=>n(t),t.onerror=()=>r(Error(`Failed to load image from "${e}"`))})}function Cr(){let e=[J.assets.sprites,J.assets.sounds,J.assets.shaders,J.assets.fonts,J.assets.bitmapFonts,J.assets.custom];return e.reduce((e,t)=>e+t.progress(),0)/e.length}function wr(){return[J.assets.sprites,J.assets.sounds,J.assets.shaders,J.assets.fonts,J.assets.bitmapFonts,J.assets.custom].reduce((e,t)=>e.concat(t.getFailedAssets()),[])}function Tr(e){return J.assets.custom.get(e)??null}function Er(e){return J.assets.custom.add(null,e)}var Dr=(e,t)=>({urlPrefix:``,sprites:new hr,fonts:new hr,bitmapFonts:new hr,sounds:new hr,shaders:new hr,custom:new hr,music:{},packer:new fr(e,2048,2048,t),loaded:!1}),Or=`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==`,kr=class e{tex;frames=[new p(0,0,1,1)];anims={};slice9=null;constructor(e,t,n={},r=null){this.tex=e,t&&(this.frames=t),this.anims=n,this.slice9=r}get width(){return this.tex.width*this.frames[0].w}get height(){return this.tex.height*this.frames[0].h}static from(t,n={}){return typeof t==`string`?e.fromURL(t,n):Promise.resolve(e.fromImage(t,n))}static fromImage(t,n={}){let[r,i]=n.singular?J.assets.packer.addSingle(t):J.assets.packer.add(t),a=n.frames?n.frames.map(e=>new p(i.x+e.x*i.w,i.y+e.y*i.h,e.w*i.w,e.h*i.h)):Nr(n.sliceX||1,n.sliceY||1,i.x,i.y,i.w,i.h);return new e(r,a,n.anims,n.slice9)}static fromURL(t,n={}){return Sr(t).then(t=>e.fromImage(t,n))}};function Ar(e){if(typeof e==`string`){let t=jr(e);
53if(t)return t;if(Cr()<1)return null;throw Error(`Sprite not found: ${e}`)}if(e instanceof kr)return mr.loaded(e);if(e instanceof mr)return e;throw Error(`Invalid sprite: ${e}`)}function jr(e){return J.assets.sprites.get(e)??null}function Mr(e,t,n={sliceX:1,sliceY:1,anims:{}}){return t=pr(t),Array.isArray(t)?t.some(e=>typeof e==`string`)?J.assets.sprites.add(e,Promise.all(t.map(e=>typeof e==`string`?Sr(e):Promise.resolve(e))).then(e=>Pr(e,n))):J.assets.sprites.addLoaded(e,Pr(t,n)):typeof t==`string`?J.assets.sprites.add(e,kr.from(t,n)):J.assets.sprites.addLoaded(e,kr.fromImage(t,n))}function Nr(e=1,t=1,n=0,r=0,i=1,a=1){let o=[],s=i/e,c=a/t;for(let i=0;i<t;i++)for(let t=0;t<e;t++)o.push(new p(n+t*s,r+i*c,s,c));return o}function Pr(e,t={}){let n=document.createElement(`canvas`),r=e[0].width,i=e[0].height;n.width=r*e.length,n.height=i;let a=n.getContext(`2d`);if(!a)throw Error(`Failed to create canvas context`);e.forEach((e,t)=>{e instanceof ImageData?a.putImageData(e,t*r,0):a.drawImage(e,t*r,0)});let o=a.getImageData(0,0,e.length*r,i);return kr.fromImage(o,{...t,sliceX:e.length,sliceY:1})}function Fr(e=`bean`){return Mr(e,Or)}function Ir(e,t,n){t=pr(t),n=pr(n),typeof t==`string`&&!n&&(n=Ut(t)+`.json`);let r=typeof n==`string`?_r(n):Promise.resolve(n);return J.assets.sprites.add(e,r.then(e=>{let n=e.meta.size,r=e.frames.map(e=>new p(e.frame.x/n.w,e.frame.y/n.h,e.frame.w/n.w,e.frame.h/n.h)),i={};for(let t of e.meta.frameTags)t.from===t.to?i[t.name]=t.from:i[t.name]={from:t.from,to:t.to,speed:10,loop:!0,pingpong:t.direction===`pingpong`};return kr.from(t,{frames:r,anims:i})}))}var Lr=class{fontface;filter=pt;outline=null;size=64;constructor(e,t={}){if(this.fontface=e,this.filter=t.filter??pt,this.size=t.size??64,this.size>256)throw Error(`Max font size: 256`);t.outline&&(this.outline={width:1,color:i(0,0,0)},typeof t.outline==`number`?this.outline.width=t.outline:typeof t.outline==`object`&&(t.outline.width&&(this.outline.width=t.outline.width),t.outline.color&&(this.outline.color=t.outline.color)))}};function Rr(e){if(!e)return Rr(J.globalOpt.font??dt);if(typeof e==`string`){let t=Hr(e),n=zr(e);if(t)return t.data??t;if(n)return n.data??n;if(document.fonts.check(`64px ${e}`))return e;if(Cr()<1)return null;throw Error(`Font not found: ${e}`)}return e instanceof mr&&e.data?e.data:e}function zr(e){return J.assets.fonts.get(e)??null}function Br(e,t,n={}){let r=pr(t),i=new FontFace(e,typeof t==`string`?`url(${r})`:r);return document.fonts.add(i),J.assets.fonts.add(e,i.load().catch(e=>{throw Error(`Failed to load font from "${r}": ${e}`)}).then(e=>new Lr(e,n)))}function Vr(e,t,n,r){let i=e.width/t,a={},o=r.split(``).entries();for(let[e,r]of o)a[r]=new p(e%i*t,Math.floor(e/i)*n,t,n);return{tex:e,map:a,size:n}}function Hr(e){return J.assets.bitmapFonts.get(e)??null}function Ur(e,t,n,r,i={}){let a=pr(t);return J.assets.bitmapFonts.add(e,Sr(a).then(e=>Vr(mi.fromImage(J.gfx.ggl,e,i),n,r,i.chars??lt)))}function Wr(e,t){return t=pr(t),J.assets.sprites.add(e,new Promise(async e=>{let n=typeof t==`string`?await _r(t):t,r=await Promise.all(n.frames.map(Sr)),i=document.createElement(`canvas`);i.width=n.width,i.height=n.height*n.frames.length;let a=i.getContext(`2d`);if(!a)throw Error(`Failed to create canvas context`);r.forEach((e,t)=>{a.drawImage(e,0,t*n.height)}),e(await Mr(null,i,{sliceY:n.frames.length,anims:n.anims}))}))}var Gr=class{ctx;glProgram;constructor(e,t,n,r){this.ctx=e,e.onDestroy(()=>this.free());let i=e.gl,a=i.createShader(i.VERTEX_SHADER),o=i.createShader(i.FRAGMENT_SHADER);if(!a||!o)throw Error(`Failed to create shader`);i.shaderSource(a,t),i.shaderSource(o,n),i.compileShader(a),i.compileShader(o);let s=i.createProgram();if(this.glProgram=s,i.attachShader(s,a),i.attachShader(s,o),r.forEach((e,t)=>i.bindAttribLocation(s,t,e)),i.linkProgram(s),!i.getProgramParameter(s,i.LINK_STATUS)){let e=i.getShaderInfoLog(a);if(e)throw Error(`VERTEX SHADER `+e);let t=i.getShaderInfoLog(o);if(t)throw Error(`FRAGMENT SHADER `+t)}i.deleteShader(a),i.deleteShader(o)}bind(){this.ctx.pushProgram(this.glProgram)}unbind(){this.ctx.popProgram()}send(e){let t=this.ctx.gl;for(let n in e){let i=e[n],a=t.getUniformLocation(this.glProgram,n);if(typeof i==`number`)t.uniform1f(a,i);else if(i instanceof _)t.uniformMatrix4fv(a,!1,new Float32Array(i.m));else if(i instanceof r)t.uniform3f(a,i.r,i.g,i.b);else if(i instanceof d)t.uniform2f(a,i.x,i.y);else if(Array.isArray(i))i[0],Pt(i)?t.uniform1fv(a,i):Nt(i)?t.uniform2fv(a,i.map(e=>[e.x,e.y]).flat()):Mt(i)&&t.uniform3fv(a,i.map(e=>[e.r,e.g,e.b]).flat());else throw Error(`Unsupported uniform data type`)}}free(){this.ctx.gl.deleteProgram(this.glProgram)}};function Kr(e,t=xt,n=St){let r=yt.replace(`{{user}}`,t??xt),i=bt.replace(`{{user}}`,n??St);try{return new Gr(e,r,i,mt.map(e=>e.name))}catch(e){let t=Kt(e).match(/(?<type>^\w+) SHADER ERROR: 0:(?<line>\d+): (?<msg>.+)/);if(!t?.groups)throw e;let n=Number(t.groups.line)-14,r=t.groups.msg.trim(),i=t.groups.type.toLowerCase();throw Error(`${i} shader line ${n}: ${r}`)}}function qr(e){if(!e)return J.gfx.defShader;if(typeof e==`string`){let t=Jr(e);if(t)return t.data??t;if(Cr()<1)return null;throw Error(`Shader not found: ${e}`)}return e instanceof mr&&e.data?e.data:e}function Jr(e){return J.assets.shaders.get(e)??null}function Yr(e,t,n){return J.assets.shaders.addLoaded(e,Kr(J.gfx.ggl,t,n))}function Xr(e,t,n){t=pr(t),n=pr(n);let r=e=>e?vr(e):Promise.resolve(null),i=Promise.all([r(t),r(n)]).then(([e,t])=>Kr(J.gfx.ggl,e,t));return J.assets.shaders.add(e,i)}var Zr=class e{buf;constructor(e){this.buf=e}
53static fromArrayBuffer(t){return new Promise((e,n)=>J.audio.ctx.decodeAudioData(t,e,n)).then(t=>new e(t))}static fromURL(t){return Ht(t)?e.fromArrayBuffer(Lt(t)):yr(t).then(t=>e.fromArrayBuffer(t))}};function Qr(e){if(typeof e==`string`){let t=$r(e);if(t)return t;if(Cr()<1)return null;throw Error(`Sound not found: ${e}`)}if(e instanceof Zr)return mr.loaded(e);if(e instanceof mr)return e;throw Error(`Invalid sound: ${e}`)}function $r(e){return J.assets.sounds.get(e)??null}function ei(e,t){return t=pr(t),J.assets.sounds.add(e,typeof t==`string`?Zr.fromURL(t):Zr.fromArrayBuffer(t))}function ti(e,t){let n=pr(t),r=new Audio(n);return r.preload=`auto`,J.assets.music[e]=n}function ni(e,t){return e=pr(e),Er(typeof t==`string`?new Promise((n,r)=>{_r(t).then(t=>{ni(e,t).then(n).catch(r)})}):kr.from(e).then(e=>{let n={};for(let r in t){let i=t[r],a=e.frames[0],o=2048*a.w,s=2048*a.h,c=i.frames?i.frames.map(e=>new p(a.x+(i.x+e.x)/o*a.w,a.y+(i.y+e.y)/s*a.h,e.w/o*a.w,e.h/s*a.h)):Nr(i.sliceX||1,i.sliceY||1,a.x+i.x/o*a.w,a.y+i.y/s*a.h,i.width/o*a.w,i.height/s*a.h),l=new kr(e.tex,c,i.anims);J.assets.sprites.addLoaded(r,l),n[r]=l}return n}))}function ri(e,t,n=!1,r,i,a={}){let o=r??J.gfx.defTex,s=qr(i??J.gfx.defShader);if(!s||s instanceof mr)return;let c=J.gfx.fixed||n?J.gfx.transform:J.game.cam.transform.mult(J.gfx.transform),l=[];for(let t of e){let e=er(c.multVec2(t.pos));l.push(e.x,e.y,t.uv.x,t.uv.y,t.color.r/255,t.color.g/255,t.color.b/255,t.opacity)}J.gfx.renderer.push(J.gfx.ggl.gl.TRIANGLES,l,t,s,o,a)}function ii(e){if(!e.pts)throw Error(`drawPolygon() requires property "pts".`);let t=e.pts.length;if(!(t<3)){if(ir(),G(e.pos),or(e.scale),sr(e.angle),G(e.offset),e.fill!==!1){let n=e.color??r.WHITE,i=e.pts.map((t,r)=>({pos:new d(t.x,t.y),uv:e.uv?e.uv[r]:new d(0,0),color:e.colors&&e.colors[r]?e.colors[r].mult(n):n,opacity:e.opacity??1})),a;a=e.triangulate?st(e.pts).map(t=>t.map(t=>e.pts.indexOf(t))).flat():[...Array(t-2).keys()].map(e=>[0,e+1,e+2]).flat(),ri(i,e.indices??a,e.fixed,e.uv?e.tex:J.gfx.defTex,e.shader,e.uniform??void 0)}e.outline&&di({pts:[...e.pts,e.pts[0]],radius:e.radius,width:e.outline.width,color:e.outline.color,join:e.outline.join,uniform:e.uniform,fixed:e.fixed,opacity:e.opacity??e.outline.opacity}),cr()}}function ai(e){if(e.radiusX===void 0||e.radiusY===void 0)throw Error(`drawEllipse() requires properties "radiusX" and "radiusY".`);if(e.radiusX===0||e.radiusY===0)return;let t=e.start??0,n=e.end??360,r=zn(e.anchor??`center`).scale(new d(-e.radiusX,-e.radiusY)),i=tr(r,e.radiusX,e.radiusY,t,n,e.resolution);i.unshift(r);let a=Object.assign({},e,{pts:i,radius:0,...e.gradient?{colors:[e.gradient[0],...Array(i.length-1).fill(e.gradient[1])]}:{}});if(n-t>=360&&e.outline){e.fill!==!1&&ii(Object.assign({},a,{outline:null})),ii(Object.assign({},a,{pts:i.slice(1),fill:!1}));return}ii(a)}function oi(e){if(typeof e.radius!=`number`)throw Error(`drawCircle() requires property "radius".`);e.radius!==0&&ai(Object.assign({},e,{radiusX:e.radius,radiusY:e.radius,angle:0}))}function si(e){let{p1:t,p2:n}=e;if(!t||!n)throw Error(`drawLine() requires properties "p1" and "p2".`);let i=e.width||1,a=n.sub(t).unit().normal().scale(i*.5);ri([t.sub(a),t.add(a),n.add(a),n.sub(a)].map(t=>({pos:new d(t.x,t.y),uv:new d(0),color:e.color??r.WHITE,opacity:e.opacity??1})),[0,1,3,1,2,3],e.fixed,J.gfx.defTex,e.shader,e.uniform??void 0)}function ci(e){let t=e.pts,n=[],i=(e.width||1)*.5,a=t[0]===t[t.length-1]||t[0].eq(t[t.length-1]),o=e.pos||f(0,0),s;s=a?t[0].sub(t[t.length-2]):t[1].sub(t[0]);let c=s.len(),l=s.normal().scale(-i/c),u,d=t[0];if(!a)switch(e.cap){case`square`:{let e=s.scale(-i/c);n.push(d.add(e).add(l)),n.push(d.add(e).sub(l));break}case`round`:{let e=Math.max(i,10),t=Math.PI/e,r=l.scale(-1),a=Math.cos(t),o=Math.sin(t);for(let t=0;t<e;t++)n.push(d),n.push(d.sub(r)),r=f(r.x*a-r.y*o,r.x*o+r.y*a)}}for(let e=1;e<t.length;e++){if(d===t[e]||d.eq(t[e]))continue;u=d,d=t[e];let r=d.sub(u),a=r.len(),o=r.normal().scale(-i/a),f=s.cross(r);if(Math.abs(f)/(c*a)<.05){n.push(u.add(l)),n.push(u.sub(l)),s.dot(r)<0&&(n.push(u.sub(l)),n.push(u.add(l))),s=r,c=a,l=o;continue}let p=o.sub(l).cross(r)/f,m=l.add(s.scale(p));f>0?(n.push(u.add(m)),n.push(u.sub(l)),n.push(u.add(m)),n.push(u.sub(o
53))):(n.push(u.add(l)),n.push(u.sub(m)),n.push(u.add(o)),n.push(u.sub(m))),s=r,c=a,l=o}if(!a)switch(n.push(d.add(l)),n.push(d.sub(l)),e.cap){case`square`:{let e=s.scale(i/c);n.push(d.add(e).add(l)),n.push(d.add(e).sub(l));break}case`round`:{let e=Math.max(i,10),t=Math.PI/e,r=l.scale(1),a=Math.cos(t),o=Math.sin(t);for(let t=0;t<e;t++)r=f(r.x*a-r.y*o,r.x*o+r.y*a),n.push(d),n.push(d.sub(r))}}if(n.length<4)return;let p=n.map(t=>({pos:o.add(t),uv:f(),color:e.color||r.WHITE,opacity:e.opacity??1})),m=[],h=0;for(let e=0;e<n.length-2;e+=2)m[h++]=e+1,m[h++]=e,m[h++]=e+2,m[h++]=e+2,m[h++]=e+3,m[h++]=e+1;a&&(m[h++]=n.length-1,m[h++]=n.length-2,m[h++]=0,m[h++]=0,m[h++]=1,m[h++]=n.length-1),ri(p,m,e.fixed,J.gfx.defTex,e.shader,e.uniform??void 0)}function li(e){let t=e.pts,n=[],i=(e.width||1)*.5,a=t[0]===t[t.length-1]||t[0].eq(t[t.length-1]),s=e.pos||f(0,0),c;c=a?t[0].sub(t[t.length-2]):t[1].sub(t[0]);let l=c.len(),u=c.normal().scale(-i/l),d,p=t[0];if(!a)switch(e.cap){case`square`:{let e=c.scale(-i/l);n.push(p.add(e).add(u)),n.push(p.add(e).sub(u));break}case`round`:{let e=Math.max(i,10),t=Math.PI/e,r=u.scale(-1),a=Math.cos(t),o=Math.sin(t);for(let t=0;t<e;t++)n.push(p),n.push(p.sub(r)),r=f(r.x*a-r.y*o,r.x*o+r.y*a)}}for(let e=1;e<t.length;e++){if(p===t[e]||p.eq(t[e]))continue;d=p,p=t[e];let r=p.sub(d),a=r.len(),s=r.normal().scale(-i/a),m=c.cross(r);if(Math.abs(m)/(l*a)<.05){n.push(d.add(u)),n.push(d.sub(u)),c.dot(r)<0&&(n.push(d.sub(u)),n.push(d.add(u))),c=r,l=a,u=s;continue}let h=s.sub(u).cross(r)/m,g=u.add(c.scale(h));if(m>0){let e=d.add(g),t=Math.max(i,10),r=o(u.angleBetween(s)/t),a=u,c=Math.cos(r),l=Math.sin(r);for(let r=0;r<t;r++)n.push(e),n.push(d.sub(a)),a=f(a.x*c-a.y*l,a.x*l+a.y*c)}else{let e=d.sub(g),t=Math.max(i,10),r=o(u.angleBetween(s)/t),a=u,c=Math.cos(r),l=Math.sin(r);for(let r=0;r<t;r++)n.push(d.add(a)),n.push(e),a=f(a.x*c-a.y*l,a.x*l+a.y*c)}c=r,l=a,u=s}if(!a)switch(n.push(p.add(u)),n.push(p.sub(u)),e.cap){case`square`:{let e=c.scale(i/l);n.push(p.add(e).add(u)),n.push(p.add(e).sub(u));break}case`round`:{let e=Math.max(i,10),t=Math.PI/e,r=u.scale(1),a=Math.cos(t),o=Math.sin(t);for(let t=0;t<e;t++)r=f(r.x*a-r.y*o,r.x*o+r.y*a),n.push(p),n.push(p.sub(r))}}if(n.length<4)return;let m=n.map(t=>({pos:s.add(t),uv:f(),color:e.color||r.WHITE,opacity:e.opacity??1})),h=[],g=0;for(let e=0;e<n.length-2;e+=2)h[g++]=e+1,h[g++]=e,h[g++]=e+2,h[g++]=e+2,h[g++]=e+3,h[g++]=e+1;a&&(h[g++]=n.length-1,h[g++]=n.length-2,h[g++]=0,h[g++]=0,h[g++]=1,h[g++]=n.length-1),ri(m,h,e.fixed,J.gfx.defTex,e.shader,e.uniform??void 0)}function ui(e){let t=e.pts,n=[],i=(e.width||1)*.5,a=t[0]===t[t.length-1]||t[0].eq(t[t.length-1]),o=e.pos||f(0,0),s;s=a?t[0].sub(t[t.length-2]):t[1].sub(t[0]);let c=s.len(),l=s.normal().scale(-i/c),u,d=t[0];if(!a)switch(e.cap){case`square`:{let e=s.scale(-i/c);n.push(d.add(e).add(l)),n.push(d.add(e).sub(l));break}case`round`:{let e=Math.max(i,10),t=Math.PI/e,r=l.scale(-1),a=Math.cos(t),o=Math.sin(t);for(let t=0;t<e;t++)n.push(d),n.push(d.sub(r)),r=f(r.x*a-r.y*o,r.x*o+r.y*a)}}for(let e=1;e<t.length;e++){if(d===t[e]||d.eq(t[e]))continue;u=d,d=t[e];let r=d.sub(u),a=r.len(),o=r.normal().scale(-i/a),f=s.cross(r);if(Math.abs(f)/(c*a)<.05){n.push(u.add(l)),n.push(u.sub(l)),s.dot(r)<0&&(n.push(u.sub(l)),n.push(u.add(l))),s=r,c=a,l=o;continue}let p=o.sub(l).cross(r)/f,m=l.add(s.scale(p));n.push(u.add(m)),n.push(u.sub(m)),s=r,c=a,l=o}if(!a)switch(n.push(d.add(l)),n.push(d.sub(l)),e.cap){case`square`:{let e=s.scale(i/c);n.push(d.add(e).add(l)),n.push(d.add(e).sub(l));break}case`round`:{let e=Math.max(i,10),t=Math.PI/e,r=l.scale(1),a=Math.cos(t),o=Math.sin(t);for(let t=0;t<e;t++)r=f(r.x*a-r.y*o,r.x*o+r.y*a),n.push(d),n.push(d.sub(r))}}if(n.length<4)return;let p=n.map(t=>({pos:o.add(t),uv:f(),color:e.color||r.WHITE,opacity:e.opacity??1})),m=[],h=0;for(let e=0;e<n.length-2;e+=2)m[h++]=e+1,m[h++]=e,m[h++]=e+2,m[h++]=e+2,m[h++]=e+3,m[h++]=e+1;a&&(m[h++]=n.length-1,m[h++]=n.length-2,m[h++]=0,m[h++]=0,m[h++]=1,m[h++]=n.length-1),ri(p,m,e.fixed,J.gfx.defTex,e.shader,e.uniform??void 0)}function di(e){let t=e.pts,n=e.width??1;if(!t)throw Error(`drawLines() requires property "pts".`);if(!(t.length<2)){if(t.length>2)switch(e.join){case`bevel`:return ci(e);case`round`:return li(e);case`miter`:return ui(e)}
53if(e.radius&&t.length>=3){si(Object.assign({},e,{p1:t[0],p2:t[1]}));for(let n=1;n<t.length-2;n++){let r=t[n],i=t[n+1];si(Object.assign({},e,{p1:r,p2:i}))}si(Object.assign({},e,{p1:t[t.length-2],p2:t[t.length-1]}))}else for(let r=0;r<t.length-1;r++)si(Object.assign({},e,{p1:t[r],p2:t[r+1]})),e.join!==`none`&&oi(Object.assign({},e,{pos:t[r],radius:n/2}))}}function fi(e,t){let n=t.segments??16,r=[];for(let t=0;t<=n;t++)r.push(e(t/n));di({pts:r,width:t.width||1,pos:t.pos,color:t.color,opacity:t.opacity})}function pi(e){fi(t=>Pe(e.pt1,e.pt2,e.pt3,e.pt4,t),e)}var mi=class e{ctx;src=null;glTex;width;height;constructor(e,t,n,r={}){this.ctx=e;let i=e.gl,a=e.gl.createTexture();if(!a)throw Error(`Failed to create texture`);this.glTex=a,e.onDestroy(()=>this.free()),this.width=t,this.height=n;let o={linear:i.LINEAR,nearest:i.NEAREST}[r.filter??e.opts.texFilter??`nearest`],s={repeat:i.REPEAT,clampToEdge:i.CLAMP_TO_EDGE}[r.wrap??`clampToEdge`];this.bind(),t&&n&&i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t,n,0,i.RGBA,i.UNSIGNED_BYTE,null),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,o),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,o),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,s),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),this.unbind()}static fromImage(t,n,r={}){let i=new e(t,n.width,n.height,r);return i.update(n),i.src=n,i}update(e,t=0,n=0){let r=this.ctx.gl;this.bind(),r.texSubImage2D(r.TEXTURE_2D,0,t,n,r.RGBA,r.UNSIGNED_BYTE,e),this.unbind()}bind(){this.ctx.pushTexture2D(this.glTex)}unbind(){this.ctx.popTexture2D()}free(){this.ctx.gl.deleteTexture(this.glTex)}},hi=class{ctx;tex;glFramebuffer;glRenderbuffer;constructor(e,t,n,r={}){this.ctx=e;let i=e.gl;e.onDestroy(()=>this.free()),this.tex=new mi(e,t,n,r);let a=i.createFramebuffer(),o=i.createRenderbuffer();if(!a||!o)throw Error(`Failed to create framebuffer`);this.glFramebuffer=a,this.glRenderbuffer=o,this.bind(),i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_STENCIL,t,n),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,this.tex.glTex,0),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.DEPTH_STENCIL_ATTACHMENT,i.RENDERBUFFER,this.glRenderbuffer),this.unbind()}get width(){return this.tex.width}get height(){return this.tex.height}toImageData(){let e=this.ctx.gl,t=new Uint8ClampedArray(this.width*this.height*4);this.bind(),e.readPixels(0,0,this.width,this.height,e.RGBA,e.UNSIGNED_BYTE,t),this.unbind();let n=this.width*4,r=new Uint8Array(n);for(let e=0;e<(this.height/2|0);e++){let i=e*n,a=(this.height-e-1)*n;r.set(t.subarray(i,i+n)),t.copyWithin(i,a,a+n),t.set(r,a)}return new ImageData(t,this.width,this.height)}toDataURL(){let e=document.createElement(`canvas`),t=e.getContext(`2d`);if(e.width=this.width,e.height=this.height,!t)throw Error(`Failed to get 2d context`);return t.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()}},gi=class{ctx;glVBuf;glIBuf;vqueue=[];iqueue=[];stride;maxVertices;maxIndices;vertexFormat;numDraws=0;curPrimitive=null;curTex=null;curShader=null;curUniform={};constructor(e,t,n,r){let i=e.gl;this.vertexFormat=t,this.ctx=e,this.stride=t.reduce((e,t)=>e+t.size,0),this.maxVertices=n,this.maxIndices=r;let a=i.createBuffer();if(!a)throw Error(`Failed to create vertex buffer`);this.glVBuf=a,e.pushArrayBuffer(this.glVBuf),i.bufferData(i.ARRAY_BUFFER,n*4,i.DYNAMIC_DRAW),e.popArrayBuffer(),this.glIBuf=i.createBuffer(),e.pushElementArrayBuffer(this.glIBuf),i.bufferData(i.ELEMENT_ARRAY_BUFFER,r*4,i.DYNAMIC_DRAW),e.popElementArrayBuffer()}push(e,t,n,r,i=null,a={}){(e!==this.curPrimitive||i!==this.curTex||r!==this.curShader||!Wt(this.curUniform,a)||this.vqueue.length+t.length*this.stride>this.maxVertices||this.iqueue.length+n.length>this.maxIndices)&&this.flush();let o=this.vqueue.length/this.stride;for(let e of t)this.vqueue.push(e);for(let e of n)this.iqueue.push(e+o);this.curPrimitive=e,this.curShader=r,this.curTex=i,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 _i(e){let t=[],n=n=>{t.push(n),e(n)},r=()=>{t.pop(),e(i()??null)},i=()=>t[t.length-1];return[n,r,i]}function vi(e,t={}){let n=[];function r(e){n.push(e)}
53function i(){n.forEach(e=>e());let t=e.getExtension(`WEBGL_lose_context`);t&&t.loseContext()}let a=null;function o(t){if(Wt(t,a))return;a=t;let n=t.reduce((e,t)=>e+t.size,0);t.reduce((t,r,i)=>(e.vertexAttribPointer(i,r.size,e.FLOAT,!1,n*4,t),e.enableVertexAttribArray(i),t+r.size*4),0)}let[s,c]=_i(t=>e.bindTexture(e.TEXTURE_2D,t)),[l,u]=_i(t=>e.bindBuffer(e.ARRAY_BUFFER,t)),[d,f]=_i(t=>e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t)),[p,m]=_i(t=>e.bindFramebuffer(e.FRAMEBUFFER,t)),[h,g]=_i(t=>e.bindRenderbuffer(e.RENDERBUFFER,t)),[_,v]=_i(t=>{if(!t)return;let{x:n,y:r,w:i,h:a}=t;e.viewport(n,r,i,a)}),[y,b]=_i(t=>e.useProgram(t));return _({x:0,y:0,w:e.drawingBufferWidth,h:e.drawingBufferHeight}),{gl:e,opts:t,onDestroy:r,destroy:i,pushTexture2D:s,popTexture2D:c,pushArrayBuffer:l,popArrayBuffer:u,pushElementArrayBuffer:d,popElementArrayBuffer:f,pushFramebuffer:p,popFramebuffer:m,pushRenderbuffer:h,popRenderbuffer:g,pushViewport:_,popViewport:v,pushProgram:y,popProgram:b,setVertexFormat:o}}var yi={};function bi(e,t){if(t.override){Object.assign(e,t);return}t.pos&&(e.pos=e.pos.add(t.pos)),t.scale&&(e.scale=e.scale.scale(f(t.scale))),t.angle&&(e.angle+=t.angle),t.color&&e.ch.length===1&&(e.color=e.color.mult(t.color)),t.opacity!=null&&(e.opacity*=t.opacity)}function xi(e){let t={},n=``,r=[],i=String(e),a=e=>{r.length>0&&(t[n.length]=r.slice()),n+=e};for(;i!==``;){if(i[0]===`\\`){if(i.length===1)throw Error(`Styled text error: \\ at end of string`);a(i[1]),i=i.slice(2);continue}if(i[0]===`[`){let e=/^\[(\/)?(\w+?)\]/.exec(i);if(!e){a(i[0]),i=i.slice(1);continue}let[t,n,o]=e;if(n!==void 0){let e=r.pop();if(e!==o)throw Error(e===void 0?`Styled text error: stray end tag [/${o}]`:`Styled text error: mismatched tags. Expected [/${e}], got [/${o}]`)}else r.push(o);i=i.slice(t.length);continue}a(i[0]),i=i.slice(1)}if(r.length>0)throw Error(`Styled text error: unclosed tags ${r}`);return{charStyleMap:t,text:n}}function Si(e){if(e.text===void 0)throw Error(`formatText() requires property "text".`);let t=Rr(e.font);if(!e.text||e.text===``||t instanceof mr||!t)return{width:0,height:0,chars:[],opt:e,renderedText:``};let{charStyleMap:n,text:i}=xi(e.text+``),a=Zt(i);if(t instanceof Lr||typeof t==`string`){let e=t instanceof Lr?t.fontface.family:t,n=t instanceof Lr?{outline:t.outline,filter:t.filter}:{outline:null,filter:pt},r=yi[e]??{font:{tex:new mi(J.gfx.ggl,2048,2048,{filter:n.filter}),map:{},size:64},cursor:new d(0),maxHeight:0,outline:n.outline};yi[e]||(yi[e]=r),t=r.font;for(let n of a)if(!r.font.map[n]){let i=J.fontCacheC2d;if(!i)throw Error(`fontCacheC2d is not defined.`);if(!J.fontCacheCanvas)throw Error(`fontCacheCanvas is not defined.`);i.clearRect(0,0,J.fontCacheCanvas.width,J.fontCacheCanvas.height),i.font=`${t.size}px ${e}`,i.textBaseline=`top`,i.textAlign=`left`,i.fillStyle=`#ffffff`;let a=i.measureText(n),o=Math.ceil(a.width);if(!o)continue;let s=Math.ceil(Math.abs(a.actualBoundingBoxAscent))+Math.ceil(Math.abs(a.actualBoundingBoxDescent));r.outline&&r.outline.width&&r.outline.color&&(i.lineJoin=`round`,i.lineWidth=r.outline.width*2,i.strokeStyle=r.outline.color.toHex(),i.strokeText(n,r.outline.width,r.outline.width),o+=r.outline.width*2,s+=r.outline.width*3),i.fillText(n,r.outline?.width??0,r.outline?.width??0);let c=i.getImageData(0,0,o,s);if(r.cursor.x+o>2048&&(r.cursor.x=0,r.cursor.y+=r.maxHeight,r.maxHeight=0,r.cursor.y>2048))throw Error(`Font atlas exceeds character limit`);t.tex.update(c,r.cursor.x,r.cursor.y),t.map[n]=new p(r.cursor.x,r.cursor.y,o,s),r.cursor.x+=o+1,r.maxHeight=Math.max(r.maxHeight,s)}}let o=e.size||t.size,s=f(e.scale??1).scale(o/t.size),c=e.lineSpacing??0,l=e.letterSpacing??0,u=0,m=0,h=0,g=[],_=[],v=0,y=null,b=0,x;for(;v<a.length;){let n=a[v];if(n===`
54`)h+=o+c,g.push({width:u-l,chars:_}),y=null,b=0,u=0,_=[],x=void 0;else{let i=t.map[n];if(i){let S=i.w*s.x;e.width&&u+S>e.width&&(h+=o+c,y!=null&&(v-=_.length-y,n=a[v],i=t.map[n],S=i.w*s.x,_=_.slice(0,y-1),u=b),y=null,b=0,g.push({width:u-l,chars:_}),u=x??0,_=[]),_.push({tex:t.tex,width:i.w,height:i.h,quad:new p(i.x/t.tex.width,i.y/t.tex.height,i.w/t.tex.width,i.h/t.tex.height),ch:n,pos:new d(u,h),opacity:e.opacity??1,color:e.color??r.WHITE,scale:f(s),angle:0}),n===` `&&(y=_.length,b=u),e.indentAll&&x===void 0&&/\S/.test(n)&&(x=u),u+=S,m=Math.max(m,u),u+=l}}v++}g.push({width:u-l,chars:_}),h+=o,e.width&&(m=e.width);let S=[];for(let r=0;r<g.length;r++){let i=(m-g[r].width)*Bn(e.align??`left`);for(let a of g[r].chars){let o=t.map[a.ch],c=S.length+r;if(a.pos=a.pos.add(i,0).add(o.w*s.x*.5,o.h*s.y*.5),e.transform){let t=typeof e.transform==`function`?e.transform(c,a.ch):e.transform;t&&bi(a,t)}if(n[c]){let t=n[c];for(let n of t){let t=e.styles?.[n],r=typeof t==`function`?t(c,a.ch):t;r&&bi(a,r)}}S.push(a)}}return{width:m,height:h,chars:S,opt:e,renderedText:i}}function Ci(e){if(e.width===void 0||e.height===void 0)throw Error(`drawUVQuad() requires property "width" and "height".`);if(e.width<=0||e.height<=0)return;
54let t=e.width,n=e.height,r=zn(e.anchor||ut).scale(new d(t,n).scale(-.5)),a=e.quad||new p(0,0,1,1),o=e.color||i(255,255,255),s=e.opacity??1,c=e.tex?.1/e.tex.width:0,l=e.tex?.1/e.tex.height:0,u=a.x+c,f=a.y+l,m=a.w-c*2,h=a.h-l*2;ir(),G(e.pos),sr(e.angle),or(e.scale),G(r),ri([{pos:new d(-t/2,n/2),uv:new d(e.flipX?u+m:u,e.flipY?f:f+h),color:o,opacity:s},{pos:new d(-t/2,-n/2),uv:new d(e.flipX?u+m:u,e.flipY?f+h:f),color:o,opacity:s},{pos:new d(t/2,-n/2),uv:new d(e.flipX?u:u+m,e.flipY?f+h:f),color:o,opacity:s},{pos:new d(t/2,n/2),uv:new d(e.flipX?u:u+m,e.flipY?f:f+h),color:o,opacity:s}],[0,1,3,1,2,3],e.fixed,e.tex,e.shader,e.uniform??void 0),cr()}function wi(e){ir(),G(e.opt.pos),sr(e.opt.angle),G(zn(e.opt.anchor??`topleft`).add(1,1).scale(e.width,e.height).scale(-.5)),e.chars.forEach(t=>{Ci({tex:t.tex,width:t.width,height:t.height,pos:t.pos,scale:t.scale,angle:t.angle,color:t.color,opacity:t.opacity,quad:t.quad,anchor:`center`,uniform:e.opt.uniform,shader:e.opt.shader,fixed:e.opt.fixed})}),cr()}function Ti(e){if(e.width===void 0||e.height===void 0)throw Error(`drawRect() requires property "width" and "height".`);if(e.width<=0||e.height<=0)return;let t=e.width,n=e.height,r=zn(e.anchor||ut).add(1,1).scale(new d(t,n).scale(-.5)),i=[new d(0,0),new d(t,0),new d(t,n),new d(0,n)];if(e.radius){let r=Math.min(t,n)/2,a=Array.isArray(e.radius)?e.radius.map(e=>Math.min(r,e)):[,,,,].fill(Math.min(r,e.radius));i=[new d(a[0],0),...a[1]?tr(new d(t-a[1],a[1]),a[1],a[1],270,360):[f(t,0)],...a[2]?tr(new d(t-a[2],n-a[2]),a[2],a[2],0,90):[f(t,n)],...a[3]?tr(new d(a[3],n-a[3]),a[3],a[3],90,180):[f(0,n)],...a[0]?tr(new d(a[0],a[0]),a[0],a[0],180,270):[]]}ii(Object.assign({},e,{offset:r,pts:i,...e.gradient?{colors:e.horizontal?[e.gradient[0],e.gradient[1],e.gradient[1],e.gradient[0]]:[e.gradient[0],e.gradient[0],e.gradient[1],e.gradient[1]]}:{}}))}function Ei(e){lr();let t=J.gfx.width,n=J.gfx.height;J.gfx.width=J.gfx.viewport.width,J.gfx.height=J.gfx.viewport.height,e(),lr(),J.gfx.width=t,J.gfx.height=n}function Di(e,t){Ei(()=>{let n=f(8);ir(),G(e);let r=Si({text:t,font:ft,size:16,pos:n,color:i(255,255,255),fixed:!0}),a=r.width+n.x*2,o=r.height+n.x*2;e.x+a>=K()&&G(f(-a,0)),e.y+o>=q()&&G(f(0,-o)),Ti({width:a,height:o,color:i(0,0,0),radius:4,opacity:.8,fixed:!0}),wi(r),cr()})}function Oi(e){if(!e.p1||!e.p2||!e.p3)throw Error(`drawTriangle() requires properties "p1", "p2" and "p3".`);return ii(Object.assign({},e,{pts:[e.p1,e.p2,e.p3]}))}function ki(){if(J.debug.inspect){let e=null;for(let t of J.game.root.get(`*`,{recursive:!0}))if(t.has(`area`)&&t.isHovering()){e=t;break}if(J.game.root.drawInspect(),e){let t=[],n=e.inspect();for(let e in n)n[e]?t.push(`${n[e]}`):t.push(`${e}`);Di(_n(J.k.mousePos()),t.join(`
55`))}Di(f(8),`FPS: ${J.debug.fps()}`)}J.debug.paused&&Ei(()=>{ir(),G(K(),0),G(-8,8),Ti({width:32,height:32,anchor:`topright`,color:i(0,0,0),opacity:.8,radius:4,fixed:!0});for(let e=1;e<=2;e++)Ti({width:4,height:19.2,anchor:`center`,pos:f(-32/3*e,16),color:i(255,255,255),radius:2,fixed:!0});cr()}),J.debug.timeScale!==1&&Ei(()=>{ir(),G(K(),q()),G(-8,-8);let e=Si({text:J.debug.timeScale.toFixed(1),font:ft,size:16,color:i(255,255,255),pos:f(-8),anchor:`botright`,fixed:!0});Ti({width:e.width+16+32,height:e.height+16,anchor:`botright`,color:i(0,0,0),opacity:.8,radius:4,fixed:!0});for(let t=0;t<2;t++){let n=J.debug.timeScale<1;Oi({p1:f(-e.width-8*(n?2:3.5),-8),p2:f(-e.width-8*(n?2:3.5),-8-e.height),p3:f(-e.width-8*(n?3.5:2),-8-e.height/2),pos:f(-t*8*1+(n?-4:0),0),color:i(255,255,255),fixed:!0})}wi(e),cr()}),J.debug.curRecording&&Ei(()=>{ir(),G(0,q()),G(24,-24),oi({radius:12,color:i(255,0,0),opacity:v(0,1,J.app.time()*4),fixed:!0}),cr()}),J.debug.showLog&&J.game.logs.length>0&&Ei(()=>{ir(),G(0,q()),G(8,-8);let e=[];for(let t of J.game.logs){let n=``,r=t.msg instanceof Error?`error`:`info`;n+=`[time]${t.time.toFixed(2)}[/time]`,n+=` `,n+=`[${r}]${Ai(t.msg)}[/${r}]`,e.push(n)}J.game.logs=J.game.logs.filter(e=>J.app.time()-e.time<(J.globalOpt.logTime||4));let t=Si({text:e.join(`
56`),font:ft,pos:f(8,-8),anchor:`botleft`,size:16,width:K()*.6,lineSpacing:4,fixed:!0,styles:{time:{color:i(127,127,127)},info:{color:i(255,255,255)},error:{color:i(255,0,127)}}});Ti({width:t.width+16,height:t.height+16,anchor:`botleft`,color:i(0,
560,0),radius:4,opacity:.8,fixed:!0}),wi(t),cr()})}function Ai(e,t=!1,n=new Set){if(n.has(e))return`<recursive>`;var r=``,i;return t&&typeof e==`string`&&(e=JSON.stringify(e)),Array.isArray(e)&&(r=[`[`,e.map(t=>Ai(t,!0,n.union(new Set([e])))).join(`, `),`]`].join(``),e=r),e===null?`null`:(typeof e==`object`&&e.toString===Object.prototype.toString&&(e.constructor!==Object&&(r+=e.constructor.name+` `),r+=[`{`,(i=Object.getOwnPropertyNames(e).map(t=>`${/^\w+$/.test(t)?t:JSON.stringify(t)}: ${Ai(e[t],!0,n.union(new Set([e])))}`).join(`, `))?` ${i} `:``,`}`].join(``),e=r),String(e).replaceAll(/(?<!\\)\[/g,`\\[`))}function ji(){let e=J.game.cam,t=d.fromAngle(T(0,360)).scale(e.shake);e.shake=c(e.shake,0,5*W()),e.transform=new _().translate(dr()).scale(e.scale).rotate(e.angle).translate((e.pos??dr()).scale(-1).add(t)),J.game.root.draw(),lr()}function Mi(){let e=Cr();J.game.events.numListeners(`loading`)>0?J.game.events.trigger(`loading`,e):Ei(()=>{let t=K()/2,n=f(K()/2,q()/2).sub(f(t/2,12));Ti({pos:f(0),width:K(),height:q(),color:i(0,0,0)}),Ti({pos:n,width:t,height:24,fill:!1,outline:{width:4}}),Ti({pos:n,width:t*e,height:24})})}function Ni(e,t,n){let r=J.gfx.ggl.gl;lr(),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),t(),lr(),r.stencilFunc(n,1,255),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),e(),lr(),r.disable(r.STENCIL_TEST)}function Pi(e,t){let n=J.gfx.ggl.gl;Ni(e,t,n.EQUAL)}function Fi(e){if(!e.tex)throw Error(`drawTexture() requires property "tex".`);let t=e.quad??new p(0,0,1,1),n=e.tex.width*t.w,i=e.tex.height*t.h,a=new d(1);if(e.tiled){let a=zn(e.anchor||ut);(e.pos?.x||0)-(a.x+1)*.5*(e.width||n),(e.pos?.y||0)-(a.y+1)*.5*(e.height||i);let o=(e.width||n)/n,s=(e.height||i)/i,c=Math.floor(o),l=Math.floor(s),u=o-c,f=s-l,m=(c+u?1:0)*(l+f?1:0),h=Array(m*6),g=Array(m*4),_=0,v=(t,n,i,o,s)=>{h[_*6+0]=_*4+0,h[_*6+1]=_*4+1,h[_*6+2]=_*4+3,h[_*6+3]=_*4+1,h[_*6+4]=_*4+2,h[_*6+5]=_*4+3,g[_*4+0]={pos:new d(t-a.x,n-a.y),uv:new d(s.x,s.y),color:e.color||r.WHITE,opacity:e.opacity||1},g[_*4+1]={pos:new d(t+i-a.x,n-a.y),uv:new d(s.x+s.w,s.y),color:e.color||r.WHITE,opacity:e.opacity||1},g[_*4+2]={pos:new d(t+i-a.x,n+o-a.y),uv:new d(s.x+s.w,s.y+s.h),color:e.color||r.WHITE,opacity:e.opacity||1},g[_*4+3]={pos:new d(t-a.x,n+o-a.y),uv:new d(s.x,s.y+s.h),color:e.color||r.WHITE,opacity:e.opacity||1},_++};for(let e=0;e<l;e++){for(let r=0;r<c;r++)v(r*n,e*i,n,i,t);u&&v(c*n,e*i,n*u,i,new p(t.x,t.y,t.w*u,t.h))}if(f){for(let e=0;e<c;e++)v(e*n,l*i,n,i*f,new p(t.x,t.y,t.w,t.h*f));u&&v(c*n,l*i,n*u,i*f,new p(t.x,t.y,t.w*u,t.h*f))}ri(g,h,e.fixed,e.tex,e.shader,e.uniform??void 0)}else e.width&&e.height?(a.x=e.width/n,a.y=e.height/i):e.width?(a.x=e.width/n,a.y=a.x):e.height&&(a.y=e.height/i,a.x=a.y),Ci(Object.assign({},e,{scale:a.scale(e.scale||new d(1)),tex:e.tex,quad:t,width:n,height:i}))}function Ii(e){if(!e.sprite)throw Error(`drawSprite() requires property "sprite"`);let t=Ar(e.sprite);if(!t||!t.data)return;let n=t.data.frames[e.frame??0];if(!n)throw Error(`Frame not found: ${e.frame??0}`);Fi(Object.assign({},e,{tex:t.data.tex,quad:n.scale(e.quad??new p(0,0,1,1))}))}function Li(e,t){let n=J.gfx.ggl.gl;Ni(e,t,n.NOTEQUAL)}function Ri(e){wi(Si(e))}var zi=(e,t)=>{let n=Kr(t,xt,St),r=e.pixelDensity??1,a=e.scale??1,{gl:o}=t,s=mi.fromImage(t,new ImageData(new Uint8ClampedArray([255,255,255,255]),1,1)),c=e.width&&e.height?new hi(t,e.width*r*a,e.height*r*a):new hi(t,o.drawingBufferWidth,o.drawingBufferHeight),l=null,u=1;e.background&&(typeof e.background==`string`?l=i(e.background):(l=i(...e.background),u=e.background[3]??1),o.clearColor(l.r/255,l.g/255,l.b/255,u??1)),o.enable(o.BLEND),o.blendFuncSeparate(o.ONE,o.ONE_MINUS_SRC_ALPHA,o.ONE,o.ONE_MINUS_SRC_ALPHA);let d=new gi(t,mt,_t,vt),f=mi.fromImage(t,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:t,defShader:n,defTex:s,frameBuffer:c,postShader:null,postShaderUniform:null,renderer:d,transform:new _,transformStack:[],bgTex:f,bgColor:l,bgAlpha:u,width:e.width??o.drawingBufferWidth/r/a,height:e.height??o.drawingBufferHeight/r/a,viewport:{x:0,y:0,width:o.drawingBufferWidth,height:o.drawingBufferHeight,scale:1},fixed:!1}};function Bi(e){return e.fixed?!0:e.parent?Bi(e.parent):!1}function Vi(e){return{color:e.color,opacity:e.opacity,anchor:e.anchor,outline:e.outline,shader:e.shader,uniform:e.uniform}}function Hi(e,t={}){return{id:`circle`,radius:e,draw(){oi(Object.assign(Vi(this),{radius:this.radius,fill:t.fill}))},renderArea(){return new R(new d(this.anchor?0:-this.radius),this.radius*2,this.radius*2)}
56,inspect(){return`radius: ${Math.ceil(this.radius)}`}}}function Ui(...e){return{id:`color`,color:i(...e),inspect(){return`color: ${this.color.toString()}`}}}function Wi(e){return{add(){this.canvas=e}}}function Gi(e=1){let t,n=0,r=!1;return{require:[`opacity`],add(){t=this.opacity,this.opacity=0},update(){r||(n+=W(),this.opacity=l(n,0,e,0,t),n>=e&&(this.opacity=t,r=!0))}}}function Ki(e=`intersect`){return{id:`mask`,mask:e}}function qi(e){return{id:`opacity`,opacity:e??1,fadeIn(e=1,t=J.k.easings.linear){return J.game.root.tween(0,this.opacity,e,e=>this.opacity=e,t)},fadeOut(e=1,t=J.k.easings.linear){return J.game.root.tween(this.opacity,0,e,e=>this.opacity=e,t)},inspect(){return`opacity: ${Yt(this.opacity,1)}`}}}function Ji(e=1,t=i(0,0,0),n=1,r=`miter`,a=10,o=`butt`){return{id:`outline`,outline:{width:e,color:t,opacity:n,join:r,miterLimit:a,cap:o},inspect(){return`outline: ${this.outline.width}px, ${this.outline.color}`}}}var Yi=class{pos=f(0);vel=f(0);acc=f(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 Xi(e,t){let n=t.lifetime,a=[],o=e.colors||[r.WHITE],s=e.opacities||[1],u=e.quads||[new p(0,0,1,1)],m=e.scales||[1],h=e.lifeTime,g=t.direction,_=t.spread,v=e.speed||[0,0],y=e.angle||[0,0],b=e.angularVelocity||[0,0],x=e.acceleration||[f(0),f(0)],S=e.damping||[0,0],C=[],w=Array(e.max),E=0,D=0;for(let t=0;t<e.max;t++){C[t*6+0]=t*4+0,C[t*6+1]=t*4+1,C[t*6+2]=t*4+3,C[t*6+3]=t*4+1,C[t*6+4]=t*4+2,C[t*6+5]=t*4+3;for(let e=0;e<4;e++)w[t*4+e]={pos:new d(0,0),uv:new d(0,0),color:i(255,255,255),opacity:1};a[t]=new Yi}let O=new H;function ee(t=0){for(;t<e.max;){if(a[t].gc)return t;t++}return null}return{id:`particles`,emit(e){let n=0;for(let r=0;r<e;r++){if(n=ee(n),n==null)return;let e=T(g-_,g+_),r=d.fromAngle(e).scale(T(v[0],v[1])),i=T(y[0],y[1]),o=T(b[0],b[1]),s=f(T(x[0].x,x[1].x),T(x[0].y,x[1].y)),c=T(S[0],S[1]),l=h?T(h[0],h[1]):null,u=t.shape?t.shape.random():f(),p=a[n];p.lt=l,p.pos=u,p.vel=r,p.acc=s,p.angle=i,p.angularVelocity=o,p.damping=c,p.angularVelocity=o,p.gc=!1}E+=e},update(){if(n!==void 0&&n<=0)return;let r=W();for(let e of a)if(!e.gc){if(e.t+=r,e.lt&&e.t>=e.lt){e.gc=!0,E--;continue}e.vel=e.vel.add(e.acc.scale(r)).scale(1-e.damping*r),e.pos=e.pos.add(e.vel.scale(r)),e.angle+=e.angularVelocity*r}for(n!==void 0&&(n-=r,n<=0&&O.trigger()),D+=r;E<e.max&&t.rate&&D>t.rate;)this.emit(1),E++,D-=t.rate},draw(){if(!(n!==void 0&&n<=0)){for(let t=0;t<a.length;t++){let n=a[t];if(n.gc)continue;let r=n.progress,i=Math.floor(n.progress*o.length),d=i<o.length-1?c(o[i],o[i+1],l(r,i/o.length,(i+1)/o.length,0,1)):o[i],f=Math.floor(n.progress*s.length),p=f<s.length-1?c(s[f],s[f+1],l(r,f/s.length,(f+1)/s.length,0,1)):s[f],h=Math.floor(n.progress*u.length),g=u[h],_=Math.floor(n.progress*m.length),v=m[_],y=Math.cos(n.angle*Math.PI/180),b=Math.sin(n.angle*Math.PI/180),x=(e.texture?e.texture.width:10)*g.w/2,S=(e.texture?e.texture.height:10)*g.h/2,C=t*4,T=w[C];T.pos.x=n.pos.x+-x*v*y- -S*v*b,T.pos.y=n.pos.y+-x*v*b+-S*v*y,T.uv.x=g.x,T.uv.y=g.y,T.color.r=d.r,T.color.g=d.g,T.color.b=d.b,T.opacity=p,T=w[C+1],T.pos.x=n.pos.x+x*v*y- -S*v*b,T.pos.y=n.pos.y+x*v*b+-S*v*y,T.uv.x=g.x+g.w,T.uv.y=g.y,T.color.r=d.r,T.color.g=d.g,T.color.b=d.b,T.opacity=p,T=w[C+2],T.pos.x=n.pos.x+x*v*y-S*v*b,T.pos.y=n.pos.y+x*v*b+S*v*y,T.uv.x=g.x+g.w,T.uv.y=g.y+g.h,T.color.r=d.r,T.color.g=d.g,T.color.b=d.b,T.opacity=p,T=w[C+3],T.pos.x=n.pos.x+-x*v*y-S*v*b,T.pos.y=n.pos.y+-x*v*b+S*v*y,T.uv.x=g.x,T.uv.y=g.y+g.h,T.color.r=d.r,T.color.g=d.g,T.color.b=d.b,T.opacity=p}ri(w,C,this.fixed,e.texture,this.shader,this.uniform)}},onEnd(e){return O.add(e)},inspect(){return`count: ${E}/${e.max}`}}}function Zi(e,t={}){if(e.length<3)throw Error(`Polygon's need more than two points, ${e.length} points provided`);return{id:`polygon`,pts:e,colors:t.colors,uv:t.uv,tex:t.tex,radius:t.radius,draw(){ii(Object.assign(Vi(this),{pts:this.pts,colors:this.colors,uv:this.uv,tex:this.tex,radius:this.radius,fill:t.fill,triangulate:t.triangulate}))},renderArea(){return new B(this.pts)},inspect(){return`polygon: ${this.pts.map(e=>`[${e.x},${e.y}]`).join(`,`)}`}}
56}function Qi(e,t,n){let r;return J.game.root.get(`area`).forEach(i=>{if(n&&n.some(e=>i.is(e)))return;let a=i.worldArea().raycast(e,t);a&&(r?a.fraction<r.fraction&&(r=a,r.object=i):(r=a,r.object=i))}),r}function $i(e,t,n={}){return{id:`rect`,width:e,height:t,radius:n.radius||0,draw(){Ti(Object.assign(Vi(this),{width:this.width,height:this.height,radius:this.radius,fill:n.fill}))},renderArea(){return new R(f(0),this.width,this.height)},inspect(){return`rect: (${Math.ceil(this.width)}w, ${Math.ceil(this.height)}h)`}}}function ea(e,t){return{id:`shader`,shader:e,...typeof t==`function`?{uniform:t(),update(){this.uniform=t()}}:{uniform:t},inspect(){return`shader: ${e}`}}}function ta(e,t){if(!t.tileWidth||!t.tileHeight)throw Error(`Must provide tileWidth and tileHeight.`);let n=J.game.root.add([ts(t.pos??f(0))]),r=e.length,i=0,a=null,o=null,s=null,c=null,l=e=>e.x+e.y*i,u=e=>f(Math.floor(e%i),Math.floor(e/i)),d=()=>{a=[];for(let e of n.children)p(e)},p=e=>{let t=l(e.tilePos);a[t]?a[t].push(e):a[t]=[e]},m=e=>{let t=l(e.tilePos);if(a[t]){let n=a[t].indexOf(e);n>=0&&a[t].splice(n,1)}},h=()=>{let e=!1;for(let t of n.children){let r=n.pos2Tile(t.pos);(t.tilePos.x!=r.x||t.tilePos.y!=r.y)&&(e=!0,m(t),t.tilePos.x=r.x,t.tilePos.y=r.y,p(t))}e&&n.trigger(`spatialMapChanged`)},g=()=>{let e=n.getSpatialMap(),t=n.numRows()*n.numColumns();o?o.length=t:o=Array(t),o.fill(1,0,t);for(let t=0;t<e.length;t++){let n=e[t];if(n){let e=0;for(let t of n)if(t.isObstacle){e=1/0;break}else e+=t.cost;o[t]=e||1}}},_=()=>{let e=n.getSpatialMap(),t=n.numRows()*n.numColumns();s?s.length=t:s=Array(t),s.fill(15,0,t);for(let t=0;t<e.length;t++){let n=e[t];if(n){let e=n.length,r=15;for(let t=0;t<e;t++)r|=n[t].edgeMask;s[t]=r}}},v=()=>{let e=n.numRows()*n.numColumns(),t=(e,t)=>{let n=[];for(n.push(e);n.length>0;){let e=n.pop();x(e).forEach(e=>{c[e]<0&&(c[e]=t,n.push(e))})}};c?c.length=e:c=Array(e),c.fill(-1,0,e);let r=0;for(let e=0;e<o.length;e++){if(c[e]>=0){r++;continue}t(e,r),r++}},y=(e,t)=>o[t],b=(e,t)=>{let n=u(e),r=u(t);return n.dist(r)},x=(e,t)=>{let n=[],a=Math.floor(e%i),c=a>0&&s[e]&1&&o[e-1]!==1/0,l=e>=i&&s[e]&2&&o[e-i]!==1/0,u=a<i-1&&s[e]&4&&o[e+1]!==1/0,d=e<i*r-i-1&&s[e]&8&&o[e+i]!==1/0;return t?(c&&(l&&n.push(e-i-1),n.push(e-1),d&&n.push(e+i-1)),l&&n.push(e-i),u&&(l&&n.push(e-i+1),n.push(e+1),d&&n.push(e+i+1)),d&&n.push(e+i)):(c&&n.push(e-1),l&&n.push(e-i),u&&n.push(e+1),d&&n.push(e+i)),n},S={id:`level`,tileWidth(){return t.tileWidth},tileHeight(){return t.tileHeight},spawn(e,...r){let i=f(...r),o=(()=>{if(typeof e==`string`){if(t.tiles[e]){if(typeof t.tiles[e]!=`function`)throw Error(`Level symbol def must be a function returning a component list`);return t.tiles[e](i)}if(t.wildcardTile)return t.wildcardTile(e,i)}else{if(Array.isArray(e))return e;throw Error(`Expected a symbol or a component list`)}})();if(!o)return null;let s=!1,c=!1;for(let e of o)e.id===`tile`&&(c=!0),e.id===`pos`&&(s=!0);s||o.push(ts(this.tile2Pos(i))),c||o.push(So());let l=n.add(o);return s&&(l.tilePosOffset=l.pos.clone()),l.tilePos=i,l.transform=$n(l),a&&(p(l),this.trigger(`spatialMapChanged`),this.trigger(`navigationMapInvalid`)),l},numColumns(){return i},numRows(){return r},levelWidth(){return i*this.tileWidth()},levelHeight(){return r*this.tileHeight()},tile2Pos(...e){return f(...e).scale(this.tileWidth(),this.tileHeight())},pos2Tile(...e){let t=f(...e);return f(Math.floor(t.x/this.tileWidth()),Math.floor(t.y/this.tileHeight()))},getSpatialMap(){return a||d(),a},removeFromSpatialMap:m,insertIntoSpatialMap:p,onSpatialMapChanged(e){return this.on(`spatialMapChanged`,e)},onNavigationMapInvalid(e){return this.on(`navigationMapInvalid`,e)},getAt(e){a||d();let t=l(e);return a[t]||[]},raycast(e,t){let n=this.toWorld(e),r=this.toWorld(e.add(t)).sub(n),i=1/this.tileWidth(),a=De(e.scale(i),t,e=>{let t=this.getAt(e);if(t.some(e=>e.isObstacle))return!0;let a=null;for(let e of t)if(e.has(`area`)){let t=e.worldArea().raycast(n,r);t&&(a?t.fraction<a.fraction&&(a=t,a.object=e):(a=t,a.object=e))}return a&&(a.point=this.fromWorld(a.point).scale(i)),a||!1},64);return a&&(a.point=a.point.scale(this.tileWidth())),a},update(){a&&h()},invalidateNavigationMap(){o=null,s=null,c=null},onNavigationMapChanged(e){return this.on(`navigationMapChanged`,e)},getTilePath(e,t,n={}){if(o||g(),s||_(),c||v(),e.x<0||e.x>=i||e.y<0||e.y>=r||t.x<0||t.x>=i||t.y<0||t.y>=r)return null;let a=l(e),d=l(t);if(o[d]===1/0)return null;if(a===d)return[];if(c[a]!=-1&&c[a]!==c[d])return null;let f=new Ft((e,t)=>e.cost<t.cost);f.insert({cost:0,node:a});let p=new Map;p.set(a,a);let m=new Map;for(m.set(a,0);f.length!==0;){let e=f.remove()?.node;if(e===d)break;let t=x(e,n.allowDiagonals);for(let n of t){let t=(m.get(e)||0)+y(e,n)+b(n,d);(!m.has(n)||t<m.get(n))&&(m.set(n,t),f.insert({cost:t,node:n}),p.set(n,e))}}let h=[],S=d,C=u(S);for(h.push(C);S!==a;){let e=p.get(S);if(e===void 0)throw Error(`Bug in pathfinding algorithm`);S=e;let t=u(S);h.push(t)}return h.reverse()},getPath(e,t,n={}){let r=this.tileWidth(),i=this.tileHeight(),a=this.getTilePath(this.pos2Tile(e),this.pos2Tile(t),n);return a?[e,...a.slice(1,-1).map(e=>e.scale(r,i).add(r/2,i/2)),t]:null}};
56return n.use(S),n.onNavigationMapInvalid(()=>{n.invalidateNavigationMap(),n.trigger(`navigationMapChanged`)}),e.forEach((e,t)=>{let r=e.split(``);i=Math.max(r.length,i),r.forEach((e,r)=>{n.spawn(e,f(r,t))})}),n}function na(e,t,n){return J.game.objEvents.registers[e]||(J.game.objEvents.registers[e]=new kt),J.game.objEvents.on(e,(e,...r)=>{e.is(t)&&n(e,...r)})}var ra=(e,t,...n)=>{for(let r of J.game.root.children)r.is(t)&&r.trigger(e,n)},ia=U(e=>{let t=J.game.root.add([{fixedUpdate:e}]);return{get paused(){return t.paused},set paused(e){t.paused=e},cancel:()=>t.destroy()}},(e,t)=>na(`fixedUpdate`,e,t)),aa=U(e=>{let t=J.game.root.add([{update:e}]);return{get paused(){return t.paused},set paused(e){t.paused=e},cancel:()=>t.destroy()}},(e,t)=>na(`update`,e,t)),oa=U(e=>{let t=J.game.root.add([{draw:e}]);return{get paused(){return t.hidden},set paused(e){t.hidden=e},cancel:()=>t.destroy()}},(e,t)=>na(`draw`,e,t)),sa=U(e=>J.game.events.on(`add`,e),(e,t)=>na(`add`,e,t)),ca=U(e=>J.game.events.on(`destroy`,e),(e,t)=>na(`destroy`,e,t)),la=U(e=>J.game.events.on(`use`,e),(e,t)=>na(`use`,e,t)),ua=U(e=>J.game.events.on(`unuse`,e),(e,t)=>na(`unuse`,e,t)),da=U(e=>J.game.events.on(`tag`,e),(e,t)=>na(`tag`,e,t)),fa=U(e=>J.game.events.on(`untag`,e),(e,t)=>na(`untag`,e,t));function pa(e,t,n){return na(`collide`,e,(e,r,i)=>r.is(t)&&n(e,r,i))}function ma(e,t,n){return na(`collideUpdate`,e,(e,r,i)=>r.is(t)&&n(e,r,i))}function ha(e,t,n){return na(`collideEnd`,e,(e,r,i)=>r.is(t)&&n(e,r,i))}function ga(e,t){J.game.root.get(e,{recursive:!0}).forEach(t),sa(e,t),da((n,r)=>{r===e&&t(n)})}var _a=U(e=>J.app.onMousePress(e),(e,t)=>{let n=[];return ga(e,e=>{if(!e.area)throw Error(`onClick() requires the object to have area() component`);n.push(e.onClick(()=>t(e)))}),At.join(n)});function va(e,t){let n=[];return ga(e,e=>{if(!e.area)throw Error(`onHover() requires the object to have area() component`);n.push(e.onHover(()=>t(e)))}),At.join(n)}function ya(e,t){let n=[];return ga(e,e=>{if(!e.area)throw Error(`onHoverUpdate() requires the object to have area() component`);n.push(e.onHoverUpdate(()=>t(e)))}),At.join(n)}function ba(e,t){let n=[];return ga(e,e=>{if(!e.area)throw Error(`onHoverEnd() requires the object to have area() component`);n.push(e.onHoverEnd(()=>t(e)))}),At.join(n)}function xa(e){J.game.events.on(`loading`,e)}function Sa(e){J.app.onResize(e)}function Ca(e){J.game.events.on(`error`,e)}function wa(e){J.assets.loaded?e():J.game.events.on(`load`,e)}function Ta(e){if(J.assets.loaded)wr().forEach(t=>e(...t));else return J.game.events.on(`loadError`,e)}function Ea(...e){J.game.cam.pos=f(...e)}function Da(){return J.game.cam.pos?J.game.cam.pos.clone():dr()}function Oa(...e){J.game.cam.scale=f(...e)}function ka(){return J.game.cam.scale.clone()}function Aa(e){J.game.cam.angle=e}function ja(){return J.game.cam.angle}function Ma(){return J.game.cam.transform.clone()}function Na(e=i(255,255,255),t=1){let n=J.game.root.add([$i(K(),q()),Ui(e),qi(1),Xo()]),r=n.fadeOut(t);return r.onEnd(()=>co(n)),r}function Pa(){return J.game.cam.transform.clone()}function Fa(e=12){J.game.cam.shake+=e}function Ia(e){return J.game.cam.transform.multVec2(e)}function La(e){return J.game.cam.transform.invert().multVec2(e)}function Ra(...e){return Jt(`camPos`,`setCamPos / getCamPos`),e.length>0&&Ea(...e),Da()}function za(...e){return Jt(`camScale`,`setCamScale / getCamScale`),e.length>0&&Oa(...e),ka()}function Ba(e){return Jt(`camRot`,`setCamRot / getCamRot`),e!==void 0&&Aa(e),ja()}function Va(e=i(255,255,255),t=1){return Jt(`camFlash`,`flash`),Na(e,t)}function Ha(e=[]){let t=new Map,n=[],r={},i=new jt,a=[],o=new Set(`*`),s=J.globalOpt.tagsAsComponents,c=null,l=!1,u={id:mn(),hidden:!1,transform:new _,children:[],parent:null,set paused(e){if(e!==l){l=e;for(let t of a)t.paused=e}},get paused(){return l},get tags(){return Array.from(o)},add(e){let t=Array.isArray(e)?Ha(e):e;if(t.parent)throw Error(`Cannot add a game obj that already has a parent.`);return t.parent=this,t.transform=$n(t),this.children.push(t),t.trigger(`add`,t),J.game.events.trigger(`add`,t),t},readd(e){let t=this.children.indexOf(e);return t!==-1&&(this.children.splice(t,1),this.children.push(e)),e},remove(e){let t=this.children.indexOf(e);if(t!==-1){e.parent=null,this.children.splice(t,1);let n=e=>{e.trigger(`destroy`),J.game.events.trigger(`destroy`,e),e.children.forEac
56h(e=>n(e))};n(e)}},removeAll(e){if(e)this.get(e).forEach(e=>this.remove(e));else for(let e of[...this.children])this.remove(e)},fixedUpdate(){this.paused||(this.children.forEach(e=>e.fixedUpdate()),this.trigger(`fixedUpdate`))},update(){this.paused||(this.children.forEach(e=>e.update()),this.trigger(`update`))},draw(){if(this.hidden)return;this.canvas&&(lr(),this.canvas.bind());let e=J.gfx.fixed;this.fixed&&(J.gfx.fixed=!0),ir(),G(this.pos),or(this.scale),sr(this.angle);let t=this.children.sort((e,t)=>(e.layerIndex??J.game.defaultLayerIndex)-(t.layerIndex??J.game.defaultLayerIndex)||(e.z??0)-(t.z??0));if(this.mask){let e={intersect:J.k.drawMasked,subtract:J.k.drawSubtracted}[this.mask];if(!e)throw Error(`Invalid mask func: "${this.mask}"`);e(()=>{t.forEach(e=>e.draw())},()=>{this.trigger(`draw`)})}else this.trigger(`draw`),t.forEach(e=>e.draw());cr(),J.gfx.fixed=e,this.canvas&&(lr(),this.canvas.unbind())},drawInspect(){this.hidden||(ir(),G(this.pos),or(this.scale),sr(this.angle),this.children.forEach(e=>e.drawInspect()),this.trigger(`drawInspect`),cr())},use(e){if(typeof e==`string`)return o.add(e);if(!e||typeof e!=`object`)throw Error(`You can only pass a component or a string to .use(), you passed a "${typeof e}"`);let i=[];e.id?(this.unuse(e.id),r[e.id]=[],i=r[e.id],t.set(e.id,e),s&&o.add(e.id)):n.push(e);for(let n in e){if(Ct.has(n))continue;let r=Object.getOwnPropertyDescriptor(e,n);if(r){if(typeof r.value==`function`&&(e[n]=e[n].bind(this)),r.set&&Object.defineProperty(e,n,{set:r.set.bind(this)}),r.get&&Object.defineProperty(e,n,{get:r.get.bind(this)}),wt.has(n)){let t=n===`add`?()=>{c=e=>i.push(e),e[n]?.(),c=null}:e[n];i.push(this.on(n,t).cancel)}else if(this[n]===void 0)Object.defineProperty(this,n,{get:()=>e[n],set:t=>e[n]=t,configurable:!0,enumerable:!0}),i.push(()=>delete this[n]);else{let r=t.values().find(e=>e[n]!==void 0)?.id;throw Error(`Duplicate component property: "${n}" while adding component "${e.id}"`+(r?` (originally added by "${r}")`:``))}}}let a=()=>{if(e.require){for(let t of e.require)if(!this.c(t))throw Error(`Component "${e.id}" requires component "${t}"`)}};e.destroy&&i.push(e.destroy.bind(this)),this.exists()?(a(),e.add&&(c=e=>i.push(e),e.add.call(this),c=null),e.id&&(this.trigger(`use`,e.id),J.game.events.trigger(`use`,this,e.id))):e.require&&i.push(this.on(`add`,a).cancel)},unuse(e){if(t.has(e)){for(let n of t.values())if(n.require&&n.require.includes(e))throw Error(`Can't unuse. Component "${n.id}" requires component "${e}"`);t.delete(e),this.trigger(`unuse`,e),J.game.events.trigger(`unuse`,this,e)}else s&&o.has(e)&&o.delete(e);r[e]&&(r[e].forEach(e=>e()),delete r[e])},c(e){return t.get(e)??null},get(e,t={}){let n=(e,n)=>t.only===`comps`?e.has(n):t.only===`tags`?e.is(n):e.is(n)||e.has(n),r=t.recursive?this.children.flatMap(function e(t){return[t,...t.children.flatMap(e)]}):this.children;if(r=r.filter(t=>!e||n(t,e)),t.liveUpdate){let i=e=>t.recursive?this.isAncestorOf(e):e.parent===this,a=[];a.push(J.k.onAdd(t=>{i(t)&&n(t,e)&&r.push(t)})),a.push(J.k.onDestroy(t=>{if(i(t)&&n(t,e)){let e=r.findIndex(e=>e.id===t.id);e!==-1&&r.splice(e,1)}})),this.onDestroy(()=>{for(let e of a)e.cancel()})}return r},query(e){let t=e.hierarchy||`children`,n=e.include,r=e.exclude,i=[];switch(t){case`children`:i=this.children;break;case`siblings`:i=this.parent?this.parent.children.filter(e=>e!==this):[];break;case`ancestors`:let e=this.parent;for(;e;)i.push(e),e=e.parent;break;case`descendants`:i=this.children.flatMap(function e(t){return[t,...t.children.flatMap(e)]})}if(n&&(i=(e.includeOp||`and`)===`and`||!Array.isArray(e.include)?i.filter(e=>e.is(n)):i.filter(t=>e.include.some(e=>t.is(e)))),r&&(i=(e.includeOp||`and`)===`and`||!Array.isArray(e.include)?i.filter(e=>!e.is(r)):i.filter(t=>!e.exclude.some(e=>t.is(e)))),e.visible===!0&&(i=i.filter(e=>e.visible)),e.distance){if(!this.pos)throw Error(`Can't do a distance query from an object without pos`);let t=e.distanceOp||`near`,n=e.distance*e.distance;i=t===`near`?i.filter(e=>e.pos&&this.pos.sdist(e.pos)<=n):i.filter(e=>e.pos&&this.pos.sdist(e.pos)>n)}return e.name&&(i=i.filter(t=>t.name===e.name)),i},isAncestorOf(e){return e.parent?e.parent===this||this.isAncestorOf(e.parent):!1},exists(){return J.game.root.isAncestorOf(this)},is(e,t=`and`){return Array.isArray(e)?t===`and`?e.every(e=>o.has(e)):e.some(e=>o.has(e)):o.has(e)},tag(e){if(Array.isArray(e))for(let t of e)o.add(t),this.trigger(`tag`,t),J.game.events.trigger(`tag`,this,t);else o.add(e),this.trigger(`tag`,e),J.game.events.trigger(`tag`,this,e)},untag(e){if(Array.isArray(e))for(let t of e)o.delete(t),this.trigger(`untag`,t),J.game.events.trigger(`untag`,this,t);else o.delete(e),this.trigger(`untag`,e),J.game.events.trigger(`untag`,this,e)},has(e,n=`and`){return Array.isArray(e)?n===`and`?e.every(e=>t.has(e)):e.some(e=>t.has(e)):t.has(e)},on(e,t){let n=i.on(e,t.bind(this));return c&&c(()=>n.cancel()),n},trigger(e,...t){i.trigger(e,...t),J.game.objEvents.trigger(e,this,...t)},destroy(){this.parent&&this.parent.remove(this)},inspect(){let e={};for(let[n,r]of t)e[n]=r.inspect?.()??null;for(let[t,r]of n.entries()){if(r.inspect){e[t]=r.inspect();continue}for(let[t,n]of Object.entries(r))typeof n!=`function`&&(e[t]=`${t}: ${n}`)}return e},onAdd(e){return this.on(`add`,e)},onFixedUpdate(e){return this.on(`fixedUpdate`,e)},onUpdate(e){return this.on(`update`,e)},onDraw(e){return this.on(`draw`,e)},onDestroy(e){return this.on(`destroy`,e)},onUse(e){return this.on(`use`,e)},onUnuse(e){return this.on(`unuse`,e)},clearEvents(){i.clear()}};for(let e of[`onKeyPress`,`onKeyPressRepeat`,`onKeyDown`,`onKeyRelease`,`onMousePress`,`onMouseDown`,`onMouseRelease`,`onMouseMove`,`onCharInput`,`onMouseMove`,`onTouchStart`,`onTouchMove`,`onTouchEnd`,`onScroll`,`onGamepadButtonPress`,`onGamepadButtonDown`,`onGamepadButtonRelease`,`onGamepadStick`,`onButtonPress`,`onButtonDown`,`onButtonRelease`])u[e]=(...t)=>{let n=J.app[e]?.(...t);return a.push(n),u.onDestroy(()=>n.cancel()),u.on(`sceneEnter`,()=>{a.splice(a.indexOf(n),1);let r=J.app[e]?.(...t);At.replace(n,r),a.push(n)}),n};for(let t of e)u.use(t);return u}var Ua=()=>({events:new jt,objEvents:new jt,root:Ha([]),gravity:null,scenes:{},currentScene:null,layers:null,defaultLayerIndex:0,logs:[],cam:{pos:null,scale:new d(1),angle:0,shake:0,transform:new _}});function Wa(e){J.game.gravity=e?(J.game.gravity||f(0,1)).unit().scale(e):null}function Ga(){return J.game.gravity?J.game.gravity.len():0}function Ka(e){J.game.gravity=e.unit().scale(J.game.gravity?J.game.gravity.len():1)}function qa(){return J.game.gravity?J.game.gravity.unit():f(0,1)}var Ja=e(`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`),Ya=()=>(()=>{let e=new(window.AudioContext||window.webkitAudioContext),t=e.createGain();t.connect(e.destination);let n=new Zr(Vn(e));return e.decodeAudioData(Ja.buffer.slice(0)).then(e=>{n.buf=e}).catch(e=>{console.error(`Failed to load burp: `,e)}),{ctx:e,masterNode:t,burpSnd:n}})();function Xa(e,t={}){let r=new H,i=new Audio(e);i.crossOrigin=`anonymous`,i.loop=!!t.loop,J.audio.ctx.createMediaElementSource(i).connect(J.audio.masterNode);function a(){J.debug.paused||J.app.isHidden()&&!J.globalOpt.backgroundAudio||J.audio.ctx.resume()}function o(){a(),i.play()}return t.paused||o(),i.onended=()=>r.trigger(),{play(){o()},seek(e){i.currentTime=e},stop(){i.pause(),this.seek(0)},set loop(e){i.loop=e},get loop(){return i.loop},set paused(e){e?i.pause():o()},get paused(){return i.paused},time(){return i.currentTime},duration(){return i.duration},set volume(e){i.volume=n(e,0,1)},get volume(){return i.volume},set speed(e){i.playbackRate=Math.max(e,0)},get speed(){return i.playbackRate},set detune(e){},get detune(){return 0},onEnd(e){return r.add(e)},then(e){return this.onEnd(e)}}}function Za(e,t={}){if(typeof e==`string`&&J.assets.music[e])return Xa(J.assets.music[e],t);let n=J.audio.ctx,r=t.paused??!1,i=n.createBufferSource(),a=new H,o=n.createGain(),s=n.createStereoPanner(),c=t.seek??0,l=0,u=0,d=!1;i.loop=!!t.loop,i.detune.value=t.detune??0,i.playbackRate.value=t.speed??1,i.connect(s),i.onended=()=>{m()>=(i.buffer?.duration??1/0)&&a.trigger()},s.pan.value=t.pan??0,s.connect(o),o.connect(J.audio.masterNode),o.gain.value=t.volume??1;let f=e=>{i.buffer=e.buf,r||(l=n.currentTime,i.start(0,c),d=!0)},p=Qr(e);p instanceof mr&&p.onLoad(f);let m=()=>{if(!i.buffer)return 0;let e=r?u-l:n.currentTime-l,t=i.buffer.duration;return i.loop?e%t:Math.min(e,t)},h=e=>{let t=n.createBufferSource();return t.buffer=e.buffer,t.loop=e.loop,t.playbackRate.value=e.playbackRate.value,t.detune.value=e.detune.value,t.onended=e.onended,t.connect(s),t};return{stop(){this.paused=!0,this.seek(0)},set paused(e){if(r!==e){if(r=e,e)d&&=(i.stop(),!1),u=n.currentTime;else{i=h(i);let e=u-l;i.start(0,e),d=!0,l=n.currentTime-e,u=0}}},get paused(){return r},play(e=0){this.seek(e),this.paused=!1},seek(e){i.buffer?.duration&&(e>i.buffer.duration||(r?(i=h(i),l=u-e):(i.stop(),i=h(i),l=n.currentTime-e,i.start(0,e),d=!0,u=0)))},set speed(e){i.playbackRate.value=e},get speed(){return i.playbackRate.value},set detune(e){i.detune.value=e},get detune(){return i.detune.value},set volume(e){o.gain.value=Math.max(e,0)},get volume(){return o.gain.value},set pan(e){s.pan.value=e},get pan(){return s.pan.value},set loop(e){i.loop=e},get loop(){return i.loop},duration(){return i.buffer?.duration??0},time(){return m()%this.duration()},onEnd(e){return a.add(e)},then(e){return this.onEnd(e)}}}function Qa(e){return J.k.play(J.audio.burpSnd,e)}function $a(e){J.audio.masterNode.gain.value=e}function eo(){return J.audio.masterNode.gain.value}function to(e){return Jt(`volume`,`setVolume / getVolume`),e!==void 0&&$a(e),eo()}function no(){J.app.onHide(()=>{J.globalOpt.backgroundAudio||J.audio.ctx.suspend()}),J.app.onShow(()=>{!J.globalOpt.backgroundAudio&&!J.debug.paused&&J.audio.ctx.resume()}),J.app.onResize(()=>{if(J.app.isFullscreen())return;let e=J.globalOpt.width&&J.globalOpt.height;e&&!J.globalOpt.stretch&&!J.globalOpt.letterbox||(J.canvas.width=J.canvas.offsetWidth*J.pixelDensity,J.canvas.height=J.canvas.offsetHeight*J.pixelDensity,gn(),e||(J.gfx.frameBuffer.free(),J.gfx.frameBuffer=new hi(J.gfx.ggl,J.gfx.ggl.gl.drawingBufferWidth,J.gfx.ggl.gl.drawingBufferHeight),J.gfx.width=J.gfx.ggl.gl.drawingBufferWidth/J.pixelDensity/J.gscale,J.gfx.height=J.gfx.ggl.gl.drawingBufferHeight/J.pixelDensity/J.gscale))}),J.globalOpt.debug!==!1&&(J.app.onKeyPress(J.globalOpt.debugKey??`f1`,()=>J.debug.inspect=!J.debug.inspect),J.app.onKeyPress(`f2`,()=>J.debug.clearLog()),J.app.onKeyPress(`f8`,()=>
56J.debug.paused=!J.debug.paused),J.app.onKeyPress(`f7`,()=>{J.debug.timeScale=Yt(n(J.debug.timeScale-.2,0,2),1)}),J.app.onKeyPress(`f9`,()=>{J.debug.timeScale=Yt(n(J.debug.timeScale+.2,0,2),1)}),J.app.onKeyPress(`f10`,()=>J.debug.stepFrame())),J.globalOpt.burp&&J.app.onKeyPress(`b`,()=>Qa())}function ro(e,t={}){let n=J.game.root.add([ts(e),Fo()]),r=(t.speed||1)*5,i=t.scale||1;n.add([ho(J.boomSprite),rs(0),Yo(`center`),Ao(r,i),...t.comps??[]]);let a=n.add([ho(J.kaSprite),rs(0),Yo(`center`),Lo(),...t.comps??[]]);return a.wait(.4/r,()=>a.use(Ao(r,i))),a.onDestroy(()=>n.destroy()),n}function io(e,t){if(J.game.layers)throw Error(`Layers can only be assigned once.`);let n=e.indexOf(t);if(n==-1)throw Error(`The default layer name should be present in the layers list.`);J.game.layers=e,J.game.defaultLayerIndex=n}function ao(){return J.game.layers}function oo(){return J.game.layers?.[J.game.defaultLayerIndex]??null}function so(e,t){Jt(`layers`,`setLayers`),io(e,t)}function co(e){e.destroy()}function lo(){return J.game.root}function uo(e,t){J.game.scenes[e]=t}function fo(e,...t){if(!J.game.scenes[e])throw Error(`Scene not found: ${e}`);J.game.events.onOnce(`frameEnd`,()=>{J.game.events.trigger(`sceneLeave`,e),J.app.events.clear(),J.game.events.clear(),J.game.objEvents.clear(),[...J.game.root.children].forEach(t=>{!t.stay||t.scenesToStay&&!t.scenesToStay.includes(e)?J.game.root.remove(t):t.trigger(`sceneEnter`,e)}),J.game.root.clearEvents(),no(),J.game.cam={pos:null,scale:f(1),angle:0,shake:0,transform:new _},J.game.scenes[e](...t)}),J.game.currentScene=e}function po(e){return J.game.events.on(`sceneLeave`,e)}function mo(){return J.game.currentScene}function ho(e,t={}){let n=null,r=null,i=null,a=new H;if(!e)throw Error(`Please pass the resource name or data to sprite()`);let o=(e,t,n,r)=>{let i=f(1,1);return n&&r?(i.x=n/(e.width*t.w),i.y=r/(e.height*t.h)):n?(i.x=n/(e.width*t.w),i.y=i.x):r&&(i.y=r/(e.height*t.h),i.x=i.y),i},s=(e,r)=>{if(!r)return;let i=r.frames[0].clone();t.quad&&(i=i.scale(t.quad));let s=o(r.tex,i,t.width,t.height);if(e.width=r.tex.width*i.w*s.x,e.height=r.tex.height*i.h*s.y,r.anims)for(let e in r.anims){let t=r.anims[e];typeof t!=`number`&&(t.frames=c(t))}n=r,a.trigger(n),t.anim&&e.play(t.anim)},c=e=>{if(e.frames)return e.frames;let t=[];if(e.from===void 0||e.to===void 0)throw Error(`Sprite anim 'from' and 'to' must be defined if 'frames' is not defined`);let n=Math.abs(e.to-e.from)+1;for(let r=0;r<n;r++)t.push(e.from+r*Math.sign(e.to-e.from));if(e.pingpong)for(let e=n-2;e>0;e--)t.push(t[e]);return t};return{id:`sprite`,width:0,height:0,frame:t.frame||0,quad:t.quad||new p(0,0,1,1),animSpeed:t.animSpeed??1,flipX:t.flipX??!1,flipY:t.flipY??!1,get sprite(){return e.toString()},set sprite(e){let t=Ar(e);t&&t.onLoad(e=>s(this,e))},get animFrame(){if(!n||!r||i===null)return this.frame;let e=n.anims[r.name];return typeof e==`number`?e:e.from===void 0||e.to===void 0?r.frameIndex:this.frame-Math.min(e.from,e.to)},draw(){if(!n)return;let e=n.frames[this.frame??0];if(!e)throw Error(`Frame not found: ${this.frame??0}`);if(n.slice9){let{left:r,right:i,top:a,bottom:o}=n.slice9,s=n.tex.width*e.w,c=n.tex.height*e.h,l=this.width-r-i,u=this.height-a-o,d=r/s,f=i/s,p=1-d-f,h=a/c,g=o/c,_=1-h-g,v=[m(0,0,d,h),m(d,0,p,h),m(d+p,0,f,h),m(0,h,d,_),m(d,h,p,_),m(d+p,h,f,_),m(0,h+_,d,g),m(d,h+_,p,g),m(d+p,h+_,f,g),m(0,0,r,a),m(r,0,l,a),m(r+l,0,i,a),m(0,a,r,u),m(r,a,l,u),m(r+l,a,i,u),m(0,a+u,r,o),m(r,a+u,l,o),m(r+l,a+u,i,o)];for(let r=0;r<9;r++){let i=v[r],a=v[r+9];Fi(Object.assign(Vi(this),{pos:a.pos(),tex:n.tex,quad:e.scale(i),flipX:this.flipX,flipY:this.flipY,tiled:t.tiled,width:a.w,height:a.h}))}}else Fi(Object.assign(Vi(this),{tex:n.tex,quad:e.scale(this.quad??new p(0,0,1,1)),flipX:this.flipX,flipY:this.flipY,tiled:t.tiled,width:this.width,height:this.height}))},add(){let t=Ar(e);t?t.onLoad(e=>s(this,e)):wa(()=>s(this,Ar(e).data))},update(){if(!n||!r||i===null)return;let e=n.anims[r.name];if(typeof e==`number`){this.frame=e;return}if(e.speed===0)throw Error(`Sprite anim speed cannot be 0`);if(r.timer+=W()*this.animSpeed,r.timer>=1/r.speed){r.timer=0,r.frameIndex+=i;let t=e.frames;if(r.frameIndex>=t.length){if(r.pingpong&&!e.pingpong)i=-1,r.frameIndex=t.length-2;else if(r.loop)r.frameIndex=0;else{this.frame=t.at(-1),r.onEnd(),this.stop();return}}else if(r.frameIndex<0){if(r.pingpong&&r.loop)i=1,r.frameIndex=1;else if(r.loop)r.frameIndex=t.length-1;else{this.frame=t[0],r.onEnd(),this.stop();return}}this.frame=t[r.frameIndex]}},play(e,t={}){if(!n){a.add(()=>this.play(e,t));return}let o=n.anims[e];if(o===void 0)throw Error(`Anim not found: ${e}`);r&&this.stop(),r=typeof o==`number`?{name:e,timer:0,loop:!1,pingpong:!1,speed:0,frameIndex:0,onEnd:()=>{}}:{name:e,timer:0,loop:t.loop??o.loop??!1,pingpong:t.pingpong??o.pingpong??!1,speed:t.speed??o.speed??10,frameIndex:0,onEnd:t.onEnd??(()=>{})},i=typeof o==`number`?null:1,this.frame=typeof o==`number`?o:o.frames[0],this.trigger(`animStart`,e)},stop(){if(!r)return;let e=r.name;r=null,this.trigger(`animEnd`,e)},numFrames(){return n?.frames.length??0},getCurAnim(){return r},curAnim(){return r?.name},getAnim(e){return n?.anims[e]??null},hasAnim(e){return!!this.getAnim(e)},onAnimEnd(e){return this.on(`animEnd`,e)},onAnimStart(e){return this.on(`animStart`,e)},renderArea(){return new R(f(0),this.width,this.height)},inspect(){return typeof e==`string`?`sprite: "${e}"`:null}}}function go(e,t={}){function n(e){let n=Si(Object.assign(Vi(e),{text:e.text+``,size:e.textSize,font:e.font,width:t.width&&e.width,align:e.align,letterSpacing:e.letterSpacing,lineSpacing:e.lineSpacing,transform:e.textTransform,styles:e.textStyles,indentAll:t.indentAll}));return t.width||(e.width=n.width/(e.scale?.x||1)),e.height=n.height/(e.scale?.y||1),n}let r={id:`text`,set text(t){e=t,n(this),this.renderedText=xi(e).text},get text(){return e},textSize:t.size??36,font:t.font,width:t.width??0,height:0,align:t.align,lineSpacing:t.lineSpacing,letterSpacing:t.letterSpacing,textTransform:t.transform,textStyles:t.styles,renderedText:e?xi(e).text:``,add(){wa(()=>n(this))},draw(){wi(n(this))},renderArea(){return new R(f(0),this.width,this.height)}};return n(r),r}function _o(e,t){return{id:`rect`,width:e,height:t,draw(){Ci(Object.assign(Vi(this),{width:this.width,height:this.height}))},renderArea(){return new R(f(0),this.width,this.height)},inspect(){return`uvquad: (${Math.ceil(this.width)}w, ${Math.ceil(this.height)})h`}}}function vo(e={}){let t=null,n=null,r=null,i=null;return{id:`agent`,require:[`pos`,`tile`],agentSpeed:e.speed??100,allowDiagonals:e.allowDiagonals??!0,getDistanceToTarget(){return t?this.pos.dist(t):0},getNextLocation(){return n&&r?n[r]:null},getPath(){return n?n.slice():null},getTarget(){return t},isNavigationFinished(){return!n||r===null},isTargetReachable(){return n!==null},isTargetReached(){return!t||this.pos.eq(t)},setTarget(e){t=e,n=this.getLevel().getPath(this.pos,t,{allowDiagonals:this.allowDiagonals}),r=n?0:null,n&&r!==null?(i||(i=this.getLevel().onNavigationMapChanged(()=>{t&&n&&r!==null&&(n=this.getLevel().getPath(this.pos,t,{allowDiagonals:this.allowDiagonals}),n?(r=0,this.trigger(`navigationNext`,this,n[r])):(r=null,this.trigger(`navigationEnded`,this)))}),this.onDestroy(()=>i?.cancel())),this.trigger(`navigationStarted`,this),this.trigger(`navigationNext`,this,n[r])):this.trigger(`navigationEnded`,this)},update(){if(t&&n&&r!==null){if(this.pos.sdist(n[r])<2){if(r===n.length-1){this.pos=t.clone(),r=null,this.trigger(`navigationEnded`,this),this.trigger(`targetReached`,this);return}r++,this.trigger(`navigationNext`,this,n[r])}this.moveTo(n[r],this.agentSpeed)}},onNavigationStarted(e){return this.on(`navigationStarted`,e)},onNavigationNext(e){return this.on(`navigationNext`,e)},onNavigationEnded(e){return this.on(`navigationEnded`,e)},onTargetReached(e){return this.on(`targetReached`,e)},inspect(){return`agent: `+JSON.stringify({target:JSON.stringify(t),path:JSON.stringify(n)})}}}function yo(e){let t=e.graph;return{id:`pathfinder`,require:[`pos`],navigateTo(t){return this.graph?.getWaypointPath(this.pos,t,e.navigationOpt)},get graph(){if(t)return t;let e=this.parent;for(;e;){if(e.has(`pathfinderMap`))return e.graph;e=e.parent}},set graph(e){t=e}}}function bo(e={}){let t=e.waypoints,n=e.speed||100,r=e.endBehavior||`stop`,i=0,a=t!=null;return{id:`patrol`,require:[`pos`],get patrolSpeed(){return n},set patrolSpeed(e){n=e},get waypoints(){return t}
56,set waypoints(e){t=e,i=0,a=!1},get nextLocation(){return t?t[i]:void 0},update(){let e=this.nextLocation;if(!(!t||!e||a)&&(this.moveTo(e,n),this.pos.sdist(e)<9))switch(r){case`loop`:i=(i+1)%t.length;break;case`ping-pong`:i+=1,i==t.length&&(t.reverse(),i=0);break;case`stop`:i<t.length-1?i+=1:a||(a=!0,this.trigger(`patrolFinished`,this));break}},onPatrolFinished(e){return this.on(`patrolFinished`,e)}}}function xo(e,t={}){let n=typeof e==`function`?e:()=>J.game.root.query(e),r=t.checkFrequency||1,i=typeof t.direction==`number`?d.fromAngle(t.direction):t.direction,a=0;return{id:`sentry`,require:[`pos`],direction:typeof t.direction==`number`?d.fromAngle(t.direction):t.direction,spotted:[],set directionAngle(e){this.direction=e===void 0?void 0:d.fromAngle(e)},get directionAngle(){return this.direction?this.direction.angle():void 0},fieldOfView:t.fieldOfView||200,isWithinFieldOfView(e,n,r){let a=(typeof n==`number`?d.fromAngle(n):n)||i,o=r||t.fieldOfView;if(!a||!o||o>=360)return!0;let s=o/2;return e.pos&&a.angleBetween(e.pos.sub(this.pos))<=s},hasLineOfSight(e){let n=Qi(this.pos,e.pos.sub(this.pos),t.raycastExclude);return n!=null&&n.object===e},update(){if(a+=W(),a>r){a-=r;let e=n();if(e.length&&i&&this.fieldOfView&&this.fieldOfView<360){let t=this.fieldOfView/2;e=e.filter(e=>e.pos&&i.angleBetween(e.pos.sub(this.pos))<=t)}e.length&&t.lineOfSight&&(e=e.filter(e=>e.pos&&this.hasLineOfSight(e))),e.length>0&&(this.spotted=e,this.trigger(`objectSpotted`,e))}},onObjectsSpotted(e){return this.on(`objectSpotted`,e)}}}function So(e={}){let t=f(0),n=e.isObstacle??!1,r=e.cost??0,i=e.edges??[],a=()=>{let e={left:1,top:2,right:4,bottom:8};return i.map(t=>e[t]||0).reduce((e,t)=>e|t,0)},o=a();return{id:`tile`,tilePosOffset:e.offset??f(0),set tilePos(e){let n=this.getLevel();t=e.clone(),this.pos=f(this.tilePos.x*n.tileWidth(),this.tilePos.y*n.tileHeight()).add(this.tilePosOffset)},get tilePos(){return t},set isObstacle(e){n!==e&&(n=e,this.getLevel().invalidateNavigationMap())},get isObstacle(){return n},set cost(e){r!==e&&(r=e,this.getLevel().invalidateNavigationMap())},get cost(){return r},set edges(e){i=e,o=a(),this.getLevel().invalidateNavigationMap()},get edges(){return i},get edgeMask(){return o},getLevel(){return this.parent},tileMove(e){let t=this.getLevel();t.removeFromSpatialMap(this),this.tilePos=this.tilePos.add(e),t.insertIntoSpatialMap(this),t.trigger(`spatialMapChanged`)},moveLeft(){this.tileMove(f(-1,0))},moveRight(){this.tileMove(f(1,0))},moveUp(){this.tileMove(f(0,-1))},moveDown(){this.tileMove(f(0,1))}}}var Co=class{name;duration;loops;direction;easing;interpolation;isFinished;timing;easings;relative;constructor(e,t,n){this.name=e,this.duration=t.duration,this.loops=t.loops||0,this.direction=t.direction||`forward`,this.easing=t.easing||qn.linear,this.interpolation=t.interpolation||`linear`,this.isFinished=!1,this.timing=t.timing,this.easings=t.easings,this.relative=n}update(e,t){return!0}getLowerKeyIndexAndRelativeTime(e,t,n){let r=t-1,i=e/this.duration;if(this.loops!==0&&i>=this.loops)return[r,0,!0];let a=Math.trunc(i);if(i-=a,(this.direction==`reverse`||this.direction==`ping-pong`&&a&1)&&(i=1-i),n){let e=0;for(;n[e+1]!==void 0&&n[e+1]<i;)e++;return e>=r?[r,0,!0]:[e,(i-n[e])/(n[e+1]-n[e]),!1]}{let e=Math.floor((t-1)*i);return[e,(i-e/r)*r,!1]}}setValue(e,t,n){if(this.relative)switch(t){case`pos`:e.pos=e.base.pos.add(n);break;case`angle`:e.angle=e.base.angle+n;break;case`scale`:e.scale=e.base.scale.scale(n);break;case`opacity`:e.opacity=e.base.opacity*n;break;default:e[t]=n}else e[t]=n}serialize(){let e={duration:this.duration,keys:[]};return this.loops&&(e.loops=this.loops),this.direction!==`forward`&&(e.direction=this.direction),this.easing!=qn.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(e=>this.easing.name)),e}};function wo(e,t){return t.add(t.sub(e))}var To=class extends Co{keys;constructor(e,t,n,r){super(e,n,r),this.keys=t}update(e,t){let[n,r,i]=this.getLowerKeyIndexAndRelativeTime(t,this.keys.length,this.timing);if(r==0||this.interpolation===`none`)this.setValue(e,this.name,this.keys[n]);else{let t=this.easings?this.easings[n]:this.easing;this.setValue(e,this.name,c(this.keys[n],this.keys[n+1],t(r)))}return i}serialize(){return Object.assign(super.serialize(),{keys:this.keys})}},Eo=class extends Co{keys;curves;dcurves;constructor(e,t,n,r,i){if(super(e,n,r),this.keys=t,this.interpolation===`spline`){this.curves=[],i&&(this.dcurves=[]);for(let e=0;e<this.keys.length-1;e++){let t=this.keys[e],n=e+1,r=this.keys[n],a=e>0?this.keys[e-1]:wo(r,t),o=n<this.keys.length-1?this.keys[n+1]:wo(t,r);this.curves.push(He(a,t,r,o)),i&&this.dcurves?.push(He(a,t,r,o,Ge))}}}update(e,t){let[n,r,i]=this.getLowerKeyIndexAndRelativeTime(t,this.keys.length,this.timing);if(r==0||this.interpolation===`none`)this.setValue(e,this.name,this.keys[n]);else{let t=this.easings?this.easings[n]:this.easing;switch(this.interpolation){case`linear`:this.setValue(e,this.name,this.keys[n].lerp(this.keys[n+1],t(r)));break;case`slerp`:this.setValue(e,this.name,this.keys[n].slerp(this.keys[n+1],t(r)));break;case`spline`:if(this.curves){this.setValue(e,this.name,this.curves[n](t(r))),this.dcurves&&this.setValue(e,`angle`,this.dcurves[n](t(r)).angle());break}}}return i}serialize(){return Object.assign(super.serialize(),{keys:this.keys.map(e=>[e.x,e.y])})}},Do=class extends Co{keys;constructor(e,t,n,r){super(e,n,r),this.keys=t}update(e,t){let[n,r,i]=this.getLowerKeyIndexAndRelativeTime(t,this.keys.length,this.timing);if(r==0||this.interpolation==`none`)this.setValue(e,this.name,this.keys[n]);else{let t=this.easings?this.easings[n]:this.easing;this.setValue(e,this.name,this.keys[n].lerp(this.keys[n+1],t(r)))}return i}serialize(){return Object.assign(super.serialize(),{keys:this.keys})}};function Oo(e={}){let t=[],i=0,a=!1;return{id:`animate`,require:e.followMotion?[`rotate`]:void 0,base:{pos:f(0,0),angle:0,scale:f(1,1),opacity:1},animation:{paused:!1,seek(e){i=n(e,0,this.duration),t.forEach(e
56=>{e.isFinished=!1}),a=!1},get duration(){return t.reduce((e,t)=>Math.max(t.duration,e),0)}},add(){e.relative&&(this.has(`pos`)&&(this.base.pos=this.pos.clone()),this.has(`rotate`)&&(this.base.angle=this.angle),this.has(`scale`)&&(this.base.scale=this.scale),this.has(`opacity`)&&(this.base.opacity=this.opacity))},update(){if(this.animation.paused)return;let e=!0,n;i+=W();for(let r of t)n=r.update(this,i),n&&!r.isFinished&&(r.isFinished=!0,this.trigger(`animateChannelFinished`,r.name)),e&&=n;e&&!a&&(a=!0,this.trigger(`animateFinished`))},animate(n,i,o){a=!1,this.unanimate(n),typeof i[0]==`number`?t.push(new To(n,i,o,e.relative||!1)):i[0]instanceof d?t.push(new Eo(n,i,o,e.relative||!1,n===`pos`&&(e.followMotion||!1))):i[0]instanceof r&&t.push(new Do(n,i,o,e.relative||!1))},unanimate(e){let n=t.findIndex(t=>t.name===e);n>=0&&t.splice(n,1)},unanimateAll(){t.splice(0,t.length)},onAnimateFinished(e){return this.on(`animateFinished`,e)},onAnimateChannelFinished(e){return this.on(`animateChannelFinished`,e)},serializeAnimationChannels(){return t.reduce((e,t)=>(e[t.name]=t.serialize(),e),{})},serializeAnimationOptions(){let t={};return e.followMotion&&(t.followMotion=!0),e.relative&&(t.relative=!0),t}}}function ko(e,t){let n={name:e.name};return e.has(`animate`)&&(n.channels=e.serializeAnimationChannels(),Object.assign(n,e.serializeAnimationOptions())),e.children.length>0&&(n.children=e.children.filter(e=>e.has(`named`)).map(e=>ko(e,e.name))),n}function Ao(e=2,t=1){let n=0;return{require:[`scale`],update(){let r=Math.sin(n*e)*t;r<0&&this.destroy(),this.scale=f(r),n+=W()}}}function jo(e,t){if(e==null)throw Error(`health() requires the initial amount of hp`);return{id:`health`,hurt(t=1){this.setHP(e-t),this.trigger(`hurt`,t)},heal(t=1){let n=e;this.setHP(e+t),this.trigger(`heal`,e-n)},hp(){return e},maxHP(){return t??null},setMaxHP(e){t=e},setHP(n){e=t?Math.min(t,n):n,e<=0&&this.trigger(`death`)},onHurt(e){return this.on(`hurt`,e)},onHeal(e){return this.on(`heal`,e)},onDeath(e){return this.on(`death`,e)},inspect(){return`health: ${e}`}}}function Mo(e,t={}){if(e==null)throw Error(`lifespan() requires time`);let n=t.fade??0;return{id:`lifespan`,require:[`opacity`],add(){J.game.root.wait(e,()=>{this.opacity=this.opacity??1,n>0?J.game.root.tween(this.opacity,0,n,e=>this.opacity=e,qn.linear).onEnd(()=>{this.destroy()}):this.destroy()})}}}function No(e){return{id:`named`,name:e}}function Po(e,t,n){if(!e)throw Error(`state() requires an initial state`);let r={};function i(e){r[e]||(r[e]={enter:new H,end:new H,update:new H,draw:new H})}function a(e,t,n){return i(t),r[t][e].add(n)}function o(e,t,...n){i(t),r[t][e].trigger(...n)}let s=!1;return{id:`state`,state:e,enterState(e,...r){if(s=!0,t&&!t.includes(e))throw Error(`State not found: ${e}`);let i=this.state;if(n){if(!n?.[i])return;let t=typeof n[i]==`string`?[n[i]]:n[i];if(!t.includes(e))throw Error(`Cannot transition state from "${i}" to "${e}". Available transitions: ${t.map(e=>`"${e}"`).join(`, `)}`)}o(`end`,i,...r),this.state=e,o(`enter`,e,...r),o(`enter`,`${i} -> ${e}`,...r)},onStateTransition(e,t,n){return a(`enter`,`${e} -> ${t}`,n)},onStateEnter(e,t){return a(`enter`,e,t)},onStateUpdate(e,t){return a(`update`,e,t)},onStateDraw(e,t){return a(`draw`,e,t)},onStateEnd(e,t){return a(`end`,e,t)},update(){s||=(o(`enter`,e),!0),o(`update`,this.state)},draw(){o(`draw`,this.state)},inspect(){return`state: ${this.state}`}}}function Fo(e){return{id:`stay`,stay:!0,scenesToStay:e}}function Io(e=!0,t){let n,r;return{id:`textInput`,hasFocus:e,require:[`text`],typedText:``,add(){let e=()=>{this.text=this.typedText.replace(/([\[\\])/g,`\\$1`)};n=J.k.onCharInput(n=>{this.hasFocus&&(!t||this.typedText.length<t)&&(J.k.isKeyDown(`shift`)?this.typedText+=n.toUpperCase():this.typedText+=n,e())}),r=J.k.onKeyPressRepeat(`backspace`,()=>{this.hasFocus&&(this.typedText=this.typedText.slice(0,-1),e())})},destroy(){n.cancel(),r.cancel()}}}function Lo(e=1e3){return{id:`timer`,maxLoopsPerFrame:e,loop(e,t,n=1/0,r=!1){let i=r?0:e,a=new H,o=this.onUpdate(()=>{i+=J.app.state.dt;for(let r=0;i>=e&&r<this.maxLoopsPerFrame;r++)if(n--,t(),i-=e,n<=0){o.cancel(),a.trigger();return}});return{get paused(){return o.paused},set paused(e){o.paused=e},cancel:o.cancel,onEnd(e){a.add(e)},then(e){return a.add(e),this}}},wait(e,t){return this.loop(e,t??(()=>{}),1,!0)},tween(e,t,n,r,i=qn.linear){let a=0,o=[],s=this.onUpdate(()=>{a+=J.app.state.dt;let l=Math.min(a/n,1);
56r(c(e,t,i(l))),l===1&&(s.cancel(),r(t),o.forEach(e=>e()))});return{get paused(){return s.paused},set paused(e){s.paused=e},onEnd(e){o.push(e)},then(e){return this.onEnd(e),this},cancel(){s.cancel()},finish(){s.cancel(),r(t),o.forEach(e=>e())}}}}}var Ro=0;function zo(){return Ro>0}function Bo(e={}){let t={},n=new Set,r=[];return{id:`area`,collisionIgnore:e.collisionIgnore??[],add(){Ro++,this.area.cursor&&r.push(this.onHover(()=>J.app.setCursor(this.area.cursor))),r.push(this.onCollideUpdate((e,r)=>{if(!e.id)throw Error(`area() requires the object to have an id`);t[e.id]||this.trigger(`collide`,e,r),r&&(t[e.id]=r,n.add(e.id))}))},destroy(){Ro--;for(let e of r)e.cancel()},fixedUpdate(){for(let e in t)n.has(Number(e))||(this.trigger(`collideEnd`,t[e].target),delete t[e]);n.clear()},drawInspect(){let e=this.localArea();ir(),G(this.area.offset);let t={outline:{width:4/ur(),color:i(0,0,255)},anchor:this.anchor,fill:!1,fixed:Bi(this)};e instanceof R?Ti({...t,pos:e.pos,width:e.width*this.area.scale.x,height:e.height*this.area.scale.y}):e instanceof B?ii({...t,pts:e.pts,scale:this.area.scale}):e instanceof z&&oi({...t,pos:e.center,radius:e.radius}),cr()},area:{shape:e.shape??null,scale:e.scale?f(e.scale):f(1),offset:e.offset??f(0),cursor:e.cursor??null},isClicked(){return J.app.isMousePressed()&&this.isHovering()},isHovering(){let e=Bi(this)?J.k.mousePos():J.k.toWorld(J.k.mousePos());return this.hasPoint(e)},checkCollision(e){if(!e.id)throw Error(`checkCollision() requires the object to have an id`);return t[e.id]??null},getCollisions(){return Object.values(t)},isColliding(e){if(!e.id)throw Error(`isColliding() requires the object to have an id`);return!!t[e.id]},isOverlapping(e){if(!e.id)throw Error(`isOverlapping() requires the object to have an id`);let n=t[e.id];return n&&n.hasOverlap()},onClick(e,t=`left`){let n=this.onMousePress(t,()=>{this.isHovering()&&e()});return r.push(n),n},onHover(e){let t=!1;return this.onUpdate(()=>{t?t=this.isHovering():this.isHovering()&&(t=!0,e())})},onHoverUpdate(e){return this.onUpdate(()=>{this.isHovering()&&e()})},onHoverEnd(e){let t=!1;return this.onUpdate(()=>{t?this.isHovering()||(t=!1,e()):t=this.isHovering()})},onCollide(e,t){if(typeof e==`function`&&t===void 0)return this.on(`collide`,e);if(typeof e==`string`)return this.onCollide((n,r)=>{n.is(e)&&t?.(n,r)});throw Error(`onCollide() requires either a function or a tag`)},onCollideUpdate(e,t){if(typeof e==`function`&&t===void 0)return this.on(`collideUpdate`,e);if(typeof e==`string`)return this.on(`collideUpdate`,(n,r)=>n.is(e)&&t?.(n,r));throw Error(`onCollideUpdate() requires either a function or a tag`)},onCollideEnd(e,t){if(typeof e==`function`&&t===void 0)return this.on(`collideEnd`,e);if(typeof e==`string`)return this.on(`collideEnd`,n=>n.is(e)&&t?.(n));throw Error(`onCollideEnd() requires either a function or a tag`)},hasPoint(e){return F(this.worldArea(),e)},resolveCollision(e){let t=this.checkCollision(e);t&&!t.resolved&&(this.pos=this.pos.add(t.displacement),t.resolved=!0)},localArea(){return this.area.shape?this.area.shape:this.renderArea()},worldArea(){let e=this.localArea();if(!(e instanceof B||e instanceof R))throw Error(`Only support polygon and rect shapes for now`);let t=this.transform.clone().translate(this.area.offset).scale(f(this.area.scale??1));if(e instanceof R){let n=zn(this.anchor||ut).add(1,1).scale(-.5).scale(e.width,e.height);t.translate(n)}return e.transform(t)},screenArea(){let e=this.worldArea();return Bi(this)?e:e.transform(J.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)`}}}function Vo(e={}){let t=null,n=null,r=!1,i=f(0),a=null,o=null,s;return{id:`body`,require:[`pos`],vel:f(0),drag:e.drag??0,jumpForce:e.jumpForce??Et,gravityScale:e.gravityScale??1,isStatic:e.isStatic??!1,mass:e.mass??1,add(){if(a=this.pos.clone(),o=this.pos.clone(),s=this.pos.clone(),this.mass===0)throw Error(`Can't set body mass to 0`);this.has(`area`)&&(this.onCollideUpdate((e,t)=>{if(!t||!e.has(`body`)||t.resolved)return;this.trigger(`beforePhysicsResolve`,t);let n=t.reverse();if(e.trigger(`beforePhysicsResolve`,n),!(t.resolved||n.resolved)&&!(this.isStatic&&e.isStatic)){if(!this.isStatic&&!e.isStatic){let n=this.mass+e.mass;this.pos=this.pos.add(t.displacement.scale(e.mass/n)),e.pos=e.pos.add(t.displacement.scale(-this.mass/n)),this.transform=$n(this),e.transform=$n(e)}else{let n=!this.isStatic&&e.isStatic?t:t.reverse();n.source.pos=n.source.pos.add(n.displacement),n.source.transform=$n(n.source)}t.resolved=!0,this.trigger(`physicsResolve`,t),e.trigger(`physicsResolve`,t.reverse())}}),this.onPhysicsResolve(e=>{if(J.game.gravity){if(e.isBottom()&&this.isFalling()){this.vel=this.vel.reject(J.game.gravity.unit());let i=t;t=e.target,i!=t&&(n=e.target.pos),r?r=!1:i||(this.trigger(`ground`,t),e.target.trigger(`land`,this))}else e.isTop()&&this.isJumping()&&(this.vel=this.vel.reject(J.game.gravity.unit()),this.trigger(`headbutt`,e.target),e.target.trigger(`headbutted`,this))}}))},update(){t&&this.isColliding(t)&&t.exists()&&t.has(`body`)&&(n&&!t.pos.eq(n)&&e.stickToPlatform!==!1&&this.moveBy(t.pos.sub(n)),n=t.pos);let r=kn();r&&(this.pos.x==s.x&&(this.pos.x=c(a.x,o.x,r/On()),s.x=this.pos.x),this.pos.y==s.y&&(this.pos.y=c(a.y,o.y,r/On()),s.y=this.pos.y))},fixedUpdate(){if(a&&=(this.pos.x==s.x&&(this.pos.x=a.x),this.pos.y==s.y&&(this.pos.y=a.y),null),J.game.gravity&&!this.isStatic){r&&=(t=null,n=null,this.trigger(`fallOff`),!1),t&&(!this.isColliding(t)||!t.exists()||
56!t.has(`body`))&&(r=!0);let i=this.vel.clone();this.vel=this.vel.add(J.game.gravity.scale(this.gravityScale*W()));let a=e.maxVelocity??Dt;this.vel.slen()>a*a&&(this.vel=this.vel.unit().scale(a)),i.dot(J.game.gravity)<0&&this.vel.dot(J.game.gravity)>=0&&this.trigger(`fall`)}if(this.vel.x+=i.x*W(),this.vel.y+=i.y*W(),this.vel.x*=1-this.drag*W(),this.vel.y*=1-this.drag*W(),this.move(this.vel),kn()){a=this.pos.clone();let e=this.vel.add(i.scale(W()));o=this.pos.add(e.scale(W())),s=this.pos.clone()}i.x=0,i.y=0},onPhysicsResolve(e){return this.on(`physicsResolve`,e)},onBeforePhysicsResolve(e){return this.on(`beforePhysicsResolve`,e)},curPlatform(){return t},isGrounded(){return t!==null},isFalling(){return this.vel.dot(qa())>0},isJumping(){return this.vel.dot(qa())<0},applyImpulse(e){this.isStatic||(this.vel=this.vel.add(e))},addForce(e){this.isStatic||(i.x+=e.x/this.mass,i.y+=e.y/this.mass)},jump(e){this.isStatic||(t=null,n=null,this.vel=qa().scale(-e||-this.jumpForce))},onGround(e){return this.on(`ground`,e)},onFall(e){return this.on(`fall`,e)},onFallOff(e){return this.on(`fallOff`,e)},onHeadbutt(e){return this.on(`headbutt`,e)},onLand(e){return this.on(`land`,e)},onHeadbutted(e){return this.on(`headbutted`,e)},inspect(){return`gravityScale: ${this.gravityScale}x`}}}function Ho(e=2){let t=e;return{id:`doubleJump`,require:[`body`],numJumps:e,add(){this.onGround(()=>{t=this.numJumps})},doubleJump(e){t<=0||(t<this.numJumps&&this.trigger(`doubleJump`),t--,this.jump(e))},onDoubleJump(e){return this.on(`doubleJump`,e)},inspect(){return`jumpsLeft: ${t}`}}}function Uo(e){return{id:`surfaceEffector`,require:[`area`],speed:e.speed,speedVariation:e.speedVariation??0,forceScale:e.speedVariation??.9,add(){this.onCollideUpdate(`body`,(e,t)=>{let n=t?.normal.normal(),r=e.vel.project(n),i=n?.scale(this.speed)?.sub(r);e.addForce(i?.scale(e.mass*this.forceScale))})}}}function Wo(e){return{id:`areaEffector`,require:[`area`],useGlobalAngle:e.useGlobalAngle||!1,forceAngle:e.forceAngle,forceMagnitude:e.forceMagnitude,forceVariation:e.forceVariation??0,linearDrag:e.linearDrag??0,add(){this.onCollideUpdate(`body`,(e,t)=>{if(!e.has(`body`))return;let n=d.fromAngle(this.forceAngle).scale(this.forceMagnitude);e.addForce(n),this.linearDrag&&e.addForce(e.vel.scale(-this.linearDrag))})}}}function Go(e){return{id:`pointEffector`,require:[`area`,`pos`],forceMagnitude:e.forceMagnitude,forceVariation:e.forceVariation??0,distanceScale:e.distanceScale??1,forceMode:e.forceMode||`inverseLinear`,linearDrag:e.linearDrag??0,add(){this.onCollideUpdate(`body`,(e,t)=>{let n=this.pos.sub(e.pos),r=n.len(),i=r*this.distanceScale/10,a=this.forceMode===`constant`?1:this.forceMode===`inverseLinear`?1/i:1/i**2,o=n.scale(this.forceMagnitude*a/r);e.addForce(o),this.linearDrag&&e.addForce(e.vel.scale(-this.linearDrag))})}}}function Ko(e){return{id:`constantForce`,require:[`body`],force:e.force,update(){this.force&&this.addForce(this.force)}}}function qo(e){return{id:`platformEffector`,require:[`area`,`body`],surfaceArc:e.surfaceArc??180,useOneWay:e.useOneWay??!1,add(){this.onBeforePhysicsResolve(e=>{let t=e.target.vel,n=qa().scale(-1).angleBetween(t);Math.abs(n)>this.surfaceArc/2&&e.preventResolution()})}}}function Jo(e){return{id:`buoyancyEffector`,require:[`area`],surfaceLevel:e.surfaceLevel,density:e.density??1,linearDrag:e.linearDrag??1,angularDrag:e.angularDrag??.2,flowAngle:e.flowAngle??0,flowMagnitude:e.flowMagnitude??0,flowVariation:e.flowVariation??0,add(){this.onCollideUpdate(`body`,(e,t)=>{let n=e,[r,i]=n.worldArea().cut(f(-100,this.surfaceLevel),f(100,this.surfaceLevel));r&&(this.applyBuoyancy(n,r),this.applyDrag(n,r)),this.flowMagnitude&&n.addForce(d.fromAngle(this.flowAngle).scale(this.flowMagnitude))})},applyBuoyancy(e,t){let n=this.density*t.area(),r=f(0,1).scale(-n);e.addForce(r)},applyDrag(e,t){let n=e.vel,r=this.density*this.linearDrag,i=n.scale(-r);e.addForce(i)}}}function Yo(e){if(!e)throw Error(`Please define an anchor`);return{id:`anchor`,anchor:e,inspect(){return typeof this.anchor==`string`?`anchor: `+this.anchor:`anchor: `+this.anchor.toString()}}}function Xo(){return{id:`fixed`,fixed:!0}}function Zo(e,t){return{id:`follow`,require:[`pos`],follow:{obj:e,offset:t??f(0)},add(){e.exists()&&(this.pos=this.follow.obj.pos.add(this.follow.offset))},update(){e.exists()&&(this.pos=this.follow.obj.pos.add(this.follow.offset))}}}function Qo(e){let t=J.game.layers?.indexOf(e);return{id:`layer`,get layerIndex(){return t??null},get layer(){return t?J.game.layers?.[t]??null:null},set layer(e){if(t=J.game.layers?.indexOf(e),t==-1)throw Error(`Invalid layer name`)},inspect(){return`layer: ${this.layer}`}}}function $o(e,t){let n=typeof e==`number`?d.fromAngle(e):e.unit();return{id:`move`,require:[`pos`],update(){this.move(n.scale(t))}}}function es(e={}){let t=!1,n=new R(f(0),K(),q()),r=new R(f(0),0,0),i=n=>{n.isOffScreen()?(t||=(n.trigger(`exitView`),!0),e.hide&&(n.hidden=!0),e.pause&&(n.paused=!0),e.destroy&&n.destroy()):(t&&=(n.trigger(`enterVie
56w`),!1),e.hide&&(n.hidden=!1),e.pause&&(n.paused=!1))};return{id:`offscreen`,require:[`pos`],offscreenDistance:e.distance??Tt,isOffScreen(){let e=this.screenPos();if(!e)return!1;if(n.width=K(),n.height=q(),!this.offscreenDistance&&this.width&&this.height)return r.width=this.width,r.height=this.height,r.pos=this.pos,r.collides(n);let t=this.offscreenDistance?this.offscreenDistance:Tt;return!A(n,e)&&n.sdistToPoint(e)>t*t},onExitScreen(e){return this.on(`exitView`,e)},onEnterScreen(e){return this.on(`enterView`,e)},add(){e.pause&&e.unpause?aa(()=>i(this)):this.onUpdate(()=>i(this))}}}function ts(...e){return{id:`pos`,pos:f(...e),moveBy(...e){this.pos=this.pos.add(f(...e))},move(...e){this.moveBy(f(...e).scale(W()))},moveTo(...e){if(typeof e[0]==`number`&&typeof e[1]==`number`)return this.moveTo(f(e[0],e[1]),e[2]);let t=e[0],n=e[1];if(n===void 0){this.pos=f(t);return}let r=t.sub(this.pos);if(r.len()<=n*W()){this.pos=f(t);return}this.move(r.unit().scale(n))},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 e=this.worldPos();return e?Bi(this)?e:Ia(e):null}},toScreen(e){let t=this.toWorld(e);return Bi(this)?t:Ia(t)},fromScreen(e){return Bi(this)?this.fromWorld(e):this.fromWorld(La(e))},toOther(e,t){return e.fromWorld(this.toWorld(t))},fromOther(e,t){return e.toOther(this,t)},inspect(){return`pos: (${Math.round(this.pos.x)}x, ${Math.round(this.pos.y)}y)`},drawInspect(){oi({color:i(255,0,0),radius:4/ur()})}}}function ns(e){return{id:`rotate`,angle:e??0,rotateBy(e){this.angle+=e},rotateTo(e){this.angle=e},inspect(){return`angle: ${Math.round(this.angle)}`}}}function rs(...e){if(e.length===0)return rs(1);let t=f(...e);return{id:`scale`,set scale(e){if(!(e instanceof d))throw Error(`The scale property on scale is a vector. Use scaleTo or scaleBy to set the scale with a number.`);t=f(e)},get scale(){return t},scaleTo(...e){t=f(...e)},scaleBy(...e){t=t.scale(f(...e))},inspect(){return t.x==t.y?`scale: ${t.x.toFixed(1)}x`:`scale: (${t.x.toFixed(1)}x, ${t.y.toFixed(1)}y)`}}}function is(e){return{id:`z`,z:e,inspect(){return`z: ${this.z}`}}}var as=`data:image/png;base64,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`,os=`data:image/png;base64,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`,ss=t.version,J={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},cs=(e={tagsAsComponents:!0})=>{J.k&&(console.warn(`KAPLAY already initialized, you are calling kaplay() multiple times, it may lead bugs!`),J.k.quit()),J.globalOpt=e;let t=e.root??document.body;t===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 h=e.canvas??t.appendChild(document.createElement(`canvas`));J.canvas=h;let g=e.scale??1;J.gscale=g;let y=e.width&&e.height&&!e.stretch&&!e.letterbox;y?(h.width=e.width*g,h.height=e.height*g):(h.width=h.parentElement.offsetWidth,h.height=h.parentElement.offsetHeight);let b=[`outline: none`,`cursor: default`];if(y){let e=h.width,t=h.height;b.push(`width: ${e}px`),b.push(`height: ${t}px`)}else b.push(`width: 100%`),b.push(`height: 100%`);e.crisp&&(b.push(`image-rendering: pixelated`),b.push(`image-rendering: crisp-edges`)),h.style.cssText=b.join(`;`);let x=e.pixelDensity||1;J.pixelDensity=x,h.width*=x,h.height*=x,h.tabIndex=0;let C=document.createElement(`canvas`);C.width=256,C.height=256,J.fontCacheCanvas=C,J.fontCacheC2d=C.getContext(`2d`,{willReadFrequently:!0});let k=Dn({canvas:h,touchToMouse:e.touchToMouse,gamepads:e.gamepads,pixelDensity:e.pixelDensity,maxFPS:e.maxFPS,buttons:e.buttons});J.app=k;let ae=[],j=k.canvas.getContext(`webgl`,{antialias:!0,depth:!0,stencil:!0,alpha:!0,preserveDrawingBuffer:!0});if(!j)throw Error(`WebGL not supported`);let N=j,se=vi(N,{texFilter:e.texFilter}),P=zi(e,se);J.gfx=P;let le=Ya();J.audio=le;let F=Dr(se,e.spriteAtlasPadding??0);J.assets=F;let I=Ua();J.game=I,I.root.use(Lo());function ue(e,t){let n=new hi(se,e,t);return{clear:()=>n.clear(),free:()=>n.free(),toDataURL:()=>n.toDataURL(),toImageData:()=>n.toImageData(),width:n.width,height:n.height,draw:e=>{lr(),n.bind(),e(),lr(),n.unbind()},get fb(){return n}}}function de(){N.clear(N.COLOR_BUFFER_BIT),P.frameBuffer.bind(),N.clear(N.COLOR_BUFFER_BIT),P.bgColor||Ei(()=>{Ci({width:K(),height:q(),quad:new p(0,0,K()/64,q()/64),tex:P.bgTex,fixed:!0})}),P.renderer.numDraws=0,P.fixed=!1,P.transformStack.length=0,P.transform=new _}function fe(e,t){P.postShader=e,P.postShaderUniform=t??null}function pe(){lr(),P.lastDrawCalls=P.renderer.numDraws,P.frameBuffer.unbind(),N.viewport(0,0,N.drawingBufferWidth,N.drawingBufferHeight);let e=P.width,t=P.height;P.width=N.drawingBufferWidth/x,P.height=N.drawingBufferHeight/x,Fi({flipY:!0,tex:P.frameBuffer.tex,pos:new d(P.viewport.x,P.viewport.y),width:P.viewport.width,height:P.viewport.height,shader:P.postShader,uniform:typeof P.postShaderUniform==`function`?P.postShaderUniform():P.postShaderUniform,fixed:!0}),lr(),P.width=e,P.height=t}let me=!1,he={inspect:!1,set timeScale(e){J.app.state.timeScale=e},get timeScale(){return J.app.state.timeScale},showLog:!0,fps:()=>k.fps(),numFrames:()=>k.numFrames(),stepFrame:Je,drawCalls:()=>P.lastDrawCalls,clearLog:()=>I.logs=[],log:(...t)=>{let n=e.logMax??8,r=t.length>1?t.concat(` `).join(` `):t[0];I.logs.unshift({msg:r,time:k.time()}),I.logs.length>n&&(I.logs=I.logs.slice(0,n))},error:e=>he.log(Error(e.toString?e.toString():e)),curRecording:null,numObjects:()=>we(`*`,{recursive:!0}).length,get paused(){return me},set paused(e){me=e,e?le.ctx.suspend():le.ctx.resume()}};J.debug=he;function ge(e,t){try{return JSON.parse(window.localStorage[e])}catch{return t?(_e(e,t),t):null}}function _e(e,t){window.localStorage[e]=JSON.stringify(t)}function ve(t,...n){let r=t(at),i;i=typeof r==`function`?r(...n)(at):r;for(let t in i)at[t]=i[t],e.global!==!1&&(window[t]=i[t]);return at}function ye(e){let t=k.canvas.captureStream(e),n=le.ctx.createMediaStreamDestination();le.masterNode.connect(n);let r=new MediaRecorder(t),i=[];return r.ondataavailable=e=>{e.data.size>0&&i.push(e.data)},r.onerror=()=>
56{le.masterNode.disconnect(n),t.getTracks().forEach(e=>e.stop())},r.start(),{resume(){r.resume()},pause(){r.pause()},stop(){return r.stop(),le.masterNode.disconnect(n),t.getTracks().forEach(e=>e.stop()),new Promise(e=>{r.onstop=()=>{e(new Blob(i,{type:`video/mp4`}))}})},download(e=`kaboom.mp4`){this.stop().then(t=>Vt(e,t))}}}function be(){return document.activeElement===k.canvas}let xe=I.root.add.bind(I.root),Se=I.root.readd.bind(I.root),Ce=I.root.removeAll.bind(I.root),we=I.root.get.bind(I.root),Te=I.root.wait.bind(I.root),Ee=I.root.loop.bind(I.root),De=I.root.query.bind(I.root),Ae=I.root.tween.bind(I.root),Ge=Mr(null,os),Ke=Mr(null,as);J.kaSprite=Ge,J.boomSprite=Ke;function qe(){I.root.fixedUpdate()}function Je(){I.root.update()}class Ye{source;target;normal;distance;resolved=!1;constructor(e,t,n,r,i=!1){this.source=e,this.target=t,this.normal=n,this.distance=r,this.resolved=i}get displacement(){return this.normal.scale(this.distance)}reverse(){return new Ye(this.target,this.source,this.normal.scale(-1),this.distance,this.resolved)}hasOverlap(){return!this.displacement.isZero()}isLeft(){return this.displacement.cross(I.gravity||f(0,1))>0}isRight(){return this.displacement.cross(I.gravity||f(0,1))<0}isTop(){return this.displacement.dot(I.gravity||f(0,1))>0}isBottom(){return this.displacement.dot(I.gravity||f(0,1))<0}preventResolution(){this.resolved=!0}}
56function Xe(){if(!zo())return;let t={},n=e.hashGridSize||64,r=new _,i=[];function a(e){if(i.push(r.clone()),e.pos&&r.translate(e.pos),e.scale&&r.scale(e.scale),e.angle&&r.rotate(e.angle),e.transform=r.clone(),e.c(`area`)&&!e.paused){let r=e,i=r.worldArea().bbox(),a=Math.floor(i.pos.x/n),o=Math.floor(i.pos.y/n),s=Math.ceil((i.pos.x+i.width)/n),c=Math.ceil((i.pos.y+i.height)/n),l=new Set;for(let e=a;e<=s;e++)for(let n=o;n<=c;n++)if(!t[e])t[e]={},t[e][n]=[r];else if(!t[e][n])t[e][n]=[r];else{let i=t[e][n];e:for(let e of i){if(e.paused||!e.exists()||l.has(e.id))continue;for(let t of r.collisionIgnore)if(e.is(t))continue e;for(let t of e.collisionIgnore)if(r.is(t))continue e;let t=et(r.worldArea(),e.worldArea());if(t){let n=new Ye(r,e,t.normal,t.distance);r.trigger(`collideUpdate`,e,n);let i=n.reverse();i.resolved=n.resolved,e.trigger(`collideUpdate`,r,i)}l.add(e.id)}i.push(r)}}e.children.forEach(a),r=i.pop()}a(I.root)}function tt(e){console.error(e),le.ctx.suspend();let t=e.message??String(e)??`Unknown error, check console for more info`;k.run(()=>{},()=>{de(),Ei(()=>{let n=K(),r=q(),a={size:36,width:n-64,letterSpacing:4,lineSpacing:4,font:ft,fixed:!0};Ti({width:n,height:r,color:i(0,0,255),fixed:!0});let o=Si({...a,text:`Error`,pos:f(32),color:i(255,128,0),fixed:!0});wi(o),Ri({...a,text:t,pos:f(32,32+o.height+16),fixed:!0}),cr(),I.events.trigger(`error`,e)}),pe()})}function nt(e){ae.push(e)}function rt(){I.events.onOnce(`frameEnd`,()=>{k.quit(),N.clear(N.COLOR_BUFFER_BIT|N.DEPTH_BUFFER_BIT|N.STENCIL_BUFFER_BIT);let e=N.getParameter(N.MAX_TEXTURE_IMAGE_UNITS);for(let t=0;t<e;t++)N.activeTexture(N.TEXTURE0+t),N.bindTexture(N.TEXTURE_2D,null),N.bindTexture(N.TEXTURE_CUBE_MAP,null);N.bindBuffer(N.ARRAY_BUFFER,null),N.bindBuffer(N.ELEMENT_ARRAY_BUFFER,null),N.bindRenderbuffer(N.RENDERBUFFER,null),N.bindFramebuffer(N.FRAMEBUFFER,null),se.destroy(),ae.forEach(e=>e())})}let it=!0;k.run(()=>{try{F.loaded&&(he.paused||qe(),Xe())}catch(e){tt(e)}},(t,n)=>{try{t(),F.loaded||Cr()===1&&!it&&(F.loaded=!0,wr().forEach(e=>I.events.trigger(`loadError`,...e)),I.events.trigger(`load`)),!F.loaded&&e.loadingScreen!==!1||it?(de(),Mi(),pe()):(he.paused||Je(),Xe(),de(),ji(),e.debug!==!1&&ki(),pe()),it&&=!1,I.events.trigger(`frameEnd`),n()}catch(e){tt(e)}}),gn(),no();let at={_k:J,VERSION:ss,loadRoot:br,loadProgress:Cr,loadSprite:Mr,loadSpriteAtlas:ni,loadSound:ei,loadMusic:ti,loadBitmapFont:Ur,loadFont:Br,loadShader:Yr,loadShaderURL:Xr,loadAseprite:Ir,loadPedit:Wr,loadBean:Fr,loadJSON:xr,load:Er,getSound:$r,getFont:zr,getBitmapFont:Hr,getSprite:jr,getShader:Jr,getAsset:Tr,Asset:mr,SpriteData:kr,SoundData:Zr,width:K,height:q,center:dr,dt:W,fixedDt:On,restDt:kn,time:k.time,screenshot:k.screenshot,record:ye,isFocused:be,setCursor:k.setCursor,getCursor:k.getCursor,setCursorLocked:k.setCursorLocked,isCursorLocked:k.isCursorLocked,setFullscreen:k.setFullscreen,isFullscreen:k.isFullscreen,isTouchscreen:k.isTouchscreen,onLoad:wa,onLoadError:Ta,onLoading:xa,onResize:Sa,onGamepadConnect:k.onGamepadConnect,onGamepadDisconnect:k.onGamepadDisconnect,onError:Ca,onCleanup:nt,flash:Na,setCamPos:Ea,getCamPos:Da,setCamRot:Aa,getCamRot:ja,setCamScale:Oa,getCamScale:ka,getCamTransform:Ma,camPos:Ra,camScale:za,camFlash:Va,camRot:Ba,camTransform:Pa,shake:Fa,toScreen:Ia,toWorld:La,setGravity:Wa,getGravity:Ga,setGravityDirection:Ka,getGravityDirection:qa,setBackground:nr,getBackground:rr,getGamepads:k.getGamepads,getTreeRoot:lo,add:xe,make:Ha,destroy:co,destroyAll:Ce,get:we,query:De,readd:Se,pos:ts,scale:rs,rotate:ns,color:Ui,opacity:qi,anchor:Yo,area:Bo,sprite:ho,text:go,polygon:Zi,rect:$i,circle:Hi,uvquad:_o,outline:Ji,particles:Xi,body:Vo,platformEffector:qo,surfaceEffector:Uo,areaEffector:Wo,pointEffector:Go,buoyancyEffector:Jo,constantForce:Ko,doubleJump:Ho,shader:ea,textInput:Io,timer:Lo,fixed:Xo,stay:Fo,health:jo,lifespan:Mo,named:No,state:Po,z:is,layer:Qo,move:$o,offscreen:es,follow:Zo,fadeIn:Gi,mask:Ki,drawon:Wi,raycast:Qi,tile:So,animate:Oo,serializeAnimation:ko,agent:vo,sentry:xo,patrol:bo,pathfinder:yo,trigger:ra,on:na,onFixedUpdate:ia,onUpdate:aa,onDraw:oa,onAdd:sa,onDestroy:ca,onTag:da,onUntag:fa,onUse:la,onUnuse:ua,onClick:_a,onCollide:pa,onCollideUpdate:ma,onCollideEnd:ha,onHover:va,onHoverUpdate:ya,onHoverEnd:ba,onKeyDown:k.onKeyDown,onKeyPress:k.onKeyPress,onKeyPressRepeat:k.onKeyPressRepeat,onKeyRelease:k.onKeyRelease,onMouseDown:k.onMouseDown,onMousePress:k.onMousePress,onMouseRelease:k.onMouseRelease,onMouseMove:k.onMouseMove,onCharInput:k.onCharInput,onTouchStart:k.onTouchStart,onTouchMove:k.onTouchMove,onTouchEnd:k.onTouchEnd,onScroll:k.onScroll,onHide:k.onHide,onShow:k.onShow,onGamepadButtonDown:k.onGamepadButtonDown,onGamepadButtonPress:k.onGamepadButtonPress,onGamepadButtonRelease:k.onGamepadButtonRelease,onGamepadStick:k.onGamepadStick,onButtonPress:k.onButtonPress,onButtonDown:k.onButtonDown,onButtonRelease:k.onButtonRelease,mousePos:k.mousePos,mouseDeltaPos:k.mouseDeltaPos,isKeyDown:k.isKeyDown,isKeyPressed:k.isKeyPressed,isKeyPressedRepeat:k.isKeyPressedRepeat,isKeyReleased:k.isKeyReleased,isMouseDown:k.isMouseDown,isMousePressed:k.isMousePressed,isMouseReleased:k.isMouseReleased,isMouseMoved:k.isMouseMoved,isGamepadButtonPressed:k.isGamepadButtonPressed,isGamepadButtonDown:k.isGamepadButtonDown,isGamepadButtonReleased:k.isGamepadButtonReleased,getGamepadStick:k.getGamepadStick,isButtonPressed:k.isButtonPressed,isButtonDown:k.isButtonDown,isButtonReleased:k.isButtonReleased,setButton:k.setButton,getButton:k.getButton,pressButton:k.pressButton,releaseButton:k.releaseButton,getLastInputDeviceType:k.getLastInputDeviceType,charInputted:k.charInputted,loop:Ee,wait:Te,play:Za,setVolume:$a,getVolume:eo,volume:to,burp:Qa,audioCtx:le.ctx,Line:L,Rect:R,Circle:z,Ellipse:ke,Point:Oe,Polygon:B,Vec2:d,Color:r,Mat4:_,Quad:p,RNG:S,rand:T,randi:E,randSeed:w,vec2:f,rgb:i,hsl2rgb:a,quad:m,choose:te,chooseMultiple:ee,shuffle:O,chance:D,lerp:c,tween:Ae,easings:qn,map:l,mapc:u,wave:v,deg2rad:o,rad2deg:s,clamp:n,evaluateQuadratic:je,evaluateQuadraticFirstDerivative:Me,evaluateQuadraticSecondDerivative:Ne,evaluateBezier:Pe,evaluateBezierFirstDerivative:Fe,evaluateBezierSecondDerivative:V,evaluateCatmullRom:Ie,evaluateCatmullRomFirstDerivative:Le,curveLengthApproximation:ze,normalizedCurve:Re,hermite:Be,cardinal:Ve,catmullRom:He,bezier:Ue,kochanekBartels:We,easingSteps:$e,easingLinear:Ze,easingCub
56icBezier:Qe,testLineLine:re,testRectRect:ne,testRectLine:ie,testRectPoint:A,testCirclePolygon:ce,testLinePoint:M,testLineCircle:oe,isConvex:ct,triangulate:st,NavMesh:Qn,drawSprite:Ii,drawText:Ri,formatText:Si,drawRect:Ti,drawLine:si,drawLines:di,drawTriangle:Oi,drawCircle:oi,drawEllipse:ai,drawUVQuad:Ci,drawPolygon:ii,drawCurve:fi,drawBezier:pi,drawFormattedText:wi,drawMasked:Pi,drawSubtracted:Li,pushTransform:ir,popTransform:cr,pushTranslate:G,pushScale:or,pushRotate:sr,pushMatrix:ar,usePostEffect:fe,makeCanvas:ue,debug:he,scene:uo,getSceneName:mo,go:fo,onSceneLeave:po,layers:so,getLayers:ao,setLayers:io,getDefaultLayer:oo,addLevel:ta,getData:ge,setData:_e,download:Rt,downloadJSON:Bt,downloadText:zt,downloadBlob:Vt,plug:ve,ASCII_CHARS:lt,canvas:k.canvas,addKaboom:ro,LEFT:d.LEFT,RIGHT:d.RIGHT,UP:d.UP,DOWN:d.DOWN,RED:r.RED,GREEN:r.GREEN,BLUE:r.BLUE,YELLOW:r.YELLOW,MAGENTA:r.MAGENTA,CYAN:r.CYAN,WHITE:r.WHITE,BLACK:r.BLACK,quit:rt,KEvent:H,KEventHandler:jt,KEventController:At,cancel:()=>Ot};J.k=at;let ot=e.plugins;if(ot&&ot.forEach(ve),e.global!==!1)for(let e in at)window[e]=at[e];return e.focus!==!1&&k.canvas.focus(),at},ls=100,us=25,ds=100,Y={chaos:12,treats:0,goodBoy:28};function fs(){return{...Y}}function ps(e=Y.goodBoy){return Math.min(10,Math.floor(e/10)+1)}function ms(e){let t=Y.chaos>=50;return e.chaos!=null&&(Y.chaos=Ss(Y.chaos+e.chaos,0,ls)),e.treats!=null&&(Y.treats=Ss(Y.treats+e.treats,0,us)),e.goodBoy!=null&&(Y.goodBoy=Ss(Y.goodBoy+e.goodBoy,0,ds)),!t&&Y.chaos>=50&&(gs=5),fs()}function hs(){Y.chaos=12,Y.treats=0,Y.goodBoy=28,gs=5}var gs=5;function _s(){return gs}function vs(){return Y.chaos>=50}function ys(){return vs()?(gs=Math.max(0,gs-1),gs<=0?`dead`:`hurt`):`safe`}function bs(e){let t=[];return e.chaos&&t.push(`CHAOS ${xs(e.chaos)}`),e.treats&&t.push(`TREATS ${xs(e.treats)}`),e.goodBoy&&t.push(`GOOD BOY ${xs(e.goodBoy)}`),t.join(`   `)}function xs(e){return e>0?`+${e}`:`${e}`}function Ss(e,t,n){return Math.max(t,Math.min(n,e))}var Cs={"couch:hide":[`The undersides accept you. Dust lives here. Dust is family. The roaring beast cannot know this place.`],"couch:nap":[`You perform a circle, then another, then a third because two is for cats. You collapse. This is a throne.`],"couch:chew":[`The arm tastes like years of hands. You improve it. The humans will call this a crime. You call it interior design.`],"shoes:sniff":[`Outside is still on them. Grass. Street. A dog you have not met. You file the report.`],"shoes:steal":[`One shoe is a pair if you believe. You take it to a place of honor: under the furniture.`],"shoes:chew":[`You taste the remaining one to confirm it is still a shoe. It is. You make sure it stays interesting.`],"tv:watch":[`Tiny animals appear. You watch with the dignity of a critic who cannot change the channel.`],"tv:bark":[`A tiny animal does not respect you. You bark. It does not respect you louder. You respect yourself.`],"tv:block":[`You sit in the glowing. The humans make the noise that means they can no longer see. This is correct. You were here first.`],"vacuum:sniff":[`Plastic and thunder. You back up one step, then two, then you consider a third for science.`],"vacuum:bark":[`THE BEAST IS AWAKE or it will be. You inform it, at volume, that this house has a king.`],"vacuum:flee":[`A strategic retreat. The hallway is a kingdom. You will return when the roaring is a rumor.`],"fridge:wait":[`Someone left a smell in here last Thursday. You remember. Waiting is a kind of hunting.`],"fridge:scratch":[`The cold box does not open. You explain, with claws, that this is a design flaw.`],"fridge:believe":[`You cannot open it. You can believe you could. Belief is almost a treat.`],"trash:sniff":[`Notes of chicken, shame, and a napkin that once knew gravy. You take the meeting.`],"trash:raid":[`The forbidden buffet is open. For science. You emerge with knowledge and a little gravy.`],"trash:tip":[`Gravity is your intern. The bowl becomes a landscape. You are the mayor of scraps.`],"bowl:drink":[`Water. You drink as if you have crossed a desert, which you have: the hallway.`],"bowl:splash":[`The water was too still. You fix this. The floor is now also a bowl.`],"bowl:guard":[`This is your water. You lie beside it in case of thieves, which include you, later.`],"bed:claim":[`You find the exact center, which is a crime, which is also love. You sigh the sigh of a landlord.`],"bed:burrow":[`The nest smells like safety and the soap they use when they leave you. You tunnel. It was always yours.`],"bed:shed":[`You leave a signature in fur. Future-you will find it and know: I was comfortable here.`],"sock:sniff":[`Still warm with the memory of a foot. This is culture. You take notes with your nose.`],"sock:claim":[`The sacred sock is yours. You will keep it. You will hide it. This is the law.`],"sock:bury":[`You present it to the empty room, extremely proud. Nobody is here. Under the bed, then.`]},ws={};function Ts(e,t){let n=Es(e);ms(t.delta);let r=bs(t.delta);return{speaker:`You`,text:r?`${n}\n\n${r}`:n,delta:t.delta}}function Es(e){let t=`${e.objectId}:${e.actionId}`,n=Cs[t]??[`You ${e.actionLabel.toLowerCase()}. The ${e.objectName.toLowerCase()} allows this. You are qualified.`],r=ws[t]??0;return ws[t]=r+1,n[r%n.length]}var Ds={couch:[{id:`hide`,label:`Hide under`,delta:{goodBoy:6,cha
56os:-2}},{id:`nap`,label:`Nap`,delta:{goodBoy:4}},{id:`chew`,label:`Chew`,delta:{chaos:12,goodBoy:-6}}],shoes:[{id:`sniff`,label:`Sniff`,delta:{goodBoy:2}},{id:`steal`,label:`Steal one`,delta:{chaos:14,goodBoy:-8}},{id:`chew`,label:`Chew`,delta:{chaos:10,goodBoy:-4}}],tv:[{id:`watch`,label:`Watch`,delta:{goodBoy:3}},{id:`bark`,label:`Bark at it`,delta:{chaos:8}},{id:`block`,label:`Sit in front`,delta:{chaos:6,goodBoy:-2}}],vacuum:[{id:`sniff`,label:`Sniff the snout`,delta:{chaos:4,goodBoy:2}},{id:`bark`,label:`Bark`,delta:{chaos:12,goodBoy:-4}},{id:`flee`,label:`Flee`,delta:{goodBoy:5,chaos:2}}],fridge:[{id:`wait`,label:`Wait (hunting)`,delta:{goodBoy:3}},{id:`scratch`,label:`Scratch`,delta:{chaos:8,goodBoy:-3}},{id:`believe`,label:`Believe you can open it`,delta:{chaos:4}}],trash:[{id:`sniff`,label:`Sniff`,delta:{chaos:4}},{id:`raid`,label:`Raid`,delta:{chaos:16,treats:5,goodBoy:-10}},{id:`tip`,label:`Tip it`,delta:{chaos:18,treats:4,goodBoy:-8}}],bowl:[{id:`drink`,label:`Drink`,delta:{goodBoy:4}},{id:`splash`,label:`Splash`,delta:{chaos:6,goodBoy:-2}},{id:`guard`,label:`Guard it`,delta:{goodBoy:5}}],bed:[{id:`claim`,label:`Claim the middle`,delta:{chaos:5,goodBoy:4}},{id:`burrow`,label:`Burrow`,delta:{goodBoy:8,chaos:3}},{id:`shed`,label:`Shed`,delta:{chaos:10,goodBoy:-2}}],sock:[{id:`sniff`,label:`Sniff`,delta:{goodBoy:2}},{id:`claim`,label:`Claim it`,delta:{chaos:12,goodBoy:-6}},{id:`bury`,label:`Bury it`,delta:{chaos:8,goodBoy:2}}]};function Os(e){return Ds[e]??[{id:`sniff`,label:`Sniff`,delta:{chaos:2}}]}var ks={living:{id:`living`,title:`Living Room`,map:[`#########n##########`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`#..................e`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`####################`],furniture:[{id:`couch`,name:`Couch`,sprite:`couch`,tx:3,ty:3},{id:`tv`,name:`Picture Box`,sprite:`tv`,tx:15,ty:3},{id:`shoes`,name:`Shoes`,sprite:`shoes`,tx:2,ty:8}],vacuum:{tx:11,ty:7,minX:256,maxX:512},spawns:{default:{tx:10,ty:9},n:{tx:9,ty:2},e:{tx:17,ty:6},s:{tx:10,ty:9},w:{tx:2,ty:6}}},kitchen:{id:`kitchen`,title:`Kitchen`,map:[`####################`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`w..................#`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`####################`],furniture:[{id:`fridge`,name:`Cold Box`,sprite:`fridge`,tx:3,ty:4},{id:`trash`,name:`Forbidden Bowl`,sprite:`trash`,tx:15,ty:7},{id:`bowl`,name:`Water Bowl`,sprite:`bowl`,tx:8,ty:8}],spawns:{default:{tx:4,ty:6},n:{tx:10,ty:2},e:{tx:17,ty:6},s:{tx:10,ty:9},w:{tx:2,ty:6}}},bedroom:{id:`bedroom`,title:`The Nest`,map:[`####################`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`#..................#`,`#########s##########`],furniture:[{id:`bed`,name:`The Nest`,sprite:`bed`,tx:5,ty:4},{id:`sock`,name:`Sacred Sock`,sprite:`sock`,tx:14,ty:8}],spawns:{default:{tx:10,ty:8},n:{tx:10,ty:2},e:{tx:17,ty:6},s:{tx:9,ty:9},w:{tx:2,ty:6}}}};function As(e,t){return e===`living`&&t===`e`?{room:`kitchen`,spawn:`w`}:e===`living`&&t===`n`?{room:`bedroom`,spawn:`s`}:e===`kitchen`&&t===`w`?{room:`living`,spawn:`e`}:e===`bedroom`&&t===`s`?{room:`living`,spawn:`n`}:null}function js(e,t){return{x:e*32+16,y:48+t*32+16}}var Ms={chaosHigh:{id:`chaosHigh`,title:`MAXIMUM CHAOS`,subtitle:`the house has fallen`,body:`Shoes have been relocated. The forbidden bowl is a landscape. The vacuum files a complaint it cannot bark. You sit in the exact center of the wreckage and sigh the sigh of a landlord. You have won at being a dog.`,accent:[196,92,74]},chaosLow:{id:`chaosLow`,title:`ZERO CHAOS`,subtitle:`nothing is happening, on purpose`,body:`No sock is out of place. The cold box is unscratch. The beast sleeps, cheated of dirt. You lie very still. The humans will call this a good day. You call it a rumor. You might be broken. You might be plotting.`,accent:[180,160,130]}
56,goodHigh:{id:`goodHigh`,title:`GOOD BOY LEVEL MAX`,subtitle:`certificates, theoretically`,body:`You have sat. You have waited. You have drunk water like a professional. The humans do not know about the sock. They do not need to. You are the goodest. The vacuum, for once, is not about you.`,accent:[106,158,109]},treatsMax:{id:`treatsMax`,title:`TREAT HOARD`,subtitle:`twenty-five, and not one fewer`,body:`The biscuits have become a geography. You cannot lie down without crushing wealth. This is a problem for future-you, who is also you, who is currently chewing. The vacuum can wait. The vacuum has always waited.`,accent:[212,160,23]},vacuumDeath:{id:`vacuumDeath`,title:`THE BEAST EATS`,subtitle:`you were fur. it was enough.`,body:`The roaring found you. Five chances. None left. The hose does not care about Good Boy. It does not care about biscuits. It cares about dirt, and today you qualified. The undersides of the couch will remember you.`,accent:[196,92,74]}};function Ns(e,t){return e.chaos<100&&t.chaos>=100?`chaosHigh`:e.chaos>0&&t.chaos<=0?`chaosLow`:e.goodBoy<100&&t.goodBoy>=100?`goodHigh`:e.treats<25&&t.treats>=25?`treatsMax`:null}function Ps(e){return e.map(e=>[...e].reverse().join(``))}var Fs=`................................,................................,.....######..........######.....,....#TTTTTT##########TTTTTT#....,...#TTTTTTTTTTWWWWTTTTTTTTTT#...,...#TTTTTTTTTTWWWWTTTTTTTTTT#...,..#TTTttttTTTTWWWWTTTTttttTTT#..,..#TTTttttTTTTWWWWTTTTttttTTT#..,..#TTttttttTTTWWWWTTTttttttTT#..,..#TTtttt#tT#TWWWWT#Tt#ttttTT#..,..#TTttttt##TTWWWWTT##tttttTT#..,..#TTttttttTWWWWWWWWTttttttTT#..,..#TTTttttTWWWWWWWWWWTttttTTT#..,..#TTTttttWWWWWW#WWWWWttttTTT#..,..#TTTTTTTWWWWW###WWWWTTTTTTT#..,..#TTTTTTTWWWWWWWWWWWWTTTTTTT#..,...#TTTTTTTWW#WWWWW#WTTTTTTT#...,...#TTTTTTTTWW#ppp#WTTTTTTTT#...,....#TTTTTTTWWW###WWTTTTTTT#....,.....###TTTWWWWWWWWWWTTTTTT#....,........#TTWWWWWWWWWWTTTTTTT#...,........#TTWWWWWWWWWWTTTTTTT#...,........#TTWWWWWWWWWWTTTTTTT#...,........##TWWWWWWWWWWT#TTTT#....,..........#WWWWWWWWWW#.##T##....,.........#WWWWWWWWWWWW#..#......,........#WWWWWWWWWWWWWW#........,........#W#W#WWWWWWW#W##........,.........##############.........,................................,................................,................................`.split(`,`),Is=`................................,................................,................................,.....######..........######.....,....#TTTTTT##########TTTTTT#....,...#TTTTTTTTTTWWWWTTTTTTTTTT#...,...#TTTTTTTTTTWWWWTTTTTTTTTT#...,..#TTTttttTTTTWWWWTTTTttttTTT#..,..#TTTttttTTTTWWWWTTTTttttTTT#..,..#TTttttttTTTWWWWTTTttttttTT#..,..#TTtttt#tT#TWWWWT#Tt#ttttTT#..,..#TTttttt##TTWWWWTT##tttttTT#..,..#TTttttttTWWWWWWWWTttttttTT#..,..#TTTttttTWWWWWWWWWWTttttTTT#..,..#TTTttttWWWWWW#WWWWWttttTTT#..,..#TTTTTTTWWWWW###WWWWTTTTTTT#..,..#TTTTTTTWWWWWWWWWWWWTTTTTTT#..,...#TTTTTTTWW#WWWWW#WTTTTTTT#...,...#TTTTTTTTWW#ppp#WTTTTTTTT#...,....#TTTTTTTWWW###WWTTTTTTT#....,.....###TTTWWWWWWWWWWTTTTTT#....,........#TTWWWWWWWWWWTTTTTTT#...,........#TTWWWWWWWWWWTTTTTTT#...,........#TTWWWWWWWWWWTTTTTTT#...,........##TWWWWWWWWWWT#TTTT#....,..........#WWWWWWWWWW#.##T##....,.........#WWWWWWWWWWWW#..#......,........#WWWWWWWWWWWWWW#........,........#W#W#WWWWWWW#W##........,.........##############.........,................................,................................`.split(`,`),Ls=`................................,................................,................####............,..............##TTTT##..........,..............#TTTTTT#..........,..........####TTTTTTTT#.........,.........#TTTTTTTTTTTTT#........,........#TTTTTTTTTTTTTT#........,.......#TTTTWWWWTTTTTTT#........,.......#TTTTWWWWTTTTTTT#........,.......#WWTTWWWWTTTTTTT#........,......#W#WW#WWWWTTTTTTT#........,.....#WWW##WWWWWTTTTTTT#........,.....#WWWWWWWTTTTTTTTTT#........,.....#W#WWWWWTTTTTTTTTT#........,.....###WWWWWTTTTTTTTTT#........,......##p##WTTTTTTTTTT#.........,........##TTTTWWWWTTTTT###......,..........#TWWWWWWWWTTTTTT#.....,...........#WWWWWWTTTTTTTT#.....,..........#WWWWWWWTTTTTTTT#.....,..........#WWWWWWWTTTTTTTT#.....,..........#WWWWWWWTTTTTTTT#.....,..........#WWWWWWWTTTTTTTT#.....,..........#WWWWWWWTTTT####......,.........#WWWWWWWWWWW#..........,........#WWWWWWWWWWW#...........,........#WW#W#WWWWWW#...........,.........####.######............,................................,................................,................................`.split(`,`),Rs=`................................,................................,................................,................####............,..............##TTTT##..........,..............#TTTTTT#..........,..........####TTTTTTTT#.........,.........#TTTTTTTTTTTTT#........,........#TTTTTTTTTTTTTT#........,.......#TTTTWWWWTTTTTTT#........,.......#TTTTWWWWTTTTTTT#........,.......#WWTTWWWWTTTTTTT#........,......#W#WW#WWWWTTTTTTT#........,.....#WWW##WWWWWTTTTTTT#........,.....#WWWWWWWTTTTTTTTTT#........,.....#W#WWWWWTTTTTTTTTT#........,.....###WWWWWTTTTTTTTTT#........,......##p##WTTTTTTTTTT#.........,........##TTTTWWWWTTTTT###......,..........#TWWWWWWWWTTTTTT#.....,...........#WWWWWWTTTTTTTT#.....,..........#WWWWWWWTTTTTTTT#.....,..........#WWWWWWWTTTTTTTT#.....,..........#WWWWWWWTTTTTTTT#.....,..........#WWWWWWWTTTTTTTT#.....,..........#WWWWWWWTTTT####......,.........#WWWWWWWWWWW#..........,........#WWWWWWWWWWW#...........,........#WW#W#WWWWWW#...........,.........####.######............,................................,................................`.split(`,`),zs=`................................,................................,.....######..........######.....,....#TTTTTT##########TTTTTT#....,...#TTTTTTTTTTTTTTTTTTTTTTTT#...,...#TTTTTTTTTTTTTTTTTTTTTTTT#...,..#TTTttttTTTTTTTTTTTTttttTTT#..,..#TTTttttTTTTTTTTTTTTttttTTT#..,..#TTttttttTTTTTTTTTTttttttTT#..,..#TTttttttTTTTTTTTTTttttttTT#..,..#TTttttttTTTTTTTTTTttttttTT#..,..#TTttttttTTTTTTTTTTttttttTT#..,..#TTTttttTTTTTTTTTTTTttttTTT#..,..#TTTttttTTTTTTTTTTTTttttTTT#..,..#TTTTTTTTTTTTTTTTTTTTTTTTTT#..,..#TTTTTTTTTTTTTTTTTTTTTTTTTT#..,...#TTTTTTTTTTTTTTTTTTTTTTTT#...,...#TTTTTTTTTTTTTTTTTTTTTTTT#...,....#TTTTTTTTTTTTTTTTTTTTTT#....,.....######TTTTTTTTTT######.....,...........#TTTTTTTT#...........,..........#TTTTTTTTTT#..........,..........#TTTTTTTTTT#..........,..........#TTTTTTTTTT#..........,..........#TTTTTTTTTT#..........,.........#WWWTTTTTTWWW#.........,........#WWWWWTTTTWWWWW#........,........#W#WWWTTTTWWWW##........,.........##############.........,................................,................................,................................`.split(`,`),Bs=`................................,................................,................................,.....######..........######.....,....#TTTTTT##########TTTTTT#....,...#TTTTTTTTTTTTTTTTTTTTTTTT#...,...#TTTTTTTTTTTTTTTTTTTTTTTT#...,..#TTTttttTTTTTTTTTTTTttttTTT#..,..#TTTttttTTTTTTTTTTTTttttTTT#..,..#TTttttttTTTTTTTTTTttttttTT#..,..#TTttttttTTTTTTTTTTttttttTT#..,..#TTttttttTTTTTTTTTTttttttTT#..,..#TTttttttTTTTTTTTTTttttttTT#..,..#TTTttttTTTTTTTTTTTTttttTTT#..,..#TTTttttTTTTTTTTTTTTttttTTT#..,..#TTTTTTTTTTTTTTTTTTTTTTTTTT#..,..#TTTTTTTTTTTTTTTTTTTTTTTTTT#..,...#TTTTTTTTTTTTTTTTTTTTTTTT#...,...#TTTTTTTTTTTTTTTTTTTTTTTT#...,....#TTTTTTTTTTTTTTTTTTTTTT#....,.....######TTTTTTTTTT######.....,...........#TTTTTTTT#...........,..........#TTTTTTTTTT#..........,..........#TTTTTTTTTT#..........,..........#TTTTTTTTTT#..........,..........#TTTTTTTTTT#..........,.........#WWWTTTTTTWWW#.........,........#WWWWWTTTTWWWWW#........,........#W#WWWTTTTWWWW##........,.........##############.........,................................,................................`.split(`,`),Vs={down0:Fs,down1:Is,left0:Ls,left1:Rs,right0:Ps(Ls),right1:Ps(Rs),up0:zs,up1:Bs},X={ink:`#1a1410`,wall:`#4a3224`,wallHi:`#6b4a32`,floor:`#c4a06a`,floor2:`#b89058`,rug:`#7a3b32`,rugHi:`#9a4e42`,wood:`#6b4423`,cream:`#e8d5a3`,snout:`#f4ead4`,ear:`#5c4033`,vacuum:`#3a3c42`,vacuumHi:`#5c616c`,vacuumRed:`#c45c4a`,gold:`#d4a017`,leaf:`#6a9e6d`,water:`#4a7380`,waterHi:`#6a98a4`};function Z(e,t,n=2){let r=e[0].length,i=e.length,a=document.createElement(`canvas`);a.width=r*n,a.height=i*n;let o=a.getContext(`2d`);o.imageSmoothingEnabled=!1;for(let a=0;a<i;a++)for(let i=0;i<r;i++){let r=e[a][i];if(r===`.`||r===` `)continue;let s=t[r];s&&(o.fillStyle=s,o.fillRect(i*n,a*n,n,n))}return a.toDataURL()}var Hs=[`################`,`#++++++++++++++#`,`#++++++++++++++#`,`#++++++++++++++#`,`#++++++++++++++#`,`################`,`################`,`#++++++++++++++#`,`#++++++++++++++#`,`#++++++++++++++#`,`#++++++++++++++#`,`################`,`################`,`#++++++++++++++#`,`#++++++++++++++#`,`################`],Us=[`oooooooooooooooo`,`o--------------o`,`o--------------o`,`o--------------o`,`o--------------o`,`o--------------o`,`o--------------o`,`o--------------o`,`o--------------o`,`o--------------o`,`o--------------o`,`o--------------o`,`o--------------o`,`o--------------o`,`o--------------o`,`ooo
56ooooooooooooo`],Ws=[`xxxxxxxxxxxxxxxx`,`x--------------x`,`x--------------x`,`x--------------x`,`x--------------x`,`x--------------x`,`x--------------x`,`x--------------x`,`x--------------x`,`x--------------x`,`x--------------x`,`x--------------x`,`x--------------x`,`x--------------x`,`x--------------x`,`xxxxxxxxxxxxxxxx`],Gs=[`rrrrrrrrrrrrrrrr`,`rRRRRRRRRRRRRRRr`,`rR............Rr`,`rR.rrrrrrrrrr.Rr`,`rR.r........r.Rr`,`rR.r.rrrrrr.r.Rr`,`rR.r.r....r.r.Rr`,`rR.r.r.rr.r.r.Rr`,`rR.r.r.rr.r.r.Rr`,`rR.r.r....r.r.Rr`,`rR.r.rrrrrr.r.Rr`,`rR.r........r.Rr`,`rR.rrrrrrrrrr.Rr`,`rR............Rr`,`rRRRRRRRRRRRRRRr`,`rrrrrrrrrrrrrrrr`],Ks=[`................................`,`..############################..`,`.##BBBBBBBBBBBBBBBBBBBBBBBBBB##.`,`##BBBBBBBBBBBBBBBBBBBBBBBBBBBB##`,`##BBbbbbbbBBBBBBBBbbbbbbBBBBBB##`,`##BBbBBBBBbBBBBBBbBBBBBbBBBBBB##`,`##BBBBBBBBBBBBBBBBBBBBBBBBBBBB##`,`##BBBBBBBBBBBBBBBBBBBBBBBBBBBB##`,`##AA########################AA##`,`##AA#SSSSSSSS##SSSSSSSSSSSS#AA##`,`##AA#SSSSSSSs##sSSSSSSSSSSS#AA##`,`##AA#SSSSSSSS##SSSSSSSSSSSS#AA##`,`##AA#SSSSSSSS##SSSSSSSSSSSS#AA##`,`##AA#SSSSSSSs##sSSSSSSSSSSS#AA##`,`##AA#SSSSSSSS##SSSSSSSSSSSS#AA##`,`##AA########################AA##`,`##AAAAAAAAAAAAAAAAAAAAAAAAAAAA##`,`.##AAAAAAAAAAAAAAAAAAAAAAAAAA##.`,`..############################..`,`....##WW##............##WW##....`,`....##WW##............##WW##....`,`....######............######....`,`................................`,`................................`],qs=[`................................`,`................................`,`...##########......#########....`,`..#LLLLLLLLLL#....#LLLLLLLLL#...`,`.#LLooooooooLL#..#LLoooooooLL#..`,`.#LL########LL#..#LL#######LL#..`,`.#LLLLLLLLLLLL#..#LLLLLLLLLLL#..`,`.##############..#############..`,`..#ssssssssss#....#sssssssss#...`,`...##########......#########....`,`................................`,`................................`,`................................`,`................................`,`................................`,`................................`],Js=[`................`,`.##############.`,`.#oooooooooooo#.`,`.#o##########o#.`,`.#o#........#o#.`,`.#o#..gg..g.#o#.`,`.#o#........#o#.`,`.#o##########o#.`,`.#oooooooooooo#.`,`.##############.`,`......####......`,`.....######.....`,`....########....`,`................`,`................`,`................`],Ys=`.##############.,.#oooooooooooo#.,.#o##########o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o#......g.#o#.,.#o#......g.#o#.,.#o#........#o#.,.#o#........#o#.,.#o##########o#.,.#oooooooooooo#.,.#o##########o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o#......g.#o#.,.#o#......g.#o#.,.#o#......g.#o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o#........#o#.,.#o##########o#.,.#oooooooooooo#.,.##############.,.#++++++++++++#.,.##############.`.split(`,`),Xs=[`................`,`......oooo......`,`....oo####oo....`,`...o##rrrr##o...`,`..o#rrggggrr#o..`,`..o#rgg..ggr#o..`,`..o#rrggggrr#o..`,`...o##rrrr##o...`,`....o######o....`,`.....o####o.....`,`......oooo......`,`................`,`................`,`................`,`................`,`................`],Zs=[`................`,`................`,`......oooo......`,`....oo####oo....`,`...o##wwww##o...`,`..o#wwWWWWWw#o..`,`..o#wWW..WWw#o..`,`..o#wwWWWWWw#o..`,`...o##wwww##o...`,`....o######o....`,`.....o####o.....`,`......oooo......`,`................`,`................`,`................`,`................`],Qs=`................................,..############################..,.##HHHHHHHHHHHHHHHHHHHHHHHHHH##.,##HHHHHHHHHHHHHHHHHHHHHHHHHHHH##,##HHHHHHHHHHHHHHHHHHHHHHHHHHHH##,##..ooPPPPPoo....ooPPPPPoo....##,##.oPPPPPPPPo....oPPPPPPPPo...##,##.oPPppPPPpo....oPPppPPPpo...##,##.oPPPPPPPPo....oPPPPPPPPo...##,##..ooPPPPPoo....ooPPPPPoo....##,##............................##,##.BBBBBBBBBBBBBBBBBBBBBBBBBB.##,##.BBBBbbBBBBBBBBBBbbBBBBBBBB.##,##.BBBBBBBBBBBBBBBBBBBBBBBBBB.##,##.BBBBBBBBbbBBBBBBBBBBBBBBBB.##,##.BBBBBBBBBBBBBBBBBBBBBSSSBB.##,##.BBbbBBBBBBBBBBBBbbBBBSSSSB.##,##.BBBBBBBBBBBBBBBBBBBBSSSSSS.##,##.BBBBBBBBbbBBBBBBBB.SSSSSSS.##,##.BBBBBBBBBBBBBBBBBB...SSSS..##,##.BBBBBBBBbbBBBBBBBB.........##,##.BBBBBBBBBBBBBBBBBB.........##,##.##########################.##,##FFFFFFFFFFFFFFFFFFFFFFFFFFFF##,.##FFFFFFFFFFFFFFFFFFFFFFFFFF##.,..############################..,....##WW##..........##WW##......,....######..........######......`.split(`,`),$s=[`................`,`...oooooo.......`,`..o######o......`,`..o#ssss#o......`,`..o#ssoo#o......`,`..o#ssss#o......`,`..o#ssss#o......`,`..o#ssss#oooooo.`,`..o#ssssssssss#o`,`..o#ssssssssss#o`,`..o#ssssoo#ss#o.`,`...o#ssssssss#o.`,`...o########o...`,`....oooooooo....`,`................`,`................`],ec=[`................`,`.....oooooo.....`,`....o######o....`,`....o#rrrr#o....`,`....o#r..r#o....`,`....o#rrrr#o....`,`....o######o....`,`.....oooooo.....`,`......o##o......`,`.....o#..#o.....`,`....o#....#o....`,`...o#......#o...`,`..o#........#o..`,`..o##########o..`,`...oooooooooo...`,`................`],tc=[`........`,`..oooo..`,`.o####o.`,`.o#gg#o.`,`.o#gg#o.`,`.o####o.`,`..oooo..`,`........`],nc=[`.r.r.`,`rrrrr`,`rrrrr`,`.rrr.`,`..r..`],rc=[`.r.r.`,`r...r`,`r...r`,`.r.r.`,`..r..`],ic={"#":X.wall,"+":X.wallHi,o:X.floor,"-":X.floor,x:X.floor2,r:X.rug,R:X.rugHi},ac={"#":X.ink,"+":X.wood,o:X.cream,e:X.ear,c:X.cream,s:X.snout,g:X.gold,r:X.vacuumRed},oc={"#":X.ink,B:`#4a2c28`,b:`#6b423c`,S:`#8a5248`,s:`#6b3a32`,A:`#5c3832`,W:X.wood}
56,sc={"#":X.ink,L:X.ear,o:X.snout,s:X.wood},cc={"#":X.ink,H:X.wood,o:X.ink,P:X.snout,p:X.cream,B:`#b08a68`,b:`#8a6a4e`,S:X.cream,F:X.ear,W:X.wood},lc={"#":X.ink,o:X.vacuumHi,r:X.vacuumRed},uc={"#":`#3a2218`,T:`#d4a05a`,t:`#c48440`,W:`#f6efe4`,p:`#e39280`};function dc(e,t=2){let n=e[0][0].length,r=e[0].length,i=document.createElement(`canvas`);i.width=n*2*t,i.height=r*4*t;let a=i.getContext(`2d`);return a.imageSmoothingEnabled=!1,e.forEach((e,i)=>{let o=i%2,s=Math.floor(i/2);for(let i=0;i<r;i++)for(let c=0;c<n;c++){let l=e[i][c];if(l===`.`||l===` `)continue;let u=uc[l];u&&(a.fillStyle=u,a.fillRect((o*n+c)*t,(s*r+i)*t,t,t))}}),i.toDataURL()}var Q={wall:Z(Hs,ic,2),floorA:Z(Us,ic,2),floorB:Z(Ws,ic,2),rug:Z(Gs,ic,2),couch:Z(Ks,oc,2),shoes:Z(qs,sc,2),tv:Z(Js,ac,2),fridge:Z(Ys,ac,2),trash:Z(Xs,ac,2),bowl:Z(Zs,{...ac,w:X.water,W:X.waterHi},2),bed:Z(Qs,cc,2),sock:Z($s,ac,2),vacuum:Z(ec,lc,2),treat:Z(tc,ac,3),heart:Z(nc,{r:X.vacuumRed},3),heartEmpty:Z(rc,{r:X.vacuumRed},3),dog:dc([Vs.down0,Vs.down1,Vs.left0,Vs.left1,Vs.right0,Vs.right1,Vs.up0,Vs.up1])},fc={step:.45,sniff:.7,chew:.7,bark:.75,soft:.65,crash:.7,vacuum:.35},pc={sniff:`sniff`,chew:`chew`,steal:`chew`,raid:`chew`,claim:`chew`,bark:`bark`,hide:`soft`,nap:`soft`,watch:`soft`,wait:`soft`,drink:`soft`,guard:`soft`,burrow:`soft`,flee:`soft`,believe:`soft`,block:`crash`,scratch:`crash`,tip:`crash`,splash:`crash`,shed:`crash`,bury:`crash`},mc=Object.keys(fc),hc=!1,gc=new Set;function _c(){return hc}function vc(e){return gc.add(e),()=>gc.delete(e)}function yc(e){hc=!hc,e.volume(+!hc);for(let e of gc)e()}function bc(e){for(let t of mc)e.loadSound(t,`/sfx/${t}.ogg`)}function xc(e,t){hc||e.play(t,{volume:fc[t]})}function Sc(e,t){xc(e,pc[t]??`soft`)}var Cc=200,wc=220;function Tc(e){let t=e.add([e.pos(0,0),e.fixed(),e.z(Cc)]);t.add([e.rect(e.width(),48),e.color(20,16,12),e.pos(0,0),e.opacity(.94)]),t.add([e.rect(e.width(),2),e.color(212,160,23),e.pos(0,46)]);let n=t.add([e.text(`CHAOS 12`,{size:10,font:`monospace`}),e.color(196,92,74),e.pos(12,8)]);t.add([e.rect(88,8),e.color(60,32,28),e.pos(90,10),e.anchor(`left`)]);let r=t.add([e.rect(88,8),e.scale(1,1),e.color(196,92,74),e.pos(90,10),e.anchor(`left`)]),i=t.add([e.text(`TREATS 0`,{size:10,font:`monospace`}),e.color(212,160,23),e.pos(200,8)]),a=t.add([e.text(`GOOD BOY 28`,{size:10,font:`monospace`}),e.color(106,158,109),e.pos(300,8)]);t.add([e.rect(88,8),e.color(28,44,30),e.pos(410,10),e.anchor(`left`)]);let o=t.add([e.rect(88,8),e.scale(1,1),e.color(106,158,109),e.pos(410,10),e.anchor(`left`)]),s=t.add([e.text(``,{size:10,font:`monospace`}),e.color(244,234,212),e.pos(12,28)]),c=Array.from({length:5},(n,r)=>t.add([e.sprite(`heart`),e.pos(520+r*22,26),e.anchor(`center`)])),l=Array.from({length:5},(n,r)=>t.add([e.sprite(`heartEmpty`),e.pos(520+r*22,26),e.anchor(`center`)]));return{setRoom(e){s.text=e.toUpperCase()},refresh(){let t=fs();n.text=`CHAOS ${t.chaos}`,r.scale=e.vec2(Math.max(.02,t.chaos/100),1),i.text=`TREATS ${t.treats}/25`;let s=ps(t.goodBoy);a.text=`GOOD BOY ${t.goodBoy}  LV.${s}`,o.scale=e.vec2(Math.max(.02,t.goodBoy/100),1);let u=vs(),d=_s();for(let e=0;e<5;e++)c[e].hidden=!u||e>=d,l[e].hidden=!u||e<d}}}function Ec(e){let t=`off`,n=``,r=0,i=!1,a=null,o=[],s=0,c=``,l=e.add([e.rect(616,118),e.outline(3,e.rgb(244,234,212)),e.color(16,12,10),e.pos(12,350),e.fixed(),e.z(wc)]),u=e.add([e.text(``,{size:14,font:`monospace`}),e.color(212,160,23),e.pos(28,362),e.fixed(),e.z(221)]),d=e.add([e.text(``,{size:14,font:`monospace`,width:580,lineSpacing:6}),e.color(244,234,212),e.pos(28,384),e.fixed(),e.z(221)]),f=e.add([e.text(`SPACE`,{size:10,font:`monospace`}),e.color(140,120,96),e.pos(600,450),e.anchor(`right`),e.fixed(),e.z(221)]);p();function p(){t=`off`,l.hidden=!0,u.hidden=!0,d.hidden=!0,f.hidden=!0}function m(){l.hidden=!1,u.hidden=!1,d.hidden=!1,f.hidden=!1}function h(){u.text=c,d.text=o.map((e,t)=>`${t===s?`>`:` `} ${e.label}`).join(`
57`),f.text=`UP/DOWN  SPACE`}return e.onUpdate(()=>{t===`text`&&r<n.length&&(r=Math.min(n.length,r+60*e.dt()),d.text=n.slice(0,Math.floor(r)))}),e.onKeyPress(`up`,()=>{t===`menu`&&o.length!==0&&(s=(s-1+o.length)%o.length,h())}),e.onKeyPress(`down`,()=>{t===`menu`&&o.length!==0&&(s=(s+1)%o.length,h())}),e.onKeyPress(`w`,()=>{t===`menu`&&o.length!==0&&(s=(s-1+o.length)%o.length,h())}),e.onKeyPress(`s`,()=>{t===`menu`&&o.length!==0&&(s=(s+1)%o.length,h())}),e.onKeyPress(`escape`,()=>{t===`menu`&&(p(),i=!1)}),{get isOpen(){return t!==`off`},get isMenu(){return t===`menu`},get isBusy(){return i},openMenu(e,n){o=n,s=0,c=e.toUpperCase(),t=`menu`,i=!0,h(),m()}
57,confirmMenu(){if(t!==`menu`)return null;let e=o[s]??null;return p(),i=!1,e},async play(e,o){i=!0,a=o??null,u.text=e.speaker,n=e.text,r=0,d.text=``,f.text=`SPACE`,t=`text`,m()},advance(){return t===`text`?r<n.length?(r=n.length,d.text=n,!0):(p(),i=!1,a?.(),a=null,!0):!1}}}function Dc(e){let t=e.add([e.text(``,{size:10,font:`monospace`}),e.color(244,234,212),e.pos(0,0),e.anchor(`center`),e.z(Cc)]);return t.hidden=!0,{showAt(e,n){t.hidden=!1,t.text=`SPACE · ${n.toUpperCase()}`,t.pos=e.pos.add(0,-28)},hide(){t.hidden=!0}}}var Oc=`SOUND ON`,kc=`SOUND OFF`,Ac=!1;function jc(e){if(Ac)return;Ac=!0;let t=e.rgb(180,160,130),n=e.rgb(110,96,80),r=e.rgb(244,234,212),i=e.add([e.text(Oc,{size:10,font:`monospace`}),e.pos(e.width()-12,10),e.anchor(`topright`),e.color(t),e.area(),e.fixed(),e.stay(),e.z(400)]);function a(e){i.text=_c()?kc:Oc,i.color=e?r:_c()?n:t}let o=!1;i.onHover(()=>{o=!0,a(!0)}),i.onHoverEnd(()=>{o=!1,a(!1)}),i.onClick(()=>yc(e)),vc(()=>a(o))}var Mc=110,Nc=42,Pc=64,Fc=.28,$=cs({width:640,height:480,letterbox:!0,background:[18,14,12],global:!1,texFilter:`nearest`,buttons:{interact:{keyboard:[`space`,`e`,`z`,`enter`]}}});$.setGravity(0),$.loadSprite(`wall`,Q.wall),$.loadSprite(`floorA`,Q.floorA),$.loadSprite(`floorB`,Q.floorB),$.loadSprite(`rug`,Q.rug),$.loadSprite(`couch`,Q.couch),$.loadSprite(`shoes`,Q.shoes),$.loadSprite(`tv`,Q.tv),$.loadSprite(`fridge`,Q.fridge),$.loadSprite(`trash`,Q.trash),$.loadSprite(`bowl`,Q.bowl),$.loadSprite(`bed`,Q.bed),$.loadSprite(`sock`,Q.sock),$.loadSprite(`vacuum`,Q.vacuum),$.loadSprite(`treat`,Q.treat),$.loadSprite(`heart`,Q.heart),$.loadSprite(`heartEmpty`,Q.heartEmpty),bc($),$.loadSprite(`dog`,Q.dog,{sliceX:2,sliceY:4,anims:{"walk-down":{from:0,to:1,speed:8,loop:!0},"walk-left":{from:2,to:3,speed:8,loop:!0},"walk-right":{from:4,to:5,speed:8,loop:!0},"walk-up":{from:6,to:7,speed:8,loop:!0}}});var Ic={down:0,left:2,right:4,up:6};$.scene(`title`,()=>{$.add([$.rect($.width(),$.height()),$.color(12,10,8)]),$.add([$.text(`THE VACUUM APPROACHES`,{size:28,font:`monospace`}),$.color(244,234,212),$.anchor(`center`),$.pos($.center().x,130)]),$.add([$.text(`you live here. it does not.`,{size:14,font:`monospace`}),$.color(196,92,74),$.anchor(`center`),$.pos($.center().x,168)]),$.add([$.sprite(`dog`),$.anchor(`center`),$.pos($.center().x-80,258),$.scale(2)]),$.add([$.sprite(`vacuum`),$.anchor(`center`),$.pos($.center().x+80,268),$.scale(3)]),$.add([$.text(`ARROWS / WASD  walk
58SPACE  interact  ·  UP/DOWN  pick a verb
59CHAOS 50+  the vacuum hunts  ·  five hearts
60M  sound on/off  ·  ENTER to go inside`,{size:14,font:`monospace`,align:`center`,lineSpacing:6}),$.color(180,160,130),$.anchor(`center`),$.pos($.center().x,390)]),$.onButtonPress(`interact`,()=>Lc()),$.onKeyPress(`enter`,()=>Lc())}),$.scene(`ending`,e=>{let t=Ms[e];$.add([$.rect($.width(),$.height()),$.color(12,10,8)]),$.add([$.rect($.width(),4),$.color(...t.accent),$.pos(0,0)]),$.add([$.rect($.width(),4),$.color(...t.accent),$.pos(0,$.height()-4)]),$.add([$.text(t.title,{size:28,font:`monospace`,align:`center`}),$.color(...t.accent),$.anchor(`center`),$.pos($.center().x,110)]),$.add([$.text(t.subtitle,{size:14,font:`monospace`,align:`center`}),$.color(180,160,130),$.anchor(`center`),$.pos($.center().x,150)]),$.add([$.text(t.body,{size:16,font:`monospace`,width:480,lineSpacing:8,align:`center`}),$.color(244,234,212),$.anchor(`center`),$.pos($.center().x,280)]),$.add([$.text(`SPACE / ENTER  ·  credits`,{size:12,font:`monospace`}),$.color(110,96,80),$.anchor(`center`),$.pos($.center().x,430)]);let n=()=>$.go(`credits`);$.onButtonPress(`interact`,n),$.onKeyPress(`enter`,n)}),$.scene(`credits`,()=>{$.add([$.rect($.width(),$.height()),$.color(12,10,8)]),$.add([$.rect($.width(),4),$.color(212,160,23),$.pos(0,0)]),$.add([$.rect($.width(),4),$.color(212,160,23),$.pos(0,$.height()-4)]),$.add([$.text(`THE VACUUM APPROACHES`,{size:22,font:`monospace`,align:`center`}),$.color(244,234,212),$.anchor(`center`),$.pos($.center().x,88)]),$.add([$.text(`Built by Shwetha Adiraj
61for the Weekend Challenge:
62Dog Days Edition`,{size:16,font:`monospace`,align:`center`,lineSpacing:10}),$.color(212,160,23),$.anchor(`center`),$.pos($.center().x,168)]),$.add([$.text(`SOUNDS  ·  CC0`,{size:12,font:`monospace`}),$.color(244,234,212),$.anchor(`center`),$.pos($.center().x,250)]),$.add([$.text(`Kenney  ·  Impact Sounds
63rubberduck  ·  80 CC0 Creature SFX
64Joseph Sardin / BigSoundBank  ·  vacuum`,{size:13,font:`monospace`,align:`center`,lineSpacing:8}),$.color(180,160,130),$.anchor(`center`),$.pos($.center().x,308)]),$.add([$.text(`you live here. it does not.`,{size:14,font:`monospace`}),$.color(180,160,130),$.anchor(`center`),$.pos($.center().x,380)]),$.add([$.text(`SPACE / ENTER  ·  title`,{size:12,font:`monospace`}),$.color(110,96,80),$.anchor(`center`),$.pos($.center().x,430)]);let e=()=>$.go(`title`);$.onButtonPress(`interact`,e),$.onKeyPress(`enter`,e)});function Lc(){hs(),$.go(`house`,{room:`living`,spawn:`default`})}$.scene(`house`,e=>{let t=ks[e.room],n=Tc($),r=Ec($),i=Dc($);n.setRoom(t.title),n.refresh();let a=`down`,o=!1;$.addLevel(t.map,{tileWidth:32,tileHeight:32,pos:$.vec2(0,48),tiles:{"#":()=>[$.sprite(`wall`),$.area(),$.body({isStatic:!0}),$.anchor(`topleft`)],".":e=>[$.sprite((Math.floor(e.x/32)+Math.floor(e.y/32))%2==0?`floorA`:`floorB`),$.anchor(`topleft`)],n:()=>s(`n`),e:()=>s(`e`),s:()=>s(`s`),w:()=>s(`w`)}});function s(e){return[$.sprite(`floorA`),$.area(),$.anchor(`topleft`),`door`,{dir:e}]}for(let e of t.furniture){let{x:t,y:n}=js(e.tx,e.ty);$.add([$.sprite(e.sprite),$.pos(t,n),$.anchor(`center`),$.area(),$.body({isStatic:!0}),$.z(n),`interact`,{objectId:e.id,objectName:e.name}])}let c=null;if(t.vacuum){let{x:e,y:n}=js(t.vacuum.tx,t.vacuum.ty),i=1;c=$.add([$.sprite(`vacuum`),$.pos(e,n),$.anchor(`center`),$.area(),$.z(n),`interact`,`beast`,{objectId:`vacuum`,objectName:`The Beast`}]);let a=t.vacuum.minX,o=t.vacuum.maxX;c.onUpdate(()=>{if(r.isOpen)return;let e=vs()?95:40;c.pos.x+=i*e*$.dt(),(c.pos.x<a||c.pos.x>
64o)&&(i*=-1),c.z=c.pos.y})}let l=t.spawns[e.spawn]??t.spawns.default,u=js(l.tx,l.ty),d=$.add([$.sprite(`dog`,{anim:`walk-down`}),$.pos(u.x,u.y),$.anchor(`center`),$.area({scale:.42}),$.body(),$.opacity(1),$.z(u.y),`player`]);d.stop(),d.frame=Ic.down;let f=0,p=!1,m=Fc,h=!1;d.onCollide(`beast`,()=>{if(r.isOpen||o||!vs()||$.time()<f)return;f=$.time()+1.2;let e=ys();if(n.refresh(),c){let e=d.pos.sub(c.pos).unit().scale(80);d.pos=d.pos.add(e)}e===`dead`&&$.go(`ending`,`vacuumDeath`)}),d.onCollide(`door`,e=>{if(o||r.isOpen)return;let n=e.dir,i=As(t.id,n);i&&(o=!0,$.go(`house`,i))}),$.onUpdate(()=>{if(n.refresh(),d.z=d.pos.y,$.time()<f?d.opacity=Math.floor($.time()*12)%2==0?.35:1:d.opacity=1,c){let e=d.pos.dist(c.pos)<Pc;e&&!h&&xc($,`vacuum`),h=e}if(r.isOpen){i.hide(),p=!1,m=Fc;return}let e=$.vec2(0,0);($.isKeyDown(`left`)||$.isKeyDown(`a`))&&--e.x,($.isKeyDown(`right`)||$.isKeyDown(`d`))&&(e.x+=1),($.isKeyDown(`up`)||$.isKeyDown(`w`))&&--e.y,($.isKeyDown(`down`)||$.isKeyDown(`s`))&&(e.y+=1);let t=e.x!==0||e.y!==0;if(t){let t=e.unit().scale(Mc);d.move(t.x,t.y),a=Math.abs(e.x)>Math.abs(e.y)?e.x<0?`left`:`right`:e.y<0?`up`:`down`;let n=`walk-${a}`;d.getCurAnim()?.name!==n&&d.play(n),p?(m+=$.dt(),m>=Fc&&(m-=Fc,xc($,`step`))):(xc($,`step`),m=0)}else d.stop(),d.frame=Ic[a],m=Fc;p=t;let o=g(d);o?i.showAt(o,o.objectName):i.hide()}),$.onButtonPress(`interact`,()=>{if(r.isMenu){let e=r.confirmMenu(),t=g(d);if(!e||!t)return;let i=fs(),a=Ts({objectId:t.objectId,objectName:t.objectName,actionId:e.id,actionLabel:e.label},e);Sc($,e.id),n.refresh();let o=Ns(i,fs());r.play(a,()=>{o&&$.go(`ending`,o)});return}if(r.advance()){n.refresh();return}let e=g(d);!e||r.isBusy||r.openMenu(e.objectName,Os(e.objectId))});function g(e){let t=null,n=Nc;for(let r of $.get(`interact`)){let i=e.pos.dist(r.pos);i<n&&(n=i,t=r)}return t}}),$.onKeyPress(`m`,()=>yc($)),$.onLoad(()=>{jc($),$.go(`title`)});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.