diff --git a/docs/agent-specs/2026-06-14-WG1-scale20-短板量化报告.md b/docs/agent-specs/2026-06-14-WG1-scale20-短板量化报告.md index d6f1acf8..48f94f88 100644 --- a/docs/agent-specs/2026-06-14-WG1-scale20-短板量化报告.md +++ b/docs/agent-specs/2026-06-14-WG1-scale20-短板量化报告.md @@ -79,6 +79,8 @@ **压测批结论**:6 款里 **0 个是"便宜模型造不出"**——match3 真可玩;3 款键盘款挂在**同一处宿主缺键盘桥**;multiball/愤怒小鸟挂在 harness driver 覆盖。**spec 预判的 CCD/match-finding/手势/文本 HUD 缺口全部未成立**(详 §八)。 +> **★ host 修复已验证(`fix/host-keyboard-bridge` 分支 · commit d754b71 · 2026-06-14,经创始人授权隔离执行)**:补宿主键盘桥 + 重打包 3 款重跑九门——**键盘输入全部接通**:**tetris 整盘翻绿**(piecesLocked 0→10 + latch✓,修前 0→1 是重力假性)、t2048 **score 0→4 真合并**(修前 0→0)、asteroids **F_wiring 0→27 + latch✓**(船真动真开火,修前全冻 0)。残留:t2048 latch(2048 盲态几乎不死锁)、asteroids score(盲射没瞄准)= driver-coverage 跟进,**非键盘非模型**。→ host 键盘桥根因**坐实**,供 L0 cherry-pick `d754b71` 到 dev/2.0.0。 + --- ## 七、三方对照:确定性门 vs M3 便宜 player vs Opus 教师审计(核心实证) diff --git a/game-runtime/games/_wg1-gen/asteroids/bundle.iife.js b/game-runtime/games/_wg1-gen/asteroids/bundle.iife.js index 78b893f3..09c7cc44 100644 --- a/game-runtime/games/_wg1-gen/asteroids/bundle.iife.js +++ b/game-runtime/games/_wg1-gen/asteroids/bundle.iife.js @@ -1,34 +1,34 @@ -"use strict";var __GameBundle=(()=>{var zi=Object.defineProperty;var kc=Object.getOwnPropertyDescriptor;var Gc=Object.getOwnPropertyNames;var Fc=Object.prototype.hasOwnProperty;var jc=(n,t,e)=>()=>{if(e)throw e[0];try{return n&&(t=n(n=0)),t}catch(s){throw e=[s],s}};var Hr=(n,t)=>{for(var e in t)zi(n,e,{get:t[e],enumerable:!0})},Bc=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Gc(t))!Fc.call(n,i)&&i!==e&&zi(n,i,{get:()=>t[i],enumerable:!(s=kc(t,i))||s.enumerable});return n};var Nc=n=>Bc(zi({},"__esModule",{value:!0}),n);var Ic={};Hr(Ic,{ASSERT:()=>f,BLACK:()=>it,BLUE:()=>Za,Box2dDistanceJoint:()=>Ti,Box2dFrictionJoint:()=>$o,Box2dGearJoint:()=>qo,Box2dJoint:()=>Ht,Box2dKinematicObject:()=>No,Box2dMotorJoint:()=>Qo,Box2dObject:()=>_s,Box2dPinJoint:()=>Uo,Box2dPlugin:()=>Ai,Box2dPrismaticJoint:()=>Ho,Box2dPulleyJoint:()=>Ko,Box2dRaycastResult:()=>wi,Box2dRevoluteJoint:()=>Wo,Box2dRopeJoint:()=>Vo,Box2dStaticObject:()=>Si,Box2dTargetJoint:()=>Jo,Box2dTileLayer:()=>zo,Box2dWeldJoint:()=>Yo,Box2dWheelJoint:()=>Xo,CLEAR_BLACK:()=>pe,CLEAR_WHITE:()=>rn,CYAN:()=>ql,CanvasLayer:()=>ui,Color:()=>wt,Ease:()=>Ci,EngineObject:()=>Je,GRAY:()=>Vl,GREEN:()=>Qa,ImageFont:()=>ii,LOG:()=>xt,Light:()=>Oo,LightSystemPlugin:()=>Lo,MAGENTA:()=>Hl,Medal:()=>xi,NewgroundsMedal:()=>_o,NewgroundsPlugin:()=>Ro,ORANGE:()=>Wl,PI:()=>X,PURPLE:()=>tc,Particle:()=>hi,ParticleEmitter:()=>vo,PathFinder:()=>Zo,PathFinderNode:()=>_i,PostProcessPlugin:()=>Po,RED:()=>rr,RandomGenerator:()=>go,Sound:()=>bs,SoundInstance:()=>ci,TextureInfo:()=>Ue,TileCollisionLayer:()=>vs,TileInfo:()=>Re,TileLayer:()=>xs,TileLayerData:()=>wn,Timer:()=>Ee,Tween:()=>Ei,UIButton:()=>Cs,UICheckbox:()=>Go,UILayout:()=>Bo,UIObject:()=>re,UISlider:()=>Fo,UISystemPlugin:()=>Io,UIText:()=>vi,UITextInput:()=>Mo,UITile:()=>ko,UIVideo:()=>jo,Vector2:()=>ot,WHITE:()=>W,YELLOW:()=>Ka,ZzFXMusic:()=>Do,abs:()=>nt,atan2:()=>sr,audioContext:()=>ft,audioDefaultSampleRate:()=>Qn,audioIsRunning:()=>ms,audioMasterGain:()=>ze,box2d:()=>m,box2dDebug:()=>qr,box2dInit:()=>ad,box2dSetDebug:()=>rd,cameraAngle:()=>Q,cameraFit:()=>rh,cameraPos:()=>_t,cameraScale:()=>H,canvasClearColor:()=>tn,canvasColorTiles:()=>Pi,canvasFixedSize:()=>Gn,canvasMaxAspect:()=>kn,canvasMaxSize:()=>Mn,canvasMinAspect:()=>os,canvasPixelRatio:()=>en,canvasPixelated:()=>lr,ceil:()=>us,clamp:()=>N,combineCanvases:()=>wr,cos:()=>ct,debug:()=>Ft,debugCircle:()=>Jt,debugClear:()=>Ml,debugLine:()=>we,debugOverlap:()=>fo,debugOverlay:()=>Ie,debugPoint:()=>nr,debugPointSize:()=>ka,debugPoly:()=>Il,debugRect:()=>bt,debugScreenshot:()=>Fa,debugShowErrors:()=>kl,debugText:()=>In,debugVideoCaptureIsActive:()=>Te,debugVideoCaptureStart:()=>ja,debugVideoCaptureStop:()=>Ba,debugWatermark:()=>Ri,distanceAngle:()=>zl,distanceWrap:()=>ir,drawCanvas2D:()=>Rn,drawCircle:()=>si,drawCircleGradient:()=>sh,drawContext:()=>Et,drawCount:()=>Ce,drawCrescent:()=>ud,drawEllipse:()=>ic,drawEllipseGradient:()=>oc,drawLine:()=>mn,drawLineList:()=>mo,drawNineSlice:()=>_c,drawNineSliceScreen:()=>cd,drawPoly:()=>Un,drawRect:()=>ni,drawRectGradient:()=>th,drawRegularPoly:()=>sc,drawText:()=>ih,drawTextScreen:()=>nn,drawTextureWrapped:()=>eh,drawThreeSlice:()=>Rc,drawThreeSliceScreen:()=>ld,drawTile:()=>It,enablePhysicsSolver:()=>Ii,engineAddPlugin:()=>Cn,engineImageFont:()=>lc,engineInit:()=>Pl,engineName:()=>Hs,engineObjects:()=>vt,engineObjectsCallback:()=>Ol,engineObjectsCollect:()=>Ma,engineObjectsCollide:()=>er,engineObjectsDestroy:()=>Ll,engineObjectsRaycast:()=>Dl,engineObjectsUpdate:()=>Ia,engineVersion:()=>Xs,fetchJSON:()=>Xl,floor:()=>St,fontDefault:()=>Rs,formatTime:()=>ar,frame:()=>Oa,frameRate:()=>Cl,gamepadConnected:()=>xo,gamepadDirectionEmulateStick:()=>yr,gamepadDpad:()=>bo,gamepadIsDown:()=>De,gamepadPrimary:()=>mt,gamepadStick:()=>gs,gamepadStickCount:()=>uc,gamepadVibrate:()=>Sh,gamepadVibrateStop:()=>wh,gamepadWasPressed:()=>Rr,gamepadWasReleased:()=>vh,gamepadsEnable:()=>Mi,getCameraSize:()=>ac,getCrescentPoints:()=>Pc,getNoteFrequency:()=>gc,getPaused:()=>_l,glAntialias:()=>Mr,glCanvas:()=>et,glCircleSides:()=>Ps,glClearCanvas:()=>vc,glClearRect:()=>Ec,glCompileShader:()=>Co,glContext:()=>g,glCopyToContext:()=>Br,glCreateProgram:()=>Xn,glCreateTexture:()=>ji,glDeleteTexture:()=>wc,glDraw:()=>Ts,glDrawColoredPoints:()=>Jr,glDrawOutlineTransform:()=>zr,glDrawPoints:()=>Ac,glDrawPointsTransform:()=>Nr,glDrawUntextured:()=>Tc,glEnable:()=>G,glFlush:()=>Rt,glSetAntialias:()=>Yh,glSetRenderTarget:()=>is,glSetTexture:()=>Fr,glSetTextureData:()=>jr,glSetTextureWrap:()=>Sc,gravity:()=>Ut,headlessMode:()=>z,hsl:()=>ke,hypot:()=>Na,inputClear:()=>ks,inputClearKey:()=>Cr,inputMouseMoveThreshold:()=>Er,inputPreventDefault:()=>Fn,inputWASDEmulateDirection:()=>rs,isArray:()=>de,isColor:()=>U,isFullscreen:()=>cc,isIntersecting:()=>Va,isNumber:()=>L,isOnScreen:()=>ah,isOverlapping:()=>Qs,isPowerOfTwo:()=>hs,isStringLike:()=>V,isTouchDevice:()=>ie,isUsingGamepad:()=>Bn,isVector2:()=>O,keyDirection:()=>bh,keyIsDown:()=>Dt,keyWasPressed:()=>kt,keyWasReleased:()=>_r,lastInputDevice:()=>Qe,lerp:()=>Vt,lerpAngle:()=>Jl,lerpWrap:()=>Ua,lightSystem:()=>q,lineTest:()=>qa,log2:()=>za,mainCanvas:()=>B,mainCanvasSize:()=>I,mainContext:()=>ut,max:()=>K,medalDisplaySize:()=>mi,medalDisplaySlideTime:()=>jn,medalDisplayTime:()=>yi,medals:()=>As,medalsForEach:()=>Bi,medalsInit:()=>Zh,medalsPreventUnlock:()=>Ur,medalsReset:()=>td,min:()=>tt,mod:()=>se,mouseDelta:()=>Tr,mouseDeltaScreen:()=>xe,mouseInWindow:()=>oi,mouseIsDown:()=>cs,mousePos:()=>Oe,mousePosScreen:()=>zt,mouseWasPressed:()=>ps,mouseWasReleased:()=>xh,mouseWheel:()=>Ar,nearestPowerOfTwo:()=>Ul,newgrounds:()=>Es,noise1D:()=>Zl,noise2D:()=>tu,objectDefaultAngleDamping:()=>fr,objectDefaultDamping:()=>dr,objectDefaultFriction:()=>gr,objectDefaultMass:()=>hr,objectDefaultRestitution:()=>pr,objectMaxSpeed:()=>Ge,oscillate:()=>Wa,particleEmitRateScale:()=>Zs,paused:()=>Ae,percent:()=>jt,percentLerp:()=>Nl,playSamples:()=>Ir,pointerLockExit:()=>Eh,pointerLockIsActive:()=>hc,pointerLockRequest:()=>Ah,postProcess:()=>Mt,primitiveCount:()=>_e,rand:()=>dt,randBool:()=>Ha,randColor:()=>po,randInCircle:()=>$a,randInt:()=>or,randSign:()=>Xa,randVec2:()=>Ya,readSaveData:()=>Kl,rgb:()=>J,round:()=>$s,saveCanvas:()=>ec,saveDataURL:()=>ds,saveText:()=>Yl,screenToWorld:()=>Is,screenToWorldDelta:()=>rc,screenToWorldTransform:()=>Ms,setAdditiveBlendMode:()=>fs,setCameraAngle:()=>nu,setCameraPos:()=>eu,setCameraScale:()=>su,setCanvasClearColor:()=>ru,setCanvasColorTiles:()=>ou,setCanvasFixedSize:()=>uu,setCanvasMaxAspect:()=>lu,setCanvasMaxSize:()=>au,setCanvasMinAspect:()=>cu,setCanvasPixelRatio:()=>du,setCanvasPixelated:()=>nc,setCursor:()=>hh,setDebugKey:()=>Zu,setDebugWatermark:()=>Qu,setEnablePhysicsSolver:()=>Su,setFontDefault:()=>fu,setGLCircleSides:()=>mu,setGLEnable:()=>yu,setGamepadDirectionEmulateStick:()=>Ou,setGamepadsEnable:()=>Lu,setGravity:()=>Ru,setHeadlessMode:()=>gu,setInputMouseMoveThreshold:()=>ph,setInputPreventDefault:()=>fh,setInputWASDEmulateDirection:()=>Du,setMedalDisplaySize:()=>sd,setMedalDisplaySlideTime:()=>nd,setMedalDisplayTime:()=>ed,setMedalsPreventUnlock:()=>id,setObjectDefaultAngleDamping:()=>Au,setObjectDefaultDamping:()=>Tu,setObjectDefaultFriction:()=>Cu,setObjectDefaultMass:()=>wu,setObjectDefaultRestitution:()=>Eu,setObjectMaxSpeed:()=>_u,setParticleEmitRateScale:()=>Pu,setPaused:()=>Rl,setShowSplashScreen:()=>pu,setSoundDefaultRange:()=>$u,setSoundDefaultTaper:()=>Ku,setSoundEnable:()=>Xu,setSoundVolume:()=>Yu,setTileDefaultBleed:()=>vu,setTileDefaultPadding:()=>xu,setTileDefaultSize:()=>bu,setTilesPixelated:()=>hu,setTimeScale:()=>iu,setTouchGamepadAlpha:()=>Vu,setTouchGamepadAnalog:()=>zu,setTouchGamepadButtonCount:()=>Fu,setTouchGamepadCenterButtonSize:()=>Gu,setTouchGamepadDisplayTime:()=>Wu,setTouchGamepadEnable:()=>Mu,setTouchGamepadFloating:()=>Ju,setTouchGamepadLeftButtonCount:()=>Bu,setTouchGamepadLeftStick:()=>ju,setTouchGamepadPassthrough:()=>ku,setTouchGamepadRightStick:()=>Nu,setTouchGamepadSize:()=>Uu,setTouchGamepadVibration:()=>qu,setTouchInputEnable:()=>Iu,setVibrateEnable:()=>Hu,shareURL:()=>$l,showSplashScreen:()=>ur,sign:()=>ne,sin:()=>st,smoothStep:()=>Ks,soundDefaultRange:()=>xr,soundDefaultTaper:()=>vr,soundEnable:()=>qt,soundVolume:()=>Sn,speak:()=>Nh,speakStop:()=>zh,tan:()=>Ja,textureInfos:()=>cn,tile:()=>Ds,tileCollisionGetData:()=>li,tileCollisionLayers:()=>sn,tileCollisionRaycast:()=>yc,tileCollisionTest:()=>$e,tileDefaultBleed:()=>Di,tileDefaultPadding:()=>Oi,tileDefaultSize:()=>Li,tileLayersLoad:()=>Uh,tilesPixelated:()=>Tn,time:()=>$t,timeDelta:()=>tr,timeReal:()=>on,timeScale:()=>cr,toggleFullscreen:()=>uh,touchGamepadAlpha:()=>br,touchGamepadAnalog:()=>Ls,touchGamepadButtonCount:()=>Yn,touchGamepadCenterButtonSize:()=>fe,touchGamepadDisplayTime:()=>as,touchGamepadEnable:()=>an,touchGamepadFloating:()=>ln,touchGamepadLeftButtonCount:()=>$n,touchGamepadLeftStick:()=>_n,touchGamepadPassthrough:()=>mr,touchGamepadRightStick:()=>Kn,touchGamepadSize:()=>Wt,touchGamepadVibration:()=>ti,touchInputEnable:()=>yn,tweenProperty:()=>hd,tweenStopAll:()=>dd,tweenUpdate:()=>Dc,uiDebug:()=>Wr,uiSetDebug:()=>od,uiSystem:()=>E,usingGamepadInput:()=>mh,usingKeyboardInput:()=>yh,usingMouseInput:()=>gh,vec2:()=>b,vibrate:()=>Pr,vibrateEnable:()=>Os,vibrateStop:()=>Th,workCanvas:()=>Be,workContext:()=>Ke,workReadCanvas:()=>Se,workReadContext:()=>Fe,worldToScreen:()=>Pn,worldToScreenDelta:()=>oh,writeSaveData:()=>Ql,zzfx:()=>Jh,zzfxG:()=>Gi,zzfxM:()=>Cc});function _l(){return Ae}function Rl(n=!0){Ae=n}function Cn(n,t,e,s){f(!bn.find(o=>o.update===n&&o.render===t&&o.glContextLost===e&&o.glContextRestored===s));let i=new uo(n,t,e,s);bn.push(i)}async function Pl(n,t,e,s,i,o=[],a){if(Da&&console.log(`${Hs} Engine v${Xs}`),f(!ut,"engine already initialized"),ut)return;f(de(o),"pass in images as array"),document.body||document.documentElement.appendChild(document.createElement("body")),a||(a=document.body),n||(n=()=>{}),t||(t=()=>{}),e||(e=()=>{}),s||(s=()=>{}),i||(i=()=>{});function r(){I=b(B.width,B.height),ut.imageSmoothingEnabled=!Tn,Eo()}function c(y=0){let x=y-ao;ao||(x=0),ao=y,(Ft||Ri)&&(Ys=Vt(Ys,1e3/(x||1),.05));let v=Ft&&Dt("Equal"),w=Ft&&Dt("Minus"),_=v?10:w?.1:1;on+=x*_/1e3;let S=cr*_;x*=S,be+=Ae?0:x,S<=1&&(be=tt(be,50));let C=!1;if(Ae){C=!0,l(),Ea(),bn.forEach(T=>{var P;return(P=T.update)==null?void 0:P.call(T)});for(let T of vt)T.parent||T.updateTransforms();Sa(),e(),Ca(),Te()&&A()}else{let T=0;for(be<0&&be>-9&&(T=be,be=0);be>=0;be-=1e3/60)$t=Oa++/60,C=!0,l(),Ea(),t(),bn.forEach(P=>{var M;return(M=P.update)==null?void 0:M.call(P)}),Ia(),Sa(),e(),Ca(),Te()&&A();be+=T}Te()||A(),requestAnimationFrame(c);function A(){if(!z){C||l(),r(),s(),vt.sort((T,P)=>T.renderOrder-P.renderOrder);for(let T of vt)T.destroyed||T.render();i(),bn.forEach(T=>{var P;return(P=T.render)==null?void 0:P.call(T)}),_h(),Fl(),Rt(),jl(),Ce=0,_e=0}}}function l(){if(!z){if(Gn.x){I=Gn.copy();let y=innerWidth/innerHeight,x=Gn.x/Gn.y,v=ykn){let C=I.y*kn|0;I.x=tt(C,Mn.x)}else if(w0&&!G&&(ut.fillStyle=tn.toString(),ut.fillRect(0,0,I.x,I.y),ut.fillStyle=it.toString()),ut.lineJoin="round",ut.lineCap="round"}}if(z)return d();qh(a);let u="margin:0;overflow:hidden;background:#000;user-select:none;-webkit-user-select:none;touch-action:none;-webkit-touch-callout:none";a.style.cssText=u,B=a.appendChild(document.createElement("canvas")),Et=ut=B.getContext("2d"),Ch(),Bh(),Gl();let h="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)";B.style.cssText=h,et&&(et.style.cssText=h),nc(lr),l(),Eo(),Be=new OffscreenCanvas(64,64),Ke=Be.getContext("2d"),Se=new OffscreenCanvas(64,64),Fe=Se.getContext("2d",{willReadFrequently:!0});let p=o.map((y,x)=>Ta(x,y));return o.length||p.push(Ta(0)),p.push(dh()),ur&&p.push(new Promise(y=>{let x=0;v();function v(){ks(),Qh(x+=.01),x>1?y():setTimeout(v,16)}})),await Promise.all(p),d();async function d(){await n(),c()}}function Ia(){er=vt.filter(t=>t.collideSolidObjects);function n(t){if(!t.destroyed){t.update();for(let e of t.children)n(e)}}for(let t of vt)if(!(t.parent||t.destroyed)){t.update(),t.updatePhysics();for(let e of t.children)n(e);t.updateTransforms()}vt=vt.filter(t=>!t.destroyed)}function Ll(n=!0){for(let t of vt)t.parent||t.destroy(n);vt=vt.filter(t=>!t.destroyed)}function Ma(n,t,e=vt){let s=[];if(n)if(t instanceof ot)for(let i of e)i.isOverlapping(n,t)&&s.push(i);else{let i=t*t;for(let o of e)n.distanceSquared(o.pos)e(i))}function Dl(n,t,e=vt){let s=[];for(let i of e)i.collideRaycast&&Va(n,t,i.pos,i.size)&&(he&&bt(i.pos,i.size,"#f00"),s.push(i));return he&&we(n,t,s.length?"#f00":"#00f",.02),s}function f(n,...t){if(!n)throw console.assert(n,...t),new Error("Assert failed!")}function xt(...n){console.log(...n)}function bt(n,t=b(),e=W,s=0,i=0,o=!1,a=!1){f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(V(e)||U(e),"color is invalid"),f(L(s),"time must be a number"),f(L(i),"angle must be a number"),U(e)&&(e=e.toString());let r=new Ee(s);Ze.push({pos:n.copy(),size:t.copy(),color:e,timer:r,angle:i,fill:o,screenSpace:a})}function Il(n,t,e=W,s=0,i=0,o=!1,a=!1){f(O(n),"pos must be a vec2"),f(de(t),"points must be an array"),f(V(e)||U(e),"color is invalid"),f(L(s),"time must be a number"),f(L(i),"angle must be a number"),U(e)&&(e=e.toString()),n=n.copy(),t=t.map(c=>c.copy());let r=new Ee(s);Ze.push({pos:n,points:t,color:e,timer:r,angle:i,fill:o,screenSpace:a})}function Jt(n,t=0,e=W,s=0,i=!1,o=!1){f(O(n),"pos must be a vec2"),f(L(t),"size must be a number"),f(V(e)||U(e),"color is invalid"),f(L(s),"time must be a number"),U(e)&&(e=e.toString()),n=n.copy();let a=new Ee(s);Ze.push({pos:n,size:t,color:e,timer:a,angle:0,fill:i,screenSpace:o})}function nr(n,t,e,s,i=!1){bt(n,void 0,t,e,s,!1,i)}function we(n,t,e,s=.1,i=0,o=!1){f(O(n),"posA must be a vec2"),f(O(t),"posB must be a vec2"),f(L(s),"width must be a number");let a=b((t.x-n.x)/2,(t.y-n.y)/2),r=b(s,a.length()*2);bt(n.add(a),r,e,i,a.angle(),!0,o)}function fo(n,t,e,s,i,o,a=!1){f(O(n),"posA must be a vec2"),f(O(e),"posB must be a vec2"),f(O(t),"sizeA must be a vec2"),f(O(s),"sizeB must be a vec2");let r=b(tt(n.x-t.x/2,e.x-s.x/2),tt(n.y-t.y/2,e.y-s.y/2)),c=b(K(n.x+t.x/2,e.x+s.x/2),K(n.y+t.y/2,e.y+s.y/2));bt(r.lerp(c,.5),c.subtract(r),i,o,0,!1,a)}function In(n,t,e=1,s=W,i=0,o=0,a="monospace",r=!1){f(V(n),"text must be a string"),f(O(t),"pos must be a vec2"),f(L(e),"size must be a number"),f(V(s)||U(s),"color is invalid"),f(L(i),"time must be a number"),f(L(o),"angle must be a number"),f(V(a),"font must be a string"),U(s)&&(s=s.toString()),t=t.copy();let c=new Ee(i);Ze.push({text:n,pos:t,size:e,color:s,timer:c,angle:o,font:a,screenSpace:r})}function Ml(){Ze=[]}function Fa(){ho=1}function kl(){let n=e=>{document.body.style="background-color:#111;margin:8px",document.body.innerHTML="
"+e},t=console.assert;console.assert=(e,...s)=>{if(t(e,...s),!e){let i=s.join(" "),o=new Error().stack;throw`Assertion failed!
+"use strict";var __GameBundle=(()=>{var zi=Object.defineProperty;var kc=Object.getOwnPropertyDescriptor;var Gc=Object.getOwnPropertyNames;var Fc=Object.prototype.hasOwnProperty;var jc=(n,t,e)=>()=>{if(e)throw e[0];try{return n&&(t=n(n=0)),t}catch(s){throw e=[s],s}};var Hr=(n,t)=>{for(var e in t)zi(n,e,{get:t[e],enumerable:!0})},Bc=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Gc(t))!Fc.call(n,i)&&i!==e&&zi(n,i,{get:()=>t[i],enumerable:!(s=kc(t,i))||s.enumerable});return n};var Nc=n=>Bc(zi({},"__esModule",{value:!0}),n);var Ic={};Hr(Ic,{ASSERT:()=>f,BLACK:()=>it,BLUE:()=>Za,Box2dDistanceJoint:()=>Ti,Box2dFrictionJoint:()=>$o,Box2dGearJoint:()=>qo,Box2dJoint:()=>Xt,Box2dKinematicObject:()=>No,Box2dMotorJoint:()=>Qo,Box2dObject:()=>_s,Box2dPinJoint:()=>Uo,Box2dPlugin:()=>Ai,Box2dPrismaticJoint:()=>Ho,Box2dPulleyJoint:()=>Ko,Box2dRaycastResult:()=>wi,Box2dRevoluteJoint:()=>Wo,Box2dRopeJoint:()=>Vo,Box2dStaticObject:()=>Si,Box2dTargetJoint:()=>Jo,Box2dTileLayer:()=>zo,Box2dWeldJoint:()=>Yo,Box2dWheelJoint:()=>Xo,CLEAR_BLACK:()=>pe,CLEAR_WHITE:()=>rn,CYAN:()=>ql,CanvasLayer:()=>ui,Color:()=>wt,Ease:()=>Ci,EngineObject:()=>Ue,GRAY:()=>Vl,GREEN:()=>Qa,ImageFont:()=>ii,LOG:()=>xt,Light:()=>Oo,LightSystemPlugin:()=>Lo,MAGENTA:()=>Hl,Medal:()=>xi,NewgroundsMedal:()=>_o,NewgroundsPlugin:()=>Ro,ORANGE:()=>Wl,PI:()=>X,PURPLE:()=>tc,Particle:()=>hi,ParticleEmitter:()=>vo,PathFinder:()=>Zo,PathFinderNode:()=>_i,PostProcessPlugin:()=>Po,RED:()=>rr,RandomGenerator:()=>go,Sound:()=>bs,SoundInstance:()=>ci,TextureInfo:()=>Ve,TileCollisionLayer:()=>vs,TileInfo:()=>Re,TileLayer:()=>xs,TileLayerData:()=>wn,Timer:()=>Ee,Tween:()=>Ei,UIButton:()=>Cs,UICheckbox:()=>Go,UILayout:()=>Bo,UIObject:()=>re,UISlider:()=>Fo,UISystemPlugin:()=>Io,UIText:()=>vi,UITextInput:()=>Mo,UITile:()=>ko,UIVideo:()=>jo,Vector2:()=>rt,WHITE:()=>W,YELLOW:()=>Ka,ZzFXMusic:()=>Do,abs:()=>nt,atan2:()=>sr,audioContext:()=>ft,audioDefaultSampleRate:()=>Qn,audioIsRunning:()=>ms,audioMasterGain:()=>Je,box2d:()=>m,box2dDebug:()=>qr,box2dInit:()=>ad,box2dSetDebug:()=>rd,cameraAngle:()=>Q,cameraFit:()=>rh,cameraPos:()=>_t,cameraScale:()=>H,canvasClearColor:()=>tn,canvasColorTiles:()=>Pi,canvasFixedSize:()=>Gn,canvasMaxAspect:()=>kn,canvasMaxSize:()=>Mn,canvasMinAspect:()=>os,canvasPixelRatio:()=>en,canvasPixelated:()=>lr,ceil:()=>us,clamp:()=>N,combineCanvases:()=>wr,cos:()=>lt,debug:()=>jt,debugCircle:()=>Ut,debugClear:()=>Ml,debugLine:()=>we,debugOverlap:()=>fo,debugOverlay:()=>Me,debugPoint:()=>nr,debugPointSize:()=>ka,debugPoly:()=>Il,debugRect:()=>bt,debugScreenshot:()=>Fa,debugShowErrors:()=>kl,debugText:()=>In,debugVideoCaptureIsActive:()=>Te,debugVideoCaptureStart:()=>ja,debugVideoCaptureStop:()=>Ba,debugWatermark:()=>Ri,distanceAngle:()=>zl,distanceWrap:()=>ir,drawCanvas2D:()=>Rn,drawCircle:()=>si,drawCircleGradient:()=>sh,drawContext:()=>Et,drawCount:()=>Ce,drawCrescent:()=>ud,drawEllipse:()=>ic,drawEllipseGradient:()=>oc,drawLine:()=>mn,drawLineList:()=>mo,drawNineSlice:()=>_c,drawNineSliceScreen:()=>cd,drawPoly:()=>Un,drawRect:()=>ni,drawRectGradient:()=>th,drawRegularPoly:()=>sc,drawText:()=>ih,drawTextScreen:()=>nn,drawTextureWrapped:()=>eh,drawThreeSlice:()=>Rc,drawThreeSliceScreen:()=>ld,drawTile:()=>Mt,enablePhysicsSolver:()=>Ii,engineAddPlugin:()=>Cn,engineImageFont:()=>lc,engineInit:()=>Pl,engineName:()=>Hs,engineObjects:()=>vt,engineObjectsCallback:()=>Ol,engineObjectsCollect:()=>Ma,engineObjectsCollide:()=>er,engineObjectsDestroy:()=>Ll,engineObjectsRaycast:()=>Dl,engineObjectsUpdate:()=>Ia,engineVersion:()=>Xs,fetchJSON:()=>Xl,floor:()=>St,fontDefault:()=>Rs,formatTime:()=>ar,frame:()=>Oa,frameRate:()=>Cl,gamepadConnected:()=>xo,gamepadDirectionEmulateStick:()=>yr,gamepadDpad:()=>bo,gamepadIsDown:()=>Ie,gamepadPrimary:()=>mt,gamepadStick:()=>gs,gamepadStickCount:()=>uc,gamepadVibrate:()=>Sh,gamepadVibrateStop:()=>wh,gamepadWasPressed:()=>Rr,gamepadWasReleased:()=>vh,gamepadsEnable:()=>Mi,getCameraSize:()=>ac,getCrescentPoints:()=>Pc,getNoteFrequency:()=>gc,getPaused:()=>_l,glAntialias:()=>Mr,glCanvas:()=>et,glCircleSides:()=>Ps,glClearCanvas:()=>vc,glClearRect:()=>Ec,glCompileShader:()=>Co,glContext:()=>g,glCopyToContext:()=>Br,glCreateProgram:()=>Xn,glCreateTexture:()=>ji,glDeleteTexture:()=>wc,glDraw:()=>Ts,glDrawColoredPoints:()=>Jr,glDrawOutlineTransform:()=>zr,glDrawPoints:()=>Ac,glDrawPointsTransform:()=>Nr,glDrawUntextured:()=>Tc,glEnable:()=>G,glFlush:()=>Rt,glSetAntialias:()=>Yh,glSetRenderTarget:()=>is,glSetTexture:()=>Fr,glSetTextureData:()=>jr,glSetTextureWrap:()=>Sc,gravity:()=>Vt,headlessMode:()=>z,hsl:()=>Ge,hypot:()=>Na,inputClear:()=>ks,inputClearKey:()=>Cr,inputMouseMoveThreshold:()=>Er,inputPreventDefault:()=>Fn,inputWASDEmulateDirection:()=>rs,isArray:()=>de,isColor:()=>U,isFullscreen:()=>cc,isIntersecting:()=>Va,isNumber:()=>L,isOnScreen:()=>ah,isOverlapping:()=>Qs,isPowerOfTwo:()=>hs,isStringLike:()=>V,isTouchDevice:()=>ie,isUsingGamepad:()=>Bn,isVector2:()=>O,keyDirection:()=>bh,keyIsDown:()=>It,keyWasPressed:()=>Gt,keyWasReleased:()=>_r,lastInputDevice:()=>Qe,lerp:()=>Wt,lerpAngle:()=>Jl,lerpWrap:()=>Ua,lightSystem:()=>q,lineTest:()=>qa,log2:()=>za,mainCanvas:()=>B,mainCanvasSize:()=>I,mainContext:()=>ut,max:()=>K,medalDisplaySize:()=>mi,medalDisplaySlideTime:()=>jn,medalDisplayTime:()=>yi,medals:()=>As,medalsForEach:()=>Bi,medalsInit:()=>Zh,medalsPreventUnlock:()=>Ur,medalsReset:()=>td,min:()=>tt,mod:()=>se,mouseDelta:()=>Tr,mouseDeltaScreen:()=>xe,mouseInWindow:()=>oi,mouseIsDown:()=>cs,mousePos:()=>De,mousePosScreen:()=>Jt,mouseWasPressed:()=>ps,mouseWasReleased:()=>xh,mouseWheel:()=>Ar,nearestPowerOfTwo:()=>Ul,newgrounds:()=>Es,noise1D:()=>Zl,noise2D:()=>tu,objectDefaultAngleDamping:()=>fr,objectDefaultDamping:()=>dr,objectDefaultFriction:()=>gr,objectDefaultMass:()=>hr,objectDefaultRestitution:()=>pr,objectMaxSpeed:()=>Fe,oscillate:()=>Wa,particleEmitRateScale:()=>Zs,paused:()=>Ae,percent:()=>Bt,percentLerp:()=>Nl,playSamples:()=>Ir,pointerLockExit:()=>Eh,pointerLockIsActive:()=>hc,pointerLockRequest:()=>Ah,postProcess:()=>kt,primitiveCount:()=>_e,rand:()=>dt,randBool:()=>Ha,randColor:()=>po,randInCircle:()=>$a,randInt:()=>or,randSign:()=>Xa,randVec2:()=>Ya,readSaveData:()=>Kl,rgb:()=>J,round:()=>$s,saveCanvas:()=>ec,saveDataURL:()=>ds,saveText:()=>Yl,screenToWorld:()=>Is,screenToWorldDelta:()=>rc,screenToWorldTransform:()=>Ms,setAdditiveBlendMode:()=>fs,setCameraAngle:()=>nu,setCameraPos:()=>eu,setCameraScale:()=>su,setCanvasClearColor:()=>ru,setCanvasColorTiles:()=>ou,setCanvasFixedSize:()=>uu,setCanvasMaxAspect:()=>lu,setCanvasMaxSize:()=>au,setCanvasMinAspect:()=>cu,setCanvasPixelRatio:()=>du,setCanvasPixelated:()=>nc,setCursor:()=>hh,setDebugKey:()=>Zu,setDebugWatermark:()=>Qu,setEnablePhysicsSolver:()=>Su,setFontDefault:()=>fu,setGLCircleSides:()=>mu,setGLEnable:()=>yu,setGamepadDirectionEmulateStick:()=>Ou,setGamepadsEnable:()=>Lu,setGravity:()=>Ru,setHeadlessMode:()=>gu,setInputMouseMoveThreshold:()=>ph,setInputPreventDefault:()=>fh,setInputWASDEmulateDirection:()=>Du,setMedalDisplaySize:()=>sd,setMedalDisplaySlideTime:()=>nd,setMedalDisplayTime:()=>ed,setMedalsPreventUnlock:()=>id,setObjectDefaultAngleDamping:()=>Au,setObjectDefaultDamping:()=>Tu,setObjectDefaultFriction:()=>Cu,setObjectDefaultMass:()=>wu,setObjectDefaultRestitution:()=>Eu,setObjectMaxSpeed:()=>_u,setParticleEmitRateScale:()=>Pu,setPaused:()=>Rl,setShowSplashScreen:()=>pu,setSoundDefaultRange:()=>$u,setSoundDefaultTaper:()=>Ku,setSoundEnable:()=>Xu,setSoundVolume:()=>Yu,setTileDefaultBleed:()=>vu,setTileDefaultPadding:()=>xu,setTileDefaultSize:()=>bu,setTilesPixelated:()=>hu,setTimeScale:()=>iu,setTouchGamepadAlpha:()=>Vu,setTouchGamepadAnalog:()=>zu,setTouchGamepadButtonCount:()=>Fu,setTouchGamepadCenterButtonSize:()=>Gu,setTouchGamepadDisplayTime:()=>Wu,setTouchGamepadEnable:()=>Mu,setTouchGamepadFloating:()=>Ju,setTouchGamepadLeftButtonCount:()=>Bu,setTouchGamepadLeftStick:()=>ju,setTouchGamepadPassthrough:()=>ku,setTouchGamepadRightStick:()=>Nu,setTouchGamepadSize:()=>Uu,setTouchGamepadVibration:()=>qu,setTouchInputEnable:()=>Iu,setVibrateEnable:()=>Hu,shareURL:()=>$l,showSplashScreen:()=>ur,sign:()=>ne,sin:()=>st,smoothStep:()=>Ks,soundDefaultRange:()=>xr,soundDefaultTaper:()=>vr,soundEnable:()=>Ht,soundVolume:()=>Sn,speak:()=>Nh,speakStop:()=>zh,tan:()=>Ja,textureInfos:()=>cn,tile:()=>Ds,tileCollisionGetData:()=>li,tileCollisionLayers:()=>sn,tileCollisionRaycast:()=>yc,tileCollisionTest:()=>$e,tileDefaultBleed:()=>Di,tileDefaultPadding:()=>Oi,tileDefaultSize:()=>Li,tileLayersLoad:()=>Uh,tilesPixelated:()=>Tn,time:()=>Kt,timeDelta:()=>tr,timeReal:()=>on,timeScale:()=>cr,toggleFullscreen:()=>uh,touchGamepadAlpha:()=>br,touchGamepadAnalog:()=>Ls,touchGamepadButtonCount:()=>Yn,touchGamepadCenterButtonSize:()=>fe,touchGamepadDisplayTime:()=>as,touchGamepadEnable:()=>an,touchGamepadFloating:()=>ln,touchGamepadLeftButtonCount:()=>$n,touchGamepadLeftStick:()=>_n,touchGamepadPassthrough:()=>mr,touchGamepadRightStick:()=>Kn,touchGamepadSize:()=>qt,touchGamepadVibration:()=>ti,touchInputEnable:()=>yn,tweenProperty:()=>hd,tweenStopAll:()=>dd,tweenUpdate:()=>Dc,uiDebug:()=>Wr,uiSetDebug:()=>od,uiSystem:()=>E,usingGamepadInput:()=>mh,usingKeyboardInput:()=>yh,usingMouseInput:()=>gh,vec2:()=>b,vibrate:()=>Pr,vibrateEnable:()=>Os,vibrateStop:()=>Th,workCanvas:()=>Ne,workContext:()=>Ke,workReadCanvas:()=>Se,workReadContext:()=>je,worldToScreen:()=>Pn,worldToScreenDelta:()=>oh,writeSaveData:()=>Ql,zzfx:()=>Jh,zzfxG:()=>Gi,zzfxM:()=>Cc});function _l(){return Ae}function Rl(n=!0){Ae=n}function Cn(n,t,e,s){f(!bn.find(o=>o.update===n&&o.render===t&&o.glContextLost===e&&o.glContextRestored===s));let i=new uo(n,t,e,s);bn.push(i)}async function Pl(n,t,e,s,i,o=[],a){if(Da&&console.log(`${Hs} Engine v${Xs}`),f(!ut,"engine already initialized"),ut)return;f(de(o),"pass in images as array"),document.body||document.documentElement.appendChild(document.createElement("body")),a||(a=document.body),n||(n=()=>{}),t||(t=()=>{}),e||(e=()=>{}),s||(s=()=>{}),i||(i=()=>{});function r(){I=b(B.width,B.height),ut.imageSmoothingEnabled=!Tn,Eo()}function c(y=0){let x=y-ao;ao||(x=0),ao=y,(jt||Ri)&&(Ys=Wt(Ys,1e3/(x||1),.05));let v=jt&&It("Equal"),w=jt&&It("Minus"),_=v?10:w?.1:1;on+=x*_/1e3;let S=cr*_;x*=S,be+=Ae?0:x,S<=1&&(be=tt(be,50));let C=!1;if(Ae){C=!0,l(),Ea(),bn.forEach(T=>{var P;return(P=T.update)==null?void 0:P.call(T)});for(let T of vt)T.parent||T.updateTransforms();Sa(),e(),Ca(),Te()&&A()}else{let T=0;for(be<0&&be>-9&&(T=be,be=0);be>=0;be-=1e3/60)Kt=Oa++/60,C=!0,l(),Ea(),t(),bn.forEach(P=>{var M;return(M=P.update)==null?void 0:M.call(P)}),Ia(),Sa(),e(),Ca(),Te()&&A();be+=T}Te()||A(),requestAnimationFrame(c);function A(){if(!z){C||l(),r(),s(),vt.sort((T,P)=>T.renderOrder-P.renderOrder);for(let T of vt)T.destroyed||T.render();i(),bn.forEach(T=>{var P;return(P=T.render)==null?void 0:P.call(T)}),_h(),Fl(),Rt(),jl(),Ce=0,_e=0}}}function l(){if(!z){if(Gn.x){I=Gn.copy();let y=innerWidth/innerHeight,x=Gn.x/Gn.y,v=ykn){let C=I.y*kn|0;I.x=tt(C,Mn.x)}else if(w0&&!G&&(ut.fillStyle=tn.toString(),ut.fillRect(0,0,I.x,I.y),ut.fillStyle=it.toString()),ut.lineJoin="round",ut.lineCap="round"}}if(z)return d();qh(a);let u="margin:0;overflow:hidden;background:#000;user-select:none;-webkit-user-select:none;touch-action:none;-webkit-touch-callout:none";a.style.cssText=u,B=a.appendChild(document.createElement("canvas")),Et=ut=B.getContext("2d"),Ch(),Bh(),Gl();let h="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)";B.style.cssText=h,et&&(et.style.cssText=h),nc(lr),l(),Eo(),Ne=new OffscreenCanvas(64,64),Ke=Ne.getContext("2d"),Se=new OffscreenCanvas(64,64),je=Se.getContext("2d",{willReadFrequently:!0});let p=o.map((y,x)=>Ta(x,y));return o.length||p.push(Ta(0)),p.push(dh()),ur&&p.push(new Promise(y=>{let x=0;v();function v(){ks(),Qh(x+=.01),x>1?y():setTimeout(v,16)}})),await Promise.all(p),d();async function d(){await n(),c()}}function Ia(){er=vt.filter(t=>t.collideSolidObjects);function n(t){if(!t.destroyed){t.update();for(let e of t.children)n(e)}}for(let t of vt)if(!(t.parent||t.destroyed)){t.update(),t.updatePhysics();for(let e of t.children)n(e);t.updateTransforms()}vt=vt.filter(t=>!t.destroyed)}function Ll(n=!0){for(let t of vt)t.parent||t.destroy(n);vt=vt.filter(t=>!t.destroyed)}function Ma(n,t,e=vt){let s=[];if(n)if(t instanceof rt)for(let i of e)i.isOverlapping(n,t)&&s.push(i);else{let i=t*t;for(let o of e)n.distanceSquared(o.pos)e(i))}function Dl(n,t,e=vt){let s=[];for(let i of e)i.collideRaycast&&Va(n,t,i.pos,i.size)&&(he&&bt(i.pos,i.size,"#f00"),s.push(i));return he&&we(n,t,s.length?"#f00":"#00f",.02),s}function f(n,...t){if(!n)throw console.assert(n,...t),new Error("Assert failed!")}function xt(...n){console.log(...n)}function bt(n,t=b(),e=W,s=0,i=0,o=!1,a=!1){f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(V(e)||U(e),"color is invalid"),f(L(s),"time must be a number"),f(L(i),"angle must be a number"),U(e)&&(e=e.toString());let r=new Ee(s);Ze.push({pos:n.copy(),size:t.copy(),color:e,timer:r,angle:i,fill:o,screenSpace:a})}function Il(n,t,e=W,s=0,i=0,o=!1,a=!1){f(O(n),"pos must be a vec2"),f(de(t),"points must be an array"),f(V(e)||U(e),"color is invalid"),f(L(s),"time must be a number"),f(L(i),"angle must be a number"),U(e)&&(e=e.toString()),n=n.copy(),t=t.map(c=>c.copy());let r=new Ee(s);Ze.push({pos:n,points:t,color:e,timer:r,angle:i,fill:o,screenSpace:a})}function Ut(n,t=0,e=W,s=0,i=!1,o=!1){f(O(n),"pos must be a vec2"),f(L(t),"size must be a number"),f(V(e)||U(e),"color is invalid"),f(L(s),"time must be a number"),U(e)&&(e=e.toString()),n=n.copy();let a=new Ee(s);Ze.push({pos:n,size:t,color:e,timer:a,angle:0,fill:i,screenSpace:o})}function nr(n,t,e,s,i=!1){bt(n,void 0,t,e,s,!1,i)}function we(n,t,e,s=.1,i=0,o=!1){f(O(n),"posA must be a vec2"),f(O(t),"posB must be a vec2"),f(L(s),"width must be a number");let a=b((t.x-n.x)/2,(t.y-n.y)/2),r=b(s,a.length()*2);bt(n.add(a),r,e,i,a.angle(),!0,o)}function fo(n,t,e,s,i,o,a=!1){f(O(n),"posA must be a vec2"),f(O(e),"posB must be a vec2"),f(O(t),"sizeA must be a vec2"),f(O(s),"sizeB must be a vec2");let r=b(tt(n.x-t.x/2,e.x-s.x/2),tt(n.y-t.y/2,e.y-s.y/2)),c=b(K(n.x+t.x/2,e.x+s.x/2),K(n.y+t.y/2,e.y+s.y/2));bt(r.lerp(c,.5),c.subtract(r),i,o,0,!1,a)}function In(n,t,e=1,s=W,i=0,o=0,a="monospace",r=!1){f(V(n),"text must be a string"),f(O(t),"pos must be a vec2"),f(L(e),"size must be a number"),f(V(s)||U(s),"color is invalid"),f(L(i),"time must be a number"),f(L(o),"angle must be a number"),f(V(a),"font must be a string"),U(s)&&(s=s.toString()),t=t.copy();let c=new Ee(i);Ze.push({text:n,pos:t,size:e,color:s,timer:c,angle:o,font:a,screenSpace:r})}function Ml(){Ze=[]}function Fa(){ho=1}function kl(){let n=e=>{document.body.style="background-color:#111;margin:8px",document.body.innerHTML="
"+e},t=console.assert;console.assert=(e,...s)=>{if(t(e,...s),!e){let i=s.join(" "),o=new Error().stack;throw`Assertion failed!
 `+i+`
 `+o}},onunhandledrejection=e=>n(e.reason.stack||e.reason),onerror=(e,s,i,o)=>n(`${e}
 ${s}
-Ln ${i}, Col ${o}`)}function Gl(){Da&&console.warn("LittleJS DEBUG build loaded. Use the release build for production.")}function Sa(){Ft&&(kt(Ga)&&(Ie=!Ie),Ie&&(kt("Digit1")&&(ue=!ue,xn=!1),kt("Digit2")&&(xn=!xn,ue=!1),kt("Digit3")&&(vn=!vn),kt("Digit4")&&(he=!he),kt("Digit5")&&Fa(),kt("Digit7")&&(Jn=!Jn)),Te()?(!Ie||kt("Digit6"))&&Ba():Ie&&kt("Digit6")&&ja())}function Fl(){if(Te())return;Rt();let n=Ce,t=_e;ho&&(wr(),ec(B),ho=0);let e=ut;if(vn&&Mi){let o=0;for(let a=0;a<8;a++)xo(a)&&o++;for(let a=0;a<8;a++){if(!xo(a))continue;let r=1,c=.2,l=_t.add(b(-r*2,((o-1)/2-a)*r*3));In(a,l.add(b(-r,r)),1),a===mt&&In("Main",l.add(b(-r*2,0)),1,"#0f0");let u=ve[a].length;for(let p=0;p{e.save();let o=i.pos,a=1,r=i.angle;if(i.screenSpace||(o=Pn(i.pos),a=H,r-=Q),e.translate(o.x|0,o.y|0),e.rotate(r),e.scale(1,i.text?1:-1),e.fillStyle=i.color,e.strokeStyle=i.color,i.text!==void 0)e.font=i.size*a+"px "+i.font,e.textAlign="center",e.textBaseline="middle",e.fillText(i.text,0,0);else if(i.points!==void 0){e.beginPath();for(let c of i.points){let l=c.scale(a).floor();e.lineTo(l.x,l.y)}e.closePath(),i.fill&&e.fill(),e.stroke()}else if(i.size===0||i.size.x===0&&i.size.y===0){let c=ka*a;e.fillRect(-c/2,-1,c,3),e.fillRect(-1,-c/2,3,c)}else if(i.size.x!==void 0){let c=i.size.scale(a).floor(),l=c.x,u=c.y;i.fill&&e.fillRect(-l/2|0,-u/2|0,l,u),e.strokeRect(-l/2|0,-u/2|0,l,u)}else e.beginPath(),e.arc(0,0,i.size*a/2,0,9),i.fill&&e.fill(),e.stroke();e.restore()}),Ze=Ze.filter(i=>i.timer<0),s){let i=yc(s.pos,Oe);i&&ni(i.floor().add(b(.5)),b(1),J(0,1,1,.3),0,!1),mn(Oe,s.pos,.1,i?J(1,0,0,.5):J(0,1,0,.5),void 0,void 0,!1);let o="mouse pos = "+Oe;sn.length&&(o+=`
-mouse collision = `+li(Oe)),o+=`
+Ln ${i}, Col ${o}`)}function Gl(){Da&&console.warn("LittleJS DEBUG build loaded. Use the release build for production.")}function Sa(){jt&&(Gt(Ga)&&(Me=!Me),Me&&(Gt("Digit1")&&(ue=!ue,xn=!1),Gt("Digit2")&&(xn=!xn,ue=!1),Gt("Digit3")&&(vn=!vn),Gt("Digit4")&&(he=!he),Gt("Digit5")&&Fa(),Gt("Digit7")&&(Jn=!Jn)),Te()?(!Me||Gt("Digit6"))&&Ba():Me&&Gt("Digit6")&&ja())}function Fl(){if(Te())return;Rt();let n=Ce,t=_e;ho&&(wr(),ec(B),ho=0);let e=ut;if(vn&&Mi){let o=0;for(let a=0;a<8;a++)xo(a)&&o++;for(let a=0;a<8;a++){if(!xo(a))continue;let r=1,c=.2,l=_t.add(b(-r*2,((o-1)/2-a)*r*3));In(a,l.add(b(-r,r)),1),a===mt&&In("Main",l.add(b(-r*2,0)),1,"#0f0");let u=ve[a].length;for(let p=0;p{e.save();let o=i.pos,a=1,r=i.angle;if(i.screenSpace||(o=Pn(i.pos),a=H,r-=Q),e.translate(o.x|0,o.y|0),e.rotate(r),e.scale(1,i.text?1:-1),e.fillStyle=i.color,e.strokeStyle=i.color,i.text!==void 0)e.font=i.size*a+"px "+i.font,e.textAlign="center",e.textBaseline="middle",e.fillText(i.text,0,0);else if(i.points!==void 0){e.beginPath();for(let c of i.points){let l=c.scale(a).floor();e.lineTo(l.x,l.y)}e.closePath(),i.fill&&e.fill(),e.stroke()}else if(i.size===0||i.size.x===0&&i.size.y===0){let c=ka*a;e.fillRect(-c/2,-1,c,3),e.fillRect(-1,-c/2,3,c)}else if(i.size.x!==void 0){let c=i.size.scale(a).floor(),l=c.x,u=c.y;i.fill&&e.fillRect(-l/2|0,-u/2|0,l,u),e.strokeRect(-l/2|0,-u/2|0,l,u)}else e.beginPath(),e.arc(0,0,i.size*a/2,0,9),i.fill&&e.fill(),e.stroke();e.restore()}),Ze=Ze.filter(i=>i.timer<0),s){let i=yc(s.pos,De);i&&ni(i.floor().add(b(.5)),b(1),J(0,1,1,.3),0,!1),mn(De,s.pos,.1,i?J(1,0,0,.5):J(0,1,0,.5),void 0,void 0,!1);let o="mouse pos = "+De;sn.length&&(o+=`
+mouse collision = `+li(De)),o+=`
 
 --- object info ---
-`,o+=s.toString(),nn(o,zt,24,J(),.05,void 0,"center","monospace")}{e.save(),e.fillStyle="#fff",e.textAlign="left",e.textBaseline="top",e.font="20px monospace",e.shadowColor="#000",e.shadowBlur=9;let a=9,r=0,c=24;if(Ie){e.fillText(`${Hs} v${Xs}`,a,r+=c/2),e.fillText("Time: "+ar($t),a,r+=c),e.fillText("FPS: "+Ys.toFixed(1)+(G?" WebGL":" Canvas2D"),a,r+=c),e.fillText("Objects: "+vt.length,a,r+=c),e.fillText("Draw Calls: "+Ce,a,r+=c),e.fillText("Primitives: "+_e,a,r+=c),e.fillText("---------",a,r+=c),e.fillStyle="#f00",e.fillText("ESC: Debug Overlay",a,r+=c),e.fillStyle=ue?"#f00":"#fff",e.fillText("1: Debug Physics",a,r+=c),e.fillStyle=xn?"#f00":"#fff",e.fillText("2: Debug Particles",a,r+=c),e.fillStyle=vn?"#f00":"#fff",e.fillText("3: Debug Gamepads",a,r+=c),e.fillStyle=he?"#f00":"#fff",e.fillText("4: Debug Raycasts",a,r+=c),e.fillStyle="#fff",e.fillText("5: Save Screenshot",a,r+=c),e.fillText("6: Toggle Video Capture",a,r+=c),e.fillStyle=Jn?"#f00":"#fff",e.fillText("7: Debug Sound",a,r+=c);let l="",u="";for(let h in Y[0])Dt(h,0)&&(parseInt(h)<3?u+=h+" ":l+=h+" ");u&&e.fillText("Mouse: "+u,a,r+=c),l&&e.fillText("Keys: "+l,a,r+=c);for(let h=1;hs.push(r.data),i.onstop=()=>{let r=new Blob(s,{type:"video/webm"}),c=URL.createObjectURL(r);ds(c,"capture.webm",1e3)};let o,a;if(qt){a=new ConstantSourceNode(ft,{offset:0}),a.connect(ze),a.start(),o=ft.createMediaStreamDestination(),ze.connect(o);for(let r of o.stream.getAudioTracks())n.addTrack(r)}try{i.start()}catch{xt("Video capture not supported in this browser!"),a==null||a.stop();return}xt("Video capture started."),Me={mediaRecorder:i,captureTimer:e,videoTrack:t,silentAudioSource:a,audioStreamDestination:o}}function Ba(){var n,t,e;f(Te(),"Not capturing video!"),xt(`Video capture ended. ${Me.captureTimer.get().toFixed(2)} seconds recorded.`),le.style.display="none",(n=Me.silentAudioSource)==null||n.stop(),(t=Me.mediaRecorder)==null||t.stop(),(e=Me.videoTrack)==null||e.stop(),Me=void 0}function Bl(){f(Te(),"Not capturing video!"),wr(),Me.videoTrack.requestFrame(),le.textContent="\u25CF REC "+ar(Me.captureTimer)}function Qt(n){if(Ft){let t=Object.keys(n),e={};t.forEach(s=>e[s]=n[s]),t.forEach(s=>{Object.defineProperty(n,s,{get:()=>e[s],set:i=>{f(!1,`Cannot modify engine constant. Attempted to set constant (${n}) property '${s}' to '${i}'.`)},enumerable:!0})})}return Object.freeze(n)}function se(n,t=1){return(n%t+t)%t}function N(n,t=0,e=1){return ne?e:n}function jt(n,t,e){return(e-=t)?N((n-t)/e):0}function Vt(n,t,e){return n+N(e)*(t-n)}function Nl(n,t,e,s,i){return Vt(s,i,jt(n,t,e))}function ir(n,t,e=1){f(e>0,"distanceWrap wrapSize must be > 0");let s=(n-t)%e;return s*2%e-s}function Ua(n,t,e,s=1){return n+N(e)*ir(t,n,s)}function zl(n,t){return ir(n,t,2*X)}function Jl(n,t,e){return Ua(n,t,e,2*X)}function Ks(n){return n*n*(3-2*n)}function hs(n){return!(n&n-1)}function Ul(n){return 2**us(za(n))}function Qs(n,t,e,s=b()){let i=(n.x-e.x)*2,o=(n.y-e.y)*2,a=t.x+s.x,r=t.y+s.y;return nt(i)p)return!1;h=K(y,h)}else{if(y0?r.x+1:r.x,x=h>0?r.y+1:r.y,v=c?(y-n.x)/c:1/0,w=l?(x-n.y)/l:1/0,_=0,S=v,C=w,A=pr.x&&(T.x=r.x+1-P),M.yr.y&&(T.y=r.y+1-P),s&&(A?s.set(-u,0):s.set(0,-h)),T}(A=SURL.revokeObjectURL(n),e)}function $l(n,t,e){var s;f(V(n),"shareURL requires title string"),f(V(t),"shareURL requires url string"),(s=navigator.share)==null||s.call(navigator,{title:n,url:t}).then(()=>e==null?void 0:e())}function Kl(n,t){f(V(n),"loadData requires saveName string");let e={};try{let s=localStorage[n];if(s)try{e=JSON.parse(s)}catch{xt("readSaveData: corrupt JSON for",n,"\u2014 using defaults")}}catch{xt("readSaveData: localStorage unavailable \u2014 using defaults")}return{...t,...e}}function Ql(n,t){f(V(n),"saveData requires saveName string");try{localStorage[n]=JSON.stringify(t)}catch{xt("writeSaveData: failed to write",n)}}function yo(n){let t=(n|0)^2654435769;return t=Math.imul(t^t>>>16,2246822507),t=Math.imul(t^t>>>13,3266489909),t^=t>>>16,(t>>>0)/2**32}function Zl(n){let t=St(n);return Vt(yo(t),yo(t+1),Ks(n-t))}function tu(n,t){let e=St(n),s=St(t),i=Ks(n-e),o=Ks(t-s),a=(r,c)=>yo(r+c*374761393);return Vt(Vt(a(e,s),a(e+1,s),i),Vt(a(e,s+1),a(e+1,s+1),i),o)}function eu(n){_t=n.copy()}function nu(n){Q=n}function su(n){H=n}function iu(n){cr=n}function ou(n){Pi=n}function ru(n){tn=n.copy()}function au(n){Mn=n.copy()}function cu(n){os=n}function lu(n){kn=n}function uu(n){Gn=n.copy()}function nc(n){lr=n,B&&(B.style.imageRendering=n?"pixelated":""),et&&(et.style.imageRendering=n?"pixelated":"")}function hu(n){Tn=n}function du(n){en=n}function fu(n){Rs=n}function pu(n){ur=n}function gu(n){z=n}function yu(n){if(n&&!Ao){console.warn("Can not enable WebGL if it was disabled on start.");return}G=n,et&&(et.style.display=n?"":"none")}function mu(n){Ps=n}function bu(n){Li=n.copy()}function xu(n){Oi=n}function vu(n){Di=n}function Su(n){Ii=n}function wu(n){hr=n}function Tu(n){dr=n}function Au(n){fr=n}function Eu(n){pr=n}function Cu(n){gr=n}function _u(n){Ge=n}function Ru(n){Ut=n.copy()}function Pu(n){Zs=n}function Lu(n){Mi=n}function Ou(n){yr=n}function Du(n){rs=n}function Iu(n){yn=n}function Mu(n){an=n}function ku(n){mr=n}function Gu(n){fe=n}function Fu(n){Yn=n,n>0&&(Kn=!1)}function ju(n){_n=n,n&&($n=0)}function Bu(n){$n=n,n>0&&(_n=!1)}function Nu(n){Kn=n,n&&(Yn=0)}function zu(n){Ls=n}function Ju(n){ln=n}function Uu(n){Wt=n}function Vu(n){br=n}function Wu(n){as=n}function qu(n){ti=n}function Hu(n){Os=n}function Xu(n){qt=n}function Yu(n){Sn=n,qt&&!z&&ze&&(ze.gain.value=n)}function $u(n){xr=n}function Ku(n){vr=n}function Qu(n){Ri=n}function Zu(n){Ga=n}function ei(n){return n.r>=1&&n.g>=1&&n.b>=1}function Sr(n){return n.r<=0&&n.g<=0&&n.b<=0&&n.a<=0}function Ds(n=0,t=Li,e=0,s=Oi,i=Di){if(f(O(n)||typeof n=="number","index must be a vec2 or number"),f(O(t)||typeof t=="number","size must be a vec2 or number"),f(L(e)||e instanceof Ue,"texture must be a number or TextureInfo"),f(L(s),"padding must be a number"),z)return new Re;typeof t=="number"&&(f(t>0),t=new ot(t,t));let o=typeof e=="number"?cn[e]:e;f(o instanceof Ue,"tile texture is not loaded"),f(o.size.x>0,"tile texture is not loaded");let a=t.x+s*2,r=t.y+s*2,c,l;if(typeof n=="number"){let h=o.size.x/a|0;c=n%h,l=n/h|0}else c=n.x,l=n.y;let u=new ot(c*a+s,l*r+s);return new Re(u,t,o,s,i)}function It(n,t=b(1),e,s=W,i=0,o,a,r=G,c=!1,l){var p;f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(U(s),"color is invalid"),f(L(i),"angle must be a number"),f(!a||U(a),"additiveColor must be a color"),f(!l||!r,"context only supported in canvas 2D mode");let u=e==null?void 0:e.textureInfo,h=(p=e==null?void 0:e.bleed)!=null?p:0;if(r&&G)if(f(!!g,"WebGL is not enabled!"),c&&([n,t,i]=Ms(n,t,i)),u){let d=u.sizeInverse,y=e.pos.x*d.x,x=e.pos.y*d.y,v=e.size.x*d.x,w=e.size.y*d.y;if(Fr(u.glTexture),h){let _=d.x*h,S=d.y*h;Ts(n.x,n.y,o?-t.x:t.x,t.y,i,y+_,x+S,y-_+v,x-S+w,s.rgbaInt(),a&&a.rgbaInt())}else Ts(n.x,n.y,o?-t.x:t.x,t.y,i,y,x,y+v,x+w,s.rgbaInt(),a&&a.rgbaInt())}else{let d=a?s.add(a):s;Tc(n.x,n.y,t.x,t.y,i,d.rgbaInt())}else++Ce,++_e,Rn(n,t,i,o,d=>{if(u){d.scale(1,-1);let y=e.pos.x,x=e.pos.y,v=e.size.x,w=e.size.y;lh(d,u.image,y,x,v,w,-.5,-.5,1,1,s,a,h)}else{let y=a?s.add(a):s;d.fillStyle=y.toString(),d.fillRect(-.5,-.5,1,1)}},c,l)}function ni(n,t,e,s,i,o,a){It(n,t,void 0,e,s,!1,void 0,i,o,a)}function th(n,t,e=W,s=rn,i=0,o=G,a=!1,r){if(f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(U(e)&&U(s),"color is invalid"),f(L(i),"angle must be a number"),f(!r||!o,"context only supported in canvas 2D mode"),o&&G){f(!!g,"WebGL is not enabled!"),a&&(n=Is(n),t=t.scale(1/H),i+=Q);let c=[],l=[],u=t.x/2,h=t.y/2,p=e.rgbaInt(),d=s.rgbaInt(),y=ct(-i),x=st(-i);for(let v=4;v--;){let w=v&1?u:-u,_=v&2?h:-h,S=w*y-_*x,C=w*x+_*y,A=v&2?p:d;c.push(b(n.x+S,n.y+C)),l.push(A)}Jr(c,l)}else++Ce,++_e,Rn(n,t,i,!1,c=>{let l=c.createLinearGradient(0,.5,0,-.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.fillRect(-.5,-.5,1,1)},a,r)}function eh(n,t,e,s=0,i=W,o=0,a,r=G,c=!1,l){if(f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(O(e),"wrapCount must be a vec2"),f(U(i),"color is invalid"),f(L(o),"angle must be a number"),f(!a||U(a),"additiveColor must be a color"),f(!l||!r,"context only supported in canvas 2D mode"),f(!(s instanceof Re),"pass a TextureInfo or texture index, not a TileInfo \u2014 use tileInfo.textureInfo"),z)return;let u=typeof s=="number"?cn[s]:s;if(f(u instanceof Ue,"texture not loaded"),f(u.size.x>0,"texture not loaded"),f(u.wrap,"drawTextureWrapped requires a wrap-enabled texture; call textureInfo.setWrap(true) first"),r&&G){f(!!g,"WebGL is not enabled!"),c&&([n,t,o]=Ms(n,t,o)),Fr(u.glTexture),Ts(n.x,n.y,t.x,t.y,o,0,0,e.x,e.y,i.rgbaInt(),a&&a.rgbaInt());return}++Ce,++_e,c||(n=Pn(n),t=t.scale(H),o-=Q);let h=!Pi||(a?ei(i.add(a))&&a.a<=0:ei(i)),p=!h&&a&&!Sr(a),d=h?u.image:ch(u.image,i,a);l=l||Et,l.save(),l.translate(n.x+.5,n.y+.5),l.rotate(o),l.globalAlpha=p?1:i.a;let y=l.createPattern(d,"repeat"),x=new DOMMatrix().translate(-t.x/2,-t.y/2).scale(t.x/(e.x*d.width),t.y/(e.y*d.height));y.setTransform(x),l.fillStyle=y,l.fillRect(-t.x/2,-t.y/2,t.x,t.y),l.globalAlpha=1,l.restore()}function mo(n,t=.1,e=W,s=!1,i=b(),o=0,a=G,r=!1,c){if(f(de(n),"points must be an array"),f(L(t),"width must be a number"),f(U(e),"color is invalid"),f(O(i),"pos must be a vec2"),f(L(o),"angle must be a number"),f(!c||!a,"context only supported in canvas 2D mode"),a&&G){f(!!g,"WebGL is not enabled!");let l=b(1);r&&([i,l,o]=Ms(i,l,o)),zr(n,e.rgbaInt(),t,i.x,i.y,l.x,l.y,o,s)}else++Ce,++_e,Rn(i,b(1),o,!1,l=>{l.strokeStyle=e.toString(),l.lineWidth=t,l.beginPath();for(let u=0;u0&&zr(n,s.rgbaInt(),e,i.x,i.y,l.x,l.y,o)}else Rn(i,b(1),o,!1,l=>{l.fillStyle=t.toString(),l.beginPath();for(let u of n)l.lineTo(u.x,u.y);l.closePath(),l.fill(),e&&(l.strokeStyle=s.toString(),l.lineWidth=e,l.stroke())},r,c)}function ic(n,t=b(1),e=W,s=0,i=0,o=it,a=G,r=!1,c){f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(U(e)&&U(o),"color is invalid"),f(L(s),"angle must be a number"),f(L(i),"lineWidth must be a number"),f(i>=0,"lineWidth must be a positive value or 0"),f(!c||!a,"context only supported in canvas 2D mode"),i=N(i,0,tt(t.x,t.y)),a&&G?sc(n,t,Ps,e,i,o,s,a,r,c):Rn(n,b(1),s,!1,l=>{l.fillStyle=e.toString(),l.beginPath(),l.ellipse(0,0,t.x/2,t.y/2,0,0,9),l.fill(),i&&(l.strokeStyle=o.toString(),l.lineWidth=i,l.stroke())},r,c)}function si(n,t=1,e=W,s=0,i=it,o=G,a=!1,r){f(L(t),"size must be a number"),ic(n,b(t),e,0,s,i,o,a,r)}function oc(n,t=b(1),e=W,s=rn,i=0,o=G,a=!1,r){if(f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(U(e)&&U(s),"color is invalid"),f(L(i),"angle must be a number"),f(!r||!o,"context only supported in canvas 2D mode"),!z)if(o&&G){f(!!g,"WebGL is not enabled!"),a&&(n=Is(n),t=t.scale(1/H),i+=Q);let c=Ps,l=t.x/2,u=t.y/2,h=e.rgbaInt(),p=s.rgbaInt(),d=nh++,y=ct(-i),x=st(-i),v=C=>{let A=st(C)*l,T=ct(C)*u;return b(n.x+A*y-T*x,n.y+A*x+T*y)},w=d%c/c*X*2,_=[v(w)],S=[p];for(let C=c;C--;){let A=(C+d)%c/c*X*2;_.push(n),S.push(h),_.push(v(A)),S.push(p)}Jr(_,S)}else++Ce,++_e,Rn(n,t,i,!1,c=>{let l=c.createRadialGradient(0,0,0,0,0,.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.beginPath(),c.ellipse(0,0,.5,.5,0,0,9),c.fill()},a,r)}function sh(n,t=1,e=W,s=rn,i=G,o=!1,a){f(L(t),"size must be a number"),oc(n,b(t),e,s,0,i,o,a)}function Rn(n,t,e=0,s=!1,i,o=!1,a=Et){f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(L(e),"angle must be a number"),f(typeof i=="function","drawFunction must be a function"),o||(n=Pn(n),t=t.scale(H),e-=Q),a.save(),a.translate(n.x+.5,n.y+.5),a.rotate(e),a.scale(s?-t.x:t.x,-t.y),i(a),a.restore()}function ih(n,t,e=1,s=W,i=0,o=it,a="center",r=Rs,c="",l,u=0,h=Et){t=Pn(t),e*=H,i*=H,u-=Q,u*=-1,nn(n,t,e,s,i,o,a,r,c,l,u,h)}function nn(n,t,e,s=W,i=0,o=it,a="center",r=Rs,c="",l,u=0,h=Et){f(V(n),"text must be a string"),f(O(t),"pos must be a vec2"),f(L(e),"size must be a number"),f(U(s),"color must be a color"),f(L(i),"lineWidth must be a number"),f(U(o),"lineColor must be a color"),f(["left","center","right"].includes(a),"align must be left, center, or right"),f(V(r),"font must be a string"),f(V(c),"fontStyle must be a string"),f(L(u),"angle must be a number");let p=(n+"").split(`
-`),d=t.y-(p.length-1)*e/2;h.save(),h.fillStyle=s.toString(),h.strokeStyle=o.toString(),h.lineWidth=i,h.textAlign=a,h.font=c+" "+e+"px "+r,h.textBaseline="middle",h.translate(t.x,d),h.rotate(-u);let y=0;p.forEach(x=>{i&&h.strokeText(x,0,y,l),h.fillText(x,0,y,l),y+=e}),h.restore()}async function Ta(n,t){f(L(n),"textureIndex must be a number"),f(!cn[n],"textureIndex is already loaded!"),f(!t||V(t),"image src must be a string");let e=new Image;t&&await new Promise(s=>{e.onerror=e.onload=s,e.crossOrigin="anonymous",e.src=t}),cn[n]=new Ue(e)}function Is(n){f(O(n),"screenPos must be a vec2");let t=(n.x-I.x/2+.5)/H,e=(n.y-I.y/2+.5)/-H;if(Q){let s=ct(-Q),i=st(-Q),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new ot(t+_t.x,e+_t.y)}function Pn(n){f(O(n),"worldPos must be a vec2");let t=n.x-_t.x,e=n.y-_t.y;if(Q){let s=ct(Q),i=st(Q),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new ot(t*H+I.x/2-.5,e*-H+I.y/2-.5)}function rc(n){f(O(n),"screenDelta must be a vec2");let t=n.x/H,e=n.y/-H;if(Q){let s=ct(-Q),i=st(-Q),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new ot(t,e)}function oh(n){f(O(n),"worldDelta must be a vec2");let t=n.x,e=n.y;if(Q){let s=ct(Q),i=st(Q),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new ot(t*H,e*-H)}function Ms(n,t,e=0){return f(O(n),"screenPos must be a vec2"),f(O(t),"screenSize must be a vec2"),f(L(e),"screenAngle must be a number"),[Is(n),t.scale(1/H),e+Q]}function ac(){return I.scale(1/H)}function rh(n,t,e,s){f(O(n),"center must be a vec2"),f(O(t),"size must be a vec2");let i=p(e),o=p(s),a=t.x+i.left+i.right,r=t.y+i.top+i.bottom,c=I.x-o.left-o.right,l=I.y-o.top-o.bottom;if(!(a>0&&r>0&&c>0&&l>0))return H;H=tt(c/a,l/r);let u=b(i.right-i.left,i.top-i.bottom).scale(.5),h=b(o.right-o.left,o.top-o.bottom).scale(.5/H);return _t=n.add(u).add(h),H;function p(d){return(d===void 0||L(d))&&(d=b(d)),O(d)?{top:d.y,right:d.x,bottom:d.y,left:d.x}:{top:d.top||0,right:d.right||0,bottom:d.bottom||0,left:d.left||0}}}function ah(n,t=0){if(f(O(n),"pos must be a vec2"),f(O(t)||L(t),"size must be a vec2 or number"),!H)return!1;let e=n.x-_t.x,s=n.y-_t.y;if(Q){let a=ct(Q),r=st(Q),c=e*a-s*r,l=e*r+s*a;e=c,s=l}e*=H*2,s*=-H*2,t instanceof ot&&(t=t.length()),t*=H;let i=I.x,o=I.y;return e+t>-i&&e-t-o&&s-t{n.onerror=n.onload=r,n.crossOrigin="anonymous",n.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAAeAQMAAABnrVXaAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAAjpJREFUOMu9kzFu2zAUhn+CAROgqrk+B2l0BWYxMjlXeYaAtFtbdA1sGgHqRQfI0CNkSG5AwYB0BQ8d5Bsomwah6CPVeGg6tEPzAxLwyI+P78cP4u9lNO9OoMKnLMOobG5020/yaj/MrRcCGh1gBbyiLTPJEYaIiom5KM9Jq7KgynMGtb6L4GL4MF2H4LQKCXTvDVw2I4MsgZT7QLExdiutH+D08VOP3INXRrWX1/mmpbkNgAPYRVANb4xpcegYvhiNbIXauQICEjBuYLfMakaakWQeXxiZ0VDtuJCKs3ztMV59QtsHJNcRxDzfdL21ty3PrfIcXTN+E+GFAv6T5nbT9jd50/WFxb5ksdAv49qS6ouymG66ji08UMT6moykYLAo+V0j23GN4m829ZySAD5K7QsBfQTvOG8eE+gTeGYRAmnNAubN3hf5Zv9tJWDHp/VTuaSm7SN4fyINQqaNO3RMVxvpSPXnOChnRNvFcGY0gnwiPswYwTKVPE0zVtX3mTEIOoFzaqLrGuJaV+Uqumb71fVk/VoOH3cdLNQP/FHi8hV0CQNoqBZsUPlLPMsdCJro9QAaQQ0woDy9BJm0eTxCFnO9srcYlhNVlfR2EyTrph1uUtbUtAJifwRgrKuYdXVHeb0YI3QpawohQHkloI3J5FuVwI5ORxC9k2Tuz9Ir1IjgeIPGMHYkAZe2RuYkmWFmt3gGbTPOmBUWVTmRmHtGrfpzG/yuQNOKa6gBB/WA9khitPgl6/GP+gl2Af6tCbvaygAAAABJRU5ErkJggg=="});let t=b(),e=b(8),s=1,i=0,o=new Ue(n),a=new Re(t,e,o,s,i);lc=new ii(a)}function fh(n=!0){Fn=n}function ph(n){Er=n}function gh(){return Qe==="mouse"}function yh(){return Qe==="keyboard"}function mh(){return Qe==="gamepad"}function Cr(n,t=0,e=!0,s=!0,i=!0){Y[t]&&(Y[t][n]&=~((e?1:0)|(s?2:0)|(i?4:0)))}function ks(){Y.length=0,Y[0]=[],oe.length=0,An.length=0,Gs.length=0,ve.length=0,pn.length=0}function Dt(n,t=0){var e;return f(V(n),"key must be a number or string"),f(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&1)}function kt(n,t=0){var e;return f(V(n),"key must be a number or string"),f(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&2)}function _r(n,t=0){var e;return f(V(n),"key must be a number or string"),f(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&4)}function bh(n="ArrowUp",t="ArrowDown",e="ArrowLeft",s="ArrowRight"){f(V(n),"up key must be a string"),f(V(t),"down key must be a string"),f(V(e),"left key must be a string"),f(V(s),"right key must be a string");let i=o=>Dt(o)?1:0;return b(i(s)-i(e),i(n)-i(t))}function cs(n){return f(L(n),"mouse button must be a number"),Dt(n)}function ps(n){return f(L(n),"mouse button must be a number"),kt(n)}function xh(n){return f(L(n),"mouse button must be a number"),_r(n)}function De(n,t=mt){return f(L(n),"button must be a number"),f(L(t),"gamepad must be a number"),Dt(n,t+1)}function Rr(n,t=mt){return f(L(n),"button must be a number"),f(L(t),"gamepad must be a number"),kt(n,t+1)}function vh(n,t=mt){return f(L(n),"button must be a number"),f(L(t),"gamepad must be a number"),_r(n,t+1)}function gs(n,t=mt){var e,s;return f(L(n),"stick must be a number"),f(L(t),"gamepad must be a number"),(s=(e=ve[t])==null?void 0:e[n])!=null?s:b()}function bo(n=mt){var t;return f(L(n),"gamepad must be a number"),(t=pn[n])!=null?t:b()}function xo(n=mt){return f(L(n),"gamepad must be a number"),!!Y[n+1]}function uc(n=mt){var t,e;return f(L(n),"gamepad must be a number"),(e=(t=ve[n])==null?void 0:t.length)!=null?e:0}function Sh(n=mt,t=200,e=1,s=1,i=0){var a,r,c;if(f(L(n),"gamepad must be a number"),!Os||z)return;let o=(a=navigator==null?void 0:navigator.getGamepads)==null?void 0:a.call(navigator)[n];(c=(r=o==null?void 0:o.vibrationActuator)==null?void 0:r.playEffect)==null||c.call(r,"dual-rumble",{duration:t,strongMagnitude:e,weakMagnitude:s,startDelay:i})}function wh(n=mt){var e,s,i;if(f(L(n),"gamepad must be a number"),!Os||z)return;let t=(e=navigator==null?void 0:navigator.getGamepads)==null?void 0:e.call(navigator)[n];(i=(s=t==null?void 0:t.vibrationActuator)==null?void 0:s.reset)==null||i.call(s)}function Pr(n=100){var t;f(L(n)||de(n),"pattern must be a number or array"),Os&&!z&&((t=navigator==null?void 0:navigator.vibrate)==null||t.call(navigator,n))}function Th(){Pr(0)}function Ah(){var n;!ie&&((n=B.requestPointerLock)==null||n.call(B))}function Eh(){var n;(n=document.exitPointerLock)==null||n.call(document)}function hc(){return document.pointerLockElement===B}function Ch(){if(z)return;document.addEventListener("keydown",n),document.addEventListener("keyup",t),document.addEventListener("mousedown",s),document.addEventListener("mouseup",i),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",a),document.addEventListener("wheel",r,{passive:!1}),document.addEventListener("contextmenu",c),document.addEventListener("blur",l),ie&&yn&&u();function n(p){if(p.repeat||(Y[0][p.code]=3,rs&&(Y[0][e(p.code)]=3)),!Fn||!p.cancelable||!document.hasFocus()||p.ctrlKey||p.metaKey||p.altKey||x(p.target)||x(document.activeElement))return;let d=typeof p.key=="string"&&p.key.length===1;(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Space","Tab","Backspace"].includes(p.code)||d)&&p.preventDefault();function x(v){let w=v==null?void 0:v.tagName;return(v==null?void 0:v.isContentEditable)||["INPUT","TEXTAREA","SELECT"].includes(w)}}function t(p){Y[0][p.code]=Y[0][p.code]&2|4,rs&&(Y[0][e(p.code)]=4)}function e(p){return rs?p==="KeyW"?"ArrowUp":p==="KeyS"?"ArrowDown":p==="KeyA"?"ArrowLeft":p==="KeyD"?"ArrowRight":p:p}function s(p){if(ie&&yn)return;qt&&!z&&ft&&!ms()&&ft.resume(),Y[0][p.button]=3;let d=zt;zt=h(b(p.x,p.y)),xe=xe.add(zt.subtract(d)),Fn&&p.cancelable&&document.hasFocus()&&p.preventDefault()}function i(p){ie&&yn||(Y[0][p.button]=Y[0][p.button]&2|4)}function o(p){oi=!0;let d=zt;zt=h(b(p.x,p.y));let y=hc()?b(p.movementX,p.movementY):zt.subtract(d);xe=xe.add(y)}function a(){oi=!1}function r(p){p.ctrlKey||(Ar+=ne(p.deltaY)),Fn&&p.cancelable&&document.hasFocus()&&p.preventDefault()}function c(p){p.preventDefault()}function l(){ks(),je.clear(),oe.length=0,An.length=0,Gs.length=0}function u(){document.addEventListener("touchstart",y=>d(y),{passive:!1}),document.addEventListener("touchmove",y=>d(y),{passive:!1}),document.addEventListener("touchend",y=>d(y),{passive:!1});let p;function d(y){if(yn){if(qt&&!z&&ft&&!ms()&&ft.resume(),!an||mr){let x=S=>ys.includes(S.target)||S.target===gn,v=[];for(let S of y.touches)x(S)||v.push(S);let w=v.length,_=0;if(w){let S=b(v[0].clientX,v[0].clientY),C=zt;zt=h(S),p?xe=xe.add(zt.subtract(C)):Y[0][_]=3}else p&&(Y[0][_]=Y[0][_]&2|4);p=w}return Fn&&y.cancelable&&document.hasFocus()&&y.preventDefault(),!0}}}function h(p){let d=B.getBoundingClientRect(),y=jt(p.x,d.left,d.right),x=jt(p.y,d.top,d.bottom);return b(y*B.width,x*B.height)}}function Ea(){if(z)return;!(yn&&ie)&&!document.hasFocus()&&ks(),Oe=Is(zt),Tr=rc(xe),Rh(),t(),n();function n(){let e=cs(0)||cs(1)||cs(2)||xe.length()>Er,s=!1;for(let o=uc();o--&&!s;)s=gs(o).lengthSquared()>.04;for(let o=17;o--&&!s;)s=De(o);let i=!1;for(let o in Y[0])if(isNaN(+o)&&Y[0][o]&1){i=!0;break}s?Qe="gamepad":e?Qe="mouse":i&&(Qe="keyboard"),Bn=Qe==="gamepad"}function t(){var a,r,c,l,u,h,p;let e=d=>{let v=w=>w>.3?jt(w,.3,.8):w<-.3?-jt(-w,.3,.8):0;return b(v(d.x),v(-d.y)).clampLength()};if(an&&ie){if(f(!_n||!$n,"set touchGamepadLeftStick or touchGamepadLeftButtonCount, not both"),f(!Kn||!Yn,"set touchGamepadRightStick or touchGamepadButtonCount, not both"),!Vn.isSet())return;mt=0;let d=(a=ve[0])!=null?a:ve[0]=[],y=(r=pn[0])!=null?r:pn[0]=b();d.length=0,y.set();for(let v=0;v<2;v++){if(!Ve(v))continue;let w=Dr(v);d[w]=b();let _=(c=An[v])!=null?c:b();if(Ls)d[w]=e(_);else if(_.lengthSquared()>.3){let S=N($s(_.x),-1,1),C=N($s(_.y),-1,1);d[w]=b(S,-C).clampLength(),w||y.set(S,-C)}}let x=(l=Y[1])!=null?l:Y[1]=[];for(let v=12;v--;){let w=De(v,0);x[v]=oe[v]?w?1:3:w?4:0,ti&&x[v]===3&&(v===9||Ph(v))&&Pr(ti)}return}try{if(!Mi||!(navigator!=null&&navigator.getGamepads))return}catch{return}if(!Ft&&!document.hasFocus())return;let s=8,i=navigator.getGamepads(),o=tt(s,i.length);for(let d=0;d>1]=e(b(y.axes[S],y.axes[S+1]));let _=!1;for(let S=y.buttons.length;S--;){let C=y.buttons[S],A=De(S,d);x[S]=C.pressed?A?1:3:A?4:0,C.pressed&&(!C.value||C.value>.9)&&(_=!0)}_&&(co[d]=!0,co[mt]||(mt=d)),y.mapping==="standard"&&w.set((De(15,d)&&1)-(De(14,d)&&1),(De(12,d)&&1)-(De(13,d)&&1)),yr&&(w.x||w.y)&&(v[0]=w.clampLength())}an&&Bn&&Vn.unset()}}function Ca(){if(!z){for(let n of Y)for(let t in n)n[t]&=1;Ar=0,Tr=b(),xe=b()}}function _h(){Ih()}function Rh(){if(Ye||!an||!ie||z||!document.body)return;let n=Ye=document.createElement("div");n.style.cssText="position:fixed;inset:0;z-index:50;pointer-events:none;opacity:0;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;transition:opacity .2s;box-sizing:border-box;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)";let t=dc=document.createElement("div");t.style.cssText="position:relative;width:100%;height:100%;pointer-events:none",n.appendChild(t);let e=Lr=document.createElementNS(ai,"svg");e.style.cssText="position:absolute;inset:0;width:100%;height:100%;pointer-events:none;overflow:visible;fill:none;stroke:#fff;stroke-width:3",t.appendChild(e);let s=()=>{let i=document.createElement("div");return i.style.cssText="position:absolute;pointer-events:auto;touch-action:none",i.addEventListener("pointerdown",o=>Fh(o,i)),i.addEventListener("pointermove",o=>jh(o)),i.addEventListener("pointerup",o=>_a(o)),i.addEventListener("pointercancel",o=>_a(o)),t.appendChild(i),i};ys[0]=s(),ys[1]=s(),gn=s(),addEventListener("resize",()=>Wn=!0),document.body.appendChild(n),Wn=!0}function ki(){return dc.getBoundingClientRect()}function Ve(n){return n?Kn:_n}function Ln(n){return n?Yn:$n}function Or(n){return n?0:4}function Dr(n){return n&&_n?1:0}function qn(n){return Ve(n)||Ln(n)>0}function Ph(n){for(let t=0;t<2;t++){let e=Or(t);if(!Ve(t)&&n>=e&&no.style.cssText="position:absolute;pointer-events:auto;touch-action:none;"+a;if(Ae){for(let o of ys)o.style.display="none";fe?(i(gn,"inset:0"),gn.style.display=""):gn.style.display="none"}else{for(let a=0;a<2;a++){let r=ys[a],c=a?"right":"left";if(r.style.display=qn(a)?"":"none",ln){let l=qn(a?0:1)?"50%":"100%";i(r,`${c}:0;bottom:0;width:${l};height:60%`)}else i(r,`${c}:0;bottom:0;width:${3*s}px;height:${3*s}px`)}gn.style.display=fe?"":"none";let o=fe;i(gn,`left:50%;top:50%;width:${2*o}px;height:${2*o}px;transform:translate(-50%,-50%)`)}Oh(t,e),Wn=!1}function Oh(n,t){let e=Lr;for(;e.firstChild;)e.removeChild(e.firstChild);let s=fc={face:[],thumb:[]},i=Wt,o=(r,c,l,u)=>{let h=document.createElementNS(ai,"circle");return h.setAttribute("cx",r),h.setAttribute("cy",c),h.setAttribute("r",l),u&&h.setAttribute("fill",u),e.appendChild(h),h},a=r=>{let c=i*.18,l=i*.5,u=r.x,h=r.y,p=document.createElementNS(ai,"path");p.setAttribute("d",`M ${u-c} ${h-l} H ${u+c} V ${h-c} H ${u+l} V ${h+c} H ${u+c} V ${h+l} H ${u-c} V ${h+c} H ${u-l} V ${h-c} H ${u-c} Z`),e.appendChild(p)};for(let r=0;r<2;r++){let c=Ln(r),l=Or(r),u=Ne(r,n,t);if(Ve(r))Ls?o(u.x,u.y,i/2):a(u),s.thumb[r]=o(u.x,u.y,i/4,"#fff");else if(c===1)s.face[l]=o(u.x,u.y,i/2,"#000");else for(let h=0;h2?p:tt(p,c-1);d=d===3?2:d===2?3:d;let y=b().setDirection(p,i/2);c===2&&(y.x*=-1),r||(y.x*=-1);let x=u.add(y);s.face[l+d]=o(x.x,x.y,i/4,"#000")}}Ft&&vn&&Dh(n,t)}function Dh(n,t){let e=Wt,s=Lr,i=(a,r,c)=>{let l=document.createElementNS(ai,a);for(let u in r)l.setAttribute(u,r[u]);l.setAttribute("stroke",c),l.setAttribute("stroke-width",2),l.setAttribute("fill","none"),s.appendChild(l)},o=(a,r,c)=>i("circle",{cx:a.x,cy:a.y,r},c);i("line",{x1:n/2,y1:0,x2:n/2,y2:t},"#0f0");for(let a=0;a<2;a++)if(Ve(a))if(ln){let r=t*.4,c=!qn(a?0:1),l=c?0:a?n/2:0;i("rect",{x:l,y:r,width:c?n:n/2,height:t-r},"#0ff")}else o(Ne(a,n,t),2*e,"#0ff");else Ln(a)>=1&&o(Ne(a,n,t),e,"#0ff");if(fe){o(b(n/2,t/2),fe,"#ff0");for(let a=0;a<2;a++)qn(a)&&o(Ne(a,n,t),2*e,"#f0f")}}function Ih(){var l;if(!Ye||z)return;if(!an||!ie){Ye.style.display!=="none"&&(Ye.style.display="none",je.clear(),oe.length=0,An.length=0,Gs.length=0);return}Ye.style.display="";let n=Ft&&vn,t=[Yn,$n,_n,Kn,Ls,Wt,ln,fe,Ae,n].join();t!==Aa&&(Aa=t,Wn=!0),Wn&&Lh();let e=as?jt(Vn.get(),as+1,as):1,s=n||Vn.isSet()&&e>0&&!Ae;if(Ye.style.opacity=s?n?1:e*br:0,!s)return;let i=ki(),o=i.width,a=i.height,r=Wt,c=fc;if(c){for(let u=0;u<2;u++)if(Ve(u)&&c.thumb[u]){let p=Ne(u,o,a).add(((l=An[u])!=null?l:b()).scale(r/2));c.thumb[u].setAttribute("cx",p.x),c.thumb[u].setAttribute("cy",p.y)}for(let u=0;u=Wt)return-1;if(i===1)return o;let r=a.subtract(t);n||(r.x*=-1);let c=i===2?r.xo:r&&Ne(a,t,e).distance(n)<2*s)return{role:"stick",side:a}}else if(Ln(a)>=1){let c=kh(a,n,t,e);if(c>=0)return{role:"face",btn:c}}}if(fe){for(let a=0;a<2;a++)if(qn(a)&&Ne(a,t,e).distance(n)<2*s)return;if(b(t/2,e/2).distance(n)h.getChannelData(v).set(x)),p.buffer=h,p.playbackRate.value=e,p.loop=i,a=a||ft.createGain(),a.gain.value=t,a.connect(ze);let d=new StereoPannerNode(ft,{pan:N(s,-1,1)});p.connect(d).connect(a),p.addEventListener("ended",()=>{a.disconnect(),d.disconnect(),c&&c(p)});let y=r*e;return p.start(0,y),Ft&&Jn&&xt("sound","vol",t.toFixed(2),"rate",e.toFixed(2),"pan",s.toFixed(2),i?"loop":""),p}function Jh(...n){return Ir([Gi(...n)])}function Gi(n=1,t=.05,e=220,s=0,i=0,o=.1,a=0,r=1,c=0,l=0,u=0,h=0,p=0,d=0,y=0,x=0,v=0,w=1,_=0,S=0,C=0){let A=Qn,T=X*2,P=c*=500*T/A/A,M=e*=(1+dt(t,-t))*T/A,pt=0,rt=0,at=0,yt=1,Bt,ge=[],Pt=0,ht=0,Lt=0,We,un=2,hn=T*nt(C)*2/A,ae=ct(hn),Pe=st(hn)/2/un,Zt=1+Pe,R=-2*ae/Zt,F=(1-Pe)/Zt,k=(1+ne(C)*ae)/2/Zt,j=-(ne(C)+ae)/Zt,$=k,Z=0,Tt=0,At=0,Ot=0;for(s=s*A||9,_*=A,i*=A,o*=A,v*=A,l*=500*T/A**3,y*=T/A,u*=T/A,h*=A,p=p*A|0,Bt=s+_+i+o+v|0;ht1?a>2?a>3?a>4?Pt/T%14?Lt:ne(Lt)*nt(Lt)**r)*(htht?0:(hth&&(e+=u,M+=u,yt=0),p&&!(++rt%p)&&(e=M,c=P,yt||(yt=1));return ge}function li(n,t=!0){for(let e of sn)if((!t||e.isSolid)&&n.arrayCheck(e.size)){let s=e.getCollisionData(n);if(s)return s}return 0}function $e(n,t=b(),e,s=!0){for(let i of sn)if((!s||i.isSolid)&&i.collisionTest(n,t,e))return i}function yc(n,t,e,s,i=!0){let o,a,r,c=s&&b();for(let l of sn)if(!i||l.isSolid){let u=l.collisionRaycast(n,t,e,c);if(u){let h=n.distanceSquared(u);(o===void 0||h{G=!1,et.style.display="none",e.preventDefault(),xt("WebGL context lost! Switching to Canvas2d rendering.");for(let s of ls)s.glTexture=void 0;Kt=void 0,Ct=0,En=!1,bn.forEach(s=>{var i;return(i=s.glContextLost)==null?void 0:i.call(s)})}),et.addEventListener("webglcontextrestored",()=>{G=!0,et.style.display="",xt("WebGL context restored, reinitializing..."),t();for(let e of ls)e.glTexture=ji(e.image,e.wrap);bn.forEach(e=>{var s;return(s=e.glContextRestored)==null?void 0:s.call(e)})});function t(){di=Xn(`#version 300 es
+`,o+=s.toString(),nn(o,Jt,24,J(),.05,void 0,"center","monospace")}{e.save(),e.fillStyle="#fff",e.textAlign="left",e.textBaseline="top",e.font="20px monospace",e.shadowColor="#000",e.shadowBlur=9;let a=9,r=0,c=24;if(Me){e.fillText(`${Hs} v${Xs}`,a,r+=c/2),e.fillText("Time: "+ar(Kt),a,r+=c),e.fillText("FPS: "+Ys.toFixed(1)+(G?" WebGL":" Canvas2D"),a,r+=c),e.fillText("Objects: "+vt.length,a,r+=c),e.fillText("Draw Calls: "+Ce,a,r+=c),e.fillText("Primitives: "+_e,a,r+=c),e.fillText("---------",a,r+=c),e.fillStyle="#f00",e.fillText("ESC: Debug Overlay",a,r+=c),e.fillStyle=ue?"#f00":"#fff",e.fillText("1: Debug Physics",a,r+=c),e.fillStyle=xn?"#f00":"#fff",e.fillText("2: Debug Particles",a,r+=c),e.fillStyle=vn?"#f00":"#fff",e.fillText("3: Debug Gamepads",a,r+=c),e.fillStyle=he?"#f00":"#fff",e.fillText("4: Debug Raycasts",a,r+=c),e.fillStyle="#fff",e.fillText("5: Save Screenshot",a,r+=c),e.fillText("6: Toggle Video Capture",a,r+=c),e.fillStyle=Jn?"#f00":"#fff",e.fillText("7: Debug Sound",a,r+=c);let l="",u="";for(let h in Y[0])It(h,0)&&(parseInt(h)<3?u+=h+" ":l+=h+" ");u&&e.fillText("Mouse: "+u,a,r+=c),l&&e.fillText("Keys: "+l,a,r+=c);for(let h=1;hs.push(r.data),i.onstop=()=>{let r=new Blob(s,{type:"video/webm"}),c=URL.createObjectURL(r);ds(c,"capture.webm",1e3)};let o,a;if(Ht){a=new ConstantSourceNode(ft,{offset:0}),a.connect(Je),a.start(),o=ft.createMediaStreamDestination(),Je.connect(o);for(let r of o.stream.getAudioTracks())n.addTrack(r)}try{i.start()}catch{xt("Video capture not supported in this browser!"),a==null||a.stop();return}xt("Video capture started."),ke={mediaRecorder:i,captureTimer:e,videoTrack:t,silentAudioSource:a,audioStreamDestination:o}}function Ba(){var n,t,e;f(Te(),"Not capturing video!"),xt(`Video capture ended. ${ke.captureTimer.get().toFixed(2)} seconds recorded.`),le.style.display="none",(n=ke.silentAudioSource)==null||n.stop(),(t=ke.mediaRecorder)==null||t.stop(),(e=ke.videoTrack)==null||e.stop(),ke=void 0}function Bl(){f(Te(),"Not capturing video!"),wr(),ke.videoTrack.requestFrame(),le.textContent="\u25CF REC "+ar(ke.captureTimer)}function Zt(n){if(jt){let t=Object.keys(n),e={};t.forEach(s=>e[s]=n[s]),t.forEach(s=>{Object.defineProperty(n,s,{get:()=>e[s],set:i=>{f(!1,`Cannot modify engine constant. Attempted to set constant (${n}) property '${s}' to '${i}'.`)},enumerable:!0})})}return Object.freeze(n)}function se(n,t=1){return(n%t+t)%t}function N(n,t=0,e=1){return ne?e:n}function Bt(n,t,e){return(e-=t)?N((n-t)/e):0}function Wt(n,t,e){return n+N(e)*(t-n)}function Nl(n,t,e,s,i){return Wt(s,i,Bt(n,t,e))}function ir(n,t,e=1){f(e>0,"distanceWrap wrapSize must be > 0");let s=(n-t)%e;return s*2%e-s}function Ua(n,t,e,s=1){return n+N(e)*ir(t,n,s)}function zl(n,t){return ir(n,t,2*X)}function Jl(n,t,e){return Ua(n,t,e,2*X)}function Ks(n){return n*n*(3-2*n)}function hs(n){return!(n&n-1)}function Ul(n){return 2**us(za(n))}function Qs(n,t,e,s=b()){let i=(n.x-e.x)*2,o=(n.y-e.y)*2,a=t.x+s.x,r=t.y+s.y;return nt(i)p)return!1;h=K(y,h)}else{if(y0?r.x+1:r.x,x=h>0?r.y+1:r.y,v=c?(y-n.x)/c:1/0,w=l?(x-n.y)/l:1/0,_=0,S=v,C=w,A=pr.x&&(T.x=r.x+1-P),M.yr.y&&(T.y=r.y+1-P),s&&(A?s.set(-u,0):s.set(0,-h)),T}(A=SURL.revokeObjectURL(n),e)}function $l(n,t,e){var s;f(V(n),"shareURL requires title string"),f(V(t),"shareURL requires url string"),(s=navigator.share)==null||s.call(navigator,{title:n,url:t}).then(()=>e==null?void 0:e())}function Kl(n,t){f(V(n),"loadData requires saveName string");let e={};try{let s=localStorage[n];if(s)try{e=JSON.parse(s)}catch{xt("readSaveData: corrupt JSON for",n,"\u2014 using defaults")}}catch{xt("readSaveData: localStorage unavailable \u2014 using defaults")}return{...t,...e}}function Ql(n,t){f(V(n),"saveData requires saveName string");try{localStorage[n]=JSON.stringify(t)}catch{xt("writeSaveData: failed to write",n)}}function yo(n){let t=(n|0)^2654435769;return t=Math.imul(t^t>>>16,2246822507),t=Math.imul(t^t>>>13,3266489909),t^=t>>>16,(t>>>0)/2**32}function Zl(n){let t=St(n);return Wt(yo(t),yo(t+1),Ks(n-t))}function tu(n,t){let e=St(n),s=St(t),i=Ks(n-e),o=Ks(t-s),a=(r,c)=>yo(r+c*374761393);return Wt(Wt(a(e,s),a(e+1,s),i),Wt(a(e,s+1),a(e+1,s+1),i),o)}function eu(n){_t=n.copy()}function nu(n){Q=n}function su(n){H=n}function iu(n){cr=n}function ou(n){Pi=n}function ru(n){tn=n.copy()}function au(n){Mn=n.copy()}function cu(n){os=n}function lu(n){kn=n}function uu(n){Gn=n.copy()}function nc(n){lr=n,B&&(B.style.imageRendering=n?"pixelated":""),et&&(et.style.imageRendering=n?"pixelated":"")}function hu(n){Tn=n}function du(n){en=n}function fu(n){Rs=n}function pu(n){ur=n}function gu(n){z=n}function yu(n){if(n&&!Ao){console.warn("Can not enable WebGL if it was disabled on start.");return}G=n,et&&(et.style.display=n?"":"none")}function mu(n){Ps=n}function bu(n){Li=n.copy()}function xu(n){Oi=n}function vu(n){Di=n}function Su(n){Ii=n}function wu(n){hr=n}function Tu(n){dr=n}function Au(n){fr=n}function Eu(n){pr=n}function Cu(n){gr=n}function _u(n){Fe=n}function Ru(n){Vt=n.copy()}function Pu(n){Zs=n}function Lu(n){Mi=n}function Ou(n){yr=n}function Du(n){rs=n}function Iu(n){yn=n}function Mu(n){an=n}function ku(n){mr=n}function Gu(n){fe=n}function Fu(n){Yn=n,n>0&&(Kn=!1)}function ju(n){_n=n,n&&($n=0)}function Bu(n){$n=n,n>0&&(_n=!1)}function Nu(n){Kn=n,n&&(Yn=0)}function zu(n){Ls=n}function Ju(n){ln=n}function Uu(n){qt=n}function Vu(n){br=n}function Wu(n){as=n}function qu(n){ti=n}function Hu(n){Os=n}function Xu(n){Ht=n}function Yu(n){Sn=n,Ht&&!z&&Je&&(Je.gain.value=n)}function $u(n){xr=n}function Ku(n){vr=n}function Qu(n){Ri=n}function Zu(n){Ga=n}function ei(n){return n.r>=1&&n.g>=1&&n.b>=1}function Sr(n){return n.r<=0&&n.g<=0&&n.b<=0&&n.a<=0}function Ds(n=0,t=Li,e=0,s=Oi,i=Di){if(f(O(n)||typeof n=="number","index must be a vec2 or number"),f(O(t)||typeof t=="number","size must be a vec2 or number"),f(L(e)||e instanceof Ve,"texture must be a number or TextureInfo"),f(L(s),"padding must be a number"),z)return new Re;typeof t=="number"&&(f(t>0),t=new rt(t,t));let o=typeof e=="number"?cn[e]:e;f(o instanceof Ve,"tile texture is not loaded"),f(o.size.x>0,"tile texture is not loaded");let a=t.x+s*2,r=t.y+s*2,c,l;if(typeof n=="number"){let h=o.size.x/a|0;c=n%h,l=n/h|0}else c=n.x,l=n.y;let u=new rt(c*a+s,l*r+s);return new Re(u,t,o,s,i)}function Mt(n,t=b(1),e,s=W,i=0,o,a,r=G,c=!1,l){var p;f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(U(s),"color is invalid"),f(L(i),"angle must be a number"),f(!a||U(a),"additiveColor must be a color"),f(!l||!r,"context only supported in canvas 2D mode");let u=e==null?void 0:e.textureInfo,h=(p=e==null?void 0:e.bleed)!=null?p:0;if(r&&G)if(f(!!g,"WebGL is not enabled!"),c&&([n,t,i]=Ms(n,t,i)),u){let d=u.sizeInverse,y=e.pos.x*d.x,x=e.pos.y*d.y,v=e.size.x*d.x,w=e.size.y*d.y;if(Fr(u.glTexture),h){let _=d.x*h,S=d.y*h;Ts(n.x,n.y,o?-t.x:t.x,t.y,i,y+_,x+S,y-_+v,x-S+w,s.rgbaInt(),a&&a.rgbaInt())}else Ts(n.x,n.y,o?-t.x:t.x,t.y,i,y,x,y+v,x+w,s.rgbaInt(),a&&a.rgbaInt())}else{let d=a?s.add(a):s;Tc(n.x,n.y,t.x,t.y,i,d.rgbaInt())}else++Ce,++_e,Rn(n,t,i,o,d=>{if(u){d.scale(1,-1);let y=e.pos.x,x=e.pos.y,v=e.size.x,w=e.size.y;lh(d,u.image,y,x,v,w,-.5,-.5,1,1,s,a,h)}else{let y=a?s.add(a):s;d.fillStyle=y.toString(),d.fillRect(-.5,-.5,1,1)}},c,l)}function ni(n,t,e,s,i,o,a){Mt(n,t,void 0,e,s,!1,void 0,i,o,a)}function th(n,t,e=W,s=rn,i=0,o=G,a=!1,r){if(f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(U(e)&&U(s),"color is invalid"),f(L(i),"angle must be a number"),f(!r||!o,"context only supported in canvas 2D mode"),o&&G){f(!!g,"WebGL is not enabled!"),a&&(n=Is(n),t=t.scale(1/H),i+=Q);let c=[],l=[],u=t.x/2,h=t.y/2,p=e.rgbaInt(),d=s.rgbaInt(),y=lt(-i),x=st(-i);for(let v=4;v--;){let w=v&1?u:-u,_=v&2?h:-h,S=w*y-_*x,C=w*x+_*y,A=v&2?p:d;c.push(b(n.x+S,n.y+C)),l.push(A)}Jr(c,l)}else++Ce,++_e,Rn(n,t,i,!1,c=>{let l=c.createLinearGradient(0,.5,0,-.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.fillRect(-.5,-.5,1,1)},a,r)}function eh(n,t,e,s=0,i=W,o=0,a,r=G,c=!1,l){if(f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(O(e),"wrapCount must be a vec2"),f(U(i),"color is invalid"),f(L(o),"angle must be a number"),f(!a||U(a),"additiveColor must be a color"),f(!l||!r,"context only supported in canvas 2D mode"),f(!(s instanceof Re),"pass a TextureInfo or texture index, not a TileInfo \u2014 use tileInfo.textureInfo"),z)return;let u=typeof s=="number"?cn[s]:s;if(f(u instanceof Ve,"texture not loaded"),f(u.size.x>0,"texture not loaded"),f(u.wrap,"drawTextureWrapped requires a wrap-enabled texture; call textureInfo.setWrap(true) first"),r&&G){f(!!g,"WebGL is not enabled!"),c&&([n,t,o]=Ms(n,t,o)),Fr(u.glTexture),Ts(n.x,n.y,t.x,t.y,o,0,0,e.x,e.y,i.rgbaInt(),a&&a.rgbaInt());return}++Ce,++_e,c||(n=Pn(n),t=t.scale(H),o-=Q);let h=!Pi||(a?ei(i.add(a))&&a.a<=0:ei(i)),p=!h&&a&&!Sr(a),d=h?u.image:ch(u.image,i,a);l=l||Et,l.save(),l.translate(n.x+.5,n.y+.5),l.rotate(o),l.globalAlpha=p?1:i.a;let y=l.createPattern(d,"repeat"),x=new DOMMatrix().translate(-t.x/2,-t.y/2).scale(t.x/(e.x*d.width),t.y/(e.y*d.height));y.setTransform(x),l.fillStyle=y,l.fillRect(-t.x/2,-t.y/2,t.x,t.y),l.globalAlpha=1,l.restore()}function mo(n,t=.1,e=W,s=!1,i=b(),o=0,a=G,r=!1,c){if(f(de(n),"points must be an array"),f(L(t),"width must be a number"),f(U(e),"color is invalid"),f(O(i),"pos must be a vec2"),f(L(o),"angle must be a number"),f(!c||!a,"context only supported in canvas 2D mode"),a&&G){f(!!g,"WebGL is not enabled!");let l=b(1);r&&([i,l,o]=Ms(i,l,o)),zr(n,e.rgbaInt(),t,i.x,i.y,l.x,l.y,o,s)}else++Ce,++_e,Rn(i,b(1),o,!1,l=>{l.strokeStyle=e.toString(),l.lineWidth=t,l.beginPath();for(let u=0;u0&&zr(n,s.rgbaInt(),e,i.x,i.y,l.x,l.y,o)}else Rn(i,b(1),o,!1,l=>{l.fillStyle=t.toString(),l.beginPath();for(let u of n)l.lineTo(u.x,u.y);l.closePath(),l.fill(),e&&(l.strokeStyle=s.toString(),l.lineWidth=e,l.stroke())},r,c)}function ic(n,t=b(1),e=W,s=0,i=0,o=it,a=G,r=!1,c){f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(U(e)&&U(o),"color is invalid"),f(L(s),"angle must be a number"),f(L(i),"lineWidth must be a number"),f(i>=0,"lineWidth must be a positive value or 0"),f(!c||!a,"context only supported in canvas 2D mode"),i=N(i,0,tt(t.x,t.y)),a&&G?sc(n,t,Ps,e,i,o,s,a,r,c):Rn(n,b(1),s,!1,l=>{l.fillStyle=e.toString(),l.beginPath(),l.ellipse(0,0,t.x/2,t.y/2,0,0,9),l.fill(),i&&(l.strokeStyle=o.toString(),l.lineWidth=i,l.stroke())},r,c)}function si(n,t=1,e=W,s=0,i=it,o=G,a=!1,r){f(L(t),"size must be a number"),ic(n,b(t),e,0,s,i,o,a,r)}function oc(n,t=b(1),e=W,s=rn,i=0,o=G,a=!1,r){if(f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(U(e)&&U(s),"color is invalid"),f(L(i),"angle must be a number"),f(!r||!o,"context only supported in canvas 2D mode"),!z)if(o&&G){f(!!g,"WebGL is not enabled!"),a&&(n=Is(n),t=t.scale(1/H),i+=Q);let c=Ps,l=t.x/2,u=t.y/2,h=e.rgbaInt(),p=s.rgbaInt(),d=nh++,y=lt(-i),x=st(-i),v=C=>{let A=st(C)*l,T=lt(C)*u;return b(n.x+A*y-T*x,n.y+A*x+T*y)},w=d%c/c*X*2,_=[v(w)],S=[p];for(let C=c;C--;){let A=(C+d)%c/c*X*2;_.push(n),S.push(h),_.push(v(A)),S.push(p)}Jr(_,S)}else++Ce,++_e,Rn(n,t,i,!1,c=>{let l=c.createRadialGradient(0,0,0,0,0,.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.beginPath(),c.ellipse(0,0,.5,.5,0,0,9),c.fill()},a,r)}function sh(n,t=1,e=W,s=rn,i=G,o=!1,a){f(L(t),"size must be a number"),oc(n,b(t),e,s,0,i,o,a)}function Rn(n,t,e=0,s=!1,i,o=!1,a=Et){f(O(n),"pos must be a vec2"),f(O(t),"size must be a vec2"),f(L(e),"angle must be a number"),f(typeof i=="function","drawFunction must be a function"),o||(n=Pn(n),t=t.scale(H),e-=Q),a.save(),a.translate(n.x+.5,n.y+.5),a.rotate(e),a.scale(s?-t.x:t.x,-t.y),i(a),a.restore()}function ih(n,t,e=1,s=W,i=0,o=it,a="center",r=Rs,c="",l,u=0,h=Et){t=Pn(t),e*=H,i*=H,u-=Q,u*=-1,nn(n,t,e,s,i,o,a,r,c,l,u,h)}function nn(n,t,e,s=W,i=0,o=it,a="center",r=Rs,c="",l,u=0,h=Et){f(V(n),"text must be a string"),f(O(t),"pos must be a vec2"),f(L(e),"size must be a number"),f(U(s),"color must be a color"),f(L(i),"lineWidth must be a number"),f(U(o),"lineColor must be a color"),f(["left","center","right"].includes(a),"align must be left, center, or right"),f(V(r),"font must be a string"),f(V(c),"fontStyle must be a string"),f(L(u),"angle must be a number");let p=(n+"").split(`
+`),d=t.y-(p.length-1)*e/2;h.save(),h.fillStyle=s.toString(),h.strokeStyle=o.toString(),h.lineWidth=i,h.textAlign=a,h.font=c+" "+e+"px "+r,h.textBaseline="middle",h.translate(t.x,d),h.rotate(-u);let y=0;p.forEach(x=>{i&&h.strokeText(x,0,y,l),h.fillText(x,0,y,l),y+=e}),h.restore()}async function Ta(n,t){f(L(n),"textureIndex must be a number"),f(!cn[n],"textureIndex is already loaded!"),f(!t||V(t),"image src must be a string");let e=new Image;t&&await new Promise(s=>{e.onerror=e.onload=s,e.crossOrigin="anonymous",e.src=t}),cn[n]=new Ve(e)}function Is(n){f(O(n),"screenPos must be a vec2");let t=(n.x-I.x/2+.5)/H,e=(n.y-I.y/2+.5)/-H;if(Q){let s=lt(-Q),i=st(-Q),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new rt(t+_t.x,e+_t.y)}function Pn(n){f(O(n),"worldPos must be a vec2");let t=n.x-_t.x,e=n.y-_t.y;if(Q){let s=lt(Q),i=st(Q),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new rt(t*H+I.x/2-.5,e*-H+I.y/2-.5)}function rc(n){f(O(n),"screenDelta must be a vec2");let t=n.x/H,e=n.y/-H;if(Q){let s=lt(-Q),i=st(-Q),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new rt(t,e)}function oh(n){f(O(n),"worldDelta must be a vec2");let t=n.x,e=n.y;if(Q){let s=lt(Q),i=st(Q),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new rt(t*H,e*-H)}function Ms(n,t,e=0){return f(O(n),"screenPos must be a vec2"),f(O(t),"screenSize must be a vec2"),f(L(e),"screenAngle must be a number"),[Is(n),t.scale(1/H),e+Q]}function ac(){return I.scale(1/H)}function rh(n,t,e,s){f(O(n),"center must be a vec2"),f(O(t),"size must be a vec2");let i=p(e),o=p(s),a=t.x+i.left+i.right,r=t.y+i.top+i.bottom,c=I.x-o.left-o.right,l=I.y-o.top-o.bottom;if(!(a>0&&r>0&&c>0&&l>0))return H;H=tt(c/a,l/r);let u=b(i.right-i.left,i.top-i.bottom).scale(.5),h=b(o.right-o.left,o.top-o.bottom).scale(.5/H);return _t=n.add(u).add(h),H;function p(d){return(d===void 0||L(d))&&(d=b(d)),O(d)?{top:d.y,right:d.x,bottom:d.y,left:d.x}:{top:d.top||0,right:d.right||0,bottom:d.bottom||0,left:d.left||0}}}function ah(n,t=0){if(f(O(n),"pos must be a vec2"),f(O(t)||L(t),"size must be a vec2 or number"),!H)return!1;let e=n.x-_t.x,s=n.y-_t.y;if(Q){let a=lt(Q),r=st(Q),c=e*a-s*r,l=e*r+s*a;e=c,s=l}e*=H*2,s*=-H*2,t instanceof rt&&(t=t.length()),t*=H;let i=I.x,o=I.y;return e+t>-i&&e-t-o&&s-t{n.onerror=n.onload=r,n.crossOrigin="anonymous",n.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAAeAQMAAABnrVXaAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAAjpJREFUOMu9kzFu2zAUhn+CAROgqrk+B2l0BWYxMjlXeYaAtFtbdA1sGgHqRQfI0CNkSG5AwYB0BQ8d5Bsomwah6CPVeGg6tEPzAxLwyI+P78cP4u9lNO9OoMKnLMOobG5020/yaj/MrRcCGh1gBbyiLTPJEYaIiom5KM9Jq7KgynMGtb6L4GL4MF2H4LQKCXTvDVw2I4MsgZT7QLExdiutH+D08VOP3INXRrWX1/mmpbkNgAPYRVANb4xpcegYvhiNbIXauQICEjBuYLfMakaakWQeXxiZ0VDtuJCKs3ztMV59QtsHJNcRxDzfdL21ty3PrfIcXTN+E+GFAv6T5nbT9jd50/WFxb5ksdAv49qS6ouymG66ji08UMT6moykYLAo+V0j23GN4m829ZySAD5K7QsBfQTvOG8eE+gTeGYRAmnNAubN3hf5Zv9tJWDHp/VTuaSm7SN4fyINQqaNO3RMVxvpSPXnOChnRNvFcGY0gnwiPswYwTKVPE0zVtX3mTEIOoFzaqLrGuJaV+Uqumb71fVk/VoOH3cdLNQP/FHi8hV0CQNoqBZsUPlLPMsdCJro9QAaQQ0woDy9BJm0eTxCFnO9srcYlhNVlfR2EyTrph1uUtbUtAJifwRgrKuYdXVHeb0YI3QpawohQHkloI3J5FuVwI5ORxC9k2Tuz9Ir1IjgeIPGMHYkAZe2RuYkmWFmt3gGbTPOmBUWVTmRmHtGrfpzG/yuQNOKa6gBB/WA9khitPgl6/GP+gl2Af6tCbvaygAAAABJRU5ErkJggg=="});let t=b(),e=b(8),s=1,i=0,o=new Ve(n),a=new Re(t,e,o,s,i);lc=new ii(a)}function fh(n=!0){Fn=n}function ph(n){Er=n}function gh(){return Qe==="mouse"}function yh(){return Qe==="keyboard"}function mh(){return Qe==="gamepad"}function Cr(n,t=0,e=!0,s=!0,i=!0){Y[t]&&(Y[t][n]&=~((e?1:0)|(s?2:0)|(i?4:0)))}function ks(){Y.length=0,Y[0]=[],oe.length=0,An.length=0,Gs.length=0,ve.length=0,pn.length=0}function It(n,t=0){var e;return f(V(n),"key must be a number or string"),f(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&1)}function Gt(n,t=0){var e;return f(V(n),"key must be a number or string"),f(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&2)}function _r(n,t=0){var e;return f(V(n),"key must be a number or string"),f(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&4)}function bh(n="ArrowUp",t="ArrowDown",e="ArrowLeft",s="ArrowRight"){f(V(n),"up key must be a string"),f(V(t),"down key must be a string"),f(V(e),"left key must be a string"),f(V(s),"right key must be a string");let i=o=>It(o)?1:0;return b(i(s)-i(e),i(n)-i(t))}function cs(n){return f(L(n),"mouse button must be a number"),It(n)}function ps(n){return f(L(n),"mouse button must be a number"),Gt(n)}function xh(n){return f(L(n),"mouse button must be a number"),_r(n)}function Ie(n,t=mt){return f(L(n),"button must be a number"),f(L(t),"gamepad must be a number"),It(n,t+1)}function Rr(n,t=mt){return f(L(n),"button must be a number"),f(L(t),"gamepad must be a number"),Gt(n,t+1)}function vh(n,t=mt){return f(L(n),"button must be a number"),f(L(t),"gamepad must be a number"),_r(n,t+1)}function gs(n,t=mt){var e,s;return f(L(n),"stick must be a number"),f(L(t),"gamepad must be a number"),(s=(e=ve[t])==null?void 0:e[n])!=null?s:b()}function bo(n=mt){var t;return f(L(n),"gamepad must be a number"),(t=pn[n])!=null?t:b()}function xo(n=mt){return f(L(n),"gamepad must be a number"),!!Y[n+1]}function uc(n=mt){var t,e;return f(L(n),"gamepad must be a number"),(e=(t=ve[n])==null?void 0:t.length)!=null?e:0}function Sh(n=mt,t=200,e=1,s=1,i=0){var a,r,c;if(f(L(n),"gamepad must be a number"),!Os||z)return;let o=(a=navigator==null?void 0:navigator.getGamepads)==null?void 0:a.call(navigator)[n];(c=(r=o==null?void 0:o.vibrationActuator)==null?void 0:r.playEffect)==null||c.call(r,"dual-rumble",{duration:t,strongMagnitude:e,weakMagnitude:s,startDelay:i})}function wh(n=mt){var e,s,i;if(f(L(n),"gamepad must be a number"),!Os||z)return;let t=(e=navigator==null?void 0:navigator.getGamepads)==null?void 0:e.call(navigator)[n];(i=(s=t==null?void 0:t.vibrationActuator)==null?void 0:s.reset)==null||i.call(s)}function Pr(n=100){var t;f(L(n)||de(n),"pattern must be a number or array"),Os&&!z&&((t=navigator==null?void 0:navigator.vibrate)==null||t.call(navigator,n))}function Th(){Pr(0)}function Ah(){var n;!ie&&((n=B.requestPointerLock)==null||n.call(B))}function Eh(){var n;(n=document.exitPointerLock)==null||n.call(document)}function hc(){return document.pointerLockElement===B}function Ch(){if(z)return;document.addEventListener("keydown",n),document.addEventListener("keyup",t),document.addEventListener("mousedown",s),document.addEventListener("mouseup",i),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",a),document.addEventListener("wheel",r,{passive:!1}),document.addEventListener("contextmenu",c),document.addEventListener("blur",l),ie&&yn&&u();function n(p){if(p.repeat||(Y[0][p.code]=3,rs&&(Y[0][e(p.code)]=3)),!Fn||!p.cancelable||!document.hasFocus()||p.ctrlKey||p.metaKey||p.altKey||x(p.target)||x(document.activeElement))return;let d=typeof p.key=="string"&&p.key.length===1;(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Space","Tab","Backspace"].includes(p.code)||d)&&p.preventDefault();function x(v){let w=v==null?void 0:v.tagName;return(v==null?void 0:v.isContentEditable)||["INPUT","TEXTAREA","SELECT"].includes(w)}}function t(p){Y[0][p.code]=Y[0][p.code]&2|4,rs&&(Y[0][e(p.code)]=4)}function e(p){return rs?p==="KeyW"?"ArrowUp":p==="KeyS"?"ArrowDown":p==="KeyA"?"ArrowLeft":p==="KeyD"?"ArrowRight":p:p}function s(p){if(ie&&yn)return;Ht&&!z&&ft&&!ms()&&ft.resume(),Y[0][p.button]=3;let d=Jt;Jt=h(b(p.x,p.y)),xe=xe.add(Jt.subtract(d)),Fn&&p.cancelable&&document.hasFocus()&&p.preventDefault()}function i(p){ie&&yn||(Y[0][p.button]=Y[0][p.button]&2|4)}function o(p){oi=!0;let d=Jt;Jt=h(b(p.x,p.y));let y=hc()?b(p.movementX,p.movementY):Jt.subtract(d);xe=xe.add(y)}function a(){oi=!1}function r(p){p.ctrlKey||(Ar+=ne(p.deltaY)),Fn&&p.cancelable&&document.hasFocus()&&p.preventDefault()}function c(p){p.preventDefault()}function l(){ks(),Be.clear(),oe.length=0,An.length=0,Gs.length=0}function u(){document.addEventListener("touchstart",y=>d(y),{passive:!1}),document.addEventListener("touchmove",y=>d(y),{passive:!1}),document.addEventListener("touchend",y=>d(y),{passive:!1});let p;function d(y){if(yn){if(Ht&&!z&&ft&&!ms()&&ft.resume(),!an||mr){let x=S=>ys.includes(S.target)||S.target===gn,v=[];for(let S of y.touches)x(S)||v.push(S);let w=v.length,_=0;if(w){let S=b(v[0].clientX,v[0].clientY),C=Jt;Jt=h(S),p?xe=xe.add(Jt.subtract(C)):Y[0][_]=3}else p&&(Y[0][_]=Y[0][_]&2|4);p=w}return Fn&&y.cancelable&&document.hasFocus()&&y.preventDefault(),!0}}}function h(p){let d=B.getBoundingClientRect(),y=Bt(p.x,d.left,d.right),x=Bt(p.y,d.top,d.bottom);return b(y*B.width,x*B.height)}}function Ea(){if(z)return;!(yn&&ie)&&!document.hasFocus()&&ks(),De=Is(Jt),Tr=rc(xe),Rh(),t(),n();function n(){let e=cs(0)||cs(1)||cs(2)||xe.length()>Er,s=!1;for(let o=uc();o--&&!s;)s=gs(o).lengthSquared()>.04;for(let o=17;o--&&!s;)s=Ie(o);let i=!1;for(let o in Y[0])if(isNaN(+o)&&Y[0][o]&1){i=!0;break}s?Qe="gamepad":e?Qe="mouse":i&&(Qe="keyboard"),Bn=Qe==="gamepad"}function t(){var a,r,c,l,u,h,p;let e=d=>{let v=w=>w>.3?Bt(w,.3,.8):w<-.3?-Bt(-w,.3,.8):0;return b(v(d.x),v(-d.y)).clampLength()};if(an&&ie){if(f(!_n||!$n,"set touchGamepadLeftStick or touchGamepadLeftButtonCount, not both"),f(!Kn||!Yn,"set touchGamepadRightStick or touchGamepadButtonCount, not both"),!Vn.isSet())return;mt=0;let d=(a=ve[0])!=null?a:ve[0]=[],y=(r=pn[0])!=null?r:pn[0]=b();d.length=0,y.set();for(let v=0;v<2;v++){if(!We(v))continue;let w=Dr(v);d[w]=b();let _=(c=An[v])!=null?c:b();if(Ls)d[w]=e(_);else if(_.lengthSquared()>.3){let S=N($s(_.x),-1,1),C=N($s(_.y),-1,1);d[w]=b(S,-C).clampLength(),w||y.set(S,-C)}}let x=(l=Y[1])!=null?l:Y[1]=[];for(let v=12;v--;){let w=Ie(v,0);x[v]=oe[v]?w?1:3:w?4:0,ti&&x[v]===3&&(v===9||Ph(v))&&Pr(ti)}return}try{if(!Mi||!(navigator!=null&&navigator.getGamepads))return}catch{return}if(!jt&&!document.hasFocus())return;let s=8,i=navigator.getGamepads(),o=tt(s,i.length);for(let d=0;d>1]=e(b(y.axes[S],y.axes[S+1]));let _=!1;for(let S=y.buttons.length;S--;){let C=y.buttons[S],A=Ie(S,d);x[S]=C.pressed?A?1:3:A?4:0,C.pressed&&(!C.value||C.value>.9)&&(_=!0)}_&&(co[d]=!0,co[mt]||(mt=d)),y.mapping==="standard"&&w.set((Ie(15,d)&&1)-(Ie(14,d)&&1),(Ie(12,d)&&1)-(Ie(13,d)&&1)),yr&&(w.x||w.y)&&(v[0]=w.clampLength())}an&&Bn&&Vn.unset()}}function Ca(){if(!z){for(let n of Y)for(let t in n)n[t]&=1;Ar=0,Tr=b(),xe=b()}}function _h(){Ih()}function Rh(){if(Ye||!an||!ie||z||!document.body)return;let n=Ye=document.createElement("div");n.style.cssText="position:fixed;inset:0;z-index:50;pointer-events:none;opacity:0;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;transition:opacity .2s;box-sizing:border-box;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)";let t=dc=document.createElement("div");t.style.cssText="position:relative;width:100%;height:100%;pointer-events:none",n.appendChild(t);let e=Lr=document.createElementNS(ai,"svg");e.style.cssText="position:absolute;inset:0;width:100%;height:100%;pointer-events:none;overflow:visible;fill:none;stroke:#fff;stroke-width:3",t.appendChild(e);let s=()=>{let i=document.createElement("div");return i.style.cssText="position:absolute;pointer-events:auto;touch-action:none",i.addEventListener("pointerdown",o=>Fh(o,i)),i.addEventListener("pointermove",o=>jh(o)),i.addEventListener("pointerup",o=>_a(o)),i.addEventListener("pointercancel",o=>_a(o)),t.appendChild(i),i};ys[0]=s(),ys[1]=s(),gn=s(),addEventListener("resize",()=>Wn=!0),document.body.appendChild(n),Wn=!0}function ki(){return dc.getBoundingClientRect()}function We(n){return n?Kn:_n}function Ln(n){return n?Yn:$n}function Or(n){return n?0:4}function Dr(n){return n&&_n?1:0}function qn(n){return We(n)||Ln(n)>0}function Ph(n){for(let t=0;t<2;t++){let e=Or(t);if(!We(t)&&n>=e&&no.style.cssText="position:absolute;pointer-events:auto;touch-action:none;"+a;if(Ae){for(let o of ys)o.style.display="none";fe?(i(gn,"inset:0"),gn.style.display=""):gn.style.display="none"}else{for(let a=0;a<2;a++){let r=ys[a],c=a?"right":"left";if(r.style.display=qn(a)?"":"none",ln){let l=qn(a?0:1)?"50%":"100%";i(r,`${c}:0;bottom:0;width:${l};height:60%`)}else i(r,`${c}:0;bottom:0;width:${3*s}px;height:${3*s}px`)}gn.style.display=fe?"":"none";let o=fe;i(gn,`left:50%;top:50%;width:${2*o}px;height:${2*o}px;transform:translate(-50%,-50%)`)}Oh(t,e),Wn=!1}function Oh(n,t){let e=Lr;for(;e.firstChild;)e.removeChild(e.firstChild);let s=fc={face:[],thumb:[]},i=qt,o=(r,c,l,u)=>{let h=document.createElementNS(ai,"circle");return h.setAttribute("cx",r),h.setAttribute("cy",c),h.setAttribute("r",l),u&&h.setAttribute("fill",u),e.appendChild(h),h},a=r=>{let c=i*.18,l=i*.5,u=r.x,h=r.y,p=document.createElementNS(ai,"path");p.setAttribute("d",`M ${u-c} ${h-l} H ${u+c} V ${h-c} H ${u+l} V ${h+c} H ${u+c} V ${h+l} H ${u-c} V ${h+c} H ${u-l} V ${h-c} H ${u-c} Z`),e.appendChild(p)};for(let r=0;r<2;r++){let c=Ln(r),l=Or(r),u=ze(r,n,t);if(We(r))Ls?o(u.x,u.y,i/2):a(u),s.thumb[r]=o(u.x,u.y,i/4,"#fff");else if(c===1)s.face[l]=o(u.x,u.y,i/2,"#000");else for(let h=0;h2?p:tt(p,c-1);d=d===3?2:d===2?3:d;let y=b().setDirection(p,i/2);c===2&&(y.x*=-1),r||(y.x*=-1);let x=u.add(y);s.face[l+d]=o(x.x,x.y,i/4,"#000")}}jt&&vn&&Dh(n,t)}function Dh(n,t){let e=qt,s=Lr,i=(a,r,c)=>{let l=document.createElementNS(ai,a);for(let u in r)l.setAttribute(u,r[u]);l.setAttribute("stroke",c),l.setAttribute("stroke-width",2),l.setAttribute("fill","none"),s.appendChild(l)},o=(a,r,c)=>i("circle",{cx:a.x,cy:a.y,r},c);i("line",{x1:n/2,y1:0,x2:n/2,y2:t},"#0f0");for(let a=0;a<2;a++)if(We(a))if(ln){let r=t*.4,c=!qn(a?0:1),l=c?0:a?n/2:0;i("rect",{x:l,y:r,width:c?n:n/2,height:t-r},"#0ff")}else o(ze(a,n,t),2*e,"#0ff");else Ln(a)>=1&&o(ze(a,n,t),e,"#0ff");if(fe){o(b(n/2,t/2),fe,"#ff0");for(let a=0;a<2;a++)qn(a)&&o(ze(a,n,t),2*e,"#f0f")}}function Ih(){var l;if(!Ye||z)return;if(!an||!ie){Ye.style.display!=="none"&&(Ye.style.display="none",Be.clear(),oe.length=0,An.length=0,Gs.length=0);return}Ye.style.display="";let n=jt&&vn,t=[Yn,$n,_n,Kn,Ls,qt,ln,fe,Ae,n].join();t!==Aa&&(Aa=t,Wn=!0),Wn&&Lh();let e=as?Bt(Vn.get(),as+1,as):1,s=n||Vn.isSet()&&e>0&&!Ae;if(Ye.style.opacity=s?n?1:e*br:0,!s)return;let i=ki(),o=i.width,a=i.height,r=qt,c=fc;if(c){for(let u=0;u<2;u++)if(We(u)&&c.thumb[u]){let p=ze(u,o,a).add(((l=An[u])!=null?l:b()).scale(r/2));c.thumb[u].setAttribute("cx",p.x),c.thumb[u].setAttribute("cy",p.y)}for(let u=0;u=qt)return-1;if(i===1)return o;let r=a.subtract(t);n||(r.x*=-1);let c=i===2?r.xo:r&&ze(a,t,e).distance(n)<2*s)return{role:"stick",side:a}}else if(Ln(a)>=1){let c=kh(a,n,t,e);if(c>=0)return{role:"face",btn:c}}}if(fe){for(let a=0;a<2;a++)if(qn(a)&&ze(a,t,e).distance(n)<2*s)return;if(b(t/2,e/2).distance(n)h.getChannelData(v).set(x)),p.buffer=h,p.playbackRate.value=e,p.loop=i,a=a||ft.createGain(),a.gain.value=t,a.connect(Je);let d=new StereoPannerNode(ft,{pan:N(s,-1,1)});p.connect(d).connect(a),p.addEventListener("ended",()=>{a.disconnect(),d.disconnect(),c&&c(p)});let y=r*e;return p.start(0,y),jt&&Jn&&xt("sound","vol",t.toFixed(2),"rate",e.toFixed(2),"pan",s.toFixed(2),i?"loop":""),p}function Jh(...n){return Ir([Gi(...n)])}function Gi(n=1,t=.05,e=220,s=0,i=0,o=.1,a=0,r=1,c=0,l=0,u=0,h=0,p=0,d=0,y=0,x=0,v=0,w=1,_=0,S=0,C=0){let A=Qn,T=X*2,P=c*=500*T/A/A,M=e*=(1+dt(t,-t))*T/A,pt=0,at=0,ct=0,yt=1,Nt,ge=[],Pt=0,ht=0,Lt=0,Pe,un=2,hn=T*nt(C)*2/A,ae=lt(hn),Le=st(hn)/2/un,te=1+Le,R=-2*ae/te,F=(1-Le)/te,k=(1+ne(C)*ae)/2/te,j=-(ne(C)+ae)/te,$=k,Z=0,Tt=0,At=0,Ot=0;for(s=s*A||9,_*=A,i*=A,o*=A,v*=A,l*=500*T/A**3,y*=T/A,u*=T/A,h*=A,p=p*A|0,Nt=s+_+i+o+v|0;ht1?a>2?a>3?a>4?Pt/T%14?Lt:ne(Lt)*nt(Lt)**r)*(htht?0:(hth&&(e+=u,M+=u,yt=0),p&&!(++at%p)&&(e=M,c=P,yt||(yt=1));return ge}function li(n,t=!0){for(let e of sn)if((!t||e.isSolid)&&n.arrayCheck(e.size)){let s=e.getCollisionData(n);if(s)return s}return 0}function $e(n,t=b(),e,s=!0){for(let i of sn)if((!s||i.isSolid)&&i.collisionTest(n,t,e))return i}function yc(n,t,e,s,i=!0){let o,a,r,c=s&&b();for(let l of sn)if(!i||l.isSolid){let u=l.collisionRaycast(n,t,e,c);if(u){let h=n.distanceSquared(u);(o===void 0||h{G=!1,et.style.display="none",e.preventDefault(),xt("WebGL context lost! Switching to Canvas2d rendering.");for(let s of ls)s.glTexture=void 0;Qt=void 0,Ct=0,En=!1,bn.forEach(s=>{var i;return(i=s.glContextLost)==null?void 0:i.call(s)})}),et.addEventListener("webglcontextrestored",()=>{G=!0,et.style.display="",xt("WebGL context restored, reinitializing..."),t();for(let e of ls)e.glTexture=ji(e.image,e.wrap);bn.forEach(e=>{var s;return(s=e.glContextRestored)==null?void 0:s.call(e)})});function t(){di=Xn(`#version 300 es
 precision highp float;uniform mat4 m;in vec2 g;in vec4 p,u,c,a;in float r;out vec2 v;out vec4 d,e;void main(){vec2 s=(g-.5)*p.zw;gl_Position=m*vec4(p.xy+s*cos(r)-vec2(-s.y,s)*sin(r),1,1);v=mix(u.xw,u.zy,g);d=c;e=a;}`,`#version 300 es
 precision highp float;uniform sampler2D s;in vec2 v;in vec4 d,e;out vec4 c;void main(){c=texture(s,v)*d+e;}`),fi=Xn(`#version 300 es
 precision highp float;uniform mat4 m;in vec2 p;in vec4 c;out vec4 d;void main(){gl_Position=m*vec4(p,1,1);d=c;}`,`#version 300 es
-precision highp float;in vec4 d;out vec4 c;void main(){c=d;}`);let e=new ArrayBuffer(gi);Gt=new Float32Array(e),Ss=new Uint32Array(e),So=g.createBuffer(),Nn=g.createBuffer(),kr=g.createFramebuffer(),Ct=0;let s=new Float32Array([0,0,1,0,0,1,1,1]);g.bindBuffer(g.ARRAY_BUFFER,Nn),g.bufferData(g.ARRAY_BUFFER,s,g.STATIC_DRAW);let i,o,a,r=(c,l,u,h,p=0)=>{let d=g.getAttribLocation(o,c),y=u===1,x=u&&a;g.enableVertexAttribArray(d),g.vertexAttribPointer(d,h,l,y,x,i),g.vertexAttribDivisor(d,p),i+=h*u};wo=g.createVertexArray(),g.bindVertexArray(wo),i=0,o=di,a=mc,g.bindBuffer(g.ARRAY_BUFFER,Nn),r("g",g.FLOAT,0,2),g.bindBuffer(g.ARRAY_BUFFER,So),g.bufferData(g.ARRAY_BUFFER,gi,g.DYNAMIC_DRAW),r("p",g.FLOAT,4,4,1),r("u",g.FLOAT,4,4,1),r("c",g.UNSIGNED_BYTE,1,4,1),r("a",g.UNSIGNED_BYTE,1,4,1),r("r",g.FLOAT,4,1,1),To=g.createVertexArray(),g.bindVertexArray(To),i=0,o=fi,a=bc,r("p",g.FLOAT,4,2),r("c",g.UNSIGNED_BYTE,1,4)}}function ws(n=!1){!n&&!En||(Rt(),En=!1,g.useProgram(di),g.bindVertexArray(wo))}function xc(){En||(Rt(),En=!0,g.useProgram(fi),g.bindVertexArray(To))}function Eo(n=!0){if(!G||!g)return;f(!Ct,"glPreRender called with unflushed batch."),pi||(et.width=I.x,et.height=I.y),g.viewport(0,0,I.x,I.y),n&&vc();let t=b(2*H).divide(I);pi&&(t.y=-t.y);let e=_t.rotate(-Q),s=b(-1).subtract(e.multiply(t)),i=ct(Q),o=st(Q),a=[t.x*i,t.y*o,0,0,-t.x*o,t.y*i,0,0,1,1,1,0,s.x,s.y,0,1],r=(c,l,u)=>{g.useProgram(c);let h=g.getUniformLocation(c,l);g.uniformMatrix4fv(h,!1,u)};r(fi,"m",a),r(di,"m",a),g.activeTexture(g.TEXTURE0),cn[0]&&(Kt=cn[0].glTexture,g.bindTexture(g.TEXTURE_2D,Kt)),g.bindBuffer(g.ARRAY_BUFFER,So),On=Hn=!1,ws(!0)}function vc(){if(!g)return;let n=tn;g.clearColor(n.r,n.g,n.b,n.a),g.clear(g.COLOR_BUFFER_BIT)}function Fr(n){!g||n===Kt||(Rt(),Kt=n,g.bindTexture(g.TEXTURE_2D,Kt))}function Sc(n,t=!0){if(!g||!n)return;let e=n===Kt;e?Rt():g.bindTexture(g.TEXTURE_2D,n);let s=t?g.REPEAT:g.CLAMP_TO_EDGE;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,s),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,s),!e&&Kt&&g.bindTexture(g.TEXTURE_2D,Kt)}function Co(n,t){if(!g)return;let e=g.createShader(t);if(g.shaderSource(e,n),g.compileShader(e),Ft&&!g.getShaderParameter(e,g.COMPILE_STATUS))throw g.getShaderInfoLog(e);return e}function Xn(n,t){if(!g)return;let e=g.createProgram();if(g.attachShader(e,Co(n,g.VERTEX_SHADER)),g.attachShader(e,Co(t,g.FRAGMENT_SHADER)),g.linkProgram(e),Ft&&!g.getProgramParameter(e,g.LINK_STATUS))throw g.getProgramInfoLog(e);return e}function ji(n,t=!1){if(!g)return;let e=g.createTexture(),s=!1;if(n!=null&&n.width)jr(e,n),g.bindTexture(g.TEXTURE_2D,e),s=!Tn&&hs(n.width)&&hs(n.height);else{let r=new Uint8Array([255,255,255,255]);g.bindTexture(g.TEXTURE_2D,e),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,1,1,0,g.RGBA,g.UNSIGNED_BYTE,r)}let i=Tn?g.NEAREST:g.LINEAR,o=s?g.LINEAR_MIPMAP_LINEAR:i;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,i),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,o);let a=t?g.REPEAT:g.CLAMP_TO_EDGE;return g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,a),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,a),s&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,Kt),e}function wc(n){g&&g.deleteTexture(n)}function jr(n,t){g&&(f((t==null?void 0:t.width)>0,"Invalid image data."),g.bindTexture(g.TEXTURE_2D,n),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,t),!Tn&&hs(t.width)&&hs(t.height)&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,Kt))}function Hh(n){z||(ls.add(n),g&&(n.glTexture?jr(n.glTexture,n.image):n.glTexture=ji(n.image,n.wrap)))}function Xh(n){if(z)return;ls.delete(n);let t=n.glTexture;n.glTexture=void 0,wc(t)}function Rt(){if(G&&g&&Ct){let n=Hn?g.ONE:g.ONE_MINUS_SRC_ALPHA;g.blendFuncSeparate(g.SRC_ALPHA,n,g.ONE,n),g.enable(g.BLEND);let t=Ct*(En?Fi:Gr);g.bufferSubData(g.ARRAY_BUFFER,0,Gt,0,t),En?g.drawArrays(g.TRIANGLE_STRIP,0,Ct):g.drawArraysInstanced(g.TRIANGLE_STRIP,0,4,Ct),++Ce,_e+=Ct,Ct=0}Hn=On}function Br(n){!G||!g||(Rt(),n.drawImage(et,0,0))}function Yh(n=!0){f(!et,"must be called before engineInit"),Mr=n}function Ts(n,t,e,s,i=0,o=0,a=0,r=1,c=1,l=-1,u=0){(Ct>=Wh||Hn!==On)&&Rt(),ws();let h=Ct++*Gr;Gt[h++]=n,Gt[h++]=t,Gt[h++]=e,Gt[h++]=s,Gt[h++]=o,Gt[h++]=a,Gt[h++]=r,Gt[h++]=c,Ss[h++]=l,Ss[h++]=u,Gt[h++]=i}function Tc(n,t,e,s,i,o){Ts(n,t,e,s,i,0,0,0,0,0,o)}function Nr(n,t,e,s,i,o,a,r=!0){let c=[],l=st(-a),u=ct(-a);for(let p of n){let d=p.x*i,y=p.y*o;c.push(b(e+u*d-l*y,s+l*d+u*y))}let h=r?Kh(c):c;Ac(h,t)}function zr(n,t,e,s,i,o,a,r,c=!0){let l=$h(n,e,c);Nr(l,t,s,i,o,a,r,!1)}function Ac(n,t){if(!G||n.length<3)return;let e=n.length+2;if((Ct+e>=zn||Hn!==On)&&Rt(),f(e=zn)return;xc();let s=Ct*Fi;for(let i=e;i--;){let o=N(i-1,0,e-3),a=n[o];Gt[s++]=a.x,Gt[s++]=a.y,Ss[s++]=t}Ct+=e}function Jr(n,t){if(!G||n.length<3)return;let e=n.length+2;if((Ct+e>=zn||Hn!==On)&&Rt(),f(e=zn)return;xc();let s=Ct*Fi;for(let i=e;i--;){let o=N(i-1,0,e-3),a=n[o],r=t[o];Gt[s++]=a.x,Gt[s++]=a.y,Ss[s++]=r}Ct+=e}function is(n,t=!1){n?(pi=n,g.bindFramebuffer(g.FRAMEBUFFER,kr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,n,0),Eo(t)):(Rt(),pi=void 0,g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,I.x,I.y))}function Ec(n,t,e,s){G&&(g.enable(g.SCISSOR_TEST),g.scissor(n,t,e,s),g.clearColor(0,0,0,0),g.clear(g.COLOR_BUFFER_BIT),g.disable(g.SCISSOR_TEST))}function $h(n,t,e=!0){if(n.length<2)return[];let s=t/2,i=[],o=n.length,a=1e-6,r=10;for(let c=0;ca?-d/y:0,S=y>a?p/y:0,C=w>a?-v/w:0,A=w>a?x/w:0,T=_+C,P=S+A,M=(T*T+P*P)**.5;if(Ma){let yt=tt(1/at,r);T*=yt,P*=yt}}let pt=b(u.x-T*s,u.y-P*s),rt=b(u.x+T*s,u.y+P*s);i.push(pt),i.push(rt)}return i.length>1&&e&&(i.push(i[0]),i.push(i[1])),i}function Kh(n){if(n.length<3)return[];let t=(d,y,x)=>(y.x-d.x)*(x.y-d.y)-(y.y-d.y)*(x.x-d.x);(d=>{let y=0;for(let x=d.length;x--;){let v=(x+1)%d.length;y+=d[x].cross(d[v])}return y})(n)<0&&(n=n.slice().reverse());let s=1e-9,i=(d,y,x,v)=>{let w=t(y,x,d),_=t(x,v,d),S=t(v,y,d),C=(w<-s?1:0)+(_<-s?1:0)+(S<-s?1:0),A=(w>s?1:0)+(_>s?1:0)+(S>s?1:0);return!(C&&A)},o=[];for(let d=0;d3&&r++{if(C>=0){let T=s.fillStyle=s.createLinearGradient(v,w,_,S);T.addColorStop(0,h(C,2)),T.addColorStop(1,h(C,1))}else s.fillStyle="#000";C>=-1?(s.fill(),A&&s.stroke()):s.stroke()},c=(v,w,_,S=0,C=2*X,A,T)=>{s.beginPath(),s.arc(v,w,_,d*S,d*C),r(v,w-_,v,w+_,A,T)},l=(v,w,_,S,C)=>{s.beginPath(),s.rect(v,w,_,S*d),r(v,w+S,v+_,w,C)},u=(v,w,_,S)=>{s.beginPath();for(let C of v)s.lineTo(C.x,C.y);s.closePath(),r(0,_,0,_+S,w)},h=(v,w)=>w?`hsl(${[.95,.56,.13][v%3]*360} 99%${[0,50,75][w]}%)`:"#000",p=Wa(1,1,n),d=jt(p,.1,.5),y=tt(6,tt(o,a)/99);s.translate(o/2,a/2),s.scale(y,y),s.translate(-40,-35),d<1&&s.setLineDash([99*d,99]),s.lineJoin=s.lineCap="round",s.lineWidth=.1+d*1.9;{let w="LittleJS";s.font="900 15.5px arial",s.lineWidth=.1+d*3.9,s.textAlign="center",s.textBaseline="top",l(11,55,59,8*d,-1),s.beginPath();let _=0;for(let S=0;S5?1:0),s[S?"strokeText":"fillText"](w[C],P,54+.5,17*d),A+=T}s.lineWidth=.1+d*1.9,l(3,54,73,0)}l(7,15,26,-7,0),l(25,15,8,25,-1),l(10,40,15,-25,1),l(14,21,7,9,2),l(38,20,6,-6,2),l(49,20,10,-6,0);let x=[b(44,8),b(64,8),b(59,8+6*d),b(49,8+6*d)];u(x,2,8,6*d),l(44,8,20,-7,0);for(let v=5;v--;)c(59-v*6*d,30,10,0,2*X,1,0);c(59,30,4,0,7,2),l(35,20,24,0),c(59,30,10),c(47,30,10,X/2,X*3/2),c(35,30,10,X/2,X*3/2),l(7,40,13,7,-1),l(17,40,43,14,-1);for(let v=3;v--;)for(let w=2;w--;)c(17+15*v,47,w?7:1,0,2*X,2);for(let v=2;v--;){let w=6,_=7,S=53+w*d*v,C=[b(S+_,54),b(S,40),b(S+w*d,40),b(S+_+w*d,54)];u(C,0,40,14)}s.restore()}function Zh(n){if(bi=n,!fn){let e={};try{e=JSON.parse(localStorage[n]||"{}")}catch{e={}}Bi(s=>{s.unlocked=!!(e[s.id]&&e[s.id].unlocked)}),Vr()}Cn(void 0,t);function t(){if(!qs.length)return;let e=qs[0],s=on-Ws;if(!Ws)Ws=on;else if(s>yi)Ws=0,qs.shift();else{let i=yi-jn,o=si?(s-i)/jn:0;e.render(o)}}}function Bi(n){Object.values(As).forEach(t=>n(t))}function td(){Bi(n=>n.unlocked=!1),Vr()}function Vr(){if(!bi)return;let n={};Bi(t=>{let e={name:t.name,description:t.description,icon:t.icon,unlocked:t.unlocked};t.image&&(e.src=t.image.src),n[t.id]=e}),localStorage[bi]=JSON.stringify(n)}function ed(n){yi=n}function nd(n){jn=n}function sd(n){mi=n.copy()}function id(n){Ur=n}function Cc(n,t,e,s=125){let i,o,a,r,c,l,u,h,p,d,y,x,v,w=0,_,S=[],C=[],A=[],T=0,P=0,M=1,pt={},rt=Qn/s*60>>2;for(;M;T++)S=[M=h=x=0],e.forEach((at,yt)=>{for(u=t[at][T]||[0,0,0],M|=t[at][T]&&1,_=x+(t[at][0].length-2-(h?0:1))*rt,v=yt===e.length-1,i=2,a=x;irt-99&&p&&y<1?y+=1/99:0)l=(1-y)*S[w++]/2||0,C[a]=(C[a]||0)-l*P+l,A[a]=(A[a++]||0)+l*P+l;c&&(y=c%1,P=u[1]||0,(c|=0)&&(S=pt[[d=u[w=0]||0,c]]=pt[[d,c]]||(r=[...n[d]],r[2]=(r[2]||220)*2**(c/12-1),c>0?Gi(...r):[])))}x=_});return[C,A]}function od(n){Wr=typeof n=="boolean"?n?1:0:n}function rd(n){qr=n}async function ad(){return new Ai(await Box2D()),e(),Cn(n,t),m;function n(){if(!Ae){m.step(),m.objects=m.objects.filter(s=>!s.destroyed);for(let s of m.objects)s.body&&(s.pos=m.vec2From(s.body.GetPosition()),s.angle=-s.body.GetAngle())}}function t(){(qr||ue)&&m.world.DrawDebugData()}function e(){let i=new m.instance.JSDraw,o=l=>new wt(l.get_r(),l.get_g(),l.get_b()),a=l=>o(m.instance.wrapPointer(l,m.instance.b2Color)),r=l=>a(l).scale(1,.8),c=(l,u)=>{let h=[];for(let p=u;p--;)h.push(m.vec2FromPointer(l+p*8));return h};i.DrawSegment=function(l,u,h){h=r(h),l=m.vec2FromPointer(l),u=m.vec2FromPointer(u),mn(l,u,.1,h,b(),0,!1)},i.DrawPolygon=function(l,u,h){h=r(h);let p=c(l,u);Un(p,rn,.1,h,b(),0,!1)},i.DrawSolidPolygon=function(l,u,h){h=r(h);let p=c(l,u);Un(p,h,0,h,b(),0,!1)},i.DrawCircle=function(l,u,h){h=r(h),l=m.vec2FromPointer(l),si(l,u*2,rn,.1,h,!1)},i.DrawSolidCircle=function(l,u,h,p){p=r(p),l=m.vec2FromPointer(l),h=m.vec2FromPointer(h).scale(u),si(l,u*2,p,.1,p,!1),mn(b(),h,.1,p,l,0,!1)},i.DrawTransform=function(l){l=m.instance.wrapPointer(l,m.instance.b2Transform);let u=m.vec2From(l.get_p()),h=-l.get_q().GetAngle(),p=b(1,0),d=J(.75,0,0,.8),y=b(0,1),x=J(0,.75,0,.8);mn(b(),p,.1,d,u,h,!1),mn(b(),y,.1,x,u,h,!1)},i.AppendFlags(m.instance.b2Draw.e_shapeBit),i.AppendFlags(m.instance.b2Draw.e_jointBit),m.world.SetDebugDraw(i)}}function cd(n,t,e,s=32,i=2,o=0){_c(n,t,e,W,s,it,i,o,!1,!0)}function _c(n,t,e,s,i=1,o,a=.05,r=0,c=G,l,u){let h=e.offset(e.size),p=t.add(b(a-i*2)),d=b(i),y=t.scale(.5).subtract(d.scale(.5)),x=l?-1:1,v=l?-r:r;It(n,p,h,s,r,!1,o,c,l,u);for(let w=4;w--;){let _=w%2,S=y.multiply(b(_?w===1?1:-1:0,_?0:w?-1:1)),C=b(_?i:p.x,_?p.y:i),A=h.offset(e.size.multiply(b(w===1?1:w===3?-1:0,w===0?-x:w===2?x:0)));It(n.add(S.rotate(v)),C,A,s,r,!1,o,c,l,u)}for(let w=4;w--;){let _=w>1,S=w&&w<3,C=y.multiply(b(_?-1:1,S?-1:1)),A=h.offset(e.size.multiply(b(_?-1:1,S?x:-x)));It(n.add(C.rotate(v)),d,A,s,r,!1,o,c,l,u)}}function ld(n,t,e,s=32,i=2,o=0){Rc(n,t,e,W,s,it,i,o,!1,!0)}function Rc(n,t,e,s,i=1,o,a=.05,r=0,c=G,l,u){let h=e.frame(0),p=e.frame(1),d=e.frame(2),y=t.add(b(a-i*2)),x=b(i),v=t.scale(.5).subtract(x.scale(.5)),w=l?-1:1,_=l?-r:r;It(n,y,d,s,r,!1,o,c,l,u);for(let S=4;S--;){let C=r+S*X/2,A=S%2,T=v.multiply(b(A?S===1?1:-1:0,A?0:S?-w:w)),P=b(A?y.y:y.x,i);It(n.add(T.rotate(_)),P,p,s,C,!1,o,c,l,u)}for(let S=4;S--;){let C=r+S*X/2,A=!S||S>2,T=S>1,P=v.multiply(b(A?-1:1,T?-w:w));It(n.add(P.rotate(_)),x,h,s,C,!1,o,c,l,u)}}function ud(n,t=1,e=0,s=W,i=0,o=!1,a=0,r=it,c=G,l=!1,u){let h=Pc(b(),t,e,0,o);Un(h,s,a,r,n,i,c,l,u)}function Pc(n,t=1,e=0,s=0,i=!1,o=Ps){f(O(n),"pos must be a vec2"),f(L(t)&&L(e),"size and percent must be numbers");let a=se(e*4,4);a>=2&&(s+=X),a=a<=2?a-1:3-a,i&&(a=-a,s+=X);let r=[],c=K(3,o>>1),l=t/2;for(let u=0;u<=c;u++){let h=u/c*X;r.push(b(l*ct(h),l*st(h)).rotate(s).add(n))}for(let u=c;u>=0;u--){let h=u/c*X;r.push(b(l*ct(h),-l*a*st(h)).rotate(s).add(n))}return r}function La(n){return n&&typeof n.lerp=="function"}function hd(n,t,e,s,i=1,o={}){f(n!=null&&typeof n=="object","tweenProperty target must be an object"),f(V(t)&&t.length>0,"tweenProperty propertyPath must be a non-empty string");let a=t.split("."),r=a.pop(),c=l=>{let u=n;for(let h of a)u=u[h];u[r]=l};return new Ei(c,e,s,i,o)}function Lc(n){n.loopRemaining!==1/0&&n.loopRemaining<=1||(n.loopRemaining!==1/0&&(n.loopRemaining-=1),n.life=n.duration,n.thenCallback=()=>Lc(n),Yt.push(n),n.callback(n.interp(n.duration)))}function Oc(n){if(n.loopRemaining!==1/0&&n.loopRemaining<=1)return;n.loopRemaining!==1/0&&(n.loopRemaining-=1);let t=n.start;n.start=n.end,n.end=t,n.life=n.duration,n.thenCallback=()=>Oc(n),Yt.push(n),n.callback(n.interp(n.duration))}function Dc(n,t){n===void 0?(n=$t-Ra,t=on-Pa,Ra=$t,Pa=on):t===void 0&&(t=n);for(let e=Yt.length;e--;){let s=Yt[e];if(s.paused)continue;let i=s.useRealTime?t:n;if(!(i<=0))if(s.life-=i,s.life>0)s.callback(s.interp(s.life));else{s.callback(s.interp(0)),Yt.splice(e,1);let o=s.thenCallback;s.thenCallback=void 0,o&&o()}}}function dd(){for(let n of Yt)n.thenCallback=void 0;Yt.length=0}var Hs,Xs,Cl,tr,vt,er,Oa,$t,on,Ae,ao,be,Ys,Da,bn,uo,Ft,ka,Ri,Ga,Ie,Ze,ue,he,xn,vn,Jn,ho,Me,le,X,nt,St,us,$s,tt,K,ne,Na,za,st,ct,Ja,sr,go,ot,wt,W,rn,it,pe,Vl,rr,Wl,Ka,Qa,ql,Za,tc,Hl,Ee,_t,Q,H,cr,Pi,tn,Mn,os,kn,Gn,lr,Tn,en,Rs,ur,z,G,Ps,Li,Oi,Di,Ii,hr,dr,fr,pr,gr,Ge,Ut,Zs,Mi,yr,rs,yn,an,mr,fe,Yn,_n,$n,Kn,Ls,ln,Wt,br,as,ti,Os,qt,Sn,xr,vr,Je,B,ut,Et,Be,Ke,Se,Fe,I,cn,Ce,_e,Re,Ue,nh,lc,ii,Oe,zt,Tr,xe,Ar,oi,Bn,Qe,Er,Fn,mt,ie,Y,ve,pn,co,Vn,oe,An,ri,Gs,je,Ye,dc,Lr,fc,ys,gn,Wn,Aa,ai,ft,ze,Qn,bs,ci,sn,wn,ui,xs,vs,vo,Vh,hi,et,g,Mr,di,fi,En,On,Hn,Kt,So,Nn,Gt,Ss,Ct,ls,wo,To,kr,pi,Ao,gi,Gr,mc,Wh,Fi,bc,zn,fn,yi,jn,mi,Ur,As,qs,bi,Ws,xi,Es,_o,Ro,Mt,Po,q,Lo,Oo,Do,E,Wr,Io,re,vi,Mo,ko,Cs,Go,Fo,jo,Bo,m,qr,_s,Si,No,zo,wi,Ht,Jo,Ti,Uo,Vo,Wo,qo,Ho,Xo,Yo,$o,Ko,Qo,Ai,Yt,Ra,Pa,Ei,Ci,fd,lo,_i,Zo,Mc=jc(()=>{"use strict";Hs="LittleJS",Xs="1.18.19",Cl=60,tr=.016666666666666666,vt=[],er=[],Oa=0,$t=0,on=0,Ae=!1;ao=0,be=0,Ys=0,Da=!0,bn=[],uo=class{constructor(t,e,s,i){this.update=t,this.render=e,this.glContextLost=s,this.glContextRestored=i}};Ft=!0,ka=.5,Ri=!0,Ga="Escape",Ie=!1,Ze=[],ue=!1,he=!1,xn=!1,vn=!1,Jn=!1;X=Math.PI,nt=Math.abs,St=Math.floor,us=Math.ceil,$s=Math.round,tt=Math.min,K=Math.max,ne=n=>Math.sign(n),Na=(...n)=>Math.hypot(...n),za=n=>Math.log2(n),st=Math.sin,ct=Math.cos,Ja=Math.tan,sr=Math.atan2;go=class{constructor(t=123456789){f(t!==0,"RandomGenerator seed must be non-zero (xorshift is fixed at 0)"),this.seed=t}float(t=1,e=0){return this.seed^=this.seed<<13,this.seed^=this.seed>>>17,this.seed^=this.seed<<5,e+(t-e)*((this.seed>>>0)/2**32)}int(t,e=0){return St(this.float(t,e))}bool(t=.5){return this.float().5?1:-1}floatSign(t=1,e=0){let s=tt(t,e),o=K(t,e)-s,a=this.float(o*2);return at?this.scale(t/e):this.copy()}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}reflect(t,e=1){return this.subtract(t.scale((1+e)*this.dot(t)))}angle(){return sr(this.x,this.y)}setAngle(t=0,e=1){return Xt(t),Xt(e),this.x=e*st(t),this.y=e*ct(t),this}rotate(t){Xt(t);let e=ct(-t),s=st(-t);return new n(this.x*e-this.y*s,this.x*s+this.y*e)}setDirection(t,e=1){return Xt(t),Xt(e),t=se(t,4),f(t===0||t===1||t===2||t===3,"Vector2.setDirection() direction must be an integer between 0 and 3."),this.x=t%2?t-1?-e:e:0,this.y=t%2?0:t?-e:e,this}direction(){return nt(this.x)>nt(this.y)?this.x<0?3:1:this.y<0?2:0}abs(){return new n(nt(this.x),nt(this.y))}floor(){return new n(St(this.x),St(this.y))}snap(t){return Xt(t),new n(St(this.x*t)/t,St(this.y*t)/t)}mod(t=1){return new n(se(this.x,t),se(this.y,t))}area(){return nt(this.x*this.y)}lerp(t,e){wa(t),Xt(e);let s=N(e);return new n(t.x*s+this.x*(1-s),t.y*s+this.y*(1-s))}arrayCheck(t){return this.x>=0&&this.y>=0&&this.x(u=se(u,1))*6<1?c+(l-c)*6*u:u*2<1?l:u*3<2?c+(l-c)*(4-u*6):c;return this.r=r(a,o,t+1/3),this.g=r(a,o,t),this.b=r(a,o,t-1/3),this.a=i,ss(this),this}HSLA(){let t=N(this.r),e=N(this.g),s=N(this.b),i=N(this.a),o=K(t,e,s),a=tt(t,e,s),r=(o+a)/2,c=0,l=0;if(o!==a){let u=o-a;l=r>.5?u/(2-o-a):u/(o+a),t===o?c=(e-s)/u+(e((s=N(s)*255|0)<16?"0":"")+s.toString(16);return"#"+e(this.r)+e(this.g)+e(this.b)+(t?e(this.a):"")}setHex(t){if(f(V(t),"Color hex code must be a string"),f(t[0]==="#","Color hex code must start with #"),f([4,5,7,9].includes(t.length),"Invalid hex"),t.length<6){let e=s=>N(parseInt(t[s],16)/15);this.r=e(1),this.g=e(2),this.b=e(3),this.a=t.length===5?e(4):1}else{let e=s=>N(parseInt(t.slice(s,s+2),16)/255);this.r=e(1),this.g=e(3),this.b=e(5),this.a=t.length===9?e(7):1}return ss(this),this}rgbaInt(){let t=N(this.r)*255|0,e=N(this.g)*255<<8,s=N(this.b)*255<<16,i=N(this.a)*255<<24;return t+e+s+i}isValid(){return L(this.r)&&L(this.g)&&L(this.b)&&L(this.a)}},W=Qt(J()),rn=Qt(J(1,1,1,0)),it=Qt(J(0,0,0)),pe=Qt(J(0,0,0,0)),Vl=Qt(J(.5,.5,.5)),rr=Qt(J(1,0,0)),Wl=Qt(J(1,.5,0)),Ka=Qt(J(1,1,0)),Qa=Qt(J(0,1,0)),ql=Qt(J(0,1,1)),Za=Qt(J(0,0,1)),tc=Qt(J(.5,0,1)),Hl=Qt(J(1,0,1)),Ee=class{constructor(t,e=!1){f(t===void 0||L(t),"Constructed Timer is invalid.",t),this.useRealTime=e;let s=this.getGlobalTime();this.time=t===void 0?void 0:s+t,this.setTime=t}set(t=0){f(L(t),"Timer is invalid.",t);let e=this.getGlobalTime();this.time=e+t,this.setTime=t}setUseRealTime(t=!0){f(!this.isSet(),"Cannot change global time setting while timer is set."),this.useRealTime=t}unset(){this.time=void 0}isSet(){return this.time!==void 0}active(){return this.getGlobalTime()=this.time}get(){return this.isSet()?this.getGlobalTime()-this.time:0}getPercent(){return this.isSet()?this.setTime?1-jt(this.time-this.getGlobalTime(),0,this.setTime):1:0}getSetTime(){return this.isSet()?this.setTime:0}getGlobalTime(){return this.useRealTime?on:$t}toString(){return this.isSet()?nt(this.get())+" seconds "+(this.get()<0?"before":"after"):"unset"}valueOf(){return this.get()}};_t=b(),Q=0,H=32,cr=1,Pi=!0,tn=pe,Mn=b(1920,1080),os=0,kn=0,Gn=b(),lr=!1,Tn=!0,en=1,Rs="arial",ur=!1,z=!1,G=!0,Ps=32,Li=b(16),Oi=0,Di=0,Ii=!0,hr=1,dr=1,fr=1,pr=0,gr=.8,Ge=1,Ut=b(),Zs=1,Mi=!0,yr=!0,rs=!0,yn=!0,an=!1,mr=!1,fe=0,Yn=4,_n=!0,$n=0,Kn=!1,Ls=!0,ln=!1,Wt=100,br=.3,as=3,ti=0,Os=!0,qt=!0,Sn=.3,xr=40,vr=.7;Je=class n{constructor(t=b(),e=b(1),s,i=0,o=W,a=0){f(O(t),"object pos must be a vec2"),f(O(e),"object size must be a vec2"),f(!s||s instanceof Re,"object tileInfo should be a TileInfo or undefined"),f(typeof i=="number"&&isFinite(i),"object angle should be a number"),f(U(o),"object color should be a valid rgba color"),f(typeof a=="number","object renderOrder should be a number"),this.pos=t.copy(),this.size=e.copy(),this.drawSize=void 0,this.tileInfo=s,this.angle=i,this.color=o.copy(),this.additiveColor=void 0,this.mirror=!1,this.destroyed=!1,this.mass=hr,this.damping=dr,this.angleDamping=fr,this.restitution=pr,this.friction=gr,this.gravityScale=1,this.renderOrder=a,this.velocity=b(),this.angleVelocity=0,this.spawnTime=$t,this.children=[],this.clampSpeed=!0,this.groundObject=void 0,this.parent=void 0,this.localPos=b(),this.localAngle=0,this.collideTiles=!1,this.collideSolidObjects=!1,this.isSolid=!1,this.collideRaycast=!1,vt.push(this)}updateTransforms(){let t=this.parent;if(t){let e=t.getMirrorSign(),s=this.localPos,i=t.pos,o=s.x*e,a=s.y,r=t.angle;if(r){let c=ct(-r),l=st(-r);this.pos.set(o*c-a*l+i.x,o*l+a*c+i.y)}else this.pos.set(o+i.x,a+i.y);this.angle=e*this.localAngle+r}for(let e of this.children)e.updateTransforms()}updatePhysics(){if(f(!this.parent),this.destroyed)return;this.clampSpeed&&(this.velocity.x=N(this.velocity.x,-Ge,Ge),this.velocity.y=N(this.velocity.y,-Ge,Ge));let t=this.pos.copy();if(this.velocity.x*=this.damping,this.velocity.y*=this.damping,this.mass&&(this.velocity.x+=Ut.x*this.gravityScale,this.velocity.y+=Ut.y*this.gravityScale),this.pos.x+=this.velocity.x,this.pos.y+=this.velocity.y,this.angle+=this.angleVelocity*=this.angleDamping,f(this.angleDamping>=0&&this.angleDamping<=1),f(this.damping>=0&&this.damping<=1),!Ii||!this.mass)return;let e=this.velocity.y<0&&Ut.y<0||this.velocity.y>0&&Ut.y>0;if(this.groundObject){let s=K(this.friction,this.groundObject.friction),i=this.groundObject.velocity.x;this.velocity.x=i+(this.velocity.x-i)*s,this.groundObject=void 0}if(this.collideSolidObjects)for(let i of er){if(i.destroyed||i.parent||i===this||!this.isSolid&&!i.isSolid||!this.isOverlappingObject(i))continue;let o=this.collideWithObject(i),a=i.collideWithObject(this);if(!o||!a)continue;if(Qs(t,this.size,i.pos,i.size)){let p=t.subtract(i.pos),d=p.length(),x=d<.001?b(0,1):p.scale(.001/d);this.velocity=this.velocity.add(x),i.mass&&(i.velocity=i.velocity.subtract(x)),ue&&fo(this.pos,this.size,i.pos,i.size,"#f00");continue}let r=this.size.add(i.size),c=(t.y-i.pos.y)*2>r.y+Ut.y,l=nt(t.y-i.pos.y)*20?-1:1)>0?St(t.y-this.size.y/2+1)+this.size.y/2+.001:us(t.y+this.size.y/2-1)-this.size.y/2-.001;if(nt(u-this.pos.y)<.1&&!$e(b(this.pos.x,u),this.size,this)){this.pos.y=u,ue&&bt(this.pos,this.size,"#ff0");return}this.pos.x=t.x,this.velocity.x*=-a}if(o||!i){if(e){let c=this.size.y/2+1e-4;this.pos.y=Ut.y<0?St(t.y-this.size.y/2)+c:us(t.y+this.size.y/2)-c,this.groundObject=s}else this.pos.y=t.y,this.groundObject=void 0;this.velocity.y*=-a}ue&&bt(this.pos,this.size,"#f00")}}}update(){}render(){It(this.pos,this.drawSize||this.size,this.tileInfo,this.color,this.angle,this.mirror,this.additiveColor)}renderLight(){}destroy(t=!1){var e;if(!this.destroyed){this.destroyed=!0,(e=this.parent)==null||e.removeChild(this);for(let s of this.children)s.parent=void 0,s.destroy(t)}}localToWorld(t){return this.pos.add(t.rotate(this.angle))}worldToLocal(t){return t.subtract(this.pos).rotate(-this.angle)}localToWorldVector(t){return t.rotate(this.angle)}worldToLocalVector(t){return t.rotate(-this.angle)}collideWithTile(t,e){return t>0}collideWithObject(t){return!0}getUp(t=1){return b().setAngle(this.angle,t)}getRight(t=1){return b().setAngle(this.angle+X/2,t)}getAliveTime(){return $t-this.spawnTime}getSpeed(){return this.velocity.length()}applyAcceleration(t){this.mass&&(this.velocity=this.velocity.add(t))}applyAngularAcceleration(t){this.mass&&(this.angleVelocity+=t)}applyForce(t){this.mass&&this.applyAcceleration(t.scale(1/this.mass))}getMirrorSign(){return this.mirror?-1:1}addChild(t,e=b(),s=0){return f(!this.destroyed,"cannot add child to destroyed object"),this.destroyed||(f(!t.parent&&!this.children.includes(t)),f(t instanceof n,"child must be an EngineObject"),f(t!==this,"cannot add self as child"),this.children.push(t),t.parent=this,t.localPos=e.copy(),t.localAngle=s,t.updateTransforms()),t}removeChild(t){f(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}isOverlappingObject(t){return this.isOverlapping(t.pos,t.size)}isOverlapping(t,e=b()){return Qs(this.pos,this.size,t,e)}setCollision(t=!0,e=!0,s=!0,i=!0){f(t||!e,"solid objects must be set to collide"),this.collideSolidObjects=t,this.isSolid=e,this.collideTiles=s,this.collideRaycast=i}toString(){let t="type = "+this.constructor.name;return(this.pos.x||this.pos.y)&&(t+=`
+precision highp float;in vec4 d;out vec4 c;void main(){c=d;}`);let e=new ArrayBuffer(gi);Ft=new Float32Array(e),Ss=new Uint32Array(e),So=g.createBuffer(),Nn=g.createBuffer(),kr=g.createFramebuffer(),Ct=0;let s=new Float32Array([0,0,1,0,0,1,1,1]);g.bindBuffer(g.ARRAY_BUFFER,Nn),g.bufferData(g.ARRAY_BUFFER,s,g.STATIC_DRAW);let i,o,a,r=(c,l,u,h,p=0)=>{let d=g.getAttribLocation(o,c),y=u===1,x=u&&a;g.enableVertexAttribArray(d),g.vertexAttribPointer(d,h,l,y,x,i),g.vertexAttribDivisor(d,p),i+=h*u};wo=g.createVertexArray(),g.bindVertexArray(wo),i=0,o=di,a=mc,g.bindBuffer(g.ARRAY_BUFFER,Nn),r("g",g.FLOAT,0,2),g.bindBuffer(g.ARRAY_BUFFER,So),g.bufferData(g.ARRAY_BUFFER,gi,g.DYNAMIC_DRAW),r("p",g.FLOAT,4,4,1),r("u",g.FLOAT,4,4,1),r("c",g.UNSIGNED_BYTE,1,4,1),r("a",g.UNSIGNED_BYTE,1,4,1),r("r",g.FLOAT,4,1,1),To=g.createVertexArray(),g.bindVertexArray(To),i=0,o=fi,a=bc,r("p",g.FLOAT,4,2),r("c",g.UNSIGNED_BYTE,1,4)}}function ws(n=!1){!n&&!En||(Rt(),En=!1,g.useProgram(di),g.bindVertexArray(wo))}function xc(){En||(Rt(),En=!0,g.useProgram(fi),g.bindVertexArray(To))}function Eo(n=!0){if(!G||!g)return;f(!Ct,"glPreRender called with unflushed batch."),pi||(et.width=I.x,et.height=I.y),g.viewport(0,0,I.x,I.y),n&&vc();let t=b(2*H).divide(I);pi&&(t.y=-t.y);let e=_t.rotate(-Q),s=b(-1).subtract(e.multiply(t)),i=lt(Q),o=st(Q),a=[t.x*i,t.y*o,0,0,-t.x*o,t.y*i,0,0,1,1,1,0,s.x,s.y,0,1],r=(c,l,u)=>{g.useProgram(c);let h=g.getUniformLocation(c,l);g.uniformMatrix4fv(h,!1,u)};r(fi,"m",a),r(di,"m",a),g.activeTexture(g.TEXTURE0),cn[0]&&(Qt=cn[0].glTexture,g.bindTexture(g.TEXTURE_2D,Qt)),g.bindBuffer(g.ARRAY_BUFFER,So),On=Hn=!1,ws(!0)}function vc(){if(!g)return;let n=tn;g.clearColor(n.r,n.g,n.b,n.a),g.clear(g.COLOR_BUFFER_BIT)}function Fr(n){!g||n===Qt||(Rt(),Qt=n,g.bindTexture(g.TEXTURE_2D,Qt))}function Sc(n,t=!0){if(!g||!n)return;let e=n===Qt;e?Rt():g.bindTexture(g.TEXTURE_2D,n);let s=t?g.REPEAT:g.CLAMP_TO_EDGE;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,s),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,s),!e&&Qt&&g.bindTexture(g.TEXTURE_2D,Qt)}function Co(n,t){if(!g)return;let e=g.createShader(t);if(g.shaderSource(e,n),g.compileShader(e),jt&&!g.getShaderParameter(e,g.COMPILE_STATUS))throw g.getShaderInfoLog(e);return e}function Xn(n,t){if(!g)return;let e=g.createProgram();if(g.attachShader(e,Co(n,g.VERTEX_SHADER)),g.attachShader(e,Co(t,g.FRAGMENT_SHADER)),g.linkProgram(e),jt&&!g.getProgramParameter(e,g.LINK_STATUS))throw g.getProgramInfoLog(e);return e}function ji(n,t=!1){if(!g)return;let e=g.createTexture(),s=!1;if(n!=null&&n.width)jr(e,n),g.bindTexture(g.TEXTURE_2D,e),s=!Tn&&hs(n.width)&&hs(n.height);else{let r=new Uint8Array([255,255,255,255]);g.bindTexture(g.TEXTURE_2D,e),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,1,1,0,g.RGBA,g.UNSIGNED_BYTE,r)}let i=Tn?g.NEAREST:g.LINEAR,o=s?g.LINEAR_MIPMAP_LINEAR:i;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,i),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,o);let a=t?g.REPEAT:g.CLAMP_TO_EDGE;return g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,a),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,a),s&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,Qt),e}function wc(n){g&&g.deleteTexture(n)}function jr(n,t){g&&(f((t==null?void 0:t.width)>0,"Invalid image data."),g.bindTexture(g.TEXTURE_2D,n),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,t),!Tn&&hs(t.width)&&hs(t.height)&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,Qt))}function Hh(n){z||(ls.add(n),g&&(n.glTexture?jr(n.glTexture,n.image):n.glTexture=ji(n.image,n.wrap)))}function Xh(n){if(z)return;ls.delete(n);let t=n.glTexture;n.glTexture=void 0,wc(t)}function Rt(){if(G&&g&&Ct){let n=Hn?g.ONE:g.ONE_MINUS_SRC_ALPHA;g.blendFuncSeparate(g.SRC_ALPHA,n,g.ONE,n),g.enable(g.BLEND);let t=Ct*(En?Fi:Gr);g.bufferSubData(g.ARRAY_BUFFER,0,Ft,0,t),En?g.drawArrays(g.TRIANGLE_STRIP,0,Ct):g.drawArraysInstanced(g.TRIANGLE_STRIP,0,4,Ct),++Ce,_e+=Ct,Ct=0}Hn=On}function Br(n){!G||!g||(Rt(),n.drawImage(et,0,0))}function Yh(n=!0){f(!et,"must be called before engineInit"),Mr=n}function Ts(n,t,e,s,i=0,o=0,a=0,r=1,c=1,l=-1,u=0){(Ct>=Wh||Hn!==On)&&Rt(),ws();let h=Ct++*Gr;Ft[h++]=n,Ft[h++]=t,Ft[h++]=e,Ft[h++]=s,Ft[h++]=o,Ft[h++]=a,Ft[h++]=r,Ft[h++]=c,Ss[h++]=l,Ss[h++]=u,Ft[h++]=i}function Tc(n,t,e,s,i,o){Ts(n,t,e,s,i,0,0,0,0,0,o)}function Nr(n,t,e,s,i,o,a,r=!0){let c=[],l=st(-a),u=lt(-a);for(let p of n){let d=p.x*i,y=p.y*o;c.push(b(e+u*d-l*y,s+l*d+u*y))}let h=r?Kh(c):c;Ac(h,t)}function zr(n,t,e,s,i,o,a,r,c=!0){let l=$h(n,e,c);Nr(l,t,s,i,o,a,r,!1)}function Ac(n,t){if(!G||n.length<3)return;let e=n.length+2;if((Ct+e>=zn||Hn!==On)&&Rt(),f(e=zn)return;xc();let s=Ct*Fi;for(let i=e;i--;){let o=N(i-1,0,e-3),a=n[o];Ft[s++]=a.x,Ft[s++]=a.y,Ss[s++]=t}Ct+=e}function Jr(n,t){if(!G||n.length<3)return;let e=n.length+2;if((Ct+e>=zn||Hn!==On)&&Rt(),f(e=zn)return;xc();let s=Ct*Fi;for(let i=e;i--;){let o=N(i-1,0,e-3),a=n[o],r=t[o];Ft[s++]=a.x,Ft[s++]=a.y,Ss[s++]=r}Ct+=e}function is(n,t=!1){n?(pi=n,g.bindFramebuffer(g.FRAMEBUFFER,kr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,n,0),Eo(t)):(Rt(),pi=void 0,g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,I.x,I.y))}function Ec(n,t,e,s){G&&(g.enable(g.SCISSOR_TEST),g.scissor(n,t,e,s),g.clearColor(0,0,0,0),g.clear(g.COLOR_BUFFER_BIT),g.disable(g.SCISSOR_TEST))}function $h(n,t,e=!0){if(n.length<2)return[];let s=t/2,i=[],o=n.length,a=1e-6,r=10;for(let c=0;ca?-d/y:0,S=y>a?p/y:0,C=w>a?-v/w:0,A=w>a?x/w:0,T=_+C,P=S+A,M=(T*T+P*P)**.5;if(Ma){let yt=tt(1/ct,r);T*=yt,P*=yt}}let pt=b(u.x-T*s,u.y-P*s),at=b(u.x+T*s,u.y+P*s);i.push(pt),i.push(at)}return i.length>1&&e&&(i.push(i[0]),i.push(i[1])),i}function Kh(n){if(n.length<3)return[];let t=(d,y,x)=>(y.x-d.x)*(x.y-d.y)-(y.y-d.y)*(x.x-d.x);(d=>{let y=0;for(let x=d.length;x--;){let v=(x+1)%d.length;y+=d[x].cross(d[v])}return y})(n)<0&&(n=n.slice().reverse());let s=1e-9,i=(d,y,x,v)=>{let w=t(y,x,d),_=t(x,v,d),S=t(v,y,d),C=(w<-s?1:0)+(_<-s?1:0)+(S<-s?1:0),A=(w>s?1:0)+(_>s?1:0)+(S>s?1:0);return!(C&&A)},o=[];for(let d=0;d3&&r++{if(C>=0){let T=s.fillStyle=s.createLinearGradient(v,w,_,S);T.addColorStop(0,h(C,2)),T.addColorStop(1,h(C,1))}else s.fillStyle="#000";C>=-1?(s.fill(),A&&s.stroke()):s.stroke()},c=(v,w,_,S=0,C=2*X,A,T)=>{s.beginPath(),s.arc(v,w,_,d*S,d*C),r(v,w-_,v,w+_,A,T)},l=(v,w,_,S,C)=>{s.beginPath(),s.rect(v,w,_,S*d),r(v,w+S,v+_,w,C)},u=(v,w,_,S)=>{s.beginPath();for(let C of v)s.lineTo(C.x,C.y);s.closePath(),r(0,_,0,_+S,w)},h=(v,w)=>w?`hsl(${[.95,.56,.13][v%3]*360} 99%${[0,50,75][w]}%)`:"#000",p=Wa(1,1,n),d=Bt(p,.1,.5),y=tt(6,tt(o,a)/99);s.translate(o/2,a/2),s.scale(y,y),s.translate(-40,-35),d<1&&s.setLineDash([99*d,99]),s.lineJoin=s.lineCap="round",s.lineWidth=.1+d*1.9;{let w="LittleJS";s.font="900 15.5px arial",s.lineWidth=.1+d*3.9,s.textAlign="center",s.textBaseline="top",l(11,55,59,8*d,-1),s.beginPath();let _=0;for(let S=0;S5?1:0),s[S?"strokeText":"fillText"](w[C],P,54+.5,17*d),A+=T}s.lineWidth=.1+d*1.9,l(3,54,73,0)}l(7,15,26,-7,0),l(25,15,8,25,-1),l(10,40,15,-25,1),l(14,21,7,9,2),l(38,20,6,-6,2),l(49,20,10,-6,0);let x=[b(44,8),b(64,8),b(59,8+6*d),b(49,8+6*d)];u(x,2,8,6*d),l(44,8,20,-7,0);for(let v=5;v--;)c(59-v*6*d,30,10,0,2*X,1,0);c(59,30,4,0,7,2),l(35,20,24,0),c(59,30,10),c(47,30,10,X/2,X*3/2),c(35,30,10,X/2,X*3/2),l(7,40,13,7,-1),l(17,40,43,14,-1);for(let v=3;v--;)for(let w=2;w--;)c(17+15*v,47,w?7:1,0,2*X,2);for(let v=2;v--;){let w=6,_=7,S=53+w*d*v,C=[b(S+_,54),b(S,40),b(S+w*d,40),b(S+_+w*d,54)];u(C,0,40,14)}s.restore()}function Zh(n){if(bi=n,!fn){let e={};try{e=JSON.parse(localStorage[n]||"{}")}catch{e={}}Bi(s=>{s.unlocked=!!(e[s.id]&&e[s.id].unlocked)}),Vr()}Cn(void 0,t);function t(){if(!qs.length)return;let e=qs[0],s=on-Ws;if(!Ws)Ws=on;else if(s>yi)Ws=0,qs.shift();else{let i=yi-jn,o=si?(s-i)/jn:0;e.render(o)}}}function Bi(n){Object.values(As).forEach(t=>n(t))}function td(){Bi(n=>n.unlocked=!1),Vr()}function Vr(){if(!bi)return;let n={};Bi(t=>{let e={name:t.name,description:t.description,icon:t.icon,unlocked:t.unlocked};t.image&&(e.src=t.image.src),n[t.id]=e}),localStorage[bi]=JSON.stringify(n)}function ed(n){yi=n}function nd(n){jn=n}function sd(n){mi=n.copy()}function id(n){Ur=n}function Cc(n,t,e,s=125){let i,o,a,r,c,l,u,h,p,d,y,x,v,w=0,_,S=[],C=[],A=[],T=0,P=0,M=1,pt={},at=Qn/s*60>>2;for(;M;T++)S=[M=h=x=0],e.forEach((ct,yt)=>{for(u=t[ct][T]||[0,0,0],M|=t[ct][T]&&1,_=x+(t[ct][0].length-2-(h?0:1))*at,v=yt===e.length-1,i=2,a=x;iat-99&&p&&y<1?y+=1/99:0)l=(1-y)*S[w++]/2||0,C[a]=(C[a]||0)-l*P+l,A[a]=(A[a++]||0)+l*P+l;c&&(y=c%1,P=u[1]||0,(c|=0)&&(S=pt[[d=u[w=0]||0,c]]=pt[[d,c]]||(r=[...n[d]],r[2]=(r[2]||220)*2**(c/12-1),c>0?Gi(...r):[])))}x=_});return[C,A]}function od(n){Wr=typeof n=="boolean"?n?1:0:n}function rd(n){qr=n}async function ad(){return new Ai(await Box2D()),e(),Cn(n,t),m;function n(){if(!Ae){m.step(),m.objects=m.objects.filter(s=>!s.destroyed);for(let s of m.objects)s.body&&(s.pos=m.vec2From(s.body.GetPosition()),s.angle=-s.body.GetAngle())}}function t(){(qr||ue)&&m.world.DrawDebugData()}function e(){let i=new m.instance.JSDraw,o=l=>new wt(l.get_r(),l.get_g(),l.get_b()),a=l=>o(m.instance.wrapPointer(l,m.instance.b2Color)),r=l=>a(l).scale(1,.8),c=(l,u)=>{let h=[];for(let p=u;p--;)h.push(m.vec2FromPointer(l+p*8));return h};i.DrawSegment=function(l,u,h){h=r(h),l=m.vec2FromPointer(l),u=m.vec2FromPointer(u),mn(l,u,.1,h,b(),0,!1)},i.DrawPolygon=function(l,u,h){h=r(h);let p=c(l,u);Un(p,rn,.1,h,b(),0,!1)},i.DrawSolidPolygon=function(l,u,h){h=r(h);let p=c(l,u);Un(p,h,0,h,b(),0,!1)},i.DrawCircle=function(l,u,h){h=r(h),l=m.vec2FromPointer(l),si(l,u*2,rn,.1,h,!1)},i.DrawSolidCircle=function(l,u,h,p){p=r(p),l=m.vec2FromPointer(l),h=m.vec2FromPointer(h).scale(u),si(l,u*2,p,.1,p,!1),mn(b(),h,.1,p,l,0,!1)},i.DrawTransform=function(l){l=m.instance.wrapPointer(l,m.instance.b2Transform);let u=m.vec2From(l.get_p()),h=-l.get_q().GetAngle(),p=b(1,0),d=J(.75,0,0,.8),y=b(0,1),x=J(0,.75,0,.8);mn(b(),p,.1,d,u,h,!1),mn(b(),y,.1,x,u,h,!1)},i.AppendFlags(m.instance.b2Draw.e_shapeBit),i.AppendFlags(m.instance.b2Draw.e_jointBit),m.world.SetDebugDraw(i)}}function cd(n,t,e,s=32,i=2,o=0){_c(n,t,e,W,s,it,i,o,!1,!0)}function _c(n,t,e,s,i=1,o,a=.05,r=0,c=G,l,u){let h=e.offset(e.size),p=t.add(b(a-i*2)),d=b(i),y=t.scale(.5).subtract(d.scale(.5)),x=l?-1:1,v=l?-r:r;Mt(n,p,h,s,r,!1,o,c,l,u);for(let w=4;w--;){let _=w%2,S=y.multiply(b(_?w===1?1:-1:0,_?0:w?-1:1)),C=b(_?i:p.x,_?p.y:i),A=h.offset(e.size.multiply(b(w===1?1:w===3?-1:0,w===0?-x:w===2?x:0)));Mt(n.add(S.rotate(v)),C,A,s,r,!1,o,c,l,u)}for(let w=4;w--;){let _=w>1,S=w&&w<3,C=y.multiply(b(_?-1:1,S?-1:1)),A=h.offset(e.size.multiply(b(_?-1:1,S?x:-x)));Mt(n.add(C.rotate(v)),d,A,s,r,!1,o,c,l,u)}}function ld(n,t,e,s=32,i=2,o=0){Rc(n,t,e,W,s,it,i,o,!1,!0)}function Rc(n,t,e,s,i=1,o,a=.05,r=0,c=G,l,u){let h=e.frame(0),p=e.frame(1),d=e.frame(2),y=t.add(b(a-i*2)),x=b(i),v=t.scale(.5).subtract(x.scale(.5)),w=l?-1:1,_=l?-r:r;Mt(n,y,d,s,r,!1,o,c,l,u);for(let S=4;S--;){let C=r+S*X/2,A=S%2,T=v.multiply(b(A?S===1?1:-1:0,A?0:S?-w:w)),P=b(A?y.y:y.x,i);Mt(n.add(T.rotate(_)),P,p,s,C,!1,o,c,l,u)}for(let S=4;S--;){let C=r+S*X/2,A=!S||S>2,T=S>1,P=v.multiply(b(A?-1:1,T?-w:w));Mt(n.add(P.rotate(_)),x,h,s,C,!1,o,c,l,u)}}function ud(n,t=1,e=0,s=W,i=0,o=!1,a=0,r=it,c=G,l=!1,u){let h=Pc(b(),t,e,0,o);Un(h,s,a,r,n,i,c,l,u)}function Pc(n,t=1,e=0,s=0,i=!1,o=Ps){f(O(n),"pos must be a vec2"),f(L(t)&&L(e),"size and percent must be numbers");let a=se(e*4,4);a>=2&&(s+=X),a=a<=2?a-1:3-a,i&&(a=-a,s+=X);let r=[],c=K(3,o>>1),l=t/2;for(let u=0;u<=c;u++){let h=u/c*X;r.push(b(l*lt(h),l*st(h)).rotate(s).add(n))}for(let u=c;u>=0;u--){let h=u/c*X;r.push(b(l*lt(h),-l*a*st(h)).rotate(s).add(n))}return r}function La(n){return n&&typeof n.lerp=="function"}function hd(n,t,e,s,i=1,o={}){f(n!=null&&typeof n=="object","tweenProperty target must be an object"),f(V(t)&&t.length>0,"tweenProperty propertyPath must be a non-empty string");let a=t.split("."),r=a.pop(),c=l=>{let u=n;for(let h of a)u=u[h];u[r]=l};return new Ei(c,e,s,i,o)}function Lc(n){n.loopRemaining!==1/0&&n.loopRemaining<=1||(n.loopRemaining!==1/0&&(n.loopRemaining-=1),n.life=n.duration,n.thenCallback=()=>Lc(n),$t.push(n),n.callback(n.interp(n.duration)))}function Oc(n){if(n.loopRemaining!==1/0&&n.loopRemaining<=1)return;n.loopRemaining!==1/0&&(n.loopRemaining-=1);let t=n.start;n.start=n.end,n.end=t,n.life=n.duration,n.thenCallback=()=>Oc(n),$t.push(n),n.callback(n.interp(n.duration))}function Dc(n,t){n===void 0?(n=Kt-Ra,t=on-Pa,Ra=Kt,Pa=on):t===void 0&&(t=n);for(let e=$t.length;e--;){let s=$t[e];if(s.paused)continue;let i=s.useRealTime?t:n;if(!(i<=0))if(s.life-=i,s.life>0)s.callback(s.interp(s.life));else{s.callback(s.interp(0)),$t.splice(e,1);let o=s.thenCallback;s.thenCallback=void 0,o&&o()}}}function dd(){for(let n of $t)n.thenCallback=void 0;$t.length=0}var Hs,Xs,Cl,tr,vt,er,Oa,Kt,on,Ae,ao,be,Ys,Da,bn,uo,jt,ka,Ri,Ga,Me,Ze,ue,he,xn,vn,Jn,ho,ke,le,X,nt,St,us,$s,tt,K,ne,Na,za,st,lt,Ja,sr,go,rt,wt,W,rn,it,pe,Vl,rr,Wl,Ka,Qa,ql,Za,tc,Hl,Ee,_t,Q,H,cr,Pi,tn,Mn,os,kn,Gn,lr,Tn,en,Rs,ur,z,G,Ps,Li,Oi,Di,Ii,hr,dr,fr,pr,gr,Fe,Vt,Zs,Mi,yr,rs,yn,an,mr,fe,Yn,_n,$n,Kn,Ls,ln,qt,br,as,ti,Os,Ht,Sn,xr,vr,Ue,B,ut,Et,Ne,Ke,Se,je,I,cn,Ce,_e,Re,Ve,nh,lc,ii,De,Jt,Tr,xe,Ar,oi,Bn,Qe,Er,Fn,mt,ie,Y,ve,pn,co,Vn,oe,An,ri,Gs,Be,Ye,dc,Lr,fc,ys,gn,Wn,Aa,ai,ft,Je,Qn,bs,ci,sn,wn,ui,xs,vs,vo,Vh,hi,et,g,Mr,di,fi,En,On,Hn,Qt,So,Nn,Ft,Ss,Ct,ls,wo,To,kr,pi,Ao,gi,Gr,mc,Wh,Fi,bc,zn,fn,yi,jn,mi,Ur,As,qs,bi,Ws,xi,Es,_o,Ro,kt,Po,q,Lo,Oo,Do,E,Wr,Io,re,vi,Mo,ko,Cs,Go,Fo,jo,Bo,m,qr,_s,Si,No,zo,wi,Xt,Jo,Ti,Uo,Vo,Wo,qo,Ho,Xo,Yo,$o,Ko,Qo,Ai,$t,Ra,Pa,Ei,Ci,fd,lo,_i,Zo,Mc=jc(()=>{"use strict";Hs="LittleJS",Xs="1.18.19",Cl=60,tr=.016666666666666666,vt=[],er=[],Oa=0,Kt=0,on=0,Ae=!1;ao=0,be=0,Ys=0,Da=!0,bn=[],uo=class{constructor(t,e,s,i){this.update=t,this.render=e,this.glContextLost=s,this.glContextRestored=i}};jt=!0,ka=.5,Ri=!0,Ga="Escape",Me=!1,Ze=[],ue=!1,he=!1,xn=!1,vn=!1,Jn=!1;X=Math.PI,nt=Math.abs,St=Math.floor,us=Math.ceil,$s=Math.round,tt=Math.min,K=Math.max,ne=n=>Math.sign(n),Na=(...n)=>Math.hypot(...n),za=n=>Math.log2(n),st=Math.sin,lt=Math.cos,Ja=Math.tan,sr=Math.atan2;go=class{constructor(t=123456789){f(t!==0,"RandomGenerator seed must be non-zero (xorshift is fixed at 0)"),this.seed=t}float(t=1,e=0){return this.seed^=this.seed<<13,this.seed^=this.seed>>>17,this.seed^=this.seed<<5,e+(t-e)*((this.seed>>>0)/2**32)}int(t,e=0){return St(this.float(t,e))}bool(t=.5){return this.float().5?1:-1}floatSign(t=1,e=0){let s=tt(t,e),o=K(t,e)-s,a=this.float(o*2);return at?this.scale(t/e):this.copy()}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}reflect(t,e=1){return this.subtract(t.scale((1+e)*this.dot(t)))}angle(){return sr(this.x,this.y)}setAngle(t=0,e=1){return Yt(t),Yt(e),this.x=e*st(t),this.y=e*lt(t),this}rotate(t){Yt(t);let e=lt(-t),s=st(-t);return new n(this.x*e-this.y*s,this.x*s+this.y*e)}setDirection(t,e=1){return Yt(t),Yt(e),t=se(t,4),f(t===0||t===1||t===2||t===3,"Vector2.setDirection() direction must be an integer between 0 and 3."),this.x=t%2?t-1?-e:e:0,this.y=t%2?0:t?-e:e,this}direction(){return nt(this.x)>nt(this.y)?this.x<0?3:1:this.y<0?2:0}abs(){return new n(nt(this.x),nt(this.y))}floor(){return new n(St(this.x),St(this.y))}snap(t){return Yt(t),new n(St(this.x*t)/t,St(this.y*t)/t)}mod(t=1){return new n(se(this.x,t),se(this.y,t))}area(){return nt(this.x*this.y)}lerp(t,e){wa(t),Yt(e);let s=N(e);return new n(t.x*s+this.x*(1-s),t.y*s+this.y*(1-s))}arrayCheck(t){return this.x>=0&&this.y>=0&&this.x(u=se(u,1))*6<1?c+(l-c)*6*u:u*2<1?l:u*3<2?c+(l-c)*(4-u*6):c;return this.r=r(a,o,t+1/3),this.g=r(a,o,t),this.b=r(a,o,t-1/3),this.a=i,ss(this),this}HSLA(){let t=N(this.r),e=N(this.g),s=N(this.b),i=N(this.a),o=K(t,e,s),a=tt(t,e,s),r=(o+a)/2,c=0,l=0;if(o!==a){let u=o-a;l=r>.5?u/(2-o-a):u/(o+a),t===o?c=(e-s)/u+(e((s=N(s)*255|0)<16?"0":"")+s.toString(16);return"#"+e(this.r)+e(this.g)+e(this.b)+(t?e(this.a):"")}setHex(t){if(f(V(t),"Color hex code must be a string"),f(t[0]==="#","Color hex code must start with #"),f([4,5,7,9].includes(t.length),"Invalid hex"),t.length<6){let e=s=>N(parseInt(t[s],16)/15);this.r=e(1),this.g=e(2),this.b=e(3),this.a=t.length===5?e(4):1}else{let e=s=>N(parseInt(t.slice(s,s+2),16)/255);this.r=e(1),this.g=e(3),this.b=e(5),this.a=t.length===9?e(7):1}return ss(this),this}rgbaInt(){let t=N(this.r)*255|0,e=N(this.g)*255<<8,s=N(this.b)*255<<16,i=N(this.a)*255<<24;return t+e+s+i}isValid(){return L(this.r)&&L(this.g)&&L(this.b)&&L(this.a)}},W=Zt(J()),rn=Zt(J(1,1,1,0)),it=Zt(J(0,0,0)),pe=Zt(J(0,0,0,0)),Vl=Zt(J(.5,.5,.5)),rr=Zt(J(1,0,0)),Wl=Zt(J(1,.5,0)),Ka=Zt(J(1,1,0)),Qa=Zt(J(0,1,0)),ql=Zt(J(0,1,1)),Za=Zt(J(0,0,1)),tc=Zt(J(.5,0,1)),Hl=Zt(J(1,0,1)),Ee=class{constructor(t,e=!1){f(t===void 0||L(t),"Constructed Timer is invalid.",t),this.useRealTime=e;let s=this.getGlobalTime();this.time=t===void 0?void 0:s+t,this.setTime=t}set(t=0){f(L(t),"Timer is invalid.",t);let e=this.getGlobalTime();this.time=e+t,this.setTime=t}setUseRealTime(t=!0){f(!this.isSet(),"Cannot change global time setting while timer is set."),this.useRealTime=t}unset(){this.time=void 0}isSet(){return this.time!==void 0}active(){return this.getGlobalTime()=this.time}get(){return this.isSet()?this.getGlobalTime()-this.time:0}getPercent(){return this.isSet()?this.setTime?1-Bt(this.time-this.getGlobalTime(),0,this.setTime):1:0}getSetTime(){return this.isSet()?this.setTime:0}getGlobalTime(){return this.useRealTime?on:Kt}toString(){return this.isSet()?nt(this.get())+" seconds "+(this.get()<0?"before":"after"):"unset"}valueOf(){return this.get()}};_t=b(),Q=0,H=32,cr=1,Pi=!0,tn=pe,Mn=b(1920,1080),os=0,kn=0,Gn=b(),lr=!1,Tn=!0,en=1,Rs="arial",ur=!1,z=!1,G=!0,Ps=32,Li=b(16),Oi=0,Di=0,Ii=!0,hr=1,dr=1,fr=1,pr=0,gr=.8,Fe=1,Vt=b(),Zs=1,Mi=!0,yr=!0,rs=!0,yn=!0,an=!1,mr=!1,fe=0,Yn=4,_n=!0,$n=0,Kn=!1,Ls=!0,ln=!1,qt=100,br=.3,as=3,ti=0,Os=!0,Ht=!0,Sn=.3,xr=40,vr=.7;Ue=class n{constructor(t=b(),e=b(1),s,i=0,o=W,a=0){f(O(t),"object pos must be a vec2"),f(O(e),"object size must be a vec2"),f(!s||s instanceof Re,"object tileInfo should be a TileInfo or undefined"),f(typeof i=="number"&&isFinite(i),"object angle should be a number"),f(U(o),"object color should be a valid rgba color"),f(typeof a=="number","object renderOrder should be a number"),this.pos=t.copy(),this.size=e.copy(),this.drawSize=void 0,this.tileInfo=s,this.angle=i,this.color=o.copy(),this.additiveColor=void 0,this.mirror=!1,this.destroyed=!1,this.mass=hr,this.damping=dr,this.angleDamping=fr,this.restitution=pr,this.friction=gr,this.gravityScale=1,this.renderOrder=a,this.velocity=b(),this.angleVelocity=0,this.spawnTime=Kt,this.children=[],this.clampSpeed=!0,this.groundObject=void 0,this.parent=void 0,this.localPos=b(),this.localAngle=0,this.collideTiles=!1,this.collideSolidObjects=!1,this.isSolid=!1,this.collideRaycast=!1,vt.push(this)}updateTransforms(){let t=this.parent;if(t){let e=t.getMirrorSign(),s=this.localPos,i=t.pos,o=s.x*e,a=s.y,r=t.angle;if(r){let c=lt(-r),l=st(-r);this.pos.set(o*c-a*l+i.x,o*l+a*c+i.y)}else this.pos.set(o+i.x,a+i.y);this.angle=e*this.localAngle+r}for(let e of this.children)e.updateTransforms()}updatePhysics(){if(f(!this.parent),this.destroyed)return;this.clampSpeed&&(this.velocity.x=N(this.velocity.x,-Fe,Fe),this.velocity.y=N(this.velocity.y,-Fe,Fe));let t=this.pos.copy();if(this.velocity.x*=this.damping,this.velocity.y*=this.damping,this.mass&&(this.velocity.x+=Vt.x*this.gravityScale,this.velocity.y+=Vt.y*this.gravityScale),this.pos.x+=this.velocity.x,this.pos.y+=this.velocity.y,this.angle+=this.angleVelocity*=this.angleDamping,f(this.angleDamping>=0&&this.angleDamping<=1),f(this.damping>=0&&this.damping<=1),!Ii||!this.mass)return;let e=this.velocity.y<0&&Vt.y<0||this.velocity.y>0&&Vt.y>0;if(this.groundObject){let s=K(this.friction,this.groundObject.friction),i=this.groundObject.velocity.x;this.velocity.x=i+(this.velocity.x-i)*s,this.groundObject=void 0}if(this.collideSolidObjects)for(let i of er){if(i.destroyed||i.parent||i===this||!this.isSolid&&!i.isSolid||!this.isOverlappingObject(i))continue;let o=this.collideWithObject(i),a=i.collideWithObject(this);if(!o||!a)continue;if(Qs(t,this.size,i.pos,i.size)){let p=t.subtract(i.pos),d=p.length(),x=d<.001?b(0,1):p.scale(.001/d);this.velocity=this.velocity.add(x),i.mass&&(i.velocity=i.velocity.subtract(x)),ue&&fo(this.pos,this.size,i.pos,i.size,"#f00");continue}let r=this.size.add(i.size),c=(t.y-i.pos.y)*2>r.y+Vt.y,l=nt(t.y-i.pos.y)*20?-1:1)>0?St(t.y-this.size.y/2+1)+this.size.y/2+.001:us(t.y+this.size.y/2-1)-this.size.y/2-.001;if(nt(u-this.pos.y)<.1&&!$e(b(this.pos.x,u),this.size,this)){this.pos.y=u,ue&&bt(this.pos,this.size,"#ff0");return}this.pos.x=t.x,this.velocity.x*=-a}if(o||!i){if(e){let c=this.size.y/2+1e-4;this.pos.y=Vt.y<0?St(t.y-this.size.y/2)+c:us(t.y+this.size.y/2)-c,this.groundObject=s}else this.pos.y=t.y,this.groundObject=void 0;this.velocity.y*=-a}ue&&bt(this.pos,this.size,"#f00")}}}update(){}render(){Mt(this.pos,this.drawSize||this.size,this.tileInfo,this.color,this.angle,this.mirror,this.additiveColor)}renderLight(){}destroy(t=!1){var e;if(!this.destroyed){this.destroyed=!0,(e=this.parent)==null||e.removeChild(this);for(let s of this.children)s.parent=void 0,s.destroy(t)}}localToWorld(t){return this.pos.add(t.rotate(this.angle))}worldToLocal(t){return t.subtract(this.pos).rotate(-this.angle)}localToWorldVector(t){return t.rotate(this.angle)}worldToLocalVector(t){return t.rotate(-this.angle)}collideWithTile(t,e){return t>0}collideWithObject(t){return!0}getUp(t=1){return b().setAngle(this.angle,t)}getRight(t=1){return b().setAngle(this.angle+X/2,t)}getAliveTime(){return Kt-this.spawnTime}getSpeed(){return this.velocity.length()}applyAcceleration(t){this.mass&&(this.velocity=this.velocity.add(t))}applyAngularAcceleration(t){this.mass&&(this.angleVelocity+=t)}applyForce(t){this.mass&&this.applyAcceleration(t.scale(1/this.mass))}getMirrorSign(){return this.mirror?-1:1}addChild(t,e=b(),s=0){return f(!this.destroyed,"cannot add child to destroyed object"),this.destroyed||(f(!t.parent&&!this.children.includes(t)),f(t instanceof n,"child must be an EngineObject"),f(t!==this,"cannot add self as child"),this.children.push(t),t.parent=this,t.localPos=e.copy(),t.localAngle=s,t.updateTransforms()),t}removeChild(t){f(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}isOverlappingObject(t){return this.isOverlapping(t.pos,t.size)}isOverlapping(t,e=b()){return Qs(this.pos,this.size,t,e)}setCollision(t=!0,e=!0,s=!0,i=!0){f(t||!e,"solid objects must be set to collide"),this.collideSolidObjects=t,this.isSolid=e,this.collideTiles=s,this.collideRaycast=i}toString(){let t="type = "+this.constructor.name;return(this.pos.x||this.pos.y)&&(t+=`
 pos = `+this.pos),(this.velocity.x||this.velocity.y)&&(t+=`
 velocity = `+this.velocity),(this.size.x||this.size.y)&&(t+=`
 size = `+this.size),this.angle&&(t+=`
 angle = `+this.angle.toFixed(3)),this.color&&(t+=`
-color = `+this.color),t}renderDebugInfo(){if(!Ft)return;let t=this.collideTiles||this.collideSolidObjects||this.isSolid;if(!t&&!this.parent)return;let e=b(K(this.size.x,.2),K(this.size.y,.2)),s=J(this.collideTiles?1:0,this.collideSolidObjects?1:0,this.isSolid?1:0,.5);bt(this.pos,e,s,0,this.angle,t),this.parent&&bt(this.pos,e.scale(.8),J(1,1,1,.5),0,this.angle),this.parent&&we(this.pos,this.parent.pos,J(1,1,1,.5),.5)}},I=b(),cn=[];Re=class n{constructor(t=b(),e=Li,s=cn[0],i=Oi,o=Di){this.pos=t.copy(),this.size=e.copy(),this.padding=i,this.textureInfo=s,this.bleed=o}offset(t){return new n(this.pos.add(t),this.size,this.textureInfo,this.padding,this.bleed)}frame(t){f(typeof t=="number");let e=this.size.x+this.padding*2,s=t*e;return f(s+this.size.x<=this.textureInfo.size.x,"frame extends beyond texture width!"),this.offset(new ot(s))}setFullImage(t=this.textureInfo){return this.textureInfo=t,this.pos=new ot,this.size=t.size.copy(),this.bleed=this.padding=0,this}tile(t){return Ds(t,this.size,this.textureInfo,this.padding,this.bleed)}},Ue=class{constructor(t,e=!0,s=!1){this.image=t,this.size=t?b(t.width,t.height):b(),this.sizeInverse=t?b(1/t.width,1/t.height):b(),this.glTexture=void 0,this.wrap=s,e&&this.createWebGLTexture()}createWebGLTexture(){Hh(this)}destroyWebGLTexture(){Xh(this)}hasWebGL(){return!!this.glTexture}setWrap(t=!0){this.wrap=t,Sc(this.glTexture,t)}};nh=0;ii=class{constructor(t){f(!!t,"tileInfo is required for ImageFont"),this.tileInfo=t.frame(0)}drawText(t,e,s=1,i,o,a,r){f(O(s)||typeof s=="number","size must be a vec2 or number"),typeof s=="number"?(f(s>0),s*=H,s=new ot(s,s)):s=s.scale(H),this.drawTextScreen(t,Pn(e),s,i,o,a,r)}drawTextScreen(t,e,s,i=!0,o=W,a=G,r){f(V(t),"text must be a string"),f(O(e),"pos must be a vec2"),f(O(s)||typeof s=="number","size must be a vec2 or number"),f(U(o),"color must be a color"),s=typeof s=="number"?new ot(s,s):s;let c=new ot,l=this.tileInfo,u=l.padding,h=l.size.x+u*2,p=l.size.y+u*2,d=l.textureInfo.size.x/h|0;(t+"").split(`
-`).forEach((y,x)=>{let v=i?(y.length-1)*s.x/2:0;for(let w=y.length;w--;){let _=y.charCodeAt(w),S=_<32||_>127?95:_-32,C=S%d,A=S/d|0;l.pos.x=C*h+u,l.pos.y=A*p+u,c.x=e.x+w*s.x-v|0,c.y=e.y+x*s.y|0,It(c,s,l,o,0,!1,void 0,a,!0,r)}})}};Oe=b(),zt=b(),Tr=b(),xe=b(),Ar=0,oi=!0,Bn=!1,Qe="mouse",Er=6,Fn=!0,mt=0,ie=!z&&window.ontouchstart!==void 0;Y=[[]],ve=[],pn=[],co=[],Vn=new Ee,oe=[],An=[],ri=[],Gs=[],je=new Map,ys=[],Wn=!0;ai="http://www.w3.org/2000/svg";ft=new AudioContext,Qn=44100;bs=class{constructor(t,e,s=xr,i=vr,o){var a;if(!(!qt||z)){if(f(!t||de(t)||V(t),"asset must be a file name or zzfx array"),f(e===void 0||L(e),"randomness must be a number"),f(e===void 0||e>=0&&e<=1,"randomness must be between 0 and 1"),f(L(s),"range must be a number"),f(L(i),"taper must be a number"),this.range=s,this.taper=i,this.randomness=e!=null?e:0,this.sampleRate=Qn,this.loadedPercent=0,this.onloadCallback=o,de(t)){let r=t.slice(),c=e!=null?e:.05,l=1;this.randomness=(a=r[l])!=null?a:c,r[l]=0,this.sampleChannels=[Gi(...r)],this.loadedPercent=1,o==null||o(this)}else if(typeof t=="string"){let r=t;this.loadSound(r)}}}play(t,e=1,s=1,i=1,o=!1,a=!1){if(f(!t||O(t),"pos must be a vec2"),f(L(e),"volume must be a number"),f(L(s),"pitch must be a number"),f(L(i),"randomnessScale must be a number"),!qt||z||!this.sampleChannels)return;let r;if(t){let u=this.range;if(u){let h=_t.distanceSquared(t);if(h>u*u)return;e*=jt(h**.5,u,u*this.taper)}r=Pn(t).x*2/B.width-1}let c=s+s*this.randomness*i*dt(-1,1),l=new ci(this,e,c,r,o,a);return Ft&&Jn&&t&&(Jt(t,.5,"#0ff",.5,!0),this.range&&(Jt(t,2*this.range,"#0ff",.5),Jt(t,2*this.range*this.taper,"#0ff",.5)),In("vol "+e.toFixed(2)+" pitch "+c.toFixed(2),t,.5,"#0ff",.5)),l}playMusic(t=1,e=!0,s=!1){return this.play(void 0,t,1,0,e,s)}playNote(t=0,e,s){f(L(t),"semitoneOffset must be a number");let i=gc(t,1);return this.play(e,s,i,0)}getDuration(){var t,e;return((e=(t=this.sampleChannels)==null?void 0:t[0])==null?void 0:e.length)/this.sampleRate||0}isLoaded(){return this.loadedPercent===1}async loadSound(t){var c;let e=await fetch(t);if(!e.ok)throw new Error(`Failed to load sound from ${t}: ${e.status} ${e.statusText}`);let s=await e.arrayBuffer(),i=await ft.decodeAudioData(s),o=i.numberOfChannels,a=1e5,r=[];for(let l=0;lsetTimeout(v,0));let d=tt(p+a,h);for(;p=0,"Sound volume must be positive or zero"),f(s>=0,"Sound rate must be positive or zero"),f(L(i),"Sound pan must be a number"),this.sound=t,this.volume=e,this.rate=s,this.pan=i,this.loop=o,this.pausedTime=0,this.startTime=void 0,this.gainNode=void 0,this.source=void 0,this.onendedCallback=r=>{r===this.source&&(this.source=void 0)},a||this.start()}start(t=0){f(t>=0,"Sound start offset must be positive or zero"),this.isPlaying()&&this.stop(),this.gainNode=ft.createGain(),this.source=Ir(this.sound.sampleChannels,this.volume,this.rate,this.pan,this.loop,this.sound.sampleRate,this.gainNode,t,this.onendedCallback),this.source?(this.startTime=ft.currentTime-t,this.pausedTime=void 0):(this.startTime=void 0,this.pausedTime=0)}setVolume(t){f(t>=0,"Sound volume must be positive or zero"),this.volume=t,this.gainNode&&(this.gainNode.gain.value=t)}stop(t=0){if(f(t>=0,"Sound fade time must be positive or zero"),this.isPlaying())if(t){let e=ft.currentTime,s=e+t;this.gainNode.gain.cancelScheduledValues(e),this.gainNode.gain.setValueAtTime(this.volume,e),this.gainNode.gain.linearRampToValueAtTime(0,s),this.source.stop(s)}else this.source.stop();this.pausedTime=0,this.source=void 0,this.startTime=void 0}pause(){this.isPaused()||(this.pausedTime=this.getCurrentTime(),this.source.stop(),this.source=void 0,this.startTime=void 0)}resume(){this.isPaused()&&this.start(this.pausedTime)}isPlaying(){return!!this.source}isPaused(){return!this.isPlaying()}getCurrentTime(){if(!this.isPlaying())return this.pausedTime;let t=this.getDuration();return t?se(ft.currentTime-this.startTime,t):0}getDuration(){return this.rate?this.sound.getDuration()/this.rate:0}getSource(){return this.source}};sn=[];wn=class{constructor(t,e=0,s=!1,i=new wt){this.tile=t,this.direction=e,this.mirror=s,this.color=i.copy()}clear(){this.tile=this.direction=0,this.mirror=!1,this.color=new wt}},ui=class extends Je{constructor(t,e,s=0,i=0,o=b(512),a=!0){var r;f(O(o),"canvasSize must be a Vector2"),super(t,e,void 0,s,W,i),this.canvas=z?void 0:new OffscreenCanvas(o.x,o.y),this.context=(r=this.canvas)==null?void 0:r.getContext("2d"),this.textureInfo=new Ue(this.canvas,a),this.mass=0}destroy(){this.destroyed||(this.textureInfo.destroyWebGLTexture(),super.destroy())}render(){this.draw(this.pos,this.size,this.color,this.angle,this.mirror,this.additiveColor)}draw(t,e,s=W,i=0,o=!1,a,r=!1,c){let l=new Re().setFullImage(this.textureInfo),u=this.hasWebGL();It(t,e,l,s,i,o,a,u,r,c)}updateWebGL(){this.textureInfo.createWebGLTexture()}hasWebGL(){return G&&this.textureInfo.hasWebGL()}},xs=class extends ui{constructor(t,e,s=Ds(),i=0,o=!0){let a=s?e.multiply(s.size):e;if(super(t,e,0,i,a,o),this.tileInfo=void 0,this.data=[],this.isUsingWebGL=!1,z){this.render=()=>{},this.redraw=()=>{},this.redrawStart=()=>{},this.redrawEnd=()=>{},this.drawTileData=()=>{},this.redrawTileData=()=>{},this.drawLayerTile=()=>{},this.drawLayerRect=()=>{},this.drawTile=()=>{},this.drawRect=()=>{},this.clearLayerRect=()=>{};return}s&&(this.tileInfo=s.frame(0),this.tileInfo.bleed=0);for(let r=this.size.area();r--;)this.data.push(new wn)}setData(t,e,s=!1){if(t=t.floor(),f(O(t),"layerPos must be a Vector2"),f(e instanceof wn,"data must be a TileLayerData"),!t.arrayCheck(this.size)||(this.data[(t.y|0)*this.size.x+(t.x|0)]=e,!s))return;Et===this.context?this.drawTileData(t):this.redrawTileData(t)}clearData(t,e=!1){this.setData(t,new wn,e)}getData(t){return f(O(t),"layerPos must be a Vector2"),t.arrayCheck(this.size)?this.data[(t.y|0)*this.size.x+(t.x|0)]:void 0}update(){!G&&this.isUsingWebGL&&(this.isUsingWebGL=!1,this.redraw())}render(){f(Et!==this.context,"must call redrawEnd() after drawing tiles!");let t=this.drawSize||this.size,e=this.pos.add(t.scale(.5));this.draw(e,this.size,this.color,this.angle,this.mirror,this.additiveColor)}onRedraw(){}redraw(){this.redrawStart(!0);for(let t=this.size.x;t--;)for(let e=this.size.y;e--;)this.drawTileData(b(t,e),!1);this.isUsingWebGL&&Rt(),this.onRedraw(),this.redrawEnd()}redrawStart(t=!1){var s,i;if(!this.context)return;f(Et!==this.context),this.savedRenderSettings=[Et,I,_t,H,tn],Et=this.context;let e=(i=(s=this.tileInfo)==null?void 0:s.size)!=null?i:b(1);I=this.size.multiply(e),tn=pe,_t=this.size.multiply(e).scale(.5),H=1,this.isUsingWebGL=this.hasWebGL(),this.isUsingWebGL?is(this.textureInfo.glTexture,t):(this.context.imageSmoothingEnabled=!Tn,t&&(this.canvas.width=I.x,this.canvas.height=I.y))}redrawEnd(){this.context&&(f(Et===this.context),this.isUsingWebGL&&is(),[Et,I,_t,H,tn]=this.savedRenderSettings)}drawTileData(t,e=!0){var r,c;if(!this.context)return;f(Et===this.context,"must call redrawStart() before drawing tiles");let s=(c=(r=this.tileInfo)==null?void 0:r.size)!=null?c:b(1),i=t.multiply(s);e&&this.clearLayerRect(i,s);let o=this.getData(t);if(!o||!o.tile)return;let a=this.tileInfo&&this.tileInfo.tile(o.tile);this.drawLayerTile(i,s,a,o.color,o.direction*X/2,o.mirror)}redrawTileData(t,e=!0){this.context&&(f(Et!==this.context,"redrawStart() should not be active when calling redrawTileData(), instead use drawTileData()"),this.redrawStart(),this.drawTileData(t,e),this.redrawEnd())}drawLayerTile(t,e=b(1),s,i=W,o=0,a,r){let c=t.add(e.scale(.5));It(c,e,s,i,o,a,r,this.isUsingWebGL)}drawLayerRect(t,e,s,i=0){this.drawLayerTile(t,e,void 0,s,i)}drawTile(t,e=b(1),s,i=new wt,o=0,a=!1){t=t.subtract(this.pos).multiply(this.tileInfo.size),e=e.multiply(this.tileInfo.size),t.y=this.canvas.height-t.y;let r=I;I=b(this.canvas.width,this.canvas.height);let c=this.hasWebGL();c&&is(this.textureInfo.glTexture);let l=c?void 0:this.context;It(t,e,s,i,o,a,void 0,c,!0,l),c&&is(),I=r}drawRect(t,e,s,i){this.drawTile(t,e,void 0,s,i)}clearLayerRect(t,e){f(Et===this.context,"must call redrawStart() before clearing tiles");let s=t.x,i=this.canvas.height-t.y-e.y;this.hasWebGL()?Ec(s,i,e.x,e.y):this.context.clearRect(s,i,e.x,e.y)}},vs=class extends xs{constructor(t,e,s=Ds(),i=0,o=!0){super(t,e.floor(),s,i,o),this.collisionData=[],this.initCollision(this.size),sn.push(this),this.isSolid=!0}destroy(){if(this.destroyed)return;let t=sn.indexOf(this);f(t>=0,"tile collision layer not found in array"),t>=0&&sn.splice(t,1),super.destroy()}initCollision(t){f(O(t),"size must be a Vector2"),this.size=t.floor(),this.collisionData=[],this.collisionData.length=t.area(),this.collisionData.fill(0)}setCollisionData(t,e=1){f(O(t),"layerPos must be a Vector2");let s=(t.y|0)*this.size.x+(t.x|0);t.arrayCheck(this.size)&&(this.collisionData[s]=e)}clearCollisionData(t){this.setCollisionData(t,0)}getCollisionData(t){f(O(t),"layerPos must be a Vector2");let e=(t.y|0)*this.size.x+(t.x|0);return t.arrayCheck(this.size)?this.collisionData[e]:0}collisionTest(t,e=new ot,s){f(O(t)&&O(e),"pos and size must be Vector2s"),f(!s||typeof s=="function"||s instanceof Je,"callbackObject must be a function or EngineObject");let i=s?typeof s=="function"?(p,d)=>s(p,d):(p,d)=>s.collideWithTile(p,d):()=>!0,o=t.x-this.pos.x,a=t.y-this.pos.y;if(o+e.x/2<0||o-e.x/2>this.size.x||a+e.y/2<0||a-e.y/2>this.size.y)return!1;let r=K(o-e.x/2|0,0),c=K(a-e.y/2|0,0),l=tt(K(o+e.x/2,r+1),this.size.x),u=tt(K(a+e.y/2,c+1),this.size.y),h=new ot;for(let p=c;ps(l,u):(l,u)=>s.collideWithTile(l,u):l=>l>0,a=l=>{let u=this.getCollisionData(r.set(l.x-this.pos.x,l.y-this.pos.y));return u&&o(u,l)},r=new ot,c=qa(t,e,a,i);if(he&&c){let l=c.floor().add(b(.5));bt(l,b(1),"#f008"),we(t,e,"#00f",.02),we(t,c,"#f00",.02),nr(c,"#0f0"),i&&we(c,c.add(i),"#ff0",.02)}return c}},vo=class extends Je{constructor(t,e,s=0,i=0,o=100,a=X,r,c=W,l=W,u=rn,h=rn,p=.5,d=.1,y=1,x=.1,v=.05,w=1,_=1,S=0,C=X,A=.1,T=.2,P=!1,M=!1,pt=!0,rt=M?1e9:0,at=!1){super(t,b(),r,e,void 0,rt),this.emitCircle=typeof s=="number",this.emitSize=typeof s=="number"?b(s):s.copy(),this.emitTime=i,this.emitRate=o,this.emitConeAngle=a,this.colorStartA=c.copy(),this.colorStartB=l.copy(),this.colorEndA=u.copy(),this.colorEndB=h.copy(),this.randomColorLinear=pt,this.particleTime=p,this.sizeStart=d,this.sizeEnd=y,this.speed=x,this.angleSpeed=v,this.damping=w,this.angleDamping=_,this.gravityScale=S,this.particleConeAngle=C,this.fadeRate=A,this.randomness=T,this.collideTiles=P,this.additive=M,this.localSpace=at,this.trailScale=0,this.particleCreateCallback=void 0,this.particleDestroyCallback=void 0,this.particleCollideCallback=void 0,this.velocityInheritance=0,this.emitTimeBuffer=0,this.particles=[],this.previousAngle=this.angle,this.previousPos=this.pos.copy()}update(){if(f(this.angleDamping>=0&&this.angleDamping<=1),f(this.damping>=0&&this.damping<=1),this.velocityInheritance){let s=this.velocityInheritance;this.velocity.x=s*(this.pos.x-this.previousPos.x),this.velocity.y=s*(this.pos.y-this.previousPos.y),this.angleVelocity=s*(this.angle-this.previousAngle),this.previousAngle=this.angle,this.previousPos.x=this.pos.x,this.previousPos.y=this.pos.y}if(this.isActive()){if(this.emitRate&&Zs){let s=1/this.emitRate/Zs;for(this.emitTimeBuffer+=tr;this.emitTimeBuffer>0;this.emitTimeBuffer-=s)this.emitParticle()}}else this.particles.length===0&&this.destroy(!0);let t=this.particles,e=0;for(let s=0;s_+_*dt(s,-s),o=i(this.particleTime),a=i(this.sizeStart),r=i(this.sizeEnd),c=i(this.speed),l=i(this.angleSpeed)*Xa(),u=dt(this.emitConeAngle,-this.emitConeAngle),h=po(this.colorStartA,this.colorStartB,this.randomColorLinear),p=po(this.colorEndA,this.colorEndB,this.randomColorLinear),d=this.localSpace?u:this.angle+u,y=b(c*st(d),c*ct(d)),x=l;!this.localSpace&&this.velocityInheritance>0&&(y.x+=this.velocity.x,y.y+=this.velocity.y,x+=this.angleVelocity);let v=new hi(this,t,e,h,p,o,a,r,y,x);return this.particles.push(v),(w=this.particleCreateCallback)==null||w.call(this,v),v}updatePhysics(){}render(){for(let t of this.particles)t.render()}isActive(){return!this.emitTime||this.getAliveTime()0&&(this.destroyed=!1,this.emitTime=-1))}},Vh=new ot,hi=class{constructor(t,e,s,i,o,a,r,c,l=b(),u=0){this.emitter=t,this.pos=e,this.angle=s,this.size=b(r),this.color=i.copy(),this.colorStart=i,this.colorEnd=o,this.lifeTime=a,this.sizeStart=r,this.sizeEnd=c,this.velocity=l,this.angleVelocity=u,this.spawnTime=$t,this.mirror=Ha(),this.groundObject=void 0,this.destroyed=!1,this.tileInfo=t.tileInfo}update(){let t=this.emitter,e=t.damping,s=t.angleDamping,i=t.restitution,o=t.friction,a=t.gravityScale,r=t.collideTiles,c=t.particleCollideCallback;if(this.lifeTime>0&&$t-this.spawnTime>this.lifeTime){this.destroy();return}let l=this.pos.copy();if(this.velocity.x*=e,this.velocity.y*=e,this.pos.x+=this.velocity.x+=Ut.x*a,this.pos.y+=this.velocity.y+=Ut.y*a,this.angle+=this.angleVelocity*=s,!Ii||!r)return;let u=this.velocity.lengthSquared();if(u>Ge*Ge){let p=Ge/u**.5;this.velocity.x*=p,this.velocity.y*=p}this.groundObject=void 0;let h=c?p=>{let d=li(p);return d&&c(this,d,p)}:p=>li(p)>0;if(h(this.pos)){let p=$e(this.pos);if(!h(l)){let d=h(b(this.pos.x,l.y)),y=h(b(l.x,this.pos.y)),x=K(i,p.restitution),v=K(o,p.friction);d&&(this.pos.x=l.x,this.velocity.x*=-x,this.velocity.y*=v),(y||!d)&&((this.velocity.y<0&&Ut.y<0||this.velocity.y>0&&Ut.y>0)&&(this.groundObject=p),this.pos.y=l.y,this.velocity.y*=-x,this.velocity.x*=v),ue&&bt(this.pos,this.size,"#f00")}}}destroy(){let t=this.emitter.particleDestroyCallback,e=this.colorEnd;this.color.set(e.r,e.g,e.b,e.a),this.size.set(this.sizeEnd,this.sizeEnd),this.destroyed=!0,t==null||t(this)}render(){let t=this.emitter,e=t.localSpace,s=t.additive,i=t.trailScale,o=t.fadeRate/2,a=this.lifeTime>0?tt(($t-this.spawnTime)/this.lifeTime,1):1,r=1-a,c=r*this.sizeStart+a*this.sizeEnd,l=b(c),u=a1-o?(1-a)/o:1;this.color.r=r*this.colorStart.r+a*this.colorEnd.r,this.color.g=r*this.colorStart.g+a*this.colorEnd.g,this.color.b=r*this.colorStart.b+a*this.colorEnd.b,this.color.a=(r*this.colorStart.a+a*this.colorEnd.a)*u;let h=Vh.set(this.pos.x,this.pos.y),p=this.angle;if(e){let d=t.angle,y=ct(-d),x=st(-d);h.set(t.pos.x+h.x*y-h.y*x,t.pos.y+h.x*x+h.y*y),p+=d}if(s&&fs(),i){let d=e?this.velocity.rotate(t.angle):this.velocity,y=d.length();if(y){let x=y*i;l.y=K(l.x,x),p=sr(d.x,d.y),It(h,l,this.tileInfo,this.color,p,this.mirror)}}else It(h,l,this.tileInfo,this.color,p,this.mirror);s&&fs(!1),xn&&bt(h,l,"#f005",0,p)}},Mr=!0,Ao=!0,gi=5e5,Gr=11,mc=Gr*4,Wh=gi/mc|0,Fi=3,bc=Fi*4,zn=gi/bc|0;fn=!1,yi=5,jn=.5,mi=b(640,80),Ur=!1,As={},qs=[];xi=class{constructor(t,e,s="",i="\u{1F3C6}",o){f(t>=0&&!As[t]),this.id=t,this.name=e,this.description=s,this.icon=i,this.unlocked=!1,this.image=void 0,o&&((this.image=new Image).src=o),As[t]=this}unlock(){Ur||this.unlocked||(f(bi,"save name must be set"),this.unlocked=!0,Vr(),qs.push(this))}render(t=0){let e=ut,s=tt(mi.x,B.width),i=mi.y,o=B.width-s,a=-i*t,r=ke(0,0,.9);e.save(),e.beginPath(),e.fillStyle=r.toString(),e.strokeStyle=it.toString(),e.lineWidth=3,e.rect(o,a,s,i),e.fill(),e.stroke(),e.clip();let c=b(.1,.05).scale(i),l=i-2*c.x;this.renderIcon(b(o+c.x+l/2,a+i/2),l);let u=i*.5,h=i*.3,p=b(o+l+2*c.x,a+c.y*2+u/2),d=s-l-3*c.x;nn(this.name,p,u,it,0,void 0,"left",void 0,void 0,d),p.y=a+i-c.y*2-h/2,nn(this.description,p,h,it,0,void 0,"left",void 0,void 0,d),e.restore()}renderIcon(t,e){this.image?ut.drawImage(this.image,t.x-e/2,t.y-e/2,e,e):nn(this.icon,t,e*.7,it)}};_o=class extends xi{constructor(t,e,s,i,o){super(t,e,s,i,o)}unlock(){super.unlock(),Es&&Es.unlockMedal(this.id)}},Ro=class{constructor(t,e,s){var c,l,u;f(!Es,"there can only be one newgrounds object"),f(!e||s,"must provide cryptojs if there is a cipher"),Es=this,this.app_id=t,this.cipher=e,this.cryptoJS=s,this.host=location?location.hostname:"";let i=new URL(location.href);if(this.session_id=i.searchParams.get("ngio_session_id"),!this.session_id)return;let o=this.call("Medal.getList");if(!o||!o.result||o.result.error){fn&&xt("Newgrounds session unavailable; skipping plugin init"),this.medals=[],this.scoreboards=[];return}this.medals=((c=o.result.data)==null?void 0:c.medals)||[],fn&&xt(this.medals);for(let h of this.medals){let p=As[h.id];p&&(p.image=new Image,p.image.src=h.icon,p.name=h.name,p.description=h.description,p.unlocked=h.unlocked,p.difficulty=h.difficulty,p.value=h.value,p.value&&(p.description=p.description+` (${p.value})`))}let a=this.call("ScoreBoard.getBoards");this.scoreboards=((u=(l=a==null?void 0:a.result)==null?void 0:l.data)==null?void 0:u.scoreboards)||[],fn&&xt(this.scoreboards);let r=60*1e3;setInterval(()=>this.call("Gateway.ping",0,!0),r)}unlockMedal(t){return this.call("Medal.unlock",{id:t},!0)}postScore(t,e){return this.call("ScoreBoard.postScore",{id:t,value:e},!0)}getScores(t,e,s=0,i=0,o=10){return this.call("ScoreBoard.getScores",{id:t,user:e,social:s,skip:i,limit:o})}logView(){return this.call("App.logView",{host:this.host},!0)}call(t,e,s=!1){let i={component:t,parameters:e};if(this.cipher){let l=this.cryptoJS,u=l.enc.Base64.parse(this.cipher),h=l.lib.WordArray.random(16),p=l.AES.encrypt(JSON.stringify(i),u,{iv:h});i.secure=l.enc.Base64.stringify(h.concat(p.ciphertext)),i.parameters=0}let o={app_id:this.app_id,session_id:this.session_id,call:i},a=new FormData;a.append("input",JSON.stringify(o));let r=new XMLHttpRequest;r.open("POST","https://newgrounds.io/gateway_v3.php",!fn&&s);try{r.send(a)}catch(l){fn&&xt("newgrounds call failed",l);return}return fn&&xt(r.responseText),r.responseText&&JSON.parse(r.responseText)}},Po=class{constructor(t,e=!1,s=!1){f(!Mt,"Post process already initialized"),f(!(e&&s),"Post process cannot both include main canvas and use feedback texture"),Mt=this,t||(t="void mainImage(out vec4 c,vec2 p){c=texture(iChannel0,p/iResolution.xy);}"),this.shader=void 0,this.texture=void 0,this.vao=void 0,i(),Cn(void 0,r,o,a);function i(){if(z)return;if(!G){console.warn("PostProcessPlugin: WebGL not enabled!");return}Mt.texture=ji(),Mt.shader=Xn(`#version 300 es
+color = `+this.color),t}renderDebugInfo(){if(!jt)return;let t=this.collideTiles||this.collideSolidObjects||this.isSolid;if(!t&&!this.parent)return;let e=b(K(this.size.x,.2),K(this.size.y,.2)),s=J(this.collideTiles?1:0,this.collideSolidObjects?1:0,this.isSolid?1:0,.5);bt(this.pos,e,s,0,this.angle,t),this.parent&&bt(this.pos,e.scale(.8),J(1,1,1,.5),0,this.angle),this.parent&&we(this.pos,this.parent.pos,J(1,1,1,.5),.5)}},I=b(),cn=[];Re=class n{constructor(t=b(),e=Li,s=cn[0],i=Oi,o=Di){this.pos=t.copy(),this.size=e.copy(),this.padding=i,this.textureInfo=s,this.bleed=o}offset(t){return new n(this.pos.add(t),this.size,this.textureInfo,this.padding,this.bleed)}frame(t){f(typeof t=="number");let e=this.size.x+this.padding*2,s=t*e;return f(s+this.size.x<=this.textureInfo.size.x,"frame extends beyond texture width!"),this.offset(new rt(s))}setFullImage(t=this.textureInfo){return this.textureInfo=t,this.pos=new rt,this.size=t.size.copy(),this.bleed=this.padding=0,this}tile(t){return Ds(t,this.size,this.textureInfo,this.padding,this.bleed)}},Ve=class{constructor(t,e=!0,s=!1){this.image=t,this.size=t?b(t.width,t.height):b(),this.sizeInverse=t?b(1/t.width,1/t.height):b(),this.glTexture=void 0,this.wrap=s,e&&this.createWebGLTexture()}createWebGLTexture(){Hh(this)}destroyWebGLTexture(){Xh(this)}hasWebGL(){return!!this.glTexture}setWrap(t=!0){this.wrap=t,Sc(this.glTexture,t)}};nh=0;ii=class{constructor(t){f(!!t,"tileInfo is required for ImageFont"),this.tileInfo=t.frame(0)}drawText(t,e,s=1,i,o,a,r){f(O(s)||typeof s=="number","size must be a vec2 or number"),typeof s=="number"?(f(s>0),s*=H,s=new rt(s,s)):s=s.scale(H),this.drawTextScreen(t,Pn(e),s,i,o,a,r)}drawTextScreen(t,e,s,i=!0,o=W,a=G,r){f(V(t),"text must be a string"),f(O(e),"pos must be a vec2"),f(O(s)||typeof s=="number","size must be a vec2 or number"),f(U(o),"color must be a color"),s=typeof s=="number"?new rt(s,s):s;let c=new rt,l=this.tileInfo,u=l.padding,h=l.size.x+u*2,p=l.size.y+u*2,d=l.textureInfo.size.x/h|0;(t+"").split(`
+`).forEach((y,x)=>{let v=i?(y.length-1)*s.x/2:0;for(let w=y.length;w--;){let _=y.charCodeAt(w),S=_<32||_>127?95:_-32,C=S%d,A=S/d|0;l.pos.x=C*h+u,l.pos.y=A*p+u,c.x=e.x+w*s.x-v|0,c.y=e.y+x*s.y|0,Mt(c,s,l,o,0,!1,void 0,a,!0,r)}})}};De=b(),Jt=b(),Tr=b(),xe=b(),Ar=0,oi=!0,Bn=!1,Qe="mouse",Er=6,Fn=!0,mt=0,ie=!z&&window.ontouchstart!==void 0;Y=[[]],ve=[],pn=[],co=[],Vn=new Ee,oe=[],An=[],ri=[],Gs=[],Be=new Map,ys=[],Wn=!0;ai="http://www.w3.org/2000/svg";ft=new AudioContext,Qn=44100;bs=class{constructor(t,e,s=xr,i=vr,o){var a;if(!(!Ht||z)){if(f(!t||de(t)||V(t),"asset must be a file name or zzfx array"),f(e===void 0||L(e),"randomness must be a number"),f(e===void 0||e>=0&&e<=1,"randomness must be between 0 and 1"),f(L(s),"range must be a number"),f(L(i),"taper must be a number"),this.range=s,this.taper=i,this.randomness=e!=null?e:0,this.sampleRate=Qn,this.loadedPercent=0,this.onloadCallback=o,de(t)){let r=t.slice(),c=e!=null?e:.05,l=1;this.randomness=(a=r[l])!=null?a:c,r[l]=0,this.sampleChannels=[Gi(...r)],this.loadedPercent=1,o==null||o(this)}else if(typeof t=="string"){let r=t;this.loadSound(r)}}}play(t,e=1,s=1,i=1,o=!1,a=!1){if(f(!t||O(t),"pos must be a vec2"),f(L(e),"volume must be a number"),f(L(s),"pitch must be a number"),f(L(i),"randomnessScale must be a number"),!Ht||z||!this.sampleChannels)return;let r;if(t){let u=this.range;if(u){let h=_t.distanceSquared(t);if(h>u*u)return;e*=Bt(h**.5,u,u*this.taper)}r=Pn(t).x*2/B.width-1}let c=s+s*this.randomness*i*dt(-1,1),l=new ci(this,e,c,r,o,a);return jt&&Jn&&t&&(Ut(t,.5,"#0ff",.5,!0),this.range&&(Ut(t,2*this.range,"#0ff",.5),Ut(t,2*this.range*this.taper,"#0ff",.5)),In("vol "+e.toFixed(2)+" pitch "+c.toFixed(2),t,.5,"#0ff",.5)),l}playMusic(t=1,e=!0,s=!1){return this.play(void 0,t,1,0,e,s)}playNote(t=0,e,s){f(L(t),"semitoneOffset must be a number");let i=gc(t,1);return this.play(e,s,i,0)}getDuration(){var t,e;return((e=(t=this.sampleChannels)==null?void 0:t[0])==null?void 0:e.length)/this.sampleRate||0}isLoaded(){return this.loadedPercent===1}async loadSound(t){var c;let e=await fetch(t);if(!e.ok)throw new Error(`Failed to load sound from ${t}: ${e.status} ${e.statusText}`);let s=await e.arrayBuffer(),i=await ft.decodeAudioData(s),o=i.numberOfChannels,a=1e5,r=[];for(let l=0;lsetTimeout(v,0));let d=tt(p+a,h);for(;p=0,"Sound volume must be positive or zero"),f(s>=0,"Sound rate must be positive or zero"),f(L(i),"Sound pan must be a number"),this.sound=t,this.volume=e,this.rate=s,this.pan=i,this.loop=o,this.pausedTime=0,this.startTime=void 0,this.gainNode=void 0,this.source=void 0,this.onendedCallback=r=>{r===this.source&&(this.source=void 0)},a||this.start()}start(t=0){f(t>=0,"Sound start offset must be positive or zero"),this.isPlaying()&&this.stop(),this.gainNode=ft.createGain(),this.source=Ir(this.sound.sampleChannels,this.volume,this.rate,this.pan,this.loop,this.sound.sampleRate,this.gainNode,t,this.onendedCallback),this.source?(this.startTime=ft.currentTime-t,this.pausedTime=void 0):(this.startTime=void 0,this.pausedTime=0)}setVolume(t){f(t>=0,"Sound volume must be positive or zero"),this.volume=t,this.gainNode&&(this.gainNode.gain.value=t)}stop(t=0){if(f(t>=0,"Sound fade time must be positive or zero"),this.isPlaying())if(t){let e=ft.currentTime,s=e+t;this.gainNode.gain.cancelScheduledValues(e),this.gainNode.gain.setValueAtTime(this.volume,e),this.gainNode.gain.linearRampToValueAtTime(0,s),this.source.stop(s)}else this.source.stop();this.pausedTime=0,this.source=void 0,this.startTime=void 0}pause(){this.isPaused()||(this.pausedTime=this.getCurrentTime(),this.source.stop(),this.source=void 0,this.startTime=void 0)}resume(){this.isPaused()&&this.start(this.pausedTime)}isPlaying(){return!!this.source}isPaused(){return!this.isPlaying()}getCurrentTime(){if(!this.isPlaying())return this.pausedTime;let t=this.getDuration();return t?se(ft.currentTime-this.startTime,t):0}getDuration(){return this.rate?this.sound.getDuration()/this.rate:0}getSource(){return this.source}};sn=[];wn=class{constructor(t,e=0,s=!1,i=new wt){this.tile=t,this.direction=e,this.mirror=s,this.color=i.copy()}clear(){this.tile=this.direction=0,this.mirror=!1,this.color=new wt}},ui=class extends Ue{constructor(t,e,s=0,i=0,o=b(512),a=!0){var r;f(O(o),"canvasSize must be a Vector2"),super(t,e,void 0,s,W,i),this.canvas=z?void 0:new OffscreenCanvas(o.x,o.y),this.context=(r=this.canvas)==null?void 0:r.getContext("2d"),this.textureInfo=new Ve(this.canvas,a),this.mass=0}destroy(){this.destroyed||(this.textureInfo.destroyWebGLTexture(),super.destroy())}render(){this.draw(this.pos,this.size,this.color,this.angle,this.mirror,this.additiveColor)}draw(t,e,s=W,i=0,o=!1,a,r=!1,c){let l=new Re().setFullImage(this.textureInfo),u=this.hasWebGL();Mt(t,e,l,s,i,o,a,u,r,c)}updateWebGL(){this.textureInfo.createWebGLTexture()}hasWebGL(){return G&&this.textureInfo.hasWebGL()}},xs=class extends ui{constructor(t,e,s=Ds(),i=0,o=!0){let a=s?e.multiply(s.size):e;if(super(t,e,0,i,a,o),this.tileInfo=void 0,this.data=[],this.isUsingWebGL=!1,z){this.render=()=>{},this.redraw=()=>{},this.redrawStart=()=>{},this.redrawEnd=()=>{},this.drawTileData=()=>{},this.redrawTileData=()=>{},this.drawLayerTile=()=>{},this.drawLayerRect=()=>{},this.drawTile=()=>{},this.drawRect=()=>{},this.clearLayerRect=()=>{};return}s&&(this.tileInfo=s.frame(0),this.tileInfo.bleed=0);for(let r=this.size.area();r--;)this.data.push(new wn)}setData(t,e,s=!1){if(t=t.floor(),f(O(t),"layerPos must be a Vector2"),f(e instanceof wn,"data must be a TileLayerData"),!t.arrayCheck(this.size)||(this.data[(t.y|0)*this.size.x+(t.x|0)]=e,!s))return;Et===this.context?this.drawTileData(t):this.redrawTileData(t)}clearData(t,e=!1){this.setData(t,new wn,e)}getData(t){return f(O(t),"layerPos must be a Vector2"),t.arrayCheck(this.size)?this.data[(t.y|0)*this.size.x+(t.x|0)]:void 0}update(){!G&&this.isUsingWebGL&&(this.isUsingWebGL=!1,this.redraw())}render(){f(Et!==this.context,"must call redrawEnd() after drawing tiles!");let t=this.drawSize||this.size,e=this.pos.add(t.scale(.5));this.draw(e,this.size,this.color,this.angle,this.mirror,this.additiveColor)}onRedraw(){}redraw(){this.redrawStart(!0);for(let t=this.size.x;t--;)for(let e=this.size.y;e--;)this.drawTileData(b(t,e),!1);this.isUsingWebGL&&Rt(),this.onRedraw(),this.redrawEnd()}redrawStart(t=!1){var s,i;if(!this.context)return;f(Et!==this.context),this.savedRenderSettings=[Et,I,_t,H,tn],Et=this.context;let e=(i=(s=this.tileInfo)==null?void 0:s.size)!=null?i:b(1);I=this.size.multiply(e),tn=pe,_t=this.size.multiply(e).scale(.5),H=1,this.isUsingWebGL=this.hasWebGL(),this.isUsingWebGL?is(this.textureInfo.glTexture,t):(this.context.imageSmoothingEnabled=!Tn,t&&(this.canvas.width=I.x,this.canvas.height=I.y))}redrawEnd(){this.context&&(f(Et===this.context),this.isUsingWebGL&&is(),[Et,I,_t,H,tn]=this.savedRenderSettings)}drawTileData(t,e=!0){var r,c;if(!this.context)return;f(Et===this.context,"must call redrawStart() before drawing tiles");let s=(c=(r=this.tileInfo)==null?void 0:r.size)!=null?c:b(1),i=t.multiply(s);e&&this.clearLayerRect(i,s);let o=this.getData(t);if(!o||!o.tile)return;let a=this.tileInfo&&this.tileInfo.tile(o.tile);this.drawLayerTile(i,s,a,o.color,o.direction*X/2,o.mirror)}redrawTileData(t,e=!0){this.context&&(f(Et!==this.context,"redrawStart() should not be active when calling redrawTileData(), instead use drawTileData()"),this.redrawStart(),this.drawTileData(t,e),this.redrawEnd())}drawLayerTile(t,e=b(1),s,i=W,o=0,a,r){let c=t.add(e.scale(.5));Mt(c,e,s,i,o,a,r,this.isUsingWebGL)}drawLayerRect(t,e,s,i=0){this.drawLayerTile(t,e,void 0,s,i)}drawTile(t,e=b(1),s,i=new wt,o=0,a=!1){t=t.subtract(this.pos).multiply(this.tileInfo.size),e=e.multiply(this.tileInfo.size),t.y=this.canvas.height-t.y;let r=I;I=b(this.canvas.width,this.canvas.height);let c=this.hasWebGL();c&&is(this.textureInfo.glTexture);let l=c?void 0:this.context;Mt(t,e,s,i,o,a,void 0,c,!0,l),c&&is(),I=r}drawRect(t,e,s,i){this.drawTile(t,e,void 0,s,i)}clearLayerRect(t,e){f(Et===this.context,"must call redrawStart() before clearing tiles");let s=t.x,i=this.canvas.height-t.y-e.y;this.hasWebGL()?Ec(s,i,e.x,e.y):this.context.clearRect(s,i,e.x,e.y)}},vs=class extends xs{constructor(t,e,s=Ds(),i=0,o=!0){super(t,e.floor(),s,i,o),this.collisionData=[],this.initCollision(this.size),sn.push(this),this.isSolid=!0}destroy(){if(this.destroyed)return;let t=sn.indexOf(this);f(t>=0,"tile collision layer not found in array"),t>=0&&sn.splice(t,1),super.destroy()}initCollision(t){f(O(t),"size must be a Vector2"),this.size=t.floor(),this.collisionData=[],this.collisionData.length=t.area(),this.collisionData.fill(0)}setCollisionData(t,e=1){f(O(t),"layerPos must be a Vector2");let s=(t.y|0)*this.size.x+(t.x|0);t.arrayCheck(this.size)&&(this.collisionData[s]=e)}clearCollisionData(t){this.setCollisionData(t,0)}getCollisionData(t){f(O(t),"layerPos must be a Vector2");let e=(t.y|0)*this.size.x+(t.x|0);return t.arrayCheck(this.size)?this.collisionData[e]:0}collisionTest(t,e=new rt,s){f(O(t)&&O(e),"pos and size must be Vector2s"),f(!s||typeof s=="function"||s instanceof Ue,"callbackObject must be a function or EngineObject");let i=s?typeof s=="function"?(p,d)=>s(p,d):(p,d)=>s.collideWithTile(p,d):()=>!0,o=t.x-this.pos.x,a=t.y-this.pos.y;if(o+e.x/2<0||o-e.x/2>this.size.x||a+e.y/2<0||a-e.y/2>this.size.y)return!1;let r=K(o-e.x/2|0,0),c=K(a-e.y/2|0,0),l=tt(K(o+e.x/2,r+1),this.size.x),u=tt(K(a+e.y/2,c+1),this.size.y),h=new rt;for(let p=c;ps(l,u):(l,u)=>s.collideWithTile(l,u):l=>l>0,a=l=>{let u=this.getCollisionData(r.set(l.x-this.pos.x,l.y-this.pos.y));return u&&o(u,l)},r=new rt,c=qa(t,e,a,i);if(he&&c){let l=c.floor().add(b(.5));bt(l,b(1),"#f008"),we(t,e,"#00f",.02),we(t,c,"#f00",.02),nr(c,"#0f0"),i&&we(c,c.add(i),"#ff0",.02)}return c}},vo=class extends Ue{constructor(t,e,s=0,i=0,o=100,a=X,r,c=W,l=W,u=rn,h=rn,p=.5,d=.1,y=1,x=.1,v=.05,w=1,_=1,S=0,C=X,A=.1,T=.2,P=!1,M=!1,pt=!0,at=M?1e9:0,ct=!1){super(t,b(),r,e,void 0,at),this.emitCircle=typeof s=="number",this.emitSize=typeof s=="number"?b(s):s.copy(),this.emitTime=i,this.emitRate=o,this.emitConeAngle=a,this.colorStartA=c.copy(),this.colorStartB=l.copy(),this.colorEndA=u.copy(),this.colorEndB=h.copy(),this.randomColorLinear=pt,this.particleTime=p,this.sizeStart=d,this.sizeEnd=y,this.speed=x,this.angleSpeed=v,this.damping=w,this.angleDamping=_,this.gravityScale=S,this.particleConeAngle=C,this.fadeRate=A,this.randomness=T,this.collideTiles=P,this.additive=M,this.localSpace=ct,this.trailScale=0,this.particleCreateCallback=void 0,this.particleDestroyCallback=void 0,this.particleCollideCallback=void 0,this.velocityInheritance=0,this.emitTimeBuffer=0,this.particles=[],this.previousAngle=this.angle,this.previousPos=this.pos.copy()}update(){if(f(this.angleDamping>=0&&this.angleDamping<=1),f(this.damping>=0&&this.damping<=1),this.velocityInheritance){let s=this.velocityInheritance;this.velocity.x=s*(this.pos.x-this.previousPos.x),this.velocity.y=s*(this.pos.y-this.previousPos.y),this.angleVelocity=s*(this.angle-this.previousAngle),this.previousAngle=this.angle,this.previousPos.x=this.pos.x,this.previousPos.y=this.pos.y}if(this.isActive()){if(this.emitRate&&Zs){let s=1/this.emitRate/Zs;for(this.emitTimeBuffer+=tr;this.emitTimeBuffer>0;this.emitTimeBuffer-=s)this.emitParticle()}}else this.particles.length===0&&this.destroy(!0);let t=this.particles,e=0;for(let s=0;s_+_*dt(s,-s),o=i(this.particleTime),a=i(this.sizeStart),r=i(this.sizeEnd),c=i(this.speed),l=i(this.angleSpeed)*Xa(),u=dt(this.emitConeAngle,-this.emitConeAngle),h=po(this.colorStartA,this.colorStartB,this.randomColorLinear),p=po(this.colorEndA,this.colorEndB,this.randomColorLinear),d=this.localSpace?u:this.angle+u,y=b(c*st(d),c*lt(d)),x=l;!this.localSpace&&this.velocityInheritance>0&&(y.x+=this.velocity.x,y.y+=this.velocity.y,x+=this.angleVelocity);let v=new hi(this,t,e,h,p,o,a,r,y,x);return this.particles.push(v),(w=this.particleCreateCallback)==null||w.call(this,v),v}updatePhysics(){}render(){for(let t of this.particles)t.render()}isActive(){return!this.emitTime||this.getAliveTime()0&&(this.destroyed=!1,this.emitTime=-1))}},Vh=new rt,hi=class{constructor(t,e,s,i,o,a,r,c,l=b(),u=0){this.emitter=t,this.pos=e,this.angle=s,this.size=b(r),this.color=i.copy(),this.colorStart=i,this.colorEnd=o,this.lifeTime=a,this.sizeStart=r,this.sizeEnd=c,this.velocity=l,this.angleVelocity=u,this.spawnTime=Kt,this.mirror=Ha(),this.groundObject=void 0,this.destroyed=!1,this.tileInfo=t.tileInfo}update(){let t=this.emitter,e=t.damping,s=t.angleDamping,i=t.restitution,o=t.friction,a=t.gravityScale,r=t.collideTiles,c=t.particleCollideCallback;if(this.lifeTime>0&&Kt-this.spawnTime>this.lifeTime){this.destroy();return}let l=this.pos.copy();if(this.velocity.x*=e,this.velocity.y*=e,this.pos.x+=this.velocity.x+=Vt.x*a,this.pos.y+=this.velocity.y+=Vt.y*a,this.angle+=this.angleVelocity*=s,!Ii||!r)return;let u=this.velocity.lengthSquared();if(u>Fe*Fe){let p=Fe/u**.5;this.velocity.x*=p,this.velocity.y*=p}this.groundObject=void 0;let h=c?p=>{let d=li(p);return d&&c(this,d,p)}:p=>li(p)>0;if(h(this.pos)){let p=$e(this.pos);if(!h(l)){let d=h(b(this.pos.x,l.y)),y=h(b(l.x,this.pos.y)),x=K(i,p.restitution),v=K(o,p.friction);d&&(this.pos.x=l.x,this.velocity.x*=-x,this.velocity.y*=v),(y||!d)&&((this.velocity.y<0&&Vt.y<0||this.velocity.y>0&&Vt.y>0)&&(this.groundObject=p),this.pos.y=l.y,this.velocity.y*=-x,this.velocity.x*=v),ue&&bt(this.pos,this.size,"#f00")}}}destroy(){let t=this.emitter.particleDestroyCallback,e=this.colorEnd;this.color.set(e.r,e.g,e.b,e.a),this.size.set(this.sizeEnd,this.sizeEnd),this.destroyed=!0,t==null||t(this)}render(){let t=this.emitter,e=t.localSpace,s=t.additive,i=t.trailScale,o=t.fadeRate/2,a=this.lifeTime>0?tt((Kt-this.spawnTime)/this.lifeTime,1):1,r=1-a,c=r*this.sizeStart+a*this.sizeEnd,l=b(c),u=a1-o?(1-a)/o:1;this.color.r=r*this.colorStart.r+a*this.colorEnd.r,this.color.g=r*this.colorStart.g+a*this.colorEnd.g,this.color.b=r*this.colorStart.b+a*this.colorEnd.b,this.color.a=(r*this.colorStart.a+a*this.colorEnd.a)*u;let h=Vh.set(this.pos.x,this.pos.y),p=this.angle;if(e){let d=t.angle,y=lt(-d),x=st(-d);h.set(t.pos.x+h.x*y-h.y*x,t.pos.y+h.x*x+h.y*y),p+=d}if(s&&fs(),i){let d=e?this.velocity.rotate(t.angle):this.velocity,y=d.length();if(y){let x=y*i;l.y=K(l.x,x),p=sr(d.x,d.y),Mt(h,l,this.tileInfo,this.color,p,this.mirror)}}else Mt(h,l,this.tileInfo,this.color,p,this.mirror);s&&fs(!1),xn&&bt(h,l,"#f005",0,p)}},Mr=!0,Ao=!0,gi=5e5,Gr=11,mc=Gr*4,Wh=gi/mc|0,Fi=3,bc=Fi*4,zn=gi/bc|0;fn=!1,yi=5,jn=.5,mi=b(640,80),Ur=!1,As={},qs=[];xi=class{constructor(t,e,s="",i="\u{1F3C6}",o){f(t>=0&&!As[t]),this.id=t,this.name=e,this.description=s,this.icon=i,this.unlocked=!1,this.image=void 0,o&&((this.image=new Image).src=o),As[t]=this}unlock(){Ur||this.unlocked||(f(bi,"save name must be set"),this.unlocked=!0,Vr(),qs.push(this))}render(t=0){let e=ut,s=tt(mi.x,B.width),i=mi.y,o=B.width-s,a=-i*t,r=Ge(0,0,.9);e.save(),e.beginPath(),e.fillStyle=r.toString(),e.strokeStyle=it.toString(),e.lineWidth=3,e.rect(o,a,s,i),e.fill(),e.stroke(),e.clip();let c=b(.1,.05).scale(i),l=i-2*c.x;this.renderIcon(b(o+c.x+l/2,a+i/2),l);let u=i*.5,h=i*.3,p=b(o+l+2*c.x,a+c.y*2+u/2),d=s-l-3*c.x;nn(this.name,p,u,it,0,void 0,"left",void 0,void 0,d),p.y=a+i-c.y*2-h/2,nn(this.description,p,h,it,0,void 0,"left",void 0,void 0,d),e.restore()}renderIcon(t,e){this.image?ut.drawImage(this.image,t.x-e/2,t.y-e/2,e,e):nn(this.icon,t,e*.7,it)}};_o=class extends xi{constructor(t,e,s,i,o){super(t,e,s,i,o)}unlock(){super.unlock(),Es&&Es.unlockMedal(this.id)}},Ro=class{constructor(t,e,s){var c,l,u;f(!Es,"there can only be one newgrounds object"),f(!e||s,"must provide cryptojs if there is a cipher"),Es=this,this.app_id=t,this.cipher=e,this.cryptoJS=s,this.host=location?location.hostname:"";let i=new URL(location.href);if(this.session_id=i.searchParams.get("ngio_session_id"),!this.session_id)return;let o=this.call("Medal.getList");if(!o||!o.result||o.result.error){fn&&xt("Newgrounds session unavailable; skipping plugin init"),this.medals=[],this.scoreboards=[];return}this.medals=((c=o.result.data)==null?void 0:c.medals)||[],fn&&xt(this.medals);for(let h of this.medals){let p=As[h.id];p&&(p.image=new Image,p.image.src=h.icon,p.name=h.name,p.description=h.description,p.unlocked=h.unlocked,p.difficulty=h.difficulty,p.value=h.value,p.value&&(p.description=p.description+` (${p.value})`))}let a=this.call("ScoreBoard.getBoards");this.scoreboards=((u=(l=a==null?void 0:a.result)==null?void 0:l.data)==null?void 0:u.scoreboards)||[],fn&&xt(this.scoreboards);let r=60*1e3;setInterval(()=>this.call("Gateway.ping",0,!0),r)}unlockMedal(t){return this.call("Medal.unlock",{id:t},!0)}postScore(t,e){return this.call("ScoreBoard.postScore",{id:t,value:e},!0)}getScores(t,e,s=0,i=0,o=10){return this.call("ScoreBoard.getScores",{id:t,user:e,social:s,skip:i,limit:o})}logView(){return this.call("App.logView",{host:this.host},!0)}call(t,e,s=!1){let i={component:t,parameters:e};if(this.cipher){let l=this.cryptoJS,u=l.enc.Base64.parse(this.cipher),h=l.lib.WordArray.random(16),p=l.AES.encrypt(JSON.stringify(i),u,{iv:h});i.secure=l.enc.Base64.stringify(h.concat(p.ciphertext)),i.parameters=0}let o={app_id:this.app_id,session_id:this.session_id,call:i},a=new FormData;a.append("input",JSON.stringify(o));let r=new XMLHttpRequest;r.open("POST","https://newgrounds.io/gateway_v3.php",!fn&&s);try{r.send(a)}catch(l){fn&&xt("newgrounds call failed",l);return}return fn&&xt(r.responseText),r.responseText&&JSON.parse(r.responseText)}},Po=class{constructor(t,e=!1,s=!1){f(!kt,"Post process already initialized"),f(!(e&&s),"Post process cannot both include main canvas and use feedback texture"),kt=this,t||(t="void mainImage(out vec4 c,vec2 p){c=texture(iChannel0,p/iResolution.xy);}"),this.shader=void 0,this.texture=void 0,this.vao=void 0,i(),Cn(void 0,r,o,a);function i(){if(z)return;if(!G){console.warn("PostProcessPlugin: WebGL not enabled!");return}kt.texture=ji(),kt.shader=Xn(`#version 300 es
 precision highp float;in vec2 p;void main(){gl_Position=vec4(p+p-1.,1,1);}`,`#version 300 es
 precision highp float;uniform sampler2D iChannel0;uniform vec3 iResolution;uniform float iTime;out vec4 c;
 `+t+`
-void main(){mainImage(c,gl_FragCoord.xy);c.a=1.;}`),Mt.vao=g.createVertexArray(),g.bindVertexArray(Mt.vao),g.bindBuffer(g.ARRAY_BUFFER,Nn);let c=8,l=g.getAttribLocation(Mt.shader,"p");g.enableVertexAttribArray(l),g.vertexAttribPointer(l,2,g.FLOAT,!1,c,0)}function o(){Mt.shader=void 0,Mt.texture=void 0,xt("PostProcessPlugin: WebGL context lost")}function a(){i(),xt("PostProcessPlugin: WebGL context restored")}function r(){if(z||!G)return;Rt(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.useProgram(Mt.shader),g.bindVertexArray(Mt.vao),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!0),g.disable(g.BLEND),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,Mt.texture),e?(Be.width=I.x,Be.height=I.y,Br(Ke),Ke.drawImage(B,0,0),B.width|=0,g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,Be)):s||g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,et);let c=l=>g.getUniformLocation(Mt.shader,l);g.uniform1i(c("iChannel0"),0),g.uniform1f(c("iTime"),$t),g.uniform3f(c("iResolution"),B.width,B.height,1),g.drawArrays(g.TRIANGLE_STRIP,0,4),s&&g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,et),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!1),ws(!0)}}},Lo=class{constructor(t,e){f(!q,"LightSystemPlugin already initialized"),f(!Mt,"LightSystemPlugin must be created before PostProcessPlugin"),q=this,this.enabled=!0,this.ambientColor=(e||it).copy(),this.textureSize=t?t.copy():void 0,this.texture=void 0,this.lightShader=void 0,this.compositeShader=void 0,this.lightVAO=void 0,this.compositeVAO=void 0,s(),Cn(void 0,i,o,a);function s(){if(z)return;if(!G){console.warn("LightSystemPlugin: WebGL not enabled!");return}q.textureSize||(q.textureSize=I.copy()),q.texture=g.createTexture(),g.bindTexture(g.TEXTURE_2D,q.texture),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,q.textureSize.x,q.textureSize.y,0,g.RGBA,g.UNSIGNED_BYTE,null),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,g.CLAMP_TO_EDGE),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,g.CLAMP_TO_EDGE),q.lightShader=Xn(`#version 300 es
+void main(){mainImage(c,gl_FragCoord.xy);c.a=1.;}`),kt.vao=g.createVertexArray(),g.bindVertexArray(kt.vao),g.bindBuffer(g.ARRAY_BUFFER,Nn);let c=8,l=g.getAttribLocation(kt.shader,"p");g.enableVertexAttribArray(l),g.vertexAttribPointer(l,2,g.FLOAT,!1,c,0)}function o(){kt.shader=void 0,kt.texture=void 0,xt("PostProcessPlugin: WebGL context lost")}function a(){i(),xt("PostProcessPlugin: WebGL context restored")}function r(){if(z||!G)return;Rt(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.useProgram(kt.shader),g.bindVertexArray(kt.vao),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!0),g.disable(g.BLEND),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,kt.texture),e?(Ne.width=I.x,Ne.height=I.y,Br(Ke),Ke.drawImage(B,0,0),B.width|=0,g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,Ne)):s||g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,et);let c=l=>g.getUniformLocation(kt.shader,l);g.uniform1i(c("iChannel0"),0),g.uniform1f(c("iTime"),Kt),g.uniform3f(c("iResolution"),B.width,B.height,1),g.drawArrays(g.TRIANGLE_STRIP,0,4),s&&g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,et),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!1),ws(!0)}}},Lo=class{constructor(t,e){f(!q,"LightSystemPlugin already initialized"),f(!kt,"LightSystemPlugin must be created before PostProcessPlugin"),q=this,this.enabled=!0,this.ambientColor=(e||it).copy(),this.textureSize=t?t.copy():void 0,this.texture=void 0,this.lightShader=void 0,this.compositeShader=void 0,this.lightVAO=void 0,this.compositeVAO=void 0,s(),Cn(void 0,i,o,a);function s(){if(z)return;if(!G){console.warn("LightSystemPlugin: WebGL not enabled!");return}q.textureSize||(q.textureSize=I.copy()),q.texture=g.createTexture(),g.bindTexture(g.TEXTURE_2D,q.texture),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,q.textureSize.x,q.textureSize.y,0,g.RGBA,g.UNSIGNED_BYTE,null),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,g.CLAMP_TO_EDGE),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,g.CLAMP_TO_EDGE),q.lightShader=Xn(`#version 300 es
 precision highp float;uniform mat4 m;uniform vec2 lightPos;uniform float radius;in vec2 g;out vec2 vWorldPos;void main(){vec2 worldP=lightPos+(g-.5)*2.*radius;gl_Position=m*vec4(worldP,1,1);vWorldPos=worldP;}`,`#version 300 es
 precision highp float;uniform vec2 lightPos;uniform float radius;uniform float fadeRange;uniform vec4 color;in vec2 vWorldPos;out vec4 c;void main(){float dist=distance(vWorldPos,lightPos);float t=clamp((radius-dist)/max(fadeRange,1e-6),0.,1.);c=vec4(color.rgb*t*color.a,1.);}`),q.compositeShader=Xn(`#version 300 es
 precision highp float;in vec2 p;void main(){gl_Position=vec4(p+p-1.,1,1);}`,`#version 300 es
-precision highp float;uniform sampler2D s;uniform vec3 iResolution;out vec4 c;void main(){vec2 uv=gl_FragCoord.xy/iResolution.xy;c=vec4(texture(s,uv).rgb,1.);}`),q.lightVAO=g.createVertexArray(),g.bindVertexArray(q.lightVAO),g.bindBuffer(g.ARRAY_BUFFER,Nn);let r=g.getAttribLocation(q.lightShader,"g");g.enableVertexAttribArray(r),g.vertexAttribPointer(r,2,g.FLOAT,!1,8,0),q.compositeVAO=g.createVertexArray(),g.bindVertexArray(q.compositeVAO),g.bindBuffer(g.ARRAY_BUFFER,Nn);let c=g.getAttribLocation(q.compositeShader,"p");g.enableVertexAttribArray(c),g.vertexAttribPointer(c,2,g.FLOAT,!1,8,0)}function i(){if(z||!G||!q.enabled||!q.texture)return;Rt();let r=On,c=q.ambientColor;g.bindFramebuffer(g.FRAMEBUFFER,kr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,q.texture,0),g.viewport(0,0,q.textureSize.x,q.textureSize.y),g.clearColor(c.r,c.g,c.b,c.a),g.clear(g.COLOR_BUFFER_BIT),fs(),g.enable(g.BLEND),g.blendFunc(g.ONE,g.ONE);for(let u of vt)u.destroyed||u.renderLight();Rt(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,I.x,I.y),g.useProgram(q.compositeShader),g.bindVertexArray(q.compositeVAO),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,q.texture);let l=q.compositeShader;g.uniform1i(g.getUniformLocation(l,"s"),0),g.uniform3f(g.getUniformLocation(l,"iResolution"),B.width,B.height,1),g.blendFunc(g.DST_COLOR,g.ZERO),g.drawArrays(g.TRIANGLE_STRIP,0,4),Kt&&g.bindTexture(g.TEXTURE_2D,Kt),fs(r),ws(!0)}function o(){q.texture=void 0,q.lightShader=void 0,q.compositeShader=void 0,q.lightVAO=void 0,q.compositeVAO=void 0,xt("LightSystemPlugin: WebGL context lost")}function a(){s(),xt("LightSystemPlugin: WebGL context restored")}}drawLight(t){if(z||!G||!this.lightShader)return;Rt(),g.useProgram(this.lightShader),g.bindVertexArray(this.lightVAO);let e=b(2*H).divide(I),s=_t.rotate(-Q),i=b(-1).subtract(s.multiply(e)),o=ct(Q),a=st(Q),r=[e.x*o,e.y*a,0,0,-e.x*a,e.y*o,0,0,1,1,1,0,i.x,i.y,0,1],c=this.lightShader;g.uniformMatrix4fv(g.getUniformLocation(c,"m"),!1,r),g.uniform2f(g.getUniformLocation(c,"lightPos"),t.pos.x,t.pos.y),g.uniform1f(g.getUniformLocation(c,"radius"),t.radius),g.uniform1f(g.getUniformLocation(c,"fadeRange"),t.fadeRange);let l=t.color;g.uniform4f(g.getUniformLocation(c,"color"),l.r,l.g,l.b,l.a),g.drawArrays(g.TRIANGLE_STRIP,0,4),ws(!0)}},Oo=class extends Je{constructor(t,e,s,i){super(t,b(1),void 0,0,s),f(L(e)&&e>=0,"Light radius must be a non-negative number"),f(i===void 0||L(i)&&i>=0,"Light fadeRange must be a non-negative number when provided"),this.radius=e,this.fadeRange=i===void 0?e:i}render(){}renderLight(){q&&q.drawLight(this)}},Do=class extends bs{constructor(t){super(void 0),!(!qt||z)&&(this.randomness=0,this.sampleChannels=Cc(...t),this.sampleRate=Qn)}playMusic(t=1,e=!0){return super.play(void 0,t,1,0,e)}};Wr=0;Io=class{constructor(t=ut){f(!E,"UI system already initialized"),E=this,this.activateOnPress=!1,this.defaultColor=W,this.defaultLineColor=it,this.defaultTextColor=it,this.defaultButtonColor=ke(0,0,.7),this.defaultHoverColor=ke(0,0,.9),this.defaultDisabledColor=ke(0,0,.3),this.defaultGradientColor=void 0,this.defaultLineWidth=4,this.defaultCornerRadius=0,this.defaultTextFitScale=.8,this.defaultFont=Rs,this.defaultSoundPress=void 0,this.defaultSoundRelease=void 0,this.defaultSoundClick=void 0,this.defaultShadowColor=pe,this.defaultShadowBlur=5,this.defaultShadowOffset=b(5),this.nativeHeight=0,this.navigationObject=void 0,this.navigationTimer=new Ee(void 0,!0),this.navigationDelay=.2,this.navigationDirection=1,this.navigationMode=!1,this.uiObjects=[],this.uiContext=t,this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.confirmDialog=void 0,this._keyInputObject=void 0,this._onKeyDown=o=>{var a;return(a=this._keyInputObject)==null?void 0:a.onKeyDown(o)},Cn(s,i);function e(o){let a,r;o.parent?(a=o.parent.nativePos,r=o.parent.size):(a=E.screenToNative(I.scale(.5)),r=E.nativeHeight?b(I.x*E.nativeHeight/I.y,E.nativeHeight):I);let c=o.anchor;o.nativePos=a.add(r.multiply(c).scale(.5)).subtract(o.size.multiply(c).scale(.5)).add(o.localPos)}function s(){E.activeObject&&!E.activeObject.visible&&(E.activeObject=void 0),E.lastHoverObject=E.hoverObject,E.hoverObject=void 0,ps(0)&&(E.navigationMode=!1,E.navigationObject=void 0),E.keyInputObject&&(E.activeObject=E.keyInputObject,E.hoverObject=E.keyInputObject,E.navigationMode=!1,E.navigationObject=void 0);let o=E.getNavigableObjects();if(!o.length)E.navigationObject=void 0;else if(!E.keyInputObject){if(o.includes(E.navigationObject)||(E.navigationObject=void 0),ie||E.navigationMode&&!E.navigationObject&&(E.navigationObject=o.find(r=>r.navigationAutoSelect)),!E.navigationTimer.active()){let r=ne(E.getNavigationDirection());if(r){let c;if(E.navigationObject){let l=o.indexOf(E.navigationObject),u=se(l+r,o.length);c=o[u]}else if(c=o.find(l=>l.navigationAutoSelect),!c){let l=r>0?0:o.length-1;c=o[l]}E.navigationObject!==c&&(E.navigationMode=!0,E.hoverObject=void 0,E.navigationObject=c,E.navigationTimer.set(E.navigationDelay),c.soundPress&&c.soundPress.play())}}E.navigationObject&&E.getNavigationWasPressed()&&E.navigationObject.navigatePressed()}for(let r=E.uiObjects.length;r--;){let c=E.uiObjects[r];c.parent||a(c)}E.uiObjects=E.uiObjects.filter(r=>!r.destroyed);function a(r){if(!(r.destroyed||!r.visible)){e(r);for(let c=r.children.length;c--;){let l=r.children[c];l&&a(l)}r.destroyed||r.update()}}}function i(){let o=E.uiContext;if(o.save(),E.nativeHeight){let r=I.y/E.nativeHeight;o.translate(-r*I.x/2,0),o.scale(r,r),o.translate(I.x/2/r,0)}function a(r){if(r.visible){e(r),r.render();for(let c of r.children)a(c)}}if(E.uiObjects.forEach(r=>r.parent||a(r)),Wr>0){let r=function(c,l=!0){l&&(l=!!c.visible),e(c),c.renderDebug(l);for(let u of c.children)r(u,l)};E.uiObjects.forEach(c=>c.parent||r(c))}o.restore()}}drawRect(t,e,s=W,i=0,o=it,a=0,r,c=it,l=0,u=b()){f(O(t),"pos must be a vec2"),f(O(e),"size must be a vec2"),f(U(s),"color must be a color"),f(L(i),"lineWidth must be a number"),f(U(o),"lineColor must be a color"),f(L(a),"cornerRadius must be a number");let h=E.uiContext;if(r){let p=h.createLinearGradient(t.x,t.y-e.y/2,t.x,t.y+e.y/2),d=s.toString();p.addColorStop(0,d),p.addColorStop(.5,r.toString()),p.addColorStop(1,d),h.fillStyle=p}else h.fillStyle=s.toString();(l||u.x||u.y)&&c.a>0&&(h.shadowColor=c.toString(),h.shadowBlur=l,h.shadowOffsetX=u.x,h.shadowOffsetY=u.y),h.beginPath(),a&&h.roundRect?h.roundRect(t.x-e.x/2,t.y-e.y/2,e.x,e.y,a):h.rect(t.x-e.x/2,t.y-e.y/2,e.x,e.y),h.fill(),h.shadowColor="#0000",i&&o.a>0&&(h.strokeStyle=o.toString(),h.lineWidth=i,h.stroke())}drawLine(t,e,s=E.defaultLineWidth,i=E.defaultLineColor){f(O(t),"posA must be a vec2"),f(O(e),"posB must be a vec2"),f(L(s),"lineWidth must be a number"),f(U(i),"lineColor must be a color");let o=E.uiContext;o.strokeStyle=i.toString(),o.lineWidth=s,o.beginPath(),o.lineTo(t.x,t.y),o.lineTo(e.x,e.y),o.stroke()}drawTile(t,e,s,i=E.defaultColor,o=0,a=!1,r=it,c=0,l=b()){let u=E.uiContext;(c||l.x||l.y)&&r.a>0&&(u.shadowColor=r.toString(),u.shadowBlur=c,u.shadowOffsetX=l.x,u.shadowOffsetY=l.y),It(t,e,s,i,o,a,pe,!1,!0,u),u.shadowColor="#0000"}drawText(t,e,s,i=E.defaultColor,o=E.defaultLineWidth,a=E.defaultLineColor,r="center",c=E.defaultFont,l="",u=!0,h=void 0,p=it,d=0,y=b()){let x=E.uiContext;p.a>0&&(h&&nn(t,e.add(h),s.y,p,o,a,r,c,l,u?s.x:void 0,0,x),(d||y.x||y.y)&&(x.shadowColor=p.toString(),x.shadowBlur=d,x.shadowOffsetX=y.x,x.shadowOffsetY=y.y)),nn(t,e,s.y,i,o,a,r,c,l,u?s.x:void 0,0,x),x.shadowColor="#0000"}setupDragAndDrop(t,e,s,i){if(this._dragListeners)for(let[a,r]of this._dragListeners)document.removeEventListener(a,r);this._dragListeners=[];let o=(a,r)=>{let c=l=>{l.preventDefault(),a&&a(l)};document.addEventListener(r,c),this._dragListeners.push([r,c])};o(t,"drop"),o(e,"dragenter"),o(s,"dragleave"),o(i,"dragover")}screenToNative(t){if(!E.nativeHeight)return t;let e=I.y/E.nativeHeight,s=1/e,i=t.copy();return i.x+=e*I.x/2,i.x*=s,i.y*=s,i.x-=s*I.x/2,i}get keyInputObject(){return this._keyInputObject}set keyInputObject(t){let e=!!this._keyInputObject;this._keyInputObject=t,!e&&t?document.addEventListener("keydown",this._onKeyDown):e&&!t&&document.removeEventListener("keydown",this._onKeyDown)}destroyObjects(){for(let t of this.uiObjects)t.parent||t.destroy();this.uiObjects=this.uiObjects.filter(t=>!t.destroyed),this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.keyInputObject=void 0}getNavigableObjects(){function t(s){if(!(!s.visible||s.disabled)){s.isInteractive()&&s.navigationIndex!==void 0&&e.push(s);for(let i=s.children.length;i--;)t(s.children[i])}}let e=[];for(let s=E.uiObjects.length;s--;){let i=E.uiObjects[s];E.confirmDialog&&i!==E.confirmDialog||i.parent||t(i)}return e.sort((s,i)=>s.navigationIndex-i.navigationIndex),e}getNavigationDirection(){let t=E.navigationDirection===1,e=E.navigationDirection===2;if(Bn){let l=gs(0,mt),u=bo(mt);return e?-(l.y||u.y)||l.x||u.x:t?-(l.y||u.y):l.x||u.x}let s="ArrowUp",i="ArrowDown",o="ArrowLeft",a="ArrowRight";if(e)return Dt(s)||Dt(o)?-1:Dt(i)||Dt(a)?1:0;let r=t?s:o,c=t?i:a;return Dt(r)?-1:Dt(c)?1:0}getNavigationOtherDirection(){if(E.navigationDirection===2)return 0;let t=E.navigationDirection===1;if(Bn){let i=gs(0,mt),o=bo(mt);return t?i.x||o.x:i.y||o.y}let e=t?"ArrowLeft":"ArrowUp",s=t?"ArrowRight":"ArrowDown";return Dt(e)?-1:Dt(s)?1:0}getNavigationWasPressed(){return Bn?Rr(0,mt):kt("Space")||kt("Enter")}showConfirmDialog(t="Are you sure?",e,s,i=b(500,250),o="Escape"){f(!E.confirmDialog);let a=E.navigationDirection;E.navigationDirection=2;let r=new re(b(),i);E.confirmDialog=r,r.onRender=()=>{let d=ke(0,0,0,.7);E.drawRect(b(),b(1e9),d)},r.onUpdate=()=>{kt(o)&&p()},r.isMouseOverlapping=()=>!0;let c=50,l=new vi(b(0,-50),b(i.x-c,70),t);r.addChild(l);let u=new Cs(b(-80,50),b(120,70),"Yes");u.textHeight=40,u.navigationIndex=1,u.hoverColor=ke(0,1,.5),u.onClick=()=>{p(),e&&e()},r.addChild(u);let h=new Cs(b(80,50),b(120,70),"No");h.textHeight=40,h.navigationIndex=2,h.navigationAutoSelect=!0,h.onClick=()=>{p(),s&&s()},r.addChild(h);function p(){f(E.confirmDialog===r),r.destroy(),E.confirmDialog=void 0,E.navigationDirection=a,ks()}}},re=class{constructor(t=b(),e=b()){var s,i;f(O(t),"ui object pos must be a vec2"),f(O(e),"ui object size must be a vec2"),this.localPos=t.copy(),this.nativePos=t.copy(),this.size=e.copy(),this.color=E.defaultColor.copy(),this.activeColor=void 0,this.text=void 0,this.disabledColor=E.defaultDisabledColor.copy(),this.disabled=!1,this.textColor=E.defaultTextColor.copy(),this.hoverColor=E.defaultHoverColor.copy(),this.lineColor=E.defaultLineColor.copy(),this.gradientColor=E.defaultGradientColor?E.defaultGradientColor.copy():void 0,this.lineWidth=E.defaultLineWidth,this.cornerRadius=E.defaultCornerRadius,this.font=E.defaultFont,this.fontStyle=void 0,this.textWidth=void 0,this.textHeight=void 0,this.textFitScale=E.defaultTextFitScale,this.textShadow=void 0,this.textLineColor=E.defaultLineColor.copy(),this.textLineWidth=0,this.visible=!0,this.children=[],this.parent=void 0,this.extraTouchSize=0,this.soundPress=E.defaultSoundPress,this.soundRelease=E.defaultSoundRelease,this.soundClick=E.defaultSoundClick,this.interactive=!1,this.dragActivate=!1,this.canBeHover=!0,this.shadowColor=(s=E.defaultShadowColor)==null?void 0:s.copy(),this.shadowBlur=E.defaultShadowBlur,this.shadowOffset=(i=E.defaultShadowOffset)==null?void 0:i.copy(),this.navigationIndex=void 0,this.navigationAutoSelect=!1,this.anchor=b(),E.uiObjects.push(this)}addChild(t){return f(!t.parent&&!this.children.includes(t)),this.children.push(t),t.parent=this,t}removeChild(t){f(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}destroy(){var t;if(!this.destroyed){E.activeObject===this&&(E.activeObject=void 0),E.hoverObject===this&&(E.hoverObject=void 0),E.lastHoverObject===this&&(E.lastHoverObject=void 0),E.navigationObject===this&&(E.navigationObject=void 0),E.keyInputObject===this&&(E.keyInputObject=void 0),this.destroyed=1,(t=this.parent)==null||t.removeChild(this);for(let e of this.children)e.parent=void 0,e.destroy();this.children.length=0}}isMouseOverlapping(){if(!oi)return!1;let t=ie?this.size.add(b(this.extraTouchSize||0)):this.size,e=E.screenToNative(zt);return Qs(this.nativePos,t,e)}update(){if(this.onUpdate(),this.disabled&&(this===E.activeObject&&(E.activeObject=void 0),this===E.keyInputObject&&(E.keyInputObject=void 0)),E.keyInputObject)return;let t=E.lastHoverObject===this,e=this.isActiveObject(),s=cs(0),i=this.dragActivate?s:ps(0);this.canBeHover&&(E.navigationMode||(i||e||!s&&!ie)&&!E.hoverObject&&this.isMouseOverlapping()&&(E.hoverObject=this)),this.isHoverObject()&&(this.disabled||(i&&this.interactive&&((!this.dragActivate||!t||ps(0))&&this.onPress(),this.soundPress&&this.soundPress.play(),E.activeObject&&!e&&E.activeObject.onRelease(),E.activeObject=this,E.activateOnPress&&this.click(!this.soundPress)),E.activateOnPress||!s&&this.isActiveObject()&&this.interactive&&this.click()),i&&Cr(0,0,0,1,0)),e&&(!s||this.dragActivate&&!this.isHoverObject())&&(this.onRelease(),this.soundRelease&&this.soundRelease.play(),E.activeObject=void 0),this.isHoverObject()!==t&&(this.isHoverObject()?this.onEnter():this.onLeave())}render(){if(this.onRender(),!this.size.x||!this.size.y)return;let t=this.isNavigationObject(),e=t?this.color:this.interactive&&this.isActiveObject()&&!this.disabled?this.color:this.lineColor,s=t?this.hoverColor:this.disabled?this.disabledColor:this.interactive?this.isActiveObject()?this.activeColor||this.hoverColor:this.isHoverObject()?this.hoverColor:this.color:this.color,i=this.lineWidth*(t?1.5:1);E.drawRect(this.nativePos,this.size,s,i,e,this.cornerRadius,this.gradientColor,this.shadowColor,this.shadowBlur,this.shadowOffset)}getTextSize(){return b(this.textWidth||this.textFitScale*this.size.x,this.textHeight||this.textFitScale*this.size.y)}navigatePressed(){this.click()}isHoverObject(){return E.hoverObject===this}isActiveObject(){return E.activeObject===this}isNavigationObject(){return E.navigationObject===this}isKeyInputObject(){return E.keyInputObject===this}isInteractive(){return this.interactive&&this.visible&&!this.disabled}toString(){let t="type = "+this.constructor.name;return this.text&&(t+=`
+precision highp float;uniform sampler2D s;uniform vec3 iResolution;out vec4 c;void main(){vec2 uv=gl_FragCoord.xy/iResolution.xy;c=vec4(texture(s,uv).rgb,1.);}`),q.lightVAO=g.createVertexArray(),g.bindVertexArray(q.lightVAO),g.bindBuffer(g.ARRAY_BUFFER,Nn);let r=g.getAttribLocation(q.lightShader,"g");g.enableVertexAttribArray(r),g.vertexAttribPointer(r,2,g.FLOAT,!1,8,0),q.compositeVAO=g.createVertexArray(),g.bindVertexArray(q.compositeVAO),g.bindBuffer(g.ARRAY_BUFFER,Nn);let c=g.getAttribLocation(q.compositeShader,"p");g.enableVertexAttribArray(c),g.vertexAttribPointer(c,2,g.FLOAT,!1,8,0)}function i(){if(z||!G||!q.enabled||!q.texture)return;Rt();let r=On,c=q.ambientColor;g.bindFramebuffer(g.FRAMEBUFFER,kr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,q.texture,0),g.viewport(0,0,q.textureSize.x,q.textureSize.y),g.clearColor(c.r,c.g,c.b,c.a),g.clear(g.COLOR_BUFFER_BIT),fs(),g.enable(g.BLEND),g.blendFunc(g.ONE,g.ONE);for(let u of vt)u.destroyed||u.renderLight();Rt(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,I.x,I.y),g.useProgram(q.compositeShader),g.bindVertexArray(q.compositeVAO),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,q.texture);let l=q.compositeShader;g.uniform1i(g.getUniformLocation(l,"s"),0),g.uniform3f(g.getUniformLocation(l,"iResolution"),B.width,B.height,1),g.blendFunc(g.DST_COLOR,g.ZERO),g.drawArrays(g.TRIANGLE_STRIP,0,4),Qt&&g.bindTexture(g.TEXTURE_2D,Qt),fs(r),ws(!0)}function o(){q.texture=void 0,q.lightShader=void 0,q.compositeShader=void 0,q.lightVAO=void 0,q.compositeVAO=void 0,xt("LightSystemPlugin: WebGL context lost")}function a(){s(),xt("LightSystemPlugin: WebGL context restored")}}drawLight(t){if(z||!G||!this.lightShader)return;Rt(),g.useProgram(this.lightShader),g.bindVertexArray(this.lightVAO);let e=b(2*H).divide(I),s=_t.rotate(-Q),i=b(-1).subtract(s.multiply(e)),o=lt(Q),a=st(Q),r=[e.x*o,e.y*a,0,0,-e.x*a,e.y*o,0,0,1,1,1,0,i.x,i.y,0,1],c=this.lightShader;g.uniformMatrix4fv(g.getUniformLocation(c,"m"),!1,r),g.uniform2f(g.getUniformLocation(c,"lightPos"),t.pos.x,t.pos.y),g.uniform1f(g.getUniformLocation(c,"radius"),t.radius),g.uniform1f(g.getUniformLocation(c,"fadeRange"),t.fadeRange);let l=t.color;g.uniform4f(g.getUniformLocation(c,"color"),l.r,l.g,l.b,l.a),g.drawArrays(g.TRIANGLE_STRIP,0,4),ws(!0)}},Oo=class extends Ue{constructor(t,e,s,i){super(t,b(1),void 0,0,s),f(L(e)&&e>=0,"Light radius must be a non-negative number"),f(i===void 0||L(i)&&i>=0,"Light fadeRange must be a non-negative number when provided"),this.radius=e,this.fadeRange=i===void 0?e:i}render(){}renderLight(){q&&q.drawLight(this)}},Do=class extends bs{constructor(t){super(void 0),!(!Ht||z)&&(this.randomness=0,this.sampleChannels=Cc(...t),this.sampleRate=Qn)}playMusic(t=1,e=!0){return super.play(void 0,t,1,0,e)}};Wr=0;Io=class{constructor(t=ut){f(!E,"UI system already initialized"),E=this,this.activateOnPress=!1,this.defaultColor=W,this.defaultLineColor=it,this.defaultTextColor=it,this.defaultButtonColor=Ge(0,0,.7),this.defaultHoverColor=Ge(0,0,.9),this.defaultDisabledColor=Ge(0,0,.3),this.defaultGradientColor=void 0,this.defaultLineWidth=4,this.defaultCornerRadius=0,this.defaultTextFitScale=.8,this.defaultFont=Rs,this.defaultSoundPress=void 0,this.defaultSoundRelease=void 0,this.defaultSoundClick=void 0,this.defaultShadowColor=pe,this.defaultShadowBlur=5,this.defaultShadowOffset=b(5),this.nativeHeight=0,this.navigationObject=void 0,this.navigationTimer=new Ee(void 0,!0),this.navigationDelay=.2,this.navigationDirection=1,this.navigationMode=!1,this.uiObjects=[],this.uiContext=t,this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.confirmDialog=void 0,this._keyInputObject=void 0,this._onKeyDown=o=>{var a;return(a=this._keyInputObject)==null?void 0:a.onKeyDown(o)},Cn(s,i);function e(o){let a,r;o.parent?(a=o.parent.nativePos,r=o.parent.size):(a=E.screenToNative(I.scale(.5)),r=E.nativeHeight?b(I.x*E.nativeHeight/I.y,E.nativeHeight):I);let c=o.anchor;o.nativePos=a.add(r.multiply(c).scale(.5)).subtract(o.size.multiply(c).scale(.5)).add(o.localPos)}function s(){E.activeObject&&!E.activeObject.visible&&(E.activeObject=void 0),E.lastHoverObject=E.hoverObject,E.hoverObject=void 0,ps(0)&&(E.navigationMode=!1,E.navigationObject=void 0),E.keyInputObject&&(E.activeObject=E.keyInputObject,E.hoverObject=E.keyInputObject,E.navigationMode=!1,E.navigationObject=void 0);let o=E.getNavigableObjects();if(!o.length)E.navigationObject=void 0;else if(!E.keyInputObject){if(o.includes(E.navigationObject)||(E.navigationObject=void 0),ie||E.navigationMode&&!E.navigationObject&&(E.navigationObject=o.find(r=>r.navigationAutoSelect)),!E.navigationTimer.active()){let r=ne(E.getNavigationDirection());if(r){let c;if(E.navigationObject){let l=o.indexOf(E.navigationObject),u=se(l+r,o.length);c=o[u]}else if(c=o.find(l=>l.navigationAutoSelect),!c){let l=r>0?0:o.length-1;c=o[l]}E.navigationObject!==c&&(E.navigationMode=!0,E.hoverObject=void 0,E.navigationObject=c,E.navigationTimer.set(E.navigationDelay),c.soundPress&&c.soundPress.play())}}E.navigationObject&&E.getNavigationWasPressed()&&E.navigationObject.navigatePressed()}for(let r=E.uiObjects.length;r--;){let c=E.uiObjects[r];c.parent||a(c)}E.uiObjects=E.uiObjects.filter(r=>!r.destroyed);function a(r){if(!(r.destroyed||!r.visible)){e(r);for(let c=r.children.length;c--;){let l=r.children[c];l&&a(l)}r.destroyed||r.update()}}}function i(){let o=E.uiContext;if(o.save(),E.nativeHeight){let r=I.y/E.nativeHeight;o.translate(-r*I.x/2,0),o.scale(r,r),o.translate(I.x/2/r,0)}function a(r){if(r.visible){e(r),r.render();for(let c of r.children)a(c)}}if(E.uiObjects.forEach(r=>r.parent||a(r)),Wr>0){let r=function(c,l=!0){l&&(l=!!c.visible),e(c),c.renderDebug(l);for(let u of c.children)r(u,l)};E.uiObjects.forEach(c=>c.parent||r(c))}o.restore()}}drawRect(t,e,s=W,i=0,o=it,a=0,r,c=it,l=0,u=b()){f(O(t),"pos must be a vec2"),f(O(e),"size must be a vec2"),f(U(s),"color must be a color"),f(L(i),"lineWidth must be a number"),f(U(o),"lineColor must be a color"),f(L(a),"cornerRadius must be a number");let h=E.uiContext;if(r){let p=h.createLinearGradient(t.x,t.y-e.y/2,t.x,t.y+e.y/2),d=s.toString();p.addColorStop(0,d),p.addColorStop(.5,r.toString()),p.addColorStop(1,d),h.fillStyle=p}else h.fillStyle=s.toString();(l||u.x||u.y)&&c.a>0&&(h.shadowColor=c.toString(),h.shadowBlur=l,h.shadowOffsetX=u.x,h.shadowOffsetY=u.y),h.beginPath(),a&&h.roundRect?h.roundRect(t.x-e.x/2,t.y-e.y/2,e.x,e.y,a):h.rect(t.x-e.x/2,t.y-e.y/2,e.x,e.y),h.fill(),h.shadowColor="#0000",i&&o.a>0&&(h.strokeStyle=o.toString(),h.lineWidth=i,h.stroke())}drawLine(t,e,s=E.defaultLineWidth,i=E.defaultLineColor){f(O(t),"posA must be a vec2"),f(O(e),"posB must be a vec2"),f(L(s),"lineWidth must be a number"),f(U(i),"lineColor must be a color");let o=E.uiContext;o.strokeStyle=i.toString(),o.lineWidth=s,o.beginPath(),o.lineTo(t.x,t.y),o.lineTo(e.x,e.y),o.stroke()}drawTile(t,e,s,i=E.defaultColor,o=0,a=!1,r=it,c=0,l=b()){let u=E.uiContext;(c||l.x||l.y)&&r.a>0&&(u.shadowColor=r.toString(),u.shadowBlur=c,u.shadowOffsetX=l.x,u.shadowOffsetY=l.y),Mt(t,e,s,i,o,a,pe,!1,!0,u),u.shadowColor="#0000"}drawText(t,e,s,i=E.defaultColor,o=E.defaultLineWidth,a=E.defaultLineColor,r="center",c=E.defaultFont,l="",u=!0,h=void 0,p=it,d=0,y=b()){let x=E.uiContext;p.a>0&&(h&&nn(t,e.add(h),s.y,p,o,a,r,c,l,u?s.x:void 0,0,x),(d||y.x||y.y)&&(x.shadowColor=p.toString(),x.shadowBlur=d,x.shadowOffsetX=y.x,x.shadowOffsetY=y.y)),nn(t,e,s.y,i,o,a,r,c,l,u?s.x:void 0,0,x),x.shadowColor="#0000"}setupDragAndDrop(t,e,s,i){if(this._dragListeners)for(let[a,r]of this._dragListeners)document.removeEventListener(a,r);this._dragListeners=[];let o=(a,r)=>{let c=l=>{l.preventDefault(),a&&a(l)};document.addEventListener(r,c),this._dragListeners.push([r,c])};o(t,"drop"),o(e,"dragenter"),o(s,"dragleave"),o(i,"dragover")}screenToNative(t){if(!E.nativeHeight)return t;let e=I.y/E.nativeHeight,s=1/e,i=t.copy();return i.x+=e*I.x/2,i.x*=s,i.y*=s,i.x-=s*I.x/2,i}get keyInputObject(){return this._keyInputObject}set keyInputObject(t){let e=!!this._keyInputObject;this._keyInputObject=t,!e&&t?document.addEventListener("keydown",this._onKeyDown):e&&!t&&document.removeEventListener("keydown",this._onKeyDown)}destroyObjects(){for(let t of this.uiObjects)t.parent||t.destroy();this.uiObjects=this.uiObjects.filter(t=>!t.destroyed),this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.keyInputObject=void 0}getNavigableObjects(){function t(s){if(!(!s.visible||s.disabled)){s.isInteractive()&&s.navigationIndex!==void 0&&e.push(s);for(let i=s.children.length;i--;)t(s.children[i])}}let e=[];for(let s=E.uiObjects.length;s--;){let i=E.uiObjects[s];E.confirmDialog&&i!==E.confirmDialog||i.parent||t(i)}return e.sort((s,i)=>s.navigationIndex-i.navigationIndex),e}getNavigationDirection(){let t=E.navigationDirection===1,e=E.navigationDirection===2;if(Bn){let l=gs(0,mt),u=bo(mt);return e?-(l.y||u.y)||l.x||u.x:t?-(l.y||u.y):l.x||u.x}let s="ArrowUp",i="ArrowDown",o="ArrowLeft",a="ArrowRight";if(e)return It(s)||It(o)?-1:It(i)||It(a)?1:0;let r=t?s:o,c=t?i:a;return It(r)?-1:It(c)?1:0}getNavigationOtherDirection(){if(E.navigationDirection===2)return 0;let t=E.navigationDirection===1;if(Bn){let i=gs(0,mt),o=bo(mt);return t?i.x||o.x:i.y||o.y}let e=t?"ArrowLeft":"ArrowUp",s=t?"ArrowRight":"ArrowDown";return It(e)?-1:It(s)?1:0}getNavigationWasPressed(){return Bn?Rr(0,mt):Gt("Space")||Gt("Enter")}showConfirmDialog(t="Are you sure?",e,s,i=b(500,250),o="Escape"){f(!E.confirmDialog);let a=E.navigationDirection;E.navigationDirection=2;let r=new re(b(),i);E.confirmDialog=r,r.onRender=()=>{let d=Ge(0,0,0,.7);E.drawRect(b(),b(1e9),d)},r.onUpdate=()=>{Gt(o)&&p()},r.isMouseOverlapping=()=>!0;let c=50,l=new vi(b(0,-50),b(i.x-c,70),t);r.addChild(l);let u=new Cs(b(-80,50),b(120,70),"Yes");u.textHeight=40,u.navigationIndex=1,u.hoverColor=Ge(0,1,.5),u.onClick=()=>{p(),e&&e()},r.addChild(u);let h=new Cs(b(80,50),b(120,70),"No");h.textHeight=40,h.navigationIndex=2,h.navigationAutoSelect=!0,h.onClick=()=>{p(),s&&s()},r.addChild(h);function p(){f(E.confirmDialog===r),r.destroy(),E.confirmDialog=void 0,E.navigationDirection=a,ks()}}},re=class{constructor(t=b(),e=b()){var s,i;f(O(t),"ui object pos must be a vec2"),f(O(e),"ui object size must be a vec2"),this.localPos=t.copy(),this.nativePos=t.copy(),this.size=e.copy(),this.color=E.defaultColor.copy(),this.activeColor=void 0,this.text=void 0,this.disabledColor=E.defaultDisabledColor.copy(),this.disabled=!1,this.textColor=E.defaultTextColor.copy(),this.hoverColor=E.defaultHoverColor.copy(),this.lineColor=E.defaultLineColor.copy(),this.gradientColor=E.defaultGradientColor?E.defaultGradientColor.copy():void 0,this.lineWidth=E.defaultLineWidth,this.cornerRadius=E.defaultCornerRadius,this.font=E.defaultFont,this.fontStyle=void 0,this.textWidth=void 0,this.textHeight=void 0,this.textFitScale=E.defaultTextFitScale,this.textShadow=void 0,this.textLineColor=E.defaultLineColor.copy(),this.textLineWidth=0,this.visible=!0,this.children=[],this.parent=void 0,this.extraTouchSize=0,this.soundPress=E.defaultSoundPress,this.soundRelease=E.defaultSoundRelease,this.soundClick=E.defaultSoundClick,this.interactive=!1,this.dragActivate=!1,this.canBeHover=!0,this.shadowColor=(s=E.defaultShadowColor)==null?void 0:s.copy(),this.shadowBlur=E.defaultShadowBlur,this.shadowOffset=(i=E.defaultShadowOffset)==null?void 0:i.copy(),this.navigationIndex=void 0,this.navigationAutoSelect=!1,this.anchor=b(),E.uiObjects.push(this)}addChild(t){return f(!t.parent&&!this.children.includes(t)),this.children.push(t),t.parent=this,t}removeChild(t){f(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}destroy(){var t;if(!this.destroyed){E.activeObject===this&&(E.activeObject=void 0),E.hoverObject===this&&(E.hoverObject=void 0),E.lastHoverObject===this&&(E.lastHoverObject=void 0),E.navigationObject===this&&(E.navigationObject=void 0),E.keyInputObject===this&&(E.keyInputObject=void 0),this.destroyed=1,(t=this.parent)==null||t.removeChild(this);for(let e of this.children)e.parent=void 0,e.destroy();this.children.length=0}}isMouseOverlapping(){if(!oi)return!1;let t=ie?this.size.add(b(this.extraTouchSize||0)):this.size,e=E.screenToNative(Jt);return Qs(this.nativePos,t,e)}update(){if(this.onUpdate(),this.disabled&&(this===E.activeObject&&(E.activeObject=void 0),this===E.keyInputObject&&(E.keyInputObject=void 0)),E.keyInputObject)return;let t=E.lastHoverObject===this,e=this.isActiveObject(),s=cs(0),i=this.dragActivate?s:ps(0);this.canBeHover&&(E.navigationMode||(i||e||!s&&!ie)&&!E.hoverObject&&this.isMouseOverlapping()&&(E.hoverObject=this)),this.isHoverObject()&&(this.disabled||(i&&this.interactive&&((!this.dragActivate||!t||ps(0))&&this.onPress(),this.soundPress&&this.soundPress.play(),E.activeObject&&!e&&E.activeObject.onRelease(),E.activeObject=this,E.activateOnPress&&this.click(!this.soundPress)),E.activateOnPress||!s&&this.isActiveObject()&&this.interactive&&this.click()),i&&Cr(0,0,0,1,0)),e&&(!s||this.dragActivate&&!this.isHoverObject())&&(this.onRelease(),this.soundRelease&&this.soundRelease.play(),E.activeObject=void 0),this.isHoverObject()!==t&&(this.isHoverObject()?this.onEnter():this.onLeave())}render(){if(this.onRender(),!this.size.x||!this.size.y)return;let t=this.isNavigationObject(),e=t?this.color:this.interactive&&this.isActiveObject()&&!this.disabled?this.color:this.lineColor,s=t?this.hoverColor:this.disabled?this.disabledColor:this.interactive?this.isActiveObject()?this.activeColor||this.hoverColor:this.isHoverObject()?this.hoverColor:this.color:this.color,i=this.lineWidth*(t?1.5:1);E.drawRect(this.nativePos,this.size,s,i,e,this.cornerRadius,this.gradientColor,this.shadowColor,this.shadowBlur,this.shadowOffset)}getTextSize(){return b(this.textWidth||this.textFitScale*this.size.x,this.textHeight||this.textFitScale*this.size.y)}navigatePressed(){this.click()}isHoverObject(){return E.hoverObject===this}isActiveObject(){return E.activeObject===this}isNavigationObject(){return E.navigationObject===this}isKeyInputObject(){return E.keyInputObject===this}isInteractive(){return this.interactive&&this.visible&&!this.disabled}toString(){let t="type = "+this.constructor.name;return this.text&&(t+=`
 text = `+this.text),(this.nativePos.x||this.nativePos.y)&&(t+=`
 nativePos = `+this.nativePos),(this.localPos.x||this.localPos.y)&&(t+=`
 localPos = `+this.localPos),(this.size.x||this.size.y)&&(t+=`
 size = `+this.size),this.color&&(t+=`
-color = `+this.color),t}renderDebug(t=!0){let e=t?this.isHoverObject()?Ka:this.disabled?tc:this.interactive?rr:Za:Qa;E.drawRect(this.nativePos,this.size,pe,4,e)}click(t=!0){this.onClick(),t&&this.soundClick&&this.soundClick.play()}onUpdate(){}onRender(){}onEnter(){}onLeave(){}onPress(){}onRelease(){}onClick(){}onChange(){}},vi=class extends re{constructor(t,e,s="",i="center",o=E.defaultFont){super(t,e),f(V(s),"ui text must be a string"),f(["left","center","right"].includes(i),"ui text align must be left, center, or right"),f(V(o),"ui text font must be a string"),this.text=s,this.align=i,this.font=o,this.canBeHover=!1,this.color=pe,this.shadowColor=pe,this.gradientColor=void 0,this.lineWidth=0,this.textFitScale=1}render(){super.render();let t=this.getTextSize();E.drawText(this.text,this.nativePos,t,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow,this.shadowColor,this.shadowBlur,this.shadowOffset)}},Mo=class extends re{constructor(t,e,s=""){super(t,e),f(V(s),"ui text must be a string"),this.maxLength=0,this.text=s,this.interactive=!0,this.canBeHover=!0}click(){E.keyInputObject=this,this.onClick()}stopEditing(){this.isKeyInputObject()&&(this.soundRelease&&this.soundRelease.play(),E.activeObject=void 0,E.keyInputObject=void 0,this.onChange())}onKeyDown(t){let e=t.code,s=t.key;e==="Backspace"?this.text=this.text.slice(0,-1):e==="Enter"||e==="Escape"?this.stopEditing():s.length===1&&(!this.maxLength||this.text.lengththis.size.y,s=e?this.size.y:this.size.x,i=e?this.size.x:this.size.y,o=e?this.nativePos.x:this.nativePos.y,a=i-s,r=o-a/2,c=o+a/2,l=E.screenToNative(zt);this.value=e?jt(l.x,r,c):jt(l.y,c,r)}else if(this.isNavigationObject()){let e=E.getNavigationOtherDirection();E.navigationTimer.active()||(this.value=N(this.value+e*.01))}this.value===t||this.onChange()}render(){super.render();let t=this.size.x>this.size.y,e=t?this.size.x:this.size.y,s=t?this.size.y:this.size.x;if(this.fillMode){let o=tt(s,this.cornerRadius*2),a=Vt(o,e,this.value),r=(a-e)*(t?.5:-.5),c=this.nativePos.add(t?b(r,0):b(0,r)),l=this.disabled?this.disabledColor:this.handleColor,u=t?b(a,this.size.y):b(this.size.x,a);E.drawRect(c,u,l,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}else{let o=N(t?this.value:1-this.value),a=(e-s)*(o-.5),r=this.nativePos.add(t?b(a,0):b(0,a)),c=this.disabled?this.disabledColor:this.handleColor,l=b(s);E.drawRect(r,l,c,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}let i=this.getTextSize();E.drawText(this.text,this.nativePos,i,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow)}navigatePressed(){this.value=this.value?0:1,this.onChange(),this.onRelease(),super.navigatePressed()}},jo=class extends re{constructor(t,e,s,i=!1,o=!1,a=1){super(t,e||b()),f(V(s),"video src must be a string"),f(L(a),"video volume must be a number"),this.color=it,this.cornerRadius=0,this.volume=a,this.video=document.createElement("video"),this.video.loop=o,this.video.volume=N(a*Sn),this.video.muted=!qt,this.video.style.display="none",this.video.src=s,document.body.appendChild(this.video),i&&this.play()}async play(){try{await this.video.play()}catch{}}pause(){this.video.pause()}stop(){this.video.pause(),this.video.currentTime=0}isLoading(){return this.video.readyState=1,"ui layout columns must be a number >= 1"),f(L(s),"ui layout gap must be a number"),f(L(i),"ui layout padding must be a number"),this.columns=e,this.gap=s,this.padding=i,o&&(this.color=pe,this.gradientColor=void 0,this.lineWidth=0,this.shadowColor=pe),this.relayout()}addChild(t){return super.addChild(t),this.relayout(),t}removeChild(t){super.removeChild(t),this.relayout()}relayout(){let t=this.children.length;if(!t){this.size=b(this.padding*2);return}let e=this.columns,s=us(t/e),i=new Array(e).fill(0),o=new Array(s).fill(0);for(let p=0;p=0&&m.objects.splice(t,1),super.destroy()}updatePhysics(){}render(){this.tileInfo?super.render():this.drawFixtures(this.color,this.lineColor,this.lineWidth)}renderDebugInfo(){let t=!this.getIsAwake(),e=this.getBodyType()===m.bodyTypeStatic,s=J(t?1:0,t?1:0,e?1:0,.5);this.drawFixtures(s)}drawFixtures(t=W,e=it,s=.1,i,o){this.getFixtureList().forEach(a=>{m.castShapeObject(a.GetShape()).GetType()!==m.instance.b2Shape.e_edge&&m.drawFixture(a,this.pos,this.angle,t,e,s,i,o)}),this.edgeLists.forEach(a=>mo(a,s,e,!1,this.pos,this.angle)),this.edgeLoops.forEach(a=>mo(a,s,e,!0,this.pos,this.angle))}beginContact(t){}endContact(t){}addShape(t,e=1,s=.2,i=0,o=!1){f(L(e),"density must be a number"),f(L(s),"friction must be a number"),f(L(i),"restitution must be a number");let a=new m.instance.b2FixtureDef;return a.set_shape(t),a.set_density(e),a.set_friction(s),a.set_restitution(i),a.set_isSensor(o),this.body.CreateFixture(a)}addBox(t=b(1),e=b(),s=0,i,o,a,r){f(O(t),"size must be a Vector2"),f(t.x>0&&t.y>0,"size must be positive"),f(O(e),"offset must be a Vector2"),f(L(s),"angle must be a number");let c=new m.instance.b2PolygonShape;return c.SetAsBox(t.x/2,t.y/2,m.vec2dTo(e),-s),this.addShape(c,i,o,a,r)}addPoly(t,e,s,i,o){f(de(t),"points must be an array");function a(c){f(3<=c.length&&c.length<=8);let l=m.instance._malloc(c.length*8);for(let p=0,d=0;p>2]=c[p].x,d+=4,m.instance.HEAPF32[l+d>>2]=c[p].y,d+=4;let u=m.instance.wrapPointer(l,m.instance.b2Vec2),h=new m.instance.b2PolygonShape;return h.Set(u,c.length),m.instance._free(l),h}let r=a(t);return this.addShape(r,e,s,i,o)}addRegularPoly(t=1,e=8,s,i,o,a){f(L(t)&&t>0,"diameter must be a positive number"),f(L(e)&&e>2,"sides must be a positive number greater than 2");let r=[],c=t/2;for(let l=e;l--;)r.push(b(c,0).rotate((l+.5)/e*X*2));return this.addPoly(r,s,i,o,a)}addRandomPoly(t=1,e,s,i,o){f(L(t)&&t>0,"diameter must be a positive number");let a=or(3,9),r=[],c=t/2;for(let l=a;l--;)r.push(b(dt(c/2,c*1.5),0).rotate(l/a*X*2));return this.addPoly(r,e,s,i,o)}addCircle(t=1,e=b(),s,i,o,a){f(L(t)&&t>0,"diameter must be a positive number"),f(O(e),"offset must be a Vector2");let r=new m.instance.b2CircleShape;return r.set_m_p(m.vec2dTo(e)),r.set_m_radius(t/2),this.addShape(r,s,i,o,a)}addEdge(t,e,s,i,o,a){f(O(t),"point1 must be a Vector2"),f(O(e),"point2 must be a Vector2");let r=new m.instance.b2EdgeShape;return r.Set(m.vec2dTo(t),m.vec2dTo(e)),this.addShape(r,s,i,o,a)}addEdgeList(t,e,s,i,o){f(de(t),"points must be an array");let a=[],r=[];for(let c=0;ct[se(l,t.length)];for(let l=0;lthis.destroyFixture(t))}getCenterOfMass(){return m.vec2From(this.body.GetWorldCenter())}getLinearVelocity(){return m.vec2From(this.body.GetLinearVelocity())}getAngularVelocity(){return this.body.GetAngularVelocity()}getMass(){return this.body.GetMass()}getInertia(){return this.body.GetInertia()}getIsAwake(){return this.body.IsAwake()}getBodyType(){return this.body.GetType()}getSpeed(){return this.getLinearVelocity().length()}setTransform(t,e){this.pos=t,this.angle=e,this.body.SetTransform(m.vec2dTo(t),-e)}setPosition(t){this.setTransform(t,this.body.GetAngle())}setAngle(t){this.setTransform(m.vec2From(this.body.GetPosition()),t)}setLinearVelocity(t){this.body.SetLinearVelocity(m.vec2dTo(t))}setAngularVelocity(t){this.body.SetAngularVelocity(t)}setLinearDamping(t){this.body.SetLinearDamping(t)}setAngularDamping(t){this.body.SetAngularDamping(t)}setGravityScale(t=1){this.body.SetGravityScale(this.gravityScale=t)}setBullet(t=!0){this.body.SetBullet(t)}setAwake(t=!0){this.body.SetAwake(t)}setBodyType(t){this.body.SetType(t)}setSleepingAllowed(t=!0){this.body.SetSleepingAllowed(t)}setFixedRotation(t=!0){this.body.SetFixedRotation(t)}setCenterOfMass(t){this.setMassData(t)}setMass(t){this.setMassData(void 0,t)}setMomentOfInertia(t){this.setMassData(void 0,void 0,t)}resetMassData(){this.body.ResetMassData()}setMassData(t,e,s){let i=new m.instance.b2MassData;this.body.GetMassData(i),t!==void 0&&i.set_center(m.vec2dTo(t)),e!==void 0&&i.set_mass(e),s!==void 0&&i.set_I(s),this.body.SetMassData(i)}setFilterData(t=0,e=0,s=0){this.getFixtureList().forEach(i=>{let o=i.GetFilterData();o.set_categoryBits(t),o.set_maskBits(65535&~e),o.set_groupIndex(s)})}setSensor(t=!0){this.getFixtureList().forEach(e=>e.SetSensor(t))}applyForce(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyForce(m.vec2dTo(t),m.vec2dTo(e))}applyAcceleration(t,e){e||(e=this.getCenterOfMass()),this.setAwake();let s=t.scale(this.getMass());this.body.ApplyLinearImpulse(m.vec2dTo(s),m.vec2dTo(e))}applyImpulse(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyLinearImpulse(m.vec2dTo(t),m.vec2dTo(e))}applyTorque(t){this.setAwake(),this.body.ApplyTorque(t)}applyAngularAcceleration(t){this.setAwake(),this.body.ApplyAngularImpulse(t*this.getInertia())}applyAngularImpulse(t){this.setAwake(),this.body.ApplyAngularImpulse(t)}hasFixtures(){return!m.isNull(this.body.GetFixtureList())}getFixtureList(){let t=[];for(let e=this.body.GetFixtureList();!m.isNull(e);)t.push(e),e=e.GetNext();return t}hasJoints(){return!m.isNull(this.body.GetJointList())}getJointList(){let t=[];for(let e=this.body.GetJointList();!m.isNull(e);)t.push(e),e=e.get_next();return t}},Si=class extends _s{constructor(t,e,s,i=0,o,a=0){let r=m.bodyTypeStatic;super(t,e,s,i,o,r,a)}},No=class extends _s{constructor(t,e,s,i=0,o,a=0){let r=m.bodyTypeKinematic;super(t,e,s,i,o,r,a)}},zo=class extends Si{constructor(t){f(t instanceof vs,"tileLayer must be a TileCollisionLayer"),super(t.pos,t.size),this.tileLayer=t,this.addChild(t)}render(){}buildCollision(t=.2,e=0){this.destroyAllFixtures(),this.pos=this.tileLayer.pos.copy(),this.size=this.tileLayer.size.copy();let s=[],i=(a,r)=>a+r*this.size.x,o=(a,r)=>!s[i(a,r)]&&this.tileLayer.getCollisionData(b(a,r))>0;for(let a=0;ai.fractiono.pos.distanceSquared(t)0,"Tween duration must be > 0"),this.callback=t,this.start=e,this.end=s,this.duration=i,this.life=i,this.ease=o.ease||Ci.LINEAR,this.useRealTime=!!o.useRealTime,this.paused=!!o.paused,this.thenCallback=void 0,this.loopRemaining=0,Yt.push(this),t(this.interp(i))}setEase(t){return this.ease=t,this}then(t){return this.thenCallback=t,this.loopRemaining=0,this}loop(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Lc(this),this}pingPong(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Oc(this),this}pause(){this.paused=!0}resume(){this.paused=!1}restart(){this.life=this.duration,this.paused=!1,Yt.indexOf(this)<0&&Yt.push(this),this.callback(this.interp(this.duration))}isActive(){return!this.paused&&Yt.indexOf(this)>=0}getPercent(){return jt(this.duration-this.life,0,this.duration)}getValue(){return this.interp(this.life)}interp(t){let e=this.ease((this.duration-t)/this.duration);return La(this.start)?this.start.lerp(this.end,e):this.start+(this.end-this.start)*e}stop(){let t=Yt.indexOf(this);t>=0&&Yt.splice(t,1),this.thenCallback=void 0}},Ci={LINEAR:n=>n,POWER:n=>t=>t**n,SINE:n=>1-ct(n*(X/2)),CIRC:n=>1-(1-n*n)**.5,EXPO:n=>n===0?0:2**(10*n-10),BACK:n=>n*n*(2.70158*n-1.70158),ELASTIC:n=>n===0?0:n===1?1:-(2**(10*n-10))*st((37-40*n)*X/6),SPRING:n=>1-(st(X*(1-n)*(.2+2.5*(1-n)**3))*n**2.2+(1-n))*(1+1.2*n),BOUNCE:n=>{let t=1-n,e;return t<4/11?e=7.5625*t*t:t<8/11?e=7.5625*(t-=6/11)*t+.75:t<10/11?e=7.5625*(t-=9/11)*t+.9375:e=7.5625*(t-=10.5/11)*t+.984375,1-e},IN:n=>n,OUT:n=>t=>1-n(1-t),IN_OUT:n=>Ci.PIECEWISE(n,Ci.OUT(n)),PIECEWISE:(...n)=>{let t=n.length;return e=>{let s=e*t-1e-9>>0;return(n[s]((e-s/t)*t)+s)/t}},BEZIER:(n,t,e,s)=>{let i=o=>{let a=1-o,r=3*a*a*o,c=3*a*o*o,l=o**3;return[r*n+c*e+l,r*t+c*s+l]};return o=>{let a=0,r=1;for(let c=0;c<128;c++){let l=(a+r)/2,[u,h]=i(l);if(nt(u-o)<1e-5)return h;u=this.size.x||e>=this.size.y?null:this.nodes[t+e*this.size.x]}worldToTile(t){let e=this.tileLayer?this.tileLayer.pos.x:0,s=this.tileLayer?this.tileLayer.pos.y:0;return b(St(t.x-e),St(t.y-s))}tileToWorld(t,e){let s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;return b(t+.5+s,e+.5+i)}buildNodeData(){let t=this.size.x,e=this.size.y,s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;for(let o=0;o0&&(c?l>0&&bt(r.posWorld,lo,J(1,0,0,tt(.2,l*.05)),this.debugTime):bt(r.posWorld,lo,J(1,0,0,.25),this.debugTime))}}aStarSearch(t,e){f(t&&e,"aStarSearch needs both endpoints"),f(t!==e,"aStarSearch: start and end must differ \u2014 caller should handle trivial case"),f(t.walkable&&e.walkable,"aStarSearch: endpoints must be walkable");let s=[t];t.isOpen=!0;let i=0;for(;s.length>0;){let o=0,a=s[0].f;for(let c=1;cthis.maxLoop)break;r.isOpen=!1,s.splice(o,1),r.isClosed=!0,this.debug&&this.debugTime>0&&bt(r.posWorld,lo,J(1,1,1,.05),this.debugTime);for(let c=-1;c<=1;++c)for(let l=-1;l<=1;++l){if(l===0&&c===0)continue;let u=this.getNode(r.pos.x+l,r.pos.y+c);if(!u||!u.walkable||u.isClosed)continue;let h=1;if(l!==0&&c!==0){let v=this.getNode(r.pos.x+l,r.pos.y);if(!v||!v.walkable)continue;let w=this.getNode(r.pos.x,r.pos.y+c);if(!w||!w.walkable)continue;h=fd}let p=r.g+h+u.cost;if(!u.isOpen)u.isOpen=!0,s.push(u);else if(p>=u.g)continue;u.parent=r,u.g=p;let d=nt(e.pos.x-u.pos.x),y=nt(e.pos.y-u.pos.y),x=K(d,y)+(Math.SQRT2-1)*tt(d,y);u.f=u.g+x*this.heuristicWeight}}return e.parent!==null}getNearestClearNode(t,e=10,s=!0){f(O(t),"worldPos must be a Vector2"),s&&this.buildNodeData();let i=this.tileLayer?this.tileLayer.pos.x:0,o=this.tileLayer?this.tileLayer.pos.y:0,a=St(t.x-i),r=St(t.y-o);for(let c=0;c<=e;++c){let l=null,u=0;for(let h=-c;h<=c;++h)for(let p=-c;p<=c;++p){if(c>0&&nt(p)!==c&&nt(h)!==c)continue;let d=this.getNode(a+p,r+h);if(!d||!d.isClear())continue;let y=d.posWorld.x-t.x,x=d.posWorld.y-t.y,v=y*y+x*x;(!l||v0&&Jt(i.posWorld,.3,J(.5,0,.5,.5),this.debugTime),t.splice(e,1),e=K(1,e-1);continue}else if(c===2){this.debug&&this.debugTime>0&&Jt(i.posWorld,.3,J(1,0,0,.5),this.debugTime);let d,y;s.pos.y===i.pos.y&&o.pos.x===i.pos.x?(d=s.pos.x,y=o.pos.y):(d=o.pos.x,y=s.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t.splice(e,1),e=K(1,e-1);continue}}else if(c===5){this.debug&&this.debugTime>0&&Jt(i.posWorld,.3,J(1,1,0,.5),this.debugTime);let d=e>=2?t[e-2]:s,y,x,v,w;l===0||h===0?(y=o.pos.x,x=i.pos.y,v=s.pos.x,w=i.pos.y):(y=i.pos.x,x=o.pos.y,v=i.pos.x,w=s.pos.y);let _=y-d.pos.x,S=x-d.pos.y,C=v-d.pos.x,A=w-d.pos.y,T=_*_+S*S,P=C*C+A*A,M=T0&&Jt(i.posWorld,.3,J(0,1,0,.5),this.debugTime),l===h&&u===p){++e;continue}else{let d,y;s.pos.y===o.pos.y?(d=i.pos.x,y=s.pos.y):(d=s.pos.x,y=i.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t[e]=x,e=K(1,e-1);continue}}++e}}smoothPathStringPull(t){if(t.length<=2)return;for(let i of t)if(!i.isClear())return;let e=t.slice();t.length=0,t.push(e[0]);let s=0;for(let i=1;i0&&we(o.posWorld,t[t.length-1].posWorld,J(0,0,1,.3),.02,this.debugTime);continue}for(;s=1;--e){let s=t[e-1],i=t[e],o=t[e+1];(i.pos.x-s.pos.x)*(o.pos.y-s.pos.y)===(i.pos.y-s.pos.y)*(o.pos.x-s.pos.x)&&t.splice(e,1)}}isNodeClear(t,e){let s=this.getNode(t,e);return s!==null&&s.isClear()}isLineClear(t,e){f(O(t)&&O(e),"isLineClear needs Vector2 endpoints"),f(this.isNodeClear(t.x,t.y)&&this.isNodeClear(e.x,e.y),"isLineClear endpoints must be in-bounds and clear");let s=e.x-t.x,i=e.y-t.y,o=nt(s),a=nt(i),r=ne(s),c=ne(i),l=t.x,u=t.y;if(a===o){for(;l!==e.x;){if(l!==t.x&&(!this.isNodeClear(l,u)||!this.isNodeClear(l,u-c))||!this.isNodeClear(l,u+c))return!1;l+=r,u+=c}if(!this.isNodeClear(e.x,e.y-c))return!1}else if(ar.posWorld.copy());if(this.debug&&this.debugTime>0&&a.length>0){for(let r=1;rpd,bootGameHost:()=>yd,default:()=>gd});var js=class{constructor(t){this._state=(t==null?2654435769:t)>>>0}next(){this._state=this._state+1831565813>>>0;let t=this._state;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}range(t,e){return t+this.next()*(e-t)}reseed(t){this._state=(t==null?2654435769:t)>>>0}},Ji=class{constructor(t){this._clock=t||Jc(),this._origin=this._clock()}nowMs(){return this._clock()}elapsedMs(){return this._clock()-this._origin}},Ui=class{constructor(t){this._time=t,this._subs=new Map}sourceFor(t){let e=this,s=t==null?null:t;return{on(i,o){if(e._assertType(i),typeof o!="function")throw new Error("[HostDevInputBridge] on \u7684 handler \u5FC5\u987B\u662F\u51FD\u6570");let a=e._subs.get(i)||[],r={handler:o,scope:s};return a.push(r),e._subs.set(i,a),{cancel(){let c=e._subs.get(i);if(!c)return;let l=c.indexOf(r);l>=0&&c.splice(l,1)}}},off(i,o){e._assertType(i);let a=e._subs.get(i);if(!a)return;let r=a.findIndex(c=>c.handler===o&&c.scope===s);r>=0&&a.splice(r,1)}}}_emit(t,e){this._assertType(t);let s=e||{},i={type:t,x:typeof s.x=="number"?s.x:0,y:typeof s.y=="number"?s.y:0,key:typeof s.key=="string"?s.key:"",tMs:this._time.nowMs()},o=this._subs.get(t);if(!o||o.length===0)return;let a=o.slice();for(let r of a)try{r.handler(i)}catch(c){qe("[host-dev input] \u8F93\u5165 handler \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09type="+t,c)}}disposeScope(t){if(t==null)return 0;let e=0;for(let[s,i]of this._subs){let o=i.filter(a=>a.scope!==t);e+=i.length-o.length,o.length===0?this._subs.delete(s):this._subs.set(s,o)}return e}_subscriptionCount(){let t=0;for(let e of this._subs.values())t+=e.length;return t}_assertType(t){if(!Vi.has(t))throw new Error("[HostDevInputBridge] \u975E\u6CD5\u8F93\u5165\u4E8B\u4EF6\u7C7B\u578B\uFF1A"+String(t)+"\uFF08\u4EC5\u652F\u6301 "+Array.from(Vi).join("/")+"\uFF09")}},Vi=new Set(["pointerdown","pointermove","pointerup","keydown","keyup"]);function Xr(n){let t=n||{},e=new Ji(t.clock),s=new js(t.seed),i=t.seed==null?2654435769:t.seed>>>0,o=new Ui(e),a=typeof t.audioFactory=="function"?t.audioFactory:null,r=null,c=!1,l=typeof t.engineFactory=="function"?t.engineFactory:null,u=null,h=!1,p=new Map,d=0,y=0;function x(){if(r)return r;if(!a)return c||(qi("[host-dev audio] \u672A\u6CE8\u5165 audioFactory\uFF0CgetAudioContext \u8FD4\u56DE null\uFF08P6 \u987B\u5BB9\u9519\u964D\u7EA7\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u5DE5\u5382\uFF09"),c=!0),null;try{r=a()}catch(C){qe("[host-dev audio] audioFactory \u629B\u9519\uFF0CgetAudioContext \u964D\u7EA7\u8FD4\u56DE null",C),r=null}return r}function v(){if(u)return u;if(!l)return h||(qi("[host-dev engine] \u672A\u6CE8\u5165 engineFactory\uFF0CgetEngine \u8FD4\u56DE null\uFF08\u63D2\u4EF6\u987B\u5BB9\u9519\u964D\u7EA7\uFF1A\u7C92\u5B50\u9000\u53D7\u63A7\u9762\u81EA\u7BA1/\u5408\u6210\u6838\u9000 vendored/\u6570\u5B66\u9000\u5185\u7F6E\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u80CC\u4E66\uFF09"),h=!0),null;try{u=l()}catch(C){qe("[host-dev engine] engineFactory \u629B\u9519\uFF0CgetEngine \u964D\u7EA7\u8FD4\u56DE null",C),u=null}return u}function w(C,A){return{getContext2d(){return t.context2d==null?null:t.context2d},onFrame(P){let M=d++;return p.set(M,P),{cancel(){p.delete(M)}}},getInput(){return o.sourceFor(C)},getAudioContext(){return x()},getEngine(){return v()},time:e,random:A}}let _=w(null,s),S={context:_,tick(C){y+=1;let A=Array.from(p.values());for(let T of A)try{T(C,y)}catch(P){qe("[host-dev tick] \u5E27\u56DE\u8C03\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09frame="+y,P)}},frameCount(){return y},inputBridge:o,deriveContextFor(C,A){let T=zc(i,C),P=new js(T);return w(A==null?C:A,P)}};return Object.defineProperty(_,Wi,{value:S,enumerable:!1,writable:!1,configurable:!1}),S}var Wi=Symbol("zaomeng.coreProtocol.contextBundle"),Bs=class{constructor(){this._plugins=new Map,this._initOrder=[],this._initErrors=[],this._phase="idle",this._disposed=!1,this._context=void 0,this._pluginContexts=new Map}register(t){if(!t||typeof t!="object")throw new Error("[PluginRegistry] register \u9700\u8981\u4E00\u4E2A\u63D2\u4EF6\u5BF9\u8C61");if(typeof t.name!="string"||t.name.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6\u7F3A\u5C11\u5408\u6CD5 name");if(typeof t.version!="string"||t.version.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11\u5408\u6CD5 version");if(typeof t.init!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11 init \u51FD\u6570");if(t.dispose!=null&&typeof t.dispose!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7684 dispose \u5FC5\u987B\u662F\u51FD\u6570\u6216\u7701\u7565");if(this._plugins.has(t.name))throw new Error("[PluginRegistry] \u63D2\u4EF6\u91CD\u540D\u62D2\u7EDD\uFF1A"+t.name+" \u5DF2\u6CE8\u518C");return this._plugins.set(t.name,t),this}has(t){return this._plugins.has(t)}get(t){return this._plugins.get(t)}list(){return Array.from(this._plugins.keys())}initAll(){if(this._phase==="initialized")return qi("[PluginRegistry] initAll \u91CD\u590D\u8C03\u7528\uFF0C\u5DF2\u5FFD\u7565\uFF08\u5DF2\u5904\u4E8E initialized\uFF09"),this._initResult();if(this._phase==="disposed")throw new Error("[PluginRegistry] \u5DF2 dispose \u7684\u6CE8\u518C\u5668\u4E0D\u53EF\u518D initAll");if(this._context==null)throw new Error("[PluginRegistry] \u672A\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\uFF1A\u8BF7\u5728 initAll() \u4E4B\u524D\u8C03\u7528 useContext(context)\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context); reg.initAll();\uFF09");for(let[t,e]of this._plugins){let s=this._missingDeps(e);if(s.length>0){let o=new Error("[PluginRegistry] \u63D2\u4EF6 "+t+" \u4F9D\u8D56\u7F3A\u5931\uFF1A"+s.join(", ")+"\uFF08\u672A\u6CE8\u518C\uFF09");this._initErrors.push({name:t,error:o}),qe("[PluginRegistry] \u8DF3\u8FC7 init\uFF08\u4F9D\u8D56\u7F3A\u5931\uFF0C\u5DF2\u9694\u79BB\uFF09\uFF1A"+t,o);continue}let i=this._contextFor(t);try{e.init(i),this._initOrder.push(t)}catch(o){let a=o instanceof Error?o:new Error(String(o));this._initErrors.push({name:t,error:a}),qe("[PluginRegistry] \u63D2\u4EF6 init \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF0C\u4E0D\u8FDE\u5750\uFF09\uFF1A"+t,a)}}return this._phase="initialized",this._initResult()}_contextFor(t){let e=this._pluginContexts.get(t);if(e)return e;let s=this._context&&this._context[Wi],i;return s&&typeof s.deriveContextFor=="function"?i=s.deriveContextFor(t,t):i=this._context,this._pluginContexts.set(t,i),i}disposeAll(){if(this._disposed)return{disposed:[],errors:[]};let t=[],e=[],s=this._context&&this._context[Wi],i=s&&s.inputBridge;for(let o=this._initOrder.length-1;o>=0;o--){let a=this._initOrder[o],r=this._plugins.get(a);if(r&&typeof r.dispose=="function")try{r.dispose(),t.push(a)}catch(c){let l=c instanceof Error?c:new Error(String(c));e.push({name:a,error:l}),qe("[PluginRegistry] \u63D2\u4EF6 dispose \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+a,l)}if(i&&typeof i.disposeScope=="function")try{i.disposeScope(a)}catch(c){qe("[PluginRegistry] \u56DE\u6536\u63D2\u4EF6\u8F93\u5165\u8BA2\u9605\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+a,c)}}return this._disposed=!0,this._phase="disposed",{disposed:t,errors:e}}useContext(t){if(this._phase!=="idle")throw new Error("[PluginRegistry] useContext \u5FC5\u987B\u5728 initAll() \u4E4B\u524D\u8C03\u7528\uFF08\u5F53\u524D\u9636\u6BB5\uFF1A"+this._phase+"\uFF09\u3002\u8BF7\u5728\u4EFB\u4F55 initAll/disposeAll \u4E4B\u524D\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\u3002");if(t==null||typeof t!="object")throw new Error("[PluginRegistry] useContext \u9700\u8981\u4E00\u4E2A\u53D7\u63A7\u4E0A\u4E0B\u6587\u5BF9\u8C61\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context);\uFF09");return this._context=t,this}_missingDeps(t){return!Array.isArray(t.dependencies)||t.dependencies.length===0?[]:t.dependencies.filter(e=>!this._plugins.has(e))}_initResult(){return{ok:this._initErrors.length===0,initialized:this._initOrder.slice(),errors:this._initErrors.slice()}}};function zc(n,t){let e=2166136261,s=16777619,i=n>>>0;for(let a=0;a<32;a+=8){let r=i>>>a&255;e^=r,e=Math.imul(e,s)>>>0}let o=String(t);for(let a=0;a>>0,e^=r>>>8&255,e=Math.imul(e,s)>>>0}return e>>>0}function Jc(){if(typeof globalThis!="undefined"&&globalThis.performance&&typeof globalThis.performance.now=="function")return()=>globalThis.performance.now();if(typeof process!="undefined"&&process.hrtime&&typeof process.hrtime.bigint=="function"){let n=process.hrtime.bigint();return()=>Number(process.hrtime.bigint()-n)/1e6}return()=>Date.now()}function qe(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function qi(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var xd=Object.freeze(Array.from(Vi)),Yr="core-protocol-v0";var $r=Object.freeze(["t_boot","t_plugins_ready","t_game_init","t_first_paint","t_input_bound","t_game_start"]),Hi=$r.reduce((n,t,e)=>(n[t]=e,n),Object.create(null)),Uc=new Set($r);function Xi(n){let t=2166136261;for(let e=0;e>>0).toString(16).padStart(8,"0")}var Kr=Xi("runtime-probe::seed::v1");function Ns(n){return n===null||typeof n!="object"?JSON.stringify(n):Array.isArray(n)?"["+n.map(Ns).join(",")+"]":"{"+Object.keys(n).sort().map(e=>JSON.stringify(e)+":"+Ns(n[e])).join(",")+"}"}function Qr(n){let t=Ns(n.extra==null?null:n.extra),e=Ns(Array.isArray(n.pluginSet)?n.pluginSet:[]);return["seq="+n.seq,"anchor="+n.anchor,"tMono="+n.tMono,"buildSha="+(n.buildSha||""),"pluginSet="+e,"extra="+t].join("|")}function Vc(n){return Math.round(n*1e3)/1e3}function Wc(n){if(!Array.isArray(n))return{ok:!1,reason:"records_not_array"};let t=Kr,e=-1;for(let s=0;stypeof C=="string").slice().sort():[],i=typeof t.sink=="function"?t.sink:null,o=t.autoBoot!==!1,a=typeof t.inputAnchorType=="string"?t.inputAnchorType:"pointerdown",r=()=>0,c=!1,l=0,u=Kr,h=[],p=new Set,d=-1,y=null,x=!1,v=!1,w=!1;function _(C,A){let T=null;if(!Uc.has(C))T="unknown_anchor";else{p.has(C)&&(T=T?T+";duplicate_anchor":"duplicate_anchor");let M=Hi[C];MC.time.nowMs(),c=!0,o&&!v&&_("t_boot",{auto:!0}),y=C.getInput().on(a,A=>{x||(x=!0,_("t_input_bound",{firstInput:!0,type:A.type}))}),_("t_input_bound",{stage:"registered",type:a})},dispose(){w||(y&&(y.cancel(),y=null),w=!0)},mark:_,getRecords(){return h.map(C=>({...C}))},toJSONL(){return h.map(C=>JSON.stringify(C)).join(`
-`)},verify(){return Wc(h)}}}function qc(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function ta(n){let t=n.LJS,e=n.engineMath,s=n.engineMode,i=n.recHook||(()=>{});if(s!=="real")return null;let o=e;return{math:{lerp:(r,c,l)=>(i("math.lerp"),o.lerp(r,c,l)),smoothStep:r=>(i("math.smoothStep"),o.smoothStep(r)),easing:Object.fromEntries(Object.keys(o.easing).map(r=>[r,c=>(i("math.easing."+r),o.easing[r](c))]))},particles:{spawnEmitter(r){i("particles.spawnEmitter");let c=t.screenToWorld(t.vec2(r.pos.x,r.pos.y)),l=t.cameraScale,u=r.emitTime!=null?r.emitTime:r.count!=null?1/60:0,h=r.emitRate!=null?r.emitRate:r.count!=null?r.count*60:100,p=(r.speed!=null?r.speed:0)/l/60,d=r.damping!=null?r.damping:1,y=r.colorStart||{r:1,g:1,b:1,a:1},x=r.colorEnd||{r:1,g:1,b:1,a:0},v=t.rgb(y.r,y.g,y.b,y.a),w=t.rgb(x.r,x.g,x.b,x.a),_=new t.ParticleEmitter(c,r.angle!=null?r.angle:0,(r.emitSize!=null?r.emitSize:0)/l,u,h,r.coneAngle!=null?r.coneAngle:Math.PI,void 0,v,v,w,w,r.particleTime!=null?r.particleTime:.5,(r.sizeStart!=null?r.sizeStart:6)/l,(r.sizeEnd!=null?r.sizeEnd:0)/l,p,0,d,1,r.gravityScale!=null?r.gravityScale:0,Math.PI,.1,0,!1,r.additive!=null?r.additive:!1,!0);return{isActive(){return _.isActive()},stop(){_.destroyed||_.destroy(!0)}}}},audio:{synth:{synthSfx:r=>{i("audio.synth.synthSfx");try{return t.zzfxG(...r)}catch(c){return console.error("[host][engine-audio] zzfxG \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(c&&c.message?c.message:c)),null}},synthSong:(r,c,l,u)=>{i("audio.synth.synthSong");try{return t.zzfxM(r,c,l,u)}catch(h){return console.error("[host][engine-audio] zzfxM \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(h&&h.message?h.message:h)),null}}}}}}function ce(n){return n<0?0:n>1?1:n}function ea(n){let t=n.Ease,e=t.POWER(2),s=t.POWER(3),i=t.OUT(e),o=t.IN_OUT(e),a=t.OUT(s),r=t.IN_OUT(s),c=t.OUT(t.BACK),l=t.OUT(t.ELASTIC);return{lerp:(u,h,p)=>n.lerp(u,h,p),smoothStep:u=>n.smoothStep(u),easing:{linear:u=>t.LINEAR(ce(u)),quadIn:u=>e(ce(u)),quadOut:u=>i(ce(u)),quadInOut:u=>o(ce(u)),cubicIn:u=>s(ce(u)),cubicOut:u=>a(ce(u)),cubicInOut:u=>r(ce(u)),backIn:u=>t.BACK(ce(u)),backOut:u=>c(ce(u)),elasticIn:u=>t.ELASTIC(ce(u)),elasticOut:u=>l(ce(u))}}}var He=2,zs=1/60;async function na(n){let t=n.canvas,e=n.statusEl||null,s=n.engine,i=n.seed>>>0,o=n.mode||"play",a=n.engineMode||"real",r=n.viewport.w,c=n.viewport.h,l=n.factory,u=n.buildFactoryOpts||(()=>{}),h=n.plugins||{},p=n.registerOrder||Object.values(h),d=n.onReady||(()=>{}),y=n.recHook||(()=>{});function x(D){e&&(e.textContent=D)}let v=[];window.addEventListener("error",D=>v.push({type:"error",message:String(D&&D.message||D)})),window.addEventListener("unhandledrejection",D=>v.push({type:"unhandledrejection",message:String(D&&D.reason&&D.reason.message||D&&D.reason||D)}));let w=null,_=!1;function S(){if(!_)return null;if(w)return w;let D=window.AudioContext||window.webkitAudioContext;return D?(w=new D,w):null}let C=0,A=null,T=null,P=null,M=null,pt=[],rt={},at=null;function yt(D,lt){try{P&&P.mark(D,lt)}catch(te){v.push({type:"mark",message:String(te&&te.message||te)})}}function Bt(){T&&typeof T._refreshChecklist=="function"&&T._refreshChecklist(rt)}async function ge(D,lt){A=Xr({context2d:D,seed:i,audioFactory:S,clock:()=>C,engineFactory:()=>ta({LJS:a==="real"?s:null,engineMath:a==="real"?ea(s):null,engineMode:a,recHook:y})});let te=new Bs;for(let ye of p)te.register(ye);te.useContext(A.context),M=te.initAll(),pt=te.list().concat(["runtime-probe"]),P=Zr({pluginSet:pt,inputAnchorType:"pointerdown",autoBoot:!0});let ee=A.deriveContextFor("runtime-probe","runtime-probe");yt("t_boot",{by:"game-host",stage:"pre-init",engineMode:a}),yt("t_plugins_ready",{initialized:M.initialized.length,ok:M.ok});let Ni=u(A.context,{bundle:A,plugins:h,getRealAudioCtx:()=>w});T=l(Ni),await T.init({ctx:A.context,mainContext:D,canvas:lt(),seed:i}),at=T&&typeof T._forensicsView=="function"?T._forensicsView():null,yt("t_game_init",{hasForensics:!!at}),ht(),yt("t_first_paint",{frame:A.frameCount()});try{P.init(ee)}catch(ye){v.push({type:"probe-init",message:String(ye&&ye.message||ye)})}yt("t_game_start",{mode:o,engineMode:a}),Bt(),d(un,{bundle:A,game:T,probe:P,checklist:rt,uncaught:v,pluginSet:pt,initRes:M,getGameForensics:()=>at,mark:yt,stepOneFrame:ht})}let Pt=null;function ht(D){let lt=typeof D=="number"?D:zs;T&&(C+=lt*1e3,T.update(lt),a==="stub"&&Pt&&T.render(Pt),Bt())}function Lt(D){for(let lt=0;lt{}),T&&typeof T._onAudioUnlock=="function"&&T._onAudioUnlock()}let un={seed:i,mode:o,engineMode:a,protocol:Yr,frameCount:()=>A?A.frameCount():0,stepFrames:Lt,startRaf:()=>F(),stopRaf:()=>k(),tap(D,lt){We(),A&&(A.inputBridge._emit("pointerdown",{x:D,y:lt}),A.inputBridge._emit("pointerup",{x:D,y:lt}))},do(D){T&&typeof T._handleAction=="function"&&T._handleAction(D)},state:()=>at?at.state():{phase:"booting"}};function hn(D){let lt=A.inputBridge;function te(ee,Ni){let ye=D.getBoundingClientRect();return{x:(ee-ye.left)/ye.width*r,y:(Ni-ye.top)/ye.height*c}}D.addEventListener("pointerdown",ee=>{We(),lt._emit("pointerdown",te(ee.clientX,ee.clientY))}),D.addEventListener("pointermove",ee=>{lt._emit("pointermove",te(ee.clientX,ee.clientY))}),D.addEventListener("pointerup",ee=>{lt._emit("pointerup",te(ee.clientX,ee.clientY))})}let ae=0,Pe=!1,Zt=0;function R(D){if(!Pe)return;Zt===0&&(Zt=D);let lt=(D-Zt)/1e3;Zt=D,lt>.05&&(lt=.05),ht(lt),ae=window.requestAnimationFrame(R)}function F(){a==="stub"&&(Pe||(Pe=!0,Zt=0,ae=window.requestAnimationFrame(R)))}function k(){Pe=!1,ae&&window.cancelAnimationFrame(ae),ae=0}function j(D){D.width=r*He,D.height=c*He,D.style.width=r+"px",D.style.height=c+"px";let lt=D.getContext("2d",{willReadFrequently:!0});return lt.setTransform(He,0,0,He,0,0),lt}async function $(){let D=j(t);return Pt=D,await ge(D,()=>t),hn(t),o==="evidence"?x(`evidence \u5C31\u7EEA seed=${i} \xB7 \u7528 host \u9A71\u52A8\uFF08stepFrames/tap\uFF09`):(x(`seed=${i} \xB7 \u70B9\u5F00\u59CB\uFF08\u9996\u6B21\u70B9\u51FB\u5F00\u58F0\uFF09`),F()),un}let Z=()=>{},Tt=()=>{};function At(){window.__gameHostEngineInitFired=!0}function Ot(){Z()}function Le(){}function Zn(){Tt()}function dn(){}async function Fs(D){await ge(D,()=>s.mainCanvas),hn(s.mainCanvas),Z=()=>{T&&(C+=zs*1e3,T.update(zs))},Tt=()=>{if(T){D.save(),D.setTransform(He,0,0,He,0,0);try{D.imageSmoothingEnabled=!1}catch{}T.render(D),D.restore()}},s.mainCanvas&&(s.mainCanvas.id="game-engine"),window.__engine={frame(){return s.frame},time(){return s.time},timeReal(){return s.timeReal},paused(){return s.paused},timeScale(){return s.timeScale},snapshot(){return{frame:s.frame,time:s.time,timeReal:s.timeReal,paused:s.paused,timeScale:s.timeScale}}},x(`engine RAF running \xB7 seed=${i} engine=real`)}if(a!=="real")return await $();if(!s){let D="real \u901A\u9053\u672A\u6CE8\u5165\u5F15\u64CE\uFF08opts.engine \u7F3A\u5931\uFF09\uFF1A\u8BF7\u7ECF entry \u5305\u88C5\u5C42\u542F\u52A8\uFF08host \u4E0D\u76F4\u63A5 import \u5F15\u64CE\uFF0CQ4/Option C\uFF09";throw x("ENGINE INJECT MISSING: "+D),new Error(D)}s.setGLEnable(!1),s.setShowSplashScreen(!1),s.setDebugWatermark(!1),s.setCanvasClearColor(s.BLACK),s.setCanvasFixedSize(s.vec2(r*He,c*He));let Dn=document.createElement("div");return Dn.id="engine-root",document.body.appendChild(Dn),await s.engineInit(At,Ot,Le,Zn,dn,[],Dn).then(()=>Fs(s.mainContext)).catch(D=>{throw window.__gameHostBootError=String(D&&D.message||D),x("ENGINE INIT FAILED: "+window.__gameHostBootError),D}),un}var Yi=class{constructor(t){let e=t||{},s=typeof e.cellSize=="number"&&e.cellSize>0?e.cellSize:64;this._cellSize=s,this._cells=new Map,this._entries=new Map,this._seq=0}get size(){return this._entries.size}_cellRange(t){let e=this._cellSize,s=Math.floor((t.x-t.hw)/e),i=Math.floor((t.x+t.hw)/e),o=Math.floor((t.y-t.hh)/e),a=Math.floor((t.y+t.hh)/e);return{cx0:s,cy0:o,cx1:i,cy1:a}}insert(t,e){this._entries.has(t)&&this.remove(t);let{cx0:s,cy0:i,cx1:o,cy1:a}=this._cellRange(e),r=[];for(let l=i;l<=a;l++)for(let u=s;u<=o;u++){let h=u+","+l,p=this._cells.get(h);p||(p=new Set,this._cells.set(h,p)),p.add(t),r.push(h)}let c={x:e.x,y:e.y,hw:e.hw,hh:e.hh};this._entries.set(t,{id:t,box:c,seq:this._seq++,cells:r})}remove(t){let e=this._entries.get(t);if(!e)return!1;for(let s of e.cells){let i=this._cells.get(s);i&&(i.delete(t),i.size===0&&this._cells.delete(s))}return this._entries.delete(t),!0}query(t){let{cx0:e,cy0:s,cx1:i,cy1:o}=this._cellRange(t),a=new Set;for(let r=s;r<=o;r++)for(let c=e;c<=i;c++){let l=this._cells.get(c+","+r);if(l)for(let u of l)a.add(u)}return this._collect(a)}queryPoint(t,e){let s=this._cellSize,i=Math.floor(t/s),o=Math.floor(e/s),a=this._cells.get(i+","+o);return a?this._collect(new Set(a)):[]}clear(){this._cells.clear(),this._entries.clear(),this._seq=0}_collect(t){let e=[];for(let s of t){let i=this._entries.get(s);i&&e.push(i)}return e.sort((s,i)=>s.seq-i.seq),e.map(s=>({id:s.id,box:s.box}))}};function sa(n){let t=n||{},e=new Yi({cellSize:t.cellSize}),s=!1;return{name:"collision",version:"1.0.0",dependencies:[],spatial:e,init(o){},dispose(){s||(e.clear(),s=!0)}}}function ia(n){let t=!1;return{name:"physics-lite",version:"1.0.0",dependencies:[],init(s){},dispose(){t||(t=!0)}}}var Hc=["pointerdown","pointermove","pointerup","keydown","keyup"];function Nt(n){return n<0?0:n>1?1:n}var Xc=n=>(n=Nt(n),n*n),Yc=n=>(n=Nt(n),1-(1-n)*(1-n)),$c=n=>(n=Nt(n),n<.5?2*n*n:1-Math.pow(-2*n+2,2)/2),Kc=n=>(n=Nt(n),n*n*n),Qc=n=>{n=Nt(n);let t=1-n;return 1-t*t*t},Zc=n=>(n=Nt(n),n<.5?4*n*n*n:1-Math.pow(-2*n+2,3)/2),aa=2*Math.PI/3,oa=2*Math.PI/4.5,tl=n=>(n=Nt(n),n===0?0:n===1?1:-Math.pow(2,10*n-10)*Math.sin((n*10-10.75)*aa)),el=n=>(n=Nt(n),n===0?0:n===1?1:Math.pow(2,-10*n)*Math.sin((n*10-.75)*aa)+1),nl=n=>(n=Nt(n),n===0?0:n===1?1:n<.5?-(Math.pow(2,20*n-10)*Math.sin((20*n-11.125)*oa))/2:Math.pow(2,-20*n+10)*Math.sin((20*n-11.125)*oa)/2+1),Us=1.70158,Js=Us*1.525,ca=Us+1,sl=n=>(n=Nt(n),ca*n*n*n-Us*n*n),il=n=>{n=Nt(n);let t=n-1;return 1+ca*t*t*t+Us*t*t},ol=n=>(n=Nt(n),n<.5?Math.pow(2*n,2)*((Js+1)*2*n-Js)/2:(Math.pow(2*n-2,2)*((Js+1)*(n*2-2)+Js)+2)/2),rl=n=>Nt(n),ra=Object.freeze({linear:rl,quadIn:Xc,quadOut:Yc,quadInOut:$c,cubicIn:Kc,cubicOut:Qc,cubicInOut:Zc,elasticIn:tl,elasticOut:el,elasticInOut:nl,backIn:sl,backOut:il,backInOut:ol});var al=["linear","quadIn","quadOut","quadInOut","cubicIn","cubicOut","cubicInOut","elasticIn","elasticOut","elasticInOut","backIn","backOut","backInOut"];function cl(n){let t=n&&n.easing;if(!t)return ra;let e=i=>typeof t[i]=="function"?o=>t[i](Nt(o)):ra[i],s={};for(let i of al)s[i]=e(i);return Object.freeze(s)}var $i=class{constructor(t,e,s){let i=s||{};this._time=e,this._windowMs=typeof i.windowMs=="number"&&i.windowMs>0?i.windowMs:120;let o=Array.isArray(i.types)&&i.types.length>0?i.types:Hc;this._records=new Map,this._subs=[],this._disposed=!1;for(let a of o){this._records.set(a,null);let r=t.on(a,c=>{this._records.set(a,c.tMs)});this._subs.push(r)}}consume(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs?(this._records.set(t,null),!0):(this._records.set(t,null),!1)}peek(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs}clear(){for(let t of this._records.keys())this._records.set(t,null)}dispose(){if(!this._disposed){for(let t of this._subs)try{t.cancel()}catch(e){}this._subs=[],this._disposed=!0}}};function la(n){let t=n||{},e=null,s=null,i=!1;return{name:"gamefeel",version:"1.0.0",dependencies:[],get inputBuffer(){return e},get easing(){return cl(s)},init(a){let r=a.getInput();e=new $i(r,a.time,{windowMs:t.inputBufferMs,types:t.inputTypes});let c=a.getEngine();s=c?c.math:null},dispose(){i||(e&&(e.dispose(),e=null),s=null,i=!0)}}}function Vs(n,t){let e=t<0?0:t>1?1:t;switch(n&&n.kind){case"constant":return n.value;case"linear":return n.from+(n.to-n.from)*e;case"easeInOut":{let s=e*e*(3-2*e);return n.from+(n.to-n.from)*s}case"decay":{let s=n.power==null?2:n.power,i=Math.pow(1-e,s);return n.to+(n.from-n.to)*i}default:return 0}}var ll=Object.freeze({burst:Object.freeze({mode:"burst",count:24,angle:0,spread:Math.PI,speedMin:80,speedMax:160,lifeMin:.4,lifeMax:.8,gravity:0,drag:0,sizeCurve:{kind:"decay",from:6,to:0,power:1.5},alphaCurve:{kind:"linear",from:1,to:0}}),trail:Object.freeze({mode:"continuous",rate:60,angle:Math.PI,spread:.25,speedMin:20,speedMax:50,lifeMin:.2,lifeMax:.5,gravity:0,drag:1.5,sizeCurve:{kind:"easeInOut",from:4,to:0},alphaCurve:{kind:"decay",from:.8,to:0,power:2}}),drift:Object.freeze({mode:"continuous",rate:12,angle:Math.PI/2,spread:.6,speedMin:10,speedMax:30,lifeMin:1.5,lifeMax:3,gravity:8,drag:.5,sizeCurve:{kind:"constant",value:3},alphaCurve:{kind:"decay",from:.7,to:0,power:1}})});function ul(n){let t=ll[n];return t?Ki(t):null}function Ki(n){let t={};for(let e of Object.keys(n)){let s=n[e];t[e]=s&&typeof s=="object"?Ki(s):s}return t}function hl(n,t,e){let s=n.mode==="continuous";return{pos:{x:t,y:e},angle:n.angle,coneAngle:n.spread,emitSize:0,emitTime:s?0:1/60,emitRate:s?n.rate||0:void 0,count:s?void 0:n.count||0,particleTime:(n.lifeMin+n.lifeMax)/2,speed:(n.speedMin+n.speedMax)/2,gravityScale:n.gravity||0,damping:n.drag!=null?1-n.drag/60:1,sizeStart:Vs(n.sizeCurve,0),sizeEnd:Vs(n.sizeCurve,1),colorStart:{r:1,g:1,b:1,a:Vs(n.alphaCurve,0)},colorEnd:{r:1,g:1,b:1,a:Vs(n.alphaCurve,1)},additive:!1}}function ua(n){let t=n||{},e=null,s=null,i=null,o=new Map,a=0,r={isActive(){return!1},stop(){}},c=0,l=1,u=0,h=0,p=0,d={x:0,y:0,remain:0,dur:0,amplitude:0,frequency:0,_phase:0},y={alpha:0,remain:0,dur:0,peak:0},x={scale:1,remain:0,dur:0,amplitude:0,frequency:0},v=!1;function w(A){if(u>0)if(u-=A,u<=0)u=0,l=1;else{let T=h>0?1-u/h:1;l=p+(1-p)*T}if(d.remain>0)if(d.remain-=A,d.remain<=0)d.remain=0,d.x=0,d.y=0;else{let T=d.remain/d.dur,P=d.amplitude*T;d._phase+=d.frequency*A*Math.PI*2,d.x=Math.sin(d._phase)*P,d.y=Math.cos(d._phase*1.3)*P}if(y.remain>0&&(y.remain-=A,y.remain<=0?(y.remain=0,y.alpha=0):y.alpha=y.peak*(y.remain/y.dur)),x.remain>0)if(x.remain-=A,x.remain<=0)x.remain=0,x.scale=1;else{let T=x.remain/x.dur,P=(1-T)*x.frequency*Math.PI*2;x.scale=1+Math.sin(P)*x.amplitude*T}}function _(A){c+=1,w(A)}function S(A){let T=A!==void 0?A:e?e.getContext2d():null;if(T&&y.alpha>0){T.globalAlpha=y.alpha,T.fillStyle="#ffffff";let P=T.canvas?T.canvas.width:0,M=T.canvas?T.canvas.height:0;T.fillRect(0,0,P,M),T.globalAlpha=1}}return{name:"particles-juice",version:"1.0.0",dependencies:[],init(A){var T;e=A,i=((T=A.getEngine())==null?void 0:T.particles)||null,typeof t.seed=="number"&&A.random.reseed(t.seed),t.autoStep!==!1&&(s=A.onFrame(P=>{_(P)}))},dispose(){v||(s&&(s.cancel(),s=null),o.forEach(A=>{try{A.stop()}catch{}}),o.clear(),l=1,u=0,d.remain=0,d.x=0,d.y=0,y.remain=0,y.alpha=0,x.remain=0,x.scale=1,v=!0)},spawnEmitter(A,T,P,M){let pt=typeof A=="string"?ul(A):Ki(A);if(!pt)return-1;M&&(pt=Object.assign(pt,M));let rt=a++;if(!i)return o.set(rt,r),rt;let at=i.spawnEmitter(hl(pt,T,P));return o.set(rt,at),rt},stopEmitter(A){let T=o.get(A);if(T)try{T.stop()}catch{}},step(A){_(A)},render(A){S(A)},particleCount(){return 0},emitterCount(){let A=0;for(let T of o.values())T.isActive()&&(A+=1);return A},hitStop(A,T){h=Math.max(0,A),u=h,p=T==null?0:Math.max(0,Math.min(1,T)),l=h>0?p:1},getTimeScale(){return l},shakeScreen(A,T,P){d.dur=Math.max(0,A),d.remain=d.dur,d.amplitude=Math.max(0,T),d.frequency=P==null?30:P,d._phase=0,d.x=0,d.y=0},getShakeOffset(){return{x:d.x,y:d.y}},flashScreen(A,T){y.dur=Math.max(0,A),y.remain=y.dur,y.peak=T==null?.8:Math.max(0,Math.min(1,T)),y.alpha=y.dur>0?y.peak:0},getFlashAlpha(){return y.alpha},pulseScale(A,T,P){x.dur=Math.max(0,A),x.remain=x.dur,x.amplitude=T==null?.2:T,x.frequency=P==null?4:P,x.scale=1},getPulseScale(){return x.scale},juiceSnapshot(){return{timeScale:l,shake:{x:d.x,y:d.y},flashAlpha:y.alpha,pulseScale:x.scale}},probe(){return{particles:0,emitters:o.size,dropped:0,steps:c,disposed:v}}}}function ha(n){let t=gt(n.r)/255,e=gt(n.g)/255,s=gt(n.b)/255,i=Math.max(t,e,s),o=Math.min(t,e,s),a=(i+o)/2,r=0,c=0,l=i-o;return l>1e-12&&(c=a>.5?l/(2-i-o):l/(i+o),i===t?r=(e-s)/l%6:i===e?r=(s-t)/l+2:r=(t-e)/l+4,r*=60,r<0&&(r+=360)),{h:r,s:c,l:a}}function da(n){let t=(n.h%360+360)%360,e=Xe(n.s),s=Xe(n.l);if(e<1e-12){let r=Math.round(s*255);return{r,g:r,b:r}}let i=s<.5?s*(1+e):s+e-s*e,o=2*s-i,a=t/360;return{r:Math.round(Qi(o,i,a+1/3)*255),g:Math.round(Qi(o,i,a)*255),b:Math.round(Qi(o,i,a-1/3)*255)}}function Qi(n,t,e){let s=e;return s<0&&(s+=1),s>1&&(s-=1),s<1/6?n+(t-n)*6*s:s<1/2?t:s<2/3?n+(t-n)*(2/3-s)*6:n}function gt(n){return n<0?0:n>255?255:n}function Xe(n){return n<0?0:n>1?1:n}function dl(n,t){let e=pl(n.from,t);if(e>=0&&e({r:gt(r.r),g:gt(r.g),b:gt(r.b)})),to:o}}function Zi(n,t,e){return n+(t-n)*e}function ml(n,t){let e=ha(n),s=e.h+(t.hue||0),i=Xe(e.s*(t.sat==null?1:t.sat)),o=Xe(e.l*(t.light==null?1:t.light));return da({h:s,s:i,l:o})}var bl=Object.freeze([Object.freeze([0,8,2,10]),Object.freeze([12,4,14,6]),Object.freeze([3,11,1,9]),Object.freeze([15,7,13,5])]);function fa(n){let t=n||{},e=null,s=!1,i={vignette:{enabled:to(t.vignette&&t.vignette.enabled,!1),strength:eo(t.vignette&&t.vignette.strength,.5)},dither:{enabled:to(t.dither&&t.dither.enabled,!1),strength:eo(t.dither&&t.dither.strength,.5)},scanline:{enabled:to(t.scanline&&t.scanline.enabled,!1),strength:eo(t.scanline&&t.scanline.strength,.5)}};function o(r){let c=r!==void 0?r:e?e.getContext2d():null;if(!c)return;let l=c.canvas?c.canvas.width:0,u=c.canvas?c.canvas.height:0;if(i.vignette.enabled&&i.vignette.strength>0&&l>0&&u>0){let h=c.createRadialGradient(l/2,u/2,Math.min(l,u)*.25,l/2,u/2,Math.max(l,u)*.75);h.addColorStop(0,"rgba(0,0,0,0)"),h.addColorStop(1,"rgba(0,0,0,"+i.vignette.strength.toFixed(3)+")"),c.fillStyle=h,c.fillRect(0,0,l,u)}if(i.scanline.enabled&&i.scanline.strength>0&&l>0&&u>0){c.fillStyle="rgba(0,0,0,"+(i.scanline.strength*.5).toFixed(3)+")";for(let h=0;h0&&l>0&&u>0&&typeof c.getImageData=="function"&&typeof c.putImageData=="function"){let h=c.getImageData(0,0,l,u);xl(h,i.dither.strength),c.putImageData(h,0,0)}}return{name:"palette-post",version:"1.0.0",dependencies:[],init(r){e=r},dispose(){s||(e=null,s=!0)},applyPaletteMap(r,c){return dl(r,c)},applyPaletteMapToBuffer(r,c){return fl(r,c)},lerpPaletteMap(r,c,l){return yl(r,c,l)},shiftHsl(r,c){return ml(r,c)},rgbToHsl(r){return ha(r)},hslToRgb(r){return da(r)},setPost(r){if(r)for(let c of["vignette","dither","scanline"])r[c]&&(typeof r[c].enabled=="boolean"&&(i[c].enabled=r[c].enabled),typeof r[c].strength=="number"&&(i[c].strength=Xe(r[c].strength)))},getPost(){return{vignette:{enabled:i.vignette.enabled,strength:i.vignette.strength},dither:{enabled:i.dither.enabled,strength:i.dither.strength},scanline:{enabled:i.scanline.enabled,strength:i.scanline.strength}}},renderPost(r){o(r)},probe(){return{disposed:s,post:this.getPost()}}}}function xl(n,t){let e=Xe(t);if(e<=0)return n;let{data:s,width:i}=n,a=255/(Math.max(2,Math.round(16-e*14))-1);for(let r=0;r+3>2)%i,l=Math.floor((r>>2)/i),u=(bl[l&3][c&3]/16-.5)*a;for(let h=0;h<3;h++){let p=s[r+h]+u,d=Math.round(p/a)*a;s[r+h]=d<0?0:d>255?255:d}}return n}function to(n,t){return typeof n=="boolean"?n:t}function eo(n,t){return typeof n=="number"?Xe(n):t}var so=Object.freeze({blip:Object.freeze({name:"blip",params:Object.freeze([.6,0,880,0,.03,.06,1,1.5])}),thud:Object.freeze({name:"thud",params:Object.freeze([.8,0,90,0,.04,.18,0,1,0,0,0,0,0,4])}),chime:Object.freeze({name:"chime",params:Object.freeze([.5,0,660,.02,.12,.3,1,2])})}),pa=Object.keys(so);function vl(n){let t=[];return n==null||typeof n!="object"?{ok:!1,errors:["song \u5FC5\u987B\u662F\u5BF9\u8C61"]}:(!Array.isArray(n.instruments)||n.instruments.length===0?t.push("instruments \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.instruments.forEach((e,s)=>{(!Array.isArray(e)||e.some(i=>typeof i!="number"||!Number.isFinite(i)))&&t.push(`instruments[${s}] \u5FC5\u987B\u662F\u6709\u9650\u6570\u5B57\u6570\u7EC4\uFF08ZzFX \u53C2\u6570\u5305\uFF09`)}),!Array.isArray(n.patterns)||n.patterns.length===0?t.push("patterns \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.patterns.forEach((e,s)=>{if(!Array.isArray(e)||e.length===0){t.push(`patterns[${s}] \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4\uFF08\u81F3\u5C11\u4E00\u4E2A\u58F0\u90E8\u901A\u9053\uFF09`);return}e.forEach((i,o)=>{if(!Array.isArray(i)||i.length<2){t.push(`patterns[${s}][${o}] \u901A\u9053\u81F3\u5C11\u542B [\u4E50\u5668\u7D22\u5F15, \u58F0\u50CF]`);return}if(i.some(c=>typeof c!="number"||!Number.isFinite(c))){t.push(`patterns[${s}][${o}] \u901A\u9053\u5FC5\u987B\u5168\u4E3A\u6709\u9650\u6570\u5B57`);return}let a=i[0]|0;Array.isArray(n.instruments)&&(a<0||a>=n.instruments.length)&&t.push(`patterns[${s}][${o}] \u4E50\u5668\u7D22\u5F15 ${a} \u8D8A\u754C\uFF08instruments \u957F\u5EA6 ${n.instruments.length}\uFF09`);let r=i[1];(r<-1||r>1)&&t.push(`patterns[${s}][${o}] \u58F0\u50CF ${r} \u8D8A\u754C\uFF08\u5E94 -1..+1\uFF09`)})}),!Array.isArray(n.sequence)||n.sequence.length===0?t.push("sequence \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.sequence.forEach((e,s)=>{if(typeof e!="number"||!Number.isInteger(e)){t.push(`sequence[${s}] \u5FC5\u987B\u662F\u6574\u6570 pattern \u7D22\u5F15`);return}Array.isArray(n.patterns)&&(e<0||e>=n.patterns.length)&&t.push(`sequence[${s}] \u7D22\u5F15 ${e} \u8D8A\u754C\uFF08patterns \u957F\u5EA6 ${n.patterns.length}\uFF09`)}),n.bpm!=null&&(typeof n.bpm!="number"||!(n.bpm>0))&&t.push("bpm \u5FC5\u987B\u662F\u6B63\u6570"),{ok:t.length===0,errors:t})}function me(n){return typeof n!="number"||Number.isNaN(n)||n<0?0:n>1?1:n}function Sl(n,t){switch(n){case"ease-in":return t*t;case"ease-out":return Math.sqrt(t);case"constant":return 1;default:return t}}function ga(n,t){let e=me(t);return n==null||!Array.isArray(n.voices)?[]:n.voices.map(s=>{let i=String(s&&s.id!=null?s.id:""),o=Array.isArray(s&&s.channelIndices)?s.channelIndices.slice():[],a=typeof s.minIntensity=="number"?me(s.minIntensity):0,r=typeof s.maxIntensity=="number"?me(s.maxIntensity):1,c=typeof s.volumeCurve=="string"?s.volumeCurve:"linear",l=typeof s.baseVolume=="number"?me(s.baseVolume):1;if(er)return{id:i,on:!1,volume:0,channelIndices:o};let u=r-a,h=u<=0?1:(e-a)/u,p=me(Sl(c,h)*l);return{id:i,on:!0,volume:p,channelIndices:o}})}function ya(n,t,e,s){try{let i=t[0]||[],o=t[1]||i,a=Math.max(i.length,o.length);if(a===0)return null;let c=n.createBuffer(2,a,44100);c.getChannelData(0).set(i),c.getChannelData(1).set(o.length?o:i);let l=n.createBufferSource();l.buffer=c,l.loop=!!s;let u=n.createGain();return u.gain.value=me(e*.3),l.connect(u),u.connect(n.destination),l.start(),{stop(){try{l.stop()}catch(h){}try{l.disconnect(),u.disconnect()}catch(h){}}}}catch(i){return io("[audio-music] \u53D7\u63A7\u97F3\u9891\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",i),null}}function ma(n){let t=n||{},e=typeof t.masterVolume=="number"?me(t.masterVolume):1,s=()=>null,i=null,o=null,a={voices:[]},r=1,c=null,l=!1,u=0,h=!1,p=!1;function d(){let S=s();return S==null?(u+=1,h||(no("[audio-music] \u65E0\u53D7\u63A7\u97F3\u9891\u4E0A\u4E0B\u6587\uFF08getAudioContext \u8FD4\u56DE null\uFF09\uFF0C\u5168\u90E8\u53D1\u58F0\u9759\u9ED8 no-op\uFF08\u8BC4\u4F30\u73AF\u5883\u65E0\u58F0\u5361\u65F6\u7684\u5BB9\u9519\u964D\u7EA7\uFF09"),h=!0),null):S}function y(){if(!o||!i)return null;try{let S=typeof o.bpm=="number"&&o.bpm>0?o.bpm:125;return i.synthSong(o.instruments,o.patterns,o.sequence,S)}catch(S){return io("[audio-music] \u66F2\u8C31\u6E32\u67D3\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",S),null}}function x(){let S=ga(a,r);if(S.length===0)return 1;let C=0;for(let A of S)A.on&&(C=Math.max(C,A.volume));return C}function v(S,C){typeof C=="number"&&(r=me(C));let A=d();if(A==null||!o)return;w();let T=y();if(!T)return;let P=me(e*x());c=ya(A,T,P,S),l=!!S&&c!=null}function w(){c&&(c.stop(),c=null),l=!1}return{name:"audio-music",version:"1.0.0",dependencies:[],init(S){s=()=>S.getAudioContext();let C=S.getEngine&&S.getEngine();i=C?C.audio.synth:null},dispose(){p||(w(),p=!0)},loadSong(S){let C=vl(S);return C.ok?o={instruments:S.instruments,patterns:S.patterns,sequence:S.sequence,bpm:typeof S.bpm=="number"?S.bpm:125}:no("[audio-music] \u66F2\u8C31\u6821\u9A8C\u5931\u8D25\uFF0C\u672A\u8F7D\u5165\uFF1A"+C.errors.join("\uFF1B")),C},play(S){v(!1,S)},stop(){w()},loop(S){v(!0,S)},setIntensityLayering(S){a=S&&Array.isArray(S.voices)?{voices:S.voices}:{voices:[]}},setIntensity(S){r=me(S)},resolveVoices(S){return ga(a,S)},playSfx(S){let C=so[S];if(!C){no("[audio-music] \u672A\u77E5\u97F3\u6548\u9884\u8BBE\uFF1A"+String(S));return}let A=d();if(A!=null)try{let T=i?i.synthSfx(C.params):null;if(!T)return;ya(A,[T,T],e,!1)}catch(T){io("[audio-music] \u97F3\u6548\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8 name="+S,T)}},getPreset(S){return so[S]},listPresets(){return pa.slice()},probe(){return{hasAudio:s()!=null,hasSong:o!=null,intensity:r,voiceCount:a.voices.length,looping:l,silentNoops:u,presetCount:pa.length}}}}function io(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function no(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var wl="zaomeng.save";function Tl(n){if(typeof TextEncoder!="undefined")return new TextEncoder().encode(n).length;if(typeof Buffer!="undefined"&&typeof Buffer.byteLength=="function")return Buffer.byteLength(n,"utf8");let t=0;for(let e=0;e=55296&&s<=56319?(t+=4,e++):t+=3}return t}function ro(){let n=new Map;return{getItem(t){return n.has(t)?n.get(t):null},setItem(t,e){n.set(t,e)},removeItem(t){n.delete(t)},keys(){return Array.from(n.keys())}}}function ba(){if(typeof localStorage=="undefined")throw new Error("[save-progress] createLocalStorageAdapter \u9700\u8981\u5168\u5C40 localStorage\uFF08\u4EC5\u6D4F\u89C8\u5668\u96C6\u6210\u6BB5\u53EF\u7528\uFF09\u3002node/host-dev \u8BF7\u7528\u7F3A\u7701\u5185\u5B58 adapter \u6216 createMemoryAdapter()\u3002");return{getItem(n){return localStorage.getItem(n)},setItem(n,t){localStorage.setItem(n,t)},removeItem(n){localStorage.removeItem(n)},keys(){let n=[];for(let t=0;t0?t.namespace:wl;if(e.indexOf(":")>=0)throw new Error('[save-progress] namespace \u4E0D\u5F97\u542B\u5206\u9694\u7B26 ":"\uFF08\u5F53\u524D="'+e+'"\uFF09');let s=typeof t.maxValueBytes=="number"&&t.maxValueBytes>0?Math.floor(t.maxValueBytes):32768,i=!Al(t.adapter),o=i?ro():t.adapter,a=e+":",r=0,c=0,l=!1;function u(d){return typeof d!="string"||d.length===0?a+String(d):a+d}function h(){try{let d=o.keys();return Array.isArray(d)?d.filter(y=>typeof y=="string"&&y.indexOf(a)===0):[]}catch(d){return ts("[save-progress] adapter.keys() \u5F02\u5E38\uFF0C\u964D\u7EA7\u8FD4\u56DE\u7A7A\u96C6",d),[]}}return{name:"save-progress",version:"1.0.0",dependencies:[],init(d){h()},dispose(){},get(d,y){if(!oo(d))return y;let x;try{x=o.getItem(u(d))}catch(v){return ts("[save-progress] adapter.getItem \u5F02\u5E38\uFF0C\u8FD4\u56DE\u9ED8\u8BA4\u503C key="+d,v),y}if(x==null)return y;try{return JSON.parse(x)}catch{return r+=1,l||(es("[save-progress] \u68C0\u6D4B\u5230\u635F\u574F\u5B58\u6863\uFF08\u975E\u6CD5 JSON\uFF09\uFF0C\u5DF2\u5BB9\u9519\u56DE\u9000\u9ED8\u8BA4\u503C key="+d),l=!0),y}},set(d,y){if(!oo(d))return es("[save-progress] set \u6536\u5230\u975E\u6CD5 key\uFF0C\u62D2\u7EDD\u5199\u5165\uFF1A"+String(d)),!1;let x;try{x=JSON.stringify(y)}catch{return c+=1,es("[save-progress] \u503C\u4E0D\u53EF JSON \u5E8F\u5217\u5316\uFF08\u5FAA\u73AF\u5F15\u7528?\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1}if(x===void 0)return c+=1,es("[save-progress] \u503C\u5E8F\u5217\u5316\u4E3A undefined\uFF08\u5982\u7EAF undefined/\u51FD\u6570\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1;let v=Tl(x);if(v>s)return c+=1,es("[save-progress] \u503C\u8D85\u5B57\u8282\u4E0A\u9650\u62D2\u7EDD\u5199\u5165 key="+d+"\uFF08"+v+" > "+s+" bytes\uFF09"),!1;try{return o.setItem(u(d),x),!0}catch(w){return c+=1,ts("[save-progress] adapter.setItem \u5F02\u5E38\uFF0C\u5199\u5165\u5931\u8D25 key="+d,w),!1}},remove(d){if(oo(d))try{o.removeItem(u(d))}catch(y){ts("[save-progress] adapter.removeItem \u5F02\u5E38\uFF08\u5DF2\u5FFD\u7565\uFF09key="+d,y)}},clear(){let d=h(),y=0;for(let x of d)try{o.removeItem(x),y+=1}catch(v){ts("[save-progress] clear \u65F6 removeItem \u5F02\u5E38\uFF08\u5DF2\u8DF3\u8FC7\uFF09fullKey="+x,v)}return y},probe(){return{namespace:e,maxValueBytes:s,usingMemoryAdapter:i,size:h().length,corruptRecoveries:r,rejectedWrites:c}}}}function oo(n){return typeof n=="string"&&n.length>0}function Al(n){return!!n&&typeof n.getItem=="function"&&typeof n.setItem=="function"&&typeof n.removeItem=="function"&&typeof n.keys=="function"}function ts(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function es(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var El={w:390,h:844};function va(n){let t=((n&&n.seed)!=null?n.seed:0)>>>0,e=sa({cellSize:96}),s=ia(),i=la({inputBufferMs:260,inputTypes:["pointerdown"]}),o=ua({seed:t,maxParticles:600}),a=fa({vignette:{enabled:!0,strength:.22}}),r=ma({masterVolume:.8}),c;try{c=ba()}catch(p){console.warn("[generic] localStorage \u4E0D\u53EF\u7528\uFF0C\u5B58\u6863\u9000\u5185\u5B58 adapter\uFF1A"+(p&&p.message)),c=ro()}let l=xa({namespace:"zaomeng-generic",adapter:c});return{plugins:{collision:e,physics:s,gamefeel:i,juice:o,palettePost:a,audioMusic:r,save:l},registerOrder:[e,s,i,o,a,l,r],viewport:El,buildFactoryOpts:(p,d)=>({runtime:{plugins:d.plugins,bundle:d.bundle,getRealAudioCtx:d.getRealAudioCtx}})}}function ns(n){let t=n||{},e=null,s=[],i="booting",o=null,a=0,r={x:0,y:0,vx:0,vy:0,angle:0,radius:15},c=[],l=[],u=0,h={},p=200,d=600,y=2e3,x=.99,v=15,w=30,_=15,S=40,C=80,A=5,T=200,P=3;function M(R){R.x<0?R.x+=390:R.x>390&&(R.x-=390),R.y<0?R.y+=844:R.y>844&&(R.y-=844)}function pt(R,F,k,j){let $=F.x-R.x,Z=F.y-R.y,Tt=R.x-k.x,At=R.y-k.y,Ot=$*$+Z*Z,Le=2*(Tt*$+At*Z),Zn=Tt*Tt+At*At-j*j,dn=Le*Le-4*Ot*Zn;if(dn<0)return!1;dn=Math.sqrt(dn);let Fs=(-Le-dn)/(2*Ot),Dn=(-Le+dn)/(2*Ot);return Fs>=0&&Fs<=1||Dn>=0&&Dn<=1}function rt(R,F,k,j){let $=R-k,Z=F-j;return Math.sqrt($*$+Z*Z)}function at(R,F,k,j,$){return{x:R,y:F,vx:j,vy:$,radius:k,isBig:k>=w}}function yt(){c=[];let R=e.random;for(let F=0;F{Z.key&&(h[Z.key]=!0)});s.push(k);let j=F.on("keyup",Z=>{Z.key&&(h[Z.key]=!1)});s.push(j);let $=F.on("pointerdown",()=>{i==="gameover"&&We()});s.push($),Lt(),i="playing",o=null}function hn(R){if(i==="gameover")return;let F=e.time.nowMs();h.ArrowLeft&&(r.angle-=P*R),h.ArrowRight&&(r.angle+=P*R),h.ArrowUp&&(r.vx+=Math.cos(r.angle)*T*R,r.vy+=Math.sin(r.angle)*T*R,ge(r.x-Math.cos(r.angle)*20,r.y-Math.sin(r.angle)*20,{r:1,g:.8,b:.2,a:1},{r:1,g:.4,b:0,a:0},5)),h.Space&&ht(),r.vx*=x,r.vy*=x,r.x+=r.vx*R,r.y+=r.vy*R,M(r);for(let k of c)k.x+=k.vx*R,k.y+=k.vy*R,M(k);for(let k=l.length-1;k>=0;k--){let j=l[k],$=j.x,Z=j.y;if(j.x+=j.vx*R,j.y+=j.vy*R,F-j.born>y){l.splice(k,1);continue}if(j.x<0||j.x>390||j.y<0||j.y>844){l.splice(k,1);continue}let Tt=!1;for(let At=c.length-1;At>=0;At--){let Ot=c[At];if(pt({x:$,y:Z},{x:j.x,y:j.y},{x:Ot.x,y:Ot.y},Ot.radius)){Tt=!0,a+=1,ge(j.x,j.y,{r:1,g:.9,b:.5,a:1},{r:1,g:.3,b:0,a:0},30),Pt([1,.1,880,,,.2,,.4]),Ot.isBig&&Bt(Ot),c.splice(At,1);break}}Tt&&l.splice(k,1)}for(let k of c){let j=r.x-k.x,$=r.y-k.y;if(j*j+$*$<(r.radius+k.radius)*(r.radius+k.radius)){i="gameover",o="lose",ge(r.x,r.y,{r:1,g:.2,b:.2,a:1},{r:.5,g:0,b:0,a:0},40),Pt([1,.2,100,,,.5,,1.5]);return}}c.length===0&&(i="gameover",o="win")}function ae(R){R.fillStyle="#0a0a1a",R.fillRect(0,0,390,844);for(let F of c)R.fillStyle=F.isBig?"#8b5e3c":"#a0744a",R.beginPath(),R.arc(F.x,F.y,F.radius,0,Math.PI*2),R.fill(),R.strokeStyle="#d4a76a",R.lineWidth=2,R.stroke();for(let F of l)R.fillStyle="#ffff00",R.beginPath(),R.arc(F.x,F.y,F.radius,0,Math.PI*2),R.fill();R.save(),R.translate(r.x,r.y),R.rotate(r.angle),R.fillStyle=i==="gameover"?"#ff4444":"#44aaff",R.beginPath(),R.moveTo(20,0),R.lineTo(-15,-12),R.lineTo(-10,0),R.lineTo(-15,12),R.closePath(),R.fill(),R.strokeStyle="#ffffff",R.lineWidth=1.5,R.stroke(),R.restore(),R.fillStyle="#ffffff",R.font="bold 16px monospace",R.fillText("Score: "+a,10,30),R.fillText("Asteroids: "+c.length,10,50),R.fillText("Phase: "+i,10,70),i==="gameover"&&(R.fillStyle=o==="win"?"#00ff00":"#ff0000",R.font="bold 28px monospace",R.textAlign="center",R.fillText(o==="win"?"YOU WIN!":"GAME OVER",195,400),R.font="16px monospace",R.fillStyle="#ffffff",R.fillText("Tap to restart",195,430),R.textAlign="start")}function Pe(){for(let R of s)try{R.cancel()}catch{}s=[],c=[],l=[],i="booting",o=null}function Zt(){return{seed:e&&e.random?e.random.seed:null,state:()=>({phase:i,result:o,score:a,asteroidsRemaining:c.length,ship:{x:r.x,y:r.y,angle:r.angle}})}}return{init:un,update:hn,render:ae,destroy:Pe,_forensicsView:Zt}}var pd=ns,gd=ns;async function yd(n){let t=n||{},e=t.engine||await Promise.resolve().then(()=>(Mc(),Ic)),s=(t.seed!=null?t.seed:305441741)>>>0,i=va({seed:s});return na({canvas:t.canvas,statusEl:t.statusEl||null,engine:e,seed:s,mode:t.mode||"play",engineMode:"real",viewport:i.viewport,factory:ns,plugins:i.plugins,registerOrder:i.registerOrder,buildFactoryOpts:i.buildFactoryOpts,recHook:t.recHook||null,onReady:t.onReady||null})}return Nc(md);})();
+color = `+this.color),t}renderDebug(t=!0){let e=t?this.isHoverObject()?Ka:this.disabled?tc:this.interactive?rr:Za:Qa;E.drawRect(this.nativePos,this.size,pe,4,e)}click(t=!0){this.onClick(),t&&this.soundClick&&this.soundClick.play()}onUpdate(){}onRender(){}onEnter(){}onLeave(){}onPress(){}onRelease(){}onClick(){}onChange(){}},vi=class extends re{constructor(t,e,s="",i="center",o=E.defaultFont){super(t,e),f(V(s),"ui text must be a string"),f(["left","center","right"].includes(i),"ui text align must be left, center, or right"),f(V(o),"ui text font must be a string"),this.text=s,this.align=i,this.font=o,this.canBeHover=!1,this.color=pe,this.shadowColor=pe,this.gradientColor=void 0,this.lineWidth=0,this.textFitScale=1}render(){super.render();let t=this.getTextSize();E.drawText(this.text,this.nativePos,t,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow,this.shadowColor,this.shadowBlur,this.shadowOffset)}},Mo=class extends re{constructor(t,e,s=""){super(t,e),f(V(s),"ui text must be a string"),this.maxLength=0,this.text=s,this.interactive=!0,this.canBeHover=!0}click(){E.keyInputObject=this,this.onClick()}stopEditing(){this.isKeyInputObject()&&(this.soundRelease&&this.soundRelease.play(),E.activeObject=void 0,E.keyInputObject=void 0,this.onChange())}onKeyDown(t){let e=t.code,s=t.key;e==="Backspace"?this.text=this.text.slice(0,-1):e==="Enter"||e==="Escape"?this.stopEditing():s.length===1&&(!this.maxLength||this.text.lengththis.size.y,s=e?this.size.y:this.size.x,i=e?this.size.x:this.size.y,o=e?this.nativePos.x:this.nativePos.y,a=i-s,r=o-a/2,c=o+a/2,l=E.screenToNative(Jt);this.value=e?Bt(l.x,r,c):Bt(l.y,c,r)}else if(this.isNavigationObject()){let e=E.getNavigationOtherDirection();E.navigationTimer.active()||(this.value=N(this.value+e*.01))}this.value===t||this.onChange()}render(){super.render();let t=this.size.x>this.size.y,e=t?this.size.x:this.size.y,s=t?this.size.y:this.size.x;if(this.fillMode){let o=tt(s,this.cornerRadius*2),a=Wt(o,e,this.value),r=(a-e)*(t?.5:-.5),c=this.nativePos.add(t?b(r,0):b(0,r)),l=this.disabled?this.disabledColor:this.handleColor,u=t?b(a,this.size.y):b(this.size.x,a);E.drawRect(c,u,l,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}else{let o=N(t?this.value:1-this.value),a=(e-s)*(o-.5),r=this.nativePos.add(t?b(a,0):b(0,a)),c=this.disabled?this.disabledColor:this.handleColor,l=b(s);E.drawRect(r,l,c,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}let i=this.getTextSize();E.drawText(this.text,this.nativePos,i,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow)}navigatePressed(){this.value=this.value?0:1,this.onChange(),this.onRelease(),super.navigatePressed()}},jo=class extends re{constructor(t,e,s,i=!1,o=!1,a=1){super(t,e||b()),f(V(s),"video src must be a string"),f(L(a),"video volume must be a number"),this.color=it,this.cornerRadius=0,this.volume=a,this.video=document.createElement("video"),this.video.loop=o,this.video.volume=N(a*Sn),this.video.muted=!Ht,this.video.style.display="none",this.video.src=s,document.body.appendChild(this.video),i&&this.play()}async play(){try{await this.video.play()}catch{}}pause(){this.video.pause()}stop(){this.video.pause(),this.video.currentTime=0}isLoading(){return this.video.readyState=1,"ui layout columns must be a number >= 1"),f(L(s),"ui layout gap must be a number"),f(L(i),"ui layout padding must be a number"),this.columns=e,this.gap=s,this.padding=i,o&&(this.color=pe,this.gradientColor=void 0,this.lineWidth=0,this.shadowColor=pe),this.relayout()}addChild(t){return super.addChild(t),this.relayout(),t}removeChild(t){super.removeChild(t),this.relayout()}relayout(){let t=this.children.length;if(!t){this.size=b(this.padding*2);return}let e=this.columns,s=us(t/e),i=new Array(e).fill(0),o=new Array(s).fill(0);for(let p=0;p=0&&m.objects.splice(t,1),super.destroy()}updatePhysics(){}render(){this.tileInfo?super.render():this.drawFixtures(this.color,this.lineColor,this.lineWidth)}renderDebugInfo(){let t=!this.getIsAwake(),e=this.getBodyType()===m.bodyTypeStatic,s=J(t?1:0,t?1:0,e?1:0,.5);this.drawFixtures(s)}drawFixtures(t=W,e=it,s=.1,i,o){this.getFixtureList().forEach(a=>{m.castShapeObject(a.GetShape()).GetType()!==m.instance.b2Shape.e_edge&&m.drawFixture(a,this.pos,this.angle,t,e,s,i,o)}),this.edgeLists.forEach(a=>mo(a,s,e,!1,this.pos,this.angle)),this.edgeLoops.forEach(a=>mo(a,s,e,!0,this.pos,this.angle))}beginContact(t){}endContact(t){}addShape(t,e=1,s=.2,i=0,o=!1){f(L(e),"density must be a number"),f(L(s),"friction must be a number"),f(L(i),"restitution must be a number");let a=new m.instance.b2FixtureDef;return a.set_shape(t),a.set_density(e),a.set_friction(s),a.set_restitution(i),a.set_isSensor(o),this.body.CreateFixture(a)}addBox(t=b(1),e=b(),s=0,i,o,a,r){f(O(t),"size must be a Vector2"),f(t.x>0&&t.y>0,"size must be positive"),f(O(e),"offset must be a Vector2"),f(L(s),"angle must be a number");let c=new m.instance.b2PolygonShape;return c.SetAsBox(t.x/2,t.y/2,m.vec2dTo(e),-s),this.addShape(c,i,o,a,r)}addPoly(t,e,s,i,o){f(de(t),"points must be an array");function a(c){f(3<=c.length&&c.length<=8);let l=m.instance._malloc(c.length*8);for(let p=0,d=0;p>2]=c[p].x,d+=4,m.instance.HEAPF32[l+d>>2]=c[p].y,d+=4;let u=m.instance.wrapPointer(l,m.instance.b2Vec2),h=new m.instance.b2PolygonShape;return h.Set(u,c.length),m.instance._free(l),h}let r=a(t);return this.addShape(r,e,s,i,o)}addRegularPoly(t=1,e=8,s,i,o,a){f(L(t)&&t>0,"diameter must be a positive number"),f(L(e)&&e>2,"sides must be a positive number greater than 2");let r=[],c=t/2;for(let l=e;l--;)r.push(b(c,0).rotate((l+.5)/e*X*2));return this.addPoly(r,s,i,o,a)}addRandomPoly(t=1,e,s,i,o){f(L(t)&&t>0,"diameter must be a positive number");let a=or(3,9),r=[],c=t/2;for(let l=a;l--;)r.push(b(dt(c/2,c*1.5),0).rotate(l/a*X*2));return this.addPoly(r,e,s,i,o)}addCircle(t=1,e=b(),s,i,o,a){f(L(t)&&t>0,"diameter must be a positive number"),f(O(e),"offset must be a Vector2");let r=new m.instance.b2CircleShape;return r.set_m_p(m.vec2dTo(e)),r.set_m_radius(t/2),this.addShape(r,s,i,o,a)}addEdge(t,e,s,i,o,a){f(O(t),"point1 must be a Vector2"),f(O(e),"point2 must be a Vector2");let r=new m.instance.b2EdgeShape;return r.Set(m.vec2dTo(t),m.vec2dTo(e)),this.addShape(r,s,i,o,a)}addEdgeList(t,e,s,i,o){f(de(t),"points must be an array");let a=[],r=[];for(let c=0;ct[se(l,t.length)];for(let l=0;lthis.destroyFixture(t))}getCenterOfMass(){return m.vec2From(this.body.GetWorldCenter())}getLinearVelocity(){return m.vec2From(this.body.GetLinearVelocity())}getAngularVelocity(){return this.body.GetAngularVelocity()}getMass(){return this.body.GetMass()}getInertia(){return this.body.GetInertia()}getIsAwake(){return this.body.IsAwake()}getBodyType(){return this.body.GetType()}getSpeed(){return this.getLinearVelocity().length()}setTransform(t,e){this.pos=t,this.angle=e,this.body.SetTransform(m.vec2dTo(t),-e)}setPosition(t){this.setTransform(t,this.body.GetAngle())}setAngle(t){this.setTransform(m.vec2From(this.body.GetPosition()),t)}setLinearVelocity(t){this.body.SetLinearVelocity(m.vec2dTo(t))}setAngularVelocity(t){this.body.SetAngularVelocity(t)}setLinearDamping(t){this.body.SetLinearDamping(t)}setAngularDamping(t){this.body.SetAngularDamping(t)}setGravityScale(t=1){this.body.SetGravityScale(this.gravityScale=t)}setBullet(t=!0){this.body.SetBullet(t)}setAwake(t=!0){this.body.SetAwake(t)}setBodyType(t){this.body.SetType(t)}setSleepingAllowed(t=!0){this.body.SetSleepingAllowed(t)}setFixedRotation(t=!0){this.body.SetFixedRotation(t)}setCenterOfMass(t){this.setMassData(t)}setMass(t){this.setMassData(void 0,t)}setMomentOfInertia(t){this.setMassData(void 0,void 0,t)}resetMassData(){this.body.ResetMassData()}setMassData(t,e,s){let i=new m.instance.b2MassData;this.body.GetMassData(i),t!==void 0&&i.set_center(m.vec2dTo(t)),e!==void 0&&i.set_mass(e),s!==void 0&&i.set_I(s),this.body.SetMassData(i)}setFilterData(t=0,e=0,s=0){this.getFixtureList().forEach(i=>{let o=i.GetFilterData();o.set_categoryBits(t),o.set_maskBits(65535&~e),o.set_groupIndex(s)})}setSensor(t=!0){this.getFixtureList().forEach(e=>e.SetSensor(t))}applyForce(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyForce(m.vec2dTo(t),m.vec2dTo(e))}applyAcceleration(t,e){e||(e=this.getCenterOfMass()),this.setAwake();let s=t.scale(this.getMass());this.body.ApplyLinearImpulse(m.vec2dTo(s),m.vec2dTo(e))}applyImpulse(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyLinearImpulse(m.vec2dTo(t),m.vec2dTo(e))}applyTorque(t){this.setAwake(),this.body.ApplyTorque(t)}applyAngularAcceleration(t){this.setAwake(),this.body.ApplyAngularImpulse(t*this.getInertia())}applyAngularImpulse(t){this.setAwake(),this.body.ApplyAngularImpulse(t)}hasFixtures(){return!m.isNull(this.body.GetFixtureList())}getFixtureList(){let t=[];for(let e=this.body.GetFixtureList();!m.isNull(e);)t.push(e),e=e.GetNext();return t}hasJoints(){return!m.isNull(this.body.GetJointList())}getJointList(){let t=[];for(let e=this.body.GetJointList();!m.isNull(e);)t.push(e),e=e.get_next();return t}},Si=class extends _s{constructor(t,e,s,i=0,o,a=0){let r=m.bodyTypeStatic;super(t,e,s,i,o,r,a)}},No=class extends _s{constructor(t,e,s,i=0,o,a=0){let r=m.bodyTypeKinematic;super(t,e,s,i,o,r,a)}},zo=class extends Si{constructor(t){f(t instanceof vs,"tileLayer must be a TileCollisionLayer"),super(t.pos,t.size),this.tileLayer=t,this.addChild(t)}render(){}buildCollision(t=.2,e=0){this.destroyAllFixtures(),this.pos=this.tileLayer.pos.copy(),this.size=this.tileLayer.size.copy();let s=[],i=(a,r)=>a+r*this.size.x,o=(a,r)=>!s[i(a,r)]&&this.tileLayer.getCollisionData(b(a,r))>0;for(let a=0;ai.fractiono.pos.distanceSquared(t)0,"Tween duration must be > 0"),this.callback=t,this.start=e,this.end=s,this.duration=i,this.life=i,this.ease=o.ease||Ci.LINEAR,this.useRealTime=!!o.useRealTime,this.paused=!!o.paused,this.thenCallback=void 0,this.loopRemaining=0,$t.push(this),t(this.interp(i))}setEase(t){return this.ease=t,this}then(t){return this.thenCallback=t,this.loopRemaining=0,this}loop(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Lc(this),this}pingPong(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Oc(this),this}pause(){this.paused=!0}resume(){this.paused=!1}restart(){this.life=this.duration,this.paused=!1,$t.indexOf(this)<0&&$t.push(this),this.callback(this.interp(this.duration))}isActive(){return!this.paused&&$t.indexOf(this)>=0}getPercent(){return Bt(this.duration-this.life,0,this.duration)}getValue(){return this.interp(this.life)}interp(t){let e=this.ease((this.duration-t)/this.duration);return La(this.start)?this.start.lerp(this.end,e):this.start+(this.end-this.start)*e}stop(){let t=$t.indexOf(this);t>=0&&$t.splice(t,1),this.thenCallback=void 0}},Ci={LINEAR:n=>n,POWER:n=>t=>t**n,SINE:n=>1-lt(n*(X/2)),CIRC:n=>1-(1-n*n)**.5,EXPO:n=>n===0?0:2**(10*n-10),BACK:n=>n*n*(2.70158*n-1.70158),ELASTIC:n=>n===0?0:n===1?1:-(2**(10*n-10))*st((37-40*n)*X/6),SPRING:n=>1-(st(X*(1-n)*(.2+2.5*(1-n)**3))*n**2.2+(1-n))*(1+1.2*n),BOUNCE:n=>{let t=1-n,e;return t<4/11?e=7.5625*t*t:t<8/11?e=7.5625*(t-=6/11)*t+.75:t<10/11?e=7.5625*(t-=9/11)*t+.9375:e=7.5625*(t-=10.5/11)*t+.984375,1-e},IN:n=>n,OUT:n=>t=>1-n(1-t),IN_OUT:n=>Ci.PIECEWISE(n,Ci.OUT(n)),PIECEWISE:(...n)=>{let t=n.length;return e=>{let s=e*t-1e-9>>0;return(n[s]((e-s/t)*t)+s)/t}},BEZIER:(n,t,e,s)=>{let i=o=>{let a=1-o,r=3*a*a*o,c=3*a*o*o,l=o**3;return[r*n+c*e+l,r*t+c*s+l]};return o=>{let a=0,r=1;for(let c=0;c<128;c++){let l=(a+r)/2,[u,h]=i(l);if(nt(u-o)<1e-5)return h;u=this.size.x||e>=this.size.y?null:this.nodes[t+e*this.size.x]}worldToTile(t){let e=this.tileLayer?this.tileLayer.pos.x:0,s=this.tileLayer?this.tileLayer.pos.y:0;return b(St(t.x-e),St(t.y-s))}tileToWorld(t,e){let s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;return b(t+.5+s,e+.5+i)}buildNodeData(){let t=this.size.x,e=this.size.y,s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;for(let o=0;o0&&(c?l>0&&bt(r.posWorld,lo,J(1,0,0,tt(.2,l*.05)),this.debugTime):bt(r.posWorld,lo,J(1,0,0,.25),this.debugTime))}}aStarSearch(t,e){f(t&&e,"aStarSearch needs both endpoints"),f(t!==e,"aStarSearch: start and end must differ \u2014 caller should handle trivial case"),f(t.walkable&&e.walkable,"aStarSearch: endpoints must be walkable");let s=[t];t.isOpen=!0;let i=0;for(;s.length>0;){let o=0,a=s[0].f;for(let c=1;cthis.maxLoop)break;r.isOpen=!1,s.splice(o,1),r.isClosed=!0,this.debug&&this.debugTime>0&&bt(r.posWorld,lo,J(1,1,1,.05),this.debugTime);for(let c=-1;c<=1;++c)for(let l=-1;l<=1;++l){if(l===0&&c===0)continue;let u=this.getNode(r.pos.x+l,r.pos.y+c);if(!u||!u.walkable||u.isClosed)continue;let h=1;if(l!==0&&c!==0){let v=this.getNode(r.pos.x+l,r.pos.y);if(!v||!v.walkable)continue;let w=this.getNode(r.pos.x,r.pos.y+c);if(!w||!w.walkable)continue;h=fd}let p=r.g+h+u.cost;if(!u.isOpen)u.isOpen=!0,s.push(u);else if(p>=u.g)continue;u.parent=r,u.g=p;let d=nt(e.pos.x-u.pos.x),y=nt(e.pos.y-u.pos.y),x=K(d,y)+(Math.SQRT2-1)*tt(d,y);u.f=u.g+x*this.heuristicWeight}}return e.parent!==null}getNearestClearNode(t,e=10,s=!0){f(O(t),"worldPos must be a Vector2"),s&&this.buildNodeData();let i=this.tileLayer?this.tileLayer.pos.x:0,o=this.tileLayer?this.tileLayer.pos.y:0,a=St(t.x-i),r=St(t.y-o);for(let c=0;c<=e;++c){let l=null,u=0;for(let h=-c;h<=c;++h)for(let p=-c;p<=c;++p){if(c>0&&nt(p)!==c&&nt(h)!==c)continue;let d=this.getNode(a+p,r+h);if(!d||!d.isClear())continue;let y=d.posWorld.x-t.x,x=d.posWorld.y-t.y,v=y*y+x*x;(!l||v0&&Ut(i.posWorld,.3,J(.5,0,.5,.5),this.debugTime),t.splice(e,1),e=K(1,e-1);continue}else if(c===2){this.debug&&this.debugTime>0&&Ut(i.posWorld,.3,J(1,0,0,.5),this.debugTime);let d,y;s.pos.y===i.pos.y&&o.pos.x===i.pos.x?(d=s.pos.x,y=o.pos.y):(d=o.pos.x,y=s.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t.splice(e,1),e=K(1,e-1);continue}}else if(c===5){this.debug&&this.debugTime>0&&Ut(i.posWorld,.3,J(1,1,0,.5),this.debugTime);let d=e>=2?t[e-2]:s,y,x,v,w;l===0||h===0?(y=o.pos.x,x=i.pos.y,v=s.pos.x,w=i.pos.y):(y=i.pos.x,x=o.pos.y,v=i.pos.x,w=s.pos.y);let _=y-d.pos.x,S=x-d.pos.y,C=v-d.pos.x,A=w-d.pos.y,T=_*_+S*S,P=C*C+A*A,M=T0&&Ut(i.posWorld,.3,J(0,1,0,.5),this.debugTime),l===h&&u===p){++e;continue}else{let d,y;s.pos.y===o.pos.y?(d=i.pos.x,y=s.pos.y):(d=s.pos.x,y=i.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t[e]=x,e=K(1,e-1);continue}}++e}}smoothPathStringPull(t){if(t.length<=2)return;for(let i of t)if(!i.isClear())return;let e=t.slice();t.length=0,t.push(e[0]);let s=0;for(let i=1;i0&&we(o.posWorld,t[t.length-1].posWorld,J(0,0,1,.3),.02,this.debugTime);continue}for(;s=1;--e){let s=t[e-1],i=t[e],o=t[e+1];(i.pos.x-s.pos.x)*(o.pos.y-s.pos.y)===(i.pos.y-s.pos.y)*(o.pos.x-s.pos.x)&&t.splice(e,1)}}isNodeClear(t,e){let s=this.getNode(t,e);return s!==null&&s.isClear()}isLineClear(t,e){f(O(t)&&O(e),"isLineClear needs Vector2 endpoints"),f(this.isNodeClear(t.x,t.y)&&this.isNodeClear(e.x,e.y),"isLineClear endpoints must be in-bounds and clear");let s=e.x-t.x,i=e.y-t.y,o=nt(s),a=nt(i),r=ne(s),c=ne(i),l=t.x,u=t.y;if(a===o){for(;l!==e.x;){if(l!==t.x&&(!this.isNodeClear(l,u)||!this.isNodeClear(l,u-c))||!this.isNodeClear(l,u+c))return!1;l+=r,u+=c}if(!this.isNodeClear(e.x,e.y-c))return!1}else if(ar.posWorld.copy());if(this.debug&&this.debugTime>0&&a.length>0){for(let r=1;rpd,bootGameHost:()=>yd,default:()=>gd});var js=class{constructor(t){this._state=(t==null?2654435769:t)>>>0}next(){this._state=this._state+1831565813>>>0;let t=this._state;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}range(t,e){return t+this.next()*(e-t)}reseed(t){this._state=(t==null?2654435769:t)>>>0}},Ji=class{constructor(t){this._clock=t||Jc(),this._origin=this._clock()}nowMs(){return this._clock()}elapsedMs(){return this._clock()-this._origin}},Ui=class{constructor(t){this._time=t,this._subs=new Map}sourceFor(t){let e=this,s=t==null?null:t;return{on(i,o){if(e._assertType(i),typeof o!="function")throw new Error("[HostDevInputBridge] on \u7684 handler \u5FC5\u987B\u662F\u51FD\u6570");let a=e._subs.get(i)||[],r={handler:o,scope:s};return a.push(r),e._subs.set(i,a),{cancel(){let c=e._subs.get(i);if(!c)return;let l=c.indexOf(r);l>=0&&c.splice(l,1)}}},off(i,o){e._assertType(i);let a=e._subs.get(i);if(!a)return;let r=a.findIndex(c=>c.handler===o&&c.scope===s);r>=0&&a.splice(r,1)}}}_emit(t,e){this._assertType(t);let s=e||{},i={type:t,x:typeof s.x=="number"?s.x:0,y:typeof s.y=="number"?s.y:0,key:typeof s.key=="string"?s.key:"",tMs:this._time.nowMs()},o=this._subs.get(t);if(!o||o.length===0)return;let a=o.slice();for(let r of a)try{r.handler(i)}catch(c){qe("[host-dev input] \u8F93\u5165 handler \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09type="+t,c)}}disposeScope(t){if(t==null)return 0;let e=0;for(let[s,i]of this._subs){let o=i.filter(a=>a.scope!==t);e+=i.length-o.length,o.length===0?this._subs.delete(s):this._subs.set(s,o)}return e}_subscriptionCount(){let t=0;for(let e of this._subs.values())t+=e.length;return t}_assertType(t){if(!Vi.has(t))throw new Error("[HostDevInputBridge] \u975E\u6CD5\u8F93\u5165\u4E8B\u4EF6\u7C7B\u578B\uFF1A"+String(t)+"\uFF08\u4EC5\u652F\u6301 "+Array.from(Vi).join("/")+"\uFF09")}},Vi=new Set(["pointerdown","pointermove","pointerup","keydown","keyup"]);function Xr(n){let t=n||{},e=new Ji(t.clock),s=new js(t.seed),i=t.seed==null?2654435769:t.seed>>>0,o=new Ui(e),a=typeof t.audioFactory=="function"?t.audioFactory:null,r=null,c=!1,l=typeof t.engineFactory=="function"?t.engineFactory:null,u=null,h=!1,p=new Map,d=0,y=0;function x(){if(r)return r;if(!a)return c||(qi("[host-dev audio] \u672A\u6CE8\u5165 audioFactory\uFF0CgetAudioContext \u8FD4\u56DE null\uFF08P6 \u987B\u5BB9\u9519\u964D\u7EA7\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u5DE5\u5382\uFF09"),c=!0),null;try{r=a()}catch(C){qe("[host-dev audio] audioFactory \u629B\u9519\uFF0CgetAudioContext \u964D\u7EA7\u8FD4\u56DE null",C),r=null}return r}function v(){if(u)return u;if(!l)return h||(qi("[host-dev engine] \u672A\u6CE8\u5165 engineFactory\uFF0CgetEngine \u8FD4\u56DE null\uFF08\u63D2\u4EF6\u987B\u5BB9\u9519\u964D\u7EA7\uFF1A\u7C92\u5B50\u9000\u53D7\u63A7\u9762\u81EA\u7BA1/\u5408\u6210\u6838\u9000 vendored/\u6570\u5B66\u9000\u5185\u7F6E\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u80CC\u4E66\uFF09"),h=!0),null;try{u=l()}catch(C){qe("[host-dev engine] engineFactory \u629B\u9519\uFF0CgetEngine \u964D\u7EA7\u8FD4\u56DE null",C),u=null}return u}function w(C,A){return{getContext2d(){return t.context2d==null?null:t.context2d},onFrame(P){let M=d++;return p.set(M,P),{cancel(){p.delete(M)}}},getInput(){return o.sourceFor(C)},getAudioContext(){return x()},getEngine(){return v()},time:e,random:A}}let _=w(null,s),S={context:_,tick(C){y+=1;let A=Array.from(p.values());for(let T of A)try{T(C,y)}catch(P){qe("[host-dev tick] \u5E27\u56DE\u8C03\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09frame="+y,P)}},frameCount(){return y},inputBridge:o,deriveContextFor(C,A){let T=zc(i,C),P=new js(T);return w(A==null?C:A,P)}};return Object.defineProperty(_,Wi,{value:S,enumerable:!1,writable:!1,configurable:!1}),S}var Wi=Symbol("zaomeng.coreProtocol.contextBundle"),Bs=class{constructor(){this._plugins=new Map,this._initOrder=[],this._initErrors=[],this._phase="idle",this._disposed=!1,this._context=void 0,this._pluginContexts=new Map}register(t){if(!t||typeof t!="object")throw new Error("[PluginRegistry] register \u9700\u8981\u4E00\u4E2A\u63D2\u4EF6\u5BF9\u8C61");if(typeof t.name!="string"||t.name.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6\u7F3A\u5C11\u5408\u6CD5 name");if(typeof t.version!="string"||t.version.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11\u5408\u6CD5 version");if(typeof t.init!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11 init \u51FD\u6570");if(t.dispose!=null&&typeof t.dispose!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7684 dispose \u5FC5\u987B\u662F\u51FD\u6570\u6216\u7701\u7565");if(this._plugins.has(t.name))throw new Error("[PluginRegistry] \u63D2\u4EF6\u91CD\u540D\u62D2\u7EDD\uFF1A"+t.name+" \u5DF2\u6CE8\u518C");return this._plugins.set(t.name,t),this}has(t){return this._plugins.has(t)}get(t){return this._plugins.get(t)}list(){return Array.from(this._plugins.keys())}initAll(){if(this._phase==="initialized")return qi("[PluginRegistry] initAll \u91CD\u590D\u8C03\u7528\uFF0C\u5DF2\u5FFD\u7565\uFF08\u5DF2\u5904\u4E8E initialized\uFF09"),this._initResult();if(this._phase==="disposed")throw new Error("[PluginRegistry] \u5DF2 dispose \u7684\u6CE8\u518C\u5668\u4E0D\u53EF\u518D initAll");if(this._context==null)throw new Error("[PluginRegistry] \u672A\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\uFF1A\u8BF7\u5728 initAll() \u4E4B\u524D\u8C03\u7528 useContext(context)\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context); reg.initAll();\uFF09");for(let[t,e]of this._plugins){let s=this._missingDeps(e);if(s.length>0){let o=new Error("[PluginRegistry] \u63D2\u4EF6 "+t+" \u4F9D\u8D56\u7F3A\u5931\uFF1A"+s.join(", ")+"\uFF08\u672A\u6CE8\u518C\uFF09");this._initErrors.push({name:t,error:o}),qe("[PluginRegistry] \u8DF3\u8FC7 init\uFF08\u4F9D\u8D56\u7F3A\u5931\uFF0C\u5DF2\u9694\u79BB\uFF09\uFF1A"+t,o);continue}let i=this._contextFor(t);try{e.init(i),this._initOrder.push(t)}catch(o){let a=o instanceof Error?o:new Error(String(o));this._initErrors.push({name:t,error:a}),qe("[PluginRegistry] \u63D2\u4EF6 init \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF0C\u4E0D\u8FDE\u5750\uFF09\uFF1A"+t,a)}}return this._phase="initialized",this._initResult()}_contextFor(t){let e=this._pluginContexts.get(t);if(e)return e;let s=this._context&&this._context[Wi],i;return s&&typeof s.deriveContextFor=="function"?i=s.deriveContextFor(t,t):i=this._context,this._pluginContexts.set(t,i),i}disposeAll(){if(this._disposed)return{disposed:[],errors:[]};let t=[],e=[],s=this._context&&this._context[Wi],i=s&&s.inputBridge;for(let o=this._initOrder.length-1;o>=0;o--){let a=this._initOrder[o],r=this._plugins.get(a);if(r&&typeof r.dispose=="function")try{r.dispose(),t.push(a)}catch(c){let l=c instanceof Error?c:new Error(String(c));e.push({name:a,error:l}),qe("[PluginRegistry] \u63D2\u4EF6 dispose \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+a,l)}if(i&&typeof i.disposeScope=="function")try{i.disposeScope(a)}catch(c){qe("[PluginRegistry] \u56DE\u6536\u63D2\u4EF6\u8F93\u5165\u8BA2\u9605\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+a,c)}}return this._disposed=!0,this._phase="disposed",{disposed:t,errors:e}}useContext(t){if(this._phase!=="idle")throw new Error("[PluginRegistry] useContext \u5FC5\u987B\u5728 initAll() \u4E4B\u524D\u8C03\u7528\uFF08\u5F53\u524D\u9636\u6BB5\uFF1A"+this._phase+"\uFF09\u3002\u8BF7\u5728\u4EFB\u4F55 initAll/disposeAll \u4E4B\u524D\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\u3002");if(t==null||typeof t!="object")throw new Error("[PluginRegistry] useContext \u9700\u8981\u4E00\u4E2A\u53D7\u63A7\u4E0A\u4E0B\u6587\u5BF9\u8C61\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context);\uFF09");return this._context=t,this}_missingDeps(t){return!Array.isArray(t.dependencies)||t.dependencies.length===0?[]:t.dependencies.filter(e=>!this._plugins.has(e))}_initResult(){return{ok:this._initErrors.length===0,initialized:this._initOrder.slice(),errors:this._initErrors.slice()}}};function zc(n,t){let e=2166136261,s=16777619,i=n>>>0;for(let a=0;a<32;a+=8){let r=i>>>a&255;e^=r,e=Math.imul(e,s)>>>0}let o=String(t);for(let a=0;a>>0,e^=r>>>8&255,e=Math.imul(e,s)>>>0}return e>>>0}function Jc(){if(typeof globalThis!="undefined"&&globalThis.performance&&typeof globalThis.performance.now=="function")return()=>globalThis.performance.now();if(typeof process!="undefined"&&process.hrtime&&typeof process.hrtime.bigint=="function"){let n=process.hrtime.bigint();return()=>Number(process.hrtime.bigint()-n)/1e6}return()=>Date.now()}function qe(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function qi(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var xd=Object.freeze(Array.from(Vi)),Yr="core-protocol-v0";var $r=Object.freeze(["t_boot","t_plugins_ready","t_game_init","t_first_paint","t_input_bound","t_game_start"]),Hi=$r.reduce((n,t,e)=>(n[t]=e,n),Object.create(null)),Uc=new Set($r);function Xi(n){let t=2166136261;for(let e=0;e>>0).toString(16).padStart(8,"0")}var Kr=Xi("runtime-probe::seed::v1");function Ns(n){return n===null||typeof n!="object"?JSON.stringify(n):Array.isArray(n)?"["+n.map(Ns).join(",")+"]":"{"+Object.keys(n).sort().map(e=>JSON.stringify(e)+":"+Ns(n[e])).join(",")+"}"}function Qr(n){let t=Ns(n.extra==null?null:n.extra),e=Ns(Array.isArray(n.pluginSet)?n.pluginSet:[]);return["seq="+n.seq,"anchor="+n.anchor,"tMono="+n.tMono,"buildSha="+(n.buildSha||""),"pluginSet="+e,"extra="+t].join("|")}function Vc(n){return Math.round(n*1e3)/1e3}function Wc(n){if(!Array.isArray(n))return{ok:!1,reason:"records_not_array"};let t=Kr,e=-1;for(let s=0;stypeof C=="string").slice().sort():[],i=typeof t.sink=="function"?t.sink:null,o=t.autoBoot!==!1,a=typeof t.inputAnchorType=="string"?t.inputAnchorType:"pointerdown",r=()=>0,c=!1,l=0,u=Kr,h=[],p=new Set,d=-1,y=null,x=!1,v=!1,w=!1;function _(C,A){let T=null;if(!Uc.has(C))T="unknown_anchor";else{p.has(C)&&(T=T?T+";duplicate_anchor":"duplicate_anchor");let M=Hi[C];MC.time.nowMs(),c=!0,o&&!v&&_("t_boot",{auto:!0}),y=C.getInput().on(a,A=>{x||(x=!0,_("t_input_bound",{firstInput:!0,type:A.type}))}),_("t_input_bound",{stage:"registered",type:a})},dispose(){w||(y&&(y.cancel(),y=null),w=!0)},mark:_,getRecords(){return h.map(C=>({...C}))},toJSONL(){return h.map(C=>JSON.stringify(C)).join(`
+`)},verify(){return Wc(h)}}}function qc(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function ta(n){let t=n.LJS,e=n.engineMath,s=n.engineMode,i=n.recHook||(()=>{});if(s!=="real")return null;let o=e;return{math:{lerp:(r,c,l)=>(i("math.lerp"),o.lerp(r,c,l)),smoothStep:r=>(i("math.smoothStep"),o.smoothStep(r)),easing:Object.fromEntries(Object.keys(o.easing).map(r=>[r,c=>(i("math.easing."+r),o.easing[r](c))]))},particles:{spawnEmitter(r){i("particles.spawnEmitter");let c=t.screenToWorld(t.vec2(r.pos.x,r.pos.y)),l=t.cameraScale,u=r.emitTime!=null?r.emitTime:r.count!=null?1/60:0,h=r.emitRate!=null?r.emitRate:r.count!=null?r.count*60:100,p=(r.speed!=null?r.speed:0)/l/60,d=r.damping!=null?r.damping:1,y=r.colorStart||{r:1,g:1,b:1,a:1},x=r.colorEnd||{r:1,g:1,b:1,a:0},v=t.rgb(y.r,y.g,y.b,y.a),w=t.rgb(x.r,x.g,x.b,x.a),_=new t.ParticleEmitter(c,r.angle!=null?r.angle:0,(r.emitSize!=null?r.emitSize:0)/l,u,h,r.coneAngle!=null?r.coneAngle:Math.PI,void 0,v,v,w,w,r.particleTime!=null?r.particleTime:.5,(r.sizeStart!=null?r.sizeStart:6)/l,(r.sizeEnd!=null?r.sizeEnd:0)/l,p,0,d,1,r.gravityScale!=null?r.gravityScale:0,Math.PI,.1,0,!1,r.additive!=null?r.additive:!1,!0);return{isActive(){return _.isActive()},stop(){_.destroyed||_.destroy(!0)}}}},audio:{synth:{synthSfx:r=>{i("audio.synth.synthSfx");try{return t.zzfxG(...r)}catch(c){return console.error("[host][engine-audio] zzfxG \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(c&&c.message?c.message:c)),null}},synthSong:(r,c,l,u)=>{i("audio.synth.synthSong");try{return t.zzfxM(r,c,l,u)}catch(h){return console.error("[host][engine-audio] zzfxM \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(h&&h.message?h.message:h)),null}}}}}}function ce(n){return n<0?0:n>1?1:n}function ea(n){let t=n.Ease,e=t.POWER(2),s=t.POWER(3),i=t.OUT(e),o=t.IN_OUT(e),a=t.OUT(s),r=t.IN_OUT(s),c=t.OUT(t.BACK),l=t.OUT(t.ELASTIC);return{lerp:(u,h,p)=>n.lerp(u,h,p),smoothStep:u=>n.smoothStep(u),easing:{linear:u=>t.LINEAR(ce(u)),quadIn:u=>e(ce(u)),quadOut:u=>i(ce(u)),quadInOut:u=>o(ce(u)),cubicIn:u=>s(ce(u)),cubicOut:u=>a(ce(u)),cubicInOut:u=>r(ce(u)),backIn:u=>t.BACK(ce(u)),backOut:u=>c(ce(u)),elasticIn:u=>t.ELASTIC(ce(u)),elasticOut:u=>l(ce(u))}}}var He=2,zs=1/60;async function na(n){let t=n.canvas,e=n.statusEl||null,s=n.engine,i=n.seed>>>0,o=n.mode||"play",a=n.engineMode||"real",r=n.viewport.w,c=n.viewport.h,l=n.factory,u=n.buildFactoryOpts||(()=>{}),h=n.plugins||{},p=n.registerOrder||Object.values(h),d=n.onReady||(()=>{}),y=n.recHook||(()=>{});function x(D){e&&(e.textContent=D)}let v=[];window.addEventListener("error",D=>v.push({type:"error",message:String(D&&D.message||D)})),window.addEventListener("unhandledrejection",D=>v.push({type:"unhandledrejection",message:String(D&&D.reason&&D.reason.message||D&&D.reason||D)}));let w=null,_=!1;function S(){if(!_)return null;if(w)return w;let D=window.AudioContext||window.webkitAudioContext;return D?(w=new D,w):null}let C=0,A=null,T=null,P=null,M=null,pt=[],at={},ct=null;function yt(D,ot){try{P&&P.mark(D,ot)}catch(ee){v.push({type:"mark",message:String(ee&&ee.message||ee)})}}function Nt(){T&&typeof T._refreshChecklist=="function"&&T._refreshChecklist(at)}async function ge(D,ot){A=Xr({context2d:D,seed:i,audioFactory:S,clock:()=>C,engineFactory:()=>ta({LJS:a==="real"?s:null,engineMath:a==="real"?ea(s):null,engineMode:a,recHook:y})});let ee=new Bs;for(let ye of p)ee.register(ye);ee.useContext(A.context),M=ee.initAll(),pt=ee.list().concat(["runtime-probe"]),P=Zr({pluginSet:pt,inputAnchorType:"pointerdown",autoBoot:!0});let Dt=A.deriveContextFor("runtime-probe","runtime-probe");yt("t_boot",{by:"game-host",stage:"pre-init",engineMode:a}),yt("t_plugins_ready",{initialized:M.initialized.length,ok:M.ok});let Ni=u(A.context,{bundle:A,plugins:h,getRealAudioCtx:()=>w});T=l(Ni),await T.init({ctx:A.context,mainContext:D,canvas:ot(),seed:i}),ct=T&&typeof T._forensicsView=="function"?T._forensicsView():null,yt("t_game_init",{hasForensics:!!ct}),ht(),yt("t_first_paint",{frame:A.frameCount()});try{P.init(Dt)}catch(ye){v.push({type:"probe-init",message:String(ye&&ye.message||ye)})}yt("t_game_start",{mode:o,engineMode:a}),Nt(),d(un,{bundle:A,game:T,probe:P,checklist:at,uncaught:v,pluginSet:pt,initRes:M,getGameForensics:()=>ct,mark:yt,stepOneFrame:ht})}let Pt=null;function ht(D){let ot=typeof D=="number"?D:zs;T&&(C+=ot*1e3,T.update(ot),a==="stub"&&Pt&&T.render(Pt),Nt())}function Lt(D){for(let ot=0;ot{}),T&&typeof T._onAudioUnlock=="function"&&T._onAudioUnlock()}let un={seed:i,mode:o,engineMode:a,protocol:Yr,frameCount:()=>A?A.frameCount():0,stepFrames:Lt,startRaf:()=>F(),stopRaf:()=>k(),tap(D,ot){Pe(),A&&(A.inputBridge._emit("pointerdown",{x:D,y:ot}),A.inputBridge._emit("pointerup",{x:D,y:ot}))},do(D){T&&typeof T._handleAction=="function"&&T._handleAction(D)},state:()=>ct?ct.state():{phase:"booting"}};function hn(D){let ot=A.inputBridge;function ee(Dt,Ni){let ye=D.getBoundingClientRect();return{x:(Dt-ye.left)/ye.width*r,y:(Ni-ye.top)/ye.height*c}}D.addEventListener("pointerdown",Dt=>{Pe(),ot._emit("pointerdown",ee(Dt.clientX,Dt.clientY))}),D.addEventListener("pointermove",Dt=>{ot._emit("pointermove",ee(Dt.clientX,Dt.clientY))}),D.addEventListener("pointerup",Dt=>{ot._emit("pointerup",ee(Dt.clientX,Dt.clientY))}),window.addEventListener("keydown",Dt=>{Pe(),ot._emit("keydown",{key:Dt.key})}),window.addEventListener("keyup",Dt=>ot._emit("keyup",{key:Dt.key}))}let ae=0,Le=!1,te=0;function R(D){if(!Le)return;te===0&&(te=D);let ot=(D-te)/1e3;te=D,ot>.05&&(ot=.05),ht(ot),ae=window.requestAnimationFrame(R)}function F(){a==="stub"&&(Le||(Le=!0,te=0,ae=window.requestAnimationFrame(R)))}function k(){Le=!1,ae&&window.cancelAnimationFrame(ae),ae=0}function j(D){D.width=r*He,D.height=c*He,D.style.width=r+"px",D.style.height=c+"px";let ot=D.getContext("2d",{willReadFrequently:!0});return ot.setTransform(He,0,0,He,0,0),ot}async function $(){let D=j(t);return Pt=D,await ge(D,()=>t),hn(t),o==="evidence"?x(`evidence \u5C31\u7EEA seed=${i} \xB7 \u7528 host \u9A71\u52A8\uFF08stepFrames/tap\uFF09`):(x(`seed=${i} \xB7 \u70B9\u5F00\u59CB\uFF08\u9996\u6B21\u70B9\u51FB\u5F00\u58F0\uFF09`),F()),un}let Z=()=>{},Tt=()=>{};function At(){window.__gameHostEngineInitFired=!0}function Ot(){Z()}function Oe(){}function Zn(){Tt()}function dn(){}async function Fs(D){await ge(D,()=>s.mainCanvas),hn(s.mainCanvas),Z=()=>{T&&(C+=zs*1e3,T.update(zs))},Tt=()=>{if(T){D.save(),D.setTransform(He,0,0,He,0,0);try{D.imageSmoothingEnabled=!1}catch{}T.render(D),D.restore()}},s.mainCanvas&&(s.mainCanvas.id="game-engine"),window.__engine={frame(){return s.frame},time(){return s.time},timeReal(){return s.timeReal},paused(){return s.paused},timeScale(){return s.timeScale},snapshot(){return{frame:s.frame,time:s.time,timeReal:s.timeReal,paused:s.paused,timeScale:s.timeScale}}},x(`engine RAF running \xB7 seed=${i} engine=real`)}if(a!=="real")return await $();if(!s){let D="real \u901A\u9053\u672A\u6CE8\u5165\u5F15\u64CE\uFF08opts.engine \u7F3A\u5931\uFF09\uFF1A\u8BF7\u7ECF entry \u5305\u88C5\u5C42\u542F\u52A8\uFF08host \u4E0D\u76F4\u63A5 import \u5F15\u64CE\uFF0CQ4/Option C\uFF09";throw x("ENGINE INJECT MISSING: "+D),new Error(D)}s.setGLEnable(!1),s.setShowSplashScreen(!1),s.setDebugWatermark(!1),s.setCanvasClearColor(s.BLACK),s.setCanvasFixedSize(s.vec2(r*He,c*He));let Dn=document.createElement("div");return Dn.id="engine-root",document.body.appendChild(Dn),await s.engineInit(At,Ot,Oe,Zn,dn,[],Dn).then(()=>Fs(s.mainContext)).catch(D=>{throw window.__gameHostBootError=String(D&&D.message||D),x("ENGINE INIT FAILED: "+window.__gameHostBootError),D}),un}var Yi=class{constructor(t){let e=t||{},s=typeof e.cellSize=="number"&&e.cellSize>0?e.cellSize:64;this._cellSize=s,this._cells=new Map,this._entries=new Map,this._seq=0}get size(){return this._entries.size}_cellRange(t){let e=this._cellSize,s=Math.floor((t.x-t.hw)/e),i=Math.floor((t.x+t.hw)/e),o=Math.floor((t.y-t.hh)/e),a=Math.floor((t.y+t.hh)/e);return{cx0:s,cy0:o,cx1:i,cy1:a}}insert(t,e){this._entries.has(t)&&this.remove(t);let{cx0:s,cy0:i,cx1:o,cy1:a}=this._cellRange(e),r=[];for(let l=i;l<=a;l++)for(let u=s;u<=o;u++){let h=u+","+l,p=this._cells.get(h);p||(p=new Set,this._cells.set(h,p)),p.add(t),r.push(h)}let c={x:e.x,y:e.y,hw:e.hw,hh:e.hh};this._entries.set(t,{id:t,box:c,seq:this._seq++,cells:r})}remove(t){let e=this._entries.get(t);if(!e)return!1;for(let s of e.cells){let i=this._cells.get(s);i&&(i.delete(t),i.size===0&&this._cells.delete(s))}return this._entries.delete(t),!0}query(t){let{cx0:e,cy0:s,cx1:i,cy1:o}=this._cellRange(t),a=new Set;for(let r=s;r<=o;r++)for(let c=e;c<=i;c++){let l=this._cells.get(c+","+r);if(l)for(let u of l)a.add(u)}return this._collect(a)}queryPoint(t,e){let s=this._cellSize,i=Math.floor(t/s),o=Math.floor(e/s),a=this._cells.get(i+","+o);return a?this._collect(new Set(a)):[]}clear(){this._cells.clear(),this._entries.clear(),this._seq=0}_collect(t){let e=[];for(let s of t){let i=this._entries.get(s);i&&e.push(i)}return e.sort((s,i)=>s.seq-i.seq),e.map(s=>({id:s.id,box:s.box}))}};function sa(n){let t=n||{},e=new Yi({cellSize:t.cellSize}),s=!1;return{name:"collision",version:"1.0.0",dependencies:[],spatial:e,init(o){},dispose(){s||(e.clear(),s=!0)}}}function ia(n){let t=!1;return{name:"physics-lite",version:"1.0.0",dependencies:[],init(s){},dispose(){t||(t=!0)}}}var Hc=["pointerdown","pointermove","pointerup","keydown","keyup"];function zt(n){return n<0?0:n>1?1:n}var Xc=n=>(n=zt(n),n*n),Yc=n=>(n=zt(n),1-(1-n)*(1-n)),$c=n=>(n=zt(n),n<.5?2*n*n:1-Math.pow(-2*n+2,2)/2),Kc=n=>(n=zt(n),n*n*n),Qc=n=>{n=zt(n);let t=1-n;return 1-t*t*t},Zc=n=>(n=zt(n),n<.5?4*n*n*n:1-Math.pow(-2*n+2,3)/2),aa=2*Math.PI/3,oa=2*Math.PI/4.5,tl=n=>(n=zt(n),n===0?0:n===1?1:-Math.pow(2,10*n-10)*Math.sin((n*10-10.75)*aa)),el=n=>(n=zt(n),n===0?0:n===1?1:Math.pow(2,-10*n)*Math.sin((n*10-.75)*aa)+1),nl=n=>(n=zt(n),n===0?0:n===1?1:n<.5?-(Math.pow(2,20*n-10)*Math.sin((20*n-11.125)*oa))/2:Math.pow(2,-20*n+10)*Math.sin((20*n-11.125)*oa)/2+1),Us=1.70158,Js=Us*1.525,ca=Us+1,sl=n=>(n=zt(n),ca*n*n*n-Us*n*n),il=n=>{n=zt(n);let t=n-1;return 1+ca*t*t*t+Us*t*t},ol=n=>(n=zt(n),n<.5?Math.pow(2*n,2)*((Js+1)*2*n-Js)/2:(Math.pow(2*n-2,2)*((Js+1)*(n*2-2)+Js)+2)/2),rl=n=>zt(n),ra=Object.freeze({linear:rl,quadIn:Xc,quadOut:Yc,quadInOut:$c,cubicIn:Kc,cubicOut:Qc,cubicInOut:Zc,elasticIn:tl,elasticOut:el,elasticInOut:nl,backIn:sl,backOut:il,backInOut:ol});var al=["linear","quadIn","quadOut","quadInOut","cubicIn","cubicOut","cubicInOut","elasticIn","elasticOut","elasticInOut","backIn","backOut","backInOut"];function cl(n){let t=n&&n.easing;if(!t)return ra;let e=i=>typeof t[i]=="function"?o=>t[i](zt(o)):ra[i],s={};for(let i of al)s[i]=e(i);return Object.freeze(s)}var $i=class{constructor(t,e,s){let i=s||{};this._time=e,this._windowMs=typeof i.windowMs=="number"&&i.windowMs>0?i.windowMs:120;let o=Array.isArray(i.types)&&i.types.length>0?i.types:Hc;this._records=new Map,this._subs=[],this._disposed=!1;for(let a of o){this._records.set(a,null);let r=t.on(a,c=>{this._records.set(a,c.tMs)});this._subs.push(r)}}consume(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs?(this._records.set(t,null),!0):(this._records.set(t,null),!1)}peek(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs}clear(){for(let t of this._records.keys())this._records.set(t,null)}dispose(){if(!this._disposed){for(let t of this._subs)try{t.cancel()}catch(e){}this._subs=[],this._disposed=!0}}};function la(n){let t=n||{},e=null,s=null,i=!1;return{name:"gamefeel",version:"1.0.0",dependencies:[],get inputBuffer(){return e},get easing(){return cl(s)},init(a){let r=a.getInput();e=new $i(r,a.time,{windowMs:t.inputBufferMs,types:t.inputTypes});let c=a.getEngine();s=c?c.math:null},dispose(){i||(e&&(e.dispose(),e=null),s=null,i=!0)}}}function Vs(n,t){let e=t<0?0:t>1?1:t;switch(n&&n.kind){case"constant":return n.value;case"linear":return n.from+(n.to-n.from)*e;case"easeInOut":{let s=e*e*(3-2*e);return n.from+(n.to-n.from)*s}case"decay":{let s=n.power==null?2:n.power,i=Math.pow(1-e,s);return n.to+(n.from-n.to)*i}default:return 0}}var ll=Object.freeze({burst:Object.freeze({mode:"burst",count:24,angle:0,spread:Math.PI,speedMin:80,speedMax:160,lifeMin:.4,lifeMax:.8,gravity:0,drag:0,sizeCurve:{kind:"decay",from:6,to:0,power:1.5},alphaCurve:{kind:"linear",from:1,to:0}}),trail:Object.freeze({mode:"continuous",rate:60,angle:Math.PI,spread:.25,speedMin:20,speedMax:50,lifeMin:.2,lifeMax:.5,gravity:0,drag:1.5,sizeCurve:{kind:"easeInOut",from:4,to:0},alphaCurve:{kind:"decay",from:.8,to:0,power:2}}),drift:Object.freeze({mode:"continuous",rate:12,angle:Math.PI/2,spread:.6,speedMin:10,speedMax:30,lifeMin:1.5,lifeMax:3,gravity:8,drag:.5,sizeCurve:{kind:"constant",value:3},alphaCurve:{kind:"decay",from:.7,to:0,power:1}})});function ul(n){let t=ll[n];return t?Ki(t):null}function Ki(n){let t={};for(let e of Object.keys(n)){let s=n[e];t[e]=s&&typeof s=="object"?Ki(s):s}return t}function hl(n,t,e){let s=n.mode==="continuous";return{pos:{x:t,y:e},angle:n.angle,coneAngle:n.spread,emitSize:0,emitTime:s?0:1/60,emitRate:s?n.rate||0:void 0,count:s?void 0:n.count||0,particleTime:(n.lifeMin+n.lifeMax)/2,speed:(n.speedMin+n.speedMax)/2,gravityScale:n.gravity||0,damping:n.drag!=null?1-n.drag/60:1,sizeStart:Vs(n.sizeCurve,0),sizeEnd:Vs(n.sizeCurve,1),colorStart:{r:1,g:1,b:1,a:Vs(n.alphaCurve,0)},colorEnd:{r:1,g:1,b:1,a:Vs(n.alphaCurve,1)},additive:!1}}function ua(n){let t=n||{},e=null,s=null,i=null,o=new Map,a=0,r={isActive(){return!1},stop(){}},c=0,l=1,u=0,h=0,p=0,d={x:0,y:0,remain:0,dur:0,amplitude:0,frequency:0,_phase:0},y={alpha:0,remain:0,dur:0,peak:0},x={scale:1,remain:0,dur:0,amplitude:0,frequency:0},v=!1;function w(A){if(u>0)if(u-=A,u<=0)u=0,l=1;else{let T=h>0?1-u/h:1;l=p+(1-p)*T}if(d.remain>0)if(d.remain-=A,d.remain<=0)d.remain=0,d.x=0,d.y=0;else{let T=d.remain/d.dur,P=d.amplitude*T;d._phase+=d.frequency*A*Math.PI*2,d.x=Math.sin(d._phase)*P,d.y=Math.cos(d._phase*1.3)*P}if(y.remain>0&&(y.remain-=A,y.remain<=0?(y.remain=0,y.alpha=0):y.alpha=y.peak*(y.remain/y.dur)),x.remain>0)if(x.remain-=A,x.remain<=0)x.remain=0,x.scale=1;else{let T=x.remain/x.dur,P=(1-T)*x.frequency*Math.PI*2;x.scale=1+Math.sin(P)*x.amplitude*T}}function _(A){c+=1,w(A)}function S(A){let T=A!==void 0?A:e?e.getContext2d():null;if(T&&y.alpha>0){T.globalAlpha=y.alpha,T.fillStyle="#ffffff";let P=T.canvas?T.canvas.width:0,M=T.canvas?T.canvas.height:0;T.fillRect(0,0,P,M),T.globalAlpha=1}}return{name:"particles-juice",version:"1.0.0",dependencies:[],init(A){var T;e=A,i=((T=A.getEngine())==null?void 0:T.particles)||null,typeof t.seed=="number"&&A.random.reseed(t.seed),t.autoStep!==!1&&(s=A.onFrame(P=>{_(P)}))},dispose(){v||(s&&(s.cancel(),s=null),o.forEach(A=>{try{A.stop()}catch{}}),o.clear(),l=1,u=0,d.remain=0,d.x=0,d.y=0,y.remain=0,y.alpha=0,x.remain=0,x.scale=1,v=!0)},spawnEmitter(A,T,P,M){let pt=typeof A=="string"?ul(A):Ki(A);if(!pt)return-1;M&&(pt=Object.assign(pt,M));let at=a++;if(!i)return o.set(at,r),at;let ct=i.spawnEmitter(hl(pt,T,P));return o.set(at,ct),at},stopEmitter(A){let T=o.get(A);if(T)try{T.stop()}catch{}},step(A){_(A)},render(A){S(A)},particleCount(){return 0},emitterCount(){let A=0;for(let T of o.values())T.isActive()&&(A+=1);return A},hitStop(A,T){h=Math.max(0,A),u=h,p=T==null?0:Math.max(0,Math.min(1,T)),l=h>0?p:1},getTimeScale(){return l},shakeScreen(A,T,P){d.dur=Math.max(0,A),d.remain=d.dur,d.amplitude=Math.max(0,T),d.frequency=P==null?30:P,d._phase=0,d.x=0,d.y=0},getShakeOffset(){return{x:d.x,y:d.y}},flashScreen(A,T){y.dur=Math.max(0,A),y.remain=y.dur,y.peak=T==null?.8:Math.max(0,Math.min(1,T)),y.alpha=y.dur>0?y.peak:0},getFlashAlpha(){return y.alpha},pulseScale(A,T,P){x.dur=Math.max(0,A),x.remain=x.dur,x.amplitude=T==null?.2:T,x.frequency=P==null?4:P,x.scale=1},getPulseScale(){return x.scale},juiceSnapshot(){return{timeScale:l,shake:{x:d.x,y:d.y},flashAlpha:y.alpha,pulseScale:x.scale}},probe(){return{particles:0,emitters:o.size,dropped:0,steps:c,disposed:v}}}}function ha(n){let t=gt(n.r)/255,e=gt(n.g)/255,s=gt(n.b)/255,i=Math.max(t,e,s),o=Math.min(t,e,s),a=(i+o)/2,r=0,c=0,l=i-o;return l>1e-12&&(c=a>.5?l/(2-i-o):l/(i+o),i===t?r=(e-s)/l%6:i===e?r=(s-t)/l+2:r=(t-e)/l+4,r*=60,r<0&&(r+=360)),{h:r,s:c,l:a}}function da(n){let t=(n.h%360+360)%360,e=Xe(n.s),s=Xe(n.l);if(e<1e-12){let r=Math.round(s*255);return{r,g:r,b:r}}let i=s<.5?s*(1+e):s+e-s*e,o=2*s-i,a=t/360;return{r:Math.round(Qi(o,i,a+1/3)*255),g:Math.round(Qi(o,i,a)*255),b:Math.round(Qi(o,i,a-1/3)*255)}}function Qi(n,t,e){let s=e;return s<0&&(s+=1),s>1&&(s-=1),s<1/6?n+(t-n)*6*s:s<1/2?t:s<2/3?n+(t-n)*(2/3-s)*6:n}function gt(n){return n<0?0:n>255?255:n}function Xe(n){return n<0?0:n>1?1:n}function dl(n,t){let e=pl(n.from,t);if(e>=0&&e({r:gt(r.r),g:gt(r.g),b:gt(r.b)})),to:o}}function Zi(n,t,e){return n+(t-n)*e}function ml(n,t){let e=ha(n),s=e.h+(t.hue||0),i=Xe(e.s*(t.sat==null?1:t.sat)),o=Xe(e.l*(t.light==null?1:t.light));return da({h:s,s:i,l:o})}var bl=Object.freeze([Object.freeze([0,8,2,10]),Object.freeze([12,4,14,6]),Object.freeze([3,11,1,9]),Object.freeze([15,7,13,5])]);function fa(n){let t=n||{},e=null,s=!1,i={vignette:{enabled:to(t.vignette&&t.vignette.enabled,!1),strength:eo(t.vignette&&t.vignette.strength,.5)},dither:{enabled:to(t.dither&&t.dither.enabled,!1),strength:eo(t.dither&&t.dither.strength,.5)},scanline:{enabled:to(t.scanline&&t.scanline.enabled,!1),strength:eo(t.scanline&&t.scanline.strength,.5)}};function o(r){let c=r!==void 0?r:e?e.getContext2d():null;if(!c)return;let l=c.canvas?c.canvas.width:0,u=c.canvas?c.canvas.height:0;if(i.vignette.enabled&&i.vignette.strength>0&&l>0&&u>0){let h=c.createRadialGradient(l/2,u/2,Math.min(l,u)*.25,l/2,u/2,Math.max(l,u)*.75);h.addColorStop(0,"rgba(0,0,0,0)"),h.addColorStop(1,"rgba(0,0,0,"+i.vignette.strength.toFixed(3)+")"),c.fillStyle=h,c.fillRect(0,0,l,u)}if(i.scanline.enabled&&i.scanline.strength>0&&l>0&&u>0){c.fillStyle="rgba(0,0,0,"+(i.scanline.strength*.5).toFixed(3)+")";for(let h=0;h0&&l>0&&u>0&&typeof c.getImageData=="function"&&typeof c.putImageData=="function"){let h=c.getImageData(0,0,l,u);xl(h,i.dither.strength),c.putImageData(h,0,0)}}return{name:"palette-post",version:"1.0.0",dependencies:[],init(r){e=r},dispose(){s||(e=null,s=!0)},applyPaletteMap(r,c){return dl(r,c)},applyPaletteMapToBuffer(r,c){return fl(r,c)},lerpPaletteMap(r,c,l){return yl(r,c,l)},shiftHsl(r,c){return ml(r,c)},rgbToHsl(r){return ha(r)},hslToRgb(r){return da(r)},setPost(r){if(r)for(let c of["vignette","dither","scanline"])r[c]&&(typeof r[c].enabled=="boolean"&&(i[c].enabled=r[c].enabled),typeof r[c].strength=="number"&&(i[c].strength=Xe(r[c].strength)))},getPost(){return{vignette:{enabled:i.vignette.enabled,strength:i.vignette.strength},dither:{enabled:i.dither.enabled,strength:i.dither.strength},scanline:{enabled:i.scanline.enabled,strength:i.scanline.strength}}},renderPost(r){o(r)},probe(){return{disposed:s,post:this.getPost()}}}}function xl(n,t){let e=Xe(t);if(e<=0)return n;let{data:s,width:i}=n,a=255/(Math.max(2,Math.round(16-e*14))-1);for(let r=0;r+3>2)%i,l=Math.floor((r>>2)/i),u=(bl[l&3][c&3]/16-.5)*a;for(let h=0;h<3;h++){let p=s[r+h]+u,d=Math.round(p/a)*a;s[r+h]=d<0?0:d>255?255:d}}return n}function to(n,t){return typeof n=="boolean"?n:t}function eo(n,t){return typeof n=="number"?Xe(n):t}var so=Object.freeze({blip:Object.freeze({name:"blip",params:Object.freeze([.6,0,880,0,.03,.06,1,1.5])}),thud:Object.freeze({name:"thud",params:Object.freeze([.8,0,90,0,.04,.18,0,1,0,0,0,0,0,4])}),chime:Object.freeze({name:"chime",params:Object.freeze([.5,0,660,.02,.12,.3,1,2])})}),pa=Object.keys(so);function vl(n){let t=[];return n==null||typeof n!="object"?{ok:!1,errors:["song \u5FC5\u987B\u662F\u5BF9\u8C61"]}:(!Array.isArray(n.instruments)||n.instruments.length===0?t.push("instruments \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.instruments.forEach((e,s)=>{(!Array.isArray(e)||e.some(i=>typeof i!="number"||!Number.isFinite(i)))&&t.push(`instruments[${s}] \u5FC5\u987B\u662F\u6709\u9650\u6570\u5B57\u6570\u7EC4\uFF08ZzFX \u53C2\u6570\u5305\uFF09`)}),!Array.isArray(n.patterns)||n.patterns.length===0?t.push("patterns \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.patterns.forEach((e,s)=>{if(!Array.isArray(e)||e.length===0){t.push(`patterns[${s}] \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4\uFF08\u81F3\u5C11\u4E00\u4E2A\u58F0\u90E8\u901A\u9053\uFF09`);return}e.forEach((i,o)=>{if(!Array.isArray(i)||i.length<2){t.push(`patterns[${s}][${o}] \u901A\u9053\u81F3\u5C11\u542B [\u4E50\u5668\u7D22\u5F15, \u58F0\u50CF]`);return}if(i.some(c=>typeof c!="number"||!Number.isFinite(c))){t.push(`patterns[${s}][${o}] \u901A\u9053\u5FC5\u987B\u5168\u4E3A\u6709\u9650\u6570\u5B57`);return}let a=i[0]|0;Array.isArray(n.instruments)&&(a<0||a>=n.instruments.length)&&t.push(`patterns[${s}][${o}] \u4E50\u5668\u7D22\u5F15 ${a} \u8D8A\u754C\uFF08instruments \u957F\u5EA6 ${n.instruments.length}\uFF09`);let r=i[1];(r<-1||r>1)&&t.push(`patterns[${s}][${o}] \u58F0\u50CF ${r} \u8D8A\u754C\uFF08\u5E94 -1..+1\uFF09`)})}),!Array.isArray(n.sequence)||n.sequence.length===0?t.push("sequence \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.sequence.forEach((e,s)=>{if(typeof e!="number"||!Number.isInteger(e)){t.push(`sequence[${s}] \u5FC5\u987B\u662F\u6574\u6570 pattern \u7D22\u5F15`);return}Array.isArray(n.patterns)&&(e<0||e>=n.patterns.length)&&t.push(`sequence[${s}] \u7D22\u5F15 ${e} \u8D8A\u754C\uFF08patterns \u957F\u5EA6 ${n.patterns.length}\uFF09`)}),n.bpm!=null&&(typeof n.bpm!="number"||!(n.bpm>0))&&t.push("bpm \u5FC5\u987B\u662F\u6B63\u6570"),{ok:t.length===0,errors:t})}function me(n){return typeof n!="number"||Number.isNaN(n)||n<0?0:n>1?1:n}function Sl(n,t){switch(n){case"ease-in":return t*t;case"ease-out":return Math.sqrt(t);case"constant":return 1;default:return t}}function ga(n,t){let e=me(t);return n==null||!Array.isArray(n.voices)?[]:n.voices.map(s=>{let i=String(s&&s.id!=null?s.id:""),o=Array.isArray(s&&s.channelIndices)?s.channelIndices.slice():[],a=typeof s.minIntensity=="number"?me(s.minIntensity):0,r=typeof s.maxIntensity=="number"?me(s.maxIntensity):1,c=typeof s.volumeCurve=="string"?s.volumeCurve:"linear",l=typeof s.baseVolume=="number"?me(s.baseVolume):1;if(er)return{id:i,on:!1,volume:0,channelIndices:o};let u=r-a,h=u<=0?1:(e-a)/u,p=me(Sl(c,h)*l);return{id:i,on:!0,volume:p,channelIndices:o}})}function ya(n,t,e,s){try{let i=t[0]||[],o=t[1]||i,a=Math.max(i.length,o.length);if(a===0)return null;let c=n.createBuffer(2,a,44100);c.getChannelData(0).set(i),c.getChannelData(1).set(o.length?o:i);let l=n.createBufferSource();l.buffer=c,l.loop=!!s;let u=n.createGain();return u.gain.value=me(e*.3),l.connect(u),u.connect(n.destination),l.start(),{stop(){try{l.stop()}catch(h){}try{l.disconnect(),u.disconnect()}catch(h){}}}}catch(i){return io("[audio-music] \u53D7\u63A7\u97F3\u9891\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",i),null}}function ma(n){let t=n||{},e=typeof t.masterVolume=="number"?me(t.masterVolume):1,s=()=>null,i=null,o=null,a={voices:[]},r=1,c=null,l=!1,u=0,h=!1,p=!1;function d(){let S=s();return S==null?(u+=1,h||(no("[audio-music] \u65E0\u53D7\u63A7\u97F3\u9891\u4E0A\u4E0B\u6587\uFF08getAudioContext \u8FD4\u56DE null\uFF09\uFF0C\u5168\u90E8\u53D1\u58F0\u9759\u9ED8 no-op\uFF08\u8BC4\u4F30\u73AF\u5883\u65E0\u58F0\u5361\u65F6\u7684\u5BB9\u9519\u964D\u7EA7\uFF09"),h=!0),null):S}function y(){if(!o||!i)return null;try{let S=typeof o.bpm=="number"&&o.bpm>0?o.bpm:125;return i.synthSong(o.instruments,o.patterns,o.sequence,S)}catch(S){return io("[audio-music] \u66F2\u8C31\u6E32\u67D3\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",S),null}}function x(){let S=ga(a,r);if(S.length===0)return 1;let C=0;for(let A of S)A.on&&(C=Math.max(C,A.volume));return C}function v(S,C){typeof C=="number"&&(r=me(C));let A=d();if(A==null||!o)return;w();let T=y();if(!T)return;let P=me(e*x());c=ya(A,T,P,S),l=!!S&&c!=null}function w(){c&&(c.stop(),c=null),l=!1}return{name:"audio-music",version:"1.0.0",dependencies:[],init(S){s=()=>S.getAudioContext();let C=S.getEngine&&S.getEngine();i=C?C.audio.synth:null},dispose(){p||(w(),p=!0)},loadSong(S){let C=vl(S);return C.ok?o={instruments:S.instruments,patterns:S.patterns,sequence:S.sequence,bpm:typeof S.bpm=="number"?S.bpm:125}:no("[audio-music] \u66F2\u8C31\u6821\u9A8C\u5931\u8D25\uFF0C\u672A\u8F7D\u5165\uFF1A"+C.errors.join("\uFF1B")),C},play(S){v(!1,S)},stop(){w()},loop(S){v(!0,S)},setIntensityLayering(S){a=S&&Array.isArray(S.voices)?{voices:S.voices}:{voices:[]}},setIntensity(S){r=me(S)},resolveVoices(S){return ga(a,S)},playSfx(S){let C=so[S];if(!C){no("[audio-music] \u672A\u77E5\u97F3\u6548\u9884\u8BBE\uFF1A"+String(S));return}let A=d();if(A!=null)try{let T=i?i.synthSfx(C.params):null;if(!T)return;ya(A,[T,T],e,!1)}catch(T){io("[audio-music] \u97F3\u6548\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8 name="+S,T)}},getPreset(S){return so[S]},listPresets(){return pa.slice()},probe(){return{hasAudio:s()!=null,hasSong:o!=null,intensity:r,voiceCount:a.voices.length,looping:l,silentNoops:u,presetCount:pa.length}}}}function io(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function no(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var wl="zaomeng.save";function Tl(n){if(typeof TextEncoder!="undefined")return new TextEncoder().encode(n).length;if(typeof Buffer!="undefined"&&typeof Buffer.byteLength=="function")return Buffer.byteLength(n,"utf8");let t=0;for(let e=0;e=55296&&s<=56319?(t+=4,e++):t+=3}return t}function ro(){let n=new Map;return{getItem(t){return n.has(t)?n.get(t):null},setItem(t,e){n.set(t,e)},removeItem(t){n.delete(t)},keys(){return Array.from(n.keys())}}}function ba(){if(typeof localStorage=="undefined")throw new Error("[save-progress] createLocalStorageAdapter \u9700\u8981\u5168\u5C40 localStorage\uFF08\u4EC5\u6D4F\u89C8\u5668\u96C6\u6210\u6BB5\u53EF\u7528\uFF09\u3002node/host-dev \u8BF7\u7528\u7F3A\u7701\u5185\u5B58 adapter \u6216 createMemoryAdapter()\u3002");return{getItem(n){return localStorage.getItem(n)},setItem(n,t){localStorage.setItem(n,t)},removeItem(n){localStorage.removeItem(n)},keys(){let n=[];for(let t=0;t0?t.namespace:wl;if(e.indexOf(":")>=0)throw new Error('[save-progress] namespace \u4E0D\u5F97\u542B\u5206\u9694\u7B26 ":"\uFF08\u5F53\u524D="'+e+'"\uFF09');let s=typeof t.maxValueBytes=="number"&&t.maxValueBytes>0?Math.floor(t.maxValueBytes):32768,i=!Al(t.adapter),o=i?ro():t.adapter,a=e+":",r=0,c=0,l=!1;function u(d){return typeof d!="string"||d.length===0?a+String(d):a+d}function h(){try{let d=o.keys();return Array.isArray(d)?d.filter(y=>typeof y=="string"&&y.indexOf(a)===0):[]}catch(d){return ts("[save-progress] adapter.keys() \u5F02\u5E38\uFF0C\u964D\u7EA7\u8FD4\u56DE\u7A7A\u96C6",d),[]}}return{name:"save-progress",version:"1.0.0",dependencies:[],init(d){h()},dispose(){},get(d,y){if(!oo(d))return y;let x;try{x=o.getItem(u(d))}catch(v){return ts("[save-progress] adapter.getItem \u5F02\u5E38\uFF0C\u8FD4\u56DE\u9ED8\u8BA4\u503C key="+d,v),y}if(x==null)return y;try{return JSON.parse(x)}catch{return r+=1,l||(es("[save-progress] \u68C0\u6D4B\u5230\u635F\u574F\u5B58\u6863\uFF08\u975E\u6CD5 JSON\uFF09\uFF0C\u5DF2\u5BB9\u9519\u56DE\u9000\u9ED8\u8BA4\u503C key="+d),l=!0),y}},set(d,y){if(!oo(d))return es("[save-progress] set \u6536\u5230\u975E\u6CD5 key\uFF0C\u62D2\u7EDD\u5199\u5165\uFF1A"+String(d)),!1;let x;try{x=JSON.stringify(y)}catch{return c+=1,es("[save-progress] \u503C\u4E0D\u53EF JSON \u5E8F\u5217\u5316\uFF08\u5FAA\u73AF\u5F15\u7528?\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1}if(x===void 0)return c+=1,es("[save-progress] \u503C\u5E8F\u5217\u5316\u4E3A undefined\uFF08\u5982\u7EAF undefined/\u51FD\u6570\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1;let v=Tl(x);if(v>s)return c+=1,es("[save-progress] \u503C\u8D85\u5B57\u8282\u4E0A\u9650\u62D2\u7EDD\u5199\u5165 key="+d+"\uFF08"+v+" > "+s+" bytes\uFF09"),!1;try{return o.setItem(u(d),x),!0}catch(w){return c+=1,ts("[save-progress] adapter.setItem \u5F02\u5E38\uFF0C\u5199\u5165\u5931\u8D25 key="+d,w),!1}},remove(d){if(oo(d))try{o.removeItem(u(d))}catch(y){ts("[save-progress] adapter.removeItem \u5F02\u5E38\uFF08\u5DF2\u5FFD\u7565\uFF09key="+d,y)}},clear(){let d=h(),y=0;for(let x of d)try{o.removeItem(x),y+=1}catch(v){ts("[save-progress] clear \u65F6 removeItem \u5F02\u5E38\uFF08\u5DF2\u8DF3\u8FC7\uFF09fullKey="+x,v)}return y},probe(){return{namespace:e,maxValueBytes:s,usingMemoryAdapter:i,size:h().length,corruptRecoveries:r,rejectedWrites:c}}}}function oo(n){return typeof n=="string"&&n.length>0}function Al(n){return!!n&&typeof n.getItem=="function"&&typeof n.setItem=="function"&&typeof n.removeItem=="function"&&typeof n.keys=="function"}function ts(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function es(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var El={w:390,h:844};function va(n){let t=((n&&n.seed)!=null?n.seed:0)>>>0,e=sa({cellSize:96}),s=ia(),i=la({inputBufferMs:260,inputTypes:["pointerdown"]}),o=ua({seed:t,maxParticles:600}),a=fa({vignette:{enabled:!0,strength:.22}}),r=ma({masterVolume:.8}),c;try{c=ba()}catch(p){console.warn("[generic] localStorage \u4E0D\u53EF\u7528\uFF0C\u5B58\u6863\u9000\u5185\u5B58 adapter\uFF1A"+(p&&p.message)),c=ro()}let l=xa({namespace:"zaomeng-generic",adapter:c});return{plugins:{collision:e,physics:s,gamefeel:i,juice:o,palettePost:a,audioMusic:r,save:l},registerOrder:[e,s,i,o,a,l,r],viewport:El,buildFactoryOpts:(p,d)=>({runtime:{plugins:d.plugins,bundle:d.bundle,getRealAudioCtx:d.getRealAudioCtx}})}}function ns(n){let t=n||{},e=null,s=[],i="booting",o=null,a=0,r={x:0,y:0,vx:0,vy:0,angle:0,radius:15},c=[],l=[],u=0,h={},p=200,d=600,y=2e3,x=.99,v=15,w=30,_=15,S=40,C=80,A=5,T=200,P=3;function M(R){R.x<0?R.x+=390:R.x>390&&(R.x-=390),R.y<0?R.y+=844:R.y>844&&(R.y-=844)}function pt(R,F,k,j){let $=F.x-R.x,Z=F.y-R.y,Tt=R.x-k.x,At=R.y-k.y,Ot=$*$+Z*Z,Oe=2*(Tt*$+At*Z),Zn=Tt*Tt+At*At-j*j,dn=Oe*Oe-4*Ot*Zn;if(dn<0)return!1;dn=Math.sqrt(dn);let Fs=(-Oe-dn)/(2*Ot),Dn=(-Oe+dn)/(2*Ot);return Fs>=0&&Fs<=1||Dn>=0&&Dn<=1}function at(R,F,k,j){let $=R-k,Z=F-j;return Math.sqrt($*$+Z*Z)}function ct(R,F,k,j,$){return{x:R,y:F,vx:j,vy:$,radius:k,isBig:k>=w}}function yt(){c=[];let R=e.random;for(let F=0;F{Z.key&&(h[Z.key]=!0)});s.push(k);let j=F.on("keyup",Z=>{Z.key&&(h[Z.key]=!1)});s.push(j);let $=F.on("pointerdown",()=>{i==="gameover"&&Pe()});s.push($),Lt(),i="playing",o=null}function hn(R){if(i==="gameover")return;let F=e.time.nowMs();h.ArrowLeft&&(r.angle-=P*R),h.ArrowRight&&(r.angle+=P*R),h.ArrowUp&&(r.vx+=Math.cos(r.angle)*T*R,r.vy+=Math.sin(r.angle)*T*R,ge(r.x-Math.cos(r.angle)*20,r.y-Math.sin(r.angle)*20,{r:1,g:.8,b:.2,a:1},{r:1,g:.4,b:0,a:0},5)),h.Space&&ht(),r.vx*=x,r.vy*=x,r.x+=r.vx*R,r.y+=r.vy*R,M(r);for(let k of c)k.x+=k.vx*R,k.y+=k.vy*R,M(k);for(let k=l.length-1;k>=0;k--){let j=l[k],$=j.x,Z=j.y;if(j.x+=j.vx*R,j.y+=j.vy*R,F-j.born>y){l.splice(k,1);continue}if(j.x<0||j.x>390||j.y<0||j.y>844){l.splice(k,1);continue}let Tt=!1;for(let At=c.length-1;At>=0;At--){let Ot=c[At];if(pt({x:$,y:Z},{x:j.x,y:j.y},{x:Ot.x,y:Ot.y},Ot.radius)){Tt=!0,a+=1,ge(j.x,j.y,{r:1,g:.9,b:.5,a:1},{r:1,g:.3,b:0,a:0},30),Pt([1,.1,880,,,.2,,.4]),Ot.isBig&&Nt(Ot),c.splice(At,1);break}}Tt&&l.splice(k,1)}for(let k of c){let j=r.x-k.x,$=r.y-k.y;if(j*j+$*$<(r.radius+k.radius)*(r.radius+k.radius)){i="gameover",o="lose",ge(r.x,r.y,{r:1,g:.2,b:.2,a:1},{r:.5,g:0,b:0,a:0},40),Pt([1,.2,100,,,.5,,1.5]);return}}c.length===0&&(i="gameover",o="win")}function ae(R){R.fillStyle="#0a0a1a",R.fillRect(0,0,390,844);for(let F of c)R.fillStyle=F.isBig?"#8b5e3c":"#a0744a",R.beginPath(),R.arc(F.x,F.y,F.radius,0,Math.PI*2),R.fill(),R.strokeStyle="#d4a76a",R.lineWidth=2,R.stroke();for(let F of l)R.fillStyle="#ffff00",R.beginPath(),R.arc(F.x,F.y,F.radius,0,Math.PI*2),R.fill();R.save(),R.translate(r.x,r.y),R.rotate(r.angle),R.fillStyle=i==="gameover"?"#ff4444":"#44aaff",R.beginPath(),R.moveTo(20,0),R.lineTo(-15,-12),R.lineTo(-10,0),R.lineTo(-15,12),R.closePath(),R.fill(),R.strokeStyle="#ffffff",R.lineWidth=1.5,R.stroke(),R.restore(),R.fillStyle="#ffffff",R.font="bold 16px monospace",R.fillText("Score: "+a,10,30),R.fillText("Asteroids: "+c.length,10,50),R.fillText("Phase: "+i,10,70),i==="gameover"&&(R.fillStyle=o==="win"?"#00ff00":"#ff0000",R.font="bold 28px monospace",R.textAlign="center",R.fillText(o==="win"?"YOU WIN!":"GAME OVER",195,400),R.font="16px monospace",R.fillStyle="#ffffff",R.fillText("Tap to restart",195,430),R.textAlign="start")}function Le(){for(let R of s)try{R.cancel()}catch{}s=[],c=[],l=[],i="booting",o=null}function te(){return{seed:e&&e.random?e.random.seed:null,state:()=>({phase:i,result:o,score:a,asteroidsRemaining:c.length,ship:{x:r.x,y:r.y,angle:r.angle}})}}return{init:un,update:hn,render:ae,destroy:Le,_forensicsView:te}}var pd=ns,gd=ns;async function yd(n){let t=n||{},e=t.engine||await Promise.resolve().then(()=>(Mc(),Ic)),s=(t.seed!=null?t.seed:305441741)>>>0,i=va({seed:s});return na({canvas:t.canvas,statusEl:t.statusEl||null,engine:e,seed:s,mode:t.mode||"play",engineMode:"real",viewport:i.viewport,factory:ns,plugins:i.plugins,registerOrder:i.registerOrder,buildFactoryOpts:i.buildFactoryOpts,recHook:t.recHook||null,onReady:t.onReady||null})}return Nc(md);})();
diff --git a/game-runtime/games/_wg1-gen/asteroids/bundle.iife.js.meta.json b/game-runtime/games/_wg1-gen/asteroids/bundle.iife.js.meta.json
index edb5ff1b..54a7023c 100644
--- a/game-runtime/games/_wg1-gen/asteroids/bundle.iife.js.meta.json
+++ b/game-runtime/games/_wg1-gen/asteroids/bundle.iife.js.meta.json
@@ -1 +1 @@
-{"inputs":{"src/core/plugin.js":{"bytes":44317,"imports":[],"format":"esm"},"src/plugins/runtime-probe/impl.js":{"bytes":16639,"imports":[],"format":"esm"},"host-dev/engine-caps.js":{"bytes":13897,"imports":[],"format":"esm"},"host-dev/engine-math.js":{"bytes":6155,"imports":[],"format":"esm"},"src/host/boot-game-host.js":{"bytes":27676,"imports":[{"path":"src/core/plugin.js","kind":"import-statement","original":"../core/plugin.js"},{"path":"src/plugins/runtime-probe/impl.js","kind":"import-statement","original":"../plugins/runtime-probe/impl.js"},{"path":"host-dev/engine-caps.js","kind":"import-statement","original":"../../host-dev/engine-caps.js"},{"path":"host-dev/engine-math.js","kind":"import-statement","original":"../../host-dev/engine-math.js"}],"format":"esm"},"src/plugins/collision/impl.js":{"bytes":24812,"imports":[],"format":"esm"},"src/plugins/physics-lite/impl.js":{"bytes":14507,"imports":[],"format":"esm"},"src/plugins/gamefeel/impl.js":{"bytes":21715,"imports":[],"format":"esm"},"src/plugins/particles-juice/impl.js":{"bytes":31830,"imports":[],"format":"esm"},"src/plugins/palette-post/impl.js":{"bytes":20240,"imports":[],"format":"esm"},"src/plugins/audio-music/impl.js":{"bytes":24659,"imports":[],"format":"esm"},"src/plugins/save-progress/impl.js":{"bytes":14608,"imports":[],"format":"esm"},"src/host/generic-host-config.js":{"bytes":7803,"imports":[{"path":"src/plugins/collision/impl.js","kind":"import-statement","original":"../plugins/collision/impl.js"},{"path":"src/plugins/physics-lite/impl.js","kind":"import-statement","original":"../plugins/physics-lite/impl.js"},{"path":"src/plugins/gamefeel/impl.js","kind":"import-statement","original":"../plugins/gamefeel/impl.js"},{"path":"src/plugins/particles-juice/impl.js","kind":"import-statement","original":"../plugins/particles-juice/impl.js"},{"path":"src/plugins/palette-post/impl.js","kind":"import-statement","original":"../plugins/palette-post/impl.js"},{"path":"src/plugins/audio-music/impl.js","kind":"import-statement","original":"../plugins/audio-music/impl.js"},{"path":"src/plugins/save-progress/impl.js","kind":"import-statement","original":"../plugins/save-progress/impl.js"}],"format":"esm"},"games/_wg1-gen/asteroids/generated-factory.js":{"bytes":9418,"imports":[],"format":"esm"},"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytes":640153,"imports":[],"format":"esm"},"games/_wg1-gen/asteroids/entry-bundle.js":{"bytes":6230,"imports":[{"path":"src/host/boot-game-host.js","kind":"import-statement","original":"../../../src/host/boot-game-host.js"},{"path":"src/host/generic-host-config.js","kind":"import-statement","original":"../../../src/host/generic-host-config.js"},{"path":"games/_wg1-gen/asteroids/generated-factory.js","kind":"import-statement","original":"./generated-factory.js"},{"path":"node_modules/littlejsengine/dist/littlejs.esm.js","kind":"dynamic-import","original":"littlejsengine"}],"format":"esm"}},"outputs":{"games/_wg1-gen/asteroids/bundle.iife.js":{"imports":[],"exports":[],"entryPoint":"games/_wg1-gen/asteroids/entry-bundle.js","inputs":{"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytesInOutput":164254},"games/_wg1-gen/asteroids/entry-bundle.js":{"bytesInOutput":507},"src/core/plugin.js":{"bytesInOutput":8989},"src/plugins/runtime-probe/impl.js":{"bytesInOutput":2794},"host-dev/engine-caps.js":{"bytesInOutput":1597},"host-dev/engine-math.js":{"bytesInOutput":498},"src/host/boot-game-host.js":{"bytesInOutput":5358},"src/plugins/collision/impl.js":{"bytesInOutput":1605},"src/plugins/physics-lite/impl.js":{"bytesInOutput":115},"src/plugins/gamefeel/impl.js":{"bytesInOutput":2533},"src/plugins/particles-juice/impl.js":{"bytesInOutput":4166},"src/plugins/palette-post/impl.js":{"bytesInOutput":4216},"src/plugins/audio-music/impl.js":{"bytesInOutput":6001},"src/plugins/save-progress/impl.js":{"bytesInOutput":3933},"src/host/generic-host-config.js":{"bytesInOutput":697},"games/_wg1-gen/asteroids/generated-factory.js":{"bytesInOutput":4408}},"bytes":212242}}}
\ No newline at end of file
+{"inputs":{"src/core/plugin.js":{"bytes":44317,"imports":[],"format":"esm"},"src/plugins/runtime-probe/impl.js":{"bytes":16639,"imports":[],"format":"esm"},"host-dev/engine-caps.js":{"bytes":13897,"imports":[],"format":"esm"},"host-dev/engine-math.js":{"bytes":6155,"imports":[],"format":"esm"},"src/host/boot-game-host.js":{"bytes":28239,"imports":[{"path":"src/core/plugin.js","kind":"import-statement","original":"../core/plugin.js"},{"path":"src/plugins/runtime-probe/impl.js","kind":"import-statement","original":"../plugins/runtime-probe/impl.js"},{"path":"host-dev/engine-caps.js","kind":"import-statement","original":"../../host-dev/engine-caps.js"},{"path":"host-dev/engine-math.js","kind":"import-statement","original":"../../host-dev/engine-math.js"}],"format":"esm"},"src/plugins/collision/impl.js":{"bytes":24812,"imports":[],"format":"esm"},"src/plugins/physics-lite/impl.js":{"bytes":14507,"imports":[],"format":"esm"},"src/plugins/gamefeel/impl.js":{"bytes":21715,"imports":[],"format":"esm"},"src/plugins/particles-juice/impl.js":{"bytes":31830,"imports":[],"format":"esm"},"src/plugins/palette-post/impl.js":{"bytes":20240,"imports":[],"format":"esm"},"src/plugins/audio-music/impl.js":{"bytes":24659,"imports":[],"format":"esm"},"src/plugins/save-progress/impl.js":{"bytes":14608,"imports":[],"format":"esm"},"src/host/generic-host-config.js":{"bytes":7803,"imports":[{"path":"src/plugins/collision/impl.js","kind":"import-statement","original":"../plugins/collision/impl.js"},{"path":"src/plugins/physics-lite/impl.js","kind":"import-statement","original":"../plugins/physics-lite/impl.js"},{"path":"src/plugins/gamefeel/impl.js","kind":"import-statement","original":"../plugins/gamefeel/impl.js"},{"path":"src/plugins/particles-juice/impl.js","kind":"import-statement","original":"../plugins/particles-juice/impl.js"},{"path":"src/plugins/palette-post/impl.js","kind":"import-statement","original":"../plugins/palette-post/impl.js"},{"path":"src/plugins/audio-music/impl.js","kind":"import-statement","original":"../plugins/audio-music/impl.js"},{"path":"src/plugins/save-progress/impl.js","kind":"import-statement","original":"../plugins/save-progress/impl.js"}],"format":"esm"},"games/_wg1-gen/asteroids/generated-factory.js":{"bytes":9418,"imports":[],"format":"esm"},"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytes":640153,"imports":[],"format":"esm"},"games/_wg1-gen/asteroids/entry-bundle.js":{"bytes":6230,"imports":[{"path":"src/host/boot-game-host.js","kind":"import-statement","original":"../../../src/host/boot-game-host.js"},{"path":"src/host/generic-host-config.js","kind":"import-statement","original":"../../../src/host/generic-host-config.js"},{"path":"games/_wg1-gen/asteroids/generated-factory.js","kind":"import-statement","original":"./generated-factory.js"},{"path":"node_modules/littlejsengine/dist/littlejs.esm.js","kind":"dynamic-import","original":"littlejsengine"}],"format":"esm"}},"outputs":{"games/_wg1-gen/asteroids/bundle.iife.js":{"imports":[],"exports":[],"entryPoint":"games/_wg1-gen/asteroids/entry-bundle.js","inputs":{"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytesInOutput":164254},"games/_wg1-gen/asteroids/entry-bundle.js":{"bytesInOutput":507},"src/core/plugin.js":{"bytesInOutput":8989},"src/plugins/runtime-probe/impl.js":{"bytesInOutput":2794},"host-dev/engine-caps.js":{"bytesInOutput":1597},"host-dev/engine-math.js":{"bytesInOutput":498},"src/host/boot-game-host.js":{"bytesInOutput":5505},"src/plugins/collision/impl.js":{"bytesInOutput":1605},"src/plugins/physics-lite/impl.js":{"bytesInOutput":115},"src/plugins/gamefeel/impl.js":{"bytesInOutput":2533},"src/plugins/particles-juice/impl.js":{"bytesInOutput":4166},"src/plugins/palette-post/impl.js":{"bytesInOutput":4216},"src/plugins/audio-music/impl.js":{"bytesInOutput":6001},"src/plugins/save-progress/impl.js":{"bytesInOutput":3933},"src/host/generic-host-config.js":{"bytesInOutput":697},"games/_wg1-gen/asteroids/generated-factory.js":{"bytesInOutput":4408}},"bytes":212389}}}
\ No newline at end of file
diff --git a/game-runtime/games/_wg1-gen/asteroids/evidence/after-play.png b/game-runtime/games/_wg1-gen/asteroids/evidence/after-play.png
index 79d97bc3..d20f0470 100644
Binary files a/game-runtime/games/_wg1-gen/asteroids/evidence/after-play.png and b/game-runtime/games/_wg1-gen/asteroids/evidence/after-play.png differ
diff --git a/game-runtime/games/_wg1-gen/asteroids/evidence/first-paint.png b/game-runtime/games/_wg1-gen/asteroids/evidence/first-paint.png
index 2f201d91..524e598a 100644
Binary files a/game-runtime/games/_wg1-gen/asteroids/evidence/first-paint.png and b/game-runtime/games/_wg1-gen/asteroids/evidence/first-paint.png differ
diff --git a/game-runtime/games/_wg1-gen/asteroids/evidence/verdict.json b/game-runtime/games/_wg1-gen/asteroids/evidence/verdict.json
index 69f1aef4..c2fbe710 100644
--- a/game-runtime/games/_wg1-gen/asteroids/evidence/verdict.json
+++ b/game-runtime/games/_wg1-gen/asteroids/evidence/verdict.json
@@ -8,8 +8,8 @@
     },
     "C_frame": {
       "pass": true,
-      "f0": 49,
-      "f1": 79,
+      "f0": 48,
+      "f1": 78,
       "delta": 30
     },
     "I_control": {
@@ -18,22 +18,35 @@
     },
     "D_render": {
       "pass": true,
-      "bright": 66529,
+      "bright": 66491,
       "maxCh": 255
     },
     "E_live": {
       "pass": true,
-      "distinctStates": 52,
-      "samples": 52
+      "distinctStates": 37,
+      "samples": 37
     },
     "B_uncaught": {
       "pass": true,
       "uncaught": []
     },
     "F_wiring": {
-      "pass": false,
-      "callCount": 0,
-      "sample": [],
+      "pass": true,
+      "callCount": 27,
+      "sample": [
+        "particles.spawnEmitter",
+        "particles.spawnEmitter",
+        "particles.spawnEmitter",
+        "particles.spawnEmitter",
+        "particles.spawnEmitter",
+        "particles.spawnEmitter",
+        "particles.spawnEmitter",
+        "particles.spawnEmitter",
+        "particles.spawnEmitter",
+        "particles.spawnEmitter",
+        "particles.spawnEmitter",
+        "particles.spawnEmitter"
+      ],
       "expected": [
         "particles.",
         "audio.synth"
@@ -41,10 +54,10 @@
     },
     "G_input": {
       "pass": true,
-      "inputHash": "241aa975",
-      "controlHash": "7f223357",
-      "atFrame": 1241,
-      "ctrlFrame": 1244
+      "inputHash": "d2d3585d",
+      "controlHash": "f13eb61f",
+      "atFrame": 901,
+      "ctrlFrame": 905
     },
     "H_progress": {
       "pass": false,
@@ -59,9 +72,10 @@
         }
       ],
       "latch": {
-        "pass": false,
-        "reason": "真玩未到达 gameover 终态(终态不可达/无失败态/play-spec 未驱动到结束)",
-        "phaseNow": "playing"
+        "pass": true,
+        "dwelledMs": 600,
+        "after": "gameover",
+        "reason": ""
       },
       "state0": {
         "phase": "playing",
@@ -75,14 +89,14 @@
         }
       },
       "state1": {
-        "phase": "playing",
-        "result": null,
+        "phase": "gameover",
+        "result": "lose",
         "score": 0,
         "asteroidsRemaining": 5,
         "ship": {
-          "x": 195,
-          "y": 422,
-          "angle": -1.5707963267948966
+          "x": 152.8208837988882,
+          "y": 301.88159315392096,
+          "angle": -1.7707963267948967
         }
       }
     }
diff --git a/game-runtime/games/_wg1-gen/t2048/bundle.iife.js b/game-runtime/games/_wg1-gen/t2048/bundle.iife.js
index fc1e4a6b..67025bbf 100644
--- a/game-runtime/games/_wg1-gen/t2048/bundle.iife.js
+++ b/game-runtime/games/_wg1-gen/t2048/bundle.iife.js
@@ -1,34 +1,34 @@
-"use strict";var __GameBundle=(()=>{var Bi=Object.defineProperty;var kc=Object.getOwnPropertyDescriptor;var Gc=Object.getOwnPropertyNames;var Fc=Object.prototype.hasOwnProperty;var jc=(n,t,e)=>()=>{if(e)throw e[0];try{return n&&(t=n(n=0)),t}catch(s){throw e=[s],s}};var qr=(n,t)=>{for(var e in t)Bi(n,e,{get:t[e],enumerable:!0})},Bc=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Gc(t))!Fc.call(n,i)&&i!==e&&Bi(n,i,{get:()=>t[i],enumerable:!(s=kc(t,i))||s.enumerable});return n};var Nc=n=>Bc(Bi({},"__esModule",{value:!0}),n);var Dc={};qr(Dc,{ASSERT:()=>p,BLACK:()=>at,BLUE:()=>Qa,Box2dDistanceJoint:()=>vi,Box2dFrictionJoint:()=>Xo,Box2dGearJoint:()=>Vo,Box2dJoint:()=>Qt,Box2dKinematicObject:()=>jo,Box2dMotorJoint:()=>$o,Box2dObject:()=>Cs,Box2dPinJoint:()=>zo,Box2dPlugin:()=>Si,Box2dPrismaticJoint:()=>Wo,Box2dPulleyJoint:()=>Yo,Box2dRaycastResult:()=>xi,Box2dRevoluteJoint:()=>Uo,Box2dRopeJoint:()=>Jo,Box2dStaticObject:()=>bi,Box2dTargetJoint:()=>No,Box2dTileLayer:()=>Bo,Box2dWeldJoint:()=>Ho,Box2dWheelJoint:()=>qo,CLEAR_BLACK:()=>xe,CLEAR_WHITE:()=>ln,CYAN:()=>ql,CanvasLayer:()=>ai,Color:()=>Lt,Ease:()=>Ti,EngineObject:()=>qe,GRAY:()=>Vl,GREEN:()=>Ka,ImageFont:()=>ei,LOG:()=>Et,Light:()=>Po,LightSystemPlugin:()=>Ro,MAGENTA:()=>Hl,Medal:()=>yi,NewgroundsMedal:()=>Co,NewgroundsPlugin:()=>Eo,ORANGE:()=>Wl,PI:()=>Q,PURPLE:()=>Za,Particle:()=>ci,ParticleEmitter:()=>bo,PathFinder:()=>Ko,PathFinderNode:()=>Ai,PostProcessPlugin:()=>_o,RED:()=>ir,RandomGenerator:()=>fo,Sound:()=>ys,SoundInstance:()=>oi,TextureInfo:()=>He,TileCollisionLayer:()=>bs,TileInfo:()=>De,TileLayer:()=>ms,TileLayerData:()=>wn,Timer:()=>Pe,Tween:()=>wi,UIButton:()=>As,UICheckbox:()=>Io,UILayout:()=>Fo,UIObject:()=>he,UISlider:()=>ko,UISystemPlugin:()=>Oo,UIText:()=>mi,UITextInput:()=>Do,UITile:()=>Mo,UIVideo:()=>Go,Vector2:()=>lt,WHITE:()=>H,YELLOW:()=>$a,ZzFXMusic:()=>Lo,abs:()=>ot,atan2:()=>er,audioContext:()=>mt,audioDefaultSampleRate:()=>Kn,audioIsRunning:()=>gs,audioMasterGain:()=>We,box2d:()=>m,box2dDebug:()=>Vr,box2dInit:()=>ad,box2dSetDebug:()=>rd,cameraAngle:()=>et,cameraFit:()=>rh,cameraPos:()=>Mt,cameraScale:()=>K,canvasClearColor:()=>sn,canvasColorTiles:()=>Ei,canvasFixedSize:()=>kn,canvasMaxAspect:()=>In,canvasMaxSize:()=>Mn,canvasMinAspect:()=>ss,canvasPixelRatio:()=>on,canvasPixelated:()=>ar,ceil:()=>cs,clamp:()=>z,combineCanvases:()=>vr,cos:()=>ut,debug:()=>zt,debugCircle:()=>Ht,debugClear:()=>Il,debugLine:()=>Ee,debugOverlap:()=>uo,debugOverlay:()=>Fe,debugPoint:()=>tr,debugPointSize:()=>Ia,debugPoly:()=>Ml,debugRect:()=>Ct,debugScreenshot:()=>Ga,debugShowErrors:()=>kl,debugText:()=>Dn,debugVideoCaptureIsActive:()=>_e,debugVideoCaptureStart:()=>Fa,debugVideoCaptureStop:()=>ja,debugWatermark:()=>Ci,distanceAngle:()=>zl,distanceWrap:()=>nr,drawCanvas2D:()=>Rn,drawCircle:()=>ti,drawCircleGradient:()=>sh,drawContext:()=>Ot,drawCount:()=>Le,drawCrescent:()=>ud,drawEllipse:()=>sc,drawEllipseGradient:()=>ic,drawLine:()=>mn,drawLineList:()=>go,drawNineSlice:()=>Ec,drawNineSliceScreen:()=>cd,drawPoly:()=>Jn,drawRect:()=>Zs,drawRectGradient:()=>th,drawRegularPoly:()=>nc,drawText:()=>ih,drawTextScreen:()=>rn,drawTextureWrapped:()=>eh,drawThreeSlice:()=>_c,drawThreeSliceScreen:()=>ld,drawTile:()=>Ft,enablePhysicsSolver:()=>Li,engineAddPlugin:()=>En,engineImageFont:()=>cc,engineInit:()=>Pl,engineName:()=>Vs,engineObjects:()=>_t,engineObjectsCallback:()=>Ol,engineObjectsCollect:()=>Ma,engineObjectsCollide:()=>Zo,engineObjectsDestroy:()=>Ll,engineObjectsRaycast:()=>Dl,engineObjectsUpdate:()=>Da,engineVersion:()=>Ws,fetchJSON:()=>Xl,floor:()=>Pt,fontDefault:()=>Es,formatTime:()=>or,frame:()=>La,frameRate:()=>El,gamepadConnected:()=>mo,gamepadDirectionEmulateStick:()=>pr,gamepadDpad:()=>yo,gamepadIsDown:()=>Ge,gamepadPrimary:()=>At,gamepadStick:()=>fs,gamepadStickCount:()=>lc,gamepadVibrate:()=>Sh,gamepadVibrateStop:()=>wh,gamepadWasPressed:()=>Er,gamepadWasReleased:()=>vh,gamepadsEnable:()=>Oi,getCameraSize:()=>rc,getCrescentPoints:()=>Rc,getNoteFrequency:()=>pc,getPaused:()=>_l,glAntialias:()=>Dr,glCanvas:()=>it,glCircleSides:()=>_s,glClearCanvas:()=>xc,glClearRect:()=>Ac,glCompileShader:()=>Ao,glContext:()=>g,glCopyToContext:()=>Fr,glCreateProgram:()=>Hn,glCreateTexture:()=>ki,glDeleteTexture:()=>Sc,glDraw:()=>Ss,glDrawColoredPoints:()=>Nr,glDrawOutlineTransform:()=>Br,glDrawPoints:()=>Tc,glDrawPointsTransform:()=>jr,glDrawUntextured:()=>wc,glEnable:()=>j,glFlush:()=>It,glSetAntialias:()=>Yh,glSetRenderTarget:()=>ns,glSetTexture:()=>kr,glSetTextureData:()=>Gr,glSetTextureWrap:()=>vc,gravity:()=>Xt,headlessMode:()=>U,hsl:()=>Be,hypot:()=>Ba,inputClear:()=>Ms,inputClearKey:()=>Ar,inputMouseMoveThreshold:()=>Tr,inputPreventDefault:()=>Gn,inputWASDEmulateDirection:()=>is,isArray:()=>me,isColor:()=>W,isFullscreen:()=>ac,isIntersecting:()=>Ua,isNumber:()=>R,isOnScreen:()=>ah,isOverlapping:()=>Ys,isPowerOfTwo:()=>ls,isStringLike:()=>q,isTouchDevice:()=>le,isUsingGamepad:()=>jn,isVector2:()=>O,keyDirection:()=>bh,keyIsDown:()=>Gt,keyWasPressed:()=>Bt,keyWasReleased:()=>Cr,lastInputDevice:()=>en,lerp:()=>Yt,lerpAngle:()=>Jl,lerpWrap:()=>Ja,lightSystem:()=>$,lineTest:()=>Wa,log2:()=>Na,mainCanvas:()=>N,mainCanvasSize:()=>k,mainContext:()=>pt,max:()=>tt,medalDisplaySize:()=>pi,medalDisplaySlideTime:()=>Fn,medalDisplayTime:()=>fi,medals:()=>ws,medalsForEach:()=>Gi,medalsInit:()=>Zh,medalsPreventUnlock:()=>zr,medalsReset:()=>td,min:()=>st,mod:()=>ce,mouseDelta:()=>Sr,mouseDeltaScreen:()=>Te,mouseInWindow:()=>ni,mouseIsDown:()=>rs,mousePos:()=>ke,mousePosScreen:()=>qt,mouseWasPressed:()=>ds,mouseWasReleased:()=>xh,mouseWheel:()=>wr,nearestPowerOfTwo:()=>Ul,newgrounds:()=>Ts,noise1D:()=>Zl,noise2D:()=>tu,objectDefaultAngleDamping:()=>hr,objectDefaultDamping:()=>ur,objectDefaultFriction:()=>fr,objectDefaultMass:()=>lr,objectDefaultRestitution:()=>dr,objectMaxSpeed:()=>Ne,oscillate:()=>Va,particleEmitRateScale:()=>$s,paused:()=>Re,percent:()=>Jt,percentLerp:()=>Nl,playSamples:()=>Or,pointerLockExit:()=>Ch,pointerLockIsActive:()=>uc,pointerLockRequest:()=>Ah,postProcess:()=>jt,primitiveCount:()=>Oe,rand:()=>yt,randBool:()=>qa,randColor:()=>ho,randInCircle:()=>Ya,randInt:()=>sr,randSign:()=>Ha,randVec2:()=>Xa,readSaveData:()=>Kl,rgb:()=>V,round:()=>Hs,saveCanvas:()=>tc,saveDataURL:()=>us,saveText:()=>Yl,screenToWorld:()=>Os,screenToWorldDelta:()=>oc,screenToWorldTransform:()=>Ds,setAdditiveBlendMode:()=>hs,setCameraAngle:()=>nu,setCameraPos:()=>eu,setCameraScale:()=>su,setCanvasClearColor:()=>ru,setCanvasColorTiles:()=>ou,setCanvasFixedSize:()=>uu,setCanvasMaxAspect:()=>lu,setCanvasMaxSize:()=>au,setCanvasMinAspect:()=>cu,setCanvasPixelRatio:()=>du,setCanvasPixelated:()=>ec,setCursor:()=>hh,setDebugKey:()=>Zu,setDebugWatermark:()=>Qu,setEnablePhysicsSolver:()=>Su,setFontDefault:()=>fu,setGLCircleSides:()=>mu,setGLEnable:()=>yu,setGamepadDirectionEmulateStick:()=>Ou,setGamepadsEnable:()=>Lu,setGravity:()=>Ru,setHeadlessMode:()=>gu,setInputMouseMoveThreshold:()=>ph,setInputPreventDefault:()=>fh,setInputWASDEmulateDirection:()=>Du,setMedalDisplaySize:()=>sd,setMedalDisplaySlideTime:()=>nd,setMedalDisplayTime:()=>ed,setMedalsPreventUnlock:()=>id,setObjectDefaultAngleDamping:()=>Au,setObjectDefaultDamping:()=>Tu,setObjectDefaultFriction:()=>Eu,setObjectDefaultMass:()=>wu,setObjectDefaultRestitution:()=>Cu,setObjectMaxSpeed:()=>_u,setParticleEmitRateScale:()=>Pu,setPaused:()=>Rl,setShowSplashScreen:()=>pu,setSoundDefaultRange:()=>$u,setSoundDefaultTaper:()=>Ku,setSoundEnable:()=>Xu,setSoundVolume:()=>Yu,setTileDefaultBleed:()=>vu,setTileDefaultPadding:()=>xu,setTileDefaultSize:()=>bu,setTilesPixelated:()=>hu,setTimeScale:()=>iu,setTouchGamepadAlpha:()=>Vu,setTouchGamepadAnalog:()=>zu,setTouchGamepadButtonCount:()=>Fu,setTouchGamepadCenterButtonSize:()=>Gu,setTouchGamepadDisplayTime:()=>Wu,setTouchGamepadEnable:()=>Iu,setTouchGamepadFloating:()=>Ju,setTouchGamepadLeftButtonCount:()=>Bu,setTouchGamepadLeftStick:()=>ju,setTouchGamepadPassthrough:()=>ku,setTouchGamepadRightStick:()=>Nu,setTouchGamepadSize:()=>Uu,setTouchGamepadVibration:()=>qu,setTouchInputEnable:()=>Mu,setVibrateEnable:()=>Hu,shareURL:()=>$l,showSplashScreen:()=>cr,sign:()=>ae,sin:()=>rt,smoothStep:()=>Xs,soundDefaultRange:()=>mr,soundDefaultTaper:()=>br,soundEnable:()=>Kt,soundVolume:()=>Sn,speak:()=>Nh,speakStop:()=>zh,tan:()=>za,textureInfos:()=>hn,tile:()=>Ls,tileCollisionGetData:()=>ri,tileCollisionLayers:()=>an,tileCollisionRaycast:()=>gc,tileCollisionTest:()=>Ze,tileDefaultBleed:()=>Pi,tileDefaultPadding:()=>Ri,tileDefaultSize:()=>_i,tileLayersLoad:()=>Uh,tilesPixelated:()=>Tn,time:()=>ee,timeDelta:()=>Qo,timeReal:()=>cn,timeScale:()=>rr,toggleFullscreen:()=>uh,touchGamepadAlpha:()=>yr,touchGamepadAnalog:()=>Rs,touchGamepadButtonCount:()=>Xn,touchGamepadCenterButtonSize:()=>be,touchGamepadDisplayTime:()=>os,touchGamepadEnable:()=>un,touchGamepadFloating:()=>dn,touchGamepadLeftButtonCount:()=>Yn,touchGamepadLeftStick:()=>_n,touchGamepadPassthrough:()=>gr,touchGamepadRightStick:()=>$n,touchGamepadSize:()=>$t,touchGamepadVibration:()=>Ks,touchInputEnable:()=>yn,tweenProperty:()=>hd,tweenStopAll:()=>dd,tweenUpdate:()=>Oc,uiDebug:()=>Ur,uiSetDebug:()=>od,uiSystem:()=>C,usingGamepadInput:()=>mh,usingKeyboardInput:()=>yh,usingMouseInput:()=>gh,vec2:()=>b,vibrate:()=>_r,vibrateEnable:()=>Ps,vibrateStop:()=>Th,workCanvas:()=>Ue,workContext:()=>tn,workReadCanvas:()=>Ce,workReadContext:()=>ze,worldToScreen:()=>Pn,worldToScreenDelta:()=>oh,writeSaveData:()=>Ql,zzfx:()=>Jh,zzfxG:()=>Mi,zzfxM:()=>Cc});function _l(){return Re}function Rl(n=!0){Re=n}function En(n,t,e,s){p(!bn.find(o=>o.update===n&&o.render===t&&o.glContextLost===e&&o.glContextRestored===s));let i=new co(n,t,e,s);bn.push(i)}async function Pl(n,t,e,s,i,o=[],a){if(Oa&&console.log(`${Vs} Engine v${Ws}`),p(!pt,"engine already initialized"),pt)return;p(me(o),"pass in images as array"),document.body||document.documentElement.appendChild(document.createElement("body")),a||(a=document.body),n||(n=()=>{}),t||(t=()=>{}),e||(e=()=>{}),s||(s=()=>{}),i||(i=()=>{});function r(){k=b(N.width,N.height),pt.imageSmoothingEnabled=!Tn,To()}function c(y=0){let x=y-oo;oo||(x=0),oo=y,(zt||Ci)&&(qs=Yt(qs,1e3/(x||1),.05));let v=zt&&Gt("Equal"),w=zt&&Gt("Minus"),_=v?10:w?.1:1;cn+=x*_/1e3;let S=rr*_;x*=S,we+=Re?0:x,S<=1&&(we=st(we,50));let E=!1;if(Re){E=!0,l(),Aa(),bn.forEach(T=>{var P;return(P=T.update)==null?void 0:P.call(T)});for(let T of _t)T.parent||T.updateTransforms();va(),e(),Ca(),_e()&&A()}else{let T=0;for(we<0&&we>-9&&(T=we,we=0);we>=0;we-=1e3/60)ee=La++/60,E=!0,l(),Aa(),t(),bn.forEach(P=>{var F;return(F=P.update)==null?void 0:F.call(P)}),Da(),va(),e(),Ca(),_e()&&A();we+=T}_e()||A(),requestAnimationFrame(c);function A(){if(!U){E||l(),r(),s(),_t.sort((T,P)=>T.renderOrder-P.renderOrder);for(let T of _t)T.destroyed||T.render();i(),bn.forEach(T=>{var P;return(P=T.render)==null?void 0:P.call(T)}),_h(),Fl(),It(),jl(),Le=0,Oe=0}}}function l(){if(!U){if(kn.x){k=kn.copy();let y=innerWidth/innerHeight,x=kn.x/kn.y,v=yIn){let E=k.y*In|0;k.x=st(E,Mn.x)}else if(w0&&!j&&(pt.fillStyle=sn.toString(),pt.fillRect(0,0,k.x,k.y),pt.fillStyle=at.toString()),pt.lineJoin="round",pt.lineCap="round"}}if(U)return d();qh(a);let u="margin:0;overflow:hidden;background:#000;user-select:none;-webkit-user-select:none;touch-action:none;-webkit-touch-callout:none";a.style.cssText=u,N=a.appendChild(document.createElement("canvas")),Ot=pt=N.getContext("2d"),Eh(),Bh(),Gl();let h="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)";N.style.cssText=h,it&&(it.style.cssText=h),ec(ar),l(),To(),Ue=new OffscreenCanvas(64,64),tn=Ue.getContext("2d"),Ce=new OffscreenCanvas(64,64),ze=Ce.getContext("2d",{willReadFrequently:!0});let f=o.map((y,x)=>wa(x,y));return o.length||f.push(wa(0)),f.push(dh()),cr&&f.push(new Promise(y=>{let x=0;v();function v(){Ms(),Qh(x+=.01),x>1?y():setTimeout(v,16)}})),await Promise.all(f),d();async function d(){await n(),c()}}function Da(){Zo=_t.filter(t=>t.collideSolidObjects);function n(t){if(!t.destroyed){t.update();for(let e of t.children)n(e)}}for(let t of _t)if(!(t.parent||t.destroyed)){t.update(),t.updatePhysics();for(let e of t.children)n(e);t.updateTransforms()}_t=_t.filter(t=>!t.destroyed)}function Ll(n=!0){for(let t of _t)t.parent||t.destroy(n);_t=_t.filter(t=>!t.destroyed)}function Ma(n,t,e=_t){let s=[];if(n)if(t instanceof lt)for(let i of e)i.isOverlapping(n,t)&&s.push(i);else{let i=t*t;for(let o of e)n.distanceSquared(o.pos)e(i))}function Dl(n,t,e=_t){let s=[];for(let i of e)i.collideRaycast&&Ua(n,t,i.pos,i.size)&&(ye&&Ct(i.pos,i.size,"#f00"),s.push(i));return ye&&Ee(n,t,s.length?"#f00":"#00f",.02),s}function p(n,...t){if(!n)throw console.assert(n,...t),new Error("Assert failed!")}function Et(...n){console.log(...n)}function Ct(n,t=b(),e=H,s=0,i=0,o=!1,a=!1){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(q(e)||W(e),"color is invalid"),p(R(s),"time must be a number"),p(R(i),"angle must be a number"),W(e)&&(e=e.toString());let r=new Pe(s);nn.push({pos:n.copy(),size:t.copy(),color:e,timer:r,angle:i,fill:o,screenSpace:a})}function Ml(n,t,e=H,s=0,i=0,o=!1,a=!1){p(O(n),"pos must be a vec2"),p(me(t),"points must be an array"),p(q(e)||W(e),"color is invalid"),p(R(s),"time must be a number"),p(R(i),"angle must be a number"),W(e)&&(e=e.toString()),n=n.copy(),t=t.map(c=>c.copy());let r=new Pe(s);nn.push({pos:n,points:t,color:e,timer:r,angle:i,fill:o,screenSpace:a})}function Ht(n,t=0,e=H,s=0,i=!1,o=!1){p(O(n),"pos must be a vec2"),p(R(t),"size must be a number"),p(q(e)||W(e),"color is invalid"),p(R(s),"time must be a number"),W(e)&&(e=e.toString()),n=n.copy();let a=new Pe(s);nn.push({pos:n,size:t,color:e,timer:a,angle:0,fill:i,screenSpace:o})}function tr(n,t,e,s,i=!1){Ct(n,void 0,t,e,s,!1,i)}function Ee(n,t,e,s=.1,i=0,o=!1){p(O(n),"posA must be a vec2"),p(O(t),"posB must be a vec2"),p(R(s),"width must be a number");let a=b((t.x-n.x)/2,(t.y-n.y)/2),r=b(s,a.length()*2);Ct(n.add(a),r,e,i,a.angle(),!0,o)}function uo(n,t,e,s,i,o,a=!1){p(O(n),"posA must be a vec2"),p(O(e),"posB must be a vec2"),p(O(t),"sizeA must be a vec2"),p(O(s),"sizeB must be a vec2");let r=b(st(n.x-t.x/2,e.x-s.x/2),st(n.y-t.y/2,e.y-s.y/2)),c=b(tt(n.x+t.x/2,e.x+s.x/2),tt(n.y+t.y/2,e.y+s.y/2));Ct(r.lerp(c,.5),c.subtract(r),i,o,0,!1,a)}function Dn(n,t,e=1,s=H,i=0,o=0,a="monospace",r=!1){p(q(n),"text must be a string"),p(O(t),"pos must be a vec2"),p(R(e),"size must be a number"),p(q(s)||W(s),"color is invalid"),p(R(i),"time must be a number"),p(R(o),"angle must be a number"),p(q(a),"font must be a string"),W(s)&&(s=s.toString()),t=t.copy();let c=new Pe(i);nn.push({text:n,pos:t,size:e,color:s,timer:c,angle:o,font:a,screenSpace:r})}function Il(){nn=[]}function Ga(){lo=1}function kl(){let n=e=>{document.body.style="background-color:#111;margin:8px",document.body.innerHTML="
"+e},t=console.assert;console.assert=(e,...s)=>{if(t(e,...s),!e){let i=s.join(" "),o=new Error().stack;throw`Assertion failed!
+"use strict";var __GameBundle=(()=>{var Bi=Object.defineProperty;var kc=Object.getOwnPropertyDescriptor;var Gc=Object.getOwnPropertyNames;var Fc=Object.prototype.hasOwnProperty;var jc=(n,t,e)=>()=>{if(e)throw e[0];try{return n&&(t=n(n=0)),t}catch(s){throw e=[s],s}};var qr=(n,t)=>{for(var e in t)Bi(n,e,{get:t[e],enumerable:!0})},Bc=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Gc(t))!Fc.call(n,i)&&i!==e&&Bi(n,i,{get:()=>t[i],enumerable:!(s=kc(t,i))||s.enumerable});return n};var Nc=n=>Bc(Bi({},"__esModule",{value:!0}),n);var Dc={};qr(Dc,{ASSERT:()=>p,BLACK:()=>at,BLUE:()=>Qa,Box2dDistanceJoint:()=>vi,Box2dFrictionJoint:()=>Xo,Box2dGearJoint:()=>Vo,Box2dJoint:()=>Zt,Box2dKinematicObject:()=>jo,Box2dMotorJoint:()=>$o,Box2dObject:()=>Cs,Box2dPinJoint:()=>zo,Box2dPlugin:()=>Si,Box2dPrismaticJoint:()=>Wo,Box2dPulleyJoint:()=>Yo,Box2dRaycastResult:()=>xi,Box2dRevoluteJoint:()=>Uo,Box2dRopeJoint:()=>Jo,Box2dStaticObject:()=>bi,Box2dTargetJoint:()=>No,Box2dTileLayer:()=>Bo,Box2dWeldJoint:()=>Ho,Box2dWheelJoint:()=>qo,CLEAR_BLACK:()=>xe,CLEAR_WHITE:()=>ln,CYAN:()=>ql,CanvasLayer:()=>ai,Color:()=>Lt,Ease:()=>Ti,EngineObject:()=>qe,GRAY:()=>Vl,GREEN:()=>Ka,ImageFont:()=>ei,LOG:()=>Et,Light:()=>Po,LightSystemPlugin:()=>Ro,MAGENTA:()=>Hl,Medal:()=>yi,NewgroundsMedal:()=>Co,NewgroundsPlugin:()=>Eo,ORANGE:()=>Wl,PI:()=>Q,PURPLE:()=>Za,Particle:()=>ci,ParticleEmitter:()=>bo,PathFinder:()=>Ko,PathFinderNode:()=>Ai,PostProcessPlugin:()=>_o,RED:()=>ir,RandomGenerator:()=>fo,Sound:()=>ys,SoundInstance:()=>oi,TextureInfo:()=>He,TileCollisionLayer:()=>bs,TileInfo:()=>De,TileLayer:()=>ms,TileLayerData:()=>wn,Timer:()=>Pe,Tween:()=>wi,UIButton:()=>As,UICheckbox:()=>Io,UILayout:()=>Fo,UIObject:()=>he,UISlider:()=>ko,UISystemPlugin:()=>Oo,UIText:()=>mi,UITextInput:()=>Do,UITile:()=>Mo,UIVideo:()=>Go,Vector2:()=>ut,WHITE:()=>H,YELLOW:()=>$a,ZzFXMusic:()=>Lo,abs:()=>ot,atan2:()=>er,audioContext:()=>mt,audioDefaultSampleRate:()=>Kn,audioIsRunning:()=>gs,audioMasterGain:()=>We,box2d:()=>m,box2dDebug:()=>Vr,box2dInit:()=>ad,box2dSetDebug:()=>rd,cameraAngle:()=>nt,cameraFit:()=>rh,cameraPos:()=>Mt,cameraScale:()=>K,canvasClearColor:()=>sn,canvasColorTiles:()=>Ei,canvasFixedSize:()=>kn,canvasMaxAspect:()=>In,canvasMaxSize:()=>Mn,canvasMinAspect:()=>ss,canvasPixelRatio:()=>on,canvasPixelated:()=>ar,ceil:()=>cs,clamp:()=>z,combineCanvases:()=>vr,cos:()=>ht,debug:()=>Jt,debugCircle:()=>Xt,debugClear:()=>Il,debugLine:()=>Ee,debugOverlap:()=>uo,debugOverlay:()=>Fe,debugPoint:()=>tr,debugPointSize:()=>Ia,debugPoly:()=>Ml,debugRect:()=>Ct,debugScreenshot:()=>Ga,debugShowErrors:()=>kl,debugText:()=>Dn,debugVideoCaptureIsActive:()=>_e,debugVideoCaptureStart:()=>Fa,debugVideoCaptureStop:()=>ja,debugWatermark:()=>Ci,distanceAngle:()=>zl,distanceWrap:()=>nr,drawCanvas2D:()=>Rn,drawCircle:()=>ti,drawCircleGradient:()=>sh,drawContext:()=>Ot,drawCount:()=>Le,drawCrescent:()=>ud,drawEllipse:()=>sc,drawEllipseGradient:()=>ic,drawLine:()=>mn,drawLineList:()=>go,drawNineSlice:()=>Ec,drawNineSliceScreen:()=>cd,drawPoly:()=>Jn,drawRect:()=>Zs,drawRectGradient:()=>th,drawRegularPoly:()=>nc,drawText:()=>ih,drawTextScreen:()=>rn,drawTextureWrapped:()=>eh,drawThreeSlice:()=>_c,drawThreeSliceScreen:()=>ld,drawTile:()=>jt,enablePhysicsSolver:()=>Li,engineAddPlugin:()=>En,engineImageFont:()=>cc,engineInit:()=>Pl,engineName:()=>Vs,engineObjects:()=>_t,engineObjectsCallback:()=>Ol,engineObjectsCollect:()=>Ma,engineObjectsCollide:()=>Zo,engineObjectsDestroy:()=>Ll,engineObjectsRaycast:()=>Dl,engineObjectsUpdate:()=>Da,engineVersion:()=>Ws,fetchJSON:()=>Xl,floor:()=>Pt,fontDefault:()=>Es,formatTime:()=>or,frame:()=>La,frameRate:()=>El,gamepadConnected:()=>mo,gamepadDirectionEmulateStick:()=>pr,gamepadDpad:()=>yo,gamepadIsDown:()=>Ge,gamepadPrimary:()=>At,gamepadStick:()=>fs,gamepadStickCount:()=>lc,gamepadVibrate:()=>Sh,gamepadVibrateStop:()=>wh,gamepadWasPressed:()=>Er,gamepadWasReleased:()=>vh,gamepadsEnable:()=>Oi,getCameraSize:()=>rc,getCrescentPoints:()=>Rc,getNoteFrequency:()=>pc,getPaused:()=>_l,glAntialias:()=>Dr,glCanvas:()=>it,glCircleSides:()=>_s,glClearCanvas:()=>xc,glClearRect:()=>Ac,glCompileShader:()=>Ao,glContext:()=>g,glCopyToContext:()=>Fr,glCreateProgram:()=>Hn,glCreateTexture:()=>ki,glDeleteTexture:()=>Sc,glDraw:()=>Ss,glDrawColoredPoints:()=>Nr,glDrawOutlineTransform:()=>Br,glDrawPoints:()=>Tc,glDrawPointsTransform:()=>jr,glDrawUntextured:()=>wc,glEnable:()=>j,glFlush:()=>It,glSetAntialias:()=>Yh,glSetRenderTarget:()=>ns,glSetTexture:()=>kr,glSetTextureData:()=>Gr,glSetTextureWrap:()=>vc,gravity:()=>Yt,headlessMode:()=>U,hsl:()=>Be,hypot:()=>Ba,inputClear:()=>Ms,inputClearKey:()=>Ar,inputMouseMoveThreshold:()=>Tr,inputPreventDefault:()=>Gn,inputWASDEmulateDirection:()=>is,isArray:()=>me,isColor:()=>W,isFullscreen:()=>ac,isIntersecting:()=>Ua,isNumber:()=>R,isOnScreen:()=>ah,isOverlapping:()=>Ys,isPowerOfTwo:()=>ls,isStringLike:()=>q,isTouchDevice:()=>le,isUsingGamepad:()=>jn,isVector2:()=>O,keyDirection:()=>bh,keyIsDown:()=>Ft,keyWasPressed:()=>Nt,keyWasReleased:()=>Cr,lastInputDevice:()=>en,lerp:()=>$t,lerpAngle:()=>Jl,lerpWrap:()=>Ja,lightSystem:()=>$,lineTest:()=>Wa,log2:()=>Na,mainCanvas:()=>N,mainCanvasSize:()=>k,mainContext:()=>pt,max:()=>tt,medalDisplaySize:()=>pi,medalDisplaySlideTime:()=>Fn,medalDisplayTime:()=>fi,medals:()=>ws,medalsForEach:()=>Gi,medalsInit:()=>Zh,medalsPreventUnlock:()=>zr,medalsReset:()=>td,min:()=>st,mod:()=>ce,mouseDelta:()=>Sr,mouseDeltaScreen:()=>Te,mouseInWindow:()=>ni,mouseIsDown:()=>rs,mousePos:()=>ke,mousePosScreen:()=>Ht,mouseWasPressed:()=>ds,mouseWasReleased:()=>xh,mouseWheel:()=>wr,nearestPowerOfTwo:()=>Ul,newgrounds:()=>Ts,noise1D:()=>Zl,noise2D:()=>tu,objectDefaultAngleDamping:()=>hr,objectDefaultDamping:()=>ur,objectDefaultFriction:()=>fr,objectDefaultMass:()=>lr,objectDefaultRestitution:()=>dr,objectMaxSpeed:()=>Ne,oscillate:()=>Va,particleEmitRateScale:()=>$s,paused:()=>Re,percent:()=>Ut,percentLerp:()=>Nl,playSamples:()=>Or,pointerLockExit:()=>Ch,pointerLockIsActive:()=>uc,pointerLockRequest:()=>Ah,postProcess:()=>Bt,primitiveCount:()=>Oe,rand:()=>yt,randBool:()=>qa,randColor:()=>ho,randInCircle:()=>Ya,randInt:()=>sr,randSign:()=>Ha,randVec2:()=>Xa,readSaveData:()=>Kl,rgb:()=>V,round:()=>Hs,saveCanvas:()=>tc,saveDataURL:()=>us,saveText:()=>Yl,screenToWorld:()=>Os,screenToWorldDelta:()=>oc,screenToWorldTransform:()=>Ds,setAdditiveBlendMode:()=>hs,setCameraAngle:()=>nu,setCameraPos:()=>eu,setCameraScale:()=>su,setCanvasClearColor:()=>ru,setCanvasColorTiles:()=>ou,setCanvasFixedSize:()=>uu,setCanvasMaxAspect:()=>lu,setCanvasMaxSize:()=>au,setCanvasMinAspect:()=>cu,setCanvasPixelRatio:()=>du,setCanvasPixelated:()=>ec,setCursor:()=>hh,setDebugKey:()=>Zu,setDebugWatermark:()=>Qu,setEnablePhysicsSolver:()=>Su,setFontDefault:()=>fu,setGLCircleSides:()=>mu,setGLEnable:()=>yu,setGamepadDirectionEmulateStick:()=>Ou,setGamepadsEnable:()=>Lu,setGravity:()=>Ru,setHeadlessMode:()=>gu,setInputMouseMoveThreshold:()=>ph,setInputPreventDefault:()=>fh,setInputWASDEmulateDirection:()=>Du,setMedalDisplaySize:()=>sd,setMedalDisplaySlideTime:()=>nd,setMedalDisplayTime:()=>ed,setMedalsPreventUnlock:()=>id,setObjectDefaultAngleDamping:()=>Au,setObjectDefaultDamping:()=>Tu,setObjectDefaultFriction:()=>Eu,setObjectDefaultMass:()=>wu,setObjectDefaultRestitution:()=>Cu,setObjectMaxSpeed:()=>_u,setParticleEmitRateScale:()=>Pu,setPaused:()=>Rl,setShowSplashScreen:()=>pu,setSoundDefaultRange:()=>$u,setSoundDefaultTaper:()=>Ku,setSoundEnable:()=>Xu,setSoundVolume:()=>Yu,setTileDefaultBleed:()=>vu,setTileDefaultPadding:()=>xu,setTileDefaultSize:()=>bu,setTilesPixelated:()=>hu,setTimeScale:()=>iu,setTouchGamepadAlpha:()=>Vu,setTouchGamepadAnalog:()=>zu,setTouchGamepadButtonCount:()=>Fu,setTouchGamepadCenterButtonSize:()=>Gu,setTouchGamepadDisplayTime:()=>Wu,setTouchGamepadEnable:()=>Iu,setTouchGamepadFloating:()=>Ju,setTouchGamepadLeftButtonCount:()=>Bu,setTouchGamepadLeftStick:()=>ju,setTouchGamepadPassthrough:()=>ku,setTouchGamepadRightStick:()=>Nu,setTouchGamepadSize:()=>Uu,setTouchGamepadVibration:()=>qu,setTouchInputEnable:()=>Mu,setVibrateEnable:()=>Hu,shareURL:()=>$l,showSplashScreen:()=>cr,sign:()=>ae,sin:()=>rt,smoothStep:()=>Xs,soundDefaultRange:()=>mr,soundDefaultTaper:()=>br,soundEnable:()=>Qt,soundVolume:()=>Sn,speak:()=>Nh,speakStop:()=>zh,tan:()=>za,textureInfos:()=>hn,tile:()=>Ls,tileCollisionGetData:()=>ri,tileCollisionLayers:()=>an,tileCollisionRaycast:()=>gc,tileCollisionTest:()=>Ze,tileDefaultBleed:()=>Pi,tileDefaultPadding:()=>Ri,tileDefaultSize:()=>_i,tileLayersLoad:()=>Uh,tilesPixelated:()=>Tn,time:()=>ne,timeDelta:()=>Qo,timeReal:()=>cn,timeScale:()=>rr,toggleFullscreen:()=>uh,touchGamepadAlpha:()=>yr,touchGamepadAnalog:()=>Rs,touchGamepadButtonCount:()=>Xn,touchGamepadCenterButtonSize:()=>be,touchGamepadDisplayTime:()=>os,touchGamepadEnable:()=>un,touchGamepadFloating:()=>dn,touchGamepadLeftButtonCount:()=>Yn,touchGamepadLeftStick:()=>_n,touchGamepadPassthrough:()=>gr,touchGamepadRightStick:()=>$n,touchGamepadSize:()=>Kt,touchGamepadVibration:()=>Ks,touchInputEnable:()=>yn,tweenProperty:()=>hd,tweenStopAll:()=>dd,tweenUpdate:()=>Oc,uiDebug:()=>Ur,uiSetDebug:()=>od,uiSystem:()=>C,usingGamepadInput:()=>mh,usingKeyboardInput:()=>yh,usingMouseInput:()=>gh,vec2:()=>b,vibrate:()=>_r,vibrateEnable:()=>Ps,vibrateStop:()=>Th,workCanvas:()=>Ue,workContext:()=>tn,workReadCanvas:()=>Ce,workReadContext:()=>ze,worldToScreen:()=>Pn,worldToScreenDelta:()=>oh,writeSaveData:()=>Ql,zzfx:()=>Jh,zzfxG:()=>Mi,zzfxM:()=>Cc});function _l(){return Re}function Rl(n=!0){Re=n}function En(n,t,e,s){p(!bn.find(o=>o.update===n&&o.render===t&&o.glContextLost===e&&o.glContextRestored===s));let i=new co(n,t,e,s);bn.push(i)}async function Pl(n,t,e,s,i,o=[],a){if(Oa&&console.log(`${Vs} Engine v${Ws}`),p(!pt,"engine already initialized"),pt)return;p(me(o),"pass in images as array"),document.body||document.documentElement.appendChild(document.createElement("body")),a||(a=document.body),n||(n=()=>{}),t||(t=()=>{}),e||(e=()=>{}),s||(s=()=>{}),i||(i=()=>{});function r(){k=b(N.width,N.height),pt.imageSmoothingEnabled=!Tn,To()}function c(y=0){let x=y-oo;oo||(x=0),oo=y,(Jt||Ci)&&(qs=$t(qs,1e3/(x||1),.05));let v=Jt&&Ft("Equal"),w=Jt&&Ft("Minus"),_=v?10:w?.1:1;cn+=x*_/1e3;let S=rr*_;x*=S,we+=Re?0:x,S<=1&&(we=st(we,50));let E=!1;if(Re){E=!0,l(),Aa(),bn.forEach(T=>{var P;return(P=T.update)==null?void 0:P.call(T)});for(let T of _t)T.parent||T.updateTransforms();va(),e(),Ca(),_e()&&A()}else{let T=0;for(we<0&&we>-9&&(T=we,we=0);we>=0;we-=1e3/60)ne=La++/60,E=!0,l(),Aa(),t(),bn.forEach(P=>{var F;return(F=P.update)==null?void 0:F.call(P)}),Da(),va(),e(),Ca(),_e()&&A();we+=T}_e()||A(),requestAnimationFrame(c);function A(){if(!U){E||l(),r(),s(),_t.sort((T,P)=>T.renderOrder-P.renderOrder);for(let T of _t)T.destroyed||T.render();i(),bn.forEach(T=>{var P;return(P=T.render)==null?void 0:P.call(T)}),_h(),Fl(),It(),jl(),Le=0,Oe=0}}}function l(){if(!U){if(kn.x){k=kn.copy();let y=innerWidth/innerHeight,x=kn.x/kn.y,v=yIn){let E=k.y*In|0;k.x=st(E,Mn.x)}else if(w0&&!j&&(pt.fillStyle=sn.toString(),pt.fillRect(0,0,k.x,k.y),pt.fillStyle=at.toString()),pt.lineJoin="round",pt.lineCap="round"}}if(U)return d();qh(a);let u="margin:0;overflow:hidden;background:#000;user-select:none;-webkit-user-select:none;touch-action:none;-webkit-touch-callout:none";a.style.cssText=u,N=a.appendChild(document.createElement("canvas")),Ot=pt=N.getContext("2d"),Eh(),Bh(),Gl();let h="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)";N.style.cssText=h,it&&(it.style.cssText=h),ec(ar),l(),To(),Ue=new OffscreenCanvas(64,64),tn=Ue.getContext("2d"),Ce=new OffscreenCanvas(64,64),ze=Ce.getContext("2d",{willReadFrequently:!0});let f=o.map((y,x)=>wa(x,y));return o.length||f.push(wa(0)),f.push(dh()),cr&&f.push(new Promise(y=>{let x=0;v();function v(){Ms(),Qh(x+=.01),x>1?y():setTimeout(v,16)}})),await Promise.all(f),d();async function d(){await n(),c()}}function Da(){Zo=_t.filter(t=>t.collideSolidObjects);function n(t){if(!t.destroyed){t.update();for(let e of t.children)n(e)}}for(let t of _t)if(!(t.parent||t.destroyed)){t.update(),t.updatePhysics();for(let e of t.children)n(e);t.updateTransforms()}_t=_t.filter(t=>!t.destroyed)}function Ll(n=!0){for(let t of _t)t.parent||t.destroy(n);_t=_t.filter(t=>!t.destroyed)}function Ma(n,t,e=_t){let s=[];if(n)if(t instanceof ut)for(let i of e)i.isOverlapping(n,t)&&s.push(i);else{let i=t*t;for(let o of e)n.distanceSquared(o.pos)e(i))}function Dl(n,t,e=_t){let s=[];for(let i of e)i.collideRaycast&&Ua(n,t,i.pos,i.size)&&(ye&&Ct(i.pos,i.size,"#f00"),s.push(i));return ye&&Ee(n,t,s.length?"#f00":"#00f",.02),s}function p(n,...t){if(!n)throw console.assert(n,...t),new Error("Assert failed!")}function Et(...n){console.log(...n)}function Ct(n,t=b(),e=H,s=0,i=0,o=!1,a=!1){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(q(e)||W(e),"color is invalid"),p(R(s),"time must be a number"),p(R(i),"angle must be a number"),W(e)&&(e=e.toString());let r=new Pe(s);nn.push({pos:n.copy(),size:t.copy(),color:e,timer:r,angle:i,fill:o,screenSpace:a})}function Ml(n,t,e=H,s=0,i=0,o=!1,a=!1){p(O(n),"pos must be a vec2"),p(me(t),"points must be an array"),p(q(e)||W(e),"color is invalid"),p(R(s),"time must be a number"),p(R(i),"angle must be a number"),W(e)&&(e=e.toString()),n=n.copy(),t=t.map(c=>c.copy());let r=new Pe(s);nn.push({pos:n,points:t,color:e,timer:r,angle:i,fill:o,screenSpace:a})}function Xt(n,t=0,e=H,s=0,i=!1,o=!1){p(O(n),"pos must be a vec2"),p(R(t),"size must be a number"),p(q(e)||W(e),"color is invalid"),p(R(s),"time must be a number"),W(e)&&(e=e.toString()),n=n.copy();let a=new Pe(s);nn.push({pos:n,size:t,color:e,timer:a,angle:0,fill:i,screenSpace:o})}function tr(n,t,e,s,i=!1){Ct(n,void 0,t,e,s,!1,i)}function Ee(n,t,e,s=.1,i=0,o=!1){p(O(n),"posA must be a vec2"),p(O(t),"posB must be a vec2"),p(R(s),"width must be a number");let a=b((t.x-n.x)/2,(t.y-n.y)/2),r=b(s,a.length()*2);Ct(n.add(a),r,e,i,a.angle(),!0,o)}function uo(n,t,e,s,i,o,a=!1){p(O(n),"posA must be a vec2"),p(O(e),"posB must be a vec2"),p(O(t),"sizeA must be a vec2"),p(O(s),"sizeB must be a vec2");let r=b(st(n.x-t.x/2,e.x-s.x/2),st(n.y-t.y/2,e.y-s.y/2)),c=b(tt(n.x+t.x/2,e.x+s.x/2),tt(n.y+t.y/2,e.y+s.y/2));Ct(r.lerp(c,.5),c.subtract(r),i,o,0,!1,a)}function Dn(n,t,e=1,s=H,i=0,o=0,a="monospace",r=!1){p(q(n),"text must be a string"),p(O(t),"pos must be a vec2"),p(R(e),"size must be a number"),p(q(s)||W(s),"color is invalid"),p(R(i),"time must be a number"),p(R(o),"angle must be a number"),p(q(a),"font must be a string"),W(s)&&(s=s.toString()),t=t.copy();let c=new Pe(i);nn.push({text:n,pos:t,size:e,color:s,timer:c,angle:o,font:a,screenSpace:r})}function Il(){nn=[]}function Ga(){lo=1}function kl(){let n=e=>{document.body.style="background-color:#111;margin:8px",document.body.innerHTML="
"+e},t=console.assert;console.assert=(e,...s)=>{if(t(e,...s),!e){let i=s.join(" "),o=new Error().stack;throw`Assertion failed!
 `+i+`
 `+o}},onunhandledrejection=e=>n(e.reason.stack||e.reason),onerror=(e,s,i,o)=>n(`${e}
 ${s}
-Ln ${i}, Col ${o}`)}function Gl(){Oa&&console.warn("LittleJS DEBUG build loaded. Use the release build for production.")}function va(){zt&&(Bt(ka)&&(Fe=!Fe),Fe&&(Bt("Digit1")&&(ge=!ge,xn=!1),Bt("Digit2")&&(xn=!xn,ge=!1),Bt("Digit3")&&(vn=!vn),Bt("Digit4")&&(ye=!ye),Bt("Digit5")&&Ga(),Bt("Digit7")&&(zn=!zn)),_e()?(!Fe||Bt("Digit6"))&&ja():Fe&&Bt("Digit6")&&Fa())}function Fl(){if(_e())return;It();let n=Le,t=Oe;lo&&(vr(),tc(N),lo=0);let e=pt;if(vn&&Oi){let o=0;for(let a=0;a<8;a++)mo(a)&&o++;for(let a=0;a<8;a++){if(!mo(a))continue;let r=1,c=.2,l=Mt.add(b(-r*2,((o-1)/2-a)*r*3));Dn(a,l.add(b(-r,r)),1),a===At&&Dn("Main",l.add(b(-r*2,0)),1,"#0f0");let u=Ae[a].length;for(let f=0;f{e.save();let o=i.pos,a=1,r=i.angle;if(i.screenSpace||(o=Pn(i.pos),a=K,r-=et),e.translate(o.x|0,o.y|0),e.rotate(r),e.scale(1,i.text?1:-1),e.fillStyle=i.color,e.strokeStyle=i.color,i.text!==void 0)e.font=i.size*a+"px "+i.font,e.textAlign="center",e.textBaseline="middle",e.fillText(i.text,0,0);else if(i.points!==void 0){e.beginPath();for(let c of i.points){let l=c.scale(a).floor();e.lineTo(l.x,l.y)}e.closePath(),i.fill&&e.fill(),e.stroke()}else if(i.size===0||i.size.x===0&&i.size.y===0){let c=Ia*a;e.fillRect(-c/2,-1,c,3),e.fillRect(-1,-c/2,3,c)}else if(i.size.x!==void 0){let c=i.size.scale(a).floor(),l=c.x,u=c.y;i.fill&&e.fillRect(-l/2|0,-u/2|0,l,u),e.strokeRect(-l/2|0,-u/2|0,l,u)}else e.beginPath(),e.arc(0,0,i.size*a/2,0,9),i.fill&&e.fill(),e.stroke();e.restore()}),nn=nn.filter(i=>i.timer<0),s){let i=gc(s.pos,ke);i&&Zs(i.floor().add(b(.5)),b(1),V(0,1,1,.3),0,!1),mn(ke,s.pos,.1,i?V(1,0,0,.5):V(0,1,0,.5),void 0,void 0,!1);let o="mouse pos = "+ke;an.length&&(o+=`
+Ln ${i}, Col ${o}`)}function Gl(){Oa&&console.warn("LittleJS DEBUG build loaded. Use the release build for production.")}function va(){Jt&&(Nt(ka)&&(Fe=!Fe),Fe&&(Nt("Digit1")&&(ge=!ge,xn=!1),Nt("Digit2")&&(xn=!xn,ge=!1),Nt("Digit3")&&(vn=!vn),Nt("Digit4")&&(ye=!ye),Nt("Digit5")&&Ga(),Nt("Digit7")&&(zn=!zn)),_e()?(!Fe||Nt("Digit6"))&&ja():Fe&&Nt("Digit6")&&Fa())}function Fl(){if(_e())return;It();let n=Le,t=Oe;lo&&(vr(),tc(N),lo=0);let e=pt;if(vn&&Oi){let o=0;for(let a=0;a<8;a++)mo(a)&&o++;for(let a=0;a<8;a++){if(!mo(a))continue;let r=1,c=.2,l=Mt.add(b(-r*2,((o-1)/2-a)*r*3));Dn(a,l.add(b(-r,r)),1),a===At&&Dn("Main",l.add(b(-r*2,0)),1,"#0f0");let u=Ae[a].length;for(let f=0;f{e.save();let o=i.pos,a=1,r=i.angle;if(i.screenSpace||(o=Pn(i.pos),a=K,r-=nt),e.translate(o.x|0,o.y|0),e.rotate(r),e.scale(1,i.text?1:-1),e.fillStyle=i.color,e.strokeStyle=i.color,i.text!==void 0)e.font=i.size*a+"px "+i.font,e.textAlign="center",e.textBaseline="middle",e.fillText(i.text,0,0);else if(i.points!==void 0){e.beginPath();for(let c of i.points){let l=c.scale(a).floor();e.lineTo(l.x,l.y)}e.closePath(),i.fill&&e.fill(),e.stroke()}else if(i.size===0||i.size.x===0&&i.size.y===0){let c=Ia*a;e.fillRect(-c/2,-1,c,3),e.fillRect(-1,-c/2,3,c)}else if(i.size.x!==void 0){let c=i.size.scale(a).floor(),l=c.x,u=c.y;i.fill&&e.fillRect(-l/2|0,-u/2|0,l,u),e.strokeRect(-l/2|0,-u/2|0,l,u)}else e.beginPath(),e.arc(0,0,i.size*a/2,0,9),i.fill&&e.fill(),e.stroke();e.restore()}),nn=nn.filter(i=>i.timer<0),s){let i=gc(s.pos,ke);i&&Zs(i.floor().add(b(.5)),b(1),V(0,1,1,.3),0,!1),mn(ke,s.pos,.1,i?V(1,0,0,.5):V(0,1,0,.5),void 0,void 0,!1);let o="mouse pos = "+ke;an.length&&(o+=`
 mouse collision = `+ri(ke)),o+=`
 
 --- object info ---
-`,o+=s.toString(),rn(o,qt,24,V(),.05,void 0,"center","monospace")}{e.save(),e.fillStyle="#fff",e.textAlign="left",e.textBaseline="top",e.font="20px monospace",e.shadowColor="#000",e.shadowBlur=9;let a=9,r=0,c=24;if(Fe){e.fillText(`${Vs} v${Ws}`,a,r+=c/2),e.fillText("Time: "+or(ee),a,r+=c),e.fillText("FPS: "+qs.toFixed(1)+(j?" WebGL":" Canvas2D"),a,r+=c),e.fillText("Objects: "+_t.length,a,r+=c),e.fillText("Draw Calls: "+Le,a,r+=c),e.fillText("Primitives: "+Oe,a,r+=c),e.fillText("---------",a,r+=c),e.fillStyle="#f00",e.fillText("ESC: Debug Overlay",a,r+=c),e.fillStyle=ge?"#f00":"#fff",e.fillText("1: Debug Physics",a,r+=c),e.fillStyle=xn?"#f00":"#fff",e.fillText("2: Debug Particles",a,r+=c),e.fillStyle=vn?"#f00":"#fff",e.fillText("3: Debug Gamepads",a,r+=c),e.fillStyle=ye?"#f00":"#fff",e.fillText("4: Debug Raycasts",a,r+=c),e.fillStyle="#fff",e.fillText("5: Save Screenshot",a,r+=c),e.fillText("6: Toggle Video Capture",a,r+=c),e.fillStyle=zn?"#f00":"#fff",e.fillText("7: Debug Sound",a,r+=c);let l="",u="";for(let h in Z[0])Gt(h,0)&&(parseInt(h)<3?u+=h+" ":l+=h+" ");u&&e.fillText("Mouse: "+u,a,r+=c),l&&e.fillText("Keys: "+l,a,r+=c);for(let h=1;hs.push(r.data),i.onstop=()=>{let r=new Blob(s,{type:"video/webm"}),c=URL.createObjectURL(r);us(c,"capture.webm",1e3)};let o,a;if(Kt){a=new ConstantSourceNode(mt,{offset:0}),a.connect(We),a.start(),o=mt.createMediaStreamDestination(),We.connect(o);for(let r of o.stream.getAudioTracks())n.addTrack(r)}try{i.start()}catch{Et("Video capture not supported in this browser!"),a==null||a.stop();return}Et("Video capture started."),je={mediaRecorder:i,captureTimer:e,videoTrack:t,silentAudioSource:a,audioStreamDestination:o}}function ja(){var n,t,e;p(_e(),"Not capturing video!"),Et(`Video capture ended. ${je.captureTimer.get().toFixed(2)} seconds recorded.`),pe.style.display="none",(n=je.silentAudioSource)==null||n.stop(),(t=je.mediaRecorder)==null||t.stop(),(e=je.videoTrack)==null||e.stop(),je=void 0}function Bl(){p(_e(),"Not capturing video!"),vr(),je.videoTrack.requestFrame(),pe.textContent="\u25CF REC "+or(je.captureTimer)}function se(n){if(zt){let t=Object.keys(n),e={};t.forEach(s=>e[s]=n[s]),t.forEach(s=>{Object.defineProperty(n,s,{get:()=>e[s],set:i=>{p(!1,`Cannot modify engine constant. Attempted to set constant (${n}) property '${s}' to '${i}'.`)},enumerable:!0})})}return Object.freeze(n)}function ce(n,t=1){return(n%t+t)%t}function z(n,t=0,e=1){return ne?e:n}function Jt(n,t,e){return(e-=t)?z((n-t)/e):0}function Yt(n,t,e){return n+z(e)*(t-n)}function Nl(n,t,e,s,i){return Yt(s,i,Jt(n,t,e))}function nr(n,t,e=1){p(e>0,"distanceWrap wrapSize must be > 0");let s=(n-t)%e;return s*2%e-s}function Ja(n,t,e,s=1){return n+z(e)*nr(t,n,s)}function zl(n,t){return nr(n,t,2*Q)}function Jl(n,t,e){return Ja(n,t,e,2*Q)}function Xs(n){return n*n*(3-2*n)}function ls(n){return!(n&n-1)}function Ul(n){return 2**cs(Na(n))}function Ys(n,t,e,s=b()){let i=(n.x-e.x)*2,o=(n.y-e.y)*2,a=t.x+s.x,r=t.y+s.y;return ot(i)f)return!1;h=tt(y,h)}else{if(y0?r.x+1:r.x,x=h>0?r.y+1:r.y,v=c?(y-n.x)/c:1/0,w=l?(x-n.y)/l:1/0,_=0,S=v,E=w,A=fr.x&&(T.x=r.x+1-P),F.yr.y&&(T.y=r.y+1-P),s&&(A?s.set(-u,0):s.set(0,-h)),T}(A=SURL.revokeObjectURL(n),e)}function $l(n,t,e){var s;p(q(n),"shareURL requires title string"),p(q(t),"shareURL requires url string"),(s=navigator.share)==null||s.call(navigator,{title:n,url:t}).then(()=>e==null?void 0:e())}function Kl(n,t){p(q(n),"loadData requires saveName string");let e={};try{let s=localStorage[n];if(s)try{e=JSON.parse(s)}catch{Et("readSaveData: corrupt JSON for",n,"\u2014 using defaults")}}catch{Et("readSaveData: localStorage unavailable \u2014 using defaults")}return{...t,...e}}function Ql(n,t){p(q(n),"saveData requires saveName string");try{localStorage[n]=JSON.stringify(t)}catch{Et("writeSaveData: failed to write",n)}}function po(n){let t=(n|0)^2654435769;return t=Math.imul(t^t>>>16,2246822507),t=Math.imul(t^t>>>13,3266489909),t^=t>>>16,(t>>>0)/2**32}function Zl(n){let t=Pt(n);return Yt(po(t),po(t+1),Xs(n-t))}function tu(n,t){let e=Pt(n),s=Pt(t),i=Xs(n-e),o=Xs(t-s),a=(r,c)=>po(r+c*374761393);return Yt(Yt(a(e,s),a(e+1,s),i),Yt(a(e,s+1),a(e+1,s+1),i),o)}function eu(n){Mt=n.copy()}function nu(n){et=n}function su(n){K=n}function iu(n){rr=n}function ou(n){Ei=n}function ru(n){sn=n.copy()}function au(n){Mn=n.copy()}function cu(n){ss=n}function lu(n){In=n}function uu(n){kn=n.copy()}function ec(n){ar=n,N&&(N.style.imageRendering=n?"pixelated":""),it&&(it.style.imageRendering=n?"pixelated":"")}function hu(n){Tn=n}function du(n){on=n}function fu(n){Es=n}function pu(n){cr=n}function gu(n){U=n}function yu(n){if(n&&!wo){console.warn("Can not enable WebGL if it was disabled on start.");return}j=n,it&&(it.style.display=n?"":"none")}function mu(n){_s=n}function bu(n){_i=n.copy()}function xu(n){Ri=n}function vu(n){Pi=n}function Su(n){Li=n}function wu(n){lr=n}function Tu(n){ur=n}function Au(n){hr=n}function Cu(n){dr=n}function Eu(n){fr=n}function _u(n){Ne=n}function Ru(n){Xt=n.copy()}function Pu(n){$s=n}function Lu(n){Oi=n}function Ou(n){pr=n}function Du(n){is=n}function Mu(n){yn=n}function Iu(n){un=n}function ku(n){gr=n}function Gu(n){be=n}function Fu(n){Xn=n,n>0&&($n=!1)}function ju(n){_n=n,n&&(Yn=0)}function Bu(n){Yn=n,n>0&&(_n=!1)}function Nu(n){$n=n,n&&(Xn=0)}function zu(n){Rs=n}function Ju(n){dn=n}function Uu(n){$t=n}function Vu(n){yr=n}function Wu(n){os=n}function qu(n){Ks=n}function Hu(n){Ps=n}function Xu(n){Kt=n}function Yu(n){Sn=n,Kt&&!U&&We&&(We.gain.value=n)}function $u(n){mr=n}function Ku(n){br=n}function Qu(n){Ci=n}function Zu(n){ka=n}function Qs(n){return n.r>=1&&n.g>=1&&n.b>=1}function xr(n){return n.r<=0&&n.g<=0&&n.b<=0&&n.a<=0}function Ls(n=0,t=_i,e=0,s=Ri,i=Pi){if(p(O(n)||typeof n=="number","index must be a vec2 or number"),p(O(t)||typeof t=="number","size must be a vec2 or number"),p(R(e)||e instanceof He,"texture must be a number or TextureInfo"),p(R(s),"padding must be a number"),U)return new De;typeof t=="number"&&(p(t>0),t=new lt(t,t));let o=typeof e=="number"?hn[e]:e;p(o instanceof He,"tile texture is not loaded"),p(o.size.x>0,"tile texture is not loaded");let a=t.x+s*2,r=t.y+s*2,c,l;if(typeof n=="number"){let h=o.size.x/a|0;c=n%h,l=n/h|0}else c=n.x,l=n.y;let u=new lt(c*a+s,l*r+s);return new De(u,t,o,s,i)}function Ft(n,t=b(1),e,s=H,i=0,o,a,r=j,c=!1,l){var f;p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(W(s),"color is invalid"),p(R(i),"angle must be a number"),p(!a||W(a),"additiveColor must be a color"),p(!l||!r,"context only supported in canvas 2D mode");let u=e==null?void 0:e.textureInfo,h=(f=e==null?void 0:e.bleed)!=null?f:0;if(r&&j)if(p(!!g,"WebGL is not enabled!"),c&&([n,t,i]=Ds(n,t,i)),u){let d=u.sizeInverse,y=e.pos.x*d.x,x=e.pos.y*d.y,v=e.size.x*d.x,w=e.size.y*d.y;if(kr(u.glTexture),h){let _=d.x*h,S=d.y*h;Ss(n.x,n.y,o?-t.x:t.x,t.y,i,y+_,x+S,y-_+v,x-S+w,s.rgbaInt(),a&&a.rgbaInt())}else Ss(n.x,n.y,o?-t.x:t.x,t.y,i,y,x,y+v,x+w,s.rgbaInt(),a&&a.rgbaInt())}else{let d=a?s.add(a):s;wc(n.x,n.y,t.x,t.y,i,d.rgbaInt())}else++Le,++Oe,Rn(n,t,i,o,d=>{if(u){d.scale(1,-1);let y=e.pos.x,x=e.pos.y,v=e.size.x,w=e.size.y;lh(d,u.image,y,x,v,w,-.5,-.5,1,1,s,a,h)}else{let y=a?s.add(a):s;d.fillStyle=y.toString(),d.fillRect(-.5,-.5,1,1)}},c,l)}function Zs(n,t,e,s,i,o,a){Ft(n,t,void 0,e,s,!1,void 0,i,o,a)}function th(n,t,e=H,s=ln,i=0,o=j,a=!1,r){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(W(e)&&W(s),"color is invalid"),p(R(i),"angle must be a number"),p(!r||!o,"context only supported in canvas 2D mode"),o&&j){p(!!g,"WebGL is not enabled!"),a&&(n=Os(n),t=t.scale(1/K),i+=et);let c=[],l=[],u=t.x/2,h=t.y/2,f=e.rgbaInt(),d=s.rgbaInt(),y=ut(-i),x=rt(-i);for(let v=4;v--;){let w=v&1?u:-u,_=v&2?h:-h,S=w*y-_*x,E=w*x+_*y,A=v&2?f:d;c.push(b(n.x+S,n.y+E)),l.push(A)}Nr(c,l)}else++Le,++Oe,Rn(n,t,i,!1,c=>{let l=c.createLinearGradient(0,.5,0,-.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.fillRect(-.5,-.5,1,1)},a,r)}function eh(n,t,e,s=0,i=H,o=0,a,r=j,c=!1,l){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(O(e),"wrapCount must be a vec2"),p(W(i),"color is invalid"),p(R(o),"angle must be a number"),p(!a||W(a),"additiveColor must be a color"),p(!l||!r,"context only supported in canvas 2D mode"),p(!(s instanceof De),"pass a TextureInfo or texture index, not a TileInfo \u2014 use tileInfo.textureInfo"),U)return;let u=typeof s=="number"?hn[s]:s;if(p(u instanceof He,"texture not loaded"),p(u.size.x>0,"texture not loaded"),p(u.wrap,"drawTextureWrapped requires a wrap-enabled texture; call textureInfo.setWrap(true) first"),r&&j){p(!!g,"WebGL is not enabled!"),c&&([n,t,o]=Ds(n,t,o)),kr(u.glTexture),Ss(n.x,n.y,t.x,t.y,o,0,0,e.x,e.y,i.rgbaInt(),a&&a.rgbaInt());return}++Le,++Oe,c||(n=Pn(n),t=t.scale(K),o-=et);let h=!Ei||(a?Qs(i.add(a))&&a.a<=0:Qs(i)),f=!h&&a&&!xr(a),d=h?u.image:ch(u.image,i,a);l=l||Ot,l.save(),l.translate(n.x+.5,n.y+.5),l.rotate(o),l.globalAlpha=f?1:i.a;let y=l.createPattern(d,"repeat"),x=new DOMMatrix().translate(-t.x/2,-t.y/2).scale(t.x/(e.x*d.width),t.y/(e.y*d.height));y.setTransform(x),l.fillStyle=y,l.fillRect(-t.x/2,-t.y/2,t.x,t.y),l.globalAlpha=1,l.restore()}function go(n,t=.1,e=H,s=!1,i=b(),o=0,a=j,r=!1,c){if(p(me(n),"points must be an array"),p(R(t),"width must be a number"),p(W(e),"color is invalid"),p(O(i),"pos must be a vec2"),p(R(o),"angle must be a number"),p(!c||!a,"context only supported in canvas 2D mode"),a&&j){p(!!g,"WebGL is not enabled!");let l=b(1);r&&([i,l,o]=Ds(i,l,o)),Br(n,e.rgbaInt(),t,i.x,i.y,l.x,l.y,o,s)}else++Le,++Oe,Rn(i,b(1),o,!1,l=>{l.strokeStyle=e.toString(),l.lineWidth=t,l.beginPath();for(let u=0;u0&&Br(n,s.rgbaInt(),e,i.x,i.y,l.x,l.y,o)}else Rn(i,b(1),o,!1,l=>{l.fillStyle=t.toString(),l.beginPath();for(let u of n)l.lineTo(u.x,u.y);l.closePath(),l.fill(),e&&(l.strokeStyle=s.toString(),l.lineWidth=e,l.stroke())},r,c)}function sc(n,t=b(1),e=H,s=0,i=0,o=at,a=j,r=!1,c){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(W(e)&&W(o),"color is invalid"),p(R(s),"angle must be a number"),p(R(i),"lineWidth must be a number"),p(i>=0,"lineWidth must be a positive value or 0"),p(!c||!a,"context only supported in canvas 2D mode"),i=z(i,0,st(t.x,t.y)),a&&j?nc(n,t,_s,e,i,o,s,a,r,c):Rn(n,b(1),s,!1,l=>{l.fillStyle=e.toString(),l.beginPath(),l.ellipse(0,0,t.x/2,t.y/2,0,0,9),l.fill(),i&&(l.strokeStyle=o.toString(),l.lineWidth=i,l.stroke())},r,c)}function ti(n,t=1,e=H,s=0,i=at,o=j,a=!1,r){p(R(t),"size must be a number"),sc(n,b(t),e,0,s,i,o,a,r)}function ic(n,t=b(1),e=H,s=ln,i=0,o=j,a=!1,r){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(W(e)&&W(s),"color is invalid"),p(R(i),"angle must be a number"),p(!r||!o,"context only supported in canvas 2D mode"),!U)if(o&&j){p(!!g,"WebGL is not enabled!"),a&&(n=Os(n),t=t.scale(1/K),i+=et);let c=_s,l=t.x/2,u=t.y/2,h=e.rgbaInt(),f=s.rgbaInt(),d=nh++,y=ut(-i),x=rt(-i),v=E=>{let A=rt(E)*l,T=ut(E)*u;return b(n.x+A*y-T*x,n.y+A*x+T*y)},w=d%c/c*Q*2,_=[v(w)],S=[f];for(let E=c;E--;){let A=(E+d)%c/c*Q*2;_.push(n),S.push(h),_.push(v(A)),S.push(f)}Nr(_,S)}else++Le,++Oe,Rn(n,t,i,!1,c=>{let l=c.createRadialGradient(0,0,0,0,0,.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.beginPath(),c.ellipse(0,0,.5,.5,0,0,9),c.fill()},a,r)}function sh(n,t=1,e=H,s=ln,i=j,o=!1,a){p(R(t),"size must be a number"),ic(n,b(t),e,s,0,i,o,a)}function Rn(n,t,e=0,s=!1,i,o=!1,a=Ot){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(R(e),"angle must be a number"),p(typeof i=="function","drawFunction must be a function"),o||(n=Pn(n),t=t.scale(K),e-=et),a.save(),a.translate(n.x+.5,n.y+.5),a.rotate(e),a.scale(s?-t.x:t.x,-t.y),i(a),a.restore()}function ih(n,t,e=1,s=H,i=0,o=at,a="center",r=Es,c="",l,u=0,h=Ot){t=Pn(t),e*=K,i*=K,u-=et,u*=-1,rn(n,t,e,s,i,o,a,r,c,l,u,h)}function rn(n,t,e,s=H,i=0,o=at,a="center",r=Es,c="",l,u=0,h=Ot){p(q(n),"text must be a string"),p(O(t),"pos must be a vec2"),p(R(e),"size must be a number"),p(W(s),"color must be a color"),p(R(i),"lineWidth must be a number"),p(W(o),"lineColor must be a color"),p(["left","center","right"].includes(a),"align must be left, center, or right"),p(q(r),"font must be a string"),p(q(c),"fontStyle must be a string"),p(R(u),"angle must be a number");let f=(n+"").split(`
-`),d=t.y-(f.length-1)*e/2;h.save(),h.fillStyle=s.toString(),h.strokeStyle=o.toString(),h.lineWidth=i,h.textAlign=a,h.font=c+" "+e+"px "+r,h.textBaseline="middle",h.translate(t.x,d),h.rotate(-u);let y=0;f.forEach(x=>{i&&h.strokeText(x,0,y,l),h.fillText(x,0,y,l),y+=e}),h.restore()}async function wa(n,t){p(R(n),"textureIndex must be a number"),p(!hn[n],"textureIndex is already loaded!"),p(!t||q(t),"image src must be a string");let e=new Image;t&&await new Promise(s=>{e.onerror=e.onload=s,e.crossOrigin="anonymous",e.src=t}),hn[n]=new He(e)}function Os(n){p(O(n),"screenPos must be a vec2");let t=(n.x-k.x/2+.5)/K,e=(n.y-k.y/2+.5)/-K;if(et){let s=ut(-et),i=rt(-et),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new lt(t+Mt.x,e+Mt.y)}function Pn(n){p(O(n),"worldPos must be a vec2");let t=n.x-Mt.x,e=n.y-Mt.y;if(et){let s=ut(et),i=rt(et),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new lt(t*K+k.x/2-.5,e*-K+k.y/2-.5)}function oc(n){p(O(n),"screenDelta must be a vec2");let t=n.x/K,e=n.y/-K;if(et){let s=ut(-et),i=rt(-et),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new lt(t,e)}function oh(n){p(O(n),"worldDelta must be a vec2");let t=n.x,e=n.y;if(et){let s=ut(et),i=rt(et),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new lt(t*K,e*-K)}function Ds(n,t,e=0){return p(O(n),"screenPos must be a vec2"),p(O(t),"screenSize must be a vec2"),p(R(e),"screenAngle must be a number"),[Os(n),t.scale(1/K),e+et]}function rc(){return k.scale(1/K)}function rh(n,t,e,s){p(O(n),"center must be a vec2"),p(O(t),"size must be a vec2");let i=f(e),o=f(s),a=t.x+i.left+i.right,r=t.y+i.top+i.bottom,c=k.x-o.left-o.right,l=k.y-o.top-o.bottom;if(!(a>0&&r>0&&c>0&&l>0))return K;K=st(c/a,l/r);let u=b(i.right-i.left,i.top-i.bottom).scale(.5),h=b(o.right-o.left,o.top-o.bottom).scale(.5/K);return Mt=n.add(u).add(h),K;function f(d){return(d===void 0||R(d))&&(d=b(d)),O(d)?{top:d.y,right:d.x,bottom:d.y,left:d.x}:{top:d.top||0,right:d.right||0,bottom:d.bottom||0,left:d.left||0}}}function ah(n,t=0){if(p(O(n),"pos must be a vec2"),p(O(t)||R(t),"size must be a vec2 or number"),!K)return!1;let e=n.x-Mt.x,s=n.y-Mt.y;if(et){let a=ut(et),r=rt(et),c=e*a-s*r,l=e*r+s*a;e=c,s=l}e*=K*2,s*=-K*2,t instanceof lt&&(t=t.length()),t*=K;let i=k.x,o=k.y;return e+t>-i&&e-t-o&&s-t{n.onerror=n.onload=r,n.crossOrigin="anonymous",n.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAAeAQMAAABnrVXaAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAAjpJREFUOMu9kzFu2zAUhn+CAROgqrk+B2l0BWYxMjlXeYaAtFtbdA1sGgHqRQfI0CNkSG5AwYB0BQ8d5Bsomwah6CPVeGg6tEPzAxLwyI+P78cP4u9lNO9OoMKnLMOobG5020/yaj/MrRcCGh1gBbyiLTPJEYaIiom5KM9Jq7KgynMGtb6L4GL4MF2H4LQKCXTvDVw2I4MsgZT7QLExdiutH+D08VOP3INXRrWX1/mmpbkNgAPYRVANb4xpcegYvhiNbIXauQICEjBuYLfMakaakWQeXxiZ0VDtuJCKs3ztMV59QtsHJNcRxDzfdL21ty3PrfIcXTN+E+GFAv6T5nbT9jd50/WFxb5ksdAv49qS6ouymG66ji08UMT6moykYLAo+V0j23GN4m829ZySAD5K7QsBfQTvOG8eE+gTeGYRAmnNAubN3hf5Zv9tJWDHp/VTuaSm7SN4fyINQqaNO3RMVxvpSPXnOChnRNvFcGY0gnwiPswYwTKVPE0zVtX3mTEIOoFzaqLrGuJaV+Uqumb71fVk/VoOH3cdLNQP/FHi8hV0CQNoqBZsUPlLPMsdCJro9QAaQQ0woDy9BJm0eTxCFnO9srcYlhNVlfR2EyTrph1uUtbUtAJifwRgrKuYdXVHeb0YI3QpawohQHkloI3J5FuVwI5ORxC9k2Tuz9Ir1IjgeIPGMHYkAZe2RuYkmWFmt3gGbTPOmBUWVTmRmHtGrfpzG/yuQNOKa6gBB/WA9khitPgl6/GP+gl2Af6tCbvaygAAAABJRU5ErkJggg=="});let t=b(),e=b(8),s=1,i=0,o=new He(n),a=new De(t,e,o,s,i);cc=new ei(a)}function fh(n=!0){Gn=n}function ph(n){Tr=n}function gh(){return en==="mouse"}function yh(){return en==="keyboard"}function mh(){return en==="gamepad"}function Ar(n,t=0,e=!0,s=!0,i=!0){Z[t]&&(Z[t][n]&=~((e?1:0)|(s?2:0)|(i?4:0)))}function Ms(){Z.length=0,Z[0]=[],ue.length=0,An.length=0,Is.length=0,Ae.length=0,pn.length=0}function Gt(n,t=0){var e;return p(q(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Z[t])==null?void 0:e[n])&1)}function Bt(n,t=0){var e;return p(q(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Z[t])==null?void 0:e[n])&2)}function Cr(n,t=0){var e;return p(q(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Z[t])==null?void 0:e[n])&4)}function bh(n="ArrowUp",t="ArrowDown",e="ArrowLeft",s="ArrowRight"){p(q(n),"up key must be a string"),p(q(t),"down key must be a string"),p(q(e),"left key must be a string"),p(q(s),"right key must be a string");let i=o=>Gt(o)?1:0;return b(i(s)-i(e),i(n)-i(t))}function rs(n){return p(R(n),"mouse button must be a number"),Gt(n)}function ds(n){return p(R(n),"mouse button must be a number"),Bt(n)}function xh(n){return p(R(n),"mouse button must be a number"),Cr(n)}function Ge(n,t=At){return p(R(n),"button must be a number"),p(R(t),"gamepad must be a number"),Gt(n,t+1)}function Er(n,t=At){return p(R(n),"button must be a number"),p(R(t),"gamepad must be a number"),Bt(n,t+1)}function vh(n,t=At){return p(R(n),"button must be a number"),p(R(t),"gamepad must be a number"),Cr(n,t+1)}function fs(n,t=At){var e,s;return p(R(n),"stick must be a number"),p(R(t),"gamepad must be a number"),(s=(e=Ae[t])==null?void 0:e[n])!=null?s:b()}function yo(n=At){var t;return p(R(n),"gamepad must be a number"),(t=pn[n])!=null?t:b()}function mo(n=At){return p(R(n),"gamepad must be a number"),!!Z[n+1]}function lc(n=At){var t,e;return p(R(n),"gamepad must be a number"),(e=(t=Ae[n])==null?void 0:t.length)!=null?e:0}function Sh(n=At,t=200,e=1,s=1,i=0){var a,r,c;if(p(R(n),"gamepad must be a number"),!Ps||U)return;let o=(a=navigator==null?void 0:navigator.getGamepads)==null?void 0:a.call(navigator)[n];(c=(r=o==null?void 0:o.vibrationActuator)==null?void 0:r.playEffect)==null||c.call(r,"dual-rumble",{duration:t,strongMagnitude:e,weakMagnitude:s,startDelay:i})}function wh(n=At){var e,s,i;if(p(R(n),"gamepad must be a number"),!Ps||U)return;let t=(e=navigator==null?void 0:navigator.getGamepads)==null?void 0:e.call(navigator)[n];(i=(s=t==null?void 0:t.vibrationActuator)==null?void 0:s.reset)==null||i.call(s)}function _r(n=100){var t;p(R(n)||me(n),"pattern must be a number or array"),Ps&&!U&&((t=navigator==null?void 0:navigator.vibrate)==null||t.call(navigator,n))}function Th(){_r(0)}function Ah(){var n;!le&&((n=N.requestPointerLock)==null||n.call(N))}function Ch(){var n;(n=document.exitPointerLock)==null||n.call(document)}function uc(){return document.pointerLockElement===N}function Eh(){if(U)return;document.addEventListener("keydown",n),document.addEventListener("keyup",t),document.addEventListener("mousedown",s),document.addEventListener("mouseup",i),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",a),document.addEventListener("wheel",r,{passive:!1}),document.addEventListener("contextmenu",c),document.addEventListener("blur",l),le&&yn&&u();function n(f){if(f.repeat||(Z[0][f.code]=3,is&&(Z[0][e(f.code)]=3)),!Gn||!f.cancelable||!document.hasFocus()||f.ctrlKey||f.metaKey||f.altKey||x(f.target)||x(document.activeElement))return;let d=typeof f.key=="string"&&f.key.length===1;(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Space","Tab","Backspace"].includes(f.code)||d)&&f.preventDefault();function x(v){let w=v==null?void 0:v.tagName;return(v==null?void 0:v.isContentEditable)||["INPUT","TEXTAREA","SELECT"].includes(w)}}function t(f){Z[0][f.code]=Z[0][f.code]&2|4,is&&(Z[0][e(f.code)]=4)}function e(f){return is?f==="KeyW"?"ArrowUp":f==="KeyS"?"ArrowDown":f==="KeyA"?"ArrowLeft":f==="KeyD"?"ArrowRight":f:f}function s(f){if(le&&yn)return;Kt&&!U&&mt&&!gs()&&mt.resume(),Z[0][f.button]=3;let d=qt;qt=h(b(f.x,f.y)),Te=Te.add(qt.subtract(d)),Gn&&f.cancelable&&document.hasFocus()&&f.preventDefault()}function i(f){le&&yn||(Z[0][f.button]=Z[0][f.button]&2|4)}function o(f){ni=!0;let d=qt;qt=h(b(f.x,f.y));let y=uc()?b(f.movementX,f.movementY):qt.subtract(d);Te=Te.add(y)}function a(){ni=!1}function r(f){f.ctrlKey||(wr+=ae(f.deltaY)),Gn&&f.cancelable&&document.hasFocus()&&f.preventDefault()}function c(f){f.preventDefault()}function l(){Ms(),Je.clear(),ue.length=0,An.length=0,Is.length=0}function u(){document.addEventListener("touchstart",y=>d(y),{passive:!1}),document.addEventListener("touchmove",y=>d(y),{passive:!1}),document.addEventListener("touchend",y=>d(y),{passive:!1});let f;function d(y){if(yn){if(Kt&&!U&&mt&&!gs()&&mt.resume(),!un||gr){let x=S=>ps.includes(S.target)||S.target===gn,v=[];for(let S of y.touches)x(S)||v.push(S);let w=v.length,_=0;if(w){let S=b(v[0].clientX,v[0].clientY),E=qt;qt=h(S),f?Te=Te.add(qt.subtract(E)):Z[0][_]=3}else f&&(Z[0][_]=Z[0][_]&2|4);f=w}return Gn&&y.cancelable&&document.hasFocus()&&y.preventDefault(),!0}}}function h(f){let d=N.getBoundingClientRect(),y=Jt(f.x,d.left,d.right),x=Jt(f.y,d.top,d.bottom);return b(y*N.width,x*N.height)}}function Aa(){if(U)return;!(yn&&le)&&!document.hasFocus()&&Ms(),ke=Os(qt),Sr=oc(Te),Rh(),t(),n();function n(){let e=rs(0)||rs(1)||rs(2)||Te.length()>Tr,s=!1;for(let o=lc();o--&&!s;)s=fs(o).lengthSquared()>.04;for(let o=17;o--&&!s;)s=Ge(o);let i=!1;for(let o in Z[0])if(isNaN(+o)&&Z[0][o]&1){i=!0;break}s?en="gamepad":e?en="mouse":i&&(en="keyboard"),jn=en==="gamepad"}function t(){var a,r,c,l,u,h,f;let e=d=>{let v=w=>w>.3?Jt(w,.3,.8):w<-.3?-Jt(-w,.3,.8):0;return b(v(d.x),v(-d.y)).clampLength()};if(un&&le){if(p(!_n||!Yn,"set touchGamepadLeftStick or touchGamepadLeftButtonCount, not both"),p(!$n||!Xn,"set touchGamepadRightStick or touchGamepadButtonCount, not both"),!Un.isSet())return;At=0;let d=(a=Ae[0])!=null?a:Ae[0]=[],y=(r=pn[0])!=null?r:pn[0]=b();d.length=0,y.set();for(let v=0;v<2;v++){if(!Xe(v))continue;let w=Lr(v);d[w]=b();let _=(c=An[v])!=null?c:b();if(Rs)d[w]=e(_);else if(_.lengthSquared()>.3){let S=z(Hs(_.x),-1,1),E=z(Hs(_.y),-1,1);d[w]=b(S,-E).clampLength(),w||y.set(S,-E)}}let x=(l=Z[1])!=null?l:Z[1]=[];for(let v=12;v--;){let w=Ge(v,0);x[v]=ue[v]?w?1:3:w?4:0,Ks&&x[v]===3&&(v===9||Ph(v))&&_r(Ks)}return}try{if(!Oi||!(navigator!=null&&navigator.getGamepads))return}catch{return}if(!zt&&!document.hasFocus())return;let s=8,i=navigator.getGamepads(),o=st(s,i.length);for(let d=0;d>1]=e(b(y.axes[S],y.axes[S+1]));let _=!1;for(let S=y.buttons.length;S--;){let E=y.buttons[S],A=Ge(S,d);x[S]=E.pressed?A?1:3:A?4:0,E.pressed&&(!E.value||E.value>.9)&&(_=!0)}_&&(ro[d]=!0,ro[At]||(At=d)),y.mapping==="standard"&&w.set((Ge(15,d)&&1)-(Ge(14,d)&&1),(Ge(12,d)&&1)-(Ge(13,d)&&1)),pr&&(w.x||w.y)&&(v[0]=w.clampLength())}un&&jn&&Un.unset()}}function Ca(){if(!U){for(let n of Z)for(let t in n)n[t]&=1;wr=0,Sr=b(),Te=b()}}function _h(){Mh()}function Rh(){if(Qe||!un||!le||U||!document.body)return;let n=Qe=document.createElement("div");n.style.cssText="position:fixed;inset:0;z-index:50;pointer-events:none;opacity:0;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;transition:opacity .2s;box-sizing:border-box;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)";let t=hc=document.createElement("div");t.style.cssText="position:relative;width:100%;height:100%;pointer-events:none",n.appendChild(t);let e=Rr=document.createElementNS(ii,"svg");e.style.cssText="position:absolute;inset:0;width:100%;height:100%;pointer-events:none;overflow:visible;fill:none;stroke:#fff;stroke-width:3",t.appendChild(e);let s=()=>{let i=document.createElement("div");return i.style.cssText="position:absolute;pointer-events:auto;touch-action:none",i.addEventListener("pointerdown",o=>Fh(o,i)),i.addEventListener("pointermove",o=>jh(o)),i.addEventListener("pointerup",o=>Ea(o)),i.addEventListener("pointercancel",o=>Ea(o)),t.appendChild(i),i};ps[0]=s(),ps[1]=s(),gn=s(),addEventListener("resize",()=>Vn=!0),document.body.appendChild(n),Vn=!0}function Di(){return hc.getBoundingClientRect()}function Xe(n){return n?$n:_n}function Ln(n){return n?Xn:Yn}function Pr(n){return n?0:4}function Lr(n){return n&&_n?1:0}function Wn(n){return Xe(n)||Ln(n)>0}function Ph(n){for(let t=0;t<2;t++){let e=Pr(t);if(!Xe(t)&&n>=e&&no.style.cssText="position:absolute;pointer-events:auto;touch-action:none;"+a;if(Re){for(let o of ps)o.style.display="none";be?(i(gn,"inset:0"),gn.style.display=""):gn.style.display="none"}else{for(let a=0;a<2;a++){let r=ps[a],c=a?"right":"left";if(r.style.display=Wn(a)?"":"none",dn){let l=Wn(a?0:1)?"50%":"100%";i(r,`${c}:0;bottom:0;width:${l};height:60%`)}else i(r,`${c}:0;bottom:0;width:${3*s}px;height:${3*s}px`)}gn.style.display=be?"":"none";let o=be;i(gn,`left:50%;top:50%;width:${2*o}px;height:${2*o}px;transform:translate(-50%,-50%)`)}Oh(t,e),Vn=!1}function Oh(n,t){let e=Rr;for(;e.firstChild;)e.removeChild(e.firstChild);let s=dc={face:[],thumb:[]},i=$t,o=(r,c,l,u)=>{let h=document.createElementNS(ii,"circle");return h.setAttribute("cx",r),h.setAttribute("cy",c),h.setAttribute("r",l),u&&h.setAttribute("fill",u),e.appendChild(h),h},a=r=>{let c=i*.18,l=i*.5,u=r.x,h=r.y,f=document.createElementNS(ii,"path");f.setAttribute("d",`M ${u-c} ${h-l} H ${u+c} V ${h-c} H ${u+l} V ${h+c} H ${u+c} V ${h+l} H ${u-c} V ${h+c} H ${u-l} V ${h-c} H ${u-c} Z`),e.appendChild(f)};for(let r=0;r<2;r++){let c=Ln(r),l=Pr(r),u=Ve(r,n,t);if(Xe(r))Rs?o(u.x,u.y,i/2):a(u),s.thumb[r]=o(u.x,u.y,i/4,"#fff");else if(c===1)s.face[l]=o(u.x,u.y,i/2,"#000");else for(let h=0;h2?f:st(f,c-1);d=d===3?2:d===2?3:d;let y=b().setDirection(f,i/2);c===2&&(y.x*=-1),r||(y.x*=-1);let x=u.add(y);s.face[l+d]=o(x.x,x.y,i/4,"#000")}}zt&&vn&&Dh(n,t)}function Dh(n,t){let e=$t,s=Rr,i=(a,r,c)=>{let l=document.createElementNS(ii,a);for(let u in r)l.setAttribute(u,r[u]);l.setAttribute("stroke",c),l.setAttribute("stroke-width",2),l.setAttribute("fill","none"),s.appendChild(l)},o=(a,r,c)=>i("circle",{cx:a.x,cy:a.y,r},c);i("line",{x1:n/2,y1:0,x2:n/2,y2:t},"#0f0");for(let a=0;a<2;a++)if(Xe(a))if(dn){let r=t*.4,c=!Wn(a?0:1),l=c?0:a?n/2:0;i("rect",{x:l,y:r,width:c?n:n/2,height:t-r},"#0ff")}else o(Ve(a,n,t),2*e,"#0ff");else Ln(a)>=1&&o(Ve(a,n,t),e,"#0ff");if(be){o(b(n/2,t/2),be,"#ff0");for(let a=0;a<2;a++)Wn(a)&&o(Ve(a,n,t),2*e,"#f0f")}}function Mh(){var l;if(!Qe||U)return;if(!un||!le){Qe.style.display!=="none"&&(Qe.style.display="none",Je.clear(),ue.length=0,An.length=0,Is.length=0);return}Qe.style.display="";let n=zt&&vn,t=[Xn,Yn,_n,$n,Rs,$t,dn,be,Re,n].join();t!==Ta&&(Ta=t,Vn=!0),Vn&&Lh();let e=os?Jt(Un.get(),os+1,os):1,s=n||Un.isSet()&&e>0&&!Re;if(Qe.style.opacity=s?n?1:e*yr:0,!s)return;let i=Di(),o=i.width,a=i.height,r=$t,c=dc;if(c){for(let u=0;u<2;u++)if(Xe(u)&&c.thumb[u]){let f=Ve(u,o,a).add(((l=An[u])!=null?l:b()).scale(r/2));c.thumb[u].setAttribute("cx",f.x),c.thumb[u].setAttribute("cy",f.y)}for(let u=0;u=$t)return-1;if(i===1)return o;let r=a.subtract(t);n||(r.x*=-1);let c=i===2?r.xo:r&&Ve(a,t,e).distance(n)<2*s)return{role:"stick",side:a}}else if(Ln(a)>=1){let c=kh(a,n,t,e);if(c>=0)return{role:"face",btn:c}}}if(be){for(let a=0;a<2;a++)if(Wn(a)&&Ve(a,t,e).distance(n)<2*s)return;if(b(t/2,e/2).distance(n)h.getChannelData(v).set(x)),f.buffer=h,f.playbackRate.value=e,f.loop=i,a=a||mt.createGain(),a.gain.value=t,a.connect(We);let d=new StereoPannerNode(mt,{pan:z(s,-1,1)});f.connect(d).connect(a),f.addEventListener("ended",()=>{a.disconnect(),d.disconnect(),c&&c(f)});let y=r*e;return f.start(0,y),zt&&zn&&Et("sound","vol",t.toFixed(2),"rate",e.toFixed(2),"pan",s.toFixed(2),i?"loop":""),f}function Jh(...n){return Or([Mi(...n)])}function Mi(n=1,t=.05,e=220,s=0,i=0,o=.1,a=0,r=1,c=0,l=0,u=0,h=0,f=0,d=0,y=0,x=0,v=0,w=1,_=0,S=0,E=0){let A=Kn,T=Q*2,P=c*=500*T/A/A,F=e*=(1+yt(t,-t))*T/A,bt=0,ct=0,gt=0,wt=1,Ut,L=[],I=0,M=0,B=0,nt,ht=2,xt=T*ot(E)*2/A,dt=ut(xt),vt=rt(xt)/2/ht,Tt=1+vt,de=-2*dt/Tt,Me=(1-vt)/Tt,G=(1+ae(E)*dt)/2/Tt,J=-(ae(E)+dt)/Tt,Rt=G,Ie=0,X=0,Y=0,kt=0;for(s=s*A||9,_*=A,i*=A,o*=A,v*=A,l*=500*T/A**3,y*=T/A,u*=T/A,h*=A,f=f*A|0,Ut=s+_+i+o+v|0;M1?a>2?a>3?a>4?I/T%14?B:ae(B)*ot(B)**r)*(MM?0:(Mh&&(e+=u,F+=u,wt=0),f&&!(++ct%f)&&(e=F,c=P,wt||(wt=1));return L}function ri(n,t=!0){for(let e of an)if((!t||e.isSolid)&&n.arrayCheck(e.size)){let s=e.getCollisionData(n);if(s)return s}return 0}function Ze(n,t=b(),e,s=!0){for(let i of an)if((!s||i.isSolid)&&i.collisionTest(n,t,e))return i}function gc(n,t,e,s,i=!0){let o,a,r,c=s&&b();for(let l of an)if(!i||l.isSolid){let u=l.collisionRaycast(n,t,e,c);if(u){let h=n.distanceSquared(u);(o===void 0||h{j=!1,it.style.display="none",e.preventDefault(),Et("WebGL context lost! Switching to Canvas2d rendering.");for(let s of as)s.glTexture=void 0;ne=void 0,Dt=0,Cn=!1,bn.forEach(s=>{var i;return(i=s.glContextLost)==null?void 0:i.call(s)})}),it.addEventListener("webglcontextrestored",()=>{j=!0,it.style.display="",Et("WebGL context restored, reinitializing..."),t();for(let e of as)e.glTexture=ki(e.image,e.wrap);bn.forEach(e=>{var s;return(s=e.glContextRestored)==null?void 0:s.call(e)})});function t(){li=Hn(`#version 300 es
+`,o+=s.toString(),rn(o,Ht,24,V(),.05,void 0,"center","monospace")}{e.save(),e.fillStyle="#fff",e.textAlign="left",e.textBaseline="top",e.font="20px monospace",e.shadowColor="#000",e.shadowBlur=9;let a=9,r=0,c=24;if(Fe){e.fillText(`${Vs} v${Ws}`,a,r+=c/2),e.fillText("Time: "+or(ne),a,r+=c),e.fillText("FPS: "+qs.toFixed(1)+(j?" WebGL":" Canvas2D"),a,r+=c),e.fillText("Objects: "+_t.length,a,r+=c),e.fillText("Draw Calls: "+Le,a,r+=c),e.fillText("Primitives: "+Oe,a,r+=c),e.fillText("---------",a,r+=c),e.fillStyle="#f00",e.fillText("ESC: Debug Overlay",a,r+=c),e.fillStyle=ge?"#f00":"#fff",e.fillText("1: Debug Physics",a,r+=c),e.fillStyle=xn?"#f00":"#fff",e.fillText("2: Debug Particles",a,r+=c),e.fillStyle=vn?"#f00":"#fff",e.fillText("3: Debug Gamepads",a,r+=c),e.fillStyle=ye?"#f00":"#fff",e.fillText("4: Debug Raycasts",a,r+=c),e.fillStyle="#fff",e.fillText("5: Save Screenshot",a,r+=c),e.fillText("6: Toggle Video Capture",a,r+=c),e.fillStyle=zn?"#f00":"#fff",e.fillText("7: Debug Sound",a,r+=c);let l="",u="";for(let h in Z[0])Ft(h,0)&&(parseInt(h)<3?u+=h+" ":l+=h+" ");u&&e.fillText("Mouse: "+u,a,r+=c),l&&e.fillText("Keys: "+l,a,r+=c);for(let h=1;hs.push(r.data),i.onstop=()=>{let r=new Blob(s,{type:"video/webm"}),c=URL.createObjectURL(r);us(c,"capture.webm",1e3)};let o,a;if(Qt){a=new ConstantSourceNode(mt,{offset:0}),a.connect(We),a.start(),o=mt.createMediaStreamDestination(),We.connect(o);for(let r of o.stream.getAudioTracks())n.addTrack(r)}try{i.start()}catch{Et("Video capture not supported in this browser!"),a==null||a.stop();return}Et("Video capture started."),je={mediaRecorder:i,captureTimer:e,videoTrack:t,silentAudioSource:a,audioStreamDestination:o}}function ja(){var n,t,e;p(_e(),"Not capturing video!"),Et(`Video capture ended. ${je.captureTimer.get().toFixed(2)} seconds recorded.`),pe.style.display="none",(n=je.silentAudioSource)==null||n.stop(),(t=je.mediaRecorder)==null||t.stop(),(e=je.videoTrack)==null||e.stop(),je=void 0}function Bl(){p(_e(),"Not capturing video!"),vr(),je.videoTrack.requestFrame(),pe.textContent="\u25CF REC "+or(je.captureTimer)}function ie(n){if(Jt){let t=Object.keys(n),e={};t.forEach(s=>e[s]=n[s]),t.forEach(s=>{Object.defineProperty(n,s,{get:()=>e[s],set:i=>{p(!1,`Cannot modify engine constant. Attempted to set constant (${n}) property '${s}' to '${i}'.`)},enumerable:!0})})}return Object.freeze(n)}function ce(n,t=1){return(n%t+t)%t}function z(n,t=0,e=1){return ne?e:n}function Ut(n,t,e){return(e-=t)?z((n-t)/e):0}function $t(n,t,e){return n+z(e)*(t-n)}function Nl(n,t,e,s,i){return $t(s,i,Ut(n,t,e))}function nr(n,t,e=1){p(e>0,"distanceWrap wrapSize must be > 0");let s=(n-t)%e;return s*2%e-s}function Ja(n,t,e,s=1){return n+z(e)*nr(t,n,s)}function zl(n,t){return nr(n,t,2*Q)}function Jl(n,t,e){return Ja(n,t,e,2*Q)}function Xs(n){return n*n*(3-2*n)}function ls(n){return!(n&n-1)}function Ul(n){return 2**cs(Na(n))}function Ys(n,t,e,s=b()){let i=(n.x-e.x)*2,o=(n.y-e.y)*2,a=t.x+s.x,r=t.y+s.y;return ot(i)f)return!1;h=tt(y,h)}else{if(y0?r.x+1:r.x,x=h>0?r.y+1:r.y,v=c?(y-n.x)/c:1/0,w=l?(x-n.y)/l:1/0,_=0,S=v,E=w,A=fr.x&&(T.x=r.x+1-P),F.yr.y&&(T.y=r.y+1-P),s&&(A?s.set(-u,0):s.set(0,-h)),T}(A=SURL.revokeObjectURL(n),e)}function $l(n,t,e){var s;p(q(n),"shareURL requires title string"),p(q(t),"shareURL requires url string"),(s=navigator.share)==null||s.call(navigator,{title:n,url:t}).then(()=>e==null?void 0:e())}function Kl(n,t){p(q(n),"loadData requires saveName string");let e={};try{let s=localStorage[n];if(s)try{e=JSON.parse(s)}catch{Et("readSaveData: corrupt JSON for",n,"\u2014 using defaults")}}catch{Et("readSaveData: localStorage unavailable \u2014 using defaults")}return{...t,...e}}function Ql(n,t){p(q(n),"saveData requires saveName string");try{localStorage[n]=JSON.stringify(t)}catch{Et("writeSaveData: failed to write",n)}}function po(n){let t=(n|0)^2654435769;return t=Math.imul(t^t>>>16,2246822507),t=Math.imul(t^t>>>13,3266489909),t^=t>>>16,(t>>>0)/2**32}function Zl(n){let t=Pt(n);return $t(po(t),po(t+1),Xs(n-t))}function tu(n,t){let e=Pt(n),s=Pt(t),i=Xs(n-e),o=Xs(t-s),a=(r,c)=>po(r+c*374761393);return $t($t(a(e,s),a(e+1,s),i),$t(a(e,s+1),a(e+1,s+1),i),o)}function eu(n){Mt=n.copy()}function nu(n){nt=n}function su(n){K=n}function iu(n){rr=n}function ou(n){Ei=n}function ru(n){sn=n.copy()}function au(n){Mn=n.copy()}function cu(n){ss=n}function lu(n){In=n}function uu(n){kn=n.copy()}function ec(n){ar=n,N&&(N.style.imageRendering=n?"pixelated":""),it&&(it.style.imageRendering=n?"pixelated":"")}function hu(n){Tn=n}function du(n){on=n}function fu(n){Es=n}function pu(n){cr=n}function gu(n){U=n}function yu(n){if(n&&!wo){console.warn("Can not enable WebGL if it was disabled on start.");return}j=n,it&&(it.style.display=n?"":"none")}function mu(n){_s=n}function bu(n){_i=n.copy()}function xu(n){Ri=n}function vu(n){Pi=n}function Su(n){Li=n}function wu(n){lr=n}function Tu(n){ur=n}function Au(n){hr=n}function Cu(n){dr=n}function Eu(n){fr=n}function _u(n){Ne=n}function Ru(n){Yt=n.copy()}function Pu(n){$s=n}function Lu(n){Oi=n}function Ou(n){pr=n}function Du(n){is=n}function Mu(n){yn=n}function Iu(n){un=n}function ku(n){gr=n}function Gu(n){be=n}function Fu(n){Xn=n,n>0&&($n=!1)}function ju(n){_n=n,n&&(Yn=0)}function Bu(n){Yn=n,n>0&&(_n=!1)}function Nu(n){$n=n,n&&(Xn=0)}function zu(n){Rs=n}function Ju(n){dn=n}function Uu(n){Kt=n}function Vu(n){yr=n}function Wu(n){os=n}function qu(n){Ks=n}function Hu(n){Ps=n}function Xu(n){Qt=n}function Yu(n){Sn=n,Qt&&!U&&We&&(We.gain.value=n)}function $u(n){mr=n}function Ku(n){br=n}function Qu(n){Ci=n}function Zu(n){ka=n}function Qs(n){return n.r>=1&&n.g>=1&&n.b>=1}function xr(n){return n.r<=0&&n.g<=0&&n.b<=0&&n.a<=0}function Ls(n=0,t=_i,e=0,s=Ri,i=Pi){if(p(O(n)||typeof n=="number","index must be a vec2 or number"),p(O(t)||typeof t=="number","size must be a vec2 or number"),p(R(e)||e instanceof He,"texture must be a number or TextureInfo"),p(R(s),"padding must be a number"),U)return new De;typeof t=="number"&&(p(t>0),t=new ut(t,t));let o=typeof e=="number"?hn[e]:e;p(o instanceof He,"tile texture is not loaded"),p(o.size.x>0,"tile texture is not loaded");let a=t.x+s*2,r=t.y+s*2,c,l;if(typeof n=="number"){let h=o.size.x/a|0;c=n%h,l=n/h|0}else c=n.x,l=n.y;let u=new ut(c*a+s,l*r+s);return new De(u,t,o,s,i)}function jt(n,t=b(1),e,s=H,i=0,o,a,r=j,c=!1,l){var f;p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(W(s),"color is invalid"),p(R(i),"angle must be a number"),p(!a||W(a),"additiveColor must be a color"),p(!l||!r,"context only supported in canvas 2D mode");let u=e==null?void 0:e.textureInfo,h=(f=e==null?void 0:e.bleed)!=null?f:0;if(r&&j)if(p(!!g,"WebGL is not enabled!"),c&&([n,t,i]=Ds(n,t,i)),u){let d=u.sizeInverse,y=e.pos.x*d.x,x=e.pos.y*d.y,v=e.size.x*d.x,w=e.size.y*d.y;if(kr(u.glTexture),h){let _=d.x*h,S=d.y*h;Ss(n.x,n.y,o?-t.x:t.x,t.y,i,y+_,x+S,y-_+v,x-S+w,s.rgbaInt(),a&&a.rgbaInt())}else Ss(n.x,n.y,o?-t.x:t.x,t.y,i,y,x,y+v,x+w,s.rgbaInt(),a&&a.rgbaInt())}else{let d=a?s.add(a):s;wc(n.x,n.y,t.x,t.y,i,d.rgbaInt())}else++Le,++Oe,Rn(n,t,i,o,d=>{if(u){d.scale(1,-1);let y=e.pos.x,x=e.pos.y,v=e.size.x,w=e.size.y;lh(d,u.image,y,x,v,w,-.5,-.5,1,1,s,a,h)}else{let y=a?s.add(a):s;d.fillStyle=y.toString(),d.fillRect(-.5,-.5,1,1)}},c,l)}function Zs(n,t,e,s,i,o,a){jt(n,t,void 0,e,s,!1,void 0,i,o,a)}function th(n,t,e=H,s=ln,i=0,o=j,a=!1,r){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(W(e)&&W(s),"color is invalid"),p(R(i),"angle must be a number"),p(!r||!o,"context only supported in canvas 2D mode"),o&&j){p(!!g,"WebGL is not enabled!"),a&&(n=Os(n),t=t.scale(1/K),i+=nt);let c=[],l=[],u=t.x/2,h=t.y/2,f=e.rgbaInt(),d=s.rgbaInt(),y=ht(-i),x=rt(-i);for(let v=4;v--;){let w=v&1?u:-u,_=v&2?h:-h,S=w*y-_*x,E=w*x+_*y,A=v&2?f:d;c.push(b(n.x+S,n.y+E)),l.push(A)}Nr(c,l)}else++Le,++Oe,Rn(n,t,i,!1,c=>{let l=c.createLinearGradient(0,.5,0,-.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.fillRect(-.5,-.5,1,1)},a,r)}function eh(n,t,e,s=0,i=H,o=0,a,r=j,c=!1,l){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(O(e),"wrapCount must be a vec2"),p(W(i),"color is invalid"),p(R(o),"angle must be a number"),p(!a||W(a),"additiveColor must be a color"),p(!l||!r,"context only supported in canvas 2D mode"),p(!(s instanceof De),"pass a TextureInfo or texture index, not a TileInfo \u2014 use tileInfo.textureInfo"),U)return;let u=typeof s=="number"?hn[s]:s;if(p(u instanceof He,"texture not loaded"),p(u.size.x>0,"texture not loaded"),p(u.wrap,"drawTextureWrapped requires a wrap-enabled texture; call textureInfo.setWrap(true) first"),r&&j){p(!!g,"WebGL is not enabled!"),c&&([n,t,o]=Ds(n,t,o)),kr(u.glTexture),Ss(n.x,n.y,t.x,t.y,o,0,0,e.x,e.y,i.rgbaInt(),a&&a.rgbaInt());return}++Le,++Oe,c||(n=Pn(n),t=t.scale(K),o-=nt);let h=!Ei||(a?Qs(i.add(a))&&a.a<=0:Qs(i)),f=!h&&a&&!xr(a),d=h?u.image:ch(u.image,i,a);l=l||Ot,l.save(),l.translate(n.x+.5,n.y+.5),l.rotate(o),l.globalAlpha=f?1:i.a;let y=l.createPattern(d,"repeat"),x=new DOMMatrix().translate(-t.x/2,-t.y/2).scale(t.x/(e.x*d.width),t.y/(e.y*d.height));y.setTransform(x),l.fillStyle=y,l.fillRect(-t.x/2,-t.y/2,t.x,t.y),l.globalAlpha=1,l.restore()}function go(n,t=.1,e=H,s=!1,i=b(),o=0,a=j,r=!1,c){if(p(me(n),"points must be an array"),p(R(t),"width must be a number"),p(W(e),"color is invalid"),p(O(i),"pos must be a vec2"),p(R(o),"angle must be a number"),p(!c||!a,"context only supported in canvas 2D mode"),a&&j){p(!!g,"WebGL is not enabled!");let l=b(1);r&&([i,l,o]=Ds(i,l,o)),Br(n,e.rgbaInt(),t,i.x,i.y,l.x,l.y,o,s)}else++Le,++Oe,Rn(i,b(1),o,!1,l=>{l.strokeStyle=e.toString(),l.lineWidth=t,l.beginPath();for(let u=0;u0&&Br(n,s.rgbaInt(),e,i.x,i.y,l.x,l.y,o)}else Rn(i,b(1),o,!1,l=>{l.fillStyle=t.toString(),l.beginPath();for(let u of n)l.lineTo(u.x,u.y);l.closePath(),l.fill(),e&&(l.strokeStyle=s.toString(),l.lineWidth=e,l.stroke())},r,c)}function sc(n,t=b(1),e=H,s=0,i=0,o=at,a=j,r=!1,c){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(W(e)&&W(o),"color is invalid"),p(R(s),"angle must be a number"),p(R(i),"lineWidth must be a number"),p(i>=0,"lineWidth must be a positive value or 0"),p(!c||!a,"context only supported in canvas 2D mode"),i=z(i,0,st(t.x,t.y)),a&&j?nc(n,t,_s,e,i,o,s,a,r,c):Rn(n,b(1),s,!1,l=>{l.fillStyle=e.toString(),l.beginPath(),l.ellipse(0,0,t.x/2,t.y/2,0,0,9),l.fill(),i&&(l.strokeStyle=o.toString(),l.lineWidth=i,l.stroke())},r,c)}function ti(n,t=1,e=H,s=0,i=at,o=j,a=!1,r){p(R(t),"size must be a number"),sc(n,b(t),e,0,s,i,o,a,r)}function ic(n,t=b(1),e=H,s=ln,i=0,o=j,a=!1,r){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(W(e)&&W(s),"color is invalid"),p(R(i),"angle must be a number"),p(!r||!o,"context only supported in canvas 2D mode"),!U)if(o&&j){p(!!g,"WebGL is not enabled!"),a&&(n=Os(n),t=t.scale(1/K),i+=nt);let c=_s,l=t.x/2,u=t.y/2,h=e.rgbaInt(),f=s.rgbaInt(),d=nh++,y=ht(-i),x=rt(-i),v=E=>{let A=rt(E)*l,T=ht(E)*u;return b(n.x+A*y-T*x,n.y+A*x+T*y)},w=d%c/c*Q*2,_=[v(w)],S=[f];for(let E=c;E--;){let A=(E+d)%c/c*Q*2;_.push(n),S.push(h),_.push(v(A)),S.push(f)}Nr(_,S)}else++Le,++Oe,Rn(n,t,i,!1,c=>{let l=c.createRadialGradient(0,0,0,0,0,.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.beginPath(),c.ellipse(0,0,.5,.5,0,0,9),c.fill()},a,r)}function sh(n,t=1,e=H,s=ln,i=j,o=!1,a){p(R(t),"size must be a number"),ic(n,b(t),e,s,0,i,o,a)}function Rn(n,t,e=0,s=!1,i,o=!1,a=Ot){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(R(e),"angle must be a number"),p(typeof i=="function","drawFunction must be a function"),o||(n=Pn(n),t=t.scale(K),e-=nt),a.save(),a.translate(n.x+.5,n.y+.5),a.rotate(e),a.scale(s?-t.x:t.x,-t.y),i(a),a.restore()}function ih(n,t,e=1,s=H,i=0,o=at,a="center",r=Es,c="",l,u=0,h=Ot){t=Pn(t),e*=K,i*=K,u-=nt,u*=-1,rn(n,t,e,s,i,o,a,r,c,l,u,h)}function rn(n,t,e,s=H,i=0,o=at,a="center",r=Es,c="",l,u=0,h=Ot){p(q(n),"text must be a string"),p(O(t),"pos must be a vec2"),p(R(e),"size must be a number"),p(W(s),"color must be a color"),p(R(i),"lineWidth must be a number"),p(W(o),"lineColor must be a color"),p(["left","center","right"].includes(a),"align must be left, center, or right"),p(q(r),"font must be a string"),p(q(c),"fontStyle must be a string"),p(R(u),"angle must be a number");let f=(n+"").split(`
+`),d=t.y-(f.length-1)*e/2;h.save(),h.fillStyle=s.toString(),h.strokeStyle=o.toString(),h.lineWidth=i,h.textAlign=a,h.font=c+" "+e+"px "+r,h.textBaseline="middle",h.translate(t.x,d),h.rotate(-u);let y=0;f.forEach(x=>{i&&h.strokeText(x,0,y,l),h.fillText(x,0,y,l),y+=e}),h.restore()}async function wa(n,t){p(R(n),"textureIndex must be a number"),p(!hn[n],"textureIndex is already loaded!"),p(!t||q(t),"image src must be a string");let e=new Image;t&&await new Promise(s=>{e.onerror=e.onload=s,e.crossOrigin="anonymous",e.src=t}),hn[n]=new He(e)}function Os(n){p(O(n),"screenPos must be a vec2");let t=(n.x-k.x/2+.5)/K,e=(n.y-k.y/2+.5)/-K;if(nt){let s=ht(-nt),i=rt(-nt),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new ut(t+Mt.x,e+Mt.y)}function Pn(n){p(O(n),"worldPos must be a vec2");let t=n.x-Mt.x,e=n.y-Mt.y;if(nt){let s=ht(nt),i=rt(nt),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new ut(t*K+k.x/2-.5,e*-K+k.y/2-.5)}function oc(n){p(O(n),"screenDelta must be a vec2");let t=n.x/K,e=n.y/-K;if(nt){let s=ht(-nt),i=rt(-nt),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new ut(t,e)}function oh(n){p(O(n),"worldDelta must be a vec2");let t=n.x,e=n.y;if(nt){let s=ht(nt),i=rt(nt),o=t*s-e*i,a=t*i+e*s;t=o,e=a}return new ut(t*K,e*-K)}function Ds(n,t,e=0){return p(O(n),"screenPos must be a vec2"),p(O(t),"screenSize must be a vec2"),p(R(e),"screenAngle must be a number"),[Os(n),t.scale(1/K),e+nt]}function rc(){return k.scale(1/K)}function rh(n,t,e,s){p(O(n),"center must be a vec2"),p(O(t),"size must be a vec2");let i=f(e),o=f(s),a=t.x+i.left+i.right,r=t.y+i.top+i.bottom,c=k.x-o.left-o.right,l=k.y-o.top-o.bottom;if(!(a>0&&r>0&&c>0&&l>0))return K;K=st(c/a,l/r);let u=b(i.right-i.left,i.top-i.bottom).scale(.5),h=b(o.right-o.left,o.top-o.bottom).scale(.5/K);return Mt=n.add(u).add(h),K;function f(d){return(d===void 0||R(d))&&(d=b(d)),O(d)?{top:d.y,right:d.x,bottom:d.y,left:d.x}:{top:d.top||0,right:d.right||0,bottom:d.bottom||0,left:d.left||0}}}function ah(n,t=0){if(p(O(n),"pos must be a vec2"),p(O(t)||R(t),"size must be a vec2 or number"),!K)return!1;let e=n.x-Mt.x,s=n.y-Mt.y;if(nt){let a=ht(nt),r=rt(nt),c=e*a-s*r,l=e*r+s*a;e=c,s=l}e*=K*2,s*=-K*2,t instanceof ut&&(t=t.length()),t*=K;let i=k.x,o=k.y;return e+t>-i&&e-t-o&&s-t{n.onerror=n.onload=r,n.crossOrigin="anonymous",n.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAAeAQMAAABnrVXaAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAAjpJREFUOMu9kzFu2zAUhn+CAROgqrk+B2l0BWYxMjlXeYaAtFtbdA1sGgHqRQfI0CNkSG5AwYB0BQ8d5Bsomwah6CPVeGg6tEPzAxLwyI+P78cP4u9lNO9OoMKnLMOobG5020/yaj/MrRcCGh1gBbyiLTPJEYaIiom5KM9Jq7KgynMGtb6L4GL4MF2H4LQKCXTvDVw2I4MsgZT7QLExdiutH+D08VOP3INXRrWX1/mmpbkNgAPYRVANb4xpcegYvhiNbIXauQICEjBuYLfMakaakWQeXxiZ0VDtuJCKs3ztMV59QtsHJNcRxDzfdL21ty3PrfIcXTN+E+GFAv6T5nbT9jd50/WFxb5ksdAv49qS6ouymG66ji08UMT6moykYLAo+V0j23GN4m829ZySAD5K7QsBfQTvOG8eE+gTeGYRAmnNAubN3hf5Zv9tJWDHp/VTuaSm7SN4fyINQqaNO3RMVxvpSPXnOChnRNvFcGY0gnwiPswYwTKVPE0zVtX3mTEIOoFzaqLrGuJaV+Uqumb71fVk/VoOH3cdLNQP/FHi8hV0CQNoqBZsUPlLPMsdCJro9QAaQQ0woDy9BJm0eTxCFnO9srcYlhNVlfR2EyTrph1uUtbUtAJifwRgrKuYdXVHeb0YI3QpawohQHkloI3J5FuVwI5ORxC9k2Tuz9Ir1IjgeIPGMHYkAZe2RuYkmWFmt3gGbTPOmBUWVTmRmHtGrfpzG/yuQNOKa6gBB/WA9khitPgl6/GP+gl2Af6tCbvaygAAAABJRU5ErkJggg=="});let t=b(),e=b(8),s=1,i=0,o=new He(n),a=new De(t,e,o,s,i);cc=new ei(a)}function fh(n=!0){Gn=n}function ph(n){Tr=n}function gh(){return en==="mouse"}function yh(){return en==="keyboard"}function mh(){return en==="gamepad"}function Ar(n,t=0,e=!0,s=!0,i=!0){Z[t]&&(Z[t][n]&=~((e?1:0)|(s?2:0)|(i?4:0)))}function Ms(){Z.length=0,Z[0]=[],ue.length=0,An.length=0,Is.length=0,Ae.length=0,pn.length=0}function Ft(n,t=0){var e;return p(q(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Z[t])==null?void 0:e[n])&1)}function Nt(n,t=0){var e;return p(q(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Z[t])==null?void 0:e[n])&2)}function Cr(n,t=0){var e;return p(q(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Z[t])==null?void 0:e[n])&4)}function bh(n="ArrowUp",t="ArrowDown",e="ArrowLeft",s="ArrowRight"){p(q(n),"up key must be a string"),p(q(t),"down key must be a string"),p(q(e),"left key must be a string"),p(q(s),"right key must be a string");let i=o=>Ft(o)?1:0;return b(i(s)-i(e),i(n)-i(t))}function rs(n){return p(R(n),"mouse button must be a number"),Ft(n)}function ds(n){return p(R(n),"mouse button must be a number"),Nt(n)}function xh(n){return p(R(n),"mouse button must be a number"),Cr(n)}function Ge(n,t=At){return p(R(n),"button must be a number"),p(R(t),"gamepad must be a number"),Ft(n,t+1)}function Er(n,t=At){return p(R(n),"button must be a number"),p(R(t),"gamepad must be a number"),Nt(n,t+1)}function vh(n,t=At){return p(R(n),"button must be a number"),p(R(t),"gamepad must be a number"),Cr(n,t+1)}function fs(n,t=At){var e,s;return p(R(n),"stick must be a number"),p(R(t),"gamepad must be a number"),(s=(e=Ae[t])==null?void 0:e[n])!=null?s:b()}function yo(n=At){var t;return p(R(n),"gamepad must be a number"),(t=pn[n])!=null?t:b()}function mo(n=At){return p(R(n),"gamepad must be a number"),!!Z[n+1]}function lc(n=At){var t,e;return p(R(n),"gamepad must be a number"),(e=(t=Ae[n])==null?void 0:t.length)!=null?e:0}function Sh(n=At,t=200,e=1,s=1,i=0){var a,r,c;if(p(R(n),"gamepad must be a number"),!Ps||U)return;let o=(a=navigator==null?void 0:navigator.getGamepads)==null?void 0:a.call(navigator)[n];(c=(r=o==null?void 0:o.vibrationActuator)==null?void 0:r.playEffect)==null||c.call(r,"dual-rumble",{duration:t,strongMagnitude:e,weakMagnitude:s,startDelay:i})}function wh(n=At){var e,s,i;if(p(R(n),"gamepad must be a number"),!Ps||U)return;let t=(e=navigator==null?void 0:navigator.getGamepads)==null?void 0:e.call(navigator)[n];(i=(s=t==null?void 0:t.vibrationActuator)==null?void 0:s.reset)==null||i.call(s)}function _r(n=100){var t;p(R(n)||me(n),"pattern must be a number or array"),Ps&&!U&&((t=navigator==null?void 0:navigator.vibrate)==null||t.call(navigator,n))}function Th(){_r(0)}function Ah(){var n;!le&&((n=N.requestPointerLock)==null||n.call(N))}function Ch(){var n;(n=document.exitPointerLock)==null||n.call(document)}function uc(){return document.pointerLockElement===N}function Eh(){if(U)return;document.addEventListener("keydown",n),document.addEventListener("keyup",t),document.addEventListener("mousedown",s),document.addEventListener("mouseup",i),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",a),document.addEventListener("wheel",r,{passive:!1}),document.addEventListener("contextmenu",c),document.addEventListener("blur",l),le&&yn&&u();function n(f){if(f.repeat||(Z[0][f.code]=3,is&&(Z[0][e(f.code)]=3)),!Gn||!f.cancelable||!document.hasFocus()||f.ctrlKey||f.metaKey||f.altKey||x(f.target)||x(document.activeElement))return;let d=typeof f.key=="string"&&f.key.length===1;(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Space","Tab","Backspace"].includes(f.code)||d)&&f.preventDefault();function x(v){let w=v==null?void 0:v.tagName;return(v==null?void 0:v.isContentEditable)||["INPUT","TEXTAREA","SELECT"].includes(w)}}function t(f){Z[0][f.code]=Z[0][f.code]&2|4,is&&(Z[0][e(f.code)]=4)}function e(f){return is?f==="KeyW"?"ArrowUp":f==="KeyS"?"ArrowDown":f==="KeyA"?"ArrowLeft":f==="KeyD"?"ArrowRight":f:f}function s(f){if(le&&yn)return;Qt&&!U&&mt&&!gs()&&mt.resume(),Z[0][f.button]=3;let d=Ht;Ht=h(b(f.x,f.y)),Te=Te.add(Ht.subtract(d)),Gn&&f.cancelable&&document.hasFocus()&&f.preventDefault()}function i(f){le&&yn||(Z[0][f.button]=Z[0][f.button]&2|4)}function o(f){ni=!0;let d=Ht;Ht=h(b(f.x,f.y));let y=uc()?b(f.movementX,f.movementY):Ht.subtract(d);Te=Te.add(y)}function a(){ni=!1}function r(f){f.ctrlKey||(wr+=ae(f.deltaY)),Gn&&f.cancelable&&document.hasFocus()&&f.preventDefault()}function c(f){f.preventDefault()}function l(){Ms(),Je.clear(),ue.length=0,An.length=0,Is.length=0}function u(){document.addEventListener("touchstart",y=>d(y),{passive:!1}),document.addEventListener("touchmove",y=>d(y),{passive:!1}),document.addEventListener("touchend",y=>d(y),{passive:!1});let f;function d(y){if(yn){if(Qt&&!U&&mt&&!gs()&&mt.resume(),!un||gr){let x=S=>ps.includes(S.target)||S.target===gn,v=[];for(let S of y.touches)x(S)||v.push(S);let w=v.length,_=0;if(w){let S=b(v[0].clientX,v[0].clientY),E=Ht;Ht=h(S),f?Te=Te.add(Ht.subtract(E)):Z[0][_]=3}else f&&(Z[0][_]=Z[0][_]&2|4);f=w}return Gn&&y.cancelable&&document.hasFocus()&&y.preventDefault(),!0}}}function h(f){let d=N.getBoundingClientRect(),y=Ut(f.x,d.left,d.right),x=Ut(f.y,d.top,d.bottom);return b(y*N.width,x*N.height)}}function Aa(){if(U)return;!(yn&&le)&&!document.hasFocus()&&Ms(),ke=Os(Ht),Sr=oc(Te),Rh(),t(),n();function n(){let e=rs(0)||rs(1)||rs(2)||Te.length()>Tr,s=!1;for(let o=lc();o--&&!s;)s=fs(o).lengthSquared()>.04;for(let o=17;o--&&!s;)s=Ge(o);let i=!1;for(let o in Z[0])if(isNaN(+o)&&Z[0][o]&1){i=!0;break}s?en="gamepad":e?en="mouse":i&&(en="keyboard"),jn=en==="gamepad"}function t(){var a,r,c,l,u,h,f;let e=d=>{let v=w=>w>.3?Ut(w,.3,.8):w<-.3?-Ut(-w,.3,.8):0;return b(v(d.x),v(-d.y)).clampLength()};if(un&&le){if(p(!_n||!Yn,"set touchGamepadLeftStick or touchGamepadLeftButtonCount, not both"),p(!$n||!Xn,"set touchGamepadRightStick or touchGamepadButtonCount, not both"),!Un.isSet())return;At=0;let d=(a=Ae[0])!=null?a:Ae[0]=[],y=(r=pn[0])!=null?r:pn[0]=b();d.length=0,y.set();for(let v=0;v<2;v++){if(!Xe(v))continue;let w=Lr(v);d[w]=b();let _=(c=An[v])!=null?c:b();if(Rs)d[w]=e(_);else if(_.lengthSquared()>.3){let S=z(Hs(_.x),-1,1),E=z(Hs(_.y),-1,1);d[w]=b(S,-E).clampLength(),w||y.set(S,-E)}}let x=(l=Z[1])!=null?l:Z[1]=[];for(let v=12;v--;){let w=Ge(v,0);x[v]=ue[v]?w?1:3:w?4:0,Ks&&x[v]===3&&(v===9||Ph(v))&&_r(Ks)}return}try{if(!Oi||!(navigator!=null&&navigator.getGamepads))return}catch{return}if(!Jt&&!document.hasFocus())return;let s=8,i=navigator.getGamepads(),o=st(s,i.length);for(let d=0;d>1]=e(b(y.axes[S],y.axes[S+1]));let _=!1;for(let S=y.buttons.length;S--;){let E=y.buttons[S],A=Ge(S,d);x[S]=E.pressed?A?1:3:A?4:0,E.pressed&&(!E.value||E.value>.9)&&(_=!0)}_&&(ro[d]=!0,ro[At]||(At=d)),y.mapping==="standard"&&w.set((Ge(15,d)&&1)-(Ge(14,d)&&1),(Ge(12,d)&&1)-(Ge(13,d)&&1)),pr&&(w.x||w.y)&&(v[0]=w.clampLength())}un&&jn&&Un.unset()}}function Ca(){if(!U){for(let n of Z)for(let t in n)n[t]&=1;wr=0,Sr=b(),Te=b()}}function _h(){Mh()}function Rh(){if(Qe||!un||!le||U||!document.body)return;let n=Qe=document.createElement("div");n.style.cssText="position:fixed;inset:0;z-index:50;pointer-events:none;opacity:0;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;transition:opacity .2s;box-sizing:border-box;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)";let t=hc=document.createElement("div");t.style.cssText="position:relative;width:100%;height:100%;pointer-events:none",n.appendChild(t);let e=Rr=document.createElementNS(ii,"svg");e.style.cssText="position:absolute;inset:0;width:100%;height:100%;pointer-events:none;overflow:visible;fill:none;stroke:#fff;stroke-width:3",t.appendChild(e);let s=()=>{let i=document.createElement("div");return i.style.cssText="position:absolute;pointer-events:auto;touch-action:none",i.addEventListener("pointerdown",o=>Fh(o,i)),i.addEventListener("pointermove",o=>jh(o)),i.addEventListener("pointerup",o=>Ea(o)),i.addEventListener("pointercancel",o=>Ea(o)),t.appendChild(i),i};ps[0]=s(),ps[1]=s(),gn=s(),addEventListener("resize",()=>Vn=!0),document.body.appendChild(n),Vn=!0}function Di(){return hc.getBoundingClientRect()}function Xe(n){return n?$n:_n}function Ln(n){return n?Xn:Yn}function Pr(n){return n?0:4}function Lr(n){return n&&_n?1:0}function Wn(n){return Xe(n)||Ln(n)>0}function Ph(n){for(let t=0;t<2;t++){let e=Pr(t);if(!Xe(t)&&n>=e&&no.style.cssText="position:absolute;pointer-events:auto;touch-action:none;"+a;if(Re){for(let o of ps)o.style.display="none";be?(i(gn,"inset:0"),gn.style.display=""):gn.style.display="none"}else{for(let a=0;a<2;a++){let r=ps[a],c=a?"right":"left";if(r.style.display=Wn(a)?"":"none",dn){let l=Wn(a?0:1)?"50%":"100%";i(r,`${c}:0;bottom:0;width:${l};height:60%`)}else i(r,`${c}:0;bottom:0;width:${3*s}px;height:${3*s}px`)}gn.style.display=be?"":"none";let o=be;i(gn,`left:50%;top:50%;width:${2*o}px;height:${2*o}px;transform:translate(-50%,-50%)`)}Oh(t,e),Vn=!1}function Oh(n,t){let e=Rr;for(;e.firstChild;)e.removeChild(e.firstChild);let s=dc={face:[],thumb:[]},i=Kt,o=(r,c,l,u)=>{let h=document.createElementNS(ii,"circle");return h.setAttribute("cx",r),h.setAttribute("cy",c),h.setAttribute("r",l),u&&h.setAttribute("fill",u),e.appendChild(h),h},a=r=>{let c=i*.18,l=i*.5,u=r.x,h=r.y,f=document.createElementNS(ii,"path");f.setAttribute("d",`M ${u-c} ${h-l} H ${u+c} V ${h-c} H ${u+l} V ${h+c} H ${u+c} V ${h+l} H ${u-c} V ${h+c} H ${u-l} V ${h-c} H ${u-c} Z`),e.appendChild(f)};for(let r=0;r<2;r++){let c=Ln(r),l=Pr(r),u=Ve(r,n,t);if(Xe(r))Rs?o(u.x,u.y,i/2):a(u),s.thumb[r]=o(u.x,u.y,i/4,"#fff");else if(c===1)s.face[l]=o(u.x,u.y,i/2,"#000");else for(let h=0;h2?f:st(f,c-1);d=d===3?2:d===2?3:d;let y=b().setDirection(f,i/2);c===2&&(y.x*=-1),r||(y.x*=-1);let x=u.add(y);s.face[l+d]=o(x.x,x.y,i/4,"#000")}}Jt&&vn&&Dh(n,t)}function Dh(n,t){let e=Kt,s=Rr,i=(a,r,c)=>{let l=document.createElementNS(ii,a);for(let u in r)l.setAttribute(u,r[u]);l.setAttribute("stroke",c),l.setAttribute("stroke-width",2),l.setAttribute("fill","none"),s.appendChild(l)},o=(a,r,c)=>i("circle",{cx:a.x,cy:a.y,r},c);i("line",{x1:n/2,y1:0,x2:n/2,y2:t},"#0f0");for(let a=0;a<2;a++)if(Xe(a))if(dn){let r=t*.4,c=!Wn(a?0:1),l=c?0:a?n/2:0;i("rect",{x:l,y:r,width:c?n:n/2,height:t-r},"#0ff")}else o(Ve(a,n,t),2*e,"#0ff");else Ln(a)>=1&&o(Ve(a,n,t),e,"#0ff");if(be){o(b(n/2,t/2),be,"#ff0");for(let a=0;a<2;a++)Wn(a)&&o(Ve(a,n,t),2*e,"#f0f")}}function Mh(){var l;if(!Qe||U)return;if(!un||!le){Qe.style.display!=="none"&&(Qe.style.display="none",Je.clear(),ue.length=0,An.length=0,Is.length=0);return}Qe.style.display="";let n=Jt&&vn,t=[Xn,Yn,_n,$n,Rs,Kt,dn,be,Re,n].join();t!==Ta&&(Ta=t,Vn=!0),Vn&&Lh();let e=os?Ut(Un.get(),os+1,os):1,s=n||Un.isSet()&&e>0&&!Re;if(Qe.style.opacity=s?n?1:e*yr:0,!s)return;let i=Di(),o=i.width,a=i.height,r=Kt,c=dc;if(c){for(let u=0;u<2;u++)if(Xe(u)&&c.thumb[u]){let f=Ve(u,o,a).add(((l=An[u])!=null?l:b()).scale(r/2));c.thumb[u].setAttribute("cx",f.x),c.thumb[u].setAttribute("cy",f.y)}for(let u=0;u=Kt)return-1;if(i===1)return o;let r=a.subtract(t);n||(r.x*=-1);let c=i===2?r.xo:r&&Ve(a,t,e).distance(n)<2*s)return{role:"stick",side:a}}else if(Ln(a)>=1){let c=kh(a,n,t,e);if(c>=0)return{role:"face",btn:c}}}if(be){for(let a=0;a<2;a++)if(Wn(a)&&Ve(a,t,e).distance(n)<2*s)return;if(b(t/2,e/2).distance(n)h.getChannelData(v).set(x)),f.buffer=h,f.playbackRate.value=e,f.loop=i,a=a||mt.createGain(),a.gain.value=t,a.connect(We);let d=new StereoPannerNode(mt,{pan:z(s,-1,1)});f.connect(d).connect(a),f.addEventListener("ended",()=>{a.disconnect(),d.disconnect(),c&&c(f)});let y=r*e;return f.start(0,y),Jt&&zn&&Et("sound","vol",t.toFixed(2),"rate",e.toFixed(2),"pan",s.toFixed(2),i?"loop":""),f}function Jh(...n){return Or([Mi(...n)])}function Mi(n=1,t=.05,e=220,s=0,i=0,o=.1,a=0,r=1,c=0,l=0,u=0,h=0,f=0,d=0,y=0,x=0,v=0,w=1,_=0,S=0,E=0){let A=Kn,T=Q*2,P=c*=500*T/A/A,F=e*=(1+yt(t,-t))*T/A,bt=0,ct=0,gt=0,wt=1,Vt,L=[],I=0,M=0,B=0,et,dt=2,xt=T*ot(E)*2/A,ft=ht(xt),vt=rt(xt)/2/dt,Tt=1+vt,de=-2*ft/Tt,Me=(1-vt)/Tt,G=(1+ae(E)*ft)/2/Tt,J=-(ae(E)+ft)/Tt,Rt=G,Ie=0,X=0,Y=0,kt=0;for(s=s*A||9,_*=A,i*=A,o*=A,v*=A,l*=500*T/A**3,y*=T/A,u*=T/A,h*=A,f=f*A|0,Vt=s+_+i+o+v|0;M1?a>2?a>3?a>4?I/T%14?B:ae(B)*ot(B)**r)*(MM?0:(Mh&&(e+=u,F+=u,wt=0),f&&!(++ct%f)&&(e=F,c=P,wt||(wt=1));return L}function ri(n,t=!0){for(let e of an)if((!t||e.isSolid)&&n.arrayCheck(e.size)){let s=e.getCollisionData(n);if(s)return s}return 0}function Ze(n,t=b(),e,s=!0){for(let i of an)if((!s||i.isSolid)&&i.collisionTest(n,t,e))return i}function gc(n,t,e,s,i=!0){let o,a,r,c=s&&b();for(let l of an)if(!i||l.isSolid){let u=l.collisionRaycast(n,t,e,c);if(u){let h=n.distanceSquared(u);(o===void 0||h{j=!1,it.style.display="none",e.preventDefault(),Et("WebGL context lost! Switching to Canvas2d rendering.");for(let s of as)s.glTexture=void 0;se=void 0,Dt=0,Cn=!1,bn.forEach(s=>{var i;return(i=s.glContextLost)==null?void 0:i.call(s)})}),it.addEventListener("webglcontextrestored",()=>{j=!0,it.style.display="",Et("WebGL context restored, reinitializing..."),t();for(let e of as)e.glTexture=ki(e.image,e.wrap);bn.forEach(e=>{var s;return(s=e.glContextRestored)==null?void 0:s.call(e)})});function t(){li=Hn(`#version 300 es
 precision highp float;uniform mat4 m;in vec2 g;in vec4 p,u,c,a;in float r;out vec2 v;out vec4 d,e;void main(){vec2 s=(g-.5)*p.zw;gl_Position=m*vec4(p.xy+s*cos(r)-vec2(-s.y,s)*sin(r),1,1);v=mix(u.xw,u.zy,g);d=c;e=a;}`,`#version 300 es
 precision highp float;uniform sampler2D s;in vec2 v;in vec4 d,e;out vec4 c;void main(){c=texture(s,v)*d+e;}`),ui=Hn(`#version 300 es
 precision highp float;uniform mat4 m;in vec2 p;in vec4 c;out vec4 d;void main(){gl_Position=m*vec4(p,1,1);d=c;}`,`#version 300 es
-precision highp float;in vec4 d;out vec4 c;void main(){c=d;}`);let e=new ArrayBuffer(di);Nt=new Float32Array(e),xs=new Uint32Array(e),xo=g.createBuffer(),Bn=g.createBuffer(),Mr=g.createFramebuffer(),Dt=0;let s=new Float32Array([0,0,1,0,0,1,1,1]);g.bindBuffer(g.ARRAY_BUFFER,Bn),g.bufferData(g.ARRAY_BUFFER,s,g.STATIC_DRAW);let i,o,a,r=(c,l,u,h,f=0)=>{let d=g.getAttribLocation(o,c),y=u===1,x=u&&a;g.enableVertexAttribArray(d),g.vertexAttribPointer(d,h,l,y,x,i),g.vertexAttribDivisor(d,f),i+=h*u};vo=g.createVertexArray(),g.bindVertexArray(vo),i=0,o=li,a=yc,g.bindBuffer(g.ARRAY_BUFFER,Bn),r("g",g.FLOAT,0,2),g.bindBuffer(g.ARRAY_BUFFER,xo),g.bufferData(g.ARRAY_BUFFER,di,g.DYNAMIC_DRAW),r("p",g.FLOAT,4,4,1),r("u",g.FLOAT,4,4,1),r("c",g.UNSIGNED_BYTE,1,4,1),r("a",g.UNSIGNED_BYTE,1,4,1),r("r",g.FLOAT,4,1,1),So=g.createVertexArray(),g.bindVertexArray(So),i=0,o=ui,a=mc,r("p",g.FLOAT,4,2),r("c",g.UNSIGNED_BYTE,1,4)}}function vs(n=!1){!n&&!Cn||(It(),Cn=!1,g.useProgram(li),g.bindVertexArray(vo))}function bc(){Cn||(It(),Cn=!0,g.useProgram(ui),g.bindVertexArray(So))}function To(n=!0){if(!j||!g)return;p(!Dt,"glPreRender called with unflushed batch."),hi||(it.width=k.x,it.height=k.y),g.viewport(0,0,k.x,k.y),n&&xc();let t=b(2*K).divide(k);hi&&(t.y=-t.y);let e=Mt.rotate(-et),s=b(-1).subtract(e.multiply(t)),i=ut(et),o=rt(et),a=[t.x*i,t.y*o,0,0,-t.x*o,t.y*i,0,0,1,1,1,0,s.x,s.y,0,1],r=(c,l,u)=>{g.useProgram(c);let h=g.getUniformLocation(c,l);g.uniformMatrix4fv(h,!1,u)};r(ui,"m",a),r(li,"m",a),g.activeTexture(g.TEXTURE0),hn[0]&&(ne=hn[0].glTexture,g.bindTexture(g.TEXTURE_2D,ne)),g.bindBuffer(g.ARRAY_BUFFER,xo),On=qn=!1,vs(!0)}function xc(){if(!g)return;let n=sn;g.clearColor(n.r,n.g,n.b,n.a),g.clear(g.COLOR_BUFFER_BIT)}function kr(n){!g||n===ne||(It(),ne=n,g.bindTexture(g.TEXTURE_2D,ne))}function vc(n,t=!0){if(!g||!n)return;let e=n===ne;e?It():g.bindTexture(g.TEXTURE_2D,n);let s=t?g.REPEAT:g.CLAMP_TO_EDGE;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,s),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,s),!e&&ne&&g.bindTexture(g.TEXTURE_2D,ne)}function Ao(n,t){if(!g)return;let e=g.createShader(t);if(g.shaderSource(e,n),g.compileShader(e),zt&&!g.getShaderParameter(e,g.COMPILE_STATUS))throw g.getShaderInfoLog(e);return e}function Hn(n,t){if(!g)return;let e=g.createProgram();if(g.attachShader(e,Ao(n,g.VERTEX_SHADER)),g.attachShader(e,Ao(t,g.FRAGMENT_SHADER)),g.linkProgram(e),zt&&!g.getProgramParameter(e,g.LINK_STATUS))throw g.getProgramInfoLog(e);return e}function ki(n,t=!1){if(!g)return;let e=g.createTexture(),s=!1;if(n!=null&&n.width)Gr(e,n),g.bindTexture(g.TEXTURE_2D,e),s=!Tn&&ls(n.width)&&ls(n.height);else{let r=new Uint8Array([255,255,255,255]);g.bindTexture(g.TEXTURE_2D,e),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,1,1,0,g.RGBA,g.UNSIGNED_BYTE,r)}let i=Tn?g.NEAREST:g.LINEAR,o=s?g.LINEAR_MIPMAP_LINEAR:i;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,i),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,o);let a=t?g.REPEAT:g.CLAMP_TO_EDGE;return g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,a),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,a),s&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,ne),e}function Sc(n){g&&g.deleteTexture(n)}function Gr(n,t){g&&(p((t==null?void 0:t.width)>0,"Invalid image data."),g.bindTexture(g.TEXTURE_2D,n),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,t),!Tn&&ls(t.width)&&ls(t.height)&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,ne))}function Hh(n){U||(as.add(n),g&&(n.glTexture?Gr(n.glTexture,n.image):n.glTexture=ki(n.image,n.wrap)))}function Xh(n){if(U)return;as.delete(n);let t=n.glTexture;n.glTexture=void 0,Sc(t)}function It(){if(j&&g&&Dt){let n=qn?g.ONE:g.ONE_MINUS_SRC_ALPHA;g.blendFuncSeparate(g.SRC_ALPHA,n,g.ONE,n),g.enable(g.BLEND);let t=Dt*(Cn?Ii:Ir);g.bufferSubData(g.ARRAY_BUFFER,0,Nt,0,t),Cn?g.drawArrays(g.TRIANGLE_STRIP,0,Dt):g.drawArraysInstanced(g.TRIANGLE_STRIP,0,4,Dt),++Le,Oe+=Dt,Dt=0}qn=On}function Fr(n){!j||!g||(It(),n.drawImage(it,0,0))}function Yh(n=!0){p(!it,"must be called before engineInit"),Dr=n}function Ss(n,t,e,s,i=0,o=0,a=0,r=1,c=1,l=-1,u=0){(Dt>=Wh||qn!==On)&&It(),vs();let h=Dt++*Ir;Nt[h++]=n,Nt[h++]=t,Nt[h++]=e,Nt[h++]=s,Nt[h++]=o,Nt[h++]=a,Nt[h++]=r,Nt[h++]=c,xs[h++]=l,xs[h++]=u,Nt[h++]=i}function wc(n,t,e,s,i,o){Ss(n,t,e,s,i,0,0,0,0,0,o)}function jr(n,t,e,s,i,o,a,r=!0){let c=[],l=rt(-a),u=ut(-a);for(let f of n){let d=f.x*i,y=f.y*o;c.push(b(e+u*d-l*y,s+l*d+u*y))}let h=r?Kh(c):c;Tc(h,t)}function Br(n,t,e,s,i,o,a,r,c=!0){let l=$h(n,e,c);jr(l,t,s,i,o,a,r,!1)}function Tc(n,t){if(!j||n.length<3)return;let e=n.length+2;if((Dt+e>=Nn||qn!==On)&&It(),p(e=Nn)return;bc();let s=Dt*Ii;for(let i=e;i--;){let o=z(i-1,0,e-3),a=n[o];Nt[s++]=a.x,Nt[s++]=a.y,xs[s++]=t}Dt+=e}function Nr(n,t){if(!j||n.length<3)return;let e=n.length+2;if((Dt+e>=Nn||qn!==On)&&It(),p(e=Nn)return;bc();let s=Dt*Ii;for(let i=e;i--;){let o=z(i-1,0,e-3),a=n[o],r=t[o];Nt[s++]=a.x,Nt[s++]=a.y,xs[s++]=r}Dt+=e}function ns(n,t=!1){n?(hi=n,g.bindFramebuffer(g.FRAMEBUFFER,Mr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,n,0),To(t)):(It(),hi=void 0,g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,k.x,k.y))}function Ac(n,t,e,s){j&&(g.enable(g.SCISSOR_TEST),g.scissor(n,t,e,s),g.clearColor(0,0,0,0),g.clear(g.COLOR_BUFFER_BIT),g.disable(g.SCISSOR_TEST))}function $h(n,t,e=!0){if(n.length<2)return[];let s=t/2,i=[],o=n.length,a=1e-6,r=10;for(let c=0;ca?-d/y:0,S=y>a?f/y:0,E=w>a?-v/w:0,A=w>a?x/w:0,T=_+E,P=S+A,F=(T*T+P*P)**.5;if(Fa){let wt=st(1/gt,r);T*=wt,P*=wt}}let bt=b(u.x-T*s,u.y-P*s),ct=b(u.x+T*s,u.y+P*s);i.push(bt),i.push(ct)}return i.length>1&&e&&(i.push(i[0]),i.push(i[1])),i}function Kh(n){if(n.length<3)return[];let t=(d,y,x)=>(y.x-d.x)*(x.y-d.y)-(y.y-d.y)*(x.x-d.x);(d=>{let y=0;for(let x=d.length;x--;){let v=(x+1)%d.length;y+=d[x].cross(d[v])}return y})(n)<0&&(n=n.slice().reverse());let s=1e-9,i=(d,y,x,v)=>{let w=t(y,x,d),_=t(x,v,d),S=t(v,y,d),E=(w<-s?1:0)+(_<-s?1:0)+(S<-s?1:0),A=(w>s?1:0)+(_>s?1:0)+(S>s?1:0);return!(E&&A)},o=[];for(let d=0;d3&&r++{if(E>=0){let T=s.fillStyle=s.createLinearGradient(v,w,_,S);T.addColorStop(0,h(E,2)),T.addColorStop(1,h(E,1))}else s.fillStyle="#000";E>=-1?(s.fill(),A&&s.stroke()):s.stroke()},c=(v,w,_,S=0,E=2*Q,A,T)=>{s.beginPath(),s.arc(v,w,_,d*S,d*E),r(v,w-_,v,w+_,A,T)},l=(v,w,_,S,E)=>{s.beginPath(),s.rect(v,w,_,S*d),r(v,w+S,v+_,w,E)},u=(v,w,_,S)=>{s.beginPath();for(let E of v)s.lineTo(E.x,E.y);s.closePath(),r(0,_,0,_+S,w)},h=(v,w)=>w?`hsl(${[.95,.56,.13][v%3]*360} 99%${[0,50,75][w]}%)`:"#000",f=Va(1,1,n),d=Jt(f,.1,.5),y=st(6,st(o,a)/99);s.translate(o/2,a/2),s.scale(y,y),s.translate(-40,-35),d<1&&s.setLineDash([99*d,99]),s.lineJoin=s.lineCap="round",s.lineWidth=.1+d*1.9;{let w="LittleJS";s.font="900 15.5px arial",s.lineWidth=.1+d*3.9,s.textAlign="center",s.textBaseline="top",l(11,55,59,8*d,-1),s.beginPath();let _=0;for(let S=0;S5?1:0),s[S?"strokeText":"fillText"](w[E],P,54+.5,17*d),A+=T}s.lineWidth=.1+d*1.9,l(3,54,73,0)}l(7,15,26,-7,0),l(25,15,8,25,-1),l(10,40,15,-25,1),l(14,21,7,9,2),l(38,20,6,-6,2),l(49,20,10,-6,0);let x=[b(44,8),b(64,8),b(59,8+6*d),b(49,8+6*d)];u(x,2,8,6*d),l(44,8,20,-7,0);for(let v=5;v--;)c(59-v*6*d,30,10,0,2*Q,1,0);c(59,30,4,0,7,2),l(35,20,24,0),c(59,30,10),c(47,30,10,Q/2,Q*3/2),c(35,30,10,Q/2,Q*3/2),l(7,40,13,7,-1),l(17,40,43,14,-1);for(let v=3;v--;)for(let w=2;w--;)c(17+15*v,47,w?7:1,0,2*Q,2);for(let v=2;v--;){let w=6,_=7,S=53+w*d*v,E=[b(S+_,54),b(S,40),b(S+w*d,40),b(S+_+w*d,54)];u(E,0,40,14)}s.restore()}function Zh(n){if(gi=n,!fn){let e={};try{e=JSON.parse(localStorage[n]||"{}")}catch{e={}}Gi(s=>{s.unlocked=!!(e[s.id]&&e[s.id].unlocked)}),Jr()}En(void 0,t);function t(){if(!Us.length)return;let e=Us[0],s=cn-Js;if(!Js)Js=cn;else if(s>fi)Js=0,Us.shift();else{let i=fi-Fn,o=si?(s-i)/Fn:0;e.render(o)}}}function Gi(n){Object.values(ws).forEach(t=>n(t))}function td(){Gi(n=>n.unlocked=!1),Jr()}function Jr(){if(!gi)return;let n={};Gi(t=>{let e={name:t.name,description:t.description,icon:t.icon,unlocked:t.unlocked};t.image&&(e.src=t.image.src),n[t.id]=e}),localStorage[gi]=JSON.stringify(n)}function ed(n){fi=n}function nd(n){Fn=n}function sd(n){pi=n.copy()}function id(n){zr=n}function Cc(n,t,e,s=125){let i,o,a,r,c,l,u,h,f,d,y,x,v,w=0,_,S=[],E=[],A=[],T=0,P=0,F=1,bt={},ct=Kn/s*60>>2;for(;F;T++)S=[F=h=x=0],e.forEach((gt,wt)=>{for(u=t[gt][T]||[0,0,0],F|=t[gt][T]&&1,_=x+(t[gt][0].length-2-(h?0:1))*ct,v=wt===e.length-1,i=2,a=x;ict-99&&f&&y<1?y+=1/99:0)l=(1-y)*S[w++]/2||0,E[a]=(E[a]||0)-l*P+l,A[a]=(A[a++]||0)+l*P+l;c&&(y=c%1,P=u[1]||0,(c|=0)&&(S=bt[[d=u[w=0]||0,c]]=bt[[d,c]]||(r=[...n[d]],r[2]=(r[2]||220)*2**(c/12-1),c>0?Mi(...r):[])))}x=_});return[E,A]}function od(n){Ur=typeof n=="boolean"?n?1:0:n}function rd(n){Vr=n}async function ad(){return new Si(await Box2D()),e(),En(n,t),m;function n(){if(!Re){m.step(),m.objects=m.objects.filter(s=>!s.destroyed);for(let s of m.objects)s.body&&(s.pos=m.vec2From(s.body.GetPosition()),s.angle=-s.body.GetAngle())}}function t(){(Vr||ge)&&m.world.DrawDebugData()}function e(){let i=new m.instance.JSDraw,o=l=>new Lt(l.get_r(),l.get_g(),l.get_b()),a=l=>o(m.instance.wrapPointer(l,m.instance.b2Color)),r=l=>a(l).scale(1,.8),c=(l,u)=>{let h=[];for(let f=u;f--;)h.push(m.vec2FromPointer(l+f*8));return h};i.DrawSegment=function(l,u,h){h=r(h),l=m.vec2FromPointer(l),u=m.vec2FromPointer(u),mn(l,u,.1,h,b(),0,!1)},i.DrawPolygon=function(l,u,h){h=r(h);let f=c(l,u);Jn(f,ln,.1,h,b(),0,!1)},i.DrawSolidPolygon=function(l,u,h){h=r(h);let f=c(l,u);Jn(f,h,0,h,b(),0,!1)},i.DrawCircle=function(l,u,h){h=r(h),l=m.vec2FromPointer(l),ti(l,u*2,ln,.1,h,!1)},i.DrawSolidCircle=function(l,u,h,f){f=r(f),l=m.vec2FromPointer(l),h=m.vec2FromPointer(h).scale(u),ti(l,u*2,f,.1,f,!1),mn(b(),h,.1,f,l,0,!1)},i.DrawTransform=function(l){l=m.instance.wrapPointer(l,m.instance.b2Transform);let u=m.vec2From(l.get_p()),h=-l.get_q().GetAngle(),f=b(1,0),d=V(.75,0,0,.8),y=b(0,1),x=V(0,.75,0,.8);mn(b(),f,.1,d,u,h,!1),mn(b(),y,.1,x,u,h,!1)},i.AppendFlags(m.instance.b2Draw.e_shapeBit),i.AppendFlags(m.instance.b2Draw.e_jointBit),m.world.SetDebugDraw(i)}}function cd(n,t,e,s=32,i=2,o=0){Ec(n,t,e,H,s,at,i,o,!1,!0)}function Ec(n,t,e,s,i=1,o,a=.05,r=0,c=j,l,u){let h=e.offset(e.size),f=t.add(b(a-i*2)),d=b(i),y=t.scale(.5).subtract(d.scale(.5)),x=l?-1:1,v=l?-r:r;Ft(n,f,h,s,r,!1,o,c,l,u);for(let w=4;w--;){let _=w%2,S=y.multiply(b(_?w===1?1:-1:0,_?0:w?-1:1)),E=b(_?i:f.x,_?f.y:i),A=h.offset(e.size.multiply(b(w===1?1:w===3?-1:0,w===0?-x:w===2?x:0)));Ft(n.add(S.rotate(v)),E,A,s,r,!1,o,c,l,u)}for(let w=4;w--;){let _=w>1,S=w&&w<3,E=y.multiply(b(_?-1:1,S?-1:1)),A=h.offset(e.size.multiply(b(_?-1:1,S?x:-x)));Ft(n.add(E.rotate(v)),d,A,s,r,!1,o,c,l,u)}}function ld(n,t,e,s=32,i=2,o=0){_c(n,t,e,H,s,at,i,o,!1,!0)}function _c(n,t,e,s,i=1,o,a=.05,r=0,c=j,l,u){let h=e.frame(0),f=e.frame(1),d=e.frame(2),y=t.add(b(a-i*2)),x=b(i),v=t.scale(.5).subtract(x.scale(.5)),w=l?-1:1,_=l?-r:r;Ft(n,y,d,s,r,!1,o,c,l,u);for(let S=4;S--;){let E=r+S*Q/2,A=S%2,T=v.multiply(b(A?S===1?1:-1:0,A?0:S?-w:w)),P=b(A?y.y:y.x,i);Ft(n.add(T.rotate(_)),P,f,s,E,!1,o,c,l,u)}for(let S=4;S--;){let E=r+S*Q/2,A=!S||S>2,T=S>1,P=v.multiply(b(A?-1:1,T?-w:w));Ft(n.add(P.rotate(_)),x,h,s,E,!1,o,c,l,u)}}function ud(n,t=1,e=0,s=H,i=0,o=!1,a=0,r=at,c=j,l=!1,u){let h=Rc(b(),t,e,0,o);Jn(h,s,a,r,n,i,c,l,u)}function Rc(n,t=1,e=0,s=0,i=!1,o=_s){p(O(n),"pos must be a vec2"),p(R(t)&&R(e),"size and percent must be numbers");let a=ce(e*4,4);a>=2&&(s+=Q),a=a<=2?a-1:3-a,i&&(a=-a,s+=Q);let r=[],c=tt(3,o>>1),l=t/2;for(let u=0;u<=c;u++){let h=u/c*Q;r.push(b(l*ut(h),l*rt(h)).rotate(s).add(n))}for(let u=c;u>=0;u--){let h=u/c*Q;r.push(b(l*ut(h),-l*a*rt(h)).rotate(s).add(n))}return r}function Pa(n){return n&&typeof n.lerp=="function"}function hd(n,t,e,s,i=1,o={}){p(n!=null&&typeof n=="object","tweenProperty target must be an object"),p(q(t)&&t.length>0,"tweenProperty propertyPath must be a non-empty string");let a=t.split("."),r=a.pop(),c=l=>{let u=n;for(let h of a)u=u[h];u[r]=l};return new wi(c,e,s,i,o)}function Pc(n){n.loopRemaining!==1/0&&n.loopRemaining<=1||(n.loopRemaining!==1/0&&(n.loopRemaining-=1),n.life=n.duration,n.thenCallback=()=>Pc(n),te.push(n),n.callback(n.interp(n.duration)))}function Lc(n){if(n.loopRemaining!==1/0&&n.loopRemaining<=1)return;n.loopRemaining!==1/0&&(n.loopRemaining-=1);let t=n.start;n.start=n.end,n.end=t,n.life=n.duration,n.thenCallback=()=>Lc(n),te.push(n),n.callback(n.interp(n.duration))}function Oc(n,t){n===void 0?(n=ee-_a,t=cn-Ra,_a=ee,Ra=cn):t===void 0&&(t=n);for(let e=te.length;e--;){let s=te[e];if(s.paused)continue;let i=s.useRealTime?t:n;if(!(i<=0))if(s.life-=i,s.life>0)s.callback(s.interp(s.life));else{s.callback(s.interp(0)),te.splice(e,1);let o=s.thenCallback;s.thenCallback=void 0,o&&o()}}}function dd(){for(let n of te)n.thenCallback=void 0;te.length=0}var Vs,Ws,El,Qo,_t,Zo,La,ee,cn,Re,oo,we,qs,Oa,bn,co,zt,Ia,Ci,ka,Fe,nn,ge,ye,xn,vn,zn,lo,je,pe,Q,ot,Pt,cs,Hs,st,tt,ae,Ba,Na,rt,ut,za,er,fo,lt,Lt,H,ln,at,xe,Vl,ir,Wl,$a,Ka,ql,Qa,Za,Hl,Pe,Mt,et,K,rr,Ei,sn,Mn,ss,In,kn,ar,Tn,on,Es,cr,U,j,_s,_i,Ri,Pi,Li,lr,ur,hr,dr,fr,Ne,Xt,$s,Oi,pr,is,yn,un,gr,be,Xn,_n,Yn,$n,Rs,dn,$t,yr,os,Ks,Ps,Kt,Sn,mr,br,qe,N,pt,Ot,Ue,tn,Ce,ze,k,hn,Le,Oe,De,He,nh,cc,ei,ke,qt,Sr,Te,wr,ni,jn,en,Tr,Gn,At,le,Z,Ae,pn,ro,Un,ue,An,si,Is,Je,Qe,hc,Rr,dc,ps,gn,Vn,Ta,ii,mt,We,Kn,ys,oi,an,wn,ai,ms,bs,bo,Vh,ci,it,g,Dr,li,ui,Cn,On,qn,ne,xo,Bn,Nt,xs,Dt,as,vo,So,Mr,hi,wo,di,Ir,yc,Wh,Ii,mc,Nn,fn,fi,Fn,pi,zr,ws,Us,gi,Js,yi,Ts,Co,Eo,jt,_o,$,Ro,Po,Lo,C,Ur,Oo,he,mi,Do,Mo,As,Io,ko,Go,Fo,m,Vr,Cs,bi,jo,Bo,xi,Qt,No,vi,zo,Jo,Uo,Vo,Wo,qo,Ho,Xo,Yo,$o,Si,te,_a,Ra,wi,Ti,fd,ao,Ai,Ko,Mc=jc(()=>{"use strict";Vs="LittleJS",Ws="1.18.19",El=60,Qo=.016666666666666666,_t=[],Zo=[],La=0,ee=0,cn=0,Re=!1;oo=0,we=0,qs=0,Oa=!0,bn=[],co=class{constructor(t,e,s,i){this.update=t,this.render=e,this.glContextLost=s,this.glContextRestored=i}};zt=!0,Ia=.5,Ci=!0,ka="Escape",Fe=!1,nn=[],ge=!1,ye=!1,xn=!1,vn=!1,zn=!1;Q=Math.PI,ot=Math.abs,Pt=Math.floor,cs=Math.ceil,Hs=Math.round,st=Math.min,tt=Math.max,ae=n=>Math.sign(n),Ba=(...n)=>Math.hypot(...n),Na=n=>Math.log2(n),rt=Math.sin,ut=Math.cos,za=Math.tan,er=Math.atan2;fo=class{constructor(t=123456789){p(t!==0,"RandomGenerator seed must be non-zero (xorshift is fixed at 0)"),this.seed=t}float(t=1,e=0){return this.seed^=this.seed<<13,this.seed^=this.seed>>>17,this.seed^=this.seed<<5,e+(t-e)*((this.seed>>>0)/2**32)}int(t,e=0){return Pt(this.float(t,e))}bool(t=.5){return this.float().5?1:-1}floatSign(t=1,e=0){let s=st(t,e),o=tt(t,e)-s,a=this.float(o*2);return at?this.scale(t/e):this.copy()}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}reflect(t,e=1){return this.subtract(t.scale((1+e)*this.dot(t)))}angle(){return er(this.x,this.y)}setAngle(t=0,e=1){return Zt(t),Zt(e),this.x=e*rt(t),this.y=e*ut(t),this}rotate(t){Zt(t);let e=ut(-t),s=rt(-t);return new n(this.x*e-this.y*s,this.x*s+this.y*e)}setDirection(t,e=1){return Zt(t),Zt(e),t=ce(t,4),p(t===0||t===1||t===2||t===3,"Vector2.setDirection() direction must be an integer between 0 and 3."),this.x=t%2?t-1?-e:e:0,this.y=t%2?0:t?-e:e,this}direction(){return ot(this.x)>ot(this.y)?this.x<0?3:1:this.y<0?2:0}abs(){return new n(ot(this.x),ot(this.y))}floor(){return new n(Pt(this.x),Pt(this.y))}snap(t){return Zt(t),new n(Pt(this.x*t)/t,Pt(this.y*t)/t)}mod(t=1){return new n(ce(this.x,t),ce(this.y,t))}area(){return ot(this.x*this.y)}lerp(t,e){Sa(t),Zt(e);let s=z(e);return new n(t.x*s+this.x*(1-s),t.y*s+this.y*(1-s))}arrayCheck(t){return this.x>=0&&this.y>=0&&this.x(u=ce(u,1))*6<1?c+(l-c)*6*u:u*2<1?l:u*3<2?c+(l-c)*(4-u*6):c;return this.r=r(a,o,t+1/3),this.g=r(a,o,t),this.b=r(a,o,t-1/3),this.a=i,es(this),this}HSLA(){let t=z(this.r),e=z(this.g),s=z(this.b),i=z(this.a),o=tt(t,e,s),a=st(t,e,s),r=(o+a)/2,c=0,l=0;if(o!==a){let u=o-a;l=r>.5?u/(2-o-a):u/(o+a),t===o?c=(e-s)/u+(e((s=z(s)*255|0)<16?"0":"")+s.toString(16);return"#"+e(this.r)+e(this.g)+e(this.b)+(t?e(this.a):"")}setHex(t){if(p(q(t),"Color hex code must be a string"),p(t[0]==="#","Color hex code must start with #"),p([4,5,7,9].includes(t.length),"Invalid hex"),t.length<6){let e=s=>z(parseInt(t[s],16)/15);this.r=e(1),this.g=e(2),this.b=e(3),this.a=t.length===5?e(4):1}else{let e=s=>z(parseInt(t.slice(s,s+2),16)/255);this.r=e(1),this.g=e(3),this.b=e(5),this.a=t.length===9?e(7):1}return es(this),this}rgbaInt(){let t=z(this.r)*255|0,e=z(this.g)*255<<8,s=z(this.b)*255<<16,i=z(this.a)*255<<24;return t+e+s+i}isValid(){return R(this.r)&&R(this.g)&&R(this.b)&&R(this.a)}},H=se(V()),ln=se(V(1,1,1,0)),at=se(V(0,0,0)),xe=se(V(0,0,0,0)),Vl=se(V(.5,.5,.5)),ir=se(V(1,0,0)),Wl=se(V(1,.5,0)),$a=se(V(1,1,0)),Ka=se(V(0,1,0)),ql=se(V(0,1,1)),Qa=se(V(0,0,1)),Za=se(V(.5,0,1)),Hl=se(V(1,0,1)),Pe=class{constructor(t,e=!1){p(t===void 0||R(t),"Constructed Timer is invalid.",t),this.useRealTime=e;let s=this.getGlobalTime();this.time=t===void 0?void 0:s+t,this.setTime=t}set(t=0){p(R(t),"Timer is invalid.",t);let e=this.getGlobalTime();this.time=e+t,this.setTime=t}setUseRealTime(t=!0){p(!this.isSet(),"Cannot change global time setting while timer is set."),this.useRealTime=t}unset(){this.time=void 0}isSet(){return this.time!==void 0}active(){return this.getGlobalTime()=this.time}get(){return this.isSet()?this.getGlobalTime()-this.time:0}getPercent(){return this.isSet()?this.setTime?1-Jt(this.time-this.getGlobalTime(),0,this.setTime):1:0}getSetTime(){return this.isSet()?this.setTime:0}getGlobalTime(){return this.useRealTime?cn:ee}toString(){return this.isSet()?ot(this.get())+" seconds "+(this.get()<0?"before":"after"):"unset"}valueOf(){return this.get()}};Mt=b(),et=0,K=32,rr=1,Ei=!0,sn=xe,Mn=b(1920,1080),ss=0,In=0,kn=b(),ar=!1,Tn=!0,on=1,Es="arial",cr=!1,U=!1,j=!0,_s=32,_i=b(16),Ri=0,Pi=0,Li=!0,lr=1,ur=1,hr=1,dr=0,fr=.8,Ne=1,Xt=b(),$s=1,Oi=!0,pr=!0,is=!0,yn=!0,un=!1,gr=!1,be=0,Xn=4,_n=!0,Yn=0,$n=!1,Rs=!0,dn=!1,$t=100,yr=.3,os=3,Ks=0,Ps=!0,Kt=!0,Sn=.3,mr=40,br=.7;qe=class n{constructor(t=b(),e=b(1),s,i=0,o=H,a=0){p(O(t),"object pos must be a vec2"),p(O(e),"object size must be a vec2"),p(!s||s instanceof De,"object tileInfo should be a TileInfo or undefined"),p(typeof i=="number"&&isFinite(i),"object angle should be a number"),p(W(o),"object color should be a valid rgba color"),p(typeof a=="number","object renderOrder should be a number"),this.pos=t.copy(),this.size=e.copy(),this.drawSize=void 0,this.tileInfo=s,this.angle=i,this.color=o.copy(),this.additiveColor=void 0,this.mirror=!1,this.destroyed=!1,this.mass=lr,this.damping=ur,this.angleDamping=hr,this.restitution=dr,this.friction=fr,this.gravityScale=1,this.renderOrder=a,this.velocity=b(),this.angleVelocity=0,this.spawnTime=ee,this.children=[],this.clampSpeed=!0,this.groundObject=void 0,this.parent=void 0,this.localPos=b(),this.localAngle=0,this.collideTiles=!1,this.collideSolidObjects=!1,this.isSolid=!1,this.collideRaycast=!1,_t.push(this)}updateTransforms(){let t=this.parent;if(t){let e=t.getMirrorSign(),s=this.localPos,i=t.pos,o=s.x*e,a=s.y,r=t.angle;if(r){let c=ut(-r),l=rt(-r);this.pos.set(o*c-a*l+i.x,o*l+a*c+i.y)}else this.pos.set(o+i.x,a+i.y);this.angle=e*this.localAngle+r}for(let e of this.children)e.updateTransforms()}updatePhysics(){if(p(!this.parent),this.destroyed)return;this.clampSpeed&&(this.velocity.x=z(this.velocity.x,-Ne,Ne),this.velocity.y=z(this.velocity.y,-Ne,Ne));let t=this.pos.copy();if(this.velocity.x*=this.damping,this.velocity.y*=this.damping,this.mass&&(this.velocity.x+=Xt.x*this.gravityScale,this.velocity.y+=Xt.y*this.gravityScale),this.pos.x+=this.velocity.x,this.pos.y+=this.velocity.y,this.angle+=this.angleVelocity*=this.angleDamping,p(this.angleDamping>=0&&this.angleDamping<=1),p(this.damping>=0&&this.damping<=1),!Li||!this.mass)return;let e=this.velocity.y<0&&Xt.y<0||this.velocity.y>0&&Xt.y>0;if(this.groundObject){let s=tt(this.friction,this.groundObject.friction),i=this.groundObject.velocity.x;this.velocity.x=i+(this.velocity.x-i)*s,this.groundObject=void 0}if(this.collideSolidObjects)for(let i of Zo){if(i.destroyed||i.parent||i===this||!this.isSolid&&!i.isSolid||!this.isOverlappingObject(i))continue;let o=this.collideWithObject(i),a=i.collideWithObject(this);if(!o||!a)continue;if(Ys(t,this.size,i.pos,i.size)){let f=t.subtract(i.pos),d=f.length(),x=d<.001?b(0,1):f.scale(.001/d);this.velocity=this.velocity.add(x),i.mass&&(i.velocity=i.velocity.subtract(x)),ge&&uo(this.pos,this.size,i.pos,i.size,"#f00");continue}let r=this.size.add(i.size),c=(t.y-i.pos.y)*2>r.y+Xt.y,l=ot(t.y-i.pos.y)*20?-1:1)>0?Pt(t.y-this.size.y/2+1)+this.size.y/2+.001:cs(t.y+this.size.y/2-1)-this.size.y/2-.001;if(ot(u-this.pos.y)<.1&&!Ze(b(this.pos.x,u),this.size,this)){this.pos.y=u,ge&&Ct(this.pos,this.size,"#ff0");return}this.pos.x=t.x,this.velocity.x*=-a}if(o||!i){if(e){let c=this.size.y/2+1e-4;this.pos.y=Xt.y<0?Pt(t.y-this.size.y/2)+c:cs(t.y+this.size.y/2)-c,this.groundObject=s}else this.pos.y=t.y,this.groundObject=void 0;this.velocity.y*=-a}ge&&Ct(this.pos,this.size,"#f00")}}}update(){}render(){Ft(this.pos,this.drawSize||this.size,this.tileInfo,this.color,this.angle,this.mirror,this.additiveColor)}renderLight(){}destroy(t=!1){var e;if(!this.destroyed){this.destroyed=!0,(e=this.parent)==null||e.removeChild(this);for(let s of this.children)s.parent=void 0,s.destroy(t)}}localToWorld(t){return this.pos.add(t.rotate(this.angle))}worldToLocal(t){return t.subtract(this.pos).rotate(-this.angle)}localToWorldVector(t){return t.rotate(this.angle)}worldToLocalVector(t){return t.rotate(-this.angle)}collideWithTile(t,e){return t>0}collideWithObject(t){return!0}getUp(t=1){return b().setAngle(this.angle,t)}getRight(t=1){return b().setAngle(this.angle+Q/2,t)}getAliveTime(){return ee-this.spawnTime}getSpeed(){return this.velocity.length()}applyAcceleration(t){this.mass&&(this.velocity=this.velocity.add(t))}applyAngularAcceleration(t){this.mass&&(this.angleVelocity+=t)}applyForce(t){this.mass&&this.applyAcceleration(t.scale(1/this.mass))}getMirrorSign(){return this.mirror?-1:1}addChild(t,e=b(),s=0){return p(!this.destroyed,"cannot add child to destroyed object"),this.destroyed||(p(!t.parent&&!this.children.includes(t)),p(t instanceof n,"child must be an EngineObject"),p(t!==this,"cannot add self as child"),this.children.push(t),t.parent=this,t.localPos=e.copy(),t.localAngle=s,t.updateTransforms()),t}removeChild(t){p(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}isOverlappingObject(t){return this.isOverlapping(t.pos,t.size)}isOverlapping(t,e=b()){return Ys(this.pos,this.size,t,e)}setCollision(t=!0,e=!0,s=!0,i=!0){p(t||!e,"solid objects must be set to collide"),this.collideSolidObjects=t,this.isSolid=e,this.collideTiles=s,this.collideRaycast=i}toString(){let t="type = "+this.constructor.name;return(this.pos.x||this.pos.y)&&(t+=`
+precision highp float;in vec4 d;out vec4 c;void main(){c=d;}`);let e=new ArrayBuffer(di);zt=new Float32Array(e),xs=new Uint32Array(e),xo=g.createBuffer(),Bn=g.createBuffer(),Mr=g.createFramebuffer(),Dt=0;let s=new Float32Array([0,0,1,0,0,1,1,1]);g.bindBuffer(g.ARRAY_BUFFER,Bn),g.bufferData(g.ARRAY_BUFFER,s,g.STATIC_DRAW);let i,o,a,r=(c,l,u,h,f=0)=>{let d=g.getAttribLocation(o,c),y=u===1,x=u&&a;g.enableVertexAttribArray(d),g.vertexAttribPointer(d,h,l,y,x,i),g.vertexAttribDivisor(d,f),i+=h*u};vo=g.createVertexArray(),g.bindVertexArray(vo),i=0,o=li,a=yc,g.bindBuffer(g.ARRAY_BUFFER,Bn),r("g",g.FLOAT,0,2),g.bindBuffer(g.ARRAY_BUFFER,xo),g.bufferData(g.ARRAY_BUFFER,di,g.DYNAMIC_DRAW),r("p",g.FLOAT,4,4,1),r("u",g.FLOAT,4,4,1),r("c",g.UNSIGNED_BYTE,1,4,1),r("a",g.UNSIGNED_BYTE,1,4,1),r("r",g.FLOAT,4,1,1),So=g.createVertexArray(),g.bindVertexArray(So),i=0,o=ui,a=mc,r("p",g.FLOAT,4,2),r("c",g.UNSIGNED_BYTE,1,4)}}function vs(n=!1){!n&&!Cn||(It(),Cn=!1,g.useProgram(li),g.bindVertexArray(vo))}function bc(){Cn||(It(),Cn=!0,g.useProgram(ui),g.bindVertexArray(So))}function To(n=!0){if(!j||!g)return;p(!Dt,"glPreRender called with unflushed batch."),hi||(it.width=k.x,it.height=k.y),g.viewport(0,0,k.x,k.y),n&&xc();let t=b(2*K).divide(k);hi&&(t.y=-t.y);let e=Mt.rotate(-nt),s=b(-1).subtract(e.multiply(t)),i=ht(nt),o=rt(nt),a=[t.x*i,t.y*o,0,0,-t.x*o,t.y*i,0,0,1,1,1,0,s.x,s.y,0,1],r=(c,l,u)=>{g.useProgram(c);let h=g.getUniformLocation(c,l);g.uniformMatrix4fv(h,!1,u)};r(ui,"m",a),r(li,"m",a),g.activeTexture(g.TEXTURE0),hn[0]&&(se=hn[0].glTexture,g.bindTexture(g.TEXTURE_2D,se)),g.bindBuffer(g.ARRAY_BUFFER,xo),On=qn=!1,vs(!0)}function xc(){if(!g)return;let n=sn;g.clearColor(n.r,n.g,n.b,n.a),g.clear(g.COLOR_BUFFER_BIT)}function kr(n){!g||n===se||(It(),se=n,g.bindTexture(g.TEXTURE_2D,se))}function vc(n,t=!0){if(!g||!n)return;let e=n===se;e?It():g.bindTexture(g.TEXTURE_2D,n);let s=t?g.REPEAT:g.CLAMP_TO_EDGE;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,s),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,s),!e&&se&&g.bindTexture(g.TEXTURE_2D,se)}function Ao(n,t){if(!g)return;let e=g.createShader(t);if(g.shaderSource(e,n),g.compileShader(e),Jt&&!g.getShaderParameter(e,g.COMPILE_STATUS))throw g.getShaderInfoLog(e);return e}function Hn(n,t){if(!g)return;let e=g.createProgram();if(g.attachShader(e,Ao(n,g.VERTEX_SHADER)),g.attachShader(e,Ao(t,g.FRAGMENT_SHADER)),g.linkProgram(e),Jt&&!g.getProgramParameter(e,g.LINK_STATUS))throw g.getProgramInfoLog(e);return e}function ki(n,t=!1){if(!g)return;let e=g.createTexture(),s=!1;if(n!=null&&n.width)Gr(e,n),g.bindTexture(g.TEXTURE_2D,e),s=!Tn&&ls(n.width)&&ls(n.height);else{let r=new Uint8Array([255,255,255,255]);g.bindTexture(g.TEXTURE_2D,e),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,1,1,0,g.RGBA,g.UNSIGNED_BYTE,r)}let i=Tn?g.NEAREST:g.LINEAR,o=s?g.LINEAR_MIPMAP_LINEAR:i;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,i),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,o);let a=t?g.REPEAT:g.CLAMP_TO_EDGE;return g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,a),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,a),s&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,se),e}function Sc(n){g&&g.deleteTexture(n)}function Gr(n,t){g&&(p((t==null?void 0:t.width)>0,"Invalid image data."),g.bindTexture(g.TEXTURE_2D,n),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,t),!Tn&&ls(t.width)&&ls(t.height)&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,se))}function Hh(n){U||(as.add(n),g&&(n.glTexture?Gr(n.glTexture,n.image):n.glTexture=ki(n.image,n.wrap)))}function Xh(n){if(U)return;as.delete(n);let t=n.glTexture;n.glTexture=void 0,Sc(t)}function It(){if(j&&g&&Dt){let n=qn?g.ONE:g.ONE_MINUS_SRC_ALPHA;g.blendFuncSeparate(g.SRC_ALPHA,n,g.ONE,n),g.enable(g.BLEND);let t=Dt*(Cn?Ii:Ir);g.bufferSubData(g.ARRAY_BUFFER,0,zt,0,t),Cn?g.drawArrays(g.TRIANGLE_STRIP,0,Dt):g.drawArraysInstanced(g.TRIANGLE_STRIP,0,4,Dt),++Le,Oe+=Dt,Dt=0}qn=On}function Fr(n){!j||!g||(It(),n.drawImage(it,0,0))}function Yh(n=!0){p(!it,"must be called before engineInit"),Dr=n}function Ss(n,t,e,s,i=0,o=0,a=0,r=1,c=1,l=-1,u=0){(Dt>=Wh||qn!==On)&&It(),vs();let h=Dt++*Ir;zt[h++]=n,zt[h++]=t,zt[h++]=e,zt[h++]=s,zt[h++]=o,zt[h++]=a,zt[h++]=r,zt[h++]=c,xs[h++]=l,xs[h++]=u,zt[h++]=i}function wc(n,t,e,s,i,o){Ss(n,t,e,s,i,0,0,0,0,0,o)}function jr(n,t,e,s,i,o,a,r=!0){let c=[],l=rt(-a),u=ht(-a);for(let f of n){let d=f.x*i,y=f.y*o;c.push(b(e+u*d-l*y,s+l*d+u*y))}let h=r?Kh(c):c;Tc(h,t)}function Br(n,t,e,s,i,o,a,r,c=!0){let l=$h(n,e,c);jr(l,t,s,i,o,a,r,!1)}function Tc(n,t){if(!j||n.length<3)return;let e=n.length+2;if((Dt+e>=Nn||qn!==On)&&It(),p(e=Nn)return;bc();let s=Dt*Ii;for(let i=e;i--;){let o=z(i-1,0,e-3),a=n[o];zt[s++]=a.x,zt[s++]=a.y,xs[s++]=t}Dt+=e}function Nr(n,t){if(!j||n.length<3)return;let e=n.length+2;if((Dt+e>=Nn||qn!==On)&&It(),p(e=Nn)return;bc();let s=Dt*Ii;for(let i=e;i--;){let o=z(i-1,0,e-3),a=n[o],r=t[o];zt[s++]=a.x,zt[s++]=a.y,xs[s++]=r}Dt+=e}function ns(n,t=!1){n?(hi=n,g.bindFramebuffer(g.FRAMEBUFFER,Mr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,n,0),To(t)):(It(),hi=void 0,g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,k.x,k.y))}function Ac(n,t,e,s){j&&(g.enable(g.SCISSOR_TEST),g.scissor(n,t,e,s),g.clearColor(0,0,0,0),g.clear(g.COLOR_BUFFER_BIT),g.disable(g.SCISSOR_TEST))}function $h(n,t,e=!0){if(n.length<2)return[];let s=t/2,i=[],o=n.length,a=1e-6,r=10;for(let c=0;ca?-d/y:0,S=y>a?f/y:0,E=w>a?-v/w:0,A=w>a?x/w:0,T=_+E,P=S+A,F=(T*T+P*P)**.5;if(Fa){let wt=st(1/gt,r);T*=wt,P*=wt}}let bt=b(u.x-T*s,u.y-P*s),ct=b(u.x+T*s,u.y+P*s);i.push(bt),i.push(ct)}return i.length>1&&e&&(i.push(i[0]),i.push(i[1])),i}function Kh(n){if(n.length<3)return[];let t=(d,y,x)=>(y.x-d.x)*(x.y-d.y)-(y.y-d.y)*(x.x-d.x);(d=>{let y=0;for(let x=d.length;x--;){let v=(x+1)%d.length;y+=d[x].cross(d[v])}return y})(n)<0&&(n=n.slice().reverse());let s=1e-9,i=(d,y,x,v)=>{let w=t(y,x,d),_=t(x,v,d),S=t(v,y,d),E=(w<-s?1:0)+(_<-s?1:0)+(S<-s?1:0),A=(w>s?1:0)+(_>s?1:0)+(S>s?1:0);return!(E&&A)},o=[];for(let d=0;d3&&r++{if(E>=0){let T=s.fillStyle=s.createLinearGradient(v,w,_,S);T.addColorStop(0,h(E,2)),T.addColorStop(1,h(E,1))}else s.fillStyle="#000";E>=-1?(s.fill(),A&&s.stroke()):s.stroke()},c=(v,w,_,S=0,E=2*Q,A,T)=>{s.beginPath(),s.arc(v,w,_,d*S,d*E),r(v,w-_,v,w+_,A,T)},l=(v,w,_,S,E)=>{s.beginPath(),s.rect(v,w,_,S*d),r(v,w+S,v+_,w,E)},u=(v,w,_,S)=>{s.beginPath();for(let E of v)s.lineTo(E.x,E.y);s.closePath(),r(0,_,0,_+S,w)},h=(v,w)=>w?`hsl(${[.95,.56,.13][v%3]*360} 99%${[0,50,75][w]}%)`:"#000",f=Va(1,1,n),d=Ut(f,.1,.5),y=st(6,st(o,a)/99);s.translate(o/2,a/2),s.scale(y,y),s.translate(-40,-35),d<1&&s.setLineDash([99*d,99]),s.lineJoin=s.lineCap="round",s.lineWidth=.1+d*1.9;{let w="LittleJS";s.font="900 15.5px arial",s.lineWidth=.1+d*3.9,s.textAlign="center",s.textBaseline="top",l(11,55,59,8*d,-1),s.beginPath();let _=0;for(let S=0;S5?1:0),s[S?"strokeText":"fillText"](w[E],P,54+.5,17*d),A+=T}s.lineWidth=.1+d*1.9,l(3,54,73,0)}l(7,15,26,-7,0),l(25,15,8,25,-1),l(10,40,15,-25,1),l(14,21,7,9,2),l(38,20,6,-6,2),l(49,20,10,-6,0);let x=[b(44,8),b(64,8),b(59,8+6*d),b(49,8+6*d)];u(x,2,8,6*d),l(44,8,20,-7,0);for(let v=5;v--;)c(59-v*6*d,30,10,0,2*Q,1,0);c(59,30,4,0,7,2),l(35,20,24,0),c(59,30,10),c(47,30,10,Q/2,Q*3/2),c(35,30,10,Q/2,Q*3/2),l(7,40,13,7,-1),l(17,40,43,14,-1);for(let v=3;v--;)for(let w=2;w--;)c(17+15*v,47,w?7:1,0,2*Q,2);for(let v=2;v--;){let w=6,_=7,S=53+w*d*v,E=[b(S+_,54),b(S,40),b(S+w*d,40),b(S+_+w*d,54)];u(E,0,40,14)}s.restore()}function Zh(n){if(gi=n,!fn){let e={};try{e=JSON.parse(localStorage[n]||"{}")}catch{e={}}Gi(s=>{s.unlocked=!!(e[s.id]&&e[s.id].unlocked)}),Jr()}En(void 0,t);function t(){if(!Us.length)return;let e=Us[0],s=cn-Js;if(!Js)Js=cn;else if(s>fi)Js=0,Us.shift();else{let i=fi-Fn,o=si?(s-i)/Fn:0;e.render(o)}}}function Gi(n){Object.values(ws).forEach(t=>n(t))}function td(){Gi(n=>n.unlocked=!1),Jr()}function Jr(){if(!gi)return;let n={};Gi(t=>{let e={name:t.name,description:t.description,icon:t.icon,unlocked:t.unlocked};t.image&&(e.src=t.image.src),n[t.id]=e}),localStorage[gi]=JSON.stringify(n)}function ed(n){fi=n}function nd(n){Fn=n}function sd(n){pi=n.copy()}function id(n){zr=n}function Cc(n,t,e,s=125){let i,o,a,r,c,l,u,h,f,d,y,x,v,w=0,_,S=[],E=[],A=[],T=0,P=0,F=1,bt={},ct=Kn/s*60>>2;for(;F;T++)S=[F=h=x=0],e.forEach((gt,wt)=>{for(u=t[gt][T]||[0,0,0],F|=t[gt][T]&&1,_=x+(t[gt][0].length-2-(h?0:1))*ct,v=wt===e.length-1,i=2,a=x;ict-99&&f&&y<1?y+=1/99:0)l=(1-y)*S[w++]/2||0,E[a]=(E[a]||0)-l*P+l,A[a]=(A[a++]||0)+l*P+l;c&&(y=c%1,P=u[1]||0,(c|=0)&&(S=bt[[d=u[w=0]||0,c]]=bt[[d,c]]||(r=[...n[d]],r[2]=(r[2]||220)*2**(c/12-1),c>0?Mi(...r):[])))}x=_});return[E,A]}function od(n){Ur=typeof n=="boolean"?n?1:0:n}function rd(n){Vr=n}async function ad(){return new Si(await Box2D()),e(),En(n,t),m;function n(){if(!Re){m.step(),m.objects=m.objects.filter(s=>!s.destroyed);for(let s of m.objects)s.body&&(s.pos=m.vec2From(s.body.GetPosition()),s.angle=-s.body.GetAngle())}}function t(){(Vr||ge)&&m.world.DrawDebugData()}function e(){let i=new m.instance.JSDraw,o=l=>new Lt(l.get_r(),l.get_g(),l.get_b()),a=l=>o(m.instance.wrapPointer(l,m.instance.b2Color)),r=l=>a(l).scale(1,.8),c=(l,u)=>{let h=[];for(let f=u;f--;)h.push(m.vec2FromPointer(l+f*8));return h};i.DrawSegment=function(l,u,h){h=r(h),l=m.vec2FromPointer(l),u=m.vec2FromPointer(u),mn(l,u,.1,h,b(),0,!1)},i.DrawPolygon=function(l,u,h){h=r(h);let f=c(l,u);Jn(f,ln,.1,h,b(),0,!1)},i.DrawSolidPolygon=function(l,u,h){h=r(h);let f=c(l,u);Jn(f,h,0,h,b(),0,!1)},i.DrawCircle=function(l,u,h){h=r(h),l=m.vec2FromPointer(l),ti(l,u*2,ln,.1,h,!1)},i.DrawSolidCircle=function(l,u,h,f){f=r(f),l=m.vec2FromPointer(l),h=m.vec2FromPointer(h).scale(u),ti(l,u*2,f,.1,f,!1),mn(b(),h,.1,f,l,0,!1)},i.DrawTransform=function(l){l=m.instance.wrapPointer(l,m.instance.b2Transform);let u=m.vec2From(l.get_p()),h=-l.get_q().GetAngle(),f=b(1,0),d=V(.75,0,0,.8),y=b(0,1),x=V(0,.75,0,.8);mn(b(),f,.1,d,u,h,!1),mn(b(),y,.1,x,u,h,!1)},i.AppendFlags(m.instance.b2Draw.e_shapeBit),i.AppendFlags(m.instance.b2Draw.e_jointBit),m.world.SetDebugDraw(i)}}function cd(n,t,e,s=32,i=2,o=0){Ec(n,t,e,H,s,at,i,o,!1,!0)}function Ec(n,t,e,s,i=1,o,a=.05,r=0,c=j,l,u){let h=e.offset(e.size),f=t.add(b(a-i*2)),d=b(i),y=t.scale(.5).subtract(d.scale(.5)),x=l?-1:1,v=l?-r:r;jt(n,f,h,s,r,!1,o,c,l,u);for(let w=4;w--;){let _=w%2,S=y.multiply(b(_?w===1?1:-1:0,_?0:w?-1:1)),E=b(_?i:f.x,_?f.y:i),A=h.offset(e.size.multiply(b(w===1?1:w===3?-1:0,w===0?-x:w===2?x:0)));jt(n.add(S.rotate(v)),E,A,s,r,!1,o,c,l,u)}for(let w=4;w--;){let _=w>1,S=w&&w<3,E=y.multiply(b(_?-1:1,S?-1:1)),A=h.offset(e.size.multiply(b(_?-1:1,S?x:-x)));jt(n.add(E.rotate(v)),d,A,s,r,!1,o,c,l,u)}}function ld(n,t,e,s=32,i=2,o=0){_c(n,t,e,H,s,at,i,o,!1,!0)}function _c(n,t,e,s,i=1,o,a=.05,r=0,c=j,l,u){let h=e.frame(0),f=e.frame(1),d=e.frame(2),y=t.add(b(a-i*2)),x=b(i),v=t.scale(.5).subtract(x.scale(.5)),w=l?-1:1,_=l?-r:r;jt(n,y,d,s,r,!1,o,c,l,u);for(let S=4;S--;){let E=r+S*Q/2,A=S%2,T=v.multiply(b(A?S===1?1:-1:0,A?0:S?-w:w)),P=b(A?y.y:y.x,i);jt(n.add(T.rotate(_)),P,f,s,E,!1,o,c,l,u)}for(let S=4;S--;){let E=r+S*Q/2,A=!S||S>2,T=S>1,P=v.multiply(b(A?-1:1,T?-w:w));jt(n.add(P.rotate(_)),x,h,s,E,!1,o,c,l,u)}}function ud(n,t=1,e=0,s=H,i=0,o=!1,a=0,r=at,c=j,l=!1,u){let h=Rc(b(),t,e,0,o);Jn(h,s,a,r,n,i,c,l,u)}function Rc(n,t=1,e=0,s=0,i=!1,o=_s){p(O(n),"pos must be a vec2"),p(R(t)&&R(e),"size and percent must be numbers");let a=ce(e*4,4);a>=2&&(s+=Q),a=a<=2?a-1:3-a,i&&(a=-a,s+=Q);let r=[],c=tt(3,o>>1),l=t/2;for(let u=0;u<=c;u++){let h=u/c*Q;r.push(b(l*ht(h),l*rt(h)).rotate(s).add(n))}for(let u=c;u>=0;u--){let h=u/c*Q;r.push(b(l*ht(h),-l*a*rt(h)).rotate(s).add(n))}return r}function Pa(n){return n&&typeof n.lerp=="function"}function hd(n,t,e,s,i=1,o={}){p(n!=null&&typeof n=="object","tweenProperty target must be an object"),p(q(t)&&t.length>0,"tweenProperty propertyPath must be a non-empty string");let a=t.split("."),r=a.pop(),c=l=>{let u=n;for(let h of a)u=u[h];u[r]=l};return new wi(c,e,s,i,o)}function Pc(n){n.loopRemaining!==1/0&&n.loopRemaining<=1||(n.loopRemaining!==1/0&&(n.loopRemaining-=1),n.life=n.duration,n.thenCallback=()=>Pc(n),ee.push(n),n.callback(n.interp(n.duration)))}function Lc(n){if(n.loopRemaining!==1/0&&n.loopRemaining<=1)return;n.loopRemaining!==1/0&&(n.loopRemaining-=1);let t=n.start;n.start=n.end,n.end=t,n.life=n.duration,n.thenCallback=()=>Lc(n),ee.push(n),n.callback(n.interp(n.duration))}function Oc(n,t){n===void 0?(n=ne-_a,t=cn-Ra,_a=ne,Ra=cn):t===void 0&&(t=n);for(let e=ee.length;e--;){let s=ee[e];if(s.paused)continue;let i=s.useRealTime?t:n;if(!(i<=0))if(s.life-=i,s.life>0)s.callback(s.interp(s.life));else{s.callback(s.interp(0)),ee.splice(e,1);let o=s.thenCallback;s.thenCallback=void 0,o&&o()}}}function dd(){for(let n of ee)n.thenCallback=void 0;ee.length=0}var Vs,Ws,El,Qo,_t,Zo,La,ne,cn,Re,oo,we,qs,Oa,bn,co,Jt,Ia,Ci,ka,Fe,nn,ge,ye,xn,vn,zn,lo,je,pe,Q,ot,Pt,cs,Hs,st,tt,ae,Ba,Na,rt,ht,za,er,fo,ut,Lt,H,ln,at,xe,Vl,ir,Wl,$a,Ka,ql,Qa,Za,Hl,Pe,Mt,nt,K,rr,Ei,sn,Mn,ss,In,kn,ar,Tn,on,Es,cr,U,j,_s,_i,Ri,Pi,Li,lr,ur,hr,dr,fr,Ne,Yt,$s,Oi,pr,is,yn,un,gr,be,Xn,_n,Yn,$n,Rs,dn,Kt,yr,os,Ks,Ps,Qt,Sn,mr,br,qe,N,pt,Ot,Ue,tn,Ce,ze,k,hn,Le,Oe,De,He,nh,cc,ei,ke,Ht,Sr,Te,wr,ni,jn,en,Tr,Gn,At,le,Z,Ae,pn,ro,Un,ue,An,si,Is,Je,Qe,hc,Rr,dc,ps,gn,Vn,Ta,ii,mt,We,Kn,ys,oi,an,wn,ai,ms,bs,bo,Vh,ci,it,g,Dr,li,ui,Cn,On,qn,se,xo,Bn,zt,xs,Dt,as,vo,So,Mr,hi,wo,di,Ir,yc,Wh,Ii,mc,Nn,fn,fi,Fn,pi,zr,ws,Us,gi,Js,yi,Ts,Co,Eo,Bt,_o,$,Ro,Po,Lo,C,Ur,Oo,he,mi,Do,Mo,As,Io,ko,Go,Fo,m,Vr,Cs,bi,jo,Bo,xi,Zt,No,vi,zo,Jo,Uo,Vo,Wo,qo,Ho,Xo,Yo,$o,Si,ee,_a,Ra,wi,Ti,fd,ao,Ai,Ko,Mc=jc(()=>{"use strict";Vs="LittleJS",Ws="1.18.19",El=60,Qo=.016666666666666666,_t=[],Zo=[],La=0,ne=0,cn=0,Re=!1;oo=0,we=0,qs=0,Oa=!0,bn=[],co=class{constructor(t,e,s,i){this.update=t,this.render=e,this.glContextLost=s,this.glContextRestored=i}};Jt=!0,Ia=.5,Ci=!0,ka="Escape",Fe=!1,nn=[],ge=!1,ye=!1,xn=!1,vn=!1,zn=!1;Q=Math.PI,ot=Math.abs,Pt=Math.floor,cs=Math.ceil,Hs=Math.round,st=Math.min,tt=Math.max,ae=n=>Math.sign(n),Ba=(...n)=>Math.hypot(...n),Na=n=>Math.log2(n),rt=Math.sin,ht=Math.cos,za=Math.tan,er=Math.atan2;fo=class{constructor(t=123456789){p(t!==0,"RandomGenerator seed must be non-zero (xorshift is fixed at 0)"),this.seed=t}float(t=1,e=0){return this.seed^=this.seed<<13,this.seed^=this.seed>>>17,this.seed^=this.seed<<5,e+(t-e)*((this.seed>>>0)/2**32)}int(t,e=0){return Pt(this.float(t,e))}bool(t=.5){return this.float().5?1:-1}floatSign(t=1,e=0){let s=st(t,e),o=tt(t,e)-s,a=this.float(o*2);return at?this.scale(t/e):this.copy()}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}reflect(t,e=1){return this.subtract(t.scale((1+e)*this.dot(t)))}angle(){return er(this.x,this.y)}setAngle(t=0,e=1){return te(t),te(e),this.x=e*rt(t),this.y=e*ht(t),this}rotate(t){te(t);let e=ht(-t),s=rt(-t);return new n(this.x*e-this.y*s,this.x*s+this.y*e)}setDirection(t,e=1){return te(t),te(e),t=ce(t,4),p(t===0||t===1||t===2||t===3,"Vector2.setDirection() direction must be an integer between 0 and 3."),this.x=t%2?t-1?-e:e:0,this.y=t%2?0:t?-e:e,this}direction(){return ot(this.x)>ot(this.y)?this.x<0?3:1:this.y<0?2:0}abs(){return new n(ot(this.x),ot(this.y))}floor(){return new n(Pt(this.x),Pt(this.y))}snap(t){return te(t),new n(Pt(this.x*t)/t,Pt(this.y*t)/t)}mod(t=1){return new n(ce(this.x,t),ce(this.y,t))}area(){return ot(this.x*this.y)}lerp(t,e){Sa(t),te(e);let s=z(e);return new n(t.x*s+this.x*(1-s),t.y*s+this.y*(1-s))}arrayCheck(t){return this.x>=0&&this.y>=0&&this.x(u=ce(u,1))*6<1?c+(l-c)*6*u:u*2<1?l:u*3<2?c+(l-c)*(4-u*6):c;return this.r=r(a,o,t+1/3),this.g=r(a,o,t),this.b=r(a,o,t-1/3),this.a=i,es(this),this}HSLA(){let t=z(this.r),e=z(this.g),s=z(this.b),i=z(this.a),o=tt(t,e,s),a=st(t,e,s),r=(o+a)/2,c=0,l=0;if(o!==a){let u=o-a;l=r>.5?u/(2-o-a):u/(o+a),t===o?c=(e-s)/u+(e((s=z(s)*255|0)<16?"0":"")+s.toString(16);return"#"+e(this.r)+e(this.g)+e(this.b)+(t?e(this.a):"")}setHex(t){if(p(q(t),"Color hex code must be a string"),p(t[0]==="#","Color hex code must start with #"),p([4,5,7,9].includes(t.length),"Invalid hex"),t.length<6){let e=s=>z(parseInt(t[s],16)/15);this.r=e(1),this.g=e(2),this.b=e(3),this.a=t.length===5?e(4):1}else{let e=s=>z(parseInt(t.slice(s,s+2),16)/255);this.r=e(1),this.g=e(3),this.b=e(5),this.a=t.length===9?e(7):1}return es(this),this}rgbaInt(){let t=z(this.r)*255|0,e=z(this.g)*255<<8,s=z(this.b)*255<<16,i=z(this.a)*255<<24;return t+e+s+i}isValid(){return R(this.r)&&R(this.g)&&R(this.b)&&R(this.a)}},H=ie(V()),ln=ie(V(1,1,1,0)),at=ie(V(0,0,0)),xe=ie(V(0,0,0,0)),Vl=ie(V(.5,.5,.5)),ir=ie(V(1,0,0)),Wl=ie(V(1,.5,0)),$a=ie(V(1,1,0)),Ka=ie(V(0,1,0)),ql=ie(V(0,1,1)),Qa=ie(V(0,0,1)),Za=ie(V(.5,0,1)),Hl=ie(V(1,0,1)),Pe=class{constructor(t,e=!1){p(t===void 0||R(t),"Constructed Timer is invalid.",t),this.useRealTime=e;let s=this.getGlobalTime();this.time=t===void 0?void 0:s+t,this.setTime=t}set(t=0){p(R(t),"Timer is invalid.",t);let e=this.getGlobalTime();this.time=e+t,this.setTime=t}setUseRealTime(t=!0){p(!this.isSet(),"Cannot change global time setting while timer is set."),this.useRealTime=t}unset(){this.time=void 0}isSet(){return this.time!==void 0}active(){return this.getGlobalTime()=this.time}get(){return this.isSet()?this.getGlobalTime()-this.time:0}getPercent(){return this.isSet()?this.setTime?1-Ut(this.time-this.getGlobalTime(),0,this.setTime):1:0}getSetTime(){return this.isSet()?this.setTime:0}getGlobalTime(){return this.useRealTime?cn:ne}toString(){return this.isSet()?ot(this.get())+" seconds "+(this.get()<0?"before":"after"):"unset"}valueOf(){return this.get()}};Mt=b(),nt=0,K=32,rr=1,Ei=!0,sn=xe,Mn=b(1920,1080),ss=0,In=0,kn=b(),ar=!1,Tn=!0,on=1,Es="arial",cr=!1,U=!1,j=!0,_s=32,_i=b(16),Ri=0,Pi=0,Li=!0,lr=1,ur=1,hr=1,dr=0,fr=.8,Ne=1,Yt=b(),$s=1,Oi=!0,pr=!0,is=!0,yn=!0,un=!1,gr=!1,be=0,Xn=4,_n=!0,Yn=0,$n=!1,Rs=!0,dn=!1,Kt=100,yr=.3,os=3,Ks=0,Ps=!0,Qt=!0,Sn=.3,mr=40,br=.7;qe=class n{constructor(t=b(),e=b(1),s,i=0,o=H,a=0){p(O(t),"object pos must be a vec2"),p(O(e),"object size must be a vec2"),p(!s||s instanceof De,"object tileInfo should be a TileInfo or undefined"),p(typeof i=="number"&&isFinite(i),"object angle should be a number"),p(W(o),"object color should be a valid rgba color"),p(typeof a=="number","object renderOrder should be a number"),this.pos=t.copy(),this.size=e.copy(),this.drawSize=void 0,this.tileInfo=s,this.angle=i,this.color=o.copy(),this.additiveColor=void 0,this.mirror=!1,this.destroyed=!1,this.mass=lr,this.damping=ur,this.angleDamping=hr,this.restitution=dr,this.friction=fr,this.gravityScale=1,this.renderOrder=a,this.velocity=b(),this.angleVelocity=0,this.spawnTime=ne,this.children=[],this.clampSpeed=!0,this.groundObject=void 0,this.parent=void 0,this.localPos=b(),this.localAngle=0,this.collideTiles=!1,this.collideSolidObjects=!1,this.isSolid=!1,this.collideRaycast=!1,_t.push(this)}updateTransforms(){let t=this.parent;if(t){let e=t.getMirrorSign(),s=this.localPos,i=t.pos,o=s.x*e,a=s.y,r=t.angle;if(r){let c=ht(-r),l=rt(-r);this.pos.set(o*c-a*l+i.x,o*l+a*c+i.y)}else this.pos.set(o+i.x,a+i.y);this.angle=e*this.localAngle+r}for(let e of this.children)e.updateTransforms()}updatePhysics(){if(p(!this.parent),this.destroyed)return;this.clampSpeed&&(this.velocity.x=z(this.velocity.x,-Ne,Ne),this.velocity.y=z(this.velocity.y,-Ne,Ne));let t=this.pos.copy();if(this.velocity.x*=this.damping,this.velocity.y*=this.damping,this.mass&&(this.velocity.x+=Yt.x*this.gravityScale,this.velocity.y+=Yt.y*this.gravityScale),this.pos.x+=this.velocity.x,this.pos.y+=this.velocity.y,this.angle+=this.angleVelocity*=this.angleDamping,p(this.angleDamping>=0&&this.angleDamping<=1),p(this.damping>=0&&this.damping<=1),!Li||!this.mass)return;let e=this.velocity.y<0&&Yt.y<0||this.velocity.y>0&&Yt.y>0;if(this.groundObject){let s=tt(this.friction,this.groundObject.friction),i=this.groundObject.velocity.x;this.velocity.x=i+(this.velocity.x-i)*s,this.groundObject=void 0}if(this.collideSolidObjects)for(let i of Zo){if(i.destroyed||i.parent||i===this||!this.isSolid&&!i.isSolid||!this.isOverlappingObject(i))continue;let o=this.collideWithObject(i),a=i.collideWithObject(this);if(!o||!a)continue;if(Ys(t,this.size,i.pos,i.size)){let f=t.subtract(i.pos),d=f.length(),x=d<.001?b(0,1):f.scale(.001/d);this.velocity=this.velocity.add(x),i.mass&&(i.velocity=i.velocity.subtract(x)),ge&&uo(this.pos,this.size,i.pos,i.size,"#f00");continue}let r=this.size.add(i.size),c=(t.y-i.pos.y)*2>r.y+Yt.y,l=ot(t.y-i.pos.y)*20?-1:1)>0?Pt(t.y-this.size.y/2+1)+this.size.y/2+.001:cs(t.y+this.size.y/2-1)-this.size.y/2-.001;if(ot(u-this.pos.y)<.1&&!Ze(b(this.pos.x,u),this.size,this)){this.pos.y=u,ge&&Ct(this.pos,this.size,"#ff0");return}this.pos.x=t.x,this.velocity.x*=-a}if(o||!i){if(e){let c=this.size.y/2+1e-4;this.pos.y=Yt.y<0?Pt(t.y-this.size.y/2)+c:cs(t.y+this.size.y/2)-c,this.groundObject=s}else this.pos.y=t.y,this.groundObject=void 0;this.velocity.y*=-a}ge&&Ct(this.pos,this.size,"#f00")}}}update(){}render(){jt(this.pos,this.drawSize||this.size,this.tileInfo,this.color,this.angle,this.mirror,this.additiveColor)}renderLight(){}destroy(t=!1){var e;if(!this.destroyed){this.destroyed=!0,(e=this.parent)==null||e.removeChild(this);for(let s of this.children)s.parent=void 0,s.destroy(t)}}localToWorld(t){return this.pos.add(t.rotate(this.angle))}worldToLocal(t){return t.subtract(this.pos).rotate(-this.angle)}localToWorldVector(t){return t.rotate(this.angle)}worldToLocalVector(t){return t.rotate(-this.angle)}collideWithTile(t,e){return t>0}collideWithObject(t){return!0}getUp(t=1){return b().setAngle(this.angle,t)}getRight(t=1){return b().setAngle(this.angle+Q/2,t)}getAliveTime(){return ne-this.spawnTime}getSpeed(){return this.velocity.length()}applyAcceleration(t){this.mass&&(this.velocity=this.velocity.add(t))}applyAngularAcceleration(t){this.mass&&(this.angleVelocity+=t)}applyForce(t){this.mass&&this.applyAcceleration(t.scale(1/this.mass))}getMirrorSign(){return this.mirror?-1:1}addChild(t,e=b(),s=0){return p(!this.destroyed,"cannot add child to destroyed object"),this.destroyed||(p(!t.parent&&!this.children.includes(t)),p(t instanceof n,"child must be an EngineObject"),p(t!==this,"cannot add self as child"),this.children.push(t),t.parent=this,t.localPos=e.copy(),t.localAngle=s,t.updateTransforms()),t}removeChild(t){p(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}isOverlappingObject(t){return this.isOverlapping(t.pos,t.size)}isOverlapping(t,e=b()){return Ys(this.pos,this.size,t,e)}setCollision(t=!0,e=!0,s=!0,i=!0){p(t||!e,"solid objects must be set to collide"),this.collideSolidObjects=t,this.isSolid=e,this.collideTiles=s,this.collideRaycast=i}toString(){let t="type = "+this.constructor.name;return(this.pos.x||this.pos.y)&&(t+=`
 pos = `+this.pos),(this.velocity.x||this.velocity.y)&&(t+=`
 velocity = `+this.velocity),(this.size.x||this.size.y)&&(t+=`
 size = `+this.size),this.angle&&(t+=`
 angle = `+this.angle.toFixed(3)),this.color&&(t+=`
-color = `+this.color),t}renderDebugInfo(){if(!zt)return;let t=this.collideTiles||this.collideSolidObjects||this.isSolid;if(!t&&!this.parent)return;let e=b(tt(this.size.x,.2),tt(this.size.y,.2)),s=V(this.collideTiles?1:0,this.collideSolidObjects?1:0,this.isSolid?1:0,.5);Ct(this.pos,e,s,0,this.angle,t),this.parent&&Ct(this.pos,e.scale(.8),V(1,1,1,.5),0,this.angle),this.parent&&Ee(this.pos,this.parent.pos,V(1,1,1,.5),.5)}},k=b(),hn=[];De=class n{constructor(t=b(),e=_i,s=hn[0],i=Ri,o=Pi){this.pos=t.copy(),this.size=e.copy(),this.padding=i,this.textureInfo=s,this.bleed=o}offset(t){return new n(this.pos.add(t),this.size,this.textureInfo,this.padding,this.bleed)}frame(t){p(typeof t=="number");let e=this.size.x+this.padding*2,s=t*e;return p(s+this.size.x<=this.textureInfo.size.x,"frame extends beyond texture width!"),this.offset(new lt(s))}setFullImage(t=this.textureInfo){return this.textureInfo=t,this.pos=new lt,this.size=t.size.copy(),this.bleed=this.padding=0,this}tile(t){return Ls(t,this.size,this.textureInfo,this.padding,this.bleed)}},He=class{constructor(t,e=!0,s=!1){this.image=t,this.size=t?b(t.width,t.height):b(),this.sizeInverse=t?b(1/t.width,1/t.height):b(),this.glTexture=void 0,this.wrap=s,e&&this.createWebGLTexture()}createWebGLTexture(){Hh(this)}destroyWebGLTexture(){Xh(this)}hasWebGL(){return!!this.glTexture}setWrap(t=!0){this.wrap=t,vc(this.glTexture,t)}};nh=0;ei=class{constructor(t){p(!!t,"tileInfo is required for ImageFont"),this.tileInfo=t.frame(0)}drawText(t,e,s=1,i,o,a,r){p(O(s)||typeof s=="number","size must be a vec2 or number"),typeof s=="number"?(p(s>0),s*=K,s=new lt(s,s)):s=s.scale(K),this.drawTextScreen(t,Pn(e),s,i,o,a,r)}drawTextScreen(t,e,s,i=!0,o=H,a=j,r){p(q(t),"text must be a string"),p(O(e),"pos must be a vec2"),p(O(s)||typeof s=="number","size must be a vec2 or number"),p(W(o),"color must be a color"),s=typeof s=="number"?new lt(s,s):s;let c=new lt,l=this.tileInfo,u=l.padding,h=l.size.x+u*2,f=l.size.y+u*2,d=l.textureInfo.size.x/h|0;(t+"").split(`
-`).forEach((y,x)=>{let v=i?(y.length-1)*s.x/2:0;for(let w=y.length;w--;){let _=y.charCodeAt(w),S=_<32||_>127?95:_-32,E=S%d,A=S/d|0;l.pos.x=E*h+u,l.pos.y=A*f+u,c.x=e.x+w*s.x-v|0,c.y=e.y+x*s.y|0,Ft(c,s,l,o,0,!1,void 0,a,!0,r)}})}};ke=b(),qt=b(),Sr=b(),Te=b(),wr=0,ni=!0,jn=!1,en="mouse",Tr=6,Gn=!0,At=0,le=!U&&window.ontouchstart!==void 0;Z=[[]],Ae=[],pn=[],ro=[],Un=new Pe,ue=[],An=[],si=[],Is=[],Je=new Map,ps=[],Vn=!0;ii="http://www.w3.org/2000/svg";mt=new AudioContext,Kn=44100;ys=class{constructor(t,e,s=mr,i=br,o){var a;if(!(!Kt||U)){if(p(!t||me(t)||q(t),"asset must be a file name or zzfx array"),p(e===void 0||R(e),"randomness must be a number"),p(e===void 0||e>=0&&e<=1,"randomness must be between 0 and 1"),p(R(s),"range must be a number"),p(R(i),"taper must be a number"),this.range=s,this.taper=i,this.randomness=e!=null?e:0,this.sampleRate=Kn,this.loadedPercent=0,this.onloadCallback=o,me(t)){let r=t.slice(),c=e!=null?e:.05,l=1;this.randomness=(a=r[l])!=null?a:c,r[l]=0,this.sampleChannels=[Mi(...r)],this.loadedPercent=1,o==null||o(this)}else if(typeof t=="string"){let r=t;this.loadSound(r)}}}play(t,e=1,s=1,i=1,o=!1,a=!1){if(p(!t||O(t),"pos must be a vec2"),p(R(e),"volume must be a number"),p(R(s),"pitch must be a number"),p(R(i),"randomnessScale must be a number"),!Kt||U||!this.sampleChannels)return;let r;if(t){let u=this.range;if(u){let h=Mt.distanceSquared(t);if(h>u*u)return;e*=Jt(h**.5,u,u*this.taper)}r=Pn(t).x*2/N.width-1}let c=s+s*this.randomness*i*yt(-1,1),l=new oi(this,e,c,r,o,a);return zt&&zn&&t&&(Ht(t,.5,"#0ff",.5,!0),this.range&&(Ht(t,2*this.range,"#0ff",.5),Ht(t,2*this.range*this.taper,"#0ff",.5)),Dn("vol "+e.toFixed(2)+" pitch "+c.toFixed(2),t,.5,"#0ff",.5)),l}playMusic(t=1,e=!0,s=!1){return this.play(void 0,t,1,0,e,s)}playNote(t=0,e,s){p(R(t),"semitoneOffset must be a number");let i=pc(t,1);return this.play(e,s,i,0)}getDuration(){var t,e;return((e=(t=this.sampleChannels)==null?void 0:t[0])==null?void 0:e.length)/this.sampleRate||0}isLoaded(){return this.loadedPercent===1}async loadSound(t){var c;let e=await fetch(t);if(!e.ok)throw new Error(`Failed to load sound from ${t}: ${e.status} ${e.statusText}`);let s=await e.arrayBuffer(),i=await mt.decodeAudioData(s),o=i.numberOfChannels,a=1e5,r=[];for(let l=0;lsetTimeout(v,0));let d=st(f+a,h);for(;f=0,"Sound volume must be positive or zero"),p(s>=0,"Sound rate must be positive or zero"),p(R(i),"Sound pan must be a number"),this.sound=t,this.volume=e,this.rate=s,this.pan=i,this.loop=o,this.pausedTime=0,this.startTime=void 0,this.gainNode=void 0,this.source=void 0,this.onendedCallback=r=>{r===this.source&&(this.source=void 0)},a||this.start()}start(t=0){p(t>=0,"Sound start offset must be positive or zero"),this.isPlaying()&&this.stop(),this.gainNode=mt.createGain(),this.source=Or(this.sound.sampleChannels,this.volume,this.rate,this.pan,this.loop,this.sound.sampleRate,this.gainNode,t,this.onendedCallback),this.source?(this.startTime=mt.currentTime-t,this.pausedTime=void 0):(this.startTime=void 0,this.pausedTime=0)}setVolume(t){p(t>=0,"Sound volume must be positive or zero"),this.volume=t,this.gainNode&&(this.gainNode.gain.value=t)}stop(t=0){if(p(t>=0,"Sound fade time must be positive or zero"),this.isPlaying())if(t){let e=mt.currentTime,s=e+t;this.gainNode.gain.cancelScheduledValues(e),this.gainNode.gain.setValueAtTime(this.volume,e),this.gainNode.gain.linearRampToValueAtTime(0,s),this.source.stop(s)}else this.source.stop();this.pausedTime=0,this.source=void 0,this.startTime=void 0}pause(){this.isPaused()||(this.pausedTime=this.getCurrentTime(),this.source.stop(),this.source=void 0,this.startTime=void 0)}resume(){this.isPaused()&&this.start(this.pausedTime)}isPlaying(){return!!this.source}isPaused(){return!this.isPlaying()}getCurrentTime(){if(!this.isPlaying())return this.pausedTime;let t=this.getDuration();return t?ce(mt.currentTime-this.startTime,t):0}getDuration(){return this.rate?this.sound.getDuration()/this.rate:0}getSource(){return this.source}};an=[];wn=class{constructor(t,e=0,s=!1,i=new Lt){this.tile=t,this.direction=e,this.mirror=s,this.color=i.copy()}clear(){this.tile=this.direction=0,this.mirror=!1,this.color=new Lt}},ai=class extends qe{constructor(t,e,s=0,i=0,o=b(512),a=!0){var r;p(O(o),"canvasSize must be a Vector2"),super(t,e,void 0,s,H,i),this.canvas=U?void 0:new OffscreenCanvas(o.x,o.y),this.context=(r=this.canvas)==null?void 0:r.getContext("2d"),this.textureInfo=new He(this.canvas,a),this.mass=0}destroy(){this.destroyed||(this.textureInfo.destroyWebGLTexture(),super.destroy())}render(){this.draw(this.pos,this.size,this.color,this.angle,this.mirror,this.additiveColor)}draw(t,e,s=H,i=0,o=!1,a,r=!1,c){let l=new De().setFullImage(this.textureInfo),u=this.hasWebGL();Ft(t,e,l,s,i,o,a,u,r,c)}updateWebGL(){this.textureInfo.createWebGLTexture()}hasWebGL(){return j&&this.textureInfo.hasWebGL()}},ms=class extends ai{constructor(t,e,s=Ls(),i=0,o=!0){let a=s?e.multiply(s.size):e;if(super(t,e,0,i,a,o),this.tileInfo=void 0,this.data=[],this.isUsingWebGL=!1,U){this.render=()=>{},this.redraw=()=>{},this.redrawStart=()=>{},this.redrawEnd=()=>{},this.drawTileData=()=>{},this.redrawTileData=()=>{},this.drawLayerTile=()=>{},this.drawLayerRect=()=>{},this.drawTile=()=>{},this.drawRect=()=>{},this.clearLayerRect=()=>{};return}s&&(this.tileInfo=s.frame(0),this.tileInfo.bleed=0);for(let r=this.size.area();r--;)this.data.push(new wn)}setData(t,e,s=!1){if(t=t.floor(),p(O(t),"layerPos must be a Vector2"),p(e instanceof wn,"data must be a TileLayerData"),!t.arrayCheck(this.size)||(this.data[(t.y|0)*this.size.x+(t.x|0)]=e,!s))return;Ot===this.context?this.drawTileData(t):this.redrawTileData(t)}clearData(t,e=!1){this.setData(t,new wn,e)}getData(t){return p(O(t),"layerPos must be a Vector2"),t.arrayCheck(this.size)?this.data[(t.y|0)*this.size.x+(t.x|0)]:void 0}update(){!j&&this.isUsingWebGL&&(this.isUsingWebGL=!1,this.redraw())}render(){p(Ot!==this.context,"must call redrawEnd() after drawing tiles!");let t=this.drawSize||this.size,e=this.pos.add(t.scale(.5));this.draw(e,this.size,this.color,this.angle,this.mirror,this.additiveColor)}onRedraw(){}redraw(){this.redrawStart(!0);for(let t=this.size.x;t--;)for(let e=this.size.y;e--;)this.drawTileData(b(t,e),!1);this.isUsingWebGL&&It(),this.onRedraw(),this.redrawEnd()}redrawStart(t=!1){var s,i;if(!this.context)return;p(Ot!==this.context),this.savedRenderSettings=[Ot,k,Mt,K,sn],Ot=this.context;let e=(i=(s=this.tileInfo)==null?void 0:s.size)!=null?i:b(1);k=this.size.multiply(e),sn=xe,Mt=this.size.multiply(e).scale(.5),K=1,this.isUsingWebGL=this.hasWebGL(),this.isUsingWebGL?ns(this.textureInfo.glTexture,t):(this.context.imageSmoothingEnabled=!Tn,t&&(this.canvas.width=k.x,this.canvas.height=k.y))}redrawEnd(){this.context&&(p(Ot===this.context),this.isUsingWebGL&&ns(),[Ot,k,Mt,K,sn]=this.savedRenderSettings)}drawTileData(t,e=!0){var r,c;if(!this.context)return;p(Ot===this.context,"must call redrawStart() before drawing tiles");let s=(c=(r=this.tileInfo)==null?void 0:r.size)!=null?c:b(1),i=t.multiply(s);e&&this.clearLayerRect(i,s);let o=this.getData(t);if(!o||!o.tile)return;let a=this.tileInfo&&this.tileInfo.tile(o.tile);this.drawLayerTile(i,s,a,o.color,o.direction*Q/2,o.mirror)}redrawTileData(t,e=!0){this.context&&(p(Ot!==this.context,"redrawStart() should not be active when calling redrawTileData(), instead use drawTileData()"),this.redrawStart(),this.drawTileData(t,e),this.redrawEnd())}drawLayerTile(t,e=b(1),s,i=H,o=0,a,r){let c=t.add(e.scale(.5));Ft(c,e,s,i,o,a,r,this.isUsingWebGL)}drawLayerRect(t,e,s,i=0){this.drawLayerTile(t,e,void 0,s,i)}drawTile(t,e=b(1),s,i=new Lt,o=0,a=!1){t=t.subtract(this.pos).multiply(this.tileInfo.size),e=e.multiply(this.tileInfo.size),t.y=this.canvas.height-t.y;let r=k;k=b(this.canvas.width,this.canvas.height);let c=this.hasWebGL();c&&ns(this.textureInfo.glTexture);let l=c?void 0:this.context;Ft(t,e,s,i,o,a,void 0,c,!0,l),c&&ns(),k=r}drawRect(t,e,s,i){this.drawTile(t,e,void 0,s,i)}clearLayerRect(t,e){p(Ot===this.context,"must call redrawStart() before clearing tiles");let s=t.x,i=this.canvas.height-t.y-e.y;this.hasWebGL()?Ac(s,i,e.x,e.y):this.context.clearRect(s,i,e.x,e.y)}},bs=class extends ms{constructor(t,e,s=Ls(),i=0,o=!0){super(t,e.floor(),s,i,o),this.collisionData=[],this.initCollision(this.size),an.push(this),this.isSolid=!0}destroy(){if(this.destroyed)return;let t=an.indexOf(this);p(t>=0,"tile collision layer not found in array"),t>=0&&an.splice(t,1),super.destroy()}initCollision(t){p(O(t),"size must be a Vector2"),this.size=t.floor(),this.collisionData=[],this.collisionData.length=t.area(),this.collisionData.fill(0)}setCollisionData(t,e=1){p(O(t),"layerPos must be a Vector2");let s=(t.y|0)*this.size.x+(t.x|0);t.arrayCheck(this.size)&&(this.collisionData[s]=e)}clearCollisionData(t){this.setCollisionData(t,0)}getCollisionData(t){p(O(t),"layerPos must be a Vector2");let e=(t.y|0)*this.size.x+(t.x|0);return t.arrayCheck(this.size)?this.collisionData[e]:0}collisionTest(t,e=new lt,s){p(O(t)&&O(e),"pos and size must be Vector2s"),p(!s||typeof s=="function"||s instanceof qe,"callbackObject must be a function or EngineObject");let i=s?typeof s=="function"?(f,d)=>s(f,d):(f,d)=>s.collideWithTile(f,d):()=>!0,o=t.x-this.pos.x,a=t.y-this.pos.y;if(o+e.x/2<0||o-e.x/2>this.size.x||a+e.y/2<0||a-e.y/2>this.size.y)return!1;let r=tt(o-e.x/2|0,0),c=tt(a-e.y/2|0,0),l=st(tt(o+e.x/2,r+1),this.size.x),u=st(tt(a+e.y/2,c+1),this.size.y),h=new lt;for(let f=c;fs(l,u):(l,u)=>s.collideWithTile(l,u):l=>l>0,a=l=>{let u=this.getCollisionData(r.set(l.x-this.pos.x,l.y-this.pos.y));return u&&o(u,l)},r=new lt,c=Wa(t,e,a,i);if(ye&&c){let l=c.floor().add(b(.5));Ct(l,b(1),"#f008"),Ee(t,e,"#00f",.02),Ee(t,c,"#f00",.02),tr(c,"#0f0"),i&&Ee(c,c.add(i),"#ff0",.02)}return c}},bo=class extends qe{constructor(t,e,s=0,i=0,o=100,a=Q,r,c=H,l=H,u=ln,h=ln,f=.5,d=.1,y=1,x=.1,v=.05,w=1,_=1,S=0,E=Q,A=.1,T=.2,P=!1,F=!1,bt=!0,ct=F?1e9:0,gt=!1){super(t,b(),r,e,void 0,ct),this.emitCircle=typeof s=="number",this.emitSize=typeof s=="number"?b(s):s.copy(),this.emitTime=i,this.emitRate=o,this.emitConeAngle=a,this.colorStartA=c.copy(),this.colorStartB=l.copy(),this.colorEndA=u.copy(),this.colorEndB=h.copy(),this.randomColorLinear=bt,this.particleTime=f,this.sizeStart=d,this.sizeEnd=y,this.speed=x,this.angleSpeed=v,this.damping=w,this.angleDamping=_,this.gravityScale=S,this.particleConeAngle=E,this.fadeRate=A,this.randomness=T,this.collideTiles=P,this.additive=F,this.localSpace=gt,this.trailScale=0,this.particleCreateCallback=void 0,this.particleDestroyCallback=void 0,this.particleCollideCallback=void 0,this.velocityInheritance=0,this.emitTimeBuffer=0,this.particles=[],this.previousAngle=this.angle,this.previousPos=this.pos.copy()}update(){if(p(this.angleDamping>=0&&this.angleDamping<=1),p(this.damping>=0&&this.damping<=1),this.velocityInheritance){let s=this.velocityInheritance;this.velocity.x=s*(this.pos.x-this.previousPos.x),this.velocity.y=s*(this.pos.y-this.previousPos.y),this.angleVelocity=s*(this.angle-this.previousAngle),this.previousAngle=this.angle,this.previousPos.x=this.pos.x,this.previousPos.y=this.pos.y}if(this.isActive()){if(this.emitRate&&$s){let s=1/this.emitRate/$s;for(this.emitTimeBuffer+=Qo;this.emitTimeBuffer>0;this.emitTimeBuffer-=s)this.emitParticle()}}else this.particles.length===0&&this.destroy(!0);let t=this.particles,e=0;for(let s=0;s_+_*yt(s,-s),o=i(this.particleTime),a=i(this.sizeStart),r=i(this.sizeEnd),c=i(this.speed),l=i(this.angleSpeed)*Ha(),u=yt(this.emitConeAngle,-this.emitConeAngle),h=ho(this.colorStartA,this.colorStartB,this.randomColorLinear),f=ho(this.colorEndA,this.colorEndB,this.randomColorLinear),d=this.localSpace?u:this.angle+u,y=b(c*rt(d),c*ut(d)),x=l;!this.localSpace&&this.velocityInheritance>0&&(y.x+=this.velocity.x,y.y+=this.velocity.y,x+=this.angleVelocity);let v=new ci(this,t,e,h,f,o,a,r,y,x);return this.particles.push(v),(w=this.particleCreateCallback)==null||w.call(this,v),v}updatePhysics(){}render(){for(let t of this.particles)t.render()}isActive(){return!this.emitTime||this.getAliveTime()0&&(this.destroyed=!1,this.emitTime=-1))}},Vh=new lt,ci=class{constructor(t,e,s,i,o,a,r,c,l=b(),u=0){this.emitter=t,this.pos=e,this.angle=s,this.size=b(r),this.color=i.copy(),this.colorStart=i,this.colorEnd=o,this.lifeTime=a,this.sizeStart=r,this.sizeEnd=c,this.velocity=l,this.angleVelocity=u,this.spawnTime=ee,this.mirror=qa(),this.groundObject=void 0,this.destroyed=!1,this.tileInfo=t.tileInfo}update(){let t=this.emitter,e=t.damping,s=t.angleDamping,i=t.restitution,o=t.friction,a=t.gravityScale,r=t.collideTiles,c=t.particleCollideCallback;if(this.lifeTime>0&&ee-this.spawnTime>this.lifeTime){this.destroy();return}let l=this.pos.copy();if(this.velocity.x*=e,this.velocity.y*=e,this.pos.x+=this.velocity.x+=Xt.x*a,this.pos.y+=this.velocity.y+=Xt.y*a,this.angle+=this.angleVelocity*=s,!Li||!r)return;let u=this.velocity.lengthSquared();if(u>Ne*Ne){let f=Ne/u**.5;this.velocity.x*=f,this.velocity.y*=f}this.groundObject=void 0;let h=c?f=>{let d=ri(f);return d&&c(this,d,f)}:f=>ri(f)>0;if(h(this.pos)){let f=Ze(this.pos);if(!h(l)){let d=h(b(this.pos.x,l.y)),y=h(b(l.x,this.pos.y)),x=tt(i,f.restitution),v=tt(o,f.friction);d&&(this.pos.x=l.x,this.velocity.x*=-x,this.velocity.y*=v),(y||!d)&&((this.velocity.y<0&&Xt.y<0||this.velocity.y>0&&Xt.y>0)&&(this.groundObject=f),this.pos.y=l.y,this.velocity.y*=-x,this.velocity.x*=v),ge&&Ct(this.pos,this.size,"#f00")}}}destroy(){let t=this.emitter.particleDestroyCallback,e=this.colorEnd;this.color.set(e.r,e.g,e.b,e.a),this.size.set(this.sizeEnd,this.sizeEnd),this.destroyed=!0,t==null||t(this)}render(){let t=this.emitter,e=t.localSpace,s=t.additive,i=t.trailScale,o=t.fadeRate/2,a=this.lifeTime>0?st((ee-this.spawnTime)/this.lifeTime,1):1,r=1-a,c=r*this.sizeStart+a*this.sizeEnd,l=b(c),u=a1-o?(1-a)/o:1;this.color.r=r*this.colorStart.r+a*this.colorEnd.r,this.color.g=r*this.colorStart.g+a*this.colorEnd.g,this.color.b=r*this.colorStart.b+a*this.colorEnd.b,this.color.a=(r*this.colorStart.a+a*this.colorEnd.a)*u;let h=Vh.set(this.pos.x,this.pos.y),f=this.angle;if(e){let d=t.angle,y=ut(-d),x=rt(-d);h.set(t.pos.x+h.x*y-h.y*x,t.pos.y+h.x*x+h.y*y),f+=d}if(s&&hs(),i){let d=e?this.velocity.rotate(t.angle):this.velocity,y=d.length();if(y){let x=y*i;l.y=tt(l.x,x),f=er(d.x,d.y),Ft(h,l,this.tileInfo,this.color,f,this.mirror)}}else Ft(h,l,this.tileInfo,this.color,f,this.mirror);s&&hs(!1),xn&&Ct(h,l,"#f005",0,f)}},Dr=!0,wo=!0,di=5e5,Ir=11,yc=Ir*4,Wh=di/yc|0,Ii=3,mc=Ii*4,Nn=di/mc|0;fn=!1,fi=5,Fn=.5,pi=b(640,80),zr=!1,ws={},Us=[];yi=class{constructor(t,e,s="",i="\u{1F3C6}",o){p(t>=0&&!ws[t]),this.id=t,this.name=e,this.description=s,this.icon=i,this.unlocked=!1,this.image=void 0,o&&((this.image=new Image).src=o),ws[t]=this}unlock(){zr||this.unlocked||(p(gi,"save name must be set"),this.unlocked=!0,Jr(),Us.push(this))}render(t=0){let e=pt,s=st(pi.x,N.width),i=pi.y,o=N.width-s,a=-i*t,r=Be(0,0,.9);e.save(),e.beginPath(),e.fillStyle=r.toString(),e.strokeStyle=at.toString(),e.lineWidth=3,e.rect(o,a,s,i),e.fill(),e.stroke(),e.clip();let c=b(.1,.05).scale(i),l=i-2*c.x;this.renderIcon(b(o+c.x+l/2,a+i/2),l);let u=i*.5,h=i*.3,f=b(o+l+2*c.x,a+c.y*2+u/2),d=s-l-3*c.x;rn(this.name,f,u,at,0,void 0,"left",void 0,void 0,d),f.y=a+i-c.y*2-h/2,rn(this.description,f,h,at,0,void 0,"left",void 0,void 0,d),e.restore()}renderIcon(t,e){this.image?pt.drawImage(this.image,t.x-e/2,t.y-e/2,e,e):rn(this.icon,t,e*.7,at)}};Co=class extends yi{constructor(t,e,s,i,o){super(t,e,s,i,o)}unlock(){super.unlock(),Ts&&Ts.unlockMedal(this.id)}},Eo=class{constructor(t,e,s){var c,l,u;p(!Ts,"there can only be one newgrounds object"),p(!e||s,"must provide cryptojs if there is a cipher"),Ts=this,this.app_id=t,this.cipher=e,this.cryptoJS=s,this.host=location?location.hostname:"";let i=new URL(location.href);if(this.session_id=i.searchParams.get("ngio_session_id"),!this.session_id)return;let o=this.call("Medal.getList");if(!o||!o.result||o.result.error){fn&&Et("Newgrounds session unavailable; skipping plugin init"),this.medals=[],this.scoreboards=[];return}this.medals=((c=o.result.data)==null?void 0:c.medals)||[],fn&&Et(this.medals);for(let h of this.medals){let f=ws[h.id];f&&(f.image=new Image,f.image.src=h.icon,f.name=h.name,f.description=h.description,f.unlocked=h.unlocked,f.difficulty=h.difficulty,f.value=h.value,f.value&&(f.description=f.description+` (${f.value})`))}let a=this.call("ScoreBoard.getBoards");this.scoreboards=((u=(l=a==null?void 0:a.result)==null?void 0:l.data)==null?void 0:u.scoreboards)||[],fn&&Et(this.scoreboards);let r=60*1e3;setInterval(()=>this.call("Gateway.ping",0,!0),r)}unlockMedal(t){return this.call("Medal.unlock",{id:t},!0)}postScore(t,e){return this.call("ScoreBoard.postScore",{id:t,value:e},!0)}getScores(t,e,s=0,i=0,o=10){return this.call("ScoreBoard.getScores",{id:t,user:e,social:s,skip:i,limit:o})}logView(){return this.call("App.logView",{host:this.host},!0)}call(t,e,s=!1){let i={component:t,parameters:e};if(this.cipher){let l=this.cryptoJS,u=l.enc.Base64.parse(this.cipher),h=l.lib.WordArray.random(16),f=l.AES.encrypt(JSON.stringify(i),u,{iv:h});i.secure=l.enc.Base64.stringify(h.concat(f.ciphertext)),i.parameters=0}let o={app_id:this.app_id,session_id:this.session_id,call:i},a=new FormData;a.append("input",JSON.stringify(o));let r=new XMLHttpRequest;r.open("POST","https://newgrounds.io/gateway_v3.php",!fn&&s);try{r.send(a)}catch(l){fn&&Et("newgrounds call failed",l);return}return fn&&Et(r.responseText),r.responseText&&JSON.parse(r.responseText)}},_o=class{constructor(t,e=!1,s=!1){p(!jt,"Post process already initialized"),p(!(e&&s),"Post process cannot both include main canvas and use feedback texture"),jt=this,t||(t="void mainImage(out vec4 c,vec2 p){c=texture(iChannel0,p/iResolution.xy);}"),this.shader=void 0,this.texture=void 0,this.vao=void 0,i(),En(void 0,r,o,a);function i(){if(U)return;if(!j){console.warn("PostProcessPlugin: WebGL not enabled!");return}jt.texture=ki(),jt.shader=Hn(`#version 300 es
+color = `+this.color),t}renderDebugInfo(){if(!Jt)return;let t=this.collideTiles||this.collideSolidObjects||this.isSolid;if(!t&&!this.parent)return;let e=b(tt(this.size.x,.2),tt(this.size.y,.2)),s=V(this.collideTiles?1:0,this.collideSolidObjects?1:0,this.isSolid?1:0,.5);Ct(this.pos,e,s,0,this.angle,t),this.parent&&Ct(this.pos,e.scale(.8),V(1,1,1,.5),0,this.angle),this.parent&&Ee(this.pos,this.parent.pos,V(1,1,1,.5),.5)}},k=b(),hn=[];De=class n{constructor(t=b(),e=_i,s=hn[0],i=Ri,o=Pi){this.pos=t.copy(),this.size=e.copy(),this.padding=i,this.textureInfo=s,this.bleed=o}offset(t){return new n(this.pos.add(t),this.size,this.textureInfo,this.padding,this.bleed)}frame(t){p(typeof t=="number");let e=this.size.x+this.padding*2,s=t*e;return p(s+this.size.x<=this.textureInfo.size.x,"frame extends beyond texture width!"),this.offset(new ut(s))}setFullImage(t=this.textureInfo){return this.textureInfo=t,this.pos=new ut,this.size=t.size.copy(),this.bleed=this.padding=0,this}tile(t){return Ls(t,this.size,this.textureInfo,this.padding,this.bleed)}},He=class{constructor(t,e=!0,s=!1){this.image=t,this.size=t?b(t.width,t.height):b(),this.sizeInverse=t?b(1/t.width,1/t.height):b(),this.glTexture=void 0,this.wrap=s,e&&this.createWebGLTexture()}createWebGLTexture(){Hh(this)}destroyWebGLTexture(){Xh(this)}hasWebGL(){return!!this.glTexture}setWrap(t=!0){this.wrap=t,vc(this.glTexture,t)}};nh=0;ei=class{constructor(t){p(!!t,"tileInfo is required for ImageFont"),this.tileInfo=t.frame(0)}drawText(t,e,s=1,i,o,a,r){p(O(s)||typeof s=="number","size must be a vec2 or number"),typeof s=="number"?(p(s>0),s*=K,s=new ut(s,s)):s=s.scale(K),this.drawTextScreen(t,Pn(e),s,i,o,a,r)}drawTextScreen(t,e,s,i=!0,o=H,a=j,r){p(q(t),"text must be a string"),p(O(e),"pos must be a vec2"),p(O(s)||typeof s=="number","size must be a vec2 or number"),p(W(o),"color must be a color"),s=typeof s=="number"?new ut(s,s):s;let c=new ut,l=this.tileInfo,u=l.padding,h=l.size.x+u*2,f=l.size.y+u*2,d=l.textureInfo.size.x/h|0;(t+"").split(`
+`).forEach((y,x)=>{let v=i?(y.length-1)*s.x/2:0;for(let w=y.length;w--;){let _=y.charCodeAt(w),S=_<32||_>127?95:_-32,E=S%d,A=S/d|0;l.pos.x=E*h+u,l.pos.y=A*f+u,c.x=e.x+w*s.x-v|0,c.y=e.y+x*s.y|0,jt(c,s,l,o,0,!1,void 0,a,!0,r)}})}};ke=b(),Ht=b(),Sr=b(),Te=b(),wr=0,ni=!0,jn=!1,en="mouse",Tr=6,Gn=!0,At=0,le=!U&&window.ontouchstart!==void 0;Z=[[]],Ae=[],pn=[],ro=[],Un=new Pe,ue=[],An=[],si=[],Is=[],Je=new Map,ps=[],Vn=!0;ii="http://www.w3.org/2000/svg";mt=new AudioContext,Kn=44100;ys=class{constructor(t,e,s=mr,i=br,o){var a;if(!(!Qt||U)){if(p(!t||me(t)||q(t),"asset must be a file name or zzfx array"),p(e===void 0||R(e),"randomness must be a number"),p(e===void 0||e>=0&&e<=1,"randomness must be between 0 and 1"),p(R(s),"range must be a number"),p(R(i),"taper must be a number"),this.range=s,this.taper=i,this.randomness=e!=null?e:0,this.sampleRate=Kn,this.loadedPercent=0,this.onloadCallback=o,me(t)){let r=t.slice(),c=e!=null?e:.05,l=1;this.randomness=(a=r[l])!=null?a:c,r[l]=0,this.sampleChannels=[Mi(...r)],this.loadedPercent=1,o==null||o(this)}else if(typeof t=="string"){let r=t;this.loadSound(r)}}}play(t,e=1,s=1,i=1,o=!1,a=!1){if(p(!t||O(t),"pos must be a vec2"),p(R(e),"volume must be a number"),p(R(s),"pitch must be a number"),p(R(i),"randomnessScale must be a number"),!Qt||U||!this.sampleChannels)return;let r;if(t){let u=this.range;if(u){let h=Mt.distanceSquared(t);if(h>u*u)return;e*=Ut(h**.5,u,u*this.taper)}r=Pn(t).x*2/N.width-1}let c=s+s*this.randomness*i*yt(-1,1),l=new oi(this,e,c,r,o,a);return Jt&&zn&&t&&(Xt(t,.5,"#0ff",.5,!0),this.range&&(Xt(t,2*this.range,"#0ff",.5),Xt(t,2*this.range*this.taper,"#0ff",.5)),Dn("vol "+e.toFixed(2)+" pitch "+c.toFixed(2),t,.5,"#0ff",.5)),l}playMusic(t=1,e=!0,s=!1){return this.play(void 0,t,1,0,e,s)}playNote(t=0,e,s){p(R(t),"semitoneOffset must be a number");let i=pc(t,1);return this.play(e,s,i,0)}getDuration(){var t,e;return((e=(t=this.sampleChannels)==null?void 0:t[0])==null?void 0:e.length)/this.sampleRate||0}isLoaded(){return this.loadedPercent===1}async loadSound(t){var c;let e=await fetch(t);if(!e.ok)throw new Error(`Failed to load sound from ${t}: ${e.status} ${e.statusText}`);let s=await e.arrayBuffer(),i=await mt.decodeAudioData(s),o=i.numberOfChannels,a=1e5,r=[];for(let l=0;lsetTimeout(v,0));let d=st(f+a,h);for(;f=0,"Sound volume must be positive or zero"),p(s>=0,"Sound rate must be positive or zero"),p(R(i),"Sound pan must be a number"),this.sound=t,this.volume=e,this.rate=s,this.pan=i,this.loop=o,this.pausedTime=0,this.startTime=void 0,this.gainNode=void 0,this.source=void 0,this.onendedCallback=r=>{r===this.source&&(this.source=void 0)},a||this.start()}start(t=0){p(t>=0,"Sound start offset must be positive or zero"),this.isPlaying()&&this.stop(),this.gainNode=mt.createGain(),this.source=Or(this.sound.sampleChannels,this.volume,this.rate,this.pan,this.loop,this.sound.sampleRate,this.gainNode,t,this.onendedCallback),this.source?(this.startTime=mt.currentTime-t,this.pausedTime=void 0):(this.startTime=void 0,this.pausedTime=0)}setVolume(t){p(t>=0,"Sound volume must be positive or zero"),this.volume=t,this.gainNode&&(this.gainNode.gain.value=t)}stop(t=0){if(p(t>=0,"Sound fade time must be positive or zero"),this.isPlaying())if(t){let e=mt.currentTime,s=e+t;this.gainNode.gain.cancelScheduledValues(e),this.gainNode.gain.setValueAtTime(this.volume,e),this.gainNode.gain.linearRampToValueAtTime(0,s),this.source.stop(s)}else this.source.stop();this.pausedTime=0,this.source=void 0,this.startTime=void 0}pause(){this.isPaused()||(this.pausedTime=this.getCurrentTime(),this.source.stop(),this.source=void 0,this.startTime=void 0)}resume(){this.isPaused()&&this.start(this.pausedTime)}isPlaying(){return!!this.source}isPaused(){return!this.isPlaying()}getCurrentTime(){if(!this.isPlaying())return this.pausedTime;let t=this.getDuration();return t?ce(mt.currentTime-this.startTime,t):0}getDuration(){return this.rate?this.sound.getDuration()/this.rate:0}getSource(){return this.source}};an=[];wn=class{constructor(t,e=0,s=!1,i=new Lt){this.tile=t,this.direction=e,this.mirror=s,this.color=i.copy()}clear(){this.tile=this.direction=0,this.mirror=!1,this.color=new Lt}},ai=class extends qe{constructor(t,e,s=0,i=0,o=b(512),a=!0){var r;p(O(o),"canvasSize must be a Vector2"),super(t,e,void 0,s,H,i),this.canvas=U?void 0:new OffscreenCanvas(o.x,o.y),this.context=(r=this.canvas)==null?void 0:r.getContext("2d"),this.textureInfo=new He(this.canvas,a),this.mass=0}destroy(){this.destroyed||(this.textureInfo.destroyWebGLTexture(),super.destroy())}render(){this.draw(this.pos,this.size,this.color,this.angle,this.mirror,this.additiveColor)}draw(t,e,s=H,i=0,o=!1,a,r=!1,c){let l=new De().setFullImage(this.textureInfo),u=this.hasWebGL();jt(t,e,l,s,i,o,a,u,r,c)}updateWebGL(){this.textureInfo.createWebGLTexture()}hasWebGL(){return j&&this.textureInfo.hasWebGL()}},ms=class extends ai{constructor(t,e,s=Ls(),i=0,o=!0){let a=s?e.multiply(s.size):e;if(super(t,e,0,i,a,o),this.tileInfo=void 0,this.data=[],this.isUsingWebGL=!1,U){this.render=()=>{},this.redraw=()=>{},this.redrawStart=()=>{},this.redrawEnd=()=>{},this.drawTileData=()=>{},this.redrawTileData=()=>{},this.drawLayerTile=()=>{},this.drawLayerRect=()=>{},this.drawTile=()=>{},this.drawRect=()=>{},this.clearLayerRect=()=>{};return}s&&(this.tileInfo=s.frame(0),this.tileInfo.bleed=0);for(let r=this.size.area();r--;)this.data.push(new wn)}setData(t,e,s=!1){if(t=t.floor(),p(O(t),"layerPos must be a Vector2"),p(e instanceof wn,"data must be a TileLayerData"),!t.arrayCheck(this.size)||(this.data[(t.y|0)*this.size.x+(t.x|0)]=e,!s))return;Ot===this.context?this.drawTileData(t):this.redrawTileData(t)}clearData(t,e=!1){this.setData(t,new wn,e)}getData(t){return p(O(t),"layerPos must be a Vector2"),t.arrayCheck(this.size)?this.data[(t.y|0)*this.size.x+(t.x|0)]:void 0}update(){!j&&this.isUsingWebGL&&(this.isUsingWebGL=!1,this.redraw())}render(){p(Ot!==this.context,"must call redrawEnd() after drawing tiles!");let t=this.drawSize||this.size,e=this.pos.add(t.scale(.5));this.draw(e,this.size,this.color,this.angle,this.mirror,this.additiveColor)}onRedraw(){}redraw(){this.redrawStart(!0);for(let t=this.size.x;t--;)for(let e=this.size.y;e--;)this.drawTileData(b(t,e),!1);this.isUsingWebGL&&It(),this.onRedraw(),this.redrawEnd()}redrawStart(t=!1){var s,i;if(!this.context)return;p(Ot!==this.context),this.savedRenderSettings=[Ot,k,Mt,K,sn],Ot=this.context;let e=(i=(s=this.tileInfo)==null?void 0:s.size)!=null?i:b(1);k=this.size.multiply(e),sn=xe,Mt=this.size.multiply(e).scale(.5),K=1,this.isUsingWebGL=this.hasWebGL(),this.isUsingWebGL?ns(this.textureInfo.glTexture,t):(this.context.imageSmoothingEnabled=!Tn,t&&(this.canvas.width=k.x,this.canvas.height=k.y))}redrawEnd(){this.context&&(p(Ot===this.context),this.isUsingWebGL&&ns(),[Ot,k,Mt,K,sn]=this.savedRenderSettings)}drawTileData(t,e=!0){var r,c;if(!this.context)return;p(Ot===this.context,"must call redrawStart() before drawing tiles");let s=(c=(r=this.tileInfo)==null?void 0:r.size)!=null?c:b(1),i=t.multiply(s);e&&this.clearLayerRect(i,s);let o=this.getData(t);if(!o||!o.tile)return;let a=this.tileInfo&&this.tileInfo.tile(o.tile);this.drawLayerTile(i,s,a,o.color,o.direction*Q/2,o.mirror)}redrawTileData(t,e=!0){this.context&&(p(Ot!==this.context,"redrawStart() should not be active when calling redrawTileData(), instead use drawTileData()"),this.redrawStart(),this.drawTileData(t,e),this.redrawEnd())}drawLayerTile(t,e=b(1),s,i=H,o=0,a,r){let c=t.add(e.scale(.5));jt(c,e,s,i,o,a,r,this.isUsingWebGL)}drawLayerRect(t,e,s,i=0){this.drawLayerTile(t,e,void 0,s,i)}drawTile(t,e=b(1),s,i=new Lt,o=0,a=!1){t=t.subtract(this.pos).multiply(this.tileInfo.size),e=e.multiply(this.tileInfo.size),t.y=this.canvas.height-t.y;let r=k;k=b(this.canvas.width,this.canvas.height);let c=this.hasWebGL();c&&ns(this.textureInfo.glTexture);let l=c?void 0:this.context;jt(t,e,s,i,o,a,void 0,c,!0,l),c&&ns(),k=r}drawRect(t,e,s,i){this.drawTile(t,e,void 0,s,i)}clearLayerRect(t,e){p(Ot===this.context,"must call redrawStart() before clearing tiles");let s=t.x,i=this.canvas.height-t.y-e.y;this.hasWebGL()?Ac(s,i,e.x,e.y):this.context.clearRect(s,i,e.x,e.y)}},bs=class extends ms{constructor(t,e,s=Ls(),i=0,o=!0){super(t,e.floor(),s,i,o),this.collisionData=[],this.initCollision(this.size),an.push(this),this.isSolid=!0}destroy(){if(this.destroyed)return;let t=an.indexOf(this);p(t>=0,"tile collision layer not found in array"),t>=0&&an.splice(t,1),super.destroy()}initCollision(t){p(O(t),"size must be a Vector2"),this.size=t.floor(),this.collisionData=[],this.collisionData.length=t.area(),this.collisionData.fill(0)}setCollisionData(t,e=1){p(O(t),"layerPos must be a Vector2");let s=(t.y|0)*this.size.x+(t.x|0);t.arrayCheck(this.size)&&(this.collisionData[s]=e)}clearCollisionData(t){this.setCollisionData(t,0)}getCollisionData(t){p(O(t),"layerPos must be a Vector2");let e=(t.y|0)*this.size.x+(t.x|0);return t.arrayCheck(this.size)?this.collisionData[e]:0}collisionTest(t,e=new ut,s){p(O(t)&&O(e),"pos and size must be Vector2s"),p(!s||typeof s=="function"||s instanceof qe,"callbackObject must be a function or EngineObject");let i=s?typeof s=="function"?(f,d)=>s(f,d):(f,d)=>s.collideWithTile(f,d):()=>!0,o=t.x-this.pos.x,a=t.y-this.pos.y;if(o+e.x/2<0||o-e.x/2>this.size.x||a+e.y/2<0||a-e.y/2>this.size.y)return!1;let r=tt(o-e.x/2|0,0),c=tt(a-e.y/2|0,0),l=st(tt(o+e.x/2,r+1),this.size.x),u=st(tt(a+e.y/2,c+1),this.size.y),h=new ut;for(let f=c;fs(l,u):(l,u)=>s.collideWithTile(l,u):l=>l>0,a=l=>{let u=this.getCollisionData(r.set(l.x-this.pos.x,l.y-this.pos.y));return u&&o(u,l)},r=new ut,c=Wa(t,e,a,i);if(ye&&c){let l=c.floor().add(b(.5));Ct(l,b(1),"#f008"),Ee(t,e,"#00f",.02),Ee(t,c,"#f00",.02),tr(c,"#0f0"),i&&Ee(c,c.add(i),"#ff0",.02)}return c}},bo=class extends qe{constructor(t,e,s=0,i=0,o=100,a=Q,r,c=H,l=H,u=ln,h=ln,f=.5,d=.1,y=1,x=.1,v=.05,w=1,_=1,S=0,E=Q,A=.1,T=.2,P=!1,F=!1,bt=!0,ct=F?1e9:0,gt=!1){super(t,b(),r,e,void 0,ct),this.emitCircle=typeof s=="number",this.emitSize=typeof s=="number"?b(s):s.copy(),this.emitTime=i,this.emitRate=o,this.emitConeAngle=a,this.colorStartA=c.copy(),this.colorStartB=l.copy(),this.colorEndA=u.copy(),this.colorEndB=h.copy(),this.randomColorLinear=bt,this.particleTime=f,this.sizeStart=d,this.sizeEnd=y,this.speed=x,this.angleSpeed=v,this.damping=w,this.angleDamping=_,this.gravityScale=S,this.particleConeAngle=E,this.fadeRate=A,this.randomness=T,this.collideTiles=P,this.additive=F,this.localSpace=gt,this.trailScale=0,this.particleCreateCallback=void 0,this.particleDestroyCallback=void 0,this.particleCollideCallback=void 0,this.velocityInheritance=0,this.emitTimeBuffer=0,this.particles=[],this.previousAngle=this.angle,this.previousPos=this.pos.copy()}update(){if(p(this.angleDamping>=0&&this.angleDamping<=1),p(this.damping>=0&&this.damping<=1),this.velocityInheritance){let s=this.velocityInheritance;this.velocity.x=s*(this.pos.x-this.previousPos.x),this.velocity.y=s*(this.pos.y-this.previousPos.y),this.angleVelocity=s*(this.angle-this.previousAngle),this.previousAngle=this.angle,this.previousPos.x=this.pos.x,this.previousPos.y=this.pos.y}if(this.isActive()){if(this.emitRate&&$s){let s=1/this.emitRate/$s;for(this.emitTimeBuffer+=Qo;this.emitTimeBuffer>0;this.emitTimeBuffer-=s)this.emitParticle()}}else this.particles.length===0&&this.destroy(!0);let t=this.particles,e=0;for(let s=0;s_+_*yt(s,-s),o=i(this.particleTime),a=i(this.sizeStart),r=i(this.sizeEnd),c=i(this.speed),l=i(this.angleSpeed)*Ha(),u=yt(this.emitConeAngle,-this.emitConeAngle),h=ho(this.colorStartA,this.colorStartB,this.randomColorLinear),f=ho(this.colorEndA,this.colorEndB,this.randomColorLinear),d=this.localSpace?u:this.angle+u,y=b(c*rt(d),c*ht(d)),x=l;!this.localSpace&&this.velocityInheritance>0&&(y.x+=this.velocity.x,y.y+=this.velocity.y,x+=this.angleVelocity);let v=new ci(this,t,e,h,f,o,a,r,y,x);return this.particles.push(v),(w=this.particleCreateCallback)==null||w.call(this,v),v}updatePhysics(){}render(){for(let t of this.particles)t.render()}isActive(){return!this.emitTime||this.getAliveTime()0&&(this.destroyed=!1,this.emitTime=-1))}},Vh=new ut,ci=class{constructor(t,e,s,i,o,a,r,c,l=b(),u=0){this.emitter=t,this.pos=e,this.angle=s,this.size=b(r),this.color=i.copy(),this.colorStart=i,this.colorEnd=o,this.lifeTime=a,this.sizeStart=r,this.sizeEnd=c,this.velocity=l,this.angleVelocity=u,this.spawnTime=ne,this.mirror=qa(),this.groundObject=void 0,this.destroyed=!1,this.tileInfo=t.tileInfo}update(){let t=this.emitter,e=t.damping,s=t.angleDamping,i=t.restitution,o=t.friction,a=t.gravityScale,r=t.collideTiles,c=t.particleCollideCallback;if(this.lifeTime>0&&ne-this.spawnTime>this.lifeTime){this.destroy();return}let l=this.pos.copy();if(this.velocity.x*=e,this.velocity.y*=e,this.pos.x+=this.velocity.x+=Yt.x*a,this.pos.y+=this.velocity.y+=Yt.y*a,this.angle+=this.angleVelocity*=s,!Li||!r)return;let u=this.velocity.lengthSquared();if(u>Ne*Ne){let f=Ne/u**.5;this.velocity.x*=f,this.velocity.y*=f}this.groundObject=void 0;let h=c?f=>{let d=ri(f);return d&&c(this,d,f)}:f=>ri(f)>0;if(h(this.pos)){let f=Ze(this.pos);if(!h(l)){let d=h(b(this.pos.x,l.y)),y=h(b(l.x,this.pos.y)),x=tt(i,f.restitution),v=tt(o,f.friction);d&&(this.pos.x=l.x,this.velocity.x*=-x,this.velocity.y*=v),(y||!d)&&((this.velocity.y<0&&Yt.y<0||this.velocity.y>0&&Yt.y>0)&&(this.groundObject=f),this.pos.y=l.y,this.velocity.y*=-x,this.velocity.x*=v),ge&&Ct(this.pos,this.size,"#f00")}}}destroy(){let t=this.emitter.particleDestroyCallback,e=this.colorEnd;this.color.set(e.r,e.g,e.b,e.a),this.size.set(this.sizeEnd,this.sizeEnd),this.destroyed=!0,t==null||t(this)}render(){let t=this.emitter,e=t.localSpace,s=t.additive,i=t.trailScale,o=t.fadeRate/2,a=this.lifeTime>0?st((ne-this.spawnTime)/this.lifeTime,1):1,r=1-a,c=r*this.sizeStart+a*this.sizeEnd,l=b(c),u=a1-o?(1-a)/o:1;this.color.r=r*this.colorStart.r+a*this.colorEnd.r,this.color.g=r*this.colorStart.g+a*this.colorEnd.g,this.color.b=r*this.colorStart.b+a*this.colorEnd.b,this.color.a=(r*this.colorStart.a+a*this.colorEnd.a)*u;let h=Vh.set(this.pos.x,this.pos.y),f=this.angle;if(e){let d=t.angle,y=ht(-d),x=rt(-d);h.set(t.pos.x+h.x*y-h.y*x,t.pos.y+h.x*x+h.y*y),f+=d}if(s&&hs(),i){let d=e?this.velocity.rotate(t.angle):this.velocity,y=d.length();if(y){let x=y*i;l.y=tt(l.x,x),f=er(d.x,d.y),jt(h,l,this.tileInfo,this.color,f,this.mirror)}}else jt(h,l,this.tileInfo,this.color,f,this.mirror);s&&hs(!1),xn&&Ct(h,l,"#f005",0,f)}},Dr=!0,wo=!0,di=5e5,Ir=11,yc=Ir*4,Wh=di/yc|0,Ii=3,mc=Ii*4,Nn=di/mc|0;fn=!1,fi=5,Fn=.5,pi=b(640,80),zr=!1,ws={},Us=[];yi=class{constructor(t,e,s="",i="\u{1F3C6}",o){p(t>=0&&!ws[t]),this.id=t,this.name=e,this.description=s,this.icon=i,this.unlocked=!1,this.image=void 0,o&&((this.image=new Image).src=o),ws[t]=this}unlock(){zr||this.unlocked||(p(gi,"save name must be set"),this.unlocked=!0,Jr(),Us.push(this))}render(t=0){let e=pt,s=st(pi.x,N.width),i=pi.y,o=N.width-s,a=-i*t,r=Be(0,0,.9);e.save(),e.beginPath(),e.fillStyle=r.toString(),e.strokeStyle=at.toString(),e.lineWidth=3,e.rect(o,a,s,i),e.fill(),e.stroke(),e.clip();let c=b(.1,.05).scale(i),l=i-2*c.x;this.renderIcon(b(o+c.x+l/2,a+i/2),l);let u=i*.5,h=i*.3,f=b(o+l+2*c.x,a+c.y*2+u/2),d=s-l-3*c.x;rn(this.name,f,u,at,0,void 0,"left",void 0,void 0,d),f.y=a+i-c.y*2-h/2,rn(this.description,f,h,at,0,void 0,"left",void 0,void 0,d),e.restore()}renderIcon(t,e){this.image?pt.drawImage(this.image,t.x-e/2,t.y-e/2,e,e):rn(this.icon,t,e*.7,at)}};Co=class extends yi{constructor(t,e,s,i,o){super(t,e,s,i,o)}unlock(){super.unlock(),Ts&&Ts.unlockMedal(this.id)}},Eo=class{constructor(t,e,s){var c,l,u;p(!Ts,"there can only be one newgrounds object"),p(!e||s,"must provide cryptojs if there is a cipher"),Ts=this,this.app_id=t,this.cipher=e,this.cryptoJS=s,this.host=location?location.hostname:"";let i=new URL(location.href);if(this.session_id=i.searchParams.get("ngio_session_id"),!this.session_id)return;let o=this.call("Medal.getList");if(!o||!o.result||o.result.error){fn&&Et("Newgrounds session unavailable; skipping plugin init"),this.medals=[],this.scoreboards=[];return}this.medals=((c=o.result.data)==null?void 0:c.medals)||[],fn&&Et(this.medals);for(let h of this.medals){let f=ws[h.id];f&&(f.image=new Image,f.image.src=h.icon,f.name=h.name,f.description=h.description,f.unlocked=h.unlocked,f.difficulty=h.difficulty,f.value=h.value,f.value&&(f.description=f.description+` (${f.value})`))}let a=this.call("ScoreBoard.getBoards");this.scoreboards=((u=(l=a==null?void 0:a.result)==null?void 0:l.data)==null?void 0:u.scoreboards)||[],fn&&Et(this.scoreboards);let r=60*1e3;setInterval(()=>this.call("Gateway.ping",0,!0),r)}unlockMedal(t){return this.call("Medal.unlock",{id:t},!0)}postScore(t,e){return this.call("ScoreBoard.postScore",{id:t,value:e},!0)}getScores(t,e,s=0,i=0,o=10){return this.call("ScoreBoard.getScores",{id:t,user:e,social:s,skip:i,limit:o})}logView(){return this.call("App.logView",{host:this.host},!0)}call(t,e,s=!1){let i={component:t,parameters:e};if(this.cipher){let l=this.cryptoJS,u=l.enc.Base64.parse(this.cipher),h=l.lib.WordArray.random(16),f=l.AES.encrypt(JSON.stringify(i),u,{iv:h});i.secure=l.enc.Base64.stringify(h.concat(f.ciphertext)),i.parameters=0}let o={app_id:this.app_id,session_id:this.session_id,call:i},a=new FormData;a.append("input",JSON.stringify(o));let r=new XMLHttpRequest;r.open("POST","https://newgrounds.io/gateway_v3.php",!fn&&s);try{r.send(a)}catch(l){fn&&Et("newgrounds call failed",l);return}return fn&&Et(r.responseText),r.responseText&&JSON.parse(r.responseText)}},_o=class{constructor(t,e=!1,s=!1){p(!Bt,"Post process already initialized"),p(!(e&&s),"Post process cannot both include main canvas and use feedback texture"),Bt=this,t||(t="void mainImage(out vec4 c,vec2 p){c=texture(iChannel0,p/iResolution.xy);}"),this.shader=void 0,this.texture=void 0,this.vao=void 0,i(),En(void 0,r,o,a);function i(){if(U)return;if(!j){console.warn("PostProcessPlugin: WebGL not enabled!");return}Bt.texture=ki(),Bt.shader=Hn(`#version 300 es
 precision highp float;in vec2 p;void main(){gl_Position=vec4(p+p-1.,1,1);}`,`#version 300 es
 precision highp float;uniform sampler2D iChannel0;uniform vec3 iResolution;uniform float iTime;out vec4 c;
 `+t+`
-void main(){mainImage(c,gl_FragCoord.xy);c.a=1.;}`),jt.vao=g.createVertexArray(),g.bindVertexArray(jt.vao),g.bindBuffer(g.ARRAY_BUFFER,Bn);let c=8,l=g.getAttribLocation(jt.shader,"p");g.enableVertexAttribArray(l),g.vertexAttribPointer(l,2,g.FLOAT,!1,c,0)}function o(){jt.shader=void 0,jt.texture=void 0,Et("PostProcessPlugin: WebGL context lost")}function a(){i(),Et("PostProcessPlugin: WebGL context restored")}function r(){if(U||!j)return;It(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.useProgram(jt.shader),g.bindVertexArray(jt.vao),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!0),g.disable(g.BLEND),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,jt.texture),e?(Ue.width=k.x,Ue.height=k.y,Fr(tn),tn.drawImage(N,0,0),N.width|=0,g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,Ue)):s||g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,it);let c=l=>g.getUniformLocation(jt.shader,l);g.uniform1i(c("iChannel0"),0),g.uniform1f(c("iTime"),ee),g.uniform3f(c("iResolution"),N.width,N.height,1),g.drawArrays(g.TRIANGLE_STRIP,0,4),s&&g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,it),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!1),vs(!0)}}},Ro=class{constructor(t,e){p(!$,"LightSystemPlugin already initialized"),p(!jt,"LightSystemPlugin must be created before PostProcessPlugin"),$=this,this.enabled=!0,this.ambientColor=(e||at).copy(),this.textureSize=t?t.copy():void 0,this.texture=void 0,this.lightShader=void 0,this.compositeShader=void 0,this.lightVAO=void 0,this.compositeVAO=void 0,s(),En(void 0,i,o,a);function s(){if(U)return;if(!j){console.warn("LightSystemPlugin: WebGL not enabled!");return}$.textureSize||($.textureSize=k.copy()),$.texture=g.createTexture(),g.bindTexture(g.TEXTURE_2D,$.texture),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,$.textureSize.x,$.textureSize.y,0,g.RGBA,g.UNSIGNED_BYTE,null),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,g.CLAMP_TO_EDGE),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,g.CLAMP_TO_EDGE),$.lightShader=Hn(`#version 300 es
+void main(){mainImage(c,gl_FragCoord.xy);c.a=1.;}`),Bt.vao=g.createVertexArray(),g.bindVertexArray(Bt.vao),g.bindBuffer(g.ARRAY_BUFFER,Bn);let c=8,l=g.getAttribLocation(Bt.shader,"p");g.enableVertexAttribArray(l),g.vertexAttribPointer(l,2,g.FLOAT,!1,c,0)}function o(){Bt.shader=void 0,Bt.texture=void 0,Et("PostProcessPlugin: WebGL context lost")}function a(){i(),Et("PostProcessPlugin: WebGL context restored")}function r(){if(U||!j)return;It(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.useProgram(Bt.shader),g.bindVertexArray(Bt.vao),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!0),g.disable(g.BLEND),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,Bt.texture),e?(Ue.width=k.x,Ue.height=k.y,Fr(tn),tn.drawImage(N,0,0),N.width|=0,g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,Ue)):s||g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,it);let c=l=>g.getUniformLocation(Bt.shader,l);g.uniform1i(c("iChannel0"),0),g.uniform1f(c("iTime"),ne),g.uniform3f(c("iResolution"),N.width,N.height,1),g.drawArrays(g.TRIANGLE_STRIP,0,4),s&&g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,it),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!1),vs(!0)}}},Ro=class{constructor(t,e){p(!$,"LightSystemPlugin already initialized"),p(!Bt,"LightSystemPlugin must be created before PostProcessPlugin"),$=this,this.enabled=!0,this.ambientColor=(e||at).copy(),this.textureSize=t?t.copy():void 0,this.texture=void 0,this.lightShader=void 0,this.compositeShader=void 0,this.lightVAO=void 0,this.compositeVAO=void 0,s(),En(void 0,i,o,a);function s(){if(U)return;if(!j){console.warn("LightSystemPlugin: WebGL not enabled!");return}$.textureSize||($.textureSize=k.copy()),$.texture=g.createTexture(),g.bindTexture(g.TEXTURE_2D,$.texture),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,$.textureSize.x,$.textureSize.y,0,g.RGBA,g.UNSIGNED_BYTE,null),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,g.CLAMP_TO_EDGE),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,g.CLAMP_TO_EDGE),$.lightShader=Hn(`#version 300 es
 precision highp float;uniform mat4 m;uniform vec2 lightPos;uniform float radius;in vec2 g;out vec2 vWorldPos;void main(){vec2 worldP=lightPos+(g-.5)*2.*radius;gl_Position=m*vec4(worldP,1,1);vWorldPos=worldP;}`,`#version 300 es
 precision highp float;uniform vec2 lightPos;uniform float radius;uniform float fadeRange;uniform vec4 color;in vec2 vWorldPos;out vec4 c;void main(){float dist=distance(vWorldPos,lightPos);float t=clamp((radius-dist)/max(fadeRange,1e-6),0.,1.);c=vec4(color.rgb*t*color.a,1.);}`),$.compositeShader=Hn(`#version 300 es
 precision highp float;in vec2 p;void main(){gl_Position=vec4(p+p-1.,1,1);}`,`#version 300 es
-precision highp float;uniform sampler2D s;uniform vec3 iResolution;out vec4 c;void main(){vec2 uv=gl_FragCoord.xy/iResolution.xy;c=vec4(texture(s,uv).rgb,1.);}`),$.lightVAO=g.createVertexArray(),g.bindVertexArray($.lightVAO),g.bindBuffer(g.ARRAY_BUFFER,Bn);let r=g.getAttribLocation($.lightShader,"g");g.enableVertexAttribArray(r),g.vertexAttribPointer(r,2,g.FLOAT,!1,8,0),$.compositeVAO=g.createVertexArray(),g.bindVertexArray($.compositeVAO),g.bindBuffer(g.ARRAY_BUFFER,Bn);let c=g.getAttribLocation($.compositeShader,"p");g.enableVertexAttribArray(c),g.vertexAttribPointer(c,2,g.FLOAT,!1,8,0)}function i(){if(U||!j||!$.enabled||!$.texture)return;It();let r=On,c=$.ambientColor;g.bindFramebuffer(g.FRAMEBUFFER,Mr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,$.texture,0),g.viewport(0,0,$.textureSize.x,$.textureSize.y),g.clearColor(c.r,c.g,c.b,c.a),g.clear(g.COLOR_BUFFER_BIT),hs(),g.enable(g.BLEND),g.blendFunc(g.ONE,g.ONE);for(let u of _t)u.destroyed||u.renderLight();It(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,k.x,k.y),g.useProgram($.compositeShader),g.bindVertexArray($.compositeVAO),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,$.texture);let l=$.compositeShader;g.uniform1i(g.getUniformLocation(l,"s"),0),g.uniform3f(g.getUniformLocation(l,"iResolution"),N.width,N.height,1),g.blendFunc(g.DST_COLOR,g.ZERO),g.drawArrays(g.TRIANGLE_STRIP,0,4),ne&&g.bindTexture(g.TEXTURE_2D,ne),hs(r),vs(!0)}function o(){$.texture=void 0,$.lightShader=void 0,$.compositeShader=void 0,$.lightVAO=void 0,$.compositeVAO=void 0,Et("LightSystemPlugin: WebGL context lost")}function a(){s(),Et("LightSystemPlugin: WebGL context restored")}}drawLight(t){if(U||!j||!this.lightShader)return;It(),g.useProgram(this.lightShader),g.bindVertexArray(this.lightVAO);let e=b(2*K).divide(k),s=Mt.rotate(-et),i=b(-1).subtract(s.multiply(e)),o=ut(et),a=rt(et),r=[e.x*o,e.y*a,0,0,-e.x*a,e.y*o,0,0,1,1,1,0,i.x,i.y,0,1],c=this.lightShader;g.uniformMatrix4fv(g.getUniformLocation(c,"m"),!1,r),g.uniform2f(g.getUniformLocation(c,"lightPos"),t.pos.x,t.pos.y),g.uniform1f(g.getUniformLocation(c,"radius"),t.radius),g.uniform1f(g.getUniformLocation(c,"fadeRange"),t.fadeRange);let l=t.color;g.uniform4f(g.getUniformLocation(c,"color"),l.r,l.g,l.b,l.a),g.drawArrays(g.TRIANGLE_STRIP,0,4),vs(!0)}},Po=class extends qe{constructor(t,e,s,i){super(t,b(1),void 0,0,s),p(R(e)&&e>=0,"Light radius must be a non-negative number"),p(i===void 0||R(i)&&i>=0,"Light fadeRange must be a non-negative number when provided"),this.radius=e,this.fadeRange=i===void 0?e:i}render(){}renderLight(){$&&$.drawLight(this)}},Lo=class extends ys{constructor(t){super(void 0),!(!Kt||U)&&(this.randomness=0,this.sampleChannels=Cc(...t),this.sampleRate=Kn)}playMusic(t=1,e=!0){return super.play(void 0,t,1,0,e)}};Ur=0;Oo=class{constructor(t=pt){p(!C,"UI system already initialized"),C=this,this.activateOnPress=!1,this.defaultColor=H,this.defaultLineColor=at,this.defaultTextColor=at,this.defaultButtonColor=Be(0,0,.7),this.defaultHoverColor=Be(0,0,.9),this.defaultDisabledColor=Be(0,0,.3),this.defaultGradientColor=void 0,this.defaultLineWidth=4,this.defaultCornerRadius=0,this.defaultTextFitScale=.8,this.defaultFont=Es,this.defaultSoundPress=void 0,this.defaultSoundRelease=void 0,this.defaultSoundClick=void 0,this.defaultShadowColor=xe,this.defaultShadowBlur=5,this.defaultShadowOffset=b(5),this.nativeHeight=0,this.navigationObject=void 0,this.navigationTimer=new Pe(void 0,!0),this.navigationDelay=.2,this.navigationDirection=1,this.navigationMode=!1,this.uiObjects=[],this.uiContext=t,this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.confirmDialog=void 0,this._keyInputObject=void 0,this._onKeyDown=o=>{var a;return(a=this._keyInputObject)==null?void 0:a.onKeyDown(o)},En(s,i);function e(o){let a,r;o.parent?(a=o.parent.nativePos,r=o.parent.size):(a=C.screenToNative(k.scale(.5)),r=C.nativeHeight?b(k.x*C.nativeHeight/k.y,C.nativeHeight):k);let c=o.anchor;o.nativePos=a.add(r.multiply(c).scale(.5)).subtract(o.size.multiply(c).scale(.5)).add(o.localPos)}function s(){C.activeObject&&!C.activeObject.visible&&(C.activeObject=void 0),C.lastHoverObject=C.hoverObject,C.hoverObject=void 0,ds(0)&&(C.navigationMode=!1,C.navigationObject=void 0),C.keyInputObject&&(C.activeObject=C.keyInputObject,C.hoverObject=C.keyInputObject,C.navigationMode=!1,C.navigationObject=void 0);let o=C.getNavigableObjects();if(!o.length)C.navigationObject=void 0;else if(!C.keyInputObject){if(o.includes(C.navigationObject)||(C.navigationObject=void 0),le||C.navigationMode&&!C.navigationObject&&(C.navigationObject=o.find(r=>r.navigationAutoSelect)),!C.navigationTimer.active()){let r=ae(C.getNavigationDirection());if(r){let c;if(C.navigationObject){let l=o.indexOf(C.navigationObject),u=ce(l+r,o.length);c=o[u]}else if(c=o.find(l=>l.navigationAutoSelect),!c){let l=r>0?0:o.length-1;c=o[l]}C.navigationObject!==c&&(C.navigationMode=!0,C.hoverObject=void 0,C.navigationObject=c,C.navigationTimer.set(C.navigationDelay),c.soundPress&&c.soundPress.play())}}C.navigationObject&&C.getNavigationWasPressed()&&C.navigationObject.navigatePressed()}for(let r=C.uiObjects.length;r--;){let c=C.uiObjects[r];c.parent||a(c)}C.uiObjects=C.uiObjects.filter(r=>!r.destroyed);function a(r){if(!(r.destroyed||!r.visible)){e(r);for(let c=r.children.length;c--;){let l=r.children[c];l&&a(l)}r.destroyed||r.update()}}}function i(){let o=C.uiContext;if(o.save(),C.nativeHeight){let r=k.y/C.nativeHeight;o.translate(-r*k.x/2,0),o.scale(r,r),o.translate(k.x/2/r,0)}function a(r){if(r.visible){e(r),r.render();for(let c of r.children)a(c)}}if(C.uiObjects.forEach(r=>r.parent||a(r)),Ur>0){let r=function(c,l=!0){l&&(l=!!c.visible),e(c),c.renderDebug(l);for(let u of c.children)r(u,l)};C.uiObjects.forEach(c=>c.parent||r(c))}o.restore()}}drawRect(t,e,s=H,i=0,o=at,a=0,r,c=at,l=0,u=b()){p(O(t),"pos must be a vec2"),p(O(e),"size must be a vec2"),p(W(s),"color must be a color"),p(R(i),"lineWidth must be a number"),p(W(o),"lineColor must be a color"),p(R(a),"cornerRadius must be a number");let h=C.uiContext;if(r){let f=h.createLinearGradient(t.x,t.y-e.y/2,t.x,t.y+e.y/2),d=s.toString();f.addColorStop(0,d),f.addColorStop(.5,r.toString()),f.addColorStop(1,d),h.fillStyle=f}else h.fillStyle=s.toString();(l||u.x||u.y)&&c.a>0&&(h.shadowColor=c.toString(),h.shadowBlur=l,h.shadowOffsetX=u.x,h.shadowOffsetY=u.y),h.beginPath(),a&&h.roundRect?h.roundRect(t.x-e.x/2,t.y-e.y/2,e.x,e.y,a):h.rect(t.x-e.x/2,t.y-e.y/2,e.x,e.y),h.fill(),h.shadowColor="#0000",i&&o.a>0&&(h.strokeStyle=o.toString(),h.lineWidth=i,h.stroke())}drawLine(t,e,s=C.defaultLineWidth,i=C.defaultLineColor){p(O(t),"posA must be a vec2"),p(O(e),"posB must be a vec2"),p(R(s),"lineWidth must be a number"),p(W(i),"lineColor must be a color");let o=C.uiContext;o.strokeStyle=i.toString(),o.lineWidth=s,o.beginPath(),o.lineTo(t.x,t.y),o.lineTo(e.x,e.y),o.stroke()}drawTile(t,e,s,i=C.defaultColor,o=0,a=!1,r=at,c=0,l=b()){let u=C.uiContext;(c||l.x||l.y)&&r.a>0&&(u.shadowColor=r.toString(),u.shadowBlur=c,u.shadowOffsetX=l.x,u.shadowOffsetY=l.y),Ft(t,e,s,i,o,a,xe,!1,!0,u),u.shadowColor="#0000"}drawText(t,e,s,i=C.defaultColor,o=C.defaultLineWidth,a=C.defaultLineColor,r="center",c=C.defaultFont,l="",u=!0,h=void 0,f=at,d=0,y=b()){let x=C.uiContext;f.a>0&&(h&&rn(t,e.add(h),s.y,f,o,a,r,c,l,u?s.x:void 0,0,x),(d||y.x||y.y)&&(x.shadowColor=f.toString(),x.shadowBlur=d,x.shadowOffsetX=y.x,x.shadowOffsetY=y.y)),rn(t,e,s.y,i,o,a,r,c,l,u?s.x:void 0,0,x),x.shadowColor="#0000"}setupDragAndDrop(t,e,s,i){if(this._dragListeners)for(let[a,r]of this._dragListeners)document.removeEventListener(a,r);this._dragListeners=[];let o=(a,r)=>{let c=l=>{l.preventDefault(),a&&a(l)};document.addEventListener(r,c),this._dragListeners.push([r,c])};o(t,"drop"),o(e,"dragenter"),o(s,"dragleave"),o(i,"dragover")}screenToNative(t){if(!C.nativeHeight)return t;let e=k.y/C.nativeHeight,s=1/e,i=t.copy();return i.x+=e*k.x/2,i.x*=s,i.y*=s,i.x-=s*k.x/2,i}get keyInputObject(){return this._keyInputObject}set keyInputObject(t){let e=!!this._keyInputObject;this._keyInputObject=t,!e&&t?document.addEventListener("keydown",this._onKeyDown):e&&!t&&document.removeEventListener("keydown",this._onKeyDown)}destroyObjects(){for(let t of this.uiObjects)t.parent||t.destroy();this.uiObjects=this.uiObjects.filter(t=>!t.destroyed),this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.keyInputObject=void 0}getNavigableObjects(){function t(s){if(!(!s.visible||s.disabled)){s.isInteractive()&&s.navigationIndex!==void 0&&e.push(s);for(let i=s.children.length;i--;)t(s.children[i])}}let e=[];for(let s=C.uiObjects.length;s--;){let i=C.uiObjects[s];C.confirmDialog&&i!==C.confirmDialog||i.parent||t(i)}return e.sort((s,i)=>s.navigationIndex-i.navigationIndex),e}getNavigationDirection(){let t=C.navigationDirection===1,e=C.navigationDirection===2;if(jn){let l=fs(0,At),u=yo(At);return e?-(l.y||u.y)||l.x||u.x:t?-(l.y||u.y):l.x||u.x}let s="ArrowUp",i="ArrowDown",o="ArrowLeft",a="ArrowRight";if(e)return Gt(s)||Gt(o)?-1:Gt(i)||Gt(a)?1:0;let r=t?s:o,c=t?i:a;return Gt(r)?-1:Gt(c)?1:0}getNavigationOtherDirection(){if(C.navigationDirection===2)return 0;let t=C.navigationDirection===1;if(jn){let i=fs(0,At),o=yo(At);return t?i.x||o.x:i.y||o.y}let e=t?"ArrowLeft":"ArrowUp",s=t?"ArrowRight":"ArrowDown";return Gt(e)?-1:Gt(s)?1:0}getNavigationWasPressed(){return jn?Er(0,At):Bt("Space")||Bt("Enter")}showConfirmDialog(t="Are you sure?",e,s,i=b(500,250),o="Escape"){p(!C.confirmDialog);let a=C.navigationDirection;C.navigationDirection=2;let r=new he(b(),i);C.confirmDialog=r,r.onRender=()=>{let d=Be(0,0,0,.7);C.drawRect(b(),b(1e9),d)},r.onUpdate=()=>{Bt(o)&&f()},r.isMouseOverlapping=()=>!0;let c=50,l=new mi(b(0,-50),b(i.x-c,70),t);r.addChild(l);let u=new As(b(-80,50),b(120,70),"Yes");u.textHeight=40,u.navigationIndex=1,u.hoverColor=Be(0,1,.5),u.onClick=()=>{f(),e&&e()},r.addChild(u);let h=new As(b(80,50),b(120,70),"No");h.textHeight=40,h.navigationIndex=2,h.navigationAutoSelect=!0,h.onClick=()=>{f(),s&&s()},r.addChild(h);function f(){p(C.confirmDialog===r),r.destroy(),C.confirmDialog=void 0,C.navigationDirection=a,Ms()}}},he=class{constructor(t=b(),e=b()){var s,i;p(O(t),"ui object pos must be a vec2"),p(O(e),"ui object size must be a vec2"),this.localPos=t.copy(),this.nativePos=t.copy(),this.size=e.copy(),this.color=C.defaultColor.copy(),this.activeColor=void 0,this.text=void 0,this.disabledColor=C.defaultDisabledColor.copy(),this.disabled=!1,this.textColor=C.defaultTextColor.copy(),this.hoverColor=C.defaultHoverColor.copy(),this.lineColor=C.defaultLineColor.copy(),this.gradientColor=C.defaultGradientColor?C.defaultGradientColor.copy():void 0,this.lineWidth=C.defaultLineWidth,this.cornerRadius=C.defaultCornerRadius,this.font=C.defaultFont,this.fontStyle=void 0,this.textWidth=void 0,this.textHeight=void 0,this.textFitScale=C.defaultTextFitScale,this.textShadow=void 0,this.textLineColor=C.defaultLineColor.copy(),this.textLineWidth=0,this.visible=!0,this.children=[],this.parent=void 0,this.extraTouchSize=0,this.soundPress=C.defaultSoundPress,this.soundRelease=C.defaultSoundRelease,this.soundClick=C.defaultSoundClick,this.interactive=!1,this.dragActivate=!1,this.canBeHover=!0,this.shadowColor=(s=C.defaultShadowColor)==null?void 0:s.copy(),this.shadowBlur=C.defaultShadowBlur,this.shadowOffset=(i=C.defaultShadowOffset)==null?void 0:i.copy(),this.navigationIndex=void 0,this.navigationAutoSelect=!1,this.anchor=b(),C.uiObjects.push(this)}addChild(t){return p(!t.parent&&!this.children.includes(t)),this.children.push(t),t.parent=this,t}removeChild(t){p(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}destroy(){var t;if(!this.destroyed){C.activeObject===this&&(C.activeObject=void 0),C.hoverObject===this&&(C.hoverObject=void 0),C.lastHoverObject===this&&(C.lastHoverObject=void 0),C.navigationObject===this&&(C.navigationObject=void 0),C.keyInputObject===this&&(C.keyInputObject=void 0),this.destroyed=1,(t=this.parent)==null||t.removeChild(this);for(let e of this.children)e.parent=void 0,e.destroy();this.children.length=0}}isMouseOverlapping(){if(!ni)return!1;let t=le?this.size.add(b(this.extraTouchSize||0)):this.size,e=C.screenToNative(qt);return Ys(this.nativePos,t,e)}update(){if(this.onUpdate(),this.disabled&&(this===C.activeObject&&(C.activeObject=void 0),this===C.keyInputObject&&(C.keyInputObject=void 0)),C.keyInputObject)return;let t=C.lastHoverObject===this,e=this.isActiveObject(),s=rs(0),i=this.dragActivate?s:ds(0);this.canBeHover&&(C.navigationMode||(i||e||!s&&!le)&&!C.hoverObject&&this.isMouseOverlapping()&&(C.hoverObject=this)),this.isHoverObject()&&(this.disabled||(i&&this.interactive&&((!this.dragActivate||!t||ds(0))&&this.onPress(),this.soundPress&&this.soundPress.play(),C.activeObject&&!e&&C.activeObject.onRelease(),C.activeObject=this,C.activateOnPress&&this.click(!this.soundPress)),C.activateOnPress||!s&&this.isActiveObject()&&this.interactive&&this.click()),i&&Ar(0,0,0,1,0)),e&&(!s||this.dragActivate&&!this.isHoverObject())&&(this.onRelease(),this.soundRelease&&this.soundRelease.play(),C.activeObject=void 0),this.isHoverObject()!==t&&(this.isHoverObject()?this.onEnter():this.onLeave())}render(){if(this.onRender(),!this.size.x||!this.size.y)return;let t=this.isNavigationObject(),e=t?this.color:this.interactive&&this.isActiveObject()&&!this.disabled?this.color:this.lineColor,s=t?this.hoverColor:this.disabled?this.disabledColor:this.interactive?this.isActiveObject()?this.activeColor||this.hoverColor:this.isHoverObject()?this.hoverColor:this.color:this.color,i=this.lineWidth*(t?1.5:1);C.drawRect(this.nativePos,this.size,s,i,e,this.cornerRadius,this.gradientColor,this.shadowColor,this.shadowBlur,this.shadowOffset)}getTextSize(){return b(this.textWidth||this.textFitScale*this.size.x,this.textHeight||this.textFitScale*this.size.y)}navigatePressed(){this.click()}isHoverObject(){return C.hoverObject===this}isActiveObject(){return C.activeObject===this}isNavigationObject(){return C.navigationObject===this}isKeyInputObject(){return C.keyInputObject===this}isInteractive(){return this.interactive&&this.visible&&!this.disabled}toString(){let t="type = "+this.constructor.name;return this.text&&(t+=`
+precision highp float;uniform sampler2D s;uniform vec3 iResolution;out vec4 c;void main(){vec2 uv=gl_FragCoord.xy/iResolution.xy;c=vec4(texture(s,uv).rgb,1.);}`),$.lightVAO=g.createVertexArray(),g.bindVertexArray($.lightVAO),g.bindBuffer(g.ARRAY_BUFFER,Bn);let r=g.getAttribLocation($.lightShader,"g");g.enableVertexAttribArray(r),g.vertexAttribPointer(r,2,g.FLOAT,!1,8,0),$.compositeVAO=g.createVertexArray(),g.bindVertexArray($.compositeVAO),g.bindBuffer(g.ARRAY_BUFFER,Bn);let c=g.getAttribLocation($.compositeShader,"p");g.enableVertexAttribArray(c),g.vertexAttribPointer(c,2,g.FLOAT,!1,8,0)}function i(){if(U||!j||!$.enabled||!$.texture)return;It();let r=On,c=$.ambientColor;g.bindFramebuffer(g.FRAMEBUFFER,Mr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,$.texture,0),g.viewport(0,0,$.textureSize.x,$.textureSize.y),g.clearColor(c.r,c.g,c.b,c.a),g.clear(g.COLOR_BUFFER_BIT),hs(),g.enable(g.BLEND),g.blendFunc(g.ONE,g.ONE);for(let u of _t)u.destroyed||u.renderLight();It(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,k.x,k.y),g.useProgram($.compositeShader),g.bindVertexArray($.compositeVAO),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,$.texture);let l=$.compositeShader;g.uniform1i(g.getUniformLocation(l,"s"),0),g.uniform3f(g.getUniformLocation(l,"iResolution"),N.width,N.height,1),g.blendFunc(g.DST_COLOR,g.ZERO),g.drawArrays(g.TRIANGLE_STRIP,0,4),se&&g.bindTexture(g.TEXTURE_2D,se),hs(r),vs(!0)}function o(){$.texture=void 0,$.lightShader=void 0,$.compositeShader=void 0,$.lightVAO=void 0,$.compositeVAO=void 0,Et("LightSystemPlugin: WebGL context lost")}function a(){s(),Et("LightSystemPlugin: WebGL context restored")}}drawLight(t){if(U||!j||!this.lightShader)return;It(),g.useProgram(this.lightShader),g.bindVertexArray(this.lightVAO);let e=b(2*K).divide(k),s=Mt.rotate(-nt),i=b(-1).subtract(s.multiply(e)),o=ht(nt),a=rt(nt),r=[e.x*o,e.y*a,0,0,-e.x*a,e.y*o,0,0,1,1,1,0,i.x,i.y,0,1],c=this.lightShader;g.uniformMatrix4fv(g.getUniformLocation(c,"m"),!1,r),g.uniform2f(g.getUniformLocation(c,"lightPos"),t.pos.x,t.pos.y),g.uniform1f(g.getUniformLocation(c,"radius"),t.radius),g.uniform1f(g.getUniformLocation(c,"fadeRange"),t.fadeRange);let l=t.color;g.uniform4f(g.getUniformLocation(c,"color"),l.r,l.g,l.b,l.a),g.drawArrays(g.TRIANGLE_STRIP,0,4),vs(!0)}},Po=class extends qe{constructor(t,e,s,i){super(t,b(1),void 0,0,s),p(R(e)&&e>=0,"Light radius must be a non-negative number"),p(i===void 0||R(i)&&i>=0,"Light fadeRange must be a non-negative number when provided"),this.radius=e,this.fadeRange=i===void 0?e:i}render(){}renderLight(){$&&$.drawLight(this)}},Lo=class extends ys{constructor(t){super(void 0),!(!Qt||U)&&(this.randomness=0,this.sampleChannels=Cc(...t),this.sampleRate=Kn)}playMusic(t=1,e=!0){return super.play(void 0,t,1,0,e)}};Ur=0;Oo=class{constructor(t=pt){p(!C,"UI system already initialized"),C=this,this.activateOnPress=!1,this.defaultColor=H,this.defaultLineColor=at,this.defaultTextColor=at,this.defaultButtonColor=Be(0,0,.7),this.defaultHoverColor=Be(0,0,.9),this.defaultDisabledColor=Be(0,0,.3),this.defaultGradientColor=void 0,this.defaultLineWidth=4,this.defaultCornerRadius=0,this.defaultTextFitScale=.8,this.defaultFont=Es,this.defaultSoundPress=void 0,this.defaultSoundRelease=void 0,this.defaultSoundClick=void 0,this.defaultShadowColor=xe,this.defaultShadowBlur=5,this.defaultShadowOffset=b(5),this.nativeHeight=0,this.navigationObject=void 0,this.navigationTimer=new Pe(void 0,!0),this.navigationDelay=.2,this.navigationDirection=1,this.navigationMode=!1,this.uiObjects=[],this.uiContext=t,this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.confirmDialog=void 0,this._keyInputObject=void 0,this._onKeyDown=o=>{var a;return(a=this._keyInputObject)==null?void 0:a.onKeyDown(o)},En(s,i);function e(o){let a,r;o.parent?(a=o.parent.nativePos,r=o.parent.size):(a=C.screenToNative(k.scale(.5)),r=C.nativeHeight?b(k.x*C.nativeHeight/k.y,C.nativeHeight):k);let c=o.anchor;o.nativePos=a.add(r.multiply(c).scale(.5)).subtract(o.size.multiply(c).scale(.5)).add(o.localPos)}function s(){C.activeObject&&!C.activeObject.visible&&(C.activeObject=void 0),C.lastHoverObject=C.hoverObject,C.hoverObject=void 0,ds(0)&&(C.navigationMode=!1,C.navigationObject=void 0),C.keyInputObject&&(C.activeObject=C.keyInputObject,C.hoverObject=C.keyInputObject,C.navigationMode=!1,C.navigationObject=void 0);let o=C.getNavigableObjects();if(!o.length)C.navigationObject=void 0;else if(!C.keyInputObject){if(o.includes(C.navigationObject)||(C.navigationObject=void 0),le||C.navigationMode&&!C.navigationObject&&(C.navigationObject=o.find(r=>r.navigationAutoSelect)),!C.navigationTimer.active()){let r=ae(C.getNavigationDirection());if(r){let c;if(C.navigationObject){let l=o.indexOf(C.navigationObject),u=ce(l+r,o.length);c=o[u]}else if(c=o.find(l=>l.navigationAutoSelect),!c){let l=r>0?0:o.length-1;c=o[l]}C.navigationObject!==c&&(C.navigationMode=!0,C.hoverObject=void 0,C.navigationObject=c,C.navigationTimer.set(C.navigationDelay),c.soundPress&&c.soundPress.play())}}C.navigationObject&&C.getNavigationWasPressed()&&C.navigationObject.navigatePressed()}for(let r=C.uiObjects.length;r--;){let c=C.uiObjects[r];c.parent||a(c)}C.uiObjects=C.uiObjects.filter(r=>!r.destroyed);function a(r){if(!(r.destroyed||!r.visible)){e(r);for(let c=r.children.length;c--;){let l=r.children[c];l&&a(l)}r.destroyed||r.update()}}}function i(){let o=C.uiContext;if(o.save(),C.nativeHeight){let r=k.y/C.nativeHeight;o.translate(-r*k.x/2,0),o.scale(r,r),o.translate(k.x/2/r,0)}function a(r){if(r.visible){e(r),r.render();for(let c of r.children)a(c)}}if(C.uiObjects.forEach(r=>r.parent||a(r)),Ur>0){let r=function(c,l=!0){l&&(l=!!c.visible),e(c),c.renderDebug(l);for(let u of c.children)r(u,l)};C.uiObjects.forEach(c=>c.parent||r(c))}o.restore()}}drawRect(t,e,s=H,i=0,o=at,a=0,r,c=at,l=0,u=b()){p(O(t),"pos must be a vec2"),p(O(e),"size must be a vec2"),p(W(s),"color must be a color"),p(R(i),"lineWidth must be a number"),p(W(o),"lineColor must be a color"),p(R(a),"cornerRadius must be a number");let h=C.uiContext;if(r){let f=h.createLinearGradient(t.x,t.y-e.y/2,t.x,t.y+e.y/2),d=s.toString();f.addColorStop(0,d),f.addColorStop(.5,r.toString()),f.addColorStop(1,d),h.fillStyle=f}else h.fillStyle=s.toString();(l||u.x||u.y)&&c.a>0&&(h.shadowColor=c.toString(),h.shadowBlur=l,h.shadowOffsetX=u.x,h.shadowOffsetY=u.y),h.beginPath(),a&&h.roundRect?h.roundRect(t.x-e.x/2,t.y-e.y/2,e.x,e.y,a):h.rect(t.x-e.x/2,t.y-e.y/2,e.x,e.y),h.fill(),h.shadowColor="#0000",i&&o.a>0&&(h.strokeStyle=o.toString(),h.lineWidth=i,h.stroke())}drawLine(t,e,s=C.defaultLineWidth,i=C.defaultLineColor){p(O(t),"posA must be a vec2"),p(O(e),"posB must be a vec2"),p(R(s),"lineWidth must be a number"),p(W(i),"lineColor must be a color");let o=C.uiContext;o.strokeStyle=i.toString(),o.lineWidth=s,o.beginPath(),o.lineTo(t.x,t.y),o.lineTo(e.x,e.y),o.stroke()}drawTile(t,e,s,i=C.defaultColor,o=0,a=!1,r=at,c=0,l=b()){let u=C.uiContext;(c||l.x||l.y)&&r.a>0&&(u.shadowColor=r.toString(),u.shadowBlur=c,u.shadowOffsetX=l.x,u.shadowOffsetY=l.y),jt(t,e,s,i,o,a,xe,!1,!0,u),u.shadowColor="#0000"}drawText(t,e,s,i=C.defaultColor,o=C.defaultLineWidth,a=C.defaultLineColor,r="center",c=C.defaultFont,l="",u=!0,h=void 0,f=at,d=0,y=b()){let x=C.uiContext;f.a>0&&(h&&rn(t,e.add(h),s.y,f,o,a,r,c,l,u?s.x:void 0,0,x),(d||y.x||y.y)&&(x.shadowColor=f.toString(),x.shadowBlur=d,x.shadowOffsetX=y.x,x.shadowOffsetY=y.y)),rn(t,e,s.y,i,o,a,r,c,l,u?s.x:void 0,0,x),x.shadowColor="#0000"}setupDragAndDrop(t,e,s,i){if(this._dragListeners)for(let[a,r]of this._dragListeners)document.removeEventListener(a,r);this._dragListeners=[];let o=(a,r)=>{let c=l=>{l.preventDefault(),a&&a(l)};document.addEventListener(r,c),this._dragListeners.push([r,c])};o(t,"drop"),o(e,"dragenter"),o(s,"dragleave"),o(i,"dragover")}screenToNative(t){if(!C.nativeHeight)return t;let e=k.y/C.nativeHeight,s=1/e,i=t.copy();return i.x+=e*k.x/2,i.x*=s,i.y*=s,i.x-=s*k.x/2,i}get keyInputObject(){return this._keyInputObject}set keyInputObject(t){let e=!!this._keyInputObject;this._keyInputObject=t,!e&&t?document.addEventListener("keydown",this._onKeyDown):e&&!t&&document.removeEventListener("keydown",this._onKeyDown)}destroyObjects(){for(let t of this.uiObjects)t.parent||t.destroy();this.uiObjects=this.uiObjects.filter(t=>!t.destroyed),this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.keyInputObject=void 0}getNavigableObjects(){function t(s){if(!(!s.visible||s.disabled)){s.isInteractive()&&s.navigationIndex!==void 0&&e.push(s);for(let i=s.children.length;i--;)t(s.children[i])}}let e=[];for(let s=C.uiObjects.length;s--;){let i=C.uiObjects[s];C.confirmDialog&&i!==C.confirmDialog||i.parent||t(i)}return e.sort((s,i)=>s.navigationIndex-i.navigationIndex),e}getNavigationDirection(){let t=C.navigationDirection===1,e=C.navigationDirection===2;if(jn){let l=fs(0,At),u=yo(At);return e?-(l.y||u.y)||l.x||u.x:t?-(l.y||u.y):l.x||u.x}let s="ArrowUp",i="ArrowDown",o="ArrowLeft",a="ArrowRight";if(e)return Ft(s)||Ft(o)?-1:Ft(i)||Ft(a)?1:0;let r=t?s:o,c=t?i:a;return Ft(r)?-1:Ft(c)?1:0}getNavigationOtherDirection(){if(C.navigationDirection===2)return 0;let t=C.navigationDirection===1;if(jn){let i=fs(0,At),o=yo(At);return t?i.x||o.x:i.y||o.y}let e=t?"ArrowLeft":"ArrowUp",s=t?"ArrowRight":"ArrowDown";return Ft(e)?-1:Ft(s)?1:0}getNavigationWasPressed(){return jn?Er(0,At):Nt("Space")||Nt("Enter")}showConfirmDialog(t="Are you sure?",e,s,i=b(500,250),o="Escape"){p(!C.confirmDialog);let a=C.navigationDirection;C.navigationDirection=2;let r=new he(b(),i);C.confirmDialog=r,r.onRender=()=>{let d=Be(0,0,0,.7);C.drawRect(b(),b(1e9),d)},r.onUpdate=()=>{Nt(o)&&f()},r.isMouseOverlapping=()=>!0;let c=50,l=new mi(b(0,-50),b(i.x-c,70),t);r.addChild(l);let u=new As(b(-80,50),b(120,70),"Yes");u.textHeight=40,u.navigationIndex=1,u.hoverColor=Be(0,1,.5),u.onClick=()=>{f(),e&&e()},r.addChild(u);let h=new As(b(80,50),b(120,70),"No");h.textHeight=40,h.navigationIndex=2,h.navigationAutoSelect=!0,h.onClick=()=>{f(),s&&s()},r.addChild(h);function f(){p(C.confirmDialog===r),r.destroy(),C.confirmDialog=void 0,C.navigationDirection=a,Ms()}}},he=class{constructor(t=b(),e=b()){var s,i;p(O(t),"ui object pos must be a vec2"),p(O(e),"ui object size must be a vec2"),this.localPos=t.copy(),this.nativePos=t.copy(),this.size=e.copy(),this.color=C.defaultColor.copy(),this.activeColor=void 0,this.text=void 0,this.disabledColor=C.defaultDisabledColor.copy(),this.disabled=!1,this.textColor=C.defaultTextColor.copy(),this.hoverColor=C.defaultHoverColor.copy(),this.lineColor=C.defaultLineColor.copy(),this.gradientColor=C.defaultGradientColor?C.defaultGradientColor.copy():void 0,this.lineWidth=C.defaultLineWidth,this.cornerRadius=C.defaultCornerRadius,this.font=C.defaultFont,this.fontStyle=void 0,this.textWidth=void 0,this.textHeight=void 0,this.textFitScale=C.defaultTextFitScale,this.textShadow=void 0,this.textLineColor=C.defaultLineColor.copy(),this.textLineWidth=0,this.visible=!0,this.children=[],this.parent=void 0,this.extraTouchSize=0,this.soundPress=C.defaultSoundPress,this.soundRelease=C.defaultSoundRelease,this.soundClick=C.defaultSoundClick,this.interactive=!1,this.dragActivate=!1,this.canBeHover=!0,this.shadowColor=(s=C.defaultShadowColor)==null?void 0:s.copy(),this.shadowBlur=C.defaultShadowBlur,this.shadowOffset=(i=C.defaultShadowOffset)==null?void 0:i.copy(),this.navigationIndex=void 0,this.navigationAutoSelect=!1,this.anchor=b(),C.uiObjects.push(this)}addChild(t){return p(!t.parent&&!this.children.includes(t)),this.children.push(t),t.parent=this,t}removeChild(t){p(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}destroy(){var t;if(!this.destroyed){C.activeObject===this&&(C.activeObject=void 0),C.hoverObject===this&&(C.hoverObject=void 0),C.lastHoverObject===this&&(C.lastHoverObject=void 0),C.navigationObject===this&&(C.navigationObject=void 0),C.keyInputObject===this&&(C.keyInputObject=void 0),this.destroyed=1,(t=this.parent)==null||t.removeChild(this);for(let e of this.children)e.parent=void 0,e.destroy();this.children.length=0}}isMouseOverlapping(){if(!ni)return!1;let t=le?this.size.add(b(this.extraTouchSize||0)):this.size,e=C.screenToNative(Ht);return Ys(this.nativePos,t,e)}update(){if(this.onUpdate(),this.disabled&&(this===C.activeObject&&(C.activeObject=void 0),this===C.keyInputObject&&(C.keyInputObject=void 0)),C.keyInputObject)return;let t=C.lastHoverObject===this,e=this.isActiveObject(),s=rs(0),i=this.dragActivate?s:ds(0);this.canBeHover&&(C.navigationMode||(i||e||!s&&!le)&&!C.hoverObject&&this.isMouseOverlapping()&&(C.hoverObject=this)),this.isHoverObject()&&(this.disabled||(i&&this.interactive&&((!this.dragActivate||!t||ds(0))&&this.onPress(),this.soundPress&&this.soundPress.play(),C.activeObject&&!e&&C.activeObject.onRelease(),C.activeObject=this,C.activateOnPress&&this.click(!this.soundPress)),C.activateOnPress||!s&&this.isActiveObject()&&this.interactive&&this.click()),i&&Ar(0,0,0,1,0)),e&&(!s||this.dragActivate&&!this.isHoverObject())&&(this.onRelease(),this.soundRelease&&this.soundRelease.play(),C.activeObject=void 0),this.isHoverObject()!==t&&(this.isHoverObject()?this.onEnter():this.onLeave())}render(){if(this.onRender(),!this.size.x||!this.size.y)return;let t=this.isNavigationObject(),e=t?this.color:this.interactive&&this.isActiveObject()&&!this.disabled?this.color:this.lineColor,s=t?this.hoverColor:this.disabled?this.disabledColor:this.interactive?this.isActiveObject()?this.activeColor||this.hoverColor:this.isHoverObject()?this.hoverColor:this.color:this.color,i=this.lineWidth*(t?1.5:1);C.drawRect(this.nativePos,this.size,s,i,e,this.cornerRadius,this.gradientColor,this.shadowColor,this.shadowBlur,this.shadowOffset)}getTextSize(){return b(this.textWidth||this.textFitScale*this.size.x,this.textHeight||this.textFitScale*this.size.y)}navigatePressed(){this.click()}isHoverObject(){return C.hoverObject===this}isActiveObject(){return C.activeObject===this}isNavigationObject(){return C.navigationObject===this}isKeyInputObject(){return C.keyInputObject===this}isInteractive(){return this.interactive&&this.visible&&!this.disabled}toString(){let t="type = "+this.constructor.name;return this.text&&(t+=`
 text = `+this.text),(this.nativePos.x||this.nativePos.y)&&(t+=`
 nativePos = `+this.nativePos),(this.localPos.x||this.localPos.y)&&(t+=`
 localPos = `+this.localPos),(this.size.x||this.size.y)&&(t+=`
 size = `+this.size),this.color&&(t+=`
-color = `+this.color),t}renderDebug(t=!0){let e=t?this.isHoverObject()?$a:this.disabled?Za:this.interactive?ir:Qa:Ka;C.drawRect(this.nativePos,this.size,xe,4,e)}click(t=!0){this.onClick(),t&&this.soundClick&&this.soundClick.play()}onUpdate(){}onRender(){}onEnter(){}onLeave(){}onPress(){}onRelease(){}onClick(){}onChange(){}},mi=class extends he{constructor(t,e,s="",i="center",o=C.defaultFont){super(t,e),p(q(s),"ui text must be a string"),p(["left","center","right"].includes(i),"ui text align must be left, center, or right"),p(q(o),"ui text font must be a string"),this.text=s,this.align=i,this.font=o,this.canBeHover=!1,this.color=xe,this.shadowColor=xe,this.gradientColor=void 0,this.lineWidth=0,this.textFitScale=1}render(){super.render();let t=this.getTextSize();C.drawText(this.text,this.nativePos,t,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow,this.shadowColor,this.shadowBlur,this.shadowOffset)}},Do=class extends he{constructor(t,e,s=""){super(t,e),p(q(s),"ui text must be a string"),this.maxLength=0,this.text=s,this.interactive=!0,this.canBeHover=!0}click(){C.keyInputObject=this,this.onClick()}stopEditing(){this.isKeyInputObject()&&(this.soundRelease&&this.soundRelease.play(),C.activeObject=void 0,C.keyInputObject=void 0,this.onChange())}onKeyDown(t){let e=t.code,s=t.key;e==="Backspace"?this.text=this.text.slice(0,-1):e==="Enter"||e==="Escape"?this.stopEditing():s.length===1&&(!this.maxLength||this.text.lengththis.size.y,s=e?this.size.y:this.size.x,i=e?this.size.x:this.size.y,o=e?this.nativePos.x:this.nativePos.y,a=i-s,r=o-a/2,c=o+a/2,l=C.screenToNative(qt);this.value=e?Jt(l.x,r,c):Jt(l.y,c,r)}else if(this.isNavigationObject()){let e=C.getNavigationOtherDirection();C.navigationTimer.active()||(this.value=z(this.value+e*.01))}this.value===t||this.onChange()}render(){super.render();let t=this.size.x>this.size.y,e=t?this.size.x:this.size.y,s=t?this.size.y:this.size.x;if(this.fillMode){let o=st(s,this.cornerRadius*2),a=Yt(o,e,this.value),r=(a-e)*(t?.5:-.5),c=this.nativePos.add(t?b(r,0):b(0,r)),l=this.disabled?this.disabledColor:this.handleColor,u=t?b(a,this.size.y):b(this.size.x,a);C.drawRect(c,u,l,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}else{let o=z(t?this.value:1-this.value),a=(e-s)*(o-.5),r=this.nativePos.add(t?b(a,0):b(0,a)),c=this.disabled?this.disabledColor:this.handleColor,l=b(s);C.drawRect(r,l,c,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}let i=this.getTextSize();C.drawText(this.text,this.nativePos,i,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow)}navigatePressed(){this.value=this.value?0:1,this.onChange(),this.onRelease(),super.navigatePressed()}},Go=class extends he{constructor(t,e,s,i=!1,o=!1,a=1){super(t,e||b()),p(q(s),"video src must be a string"),p(R(a),"video volume must be a number"),this.color=at,this.cornerRadius=0,this.volume=a,this.video=document.createElement("video"),this.video.loop=o,this.video.volume=z(a*Sn),this.video.muted=!Kt,this.video.style.display="none",this.video.src=s,document.body.appendChild(this.video),i&&this.play()}async play(){try{await this.video.play()}catch{}}pause(){this.video.pause()}stop(){this.video.pause(),this.video.currentTime=0}isLoading(){return this.video.readyState=1,"ui layout columns must be a number >= 1"),p(R(s),"ui layout gap must be a number"),p(R(i),"ui layout padding must be a number"),this.columns=e,this.gap=s,this.padding=i,o&&(this.color=xe,this.gradientColor=void 0,this.lineWidth=0,this.shadowColor=xe),this.relayout()}addChild(t){return super.addChild(t),this.relayout(),t}removeChild(t){super.removeChild(t),this.relayout()}relayout(){let t=this.children.length;if(!t){this.size=b(this.padding*2);return}let e=this.columns,s=cs(t/e),i=new Array(e).fill(0),o=new Array(s).fill(0);for(let f=0;f=0&&m.objects.splice(t,1),super.destroy()}updatePhysics(){}render(){this.tileInfo?super.render():this.drawFixtures(this.color,this.lineColor,this.lineWidth)}renderDebugInfo(){let t=!this.getIsAwake(),e=this.getBodyType()===m.bodyTypeStatic,s=V(t?1:0,t?1:0,e?1:0,.5);this.drawFixtures(s)}drawFixtures(t=H,e=at,s=.1,i,o){this.getFixtureList().forEach(a=>{m.castShapeObject(a.GetShape()).GetType()!==m.instance.b2Shape.e_edge&&m.drawFixture(a,this.pos,this.angle,t,e,s,i,o)}),this.edgeLists.forEach(a=>go(a,s,e,!1,this.pos,this.angle)),this.edgeLoops.forEach(a=>go(a,s,e,!0,this.pos,this.angle))}beginContact(t){}endContact(t){}addShape(t,e=1,s=.2,i=0,o=!1){p(R(e),"density must be a number"),p(R(s),"friction must be a number"),p(R(i),"restitution must be a number");let a=new m.instance.b2FixtureDef;return a.set_shape(t),a.set_density(e),a.set_friction(s),a.set_restitution(i),a.set_isSensor(o),this.body.CreateFixture(a)}addBox(t=b(1),e=b(),s=0,i,o,a,r){p(O(t),"size must be a Vector2"),p(t.x>0&&t.y>0,"size must be positive"),p(O(e),"offset must be a Vector2"),p(R(s),"angle must be a number");let c=new m.instance.b2PolygonShape;return c.SetAsBox(t.x/2,t.y/2,m.vec2dTo(e),-s),this.addShape(c,i,o,a,r)}addPoly(t,e,s,i,o){p(me(t),"points must be an array");function a(c){p(3<=c.length&&c.length<=8);let l=m.instance._malloc(c.length*8);for(let f=0,d=0;f>2]=c[f].x,d+=4,m.instance.HEAPF32[l+d>>2]=c[f].y,d+=4;let u=m.instance.wrapPointer(l,m.instance.b2Vec2),h=new m.instance.b2PolygonShape;return h.Set(u,c.length),m.instance._free(l),h}let r=a(t);return this.addShape(r,e,s,i,o)}addRegularPoly(t=1,e=8,s,i,o,a){p(R(t)&&t>0,"diameter must be a positive number"),p(R(e)&&e>2,"sides must be a positive number greater than 2");let r=[],c=t/2;for(let l=e;l--;)r.push(b(c,0).rotate((l+.5)/e*Q*2));return this.addPoly(r,s,i,o,a)}addRandomPoly(t=1,e,s,i,o){p(R(t)&&t>0,"diameter must be a positive number");let a=sr(3,9),r=[],c=t/2;for(let l=a;l--;)r.push(b(yt(c/2,c*1.5),0).rotate(l/a*Q*2));return this.addPoly(r,e,s,i,o)}addCircle(t=1,e=b(),s,i,o,a){p(R(t)&&t>0,"diameter must be a positive number"),p(O(e),"offset must be a Vector2");let r=new m.instance.b2CircleShape;return r.set_m_p(m.vec2dTo(e)),r.set_m_radius(t/2),this.addShape(r,s,i,o,a)}addEdge(t,e,s,i,o,a){p(O(t),"point1 must be a Vector2"),p(O(e),"point2 must be a Vector2");let r=new m.instance.b2EdgeShape;return r.Set(m.vec2dTo(t),m.vec2dTo(e)),this.addShape(r,s,i,o,a)}addEdgeList(t,e,s,i,o){p(me(t),"points must be an array");let a=[],r=[];for(let c=0;ct[ce(l,t.length)];for(let l=0;lthis.destroyFixture(t))}getCenterOfMass(){return m.vec2From(this.body.GetWorldCenter())}getLinearVelocity(){return m.vec2From(this.body.GetLinearVelocity())}getAngularVelocity(){return this.body.GetAngularVelocity()}getMass(){return this.body.GetMass()}getInertia(){return this.body.GetInertia()}getIsAwake(){return this.body.IsAwake()}getBodyType(){return this.body.GetType()}getSpeed(){return this.getLinearVelocity().length()}setTransform(t,e){this.pos=t,this.angle=e,this.body.SetTransform(m.vec2dTo(t),-e)}setPosition(t){this.setTransform(t,this.body.GetAngle())}setAngle(t){this.setTransform(m.vec2From(this.body.GetPosition()),t)}setLinearVelocity(t){this.body.SetLinearVelocity(m.vec2dTo(t))}setAngularVelocity(t){this.body.SetAngularVelocity(t)}setLinearDamping(t){this.body.SetLinearDamping(t)}setAngularDamping(t){this.body.SetAngularDamping(t)}setGravityScale(t=1){this.body.SetGravityScale(this.gravityScale=t)}setBullet(t=!0){this.body.SetBullet(t)}setAwake(t=!0){this.body.SetAwake(t)}setBodyType(t){this.body.SetType(t)}setSleepingAllowed(t=!0){this.body.SetSleepingAllowed(t)}setFixedRotation(t=!0){this.body.SetFixedRotation(t)}setCenterOfMass(t){this.setMassData(t)}setMass(t){this.setMassData(void 0,t)}setMomentOfInertia(t){this.setMassData(void 0,void 0,t)}resetMassData(){this.body.ResetMassData()}setMassData(t,e,s){let i=new m.instance.b2MassData;this.body.GetMassData(i),t!==void 0&&i.set_center(m.vec2dTo(t)),e!==void 0&&i.set_mass(e),s!==void 0&&i.set_I(s),this.body.SetMassData(i)}setFilterData(t=0,e=0,s=0){this.getFixtureList().forEach(i=>{let o=i.GetFilterData();o.set_categoryBits(t),o.set_maskBits(65535&~e),o.set_groupIndex(s)})}setSensor(t=!0){this.getFixtureList().forEach(e=>e.SetSensor(t))}applyForce(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyForce(m.vec2dTo(t),m.vec2dTo(e))}applyAcceleration(t,e){e||(e=this.getCenterOfMass()),this.setAwake();let s=t.scale(this.getMass());this.body.ApplyLinearImpulse(m.vec2dTo(s),m.vec2dTo(e))}applyImpulse(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyLinearImpulse(m.vec2dTo(t),m.vec2dTo(e))}applyTorque(t){this.setAwake(),this.body.ApplyTorque(t)}applyAngularAcceleration(t){this.setAwake(),this.body.ApplyAngularImpulse(t*this.getInertia())}applyAngularImpulse(t){this.setAwake(),this.body.ApplyAngularImpulse(t)}hasFixtures(){return!m.isNull(this.body.GetFixtureList())}getFixtureList(){let t=[];for(let e=this.body.GetFixtureList();!m.isNull(e);)t.push(e),e=e.GetNext();return t}hasJoints(){return!m.isNull(this.body.GetJointList())}getJointList(){let t=[];for(let e=this.body.GetJointList();!m.isNull(e);)t.push(e),e=e.get_next();return t}},bi=class extends Cs{constructor(t,e,s,i=0,o,a=0){let r=m.bodyTypeStatic;super(t,e,s,i,o,r,a)}},jo=class extends Cs{constructor(t,e,s,i=0,o,a=0){let r=m.bodyTypeKinematic;super(t,e,s,i,o,r,a)}},Bo=class extends bi{constructor(t){p(t instanceof bs,"tileLayer must be a TileCollisionLayer"),super(t.pos,t.size),this.tileLayer=t,this.addChild(t)}render(){}buildCollision(t=.2,e=0){this.destroyAllFixtures(),this.pos=this.tileLayer.pos.copy(),this.size=this.tileLayer.size.copy();let s=[],i=(a,r)=>a+r*this.size.x,o=(a,r)=>!s[i(a,r)]&&this.tileLayer.getCollisionData(b(a,r))>0;for(let a=0;ai.fractiono.pos.distanceSquared(t)0,"Tween duration must be > 0"),this.callback=t,this.start=e,this.end=s,this.duration=i,this.life=i,this.ease=o.ease||Ti.LINEAR,this.useRealTime=!!o.useRealTime,this.paused=!!o.paused,this.thenCallback=void 0,this.loopRemaining=0,te.push(this),t(this.interp(i))}setEase(t){return this.ease=t,this}then(t){return this.thenCallback=t,this.loopRemaining=0,this}loop(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Pc(this),this}pingPong(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Lc(this),this}pause(){this.paused=!0}resume(){this.paused=!1}restart(){this.life=this.duration,this.paused=!1,te.indexOf(this)<0&&te.push(this),this.callback(this.interp(this.duration))}isActive(){return!this.paused&&te.indexOf(this)>=0}getPercent(){return Jt(this.duration-this.life,0,this.duration)}getValue(){return this.interp(this.life)}interp(t){let e=this.ease((this.duration-t)/this.duration);return Pa(this.start)?this.start.lerp(this.end,e):this.start+(this.end-this.start)*e}stop(){let t=te.indexOf(this);t>=0&&te.splice(t,1),this.thenCallback=void 0}},Ti={LINEAR:n=>n,POWER:n=>t=>t**n,SINE:n=>1-ut(n*(Q/2)),CIRC:n=>1-(1-n*n)**.5,EXPO:n=>n===0?0:2**(10*n-10),BACK:n=>n*n*(2.70158*n-1.70158),ELASTIC:n=>n===0?0:n===1?1:-(2**(10*n-10))*rt((37-40*n)*Q/6),SPRING:n=>1-(rt(Q*(1-n)*(.2+2.5*(1-n)**3))*n**2.2+(1-n))*(1+1.2*n),BOUNCE:n=>{let t=1-n,e;return t<4/11?e=7.5625*t*t:t<8/11?e=7.5625*(t-=6/11)*t+.75:t<10/11?e=7.5625*(t-=9/11)*t+.9375:e=7.5625*(t-=10.5/11)*t+.984375,1-e},IN:n=>n,OUT:n=>t=>1-n(1-t),IN_OUT:n=>Ti.PIECEWISE(n,Ti.OUT(n)),PIECEWISE:(...n)=>{let t=n.length;return e=>{let s=e*t-1e-9>>0;return(n[s]((e-s/t)*t)+s)/t}},BEZIER:(n,t,e,s)=>{let i=o=>{let a=1-o,r=3*a*a*o,c=3*a*o*o,l=o**3;return[r*n+c*e+l,r*t+c*s+l]};return o=>{let a=0,r=1;for(let c=0;c<128;c++){let l=(a+r)/2,[u,h]=i(l);if(ot(u-o)<1e-5)return h;u=this.size.x||e>=this.size.y?null:this.nodes[t+e*this.size.x]}worldToTile(t){let e=this.tileLayer?this.tileLayer.pos.x:0,s=this.tileLayer?this.tileLayer.pos.y:0;return b(Pt(t.x-e),Pt(t.y-s))}tileToWorld(t,e){let s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;return b(t+.5+s,e+.5+i)}buildNodeData(){let t=this.size.x,e=this.size.y,s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;for(let o=0;o0&&(c?l>0&&Ct(r.posWorld,ao,V(1,0,0,st(.2,l*.05)),this.debugTime):Ct(r.posWorld,ao,V(1,0,0,.25),this.debugTime))}}aStarSearch(t,e){p(t&&e,"aStarSearch needs both endpoints"),p(t!==e,"aStarSearch: start and end must differ \u2014 caller should handle trivial case"),p(t.walkable&&e.walkable,"aStarSearch: endpoints must be walkable");let s=[t];t.isOpen=!0;let i=0;for(;s.length>0;){let o=0,a=s[0].f;for(let c=1;cthis.maxLoop)break;r.isOpen=!1,s.splice(o,1),r.isClosed=!0,this.debug&&this.debugTime>0&&Ct(r.posWorld,ao,V(1,1,1,.05),this.debugTime);for(let c=-1;c<=1;++c)for(let l=-1;l<=1;++l){if(l===0&&c===0)continue;let u=this.getNode(r.pos.x+l,r.pos.y+c);if(!u||!u.walkable||u.isClosed)continue;let h=1;if(l!==0&&c!==0){let v=this.getNode(r.pos.x+l,r.pos.y);if(!v||!v.walkable)continue;let w=this.getNode(r.pos.x,r.pos.y+c);if(!w||!w.walkable)continue;h=fd}let f=r.g+h+u.cost;if(!u.isOpen)u.isOpen=!0,s.push(u);else if(f>=u.g)continue;u.parent=r,u.g=f;let d=ot(e.pos.x-u.pos.x),y=ot(e.pos.y-u.pos.y),x=tt(d,y)+(Math.SQRT2-1)*st(d,y);u.f=u.g+x*this.heuristicWeight}}return e.parent!==null}getNearestClearNode(t,e=10,s=!0){p(O(t),"worldPos must be a Vector2"),s&&this.buildNodeData();let i=this.tileLayer?this.tileLayer.pos.x:0,o=this.tileLayer?this.tileLayer.pos.y:0,a=Pt(t.x-i),r=Pt(t.y-o);for(let c=0;c<=e;++c){let l=null,u=0;for(let h=-c;h<=c;++h)for(let f=-c;f<=c;++f){if(c>0&&ot(f)!==c&&ot(h)!==c)continue;let d=this.getNode(a+f,r+h);if(!d||!d.isClear())continue;let y=d.posWorld.x-t.x,x=d.posWorld.y-t.y,v=y*y+x*x;(!l||v0&&Ht(i.posWorld,.3,V(.5,0,.5,.5),this.debugTime),t.splice(e,1),e=tt(1,e-1);continue}else if(c===2){this.debug&&this.debugTime>0&&Ht(i.posWorld,.3,V(1,0,0,.5),this.debugTime);let d,y;s.pos.y===i.pos.y&&o.pos.x===i.pos.x?(d=s.pos.x,y=o.pos.y):(d=o.pos.x,y=s.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t.splice(e,1),e=tt(1,e-1);continue}}else if(c===5){this.debug&&this.debugTime>0&&Ht(i.posWorld,.3,V(1,1,0,.5),this.debugTime);let d=e>=2?t[e-2]:s,y,x,v,w;l===0||h===0?(y=o.pos.x,x=i.pos.y,v=s.pos.x,w=i.pos.y):(y=i.pos.x,x=o.pos.y,v=i.pos.x,w=s.pos.y);let _=y-d.pos.x,S=x-d.pos.y,E=v-d.pos.x,A=w-d.pos.y,T=_*_+S*S,P=E*E+A*A,F=T0&&Ht(i.posWorld,.3,V(0,1,0,.5),this.debugTime),l===h&&u===f){++e;continue}else{let d,y;s.pos.y===o.pos.y?(d=i.pos.x,y=s.pos.y):(d=s.pos.x,y=i.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t[e]=x,e=tt(1,e-1);continue}}++e}}smoothPathStringPull(t){if(t.length<=2)return;for(let i of t)if(!i.isClear())return;let e=t.slice();t.length=0,t.push(e[0]);let s=0;for(let i=1;i0&&Ee(o.posWorld,t[t.length-1].posWorld,V(0,0,1,.3),.02,this.debugTime);continue}for(;s=1;--e){let s=t[e-1],i=t[e],o=t[e+1];(i.pos.x-s.pos.x)*(o.pos.y-s.pos.y)===(i.pos.y-s.pos.y)*(o.pos.x-s.pos.x)&&t.splice(e,1)}}isNodeClear(t,e){let s=this.getNode(t,e);return s!==null&&s.isClear()}isLineClear(t,e){p(O(t)&&O(e),"isLineClear needs Vector2 endpoints"),p(this.isNodeClear(t.x,t.y)&&this.isNodeClear(e.x,e.y),"isLineClear endpoints must be in-bounds and clear");let s=e.x-t.x,i=e.y-t.y,o=ot(s),a=ot(i),r=ae(s),c=ae(i),l=t.x,u=t.y;if(a===o){for(;l!==e.x;){if(l!==t.x&&(!this.isNodeClear(l,u)||!this.isNodeClear(l,u-c))||!this.isNodeClear(l,u+c))return!1;l+=r,u+=c}if(!this.isNodeClear(e.x,e.y-c))return!1}else if(ar.posWorld.copy());if(this.debug&&this.debugTime>0&&a.length>0){for(let r=1;rpd,bootGameHost:()=>yd,default:()=>gd});var ks=class{constructor(t){this._state=(t==null?2654435769:t)>>>0}next(){this._state=this._state+1831565813>>>0;let t=this._state;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}range(t,e){return t+this.next()*(e-t)}reseed(t){this._state=(t==null?2654435769:t)>>>0}},Ni=class{constructor(t){this._clock=t||Jc(),this._origin=this._clock()}nowMs(){return this._clock()}elapsedMs(){return this._clock()-this._origin}},zi=class{constructor(t){this._time=t,this._subs=new Map}sourceFor(t){let e=this,s=t==null?null:t;return{on(i,o){if(e._assertType(i),typeof o!="function")throw new Error("[HostDevInputBridge] on \u7684 handler \u5FC5\u987B\u662F\u51FD\u6570");let a=e._subs.get(i)||[],r={handler:o,scope:s};return a.push(r),e._subs.set(i,a),{cancel(){let c=e._subs.get(i);if(!c)return;let l=c.indexOf(r);l>=0&&c.splice(l,1)}}},off(i,o){e._assertType(i);let a=e._subs.get(i);if(!a)return;let r=a.findIndex(c=>c.handler===o&&c.scope===s);r>=0&&a.splice(r,1)}}}_emit(t,e){this._assertType(t);let s=e||{},i={type:t,x:typeof s.x=="number"?s.x:0,y:typeof s.y=="number"?s.y:0,key:typeof s.key=="string"?s.key:"",tMs:this._time.nowMs()},o=this._subs.get(t);if(!o||o.length===0)return;let a=o.slice();for(let r of a)try{r.handler(i)}catch(c){Ye("[host-dev input] \u8F93\u5165 handler \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09type="+t,c)}}disposeScope(t){if(t==null)return 0;let e=0;for(let[s,i]of this._subs){let o=i.filter(a=>a.scope!==t);e+=i.length-o.length,o.length===0?this._subs.delete(s):this._subs.set(s,o)}return e}_subscriptionCount(){let t=0;for(let e of this._subs.values())t+=e.length;return t}_assertType(t){if(!Ji.has(t))throw new Error("[HostDevInputBridge] \u975E\u6CD5\u8F93\u5165\u4E8B\u4EF6\u7C7B\u578B\uFF1A"+String(t)+"\uFF08\u4EC5\u652F\u6301 "+Array.from(Ji).join("/")+"\uFF09")}},Ji=new Set(["pointerdown","pointermove","pointerup","keydown","keyup"]);function Hr(n){let t=n||{},e=new Ni(t.clock),s=new ks(t.seed),i=t.seed==null?2654435769:t.seed>>>0,o=new zi(e),a=typeof t.audioFactory=="function"?t.audioFactory:null,r=null,c=!1,l=typeof t.engineFactory=="function"?t.engineFactory:null,u=null,h=!1,f=new Map,d=0,y=0;function x(){if(r)return r;if(!a)return c||(Vi("[host-dev audio] \u672A\u6CE8\u5165 audioFactory\uFF0CgetAudioContext \u8FD4\u56DE null\uFF08P6 \u987B\u5BB9\u9519\u964D\u7EA7\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u5DE5\u5382\uFF09"),c=!0),null;try{r=a()}catch(E){Ye("[host-dev audio] audioFactory \u629B\u9519\uFF0CgetAudioContext \u964D\u7EA7\u8FD4\u56DE null",E),r=null}return r}function v(){if(u)return u;if(!l)return h||(Vi("[host-dev engine] \u672A\u6CE8\u5165 engineFactory\uFF0CgetEngine \u8FD4\u56DE null\uFF08\u63D2\u4EF6\u987B\u5BB9\u9519\u964D\u7EA7\uFF1A\u7C92\u5B50\u9000\u53D7\u63A7\u9762\u81EA\u7BA1/\u5408\u6210\u6838\u9000 vendored/\u6570\u5B66\u9000\u5185\u7F6E\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u80CC\u4E66\uFF09"),h=!0),null;try{u=l()}catch(E){Ye("[host-dev engine] engineFactory \u629B\u9519\uFF0CgetEngine \u964D\u7EA7\u8FD4\u56DE null",E),u=null}return u}function w(E,A){return{getContext2d(){return t.context2d==null?null:t.context2d},onFrame(P){let F=d++;return f.set(F,P),{cancel(){f.delete(F)}}},getInput(){return o.sourceFor(E)},getAudioContext(){return x()},getEngine(){return v()},time:e,random:A}}let _=w(null,s),S={context:_,tick(E){y+=1;let A=Array.from(f.values());for(let T of A)try{T(E,y)}catch(P){Ye("[host-dev tick] \u5E27\u56DE\u8C03\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09frame="+y,P)}},frameCount(){return y},inputBridge:o,deriveContextFor(E,A){let T=zc(i,E),P=new ks(T);return w(A==null?E:A,P)}};return Object.defineProperty(_,Ui,{value:S,enumerable:!1,writable:!1,configurable:!1}),S}var Ui=Symbol("zaomeng.coreProtocol.contextBundle"),Gs=class{constructor(){this._plugins=new Map,this._initOrder=[],this._initErrors=[],this._phase="idle",this._disposed=!1,this._context=void 0,this._pluginContexts=new Map}register(t){if(!t||typeof t!="object")throw new Error("[PluginRegistry] register \u9700\u8981\u4E00\u4E2A\u63D2\u4EF6\u5BF9\u8C61");if(typeof t.name!="string"||t.name.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6\u7F3A\u5C11\u5408\u6CD5 name");if(typeof t.version!="string"||t.version.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11\u5408\u6CD5 version");if(typeof t.init!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11 init \u51FD\u6570");if(t.dispose!=null&&typeof t.dispose!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7684 dispose \u5FC5\u987B\u662F\u51FD\u6570\u6216\u7701\u7565");if(this._plugins.has(t.name))throw new Error("[PluginRegistry] \u63D2\u4EF6\u91CD\u540D\u62D2\u7EDD\uFF1A"+t.name+" \u5DF2\u6CE8\u518C");return this._plugins.set(t.name,t),this}has(t){return this._plugins.has(t)}get(t){return this._plugins.get(t)}list(){return Array.from(this._plugins.keys())}initAll(){if(this._phase==="initialized")return Vi("[PluginRegistry] initAll \u91CD\u590D\u8C03\u7528\uFF0C\u5DF2\u5FFD\u7565\uFF08\u5DF2\u5904\u4E8E initialized\uFF09"),this._initResult();if(this._phase==="disposed")throw new Error("[PluginRegistry] \u5DF2 dispose \u7684\u6CE8\u518C\u5668\u4E0D\u53EF\u518D initAll");if(this._context==null)throw new Error("[PluginRegistry] \u672A\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\uFF1A\u8BF7\u5728 initAll() \u4E4B\u524D\u8C03\u7528 useContext(context)\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context); reg.initAll();\uFF09");for(let[t,e]of this._plugins){let s=this._missingDeps(e);if(s.length>0){let o=new Error("[PluginRegistry] \u63D2\u4EF6 "+t+" \u4F9D\u8D56\u7F3A\u5931\uFF1A"+s.join(", ")+"\uFF08\u672A\u6CE8\u518C\uFF09");this._initErrors.push({name:t,error:o}),Ye("[PluginRegistry] \u8DF3\u8FC7 init\uFF08\u4F9D\u8D56\u7F3A\u5931\uFF0C\u5DF2\u9694\u79BB\uFF09\uFF1A"+t,o);continue}let i=this._contextFor(t);try{e.init(i),this._initOrder.push(t)}catch(o){let a=o instanceof Error?o:new Error(String(o));this._initErrors.push({name:t,error:a}),Ye("[PluginRegistry] \u63D2\u4EF6 init \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF0C\u4E0D\u8FDE\u5750\uFF09\uFF1A"+t,a)}}return this._phase="initialized",this._initResult()}_contextFor(t){let e=this._pluginContexts.get(t);if(e)return e;let s=this._context&&this._context[Ui],i;return s&&typeof s.deriveContextFor=="function"?i=s.deriveContextFor(t,t):i=this._context,this._pluginContexts.set(t,i),i}disposeAll(){if(this._disposed)return{disposed:[],errors:[]};let t=[],e=[],s=this._context&&this._context[Ui],i=s&&s.inputBridge;for(let o=this._initOrder.length-1;o>=0;o--){let a=this._initOrder[o],r=this._plugins.get(a);if(r&&typeof r.dispose=="function")try{r.dispose(),t.push(a)}catch(c){let l=c instanceof Error?c:new Error(String(c));e.push({name:a,error:l}),Ye("[PluginRegistry] \u63D2\u4EF6 dispose \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+a,l)}if(i&&typeof i.disposeScope=="function")try{i.disposeScope(a)}catch(c){Ye("[PluginRegistry] \u56DE\u6536\u63D2\u4EF6\u8F93\u5165\u8BA2\u9605\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+a,c)}}return this._disposed=!0,this._phase="disposed",{disposed:t,errors:e}}useContext(t){if(this._phase!=="idle")throw new Error("[PluginRegistry] useContext \u5FC5\u987B\u5728 initAll() \u4E4B\u524D\u8C03\u7528\uFF08\u5F53\u524D\u9636\u6BB5\uFF1A"+this._phase+"\uFF09\u3002\u8BF7\u5728\u4EFB\u4F55 initAll/disposeAll \u4E4B\u524D\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\u3002");if(t==null||typeof t!="object")throw new Error("[PluginRegistry] useContext \u9700\u8981\u4E00\u4E2A\u53D7\u63A7\u4E0A\u4E0B\u6587\u5BF9\u8C61\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context);\uFF09");return this._context=t,this}_missingDeps(t){return!Array.isArray(t.dependencies)||t.dependencies.length===0?[]:t.dependencies.filter(e=>!this._plugins.has(e))}_initResult(){return{ok:this._initErrors.length===0,initialized:this._initOrder.slice(),errors:this._initErrors.slice()}}};function zc(n,t){let e=2166136261,s=16777619,i=n>>>0;for(let a=0;a<32;a+=8){let r=i>>>a&255;e^=r,e=Math.imul(e,s)>>>0}let o=String(t);for(let a=0;a>>0,e^=r>>>8&255,e=Math.imul(e,s)>>>0}return e>>>0}function Jc(){if(typeof globalThis!="undefined"&&globalThis.performance&&typeof globalThis.performance.now=="function")return()=>globalThis.performance.now();if(typeof process!="undefined"&&process.hrtime&&typeof process.hrtime.bigint=="function"){let n=process.hrtime.bigint();return()=>Number(process.hrtime.bigint()-n)/1e6}return()=>Date.now()}function Ye(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function Vi(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var xd=Object.freeze(Array.from(Ji)),Xr="core-protocol-v0";var Yr=Object.freeze(["t_boot","t_plugins_ready","t_game_init","t_first_paint","t_input_bound","t_game_start"]),Wi=Yr.reduce((n,t,e)=>(n[t]=e,n),Object.create(null)),Uc=new Set(Yr);function qi(n){let t=2166136261;for(let e=0;e>>0).toString(16).padStart(8,"0")}var $r=qi("runtime-probe::seed::v1");function Fs(n){return n===null||typeof n!="object"?JSON.stringify(n):Array.isArray(n)?"["+n.map(Fs).join(",")+"]":"{"+Object.keys(n).sort().map(e=>JSON.stringify(e)+":"+Fs(n[e])).join(",")+"}"}function Kr(n){let t=Fs(n.extra==null?null:n.extra),e=Fs(Array.isArray(n.pluginSet)?n.pluginSet:[]);return["seq="+n.seq,"anchor="+n.anchor,"tMono="+n.tMono,"buildSha="+(n.buildSha||""),"pluginSet="+e,"extra="+t].join("|")}function Vc(n){return Math.round(n*1e3)/1e3}function Wc(n){if(!Array.isArray(n))return{ok:!1,reason:"records_not_array"};let t=$r,e=-1;for(let s=0;stypeof E=="string").slice().sort():[],i=typeof t.sink=="function"?t.sink:null,o=t.autoBoot!==!1,a=typeof t.inputAnchorType=="string"?t.inputAnchorType:"pointerdown",r=()=>0,c=!1,l=0,u=$r,h=[],f=new Set,d=-1,y=null,x=!1,v=!1,w=!1;function _(E,A){let T=null;if(!Uc.has(E))T="unknown_anchor";else{f.has(E)&&(T=T?T+";duplicate_anchor":"duplicate_anchor");let F=Wi[E];FE.time.nowMs(),c=!0,o&&!v&&_("t_boot",{auto:!0}),y=E.getInput().on(a,A=>{x||(x=!0,_("t_input_bound",{firstInput:!0,type:A.type}))}),_("t_input_bound",{stage:"registered",type:a})},dispose(){w||(y&&(y.cancel(),y=null),w=!0)},mark:_,getRecords(){return h.map(E=>({...E}))},toJSONL(){return h.map(E=>JSON.stringify(E)).join(`
-`)},verify(){return Wc(h)}}}function qc(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function Zr(n){let t=n.LJS,e=n.engineMath,s=n.engineMode,i=n.recHook||(()=>{});if(s!=="real")return null;let o=e;return{math:{lerp:(r,c,l)=>(i("math.lerp"),o.lerp(r,c,l)),smoothStep:r=>(i("math.smoothStep"),o.smoothStep(r)),easing:Object.fromEntries(Object.keys(o.easing).map(r=>[r,c=>(i("math.easing."+r),o.easing[r](c))]))},particles:{spawnEmitter(r){i("particles.spawnEmitter");let c=t.screenToWorld(t.vec2(r.pos.x,r.pos.y)),l=t.cameraScale,u=r.emitTime!=null?r.emitTime:r.count!=null?1/60:0,h=r.emitRate!=null?r.emitRate:r.count!=null?r.count*60:100,f=(r.speed!=null?r.speed:0)/l/60,d=r.damping!=null?r.damping:1,y=r.colorStart||{r:1,g:1,b:1,a:1},x=r.colorEnd||{r:1,g:1,b:1,a:0},v=t.rgb(y.r,y.g,y.b,y.a),w=t.rgb(x.r,x.g,x.b,x.a),_=new t.ParticleEmitter(c,r.angle!=null?r.angle:0,(r.emitSize!=null?r.emitSize:0)/l,u,h,r.coneAngle!=null?r.coneAngle:Math.PI,void 0,v,v,w,w,r.particleTime!=null?r.particleTime:.5,(r.sizeStart!=null?r.sizeStart:6)/l,(r.sizeEnd!=null?r.sizeEnd:0)/l,f,0,d,1,r.gravityScale!=null?r.gravityScale:0,Math.PI,.1,0,!1,r.additive!=null?r.additive:!1,!0);return{isActive(){return _.isActive()},stop(){_.destroyed||_.destroy(!0)}}}},audio:{synth:{synthSfx:r=>{i("audio.synth.synthSfx");try{return t.zzfxG(...r)}catch(c){return console.error("[host][engine-audio] zzfxG \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(c&&c.message?c.message:c)),null}},synthSong:(r,c,l,u)=>{i("audio.synth.synthSong");try{return t.zzfxM(r,c,l,u)}catch(h){return console.error("[host][engine-audio] zzfxM \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(h&&h.message?h.message:h)),null}}}}}}function fe(n){return n<0?0:n>1?1:n}function ta(n){let t=n.Ease,e=t.POWER(2),s=t.POWER(3),i=t.OUT(e),o=t.IN_OUT(e),a=t.OUT(s),r=t.IN_OUT(s),c=t.OUT(t.BACK),l=t.OUT(t.ELASTIC);return{lerp:(u,h,f)=>n.lerp(u,h,f),smoothStep:u=>n.smoothStep(u),easing:{linear:u=>t.LINEAR(fe(u)),quadIn:u=>e(fe(u)),quadOut:u=>i(fe(u)),quadInOut:u=>o(fe(u)),cubicIn:u=>s(fe(u)),cubicOut:u=>a(fe(u)),cubicInOut:u=>r(fe(u)),backIn:u=>t.BACK(fe(u)),backOut:u=>c(fe(u)),elasticIn:u=>t.ELASTIC(fe(u)),elasticOut:u=>l(fe(u))}}}var $e=2,js=1/60;async function ea(n){let t=n.canvas,e=n.statusEl||null,s=n.engine,i=n.seed>>>0,o=n.mode||"play",a=n.engineMode||"real",r=n.viewport.w,c=n.viewport.h,l=n.factory,u=n.buildFactoryOpts||(()=>{}),h=n.plugins||{},f=n.registerOrder||Object.values(h),d=n.onReady||(()=>{}),y=n.recHook||(()=>{});function x(D){e&&(e.textContent=D)}let v=[];window.addEventListener("error",D=>v.push({type:"error",message:String(D&&D.message||D)})),window.addEventListener("unhandledrejection",D=>v.push({type:"unhandledrejection",message:String(D&&D.reason&&D.reason.message||D&&D.reason||D)}));let w=null,_=!1;function S(){if(!_)return null;if(w)return w;let D=window.AudioContext||window.webkitAudioContext;return D?(w=new D,w):null}let E=0,A=null,T=null,P=null,F=null,bt=[],ct={},gt=null;function wt(D,ft){try{P&&P.mark(D,ft)}catch(oe){v.push({type:"mark",message:String(oe&&oe.message||oe)})}}function Ut(){T&&typeof T._refreshChecklist=="function"&&T._refreshChecklist(ct)}async function L(D,ft){A=Hr({context2d:D,seed:i,audioFactory:S,clock:()=>E,engineFactory:()=>Zr({LJS:a==="real"?s:null,engineMath:a==="real"?ta(s):null,engineMode:a,recHook:y})});let oe=new Gs;for(let ve of f)oe.register(ve);oe.useContext(A.context),F=oe.initAll(),bt=oe.list().concat(["runtime-probe"]),P=Qr({pluginSet:bt,inputAnchorType:"pointerdown",autoBoot:!0});let re=A.deriveContextFor("runtime-probe","runtime-probe");wt("t_boot",{by:"game-host",stage:"pre-init",engineMode:a}),wt("t_plugins_ready",{initialized:F.initialized.length,ok:F.ok});let ji=u(A.context,{bundle:A,plugins:h,getRealAudioCtx:()=>w});T=l(ji),await T.init({ctx:A.context,mainContext:D,canvas:ft(),seed:i}),gt=T&&typeof T._forensicsView=="function"?T._forensicsView():null,wt("t_game_init",{hasForensics:!!gt}),M(),wt("t_first_paint",{frame:A.frameCount()});try{P.init(re)}catch(ve){v.push({type:"probe-init",message:String(ve&&ve.message||ve)})}wt("t_game_start",{mode:o,engineMode:a}),Ut(),d(ht,{bundle:A,game:T,probe:P,checklist:ct,uncaught:v,pluginSet:bt,initRes:F,getGameForensics:()=>gt,mark:wt,stepOneFrame:M})}let I=null;function M(D){let ft=typeof D=="number"?D:js;T&&(E+=ft*1e3,T.update(ft),a==="stub"&&I&&T.render(I),Ut())}function B(D){for(let ft=0;ft{}),T&&typeof T._onAudioUnlock=="function"&&T._onAudioUnlock()}let ht={seed:i,mode:o,engineMode:a,protocol:Xr,frameCount:()=>A?A.frameCount():0,stepFrames:B,startRaf:()=>Me(),stopRaf:()=>G(),tap(D,ft){nt(),A&&(A.inputBridge._emit("pointerdown",{x:D,y:ft}),A.inputBridge._emit("pointerup",{x:D,y:ft}))},do(D){T&&typeof T._handleAction=="function"&&T._handleAction(D)},state:()=>gt?gt.state():{phase:"booting"}};function xt(D){let ft=A.inputBridge;function oe(re,ji){let ve=D.getBoundingClientRect();return{x:(re-ve.left)/ve.width*r,y:(ji-ve.top)/ve.height*c}}D.addEventListener("pointerdown",re=>{nt(),ft._emit("pointerdown",oe(re.clientX,re.clientY))}),D.addEventListener("pointermove",re=>{ft._emit("pointermove",oe(re.clientX,re.clientY))}),D.addEventListener("pointerup",re=>{ft._emit("pointerup",oe(re.clientX,re.clientY))})}let dt=0,vt=!1,Tt=0;function de(D){if(!vt)return;Tt===0&&(Tt=D);let ft=(D-Tt)/1e3;Tt=D,ft>.05&&(ft=.05),M(ft),dt=window.requestAnimationFrame(de)}function Me(){a==="stub"&&(vt||(vt=!0,Tt=0,dt=window.requestAnimationFrame(de)))}function G(){vt=!1,dt&&window.cancelAnimationFrame(dt),dt=0}function J(D){D.width=r*$e,D.height=c*$e,D.style.width=r+"px",D.style.height=c+"px";let ft=D.getContext("2d",{willReadFrequently:!0});return ft.setTransform($e,0,0,$e,0,0),ft}async function Rt(){let D=J(t);return I=D,await L(D,()=>t),xt(t),o==="evidence"?x(`evidence \u5C31\u7EEA seed=${i} \xB7 \u7528 host \u9A71\u52A8\uFF08stepFrames/tap\uFF09`):(x(`seed=${i} \xB7 \u70B9\u5F00\u59CB\uFF08\u9996\u6B21\u70B9\u51FB\u5F00\u58F0\uFF09`),Me()),ht}let Ie=()=>{},X=()=>{};function Y(){window.__gameHostEngineInitFired=!0}function kt(){Ie()}function ie(){}function Vt(){X()}function Wr(){}async function Ic(D){await L(D,()=>s.mainCanvas),xt(s.mainCanvas),Ie=()=>{T&&(E+=js*1e3,T.update(js))},X=()=>{if(T){D.save(),D.setTransform($e,0,0,$e,0,0);try{D.imageSmoothingEnabled=!1}catch{}T.render(D),D.restore()}},s.mainCanvas&&(s.mainCanvas.id="game-engine"),window.__engine={frame(){return s.frame},time(){return s.time},timeReal(){return s.timeReal},paused(){return s.paused},timeScale(){return s.timeScale},snapshot(){return{frame:s.frame,time:s.time,timeReal:s.timeReal,paused:s.paused,timeScale:s.timeScale}}},x(`engine RAF running \xB7 seed=${i} engine=real`)}if(a!=="real")return await Rt();if(!s){let D="real \u901A\u9053\u672A\u6CE8\u5165\u5F15\u64CE\uFF08opts.engine \u7F3A\u5931\uFF09\uFF1A\u8BF7\u7ECF entry \u5305\u88C5\u5C42\u542F\u52A8\uFF08host \u4E0D\u76F4\u63A5 import \u5F15\u64CE\uFF0CQ4/Option C\uFF09";throw x("ENGINE INJECT MISSING: "+D),new Error(D)}s.setGLEnable(!1),s.setShowSplashScreen(!1),s.setDebugWatermark(!1),s.setCanvasClearColor(s.BLACK),s.setCanvasFixedSize(s.vec2(r*$e,c*$e));let Fi=document.createElement("div");return Fi.id="engine-root",document.body.appendChild(Fi),await s.engineInit(Y,kt,ie,Vt,Wr,[],Fi).then(()=>Ic(s.mainContext)).catch(D=>{throw window.__gameHostBootError=String(D&&D.message||D),x("ENGINE INIT FAILED: "+window.__gameHostBootError),D}),ht}var Hi=class{constructor(t){let e=t||{},s=typeof e.cellSize=="number"&&e.cellSize>0?e.cellSize:64;this._cellSize=s,this._cells=new Map,this._entries=new Map,this._seq=0}get size(){return this._entries.size}_cellRange(t){let e=this._cellSize,s=Math.floor((t.x-t.hw)/e),i=Math.floor((t.x+t.hw)/e),o=Math.floor((t.y-t.hh)/e),a=Math.floor((t.y+t.hh)/e);return{cx0:s,cy0:o,cx1:i,cy1:a}}insert(t,e){this._entries.has(t)&&this.remove(t);let{cx0:s,cy0:i,cx1:o,cy1:a}=this._cellRange(e),r=[];for(let l=i;l<=a;l++)for(let u=s;u<=o;u++){let h=u+","+l,f=this._cells.get(h);f||(f=new Set,this._cells.set(h,f)),f.add(t),r.push(h)}let c={x:e.x,y:e.y,hw:e.hw,hh:e.hh};this._entries.set(t,{id:t,box:c,seq:this._seq++,cells:r})}remove(t){let e=this._entries.get(t);if(!e)return!1;for(let s of e.cells){let i=this._cells.get(s);i&&(i.delete(t),i.size===0&&this._cells.delete(s))}return this._entries.delete(t),!0}query(t){let{cx0:e,cy0:s,cx1:i,cy1:o}=this._cellRange(t),a=new Set;for(let r=s;r<=o;r++)for(let c=e;c<=i;c++){let l=this._cells.get(c+","+r);if(l)for(let u of l)a.add(u)}return this._collect(a)}queryPoint(t,e){let s=this._cellSize,i=Math.floor(t/s),o=Math.floor(e/s),a=this._cells.get(i+","+o);return a?this._collect(new Set(a)):[]}clear(){this._cells.clear(),this._entries.clear(),this._seq=0}_collect(t){let e=[];for(let s of t){let i=this._entries.get(s);i&&e.push(i)}return e.sort((s,i)=>s.seq-i.seq),e.map(s=>({id:s.id,box:s.box}))}};function na(n){let t=n||{},e=new Hi({cellSize:t.cellSize}),s=!1;return{name:"collision",version:"1.0.0",dependencies:[],spatial:e,init(o){},dispose(){s||(e.clear(),s=!0)}}}function sa(n){let t=!1;return{name:"physics-lite",version:"1.0.0",dependencies:[],init(s){},dispose(){t||(t=!0)}}}var Hc=["pointerdown","pointermove","pointerup","keydown","keyup"];function Wt(n){return n<0?0:n>1?1:n}var Xc=n=>(n=Wt(n),n*n),Yc=n=>(n=Wt(n),1-(1-n)*(1-n)),$c=n=>(n=Wt(n),n<.5?2*n*n:1-Math.pow(-2*n+2,2)/2),Kc=n=>(n=Wt(n),n*n*n),Qc=n=>{n=Wt(n);let t=1-n;return 1-t*t*t},Zc=n=>(n=Wt(n),n<.5?4*n*n*n:1-Math.pow(-2*n+2,3)/2),ra=2*Math.PI/3,ia=2*Math.PI/4.5,tl=n=>(n=Wt(n),n===0?0:n===1?1:-Math.pow(2,10*n-10)*Math.sin((n*10-10.75)*ra)),el=n=>(n=Wt(n),n===0?0:n===1?1:Math.pow(2,-10*n)*Math.sin((n*10-.75)*ra)+1),nl=n=>(n=Wt(n),n===0?0:n===1?1:n<.5?-(Math.pow(2,20*n-10)*Math.sin((20*n-11.125)*ia))/2:Math.pow(2,-20*n+10)*Math.sin((20*n-11.125)*ia)/2+1),Ns=1.70158,Bs=Ns*1.525,aa=Ns+1,sl=n=>(n=Wt(n),aa*n*n*n-Ns*n*n),il=n=>{n=Wt(n);let t=n-1;return 1+aa*t*t*t+Ns*t*t},ol=n=>(n=Wt(n),n<.5?Math.pow(2*n,2)*((Bs+1)*2*n-Bs)/2:(Math.pow(2*n-2,2)*((Bs+1)*(n*2-2)+Bs)+2)/2),rl=n=>Wt(n),oa=Object.freeze({linear:rl,quadIn:Xc,quadOut:Yc,quadInOut:$c,cubicIn:Kc,cubicOut:Qc,cubicInOut:Zc,elasticIn:tl,elasticOut:el,elasticInOut:nl,backIn:sl,backOut:il,backInOut:ol});var al=["linear","quadIn","quadOut","quadInOut","cubicIn","cubicOut","cubicInOut","elasticIn","elasticOut","elasticInOut","backIn","backOut","backInOut"];function cl(n){let t=n&&n.easing;if(!t)return oa;let e=i=>typeof t[i]=="function"?o=>t[i](Wt(o)):oa[i],s={};for(let i of al)s[i]=e(i);return Object.freeze(s)}var Xi=class{constructor(t,e,s){let i=s||{};this._time=e,this._windowMs=typeof i.windowMs=="number"&&i.windowMs>0?i.windowMs:120;let o=Array.isArray(i.types)&&i.types.length>0?i.types:Hc;this._records=new Map,this._subs=[],this._disposed=!1;for(let a of o){this._records.set(a,null);let r=t.on(a,c=>{this._records.set(a,c.tMs)});this._subs.push(r)}}consume(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs?(this._records.set(t,null),!0):(this._records.set(t,null),!1)}peek(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs}clear(){for(let t of this._records.keys())this._records.set(t,null)}dispose(){if(!this._disposed){for(let t of this._subs)try{t.cancel()}catch(e){}this._subs=[],this._disposed=!0}}};function ca(n){let t=n||{},e=null,s=null,i=!1;return{name:"gamefeel",version:"1.0.0",dependencies:[],get inputBuffer(){return e},get easing(){return cl(s)},init(a){let r=a.getInput();e=new Xi(r,a.time,{windowMs:t.inputBufferMs,types:t.inputTypes});let c=a.getEngine();s=c?c.math:null},dispose(){i||(e&&(e.dispose(),e=null),s=null,i=!0)}}}function zs(n,t){let e=t<0?0:t>1?1:t;switch(n&&n.kind){case"constant":return n.value;case"linear":return n.from+(n.to-n.from)*e;case"easeInOut":{let s=e*e*(3-2*e);return n.from+(n.to-n.from)*s}case"decay":{let s=n.power==null?2:n.power,i=Math.pow(1-e,s);return n.to+(n.from-n.to)*i}default:return 0}}var ll=Object.freeze({burst:Object.freeze({mode:"burst",count:24,angle:0,spread:Math.PI,speedMin:80,speedMax:160,lifeMin:.4,lifeMax:.8,gravity:0,drag:0,sizeCurve:{kind:"decay",from:6,to:0,power:1.5},alphaCurve:{kind:"linear",from:1,to:0}}),trail:Object.freeze({mode:"continuous",rate:60,angle:Math.PI,spread:.25,speedMin:20,speedMax:50,lifeMin:.2,lifeMax:.5,gravity:0,drag:1.5,sizeCurve:{kind:"easeInOut",from:4,to:0},alphaCurve:{kind:"decay",from:.8,to:0,power:2}}),drift:Object.freeze({mode:"continuous",rate:12,angle:Math.PI/2,spread:.6,speedMin:10,speedMax:30,lifeMin:1.5,lifeMax:3,gravity:8,drag:.5,sizeCurve:{kind:"constant",value:3},alphaCurve:{kind:"decay",from:.7,to:0,power:1}})});function ul(n){let t=ll[n];return t?Yi(t):null}function Yi(n){let t={};for(let e of Object.keys(n)){let s=n[e];t[e]=s&&typeof s=="object"?Yi(s):s}return t}function hl(n,t,e){let s=n.mode==="continuous";return{pos:{x:t,y:e},angle:n.angle,coneAngle:n.spread,emitSize:0,emitTime:s?0:1/60,emitRate:s?n.rate||0:void 0,count:s?void 0:n.count||0,particleTime:(n.lifeMin+n.lifeMax)/2,speed:(n.speedMin+n.speedMax)/2,gravityScale:n.gravity||0,damping:n.drag!=null?1-n.drag/60:1,sizeStart:zs(n.sizeCurve,0),sizeEnd:zs(n.sizeCurve,1),colorStart:{r:1,g:1,b:1,a:zs(n.alphaCurve,0)},colorEnd:{r:1,g:1,b:1,a:zs(n.alphaCurve,1)},additive:!1}}function la(n){let t=n||{},e=null,s=null,i=null,o=new Map,a=0,r={isActive(){return!1},stop(){}},c=0,l=1,u=0,h=0,f=0,d={x:0,y:0,remain:0,dur:0,amplitude:0,frequency:0,_phase:0},y={alpha:0,remain:0,dur:0,peak:0},x={scale:1,remain:0,dur:0,amplitude:0,frequency:0},v=!1;function w(A){if(u>0)if(u-=A,u<=0)u=0,l=1;else{let T=h>0?1-u/h:1;l=f+(1-f)*T}if(d.remain>0)if(d.remain-=A,d.remain<=0)d.remain=0,d.x=0,d.y=0;else{let T=d.remain/d.dur,P=d.amplitude*T;d._phase+=d.frequency*A*Math.PI*2,d.x=Math.sin(d._phase)*P,d.y=Math.cos(d._phase*1.3)*P}if(y.remain>0&&(y.remain-=A,y.remain<=0?(y.remain=0,y.alpha=0):y.alpha=y.peak*(y.remain/y.dur)),x.remain>0)if(x.remain-=A,x.remain<=0)x.remain=0,x.scale=1;else{let T=x.remain/x.dur,P=(1-T)*x.frequency*Math.PI*2;x.scale=1+Math.sin(P)*x.amplitude*T}}function _(A){c+=1,w(A)}function S(A){let T=A!==void 0?A:e?e.getContext2d():null;if(T&&y.alpha>0){T.globalAlpha=y.alpha,T.fillStyle="#ffffff";let P=T.canvas?T.canvas.width:0,F=T.canvas?T.canvas.height:0;T.fillRect(0,0,P,F),T.globalAlpha=1}}return{name:"particles-juice",version:"1.0.0",dependencies:[],init(A){var T;e=A,i=((T=A.getEngine())==null?void 0:T.particles)||null,typeof t.seed=="number"&&A.random.reseed(t.seed),t.autoStep!==!1&&(s=A.onFrame(P=>{_(P)}))},dispose(){v||(s&&(s.cancel(),s=null),o.forEach(A=>{try{A.stop()}catch{}}),o.clear(),l=1,u=0,d.remain=0,d.x=0,d.y=0,y.remain=0,y.alpha=0,x.remain=0,x.scale=1,v=!0)},spawnEmitter(A,T,P,F){let bt=typeof A=="string"?ul(A):Yi(A);if(!bt)return-1;F&&(bt=Object.assign(bt,F));let ct=a++;if(!i)return o.set(ct,r),ct;let gt=i.spawnEmitter(hl(bt,T,P));return o.set(ct,gt),ct},stopEmitter(A){let T=o.get(A);if(T)try{T.stop()}catch{}},step(A){_(A)},render(A){S(A)},particleCount(){return 0},emitterCount(){let A=0;for(let T of o.values())T.isActive()&&(A+=1);return A},hitStop(A,T){h=Math.max(0,A),u=h,f=T==null?0:Math.max(0,Math.min(1,T)),l=h>0?f:1},getTimeScale(){return l},shakeScreen(A,T,P){d.dur=Math.max(0,A),d.remain=d.dur,d.amplitude=Math.max(0,T),d.frequency=P==null?30:P,d._phase=0,d.x=0,d.y=0},getShakeOffset(){return{x:d.x,y:d.y}},flashScreen(A,T){y.dur=Math.max(0,A),y.remain=y.dur,y.peak=T==null?.8:Math.max(0,Math.min(1,T)),y.alpha=y.dur>0?y.peak:0},getFlashAlpha(){return y.alpha},pulseScale(A,T,P){x.dur=Math.max(0,A),x.remain=x.dur,x.amplitude=T==null?.2:T,x.frequency=P==null?4:P,x.scale=1},getPulseScale(){return x.scale},juiceSnapshot(){return{timeScale:l,shake:{x:d.x,y:d.y},flashAlpha:y.alpha,pulseScale:x.scale}},probe(){return{particles:0,emitters:o.size,dropped:0,steps:c,disposed:v}}}}function ua(n){let t=St(n.r)/255,e=St(n.g)/255,s=St(n.b)/255,i=Math.max(t,e,s),o=Math.min(t,e,s),a=(i+o)/2,r=0,c=0,l=i-o;return l>1e-12&&(c=a>.5?l/(2-i-o):l/(i+o),i===t?r=(e-s)/l%6:i===e?r=(s-t)/l+2:r=(t-e)/l+4,r*=60,r<0&&(r+=360)),{h:r,s:c,l:a}}function ha(n){let t=(n.h%360+360)%360,e=Ke(n.s),s=Ke(n.l);if(e<1e-12){let r=Math.round(s*255);return{r,g:r,b:r}}let i=s<.5?s*(1+e):s+e-s*e,o=2*s-i,a=t/360;return{r:Math.round($i(o,i,a+1/3)*255),g:Math.round($i(o,i,a)*255),b:Math.round($i(o,i,a-1/3)*255)}}function $i(n,t,e){let s=e;return s<0&&(s+=1),s>1&&(s-=1),s<1/6?n+(t-n)*6*s:s<1/2?t:s<2/3?n+(t-n)*(2/3-s)*6:n}function St(n){return n<0?0:n>255?255:n}function Ke(n){return n<0?0:n>1?1:n}function dl(n,t){let e=pl(n.from,t);if(e>=0&&e({r:St(r.r),g:St(r.g),b:St(r.b)})),to:o}}function Ki(n,t,e){return n+(t-n)*e}function ml(n,t){let e=ua(n),s=e.h+(t.hue||0),i=Ke(e.s*(t.sat==null?1:t.sat)),o=Ke(e.l*(t.light==null?1:t.light));return ha({h:s,s:i,l:o})}var bl=Object.freeze([Object.freeze([0,8,2,10]),Object.freeze([12,4,14,6]),Object.freeze([3,11,1,9]),Object.freeze([15,7,13,5])]);function da(n){let t=n||{},e=null,s=!1,i={vignette:{enabled:Qi(t.vignette&&t.vignette.enabled,!1),strength:Zi(t.vignette&&t.vignette.strength,.5)},dither:{enabled:Qi(t.dither&&t.dither.enabled,!1),strength:Zi(t.dither&&t.dither.strength,.5)},scanline:{enabled:Qi(t.scanline&&t.scanline.enabled,!1),strength:Zi(t.scanline&&t.scanline.strength,.5)}};function o(r){let c=r!==void 0?r:e?e.getContext2d():null;if(!c)return;let l=c.canvas?c.canvas.width:0,u=c.canvas?c.canvas.height:0;if(i.vignette.enabled&&i.vignette.strength>0&&l>0&&u>0){let h=c.createRadialGradient(l/2,u/2,Math.min(l,u)*.25,l/2,u/2,Math.max(l,u)*.75);h.addColorStop(0,"rgba(0,0,0,0)"),h.addColorStop(1,"rgba(0,0,0,"+i.vignette.strength.toFixed(3)+")"),c.fillStyle=h,c.fillRect(0,0,l,u)}if(i.scanline.enabled&&i.scanline.strength>0&&l>0&&u>0){c.fillStyle="rgba(0,0,0,"+(i.scanline.strength*.5).toFixed(3)+")";for(let h=0;h0&&l>0&&u>0&&typeof c.getImageData=="function"&&typeof c.putImageData=="function"){let h=c.getImageData(0,0,l,u);xl(h,i.dither.strength),c.putImageData(h,0,0)}}return{name:"palette-post",version:"1.0.0",dependencies:[],init(r){e=r},dispose(){s||(e=null,s=!0)},applyPaletteMap(r,c){return dl(r,c)},applyPaletteMapToBuffer(r,c){return fl(r,c)},lerpPaletteMap(r,c,l){return yl(r,c,l)},shiftHsl(r,c){return ml(r,c)},rgbToHsl(r){return ua(r)},hslToRgb(r){return ha(r)},setPost(r){if(r)for(let c of["vignette","dither","scanline"])r[c]&&(typeof r[c].enabled=="boolean"&&(i[c].enabled=r[c].enabled),typeof r[c].strength=="number"&&(i[c].strength=Ke(r[c].strength)))},getPost(){return{vignette:{enabled:i.vignette.enabled,strength:i.vignette.strength},dither:{enabled:i.dither.enabled,strength:i.dither.strength},scanline:{enabled:i.scanline.enabled,strength:i.scanline.strength}}},renderPost(r){o(r)},probe(){return{disposed:s,post:this.getPost()}}}}function xl(n,t){let e=Ke(t);if(e<=0)return n;let{data:s,width:i}=n,a=255/(Math.max(2,Math.round(16-e*14))-1);for(let r=0;r+3>2)%i,l=Math.floor((r>>2)/i),u=(bl[l&3][c&3]/16-.5)*a;for(let h=0;h<3;h++){let f=s[r+h]+u,d=Math.round(f/a)*a;s[r+h]=d<0?0:d>255?255:d}}return n}function Qi(n,t){return typeof n=="boolean"?n:t}function Zi(n,t){return typeof n=="number"?Ke(n):t}var eo=Object.freeze({blip:Object.freeze({name:"blip",params:Object.freeze([.6,0,880,0,.03,.06,1,1.5])}),thud:Object.freeze({name:"thud",params:Object.freeze([.8,0,90,0,.04,.18,0,1,0,0,0,0,0,4])}),chime:Object.freeze({name:"chime",params:Object.freeze([.5,0,660,.02,.12,.3,1,2])})}),fa=Object.keys(eo);function vl(n){let t=[];return n==null||typeof n!="object"?{ok:!1,errors:["song \u5FC5\u987B\u662F\u5BF9\u8C61"]}:(!Array.isArray(n.instruments)||n.instruments.length===0?t.push("instruments \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.instruments.forEach((e,s)=>{(!Array.isArray(e)||e.some(i=>typeof i!="number"||!Number.isFinite(i)))&&t.push(`instruments[${s}] \u5FC5\u987B\u662F\u6709\u9650\u6570\u5B57\u6570\u7EC4\uFF08ZzFX \u53C2\u6570\u5305\uFF09`)}),!Array.isArray(n.patterns)||n.patterns.length===0?t.push("patterns \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.patterns.forEach((e,s)=>{if(!Array.isArray(e)||e.length===0){t.push(`patterns[${s}] \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4\uFF08\u81F3\u5C11\u4E00\u4E2A\u58F0\u90E8\u901A\u9053\uFF09`);return}e.forEach((i,o)=>{if(!Array.isArray(i)||i.length<2){t.push(`patterns[${s}][${o}] \u901A\u9053\u81F3\u5C11\u542B [\u4E50\u5668\u7D22\u5F15, \u58F0\u50CF]`);return}if(i.some(c=>typeof c!="number"||!Number.isFinite(c))){t.push(`patterns[${s}][${o}] \u901A\u9053\u5FC5\u987B\u5168\u4E3A\u6709\u9650\u6570\u5B57`);return}let a=i[0]|0;Array.isArray(n.instruments)&&(a<0||a>=n.instruments.length)&&t.push(`patterns[${s}][${o}] \u4E50\u5668\u7D22\u5F15 ${a} \u8D8A\u754C\uFF08instruments \u957F\u5EA6 ${n.instruments.length}\uFF09`);let r=i[1];(r<-1||r>1)&&t.push(`patterns[${s}][${o}] \u58F0\u50CF ${r} \u8D8A\u754C\uFF08\u5E94 -1..+1\uFF09`)})}),!Array.isArray(n.sequence)||n.sequence.length===0?t.push("sequence \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.sequence.forEach((e,s)=>{if(typeof e!="number"||!Number.isInteger(e)){t.push(`sequence[${s}] \u5FC5\u987B\u662F\u6574\u6570 pattern \u7D22\u5F15`);return}Array.isArray(n.patterns)&&(e<0||e>=n.patterns.length)&&t.push(`sequence[${s}] \u7D22\u5F15 ${e} \u8D8A\u754C\uFF08patterns \u957F\u5EA6 ${n.patterns.length}\uFF09`)}),n.bpm!=null&&(typeof n.bpm!="number"||!(n.bpm>0))&&t.push("bpm \u5FC5\u987B\u662F\u6B63\u6570"),{ok:t.length===0,errors:t})}function Se(n){return typeof n!="number"||Number.isNaN(n)||n<0?0:n>1?1:n}function Sl(n,t){switch(n){case"ease-in":return t*t;case"ease-out":return Math.sqrt(t);case"constant":return 1;default:return t}}function pa(n,t){let e=Se(t);return n==null||!Array.isArray(n.voices)?[]:n.voices.map(s=>{let i=String(s&&s.id!=null?s.id:""),o=Array.isArray(s&&s.channelIndices)?s.channelIndices.slice():[],a=typeof s.minIntensity=="number"?Se(s.minIntensity):0,r=typeof s.maxIntensity=="number"?Se(s.maxIntensity):1,c=typeof s.volumeCurve=="string"?s.volumeCurve:"linear",l=typeof s.baseVolume=="number"?Se(s.baseVolume):1;if(er)return{id:i,on:!1,volume:0,channelIndices:o};let u=r-a,h=u<=0?1:(e-a)/u,f=Se(Sl(c,h)*l);return{id:i,on:!0,volume:f,channelIndices:o}})}function ga(n,t,e,s){try{let i=t[0]||[],o=t[1]||i,a=Math.max(i.length,o.length);if(a===0)return null;let c=n.createBuffer(2,a,44100);c.getChannelData(0).set(i),c.getChannelData(1).set(o.length?o:i);let l=n.createBufferSource();l.buffer=c,l.loop=!!s;let u=n.createGain();return u.gain.value=Se(e*.3),l.connect(u),u.connect(n.destination),l.start(),{stop(){try{l.stop()}catch(h){}try{l.disconnect(),u.disconnect()}catch(h){}}}}catch(i){return no("[audio-music] \u53D7\u63A7\u97F3\u9891\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",i),null}}function ya(n){let t=n||{},e=typeof t.masterVolume=="number"?Se(t.masterVolume):1,s=()=>null,i=null,o=null,a={voices:[]},r=1,c=null,l=!1,u=0,h=!1,f=!1;function d(){let S=s();return S==null?(u+=1,h||(to("[audio-music] \u65E0\u53D7\u63A7\u97F3\u9891\u4E0A\u4E0B\u6587\uFF08getAudioContext \u8FD4\u56DE null\uFF09\uFF0C\u5168\u90E8\u53D1\u58F0\u9759\u9ED8 no-op\uFF08\u8BC4\u4F30\u73AF\u5883\u65E0\u58F0\u5361\u65F6\u7684\u5BB9\u9519\u964D\u7EA7\uFF09"),h=!0),null):S}function y(){if(!o||!i)return null;try{let S=typeof o.bpm=="number"&&o.bpm>0?o.bpm:125;return i.synthSong(o.instruments,o.patterns,o.sequence,S)}catch(S){return no("[audio-music] \u66F2\u8C31\u6E32\u67D3\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",S),null}}function x(){let S=pa(a,r);if(S.length===0)return 1;let E=0;for(let A of S)A.on&&(E=Math.max(E,A.volume));return E}function v(S,E){typeof E=="number"&&(r=Se(E));let A=d();if(A==null||!o)return;w();let T=y();if(!T)return;let P=Se(e*x());c=ga(A,T,P,S),l=!!S&&c!=null}function w(){c&&(c.stop(),c=null),l=!1}return{name:"audio-music",version:"1.0.0",dependencies:[],init(S){s=()=>S.getAudioContext();let E=S.getEngine&&S.getEngine();i=E?E.audio.synth:null},dispose(){f||(w(),f=!0)},loadSong(S){let E=vl(S);return E.ok?o={instruments:S.instruments,patterns:S.patterns,sequence:S.sequence,bpm:typeof S.bpm=="number"?S.bpm:125}:to("[audio-music] \u66F2\u8C31\u6821\u9A8C\u5931\u8D25\uFF0C\u672A\u8F7D\u5165\uFF1A"+E.errors.join("\uFF1B")),E},play(S){v(!1,S)},stop(){w()},loop(S){v(!0,S)},setIntensityLayering(S){a=S&&Array.isArray(S.voices)?{voices:S.voices}:{voices:[]}},setIntensity(S){r=Se(S)},resolveVoices(S){return pa(a,S)},playSfx(S){let E=eo[S];if(!E){to("[audio-music] \u672A\u77E5\u97F3\u6548\u9884\u8BBE\uFF1A"+String(S));return}let A=d();if(A!=null)try{let T=i?i.synthSfx(E.params):null;if(!T)return;ga(A,[T,T],e,!1)}catch(T){no("[audio-music] \u97F3\u6548\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8 name="+S,T)}},getPreset(S){return eo[S]},listPresets(){return fa.slice()},probe(){return{hasAudio:s()!=null,hasSong:o!=null,intensity:r,voiceCount:a.voices.length,looping:l,silentNoops:u,presetCount:fa.length}}}}function no(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function to(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var wl="zaomeng.save";function Tl(n){if(typeof TextEncoder!="undefined")return new TextEncoder().encode(n).length;if(typeof Buffer!="undefined"&&typeof Buffer.byteLength=="function")return Buffer.byteLength(n,"utf8");let t=0;for(let e=0;e=55296&&s<=56319?(t+=4,e++):t+=3}return t}function io(){let n=new Map;return{getItem(t){return n.has(t)?n.get(t):null},setItem(t,e){n.set(t,e)},removeItem(t){n.delete(t)},keys(){return Array.from(n.keys())}}}function ma(){if(typeof localStorage=="undefined")throw new Error("[save-progress] createLocalStorageAdapter \u9700\u8981\u5168\u5C40 localStorage\uFF08\u4EC5\u6D4F\u89C8\u5668\u96C6\u6210\u6BB5\u53EF\u7528\uFF09\u3002node/host-dev \u8BF7\u7528\u7F3A\u7701\u5185\u5B58 adapter \u6216 createMemoryAdapter()\u3002");return{getItem(n){return localStorage.getItem(n)},setItem(n,t){localStorage.setItem(n,t)},removeItem(n){localStorage.removeItem(n)},keys(){let n=[];for(let t=0;t0?t.namespace:wl;if(e.indexOf(":")>=0)throw new Error('[save-progress] namespace \u4E0D\u5F97\u542B\u5206\u9694\u7B26 ":"\uFF08\u5F53\u524D="'+e+'"\uFF09');let s=typeof t.maxValueBytes=="number"&&t.maxValueBytes>0?Math.floor(t.maxValueBytes):32768,i=!Al(t.adapter),o=i?io():t.adapter,a=e+":",r=0,c=0,l=!1;function u(d){return typeof d!="string"||d.length===0?a+String(d):a+d}function h(){try{let d=o.keys();return Array.isArray(d)?d.filter(y=>typeof y=="string"&&y.indexOf(a)===0):[]}catch(d){return Qn("[save-progress] adapter.keys() \u5F02\u5E38\uFF0C\u964D\u7EA7\u8FD4\u56DE\u7A7A\u96C6",d),[]}}return{name:"save-progress",version:"1.0.0",dependencies:[],init(d){h()},dispose(){},get(d,y){if(!so(d))return y;let x;try{x=o.getItem(u(d))}catch(v){return Qn("[save-progress] adapter.getItem \u5F02\u5E38\uFF0C\u8FD4\u56DE\u9ED8\u8BA4\u503C key="+d,v),y}if(x==null)return y;try{return JSON.parse(x)}catch{return r+=1,l||(Zn("[save-progress] \u68C0\u6D4B\u5230\u635F\u574F\u5B58\u6863\uFF08\u975E\u6CD5 JSON\uFF09\uFF0C\u5DF2\u5BB9\u9519\u56DE\u9000\u9ED8\u8BA4\u503C key="+d),l=!0),y}},set(d,y){if(!so(d))return Zn("[save-progress] set \u6536\u5230\u975E\u6CD5 key\uFF0C\u62D2\u7EDD\u5199\u5165\uFF1A"+String(d)),!1;let x;try{x=JSON.stringify(y)}catch{return c+=1,Zn("[save-progress] \u503C\u4E0D\u53EF JSON \u5E8F\u5217\u5316\uFF08\u5FAA\u73AF\u5F15\u7528?\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1}if(x===void 0)return c+=1,Zn("[save-progress] \u503C\u5E8F\u5217\u5316\u4E3A undefined\uFF08\u5982\u7EAF undefined/\u51FD\u6570\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1;let v=Tl(x);if(v>s)return c+=1,Zn("[save-progress] \u503C\u8D85\u5B57\u8282\u4E0A\u9650\u62D2\u7EDD\u5199\u5165 key="+d+"\uFF08"+v+" > "+s+" bytes\uFF09"),!1;try{return o.setItem(u(d),x),!0}catch(w){return c+=1,Qn("[save-progress] adapter.setItem \u5F02\u5E38\uFF0C\u5199\u5165\u5931\u8D25 key="+d,w),!1}},remove(d){if(so(d))try{o.removeItem(u(d))}catch(y){Qn("[save-progress] adapter.removeItem \u5F02\u5E38\uFF08\u5DF2\u5FFD\u7565\uFF09key="+d,y)}},clear(){let d=h(),y=0;for(let x of d)try{o.removeItem(x),y+=1}catch(v){Qn("[save-progress] clear \u65F6 removeItem \u5F02\u5E38\uFF08\u5DF2\u8DF3\u8FC7\uFF09fullKey="+x,v)}return y},probe(){return{namespace:e,maxValueBytes:s,usingMemoryAdapter:i,size:h().length,corruptRecoveries:r,rejectedWrites:c}}}}function so(n){return typeof n=="string"&&n.length>0}function Al(n){return!!n&&typeof n.getItem=="function"&&typeof n.setItem=="function"&&typeof n.removeItem=="function"&&typeof n.keys=="function"}function Qn(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function Zn(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var Cl={w:390,h:844};function xa(n){let t=((n&&n.seed)!=null?n.seed:0)>>>0,e=na({cellSize:96}),s=sa(),i=ca({inputBufferMs:260,inputTypes:["pointerdown"]}),o=la({seed:t,maxParticles:600}),a=da({vignette:{enabled:!0,strength:.22}}),r=ya({masterVolume:.8}),c;try{c=ma()}catch(f){console.warn("[generic] localStorage \u4E0D\u53EF\u7528\uFF0C\u5B58\u6863\u9000\u5185\u5B58 adapter\uFF1A"+(f&&f.message)),c=io()}let l=ba({namespace:"zaomeng-generic",adapter:c});return{plugins:{collision:e,physics:s,gamefeel:i,juice:o,palettePost:a,audioMusic:r,save:l},registerOrder:[e,s,i,o,a,l,r],viewport:Cl,buildFactoryOpts:(f,d)=>({runtime:{plugins:d.plugins,bundle:d.bundle,getRealAudioCtx:d.getRealAudioCtx}})}}function ts(n){let t=n||{},e=null,s=null,i=0,o=0,a=[],r=[],c=0,l=0,u="booting",h=null,f=null,d=0,y=0,x=null;function v(L){if(e=L.ctx,s=e.getEngine(),r=E(),A(),A(),u="playing",h=null,c=0,l=0,a.push(e.getInput().on("keydown",w)),a.push(e.getInput().on("pointerdown",_)),s&&s.math&&s.math.lerp(0,1,.5),s&&s.particles)try{s.particles.spawnEmitter({pos:{x:195,y:422},emitRate:5,particleTime:1.2,speed:30,colorStart:{r:.5,g:.8,b:1,a:.3},colorEnd:{r:.2,g:.4,b:.8,a:0}})}catch{}}function w(L){if(u!=="playing")return;let I=L.key;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(I)&&(f=I)}function _(L){u==="gameover"&&S()}function S(){r=E(),A(),A(),u="playing",h=null,c=0,l=0,f=null,d=0}function E(){let L=[];for(let I=0;I<4;I++){L[I]=[];for(let M=0;M<4;M++)L[I][M]={value:0,row:I,col:M,scale:1,merging:!1,newBlock:!1,timeBorn:0}}return L}function A(){let L=[];for(let nt=0;nt<4;nt++)for(let ht=0;ht<4;ht++)r[nt][ht].value===0&&L.push({r:nt,c:ht});if(L.length===0)return!1;let I=L[Math.floor(e.random.next()*L.length)],M=e.random.next()<.9?2:4,B=r[I.r][I.c];return B.value=M,B.newBlock=!0,B.scale=0,B.timeBorn=o,!0}function T(L){if(u!=="playing")return!1;let I=!1,M=r.map(G=>G.map(J=>J.value)),B=[0,1,2,3],nt=[0,1,2,3],ht,xt,dt,vt,Tt,de;L==="up"?(ht=B,xt=nt,dt=(G,J)=>r[G][J],vt=(G,J,Rt)=>r[G][J].value=Rt,Tt=1,de=0):L==="down"?(ht=B.slice().reverse(),xt=nt,dt=(G,J)=>r[G][J],vt=(G,J,Rt)=>r[G][J].value=Rt,Tt=-1,de=0):L==="left"?(ht=B,xt=nt,dt=(G,J)=>r[G][J],vt=(G,J,Rt)=>r[G][J].value=Rt,Tt=0,de=1):L==="right"&&(ht=B,xt=nt.slice().reverse(),dt=(G,J)=>r[G][J],vt=(G,J,Rt)=>r[G][J].value=Rt,Tt=0,de=-1);function Me(G,J,Rt,Ie){let X=[];for(let Y=0;Y0&&X[X.length-1].value===kt.value){let ie=X[X.length-1];if(ie.value*=2,ie.merged=!0,Rt(G[Y].row,G[Y].col,0),c+=ie.value,I=!0,s&&s.particles){let Vt={x:48.75+ie.col*97.5,y:48.75+ie.row*97.5};try{s.particles.spawnEmitter({pos:Vt,count:15,speed:80,particleTime:.4,sizeStart:6,sizeEnd:12,colorStart:{r:1,g:.9,b:.2,a:1},colorEnd:{r:1,g:.5,b:0,a:0}})}catch{}}if(s&&s.audio&&s.audio.synth)try{s.audio.synth.synthSfx([1,.05,330,,,.18,,1.4])}catch{}}else X.push({row:G[Y].row,col:G[Y].col,value:kt.value,merged:!1})}for(let Y=0;Yr[X][Y],(X,Y,kt)=>r[X][Y].value=kt,L)}else for(let G=0;G<4;G++){let J=[];for(let X=0;X<4;X++){let Y=L==="left"?X:3-X;J.push({row:G,col:Y})}Me(J,(X,Y)=>r[X][Y],(X,Y,kt)=>r[X][Y].value=kt,L)}for(let G=0;G<4;G++){for(let J=0;J<4;J++)if(r[G][J].value!==M[G][J]){I=!0;break}if(I)break}return I}function P(L){if(i=e.time.nowMs(),o=i/1e3,d+=L,y=(y+L*5)%360,u!=="playing"){ct();return}if(f){let I=f;if(f=null,T(I)){l++,A();let B=!1;for(let nt=0;nt<4;nt++){for(let ht=0;ht<4;ht++)if(r[nt][ht].value>=2048){B=!0;break}if(B)break}if(B){if(u="gameover",h="win",s&&s.particles)for(let nt=0;nt<3;nt++)try{s.particles.spawnEmitter({pos:{x:195,y:422},count:30,speed:120,particleTime:1,colorStart:{r:1,g:.8,b:0,a:1},colorEnd:{r:1,g:0,b:.5,a:0}})}catch{}if(s&&s.audio&&s.audio.synth)try{s.audio.synth.synthSfx([1,.05,440,.3,.2,.18,.3,1.4])}catch{}return}if(F()&&!bt()){if(u="gameover",h="lose",s&&s.particles)try{s.particles.spawnEmitter({pos:{x:195,y:422},count:40,speed:100,particleTime:.6,colorStart:{r:.8,g:.2,b:.2,a:1},colorEnd:{r:.3,g:0,b:0,a:0}})}catch{}if(s&&s.audio&&s.audio.synth)try{s.audio.synth.synthSfx([1,.1,110,.3,.2,.5,.5,1.4])}catch{}}}}ct()}function F(){for(let L=0;L<4;L++)for(let I=0;I<4;I++)if(r[L][I].value===0)return!1;return!0}function bt(){for(let L=0;L<4;L++)for(let I=0;I<4;I++){let M=r[L][I].value;if(M===0||I<3&&r[L][I+1].value===M||L<3&&r[L+1][I].value===M)return!0}return!1}function ct(){for(let L=0;L<4;L++)for(let I=0;I<4;I++){let M=r[L][I];if(M.newBlock){let B=o-M.timeBorn;B<.2?M.scale=B/.2:(M.scale=1,M.newBlock=!1)}M.merging&&(M.scale=1.1+.1*Math.sin(o*20))}}function gt(L){let I=y;L.fillStyle=`hsl(${I}, 20%, 10%)`,L.fillRect(0,0,390,844);let M=97.5,B=5,nt=0,ht=200;for(let xt=0;xt<4;xt++)for(let dt=0;dt<4;dt++){let vt=nt+dt*(M+B)+B/2,Tt=ht+xt*(M+B)+B/2;L.fillStyle="rgba(255,255,255,0.05)",L.fillRect(vt,Tt,M,M),L.beginPath(),L.roundRect(vt,Tt,M,M,8),L.fill()}for(let xt=0;xt<4;xt++)for(let dt=0;dt<4;dt++){let vt=r[xt][dt];if(vt.value===0)continue;let Tt=nt+dt*(M+B)+B/2,de=ht+xt*(M+B)+B/2,Me=vt.scale||1,G=M*Me,J=Tt+(M-G)/2,Rt=de+(M-G)/2,X={2:"#eee4da",4:"#ede0c8",8:"#f2b179",16:"#f59563",32:"#f67c5f",64:"#f65e3b",128:"#edcf72",256:"#edcc61",512:"#edc850",1024:"#edc53f",2048:"#edc22e"}[vt.value]||"#3c3a32";L.fillStyle=X,L.beginPath(),L.roundRect(J,Rt,G,G,6),L.fill(),L.fillStyle=vt.value<=4?"#776e65":"#f9f6f2",L.font=`bold ${Math.min(36,60*(G/M))}px monospace`,L.textAlign="center",L.textBaseline="middle";let Y=vt.value.toString(),kt=J+G/2,ie=Rt+G/2;L.fillText(Y,kt,ie)}if(L.fillStyle="#f9f6f2",L.font="bold 28px monospace",L.textAlign="center",L.textBaseline="top",L.fillText("2048",195,30),L.font="18px monospace",L.fillText(`Score: ${c}`,195,70),L.fillText(`Moves: ${l}`,195,100),u==="gameover"){L.fillStyle="rgba(0,0,0,0.6)",L.fillRect(0,0,390,844),L.fillStyle="#fff",L.font="bold 36px monospace",L.textBaseline="middle";let xt=h==="win"?"You Win!":"Game Over";L.fillText(xt,195,160),L.font="20px monospace",L.fillText("Tap to restart",195,200)}}function wt(){for(let L of a)try{L.cancel()}catch{}a=[],r=[],c=0,l=0,u="booting"}function Ut(){return{seed:t.seed||"none",state:()=>{let L=[];for(let I=0;I<4;I++){L[I]=[];for(let M=0;M<4;M++)L[I][M]=r[I][M].value}return{phase:u,result:h,score:c,moves:l,board:L}}}}return{init:v,update:P,render:gt,destroy:wt,_forensicsView:Ut}}var pd=ts,gd=ts;async function yd(n){let t=n||{},e=t.engine||await Promise.resolve().then(()=>(Mc(),Dc)),s=(t.seed!=null?t.seed:305441741)>>>0,i=xa({seed:s});return ea({canvas:t.canvas,statusEl:t.statusEl||null,engine:e,seed:s,mode:t.mode||"play",engineMode:"real",viewport:i.viewport,factory:ts,plugins:i.plugins,registerOrder:i.registerOrder,buildFactoryOpts:i.buildFactoryOpts,recHook:t.recHook||null,onReady:t.onReady||null})}return Nc(md);})();
+color = `+this.color),t}renderDebug(t=!0){let e=t?this.isHoverObject()?$a:this.disabled?Za:this.interactive?ir:Qa:Ka;C.drawRect(this.nativePos,this.size,xe,4,e)}click(t=!0){this.onClick(),t&&this.soundClick&&this.soundClick.play()}onUpdate(){}onRender(){}onEnter(){}onLeave(){}onPress(){}onRelease(){}onClick(){}onChange(){}},mi=class extends he{constructor(t,e,s="",i="center",o=C.defaultFont){super(t,e),p(q(s),"ui text must be a string"),p(["left","center","right"].includes(i),"ui text align must be left, center, or right"),p(q(o),"ui text font must be a string"),this.text=s,this.align=i,this.font=o,this.canBeHover=!1,this.color=xe,this.shadowColor=xe,this.gradientColor=void 0,this.lineWidth=0,this.textFitScale=1}render(){super.render();let t=this.getTextSize();C.drawText(this.text,this.nativePos,t,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow,this.shadowColor,this.shadowBlur,this.shadowOffset)}},Do=class extends he{constructor(t,e,s=""){super(t,e),p(q(s),"ui text must be a string"),this.maxLength=0,this.text=s,this.interactive=!0,this.canBeHover=!0}click(){C.keyInputObject=this,this.onClick()}stopEditing(){this.isKeyInputObject()&&(this.soundRelease&&this.soundRelease.play(),C.activeObject=void 0,C.keyInputObject=void 0,this.onChange())}onKeyDown(t){let e=t.code,s=t.key;e==="Backspace"?this.text=this.text.slice(0,-1):e==="Enter"||e==="Escape"?this.stopEditing():s.length===1&&(!this.maxLength||this.text.lengththis.size.y,s=e?this.size.y:this.size.x,i=e?this.size.x:this.size.y,o=e?this.nativePos.x:this.nativePos.y,a=i-s,r=o-a/2,c=o+a/2,l=C.screenToNative(Ht);this.value=e?Ut(l.x,r,c):Ut(l.y,c,r)}else if(this.isNavigationObject()){let e=C.getNavigationOtherDirection();C.navigationTimer.active()||(this.value=z(this.value+e*.01))}this.value===t||this.onChange()}render(){super.render();let t=this.size.x>this.size.y,e=t?this.size.x:this.size.y,s=t?this.size.y:this.size.x;if(this.fillMode){let o=st(s,this.cornerRadius*2),a=$t(o,e,this.value),r=(a-e)*(t?.5:-.5),c=this.nativePos.add(t?b(r,0):b(0,r)),l=this.disabled?this.disabledColor:this.handleColor,u=t?b(a,this.size.y):b(this.size.x,a);C.drawRect(c,u,l,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}else{let o=z(t?this.value:1-this.value),a=(e-s)*(o-.5),r=this.nativePos.add(t?b(a,0):b(0,a)),c=this.disabled?this.disabledColor:this.handleColor,l=b(s);C.drawRect(r,l,c,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}let i=this.getTextSize();C.drawText(this.text,this.nativePos,i,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow)}navigatePressed(){this.value=this.value?0:1,this.onChange(),this.onRelease(),super.navigatePressed()}},Go=class extends he{constructor(t,e,s,i=!1,o=!1,a=1){super(t,e||b()),p(q(s),"video src must be a string"),p(R(a),"video volume must be a number"),this.color=at,this.cornerRadius=0,this.volume=a,this.video=document.createElement("video"),this.video.loop=o,this.video.volume=z(a*Sn),this.video.muted=!Qt,this.video.style.display="none",this.video.src=s,document.body.appendChild(this.video),i&&this.play()}async play(){try{await this.video.play()}catch{}}pause(){this.video.pause()}stop(){this.video.pause(),this.video.currentTime=0}isLoading(){return this.video.readyState=1,"ui layout columns must be a number >= 1"),p(R(s),"ui layout gap must be a number"),p(R(i),"ui layout padding must be a number"),this.columns=e,this.gap=s,this.padding=i,o&&(this.color=xe,this.gradientColor=void 0,this.lineWidth=0,this.shadowColor=xe),this.relayout()}addChild(t){return super.addChild(t),this.relayout(),t}removeChild(t){super.removeChild(t),this.relayout()}relayout(){let t=this.children.length;if(!t){this.size=b(this.padding*2);return}let e=this.columns,s=cs(t/e),i=new Array(e).fill(0),o=new Array(s).fill(0);for(let f=0;f=0&&m.objects.splice(t,1),super.destroy()}updatePhysics(){}render(){this.tileInfo?super.render():this.drawFixtures(this.color,this.lineColor,this.lineWidth)}renderDebugInfo(){let t=!this.getIsAwake(),e=this.getBodyType()===m.bodyTypeStatic,s=V(t?1:0,t?1:0,e?1:0,.5);this.drawFixtures(s)}drawFixtures(t=H,e=at,s=.1,i,o){this.getFixtureList().forEach(a=>{m.castShapeObject(a.GetShape()).GetType()!==m.instance.b2Shape.e_edge&&m.drawFixture(a,this.pos,this.angle,t,e,s,i,o)}),this.edgeLists.forEach(a=>go(a,s,e,!1,this.pos,this.angle)),this.edgeLoops.forEach(a=>go(a,s,e,!0,this.pos,this.angle))}beginContact(t){}endContact(t){}addShape(t,e=1,s=.2,i=0,o=!1){p(R(e),"density must be a number"),p(R(s),"friction must be a number"),p(R(i),"restitution must be a number");let a=new m.instance.b2FixtureDef;return a.set_shape(t),a.set_density(e),a.set_friction(s),a.set_restitution(i),a.set_isSensor(o),this.body.CreateFixture(a)}addBox(t=b(1),e=b(),s=0,i,o,a,r){p(O(t),"size must be a Vector2"),p(t.x>0&&t.y>0,"size must be positive"),p(O(e),"offset must be a Vector2"),p(R(s),"angle must be a number");let c=new m.instance.b2PolygonShape;return c.SetAsBox(t.x/2,t.y/2,m.vec2dTo(e),-s),this.addShape(c,i,o,a,r)}addPoly(t,e,s,i,o){p(me(t),"points must be an array");function a(c){p(3<=c.length&&c.length<=8);let l=m.instance._malloc(c.length*8);for(let f=0,d=0;f>2]=c[f].x,d+=4,m.instance.HEAPF32[l+d>>2]=c[f].y,d+=4;let u=m.instance.wrapPointer(l,m.instance.b2Vec2),h=new m.instance.b2PolygonShape;return h.Set(u,c.length),m.instance._free(l),h}let r=a(t);return this.addShape(r,e,s,i,o)}addRegularPoly(t=1,e=8,s,i,o,a){p(R(t)&&t>0,"diameter must be a positive number"),p(R(e)&&e>2,"sides must be a positive number greater than 2");let r=[],c=t/2;for(let l=e;l--;)r.push(b(c,0).rotate((l+.5)/e*Q*2));return this.addPoly(r,s,i,o,a)}addRandomPoly(t=1,e,s,i,o){p(R(t)&&t>0,"diameter must be a positive number");let a=sr(3,9),r=[],c=t/2;for(let l=a;l--;)r.push(b(yt(c/2,c*1.5),0).rotate(l/a*Q*2));return this.addPoly(r,e,s,i,o)}addCircle(t=1,e=b(),s,i,o,a){p(R(t)&&t>0,"diameter must be a positive number"),p(O(e),"offset must be a Vector2");let r=new m.instance.b2CircleShape;return r.set_m_p(m.vec2dTo(e)),r.set_m_radius(t/2),this.addShape(r,s,i,o,a)}addEdge(t,e,s,i,o,a){p(O(t),"point1 must be a Vector2"),p(O(e),"point2 must be a Vector2");let r=new m.instance.b2EdgeShape;return r.Set(m.vec2dTo(t),m.vec2dTo(e)),this.addShape(r,s,i,o,a)}addEdgeList(t,e,s,i,o){p(me(t),"points must be an array");let a=[],r=[];for(let c=0;ct[ce(l,t.length)];for(let l=0;lthis.destroyFixture(t))}getCenterOfMass(){return m.vec2From(this.body.GetWorldCenter())}getLinearVelocity(){return m.vec2From(this.body.GetLinearVelocity())}getAngularVelocity(){return this.body.GetAngularVelocity()}getMass(){return this.body.GetMass()}getInertia(){return this.body.GetInertia()}getIsAwake(){return this.body.IsAwake()}getBodyType(){return this.body.GetType()}getSpeed(){return this.getLinearVelocity().length()}setTransform(t,e){this.pos=t,this.angle=e,this.body.SetTransform(m.vec2dTo(t),-e)}setPosition(t){this.setTransform(t,this.body.GetAngle())}setAngle(t){this.setTransform(m.vec2From(this.body.GetPosition()),t)}setLinearVelocity(t){this.body.SetLinearVelocity(m.vec2dTo(t))}setAngularVelocity(t){this.body.SetAngularVelocity(t)}setLinearDamping(t){this.body.SetLinearDamping(t)}setAngularDamping(t){this.body.SetAngularDamping(t)}setGravityScale(t=1){this.body.SetGravityScale(this.gravityScale=t)}setBullet(t=!0){this.body.SetBullet(t)}setAwake(t=!0){this.body.SetAwake(t)}setBodyType(t){this.body.SetType(t)}setSleepingAllowed(t=!0){this.body.SetSleepingAllowed(t)}setFixedRotation(t=!0){this.body.SetFixedRotation(t)}setCenterOfMass(t){this.setMassData(t)}setMass(t){this.setMassData(void 0,t)}setMomentOfInertia(t){this.setMassData(void 0,void 0,t)}resetMassData(){this.body.ResetMassData()}setMassData(t,e,s){let i=new m.instance.b2MassData;this.body.GetMassData(i),t!==void 0&&i.set_center(m.vec2dTo(t)),e!==void 0&&i.set_mass(e),s!==void 0&&i.set_I(s),this.body.SetMassData(i)}setFilterData(t=0,e=0,s=0){this.getFixtureList().forEach(i=>{let o=i.GetFilterData();o.set_categoryBits(t),o.set_maskBits(65535&~e),o.set_groupIndex(s)})}setSensor(t=!0){this.getFixtureList().forEach(e=>e.SetSensor(t))}applyForce(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyForce(m.vec2dTo(t),m.vec2dTo(e))}applyAcceleration(t,e){e||(e=this.getCenterOfMass()),this.setAwake();let s=t.scale(this.getMass());this.body.ApplyLinearImpulse(m.vec2dTo(s),m.vec2dTo(e))}applyImpulse(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyLinearImpulse(m.vec2dTo(t),m.vec2dTo(e))}applyTorque(t){this.setAwake(),this.body.ApplyTorque(t)}applyAngularAcceleration(t){this.setAwake(),this.body.ApplyAngularImpulse(t*this.getInertia())}applyAngularImpulse(t){this.setAwake(),this.body.ApplyAngularImpulse(t)}hasFixtures(){return!m.isNull(this.body.GetFixtureList())}getFixtureList(){let t=[];for(let e=this.body.GetFixtureList();!m.isNull(e);)t.push(e),e=e.GetNext();return t}hasJoints(){return!m.isNull(this.body.GetJointList())}getJointList(){let t=[];for(let e=this.body.GetJointList();!m.isNull(e);)t.push(e),e=e.get_next();return t}},bi=class extends Cs{constructor(t,e,s,i=0,o,a=0){let r=m.bodyTypeStatic;super(t,e,s,i,o,r,a)}},jo=class extends Cs{constructor(t,e,s,i=0,o,a=0){let r=m.bodyTypeKinematic;super(t,e,s,i,o,r,a)}},Bo=class extends bi{constructor(t){p(t instanceof bs,"tileLayer must be a TileCollisionLayer"),super(t.pos,t.size),this.tileLayer=t,this.addChild(t)}render(){}buildCollision(t=.2,e=0){this.destroyAllFixtures(),this.pos=this.tileLayer.pos.copy(),this.size=this.tileLayer.size.copy();let s=[],i=(a,r)=>a+r*this.size.x,o=(a,r)=>!s[i(a,r)]&&this.tileLayer.getCollisionData(b(a,r))>0;for(let a=0;ai.fractiono.pos.distanceSquared(t)0,"Tween duration must be > 0"),this.callback=t,this.start=e,this.end=s,this.duration=i,this.life=i,this.ease=o.ease||Ti.LINEAR,this.useRealTime=!!o.useRealTime,this.paused=!!o.paused,this.thenCallback=void 0,this.loopRemaining=0,ee.push(this),t(this.interp(i))}setEase(t){return this.ease=t,this}then(t){return this.thenCallback=t,this.loopRemaining=0,this}loop(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Pc(this),this}pingPong(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Lc(this),this}pause(){this.paused=!0}resume(){this.paused=!1}restart(){this.life=this.duration,this.paused=!1,ee.indexOf(this)<0&&ee.push(this),this.callback(this.interp(this.duration))}isActive(){return!this.paused&&ee.indexOf(this)>=0}getPercent(){return Ut(this.duration-this.life,0,this.duration)}getValue(){return this.interp(this.life)}interp(t){let e=this.ease((this.duration-t)/this.duration);return Pa(this.start)?this.start.lerp(this.end,e):this.start+(this.end-this.start)*e}stop(){let t=ee.indexOf(this);t>=0&&ee.splice(t,1),this.thenCallback=void 0}},Ti={LINEAR:n=>n,POWER:n=>t=>t**n,SINE:n=>1-ht(n*(Q/2)),CIRC:n=>1-(1-n*n)**.5,EXPO:n=>n===0?0:2**(10*n-10),BACK:n=>n*n*(2.70158*n-1.70158),ELASTIC:n=>n===0?0:n===1?1:-(2**(10*n-10))*rt((37-40*n)*Q/6),SPRING:n=>1-(rt(Q*(1-n)*(.2+2.5*(1-n)**3))*n**2.2+(1-n))*(1+1.2*n),BOUNCE:n=>{let t=1-n,e;return t<4/11?e=7.5625*t*t:t<8/11?e=7.5625*(t-=6/11)*t+.75:t<10/11?e=7.5625*(t-=9/11)*t+.9375:e=7.5625*(t-=10.5/11)*t+.984375,1-e},IN:n=>n,OUT:n=>t=>1-n(1-t),IN_OUT:n=>Ti.PIECEWISE(n,Ti.OUT(n)),PIECEWISE:(...n)=>{let t=n.length;return e=>{let s=e*t-1e-9>>0;return(n[s]((e-s/t)*t)+s)/t}},BEZIER:(n,t,e,s)=>{let i=o=>{let a=1-o,r=3*a*a*o,c=3*a*o*o,l=o**3;return[r*n+c*e+l,r*t+c*s+l]};return o=>{let a=0,r=1;for(let c=0;c<128;c++){let l=(a+r)/2,[u,h]=i(l);if(ot(u-o)<1e-5)return h;u=this.size.x||e>=this.size.y?null:this.nodes[t+e*this.size.x]}worldToTile(t){let e=this.tileLayer?this.tileLayer.pos.x:0,s=this.tileLayer?this.tileLayer.pos.y:0;return b(Pt(t.x-e),Pt(t.y-s))}tileToWorld(t,e){let s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;return b(t+.5+s,e+.5+i)}buildNodeData(){let t=this.size.x,e=this.size.y,s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;for(let o=0;o0&&(c?l>0&&Ct(r.posWorld,ao,V(1,0,0,st(.2,l*.05)),this.debugTime):Ct(r.posWorld,ao,V(1,0,0,.25),this.debugTime))}}aStarSearch(t,e){p(t&&e,"aStarSearch needs both endpoints"),p(t!==e,"aStarSearch: start and end must differ \u2014 caller should handle trivial case"),p(t.walkable&&e.walkable,"aStarSearch: endpoints must be walkable");let s=[t];t.isOpen=!0;let i=0;for(;s.length>0;){let o=0,a=s[0].f;for(let c=1;cthis.maxLoop)break;r.isOpen=!1,s.splice(o,1),r.isClosed=!0,this.debug&&this.debugTime>0&&Ct(r.posWorld,ao,V(1,1,1,.05),this.debugTime);for(let c=-1;c<=1;++c)for(let l=-1;l<=1;++l){if(l===0&&c===0)continue;let u=this.getNode(r.pos.x+l,r.pos.y+c);if(!u||!u.walkable||u.isClosed)continue;let h=1;if(l!==0&&c!==0){let v=this.getNode(r.pos.x+l,r.pos.y);if(!v||!v.walkable)continue;let w=this.getNode(r.pos.x,r.pos.y+c);if(!w||!w.walkable)continue;h=fd}let f=r.g+h+u.cost;if(!u.isOpen)u.isOpen=!0,s.push(u);else if(f>=u.g)continue;u.parent=r,u.g=f;let d=ot(e.pos.x-u.pos.x),y=ot(e.pos.y-u.pos.y),x=tt(d,y)+(Math.SQRT2-1)*st(d,y);u.f=u.g+x*this.heuristicWeight}}return e.parent!==null}getNearestClearNode(t,e=10,s=!0){p(O(t),"worldPos must be a Vector2"),s&&this.buildNodeData();let i=this.tileLayer?this.tileLayer.pos.x:0,o=this.tileLayer?this.tileLayer.pos.y:0,a=Pt(t.x-i),r=Pt(t.y-o);for(let c=0;c<=e;++c){let l=null,u=0;for(let h=-c;h<=c;++h)for(let f=-c;f<=c;++f){if(c>0&&ot(f)!==c&&ot(h)!==c)continue;let d=this.getNode(a+f,r+h);if(!d||!d.isClear())continue;let y=d.posWorld.x-t.x,x=d.posWorld.y-t.y,v=y*y+x*x;(!l||v0&&Xt(i.posWorld,.3,V(.5,0,.5,.5),this.debugTime),t.splice(e,1),e=tt(1,e-1);continue}else if(c===2){this.debug&&this.debugTime>0&&Xt(i.posWorld,.3,V(1,0,0,.5),this.debugTime);let d,y;s.pos.y===i.pos.y&&o.pos.x===i.pos.x?(d=s.pos.x,y=o.pos.y):(d=o.pos.x,y=s.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t.splice(e,1),e=tt(1,e-1);continue}}else if(c===5){this.debug&&this.debugTime>0&&Xt(i.posWorld,.3,V(1,1,0,.5),this.debugTime);let d=e>=2?t[e-2]:s,y,x,v,w;l===0||h===0?(y=o.pos.x,x=i.pos.y,v=s.pos.x,w=i.pos.y):(y=i.pos.x,x=o.pos.y,v=i.pos.x,w=s.pos.y);let _=y-d.pos.x,S=x-d.pos.y,E=v-d.pos.x,A=w-d.pos.y,T=_*_+S*S,P=E*E+A*A,F=T0&&Xt(i.posWorld,.3,V(0,1,0,.5),this.debugTime),l===h&&u===f){++e;continue}else{let d,y;s.pos.y===o.pos.y?(d=i.pos.x,y=s.pos.y):(d=s.pos.x,y=i.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t[e]=x,e=tt(1,e-1);continue}}++e}}smoothPathStringPull(t){if(t.length<=2)return;for(let i of t)if(!i.isClear())return;let e=t.slice();t.length=0,t.push(e[0]);let s=0;for(let i=1;i0&&Ee(o.posWorld,t[t.length-1].posWorld,V(0,0,1,.3),.02,this.debugTime);continue}for(;s=1;--e){let s=t[e-1],i=t[e],o=t[e+1];(i.pos.x-s.pos.x)*(o.pos.y-s.pos.y)===(i.pos.y-s.pos.y)*(o.pos.x-s.pos.x)&&t.splice(e,1)}}isNodeClear(t,e){let s=this.getNode(t,e);return s!==null&&s.isClear()}isLineClear(t,e){p(O(t)&&O(e),"isLineClear needs Vector2 endpoints"),p(this.isNodeClear(t.x,t.y)&&this.isNodeClear(e.x,e.y),"isLineClear endpoints must be in-bounds and clear");let s=e.x-t.x,i=e.y-t.y,o=ot(s),a=ot(i),r=ae(s),c=ae(i),l=t.x,u=t.y;if(a===o){for(;l!==e.x;){if(l!==t.x&&(!this.isNodeClear(l,u)||!this.isNodeClear(l,u-c))||!this.isNodeClear(l,u+c))return!1;l+=r,u+=c}if(!this.isNodeClear(e.x,e.y-c))return!1}else if(ar.posWorld.copy());if(this.debug&&this.debugTime>0&&a.length>0){for(let r=1;rpd,bootGameHost:()=>yd,default:()=>gd});var ks=class{constructor(t){this._state=(t==null?2654435769:t)>>>0}next(){this._state=this._state+1831565813>>>0;let t=this._state;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}range(t,e){return t+this.next()*(e-t)}reseed(t){this._state=(t==null?2654435769:t)>>>0}},Ni=class{constructor(t){this._clock=t||Jc(),this._origin=this._clock()}nowMs(){return this._clock()}elapsedMs(){return this._clock()-this._origin}},zi=class{constructor(t){this._time=t,this._subs=new Map}sourceFor(t){let e=this,s=t==null?null:t;return{on(i,o){if(e._assertType(i),typeof o!="function")throw new Error("[HostDevInputBridge] on \u7684 handler \u5FC5\u987B\u662F\u51FD\u6570");let a=e._subs.get(i)||[],r={handler:o,scope:s};return a.push(r),e._subs.set(i,a),{cancel(){let c=e._subs.get(i);if(!c)return;let l=c.indexOf(r);l>=0&&c.splice(l,1)}}},off(i,o){e._assertType(i);let a=e._subs.get(i);if(!a)return;let r=a.findIndex(c=>c.handler===o&&c.scope===s);r>=0&&a.splice(r,1)}}}_emit(t,e){this._assertType(t);let s=e||{},i={type:t,x:typeof s.x=="number"?s.x:0,y:typeof s.y=="number"?s.y:0,key:typeof s.key=="string"?s.key:"",tMs:this._time.nowMs()},o=this._subs.get(t);if(!o||o.length===0)return;let a=o.slice();for(let r of a)try{r.handler(i)}catch(c){Ye("[host-dev input] \u8F93\u5165 handler \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09type="+t,c)}}disposeScope(t){if(t==null)return 0;let e=0;for(let[s,i]of this._subs){let o=i.filter(a=>a.scope!==t);e+=i.length-o.length,o.length===0?this._subs.delete(s):this._subs.set(s,o)}return e}_subscriptionCount(){let t=0;for(let e of this._subs.values())t+=e.length;return t}_assertType(t){if(!Ji.has(t))throw new Error("[HostDevInputBridge] \u975E\u6CD5\u8F93\u5165\u4E8B\u4EF6\u7C7B\u578B\uFF1A"+String(t)+"\uFF08\u4EC5\u652F\u6301 "+Array.from(Ji).join("/")+"\uFF09")}},Ji=new Set(["pointerdown","pointermove","pointerup","keydown","keyup"]);function Hr(n){let t=n||{},e=new Ni(t.clock),s=new ks(t.seed),i=t.seed==null?2654435769:t.seed>>>0,o=new zi(e),a=typeof t.audioFactory=="function"?t.audioFactory:null,r=null,c=!1,l=typeof t.engineFactory=="function"?t.engineFactory:null,u=null,h=!1,f=new Map,d=0,y=0;function x(){if(r)return r;if(!a)return c||(Vi("[host-dev audio] \u672A\u6CE8\u5165 audioFactory\uFF0CgetAudioContext \u8FD4\u56DE null\uFF08P6 \u987B\u5BB9\u9519\u964D\u7EA7\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u5DE5\u5382\uFF09"),c=!0),null;try{r=a()}catch(E){Ye("[host-dev audio] audioFactory \u629B\u9519\uFF0CgetAudioContext \u964D\u7EA7\u8FD4\u56DE null",E),r=null}return r}function v(){if(u)return u;if(!l)return h||(Vi("[host-dev engine] \u672A\u6CE8\u5165 engineFactory\uFF0CgetEngine \u8FD4\u56DE null\uFF08\u63D2\u4EF6\u987B\u5BB9\u9519\u964D\u7EA7\uFF1A\u7C92\u5B50\u9000\u53D7\u63A7\u9762\u81EA\u7BA1/\u5408\u6210\u6838\u9000 vendored/\u6570\u5B66\u9000\u5185\u7F6E\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u80CC\u4E66\uFF09"),h=!0),null;try{u=l()}catch(E){Ye("[host-dev engine] engineFactory \u629B\u9519\uFF0CgetEngine \u964D\u7EA7\u8FD4\u56DE null",E),u=null}return u}function w(E,A){return{getContext2d(){return t.context2d==null?null:t.context2d},onFrame(P){let F=d++;return f.set(F,P),{cancel(){f.delete(F)}}},getInput(){return o.sourceFor(E)},getAudioContext(){return x()},getEngine(){return v()},time:e,random:A}}let _=w(null,s),S={context:_,tick(E){y+=1;let A=Array.from(f.values());for(let T of A)try{T(E,y)}catch(P){Ye("[host-dev tick] \u5E27\u56DE\u8C03\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09frame="+y,P)}},frameCount(){return y},inputBridge:o,deriveContextFor(E,A){let T=zc(i,E),P=new ks(T);return w(A==null?E:A,P)}};return Object.defineProperty(_,Ui,{value:S,enumerable:!1,writable:!1,configurable:!1}),S}var Ui=Symbol("zaomeng.coreProtocol.contextBundle"),Gs=class{constructor(){this._plugins=new Map,this._initOrder=[],this._initErrors=[],this._phase="idle",this._disposed=!1,this._context=void 0,this._pluginContexts=new Map}register(t){if(!t||typeof t!="object")throw new Error("[PluginRegistry] register \u9700\u8981\u4E00\u4E2A\u63D2\u4EF6\u5BF9\u8C61");if(typeof t.name!="string"||t.name.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6\u7F3A\u5C11\u5408\u6CD5 name");if(typeof t.version!="string"||t.version.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11\u5408\u6CD5 version");if(typeof t.init!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11 init \u51FD\u6570");if(t.dispose!=null&&typeof t.dispose!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7684 dispose \u5FC5\u987B\u662F\u51FD\u6570\u6216\u7701\u7565");if(this._plugins.has(t.name))throw new Error("[PluginRegistry] \u63D2\u4EF6\u91CD\u540D\u62D2\u7EDD\uFF1A"+t.name+" \u5DF2\u6CE8\u518C");return this._plugins.set(t.name,t),this}has(t){return this._plugins.has(t)}get(t){return this._plugins.get(t)}list(){return Array.from(this._plugins.keys())}initAll(){if(this._phase==="initialized")return Vi("[PluginRegistry] initAll \u91CD\u590D\u8C03\u7528\uFF0C\u5DF2\u5FFD\u7565\uFF08\u5DF2\u5904\u4E8E initialized\uFF09"),this._initResult();if(this._phase==="disposed")throw new Error("[PluginRegistry] \u5DF2 dispose \u7684\u6CE8\u518C\u5668\u4E0D\u53EF\u518D initAll");if(this._context==null)throw new Error("[PluginRegistry] \u672A\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\uFF1A\u8BF7\u5728 initAll() \u4E4B\u524D\u8C03\u7528 useContext(context)\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context); reg.initAll();\uFF09");for(let[t,e]of this._plugins){let s=this._missingDeps(e);if(s.length>0){let o=new Error("[PluginRegistry] \u63D2\u4EF6 "+t+" \u4F9D\u8D56\u7F3A\u5931\uFF1A"+s.join(", ")+"\uFF08\u672A\u6CE8\u518C\uFF09");this._initErrors.push({name:t,error:o}),Ye("[PluginRegistry] \u8DF3\u8FC7 init\uFF08\u4F9D\u8D56\u7F3A\u5931\uFF0C\u5DF2\u9694\u79BB\uFF09\uFF1A"+t,o);continue}let i=this._contextFor(t);try{e.init(i),this._initOrder.push(t)}catch(o){let a=o instanceof Error?o:new Error(String(o));this._initErrors.push({name:t,error:a}),Ye("[PluginRegistry] \u63D2\u4EF6 init \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF0C\u4E0D\u8FDE\u5750\uFF09\uFF1A"+t,a)}}return this._phase="initialized",this._initResult()}_contextFor(t){let e=this._pluginContexts.get(t);if(e)return e;let s=this._context&&this._context[Ui],i;return s&&typeof s.deriveContextFor=="function"?i=s.deriveContextFor(t,t):i=this._context,this._pluginContexts.set(t,i),i}disposeAll(){if(this._disposed)return{disposed:[],errors:[]};let t=[],e=[],s=this._context&&this._context[Ui],i=s&&s.inputBridge;for(let o=this._initOrder.length-1;o>=0;o--){let a=this._initOrder[o],r=this._plugins.get(a);if(r&&typeof r.dispose=="function")try{r.dispose(),t.push(a)}catch(c){let l=c instanceof Error?c:new Error(String(c));e.push({name:a,error:l}),Ye("[PluginRegistry] \u63D2\u4EF6 dispose \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+a,l)}if(i&&typeof i.disposeScope=="function")try{i.disposeScope(a)}catch(c){Ye("[PluginRegistry] \u56DE\u6536\u63D2\u4EF6\u8F93\u5165\u8BA2\u9605\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+a,c)}}return this._disposed=!0,this._phase="disposed",{disposed:t,errors:e}}useContext(t){if(this._phase!=="idle")throw new Error("[PluginRegistry] useContext \u5FC5\u987B\u5728 initAll() \u4E4B\u524D\u8C03\u7528\uFF08\u5F53\u524D\u9636\u6BB5\uFF1A"+this._phase+"\uFF09\u3002\u8BF7\u5728\u4EFB\u4F55 initAll/disposeAll \u4E4B\u524D\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\u3002");if(t==null||typeof t!="object")throw new Error("[PluginRegistry] useContext \u9700\u8981\u4E00\u4E2A\u53D7\u63A7\u4E0A\u4E0B\u6587\u5BF9\u8C61\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context);\uFF09");return this._context=t,this}_missingDeps(t){return!Array.isArray(t.dependencies)||t.dependencies.length===0?[]:t.dependencies.filter(e=>!this._plugins.has(e))}_initResult(){return{ok:this._initErrors.length===0,initialized:this._initOrder.slice(),errors:this._initErrors.slice()}}};function zc(n,t){let e=2166136261,s=16777619,i=n>>>0;for(let a=0;a<32;a+=8){let r=i>>>a&255;e^=r,e=Math.imul(e,s)>>>0}let o=String(t);for(let a=0;a>>0,e^=r>>>8&255,e=Math.imul(e,s)>>>0}return e>>>0}function Jc(){if(typeof globalThis!="undefined"&&globalThis.performance&&typeof globalThis.performance.now=="function")return()=>globalThis.performance.now();if(typeof process!="undefined"&&process.hrtime&&typeof process.hrtime.bigint=="function"){let n=process.hrtime.bigint();return()=>Number(process.hrtime.bigint()-n)/1e6}return()=>Date.now()}function Ye(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function Vi(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var xd=Object.freeze(Array.from(Ji)),Xr="core-protocol-v0";var Yr=Object.freeze(["t_boot","t_plugins_ready","t_game_init","t_first_paint","t_input_bound","t_game_start"]),Wi=Yr.reduce((n,t,e)=>(n[t]=e,n),Object.create(null)),Uc=new Set(Yr);function qi(n){let t=2166136261;for(let e=0;e>>0).toString(16).padStart(8,"0")}var $r=qi("runtime-probe::seed::v1");function Fs(n){return n===null||typeof n!="object"?JSON.stringify(n):Array.isArray(n)?"["+n.map(Fs).join(",")+"]":"{"+Object.keys(n).sort().map(e=>JSON.stringify(e)+":"+Fs(n[e])).join(",")+"}"}function Kr(n){let t=Fs(n.extra==null?null:n.extra),e=Fs(Array.isArray(n.pluginSet)?n.pluginSet:[]);return["seq="+n.seq,"anchor="+n.anchor,"tMono="+n.tMono,"buildSha="+(n.buildSha||""),"pluginSet="+e,"extra="+t].join("|")}function Vc(n){return Math.round(n*1e3)/1e3}function Wc(n){if(!Array.isArray(n))return{ok:!1,reason:"records_not_array"};let t=$r,e=-1;for(let s=0;stypeof E=="string").slice().sort():[],i=typeof t.sink=="function"?t.sink:null,o=t.autoBoot!==!1,a=typeof t.inputAnchorType=="string"?t.inputAnchorType:"pointerdown",r=()=>0,c=!1,l=0,u=$r,h=[],f=new Set,d=-1,y=null,x=!1,v=!1,w=!1;function _(E,A){let T=null;if(!Uc.has(E))T="unknown_anchor";else{f.has(E)&&(T=T?T+";duplicate_anchor":"duplicate_anchor");let F=Wi[E];FE.time.nowMs(),c=!0,o&&!v&&_("t_boot",{auto:!0}),y=E.getInput().on(a,A=>{x||(x=!0,_("t_input_bound",{firstInput:!0,type:A.type}))}),_("t_input_bound",{stage:"registered",type:a})},dispose(){w||(y&&(y.cancel(),y=null),w=!0)},mark:_,getRecords(){return h.map(E=>({...E}))},toJSONL(){return h.map(E=>JSON.stringify(E)).join(`
+`)},verify(){return Wc(h)}}}function qc(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function Zr(n){let t=n.LJS,e=n.engineMath,s=n.engineMode,i=n.recHook||(()=>{});if(s!=="real")return null;let o=e;return{math:{lerp:(r,c,l)=>(i("math.lerp"),o.lerp(r,c,l)),smoothStep:r=>(i("math.smoothStep"),o.smoothStep(r)),easing:Object.fromEntries(Object.keys(o.easing).map(r=>[r,c=>(i("math.easing."+r),o.easing[r](c))]))},particles:{spawnEmitter(r){i("particles.spawnEmitter");let c=t.screenToWorld(t.vec2(r.pos.x,r.pos.y)),l=t.cameraScale,u=r.emitTime!=null?r.emitTime:r.count!=null?1/60:0,h=r.emitRate!=null?r.emitRate:r.count!=null?r.count*60:100,f=(r.speed!=null?r.speed:0)/l/60,d=r.damping!=null?r.damping:1,y=r.colorStart||{r:1,g:1,b:1,a:1},x=r.colorEnd||{r:1,g:1,b:1,a:0},v=t.rgb(y.r,y.g,y.b,y.a),w=t.rgb(x.r,x.g,x.b,x.a),_=new t.ParticleEmitter(c,r.angle!=null?r.angle:0,(r.emitSize!=null?r.emitSize:0)/l,u,h,r.coneAngle!=null?r.coneAngle:Math.PI,void 0,v,v,w,w,r.particleTime!=null?r.particleTime:.5,(r.sizeStart!=null?r.sizeStart:6)/l,(r.sizeEnd!=null?r.sizeEnd:0)/l,f,0,d,1,r.gravityScale!=null?r.gravityScale:0,Math.PI,.1,0,!1,r.additive!=null?r.additive:!1,!0);return{isActive(){return _.isActive()},stop(){_.destroyed||_.destroy(!0)}}}},audio:{synth:{synthSfx:r=>{i("audio.synth.synthSfx");try{return t.zzfxG(...r)}catch(c){return console.error("[host][engine-audio] zzfxG \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(c&&c.message?c.message:c)),null}},synthSong:(r,c,l,u)=>{i("audio.synth.synthSong");try{return t.zzfxM(r,c,l,u)}catch(h){return console.error("[host][engine-audio] zzfxM \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(h&&h.message?h.message:h)),null}}}}}}function fe(n){return n<0?0:n>1?1:n}function ta(n){let t=n.Ease,e=t.POWER(2),s=t.POWER(3),i=t.OUT(e),o=t.IN_OUT(e),a=t.OUT(s),r=t.IN_OUT(s),c=t.OUT(t.BACK),l=t.OUT(t.ELASTIC);return{lerp:(u,h,f)=>n.lerp(u,h,f),smoothStep:u=>n.smoothStep(u),easing:{linear:u=>t.LINEAR(fe(u)),quadIn:u=>e(fe(u)),quadOut:u=>i(fe(u)),quadInOut:u=>o(fe(u)),cubicIn:u=>s(fe(u)),cubicOut:u=>a(fe(u)),cubicInOut:u=>r(fe(u)),backIn:u=>t.BACK(fe(u)),backOut:u=>c(fe(u)),elasticIn:u=>t.ELASTIC(fe(u)),elasticOut:u=>l(fe(u))}}}var $e=2,js=1/60;async function ea(n){let t=n.canvas,e=n.statusEl||null,s=n.engine,i=n.seed>>>0,o=n.mode||"play",a=n.engineMode||"real",r=n.viewport.w,c=n.viewport.h,l=n.factory,u=n.buildFactoryOpts||(()=>{}),h=n.plugins||{},f=n.registerOrder||Object.values(h),d=n.onReady||(()=>{}),y=n.recHook||(()=>{});function x(D){e&&(e.textContent=D)}let v=[];window.addEventListener("error",D=>v.push({type:"error",message:String(D&&D.message||D)})),window.addEventListener("unhandledrejection",D=>v.push({type:"unhandledrejection",message:String(D&&D.reason&&D.reason.message||D&&D.reason||D)}));let w=null,_=!1;function S(){if(!_)return null;if(w)return w;let D=window.AudioContext||window.webkitAudioContext;return D?(w=new D,w):null}let E=0,A=null,T=null,P=null,F=null,bt=[],ct={},gt=null;function wt(D,lt){try{P&&P.mark(D,lt)}catch(re){v.push({type:"mark",message:String(re&&re.message||re)})}}function Vt(){T&&typeof T._refreshChecklist=="function"&&T._refreshChecklist(ct)}async function L(D,lt){A=Hr({context2d:D,seed:i,audioFactory:S,clock:()=>E,engineFactory:()=>Zr({LJS:a==="real"?s:null,engineMath:a==="real"?ta(s):null,engineMode:a,recHook:y})});let re=new Gs;for(let ve of f)re.register(ve);re.useContext(A.context),F=re.initAll(),bt=re.list().concat(["runtime-probe"]),P=Qr({pluginSet:bt,inputAnchorType:"pointerdown",autoBoot:!0});let Gt=A.deriveContextFor("runtime-probe","runtime-probe");wt("t_boot",{by:"game-host",stage:"pre-init",engineMode:a}),wt("t_plugins_ready",{initialized:F.initialized.length,ok:F.ok});let ji=u(A.context,{bundle:A,plugins:h,getRealAudioCtx:()=>w});T=l(ji),await T.init({ctx:A.context,mainContext:D,canvas:lt(),seed:i}),gt=T&&typeof T._forensicsView=="function"?T._forensicsView():null,wt("t_game_init",{hasForensics:!!gt}),M(),wt("t_first_paint",{frame:A.frameCount()});try{P.init(Gt)}catch(ve){v.push({type:"probe-init",message:String(ve&&ve.message||ve)})}wt("t_game_start",{mode:o,engineMode:a}),Vt(),d(dt,{bundle:A,game:T,probe:P,checklist:ct,uncaught:v,pluginSet:bt,initRes:F,getGameForensics:()=>gt,mark:wt,stepOneFrame:M})}let I=null;function M(D){let lt=typeof D=="number"?D:js;T&&(E+=lt*1e3,T.update(lt),a==="stub"&&I&&T.render(I),Vt())}function B(D){for(let lt=0;lt{}),T&&typeof T._onAudioUnlock=="function"&&T._onAudioUnlock()}let dt={seed:i,mode:o,engineMode:a,protocol:Xr,frameCount:()=>A?A.frameCount():0,stepFrames:B,startRaf:()=>Me(),stopRaf:()=>G(),tap(D,lt){et(),A&&(A.inputBridge._emit("pointerdown",{x:D,y:lt}),A.inputBridge._emit("pointerup",{x:D,y:lt}))},do(D){T&&typeof T._handleAction=="function"&&T._handleAction(D)},state:()=>gt?gt.state():{phase:"booting"}};function xt(D){let lt=A.inputBridge;function re(Gt,ji){let ve=D.getBoundingClientRect();return{x:(Gt-ve.left)/ve.width*r,y:(ji-ve.top)/ve.height*c}}D.addEventListener("pointerdown",Gt=>{et(),lt._emit("pointerdown",re(Gt.clientX,Gt.clientY))}),D.addEventListener("pointermove",Gt=>{lt._emit("pointermove",re(Gt.clientX,Gt.clientY))}),D.addEventListener("pointerup",Gt=>{lt._emit("pointerup",re(Gt.clientX,Gt.clientY))}),window.addEventListener("keydown",Gt=>{et(),lt._emit("keydown",{key:Gt.key})}),window.addEventListener("keyup",Gt=>lt._emit("keyup",{key:Gt.key}))}let ft=0,vt=!1,Tt=0;function de(D){if(!vt)return;Tt===0&&(Tt=D);let lt=(D-Tt)/1e3;Tt=D,lt>.05&&(lt=.05),M(lt),ft=window.requestAnimationFrame(de)}function Me(){a==="stub"&&(vt||(vt=!0,Tt=0,ft=window.requestAnimationFrame(de)))}function G(){vt=!1,ft&&window.cancelAnimationFrame(ft),ft=0}function J(D){D.width=r*$e,D.height=c*$e,D.style.width=r+"px",D.style.height=c+"px";let lt=D.getContext("2d",{willReadFrequently:!0});return lt.setTransform($e,0,0,$e,0,0),lt}async function Rt(){let D=J(t);return I=D,await L(D,()=>t),xt(t),o==="evidence"?x(`evidence \u5C31\u7EEA seed=${i} \xB7 \u7528 host \u9A71\u52A8\uFF08stepFrames/tap\uFF09`):(x(`seed=${i} \xB7 \u70B9\u5F00\u59CB\uFF08\u9996\u6B21\u70B9\u51FB\u5F00\u58F0\uFF09`),Me()),dt}let Ie=()=>{},X=()=>{};function Y(){window.__gameHostEngineInitFired=!0}function kt(){Ie()}function oe(){}function Wt(){X()}function Wr(){}async function Ic(D){await L(D,()=>s.mainCanvas),xt(s.mainCanvas),Ie=()=>{T&&(E+=js*1e3,T.update(js))},X=()=>{if(T){D.save(),D.setTransform($e,0,0,$e,0,0);try{D.imageSmoothingEnabled=!1}catch{}T.render(D),D.restore()}},s.mainCanvas&&(s.mainCanvas.id="game-engine"),window.__engine={frame(){return s.frame},time(){return s.time},timeReal(){return s.timeReal},paused(){return s.paused},timeScale(){return s.timeScale},snapshot(){return{frame:s.frame,time:s.time,timeReal:s.timeReal,paused:s.paused,timeScale:s.timeScale}}},x(`engine RAF running \xB7 seed=${i} engine=real`)}if(a!=="real")return await Rt();if(!s){let D="real \u901A\u9053\u672A\u6CE8\u5165\u5F15\u64CE\uFF08opts.engine \u7F3A\u5931\uFF09\uFF1A\u8BF7\u7ECF entry \u5305\u88C5\u5C42\u542F\u52A8\uFF08host \u4E0D\u76F4\u63A5 import \u5F15\u64CE\uFF0CQ4/Option C\uFF09";throw x("ENGINE INJECT MISSING: "+D),new Error(D)}s.setGLEnable(!1),s.setShowSplashScreen(!1),s.setDebugWatermark(!1),s.setCanvasClearColor(s.BLACK),s.setCanvasFixedSize(s.vec2(r*$e,c*$e));let Fi=document.createElement("div");return Fi.id="engine-root",document.body.appendChild(Fi),await s.engineInit(Y,kt,oe,Wt,Wr,[],Fi).then(()=>Ic(s.mainContext)).catch(D=>{throw window.__gameHostBootError=String(D&&D.message||D),x("ENGINE INIT FAILED: "+window.__gameHostBootError),D}),dt}var Hi=class{constructor(t){let e=t||{},s=typeof e.cellSize=="number"&&e.cellSize>0?e.cellSize:64;this._cellSize=s,this._cells=new Map,this._entries=new Map,this._seq=0}get size(){return this._entries.size}_cellRange(t){let e=this._cellSize,s=Math.floor((t.x-t.hw)/e),i=Math.floor((t.x+t.hw)/e),o=Math.floor((t.y-t.hh)/e),a=Math.floor((t.y+t.hh)/e);return{cx0:s,cy0:o,cx1:i,cy1:a}}insert(t,e){this._entries.has(t)&&this.remove(t);let{cx0:s,cy0:i,cx1:o,cy1:a}=this._cellRange(e),r=[];for(let l=i;l<=a;l++)for(let u=s;u<=o;u++){let h=u+","+l,f=this._cells.get(h);f||(f=new Set,this._cells.set(h,f)),f.add(t),r.push(h)}let c={x:e.x,y:e.y,hw:e.hw,hh:e.hh};this._entries.set(t,{id:t,box:c,seq:this._seq++,cells:r})}remove(t){let e=this._entries.get(t);if(!e)return!1;for(let s of e.cells){let i=this._cells.get(s);i&&(i.delete(t),i.size===0&&this._cells.delete(s))}return this._entries.delete(t),!0}query(t){let{cx0:e,cy0:s,cx1:i,cy1:o}=this._cellRange(t),a=new Set;for(let r=s;r<=o;r++)for(let c=e;c<=i;c++){let l=this._cells.get(c+","+r);if(l)for(let u of l)a.add(u)}return this._collect(a)}queryPoint(t,e){let s=this._cellSize,i=Math.floor(t/s),o=Math.floor(e/s),a=this._cells.get(i+","+o);return a?this._collect(new Set(a)):[]}clear(){this._cells.clear(),this._entries.clear(),this._seq=0}_collect(t){let e=[];for(let s of t){let i=this._entries.get(s);i&&e.push(i)}return e.sort((s,i)=>s.seq-i.seq),e.map(s=>({id:s.id,box:s.box}))}};function na(n){let t=n||{},e=new Hi({cellSize:t.cellSize}),s=!1;return{name:"collision",version:"1.0.0",dependencies:[],spatial:e,init(o){},dispose(){s||(e.clear(),s=!0)}}}function sa(n){let t=!1;return{name:"physics-lite",version:"1.0.0",dependencies:[],init(s){},dispose(){t||(t=!0)}}}var Hc=["pointerdown","pointermove","pointerup","keydown","keyup"];function qt(n){return n<0?0:n>1?1:n}var Xc=n=>(n=qt(n),n*n),Yc=n=>(n=qt(n),1-(1-n)*(1-n)),$c=n=>(n=qt(n),n<.5?2*n*n:1-Math.pow(-2*n+2,2)/2),Kc=n=>(n=qt(n),n*n*n),Qc=n=>{n=qt(n);let t=1-n;return 1-t*t*t},Zc=n=>(n=qt(n),n<.5?4*n*n*n:1-Math.pow(-2*n+2,3)/2),ra=2*Math.PI/3,ia=2*Math.PI/4.5,tl=n=>(n=qt(n),n===0?0:n===1?1:-Math.pow(2,10*n-10)*Math.sin((n*10-10.75)*ra)),el=n=>(n=qt(n),n===0?0:n===1?1:Math.pow(2,-10*n)*Math.sin((n*10-.75)*ra)+1),nl=n=>(n=qt(n),n===0?0:n===1?1:n<.5?-(Math.pow(2,20*n-10)*Math.sin((20*n-11.125)*ia))/2:Math.pow(2,-20*n+10)*Math.sin((20*n-11.125)*ia)/2+1),Ns=1.70158,Bs=Ns*1.525,aa=Ns+1,sl=n=>(n=qt(n),aa*n*n*n-Ns*n*n),il=n=>{n=qt(n);let t=n-1;return 1+aa*t*t*t+Ns*t*t},ol=n=>(n=qt(n),n<.5?Math.pow(2*n,2)*((Bs+1)*2*n-Bs)/2:(Math.pow(2*n-2,2)*((Bs+1)*(n*2-2)+Bs)+2)/2),rl=n=>qt(n),oa=Object.freeze({linear:rl,quadIn:Xc,quadOut:Yc,quadInOut:$c,cubicIn:Kc,cubicOut:Qc,cubicInOut:Zc,elasticIn:tl,elasticOut:el,elasticInOut:nl,backIn:sl,backOut:il,backInOut:ol});var al=["linear","quadIn","quadOut","quadInOut","cubicIn","cubicOut","cubicInOut","elasticIn","elasticOut","elasticInOut","backIn","backOut","backInOut"];function cl(n){let t=n&&n.easing;if(!t)return oa;let e=i=>typeof t[i]=="function"?o=>t[i](qt(o)):oa[i],s={};for(let i of al)s[i]=e(i);return Object.freeze(s)}var Xi=class{constructor(t,e,s){let i=s||{};this._time=e,this._windowMs=typeof i.windowMs=="number"&&i.windowMs>0?i.windowMs:120;let o=Array.isArray(i.types)&&i.types.length>0?i.types:Hc;this._records=new Map,this._subs=[],this._disposed=!1;for(let a of o){this._records.set(a,null);let r=t.on(a,c=>{this._records.set(a,c.tMs)});this._subs.push(r)}}consume(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs?(this._records.set(t,null),!0):(this._records.set(t,null),!1)}peek(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs}clear(){for(let t of this._records.keys())this._records.set(t,null)}dispose(){if(!this._disposed){for(let t of this._subs)try{t.cancel()}catch(e){}this._subs=[],this._disposed=!0}}};function ca(n){let t=n||{},e=null,s=null,i=!1;return{name:"gamefeel",version:"1.0.0",dependencies:[],get inputBuffer(){return e},get easing(){return cl(s)},init(a){let r=a.getInput();e=new Xi(r,a.time,{windowMs:t.inputBufferMs,types:t.inputTypes});let c=a.getEngine();s=c?c.math:null},dispose(){i||(e&&(e.dispose(),e=null),s=null,i=!0)}}}function zs(n,t){let e=t<0?0:t>1?1:t;switch(n&&n.kind){case"constant":return n.value;case"linear":return n.from+(n.to-n.from)*e;case"easeInOut":{let s=e*e*(3-2*e);return n.from+(n.to-n.from)*s}case"decay":{let s=n.power==null?2:n.power,i=Math.pow(1-e,s);return n.to+(n.from-n.to)*i}default:return 0}}var ll=Object.freeze({burst:Object.freeze({mode:"burst",count:24,angle:0,spread:Math.PI,speedMin:80,speedMax:160,lifeMin:.4,lifeMax:.8,gravity:0,drag:0,sizeCurve:{kind:"decay",from:6,to:0,power:1.5},alphaCurve:{kind:"linear",from:1,to:0}}),trail:Object.freeze({mode:"continuous",rate:60,angle:Math.PI,spread:.25,speedMin:20,speedMax:50,lifeMin:.2,lifeMax:.5,gravity:0,drag:1.5,sizeCurve:{kind:"easeInOut",from:4,to:0},alphaCurve:{kind:"decay",from:.8,to:0,power:2}}),drift:Object.freeze({mode:"continuous",rate:12,angle:Math.PI/2,spread:.6,speedMin:10,speedMax:30,lifeMin:1.5,lifeMax:3,gravity:8,drag:.5,sizeCurve:{kind:"constant",value:3},alphaCurve:{kind:"decay",from:.7,to:0,power:1}})});function ul(n){let t=ll[n];return t?Yi(t):null}function Yi(n){let t={};for(let e of Object.keys(n)){let s=n[e];t[e]=s&&typeof s=="object"?Yi(s):s}return t}function hl(n,t,e){let s=n.mode==="continuous";return{pos:{x:t,y:e},angle:n.angle,coneAngle:n.spread,emitSize:0,emitTime:s?0:1/60,emitRate:s?n.rate||0:void 0,count:s?void 0:n.count||0,particleTime:(n.lifeMin+n.lifeMax)/2,speed:(n.speedMin+n.speedMax)/2,gravityScale:n.gravity||0,damping:n.drag!=null?1-n.drag/60:1,sizeStart:zs(n.sizeCurve,0),sizeEnd:zs(n.sizeCurve,1),colorStart:{r:1,g:1,b:1,a:zs(n.alphaCurve,0)},colorEnd:{r:1,g:1,b:1,a:zs(n.alphaCurve,1)},additive:!1}}function la(n){let t=n||{},e=null,s=null,i=null,o=new Map,a=0,r={isActive(){return!1},stop(){}},c=0,l=1,u=0,h=0,f=0,d={x:0,y:0,remain:0,dur:0,amplitude:0,frequency:0,_phase:0},y={alpha:0,remain:0,dur:0,peak:0},x={scale:1,remain:0,dur:0,amplitude:0,frequency:0},v=!1;function w(A){if(u>0)if(u-=A,u<=0)u=0,l=1;else{let T=h>0?1-u/h:1;l=f+(1-f)*T}if(d.remain>0)if(d.remain-=A,d.remain<=0)d.remain=0,d.x=0,d.y=0;else{let T=d.remain/d.dur,P=d.amplitude*T;d._phase+=d.frequency*A*Math.PI*2,d.x=Math.sin(d._phase)*P,d.y=Math.cos(d._phase*1.3)*P}if(y.remain>0&&(y.remain-=A,y.remain<=0?(y.remain=0,y.alpha=0):y.alpha=y.peak*(y.remain/y.dur)),x.remain>0)if(x.remain-=A,x.remain<=0)x.remain=0,x.scale=1;else{let T=x.remain/x.dur,P=(1-T)*x.frequency*Math.PI*2;x.scale=1+Math.sin(P)*x.amplitude*T}}function _(A){c+=1,w(A)}function S(A){let T=A!==void 0?A:e?e.getContext2d():null;if(T&&y.alpha>0){T.globalAlpha=y.alpha,T.fillStyle="#ffffff";let P=T.canvas?T.canvas.width:0,F=T.canvas?T.canvas.height:0;T.fillRect(0,0,P,F),T.globalAlpha=1}}return{name:"particles-juice",version:"1.0.0",dependencies:[],init(A){var T;e=A,i=((T=A.getEngine())==null?void 0:T.particles)||null,typeof t.seed=="number"&&A.random.reseed(t.seed),t.autoStep!==!1&&(s=A.onFrame(P=>{_(P)}))},dispose(){v||(s&&(s.cancel(),s=null),o.forEach(A=>{try{A.stop()}catch{}}),o.clear(),l=1,u=0,d.remain=0,d.x=0,d.y=0,y.remain=0,y.alpha=0,x.remain=0,x.scale=1,v=!0)},spawnEmitter(A,T,P,F){let bt=typeof A=="string"?ul(A):Yi(A);if(!bt)return-1;F&&(bt=Object.assign(bt,F));let ct=a++;if(!i)return o.set(ct,r),ct;let gt=i.spawnEmitter(hl(bt,T,P));return o.set(ct,gt),ct},stopEmitter(A){let T=o.get(A);if(T)try{T.stop()}catch{}},step(A){_(A)},render(A){S(A)},particleCount(){return 0},emitterCount(){let A=0;for(let T of o.values())T.isActive()&&(A+=1);return A},hitStop(A,T){h=Math.max(0,A),u=h,f=T==null?0:Math.max(0,Math.min(1,T)),l=h>0?f:1},getTimeScale(){return l},shakeScreen(A,T,P){d.dur=Math.max(0,A),d.remain=d.dur,d.amplitude=Math.max(0,T),d.frequency=P==null?30:P,d._phase=0,d.x=0,d.y=0},getShakeOffset(){return{x:d.x,y:d.y}},flashScreen(A,T){y.dur=Math.max(0,A),y.remain=y.dur,y.peak=T==null?.8:Math.max(0,Math.min(1,T)),y.alpha=y.dur>0?y.peak:0},getFlashAlpha(){return y.alpha},pulseScale(A,T,P){x.dur=Math.max(0,A),x.remain=x.dur,x.amplitude=T==null?.2:T,x.frequency=P==null?4:P,x.scale=1},getPulseScale(){return x.scale},juiceSnapshot(){return{timeScale:l,shake:{x:d.x,y:d.y},flashAlpha:y.alpha,pulseScale:x.scale}},probe(){return{particles:0,emitters:o.size,dropped:0,steps:c,disposed:v}}}}function ua(n){let t=St(n.r)/255,e=St(n.g)/255,s=St(n.b)/255,i=Math.max(t,e,s),o=Math.min(t,e,s),a=(i+o)/2,r=0,c=0,l=i-o;return l>1e-12&&(c=a>.5?l/(2-i-o):l/(i+o),i===t?r=(e-s)/l%6:i===e?r=(s-t)/l+2:r=(t-e)/l+4,r*=60,r<0&&(r+=360)),{h:r,s:c,l:a}}function ha(n){let t=(n.h%360+360)%360,e=Ke(n.s),s=Ke(n.l);if(e<1e-12){let r=Math.round(s*255);return{r,g:r,b:r}}let i=s<.5?s*(1+e):s+e-s*e,o=2*s-i,a=t/360;return{r:Math.round($i(o,i,a+1/3)*255),g:Math.round($i(o,i,a)*255),b:Math.round($i(o,i,a-1/3)*255)}}function $i(n,t,e){let s=e;return s<0&&(s+=1),s>1&&(s-=1),s<1/6?n+(t-n)*6*s:s<1/2?t:s<2/3?n+(t-n)*(2/3-s)*6:n}function St(n){return n<0?0:n>255?255:n}function Ke(n){return n<0?0:n>1?1:n}function dl(n,t){let e=pl(n.from,t);if(e>=0&&e({r:St(r.r),g:St(r.g),b:St(r.b)})),to:o}}function Ki(n,t,e){return n+(t-n)*e}function ml(n,t){let e=ua(n),s=e.h+(t.hue||0),i=Ke(e.s*(t.sat==null?1:t.sat)),o=Ke(e.l*(t.light==null?1:t.light));return ha({h:s,s:i,l:o})}var bl=Object.freeze([Object.freeze([0,8,2,10]),Object.freeze([12,4,14,6]),Object.freeze([3,11,1,9]),Object.freeze([15,7,13,5])]);function da(n){let t=n||{},e=null,s=!1,i={vignette:{enabled:Qi(t.vignette&&t.vignette.enabled,!1),strength:Zi(t.vignette&&t.vignette.strength,.5)},dither:{enabled:Qi(t.dither&&t.dither.enabled,!1),strength:Zi(t.dither&&t.dither.strength,.5)},scanline:{enabled:Qi(t.scanline&&t.scanline.enabled,!1),strength:Zi(t.scanline&&t.scanline.strength,.5)}};function o(r){let c=r!==void 0?r:e?e.getContext2d():null;if(!c)return;let l=c.canvas?c.canvas.width:0,u=c.canvas?c.canvas.height:0;if(i.vignette.enabled&&i.vignette.strength>0&&l>0&&u>0){let h=c.createRadialGradient(l/2,u/2,Math.min(l,u)*.25,l/2,u/2,Math.max(l,u)*.75);h.addColorStop(0,"rgba(0,0,0,0)"),h.addColorStop(1,"rgba(0,0,0,"+i.vignette.strength.toFixed(3)+")"),c.fillStyle=h,c.fillRect(0,0,l,u)}if(i.scanline.enabled&&i.scanline.strength>0&&l>0&&u>0){c.fillStyle="rgba(0,0,0,"+(i.scanline.strength*.5).toFixed(3)+")";for(let h=0;h0&&l>0&&u>0&&typeof c.getImageData=="function"&&typeof c.putImageData=="function"){let h=c.getImageData(0,0,l,u);xl(h,i.dither.strength),c.putImageData(h,0,0)}}return{name:"palette-post",version:"1.0.0",dependencies:[],init(r){e=r},dispose(){s||(e=null,s=!0)},applyPaletteMap(r,c){return dl(r,c)},applyPaletteMapToBuffer(r,c){return fl(r,c)},lerpPaletteMap(r,c,l){return yl(r,c,l)},shiftHsl(r,c){return ml(r,c)},rgbToHsl(r){return ua(r)},hslToRgb(r){return ha(r)},setPost(r){if(r)for(let c of["vignette","dither","scanline"])r[c]&&(typeof r[c].enabled=="boolean"&&(i[c].enabled=r[c].enabled),typeof r[c].strength=="number"&&(i[c].strength=Ke(r[c].strength)))},getPost(){return{vignette:{enabled:i.vignette.enabled,strength:i.vignette.strength},dither:{enabled:i.dither.enabled,strength:i.dither.strength},scanline:{enabled:i.scanline.enabled,strength:i.scanline.strength}}},renderPost(r){o(r)},probe(){return{disposed:s,post:this.getPost()}}}}function xl(n,t){let e=Ke(t);if(e<=0)return n;let{data:s,width:i}=n,a=255/(Math.max(2,Math.round(16-e*14))-1);for(let r=0;r+3>2)%i,l=Math.floor((r>>2)/i),u=(bl[l&3][c&3]/16-.5)*a;for(let h=0;h<3;h++){let f=s[r+h]+u,d=Math.round(f/a)*a;s[r+h]=d<0?0:d>255?255:d}}return n}function Qi(n,t){return typeof n=="boolean"?n:t}function Zi(n,t){return typeof n=="number"?Ke(n):t}var eo=Object.freeze({blip:Object.freeze({name:"blip",params:Object.freeze([.6,0,880,0,.03,.06,1,1.5])}),thud:Object.freeze({name:"thud",params:Object.freeze([.8,0,90,0,.04,.18,0,1,0,0,0,0,0,4])}),chime:Object.freeze({name:"chime",params:Object.freeze([.5,0,660,.02,.12,.3,1,2])})}),fa=Object.keys(eo);function vl(n){let t=[];return n==null||typeof n!="object"?{ok:!1,errors:["song \u5FC5\u987B\u662F\u5BF9\u8C61"]}:(!Array.isArray(n.instruments)||n.instruments.length===0?t.push("instruments \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.instruments.forEach((e,s)=>{(!Array.isArray(e)||e.some(i=>typeof i!="number"||!Number.isFinite(i)))&&t.push(`instruments[${s}] \u5FC5\u987B\u662F\u6709\u9650\u6570\u5B57\u6570\u7EC4\uFF08ZzFX \u53C2\u6570\u5305\uFF09`)}),!Array.isArray(n.patterns)||n.patterns.length===0?t.push("patterns \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.patterns.forEach((e,s)=>{if(!Array.isArray(e)||e.length===0){t.push(`patterns[${s}] \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4\uFF08\u81F3\u5C11\u4E00\u4E2A\u58F0\u90E8\u901A\u9053\uFF09`);return}e.forEach((i,o)=>{if(!Array.isArray(i)||i.length<2){t.push(`patterns[${s}][${o}] \u901A\u9053\u81F3\u5C11\u542B [\u4E50\u5668\u7D22\u5F15, \u58F0\u50CF]`);return}if(i.some(c=>typeof c!="number"||!Number.isFinite(c))){t.push(`patterns[${s}][${o}] \u901A\u9053\u5FC5\u987B\u5168\u4E3A\u6709\u9650\u6570\u5B57`);return}let a=i[0]|0;Array.isArray(n.instruments)&&(a<0||a>=n.instruments.length)&&t.push(`patterns[${s}][${o}] \u4E50\u5668\u7D22\u5F15 ${a} \u8D8A\u754C\uFF08instruments \u957F\u5EA6 ${n.instruments.length}\uFF09`);let r=i[1];(r<-1||r>1)&&t.push(`patterns[${s}][${o}] \u58F0\u50CF ${r} \u8D8A\u754C\uFF08\u5E94 -1..+1\uFF09`)})}),!Array.isArray(n.sequence)||n.sequence.length===0?t.push("sequence \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.sequence.forEach((e,s)=>{if(typeof e!="number"||!Number.isInteger(e)){t.push(`sequence[${s}] \u5FC5\u987B\u662F\u6574\u6570 pattern \u7D22\u5F15`);return}Array.isArray(n.patterns)&&(e<0||e>=n.patterns.length)&&t.push(`sequence[${s}] \u7D22\u5F15 ${e} \u8D8A\u754C\uFF08patterns \u957F\u5EA6 ${n.patterns.length}\uFF09`)}),n.bpm!=null&&(typeof n.bpm!="number"||!(n.bpm>0))&&t.push("bpm \u5FC5\u987B\u662F\u6B63\u6570"),{ok:t.length===0,errors:t})}function Se(n){return typeof n!="number"||Number.isNaN(n)||n<0?0:n>1?1:n}function Sl(n,t){switch(n){case"ease-in":return t*t;case"ease-out":return Math.sqrt(t);case"constant":return 1;default:return t}}function pa(n,t){let e=Se(t);return n==null||!Array.isArray(n.voices)?[]:n.voices.map(s=>{let i=String(s&&s.id!=null?s.id:""),o=Array.isArray(s&&s.channelIndices)?s.channelIndices.slice():[],a=typeof s.minIntensity=="number"?Se(s.minIntensity):0,r=typeof s.maxIntensity=="number"?Se(s.maxIntensity):1,c=typeof s.volumeCurve=="string"?s.volumeCurve:"linear",l=typeof s.baseVolume=="number"?Se(s.baseVolume):1;if(er)return{id:i,on:!1,volume:0,channelIndices:o};let u=r-a,h=u<=0?1:(e-a)/u,f=Se(Sl(c,h)*l);return{id:i,on:!0,volume:f,channelIndices:o}})}function ga(n,t,e,s){try{let i=t[0]||[],o=t[1]||i,a=Math.max(i.length,o.length);if(a===0)return null;let c=n.createBuffer(2,a,44100);c.getChannelData(0).set(i),c.getChannelData(1).set(o.length?o:i);let l=n.createBufferSource();l.buffer=c,l.loop=!!s;let u=n.createGain();return u.gain.value=Se(e*.3),l.connect(u),u.connect(n.destination),l.start(),{stop(){try{l.stop()}catch(h){}try{l.disconnect(),u.disconnect()}catch(h){}}}}catch(i){return no("[audio-music] \u53D7\u63A7\u97F3\u9891\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",i),null}}function ya(n){let t=n||{},e=typeof t.masterVolume=="number"?Se(t.masterVolume):1,s=()=>null,i=null,o=null,a={voices:[]},r=1,c=null,l=!1,u=0,h=!1,f=!1;function d(){let S=s();return S==null?(u+=1,h||(to("[audio-music] \u65E0\u53D7\u63A7\u97F3\u9891\u4E0A\u4E0B\u6587\uFF08getAudioContext \u8FD4\u56DE null\uFF09\uFF0C\u5168\u90E8\u53D1\u58F0\u9759\u9ED8 no-op\uFF08\u8BC4\u4F30\u73AF\u5883\u65E0\u58F0\u5361\u65F6\u7684\u5BB9\u9519\u964D\u7EA7\uFF09"),h=!0),null):S}function y(){if(!o||!i)return null;try{let S=typeof o.bpm=="number"&&o.bpm>0?o.bpm:125;return i.synthSong(o.instruments,o.patterns,o.sequence,S)}catch(S){return no("[audio-music] \u66F2\u8C31\u6E32\u67D3\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",S),null}}function x(){let S=pa(a,r);if(S.length===0)return 1;let E=0;for(let A of S)A.on&&(E=Math.max(E,A.volume));return E}function v(S,E){typeof E=="number"&&(r=Se(E));let A=d();if(A==null||!o)return;w();let T=y();if(!T)return;let P=Se(e*x());c=ga(A,T,P,S),l=!!S&&c!=null}function w(){c&&(c.stop(),c=null),l=!1}return{name:"audio-music",version:"1.0.0",dependencies:[],init(S){s=()=>S.getAudioContext();let E=S.getEngine&&S.getEngine();i=E?E.audio.synth:null},dispose(){f||(w(),f=!0)},loadSong(S){let E=vl(S);return E.ok?o={instruments:S.instruments,patterns:S.patterns,sequence:S.sequence,bpm:typeof S.bpm=="number"?S.bpm:125}:to("[audio-music] \u66F2\u8C31\u6821\u9A8C\u5931\u8D25\uFF0C\u672A\u8F7D\u5165\uFF1A"+E.errors.join("\uFF1B")),E},play(S){v(!1,S)},stop(){w()},loop(S){v(!0,S)},setIntensityLayering(S){a=S&&Array.isArray(S.voices)?{voices:S.voices}:{voices:[]}},setIntensity(S){r=Se(S)},resolveVoices(S){return pa(a,S)},playSfx(S){let E=eo[S];if(!E){to("[audio-music] \u672A\u77E5\u97F3\u6548\u9884\u8BBE\uFF1A"+String(S));return}let A=d();if(A!=null)try{let T=i?i.synthSfx(E.params):null;if(!T)return;ga(A,[T,T],e,!1)}catch(T){no("[audio-music] \u97F3\u6548\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8 name="+S,T)}},getPreset(S){return eo[S]},listPresets(){return fa.slice()},probe(){return{hasAudio:s()!=null,hasSong:o!=null,intensity:r,voiceCount:a.voices.length,looping:l,silentNoops:u,presetCount:fa.length}}}}function no(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function to(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var wl="zaomeng.save";function Tl(n){if(typeof TextEncoder!="undefined")return new TextEncoder().encode(n).length;if(typeof Buffer!="undefined"&&typeof Buffer.byteLength=="function")return Buffer.byteLength(n,"utf8");let t=0;for(let e=0;e=55296&&s<=56319?(t+=4,e++):t+=3}return t}function io(){let n=new Map;return{getItem(t){return n.has(t)?n.get(t):null},setItem(t,e){n.set(t,e)},removeItem(t){n.delete(t)},keys(){return Array.from(n.keys())}}}function ma(){if(typeof localStorage=="undefined")throw new Error("[save-progress] createLocalStorageAdapter \u9700\u8981\u5168\u5C40 localStorage\uFF08\u4EC5\u6D4F\u89C8\u5668\u96C6\u6210\u6BB5\u53EF\u7528\uFF09\u3002node/host-dev \u8BF7\u7528\u7F3A\u7701\u5185\u5B58 adapter \u6216 createMemoryAdapter()\u3002");return{getItem(n){return localStorage.getItem(n)},setItem(n,t){localStorage.setItem(n,t)},removeItem(n){localStorage.removeItem(n)},keys(){let n=[];for(let t=0;t0?t.namespace:wl;if(e.indexOf(":")>=0)throw new Error('[save-progress] namespace \u4E0D\u5F97\u542B\u5206\u9694\u7B26 ":"\uFF08\u5F53\u524D="'+e+'"\uFF09');let s=typeof t.maxValueBytes=="number"&&t.maxValueBytes>0?Math.floor(t.maxValueBytes):32768,i=!Al(t.adapter),o=i?io():t.adapter,a=e+":",r=0,c=0,l=!1;function u(d){return typeof d!="string"||d.length===0?a+String(d):a+d}function h(){try{let d=o.keys();return Array.isArray(d)?d.filter(y=>typeof y=="string"&&y.indexOf(a)===0):[]}catch(d){return Qn("[save-progress] adapter.keys() \u5F02\u5E38\uFF0C\u964D\u7EA7\u8FD4\u56DE\u7A7A\u96C6",d),[]}}return{name:"save-progress",version:"1.0.0",dependencies:[],init(d){h()},dispose(){},get(d,y){if(!so(d))return y;let x;try{x=o.getItem(u(d))}catch(v){return Qn("[save-progress] adapter.getItem \u5F02\u5E38\uFF0C\u8FD4\u56DE\u9ED8\u8BA4\u503C key="+d,v),y}if(x==null)return y;try{return JSON.parse(x)}catch{return r+=1,l||(Zn("[save-progress] \u68C0\u6D4B\u5230\u635F\u574F\u5B58\u6863\uFF08\u975E\u6CD5 JSON\uFF09\uFF0C\u5DF2\u5BB9\u9519\u56DE\u9000\u9ED8\u8BA4\u503C key="+d),l=!0),y}},set(d,y){if(!so(d))return Zn("[save-progress] set \u6536\u5230\u975E\u6CD5 key\uFF0C\u62D2\u7EDD\u5199\u5165\uFF1A"+String(d)),!1;let x;try{x=JSON.stringify(y)}catch{return c+=1,Zn("[save-progress] \u503C\u4E0D\u53EF JSON \u5E8F\u5217\u5316\uFF08\u5FAA\u73AF\u5F15\u7528?\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1}if(x===void 0)return c+=1,Zn("[save-progress] \u503C\u5E8F\u5217\u5316\u4E3A undefined\uFF08\u5982\u7EAF undefined/\u51FD\u6570\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1;let v=Tl(x);if(v>s)return c+=1,Zn("[save-progress] \u503C\u8D85\u5B57\u8282\u4E0A\u9650\u62D2\u7EDD\u5199\u5165 key="+d+"\uFF08"+v+" > "+s+" bytes\uFF09"),!1;try{return o.setItem(u(d),x),!0}catch(w){return c+=1,Qn("[save-progress] adapter.setItem \u5F02\u5E38\uFF0C\u5199\u5165\u5931\u8D25 key="+d,w),!1}},remove(d){if(so(d))try{o.removeItem(u(d))}catch(y){Qn("[save-progress] adapter.removeItem \u5F02\u5E38\uFF08\u5DF2\u5FFD\u7565\uFF09key="+d,y)}},clear(){let d=h(),y=0;for(let x of d)try{o.removeItem(x),y+=1}catch(v){Qn("[save-progress] clear \u65F6 removeItem \u5F02\u5E38\uFF08\u5DF2\u8DF3\u8FC7\uFF09fullKey="+x,v)}return y},probe(){return{namespace:e,maxValueBytes:s,usingMemoryAdapter:i,size:h().length,corruptRecoveries:r,rejectedWrites:c}}}}function so(n){return typeof n=="string"&&n.length>0}function Al(n){return!!n&&typeof n.getItem=="function"&&typeof n.setItem=="function"&&typeof n.removeItem=="function"&&typeof n.keys=="function"}function Qn(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function Zn(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var Cl={w:390,h:844};function xa(n){let t=((n&&n.seed)!=null?n.seed:0)>>>0,e=na({cellSize:96}),s=sa(),i=ca({inputBufferMs:260,inputTypes:["pointerdown"]}),o=la({seed:t,maxParticles:600}),a=da({vignette:{enabled:!0,strength:.22}}),r=ya({masterVolume:.8}),c;try{c=ma()}catch(f){console.warn("[generic] localStorage \u4E0D\u53EF\u7528\uFF0C\u5B58\u6863\u9000\u5185\u5B58 adapter\uFF1A"+(f&&f.message)),c=io()}let l=ba({namespace:"zaomeng-generic",adapter:c});return{plugins:{collision:e,physics:s,gamefeel:i,juice:o,palettePost:a,audioMusic:r,save:l},registerOrder:[e,s,i,o,a,l,r],viewport:Cl,buildFactoryOpts:(f,d)=>({runtime:{plugins:d.plugins,bundle:d.bundle,getRealAudioCtx:d.getRealAudioCtx}})}}function ts(n){let t=n||{},e=null,s=null,i=0,o=0,a=[],r=[],c=0,l=0,u="booting",h=null,f=null,d=0,y=0,x=null;function v(L){if(e=L.ctx,s=e.getEngine(),r=E(),A(),A(),u="playing",h=null,c=0,l=0,a.push(e.getInput().on("keydown",w)),a.push(e.getInput().on("pointerdown",_)),s&&s.math&&s.math.lerp(0,1,.5),s&&s.particles)try{s.particles.spawnEmitter({pos:{x:195,y:422},emitRate:5,particleTime:1.2,speed:30,colorStart:{r:.5,g:.8,b:1,a:.3},colorEnd:{r:.2,g:.4,b:.8,a:0}})}catch{}}function w(L){if(u!=="playing")return;let I=L.key;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(I)&&(f=I)}function _(L){u==="gameover"&&S()}function S(){r=E(),A(),A(),u="playing",h=null,c=0,l=0,f=null,d=0}function E(){let L=[];for(let I=0;I<4;I++){L[I]=[];for(let M=0;M<4;M++)L[I][M]={value:0,row:I,col:M,scale:1,merging:!1,newBlock:!1,timeBorn:0}}return L}function A(){let L=[];for(let et=0;et<4;et++)for(let dt=0;dt<4;dt++)r[et][dt].value===0&&L.push({r:et,c:dt});if(L.length===0)return!1;let I=L[Math.floor(e.random.next()*L.length)],M=e.random.next()<.9?2:4,B=r[I.r][I.c];return B.value=M,B.newBlock=!0,B.scale=0,B.timeBorn=o,!0}function T(L){if(u!=="playing")return!1;let I=!1,M=r.map(G=>G.map(J=>J.value)),B=[0,1,2,3],et=[0,1,2,3],dt,xt,ft,vt,Tt,de;L==="up"?(dt=B,xt=et,ft=(G,J)=>r[G][J],vt=(G,J,Rt)=>r[G][J].value=Rt,Tt=1,de=0):L==="down"?(dt=B.slice().reverse(),xt=et,ft=(G,J)=>r[G][J],vt=(G,J,Rt)=>r[G][J].value=Rt,Tt=-1,de=0):L==="left"?(dt=B,xt=et,ft=(G,J)=>r[G][J],vt=(G,J,Rt)=>r[G][J].value=Rt,Tt=0,de=1):L==="right"&&(dt=B,xt=et.slice().reverse(),ft=(G,J)=>r[G][J],vt=(G,J,Rt)=>r[G][J].value=Rt,Tt=0,de=-1);function Me(G,J,Rt,Ie){let X=[];for(let Y=0;Y0&&X[X.length-1].value===kt.value){let oe=X[X.length-1];if(oe.value*=2,oe.merged=!0,Rt(G[Y].row,G[Y].col,0),c+=oe.value,I=!0,s&&s.particles){let Wt={x:48.75+oe.col*97.5,y:48.75+oe.row*97.5};try{s.particles.spawnEmitter({pos:Wt,count:15,speed:80,particleTime:.4,sizeStart:6,sizeEnd:12,colorStart:{r:1,g:.9,b:.2,a:1},colorEnd:{r:1,g:.5,b:0,a:0}})}catch{}}if(s&&s.audio&&s.audio.synth)try{s.audio.synth.synthSfx([1,.05,330,,,.18,,1.4])}catch{}}else X.push({row:G[Y].row,col:G[Y].col,value:kt.value,merged:!1})}for(let Y=0;Yr[X][Y],(X,Y,kt)=>r[X][Y].value=kt,L)}else for(let G=0;G<4;G++){let J=[];for(let X=0;X<4;X++){let Y=L==="left"?X:3-X;J.push({row:G,col:Y})}Me(J,(X,Y)=>r[X][Y],(X,Y,kt)=>r[X][Y].value=kt,L)}for(let G=0;G<4;G++){for(let J=0;J<4;J++)if(r[G][J].value!==M[G][J]){I=!0;break}if(I)break}return I}function P(L){if(i=e.time.nowMs(),o=i/1e3,d+=L,y=(y+L*5)%360,u!=="playing"){ct();return}if(f){let I=f;if(f=null,T(I)){l++,A();let B=!1;for(let et=0;et<4;et++){for(let dt=0;dt<4;dt++)if(r[et][dt].value>=2048){B=!0;break}if(B)break}if(B){if(u="gameover",h="win",s&&s.particles)for(let et=0;et<3;et++)try{s.particles.spawnEmitter({pos:{x:195,y:422},count:30,speed:120,particleTime:1,colorStart:{r:1,g:.8,b:0,a:1},colorEnd:{r:1,g:0,b:.5,a:0}})}catch{}if(s&&s.audio&&s.audio.synth)try{s.audio.synth.synthSfx([1,.05,440,.3,.2,.18,.3,1.4])}catch{}return}if(F()&&!bt()){if(u="gameover",h="lose",s&&s.particles)try{s.particles.spawnEmitter({pos:{x:195,y:422},count:40,speed:100,particleTime:.6,colorStart:{r:.8,g:.2,b:.2,a:1},colorEnd:{r:.3,g:0,b:0,a:0}})}catch{}if(s&&s.audio&&s.audio.synth)try{s.audio.synth.synthSfx([1,.1,110,.3,.2,.5,.5,1.4])}catch{}}}}ct()}function F(){for(let L=0;L<4;L++)for(let I=0;I<4;I++)if(r[L][I].value===0)return!1;return!0}function bt(){for(let L=0;L<4;L++)for(let I=0;I<4;I++){let M=r[L][I].value;if(M===0||I<3&&r[L][I+1].value===M||L<3&&r[L+1][I].value===M)return!0}return!1}function ct(){for(let L=0;L<4;L++)for(let I=0;I<4;I++){let M=r[L][I];if(M.newBlock){let B=o-M.timeBorn;B<.2?M.scale=B/.2:(M.scale=1,M.newBlock=!1)}M.merging&&(M.scale=1.1+.1*Math.sin(o*20))}}function gt(L){let I=y;L.fillStyle=`hsl(${I}, 20%, 10%)`,L.fillRect(0,0,390,844);let M=97.5,B=5,et=0,dt=200;for(let xt=0;xt<4;xt++)for(let ft=0;ft<4;ft++){let vt=et+ft*(M+B)+B/2,Tt=dt+xt*(M+B)+B/2;L.fillStyle="rgba(255,255,255,0.05)",L.fillRect(vt,Tt,M,M),L.beginPath(),L.roundRect(vt,Tt,M,M,8),L.fill()}for(let xt=0;xt<4;xt++)for(let ft=0;ft<4;ft++){let vt=r[xt][ft];if(vt.value===0)continue;let Tt=et+ft*(M+B)+B/2,de=dt+xt*(M+B)+B/2,Me=vt.scale||1,G=M*Me,J=Tt+(M-G)/2,Rt=de+(M-G)/2,X={2:"#eee4da",4:"#ede0c8",8:"#f2b179",16:"#f59563",32:"#f67c5f",64:"#f65e3b",128:"#edcf72",256:"#edcc61",512:"#edc850",1024:"#edc53f",2048:"#edc22e"}[vt.value]||"#3c3a32";L.fillStyle=X,L.beginPath(),L.roundRect(J,Rt,G,G,6),L.fill(),L.fillStyle=vt.value<=4?"#776e65":"#f9f6f2",L.font=`bold ${Math.min(36,60*(G/M))}px monospace`,L.textAlign="center",L.textBaseline="middle";let Y=vt.value.toString(),kt=J+G/2,oe=Rt+G/2;L.fillText(Y,kt,oe)}if(L.fillStyle="#f9f6f2",L.font="bold 28px monospace",L.textAlign="center",L.textBaseline="top",L.fillText("2048",195,30),L.font="18px monospace",L.fillText(`Score: ${c}`,195,70),L.fillText(`Moves: ${l}`,195,100),u==="gameover"){L.fillStyle="rgba(0,0,0,0.6)",L.fillRect(0,0,390,844),L.fillStyle="#fff",L.font="bold 36px monospace",L.textBaseline="middle";let xt=h==="win"?"You Win!":"Game Over";L.fillText(xt,195,160),L.font="20px monospace",L.fillText("Tap to restart",195,200)}}function wt(){for(let L of a)try{L.cancel()}catch{}a=[],r=[],c=0,l=0,u="booting"}function Vt(){return{seed:t.seed||"none",state:()=>{let L=[];for(let I=0;I<4;I++){L[I]=[];for(let M=0;M<4;M++)L[I][M]=r[I][M].value}return{phase:u,result:h,score:c,moves:l,board:L}}}}return{init:v,update:P,render:gt,destroy:wt,_forensicsView:Vt}}var pd=ts,gd=ts;async function yd(n){let t=n||{},e=t.engine||await Promise.resolve().then(()=>(Mc(),Dc)),s=(t.seed!=null?t.seed:305441741)>>>0,i=xa({seed:s});return ea({canvas:t.canvas,statusEl:t.statusEl||null,engine:e,seed:s,mode:t.mode||"play",engineMode:"real",viewport:i.viewport,factory:ts,plugins:i.plugins,registerOrder:i.registerOrder,buildFactoryOpts:i.buildFactoryOpts,recHook:t.recHook||null,onReady:t.onReady||null})}return Nc(md);})();
diff --git a/game-runtime/games/_wg1-gen/t2048/bundle.iife.js.meta.json b/game-runtime/games/_wg1-gen/t2048/bundle.iife.js.meta.json
index 496a8d0f..2441ae20 100644
--- a/game-runtime/games/_wg1-gen/t2048/bundle.iife.js.meta.json
+++ b/game-runtime/games/_wg1-gen/t2048/bundle.iife.js.meta.json
@@ -1 +1 @@
-{"inputs":{"src/core/plugin.js":{"bytes":44317,"imports":[],"format":"esm"},"src/plugins/runtime-probe/impl.js":{"bytes":16639,"imports":[],"format":"esm"},"host-dev/engine-caps.js":{"bytes":13897,"imports":[],"format":"esm"},"host-dev/engine-math.js":{"bytes":6155,"imports":[],"format":"esm"},"src/host/boot-game-host.js":{"bytes":27676,"imports":[{"path":"src/core/plugin.js","kind":"import-statement","original":"../core/plugin.js"},{"path":"src/plugins/runtime-probe/impl.js","kind":"import-statement","original":"../plugins/runtime-probe/impl.js"},{"path":"host-dev/engine-caps.js","kind":"import-statement","original":"../../host-dev/engine-caps.js"},{"path":"host-dev/engine-math.js","kind":"import-statement","original":"../../host-dev/engine-math.js"}],"format":"esm"},"src/plugins/collision/impl.js":{"bytes":24812,"imports":[],"format":"esm"},"src/plugins/physics-lite/impl.js":{"bytes":14507,"imports":[],"format":"esm"},"src/plugins/gamefeel/impl.js":{"bytes":21715,"imports":[],"format":"esm"},"src/plugins/particles-juice/impl.js":{"bytes":31830,"imports":[],"format":"esm"},"src/plugins/palette-post/impl.js":{"bytes":20240,"imports":[],"format":"esm"},"src/plugins/audio-music/impl.js":{"bytes":24659,"imports":[],"format":"esm"},"src/plugins/save-progress/impl.js":{"bytes":14608,"imports":[],"format":"esm"},"src/host/generic-host-config.js":{"bytes":7803,"imports":[{"path":"src/plugins/collision/impl.js","kind":"import-statement","original":"../plugins/collision/impl.js"},{"path":"src/plugins/physics-lite/impl.js","kind":"import-statement","original":"../plugins/physics-lite/impl.js"},{"path":"src/plugins/gamefeel/impl.js","kind":"import-statement","original":"../plugins/gamefeel/impl.js"},{"path":"src/plugins/particles-juice/impl.js","kind":"import-statement","original":"../plugins/particles-juice/impl.js"},{"path":"src/plugins/palette-post/impl.js","kind":"import-statement","original":"../plugins/palette-post/impl.js"},{"path":"src/plugins/audio-music/impl.js","kind":"import-statement","original":"../plugins/audio-music/impl.js"},{"path":"src/plugins/save-progress/impl.js","kind":"import-statement","original":"../plugins/save-progress/impl.js"}],"format":"esm"},"games/_wg1-gen/t2048/generated-factory.js":{"bytes":15261,"imports":[],"format":"esm"},"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytes":640153,"imports":[],"format":"esm"},"games/_wg1-gen/t2048/entry-bundle.js":{"bytes":6230,"imports":[{"path":"src/host/boot-game-host.js","kind":"import-statement","original":"../../../src/host/boot-game-host.js"},{"path":"src/host/generic-host-config.js","kind":"import-statement","original":"../../../src/host/generic-host-config.js"},{"path":"games/_wg1-gen/t2048/generated-factory.js","kind":"import-statement","original":"./generated-factory.js"},{"path":"node_modules/littlejsengine/dist/littlejs.esm.js","kind":"dynamic-import","original":"littlejsengine"}],"format":"esm"}},"outputs":{"games/_wg1-gen/t2048/bundle.iife.js":{"imports":[],"exports":[],"entryPoint":"games/_wg1-gen/t2048/entry-bundle.js","inputs":{"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytesInOutput":164281},"games/_wg1-gen/t2048/entry-bundle.js":{"bytesInOutput":507},"src/core/plugin.js":{"bytesInOutput":8989},"src/plugins/runtime-probe/impl.js":{"bytesInOutput":2794},"host-dev/engine-caps.js":{"bytesInOutput":1597},"host-dev/engine-math.js":{"bytesInOutput":498},"src/host/boot-game-host.js":{"bytesInOutput":5350},"src/plugins/collision/impl.js":{"bytesInOutput":1605},"src/plugins/physics-lite/impl.js":{"bytesInOutput":115},"src/plugins/gamefeel/impl.js":{"bytesInOutput":2533},"src/plugins/particles-juice/impl.js":{"bytesInOutput":4166},"src/plugins/palette-post/impl.js":{"bytesInOutput":4216},"src/plugins/audio-music/impl.js":{"bytesInOutput":6001},"src/plugins/save-progress/impl.js":{"bytesInOutput":3933},"src/host/generic-host-config.js":{"bytesInOutput":697},"games/_wg1-gen/t2048/generated-factory.js":{"bytesInOutput":5883}},"bytes":213736}}}
\ No newline at end of file
+{"inputs":{"src/core/plugin.js":{"bytes":44317,"imports":[],"format":"esm"},"src/plugins/runtime-probe/impl.js":{"bytes":16639,"imports":[],"format":"esm"},"host-dev/engine-caps.js":{"bytes":13897,"imports":[],"format":"esm"},"host-dev/engine-math.js":{"bytes":6155,"imports":[],"format":"esm"},"src/host/boot-game-host.js":{"bytes":28239,"imports":[{"path":"src/core/plugin.js","kind":"import-statement","original":"../core/plugin.js"},{"path":"src/plugins/runtime-probe/impl.js","kind":"import-statement","original":"../plugins/runtime-probe/impl.js"},{"path":"host-dev/engine-caps.js","kind":"import-statement","original":"../../host-dev/engine-caps.js"},{"path":"host-dev/engine-math.js","kind":"import-statement","original":"../../host-dev/engine-math.js"}],"format":"esm"},"src/plugins/collision/impl.js":{"bytes":24812,"imports":[],"format":"esm"},"src/plugins/physics-lite/impl.js":{"bytes":14507,"imports":[],"format":"esm"},"src/plugins/gamefeel/impl.js":{"bytes":21715,"imports":[],"format":"esm"},"src/plugins/particles-juice/impl.js":{"bytes":31830,"imports":[],"format":"esm"},"src/plugins/palette-post/impl.js":{"bytes":20240,"imports":[],"format":"esm"},"src/plugins/audio-music/impl.js":{"bytes":24659,"imports":[],"format":"esm"},"src/plugins/save-progress/impl.js":{"bytes":14608,"imports":[],"format":"esm"},"src/host/generic-host-config.js":{"bytes":7803,"imports":[{"path":"src/plugins/collision/impl.js","kind":"import-statement","original":"../plugins/collision/impl.js"},{"path":"src/plugins/physics-lite/impl.js","kind":"import-statement","original":"../plugins/physics-lite/impl.js"},{"path":"src/plugins/gamefeel/impl.js","kind":"import-statement","original":"../plugins/gamefeel/impl.js"},{"path":"src/plugins/particles-juice/impl.js","kind":"import-statement","original":"../plugins/particles-juice/impl.js"},{"path":"src/plugins/palette-post/impl.js","kind":"import-statement","original":"../plugins/palette-post/impl.js"},{"path":"src/plugins/audio-music/impl.js","kind":"import-statement","original":"../plugins/audio-music/impl.js"},{"path":"src/plugins/save-progress/impl.js","kind":"import-statement","original":"../plugins/save-progress/impl.js"}],"format":"esm"},"games/_wg1-gen/t2048/generated-factory.js":{"bytes":15261,"imports":[],"format":"esm"},"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytes":640153,"imports":[],"format":"esm"},"games/_wg1-gen/t2048/entry-bundle.js":{"bytes":6230,"imports":[{"path":"src/host/boot-game-host.js","kind":"import-statement","original":"../../../src/host/boot-game-host.js"},{"path":"src/host/generic-host-config.js","kind":"import-statement","original":"../../../src/host/generic-host-config.js"},{"path":"games/_wg1-gen/t2048/generated-factory.js","kind":"import-statement","original":"./generated-factory.js"},{"path":"node_modules/littlejsengine/dist/littlejs.esm.js","kind":"dynamic-import","original":"littlejsengine"}],"format":"esm"}},"outputs":{"games/_wg1-gen/t2048/bundle.iife.js":{"imports":[],"exports":[],"entryPoint":"games/_wg1-gen/t2048/entry-bundle.js","inputs":{"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytesInOutput":164281},"games/_wg1-gen/t2048/entry-bundle.js":{"bytesInOutput":507},"src/core/plugin.js":{"bytesInOutput":8989},"src/plugins/runtime-probe/impl.js":{"bytesInOutput":2794},"host-dev/engine-caps.js":{"bytesInOutput":1597},"host-dev/engine-math.js":{"bytesInOutput":498},"src/host/boot-game-host.js":{"bytesInOutput":5497},"src/plugins/collision/impl.js":{"bytesInOutput":1605},"src/plugins/physics-lite/impl.js":{"bytesInOutput":115},"src/plugins/gamefeel/impl.js":{"bytesInOutput":2533},"src/plugins/particles-juice/impl.js":{"bytesInOutput":4166},"src/plugins/palette-post/impl.js":{"bytesInOutput":4216},"src/plugins/audio-music/impl.js":{"bytesInOutput":6001},"src/plugins/save-progress/impl.js":{"bytesInOutput":3933},"src/host/generic-host-config.js":{"bytesInOutput":697},"games/_wg1-gen/t2048/generated-factory.js":{"bytesInOutput":5883}},"bytes":213883}}}
\ No newline at end of file
diff --git a/game-runtime/games/_wg1-gen/t2048/evidence/after-play.png b/game-runtime/games/_wg1-gen/t2048/evidence/after-play.png
index c0317da0..a35438be 100644
Binary files a/game-runtime/games/_wg1-gen/t2048/evidence/after-play.png and b/game-runtime/games/_wg1-gen/t2048/evidence/after-play.png differ
diff --git a/game-runtime/games/_wg1-gen/t2048/evidence/first-paint.png b/game-runtime/games/_wg1-gen/t2048/evidence/first-paint.png
index f1ea49f1..73dd069d 100644
Binary files a/game-runtime/games/_wg1-gen/t2048/evidence/first-paint.png and b/game-runtime/games/_wg1-gen/t2048/evidence/first-paint.png differ
diff --git a/game-runtime/games/_wg1-gen/t2048/evidence/verdict.json b/game-runtime/games/_wg1-gen/t2048/evidence/verdict.json
index 566714ac..bc79f6b4 100644
--- a/game-runtime/games/_wg1-gen/t2048/evidence/verdict.json
+++ b/game-runtime/games/_wg1-gen/t2048/evidence/verdict.json
@@ -8,8 +8,8 @@
     },
     "C_frame": {
       "pass": true,
-      "f0": 53,
-      "f1": 83,
+      "f0": 47,
+      "f1": 77,
       "delta": 30
     },
     "I_control": {
@@ -18,13 +18,13 @@
     },
     "D_render": {
       "pass": true,
-      "bright": 81981,
+      "bright": 81964,
       "maxCh": 249
     },
     "E_live": {
       "pass": true,
-      "distinctStates": 52,
-      "samples": 52
+      "distinctStates": 122,
+      "samples": 122
     },
     "B_uncaught": {
       "pass": true,
@@ -32,9 +32,11 @@
     },
     "F_wiring": {
       "pass": true,
-      "callCount": 2,
+      "callCount": 4,
       "sample": [
-        "particles.spawnEmitter"
+        "particles.spawnEmitter",
+        "particles.spawnEmitter",
+        "audio.synth.synthSfx"
       ],
       "expected": [
         "particles.",
@@ -43,9 +45,9 @@
     },
     "G_input": {
       "pass": true,
-      "inputHash": "2540a17d",
-      "controlHash": "f6024d63",
-      "atFrame": 1306,
+      "inputHash": "400f8c09",
+      "controlHash": "9c7f4289",
+      "atFrame": 2967,
       "ctrlFrame": -1
     },
     "H_progress": {
@@ -55,8 +57,8 @@
           "path": "score",
           "op": "increased",
           "before": 0,
-          "after": 0,
-          "pass": false,
+          "after": 4,
+          "pass": true,
           "why": "循环四向滑动→合并得分上升;不合并/不响应键则不升"
         }
       ],
@@ -100,13 +102,13 @@
       "state1": {
         "phase": "playing",
         "result": null,
-        "score": 0,
-        "moves": 0,
+        "score": 4,
+        "moves": 1,
         "board": [
           [
             0,
-            2,
-            2,
+            0,
+            0,
             0
           ],
           [
@@ -125,7 +127,7 @@
             0,
             0,
             0,
-            0
+            2
           ]
         ]
       }
diff --git a/game-runtime/games/_wg1-gen/t2048/play-spec.json b/game-runtime/games/_wg1-gen/t2048/play-spec.json
index 3084ae0a..705f8efd 100644
--- a/game-runtime/games/_wg1-gen/t2048/play-spec.json
+++ b/game-runtime/games/_wg1-gen/t2048/play-spec.json
@@ -7,7 +7,7 @@
       "ArrowRight",
       "ArrowDown"
     ],
-    "steps": 50,
+    "steps": 120,
     "stepMs": 220
   },
   "expectedEngineCallPrefixes": [
diff --git a/game-runtime/games/_wg1-gen/tetris/bundle.iife.js b/game-runtime/games/_wg1-gen/tetris/bundle.iife.js
index 76ab9e69..c601de56 100644
--- a/game-runtime/games/_wg1-gen/tetris/bundle.iife.js
+++ b/game-runtime/games/_wg1-gen/tetris/bundle.iife.js
@@ -1,34 +1,34 @@
-"use strict";var __GameBundle=(()=>{var zi=Object.defineProperty;var kc=Object.getOwnPropertyDescriptor;var Gc=Object.getOwnPropertyNames;var Fc=Object.prototype.hasOwnProperty;var jc=(n,t,e)=>()=>{if(e)throw e[0];try{return n&&(t=n(n=0)),t}catch(s){throw e=[s],s}};var Hr=(n,t)=>{for(var e in t)zi(n,e,{get:t[e],enumerable:!0})},Nc=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Gc(t))!Fc.call(n,i)&&i!==e&&zi(n,i,{get:()=>t[i],enumerable:!(s=kc(t,i))||s.enumerable});return n};var Bc=n=>Nc(zi({},"__esModule",{value:!0}),n);var Ic={};Hr(Ic,{ASSERT:()=>p,BLACK:()=>st,BLUE:()=>Za,Box2dDistanceJoint:()=>Ti,Box2dFrictionJoint:()=>$o,Box2dGearJoint:()=>qo,Box2dJoint:()=>Xt,Box2dKinematicObject:()=>Bo,Box2dMotorJoint:()=>Qo,Box2dObject:()=>Rs,Box2dPinJoint:()=>Uo,Box2dPlugin:()=>Ai,Box2dPrismaticJoint:()=>Ho,Box2dPulleyJoint:()=>Ko,Box2dRaycastResult:()=>wi,Box2dRevoluteJoint:()=>Wo,Box2dRopeJoint:()=>Vo,Box2dStaticObject:()=>Si,Box2dTargetJoint:()=>Jo,Box2dTileLayer:()=>zo,Box2dWeldJoint:()=>Yo,Box2dWheelJoint:()=>Xo,CLEAR_BLACK:()=>ye,CLEAR_WHITE:()=>cn,CYAN:()=>ql,CanvasLayer:()=>ui,Color:()=>wt,Ease:()=>Ei,EngineObject:()=>Ue,GRAY:()=>Vl,GREEN:()=>Qa,ImageFont:()=>ii,LOG:()=>xt,Light:()=>Oo,LightSystemPlugin:()=>Lo,MAGENTA:()=>Hl,Medal:()=>xi,NewgroundsMedal:()=>_o,NewgroundsPlugin:()=>Ro,ORANGE:()=>Wl,PI:()=>X,PURPLE:()=>tc,Particle:()=>hi,ParticleEmitter:()=>vo,PathFinder:()=>Zo,PathFinderNode:()=>_i,PostProcessPlugin:()=>Po,RED:()=>rr,RandomGenerator:()=>go,Sound:()=>xs,SoundInstance:()=>ci,TextureInfo:()=>Ve,TileCollisionLayer:()=>Ss,TileInfo:()=>Pe,TileLayer:()=>vs,TileLayerData:()=>Tn,Timer:()=>Ee,Tween:()=>Ci,UIButton:()=>_s,UICheckbox:()=>Go,UILayout:()=>No,UIObject:()=>ae,UISlider:()=>Fo,UISystemPlugin:()=>Io,UIText:()=>vi,UITextInput:()=>Mo,UITile:()=>ko,UIVideo:()=>jo,Vector2:()=>ot,WHITE:()=>V,YELLOW:()=>Ka,ZzFXMusic:()=>Do,abs:()=>et,atan2:()=>sr,audioContext:()=>pt,audioDefaultSampleRate:()=>Zn,audioIsRunning:()=>bs,audioMasterGain:()=>Je,box2d:()=>m,box2dDebug:()=>qr,box2dInit:()=>ad,box2dSetDebug:()=>rd,cameraAngle:()=>K,cameraFit:()=>rh,cameraPos:()=>Ct,cameraScale:()=>q,canvasClearColor:()=>nn,canvasColorTiles:()=>Pi,canvasFixedSize:()=>Fn,canvasMaxAspect:()=>Gn,canvasMaxSize:()=>kn,canvasMinAspect:()=>rs,canvasPixelRatio:()=>sn,canvasPixelated:()=>lr,ceil:()=>hs,clamp:()=>F,combineCanvases:()=>wr,cos:()=>at,debug:()=>Gt,debugCircle:()=>Ut,debugClear:()=>Ml,debugLine:()=>Te,debugOverlap:()=>fo,debugOverlay:()=>Me,debugPoint:()=>nr,debugPointSize:()=>ka,debugPoly:()=>Il,debugRect:()=>bt,debugScreenshot:()=>Fa,debugShowErrors:()=>kl,debugText:()=>Mn,debugVideoCaptureIsActive:()=>Ae,debugVideoCaptureStart:()=>ja,debugVideoCaptureStop:()=>Na,debugWatermark:()=>Ri,distanceAngle:()=>zl,distanceWrap:()=>ir,drawCanvas2D:()=>Pn,drawCircle:()=>si,drawCircleGradient:()=>sh,drawContext:()=>Tt,drawCount:()=>_e,drawCrescent:()=>ud,drawEllipse:()=>ic,drawEllipseGradient:()=>oc,drawLine:()=>bn,drawLineList:()=>mo,drawNineSlice:()=>_c,drawNineSliceScreen:()=>cd,drawPoly:()=>Vn,drawRect:()=>ni,drawRectGradient:()=>th,drawRegularPoly:()=>sc,drawText:()=>ih,drawTextScreen:()=>on,drawTextureWrapped:()=>eh,drawThreeSlice:()=>Rc,drawThreeSliceScreen:()=>ld,drawTile:()=>Pt,enablePhysicsSolver:()=>Ii,engineAddPlugin:()=>_n,engineImageFont:()=>lc,engineInit:()=>Pl,engineName:()=>Hs,engineObjects:()=>vt,engineObjectsCallback:()=>Ol,engineObjectsCollect:()=>Ma,engineObjectsCollide:()=>er,engineObjectsDestroy:()=>Ll,engineObjectsRaycast:()=>Dl,engineObjectsUpdate:()=>Ia,engineVersion:()=>Xs,fetchJSON:()=>Xl,floor:()=>St,fontDefault:()=>Ps,formatTime:()=>ar,frame:()=>Oa,frameRate:()=>El,gamepadConnected:()=>xo,gamepadDirectionEmulateStick:()=>yr,gamepadDpad:()=>bo,gamepadIsDown:()=>Ie,gamepadPrimary:()=>mt,gamepadStick:()=>ys,gamepadStickCount:()=>uc,gamepadVibrate:()=>Sh,gamepadVibrateStop:()=>wh,gamepadWasPressed:()=>Rr,gamepadWasReleased:()=>vh,gamepadsEnable:()=>Mi,getCameraSize:()=>ac,getCrescentPoints:()=>Pc,getNoteFrequency:()=>gc,getPaused:()=>_l,glAntialias:()=>Mr,glCanvas:()=>tt,glCircleSides:()=>Ls,glClearCanvas:()=>vc,glClearRect:()=>Cc,glCompileShader:()=>Eo,glContext:()=>g,glCopyToContext:()=>Nr,glCreateProgram:()=>Yn,glCreateTexture:()=>ji,glDeleteTexture:()=>wc,glDraw:()=>As,glDrawColoredPoints:()=>Jr,glDrawOutlineTransform:()=>zr,glDrawPoints:()=>Ac,glDrawPointsTransform:()=>Br,glDrawUntextured:()=>Tc,glEnable:()=>k,glFlush:()=>Et,glSetAntialias:()=>Yh,glSetRenderTarget:()=>os,glSetTexture:()=>Fr,glSetTextureData:()=>jr,glSetTextureWrap:()=>Sc,gravity:()=>Vt,headlessMode:()=>N,hsl:()=>Ge,hypot:()=>Ba,inputClear:()=>Gs,inputClearKey:()=>Er,inputMouseMoveThreshold:()=>Cr,inputPreventDefault:()=>jn,inputWASDEmulateDirection:()=>as,isArray:()=>pe,isColor:()=>J,isFullscreen:()=>cc,isIntersecting:()=>Va,isNumber:()=>P,isOnScreen:()=>ah,isOverlapping:()=>Qs,isPowerOfTwo:()=>ds,isStringLike:()=>U,isTouchDevice:()=>oe,isUsingGamepad:()=>Bn,isVector2:()=>O,keyDirection:()=>bh,keyIsDown:()=>Rt,keyWasPressed:()=>Mt,keyWasReleased:()=>_r,lastInputDevice:()=>tn,lerp:()=>Wt,lerpAngle:()=>Jl,lerpWrap:()=>Ua,lightSystem:()=>W,lineTest:()=>qa,log2:()=>za,mainCanvas:()=>G,mainCanvasSize:()=>I,mainContext:()=>ut,max:()=>$,medalDisplaySize:()=>mi,medalDisplaySlideTime:()=>Nn,medalDisplayTime:()=>yi,medals:()=>Cs,medalsForEach:()=>Ni,medalsInit:()=>Zh,medalsPreventUnlock:()=>Ur,medalsReset:()=>td,min:()=>Q,mod:()=>ie,mouseDelta:()=>Tr,mouseDeltaScreen:()=>ve,mouseInWindow:()=>oi,mouseIsDown:()=>ls,mousePos:()=>De,mousePosScreen:()=>Jt,mouseWasPressed:()=>gs,mouseWasReleased:()=>xh,mouseWheel:()=>Ar,nearestPowerOfTwo:()=>Ul,newgrounds:()=>Es,noise1D:()=>Zl,noise2D:()=>tu,objectDefaultAngleDamping:()=>fr,objectDefaultDamping:()=>dr,objectDefaultFriction:()=>gr,objectDefaultMass:()=>hr,objectDefaultRestitution:()=>pr,objectMaxSpeed:()=>Fe,oscillate:()=>Wa,particleEmitRateScale:()=>Zs,paused:()=>Ce,percent:()=>Ft,percentLerp:()=>Bl,playSamples:()=>Ir,pointerLockExit:()=>Ch,pointerLockIsActive:()=>hc,pointerLockRequest:()=>Ah,postProcess:()=>It,primitiveCount:()=>Re,rand:()=>ft,randBool:()=>Ha,randColor:()=>po,randInCircle:()=>$a,randInt:()=>or,randSign:()=>Xa,randVec2:()=>Ya,readSaveData:()=>Kl,rgb:()=>z,round:()=>$s,saveCanvas:()=>ec,saveDataURL:()=>fs,saveText:()=>Yl,screenToWorld:()=>Ms,screenToWorldDelta:()=>rc,screenToWorldTransform:()=>ks,setAdditiveBlendMode:()=>ps,setCameraAngle:()=>nu,setCameraPos:()=>eu,setCameraScale:()=>su,setCanvasClearColor:()=>ru,setCanvasColorTiles:()=>ou,setCanvasFixedSize:()=>uu,setCanvasMaxAspect:()=>lu,setCanvasMaxSize:()=>au,setCanvasMinAspect:()=>cu,setCanvasPixelRatio:()=>du,setCanvasPixelated:()=>nc,setCursor:()=>hh,setDebugKey:()=>Zu,setDebugWatermark:()=>Qu,setEnablePhysicsSolver:()=>Su,setFontDefault:()=>fu,setGLCircleSides:()=>mu,setGLEnable:()=>yu,setGamepadDirectionEmulateStick:()=>Ou,setGamepadsEnable:()=>Lu,setGravity:()=>Ru,setHeadlessMode:()=>gu,setInputMouseMoveThreshold:()=>ph,setInputPreventDefault:()=>fh,setInputWASDEmulateDirection:()=>Du,setMedalDisplaySize:()=>sd,setMedalDisplaySlideTime:()=>nd,setMedalDisplayTime:()=>ed,setMedalsPreventUnlock:()=>id,setObjectDefaultAngleDamping:()=>Au,setObjectDefaultDamping:()=>Tu,setObjectDefaultFriction:()=>Eu,setObjectDefaultMass:()=>wu,setObjectDefaultRestitution:()=>Cu,setObjectMaxSpeed:()=>_u,setParticleEmitRateScale:()=>Pu,setPaused:()=>Rl,setShowSplashScreen:()=>pu,setSoundDefaultRange:()=>$u,setSoundDefaultTaper:()=>Ku,setSoundEnable:()=>Xu,setSoundVolume:()=>Yu,setTileDefaultBleed:()=>vu,setTileDefaultPadding:()=>xu,setTileDefaultSize:()=>bu,setTilesPixelated:()=>hu,setTimeScale:()=>iu,setTouchGamepadAlpha:()=>Vu,setTouchGamepadAnalog:()=>zu,setTouchGamepadButtonCount:()=>Fu,setTouchGamepadCenterButtonSize:()=>Gu,setTouchGamepadDisplayTime:()=>Wu,setTouchGamepadEnable:()=>Mu,setTouchGamepadFloating:()=>Ju,setTouchGamepadLeftButtonCount:()=>Nu,setTouchGamepadLeftStick:()=>ju,setTouchGamepadPassthrough:()=>ku,setTouchGamepadRightStick:()=>Bu,setTouchGamepadSize:()=>Uu,setTouchGamepadVibration:()=>qu,setTouchInputEnable:()=>Iu,setVibrateEnable:()=>Hu,shareURL:()=>$l,showSplashScreen:()=>ur,sign:()=>se,sin:()=>nt,smoothStep:()=>Ks,soundDefaultRange:()=>xr,soundDefaultTaper:()=>vr,soundEnable:()=>Ht,soundVolume:()=>wn,speak:()=>Bh,speakStop:()=>zh,tan:()=>Ja,textureInfos:()=>un,tile:()=>Is,tileCollisionGetData:()=>li,tileCollisionLayers:()=>rn,tileCollisionRaycast:()=>yc,tileCollisionTest:()=>Qe,tileDefaultBleed:()=>Di,tileDefaultPadding:()=>Oi,tileDefaultSize:()=>Li,tileLayersLoad:()=>Uh,tilesPixelated:()=>An,time:()=>Kt,timeDelta:()=>tr,timeReal:()=>an,timeScale:()=>cr,toggleFullscreen:()=>uh,touchGamepadAlpha:()=>br,touchGamepadAnalog:()=>Os,touchGamepadButtonCount:()=>$n,touchGamepadCenterButtonSize:()=>ge,touchGamepadDisplayTime:()=>cs,touchGamepadEnable:()=>ln,touchGamepadFloating:()=>hn,touchGamepadLeftButtonCount:()=>Kn,touchGamepadLeftStick:()=>Rn,touchGamepadPassthrough:()=>mr,touchGamepadRightStick:()=>Qn,touchGamepadSize:()=>qt,touchGamepadVibration:()=>ti,touchInputEnable:()=>mn,tweenProperty:()=>hd,tweenStopAll:()=>dd,tweenUpdate:()=>Dc,uiDebug:()=>Wr,uiSetDebug:()=>od,uiSystem:()=>C,usingGamepadInput:()=>mh,usingKeyboardInput:()=>yh,usingMouseInput:()=>gh,vec2:()=>b,vibrate:()=>Pr,vibrateEnable:()=>Ds,vibrateStop:()=>Th,workCanvas:()=>Be,workContext:()=>Ze,workReadCanvas:()=>we,workReadContext:()=>je,worldToScreen:()=>Ln,worldToScreenDelta:()=>oh,writeSaveData:()=>Ql,zzfx:()=>Jh,zzfxG:()=>Gi,zzfxM:()=>Ec});function _l(){return Ce}function Rl(n=!0){Ce=n}function _n(n,t,e,s){p(!xn.find(o=>o.update===n&&o.render===t&&o.glContextLost===e&&o.glContextRestored===s));let i=new uo(n,t,e,s);xn.push(i)}async function Pl(n,t,e,s,i,o=[],r){if(Da&&console.log(`${Hs} Engine v${Xs}`),p(!ut,"engine already initialized"),ut)return;p(pe(o),"pass in images as array"),document.body||document.documentElement.appendChild(document.createElement("body")),r||(r=document.body),n||(n=()=>{}),t||(t=()=>{}),e||(e=()=>{}),s||(s=()=>{}),i||(i=()=>{});function a(){I=b(G.width,G.height),ut.imageSmoothingEnabled=!An,Co()}function c(y=0){let x=y-ao;ao||(x=0),ao=y,(Gt||Ri)&&(Ys=Wt(Ys,1e3/(x||1),.05));let v=Gt&&Rt("Equal"),w=Gt&&Rt("Minus"),_=v?10:w?.1:1;an+=x*_/1e3;let S=cr*_;x*=S,xe+=Ce?0:x,S<=1&&(xe=Q(xe,50));let E=!1;if(Ce){E=!0,l(),Ca(),xn.forEach(T=>{var R;return(R=T.update)==null?void 0:R.call(T)});for(let T of vt)T.parent||T.updateTransforms();Sa(),e(),Ea(),Ae()&&A()}else{let T=0;for(xe<0&&xe>-9&&(T=xe,xe=0);xe>=0;xe-=1e3/60)Kt=Oa++/60,E=!0,l(),Ca(),t(),xn.forEach(R=>{var M;return(M=R.update)==null?void 0:M.call(R)}),Ia(),Sa(),e(),Ea(),Ae()&&A();xe+=T}Ae()||A(),requestAnimationFrame(c);function A(){if(!N){E||l(),a(),s(),vt.sort((T,R)=>T.renderOrder-R.renderOrder);for(let T of vt)T.destroyed||T.render();i(),xn.forEach(T=>{var R;return(R=T.render)==null?void 0:R.call(T)}),_h(),Fl(),Et(),jl(),_e=0,Re=0}}}function l(){if(!N){if(Fn.x){I=Fn.copy();let y=innerWidth/innerHeight,x=Fn.x/Fn.y,v=yGn){let E=I.y*Gn|0;I.x=Q(E,kn.x)}else if(w0&&!k&&(ut.fillStyle=nn.toString(),ut.fillRect(0,0,I.x,I.y),ut.fillStyle=st.toString()),ut.lineJoin="round",ut.lineCap="round"}}if(N)return d();qh(r);let u="margin:0;overflow:hidden;background:#000;user-select:none;-webkit-user-select:none;touch-action:none;-webkit-touch-callout:none";r.style.cssText=u,G=r.appendChild(document.createElement("canvas")),Tt=ut=G.getContext("2d"),Eh(),Nh(),Gl();let h="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)";G.style.cssText=h,tt&&(tt.style.cssText=h),nc(lr),l(),Co(),Be=new OffscreenCanvas(64,64),Ze=Be.getContext("2d"),we=new OffscreenCanvas(64,64),je=we.getContext("2d",{willReadFrequently:!0});let f=o.map((y,x)=>Ta(x,y));return o.length||f.push(Ta(0)),f.push(dh()),ur&&f.push(new Promise(y=>{let x=0;v();function v(){Gs(),Qh(x+=.01),x>1?y():setTimeout(v,16)}})),await Promise.all(f),d();async function d(){await n(),c()}}function Ia(){er=vt.filter(t=>t.collideSolidObjects);function n(t){if(!t.destroyed){t.update();for(let e of t.children)n(e)}}for(let t of vt)if(!(t.parent||t.destroyed)){t.update(),t.updatePhysics();for(let e of t.children)n(e);t.updateTransforms()}vt=vt.filter(t=>!t.destroyed)}function Ll(n=!0){for(let t of vt)t.parent||t.destroy(n);vt=vt.filter(t=>!t.destroyed)}function Ma(n,t,e=vt){let s=[];if(n)if(t instanceof ot)for(let i of e)i.isOverlapping(n,t)&&s.push(i);else{let i=t*t;for(let o of e)n.distanceSquared(o.pos)e(i))}function Dl(n,t,e=vt){let s=[];for(let i of e)i.collideRaycast&&Va(n,t,i.pos,i.size)&&(fe&&bt(i.pos,i.size,"#f00"),s.push(i));return fe&&Te(n,t,s.length?"#f00":"#00f",.02),s}function p(n,...t){if(!n)throw console.assert(n,...t),new Error("Assert failed!")}function xt(...n){console.log(...n)}function bt(n,t=b(),e=V,s=0,i=0,o=!1,r=!1){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(U(e)||J(e),"color is invalid"),p(P(s),"time must be a number"),p(P(i),"angle must be a number"),J(e)&&(e=e.toString());let a=new Ee(s);en.push({pos:n.copy(),size:t.copy(),color:e,timer:a,angle:i,fill:o,screenSpace:r})}function Il(n,t,e=V,s=0,i=0,o=!1,r=!1){p(O(n),"pos must be a vec2"),p(pe(t),"points must be an array"),p(U(e)||J(e),"color is invalid"),p(P(s),"time must be a number"),p(P(i),"angle must be a number"),J(e)&&(e=e.toString()),n=n.copy(),t=t.map(c=>c.copy());let a=new Ee(s);en.push({pos:n,points:t,color:e,timer:a,angle:i,fill:o,screenSpace:r})}function Ut(n,t=0,e=V,s=0,i=!1,o=!1){p(O(n),"pos must be a vec2"),p(P(t),"size must be a number"),p(U(e)||J(e),"color is invalid"),p(P(s),"time must be a number"),J(e)&&(e=e.toString()),n=n.copy();let r=new Ee(s);en.push({pos:n,size:t,color:e,timer:r,angle:0,fill:i,screenSpace:o})}function nr(n,t,e,s,i=!1){bt(n,void 0,t,e,s,!1,i)}function Te(n,t,e,s=.1,i=0,o=!1){p(O(n),"posA must be a vec2"),p(O(t),"posB must be a vec2"),p(P(s),"width must be a number");let r=b((t.x-n.x)/2,(t.y-n.y)/2),a=b(s,r.length()*2);bt(n.add(r),a,e,i,r.angle(),!0,o)}function fo(n,t,e,s,i,o,r=!1){p(O(n),"posA must be a vec2"),p(O(e),"posB must be a vec2"),p(O(t),"sizeA must be a vec2"),p(O(s),"sizeB must be a vec2");let a=b(Q(n.x-t.x/2,e.x-s.x/2),Q(n.y-t.y/2,e.y-s.y/2)),c=b($(n.x+t.x/2,e.x+s.x/2),$(n.y+t.y/2,e.y+s.y/2));bt(a.lerp(c,.5),c.subtract(a),i,o,0,!1,r)}function Mn(n,t,e=1,s=V,i=0,o=0,r="monospace",a=!1){p(U(n),"text must be a string"),p(O(t),"pos must be a vec2"),p(P(e),"size must be a number"),p(U(s)||J(s),"color is invalid"),p(P(i),"time must be a number"),p(P(o),"angle must be a number"),p(U(r),"font must be a string"),J(s)&&(s=s.toString()),t=t.copy();let c=new Ee(i);en.push({text:n,pos:t,size:e,color:s,timer:c,angle:o,font:r,screenSpace:a})}function Ml(){en=[]}function Fa(){ho=1}function kl(){let n=e=>{document.body.style="background-color:#111;margin:8px",document.body.innerHTML="
"+e},t=console.assert;console.assert=(e,...s)=>{if(t(e,...s),!e){let i=s.join(" "),o=new Error().stack;throw`Assertion failed!
+"use strict";var __GameBundle=(()=>{var zi=Object.defineProperty;var kc=Object.getOwnPropertyDescriptor;var Gc=Object.getOwnPropertyNames;var Fc=Object.prototype.hasOwnProperty;var jc=(n,t,e)=>()=>{if(e)throw e[0];try{return n&&(t=n(n=0)),t}catch(s){throw e=[s],s}};var Hr=(n,t)=>{for(var e in t)zi(n,e,{get:t[e],enumerable:!0})},Nc=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Gc(t))!Fc.call(n,i)&&i!==e&&zi(n,i,{get:()=>t[i],enumerable:!(s=kc(t,i))||s.enumerable});return n};var Bc=n=>Nc(zi({},"__esModule",{value:!0}),n);var Ic={};Hr(Ic,{ASSERT:()=>p,BLACK:()=>st,BLUE:()=>Za,Box2dDistanceJoint:()=>Ti,Box2dFrictionJoint:()=>$o,Box2dGearJoint:()=>qo,Box2dJoint:()=>Yt,Box2dKinematicObject:()=>Bo,Box2dMotorJoint:()=>Qo,Box2dObject:()=>Rs,Box2dPinJoint:()=>Uo,Box2dPlugin:()=>Ai,Box2dPrismaticJoint:()=>Ho,Box2dPulleyJoint:()=>Ko,Box2dRaycastResult:()=>wi,Box2dRevoluteJoint:()=>Wo,Box2dRopeJoint:()=>Vo,Box2dStaticObject:()=>Si,Box2dTargetJoint:()=>Jo,Box2dTileLayer:()=>zo,Box2dWeldJoint:()=>Yo,Box2dWheelJoint:()=>Xo,CLEAR_BLACK:()=>ye,CLEAR_WHITE:()=>cn,CYAN:()=>ql,CanvasLayer:()=>ui,Color:()=>wt,Ease:()=>Ei,EngineObject:()=>Ve,GRAY:()=>Vl,GREEN:()=>Qa,ImageFont:()=>ii,LOG:()=>xt,Light:()=>Oo,LightSystemPlugin:()=>Lo,MAGENTA:()=>Hl,Medal:()=>xi,NewgroundsMedal:()=>_o,NewgroundsPlugin:()=>Ro,ORANGE:()=>Wl,PI:()=>X,PURPLE:()=>tc,Particle:()=>hi,ParticleEmitter:()=>vo,PathFinder:()=>Zo,PathFinderNode:()=>_i,PostProcessPlugin:()=>Po,RED:()=>rr,RandomGenerator:()=>go,Sound:()=>xs,SoundInstance:()=>ci,TextureInfo:()=>We,TileCollisionLayer:()=>Ss,TileInfo:()=>Pe,TileLayer:()=>vs,TileLayerData:()=>Tn,Timer:()=>Ee,Tween:()=>Ci,UIButton:()=>_s,UICheckbox:()=>Go,UILayout:()=>No,UIObject:()=>ae,UISlider:()=>Fo,UISystemPlugin:()=>Io,UIText:()=>vi,UITextInput:()=>Mo,UITile:()=>ko,UIVideo:()=>jo,Vector2:()=>rt,WHITE:()=>V,YELLOW:()=>Ka,ZzFXMusic:()=>Do,abs:()=>et,atan2:()=>sr,audioContext:()=>pt,audioDefaultSampleRate:()=>Zn,audioIsRunning:()=>bs,audioMasterGain:()=>Ue,box2d:()=>m,box2dDebug:()=>qr,box2dInit:()=>ad,box2dSetDebug:()=>rd,cameraAngle:()=>K,cameraFit:()=>rh,cameraPos:()=>Ct,cameraScale:()=>q,canvasClearColor:()=>nn,canvasColorTiles:()=>Pi,canvasFixedSize:()=>Fn,canvasMaxAspect:()=>Gn,canvasMaxSize:()=>kn,canvasMinAspect:()=>rs,canvasPixelRatio:()=>sn,canvasPixelated:()=>lr,ceil:()=>hs,clamp:()=>F,combineCanvases:()=>wr,cos:()=>ct,debug:()=>Ft,debugCircle:()=>Vt,debugClear:()=>Ml,debugLine:()=>Te,debugOverlap:()=>fo,debugOverlay:()=>ke,debugPoint:()=>nr,debugPointSize:()=>ka,debugPoly:()=>Il,debugRect:()=>bt,debugScreenshot:()=>Fa,debugShowErrors:()=>kl,debugText:()=>Mn,debugVideoCaptureIsActive:()=>Ae,debugVideoCaptureStart:()=>ja,debugVideoCaptureStop:()=>Na,debugWatermark:()=>Ri,distanceAngle:()=>zl,distanceWrap:()=>ir,drawCanvas2D:()=>Pn,drawCircle:()=>si,drawCircleGradient:()=>sh,drawContext:()=>Tt,drawCount:()=>_e,drawCrescent:()=>ud,drawEllipse:()=>ic,drawEllipseGradient:()=>oc,drawLine:()=>bn,drawLineList:()=>mo,drawNineSlice:()=>_c,drawNineSliceScreen:()=>cd,drawPoly:()=>Vn,drawRect:()=>ni,drawRectGradient:()=>th,drawRegularPoly:()=>sc,drawText:()=>ih,drawTextScreen:()=>on,drawTextureWrapped:()=>eh,drawThreeSlice:()=>Rc,drawThreeSliceScreen:()=>ld,drawTile:()=>Lt,enablePhysicsSolver:()=>Ii,engineAddPlugin:()=>_n,engineImageFont:()=>lc,engineInit:()=>Pl,engineName:()=>Hs,engineObjects:()=>vt,engineObjectsCallback:()=>Ol,engineObjectsCollect:()=>Ma,engineObjectsCollide:()=>er,engineObjectsDestroy:()=>Ll,engineObjectsRaycast:()=>Dl,engineObjectsUpdate:()=>Ia,engineVersion:()=>Xs,fetchJSON:()=>Xl,floor:()=>St,fontDefault:()=>Ps,formatTime:()=>ar,frame:()=>Oa,frameRate:()=>El,gamepadConnected:()=>xo,gamepadDirectionEmulateStick:()=>yr,gamepadDpad:()=>bo,gamepadIsDown:()=>Me,gamepadPrimary:()=>mt,gamepadStick:()=>ys,gamepadStickCount:()=>uc,gamepadVibrate:()=>Sh,gamepadVibrateStop:()=>wh,gamepadWasPressed:()=>Rr,gamepadWasReleased:()=>vh,gamepadsEnable:()=>Mi,getCameraSize:()=>ac,getCrescentPoints:()=>Pc,getNoteFrequency:()=>gc,getPaused:()=>_l,glAntialias:()=>Mr,glCanvas:()=>tt,glCircleSides:()=>Ls,glClearCanvas:()=>vc,glClearRect:()=>Cc,glCompileShader:()=>Eo,glContext:()=>g,glCopyToContext:()=>Nr,glCreateProgram:()=>Yn,glCreateTexture:()=>ji,glDeleteTexture:()=>wc,glDraw:()=>As,glDrawColoredPoints:()=>Jr,glDrawOutlineTransform:()=>zr,glDrawPoints:()=>Ac,glDrawPointsTransform:()=>Br,glDrawUntextured:()=>Tc,glEnable:()=>k,glFlush:()=>Et,glSetAntialias:()=>Yh,glSetRenderTarget:()=>os,glSetTexture:()=>Fr,glSetTextureData:()=>jr,glSetTextureWrap:()=>Sc,gravity:()=>Wt,headlessMode:()=>N,hsl:()=>Fe,hypot:()=>Ba,inputClear:()=>Gs,inputClearKey:()=>Er,inputMouseMoveThreshold:()=>Cr,inputPreventDefault:()=>jn,inputWASDEmulateDirection:()=>as,isArray:()=>pe,isColor:()=>J,isFullscreen:()=>cc,isIntersecting:()=>Va,isNumber:()=>P,isOnScreen:()=>ah,isOverlapping:()=>Qs,isPowerOfTwo:()=>ds,isStringLike:()=>U,isTouchDevice:()=>oe,isUsingGamepad:()=>Bn,isVector2:()=>O,keyDirection:()=>bh,keyIsDown:()=>Pt,keyWasPressed:()=>kt,keyWasReleased:()=>_r,lastInputDevice:()=>tn,lerp:()=>qt,lerpAngle:()=>Jl,lerpWrap:()=>Ua,lightSystem:()=>W,lineTest:()=>qa,log2:()=>za,mainCanvas:()=>G,mainCanvasSize:()=>I,mainContext:()=>ut,max:()=>$,medalDisplaySize:()=>mi,medalDisplaySlideTime:()=>Nn,medalDisplayTime:()=>yi,medals:()=>Cs,medalsForEach:()=>Ni,medalsInit:()=>Zh,medalsPreventUnlock:()=>Ur,medalsReset:()=>td,min:()=>Q,mod:()=>ie,mouseDelta:()=>Tr,mouseDeltaScreen:()=>ve,mouseInWindow:()=>oi,mouseIsDown:()=>ls,mousePos:()=>Ie,mousePosScreen:()=>Ut,mouseWasPressed:()=>gs,mouseWasReleased:()=>xh,mouseWheel:()=>Ar,nearestPowerOfTwo:()=>Ul,newgrounds:()=>Es,noise1D:()=>Zl,noise2D:()=>tu,objectDefaultAngleDamping:()=>fr,objectDefaultDamping:()=>dr,objectDefaultFriction:()=>gr,objectDefaultMass:()=>hr,objectDefaultRestitution:()=>pr,objectMaxSpeed:()=>je,oscillate:()=>Wa,particleEmitRateScale:()=>Zs,paused:()=>Ce,percent:()=>jt,percentLerp:()=>Bl,playSamples:()=>Ir,pointerLockExit:()=>Ch,pointerLockIsActive:()=>hc,pointerLockRequest:()=>Ah,postProcess:()=>Mt,primitiveCount:()=>Re,rand:()=>ft,randBool:()=>Ha,randColor:()=>po,randInCircle:()=>$a,randInt:()=>or,randSign:()=>Xa,randVec2:()=>Ya,readSaveData:()=>Kl,rgb:()=>z,round:()=>$s,saveCanvas:()=>ec,saveDataURL:()=>fs,saveText:()=>Yl,screenToWorld:()=>Ms,screenToWorldDelta:()=>rc,screenToWorldTransform:()=>ks,setAdditiveBlendMode:()=>ps,setCameraAngle:()=>nu,setCameraPos:()=>eu,setCameraScale:()=>su,setCanvasClearColor:()=>ru,setCanvasColorTiles:()=>ou,setCanvasFixedSize:()=>uu,setCanvasMaxAspect:()=>lu,setCanvasMaxSize:()=>au,setCanvasMinAspect:()=>cu,setCanvasPixelRatio:()=>du,setCanvasPixelated:()=>nc,setCursor:()=>hh,setDebugKey:()=>Zu,setDebugWatermark:()=>Qu,setEnablePhysicsSolver:()=>Su,setFontDefault:()=>fu,setGLCircleSides:()=>mu,setGLEnable:()=>yu,setGamepadDirectionEmulateStick:()=>Ou,setGamepadsEnable:()=>Lu,setGravity:()=>Ru,setHeadlessMode:()=>gu,setInputMouseMoveThreshold:()=>ph,setInputPreventDefault:()=>fh,setInputWASDEmulateDirection:()=>Du,setMedalDisplaySize:()=>sd,setMedalDisplaySlideTime:()=>nd,setMedalDisplayTime:()=>ed,setMedalsPreventUnlock:()=>id,setObjectDefaultAngleDamping:()=>Au,setObjectDefaultDamping:()=>Tu,setObjectDefaultFriction:()=>Eu,setObjectDefaultMass:()=>wu,setObjectDefaultRestitution:()=>Cu,setObjectMaxSpeed:()=>_u,setParticleEmitRateScale:()=>Pu,setPaused:()=>Rl,setShowSplashScreen:()=>pu,setSoundDefaultRange:()=>$u,setSoundDefaultTaper:()=>Ku,setSoundEnable:()=>Xu,setSoundVolume:()=>Yu,setTileDefaultBleed:()=>vu,setTileDefaultPadding:()=>xu,setTileDefaultSize:()=>bu,setTilesPixelated:()=>hu,setTimeScale:()=>iu,setTouchGamepadAlpha:()=>Vu,setTouchGamepadAnalog:()=>zu,setTouchGamepadButtonCount:()=>Fu,setTouchGamepadCenterButtonSize:()=>Gu,setTouchGamepadDisplayTime:()=>Wu,setTouchGamepadEnable:()=>Mu,setTouchGamepadFloating:()=>Ju,setTouchGamepadLeftButtonCount:()=>Nu,setTouchGamepadLeftStick:()=>ju,setTouchGamepadPassthrough:()=>ku,setTouchGamepadRightStick:()=>Bu,setTouchGamepadSize:()=>Uu,setTouchGamepadVibration:()=>qu,setTouchInputEnable:()=>Iu,setVibrateEnable:()=>Hu,shareURL:()=>$l,showSplashScreen:()=>ur,sign:()=>se,sin:()=>nt,smoothStep:()=>Ks,soundDefaultRange:()=>xr,soundDefaultTaper:()=>vr,soundEnable:()=>Xt,soundVolume:()=>wn,speak:()=>Bh,speakStop:()=>zh,tan:()=>Ja,textureInfos:()=>un,tile:()=>Is,tileCollisionGetData:()=>li,tileCollisionLayers:()=>rn,tileCollisionRaycast:()=>yc,tileCollisionTest:()=>Qe,tileDefaultBleed:()=>Di,tileDefaultPadding:()=>Oi,tileDefaultSize:()=>Li,tileLayersLoad:()=>Uh,tilesPixelated:()=>An,time:()=>Qt,timeDelta:()=>tr,timeReal:()=>an,timeScale:()=>cr,toggleFullscreen:()=>uh,touchGamepadAlpha:()=>br,touchGamepadAnalog:()=>Os,touchGamepadButtonCount:()=>$n,touchGamepadCenterButtonSize:()=>ge,touchGamepadDisplayTime:()=>cs,touchGamepadEnable:()=>ln,touchGamepadFloating:()=>hn,touchGamepadLeftButtonCount:()=>Kn,touchGamepadLeftStick:()=>Rn,touchGamepadPassthrough:()=>mr,touchGamepadRightStick:()=>Qn,touchGamepadSize:()=>Ht,touchGamepadVibration:()=>ti,touchInputEnable:()=>mn,tweenProperty:()=>hd,tweenStopAll:()=>dd,tweenUpdate:()=>Dc,uiDebug:()=>Wr,uiSetDebug:()=>od,uiSystem:()=>C,usingGamepadInput:()=>mh,usingKeyboardInput:()=>yh,usingMouseInput:()=>gh,vec2:()=>b,vibrate:()=>Pr,vibrateEnable:()=>Ds,vibrateStop:()=>Th,workCanvas:()=>ze,workContext:()=>Ze,workReadCanvas:()=>we,workReadContext:()=>Ne,worldToScreen:()=>Ln,worldToScreenDelta:()=>oh,writeSaveData:()=>Ql,zzfx:()=>Jh,zzfxG:()=>Gi,zzfxM:()=>Ec});function _l(){return Ce}function Rl(n=!0){Ce=n}function _n(n,t,e,s){p(!xn.find(o=>o.update===n&&o.render===t&&o.glContextLost===e&&o.glContextRestored===s));let i=new uo(n,t,e,s);xn.push(i)}async function Pl(n,t,e,s,i,o=[],r){if(Da&&console.log(`${Hs} Engine v${Xs}`),p(!ut,"engine already initialized"),ut)return;p(pe(o),"pass in images as array"),document.body||document.documentElement.appendChild(document.createElement("body")),r||(r=document.body),n||(n=()=>{}),t||(t=()=>{}),e||(e=()=>{}),s||(s=()=>{}),i||(i=()=>{});function a(){I=b(G.width,G.height),ut.imageSmoothingEnabled=!An,Co()}function c(y=0){let x=y-ao;ao||(x=0),ao=y,(Ft||Ri)&&(Ys=qt(Ys,1e3/(x||1),.05));let v=Ft&&Pt("Equal"),w=Ft&&Pt("Minus"),_=v?10:w?.1:1;an+=x*_/1e3;let S=cr*_;x*=S,xe+=Ce?0:x,S<=1&&(xe=Q(xe,50));let E=!1;if(Ce){E=!0,l(),Ca(),xn.forEach(T=>{var R;return(R=T.update)==null?void 0:R.call(T)});for(let T of vt)T.parent||T.updateTransforms();Sa(),e(),Ea(),Ae()&&A()}else{let T=0;for(xe<0&&xe>-9&&(T=xe,xe=0);xe>=0;xe-=1e3/60)Qt=Oa++/60,E=!0,l(),Ca(),t(),xn.forEach(R=>{var M;return(M=R.update)==null?void 0:M.call(R)}),Ia(),Sa(),e(),Ea(),Ae()&&A();xe+=T}Ae()||A(),requestAnimationFrame(c);function A(){if(!N){E||l(),a(),s(),vt.sort((T,R)=>T.renderOrder-R.renderOrder);for(let T of vt)T.destroyed||T.render();i(),xn.forEach(T=>{var R;return(R=T.render)==null?void 0:R.call(T)}),_h(),Fl(),Et(),jl(),_e=0,Re=0}}}function l(){if(!N){if(Fn.x){I=Fn.copy();let y=innerWidth/innerHeight,x=Fn.x/Fn.y,v=yGn){let E=I.y*Gn|0;I.x=Q(E,kn.x)}else if(w0&&!k&&(ut.fillStyle=nn.toString(),ut.fillRect(0,0,I.x,I.y),ut.fillStyle=st.toString()),ut.lineJoin="round",ut.lineCap="round"}}if(N)return d();qh(r);let u="margin:0;overflow:hidden;background:#000;user-select:none;-webkit-user-select:none;touch-action:none;-webkit-touch-callout:none";r.style.cssText=u,G=r.appendChild(document.createElement("canvas")),Tt=ut=G.getContext("2d"),Eh(),Nh(),Gl();let h="position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)";G.style.cssText=h,tt&&(tt.style.cssText=h),nc(lr),l(),Co(),ze=new OffscreenCanvas(64,64),Ze=ze.getContext("2d"),we=new OffscreenCanvas(64,64),Ne=we.getContext("2d",{willReadFrequently:!0});let f=o.map((y,x)=>Ta(x,y));return o.length||f.push(Ta(0)),f.push(dh()),ur&&f.push(new Promise(y=>{let x=0;v();function v(){Gs(),Qh(x+=.01),x>1?y():setTimeout(v,16)}})),await Promise.all(f),d();async function d(){await n(),c()}}function Ia(){er=vt.filter(t=>t.collideSolidObjects);function n(t){if(!t.destroyed){t.update();for(let e of t.children)n(e)}}for(let t of vt)if(!(t.parent||t.destroyed)){t.update(),t.updatePhysics();for(let e of t.children)n(e);t.updateTransforms()}vt=vt.filter(t=>!t.destroyed)}function Ll(n=!0){for(let t of vt)t.parent||t.destroy(n);vt=vt.filter(t=>!t.destroyed)}function Ma(n,t,e=vt){let s=[];if(n)if(t instanceof rt)for(let i of e)i.isOverlapping(n,t)&&s.push(i);else{let i=t*t;for(let o of e)n.distanceSquared(o.pos)e(i))}function Dl(n,t,e=vt){let s=[];for(let i of e)i.collideRaycast&&Va(n,t,i.pos,i.size)&&(fe&&bt(i.pos,i.size,"#f00"),s.push(i));return fe&&Te(n,t,s.length?"#f00":"#00f",.02),s}function p(n,...t){if(!n)throw console.assert(n,...t),new Error("Assert failed!")}function xt(...n){console.log(...n)}function bt(n,t=b(),e=V,s=0,i=0,o=!1,r=!1){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(U(e)||J(e),"color is invalid"),p(P(s),"time must be a number"),p(P(i),"angle must be a number"),J(e)&&(e=e.toString());let a=new Ee(s);en.push({pos:n.copy(),size:t.copy(),color:e,timer:a,angle:i,fill:o,screenSpace:r})}function Il(n,t,e=V,s=0,i=0,o=!1,r=!1){p(O(n),"pos must be a vec2"),p(pe(t),"points must be an array"),p(U(e)||J(e),"color is invalid"),p(P(s),"time must be a number"),p(P(i),"angle must be a number"),J(e)&&(e=e.toString()),n=n.copy(),t=t.map(c=>c.copy());let a=new Ee(s);en.push({pos:n,points:t,color:e,timer:a,angle:i,fill:o,screenSpace:r})}function Vt(n,t=0,e=V,s=0,i=!1,o=!1){p(O(n),"pos must be a vec2"),p(P(t),"size must be a number"),p(U(e)||J(e),"color is invalid"),p(P(s),"time must be a number"),J(e)&&(e=e.toString()),n=n.copy();let r=new Ee(s);en.push({pos:n,size:t,color:e,timer:r,angle:0,fill:i,screenSpace:o})}function nr(n,t,e,s,i=!1){bt(n,void 0,t,e,s,!1,i)}function Te(n,t,e,s=.1,i=0,o=!1){p(O(n),"posA must be a vec2"),p(O(t),"posB must be a vec2"),p(P(s),"width must be a number");let r=b((t.x-n.x)/2,(t.y-n.y)/2),a=b(s,r.length()*2);bt(n.add(r),a,e,i,r.angle(),!0,o)}function fo(n,t,e,s,i,o,r=!1){p(O(n),"posA must be a vec2"),p(O(e),"posB must be a vec2"),p(O(t),"sizeA must be a vec2"),p(O(s),"sizeB must be a vec2");let a=b(Q(n.x-t.x/2,e.x-s.x/2),Q(n.y-t.y/2,e.y-s.y/2)),c=b($(n.x+t.x/2,e.x+s.x/2),$(n.y+t.y/2,e.y+s.y/2));bt(a.lerp(c,.5),c.subtract(a),i,o,0,!1,r)}function Mn(n,t,e=1,s=V,i=0,o=0,r="monospace",a=!1){p(U(n),"text must be a string"),p(O(t),"pos must be a vec2"),p(P(e),"size must be a number"),p(U(s)||J(s),"color is invalid"),p(P(i),"time must be a number"),p(P(o),"angle must be a number"),p(U(r),"font must be a string"),J(s)&&(s=s.toString()),t=t.copy();let c=new Ee(i);en.push({text:n,pos:t,size:e,color:s,timer:c,angle:o,font:r,screenSpace:a})}function Ml(){en=[]}function Fa(){ho=1}function kl(){let n=e=>{document.body.style="background-color:#111;margin:8px",document.body.innerHTML="
"+e},t=console.assert;console.assert=(e,...s)=>{if(t(e,...s),!e){let i=s.join(" "),o=new Error().stack;throw`Assertion failed!
 `+i+`
 `+o}},onunhandledrejection=e=>n(e.reason.stack||e.reason),onerror=(e,s,i,o)=>n(`${e}
 ${s}
-Ln ${i}, Col ${o}`)}function Gl(){Da&&console.warn("LittleJS DEBUG build loaded. Use the release build for production.")}function Sa(){Gt&&(Mt(Ga)&&(Me=!Me),Me&&(Mt("Digit1")&&(de=!de,vn=!1),Mt("Digit2")&&(vn=!vn,de=!1),Mt("Digit3")&&(Sn=!Sn),Mt("Digit4")&&(fe=!fe),Mt("Digit5")&&Fa(),Mt("Digit7")&&(Un=!Un)),Ae()?(!Me||Mt("Digit6"))&&Na():Me&&Mt("Digit6")&&ja())}function Fl(){if(Ae())return;Et();let n=_e,t=Re;ho&&(wr(),ec(G),ho=0);let e=ut;if(Sn&&Mi){let o=0;for(let r=0;r<8;r++)xo(r)&&o++;for(let r=0;r<8;r++){if(!xo(r))continue;let a=1,c=.2,l=Ct.add(b(-a*2,((o-1)/2-r)*a*3));Mn(r,l.add(b(-a,a)),1),r===mt&&Mn("Main",l.add(b(-a*2,0)),1,"#0f0");let u=Se[r].length;for(let f=0;f{e.save();let o=i.pos,r=1,a=i.angle;if(i.screenSpace||(o=Ln(i.pos),r=q,a-=K),e.translate(o.x|0,o.y|0),e.rotate(a),e.scale(1,i.text?1:-1),e.fillStyle=i.color,e.strokeStyle=i.color,i.text!==void 0)e.font=i.size*r+"px "+i.font,e.textAlign="center",e.textBaseline="middle",e.fillText(i.text,0,0);else if(i.points!==void 0){e.beginPath();for(let c of i.points){let l=c.scale(r).floor();e.lineTo(l.x,l.y)}e.closePath(),i.fill&&e.fill(),e.stroke()}else if(i.size===0||i.size.x===0&&i.size.y===0){let c=ka*r;e.fillRect(-c/2,-1,c,3),e.fillRect(-1,-c/2,3,c)}else if(i.size.x!==void 0){let c=i.size.scale(r).floor(),l=c.x,u=c.y;i.fill&&e.fillRect(-l/2|0,-u/2|0,l,u),e.strokeRect(-l/2|0,-u/2|0,l,u)}else e.beginPath(),e.arc(0,0,i.size*r/2,0,9),i.fill&&e.fill(),e.stroke();e.restore()}),en=en.filter(i=>i.timer<0),s){let i=yc(s.pos,De);i&&ni(i.floor().add(b(.5)),b(1),z(0,1,1,.3),0,!1),bn(De,s.pos,.1,i?z(1,0,0,.5):z(0,1,0,.5),void 0,void 0,!1);let o="mouse pos = "+De;rn.length&&(o+=`
-mouse collision = `+li(De)),o+=`
+Ln ${i}, Col ${o}`)}function Gl(){Da&&console.warn("LittleJS DEBUG build loaded. Use the release build for production.")}function Sa(){Ft&&(kt(Ga)&&(ke=!ke),ke&&(kt("Digit1")&&(de=!de,vn=!1),kt("Digit2")&&(vn=!vn,de=!1),kt("Digit3")&&(Sn=!Sn),kt("Digit4")&&(fe=!fe),kt("Digit5")&&Fa(),kt("Digit7")&&(Un=!Un)),Ae()?(!ke||kt("Digit6"))&&Na():ke&&kt("Digit6")&&ja())}function Fl(){if(Ae())return;Et();let n=_e,t=Re;ho&&(wr(),ec(G),ho=0);let e=ut;if(Sn&&Mi){let o=0;for(let r=0;r<8;r++)xo(r)&&o++;for(let r=0;r<8;r++){if(!xo(r))continue;let a=1,c=.2,l=Ct.add(b(-a*2,((o-1)/2-r)*a*3));Mn(r,l.add(b(-a,a)),1),r===mt&&Mn("Main",l.add(b(-a*2,0)),1,"#0f0");let u=Se[r].length;for(let f=0;f{e.save();let o=i.pos,r=1,a=i.angle;if(i.screenSpace||(o=Ln(i.pos),r=q,a-=K),e.translate(o.x|0,o.y|0),e.rotate(a),e.scale(1,i.text?1:-1),e.fillStyle=i.color,e.strokeStyle=i.color,i.text!==void 0)e.font=i.size*r+"px "+i.font,e.textAlign="center",e.textBaseline="middle",e.fillText(i.text,0,0);else if(i.points!==void 0){e.beginPath();for(let c of i.points){let l=c.scale(r).floor();e.lineTo(l.x,l.y)}e.closePath(),i.fill&&e.fill(),e.stroke()}else if(i.size===0||i.size.x===0&&i.size.y===0){let c=ka*r;e.fillRect(-c/2,-1,c,3),e.fillRect(-1,-c/2,3,c)}else if(i.size.x!==void 0){let c=i.size.scale(r).floor(),l=c.x,u=c.y;i.fill&&e.fillRect(-l/2|0,-u/2|0,l,u),e.strokeRect(-l/2|0,-u/2|0,l,u)}else e.beginPath(),e.arc(0,0,i.size*r/2,0,9),i.fill&&e.fill(),e.stroke();e.restore()}),en=en.filter(i=>i.timer<0),s){let i=yc(s.pos,Ie);i&&ni(i.floor().add(b(.5)),b(1),z(0,1,1,.3),0,!1),bn(Ie,s.pos,.1,i?z(1,0,0,.5):z(0,1,0,.5),void 0,void 0,!1);let o="mouse pos = "+Ie;rn.length&&(o+=`
+mouse collision = `+li(Ie)),o+=`
 
 --- object info ---
-`,o+=s.toString(),on(o,Jt,24,z(),.05,void 0,"center","monospace")}{e.save(),e.fillStyle="#fff",e.textAlign="left",e.textBaseline="top",e.font="20px monospace",e.shadowColor="#000",e.shadowBlur=9;let r=9,a=0,c=24;if(Me){e.fillText(`${Hs} v${Xs}`,r,a+=c/2),e.fillText("Time: "+ar(Kt),r,a+=c),e.fillText("FPS: "+Ys.toFixed(1)+(k?" WebGL":" Canvas2D"),r,a+=c),e.fillText("Objects: "+vt.length,r,a+=c),e.fillText("Draw Calls: "+_e,r,a+=c),e.fillText("Primitives: "+Re,r,a+=c),e.fillText("---------",r,a+=c),e.fillStyle="#f00",e.fillText("ESC: Debug Overlay",r,a+=c),e.fillStyle=de?"#f00":"#fff",e.fillText("1: Debug Physics",r,a+=c),e.fillStyle=vn?"#f00":"#fff",e.fillText("2: Debug Particles",r,a+=c),e.fillStyle=Sn?"#f00":"#fff",e.fillText("3: Debug Gamepads",r,a+=c),e.fillStyle=fe?"#f00":"#fff",e.fillText("4: Debug Raycasts",r,a+=c),e.fillStyle="#fff",e.fillText("5: Save Screenshot",r,a+=c),e.fillText("6: Toggle Video Capture",r,a+=c),e.fillStyle=Un?"#f00":"#fff",e.fillText("7: Debug Sound",r,a+=c);let l="",u="";for(let h in Y[0])Rt(h,0)&&(parseInt(h)<3?u+=h+" ":l+=h+" ");u&&e.fillText("Mouse: "+u,r,a+=c),l&&e.fillText("Keys: "+l,r,a+=c);for(let h=1;hs.push(a.data),i.onstop=()=>{let a=new Blob(s,{type:"video/webm"}),c=URL.createObjectURL(a);fs(c,"capture.webm",1e3)};let o,r;if(Ht){r=new ConstantSourceNode(pt,{offset:0}),r.connect(Je),r.start(),o=pt.createMediaStreamDestination(),Je.connect(o);for(let a of o.stream.getAudioTracks())n.addTrack(a)}try{i.start()}catch{xt("Video capture not supported in this browser!"),r==null||r.stop();return}xt("Video capture started."),ke={mediaRecorder:i,captureTimer:e,videoTrack:t,silentAudioSource:r,audioStreamDestination:o}}function Na(){var n,t,e;p(Ae(),"Not capturing video!"),xt(`Video capture ended. ${ke.captureTimer.get().toFixed(2)} seconds recorded.`),he.style.display="none",(n=ke.silentAudioSource)==null||n.stop(),(t=ke.mediaRecorder)==null||t.stop(),(e=ke.videoTrack)==null||e.stop(),ke=void 0}function Nl(){p(Ae(),"Not capturing video!"),wr(),ke.videoTrack.requestFrame(),he.textContent="\u25CF REC "+ar(ke.captureTimer)}function Zt(n){if(Gt){let t=Object.keys(n),e={};t.forEach(s=>e[s]=n[s]),t.forEach(s=>{Object.defineProperty(n,s,{get:()=>e[s],set:i=>{p(!1,`Cannot modify engine constant. Attempted to set constant (${n}) property '${s}' to '${i}'.`)},enumerable:!0})})}return Object.freeze(n)}function ie(n,t=1){return(n%t+t)%t}function F(n,t=0,e=1){return ne?e:n}function Ft(n,t,e){return(e-=t)?F((n-t)/e):0}function Wt(n,t,e){return n+F(e)*(t-n)}function Bl(n,t,e,s,i){return Wt(s,i,Ft(n,t,e))}function ir(n,t,e=1){p(e>0,"distanceWrap wrapSize must be > 0");let s=(n-t)%e;return s*2%e-s}function Ua(n,t,e,s=1){return n+F(e)*ir(t,n,s)}function zl(n,t){return ir(n,t,2*X)}function Jl(n,t,e){return Ua(n,t,e,2*X)}function Ks(n){return n*n*(3-2*n)}function ds(n){return!(n&n-1)}function Ul(n){return 2**hs(za(n))}function Qs(n,t,e,s=b()){let i=(n.x-e.x)*2,o=(n.y-e.y)*2,r=t.x+s.x,a=t.y+s.y;return et(i)f)return!1;h=$(y,h)}else{if(y0?a.x+1:a.x,x=h>0?a.y+1:a.y,v=c?(y-n.x)/c:1/0,w=l?(x-n.y)/l:1/0,_=0,S=v,E=w,A=fa.x&&(T.x=a.x+1-R),M.ya.y&&(T.y=a.y+1-R),s&&(A?s.set(-u,0):s.set(0,-h)),T}(A=SURL.revokeObjectURL(n),e)}function $l(n,t,e){var s;p(U(n),"shareURL requires title string"),p(U(t),"shareURL requires url string"),(s=navigator.share)==null||s.call(navigator,{title:n,url:t}).then(()=>e==null?void 0:e())}function Kl(n,t){p(U(n),"loadData requires saveName string");let e={};try{let s=localStorage[n];if(s)try{e=JSON.parse(s)}catch{xt("readSaveData: corrupt JSON for",n,"\u2014 using defaults")}}catch{xt("readSaveData: localStorage unavailable \u2014 using defaults")}return{...t,...e}}function Ql(n,t){p(U(n),"saveData requires saveName string");try{localStorage[n]=JSON.stringify(t)}catch{xt("writeSaveData: failed to write",n)}}function yo(n){let t=(n|0)^2654435769;return t=Math.imul(t^t>>>16,2246822507),t=Math.imul(t^t>>>13,3266489909),t^=t>>>16,(t>>>0)/2**32}function Zl(n){let t=St(n);return Wt(yo(t),yo(t+1),Ks(n-t))}function tu(n,t){let e=St(n),s=St(t),i=Ks(n-e),o=Ks(t-s),r=(a,c)=>yo(a+c*374761393);return Wt(Wt(r(e,s),r(e+1,s),i),Wt(r(e,s+1),r(e+1,s+1),i),o)}function eu(n){Ct=n.copy()}function nu(n){K=n}function su(n){q=n}function iu(n){cr=n}function ou(n){Pi=n}function ru(n){nn=n.copy()}function au(n){kn=n.copy()}function cu(n){rs=n}function lu(n){Gn=n}function uu(n){Fn=n.copy()}function nc(n){lr=n,G&&(G.style.imageRendering=n?"pixelated":""),tt&&(tt.style.imageRendering=n?"pixelated":"")}function hu(n){An=n}function du(n){sn=n}function fu(n){Ps=n}function pu(n){ur=n}function gu(n){N=n}function yu(n){if(n&&!Ao){console.warn("Can not enable WebGL if it was disabled on start.");return}k=n,tt&&(tt.style.display=n?"":"none")}function mu(n){Ls=n}function bu(n){Li=n.copy()}function xu(n){Oi=n}function vu(n){Di=n}function Su(n){Ii=n}function wu(n){hr=n}function Tu(n){dr=n}function Au(n){fr=n}function Cu(n){pr=n}function Eu(n){gr=n}function _u(n){Fe=n}function Ru(n){Vt=n.copy()}function Pu(n){Zs=n}function Lu(n){Mi=n}function Ou(n){yr=n}function Du(n){as=n}function Iu(n){mn=n}function Mu(n){ln=n}function ku(n){mr=n}function Gu(n){ge=n}function Fu(n){$n=n,n>0&&(Qn=!1)}function ju(n){Rn=n,n&&(Kn=0)}function Nu(n){Kn=n,n>0&&(Rn=!1)}function Bu(n){Qn=n,n&&($n=0)}function zu(n){Os=n}function Ju(n){hn=n}function Uu(n){qt=n}function Vu(n){br=n}function Wu(n){cs=n}function qu(n){ti=n}function Hu(n){Ds=n}function Xu(n){Ht=n}function Yu(n){wn=n,Ht&&!N&&Je&&(Je.gain.value=n)}function $u(n){xr=n}function Ku(n){vr=n}function Qu(n){Ri=n}function Zu(n){Ga=n}function ei(n){return n.r>=1&&n.g>=1&&n.b>=1}function Sr(n){return n.r<=0&&n.g<=0&&n.b<=0&&n.a<=0}function Is(n=0,t=Li,e=0,s=Oi,i=Di){if(p(O(n)||typeof n=="number","index must be a vec2 or number"),p(O(t)||typeof t=="number","size must be a vec2 or number"),p(P(e)||e instanceof Ve,"texture must be a number or TextureInfo"),p(P(s),"padding must be a number"),N)return new Pe;typeof t=="number"&&(p(t>0),t=new ot(t,t));let o=typeof e=="number"?un[e]:e;p(o instanceof Ve,"tile texture is not loaded"),p(o.size.x>0,"tile texture is not loaded");let r=t.x+s*2,a=t.y+s*2,c,l;if(typeof n=="number"){let h=o.size.x/r|0;c=n%h,l=n/h|0}else c=n.x,l=n.y;let u=new ot(c*r+s,l*a+s);return new Pe(u,t,o,s,i)}function Pt(n,t=b(1),e,s=V,i=0,o,r,a=k,c=!1,l){var f;p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(J(s),"color is invalid"),p(P(i),"angle must be a number"),p(!r||J(r),"additiveColor must be a color"),p(!l||!a,"context only supported in canvas 2D mode");let u=e==null?void 0:e.textureInfo,h=(f=e==null?void 0:e.bleed)!=null?f:0;if(a&&k)if(p(!!g,"WebGL is not enabled!"),c&&([n,t,i]=ks(n,t,i)),u){let d=u.sizeInverse,y=e.pos.x*d.x,x=e.pos.y*d.y,v=e.size.x*d.x,w=e.size.y*d.y;if(Fr(u.glTexture),h){let _=d.x*h,S=d.y*h;As(n.x,n.y,o?-t.x:t.x,t.y,i,y+_,x+S,y-_+v,x-S+w,s.rgbaInt(),r&&r.rgbaInt())}else As(n.x,n.y,o?-t.x:t.x,t.y,i,y,x,y+v,x+w,s.rgbaInt(),r&&r.rgbaInt())}else{let d=r?s.add(r):s;Tc(n.x,n.y,t.x,t.y,i,d.rgbaInt())}else++_e,++Re,Pn(n,t,i,o,d=>{if(u){d.scale(1,-1);let y=e.pos.x,x=e.pos.y,v=e.size.x,w=e.size.y;lh(d,u.image,y,x,v,w,-.5,-.5,1,1,s,r,h)}else{let y=r?s.add(r):s;d.fillStyle=y.toString(),d.fillRect(-.5,-.5,1,1)}},c,l)}function ni(n,t,e,s,i,o,r){Pt(n,t,void 0,e,s,!1,void 0,i,o,r)}function th(n,t,e=V,s=cn,i=0,o=k,r=!1,a){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(J(e)&&J(s),"color is invalid"),p(P(i),"angle must be a number"),p(!a||!o,"context only supported in canvas 2D mode"),o&&k){p(!!g,"WebGL is not enabled!"),r&&(n=Ms(n),t=t.scale(1/q),i+=K);let c=[],l=[],u=t.x/2,h=t.y/2,f=e.rgbaInt(),d=s.rgbaInt(),y=at(-i),x=nt(-i);for(let v=4;v--;){let w=v&1?u:-u,_=v&2?h:-h,S=w*y-_*x,E=w*x+_*y,A=v&2?f:d;c.push(b(n.x+S,n.y+E)),l.push(A)}Jr(c,l)}else++_e,++Re,Pn(n,t,i,!1,c=>{let l=c.createLinearGradient(0,.5,0,-.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.fillRect(-.5,-.5,1,1)},r,a)}function eh(n,t,e,s=0,i=V,o=0,r,a=k,c=!1,l){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(O(e),"wrapCount must be a vec2"),p(J(i),"color is invalid"),p(P(o),"angle must be a number"),p(!r||J(r),"additiveColor must be a color"),p(!l||!a,"context only supported in canvas 2D mode"),p(!(s instanceof Pe),"pass a TextureInfo or texture index, not a TileInfo \u2014 use tileInfo.textureInfo"),N)return;let u=typeof s=="number"?un[s]:s;if(p(u instanceof Ve,"texture not loaded"),p(u.size.x>0,"texture not loaded"),p(u.wrap,"drawTextureWrapped requires a wrap-enabled texture; call textureInfo.setWrap(true) first"),a&&k){p(!!g,"WebGL is not enabled!"),c&&([n,t,o]=ks(n,t,o)),Fr(u.glTexture),As(n.x,n.y,t.x,t.y,o,0,0,e.x,e.y,i.rgbaInt(),r&&r.rgbaInt());return}++_e,++Re,c||(n=Ln(n),t=t.scale(q),o-=K);let h=!Pi||(r?ei(i.add(r))&&r.a<=0:ei(i)),f=!h&&r&&!Sr(r),d=h?u.image:ch(u.image,i,r);l=l||Tt,l.save(),l.translate(n.x+.5,n.y+.5),l.rotate(o),l.globalAlpha=f?1:i.a;let y=l.createPattern(d,"repeat"),x=new DOMMatrix().translate(-t.x/2,-t.y/2).scale(t.x/(e.x*d.width),t.y/(e.y*d.height));y.setTransform(x),l.fillStyle=y,l.fillRect(-t.x/2,-t.y/2,t.x,t.y),l.globalAlpha=1,l.restore()}function mo(n,t=.1,e=V,s=!1,i=b(),o=0,r=k,a=!1,c){if(p(pe(n),"points must be an array"),p(P(t),"width must be a number"),p(J(e),"color is invalid"),p(O(i),"pos must be a vec2"),p(P(o),"angle must be a number"),p(!c||!r,"context only supported in canvas 2D mode"),r&&k){p(!!g,"WebGL is not enabled!");let l=b(1);a&&([i,l,o]=ks(i,l,o)),zr(n,e.rgbaInt(),t,i.x,i.y,l.x,l.y,o,s)}else++_e,++Re,Pn(i,b(1),o,!1,l=>{l.strokeStyle=e.toString(),l.lineWidth=t,l.beginPath();for(let u=0;u0&&zr(n,s.rgbaInt(),e,i.x,i.y,l.x,l.y,o)}else Pn(i,b(1),o,!1,l=>{l.fillStyle=t.toString(),l.beginPath();for(let u of n)l.lineTo(u.x,u.y);l.closePath(),l.fill(),e&&(l.strokeStyle=s.toString(),l.lineWidth=e,l.stroke())},a,c)}function ic(n,t=b(1),e=V,s=0,i=0,o=st,r=k,a=!1,c){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(J(e)&&J(o),"color is invalid"),p(P(s),"angle must be a number"),p(P(i),"lineWidth must be a number"),p(i>=0,"lineWidth must be a positive value or 0"),p(!c||!r,"context only supported in canvas 2D mode"),i=F(i,0,Q(t.x,t.y)),r&&k?sc(n,t,Ls,e,i,o,s,r,a,c):Pn(n,b(1),s,!1,l=>{l.fillStyle=e.toString(),l.beginPath(),l.ellipse(0,0,t.x/2,t.y/2,0,0,9),l.fill(),i&&(l.strokeStyle=o.toString(),l.lineWidth=i,l.stroke())},a,c)}function si(n,t=1,e=V,s=0,i=st,o=k,r=!1,a){p(P(t),"size must be a number"),ic(n,b(t),e,0,s,i,o,r,a)}function oc(n,t=b(1),e=V,s=cn,i=0,o=k,r=!1,a){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(J(e)&&J(s),"color is invalid"),p(P(i),"angle must be a number"),p(!a||!o,"context only supported in canvas 2D mode"),!N)if(o&&k){p(!!g,"WebGL is not enabled!"),r&&(n=Ms(n),t=t.scale(1/q),i+=K);let c=Ls,l=t.x/2,u=t.y/2,h=e.rgbaInt(),f=s.rgbaInt(),d=nh++,y=at(-i),x=nt(-i),v=E=>{let A=nt(E)*l,T=at(E)*u;return b(n.x+A*y-T*x,n.y+A*x+T*y)},w=d%c/c*X*2,_=[v(w)],S=[f];for(let E=c;E--;){let A=(E+d)%c/c*X*2;_.push(n),S.push(h),_.push(v(A)),S.push(f)}Jr(_,S)}else++_e,++Re,Pn(n,t,i,!1,c=>{let l=c.createRadialGradient(0,0,0,0,0,.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.beginPath(),c.ellipse(0,0,.5,.5,0,0,9),c.fill()},r,a)}function sh(n,t=1,e=V,s=cn,i=k,o=!1,r){p(P(t),"size must be a number"),oc(n,b(t),e,s,0,i,o,r)}function Pn(n,t,e=0,s=!1,i,o=!1,r=Tt){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(P(e),"angle must be a number"),p(typeof i=="function","drawFunction must be a function"),o||(n=Ln(n),t=t.scale(q),e-=K),r.save(),r.translate(n.x+.5,n.y+.5),r.rotate(e),r.scale(s?-t.x:t.x,-t.y),i(r),r.restore()}function ih(n,t,e=1,s=V,i=0,o=st,r="center",a=Ps,c="",l,u=0,h=Tt){t=Ln(t),e*=q,i*=q,u-=K,u*=-1,on(n,t,e,s,i,o,r,a,c,l,u,h)}function on(n,t,e,s=V,i=0,o=st,r="center",a=Ps,c="",l,u=0,h=Tt){p(U(n),"text must be a string"),p(O(t),"pos must be a vec2"),p(P(e),"size must be a number"),p(J(s),"color must be a color"),p(P(i),"lineWidth must be a number"),p(J(o),"lineColor must be a color"),p(["left","center","right"].includes(r),"align must be left, center, or right"),p(U(a),"font must be a string"),p(U(c),"fontStyle must be a string"),p(P(u),"angle must be a number");let f=(n+"").split(`
-`),d=t.y-(f.length-1)*e/2;h.save(),h.fillStyle=s.toString(),h.strokeStyle=o.toString(),h.lineWidth=i,h.textAlign=r,h.font=c+" "+e+"px "+a,h.textBaseline="middle",h.translate(t.x,d),h.rotate(-u);let y=0;f.forEach(x=>{i&&h.strokeText(x,0,y,l),h.fillText(x,0,y,l),y+=e}),h.restore()}async function Ta(n,t){p(P(n),"textureIndex must be a number"),p(!un[n],"textureIndex is already loaded!"),p(!t||U(t),"image src must be a string");let e=new Image;t&&await new Promise(s=>{e.onerror=e.onload=s,e.crossOrigin="anonymous",e.src=t}),un[n]=new Ve(e)}function Ms(n){p(O(n),"screenPos must be a vec2");let t=(n.x-I.x/2+.5)/q,e=(n.y-I.y/2+.5)/-q;if(K){let s=at(-K),i=nt(-K),o=t*s-e*i,r=t*i+e*s;t=o,e=r}return new ot(t+Ct.x,e+Ct.y)}function Ln(n){p(O(n),"worldPos must be a vec2");let t=n.x-Ct.x,e=n.y-Ct.y;if(K){let s=at(K),i=nt(K),o=t*s-e*i,r=t*i+e*s;t=o,e=r}return new ot(t*q+I.x/2-.5,e*-q+I.y/2-.5)}function rc(n){p(O(n),"screenDelta must be a vec2");let t=n.x/q,e=n.y/-q;if(K){let s=at(-K),i=nt(-K),o=t*s-e*i,r=t*i+e*s;t=o,e=r}return new ot(t,e)}function oh(n){p(O(n),"worldDelta must be a vec2");let t=n.x,e=n.y;if(K){let s=at(K),i=nt(K),o=t*s-e*i,r=t*i+e*s;t=o,e=r}return new ot(t*q,e*-q)}function ks(n,t,e=0){return p(O(n),"screenPos must be a vec2"),p(O(t),"screenSize must be a vec2"),p(P(e),"screenAngle must be a number"),[Ms(n),t.scale(1/q),e+K]}function ac(){return I.scale(1/q)}function rh(n,t,e,s){p(O(n),"center must be a vec2"),p(O(t),"size must be a vec2");let i=f(e),o=f(s),r=t.x+i.left+i.right,a=t.y+i.top+i.bottom,c=I.x-o.left-o.right,l=I.y-o.top-o.bottom;if(!(r>0&&a>0&&c>0&&l>0))return q;q=Q(c/r,l/a);let u=b(i.right-i.left,i.top-i.bottom).scale(.5),h=b(o.right-o.left,o.top-o.bottom).scale(.5/q);return Ct=n.add(u).add(h),q;function f(d){return(d===void 0||P(d))&&(d=b(d)),O(d)?{top:d.y,right:d.x,bottom:d.y,left:d.x}:{top:d.top||0,right:d.right||0,bottom:d.bottom||0,left:d.left||0}}}function ah(n,t=0){if(p(O(n),"pos must be a vec2"),p(O(t)||P(t),"size must be a vec2 or number"),!q)return!1;let e=n.x-Ct.x,s=n.y-Ct.y;if(K){let r=at(K),a=nt(K),c=e*r-s*a,l=e*a+s*r;e=c,s=l}e*=q*2,s*=-q*2,t instanceof ot&&(t=t.length()),t*=q;let i=I.x,o=I.y;return e+t>-i&&e-t-o&&s-t{n.onerror=n.onload=a,n.crossOrigin="anonymous",n.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAAeAQMAAABnrVXaAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAAjpJREFUOMu9kzFu2zAUhn+CAROgqrk+B2l0BWYxMjlXeYaAtFtbdA1sGgHqRQfI0CNkSG5AwYB0BQ8d5Bsomwah6CPVeGg6tEPzAxLwyI+P78cP4u9lNO9OoMKnLMOobG5020/yaj/MrRcCGh1gBbyiLTPJEYaIiom5KM9Jq7KgynMGtb6L4GL4MF2H4LQKCXTvDVw2I4MsgZT7QLExdiutH+D08VOP3INXRrWX1/mmpbkNgAPYRVANb4xpcegYvhiNbIXauQICEjBuYLfMakaakWQeXxiZ0VDtuJCKs3ztMV59QtsHJNcRxDzfdL21ty3PrfIcXTN+E+GFAv6T5nbT9jd50/WFxb5ksdAv49qS6ouymG66ji08UMT6moykYLAo+V0j23GN4m829ZySAD5K7QsBfQTvOG8eE+gTeGYRAmnNAubN3hf5Zv9tJWDHp/VTuaSm7SN4fyINQqaNO3RMVxvpSPXnOChnRNvFcGY0gnwiPswYwTKVPE0zVtX3mTEIOoFzaqLrGuJaV+Uqumb71fVk/VoOH3cdLNQP/FHi8hV0CQNoqBZsUPlLPMsdCJro9QAaQQ0woDy9BJm0eTxCFnO9srcYlhNVlfR2EyTrph1uUtbUtAJifwRgrKuYdXVHeb0YI3QpawohQHkloI3J5FuVwI5ORxC9k2Tuz9Ir1IjgeIPGMHYkAZe2RuYkmWFmt3gGbTPOmBUWVTmRmHtGrfpzG/yuQNOKa6gBB/WA9khitPgl6/GP+gl2Af6tCbvaygAAAABJRU5ErkJggg=="});let t=b(),e=b(8),s=1,i=0,o=new Ve(n),r=new Pe(t,e,o,s,i);lc=new ii(r)}function fh(n=!0){jn=n}function ph(n){Cr=n}function gh(){return tn==="mouse"}function yh(){return tn==="keyboard"}function mh(){return tn==="gamepad"}function Er(n,t=0,e=!0,s=!0,i=!0){Y[t]&&(Y[t][n]&=~((e?1:0)|(s?2:0)|(i?4:0)))}function Gs(){Y.length=0,Y[0]=[],re.length=0,Cn.length=0,Fs.length=0,Se.length=0,gn.length=0}function Rt(n,t=0){var e;return p(U(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&1)}function Mt(n,t=0){var e;return p(U(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&2)}function _r(n,t=0){var e;return p(U(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&4)}function bh(n="ArrowUp",t="ArrowDown",e="ArrowLeft",s="ArrowRight"){p(U(n),"up key must be a string"),p(U(t),"down key must be a string"),p(U(e),"left key must be a string"),p(U(s),"right key must be a string");let i=o=>Rt(o)?1:0;return b(i(s)-i(e),i(n)-i(t))}function ls(n){return p(P(n),"mouse button must be a number"),Rt(n)}function gs(n){return p(P(n),"mouse button must be a number"),Mt(n)}function xh(n){return p(P(n),"mouse button must be a number"),_r(n)}function Ie(n,t=mt){return p(P(n),"button must be a number"),p(P(t),"gamepad must be a number"),Rt(n,t+1)}function Rr(n,t=mt){return p(P(n),"button must be a number"),p(P(t),"gamepad must be a number"),Mt(n,t+1)}function vh(n,t=mt){return p(P(n),"button must be a number"),p(P(t),"gamepad must be a number"),_r(n,t+1)}function ys(n,t=mt){var e,s;return p(P(n),"stick must be a number"),p(P(t),"gamepad must be a number"),(s=(e=Se[t])==null?void 0:e[n])!=null?s:b()}function bo(n=mt){var t;return p(P(n),"gamepad must be a number"),(t=gn[n])!=null?t:b()}function xo(n=mt){return p(P(n),"gamepad must be a number"),!!Y[n+1]}function uc(n=mt){var t,e;return p(P(n),"gamepad must be a number"),(e=(t=Se[n])==null?void 0:t.length)!=null?e:0}function Sh(n=mt,t=200,e=1,s=1,i=0){var r,a,c;if(p(P(n),"gamepad must be a number"),!Ds||N)return;let o=(r=navigator==null?void 0:navigator.getGamepads)==null?void 0:r.call(navigator)[n];(c=(a=o==null?void 0:o.vibrationActuator)==null?void 0:a.playEffect)==null||c.call(a,"dual-rumble",{duration:t,strongMagnitude:e,weakMagnitude:s,startDelay:i})}function wh(n=mt){var e,s,i;if(p(P(n),"gamepad must be a number"),!Ds||N)return;let t=(e=navigator==null?void 0:navigator.getGamepads)==null?void 0:e.call(navigator)[n];(i=(s=t==null?void 0:t.vibrationActuator)==null?void 0:s.reset)==null||i.call(s)}function Pr(n=100){var t;p(P(n)||pe(n),"pattern must be a number or array"),Ds&&!N&&((t=navigator==null?void 0:navigator.vibrate)==null||t.call(navigator,n))}function Th(){Pr(0)}function Ah(){var n;!oe&&((n=G.requestPointerLock)==null||n.call(G))}function Ch(){var n;(n=document.exitPointerLock)==null||n.call(document)}function hc(){return document.pointerLockElement===G}function Eh(){if(N)return;document.addEventListener("keydown",n),document.addEventListener("keyup",t),document.addEventListener("mousedown",s),document.addEventListener("mouseup",i),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",r),document.addEventListener("wheel",a,{passive:!1}),document.addEventListener("contextmenu",c),document.addEventListener("blur",l),oe&&mn&&u();function n(f){if(f.repeat||(Y[0][f.code]=3,as&&(Y[0][e(f.code)]=3)),!jn||!f.cancelable||!document.hasFocus()||f.ctrlKey||f.metaKey||f.altKey||x(f.target)||x(document.activeElement))return;let d=typeof f.key=="string"&&f.key.length===1;(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Space","Tab","Backspace"].includes(f.code)||d)&&f.preventDefault();function x(v){let w=v==null?void 0:v.tagName;return(v==null?void 0:v.isContentEditable)||["INPUT","TEXTAREA","SELECT"].includes(w)}}function t(f){Y[0][f.code]=Y[0][f.code]&2|4,as&&(Y[0][e(f.code)]=4)}function e(f){return as?f==="KeyW"?"ArrowUp":f==="KeyS"?"ArrowDown":f==="KeyA"?"ArrowLeft":f==="KeyD"?"ArrowRight":f:f}function s(f){if(oe&&mn)return;Ht&&!N&&pt&&!bs()&&pt.resume(),Y[0][f.button]=3;let d=Jt;Jt=h(b(f.x,f.y)),ve=ve.add(Jt.subtract(d)),jn&&f.cancelable&&document.hasFocus()&&f.preventDefault()}function i(f){oe&&mn||(Y[0][f.button]=Y[0][f.button]&2|4)}function o(f){oi=!0;let d=Jt;Jt=h(b(f.x,f.y));let y=hc()?b(f.movementX,f.movementY):Jt.subtract(d);ve=ve.add(y)}function r(){oi=!1}function a(f){f.ctrlKey||(Ar+=se(f.deltaY)),jn&&f.cancelable&&document.hasFocus()&&f.preventDefault()}function c(f){f.preventDefault()}function l(){Gs(),Ne.clear(),re.length=0,Cn.length=0,Fs.length=0}function u(){document.addEventListener("touchstart",y=>d(y),{passive:!1}),document.addEventListener("touchmove",y=>d(y),{passive:!1}),document.addEventListener("touchend",y=>d(y),{passive:!1});let f;function d(y){if(mn){if(Ht&&!N&&pt&&!bs()&&pt.resume(),!ln||mr){let x=S=>ms.includes(S.target)||S.target===yn,v=[];for(let S of y.touches)x(S)||v.push(S);let w=v.length,_=0;if(w){let S=b(v[0].clientX,v[0].clientY),E=Jt;Jt=h(S),f?ve=ve.add(Jt.subtract(E)):Y[0][_]=3}else f&&(Y[0][_]=Y[0][_]&2|4);f=w}return jn&&y.cancelable&&document.hasFocus()&&y.preventDefault(),!0}}}function h(f){let d=G.getBoundingClientRect(),y=Ft(f.x,d.left,d.right),x=Ft(f.y,d.top,d.bottom);return b(y*G.width,x*G.height)}}function Ca(){if(N)return;!(mn&&oe)&&!document.hasFocus()&&Gs(),De=Ms(Jt),Tr=rc(ve),Rh(),t(),n();function n(){let e=ls(0)||ls(1)||ls(2)||ve.length()>Cr,s=!1;for(let o=uc();o--&&!s;)s=ys(o).lengthSquared()>.04;for(let o=17;o--&&!s;)s=Ie(o);let i=!1;for(let o in Y[0])if(isNaN(+o)&&Y[0][o]&1){i=!0;break}s?tn="gamepad":e?tn="mouse":i&&(tn="keyboard"),Bn=tn==="gamepad"}function t(){var r,a,c,l,u,h,f;let e=d=>{let v=w=>w>.3?Ft(w,.3,.8):w<-.3?-Ft(-w,.3,.8):0;return b(v(d.x),v(-d.y)).clampLength()};if(ln&&oe){if(p(!Rn||!Kn,"set touchGamepadLeftStick or touchGamepadLeftButtonCount, not both"),p(!Qn||!$n,"set touchGamepadRightStick or touchGamepadButtonCount, not both"),!Wn.isSet())return;mt=0;let d=(r=Se[0])!=null?r:Se[0]=[],y=(a=gn[0])!=null?a:gn[0]=b();d.length=0,y.set();for(let v=0;v<2;v++){if(!We(v))continue;let w=Dr(v);d[w]=b();let _=(c=Cn[v])!=null?c:b();if(Os)d[w]=e(_);else if(_.lengthSquared()>.3){let S=F($s(_.x),-1,1),E=F($s(_.y),-1,1);d[w]=b(S,-E).clampLength(),w||y.set(S,-E)}}let x=(l=Y[1])!=null?l:Y[1]=[];for(let v=12;v--;){let w=Ie(v,0);x[v]=re[v]?w?1:3:w?4:0,ti&&x[v]===3&&(v===9||Ph(v))&&Pr(ti)}return}try{if(!Mi||!(navigator!=null&&navigator.getGamepads))return}catch{return}if(!Gt&&!document.hasFocus())return;let s=8,i=navigator.getGamepads(),o=Q(s,i.length);for(let d=0;d>1]=e(b(y.axes[S],y.axes[S+1]));let _=!1;for(let S=y.buttons.length;S--;){let E=y.buttons[S],A=Ie(S,d);x[S]=E.pressed?A?1:3:A?4:0,E.pressed&&(!E.value||E.value>.9)&&(_=!0)}_&&(co[d]=!0,co[mt]||(mt=d)),y.mapping==="standard"&&w.set((Ie(15,d)&&1)-(Ie(14,d)&&1),(Ie(12,d)&&1)-(Ie(13,d)&&1)),yr&&(w.x||w.y)&&(v[0]=w.clampLength())}ln&&Bn&&Wn.unset()}}function Ea(){if(!N){for(let n of Y)for(let t in n)n[t]&=1;Ar=0,Tr=b(),ve=b()}}function _h(){Ih()}function Rh(){if(Ke||!ln||!oe||N||!document.body)return;let n=Ke=document.createElement("div");n.style.cssText="position:fixed;inset:0;z-index:50;pointer-events:none;opacity:0;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;transition:opacity .2s;box-sizing:border-box;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)";let t=dc=document.createElement("div");t.style.cssText="position:relative;width:100%;height:100%;pointer-events:none",n.appendChild(t);let e=Lr=document.createElementNS(ai,"svg");e.style.cssText="position:absolute;inset:0;width:100%;height:100%;pointer-events:none;overflow:visible;fill:none;stroke:#fff;stroke-width:3",t.appendChild(e);let s=()=>{let i=document.createElement("div");return i.style.cssText="position:absolute;pointer-events:auto;touch-action:none",i.addEventListener("pointerdown",o=>Fh(o,i)),i.addEventListener("pointermove",o=>jh(o)),i.addEventListener("pointerup",o=>_a(o)),i.addEventListener("pointercancel",o=>_a(o)),t.appendChild(i),i};ms[0]=s(),ms[1]=s(),yn=s(),addEventListener("resize",()=>qn=!0),document.body.appendChild(n),qn=!0}function ki(){return dc.getBoundingClientRect()}function We(n){return n?Qn:Rn}function On(n){return n?$n:Kn}function Or(n){return n?0:4}function Dr(n){return n&&Rn?1:0}function Hn(n){return We(n)||On(n)>0}function Ph(n){for(let t=0;t<2;t++){let e=Or(t);if(!We(t)&&n>=e&&no.style.cssText="position:absolute;pointer-events:auto;touch-action:none;"+r;if(Ce){for(let o of ms)o.style.display="none";ge?(i(yn,"inset:0"),yn.style.display=""):yn.style.display="none"}else{for(let r=0;r<2;r++){let a=ms[r],c=r?"right":"left";if(a.style.display=Hn(r)?"":"none",hn){let l=Hn(r?0:1)?"50%":"100%";i(a,`${c}:0;bottom:0;width:${l};height:60%`)}else i(a,`${c}:0;bottom:0;width:${3*s}px;height:${3*s}px`)}yn.style.display=ge?"":"none";let o=ge;i(yn,`left:50%;top:50%;width:${2*o}px;height:${2*o}px;transform:translate(-50%,-50%)`)}Oh(t,e),qn=!1}function Oh(n,t){let e=Lr;for(;e.firstChild;)e.removeChild(e.firstChild);let s=fc={face:[],thumb:[]},i=qt,o=(a,c,l,u)=>{let h=document.createElementNS(ai,"circle");return h.setAttribute("cx",a),h.setAttribute("cy",c),h.setAttribute("r",l),u&&h.setAttribute("fill",u),e.appendChild(h),h},r=a=>{let c=i*.18,l=i*.5,u=a.x,h=a.y,f=document.createElementNS(ai,"path");f.setAttribute("d",`M ${u-c} ${h-l} H ${u+c} V ${h-c} H ${u+l} V ${h+c} H ${u+c} V ${h+l} H ${u-c} V ${h+c} H ${u-l} V ${h-c} H ${u-c} Z`),e.appendChild(f)};for(let a=0;a<2;a++){let c=On(a),l=Or(a),u=ze(a,n,t);if(We(a))Os?o(u.x,u.y,i/2):r(u),s.thumb[a]=o(u.x,u.y,i/4,"#fff");else if(c===1)s.face[l]=o(u.x,u.y,i/2,"#000");else for(let h=0;h2?f:Q(f,c-1);d=d===3?2:d===2?3:d;let y=b().setDirection(f,i/2);c===2&&(y.x*=-1),a||(y.x*=-1);let x=u.add(y);s.face[l+d]=o(x.x,x.y,i/4,"#000")}}Gt&&Sn&&Dh(n,t)}function Dh(n,t){let e=qt,s=Lr,i=(r,a,c)=>{let l=document.createElementNS(ai,r);for(let u in a)l.setAttribute(u,a[u]);l.setAttribute("stroke",c),l.setAttribute("stroke-width",2),l.setAttribute("fill","none"),s.appendChild(l)},o=(r,a,c)=>i("circle",{cx:r.x,cy:r.y,r:a},c);i("line",{x1:n/2,y1:0,x2:n/2,y2:t},"#0f0");for(let r=0;r<2;r++)if(We(r))if(hn){let a=t*.4,c=!Hn(r?0:1),l=c?0:r?n/2:0;i("rect",{x:l,y:a,width:c?n:n/2,height:t-a},"#0ff")}else o(ze(r,n,t),2*e,"#0ff");else On(r)>=1&&o(ze(r,n,t),e,"#0ff");if(ge){o(b(n/2,t/2),ge,"#ff0");for(let r=0;r<2;r++)Hn(r)&&o(ze(r,n,t),2*e,"#f0f")}}function Ih(){var l;if(!Ke||N)return;if(!ln||!oe){Ke.style.display!=="none"&&(Ke.style.display="none",Ne.clear(),re.length=0,Cn.length=0,Fs.length=0);return}Ke.style.display="";let n=Gt&&Sn,t=[$n,Kn,Rn,Qn,Os,qt,hn,ge,Ce,n].join();t!==Aa&&(Aa=t,qn=!0),qn&&Lh();let e=cs?Ft(Wn.get(),cs+1,cs):1,s=n||Wn.isSet()&&e>0&&!Ce;if(Ke.style.opacity=s?n?1:e*br:0,!s)return;let i=ki(),o=i.width,r=i.height,a=qt,c=fc;if(c){for(let u=0;u<2;u++)if(We(u)&&c.thumb[u]){let f=ze(u,o,r).add(((l=Cn[u])!=null?l:b()).scale(a/2));c.thumb[u].setAttribute("cx",f.x),c.thumb[u].setAttribute("cy",f.y)}for(let u=0;u=qt)return-1;if(i===1)return o;let a=r.subtract(t);n||(a.x*=-1);let c=i===2?a.xo:a&&ze(r,t,e).distance(n)<2*s)return{role:"stick",side:r}}else if(On(r)>=1){let c=kh(r,n,t,e);if(c>=0)return{role:"face",btn:c}}}if(ge){for(let r=0;r<2;r++)if(Hn(r)&&ze(r,t,e).distance(n)<2*s)return;if(b(t/2,e/2).distance(n)h.getChannelData(v).set(x)),f.buffer=h,f.playbackRate.value=e,f.loop=i,r=r||pt.createGain(),r.gain.value=t,r.connect(Je);let d=new StereoPannerNode(pt,{pan:F(s,-1,1)});f.connect(d).connect(r),f.addEventListener("ended",()=>{r.disconnect(),d.disconnect(),c&&c(f)});let y=a*e;return f.start(0,y),Gt&&Un&&xt("sound","vol",t.toFixed(2),"rate",e.toFixed(2),"pan",s.toFixed(2),i?"loop":""),f}function Jh(...n){return Ir([Gi(...n)])}function Gi(n=1,t=.05,e=220,s=0,i=0,o=.1,r=0,a=1,c=0,l=0,u=0,h=0,f=0,d=0,y=0,x=0,v=0,w=1,_=0,S=0,E=0){let A=Zn,T=X*2,R=c*=500*T/A/A,M=e*=(1+ft(t,-t))*T/A,Z=0,it=0,ht=0,gt=1,jt,qe=[],Lt=0,dt=0,Ot=0,He,dn=2,fn=T*et(E)*2/A,ce=at(fn),Le=nt(fn)/2/dn,te=1+Le,L=-2*ce/te,B=(1-Le)/te,j=(1+se(E)*ce)/2/te,H=-(se(E)+ce)/te,Nt=j,ct=0,le=0,Dt=0,Bt=0;for(s=s*A||9,_*=A,i*=A,o*=A,v*=A,l*=500*T/A**3,y*=T/A,u*=T/A,h*=A,f=f*A|0,jt=s+_+i+o+v|0;dt1?r>2?r>3?r>4?Lt/T%14?Ot:se(Ot)*et(Ot)**a)*(dtdt?0:(dth&&(e+=u,M+=u,gt=0),f&&!(++it%f)&&(e=M,c=R,gt||(gt=1));return qe}function li(n,t=!0){for(let e of rn)if((!t||e.isSolid)&&n.arrayCheck(e.size)){let s=e.getCollisionData(n);if(s)return s}return 0}function Qe(n,t=b(),e,s=!0){for(let i of rn)if((!s||i.isSolid)&&i.collisionTest(n,t,e))return i}function yc(n,t,e,s,i=!0){let o,r,a,c=s&&b();for(let l of rn)if(!i||l.isSolid){let u=l.collisionRaycast(n,t,e,c);if(u){let h=n.distanceSquared(u);(o===void 0||h{k=!1,tt.style.display="none",e.preventDefault(),xt("WebGL context lost! Switching to Canvas2d rendering.");for(let s of us)s.glTexture=void 0;Qt=void 0,At=0,En=!1,xn.forEach(s=>{var i;return(i=s.glContextLost)==null?void 0:i.call(s)})}),tt.addEventListener("webglcontextrestored",()=>{k=!0,tt.style.display="",xt("WebGL context restored, reinitializing..."),t();for(let e of us)e.glTexture=ji(e.image,e.wrap);xn.forEach(e=>{var s;return(s=e.glContextRestored)==null?void 0:s.call(e)})});function t(){di=Yn(`#version 300 es
+`,o+=s.toString(),on(o,Ut,24,z(),.05,void 0,"center","monospace")}{e.save(),e.fillStyle="#fff",e.textAlign="left",e.textBaseline="top",e.font="20px monospace",e.shadowColor="#000",e.shadowBlur=9;let r=9,a=0,c=24;if(ke){e.fillText(`${Hs} v${Xs}`,r,a+=c/2),e.fillText("Time: "+ar(Qt),r,a+=c),e.fillText("FPS: "+Ys.toFixed(1)+(k?" WebGL":" Canvas2D"),r,a+=c),e.fillText("Objects: "+vt.length,r,a+=c),e.fillText("Draw Calls: "+_e,r,a+=c),e.fillText("Primitives: "+Re,r,a+=c),e.fillText("---------",r,a+=c),e.fillStyle="#f00",e.fillText("ESC: Debug Overlay",r,a+=c),e.fillStyle=de?"#f00":"#fff",e.fillText("1: Debug Physics",r,a+=c),e.fillStyle=vn?"#f00":"#fff",e.fillText("2: Debug Particles",r,a+=c),e.fillStyle=Sn?"#f00":"#fff",e.fillText("3: Debug Gamepads",r,a+=c),e.fillStyle=fe?"#f00":"#fff",e.fillText("4: Debug Raycasts",r,a+=c),e.fillStyle="#fff",e.fillText("5: Save Screenshot",r,a+=c),e.fillText("6: Toggle Video Capture",r,a+=c),e.fillStyle=Un?"#f00":"#fff",e.fillText("7: Debug Sound",r,a+=c);let l="",u="";for(let h in Y[0])Pt(h,0)&&(parseInt(h)<3?u+=h+" ":l+=h+" ");u&&e.fillText("Mouse: "+u,r,a+=c),l&&e.fillText("Keys: "+l,r,a+=c);for(let h=1;hs.push(a.data),i.onstop=()=>{let a=new Blob(s,{type:"video/webm"}),c=URL.createObjectURL(a);fs(c,"capture.webm",1e3)};let o,r;if(Xt){r=new ConstantSourceNode(pt,{offset:0}),r.connect(Ue),r.start(),o=pt.createMediaStreamDestination(),Ue.connect(o);for(let a of o.stream.getAudioTracks())n.addTrack(a)}try{i.start()}catch{xt("Video capture not supported in this browser!"),r==null||r.stop();return}xt("Video capture started."),Ge={mediaRecorder:i,captureTimer:e,videoTrack:t,silentAudioSource:r,audioStreamDestination:o}}function Na(){var n,t,e;p(Ae(),"Not capturing video!"),xt(`Video capture ended. ${Ge.captureTimer.get().toFixed(2)} seconds recorded.`),he.style.display="none",(n=Ge.silentAudioSource)==null||n.stop(),(t=Ge.mediaRecorder)==null||t.stop(),(e=Ge.videoTrack)==null||e.stop(),Ge=void 0}function Nl(){p(Ae(),"Not capturing video!"),wr(),Ge.videoTrack.requestFrame(),he.textContent="\u25CF REC "+ar(Ge.captureTimer)}function te(n){if(Ft){let t=Object.keys(n),e={};t.forEach(s=>e[s]=n[s]),t.forEach(s=>{Object.defineProperty(n,s,{get:()=>e[s],set:i=>{p(!1,`Cannot modify engine constant. Attempted to set constant (${n}) property '${s}' to '${i}'.`)},enumerable:!0})})}return Object.freeze(n)}function ie(n,t=1){return(n%t+t)%t}function F(n,t=0,e=1){return ne?e:n}function jt(n,t,e){return(e-=t)?F((n-t)/e):0}function qt(n,t,e){return n+F(e)*(t-n)}function Bl(n,t,e,s,i){return qt(s,i,jt(n,t,e))}function ir(n,t,e=1){p(e>0,"distanceWrap wrapSize must be > 0");let s=(n-t)%e;return s*2%e-s}function Ua(n,t,e,s=1){return n+F(e)*ir(t,n,s)}function zl(n,t){return ir(n,t,2*X)}function Jl(n,t,e){return Ua(n,t,e,2*X)}function Ks(n){return n*n*(3-2*n)}function ds(n){return!(n&n-1)}function Ul(n){return 2**hs(za(n))}function Qs(n,t,e,s=b()){let i=(n.x-e.x)*2,o=(n.y-e.y)*2,r=t.x+s.x,a=t.y+s.y;return et(i)f)return!1;h=$(y,h)}else{if(y0?a.x+1:a.x,x=h>0?a.y+1:a.y,v=c?(y-n.x)/c:1/0,w=l?(x-n.y)/l:1/0,_=0,S=v,E=w,A=fa.x&&(T.x=a.x+1-R),M.ya.y&&(T.y=a.y+1-R),s&&(A?s.set(-u,0):s.set(0,-h)),T}(A=SURL.revokeObjectURL(n),e)}function $l(n,t,e){var s;p(U(n),"shareURL requires title string"),p(U(t),"shareURL requires url string"),(s=navigator.share)==null||s.call(navigator,{title:n,url:t}).then(()=>e==null?void 0:e())}function Kl(n,t){p(U(n),"loadData requires saveName string");let e={};try{let s=localStorage[n];if(s)try{e=JSON.parse(s)}catch{xt("readSaveData: corrupt JSON for",n,"\u2014 using defaults")}}catch{xt("readSaveData: localStorage unavailable \u2014 using defaults")}return{...t,...e}}function Ql(n,t){p(U(n),"saveData requires saveName string");try{localStorage[n]=JSON.stringify(t)}catch{xt("writeSaveData: failed to write",n)}}function yo(n){let t=(n|0)^2654435769;return t=Math.imul(t^t>>>16,2246822507),t=Math.imul(t^t>>>13,3266489909),t^=t>>>16,(t>>>0)/2**32}function Zl(n){let t=St(n);return qt(yo(t),yo(t+1),Ks(n-t))}function tu(n,t){let e=St(n),s=St(t),i=Ks(n-e),o=Ks(t-s),r=(a,c)=>yo(a+c*374761393);return qt(qt(r(e,s),r(e+1,s),i),qt(r(e,s+1),r(e+1,s+1),i),o)}function eu(n){Ct=n.copy()}function nu(n){K=n}function su(n){q=n}function iu(n){cr=n}function ou(n){Pi=n}function ru(n){nn=n.copy()}function au(n){kn=n.copy()}function cu(n){rs=n}function lu(n){Gn=n}function uu(n){Fn=n.copy()}function nc(n){lr=n,G&&(G.style.imageRendering=n?"pixelated":""),tt&&(tt.style.imageRendering=n?"pixelated":"")}function hu(n){An=n}function du(n){sn=n}function fu(n){Ps=n}function pu(n){ur=n}function gu(n){N=n}function yu(n){if(n&&!Ao){console.warn("Can not enable WebGL if it was disabled on start.");return}k=n,tt&&(tt.style.display=n?"":"none")}function mu(n){Ls=n}function bu(n){Li=n.copy()}function xu(n){Oi=n}function vu(n){Di=n}function Su(n){Ii=n}function wu(n){hr=n}function Tu(n){dr=n}function Au(n){fr=n}function Cu(n){pr=n}function Eu(n){gr=n}function _u(n){je=n}function Ru(n){Wt=n.copy()}function Pu(n){Zs=n}function Lu(n){Mi=n}function Ou(n){yr=n}function Du(n){as=n}function Iu(n){mn=n}function Mu(n){ln=n}function ku(n){mr=n}function Gu(n){ge=n}function Fu(n){$n=n,n>0&&(Qn=!1)}function ju(n){Rn=n,n&&(Kn=0)}function Nu(n){Kn=n,n>0&&(Rn=!1)}function Bu(n){Qn=n,n&&($n=0)}function zu(n){Os=n}function Ju(n){hn=n}function Uu(n){Ht=n}function Vu(n){br=n}function Wu(n){cs=n}function qu(n){ti=n}function Hu(n){Ds=n}function Xu(n){Xt=n}function Yu(n){wn=n,Xt&&!N&&Ue&&(Ue.gain.value=n)}function $u(n){xr=n}function Ku(n){vr=n}function Qu(n){Ri=n}function Zu(n){Ga=n}function ei(n){return n.r>=1&&n.g>=1&&n.b>=1}function Sr(n){return n.r<=0&&n.g<=0&&n.b<=0&&n.a<=0}function Is(n=0,t=Li,e=0,s=Oi,i=Di){if(p(O(n)||typeof n=="number","index must be a vec2 or number"),p(O(t)||typeof t=="number","size must be a vec2 or number"),p(P(e)||e instanceof We,"texture must be a number or TextureInfo"),p(P(s),"padding must be a number"),N)return new Pe;typeof t=="number"&&(p(t>0),t=new rt(t,t));let o=typeof e=="number"?un[e]:e;p(o instanceof We,"tile texture is not loaded"),p(o.size.x>0,"tile texture is not loaded");let r=t.x+s*2,a=t.y+s*2,c,l;if(typeof n=="number"){let h=o.size.x/r|0;c=n%h,l=n/h|0}else c=n.x,l=n.y;let u=new rt(c*r+s,l*a+s);return new Pe(u,t,o,s,i)}function Lt(n,t=b(1),e,s=V,i=0,o,r,a=k,c=!1,l){var f;p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(J(s),"color is invalid"),p(P(i),"angle must be a number"),p(!r||J(r),"additiveColor must be a color"),p(!l||!a,"context only supported in canvas 2D mode");let u=e==null?void 0:e.textureInfo,h=(f=e==null?void 0:e.bleed)!=null?f:0;if(a&&k)if(p(!!g,"WebGL is not enabled!"),c&&([n,t,i]=ks(n,t,i)),u){let d=u.sizeInverse,y=e.pos.x*d.x,x=e.pos.y*d.y,v=e.size.x*d.x,w=e.size.y*d.y;if(Fr(u.glTexture),h){let _=d.x*h,S=d.y*h;As(n.x,n.y,o?-t.x:t.x,t.y,i,y+_,x+S,y-_+v,x-S+w,s.rgbaInt(),r&&r.rgbaInt())}else As(n.x,n.y,o?-t.x:t.x,t.y,i,y,x,y+v,x+w,s.rgbaInt(),r&&r.rgbaInt())}else{let d=r?s.add(r):s;Tc(n.x,n.y,t.x,t.y,i,d.rgbaInt())}else++_e,++Re,Pn(n,t,i,o,d=>{if(u){d.scale(1,-1);let y=e.pos.x,x=e.pos.y,v=e.size.x,w=e.size.y;lh(d,u.image,y,x,v,w,-.5,-.5,1,1,s,r,h)}else{let y=r?s.add(r):s;d.fillStyle=y.toString(),d.fillRect(-.5,-.5,1,1)}},c,l)}function ni(n,t,e,s,i,o,r){Lt(n,t,void 0,e,s,!1,void 0,i,o,r)}function th(n,t,e=V,s=cn,i=0,o=k,r=!1,a){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(J(e)&&J(s),"color is invalid"),p(P(i),"angle must be a number"),p(!a||!o,"context only supported in canvas 2D mode"),o&&k){p(!!g,"WebGL is not enabled!"),r&&(n=Ms(n),t=t.scale(1/q),i+=K);let c=[],l=[],u=t.x/2,h=t.y/2,f=e.rgbaInt(),d=s.rgbaInt(),y=ct(-i),x=nt(-i);for(let v=4;v--;){let w=v&1?u:-u,_=v&2?h:-h,S=w*y-_*x,E=w*x+_*y,A=v&2?f:d;c.push(b(n.x+S,n.y+E)),l.push(A)}Jr(c,l)}else++_e,++Re,Pn(n,t,i,!1,c=>{let l=c.createLinearGradient(0,.5,0,-.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.fillRect(-.5,-.5,1,1)},r,a)}function eh(n,t,e,s=0,i=V,o=0,r,a=k,c=!1,l){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(O(e),"wrapCount must be a vec2"),p(J(i),"color is invalid"),p(P(o),"angle must be a number"),p(!r||J(r),"additiveColor must be a color"),p(!l||!a,"context only supported in canvas 2D mode"),p(!(s instanceof Pe),"pass a TextureInfo or texture index, not a TileInfo \u2014 use tileInfo.textureInfo"),N)return;let u=typeof s=="number"?un[s]:s;if(p(u instanceof We,"texture not loaded"),p(u.size.x>0,"texture not loaded"),p(u.wrap,"drawTextureWrapped requires a wrap-enabled texture; call textureInfo.setWrap(true) first"),a&&k){p(!!g,"WebGL is not enabled!"),c&&([n,t,o]=ks(n,t,o)),Fr(u.glTexture),As(n.x,n.y,t.x,t.y,o,0,0,e.x,e.y,i.rgbaInt(),r&&r.rgbaInt());return}++_e,++Re,c||(n=Ln(n),t=t.scale(q),o-=K);let h=!Pi||(r?ei(i.add(r))&&r.a<=0:ei(i)),f=!h&&r&&!Sr(r),d=h?u.image:ch(u.image,i,r);l=l||Tt,l.save(),l.translate(n.x+.5,n.y+.5),l.rotate(o),l.globalAlpha=f?1:i.a;let y=l.createPattern(d,"repeat"),x=new DOMMatrix().translate(-t.x/2,-t.y/2).scale(t.x/(e.x*d.width),t.y/(e.y*d.height));y.setTransform(x),l.fillStyle=y,l.fillRect(-t.x/2,-t.y/2,t.x,t.y),l.globalAlpha=1,l.restore()}function mo(n,t=.1,e=V,s=!1,i=b(),o=0,r=k,a=!1,c){if(p(pe(n),"points must be an array"),p(P(t),"width must be a number"),p(J(e),"color is invalid"),p(O(i),"pos must be a vec2"),p(P(o),"angle must be a number"),p(!c||!r,"context only supported in canvas 2D mode"),r&&k){p(!!g,"WebGL is not enabled!");let l=b(1);a&&([i,l,o]=ks(i,l,o)),zr(n,e.rgbaInt(),t,i.x,i.y,l.x,l.y,o,s)}else++_e,++Re,Pn(i,b(1),o,!1,l=>{l.strokeStyle=e.toString(),l.lineWidth=t,l.beginPath();for(let u=0;u0&&zr(n,s.rgbaInt(),e,i.x,i.y,l.x,l.y,o)}else Pn(i,b(1),o,!1,l=>{l.fillStyle=t.toString(),l.beginPath();for(let u of n)l.lineTo(u.x,u.y);l.closePath(),l.fill(),e&&(l.strokeStyle=s.toString(),l.lineWidth=e,l.stroke())},a,c)}function ic(n,t=b(1),e=V,s=0,i=0,o=st,r=k,a=!1,c){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(J(e)&&J(o),"color is invalid"),p(P(s),"angle must be a number"),p(P(i),"lineWidth must be a number"),p(i>=0,"lineWidth must be a positive value or 0"),p(!c||!r,"context only supported in canvas 2D mode"),i=F(i,0,Q(t.x,t.y)),r&&k?sc(n,t,Ls,e,i,o,s,r,a,c):Pn(n,b(1),s,!1,l=>{l.fillStyle=e.toString(),l.beginPath(),l.ellipse(0,0,t.x/2,t.y/2,0,0,9),l.fill(),i&&(l.strokeStyle=o.toString(),l.lineWidth=i,l.stroke())},a,c)}function si(n,t=1,e=V,s=0,i=st,o=k,r=!1,a){p(P(t),"size must be a number"),ic(n,b(t),e,0,s,i,o,r,a)}function oc(n,t=b(1),e=V,s=cn,i=0,o=k,r=!1,a){if(p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(J(e)&&J(s),"color is invalid"),p(P(i),"angle must be a number"),p(!a||!o,"context only supported in canvas 2D mode"),!N)if(o&&k){p(!!g,"WebGL is not enabled!"),r&&(n=Ms(n),t=t.scale(1/q),i+=K);let c=Ls,l=t.x/2,u=t.y/2,h=e.rgbaInt(),f=s.rgbaInt(),d=nh++,y=ct(-i),x=nt(-i),v=E=>{let A=nt(E)*l,T=ct(E)*u;return b(n.x+A*y-T*x,n.y+A*x+T*y)},w=d%c/c*X*2,_=[v(w)],S=[f];for(let E=c;E--;){let A=(E+d)%c/c*X*2;_.push(n),S.push(h),_.push(v(A)),S.push(f)}Jr(_,S)}else++_e,++Re,Pn(n,t,i,!1,c=>{let l=c.createRadialGradient(0,0,0,0,0,.5);l.addColorStop(0,e.toString()),l.addColorStop(1,s.toString()),c.fillStyle=l,c.beginPath(),c.ellipse(0,0,.5,.5,0,0,9),c.fill()},r,a)}function sh(n,t=1,e=V,s=cn,i=k,o=!1,r){p(P(t),"size must be a number"),oc(n,b(t),e,s,0,i,o,r)}function Pn(n,t,e=0,s=!1,i,o=!1,r=Tt){p(O(n),"pos must be a vec2"),p(O(t),"size must be a vec2"),p(P(e),"angle must be a number"),p(typeof i=="function","drawFunction must be a function"),o||(n=Ln(n),t=t.scale(q),e-=K),r.save(),r.translate(n.x+.5,n.y+.5),r.rotate(e),r.scale(s?-t.x:t.x,-t.y),i(r),r.restore()}function ih(n,t,e=1,s=V,i=0,o=st,r="center",a=Ps,c="",l,u=0,h=Tt){t=Ln(t),e*=q,i*=q,u-=K,u*=-1,on(n,t,e,s,i,o,r,a,c,l,u,h)}function on(n,t,e,s=V,i=0,o=st,r="center",a=Ps,c="",l,u=0,h=Tt){p(U(n),"text must be a string"),p(O(t),"pos must be a vec2"),p(P(e),"size must be a number"),p(J(s),"color must be a color"),p(P(i),"lineWidth must be a number"),p(J(o),"lineColor must be a color"),p(["left","center","right"].includes(r),"align must be left, center, or right"),p(U(a),"font must be a string"),p(U(c),"fontStyle must be a string"),p(P(u),"angle must be a number");let f=(n+"").split(`
+`),d=t.y-(f.length-1)*e/2;h.save(),h.fillStyle=s.toString(),h.strokeStyle=o.toString(),h.lineWidth=i,h.textAlign=r,h.font=c+" "+e+"px "+a,h.textBaseline="middle",h.translate(t.x,d),h.rotate(-u);let y=0;f.forEach(x=>{i&&h.strokeText(x,0,y,l),h.fillText(x,0,y,l),y+=e}),h.restore()}async function Ta(n,t){p(P(n),"textureIndex must be a number"),p(!un[n],"textureIndex is already loaded!"),p(!t||U(t),"image src must be a string");let e=new Image;t&&await new Promise(s=>{e.onerror=e.onload=s,e.crossOrigin="anonymous",e.src=t}),un[n]=new We(e)}function Ms(n){p(O(n),"screenPos must be a vec2");let t=(n.x-I.x/2+.5)/q,e=(n.y-I.y/2+.5)/-q;if(K){let s=ct(-K),i=nt(-K),o=t*s-e*i,r=t*i+e*s;t=o,e=r}return new rt(t+Ct.x,e+Ct.y)}function Ln(n){p(O(n),"worldPos must be a vec2");let t=n.x-Ct.x,e=n.y-Ct.y;if(K){let s=ct(K),i=nt(K),o=t*s-e*i,r=t*i+e*s;t=o,e=r}return new rt(t*q+I.x/2-.5,e*-q+I.y/2-.5)}function rc(n){p(O(n),"screenDelta must be a vec2");let t=n.x/q,e=n.y/-q;if(K){let s=ct(-K),i=nt(-K),o=t*s-e*i,r=t*i+e*s;t=o,e=r}return new rt(t,e)}function oh(n){p(O(n),"worldDelta must be a vec2");let t=n.x,e=n.y;if(K){let s=ct(K),i=nt(K),o=t*s-e*i,r=t*i+e*s;t=o,e=r}return new rt(t*q,e*-q)}function ks(n,t,e=0){return p(O(n),"screenPos must be a vec2"),p(O(t),"screenSize must be a vec2"),p(P(e),"screenAngle must be a number"),[Ms(n),t.scale(1/q),e+K]}function ac(){return I.scale(1/q)}function rh(n,t,e,s){p(O(n),"center must be a vec2"),p(O(t),"size must be a vec2");let i=f(e),o=f(s),r=t.x+i.left+i.right,a=t.y+i.top+i.bottom,c=I.x-o.left-o.right,l=I.y-o.top-o.bottom;if(!(r>0&&a>0&&c>0&&l>0))return q;q=Q(c/r,l/a);let u=b(i.right-i.left,i.top-i.bottom).scale(.5),h=b(o.right-o.left,o.top-o.bottom).scale(.5/q);return Ct=n.add(u).add(h),q;function f(d){return(d===void 0||P(d))&&(d=b(d)),O(d)?{top:d.y,right:d.x,bottom:d.y,left:d.x}:{top:d.top||0,right:d.right||0,bottom:d.bottom||0,left:d.left||0}}}function ah(n,t=0){if(p(O(n),"pos must be a vec2"),p(O(t)||P(t),"size must be a vec2 or number"),!q)return!1;let e=n.x-Ct.x,s=n.y-Ct.y;if(K){let r=ct(K),a=nt(K),c=e*r-s*a,l=e*a+s*r;e=c,s=l}e*=q*2,s*=-q*2,t instanceof rt&&(t=t.length()),t*=q;let i=I.x,o=I.y;return e+t>-i&&e-t-o&&s-t{n.onerror=n.onload=a,n.crossOrigin="anonymous",n.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAAAeAQMAAABnrVXaAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAAjpJREFUOMu9kzFu2zAUhn+CAROgqrk+B2l0BWYxMjlXeYaAtFtbdA1sGgHqRQfI0CNkSG5AwYB0BQ8d5Bsomwah6CPVeGg6tEPzAxLwyI+P78cP4u9lNO9OoMKnLMOobG5020/yaj/MrRcCGh1gBbyiLTPJEYaIiom5KM9Jq7KgynMGtb6L4GL4MF2H4LQKCXTvDVw2I4MsgZT7QLExdiutH+D08VOP3INXRrWX1/mmpbkNgAPYRVANb4xpcegYvhiNbIXauQICEjBuYLfMakaakWQeXxiZ0VDtuJCKs3ztMV59QtsHJNcRxDzfdL21ty3PrfIcXTN+E+GFAv6T5nbT9jd50/WFxb5ksdAv49qS6ouymG66ji08UMT6moykYLAo+V0j23GN4m829ZySAD5K7QsBfQTvOG8eE+gTeGYRAmnNAubN3hf5Zv9tJWDHp/VTuaSm7SN4fyINQqaNO3RMVxvpSPXnOChnRNvFcGY0gnwiPswYwTKVPE0zVtX3mTEIOoFzaqLrGuJaV+Uqumb71fVk/VoOH3cdLNQP/FHi8hV0CQNoqBZsUPlLPMsdCJro9QAaQQ0woDy9BJm0eTxCFnO9srcYlhNVlfR2EyTrph1uUtbUtAJifwRgrKuYdXVHeb0YI3QpawohQHkloI3J5FuVwI5ORxC9k2Tuz9Ir1IjgeIPGMHYkAZe2RuYkmWFmt3gGbTPOmBUWVTmRmHtGrfpzG/yuQNOKa6gBB/WA9khitPgl6/GP+gl2Af6tCbvaygAAAABJRU5ErkJggg=="});let t=b(),e=b(8),s=1,i=0,o=new We(n),r=new Pe(t,e,o,s,i);lc=new ii(r)}function fh(n=!0){jn=n}function ph(n){Cr=n}function gh(){return tn==="mouse"}function yh(){return tn==="keyboard"}function mh(){return tn==="gamepad"}function Er(n,t=0,e=!0,s=!0,i=!0){Y[t]&&(Y[t][n]&=~((e?1:0)|(s?2:0)|(i?4:0)))}function Gs(){Y.length=0,Y[0]=[],re.length=0,Cn.length=0,Fs.length=0,Se.length=0,gn.length=0}function Pt(n,t=0){var e;return p(U(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&1)}function kt(n,t=0){var e;return p(U(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&2)}function _r(n,t=0){var e;return p(U(n),"key must be a number or string"),p(t>0||typeof n!="number"||n<3,"use code string for keyboard"),!!(((e=Y[t])==null?void 0:e[n])&4)}function bh(n="ArrowUp",t="ArrowDown",e="ArrowLeft",s="ArrowRight"){p(U(n),"up key must be a string"),p(U(t),"down key must be a string"),p(U(e),"left key must be a string"),p(U(s),"right key must be a string");let i=o=>Pt(o)?1:0;return b(i(s)-i(e),i(n)-i(t))}function ls(n){return p(P(n),"mouse button must be a number"),Pt(n)}function gs(n){return p(P(n),"mouse button must be a number"),kt(n)}function xh(n){return p(P(n),"mouse button must be a number"),_r(n)}function Me(n,t=mt){return p(P(n),"button must be a number"),p(P(t),"gamepad must be a number"),Pt(n,t+1)}function Rr(n,t=mt){return p(P(n),"button must be a number"),p(P(t),"gamepad must be a number"),kt(n,t+1)}function vh(n,t=mt){return p(P(n),"button must be a number"),p(P(t),"gamepad must be a number"),_r(n,t+1)}function ys(n,t=mt){var e,s;return p(P(n),"stick must be a number"),p(P(t),"gamepad must be a number"),(s=(e=Se[t])==null?void 0:e[n])!=null?s:b()}function bo(n=mt){var t;return p(P(n),"gamepad must be a number"),(t=gn[n])!=null?t:b()}function xo(n=mt){return p(P(n),"gamepad must be a number"),!!Y[n+1]}function uc(n=mt){var t,e;return p(P(n),"gamepad must be a number"),(e=(t=Se[n])==null?void 0:t.length)!=null?e:0}function Sh(n=mt,t=200,e=1,s=1,i=0){var r,a,c;if(p(P(n),"gamepad must be a number"),!Ds||N)return;let o=(r=navigator==null?void 0:navigator.getGamepads)==null?void 0:r.call(navigator)[n];(c=(a=o==null?void 0:o.vibrationActuator)==null?void 0:a.playEffect)==null||c.call(a,"dual-rumble",{duration:t,strongMagnitude:e,weakMagnitude:s,startDelay:i})}function wh(n=mt){var e,s,i;if(p(P(n),"gamepad must be a number"),!Ds||N)return;let t=(e=navigator==null?void 0:navigator.getGamepads)==null?void 0:e.call(navigator)[n];(i=(s=t==null?void 0:t.vibrationActuator)==null?void 0:s.reset)==null||i.call(s)}function Pr(n=100){var t;p(P(n)||pe(n),"pattern must be a number or array"),Ds&&!N&&((t=navigator==null?void 0:navigator.vibrate)==null||t.call(navigator,n))}function Th(){Pr(0)}function Ah(){var n;!oe&&((n=G.requestPointerLock)==null||n.call(G))}function Ch(){var n;(n=document.exitPointerLock)==null||n.call(document)}function hc(){return document.pointerLockElement===G}function Eh(){if(N)return;document.addEventListener("keydown",n),document.addEventListener("keyup",t),document.addEventListener("mousedown",s),document.addEventListener("mouseup",i),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",r),document.addEventListener("wheel",a,{passive:!1}),document.addEventListener("contextmenu",c),document.addEventListener("blur",l),oe&&mn&&u();function n(f){if(f.repeat||(Y[0][f.code]=3,as&&(Y[0][e(f.code)]=3)),!jn||!f.cancelable||!document.hasFocus()||f.ctrlKey||f.metaKey||f.altKey||x(f.target)||x(document.activeElement))return;let d=typeof f.key=="string"&&f.key.length===1;(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Space","Tab","Backspace"].includes(f.code)||d)&&f.preventDefault();function x(v){let w=v==null?void 0:v.tagName;return(v==null?void 0:v.isContentEditable)||["INPUT","TEXTAREA","SELECT"].includes(w)}}function t(f){Y[0][f.code]=Y[0][f.code]&2|4,as&&(Y[0][e(f.code)]=4)}function e(f){return as?f==="KeyW"?"ArrowUp":f==="KeyS"?"ArrowDown":f==="KeyA"?"ArrowLeft":f==="KeyD"?"ArrowRight":f:f}function s(f){if(oe&&mn)return;Xt&&!N&&pt&&!bs()&&pt.resume(),Y[0][f.button]=3;let d=Ut;Ut=h(b(f.x,f.y)),ve=ve.add(Ut.subtract(d)),jn&&f.cancelable&&document.hasFocus()&&f.preventDefault()}function i(f){oe&&mn||(Y[0][f.button]=Y[0][f.button]&2|4)}function o(f){oi=!0;let d=Ut;Ut=h(b(f.x,f.y));let y=hc()?b(f.movementX,f.movementY):Ut.subtract(d);ve=ve.add(y)}function r(){oi=!1}function a(f){f.ctrlKey||(Ar+=se(f.deltaY)),jn&&f.cancelable&&document.hasFocus()&&f.preventDefault()}function c(f){f.preventDefault()}function l(){Gs(),Be.clear(),re.length=0,Cn.length=0,Fs.length=0}function u(){document.addEventListener("touchstart",y=>d(y),{passive:!1}),document.addEventListener("touchmove",y=>d(y),{passive:!1}),document.addEventListener("touchend",y=>d(y),{passive:!1});let f;function d(y){if(mn){if(Xt&&!N&&pt&&!bs()&&pt.resume(),!ln||mr){let x=S=>ms.includes(S.target)||S.target===yn,v=[];for(let S of y.touches)x(S)||v.push(S);let w=v.length,_=0;if(w){let S=b(v[0].clientX,v[0].clientY),E=Ut;Ut=h(S),f?ve=ve.add(Ut.subtract(E)):Y[0][_]=3}else f&&(Y[0][_]=Y[0][_]&2|4);f=w}return jn&&y.cancelable&&document.hasFocus()&&y.preventDefault(),!0}}}function h(f){let d=G.getBoundingClientRect(),y=jt(f.x,d.left,d.right),x=jt(f.y,d.top,d.bottom);return b(y*G.width,x*G.height)}}function Ca(){if(N)return;!(mn&&oe)&&!document.hasFocus()&&Gs(),Ie=Ms(Ut),Tr=rc(ve),Rh(),t(),n();function n(){let e=ls(0)||ls(1)||ls(2)||ve.length()>Cr,s=!1;for(let o=uc();o--&&!s;)s=ys(o).lengthSquared()>.04;for(let o=17;o--&&!s;)s=Me(o);let i=!1;for(let o in Y[0])if(isNaN(+o)&&Y[0][o]&1){i=!0;break}s?tn="gamepad":e?tn="mouse":i&&(tn="keyboard"),Bn=tn==="gamepad"}function t(){var r,a,c,l,u,h,f;let e=d=>{let v=w=>w>.3?jt(w,.3,.8):w<-.3?-jt(-w,.3,.8):0;return b(v(d.x),v(-d.y)).clampLength()};if(ln&&oe){if(p(!Rn||!Kn,"set touchGamepadLeftStick or touchGamepadLeftButtonCount, not both"),p(!Qn||!$n,"set touchGamepadRightStick or touchGamepadButtonCount, not both"),!Wn.isSet())return;mt=0;let d=(r=Se[0])!=null?r:Se[0]=[],y=(a=gn[0])!=null?a:gn[0]=b();d.length=0,y.set();for(let v=0;v<2;v++){if(!qe(v))continue;let w=Dr(v);d[w]=b();let _=(c=Cn[v])!=null?c:b();if(Os)d[w]=e(_);else if(_.lengthSquared()>.3){let S=F($s(_.x),-1,1),E=F($s(_.y),-1,1);d[w]=b(S,-E).clampLength(),w||y.set(S,-E)}}let x=(l=Y[1])!=null?l:Y[1]=[];for(let v=12;v--;){let w=Me(v,0);x[v]=re[v]?w?1:3:w?4:0,ti&&x[v]===3&&(v===9||Ph(v))&&Pr(ti)}return}try{if(!Mi||!(navigator!=null&&navigator.getGamepads))return}catch{return}if(!Ft&&!document.hasFocus())return;let s=8,i=navigator.getGamepads(),o=Q(s,i.length);for(let d=0;d>1]=e(b(y.axes[S],y.axes[S+1]));let _=!1;for(let S=y.buttons.length;S--;){let E=y.buttons[S],A=Me(S,d);x[S]=E.pressed?A?1:3:A?4:0,E.pressed&&(!E.value||E.value>.9)&&(_=!0)}_&&(co[d]=!0,co[mt]||(mt=d)),y.mapping==="standard"&&w.set((Me(15,d)&&1)-(Me(14,d)&&1),(Me(12,d)&&1)-(Me(13,d)&&1)),yr&&(w.x||w.y)&&(v[0]=w.clampLength())}ln&&Bn&&Wn.unset()}}function Ea(){if(!N){for(let n of Y)for(let t in n)n[t]&=1;Ar=0,Tr=b(),ve=b()}}function _h(){Ih()}function Rh(){if(Ke||!ln||!oe||N||!document.body)return;let n=Ke=document.createElement("div");n.style.cssText="position:fixed;inset:0;z-index:50;pointer-events:none;opacity:0;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-touch-callout:none;transition:opacity .2s;box-sizing:border-box;padding:env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)";let t=dc=document.createElement("div");t.style.cssText="position:relative;width:100%;height:100%;pointer-events:none",n.appendChild(t);let e=Lr=document.createElementNS(ai,"svg");e.style.cssText="position:absolute;inset:0;width:100%;height:100%;pointer-events:none;overflow:visible;fill:none;stroke:#fff;stroke-width:3",t.appendChild(e);let s=()=>{let i=document.createElement("div");return i.style.cssText="position:absolute;pointer-events:auto;touch-action:none",i.addEventListener("pointerdown",o=>Fh(o,i)),i.addEventListener("pointermove",o=>jh(o)),i.addEventListener("pointerup",o=>_a(o)),i.addEventListener("pointercancel",o=>_a(o)),t.appendChild(i),i};ms[0]=s(),ms[1]=s(),yn=s(),addEventListener("resize",()=>qn=!0),document.body.appendChild(n),qn=!0}function ki(){return dc.getBoundingClientRect()}function qe(n){return n?Qn:Rn}function On(n){return n?$n:Kn}function Or(n){return n?0:4}function Dr(n){return n&&Rn?1:0}function Hn(n){return qe(n)||On(n)>0}function Ph(n){for(let t=0;t<2;t++){let e=Or(t);if(!qe(t)&&n>=e&&no.style.cssText="position:absolute;pointer-events:auto;touch-action:none;"+r;if(Ce){for(let o of ms)o.style.display="none";ge?(i(yn,"inset:0"),yn.style.display=""):yn.style.display="none"}else{for(let r=0;r<2;r++){let a=ms[r],c=r?"right":"left";if(a.style.display=Hn(r)?"":"none",hn){let l=Hn(r?0:1)?"50%":"100%";i(a,`${c}:0;bottom:0;width:${l};height:60%`)}else i(a,`${c}:0;bottom:0;width:${3*s}px;height:${3*s}px`)}yn.style.display=ge?"":"none";let o=ge;i(yn,`left:50%;top:50%;width:${2*o}px;height:${2*o}px;transform:translate(-50%,-50%)`)}Oh(t,e),qn=!1}function Oh(n,t){let e=Lr;for(;e.firstChild;)e.removeChild(e.firstChild);let s=fc={face:[],thumb:[]},i=Ht,o=(a,c,l,u)=>{let h=document.createElementNS(ai,"circle");return h.setAttribute("cx",a),h.setAttribute("cy",c),h.setAttribute("r",l),u&&h.setAttribute("fill",u),e.appendChild(h),h},r=a=>{let c=i*.18,l=i*.5,u=a.x,h=a.y,f=document.createElementNS(ai,"path");f.setAttribute("d",`M ${u-c} ${h-l} H ${u+c} V ${h-c} H ${u+l} V ${h+c} H ${u+c} V ${h+l} H ${u-c} V ${h+c} H ${u-l} V ${h-c} H ${u-c} Z`),e.appendChild(f)};for(let a=0;a<2;a++){let c=On(a),l=Or(a),u=Je(a,n,t);if(qe(a))Os?o(u.x,u.y,i/2):r(u),s.thumb[a]=o(u.x,u.y,i/4,"#fff");else if(c===1)s.face[l]=o(u.x,u.y,i/2,"#000");else for(let h=0;h2?f:Q(f,c-1);d=d===3?2:d===2?3:d;let y=b().setDirection(f,i/2);c===2&&(y.x*=-1),a||(y.x*=-1);let x=u.add(y);s.face[l+d]=o(x.x,x.y,i/4,"#000")}}Ft&&Sn&&Dh(n,t)}function Dh(n,t){let e=Ht,s=Lr,i=(r,a,c)=>{let l=document.createElementNS(ai,r);for(let u in a)l.setAttribute(u,a[u]);l.setAttribute("stroke",c),l.setAttribute("stroke-width",2),l.setAttribute("fill","none"),s.appendChild(l)},o=(r,a,c)=>i("circle",{cx:r.x,cy:r.y,r:a},c);i("line",{x1:n/2,y1:0,x2:n/2,y2:t},"#0f0");for(let r=0;r<2;r++)if(qe(r))if(hn){let a=t*.4,c=!Hn(r?0:1),l=c?0:r?n/2:0;i("rect",{x:l,y:a,width:c?n:n/2,height:t-a},"#0ff")}else o(Je(r,n,t),2*e,"#0ff");else On(r)>=1&&o(Je(r,n,t),e,"#0ff");if(ge){o(b(n/2,t/2),ge,"#ff0");for(let r=0;r<2;r++)Hn(r)&&o(Je(r,n,t),2*e,"#f0f")}}function Ih(){var l;if(!Ke||N)return;if(!ln||!oe){Ke.style.display!=="none"&&(Ke.style.display="none",Be.clear(),re.length=0,Cn.length=0,Fs.length=0);return}Ke.style.display="";let n=Ft&&Sn,t=[$n,Kn,Rn,Qn,Os,Ht,hn,ge,Ce,n].join();t!==Aa&&(Aa=t,qn=!0),qn&&Lh();let e=cs?jt(Wn.get(),cs+1,cs):1,s=n||Wn.isSet()&&e>0&&!Ce;if(Ke.style.opacity=s?n?1:e*br:0,!s)return;let i=ki(),o=i.width,r=i.height,a=Ht,c=fc;if(c){for(let u=0;u<2;u++)if(qe(u)&&c.thumb[u]){let f=Je(u,o,r).add(((l=Cn[u])!=null?l:b()).scale(a/2));c.thumb[u].setAttribute("cx",f.x),c.thumb[u].setAttribute("cy",f.y)}for(let u=0;u=Ht)return-1;if(i===1)return o;let a=r.subtract(t);n||(a.x*=-1);let c=i===2?a.xo:a&&Je(r,t,e).distance(n)<2*s)return{role:"stick",side:r}}else if(On(r)>=1){let c=kh(r,n,t,e);if(c>=0)return{role:"face",btn:c}}}if(ge){for(let r=0;r<2;r++)if(Hn(r)&&Je(r,t,e).distance(n)<2*s)return;if(b(t/2,e/2).distance(n)h.getChannelData(v).set(x)),f.buffer=h,f.playbackRate.value=e,f.loop=i,r=r||pt.createGain(),r.gain.value=t,r.connect(Ue);let d=new StereoPannerNode(pt,{pan:F(s,-1,1)});f.connect(d).connect(r),f.addEventListener("ended",()=>{r.disconnect(),d.disconnect(),c&&c(f)});let y=a*e;return f.start(0,y),Ft&&Un&&xt("sound","vol",t.toFixed(2),"rate",e.toFixed(2),"pan",s.toFixed(2),i?"loop":""),f}function Jh(...n){return Ir([Gi(...n)])}function Gi(n=1,t=.05,e=220,s=0,i=0,o=.1,r=0,a=1,c=0,l=0,u=0,h=0,f=0,d=0,y=0,x=0,v=0,w=1,_=0,S=0,E=0){let A=Zn,T=X*2,R=c*=500*T/A/A,M=e*=(1+ft(t,-t))*T/A,Z=0,it=0,ht=0,gt=1,Nt,He=[],Ot=0,dt=0,Dt=0,Le,dn=2,fn=T*et(E)*2/A,ce=ct(fn),Oe=nt(fn)/2/dn,ee=1+Oe,L=-2*ce/ee,B=(1-Oe)/ee,j=(1+se(E)*ce)/2/ee,H=-(se(E)+ce)/ee,Bt=j,lt=0,le=0,It=0,zt=0;for(s=s*A||9,_*=A,i*=A,o*=A,v*=A,l*=500*T/A**3,y*=T/A,u*=T/A,h*=A,f=f*A|0,Nt=s+_+i+o+v|0;dt1?r>2?r>3?r>4?Ot/T%14?Dt:se(Dt)*et(Dt)**a)*(dtdt?0:(dth&&(e+=u,M+=u,gt=0),f&&!(++it%f)&&(e=M,c=R,gt||(gt=1));return He}function li(n,t=!0){for(let e of rn)if((!t||e.isSolid)&&n.arrayCheck(e.size)){let s=e.getCollisionData(n);if(s)return s}return 0}function Qe(n,t=b(),e,s=!0){for(let i of rn)if((!s||i.isSolid)&&i.collisionTest(n,t,e))return i}function yc(n,t,e,s,i=!0){let o,r,a,c=s&&b();for(let l of rn)if(!i||l.isSolid){let u=l.collisionRaycast(n,t,e,c);if(u){let h=n.distanceSquared(u);(o===void 0||h{k=!1,tt.style.display="none",e.preventDefault(),xt("WebGL context lost! Switching to Canvas2d rendering.");for(let s of us)s.glTexture=void 0;Zt=void 0,At=0,En=!1,xn.forEach(s=>{var i;return(i=s.glContextLost)==null?void 0:i.call(s)})}),tt.addEventListener("webglcontextrestored",()=>{k=!0,tt.style.display="",xt("WebGL context restored, reinitializing..."),t();for(let e of us)e.glTexture=ji(e.image,e.wrap);xn.forEach(e=>{var s;return(s=e.glContextRestored)==null?void 0:s.call(e)})});function t(){di=Yn(`#version 300 es
 precision highp float;uniform mat4 m;in vec2 g;in vec4 p,u,c,a;in float r;out vec2 v;out vec4 d,e;void main(){vec2 s=(g-.5)*p.zw;gl_Position=m*vec4(p.xy+s*cos(r)-vec2(-s.y,s)*sin(r),1,1);v=mix(u.xw,u.zy,g);d=c;e=a;}`,`#version 300 es
 precision highp float;uniform sampler2D s;in vec2 v;in vec4 d,e;out vec4 c;void main(){c=texture(s,v)*d+e;}`),fi=Yn(`#version 300 es
 precision highp float;uniform mat4 m;in vec2 p;in vec4 c;out vec4 d;void main(){gl_Position=m*vec4(p,1,1);d=c;}`,`#version 300 es
-precision highp float;in vec4 d;out vec4 c;void main(){c=d;}`);let e=new ArrayBuffer(gi);kt=new Float32Array(e),ws=new Uint32Array(e),So=g.createBuffer(),zn=g.createBuffer(),kr=g.createFramebuffer(),At=0;let s=new Float32Array([0,0,1,0,0,1,1,1]);g.bindBuffer(g.ARRAY_BUFFER,zn),g.bufferData(g.ARRAY_BUFFER,s,g.STATIC_DRAW);let i,o,r,a=(c,l,u,h,f=0)=>{let d=g.getAttribLocation(o,c),y=u===1,x=u&&r;g.enableVertexAttribArray(d),g.vertexAttribPointer(d,h,l,y,x,i),g.vertexAttribDivisor(d,f),i+=h*u};wo=g.createVertexArray(),g.bindVertexArray(wo),i=0,o=di,r=mc,g.bindBuffer(g.ARRAY_BUFFER,zn),a("g",g.FLOAT,0,2),g.bindBuffer(g.ARRAY_BUFFER,So),g.bufferData(g.ARRAY_BUFFER,gi,g.DYNAMIC_DRAW),a("p",g.FLOAT,4,4,1),a("u",g.FLOAT,4,4,1),a("c",g.UNSIGNED_BYTE,1,4,1),a("a",g.UNSIGNED_BYTE,1,4,1),a("r",g.FLOAT,4,1,1),To=g.createVertexArray(),g.bindVertexArray(To),i=0,o=fi,r=bc,a("p",g.FLOAT,4,2),a("c",g.UNSIGNED_BYTE,1,4)}}function Ts(n=!1){!n&&!En||(Et(),En=!1,g.useProgram(di),g.bindVertexArray(wo))}function xc(){En||(Et(),En=!0,g.useProgram(fi),g.bindVertexArray(To))}function Co(n=!0){if(!k||!g)return;p(!At,"glPreRender called with unflushed batch."),pi||(tt.width=I.x,tt.height=I.y),g.viewport(0,0,I.x,I.y),n&&vc();let t=b(2*q).divide(I);pi&&(t.y=-t.y);let e=Ct.rotate(-K),s=b(-1).subtract(e.multiply(t)),i=at(K),o=nt(K),r=[t.x*i,t.y*o,0,0,-t.x*o,t.y*i,0,0,1,1,1,0,s.x,s.y,0,1],a=(c,l,u)=>{g.useProgram(c);let h=g.getUniformLocation(c,l);g.uniformMatrix4fv(h,!1,u)};a(fi,"m",r),a(di,"m",r),g.activeTexture(g.TEXTURE0),un[0]&&(Qt=un[0].glTexture,g.bindTexture(g.TEXTURE_2D,Qt)),g.bindBuffer(g.ARRAY_BUFFER,So),Dn=Xn=!1,Ts(!0)}function vc(){if(!g)return;let n=nn;g.clearColor(n.r,n.g,n.b,n.a),g.clear(g.COLOR_BUFFER_BIT)}function Fr(n){!g||n===Qt||(Et(),Qt=n,g.bindTexture(g.TEXTURE_2D,Qt))}function Sc(n,t=!0){if(!g||!n)return;let e=n===Qt;e?Et():g.bindTexture(g.TEXTURE_2D,n);let s=t?g.REPEAT:g.CLAMP_TO_EDGE;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,s),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,s),!e&&Qt&&g.bindTexture(g.TEXTURE_2D,Qt)}function Eo(n,t){if(!g)return;let e=g.createShader(t);if(g.shaderSource(e,n),g.compileShader(e),Gt&&!g.getShaderParameter(e,g.COMPILE_STATUS))throw g.getShaderInfoLog(e);return e}function Yn(n,t){if(!g)return;let e=g.createProgram();if(g.attachShader(e,Eo(n,g.VERTEX_SHADER)),g.attachShader(e,Eo(t,g.FRAGMENT_SHADER)),g.linkProgram(e),Gt&&!g.getProgramParameter(e,g.LINK_STATUS))throw g.getProgramInfoLog(e);return e}function ji(n,t=!1){if(!g)return;let e=g.createTexture(),s=!1;if(n!=null&&n.width)jr(e,n),g.bindTexture(g.TEXTURE_2D,e),s=!An&&ds(n.width)&&ds(n.height);else{let a=new Uint8Array([255,255,255,255]);g.bindTexture(g.TEXTURE_2D,e),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,1,1,0,g.RGBA,g.UNSIGNED_BYTE,a)}let i=An?g.NEAREST:g.LINEAR,o=s?g.LINEAR_MIPMAP_LINEAR:i;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,i),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,o);let r=t?g.REPEAT:g.CLAMP_TO_EDGE;return g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,r),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,r),s&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,Qt),e}function wc(n){g&&g.deleteTexture(n)}function jr(n,t){g&&(p((t==null?void 0:t.width)>0,"Invalid image data."),g.bindTexture(g.TEXTURE_2D,n),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,t),!An&&ds(t.width)&&ds(t.height)&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,Qt))}function Hh(n){N||(us.add(n),g&&(n.glTexture?jr(n.glTexture,n.image):n.glTexture=ji(n.image,n.wrap)))}function Xh(n){if(N)return;us.delete(n);let t=n.glTexture;n.glTexture=void 0,wc(t)}function Et(){if(k&&g&&At){let n=Xn?g.ONE:g.ONE_MINUS_SRC_ALPHA;g.blendFuncSeparate(g.SRC_ALPHA,n,g.ONE,n),g.enable(g.BLEND);let t=At*(En?Fi:Gr);g.bufferSubData(g.ARRAY_BUFFER,0,kt,0,t),En?g.drawArrays(g.TRIANGLE_STRIP,0,At):g.drawArraysInstanced(g.TRIANGLE_STRIP,0,4,At),++_e,Re+=At,At=0}Xn=Dn}function Nr(n){!k||!g||(Et(),n.drawImage(tt,0,0))}function Yh(n=!0){p(!tt,"must be called before engineInit"),Mr=n}function As(n,t,e,s,i=0,o=0,r=0,a=1,c=1,l=-1,u=0){(At>=Wh||Xn!==Dn)&&Et(),Ts();let h=At++*Gr;kt[h++]=n,kt[h++]=t,kt[h++]=e,kt[h++]=s,kt[h++]=o,kt[h++]=r,kt[h++]=a,kt[h++]=c,ws[h++]=l,ws[h++]=u,kt[h++]=i}function Tc(n,t,e,s,i,o){As(n,t,e,s,i,0,0,0,0,0,o)}function Br(n,t,e,s,i,o,r,a=!0){let c=[],l=nt(-r),u=at(-r);for(let f of n){let d=f.x*i,y=f.y*o;c.push(b(e+u*d-l*y,s+l*d+u*y))}let h=a?Kh(c):c;Ac(h,t)}function zr(n,t,e,s,i,o,r,a,c=!0){let l=$h(n,e,c);Br(l,t,s,i,o,r,a,!1)}function Ac(n,t){if(!k||n.length<3)return;let e=n.length+2;if((At+e>=Jn||Xn!==Dn)&&Et(),p(e=Jn)return;xc();let s=At*Fi;for(let i=e;i--;){let o=F(i-1,0,e-3),r=n[o];kt[s++]=r.x,kt[s++]=r.y,ws[s++]=t}At+=e}function Jr(n,t){if(!k||n.length<3)return;let e=n.length+2;if((At+e>=Jn||Xn!==Dn)&&Et(),p(e=Jn)return;xc();let s=At*Fi;for(let i=e;i--;){let o=F(i-1,0,e-3),r=n[o],a=t[o];kt[s++]=r.x,kt[s++]=r.y,ws[s++]=a}At+=e}function os(n,t=!1){n?(pi=n,g.bindFramebuffer(g.FRAMEBUFFER,kr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,n,0),Co(t)):(Et(),pi=void 0,g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,I.x,I.y))}function Cc(n,t,e,s){k&&(g.enable(g.SCISSOR_TEST),g.scissor(n,t,e,s),g.clearColor(0,0,0,0),g.clear(g.COLOR_BUFFER_BIT),g.disable(g.SCISSOR_TEST))}function $h(n,t,e=!0){if(n.length<2)return[];let s=t/2,i=[],o=n.length,r=1e-6,a=10;for(let c=0;cr?-d/y:0,S=y>r?f/y:0,E=w>r?-v/w:0,A=w>r?x/w:0,T=_+E,R=S+A,M=(T*T+R*R)**.5;if(Mr){let gt=Q(1/ht,a);T*=gt,R*=gt}}let Z=b(u.x-T*s,u.y-R*s),it=b(u.x+T*s,u.y+R*s);i.push(Z),i.push(it)}return i.length>1&&e&&(i.push(i[0]),i.push(i[1])),i}function Kh(n){if(n.length<3)return[];let t=(d,y,x)=>(y.x-d.x)*(x.y-d.y)-(y.y-d.y)*(x.x-d.x);(d=>{let y=0;for(let x=d.length;x--;){let v=(x+1)%d.length;y+=d[x].cross(d[v])}return y})(n)<0&&(n=n.slice().reverse());let s=1e-9,i=(d,y,x,v)=>{let w=t(y,x,d),_=t(x,v,d),S=t(v,y,d),E=(w<-s?1:0)+(_<-s?1:0)+(S<-s?1:0),A=(w>s?1:0)+(_>s?1:0)+(S>s?1:0);return!(E&&A)},o=[];for(let d=0;d3&&a++{if(E>=0){let T=s.fillStyle=s.createLinearGradient(v,w,_,S);T.addColorStop(0,h(E,2)),T.addColorStop(1,h(E,1))}else s.fillStyle="#000";E>=-1?(s.fill(),A&&s.stroke()):s.stroke()},c=(v,w,_,S=0,E=2*X,A,T)=>{s.beginPath(),s.arc(v,w,_,d*S,d*E),a(v,w-_,v,w+_,A,T)},l=(v,w,_,S,E)=>{s.beginPath(),s.rect(v,w,_,S*d),a(v,w+S,v+_,w,E)},u=(v,w,_,S)=>{s.beginPath();for(let E of v)s.lineTo(E.x,E.y);s.closePath(),a(0,_,0,_+S,w)},h=(v,w)=>w?`hsl(${[.95,.56,.13][v%3]*360} 99%${[0,50,75][w]}%)`:"#000",f=Wa(1,1,n),d=Ft(f,.1,.5),y=Q(6,Q(o,r)/99);s.translate(o/2,r/2),s.scale(y,y),s.translate(-40,-35),d<1&&s.setLineDash([99*d,99]),s.lineJoin=s.lineCap="round",s.lineWidth=.1+d*1.9;{let w="LittleJS";s.font="900 15.5px arial",s.lineWidth=.1+d*3.9,s.textAlign="center",s.textBaseline="top",l(11,55,59,8*d,-1),s.beginPath();let _=0;for(let S=0;S5?1:0),s[S?"strokeText":"fillText"](w[E],R,54+.5,17*d),A+=T}s.lineWidth=.1+d*1.9,l(3,54,73,0)}l(7,15,26,-7,0),l(25,15,8,25,-1),l(10,40,15,-25,1),l(14,21,7,9,2),l(38,20,6,-6,2),l(49,20,10,-6,0);let x=[b(44,8),b(64,8),b(59,8+6*d),b(49,8+6*d)];u(x,2,8,6*d),l(44,8,20,-7,0);for(let v=5;v--;)c(59-v*6*d,30,10,0,2*X,1,0);c(59,30,4,0,7,2),l(35,20,24,0),c(59,30,10),c(47,30,10,X/2,X*3/2),c(35,30,10,X/2,X*3/2),l(7,40,13,7,-1),l(17,40,43,14,-1);for(let v=3;v--;)for(let w=2;w--;)c(17+15*v,47,w?7:1,0,2*X,2);for(let v=2;v--;){let w=6,_=7,S=53+w*d*v,E=[b(S+_,54),b(S,40),b(S+w*d,40),b(S+_+w*d,54)];u(E,0,40,14)}s.restore()}function Zh(n){if(bi=n,!pn){let e={};try{e=JSON.parse(localStorage[n]||"{}")}catch{e={}}Ni(s=>{s.unlocked=!!(e[s.id]&&e[s.id].unlocked)}),Vr()}_n(void 0,t);function t(){if(!qs.length)return;let e=qs[0],s=an-Ws;if(!Ws)Ws=an;else if(s>yi)Ws=0,qs.shift();else{let i=yi-Nn,o=si?(s-i)/Nn:0;e.render(o)}}}function Ni(n){Object.values(Cs).forEach(t=>n(t))}function td(){Ni(n=>n.unlocked=!1),Vr()}function Vr(){if(!bi)return;let n={};Ni(t=>{let e={name:t.name,description:t.description,icon:t.icon,unlocked:t.unlocked};t.image&&(e.src=t.image.src),n[t.id]=e}),localStorage[bi]=JSON.stringify(n)}function ed(n){yi=n}function nd(n){Nn=n}function sd(n){mi=n.copy()}function id(n){Ur=n}function Ec(n,t,e,s=125){let i,o,r,a,c,l,u,h,f,d,y,x,v,w=0,_,S=[],E=[],A=[],T=0,R=0,M=1,Z={},it=Zn/s*60>>2;for(;M;T++)S=[M=h=x=0],e.forEach((ht,gt)=>{for(u=t[ht][T]||[0,0,0],M|=t[ht][T]&&1,_=x+(t[ht][0].length-2-(h?0:1))*it,v=gt===e.length-1,i=2,r=x;iit-99&&f&&y<1?y+=1/99:0)l=(1-y)*S[w++]/2||0,E[r]=(E[r]||0)-l*R+l,A[r]=(A[r++]||0)+l*R+l;c&&(y=c%1,R=u[1]||0,(c|=0)&&(S=Z[[d=u[w=0]||0,c]]=Z[[d,c]]||(a=[...n[d]],a[2]=(a[2]||220)*2**(c/12-1),c>0?Gi(...a):[])))}x=_});return[E,A]}function od(n){Wr=typeof n=="boolean"?n?1:0:n}function rd(n){qr=n}async function ad(){return new Ai(await Box2D()),e(),_n(n,t),m;function n(){if(!Ce){m.step(),m.objects=m.objects.filter(s=>!s.destroyed);for(let s of m.objects)s.body&&(s.pos=m.vec2From(s.body.GetPosition()),s.angle=-s.body.GetAngle())}}function t(){(qr||de)&&m.world.DrawDebugData()}function e(){let i=new m.instance.JSDraw,o=l=>new wt(l.get_r(),l.get_g(),l.get_b()),r=l=>o(m.instance.wrapPointer(l,m.instance.b2Color)),a=l=>r(l).scale(1,.8),c=(l,u)=>{let h=[];for(let f=u;f--;)h.push(m.vec2FromPointer(l+f*8));return h};i.DrawSegment=function(l,u,h){h=a(h),l=m.vec2FromPointer(l),u=m.vec2FromPointer(u),bn(l,u,.1,h,b(),0,!1)},i.DrawPolygon=function(l,u,h){h=a(h);let f=c(l,u);Vn(f,cn,.1,h,b(),0,!1)},i.DrawSolidPolygon=function(l,u,h){h=a(h);let f=c(l,u);Vn(f,h,0,h,b(),0,!1)},i.DrawCircle=function(l,u,h){h=a(h),l=m.vec2FromPointer(l),si(l,u*2,cn,.1,h,!1)},i.DrawSolidCircle=function(l,u,h,f){f=a(f),l=m.vec2FromPointer(l),h=m.vec2FromPointer(h).scale(u),si(l,u*2,f,.1,f,!1),bn(b(),h,.1,f,l,0,!1)},i.DrawTransform=function(l){l=m.instance.wrapPointer(l,m.instance.b2Transform);let u=m.vec2From(l.get_p()),h=-l.get_q().GetAngle(),f=b(1,0),d=z(.75,0,0,.8),y=b(0,1),x=z(0,.75,0,.8);bn(b(),f,.1,d,u,h,!1),bn(b(),y,.1,x,u,h,!1)},i.AppendFlags(m.instance.b2Draw.e_shapeBit),i.AppendFlags(m.instance.b2Draw.e_jointBit),m.world.SetDebugDraw(i)}}function cd(n,t,e,s=32,i=2,o=0){_c(n,t,e,V,s,st,i,o,!1,!0)}function _c(n,t,e,s,i=1,o,r=.05,a=0,c=k,l,u){let h=e.offset(e.size),f=t.add(b(r-i*2)),d=b(i),y=t.scale(.5).subtract(d.scale(.5)),x=l?-1:1,v=l?-a:a;Pt(n,f,h,s,a,!1,o,c,l,u);for(let w=4;w--;){let _=w%2,S=y.multiply(b(_?w===1?1:-1:0,_?0:w?-1:1)),E=b(_?i:f.x,_?f.y:i),A=h.offset(e.size.multiply(b(w===1?1:w===3?-1:0,w===0?-x:w===2?x:0)));Pt(n.add(S.rotate(v)),E,A,s,a,!1,o,c,l,u)}for(let w=4;w--;){let _=w>1,S=w&&w<3,E=y.multiply(b(_?-1:1,S?-1:1)),A=h.offset(e.size.multiply(b(_?-1:1,S?x:-x)));Pt(n.add(E.rotate(v)),d,A,s,a,!1,o,c,l,u)}}function ld(n,t,e,s=32,i=2,o=0){Rc(n,t,e,V,s,st,i,o,!1,!0)}function Rc(n,t,e,s,i=1,o,r=.05,a=0,c=k,l,u){let h=e.frame(0),f=e.frame(1),d=e.frame(2),y=t.add(b(r-i*2)),x=b(i),v=t.scale(.5).subtract(x.scale(.5)),w=l?-1:1,_=l?-a:a;Pt(n,y,d,s,a,!1,o,c,l,u);for(let S=4;S--;){let E=a+S*X/2,A=S%2,T=v.multiply(b(A?S===1?1:-1:0,A?0:S?-w:w)),R=b(A?y.y:y.x,i);Pt(n.add(T.rotate(_)),R,f,s,E,!1,o,c,l,u)}for(let S=4;S--;){let E=a+S*X/2,A=!S||S>2,T=S>1,R=v.multiply(b(A?-1:1,T?-w:w));Pt(n.add(R.rotate(_)),x,h,s,E,!1,o,c,l,u)}}function ud(n,t=1,e=0,s=V,i=0,o=!1,r=0,a=st,c=k,l=!1,u){let h=Pc(b(),t,e,0,o);Vn(h,s,r,a,n,i,c,l,u)}function Pc(n,t=1,e=0,s=0,i=!1,o=Ls){p(O(n),"pos must be a vec2"),p(P(t)&&P(e),"size and percent must be numbers");let r=ie(e*4,4);r>=2&&(s+=X),r=r<=2?r-1:3-r,i&&(r=-r,s+=X);let a=[],c=$(3,o>>1),l=t/2;for(let u=0;u<=c;u++){let h=u/c*X;a.push(b(l*at(h),l*nt(h)).rotate(s).add(n))}for(let u=c;u>=0;u--){let h=u/c*X;a.push(b(l*at(h),-l*r*nt(h)).rotate(s).add(n))}return a}function La(n){return n&&typeof n.lerp=="function"}function hd(n,t,e,s,i=1,o={}){p(n!=null&&typeof n=="object","tweenProperty target must be an object"),p(U(t)&&t.length>0,"tweenProperty propertyPath must be a non-empty string");let r=t.split("."),a=r.pop(),c=l=>{let u=n;for(let h of r)u=u[h];u[a]=l};return new Ci(c,e,s,i,o)}function Lc(n){n.loopRemaining!==1/0&&n.loopRemaining<=1||(n.loopRemaining!==1/0&&(n.loopRemaining-=1),n.life=n.duration,n.thenCallback=()=>Lc(n),$t.push(n),n.callback(n.interp(n.duration)))}function Oc(n){if(n.loopRemaining!==1/0&&n.loopRemaining<=1)return;n.loopRemaining!==1/0&&(n.loopRemaining-=1);let t=n.start;n.start=n.end,n.end=t,n.life=n.duration,n.thenCallback=()=>Oc(n),$t.push(n),n.callback(n.interp(n.duration))}function Dc(n,t){n===void 0?(n=Kt-Ra,t=an-Pa,Ra=Kt,Pa=an):t===void 0&&(t=n);for(let e=$t.length;e--;){let s=$t[e];if(s.paused)continue;let i=s.useRealTime?t:n;if(!(i<=0))if(s.life-=i,s.life>0)s.callback(s.interp(s.life));else{s.callback(s.interp(0)),$t.splice(e,1);let o=s.thenCallback;s.thenCallback=void 0,o&&o()}}}function dd(){for(let n of $t)n.thenCallback=void 0;$t.length=0}var Hs,Xs,El,tr,vt,er,Oa,Kt,an,Ce,ao,xe,Ys,Da,xn,uo,Gt,ka,Ri,Ga,Me,en,de,fe,vn,Sn,Un,ho,ke,he,X,et,St,hs,$s,Q,$,se,Ba,za,nt,at,Ja,sr,go,ot,wt,V,cn,st,ye,Vl,rr,Wl,Ka,Qa,ql,Za,tc,Hl,Ee,Ct,K,q,cr,Pi,nn,kn,rs,Gn,Fn,lr,An,sn,Ps,ur,N,k,Ls,Li,Oi,Di,Ii,hr,dr,fr,pr,gr,Fe,Vt,Zs,Mi,yr,as,mn,ln,mr,ge,$n,Rn,Kn,Qn,Os,hn,qt,br,cs,ti,Ds,Ht,wn,xr,vr,Ue,G,ut,Tt,Be,Ze,we,je,I,un,_e,Re,Pe,Ve,nh,lc,ii,De,Jt,Tr,ve,Ar,oi,Bn,tn,Cr,jn,mt,oe,Y,Se,gn,co,Wn,re,Cn,ri,Fs,Ne,Ke,dc,Lr,fc,ms,yn,qn,Aa,ai,pt,Je,Zn,xs,ci,rn,Tn,ui,vs,Ss,vo,Vh,hi,tt,g,Mr,di,fi,En,Dn,Xn,Qt,So,zn,kt,ws,At,us,wo,To,kr,pi,Ao,gi,Gr,mc,Wh,Fi,bc,Jn,pn,yi,Nn,mi,Ur,Cs,qs,bi,Ws,xi,Es,_o,Ro,It,Po,W,Lo,Oo,Do,C,Wr,Io,ae,vi,Mo,ko,_s,Go,Fo,jo,No,m,qr,Rs,Si,Bo,zo,wi,Xt,Jo,Ti,Uo,Vo,Wo,qo,Ho,Xo,Yo,$o,Ko,Qo,Ai,$t,Ra,Pa,Ci,Ei,fd,lo,_i,Zo,Mc=jc(()=>{"use strict";Hs="LittleJS",Xs="1.18.19",El=60,tr=.016666666666666666,vt=[],er=[],Oa=0,Kt=0,an=0,Ce=!1;ao=0,xe=0,Ys=0,Da=!0,xn=[],uo=class{constructor(t,e,s,i){this.update=t,this.render=e,this.glContextLost=s,this.glContextRestored=i}};Gt=!0,ka=.5,Ri=!0,Ga="Escape",Me=!1,en=[],de=!1,fe=!1,vn=!1,Sn=!1,Un=!1;X=Math.PI,et=Math.abs,St=Math.floor,hs=Math.ceil,$s=Math.round,Q=Math.min,$=Math.max,se=n=>Math.sign(n),Ba=(...n)=>Math.hypot(...n),za=n=>Math.log2(n),nt=Math.sin,at=Math.cos,Ja=Math.tan,sr=Math.atan2;go=class{constructor(t=123456789){p(t!==0,"RandomGenerator seed must be non-zero (xorshift is fixed at 0)"),this.seed=t}float(t=1,e=0){return this.seed^=this.seed<<13,this.seed^=this.seed>>>17,this.seed^=this.seed<<5,e+(t-e)*((this.seed>>>0)/2**32)}int(t,e=0){return St(this.float(t,e))}bool(t=.5){return this.float().5?1:-1}floatSign(t=1,e=0){let s=Q(t,e),o=$(t,e)-s,r=this.float(o*2);return rt?this.scale(t/e):this.copy()}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}reflect(t,e=1){return this.subtract(t.scale((1+e)*this.dot(t)))}angle(){return sr(this.x,this.y)}setAngle(t=0,e=1){return Yt(t),Yt(e),this.x=e*nt(t),this.y=e*at(t),this}rotate(t){Yt(t);let e=at(-t),s=nt(-t);return new n(this.x*e-this.y*s,this.x*s+this.y*e)}setDirection(t,e=1){return Yt(t),Yt(e),t=ie(t,4),p(t===0||t===1||t===2||t===3,"Vector2.setDirection() direction must be an integer between 0 and 3."),this.x=t%2?t-1?-e:e:0,this.y=t%2?0:t?-e:e,this}direction(){return et(this.x)>et(this.y)?this.x<0?3:1:this.y<0?2:0}abs(){return new n(et(this.x),et(this.y))}floor(){return new n(St(this.x),St(this.y))}snap(t){return Yt(t),new n(St(this.x*t)/t,St(this.y*t)/t)}mod(t=1){return new n(ie(this.x,t),ie(this.y,t))}area(){return et(this.x*this.y)}lerp(t,e){wa(t),Yt(e);let s=F(e);return new n(t.x*s+this.x*(1-s),t.y*s+this.y*(1-s))}arrayCheck(t){return this.x>=0&&this.y>=0&&this.x(u=ie(u,1))*6<1?c+(l-c)*6*u:u*2<1?l:u*3<2?c+(l-c)*(4-u*6):c;return this.r=a(r,o,t+1/3),this.g=a(r,o,t),this.b=a(r,o,t-1/3),this.a=i,is(this),this}HSLA(){let t=F(this.r),e=F(this.g),s=F(this.b),i=F(this.a),o=$(t,e,s),r=Q(t,e,s),a=(o+r)/2,c=0,l=0;if(o!==r){let u=o-r;l=a>.5?u/(2-o-r):u/(o+r),t===o?c=(e-s)/u+(e((s=F(s)*255|0)<16?"0":"")+s.toString(16);return"#"+e(this.r)+e(this.g)+e(this.b)+(t?e(this.a):"")}setHex(t){if(p(U(t),"Color hex code must be a string"),p(t[0]==="#","Color hex code must start with #"),p([4,5,7,9].includes(t.length),"Invalid hex"),t.length<6){let e=s=>F(parseInt(t[s],16)/15);this.r=e(1),this.g=e(2),this.b=e(3),this.a=t.length===5?e(4):1}else{let e=s=>F(parseInt(t.slice(s,s+2),16)/255);this.r=e(1),this.g=e(3),this.b=e(5),this.a=t.length===9?e(7):1}return is(this),this}rgbaInt(){let t=F(this.r)*255|0,e=F(this.g)*255<<8,s=F(this.b)*255<<16,i=F(this.a)*255<<24;return t+e+s+i}isValid(){return P(this.r)&&P(this.g)&&P(this.b)&&P(this.a)}},V=Zt(z()),cn=Zt(z(1,1,1,0)),st=Zt(z(0,0,0)),ye=Zt(z(0,0,0,0)),Vl=Zt(z(.5,.5,.5)),rr=Zt(z(1,0,0)),Wl=Zt(z(1,.5,0)),Ka=Zt(z(1,1,0)),Qa=Zt(z(0,1,0)),ql=Zt(z(0,1,1)),Za=Zt(z(0,0,1)),tc=Zt(z(.5,0,1)),Hl=Zt(z(1,0,1)),Ee=class{constructor(t,e=!1){p(t===void 0||P(t),"Constructed Timer is invalid.",t),this.useRealTime=e;let s=this.getGlobalTime();this.time=t===void 0?void 0:s+t,this.setTime=t}set(t=0){p(P(t),"Timer is invalid.",t);let e=this.getGlobalTime();this.time=e+t,this.setTime=t}setUseRealTime(t=!0){p(!this.isSet(),"Cannot change global time setting while timer is set."),this.useRealTime=t}unset(){this.time=void 0}isSet(){return this.time!==void 0}active(){return this.getGlobalTime()=this.time}get(){return this.isSet()?this.getGlobalTime()-this.time:0}getPercent(){return this.isSet()?this.setTime?1-Ft(this.time-this.getGlobalTime(),0,this.setTime):1:0}getSetTime(){return this.isSet()?this.setTime:0}getGlobalTime(){return this.useRealTime?an:Kt}toString(){return this.isSet()?et(this.get())+" seconds "+(this.get()<0?"before":"after"):"unset"}valueOf(){return this.get()}};Ct=b(),K=0,q=32,cr=1,Pi=!0,nn=ye,kn=b(1920,1080),rs=0,Gn=0,Fn=b(),lr=!1,An=!0,sn=1,Ps="arial",ur=!1,N=!1,k=!0,Ls=32,Li=b(16),Oi=0,Di=0,Ii=!0,hr=1,dr=1,fr=1,pr=0,gr=.8,Fe=1,Vt=b(),Zs=1,Mi=!0,yr=!0,as=!0,mn=!0,ln=!1,mr=!1,ge=0,$n=4,Rn=!0,Kn=0,Qn=!1,Os=!0,hn=!1,qt=100,br=.3,cs=3,ti=0,Ds=!0,Ht=!0,wn=.3,xr=40,vr=.7;Ue=class n{constructor(t=b(),e=b(1),s,i=0,o=V,r=0){p(O(t),"object pos must be a vec2"),p(O(e),"object size must be a vec2"),p(!s||s instanceof Pe,"object tileInfo should be a TileInfo or undefined"),p(typeof i=="number"&&isFinite(i),"object angle should be a number"),p(J(o),"object color should be a valid rgba color"),p(typeof r=="number","object renderOrder should be a number"),this.pos=t.copy(),this.size=e.copy(),this.drawSize=void 0,this.tileInfo=s,this.angle=i,this.color=o.copy(),this.additiveColor=void 0,this.mirror=!1,this.destroyed=!1,this.mass=hr,this.damping=dr,this.angleDamping=fr,this.restitution=pr,this.friction=gr,this.gravityScale=1,this.renderOrder=r,this.velocity=b(),this.angleVelocity=0,this.spawnTime=Kt,this.children=[],this.clampSpeed=!0,this.groundObject=void 0,this.parent=void 0,this.localPos=b(),this.localAngle=0,this.collideTiles=!1,this.collideSolidObjects=!1,this.isSolid=!1,this.collideRaycast=!1,vt.push(this)}updateTransforms(){let t=this.parent;if(t){let e=t.getMirrorSign(),s=this.localPos,i=t.pos,o=s.x*e,r=s.y,a=t.angle;if(a){let c=at(-a),l=nt(-a);this.pos.set(o*c-r*l+i.x,o*l+r*c+i.y)}else this.pos.set(o+i.x,r+i.y);this.angle=e*this.localAngle+a}for(let e of this.children)e.updateTransforms()}updatePhysics(){if(p(!this.parent),this.destroyed)return;this.clampSpeed&&(this.velocity.x=F(this.velocity.x,-Fe,Fe),this.velocity.y=F(this.velocity.y,-Fe,Fe));let t=this.pos.copy();if(this.velocity.x*=this.damping,this.velocity.y*=this.damping,this.mass&&(this.velocity.x+=Vt.x*this.gravityScale,this.velocity.y+=Vt.y*this.gravityScale),this.pos.x+=this.velocity.x,this.pos.y+=this.velocity.y,this.angle+=this.angleVelocity*=this.angleDamping,p(this.angleDamping>=0&&this.angleDamping<=1),p(this.damping>=0&&this.damping<=1),!Ii||!this.mass)return;let e=this.velocity.y<0&&Vt.y<0||this.velocity.y>0&&Vt.y>0;if(this.groundObject){let s=$(this.friction,this.groundObject.friction),i=this.groundObject.velocity.x;this.velocity.x=i+(this.velocity.x-i)*s,this.groundObject=void 0}if(this.collideSolidObjects)for(let i of er){if(i.destroyed||i.parent||i===this||!this.isSolid&&!i.isSolid||!this.isOverlappingObject(i))continue;let o=this.collideWithObject(i),r=i.collideWithObject(this);if(!o||!r)continue;if(Qs(t,this.size,i.pos,i.size)){let f=t.subtract(i.pos),d=f.length(),x=d<.001?b(0,1):f.scale(.001/d);this.velocity=this.velocity.add(x),i.mass&&(i.velocity=i.velocity.subtract(x)),de&&fo(this.pos,this.size,i.pos,i.size,"#f00");continue}let a=this.size.add(i.size),c=(t.y-i.pos.y)*2>a.y+Vt.y,l=et(t.y-i.pos.y)*20?-1:1)>0?St(t.y-this.size.y/2+1)+this.size.y/2+.001:hs(t.y+this.size.y/2-1)-this.size.y/2-.001;if(et(u-this.pos.y)<.1&&!Qe(b(this.pos.x,u),this.size,this)){this.pos.y=u,de&&bt(this.pos,this.size,"#ff0");return}this.pos.x=t.x,this.velocity.x*=-r}if(o||!i){if(e){let c=this.size.y/2+1e-4;this.pos.y=Vt.y<0?St(t.y-this.size.y/2)+c:hs(t.y+this.size.y/2)-c,this.groundObject=s}else this.pos.y=t.y,this.groundObject=void 0;this.velocity.y*=-r}de&&bt(this.pos,this.size,"#f00")}}}update(){}render(){Pt(this.pos,this.drawSize||this.size,this.tileInfo,this.color,this.angle,this.mirror,this.additiveColor)}renderLight(){}destroy(t=!1){var e;if(!this.destroyed){this.destroyed=!0,(e=this.parent)==null||e.removeChild(this);for(let s of this.children)s.parent=void 0,s.destroy(t)}}localToWorld(t){return this.pos.add(t.rotate(this.angle))}worldToLocal(t){return t.subtract(this.pos).rotate(-this.angle)}localToWorldVector(t){return t.rotate(this.angle)}worldToLocalVector(t){return t.rotate(-this.angle)}collideWithTile(t,e){return t>0}collideWithObject(t){return!0}getUp(t=1){return b().setAngle(this.angle,t)}getRight(t=1){return b().setAngle(this.angle+X/2,t)}getAliveTime(){return Kt-this.spawnTime}getSpeed(){return this.velocity.length()}applyAcceleration(t){this.mass&&(this.velocity=this.velocity.add(t))}applyAngularAcceleration(t){this.mass&&(this.angleVelocity+=t)}applyForce(t){this.mass&&this.applyAcceleration(t.scale(1/this.mass))}getMirrorSign(){return this.mirror?-1:1}addChild(t,e=b(),s=0){return p(!this.destroyed,"cannot add child to destroyed object"),this.destroyed||(p(!t.parent&&!this.children.includes(t)),p(t instanceof n,"child must be an EngineObject"),p(t!==this,"cannot add self as child"),this.children.push(t),t.parent=this,t.localPos=e.copy(),t.localAngle=s,t.updateTransforms()),t}removeChild(t){p(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}isOverlappingObject(t){return this.isOverlapping(t.pos,t.size)}isOverlapping(t,e=b()){return Qs(this.pos,this.size,t,e)}setCollision(t=!0,e=!0,s=!0,i=!0){p(t||!e,"solid objects must be set to collide"),this.collideSolidObjects=t,this.isSolid=e,this.collideTiles=s,this.collideRaycast=i}toString(){let t="type = "+this.constructor.name;return(this.pos.x||this.pos.y)&&(t+=`
+precision highp float;in vec4 d;out vec4 c;void main(){c=d;}`);let e=new ArrayBuffer(gi);Gt=new Float32Array(e),ws=new Uint32Array(e),So=g.createBuffer(),zn=g.createBuffer(),kr=g.createFramebuffer(),At=0;let s=new Float32Array([0,0,1,0,0,1,1,1]);g.bindBuffer(g.ARRAY_BUFFER,zn),g.bufferData(g.ARRAY_BUFFER,s,g.STATIC_DRAW);let i,o,r,a=(c,l,u,h,f=0)=>{let d=g.getAttribLocation(o,c),y=u===1,x=u&&r;g.enableVertexAttribArray(d),g.vertexAttribPointer(d,h,l,y,x,i),g.vertexAttribDivisor(d,f),i+=h*u};wo=g.createVertexArray(),g.bindVertexArray(wo),i=0,o=di,r=mc,g.bindBuffer(g.ARRAY_BUFFER,zn),a("g",g.FLOAT,0,2),g.bindBuffer(g.ARRAY_BUFFER,So),g.bufferData(g.ARRAY_BUFFER,gi,g.DYNAMIC_DRAW),a("p",g.FLOAT,4,4,1),a("u",g.FLOAT,4,4,1),a("c",g.UNSIGNED_BYTE,1,4,1),a("a",g.UNSIGNED_BYTE,1,4,1),a("r",g.FLOAT,4,1,1),To=g.createVertexArray(),g.bindVertexArray(To),i=0,o=fi,r=bc,a("p",g.FLOAT,4,2),a("c",g.UNSIGNED_BYTE,1,4)}}function Ts(n=!1){!n&&!En||(Et(),En=!1,g.useProgram(di),g.bindVertexArray(wo))}function xc(){En||(Et(),En=!0,g.useProgram(fi),g.bindVertexArray(To))}function Co(n=!0){if(!k||!g)return;p(!At,"glPreRender called with unflushed batch."),pi||(tt.width=I.x,tt.height=I.y),g.viewport(0,0,I.x,I.y),n&&vc();let t=b(2*q).divide(I);pi&&(t.y=-t.y);let e=Ct.rotate(-K),s=b(-1).subtract(e.multiply(t)),i=ct(K),o=nt(K),r=[t.x*i,t.y*o,0,0,-t.x*o,t.y*i,0,0,1,1,1,0,s.x,s.y,0,1],a=(c,l,u)=>{g.useProgram(c);let h=g.getUniformLocation(c,l);g.uniformMatrix4fv(h,!1,u)};a(fi,"m",r),a(di,"m",r),g.activeTexture(g.TEXTURE0),un[0]&&(Zt=un[0].glTexture,g.bindTexture(g.TEXTURE_2D,Zt)),g.bindBuffer(g.ARRAY_BUFFER,So),Dn=Xn=!1,Ts(!0)}function vc(){if(!g)return;let n=nn;g.clearColor(n.r,n.g,n.b,n.a),g.clear(g.COLOR_BUFFER_BIT)}function Fr(n){!g||n===Zt||(Et(),Zt=n,g.bindTexture(g.TEXTURE_2D,Zt))}function Sc(n,t=!0){if(!g||!n)return;let e=n===Zt;e?Et():g.bindTexture(g.TEXTURE_2D,n);let s=t?g.REPEAT:g.CLAMP_TO_EDGE;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,s),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,s),!e&&Zt&&g.bindTexture(g.TEXTURE_2D,Zt)}function Eo(n,t){if(!g)return;let e=g.createShader(t);if(g.shaderSource(e,n),g.compileShader(e),Ft&&!g.getShaderParameter(e,g.COMPILE_STATUS))throw g.getShaderInfoLog(e);return e}function Yn(n,t){if(!g)return;let e=g.createProgram();if(g.attachShader(e,Eo(n,g.VERTEX_SHADER)),g.attachShader(e,Eo(t,g.FRAGMENT_SHADER)),g.linkProgram(e),Ft&&!g.getProgramParameter(e,g.LINK_STATUS))throw g.getProgramInfoLog(e);return e}function ji(n,t=!1){if(!g)return;let e=g.createTexture(),s=!1;if(n!=null&&n.width)jr(e,n),g.bindTexture(g.TEXTURE_2D,e),s=!An&&ds(n.width)&&ds(n.height);else{let a=new Uint8Array([255,255,255,255]);g.bindTexture(g.TEXTURE_2D,e),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,1,1,0,g.RGBA,g.UNSIGNED_BYTE,a)}let i=An?g.NEAREST:g.LINEAR,o=s?g.LINEAR_MIPMAP_LINEAR:i;g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,i),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,o);let r=t?g.REPEAT:g.CLAMP_TO_EDGE;return g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,r),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,r),s&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,Zt),e}function wc(n){g&&g.deleteTexture(n)}function jr(n,t){g&&(p((t==null?void 0:t.width)>0,"Invalid image data."),g.bindTexture(g.TEXTURE_2D,n),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,t),!An&&ds(t.width)&&ds(t.height)&&g.generateMipmap(g.TEXTURE_2D),g.bindTexture(g.TEXTURE_2D,Zt))}function Hh(n){N||(us.add(n),g&&(n.glTexture?jr(n.glTexture,n.image):n.glTexture=ji(n.image,n.wrap)))}function Xh(n){if(N)return;us.delete(n);let t=n.glTexture;n.glTexture=void 0,wc(t)}function Et(){if(k&&g&&At){let n=Xn?g.ONE:g.ONE_MINUS_SRC_ALPHA;g.blendFuncSeparate(g.SRC_ALPHA,n,g.ONE,n),g.enable(g.BLEND);let t=At*(En?Fi:Gr);g.bufferSubData(g.ARRAY_BUFFER,0,Gt,0,t),En?g.drawArrays(g.TRIANGLE_STRIP,0,At):g.drawArraysInstanced(g.TRIANGLE_STRIP,0,4,At),++_e,Re+=At,At=0}Xn=Dn}function Nr(n){!k||!g||(Et(),n.drawImage(tt,0,0))}function Yh(n=!0){p(!tt,"must be called before engineInit"),Mr=n}function As(n,t,e,s,i=0,o=0,r=0,a=1,c=1,l=-1,u=0){(At>=Wh||Xn!==Dn)&&Et(),Ts();let h=At++*Gr;Gt[h++]=n,Gt[h++]=t,Gt[h++]=e,Gt[h++]=s,Gt[h++]=o,Gt[h++]=r,Gt[h++]=a,Gt[h++]=c,ws[h++]=l,ws[h++]=u,Gt[h++]=i}function Tc(n,t,e,s,i,o){As(n,t,e,s,i,0,0,0,0,0,o)}function Br(n,t,e,s,i,o,r,a=!0){let c=[],l=nt(-r),u=ct(-r);for(let f of n){let d=f.x*i,y=f.y*o;c.push(b(e+u*d-l*y,s+l*d+u*y))}let h=a?Kh(c):c;Ac(h,t)}function zr(n,t,e,s,i,o,r,a,c=!0){let l=$h(n,e,c);Br(l,t,s,i,o,r,a,!1)}function Ac(n,t){if(!k||n.length<3)return;let e=n.length+2;if((At+e>=Jn||Xn!==Dn)&&Et(),p(e=Jn)return;xc();let s=At*Fi;for(let i=e;i--;){let o=F(i-1,0,e-3),r=n[o];Gt[s++]=r.x,Gt[s++]=r.y,ws[s++]=t}At+=e}function Jr(n,t){if(!k||n.length<3)return;let e=n.length+2;if((At+e>=Jn||Xn!==Dn)&&Et(),p(e=Jn)return;xc();let s=At*Fi;for(let i=e;i--;){let o=F(i-1,0,e-3),r=n[o],a=t[o];Gt[s++]=r.x,Gt[s++]=r.y,ws[s++]=a}At+=e}function os(n,t=!1){n?(pi=n,g.bindFramebuffer(g.FRAMEBUFFER,kr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,n,0),Co(t)):(Et(),pi=void 0,g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,I.x,I.y))}function Cc(n,t,e,s){k&&(g.enable(g.SCISSOR_TEST),g.scissor(n,t,e,s),g.clearColor(0,0,0,0),g.clear(g.COLOR_BUFFER_BIT),g.disable(g.SCISSOR_TEST))}function $h(n,t,e=!0){if(n.length<2)return[];let s=t/2,i=[],o=n.length,r=1e-6,a=10;for(let c=0;cr?-d/y:0,S=y>r?f/y:0,E=w>r?-v/w:0,A=w>r?x/w:0,T=_+E,R=S+A,M=(T*T+R*R)**.5;if(Mr){let gt=Q(1/ht,a);T*=gt,R*=gt}}let Z=b(u.x-T*s,u.y-R*s),it=b(u.x+T*s,u.y+R*s);i.push(Z),i.push(it)}return i.length>1&&e&&(i.push(i[0]),i.push(i[1])),i}function Kh(n){if(n.length<3)return[];let t=(d,y,x)=>(y.x-d.x)*(x.y-d.y)-(y.y-d.y)*(x.x-d.x);(d=>{let y=0;for(let x=d.length;x--;){let v=(x+1)%d.length;y+=d[x].cross(d[v])}return y})(n)<0&&(n=n.slice().reverse());let s=1e-9,i=(d,y,x,v)=>{let w=t(y,x,d),_=t(x,v,d),S=t(v,y,d),E=(w<-s?1:0)+(_<-s?1:0)+(S<-s?1:0),A=(w>s?1:0)+(_>s?1:0)+(S>s?1:0);return!(E&&A)},o=[];for(let d=0;d3&&a++{if(E>=0){let T=s.fillStyle=s.createLinearGradient(v,w,_,S);T.addColorStop(0,h(E,2)),T.addColorStop(1,h(E,1))}else s.fillStyle="#000";E>=-1?(s.fill(),A&&s.stroke()):s.stroke()},c=(v,w,_,S=0,E=2*X,A,T)=>{s.beginPath(),s.arc(v,w,_,d*S,d*E),a(v,w-_,v,w+_,A,T)},l=(v,w,_,S,E)=>{s.beginPath(),s.rect(v,w,_,S*d),a(v,w+S,v+_,w,E)},u=(v,w,_,S)=>{s.beginPath();for(let E of v)s.lineTo(E.x,E.y);s.closePath(),a(0,_,0,_+S,w)},h=(v,w)=>w?`hsl(${[.95,.56,.13][v%3]*360} 99%${[0,50,75][w]}%)`:"#000",f=Wa(1,1,n),d=jt(f,.1,.5),y=Q(6,Q(o,r)/99);s.translate(o/2,r/2),s.scale(y,y),s.translate(-40,-35),d<1&&s.setLineDash([99*d,99]),s.lineJoin=s.lineCap="round",s.lineWidth=.1+d*1.9;{let w="LittleJS";s.font="900 15.5px arial",s.lineWidth=.1+d*3.9,s.textAlign="center",s.textBaseline="top",l(11,55,59,8*d,-1),s.beginPath();let _=0;for(let S=0;S5?1:0),s[S?"strokeText":"fillText"](w[E],R,54+.5,17*d),A+=T}s.lineWidth=.1+d*1.9,l(3,54,73,0)}l(7,15,26,-7,0),l(25,15,8,25,-1),l(10,40,15,-25,1),l(14,21,7,9,2),l(38,20,6,-6,2),l(49,20,10,-6,0);let x=[b(44,8),b(64,8),b(59,8+6*d),b(49,8+6*d)];u(x,2,8,6*d),l(44,8,20,-7,0);for(let v=5;v--;)c(59-v*6*d,30,10,0,2*X,1,0);c(59,30,4,0,7,2),l(35,20,24,0),c(59,30,10),c(47,30,10,X/2,X*3/2),c(35,30,10,X/2,X*3/2),l(7,40,13,7,-1),l(17,40,43,14,-1);for(let v=3;v--;)for(let w=2;w--;)c(17+15*v,47,w?7:1,0,2*X,2);for(let v=2;v--;){let w=6,_=7,S=53+w*d*v,E=[b(S+_,54),b(S,40),b(S+w*d,40),b(S+_+w*d,54)];u(E,0,40,14)}s.restore()}function Zh(n){if(bi=n,!pn){let e={};try{e=JSON.parse(localStorage[n]||"{}")}catch{e={}}Ni(s=>{s.unlocked=!!(e[s.id]&&e[s.id].unlocked)}),Vr()}_n(void 0,t);function t(){if(!qs.length)return;let e=qs[0],s=an-Ws;if(!Ws)Ws=an;else if(s>yi)Ws=0,qs.shift();else{let i=yi-Nn,o=si?(s-i)/Nn:0;e.render(o)}}}function Ni(n){Object.values(Cs).forEach(t=>n(t))}function td(){Ni(n=>n.unlocked=!1),Vr()}function Vr(){if(!bi)return;let n={};Ni(t=>{let e={name:t.name,description:t.description,icon:t.icon,unlocked:t.unlocked};t.image&&(e.src=t.image.src),n[t.id]=e}),localStorage[bi]=JSON.stringify(n)}function ed(n){yi=n}function nd(n){Nn=n}function sd(n){mi=n.copy()}function id(n){Ur=n}function Ec(n,t,e,s=125){let i,o,r,a,c,l,u,h,f,d,y,x,v,w=0,_,S=[],E=[],A=[],T=0,R=0,M=1,Z={},it=Zn/s*60>>2;for(;M;T++)S=[M=h=x=0],e.forEach((ht,gt)=>{for(u=t[ht][T]||[0,0,0],M|=t[ht][T]&&1,_=x+(t[ht][0].length-2-(h?0:1))*it,v=gt===e.length-1,i=2,r=x;iit-99&&f&&y<1?y+=1/99:0)l=(1-y)*S[w++]/2||0,E[r]=(E[r]||0)-l*R+l,A[r]=(A[r++]||0)+l*R+l;c&&(y=c%1,R=u[1]||0,(c|=0)&&(S=Z[[d=u[w=0]||0,c]]=Z[[d,c]]||(a=[...n[d]],a[2]=(a[2]||220)*2**(c/12-1),c>0?Gi(...a):[])))}x=_});return[E,A]}function od(n){Wr=typeof n=="boolean"?n?1:0:n}function rd(n){qr=n}async function ad(){return new Ai(await Box2D()),e(),_n(n,t),m;function n(){if(!Ce){m.step(),m.objects=m.objects.filter(s=>!s.destroyed);for(let s of m.objects)s.body&&(s.pos=m.vec2From(s.body.GetPosition()),s.angle=-s.body.GetAngle())}}function t(){(qr||de)&&m.world.DrawDebugData()}function e(){let i=new m.instance.JSDraw,o=l=>new wt(l.get_r(),l.get_g(),l.get_b()),r=l=>o(m.instance.wrapPointer(l,m.instance.b2Color)),a=l=>r(l).scale(1,.8),c=(l,u)=>{let h=[];for(let f=u;f--;)h.push(m.vec2FromPointer(l+f*8));return h};i.DrawSegment=function(l,u,h){h=a(h),l=m.vec2FromPointer(l),u=m.vec2FromPointer(u),bn(l,u,.1,h,b(),0,!1)},i.DrawPolygon=function(l,u,h){h=a(h);let f=c(l,u);Vn(f,cn,.1,h,b(),0,!1)},i.DrawSolidPolygon=function(l,u,h){h=a(h);let f=c(l,u);Vn(f,h,0,h,b(),0,!1)},i.DrawCircle=function(l,u,h){h=a(h),l=m.vec2FromPointer(l),si(l,u*2,cn,.1,h,!1)},i.DrawSolidCircle=function(l,u,h,f){f=a(f),l=m.vec2FromPointer(l),h=m.vec2FromPointer(h).scale(u),si(l,u*2,f,.1,f,!1),bn(b(),h,.1,f,l,0,!1)},i.DrawTransform=function(l){l=m.instance.wrapPointer(l,m.instance.b2Transform);let u=m.vec2From(l.get_p()),h=-l.get_q().GetAngle(),f=b(1,0),d=z(.75,0,0,.8),y=b(0,1),x=z(0,.75,0,.8);bn(b(),f,.1,d,u,h,!1),bn(b(),y,.1,x,u,h,!1)},i.AppendFlags(m.instance.b2Draw.e_shapeBit),i.AppendFlags(m.instance.b2Draw.e_jointBit),m.world.SetDebugDraw(i)}}function cd(n,t,e,s=32,i=2,o=0){_c(n,t,e,V,s,st,i,o,!1,!0)}function _c(n,t,e,s,i=1,o,r=.05,a=0,c=k,l,u){let h=e.offset(e.size),f=t.add(b(r-i*2)),d=b(i),y=t.scale(.5).subtract(d.scale(.5)),x=l?-1:1,v=l?-a:a;Lt(n,f,h,s,a,!1,o,c,l,u);for(let w=4;w--;){let _=w%2,S=y.multiply(b(_?w===1?1:-1:0,_?0:w?-1:1)),E=b(_?i:f.x,_?f.y:i),A=h.offset(e.size.multiply(b(w===1?1:w===3?-1:0,w===0?-x:w===2?x:0)));Lt(n.add(S.rotate(v)),E,A,s,a,!1,o,c,l,u)}for(let w=4;w--;){let _=w>1,S=w&&w<3,E=y.multiply(b(_?-1:1,S?-1:1)),A=h.offset(e.size.multiply(b(_?-1:1,S?x:-x)));Lt(n.add(E.rotate(v)),d,A,s,a,!1,o,c,l,u)}}function ld(n,t,e,s=32,i=2,o=0){Rc(n,t,e,V,s,st,i,o,!1,!0)}function Rc(n,t,e,s,i=1,o,r=.05,a=0,c=k,l,u){let h=e.frame(0),f=e.frame(1),d=e.frame(2),y=t.add(b(r-i*2)),x=b(i),v=t.scale(.5).subtract(x.scale(.5)),w=l?-1:1,_=l?-a:a;Lt(n,y,d,s,a,!1,o,c,l,u);for(let S=4;S--;){let E=a+S*X/2,A=S%2,T=v.multiply(b(A?S===1?1:-1:0,A?0:S?-w:w)),R=b(A?y.y:y.x,i);Lt(n.add(T.rotate(_)),R,f,s,E,!1,o,c,l,u)}for(let S=4;S--;){let E=a+S*X/2,A=!S||S>2,T=S>1,R=v.multiply(b(A?-1:1,T?-w:w));Lt(n.add(R.rotate(_)),x,h,s,E,!1,o,c,l,u)}}function ud(n,t=1,e=0,s=V,i=0,o=!1,r=0,a=st,c=k,l=!1,u){let h=Pc(b(),t,e,0,o);Vn(h,s,r,a,n,i,c,l,u)}function Pc(n,t=1,e=0,s=0,i=!1,o=Ls){p(O(n),"pos must be a vec2"),p(P(t)&&P(e),"size and percent must be numbers");let r=ie(e*4,4);r>=2&&(s+=X),r=r<=2?r-1:3-r,i&&(r=-r,s+=X);let a=[],c=$(3,o>>1),l=t/2;for(let u=0;u<=c;u++){let h=u/c*X;a.push(b(l*ct(h),l*nt(h)).rotate(s).add(n))}for(let u=c;u>=0;u--){let h=u/c*X;a.push(b(l*ct(h),-l*r*nt(h)).rotate(s).add(n))}return a}function La(n){return n&&typeof n.lerp=="function"}function hd(n,t,e,s,i=1,o={}){p(n!=null&&typeof n=="object","tweenProperty target must be an object"),p(U(t)&&t.length>0,"tweenProperty propertyPath must be a non-empty string");let r=t.split("."),a=r.pop(),c=l=>{let u=n;for(let h of r)u=u[h];u[a]=l};return new Ci(c,e,s,i,o)}function Lc(n){n.loopRemaining!==1/0&&n.loopRemaining<=1||(n.loopRemaining!==1/0&&(n.loopRemaining-=1),n.life=n.duration,n.thenCallback=()=>Lc(n),Kt.push(n),n.callback(n.interp(n.duration)))}function Oc(n){if(n.loopRemaining!==1/0&&n.loopRemaining<=1)return;n.loopRemaining!==1/0&&(n.loopRemaining-=1);let t=n.start;n.start=n.end,n.end=t,n.life=n.duration,n.thenCallback=()=>Oc(n),Kt.push(n),n.callback(n.interp(n.duration))}function Dc(n,t){n===void 0?(n=Qt-Ra,t=an-Pa,Ra=Qt,Pa=an):t===void 0&&(t=n);for(let e=Kt.length;e--;){let s=Kt[e];if(s.paused)continue;let i=s.useRealTime?t:n;if(!(i<=0))if(s.life-=i,s.life>0)s.callback(s.interp(s.life));else{s.callback(s.interp(0)),Kt.splice(e,1);let o=s.thenCallback;s.thenCallback=void 0,o&&o()}}}function dd(){for(let n of Kt)n.thenCallback=void 0;Kt.length=0}var Hs,Xs,El,tr,vt,er,Oa,Qt,an,Ce,ao,xe,Ys,Da,xn,uo,Ft,ka,Ri,Ga,ke,en,de,fe,vn,Sn,Un,ho,Ge,he,X,et,St,hs,$s,Q,$,se,Ba,za,nt,ct,Ja,sr,go,rt,wt,V,cn,st,ye,Vl,rr,Wl,Ka,Qa,ql,Za,tc,Hl,Ee,Ct,K,q,cr,Pi,nn,kn,rs,Gn,Fn,lr,An,sn,Ps,ur,N,k,Ls,Li,Oi,Di,Ii,hr,dr,fr,pr,gr,je,Wt,Zs,Mi,yr,as,mn,ln,mr,ge,$n,Rn,Kn,Qn,Os,hn,Ht,br,cs,ti,Ds,Xt,wn,xr,vr,Ve,G,ut,Tt,ze,Ze,we,Ne,I,un,_e,Re,Pe,We,nh,lc,ii,Ie,Ut,Tr,ve,Ar,oi,Bn,tn,Cr,jn,mt,oe,Y,Se,gn,co,Wn,re,Cn,ri,Fs,Be,Ke,dc,Lr,fc,ms,yn,qn,Aa,ai,pt,Ue,Zn,xs,ci,rn,Tn,ui,vs,Ss,vo,Vh,hi,tt,g,Mr,di,fi,En,Dn,Xn,Zt,So,zn,Gt,ws,At,us,wo,To,kr,pi,Ao,gi,Gr,mc,Wh,Fi,bc,Jn,pn,yi,Nn,mi,Ur,Cs,qs,bi,Ws,xi,Es,_o,Ro,Mt,Po,W,Lo,Oo,Do,C,Wr,Io,ae,vi,Mo,ko,_s,Go,Fo,jo,No,m,qr,Rs,Si,Bo,zo,wi,Yt,Jo,Ti,Uo,Vo,Wo,qo,Ho,Xo,Yo,$o,Ko,Qo,Ai,Kt,Ra,Pa,Ci,Ei,fd,lo,_i,Zo,Mc=jc(()=>{"use strict";Hs="LittleJS",Xs="1.18.19",El=60,tr=.016666666666666666,vt=[],er=[],Oa=0,Qt=0,an=0,Ce=!1;ao=0,xe=0,Ys=0,Da=!0,xn=[],uo=class{constructor(t,e,s,i){this.update=t,this.render=e,this.glContextLost=s,this.glContextRestored=i}};Ft=!0,ka=.5,Ri=!0,Ga="Escape",ke=!1,en=[],de=!1,fe=!1,vn=!1,Sn=!1,Un=!1;X=Math.PI,et=Math.abs,St=Math.floor,hs=Math.ceil,$s=Math.round,Q=Math.min,$=Math.max,se=n=>Math.sign(n),Ba=(...n)=>Math.hypot(...n),za=n=>Math.log2(n),nt=Math.sin,ct=Math.cos,Ja=Math.tan,sr=Math.atan2;go=class{constructor(t=123456789){p(t!==0,"RandomGenerator seed must be non-zero (xorshift is fixed at 0)"),this.seed=t}float(t=1,e=0){return this.seed^=this.seed<<13,this.seed^=this.seed>>>17,this.seed^=this.seed<<5,e+(t-e)*((this.seed>>>0)/2**32)}int(t,e=0){return St(this.float(t,e))}bool(t=.5){return this.float().5?1:-1}floatSign(t=1,e=0){let s=Q(t,e),o=$(t,e)-s,r=this.float(o*2);return rt?this.scale(t/e):this.copy()}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}reflect(t,e=1){return this.subtract(t.scale((1+e)*this.dot(t)))}angle(){return sr(this.x,this.y)}setAngle(t=0,e=1){return $t(t),$t(e),this.x=e*nt(t),this.y=e*ct(t),this}rotate(t){$t(t);let e=ct(-t),s=nt(-t);return new n(this.x*e-this.y*s,this.x*s+this.y*e)}setDirection(t,e=1){return $t(t),$t(e),t=ie(t,4),p(t===0||t===1||t===2||t===3,"Vector2.setDirection() direction must be an integer between 0 and 3."),this.x=t%2?t-1?-e:e:0,this.y=t%2?0:t?-e:e,this}direction(){return et(this.x)>et(this.y)?this.x<0?3:1:this.y<0?2:0}abs(){return new n(et(this.x),et(this.y))}floor(){return new n(St(this.x),St(this.y))}snap(t){return $t(t),new n(St(this.x*t)/t,St(this.y*t)/t)}mod(t=1){return new n(ie(this.x,t),ie(this.y,t))}area(){return et(this.x*this.y)}lerp(t,e){wa(t),$t(e);let s=F(e);return new n(t.x*s+this.x*(1-s),t.y*s+this.y*(1-s))}arrayCheck(t){return this.x>=0&&this.y>=0&&this.x(u=ie(u,1))*6<1?c+(l-c)*6*u:u*2<1?l:u*3<2?c+(l-c)*(4-u*6):c;return this.r=a(r,o,t+1/3),this.g=a(r,o,t),this.b=a(r,o,t-1/3),this.a=i,is(this),this}HSLA(){let t=F(this.r),e=F(this.g),s=F(this.b),i=F(this.a),o=$(t,e,s),r=Q(t,e,s),a=(o+r)/2,c=0,l=0;if(o!==r){let u=o-r;l=a>.5?u/(2-o-r):u/(o+r),t===o?c=(e-s)/u+(e((s=F(s)*255|0)<16?"0":"")+s.toString(16);return"#"+e(this.r)+e(this.g)+e(this.b)+(t?e(this.a):"")}setHex(t){if(p(U(t),"Color hex code must be a string"),p(t[0]==="#","Color hex code must start with #"),p([4,5,7,9].includes(t.length),"Invalid hex"),t.length<6){let e=s=>F(parseInt(t[s],16)/15);this.r=e(1),this.g=e(2),this.b=e(3),this.a=t.length===5?e(4):1}else{let e=s=>F(parseInt(t.slice(s,s+2),16)/255);this.r=e(1),this.g=e(3),this.b=e(5),this.a=t.length===9?e(7):1}return is(this),this}rgbaInt(){let t=F(this.r)*255|0,e=F(this.g)*255<<8,s=F(this.b)*255<<16,i=F(this.a)*255<<24;return t+e+s+i}isValid(){return P(this.r)&&P(this.g)&&P(this.b)&&P(this.a)}},V=te(z()),cn=te(z(1,1,1,0)),st=te(z(0,0,0)),ye=te(z(0,0,0,0)),Vl=te(z(.5,.5,.5)),rr=te(z(1,0,0)),Wl=te(z(1,.5,0)),Ka=te(z(1,1,0)),Qa=te(z(0,1,0)),ql=te(z(0,1,1)),Za=te(z(0,0,1)),tc=te(z(.5,0,1)),Hl=te(z(1,0,1)),Ee=class{constructor(t,e=!1){p(t===void 0||P(t),"Constructed Timer is invalid.",t),this.useRealTime=e;let s=this.getGlobalTime();this.time=t===void 0?void 0:s+t,this.setTime=t}set(t=0){p(P(t),"Timer is invalid.",t);let e=this.getGlobalTime();this.time=e+t,this.setTime=t}setUseRealTime(t=!0){p(!this.isSet(),"Cannot change global time setting while timer is set."),this.useRealTime=t}unset(){this.time=void 0}isSet(){return this.time!==void 0}active(){return this.getGlobalTime()=this.time}get(){return this.isSet()?this.getGlobalTime()-this.time:0}getPercent(){return this.isSet()?this.setTime?1-jt(this.time-this.getGlobalTime(),0,this.setTime):1:0}getSetTime(){return this.isSet()?this.setTime:0}getGlobalTime(){return this.useRealTime?an:Qt}toString(){return this.isSet()?et(this.get())+" seconds "+(this.get()<0?"before":"after"):"unset"}valueOf(){return this.get()}};Ct=b(),K=0,q=32,cr=1,Pi=!0,nn=ye,kn=b(1920,1080),rs=0,Gn=0,Fn=b(),lr=!1,An=!0,sn=1,Ps="arial",ur=!1,N=!1,k=!0,Ls=32,Li=b(16),Oi=0,Di=0,Ii=!0,hr=1,dr=1,fr=1,pr=0,gr=.8,je=1,Wt=b(),Zs=1,Mi=!0,yr=!0,as=!0,mn=!0,ln=!1,mr=!1,ge=0,$n=4,Rn=!0,Kn=0,Qn=!1,Os=!0,hn=!1,Ht=100,br=.3,cs=3,ti=0,Ds=!0,Xt=!0,wn=.3,xr=40,vr=.7;Ve=class n{constructor(t=b(),e=b(1),s,i=0,o=V,r=0){p(O(t),"object pos must be a vec2"),p(O(e),"object size must be a vec2"),p(!s||s instanceof Pe,"object tileInfo should be a TileInfo or undefined"),p(typeof i=="number"&&isFinite(i),"object angle should be a number"),p(J(o),"object color should be a valid rgba color"),p(typeof r=="number","object renderOrder should be a number"),this.pos=t.copy(),this.size=e.copy(),this.drawSize=void 0,this.tileInfo=s,this.angle=i,this.color=o.copy(),this.additiveColor=void 0,this.mirror=!1,this.destroyed=!1,this.mass=hr,this.damping=dr,this.angleDamping=fr,this.restitution=pr,this.friction=gr,this.gravityScale=1,this.renderOrder=r,this.velocity=b(),this.angleVelocity=0,this.spawnTime=Qt,this.children=[],this.clampSpeed=!0,this.groundObject=void 0,this.parent=void 0,this.localPos=b(),this.localAngle=0,this.collideTiles=!1,this.collideSolidObjects=!1,this.isSolid=!1,this.collideRaycast=!1,vt.push(this)}updateTransforms(){let t=this.parent;if(t){let e=t.getMirrorSign(),s=this.localPos,i=t.pos,o=s.x*e,r=s.y,a=t.angle;if(a){let c=ct(-a),l=nt(-a);this.pos.set(o*c-r*l+i.x,o*l+r*c+i.y)}else this.pos.set(o+i.x,r+i.y);this.angle=e*this.localAngle+a}for(let e of this.children)e.updateTransforms()}updatePhysics(){if(p(!this.parent),this.destroyed)return;this.clampSpeed&&(this.velocity.x=F(this.velocity.x,-je,je),this.velocity.y=F(this.velocity.y,-je,je));let t=this.pos.copy();if(this.velocity.x*=this.damping,this.velocity.y*=this.damping,this.mass&&(this.velocity.x+=Wt.x*this.gravityScale,this.velocity.y+=Wt.y*this.gravityScale),this.pos.x+=this.velocity.x,this.pos.y+=this.velocity.y,this.angle+=this.angleVelocity*=this.angleDamping,p(this.angleDamping>=0&&this.angleDamping<=1),p(this.damping>=0&&this.damping<=1),!Ii||!this.mass)return;let e=this.velocity.y<0&&Wt.y<0||this.velocity.y>0&&Wt.y>0;if(this.groundObject){let s=$(this.friction,this.groundObject.friction),i=this.groundObject.velocity.x;this.velocity.x=i+(this.velocity.x-i)*s,this.groundObject=void 0}if(this.collideSolidObjects)for(let i of er){if(i.destroyed||i.parent||i===this||!this.isSolid&&!i.isSolid||!this.isOverlappingObject(i))continue;let o=this.collideWithObject(i),r=i.collideWithObject(this);if(!o||!r)continue;if(Qs(t,this.size,i.pos,i.size)){let f=t.subtract(i.pos),d=f.length(),x=d<.001?b(0,1):f.scale(.001/d);this.velocity=this.velocity.add(x),i.mass&&(i.velocity=i.velocity.subtract(x)),de&&fo(this.pos,this.size,i.pos,i.size,"#f00");continue}let a=this.size.add(i.size),c=(t.y-i.pos.y)*2>a.y+Wt.y,l=et(t.y-i.pos.y)*20?-1:1)>0?St(t.y-this.size.y/2+1)+this.size.y/2+.001:hs(t.y+this.size.y/2-1)-this.size.y/2-.001;if(et(u-this.pos.y)<.1&&!Qe(b(this.pos.x,u),this.size,this)){this.pos.y=u,de&&bt(this.pos,this.size,"#ff0");return}this.pos.x=t.x,this.velocity.x*=-r}if(o||!i){if(e){let c=this.size.y/2+1e-4;this.pos.y=Wt.y<0?St(t.y-this.size.y/2)+c:hs(t.y+this.size.y/2)-c,this.groundObject=s}else this.pos.y=t.y,this.groundObject=void 0;this.velocity.y*=-r}de&&bt(this.pos,this.size,"#f00")}}}update(){}render(){Lt(this.pos,this.drawSize||this.size,this.tileInfo,this.color,this.angle,this.mirror,this.additiveColor)}renderLight(){}destroy(t=!1){var e;if(!this.destroyed){this.destroyed=!0,(e=this.parent)==null||e.removeChild(this);for(let s of this.children)s.parent=void 0,s.destroy(t)}}localToWorld(t){return this.pos.add(t.rotate(this.angle))}worldToLocal(t){return t.subtract(this.pos).rotate(-this.angle)}localToWorldVector(t){return t.rotate(this.angle)}worldToLocalVector(t){return t.rotate(-this.angle)}collideWithTile(t,e){return t>0}collideWithObject(t){return!0}getUp(t=1){return b().setAngle(this.angle,t)}getRight(t=1){return b().setAngle(this.angle+X/2,t)}getAliveTime(){return Qt-this.spawnTime}getSpeed(){return this.velocity.length()}applyAcceleration(t){this.mass&&(this.velocity=this.velocity.add(t))}applyAngularAcceleration(t){this.mass&&(this.angleVelocity+=t)}applyForce(t){this.mass&&this.applyAcceleration(t.scale(1/this.mass))}getMirrorSign(){return this.mirror?-1:1}addChild(t,e=b(),s=0){return p(!this.destroyed,"cannot add child to destroyed object"),this.destroyed||(p(!t.parent&&!this.children.includes(t)),p(t instanceof n,"child must be an EngineObject"),p(t!==this,"cannot add self as child"),this.children.push(t),t.parent=this,t.localPos=e.copy(),t.localAngle=s,t.updateTransforms()),t}removeChild(t){p(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}isOverlappingObject(t){return this.isOverlapping(t.pos,t.size)}isOverlapping(t,e=b()){return Qs(this.pos,this.size,t,e)}setCollision(t=!0,e=!0,s=!0,i=!0){p(t||!e,"solid objects must be set to collide"),this.collideSolidObjects=t,this.isSolid=e,this.collideTiles=s,this.collideRaycast=i}toString(){let t="type = "+this.constructor.name;return(this.pos.x||this.pos.y)&&(t+=`
 pos = `+this.pos),(this.velocity.x||this.velocity.y)&&(t+=`
 velocity = `+this.velocity),(this.size.x||this.size.y)&&(t+=`
 size = `+this.size),this.angle&&(t+=`
 angle = `+this.angle.toFixed(3)),this.color&&(t+=`
-color = `+this.color),t}renderDebugInfo(){if(!Gt)return;let t=this.collideTiles||this.collideSolidObjects||this.isSolid;if(!t&&!this.parent)return;let e=b($(this.size.x,.2),$(this.size.y,.2)),s=z(this.collideTiles?1:0,this.collideSolidObjects?1:0,this.isSolid?1:0,.5);bt(this.pos,e,s,0,this.angle,t),this.parent&&bt(this.pos,e.scale(.8),z(1,1,1,.5),0,this.angle),this.parent&&Te(this.pos,this.parent.pos,z(1,1,1,.5),.5)}},I=b(),un=[];Pe=class n{constructor(t=b(),e=Li,s=un[0],i=Oi,o=Di){this.pos=t.copy(),this.size=e.copy(),this.padding=i,this.textureInfo=s,this.bleed=o}offset(t){return new n(this.pos.add(t),this.size,this.textureInfo,this.padding,this.bleed)}frame(t){p(typeof t=="number");let e=this.size.x+this.padding*2,s=t*e;return p(s+this.size.x<=this.textureInfo.size.x,"frame extends beyond texture width!"),this.offset(new ot(s))}setFullImage(t=this.textureInfo){return this.textureInfo=t,this.pos=new ot,this.size=t.size.copy(),this.bleed=this.padding=0,this}tile(t){return Is(t,this.size,this.textureInfo,this.padding,this.bleed)}},Ve=class{constructor(t,e=!0,s=!1){this.image=t,this.size=t?b(t.width,t.height):b(),this.sizeInverse=t?b(1/t.width,1/t.height):b(),this.glTexture=void 0,this.wrap=s,e&&this.createWebGLTexture()}createWebGLTexture(){Hh(this)}destroyWebGLTexture(){Xh(this)}hasWebGL(){return!!this.glTexture}setWrap(t=!0){this.wrap=t,Sc(this.glTexture,t)}};nh=0;ii=class{constructor(t){p(!!t,"tileInfo is required for ImageFont"),this.tileInfo=t.frame(0)}drawText(t,e,s=1,i,o,r,a){p(O(s)||typeof s=="number","size must be a vec2 or number"),typeof s=="number"?(p(s>0),s*=q,s=new ot(s,s)):s=s.scale(q),this.drawTextScreen(t,Ln(e),s,i,o,r,a)}drawTextScreen(t,e,s,i=!0,o=V,r=k,a){p(U(t),"text must be a string"),p(O(e),"pos must be a vec2"),p(O(s)||typeof s=="number","size must be a vec2 or number"),p(J(o),"color must be a color"),s=typeof s=="number"?new ot(s,s):s;let c=new ot,l=this.tileInfo,u=l.padding,h=l.size.x+u*2,f=l.size.y+u*2,d=l.textureInfo.size.x/h|0;(t+"").split(`
-`).forEach((y,x)=>{let v=i?(y.length-1)*s.x/2:0;for(let w=y.length;w--;){let _=y.charCodeAt(w),S=_<32||_>127?95:_-32,E=S%d,A=S/d|0;l.pos.x=E*h+u,l.pos.y=A*f+u,c.x=e.x+w*s.x-v|0,c.y=e.y+x*s.y|0,Pt(c,s,l,o,0,!1,void 0,r,!0,a)}})}};De=b(),Jt=b(),Tr=b(),ve=b(),Ar=0,oi=!0,Bn=!1,tn="mouse",Cr=6,jn=!0,mt=0,oe=!N&&window.ontouchstart!==void 0;Y=[[]],Se=[],gn=[],co=[],Wn=new Ee,re=[],Cn=[],ri=[],Fs=[],Ne=new Map,ms=[],qn=!0;ai="http://www.w3.org/2000/svg";pt=new AudioContext,Zn=44100;xs=class{constructor(t,e,s=xr,i=vr,o){var r;if(!(!Ht||N)){if(p(!t||pe(t)||U(t),"asset must be a file name or zzfx array"),p(e===void 0||P(e),"randomness must be a number"),p(e===void 0||e>=0&&e<=1,"randomness must be between 0 and 1"),p(P(s),"range must be a number"),p(P(i),"taper must be a number"),this.range=s,this.taper=i,this.randomness=e!=null?e:0,this.sampleRate=Zn,this.loadedPercent=0,this.onloadCallback=o,pe(t)){let a=t.slice(),c=e!=null?e:.05,l=1;this.randomness=(r=a[l])!=null?r:c,a[l]=0,this.sampleChannels=[Gi(...a)],this.loadedPercent=1,o==null||o(this)}else if(typeof t=="string"){let a=t;this.loadSound(a)}}}play(t,e=1,s=1,i=1,o=!1,r=!1){if(p(!t||O(t),"pos must be a vec2"),p(P(e),"volume must be a number"),p(P(s),"pitch must be a number"),p(P(i),"randomnessScale must be a number"),!Ht||N||!this.sampleChannels)return;let a;if(t){let u=this.range;if(u){let h=Ct.distanceSquared(t);if(h>u*u)return;e*=Ft(h**.5,u,u*this.taper)}a=Ln(t).x*2/G.width-1}let c=s+s*this.randomness*i*ft(-1,1),l=new ci(this,e,c,a,o,r);return Gt&&Un&&t&&(Ut(t,.5,"#0ff",.5,!0),this.range&&(Ut(t,2*this.range,"#0ff",.5),Ut(t,2*this.range*this.taper,"#0ff",.5)),Mn("vol "+e.toFixed(2)+" pitch "+c.toFixed(2),t,.5,"#0ff",.5)),l}playMusic(t=1,e=!0,s=!1){return this.play(void 0,t,1,0,e,s)}playNote(t=0,e,s){p(P(t),"semitoneOffset must be a number");let i=gc(t,1);return this.play(e,s,i,0)}getDuration(){var t,e;return((e=(t=this.sampleChannels)==null?void 0:t[0])==null?void 0:e.length)/this.sampleRate||0}isLoaded(){return this.loadedPercent===1}async loadSound(t){var c;let e=await fetch(t);if(!e.ok)throw new Error(`Failed to load sound from ${t}: ${e.status} ${e.statusText}`);let s=await e.arrayBuffer(),i=await pt.decodeAudioData(s),o=i.numberOfChannels,r=1e5,a=[];for(let l=0;lsetTimeout(v,0));let d=Q(f+r,h);for(;f=0,"Sound volume must be positive or zero"),p(s>=0,"Sound rate must be positive or zero"),p(P(i),"Sound pan must be a number"),this.sound=t,this.volume=e,this.rate=s,this.pan=i,this.loop=o,this.pausedTime=0,this.startTime=void 0,this.gainNode=void 0,this.source=void 0,this.onendedCallback=a=>{a===this.source&&(this.source=void 0)},r||this.start()}start(t=0){p(t>=0,"Sound start offset must be positive or zero"),this.isPlaying()&&this.stop(),this.gainNode=pt.createGain(),this.source=Ir(this.sound.sampleChannels,this.volume,this.rate,this.pan,this.loop,this.sound.sampleRate,this.gainNode,t,this.onendedCallback),this.source?(this.startTime=pt.currentTime-t,this.pausedTime=void 0):(this.startTime=void 0,this.pausedTime=0)}setVolume(t){p(t>=0,"Sound volume must be positive or zero"),this.volume=t,this.gainNode&&(this.gainNode.gain.value=t)}stop(t=0){if(p(t>=0,"Sound fade time must be positive or zero"),this.isPlaying())if(t){let e=pt.currentTime,s=e+t;this.gainNode.gain.cancelScheduledValues(e),this.gainNode.gain.setValueAtTime(this.volume,e),this.gainNode.gain.linearRampToValueAtTime(0,s),this.source.stop(s)}else this.source.stop();this.pausedTime=0,this.source=void 0,this.startTime=void 0}pause(){this.isPaused()||(this.pausedTime=this.getCurrentTime(),this.source.stop(),this.source=void 0,this.startTime=void 0)}resume(){this.isPaused()&&this.start(this.pausedTime)}isPlaying(){return!!this.source}isPaused(){return!this.isPlaying()}getCurrentTime(){if(!this.isPlaying())return this.pausedTime;let t=this.getDuration();return t?ie(pt.currentTime-this.startTime,t):0}getDuration(){return this.rate?this.sound.getDuration()/this.rate:0}getSource(){return this.source}};rn=[];Tn=class{constructor(t,e=0,s=!1,i=new wt){this.tile=t,this.direction=e,this.mirror=s,this.color=i.copy()}clear(){this.tile=this.direction=0,this.mirror=!1,this.color=new wt}},ui=class extends Ue{constructor(t,e,s=0,i=0,o=b(512),r=!0){var a;p(O(o),"canvasSize must be a Vector2"),super(t,e,void 0,s,V,i),this.canvas=N?void 0:new OffscreenCanvas(o.x,o.y),this.context=(a=this.canvas)==null?void 0:a.getContext("2d"),this.textureInfo=new Ve(this.canvas,r),this.mass=0}destroy(){this.destroyed||(this.textureInfo.destroyWebGLTexture(),super.destroy())}render(){this.draw(this.pos,this.size,this.color,this.angle,this.mirror,this.additiveColor)}draw(t,e,s=V,i=0,o=!1,r,a=!1,c){let l=new Pe().setFullImage(this.textureInfo),u=this.hasWebGL();Pt(t,e,l,s,i,o,r,u,a,c)}updateWebGL(){this.textureInfo.createWebGLTexture()}hasWebGL(){return k&&this.textureInfo.hasWebGL()}},vs=class extends ui{constructor(t,e,s=Is(),i=0,o=!0){let r=s?e.multiply(s.size):e;if(super(t,e,0,i,r,o),this.tileInfo=void 0,this.data=[],this.isUsingWebGL=!1,N){this.render=()=>{},this.redraw=()=>{},this.redrawStart=()=>{},this.redrawEnd=()=>{},this.drawTileData=()=>{},this.redrawTileData=()=>{},this.drawLayerTile=()=>{},this.drawLayerRect=()=>{},this.drawTile=()=>{},this.drawRect=()=>{},this.clearLayerRect=()=>{};return}s&&(this.tileInfo=s.frame(0),this.tileInfo.bleed=0);for(let a=this.size.area();a--;)this.data.push(new Tn)}setData(t,e,s=!1){if(t=t.floor(),p(O(t),"layerPos must be a Vector2"),p(e instanceof Tn,"data must be a TileLayerData"),!t.arrayCheck(this.size)||(this.data[(t.y|0)*this.size.x+(t.x|0)]=e,!s))return;Tt===this.context?this.drawTileData(t):this.redrawTileData(t)}clearData(t,e=!1){this.setData(t,new Tn,e)}getData(t){return p(O(t),"layerPos must be a Vector2"),t.arrayCheck(this.size)?this.data[(t.y|0)*this.size.x+(t.x|0)]:void 0}update(){!k&&this.isUsingWebGL&&(this.isUsingWebGL=!1,this.redraw())}render(){p(Tt!==this.context,"must call redrawEnd() after drawing tiles!");let t=this.drawSize||this.size,e=this.pos.add(t.scale(.5));this.draw(e,this.size,this.color,this.angle,this.mirror,this.additiveColor)}onRedraw(){}redraw(){this.redrawStart(!0);for(let t=this.size.x;t--;)for(let e=this.size.y;e--;)this.drawTileData(b(t,e),!1);this.isUsingWebGL&&Et(),this.onRedraw(),this.redrawEnd()}redrawStart(t=!1){var s,i;if(!this.context)return;p(Tt!==this.context),this.savedRenderSettings=[Tt,I,Ct,q,nn],Tt=this.context;let e=(i=(s=this.tileInfo)==null?void 0:s.size)!=null?i:b(1);I=this.size.multiply(e),nn=ye,Ct=this.size.multiply(e).scale(.5),q=1,this.isUsingWebGL=this.hasWebGL(),this.isUsingWebGL?os(this.textureInfo.glTexture,t):(this.context.imageSmoothingEnabled=!An,t&&(this.canvas.width=I.x,this.canvas.height=I.y))}redrawEnd(){this.context&&(p(Tt===this.context),this.isUsingWebGL&&os(),[Tt,I,Ct,q,nn]=this.savedRenderSettings)}drawTileData(t,e=!0){var a,c;if(!this.context)return;p(Tt===this.context,"must call redrawStart() before drawing tiles");let s=(c=(a=this.tileInfo)==null?void 0:a.size)!=null?c:b(1),i=t.multiply(s);e&&this.clearLayerRect(i,s);let o=this.getData(t);if(!o||!o.tile)return;let r=this.tileInfo&&this.tileInfo.tile(o.tile);this.drawLayerTile(i,s,r,o.color,o.direction*X/2,o.mirror)}redrawTileData(t,e=!0){this.context&&(p(Tt!==this.context,"redrawStart() should not be active when calling redrawTileData(), instead use drawTileData()"),this.redrawStart(),this.drawTileData(t,e),this.redrawEnd())}drawLayerTile(t,e=b(1),s,i=V,o=0,r,a){let c=t.add(e.scale(.5));Pt(c,e,s,i,o,r,a,this.isUsingWebGL)}drawLayerRect(t,e,s,i=0){this.drawLayerTile(t,e,void 0,s,i)}drawTile(t,e=b(1),s,i=new wt,o=0,r=!1){t=t.subtract(this.pos).multiply(this.tileInfo.size),e=e.multiply(this.tileInfo.size),t.y=this.canvas.height-t.y;let a=I;I=b(this.canvas.width,this.canvas.height);let c=this.hasWebGL();c&&os(this.textureInfo.glTexture);let l=c?void 0:this.context;Pt(t,e,s,i,o,r,void 0,c,!0,l),c&&os(),I=a}drawRect(t,e,s,i){this.drawTile(t,e,void 0,s,i)}clearLayerRect(t,e){p(Tt===this.context,"must call redrawStart() before clearing tiles");let s=t.x,i=this.canvas.height-t.y-e.y;this.hasWebGL()?Cc(s,i,e.x,e.y):this.context.clearRect(s,i,e.x,e.y)}},Ss=class extends vs{constructor(t,e,s=Is(),i=0,o=!0){super(t,e.floor(),s,i,o),this.collisionData=[],this.initCollision(this.size),rn.push(this),this.isSolid=!0}destroy(){if(this.destroyed)return;let t=rn.indexOf(this);p(t>=0,"tile collision layer not found in array"),t>=0&&rn.splice(t,1),super.destroy()}initCollision(t){p(O(t),"size must be a Vector2"),this.size=t.floor(),this.collisionData=[],this.collisionData.length=t.area(),this.collisionData.fill(0)}setCollisionData(t,e=1){p(O(t),"layerPos must be a Vector2");let s=(t.y|0)*this.size.x+(t.x|0);t.arrayCheck(this.size)&&(this.collisionData[s]=e)}clearCollisionData(t){this.setCollisionData(t,0)}getCollisionData(t){p(O(t),"layerPos must be a Vector2");let e=(t.y|0)*this.size.x+(t.x|0);return t.arrayCheck(this.size)?this.collisionData[e]:0}collisionTest(t,e=new ot,s){p(O(t)&&O(e),"pos and size must be Vector2s"),p(!s||typeof s=="function"||s instanceof Ue,"callbackObject must be a function or EngineObject");let i=s?typeof s=="function"?(f,d)=>s(f,d):(f,d)=>s.collideWithTile(f,d):()=>!0,o=t.x-this.pos.x,r=t.y-this.pos.y;if(o+e.x/2<0||o-e.x/2>this.size.x||r+e.y/2<0||r-e.y/2>this.size.y)return!1;let a=$(o-e.x/2|0,0),c=$(r-e.y/2|0,0),l=Q($(o+e.x/2,a+1),this.size.x),u=Q($(r+e.y/2,c+1),this.size.y),h=new ot;for(let f=c;fs(l,u):(l,u)=>s.collideWithTile(l,u):l=>l>0,r=l=>{let u=this.getCollisionData(a.set(l.x-this.pos.x,l.y-this.pos.y));return u&&o(u,l)},a=new ot,c=qa(t,e,r,i);if(fe&&c){let l=c.floor().add(b(.5));bt(l,b(1),"#f008"),Te(t,e,"#00f",.02),Te(t,c,"#f00",.02),nr(c,"#0f0"),i&&Te(c,c.add(i),"#ff0",.02)}return c}},vo=class extends Ue{constructor(t,e,s=0,i=0,o=100,r=X,a,c=V,l=V,u=cn,h=cn,f=.5,d=.1,y=1,x=.1,v=.05,w=1,_=1,S=0,E=X,A=.1,T=.2,R=!1,M=!1,Z=!0,it=M?1e9:0,ht=!1){super(t,b(),a,e,void 0,it),this.emitCircle=typeof s=="number",this.emitSize=typeof s=="number"?b(s):s.copy(),this.emitTime=i,this.emitRate=o,this.emitConeAngle=r,this.colorStartA=c.copy(),this.colorStartB=l.copy(),this.colorEndA=u.copy(),this.colorEndB=h.copy(),this.randomColorLinear=Z,this.particleTime=f,this.sizeStart=d,this.sizeEnd=y,this.speed=x,this.angleSpeed=v,this.damping=w,this.angleDamping=_,this.gravityScale=S,this.particleConeAngle=E,this.fadeRate=A,this.randomness=T,this.collideTiles=R,this.additive=M,this.localSpace=ht,this.trailScale=0,this.particleCreateCallback=void 0,this.particleDestroyCallback=void 0,this.particleCollideCallback=void 0,this.velocityInheritance=0,this.emitTimeBuffer=0,this.particles=[],this.previousAngle=this.angle,this.previousPos=this.pos.copy()}update(){if(p(this.angleDamping>=0&&this.angleDamping<=1),p(this.damping>=0&&this.damping<=1),this.velocityInheritance){let s=this.velocityInheritance;this.velocity.x=s*(this.pos.x-this.previousPos.x),this.velocity.y=s*(this.pos.y-this.previousPos.y),this.angleVelocity=s*(this.angle-this.previousAngle),this.previousAngle=this.angle,this.previousPos.x=this.pos.x,this.previousPos.y=this.pos.y}if(this.isActive()){if(this.emitRate&&Zs){let s=1/this.emitRate/Zs;for(this.emitTimeBuffer+=tr;this.emitTimeBuffer>0;this.emitTimeBuffer-=s)this.emitParticle()}}else this.particles.length===0&&this.destroy(!0);let t=this.particles,e=0;for(let s=0;s_+_*ft(s,-s),o=i(this.particleTime),r=i(this.sizeStart),a=i(this.sizeEnd),c=i(this.speed),l=i(this.angleSpeed)*Xa(),u=ft(this.emitConeAngle,-this.emitConeAngle),h=po(this.colorStartA,this.colorStartB,this.randomColorLinear),f=po(this.colorEndA,this.colorEndB,this.randomColorLinear),d=this.localSpace?u:this.angle+u,y=b(c*nt(d),c*at(d)),x=l;!this.localSpace&&this.velocityInheritance>0&&(y.x+=this.velocity.x,y.y+=this.velocity.y,x+=this.angleVelocity);let v=new hi(this,t,e,h,f,o,r,a,y,x);return this.particles.push(v),(w=this.particleCreateCallback)==null||w.call(this,v),v}updatePhysics(){}render(){for(let t of this.particles)t.render()}isActive(){return!this.emitTime||this.getAliveTime()0&&(this.destroyed=!1,this.emitTime=-1))}},Vh=new ot,hi=class{constructor(t,e,s,i,o,r,a,c,l=b(),u=0){this.emitter=t,this.pos=e,this.angle=s,this.size=b(a),this.color=i.copy(),this.colorStart=i,this.colorEnd=o,this.lifeTime=r,this.sizeStart=a,this.sizeEnd=c,this.velocity=l,this.angleVelocity=u,this.spawnTime=Kt,this.mirror=Ha(),this.groundObject=void 0,this.destroyed=!1,this.tileInfo=t.tileInfo}update(){let t=this.emitter,e=t.damping,s=t.angleDamping,i=t.restitution,o=t.friction,r=t.gravityScale,a=t.collideTiles,c=t.particleCollideCallback;if(this.lifeTime>0&&Kt-this.spawnTime>this.lifeTime){this.destroy();return}let l=this.pos.copy();if(this.velocity.x*=e,this.velocity.y*=e,this.pos.x+=this.velocity.x+=Vt.x*r,this.pos.y+=this.velocity.y+=Vt.y*r,this.angle+=this.angleVelocity*=s,!Ii||!a)return;let u=this.velocity.lengthSquared();if(u>Fe*Fe){let f=Fe/u**.5;this.velocity.x*=f,this.velocity.y*=f}this.groundObject=void 0;let h=c?f=>{let d=li(f);return d&&c(this,d,f)}:f=>li(f)>0;if(h(this.pos)){let f=Qe(this.pos);if(!h(l)){let d=h(b(this.pos.x,l.y)),y=h(b(l.x,this.pos.y)),x=$(i,f.restitution),v=$(o,f.friction);d&&(this.pos.x=l.x,this.velocity.x*=-x,this.velocity.y*=v),(y||!d)&&((this.velocity.y<0&&Vt.y<0||this.velocity.y>0&&Vt.y>0)&&(this.groundObject=f),this.pos.y=l.y,this.velocity.y*=-x,this.velocity.x*=v),de&&bt(this.pos,this.size,"#f00")}}}destroy(){let t=this.emitter.particleDestroyCallback,e=this.colorEnd;this.color.set(e.r,e.g,e.b,e.a),this.size.set(this.sizeEnd,this.sizeEnd),this.destroyed=!0,t==null||t(this)}render(){let t=this.emitter,e=t.localSpace,s=t.additive,i=t.trailScale,o=t.fadeRate/2,r=this.lifeTime>0?Q((Kt-this.spawnTime)/this.lifeTime,1):1,a=1-r,c=a*this.sizeStart+r*this.sizeEnd,l=b(c),u=r1-o?(1-r)/o:1;this.color.r=a*this.colorStart.r+r*this.colorEnd.r,this.color.g=a*this.colorStart.g+r*this.colorEnd.g,this.color.b=a*this.colorStart.b+r*this.colorEnd.b,this.color.a=(a*this.colorStart.a+r*this.colorEnd.a)*u;let h=Vh.set(this.pos.x,this.pos.y),f=this.angle;if(e){let d=t.angle,y=at(-d),x=nt(-d);h.set(t.pos.x+h.x*y-h.y*x,t.pos.y+h.x*x+h.y*y),f+=d}if(s&&ps(),i){let d=e?this.velocity.rotate(t.angle):this.velocity,y=d.length();if(y){let x=y*i;l.y=$(l.x,x),f=sr(d.x,d.y),Pt(h,l,this.tileInfo,this.color,f,this.mirror)}}else Pt(h,l,this.tileInfo,this.color,f,this.mirror);s&&ps(!1),vn&&bt(h,l,"#f005",0,f)}},Mr=!0,Ao=!0,gi=5e5,Gr=11,mc=Gr*4,Wh=gi/mc|0,Fi=3,bc=Fi*4,Jn=gi/bc|0;pn=!1,yi=5,Nn=.5,mi=b(640,80),Ur=!1,Cs={},qs=[];xi=class{constructor(t,e,s="",i="\u{1F3C6}",o){p(t>=0&&!Cs[t]),this.id=t,this.name=e,this.description=s,this.icon=i,this.unlocked=!1,this.image=void 0,o&&((this.image=new Image).src=o),Cs[t]=this}unlock(){Ur||this.unlocked||(p(bi,"save name must be set"),this.unlocked=!0,Vr(),qs.push(this))}render(t=0){let e=ut,s=Q(mi.x,G.width),i=mi.y,o=G.width-s,r=-i*t,a=Ge(0,0,.9);e.save(),e.beginPath(),e.fillStyle=a.toString(),e.strokeStyle=st.toString(),e.lineWidth=3,e.rect(o,r,s,i),e.fill(),e.stroke(),e.clip();let c=b(.1,.05).scale(i),l=i-2*c.x;this.renderIcon(b(o+c.x+l/2,r+i/2),l);let u=i*.5,h=i*.3,f=b(o+l+2*c.x,r+c.y*2+u/2),d=s-l-3*c.x;on(this.name,f,u,st,0,void 0,"left",void 0,void 0,d),f.y=r+i-c.y*2-h/2,on(this.description,f,h,st,0,void 0,"left",void 0,void 0,d),e.restore()}renderIcon(t,e){this.image?ut.drawImage(this.image,t.x-e/2,t.y-e/2,e,e):on(this.icon,t,e*.7,st)}};_o=class extends xi{constructor(t,e,s,i,o){super(t,e,s,i,o)}unlock(){super.unlock(),Es&&Es.unlockMedal(this.id)}},Ro=class{constructor(t,e,s){var c,l,u;p(!Es,"there can only be one newgrounds object"),p(!e||s,"must provide cryptojs if there is a cipher"),Es=this,this.app_id=t,this.cipher=e,this.cryptoJS=s,this.host=location?location.hostname:"";let i=new URL(location.href);if(this.session_id=i.searchParams.get("ngio_session_id"),!this.session_id)return;let o=this.call("Medal.getList");if(!o||!o.result||o.result.error){pn&&xt("Newgrounds session unavailable; skipping plugin init"),this.medals=[],this.scoreboards=[];return}this.medals=((c=o.result.data)==null?void 0:c.medals)||[],pn&&xt(this.medals);for(let h of this.medals){let f=Cs[h.id];f&&(f.image=new Image,f.image.src=h.icon,f.name=h.name,f.description=h.description,f.unlocked=h.unlocked,f.difficulty=h.difficulty,f.value=h.value,f.value&&(f.description=f.description+` (${f.value})`))}let r=this.call("ScoreBoard.getBoards");this.scoreboards=((u=(l=r==null?void 0:r.result)==null?void 0:l.data)==null?void 0:u.scoreboards)||[],pn&&xt(this.scoreboards);let a=60*1e3;setInterval(()=>this.call("Gateway.ping",0,!0),a)}unlockMedal(t){return this.call("Medal.unlock",{id:t},!0)}postScore(t,e){return this.call("ScoreBoard.postScore",{id:t,value:e},!0)}getScores(t,e,s=0,i=0,o=10){return this.call("ScoreBoard.getScores",{id:t,user:e,social:s,skip:i,limit:o})}logView(){return this.call("App.logView",{host:this.host},!0)}call(t,e,s=!1){let i={component:t,parameters:e};if(this.cipher){let l=this.cryptoJS,u=l.enc.Base64.parse(this.cipher),h=l.lib.WordArray.random(16),f=l.AES.encrypt(JSON.stringify(i),u,{iv:h});i.secure=l.enc.Base64.stringify(h.concat(f.ciphertext)),i.parameters=0}let o={app_id:this.app_id,session_id:this.session_id,call:i},r=new FormData;r.append("input",JSON.stringify(o));let a=new XMLHttpRequest;a.open("POST","https://newgrounds.io/gateway_v3.php",!pn&&s);try{a.send(r)}catch(l){pn&&xt("newgrounds call failed",l);return}return pn&&xt(a.responseText),a.responseText&&JSON.parse(a.responseText)}},Po=class{constructor(t,e=!1,s=!1){p(!It,"Post process already initialized"),p(!(e&&s),"Post process cannot both include main canvas and use feedback texture"),It=this,t||(t="void mainImage(out vec4 c,vec2 p){c=texture(iChannel0,p/iResolution.xy);}"),this.shader=void 0,this.texture=void 0,this.vao=void 0,i(),_n(void 0,a,o,r);function i(){if(N)return;if(!k){console.warn("PostProcessPlugin: WebGL not enabled!");return}It.texture=ji(),It.shader=Yn(`#version 300 es
+color = `+this.color),t}renderDebugInfo(){if(!Ft)return;let t=this.collideTiles||this.collideSolidObjects||this.isSolid;if(!t&&!this.parent)return;let e=b($(this.size.x,.2),$(this.size.y,.2)),s=z(this.collideTiles?1:0,this.collideSolidObjects?1:0,this.isSolid?1:0,.5);bt(this.pos,e,s,0,this.angle,t),this.parent&&bt(this.pos,e.scale(.8),z(1,1,1,.5),0,this.angle),this.parent&&Te(this.pos,this.parent.pos,z(1,1,1,.5),.5)}},I=b(),un=[];Pe=class n{constructor(t=b(),e=Li,s=un[0],i=Oi,o=Di){this.pos=t.copy(),this.size=e.copy(),this.padding=i,this.textureInfo=s,this.bleed=o}offset(t){return new n(this.pos.add(t),this.size,this.textureInfo,this.padding,this.bleed)}frame(t){p(typeof t=="number");let e=this.size.x+this.padding*2,s=t*e;return p(s+this.size.x<=this.textureInfo.size.x,"frame extends beyond texture width!"),this.offset(new rt(s))}setFullImage(t=this.textureInfo){return this.textureInfo=t,this.pos=new rt,this.size=t.size.copy(),this.bleed=this.padding=0,this}tile(t){return Is(t,this.size,this.textureInfo,this.padding,this.bleed)}},We=class{constructor(t,e=!0,s=!1){this.image=t,this.size=t?b(t.width,t.height):b(),this.sizeInverse=t?b(1/t.width,1/t.height):b(),this.glTexture=void 0,this.wrap=s,e&&this.createWebGLTexture()}createWebGLTexture(){Hh(this)}destroyWebGLTexture(){Xh(this)}hasWebGL(){return!!this.glTexture}setWrap(t=!0){this.wrap=t,Sc(this.glTexture,t)}};nh=0;ii=class{constructor(t){p(!!t,"tileInfo is required for ImageFont"),this.tileInfo=t.frame(0)}drawText(t,e,s=1,i,o,r,a){p(O(s)||typeof s=="number","size must be a vec2 or number"),typeof s=="number"?(p(s>0),s*=q,s=new rt(s,s)):s=s.scale(q),this.drawTextScreen(t,Ln(e),s,i,o,r,a)}drawTextScreen(t,e,s,i=!0,o=V,r=k,a){p(U(t),"text must be a string"),p(O(e),"pos must be a vec2"),p(O(s)||typeof s=="number","size must be a vec2 or number"),p(J(o),"color must be a color"),s=typeof s=="number"?new rt(s,s):s;let c=new rt,l=this.tileInfo,u=l.padding,h=l.size.x+u*2,f=l.size.y+u*2,d=l.textureInfo.size.x/h|0;(t+"").split(`
+`).forEach((y,x)=>{let v=i?(y.length-1)*s.x/2:0;for(let w=y.length;w--;){let _=y.charCodeAt(w),S=_<32||_>127?95:_-32,E=S%d,A=S/d|0;l.pos.x=E*h+u,l.pos.y=A*f+u,c.x=e.x+w*s.x-v|0,c.y=e.y+x*s.y|0,Lt(c,s,l,o,0,!1,void 0,r,!0,a)}})}};Ie=b(),Ut=b(),Tr=b(),ve=b(),Ar=0,oi=!0,Bn=!1,tn="mouse",Cr=6,jn=!0,mt=0,oe=!N&&window.ontouchstart!==void 0;Y=[[]],Se=[],gn=[],co=[],Wn=new Ee,re=[],Cn=[],ri=[],Fs=[],Be=new Map,ms=[],qn=!0;ai="http://www.w3.org/2000/svg";pt=new AudioContext,Zn=44100;xs=class{constructor(t,e,s=xr,i=vr,o){var r;if(!(!Xt||N)){if(p(!t||pe(t)||U(t),"asset must be a file name or zzfx array"),p(e===void 0||P(e),"randomness must be a number"),p(e===void 0||e>=0&&e<=1,"randomness must be between 0 and 1"),p(P(s),"range must be a number"),p(P(i),"taper must be a number"),this.range=s,this.taper=i,this.randomness=e!=null?e:0,this.sampleRate=Zn,this.loadedPercent=0,this.onloadCallback=o,pe(t)){let a=t.slice(),c=e!=null?e:.05,l=1;this.randomness=(r=a[l])!=null?r:c,a[l]=0,this.sampleChannels=[Gi(...a)],this.loadedPercent=1,o==null||o(this)}else if(typeof t=="string"){let a=t;this.loadSound(a)}}}play(t,e=1,s=1,i=1,o=!1,r=!1){if(p(!t||O(t),"pos must be a vec2"),p(P(e),"volume must be a number"),p(P(s),"pitch must be a number"),p(P(i),"randomnessScale must be a number"),!Xt||N||!this.sampleChannels)return;let a;if(t){let u=this.range;if(u){let h=Ct.distanceSquared(t);if(h>u*u)return;e*=jt(h**.5,u,u*this.taper)}a=Ln(t).x*2/G.width-1}let c=s+s*this.randomness*i*ft(-1,1),l=new ci(this,e,c,a,o,r);return Ft&&Un&&t&&(Vt(t,.5,"#0ff",.5,!0),this.range&&(Vt(t,2*this.range,"#0ff",.5),Vt(t,2*this.range*this.taper,"#0ff",.5)),Mn("vol "+e.toFixed(2)+" pitch "+c.toFixed(2),t,.5,"#0ff",.5)),l}playMusic(t=1,e=!0,s=!1){return this.play(void 0,t,1,0,e,s)}playNote(t=0,e,s){p(P(t),"semitoneOffset must be a number");let i=gc(t,1);return this.play(e,s,i,0)}getDuration(){var t,e;return((e=(t=this.sampleChannels)==null?void 0:t[0])==null?void 0:e.length)/this.sampleRate||0}isLoaded(){return this.loadedPercent===1}async loadSound(t){var c;let e=await fetch(t);if(!e.ok)throw new Error(`Failed to load sound from ${t}: ${e.status} ${e.statusText}`);let s=await e.arrayBuffer(),i=await pt.decodeAudioData(s),o=i.numberOfChannels,r=1e5,a=[];for(let l=0;lsetTimeout(v,0));let d=Q(f+r,h);for(;f=0,"Sound volume must be positive or zero"),p(s>=0,"Sound rate must be positive or zero"),p(P(i),"Sound pan must be a number"),this.sound=t,this.volume=e,this.rate=s,this.pan=i,this.loop=o,this.pausedTime=0,this.startTime=void 0,this.gainNode=void 0,this.source=void 0,this.onendedCallback=a=>{a===this.source&&(this.source=void 0)},r||this.start()}start(t=0){p(t>=0,"Sound start offset must be positive or zero"),this.isPlaying()&&this.stop(),this.gainNode=pt.createGain(),this.source=Ir(this.sound.sampleChannels,this.volume,this.rate,this.pan,this.loop,this.sound.sampleRate,this.gainNode,t,this.onendedCallback),this.source?(this.startTime=pt.currentTime-t,this.pausedTime=void 0):(this.startTime=void 0,this.pausedTime=0)}setVolume(t){p(t>=0,"Sound volume must be positive or zero"),this.volume=t,this.gainNode&&(this.gainNode.gain.value=t)}stop(t=0){if(p(t>=0,"Sound fade time must be positive or zero"),this.isPlaying())if(t){let e=pt.currentTime,s=e+t;this.gainNode.gain.cancelScheduledValues(e),this.gainNode.gain.setValueAtTime(this.volume,e),this.gainNode.gain.linearRampToValueAtTime(0,s),this.source.stop(s)}else this.source.stop();this.pausedTime=0,this.source=void 0,this.startTime=void 0}pause(){this.isPaused()||(this.pausedTime=this.getCurrentTime(),this.source.stop(),this.source=void 0,this.startTime=void 0)}resume(){this.isPaused()&&this.start(this.pausedTime)}isPlaying(){return!!this.source}isPaused(){return!this.isPlaying()}getCurrentTime(){if(!this.isPlaying())return this.pausedTime;let t=this.getDuration();return t?ie(pt.currentTime-this.startTime,t):0}getDuration(){return this.rate?this.sound.getDuration()/this.rate:0}getSource(){return this.source}};rn=[];Tn=class{constructor(t,e=0,s=!1,i=new wt){this.tile=t,this.direction=e,this.mirror=s,this.color=i.copy()}clear(){this.tile=this.direction=0,this.mirror=!1,this.color=new wt}},ui=class extends Ve{constructor(t,e,s=0,i=0,o=b(512),r=!0){var a;p(O(o),"canvasSize must be a Vector2"),super(t,e,void 0,s,V,i),this.canvas=N?void 0:new OffscreenCanvas(o.x,o.y),this.context=(a=this.canvas)==null?void 0:a.getContext("2d"),this.textureInfo=new We(this.canvas,r),this.mass=0}destroy(){this.destroyed||(this.textureInfo.destroyWebGLTexture(),super.destroy())}render(){this.draw(this.pos,this.size,this.color,this.angle,this.mirror,this.additiveColor)}draw(t,e,s=V,i=0,o=!1,r,a=!1,c){let l=new Pe().setFullImage(this.textureInfo),u=this.hasWebGL();Lt(t,e,l,s,i,o,r,u,a,c)}updateWebGL(){this.textureInfo.createWebGLTexture()}hasWebGL(){return k&&this.textureInfo.hasWebGL()}},vs=class extends ui{constructor(t,e,s=Is(),i=0,o=!0){let r=s?e.multiply(s.size):e;if(super(t,e,0,i,r,o),this.tileInfo=void 0,this.data=[],this.isUsingWebGL=!1,N){this.render=()=>{},this.redraw=()=>{},this.redrawStart=()=>{},this.redrawEnd=()=>{},this.drawTileData=()=>{},this.redrawTileData=()=>{},this.drawLayerTile=()=>{},this.drawLayerRect=()=>{},this.drawTile=()=>{},this.drawRect=()=>{},this.clearLayerRect=()=>{};return}s&&(this.tileInfo=s.frame(0),this.tileInfo.bleed=0);for(let a=this.size.area();a--;)this.data.push(new Tn)}setData(t,e,s=!1){if(t=t.floor(),p(O(t),"layerPos must be a Vector2"),p(e instanceof Tn,"data must be a TileLayerData"),!t.arrayCheck(this.size)||(this.data[(t.y|0)*this.size.x+(t.x|0)]=e,!s))return;Tt===this.context?this.drawTileData(t):this.redrawTileData(t)}clearData(t,e=!1){this.setData(t,new Tn,e)}getData(t){return p(O(t),"layerPos must be a Vector2"),t.arrayCheck(this.size)?this.data[(t.y|0)*this.size.x+(t.x|0)]:void 0}update(){!k&&this.isUsingWebGL&&(this.isUsingWebGL=!1,this.redraw())}render(){p(Tt!==this.context,"must call redrawEnd() after drawing tiles!");let t=this.drawSize||this.size,e=this.pos.add(t.scale(.5));this.draw(e,this.size,this.color,this.angle,this.mirror,this.additiveColor)}onRedraw(){}redraw(){this.redrawStart(!0);for(let t=this.size.x;t--;)for(let e=this.size.y;e--;)this.drawTileData(b(t,e),!1);this.isUsingWebGL&&Et(),this.onRedraw(),this.redrawEnd()}redrawStart(t=!1){var s,i;if(!this.context)return;p(Tt!==this.context),this.savedRenderSettings=[Tt,I,Ct,q,nn],Tt=this.context;let e=(i=(s=this.tileInfo)==null?void 0:s.size)!=null?i:b(1);I=this.size.multiply(e),nn=ye,Ct=this.size.multiply(e).scale(.5),q=1,this.isUsingWebGL=this.hasWebGL(),this.isUsingWebGL?os(this.textureInfo.glTexture,t):(this.context.imageSmoothingEnabled=!An,t&&(this.canvas.width=I.x,this.canvas.height=I.y))}redrawEnd(){this.context&&(p(Tt===this.context),this.isUsingWebGL&&os(),[Tt,I,Ct,q,nn]=this.savedRenderSettings)}drawTileData(t,e=!0){var a,c;if(!this.context)return;p(Tt===this.context,"must call redrawStart() before drawing tiles");let s=(c=(a=this.tileInfo)==null?void 0:a.size)!=null?c:b(1),i=t.multiply(s);e&&this.clearLayerRect(i,s);let o=this.getData(t);if(!o||!o.tile)return;let r=this.tileInfo&&this.tileInfo.tile(o.tile);this.drawLayerTile(i,s,r,o.color,o.direction*X/2,o.mirror)}redrawTileData(t,e=!0){this.context&&(p(Tt!==this.context,"redrawStart() should not be active when calling redrawTileData(), instead use drawTileData()"),this.redrawStart(),this.drawTileData(t,e),this.redrawEnd())}drawLayerTile(t,e=b(1),s,i=V,o=0,r,a){let c=t.add(e.scale(.5));Lt(c,e,s,i,o,r,a,this.isUsingWebGL)}drawLayerRect(t,e,s,i=0){this.drawLayerTile(t,e,void 0,s,i)}drawTile(t,e=b(1),s,i=new wt,o=0,r=!1){t=t.subtract(this.pos).multiply(this.tileInfo.size),e=e.multiply(this.tileInfo.size),t.y=this.canvas.height-t.y;let a=I;I=b(this.canvas.width,this.canvas.height);let c=this.hasWebGL();c&&os(this.textureInfo.glTexture);let l=c?void 0:this.context;Lt(t,e,s,i,o,r,void 0,c,!0,l),c&&os(),I=a}drawRect(t,e,s,i){this.drawTile(t,e,void 0,s,i)}clearLayerRect(t,e){p(Tt===this.context,"must call redrawStart() before clearing tiles");let s=t.x,i=this.canvas.height-t.y-e.y;this.hasWebGL()?Cc(s,i,e.x,e.y):this.context.clearRect(s,i,e.x,e.y)}},Ss=class extends vs{constructor(t,e,s=Is(),i=0,o=!0){super(t,e.floor(),s,i,o),this.collisionData=[],this.initCollision(this.size),rn.push(this),this.isSolid=!0}destroy(){if(this.destroyed)return;let t=rn.indexOf(this);p(t>=0,"tile collision layer not found in array"),t>=0&&rn.splice(t,1),super.destroy()}initCollision(t){p(O(t),"size must be a Vector2"),this.size=t.floor(),this.collisionData=[],this.collisionData.length=t.area(),this.collisionData.fill(0)}setCollisionData(t,e=1){p(O(t),"layerPos must be a Vector2");let s=(t.y|0)*this.size.x+(t.x|0);t.arrayCheck(this.size)&&(this.collisionData[s]=e)}clearCollisionData(t){this.setCollisionData(t,0)}getCollisionData(t){p(O(t),"layerPos must be a Vector2");let e=(t.y|0)*this.size.x+(t.x|0);return t.arrayCheck(this.size)?this.collisionData[e]:0}collisionTest(t,e=new rt,s){p(O(t)&&O(e),"pos and size must be Vector2s"),p(!s||typeof s=="function"||s instanceof Ve,"callbackObject must be a function or EngineObject");let i=s?typeof s=="function"?(f,d)=>s(f,d):(f,d)=>s.collideWithTile(f,d):()=>!0,o=t.x-this.pos.x,r=t.y-this.pos.y;if(o+e.x/2<0||o-e.x/2>this.size.x||r+e.y/2<0||r-e.y/2>this.size.y)return!1;let a=$(o-e.x/2|0,0),c=$(r-e.y/2|0,0),l=Q($(o+e.x/2,a+1),this.size.x),u=Q($(r+e.y/2,c+1),this.size.y),h=new rt;for(let f=c;fs(l,u):(l,u)=>s.collideWithTile(l,u):l=>l>0,r=l=>{let u=this.getCollisionData(a.set(l.x-this.pos.x,l.y-this.pos.y));return u&&o(u,l)},a=new rt,c=qa(t,e,r,i);if(fe&&c){let l=c.floor().add(b(.5));bt(l,b(1),"#f008"),Te(t,e,"#00f",.02),Te(t,c,"#f00",.02),nr(c,"#0f0"),i&&Te(c,c.add(i),"#ff0",.02)}return c}},vo=class extends Ve{constructor(t,e,s=0,i=0,o=100,r=X,a,c=V,l=V,u=cn,h=cn,f=.5,d=.1,y=1,x=.1,v=.05,w=1,_=1,S=0,E=X,A=.1,T=.2,R=!1,M=!1,Z=!0,it=M?1e9:0,ht=!1){super(t,b(),a,e,void 0,it),this.emitCircle=typeof s=="number",this.emitSize=typeof s=="number"?b(s):s.copy(),this.emitTime=i,this.emitRate=o,this.emitConeAngle=r,this.colorStartA=c.copy(),this.colorStartB=l.copy(),this.colorEndA=u.copy(),this.colorEndB=h.copy(),this.randomColorLinear=Z,this.particleTime=f,this.sizeStart=d,this.sizeEnd=y,this.speed=x,this.angleSpeed=v,this.damping=w,this.angleDamping=_,this.gravityScale=S,this.particleConeAngle=E,this.fadeRate=A,this.randomness=T,this.collideTiles=R,this.additive=M,this.localSpace=ht,this.trailScale=0,this.particleCreateCallback=void 0,this.particleDestroyCallback=void 0,this.particleCollideCallback=void 0,this.velocityInheritance=0,this.emitTimeBuffer=0,this.particles=[],this.previousAngle=this.angle,this.previousPos=this.pos.copy()}update(){if(p(this.angleDamping>=0&&this.angleDamping<=1),p(this.damping>=0&&this.damping<=1),this.velocityInheritance){let s=this.velocityInheritance;this.velocity.x=s*(this.pos.x-this.previousPos.x),this.velocity.y=s*(this.pos.y-this.previousPos.y),this.angleVelocity=s*(this.angle-this.previousAngle),this.previousAngle=this.angle,this.previousPos.x=this.pos.x,this.previousPos.y=this.pos.y}if(this.isActive()){if(this.emitRate&&Zs){let s=1/this.emitRate/Zs;for(this.emitTimeBuffer+=tr;this.emitTimeBuffer>0;this.emitTimeBuffer-=s)this.emitParticle()}}else this.particles.length===0&&this.destroy(!0);let t=this.particles,e=0;for(let s=0;s_+_*ft(s,-s),o=i(this.particleTime),r=i(this.sizeStart),a=i(this.sizeEnd),c=i(this.speed),l=i(this.angleSpeed)*Xa(),u=ft(this.emitConeAngle,-this.emitConeAngle),h=po(this.colorStartA,this.colorStartB,this.randomColorLinear),f=po(this.colorEndA,this.colorEndB,this.randomColorLinear),d=this.localSpace?u:this.angle+u,y=b(c*nt(d),c*ct(d)),x=l;!this.localSpace&&this.velocityInheritance>0&&(y.x+=this.velocity.x,y.y+=this.velocity.y,x+=this.angleVelocity);let v=new hi(this,t,e,h,f,o,r,a,y,x);return this.particles.push(v),(w=this.particleCreateCallback)==null||w.call(this,v),v}updatePhysics(){}render(){for(let t of this.particles)t.render()}isActive(){return!this.emitTime||this.getAliveTime()0&&(this.destroyed=!1,this.emitTime=-1))}},Vh=new rt,hi=class{constructor(t,e,s,i,o,r,a,c,l=b(),u=0){this.emitter=t,this.pos=e,this.angle=s,this.size=b(a),this.color=i.copy(),this.colorStart=i,this.colorEnd=o,this.lifeTime=r,this.sizeStart=a,this.sizeEnd=c,this.velocity=l,this.angleVelocity=u,this.spawnTime=Qt,this.mirror=Ha(),this.groundObject=void 0,this.destroyed=!1,this.tileInfo=t.tileInfo}update(){let t=this.emitter,e=t.damping,s=t.angleDamping,i=t.restitution,o=t.friction,r=t.gravityScale,a=t.collideTiles,c=t.particleCollideCallback;if(this.lifeTime>0&&Qt-this.spawnTime>this.lifeTime){this.destroy();return}let l=this.pos.copy();if(this.velocity.x*=e,this.velocity.y*=e,this.pos.x+=this.velocity.x+=Wt.x*r,this.pos.y+=this.velocity.y+=Wt.y*r,this.angle+=this.angleVelocity*=s,!Ii||!a)return;let u=this.velocity.lengthSquared();if(u>je*je){let f=je/u**.5;this.velocity.x*=f,this.velocity.y*=f}this.groundObject=void 0;let h=c?f=>{let d=li(f);return d&&c(this,d,f)}:f=>li(f)>0;if(h(this.pos)){let f=Qe(this.pos);if(!h(l)){let d=h(b(this.pos.x,l.y)),y=h(b(l.x,this.pos.y)),x=$(i,f.restitution),v=$(o,f.friction);d&&(this.pos.x=l.x,this.velocity.x*=-x,this.velocity.y*=v),(y||!d)&&((this.velocity.y<0&&Wt.y<0||this.velocity.y>0&&Wt.y>0)&&(this.groundObject=f),this.pos.y=l.y,this.velocity.y*=-x,this.velocity.x*=v),de&&bt(this.pos,this.size,"#f00")}}}destroy(){let t=this.emitter.particleDestroyCallback,e=this.colorEnd;this.color.set(e.r,e.g,e.b,e.a),this.size.set(this.sizeEnd,this.sizeEnd),this.destroyed=!0,t==null||t(this)}render(){let t=this.emitter,e=t.localSpace,s=t.additive,i=t.trailScale,o=t.fadeRate/2,r=this.lifeTime>0?Q((Qt-this.spawnTime)/this.lifeTime,1):1,a=1-r,c=a*this.sizeStart+r*this.sizeEnd,l=b(c),u=r1-o?(1-r)/o:1;this.color.r=a*this.colorStart.r+r*this.colorEnd.r,this.color.g=a*this.colorStart.g+r*this.colorEnd.g,this.color.b=a*this.colorStart.b+r*this.colorEnd.b,this.color.a=(a*this.colorStart.a+r*this.colorEnd.a)*u;let h=Vh.set(this.pos.x,this.pos.y),f=this.angle;if(e){let d=t.angle,y=ct(-d),x=nt(-d);h.set(t.pos.x+h.x*y-h.y*x,t.pos.y+h.x*x+h.y*y),f+=d}if(s&&ps(),i){let d=e?this.velocity.rotate(t.angle):this.velocity,y=d.length();if(y){let x=y*i;l.y=$(l.x,x),f=sr(d.x,d.y),Lt(h,l,this.tileInfo,this.color,f,this.mirror)}}else Lt(h,l,this.tileInfo,this.color,f,this.mirror);s&&ps(!1),vn&&bt(h,l,"#f005",0,f)}},Mr=!0,Ao=!0,gi=5e5,Gr=11,mc=Gr*4,Wh=gi/mc|0,Fi=3,bc=Fi*4,Jn=gi/bc|0;pn=!1,yi=5,Nn=.5,mi=b(640,80),Ur=!1,Cs={},qs=[];xi=class{constructor(t,e,s="",i="\u{1F3C6}",o){p(t>=0&&!Cs[t]),this.id=t,this.name=e,this.description=s,this.icon=i,this.unlocked=!1,this.image=void 0,o&&((this.image=new Image).src=o),Cs[t]=this}unlock(){Ur||this.unlocked||(p(bi,"save name must be set"),this.unlocked=!0,Vr(),qs.push(this))}render(t=0){let e=ut,s=Q(mi.x,G.width),i=mi.y,o=G.width-s,r=-i*t,a=Fe(0,0,.9);e.save(),e.beginPath(),e.fillStyle=a.toString(),e.strokeStyle=st.toString(),e.lineWidth=3,e.rect(o,r,s,i),e.fill(),e.stroke(),e.clip();let c=b(.1,.05).scale(i),l=i-2*c.x;this.renderIcon(b(o+c.x+l/2,r+i/2),l);let u=i*.5,h=i*.3,f=b(o+l+2*c.x,r+c.y*2+u/2),d=s-l-3*c.x;on(this.name,f,u,st,0,void 0,"left",void 0,void 0,d),f.y=r+i-c.y*2-h/2,on(this.description,f,h,st,0,void 0,"left",void 0,void 0,d),e.restore()}renderIcon(t,e){this.image?ut.drawImage(this.image,t.x-e/2,t.y-e/2,e,e):on(this.icon,t,e*.7,st)}};_o=class extends xi{constructor(t,e,s,i,o){super(t,e,s,i,o)}unlock(){super.unlock(),Es&&Es.unlockMedal(this.id)}},Ro=class{constructor(t,e,s){var c,l,u;p(!Es,"there can only be one newgrounds object"),p(!e||s,"must provide cryptojs if there is a cipher"),Es=this,this.app_id=t,this.cipher=e,this.cryptoJS=s,this.host=location?location.hostname:"";let i=new URL(location.href);if(this.session_id=i.searchParams.get("ngio_session_id"),!this.session_id)return;let o=this.call("Medal.getList");if(!o||!o.result||o.result.error){pn&&xt("Newgrounds session unavailable; skipping plugin init"),this.medals=[],this.scoreboards=[];return}this.medals=((c=o.result.data)==null?void 0:c.medals)||[],pn&&xt(this.medals);for(let h of this.medals){let f=Cs[h.id];f&&(f.image=new Image,f.image.src=h.icon,f.name=h.name,f.description=h.description,f.unlocked=h.unlocked,f.difficulty=h.difficulty,f.value=h.value,f.value&&(f.description=f.description+` (${f.value})`))}let r=this.call("ScoreBoard.getBoards");this.scoreboards=((u=(l=r==null?void 0:r.result)==null?void 0:l.data)==null?void 0:u.scoreboards)||[],pn&&xt(this.scoreboards);let a=60*1e3;setInterval(()=>this.call("Gateway.ping",0,!0),a)}unlockMedal(t){return this.call("Medal.unlock",{id:t},!0)}postScore(t,e){return this.call("ScoreBoard.postScore",{id:t,value:e},!0)}getScores(t,e,s=0,i=0,o=10){return this.call("ScoreBoard.getScores",{id:t,user:e,social:s,skip:i,limit:o})}logView(){return this.call("App.logView",{host:this.host},!0)}call(t,e,s=!1){let i={component:t,parameters:e};if(this.cipher){let l=this.cryptoJS,u=l.enc.Base64.parse(this.cipher),h=l.lib.WordArray.random(16),f=l.AES.encrypt(JSON.stringify(i),u,{iv:h});i.secure=l.enc.Base64.stringify(h.concat(f.ciphertext)),i.parameters=0}let o={app_id:this.app_id,session_id:this.session_id,call:i},r=new FormData;r.append("input",JSON.stringify(o));let a=new XMLHttpRequest;a.open("POST","https://newgrounds.io/gateway_v3.php",!pn&&s);try{a.send(r)}catch(l){pn&&xt("newgrounds call failed",l);return}return pn&&xt(a.responseText),a.responseText&&JSON.parse(a.responseText)}},Po=class{constructor(t,e=!1,s=!1){p(!Mt,"Post process already initialized"),p(!(e&&s),"Post process cannot both include main canvas and use feedback texture"),Mt=this,t||(t="void mainImage(out vec4 c,vec2 p){c=texture(iChannel0,p/iResolution.xy);}"),this.shader=void 0,this.texture=void 0,this.vao=void 0,i(),_n(void 0,a,o,r);function i(){if(N)return;if(!k){console.warn("PostProcessPlugin: WebGL not enabled!");return}Mt.texture=ji(),Mt.shader=Yn(`#version 300 es
 precision highp float;in vec2 p;void main(){gl_Position=vec4(p+p-1.,1,1);}`,`#version 300 es
 precision highp float;uniform sampler2D iChannel0;uniform vec3 iResolution;uniform float iTime;out vec4 c;
 `+t+`
-void main(){mainImage(c,gl_FragCoord.xy);c.a=1.;}`),It.vao=g.createVertexArray(),g.bindVertexArray(It.vao),g.bindBuffer(g.ARRAY_BUFFER,zn);let c=8,l=g.getAttribLocation(It.shader,"p");g.enableVertexAttribArray(l),g.vertexAttribPointer(l,2,g.FLOAT,!1,c,0)}function o(){It.shader=void 0,It.texture=void 0,xt("PostProcessPlugin: WebGL context lost")}function r(){i(),xt("PostProcessPlugin: WebGL context restored")}function a(){if(N||!k)return;Et(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.useProgram(It.shader),g.bindVertexArray(It.vao),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!0),g.disable(g.BLEND),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,It.texture),e?(Be.width=I.x,Be.height=I.y,Nr(Ze),Ze.drawImage(G,0,0),G.width|=0,g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,Be)):s||g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,tt);let c=l=>g.getUniformLocation(It.shader,l);g.uniform1i(c("iChannel0"),0),g.uniform1f(c("iTime"),Kt),g.uniform3f(c("iResolution"),G.width,G.height,1),g.drawArrays(g.TRIANGLE_STRIP,0,4),s&&g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,tt),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!1),Ts(!0)}}},Lo=class{constructor(t,e){p(!W,"LightSystemPlugin already initialized"),p(!It,"LightSystemPlugin must be created before PostProcessPlugin"),W=this,this.enabled=!0,this.ambientColor=(e||st).copy(),this.textureSize=t?t.copy():void 0,this.texture=void 0,this.lightShader=void 0,this.compositeShader=void 0,this.lightVAO=void 0,this.compositeVAO=void 0,s(),_n(void 0,i,o,r);function s(){if(N)return;if(!k){console.warn("LightSystemPlugin: WebGL not enabled!");return}W.textureSize||(W.textureSize=I.copy()),W.texture=g.createTexture(),g.bindTexture(g.TEXTURE_2D,W.texture),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,W.textureSize.x,W.textureSize.y,0,g.RGBA,g.UNSIGNED_BYTE,null),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,g.CLAMP_TO_EDGE),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,g.CLAMP_TO_EDGE),W.lightShader=Yn(`#version 300 es
+void main(){mainImage(c,gl_FragCoord.xy);c.a=1.;}`),Mt.vao=g.createVertexArray(),g.bindVertexArray(Mt.vao),g.bindBuffer(g.ARRAY_BUFFER,zn);let c=8,l=g.getAttribLocation(Mt.shader,"p");g.enableVertexAttribArray(l),g.vertexAttribPointer(l,2,g.FLOAT,!1,c,0)}function o(){Mt.shader=void 0,Mt.texture=void 0,xt("PostProcessPlugin: WebGL context lost")}function r(){i(),xt("PostProcessPlugin: WebGL context restored")}function a(){if(N||!k)return;Et(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.useProgram(Mt.shader),g.bindVertexArray(Mt.vao),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!0),g.disable(g.BLEND),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,Mt.texture),e?(ze.width=I.x,ze.height=I.y,Nr(Ze),Ze.drawImage(G,0,0),G.width|=0,g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,ze)):s||g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,tt);let c=l=>g.getUniformLocation(Mt.shader,l);g.uniform1i(c("iChannel0"),0),g.uniform1f(c("iTime"),Qt),g.uniform3f(c("iResolution"),G.width,G.height,1),g.drawArrays(g.TRIANGLE_STRIP,0,4),s&&g.texImage2D(g.TEXTURE_2D,0,g.RGBA,g.RGBA,g.UNSIGNED_BYTE,tt),g.pixelStorei(g.UNPACK_FLIP_Y_WEBGL,!1),Ts(!0)}}},Lo=class{constructor(t,e){p(!W,"LightSystemPlugin already initialized"),p(!Mt,"LightSystemPlugin must be created before PostProcessPlugin"),W=this,this.enabled=!0,this.ambientColor=(e||st).copy(),this.textureSize=t?t.copy():void 0,this.texture=void 0,this.lightShader=void 0,this.compositeShader=void 0,this.lightVAO=void 0,this.compositeVAO=void 0,s(),_n(void 0,i,o,r);function s(){if(N)return;if(!k){console.warn("LightSystemPlugin: WebGL not enabled!");return}W.textureSize||(W.textureSize=I.copy()),W.texture=g.createTexture(),g.bindTexture(g.TEXTURE_2D,W.texture),g.texImage2D(g.TEXTURE_2D,0,g.RGBA,W.textureSize.x,W.textureSize.y,0,g.RGBA,g.UNSIGNED_BYTE,null),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,g.LINEAR),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,g.CLAMP_TO_EDGE),g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,g.CLAMP_TO_EDGE),W.lightShader=Yn(`#version 300 es
 precision highp float;uniform mat4 m;uniform vec2 lightPos;uniform float radius;in vec2 g;out vec2 vWorldPos;void main(){vec2 worldP=lightPos+(g-.5)*2.*radius;gl_Position=m*vec4(worldP,1,1);vWorldPos=worldP;}`,`#version 300 es
 precision highp float;uniform vec2 lightPos;uniform float radius;uniform float fadeRange;uniform vec4 color;in vec2 vWorldPos;out vec4 c;void main(){float dist=distance(vWorldPos,lightPos);float t=clamp((radius-dist)/max(fadeRange,1e-6),0.,1.);c=vec4(color.rgb*t*color.a,1.);}`),W.compositeShader=Yn(`#version 300 es
 precision highp float;in vec2 p;void main(){gl_Position=vec4(p+p-1.,1,1);}`,`#version 300 es
-precision highp float;uniform sampler2D s;uniform vec3 iResolution;out vec4 c;void main(){vec2 uv=gl_FragCoord.xy/iResolution.xy;c=vec4(texture(s,uv).rgb,1.);}`),W.lightVAO=g.createVertexArray(),g.bindVertexArray(W.lightVAO),g.bindBuffer(g.ARRAY_BUFFER,zn);let a=g.getAttribLocation(W.lightShader,"g");g.enableVertexAttribArray(a),g.vertexAttribPointer(a,2,g.FLOAT,!1,8,0),W.compositeVAO=g.createVertexArray(),g.bindVertexArray(W.compositeVAO),g.bindBuffer(g.ARRAY_BUFFER,zn);let c=g.getAttribLocation(W.compositeShader,"p");g.enableVertexAttribArray(c),g.vertexAttribPointer(c,2,g.FLOAT,!1,8,0)}function i(){if(N||!k||!W.enabled||!W.texture)return;Et();let a=Dn,c=W.ambientColor;g.bindFramebuffer(g.FRAMEBUFFER,kr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,W.texture,0),g.viewport(0,0,W.textureSize.x,W.textureSize.y),g.clearColor(c.r,c.g,c.b,c.a),g.clear(g.COLOR_BUFFER_BIT),ps(),g.enable(g.BLEND),g.blendFunc(g.ONE,g.ONE);for(let u of vt)u.destroyed||u.renderLight();Et(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,I.x,I.y),g.useProgram(W.compositeShader),g.bindVertexArray(W.compositeVAO),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,W.texture);let l=W.compositeShader;g.uniform1i(g.getUniformLocation(l,"s"),0),g.uniform3f(g.getUniformLocation(l,"iResolution"),G.width,G.height,1),g.blendFunc(g.DST_COLOR,g.ZERO),g.drawArrays(g.TRIANGLE_STRIP,0,4),Qt&&g.bindTexture(g.TEXTURE_2D,Qt),ps(a),Ts(!0)}function o(){W.texture=void 0,W.lightShader=void 0,W.compositeShader=void 0,W.lightVAO=void 0,W.compositeVAO=void 0,xt("LightSystemPlugin: WebGL context lost")}function r(){s(),xt("LightSystemPlugin: WebGL context restored")}}drawLight(t){if(N||!k||!this.lightShader)return;Et(),g.useProgram(this.lightShader),g.bindVertexArray(this.lightVAO);let e=b(2*q).divide(I),s=Ct.rotate(-K),i=b(-1).subtract(s.multiply(e)),o=at(K),r=nt(K),a=[e.x*o,e.y*r,0,0,-e.x*r,e.y*o,0,0,1,1,1,0,i.x,i.y,0,1],c=this.lightShader;g.uniformMatrix4fv(g.getUniformLocation(c,"m"),!1,a),g.uniform2f(g.getUniformLocation(c,"lightPos"),t.pos.x,t.pos.y),g.uniform1f(g.getUniformLocation(c,"radius"),t.radius),g.uniform1f(g.getUniformLocation(c,"fadeRange"),t.fadeRange);let l=t.color;g.uniform4f(g.getUniformLocation(c,"color"),l.r,l.g,l.b,l.a),g.drawArrays(g.TRIANGLE_STRIP,0,4),Ts(!0)}},Oo=class extends Ue{constructor(t,e,s,i){super(t,b(1),void 0,0,s),p(P(e)&&e>=0,"Light radius must be a non-negative number"),p(i===void 0||P(i)&&i>=0,"Light fadeRange must be a non-negative number when provided"),this.radius=e,this.fadeRange=i===void 0?e:i}render(){}renderLight(){W&&W.drawLight(this)}},Do=class extends xs{constructor(t){super(void 0),!(!Ht||N)&&(this.randomness=0,this.sampleChannels=Ec(...t),this.sampleRate=Zn)}playMusic(t=1,e=!0){return super.play(void 0,t,1,0,e)}};Wr=0;Io=class{constructor(t=ut){p(!C,"UI system already initialized"),C=this,this.activateOnPress=!1,this.defaultColor=V,this.defaultLineColor=st,this.defaultTextColor=st,this.defaultButtonColor=Ge(0,0,.7),this.defaultHoverColor=Ge(0,0,.9),this.defaultDisabledColor=Ge(0,0,.3),this.defaultGradientColor=void 0,this.defaultLineWidth=4,this.defaultCornerRadius=0,this.defaultTextFitScale=.8,this.defaultFont=Ps,this.defaultSoundPress=void 0,this.defaultSoundRelease=void 0,this.defaultSoundClick=void 0,this.defaultShadowColor=ye,this.defaultShadowBlur=5,this.defaultShadowOffset=b(5),this.nativeHeight=0,this.navigationObject=void 0,this.navigationTimer=new Ee(void 0,!0),this.navigationDelay=.2,this.navigationDirection=1,this.navigationMode=!1,this.uiObjects=[],this.uiContext=t,this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.confirmDialog=void 0,this._keyInputObject=void 0,this._onKeyDown=o=>{var r;return(r=this._keyInputObject)==null?void 0:r.onKeyDown(o)},_n(s,i);function e(o){let r,a;o.parent?(r=o.parent.nativePos,a=o.parent.size):(r=C.screenToNative(I.scale(.5)),a=C.nativeHeight?b(I.x*C.nativeHeight/I.y,C.nativeHeight):I);let c=o.anchor;o.nativePos=r.add(a.multiply(c).scale(.5)).subtract(o.size.multiply(c).scale(.5)).add(o.localPos)}function s(){C.activeObject&&!C.activeObject.visible&&(C.activeObject=void 0),C.lastHoverObject=C.hoverObject,C.hoverObject=void 0,gs(0)&&(C.navigationMode=!1,C.navigationObject=void 0),C.keyInputObject&&(C.activeObject=C.keyInputObject,C.hoverObject=C.keyInputObject,C.navigationMode=!1,C.navigationObject=void 0);let o=C.getNavigableObjects();if(!o.length)C.navigationObject=void 0;else if(!C.keyInputObject){if(o.includes(C.navigationObject)||(C.navigationObject=void 0),oe||C.navigationMode&&!C.navigationObject&&(C.navigationObject=o.find(a=>a.navigationAutoSelect)),!C.navigationTimer.active()){let a=se(C.getNavigationDirection());if(a){let c;if(C.navigationObject){let l=o.indexOf(C.navigationObject),u=ie(l+a,o.length);c=o[u]}else if(c=o.find(l=>l.navigationAutoSelect),!c){let l=a>0?0:o.length-1;c=o[l]}C.navigationObject!==c&&(C.navigationMode=!0,C.hoverObject=void 0,C.navigationObject=c,C.navigationTimer.set(C.navigationDelay),c.soundPress&&c.soundPress.play())}}C.navigationObject&&C.getNavigationWasPressed()&&C.navigationObject.navigatePressed()}for(let a=C.uiObjects.length;a--;){let c=C.uiObjects[a];c.parent||r(c)}C.uiObjects=C.uiObjects.filter(a=>!a.destroyed);function r(a){if(!(a.destroyed||!a.visible)){e(a);for(let c=a.children.length;c--;){let l=a.children[c];l&&r(l)}a.destroyed||a.update()}}}function i(){let o=C.uiContext;if(o.save(),C.nativeHeight){let a=I.y/C.nativeHeight;o.translate(-a*I.x/2,0),o.scale(a,a),o.translate(I.x/2/a,0)}function r(a){if(a.visible){e(a),a.render();for(let c of a.children)r(c)}}if(C.uiObjects.forEach(a=>a.parent||r(a)),Wr>0){let a=function(c,l=!0){l&&(l=!!c.visible),e(c),c.renderDebug(l);for(let u of c.children)a(u,l)};C.uiObjects.forEach(c=>c.parent||a(c))}o.restore()}}drawRect(t,e,s=V,i=0,o=st,r=0,a,c=st,l=0,u=b()){p(O(t),"pos must be a vec2"),p(O(e),"size must be a vec2"),p(J(s),"color must be a color"),p(P(i),"lineWidth must be a number"),p(J(o),"lineColor must be a color"),p(P(r),"cornerRadius must be a number");let h=C.uiContext;if(a){let f=h.createLinearGradient(t.x,t.y-e.y/2,t.x,t.y+e.y/2),d=s.toString();f.addColorStop(0,d),f.addColorStop(.5,a.toString()),f.addColorStop(1,d),h.fillStyle=f}else h.fillStyle=s.toString();(l||u.x||u.y)&&c.a>0&&(h.shadowColor=c.toString(),h.shadowBlur=l,h.shadowOffsetX=u.x,h.shadowOffsetY=u.y),h.beginPath(),r&&h.roundRect?h.roundRect(t.x-e.x/2,t.y-e.y/2,e.x,e.y,r):h.rect(t.x-e.x/2,t.y-e.y/2,e.x,e.y),h.fill(),h.shadowColor="#0000",i&&o.a>0&&(h.strokeStyle=o.toString(),h.lineWidth=i,h.stroke())}drawLine(t,e,s=C.defaultLineWidth,i=C.defaultLineColor){p(O(t),"posA must be a vec2"),p(O(e),"posB must be a vec2"),p(P(s),"lineWidth must be a number"),p(J(i),"lineColor must be a color");let o=C.uiContext;o.strokeStyle=i.toString(),o.lineWidth=s,o.beginPath(),o.lineTo(t.x,t.y),o.lineTo(e.x,e.y),o.stroke()}drawTile(t,e,s,i=C.defaultColor,o=0,r=!1,a=st,c=0,l=b()){let u=C.uiContext;(c||l.x||l.y)&&a.a>0&&(u.shadowColor=a.toString(),u.shadowBlur=c,u.shadowOffsetX=l.x,u.shadowOffsetY=l.y),Pt(t,e,s,i,o,r,ye,!1,!0,u),u.shadowColor="#0000"}drawText(t,e,s,i=C.defaultColor,o=C.defaultLineWidth,r=C.defaultLineColor,a="center",c=C.defaultFont,l="",u=!0,h=void 0,f=st,d=0,y=b()){let x=C.uiContext;f.a>0&&(h&&on(t,e.add(h),s.y,f,o,r,a,c,l,u?s.x:void 0,0,x),(d||y.x||y.y)&&(x.shadowColor=f.toString(),x.shadowBlur=d,x.shadowOffsetX=y.x,x.shadowOffsetY=y.y)),on(t,e,s.y,i,o,r,a,c,l,u?s.x:void 0,0,x),x.shadowColor="#0000"}setupDragAndDrop(t,e,s,i){if(this._dragListeners)for(let[r,a]of this._dragListeners)document.removeEventListener(r,a);this._dragListeners=[];let o=(r,a)=>{let c=l=>{l.preventDefault(),r&&r(l)};document.addEventListener(a,c),this._dragListeners.push([a,c])};o(t,"drop"),o(e,"dragenter"),o(s,"dragleave"),o(i,"dragover")}screenToNative(t){if(!C.nativeHeight)return t;let e=I.y/C.nativeHeight,s=1/e,i=t.copy();return i.x+=e*I.x/2,i.x*=s,i.y*=s,i.x-=s*I.x/2,i}get keyInputObject(){return this._keyInputObject}set keyInputObject(t){let e=!!this._keyInputObject;this._keyInputObject=t,!e&&t?document.addEventListener("keydown",this._onKeyDown):e&&!t&&document.removeEventListener("keydown",this._onKeyDown)}destroyObjects(){for(let t of this.uiObjects)t.parent||t.destroy();this.uiObjects=this.uiObjects.filter(t=>!t.destroyed),this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.keyInputObject=void 0}getNavigableObjects(){function t(s){if(!(!s.visible||s.disabled)){s.isInteractive()&&s.navigationIndex!==void 0&&e.push(s);for(let i=s.children.length;i--;)t(s.children[i])}}let e=[];for(let s=C.uiObjects.length;s--;){let i=C.uiObjects[s];C.confirmDialog&&i!==C.confirmDialog||i.parent||t(i)}return e.sort((s,i)=>s.navigationIndex-i.navigationIndex),e}getNavigationDirection(){let t=C.navigationDirection===1,e=C.navigationDirection===2;if(Bn){let l=ys(0,mt),u=bo(mt);return e?-(l.y||u.y)||l.x||u.x:t?-(l.y||u.y):l.x||u.x}let s="ArrowUp",i="ArrowDown",o="ArrowLeft",r="ArrowRight";if(e)return Rt(s)||Rt(o)?-1:Rt(i)||Rt(r)?1:0;let a=t?s:o,c=t?i:r;return Rt(a)?-1:Rt(c)?1:0}getNavigationOtherDirection(){if(C.navigationDirection===2)return 0;let t=C.navigationDirection===1;if(Bn){let i=ys(0,mt),o=bo(mt);return t?i.x||o.x:i.y||o.y}let e=t?"ArrowLeft":"ArrowUp",s=t?"ArrowRight":"ArrowDown";return Rt(e)?-1:Rt(s)?1:0}getNavigationWasPressed(){return Bn?Rr(0,mt):Mt("Space")||Mt("Enter")}showConfirmDialog(t="Are you sure?",e,s,i=b(500,250),o="Escape"){p(!C.confirmDialog);let r=C.navigationDirection;C.navigationDirection=2;let a=new ae(b(),i);C.confirmDialog=a,a.onRender=()=>{let d=Ge(0,0,0,.7);C.drawRect(b(),b(1e9),d)},a.onUpdate=()=>{Mt(o)&&f()},a.isMouseOverlapping=()=>!0;let c=50,l=new vi(b(0,-50),b(i.x-c,70),t);a.addChild(l);let u=new _s(b(-80,50),b(120,70),"Yes");u.textHeight=40,u.navigationIndex=1,u.hoverColor=Ge(0,1,.5),u.onClick=()=>{f(),e&&e()},a.addChild(u);let h=new _s(b(80,50),b(120,70),"No");h.textHeight=40,h.navigationIndex=2,h.navigationAutoSelect=!0,h.onClick=()=>{f(),s&&s()},a.addChild(h);function f(){p(C.confirmDialog===a),a.destroy(),C.confirmDialog=void 0,C.navigationDirection=r,Gs()}}},ae=class{constructor(t=b(),e=b()){var s,i;p(O(t),"ui object pos must be a vec2"),p(O(e),"ui object size must be a vec2"),this.localPos=t.copy(),this.nativePos=t.copy(),this.size=e.copy(),this.color=C.defaultColor.copy(),this.activeColor=void 0,this.text=void 0,this.disabledColor=C.defaultDisabledColor.copy(),this.disabled=!1,this.textColor=C.defaultTextColor.copy(),this.hoverColor=C.defaultHoverColor.copy(),this.lineColor=C.defaultLineColor.copy(),this.gradientColor=C.defaultGradientColor?C.defaultGradientColor.copy():void 0,this.lineWidth=C.defaultLineWidth,this.cornerRadius=C.defaultCornerRadius,this.font=C.defaultFont,this.fontStyle=void 0,this.textWidth=void 0,this.textHeight=void 0,this.textFitScale=C.defaultTextFitScale,this.textShadow=void 0,this.textLineColor=C.defaultLineColor.copy(),this.textLineWidth=0,this.visible=!0,this.children=[],this.parent=void 0,this.extraTouchSize=0,this.soundPress=C.defaultSoundPress,this.soundRelease=C.defaultSoundRelease,this.soundClick=C.defaultSoundClick,this.interactive=!1,this.dragActivate=!1,this.canBeHover=!0,this.shadowColor=(s=C.defaultShadowColor)==null?void 0:s.copy(),this.shadowBlur=C.defaultShadowBlur,this.shadowOffset=(i=C.defaultShadowOffset)==null?void 0:i.copy(),this.navigationIndex=void 0,this.navigationAutoSelect=!1,this.anchor=b(),C.uiObjects.push(this)}addChild(t){return p(!t.parent&&!this.children.includes(t)),this.children.push(t),t.parent=this,t}removeChild(t){p(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}destroy(){var t;if(!this.destroyed){C.activeObject===this&&(C.activeObject=void 0),C.hoverObject===this&&(C.hoverObject=void 0),C.lastHoverObject===this&&(C.lastHoverObject=void 0),C.navigationObject===this&&(C.navigationObject=void 0),C.keyInputObject===this&&(C.keyInputObject=void 0),this.destroyed=1,(t=this.parent)==null||t.removeChild(this);for(let e of this.children)e.parent=void 0,e.destroy();this.children.length=0}}isMouseOverlapping(){if(!oi)return!1;let t=oe?this.size.add(b(this.extraTouchSize||0)):this.size,e=C.screenToNative(Jt);return Qs(this.nativePos,t,e)}update(){if(this.onUpdate(),this.disabled&&(this===C.activeObject&&(C.activeObject=void 0),this===C.keyInputObject&&(C.keyInputObject=void 0)),C.keyInputObject)return;let t=C.lastHoverObject===this,e=this.isActiveObject(),s=ls(0),i=this.dragActivate?s:gs(0);this.canBeHover&&(C.navigationMode||(i||e||!s&&!oe)&&!C.hoverObject&&this.isMouseOverlapping()&&(C.hoverObject=this)),this.isHoverObject()&&(this.disabled||(i&&this.interactive&&((!this.dragActivate||!t||gs(0))&&this.onPress(),this.soundPress&&this.soundPress.play(),C.activeObject&&!e&&C.activeObject.onRelease(),C.activeObject=this,C.activateOnPress&&this.click(!this.soundPress)),C.activateOnPress||!s&&this.isActiveObject()&&this.interactive&&this.click()),i&&Er(0,0,0,1,0)),e&&(!s||this.dragActivate&&!this.isHoverObject())&&(this.onRelease(),this.soundRelease&&this.soundRelease.play(),C.activeObject=void 0),this.isHoverObject()!==t&&(this.isHoverObject()?this.onEnter():this.onLeave())}render(){if(this.onRender(),!this.size.x||!this.size.y)return;let t=this.isNavigationObject(),e=t?this.color:this.interactive&&this.isActiveObject()&&!this.disabled?this.color:this.lineColor,s=t?this.hoverColor:this.disabled?this.disabledColor:this.interactive?this.isActiveObject()?this.activeColor||this.hoverColor:this.isHoverObject()?this.hoverColor:this.color:this.color,i=this.lineWidth*(t?1.5:1);C.drawRect(this.nativePos,this.size,s,i,e,this.cornerRadius,this.gradientColor,this.shadowColor,this.shadowBlur,this.shadowOffset)}getTextSize(){return b(this.textWidth||this.textFitScale*this.size.x,this.textHeight||this.textFitScale*this.size.y)}navigatePressed(){this.click()}isHoverObject(){return C.hoverObject===this}isActiveObject(){return C.activeObject===this}isNavigationObject(){return C.navigationObject===this}isKeyInputObject(){return C.keyInputObject===this}isInteractive(){return this.interactive&&this.visible&&!this.disabled}toString(){let t="type = "+this.constructor.name;return this.text&&(t+=`
+precision highp float;uniform sampler2D s;uniform vec3 iResolution;out vec4 c;void main(){vec2 uv=gl_FragCoord.xy/iResolution.xy;c=vec4(texture(s,uv).rgb,1.);}`),W.lightVAO=g.createVertexArray(),g.bindVertexArray(W.lightVAO),g.bindBuffer(g.ARRAY_BUFFER,zn);let a=g.getAttribLocation(W.lightShader,"g");g.enableVertexAttribArray(a),g.vertexAttribPointer(a,2,g.FLOAT,!1,8,0),W.compositeVAO=g.createVertexArray(),g.bindVertexArray(W.compositeVAO),g.bindBuffer(g.ARRAY_BUFFER,zn);let c=g.getAttribLocation(W.compositeShader,"p");g.enableVertexAttribArray(c),g.vertexAttribPointer(c,2,g.FLOAT,!1,8,0)}function i(){if(N||!k||!W.enabled||!W.texture)return;Et();let a=Dn,c=W.ambientColor;g.bindFramebuffer(g.FRAMEBUFFER,kr),g.framebufferTexture2D(g.FRAMEBUFFER,g.COLOR_ATTACHMENT0,g.TEXTURE_2D,W.texture,0),g.viewport(0,0,W.textureSize.x,W.textureSize.y),g.clearColor(c.r,c.g,c.b,c.a),g.clear(g.COLOR_BUFFER_BIT),ps(),g.enable(g.BLEND),g.blendFunc(g.ONE,g.ONE);for(let u of vt)u.destroyed||u.renderLight();Et(),g.bindFramebuffer(g.FRAMEBUFFER,null),g.viewport(0,0,I.x,I.y),g.useProgram(W.compositeShader),g.bindVertexArray(W.compositeVAO),g.activeTexture(g.TEXTURE0),g.bindTexture(g.TEXTURE_2D,W.texture);let l=W.compositeShader;g.uniform1i(g.getUniformLocation(l,"s"),0),g.uniform3f(g.getUniformLocation(l,"iResolution"),G.width,G.height,1),g.blendFunc(g.DST_COLOR,g.ZERO),g.drawArrays(g.TRIANGLE_STRIP,0,4),Zt&&g.bindTexture(g.TEXTURE_2D,Zt),ps(a),Ts(!0)}function o(){W.texture=void 0,W.lightShader=void 0,W.compositeShader=void 0,W.lightVAO=void 0,W.compositeVAO=void 0,xt("LightSystemPlugin: WebGL context lost")}function r(){s(),xt("LightSystemPlugin: WebGL context restored")}}drawLight(t){if(N||!k||!this.lightShader)return;Et(),g.useProgram(this.lightShader),g.bindVertexArray(this.lightVAO);let e=b(2*q).divide(I),s=Ct.rotate(-K),i=b(-1).subtract(s.multiply(e)),o=ct(K),r=nt(K),a=[e.x*o,e.y*r,0,0,-e.x*r,e.y*o,0,0,1,1,1,0,i.x,i.y,0,1],c=this.lightShader;g.uniformMatrix4fv(g.getUniformLocation(c,"m"),!1,a),g.uniform2f(g.getUniformLocation(c,"lightPos"),t.pos.x,t.pos.y),g.uniform1f(g.getUniformLocation(c,"radius"),t.radius),g.uniform1f(g.getUniformLocation(c,"fadeRange"),t.fadeRange);let l=t.color;g.uniform4f(g.getUniformLocation(c,"color"),l.r,l.g,l.b,l.a),g.drawArrays(g.TRIANGLE_STRIP,0,4),Ts(!0)}},Oo=class extends Ve{constructor(t,e,s,i){super(t,b(1),void 0,0,s),p(P(e)&&e>=0,"Light radius must be a non-negative number"),p(i===void 0||P(i)&&i>=0,"Light fadeRange must be a non-negative number when provided"),this.radius=e,this.fadeRange=i===void 0?e:i}render(){}renderLight(){W&&W.drawLight(this)}},Do=class extends xs{constructor(t){super(void 0),!(!Xt||N)&&(this.randomness=0,this.sampleChannels=Ec(...t),this.sampleRate=Zn)}playMusic(t=1,e=!0){return super.play(void 0,t,1,0,e)}};Wr=0;Io=class{constructor(t=ut){p(!C,"UI system already initialized"),C=this,this.activateOnPress=!1,this.defaultColor=V,this.defaultLineColor=st,this.defaultTextColor=st,this.defaultButtonColor=Fe(0,0,.7),this.defaultHoverColor=Fe(0,0,.9),this.defaultDisabledColor=Fe(0,0,.3),this.defaultGradientColor=void 0,this.defaultLineWidth=4,this.defaultCornerRadius=0,this.defaultTextFitScale=.8,this.defaultFont=Ps,this.defaultSoundPress=void 0,this.defaultSoundRelease=void 0,this.defaultSoundClick=void 0,this.defaultShadowColor=ye,this.defaultShadowBlur=5,this.defaultShadowOffset=b(5),this.nativeHeight=0,this.navigationObject=void 0,this.navigationTimer=new Ee(void 0,!0),this.navigationDelay=.2,this.navigationDirection=1,this.navigationMode=!1,this.uiObjects=[],this.uiContext=t,this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.confirmDialog=void 0,this._keyInputObject=void 0,this._onKeyDown=o=>{var r;return(r=this._keyInputObject)==null?void 0:r.onKeyDown(o)},_n(s,i);function e(o){let r,a;o.parent?(r=o.parent.nativePos,a=o.parent.size):(r=C.screenToNative(I.scale(.5)),a=C.nativeHeight?b(I.x*C.nativeHeight/I.y,C.nativeHeight):I);let c=o.anchor;o.nativePos=r.add(a.multiply(c).scale(.5)).subtract(o.size.multiply(c).scale(.5)).add(o.localPos)}function s(){C.activeObject&&!C.activeObject.visible&&(C.activeObject=void 0),C.lastHoverObject=C.hoverObject,C.hoverObject=void 0,gs(0)&&(C.navigationMode=!1,C.navigationObject=void 0),C.keyInputObject&&(C.activeObject=C.keyInputObject,C.hoverObject=C.keyInputObject,C.navigationMode=!1,C.navigationObject=void 0);let o=C.getNavigableObjects();if(!o.length)C.navigationObject=void 0;else if(!C.keyInputObject){if(o.includes(C.navigationObject)||(C.navigationObject=void 0),oe||C.navigationMode&&!C.navigationObject&&(C.navigationObject=o.find(a=>a.navigationAutoSelect)),!C.navigationTimer.active()){let a=se(C.getNavigationDirection());if(a){let c;if(C.navigationObject){let l=o.indexOf(C.navigationObject),u=ie(l+a,o.length);c=o[u]}else if(c=o.find(l=>l.navigationAutoSelect),!c){let l=a>0?0:o.length-1;c=o[l]}C.navigationObject!==c&&(C.navigationMode=!0,C.hoverObject=void 0,C.navigationObject=c,C.navigationTimer.set(C.navigationDelay),c.soundPress&&c.soundPress.play())}}C.navigationObject&&C.getNavigationWasPressed()&&C.navigationObject.navigatePressed()}for(let a=C.uiObjects.length;a--;){let c=C.uiObjects[a];c.parent||r(c)}C.uiObjects=C.uiObjects.filter(a=>!a.destroyed);function r(a){if(!(a.destroyed||!a.visible)){e(a);for(let c=a.children.length;c--;){let l=a.children[c];l&&r(l)}a.destroyed||a.update()}}}function i(){let o=C.uiContext;if(o.save(),C.nativeHeight){let a=I.y/C.nativeHeight;o.translate(-a*I.x/2,0),o.scale(a,a),o.translate(I.x/2/a,0)}function r(a){if(a.visible){e(a),a.render();for(let c of a.children)r(c)}}if(C.uiObjects.forEach(a=>a.parent||r(a)),Wr>0){let a=function(c,l=!0){l&&(l=!!c.visible),e(c),c.renderDebug(l);for(let u of c.children)a(u,l)};C.uiObjects.forEach(c=>c.parent||a(c))}o.restore()}}drawRect(t,e,s=V,i=0,o=st,r=0,a,c=st,l=0,u=b()){p(O(t),"pos must be a vec2"),p(O(e),"size must be a vec2"),p(J(s),"color must be a color"),p(P(i),"lineWidth must be a number"),p(J(o),"lineColor must be a color"),p(P(r),"cornerRadius must be a number");let h=C.uiContext;if(a){let f=h.createLinearGradient(t.x,t.y-e.y/2,t.x,t.y+e.y/2),d=s.toString();f.addColorStop(0,d),f.addColorStop(.5,a.toString()),f.addColorStop(1,d),h.fillStyle=f}else h.fillStyle=s.toString();(l||u.x||u.y)&&c.a>0&&(h.shadowColor=c.toString(),h.shadowBlur=l,h.shadowOffsetX=u.x,h.shadowOffsetY=u.y),h.beginPath(),r&&h.roundRect?h.roundRect(t.x-e.x/2,t.y-e.y/2,e.x,e.y,r):h.rect(t.x-e.x/2,t.y-e.y/2,e.x,e.y),h.fill(),h.shadowColor="#0000",i&&o.a>0&&(h.strokeStyle=o.toString(),h.lineWidth=i,h.stroke())}drawLine(t,e,s=C.defaultLineWidth,i=C.defaultLineColor){p(O(t),"posA must be a vec2"),p(O(e),"posB must be a vec2"),p(P(s),"lineWidth must be a number"),p(J(i),"lineColor must be a color");let o=C.uiContext;o.strokeStyle=i.toString(),o.lineWidth=s,o.beginPath(),o.lineTo(t.x,t.y),o.lineTo(e.x,e.y),o.stroke()}drawTile(t,e,s,i=C.defaultColor,o=0,r=!1,a=st,c=0,l=b()){let u=C.uiContext;(c||l.x||l.y)&&a.a>0&&(u.shadowColor=a.toString(),u.shadowBlur=c,u.shadowOffsetX=l.x,u.shadowOffsetY=l.y),Lt(t,e,s,i,o,r,ye,!1,!0,u),u.shadowColor="#0000"}drawText(t,e,s,i=C.defaultColor,o=C.defaultLineWidth,r=C.defaultLineColor,a="center",c=C.defaultFont,l="",u=!0,h=void 0,f=st,d=0,y=b()){let x=C.uiContext;f.a>0&&(h&&on(t,e.add(h),s.y,f,o,r,a,c,l,u?s.x:void 0,0,x),(d||y.x||y.y)&&(x.shadowColor=f.toString(),x.shadowBlur=d,x.shadowOffsetX=y.x,x.shadowOffsetY=y.y)),on(t,e,s.y,i,o,r,a,c,l,u?s.x:void 0,0,x),x.shadowColor="#0000"}setupDragAndDrop(t,e,s,i){if(this._dragListeners)for(let[r,a]of this._dragListeners)document.removeEventListener(r,a);this._dragListeners=[];let o=(r,a)=>{let c=l=>{l.preventDefault(),r&&r(l)};document.addEventListener(a,c),this._dragListeners.push([a,c])};o(t,"drop"),o(e,"dragenter"),o(s,"dragleave"),o(i,"dragover")}screenToNative(t){if(!C.nativeHeight)return t;let e=I.y/C.nativeHeight,s=1/e,i=t.copy();return i.x+=e*I.x/2,i.x*=s,i.y*=s,i.x-=s*I.x/2,i}get keyInputObject(){return this._keyInputObject}set keyInputObject(t){let e=!!this._keyInputObject;this._keyInputObject=t,!e&&t?document.addEventListener("keydown",this._onKeyDown):e&&!t&&document.removeEventListener("keydown",this._onKeyDown)}destroyObjects(){for(let t of this.uiObjects)t.parent||t.destroy();this.uiObjects=this.uiObjects.filter(t=>!t.destroyed),this.activeObject=void 0,this.hoverObject=void 0,this.lastHoverObject=void 0,this.keyInputObject=void 0}getNavigableObjects(){function t(s){if(!(!s.visible||s.disabled)){s.isInteractive()&&s.navigationIndex!==void 0&&e.push(s);for(let i=s.children.length;i--;)t(s.children[i])}}let e=[];for(let s=C.uiObjects.length;s--;){let i=C.uiObjects[s];C.confirmDialog&&i!==C.confirmDialog||i.parent||t(i)}return e.sort((s,i)=>s.navigationIndex-i.navigationIndex),e}getNavigationDirection(){let t=C.navigationDirection===1,e=C.navigationDirection===2;if(Bn){let l=ys(0,mt),u=bo(mt);return e?-(l.y||u.y)||l.x||u.x:t?-(l.y||u.y):l.x||u.x}let s="ArrowUp",i="ArrowDown",o="ArrowLeft",r="ArrowRight";if(e)return Pt(s)||Pt(o)?-1:Pt(i)||Pt(r)?1:0;let a=t?s:o,c=t?i:r;return Pt(a)?-1:Pt(c)?1:0}getNavigationOtherDirection(){if(C.navigationDirection===2)return 0;let t=C.navigationDirection===1;if(Bn){let i=ys(0,mt),o=bo(mt);return t?i.x||o.x:i.y||o.y}let e=t?"ArrowLeft":"ArrowUp",s=t?"ArrowRight":"ArrowDown";return Pt(e)?-1:Pt(s)?1:0}getNavigationWasPressed(){return Bn?Rr(0,mt):kt("Space")||kt("Enter")}showConfirmDialog(t="Are you sure?",e,s,i=b(500,250),o="Escape"){p(!C.confirmDialog);let r=C.navigationDirection;C.navigationDirection=2;let a=new ae(b(),i);C.confirmDialog=a,a.onRender=()=>{let d=Fe(0,0,0,.7);C.drawRect(b(),b(1e9),d)},a.onUpdate=()=>{kt(o)&&f()},a.isMouseOverlapping=()=>!0;let c=50,l=new vi(b(0,-50),b(i.x-c,70),t);a.addChild(l);let u=new _s(b(-80,50),b(120,70),"Yes");u.textHeight=40,u.navigationIndex=1,u.hoverColor=Fe(0,1,.5),u.onClick=()=>{f(),e&&e()},a.addChild(u);let h=new _s(b(80,50),b(120,70),"No");h.textHeight=40,h.navigationIndex=2,h.navigationAutoSelect=!0,h.onClick=()=>{f(),s&&s()},a.addChild(h);function f(){p(C.confirmDialog===a),a.destroy(),C.confirmDialog=void 0,C.navigationDirection=r,Gs()}}},ae=class{constructor(t=b(),e=b()){var s,i;p(O(t),"ui object pos must be a vec2"),p(O(e),"ui object size must be a vec2"),this.localPos=t.copy(),this.nativePos=t.copy(),this.size=e.copy(),this.color=C.defaultColor.copy(),this.activeColor=void 0,this.text=void 0,this.disabledColor=C.defaultDisabledColor.copy(),this.disabled=!1,this.textColor=C.defaultTextColor.copy(),this.hoverColor=C.defaultHoverColor.copy(),this.lineColor=C.defaultLineColor.copy(),this.gradientColor=C.defaultGradientColor?C.defaultGradientColor.copy():void 0,this.lineWidth=C.defaultLineWidth,this.cornerRadius=C.defaultCornerRadius,this.font=C.defaultFont,this.fontStyle=void 0,this.textWidth=void 0,this.textHeight=void 0,this.textFitScale=C.defaultTextFitScale,this.textShadow=void 0,this.textLineColor=C.defaultLineColor.copy(),this.textLineWidth=0,this.visible=!0,this.children=[],this.parent=void 0,this.extraTouchSize=0,this.soundPress=C.defaultSoundPress,this.soundRelease=C.defaultSoundRelease,this.soundClick=C.defaultSoundClick,this.interactive=!1,this.dragActivate=!1,this.canBeHover=!0,this.shadowColor=(s=C.defaultShadowColor)==null?void 0:s.copy(),this.shadowBlur=C.defaultShadowBlur,this.shadowOffset=(i=C.defaultShadowOffset)==null?void 0:i.copy(),this.navigationIndex=void 0,this.navigationAutoSelect=!1,this.anchor=b(),C.uiObjects.push(this)}addChild(t){return p(!t.parent&&!this.children.includes(t)),this.children.push(t),t.parent=this,t}removeChild(t){p(t.parent===this&&this.children.includes(t)),this.children.splice(this.children.indexOf(t),1),t.parent=void 0}destroy(){var t;if(!this.destroyed){C.activeObject===this&&(C.activeObject=void 0),C.hoverObject===this&&(C.hoverObject=void 0),C.lastHoverObject===this&&(C.lastHoverObject=void 0),C.navigationObject===this&&(C.navigationObject=void 0),C.keyInputObject===this&&(C.keyInputObject=void 0),this.destroyed=1,(t=this.parent)==null||t.removeChild(this);for(let e of this.children)e.parent=void 0,e.destroy();this.children.length=0}}isMouseOverlapping(){if(!oi)return!1;let t=oe?this.size.add(b(this.extraTouchSize||0)):this.size,e=C.screenToNative(Ut);return Qs(this.nativePos,t,e)}update(){if(this.onUpdate(),this.disabled&&(this===C.activeObject&&(C.activeObject=void 0),this===C.keyInputObject&&(C.keyInputObject=void 0)),C.keyInputObject)return;let t=C.lastHoverObject===this,e=this.isActiveObject(),s=ls(0),i=this.dragActivate?s:gs(0);this.canBeHover&&(C.navigationMode||(i||e||!s&&!oe)&&!C.hoverObject&&this.isMouseOverlapping()&&(C.hoverObject=this)),this.isHoverObject()&&(this.disabled||(i&&this.interactive&&((!this.dragActivate||!t||gs(0))&&this.onPress(),this.soundPress&&this.soundPress.play(),C.activeObject&&!e&&C.activeObject.onRelease(),C.activeObject=this,C.activateOnPress&&this.click(!this.soundPress)),C.activateOnPress||!s&&this.isActiveObject()&&this.interactive&&this.click()),i&&Er(0,0,0,1,0)),e&&(!s||this.dragActivate&&!this.isHoverObject())&&(this.onRelease(),this.soundRelease&&this.soundRelease.play(),C.activeObject=void 0),this.isHoverObject()!==t&&(this.isHoverObject()?this.onEnter():this.onLeave())}render(){if(this.onRender(),!this.size.x||!this.size.y)return;let t=this.isNavigationObject(),e=t?this.color:this.interactive&&this.isActiveObject()&&!this.disabled?this.color:this.lineColor,s=t?this.hoverColor:this.disabled?this.disabledColor:this.interactive?this.isActiveObject()?this.activeColor||this.hoverColor:this.isHoverObject()?this.hoverColor:this.color:this.color,i=this.lineWidth*(t?1.5:1);C.drawRect(this.nativePos,this.size,s,i,e,this.cornerRadius,this.gradientColor,this.shadowColor,this.shadowBlur,this.shadowOffset)}getTextSize(){return b(this.textWidth||this.textFitScale*this.size.x,this.textHeight||this.textFitScale*this.size.y)}navigatePressed(){this.click()}isHoverObject(){return C.hoverObject===this}isActiveObject(){return C.activeObject===this}isNavigationObject(){return C.navigationObject===this}isKeyInputObject(){return C.keyInputObject===this}isInteractive(){return this.interactive&&this.visible&&!this.disabled}toString(){let t="type = "+this.constructor.name;return this.text&&(t+=`
 text = `+this.text),(this.nativePos.x||this.nativePos.y)&&(t+=`
 nativePos = `+this.nativePos),(this.localPos.x||this.localPos.y)&&(t+=`
 localPos = `+this.localPos),(this.size.x||this.size.y)&&(t+=`
 size = `+this.size),this.color&&(t+=`
-color = `+this.color),t}renderDebug(t=!0){let e=t?this.isHoverObject()?Ka:this.disabled?tc:this.interactive?rr:Za:Qa;C.drawRect(this.nativePos,this.size,ye,4,e)}click(t=!0){this.onClick(),t&&this.soundClick&&this.soundClick.play()}onUpdate(){}onRender(){}onEnter(){}onLeave(){}onPress(){}onRelease(){}onClick(){}onChange(){}},vi=class extends ae{constructor(t,e,s="",i="center",o=C.defaultFont){super(t,e),p(U(s),"ui text must be a string"),p(["left","center","right"].includes(i),"ui text align must be left, center, or right"),p(U(o),"ui text font must be a string"),this.text=s,this.align=i,this.font=o,this.canBeHover=!1,this.color=ye,this.shadowColor=ye,this.gradientColor=void 0,this.lineWidth=0,this.textFitScale=1}render(){super.render();let t=this.getTextSize();C.drawText(this.text,this.nativePos,t,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow,this.shadowColor,this.shadowBlur,this.shadowOffset)}},Mo=class extends ae{constructor(t,e,s=""){super(t,e),p(U(s),"ui text must be a string"),this.maxLength=0,this.text=s,this.interactive=!0,this.canBeHover=!0}click(){C.keyInputObject=this,this.onClick()}stopEditing(){this.isKeyInputObject()&&(this.soundRelease&&this.soundRelease.play(),C.activeObject=void 0,C.keyInputObject=void 0,this.onChange())}onKeyDown(t){let e=t.code,s=t.key;e==="Backspace"?this.text=this.text.slice(0,-1):e==="Enter"||e==="Escape"?this.stopEditing():s.length===1&&(!this.maxLength||this.text.lengththis.size.y,s=e?this.size.y:this.size.x,i=e?this.size.x:this.size.y,o=e?this.nativePos.x:this.nativePos.y,r=i-s,a=o-r/2,c=o+r/2,l=C.screenToNative(Jt);this.value=e?Ft(l.x,a,c):Ft(l.y,c,a)}else if(this.isNavigationObject()){let e=C.getNavigationOtherDirection();C.navigationTimer.active()||(this.value=F(this.value+e*.01))}this.value===t||this.onChange()}render(){super.render();let t=this.size.x>this.size.y,e=t?this.size.x:this.size.y,s=t?this.size.y:this.size.x;if(this.fillMode){let o=Q(s,this.cornerRadius*2),r=Wt(o,e,this.value),a=(r-e)*(t?.5:-.5),c=this.nativePos.add(t?b(a,0):b(0,a)),l=this.disabled?this.disabledColor:this.handleColor,u=t?b(r,this.size.y):b(this.size.x,r);C.drawRect(c,u,l,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}else{let o=F(t?this.value:1-this.value),r=(e-s)*(o-.5),a=this.nativePos.add(t?b(r,0):b(0,r)),c=this.disabled?this.disabledColor:this.handleColor,l=b(s);C.drawRect(a,l,c,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}let i=this.getTextSize();C.drawText(this.text,this.nativePos,i,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow)}navigatePressed(){this.value=this.value?0:1,this.onChange(),this.onRelease(),super.navigatePressed()}},jo=class extends ae{constructor(t,e,s,i=!1,o=!1,r=1){super(t,e||b()),p(U(s),"video src must be a string"),p(P(r),"video volume must be a number"),this.color=st,this.cornerRadius=0,this.volume=r,this.video=document.createElement("video"),this.video.loop=o,this.video.volume=F(r*wn),this.video.muted=!Ht,this.video.style.display="none",this.video.src=s,document.body.appendChild(this.video),i&&this.play()}async play(){try{await this.video.play()}catch{}}pause(){this.video.pause()}stop(){this.video.pause(),this.video.currentTime=0}isLoading(){return this.video.readyState=1,"ui layout columns must be a number >= 1"),p(P(s),"ui layout gap must be a number"),p(P(i),"ui layout padding must be a number"),this.columns=e,this.gap=s,this.padding=i,o&&(this.color=ye,this.gradientColor=void 0,this.lineWidth=0,this.shadowColor=ye),this.relayout()}addChild(t){return super.addChild(t),this.relayout(),t}removeChild(t){super.removeChild(t),this.relayout()}relayout(){let t=this.children.length;if(!t){this.size=b(this.padding*2);return}let e=this.columns,s=hs(t/e),i=new Array(e).fill(0),o=new Array(s).fill(0);for(let f=0;f=0&&m.objects.splice(t,1),super.destroy()}updatePhysics(){}render(){this.tileInfo?super.render():this.drawFixtures(this.color,this.lineColor,this.lineWidth)}renderDebugInfo(){let t=!this.getIsAwake(),e=this.getBodyType()===m.bodyTypeStatic,s=z(t?1:0,t?1:0,e?1:0,.5);this.drawFixtures(s)}drawFixtures(t=V,e=st,s=.1,i,o){this.getFixtureList().forEach(r=>{m.castShapeObject(r.GetShape()).GetType()!==m.instance.b2Shape.e_edge&&m.drawFixture(r,this.pos,this.angle,t,e,s,i,o)}),this.edgeLists.forEach(r=>mo(r,s,e,!1,this.pos,this.angle)),this.edgeLoops.forEach(r=>mo(r,s,e,!0,this.pos,this.angle))}beginContact(t){}endContact(t){}addShape(t,e=1,s=.2,i=0,o=!1){p(P(e),"density must be a number"),p(P(s),"friction must be a number"),p(P(i),"restitution must be a number");let r=new m.instance.b2FixtureDef;return r.set_shape(t),r.set_density(e),r.set_friction(s),r.set_restitution(i),r.set_isSensor(o),this.body.CreateFixture(r)}addBox(t=b(1),e=b(),s=0,i,o,r,a){p(O(t),"size must be a Vector2"),p(t.x>0&&t.y>0,"size must be positive"),p(O(e),"offset must be a Vector2"),p(P(s),"angle must be a number");let c=new m.instance.b2PolygonShape;return c.SetAsBox(t.x/2,t.y/2,m.vec2dTo(e),-s),this.addShape(c,i,o,r,a)}addPoly(t,e,s,i,o){p(pe(t),"points must be an array");function r(c){p(3<=c.length&&c.length<=8);let l=m.instance._malloc(c.length*8);for(let f=0,d=0;f>2]=c[f].x,d+=4,m.instance.HEAPF32[l+d>>2]=c[f].y,d+=4;let u=m.instance.wrapPointer(l,m.instance.b2Vec2),h=new m.instance.b2PolygonShape;return h.Set(u,c.length),m.instance._free(l),h}let a=r(t);return this.addShape(a,e,s,i,o)}addRegularPoly(t=1,e=8,s,i,o,r){p(P(t)&&t>0,"diameter must be a positive number"),p(P(e)&&e>2,"sides must be a positive number greater than 2");let a=[],c=t/2;for(let l=e;l--;)a.push(b(c,0).rotate((l+.5)/e*X*2));return this.addPoly(a,s,i,o,r)}addRandomPoly(t=1,e,s,i,o){p(P(t)&&t>0,"diameter must be a positive number");let r=or(3,9),a=[],c=t/2;for(let l=r;l--;)a.push(b(ft(c/2,c*1.5),0).rotate(l/r*X*2));return this.addPoly(a,e,s,i,o)}addCircle(t=1,e=b(),s,i,o,r){p(P(t)&&t>0,"diameter must be a positive number"),p(O(e),"offset must be a Vector2");let a=new m.instance.b2CircleShape;return a.set_m_p(m.vec2dTo(e)),a.set_m_radius(t/2),this.addShape(a,s,i,o,r)}addEdge(t,e,s,i,o,r){p(O(t),"point1 must be a Vector2"),p(O(e),"point2 must be a Vector2");let a=new m.instance.b2EdgeShape;return a.Set(m.vec2dTo(t),m.vec2dTo(e)),this.addShape(a,s,i,o,r)}addEdgeList(t,e,s,i,o){p(pe(t),"points must be an array");let r=[],a=[];for(let c=0;ct[ie(l,t.length)];for(let l=0;lthis.destroyFixture(t))}getCenterOfMass(){return m.vec2From(this.body.GetWorldCenter())}getLinearVelocity(){return m.vec2From(this.body.GetLinearVelocity())}getAngularVelocity(){return this.body.GetAngularVelocity()}getMass(){return this.body.GetMass()}getInertia(){return this.body.GetInertia()}getIsAwake(){return this.body.IsAwake()}getBodyType(){return this.body.GetType()}getSpeed(){return this.getLinearVelocity().length()}setTransform(t,e){this.pos=t,this.angle=e,this.body.SetTransform(m.vec2dTo(t),-e)}setPosition(t){this.setTransform(t,this.body.GetAngle())}setAngle(t){this.setTransform(m.vec2From(this.body.GetPosition()),t)}setLinearVelocity(t){this.body.SetLinearVelocity(m.vec2dTo(t))}setAngularVelocity(t){this.body.SetAngularVelocity(t)}setLinearDamping(t){this.body.SetLinearDamping(t)}setAngularDamping(t){this.body.SetAngularDamping(t)}setGravityScale(t=1){this.body.SetGravityScale(this.gravityScale=t)}setBullet(t=!0){this.body.SetBullet(t)}setAwake(t=!0){this.body.SetAwake(t)}setBodyType(t){this.body.SetType(t)}setSleepingAllowed(t=!0){this.body.SetSleepingAllowed(t)}setFixedRotation(t=!0){this.body.SetFixedRotation(t)}setCenterOfMass(t){this.setMassData(t)}setMass(t){this.setMassData(void 0,t)}setMomentOfInertia(t){this.setMassData(void 0,void 0,t)}resetMassData(){this.body.ResetMassData()}setMassData(t,e,s){let i=new m.instance.b2MassData;this.body.GetMassData(i),t!==void 0&&i.set_center(m.vec2dTo(t)),e!==void 0&&i.set_mass(e),s!==void 0&&i.set_I(s),this.body.SetMassData(i)}setFilterData(t=0,e=0,s=0){this.getFixtureList().forEach(i=>{let o=i.GetFilterData();o.set_categoryBits(t),o.set_maskBits(65535&~e),o.set_groupIndex(s)})}setSensor(t=!0){this.getFixtureList().forEach(e=>e.SetSensor(t))}applyForce(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyForce(m.vec2dTo(t),m.vec2dTo(e))}applyAcceleration(t,e){e||(e=this.getCenterOfMass()),this.setAwake();let s=t.scale(this.getMass());this.body.ApplyLinearImpulse(m.vec2dTo(s),m.vec2dTo(e))}applyImpulse(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyLinearImpulse(m.vec2dTo(t),m.vec2dTo(e))}applyTorque(t){this.setAwake(),this.body.ApplyTorque(t)}applyAngularAcceleration(t){this.setAwake(),this.body.ApplyAngularImpulse(t*this.getInertia())}applyAngularImpulse(t){this.setAwake(),this.body.ApplyAngularImpulse(t)}hasFixtures(){return!m.isNull(this.body.GetFixtureList())}getFixtureList(){let t=[];for(let e=this.body.GetFixtureList();!m.isNull(e);)t.push(e),e=e.GetNext();return t}hasJoints(){return!m.isNull(this.body.GetJointList())}getJointList(){let t=[];for(let e=this.body.GetJointList();!m.isNull(e);)t.push(e),e=e.get_next();return t}},Si=class extends Rs{constructor(t,e,s,i=0,o,r=0){let a=m.bodyTypeStatic;super(t,e,s,i,o,a,r)}},Bo=class extends Rs{constructor(t,e,s,i=0,o,r=0){let a=m.bodyTypeKinematic;super(t,e,s,i,o,a,r)}},zo=class extends Si{constructor(t){p(t instanceof Ss,"tileLayer must be a TileCollisionLayer"),super(t.pos,t.size),this.tileLayer=t,this.addChild(t)}render(){}buildCollision(t=.2,e=0){this.destroyAllFixtures(),this.pos=this.tileLayer.pos.copy(),this.size=this.tileLayer.size.copy();let s=[],i=(r,a)=>r+a*this.size.x,o=(r,a)=>!s[i(r,a)]&&this.tileLayer.getCollisionData(b(r,a))>0;for(let r=0;ri.fractiono.pos.distanceSquared(t)0,"Tween duration must be > 0"),this.callback=t,this.start=e,this.end=s,this.duration=i,this.life=i,this.ease=o.ease||Ei.LINEAR,this.useRealTime=!!o.useRealTime,this.paused=!!o.paused,this.thenCallback=void 0,this.loopRemaining=0,$t.push(this),t(this.interp(i))}setEase(t){return this.ease=t,this}then(t){return this.thenCallback=t,this.loopRemaining=0,this}loop(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Lc(this),this}pingPong(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Oc(this),this}pause(){this.paused=!0}resume(){this.paused=!1}restart(){this.life=this.duration,this.paused=!1,$t.indexOf(this)<0&&$t.push(this),this.callback(this.interp(this.duration))}isActive(){return!this.paused&&$t.indexOf(this)>=0}getPercent(){return Ft(this.duration-this.life,0,this.duration)}getValue(){return this.interp(this.life)}interp(t){let e=this.ease((this.duration-t)/this.duration);return La(this.start)?this.start.lerp(this.end,e):this.start+(this.end-this.start)*e}stop(){let t=$t.indexOf(this);t>=0&&$t.splice(t,1),this.thenCallback=void 0}},Ei={LINEAR:n=>n,POWER:n=>t=>t**n,SINE:n=>1-at(n*(X/2)),CIRC:n=>1-(1-n*n)**.5,EXPO:n=>n===0?0:2**(10*n-10),BACK:n=>n*n*(2.70158*n-1.70158),ELASTIC:n=>n===0?0:n===1?1:-(2**(10*n-10))*nt((37-40*n)*X/6),SPRING:n=>1-(nt(X*(1-n)*(.2+2.5*(1-n)**3))*n**2.2+(1-n))*(1+1.2*n),BOUNCE:n=>{let t=1-n,e;return t<4/11?e=7.5625*t*t:t<8/11?e=7.5625*(t-=6/11)*t+.75:t<10/11?e=7.5625*(t-=9/11)*t+.9375:e=7.5625*(t-=10.5/11)*t+.984375,1-e},IN:n=>n,OUT:n=>t=>1-n(1-t),IN_OUT:n=>Ei.PIECEWISE(n,Ei.OUT(n)),PIECEWISE:(...n)=>{let t=n.length;return e=>{let s=e*t-1e-9>>0;return(n[s]((e-s/t)*t)+s)/t}},BEZIER:(n,t,e,s)=>{let i=o=>{let r=1-o,a=3*r*r*o,c=3*r*o*o,l=o**3;return[a*n+c*e+l,a*t+c*s+l]};return o=>{let r=0,a=1;for(let c=0;c<128;c++){let l=(r+a)/2,[u,h]=i(l);if(et(u-o)<1e-5)return h;u=this.size.x||e>=this.size.y?null:this.nodes[t+e*this.size.x]}worldToTile(t){let e=this.tileLayer?this.tileLayer.pos.x:0,s=this.tileLayer?this.tileLayer.pos.y:0;return b(St(t.x-e),St(t.y-s))}tileToWorld(t,e){let s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;return b(t+.5+s,e+.5+i)}buildNodeData(){let t=this.size.x,e=this.size.y,s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;for(let o=0;o0&&(c?l>0&&bt(a.posWorld,lo,z(1,0,0,Q(.2,l*.05)),this.debugTime):bt(a.posWorld,lo,z(1,0,0,.25),this.debugTime))}}aStarSearch(t,e){p(t&&e,"aStarSearch needs both endpoints"),p(t!==e,"aStarSearch: start and end must differ \u2014 caller should handle trivial case"),p(t.walkable&&e.walkable,"aStarSearch: endpoints must be walkable");let s=[t];t.isOpen=!0;let i=0;for(;s.length>0;){let o=0,r=s[0].f;for(let c=1;cthis.maxLoop)break;a.isOpen=!1,s.splice(o,1),a.isClosed=!0,this.debug&&this.debugTime>0&&bt(a.posWorld,lo,z(1,1,1,.05),this.debugTime);for(let c=-1;c<=1;++c)for(let l=-1;l<=1;++l){if(l===0&&c===0)continue;let u=this.getNode(a.pos.x+l,a.pos.y+c);if(!u||!u.walkable||u.isClosed)continue;let h=1;if(l!==0&&c!==0){let v=this.getNode(a.pos.x+l,a.pos.y);if(!v||!v.walkable)continue;let w=this.getNode(a.pos.x,a.pos.y+c);if(!w||!w.walkable)continue;h=fd}let f=a.g+h+u.cost;if(!u.isOpen)u.isOpen=!0,s.push(u);else if(f>=u.g)continue;u.parent=a,u.g=f;let d=et(e.pos.x-u.pos.x),y=et(e.pos.y-u.pos.y),x=$(d,y)+(Math.SQRT2-1)*Q(d,y);u.f=u.g+x*this.heuristicWeight}}return e.parent!==null}getNearestClearNode(t,e=10,s=!0){p(O(t),"worldPos must be a Vector2"),s&&this.buildNodeData();let i=this.tileLayer?this.tileLayer.pos.x:0,o=this.tileLayer?this.tileLayer.pos.y:0,r=St(t.x-i),a=St(t.y-o);for(let c=0;c<=e;++c){let l=null,u=0;for(let h=-c;h<=c;++h)for(let f=-c;f<=c;++f){if(c>0&&et(f)!==c&&et(h)!==c)continue;let d=this.getNode(r+f,a+h);if(!d||!d.isClear())continue;let y=d.posWorld.x-t.x,x=d.posWorld.y-t.y,v=y*y+x*x;(!l||v0&&Ut(i.posWorld,.3,z(.5,0,.5,.5),this.debugTime),t.splice(e,1),e=$(1,e-1);continue}else if(c===2){this.debug&&this.debugTime>0&&Ut(i.posWorld,.3,z(1,0,0,.5),this.debugTime);let d,y;s.pos.y===i.pos.y&&o.pos.x===i.pos.x?(d=s.pos.x,y=o.pos.y):(d=o.pos.x,y=s.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t.splice(e,1),e=$(1,e-1);continue}}else if(c===5){this.debug&&this.debugTime>0&&Ut(i.posWorld,.3,z(1,1,0,.5),this.debugTime);let d=e>=2?t[e-2]:s,y,x,v,w;l===0||h===0?(y=o.pos.x,x=i.pos.y,v=s.pos.x,w=i.pos.y):(y=i.pos.x,x=o.pos.y,v=i.pos.x,w=s.pos.y);let _=y-d.pos.x,S=x-d.pos.y,E=v-d.pos.x,A=w-d.pos.y,T=_*_+S*S,R=E*E+A*A,M=T0&&Ut(i.posWorld,.3,z(0,1,0,.5),this.debugTime),l===h&&u===f){++e;continue}else{let d,y;s.pos.y===o.pos.y?(d=i.pos.x,y=s.pos.y):(d=s.pos.x,y=i.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t[e]=x,e=$(1,e-1);continue}}++e}}smoothPathStringPull(t){if(t.length<=2)return;for(let i of t)if(!i.isClear())return;let e=t.slice();t.length=0,t.push(e[0]);let s=0;for(let i=1;i0&&Te(o.posWorld,t[t.length-1].posWorld,z(0,0,1,.3),.02,this.debugTime);continue}for(;s=1;--e){let s=t[e-1],i=t[e],o=t[e+1];(i.pos.x-s.pos.x)*(o.pos.y-s.pos.y)===(i.pos.y-s.pos.y)*(o.pos.x-s.pos.x)&&t.splice(e,1)}}isNodeClear(t,e){let s=this.getNode(t,e);return s!==null&&s.isClear()}isLineClear(t,e){p(O(t)&&O(e),"isLineClear needs Vector2 endpoints"),p(this.isNodeClear(t.x,t.y)&&this.isNodeClear(e.x,e.y),"isLineClear endpoints must be in-bounds and clear");let s=e.x-t.x,i=e.y-t.y,o=et(s),r=et(i),a=se(s),c=se(i),l=t.x,u=t.y;if(r===o){for(;l!==e.x;){if(l!==t.x&&(!this.isNodeClear(l,u)||!this.isNodeClear(l,u-c))||!this.isNodeClear(l,u+c))return!1;l+=a,u+=c}if(!this.isNodeClear(e.x,e.y-c))return!1}else if(ra.posWorld.copy());if(this.debug&&this.debugTime>0&&r.length>0){for(let a=1;apd,bootGameHost:()=>yd,default:()=>gd});var js=class{constructor(t){this._state=(t==null?2654435769:t)>>>0}next(){this._state=this._state+1831565813>>>0;let t=this._state;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}range(t,e){return t+this.next()*(e-t)}reseed(t){this._state=(t==null?2654435769:t)>>>0}},Ji=class{constructor(t){this._clock=t||Jc(),this._origin=this._clock()}nowMs(){return this._clock()}elapsedMs(){return this._clock()-this._origin}},Ui=class{constructor(t){this._time=t,this._subs=new Map}sourceFor(t){let e=this,s=t==null?null:t;return{on(i,o){if(e._assertType(i),typeof o!="function")throw new Error("[HostDevInputBridge] on \u7684 handler \u5FC5\u987B\u662F\u51FD\u6570");let r=e._subs.get(i)||[],a={handler:o,scope:s};return r.push(a),e._subs.set(i,r),{cancel(){let c=e._subs.get(i);if(!c)return;let l=c.indexOf(a);l>=0&&c.splice(l,1)}}},off(i,o){e._assertType(i);let r=e._subs.get(i);if(!r)return;let a=r.findIndex(c=>c.handler===o&&c.scope===s);a>=0&&r.splice(a,1)}}}_emit(t,e){this._assertType(t);let s=e||{},i={type:t,x:typeof s.x=="number"?s.x:0,y:typeof s.y=="number"?s.y:0,key:typeof s.key=="string"?s.key:"",tMs:this._time.nowMs()},o=this._subs.get(t);if(!o||o.length===0)return;let r=o.slice();for(let a of r)try{a.handler(i)}catch(c){Xe("[host-dev input] \u8F93\u5165 handler \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09type="+t,c)}}disposeScope(t){if(t==null)return 0;let e=0;for(let[s,i]of this._subs){let o=i.filter(r=>r.scope!==t);e+=i.length-o.length,o.length===0?this._subs.delete(s):this._subs.set(s,o)}return e}_subscriptionCount(){let t=0;for(let e of this._subs.values())t+=e.length;return t}_assertType(t){if(!Vi.has(t))throw new Error("[HostDevInputBridge] \u975E\u6CD5\u8F93\u5165\u4E8B\u4EF6\u7C7B\u578B\uFF1A"+String(t)+"\uFF08\u4EC5\u652F\u6301 "+Array.from(Vi).join("/")+"\uFF09")}},Vi=new Set(["pointerdown","pointermove","pointerup","keydown","keyup"]);function Xr(n){let t=n||{},e=new Ji(t.clock),s=new js(t.seed),i=t.seed==null?2654435769:t.seed>>>0,o=new Ui(e),r=typeof t.audioFactory=="function"?t.audioFactory:null,a=null,c=!1,l=typeof t.engineFactory=="function"?t.engineFactory:null,u=null,h=!1,f=new Map,d=0,y=0;function x(){if(a)return a;if(!r)return c||(qi("[host-dev audio] \u672A\u6CE8\u5165 audioFactory\uFF0CgetAudioContext \u8FD4\u56DE null\uFF08P6 \u987B\u5BB9\u9519\u964D\u7EA7\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u5DE5\u5382\uFF09"),c=!0),null;try{a=r()}catch(E){Xe("[host-dev audio] audioFactory \u629B\u9519\uFF0CgetAudioContext \u964D\u7EA7\u8FD4\u56DE null",E),a=null}return a}function v(){if(u)return u;if(!l)return h||(qi("[host-dev engine] \u672A\u6CE8\u5165 engineFactory\uFF0CgetEngine \u8FD4\u56DE null\uFF08\u63D2\u4EF6\u987B\u5BB9\u9519\u964D\u7EA7\uFF1A\u7C92\u5B50\u9000\u53D7\u63A7\u9762\u81EA\u7BA1/\u5408\u6210\u6838\u9000 vendored/\u6570\u5B66\u9000\u5185\u7F6E\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u80CC\u4E66\uFF09"),h=!0),null;try{u=l()}catch(E){Xe("[host-dev engine] engineFactory \u629B\u9519\uFF0CgetEngine \u964D\u7EA7\u8FD4\u56DE null",E),u=null}return u}function w(E,A){return{getContext2d(){return t.context2d==null?null:t.context2d},onFrame(R){let M=d++;return f.set(M,R),{cancel(){f.delete(M)}}},getInput(){return o.sourceFor(E)},getAudioContext(){return x()},getEngine(){return v()},time:e,random:A}}let _=w(null,s),S={context:_,tick(E){y+=1;let A=Array.from(f.values());for(let T of A)try{T(E,y)}catch(R){Xe("[host-dev tick] \u5E27\u56DE\u8C03\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09frame="+y,R)}},frameCount(){return y},inputBridge:o,deriveContextFor(E,A){let T=zc(i,E),R=new js(T);return w(A==null?E:A,R)}};return Object.defineProperty(_,Wi,{value:S,enumerable:!1,writable:!1,configurable:!1}),S}var Wi=Symbol("zaomeng.coreProtocol.contextBundle"),Ns=class{constructor(){this._plugins=new Map,this._initOrder=[],this._initErrors=[],this._phase="idle",this._disposed=!1,this._context=void 0,this._pluginContexts=new Map}register(t){if(!t||typeof t!="object")throw new Error("[PluginRegistry] register \u9700\u8981\u4E00\u4E2A\u63D2\u4EF6\u5BF9\u8C61");if(typeof t.name!="string"||t.name.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6\u7F3A\u5C11\u5408\u6CD5 name");if(typeof t.version!="string"||t.version.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11\u5408\u6CD5 version");if(typeof t.init!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11 init \u51FD\u6570");if(t.dispose!=null&&typeof t.dispose!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7684 dispose \u5FC5\u987B\u662F\u51FD\u6570\u6216\u7701\u7565");if(this._plugins.has(t.name))throw new Error("[PluginRegistry] \u63D2\u4EF6\u91CD\u540D\u62D2\u7EDD\uFF1A"+t.name+" \u5DF2\u6CE8\u518C");return this._plugins.set(t.name,t),this}has(t){return this._plugins.has(t)}get(t){return this._plugins.get(t)}list(){return Array.from(this._plugins.keys())}initAll(){if(this._phase==="initialized")return qi("[PluginRegistry] initAll \u91CD\u590D\u8C03\u7528\uFF0C\u5DF2\u5FFD\u7565\uFF08\u5DF2\u5904\u4E8E initialized\uFF09"),this._initResult();if(this._phase==="disposed")throw new Error("[PluginRegistry] \u5DF2 dispose \u7684\u6CE8\u518C\u5668\u4E0D\u53EF\u518D initAll");if(this._context==null)throw new Error("[PluginRegistry] \u672A\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\uFF1A\u8BF7\u5728 initAll() \u4E4B\u524D\u8C03\u7528 useContext(context)\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context); reg.initAll();\uFF09");for(let[t,e]of this._plugins){let s=this._missingDeps(e);if(s.length>0){let o=new Error("[PluginRegistry] \u63D2\u4EF6 "+t+" \u4F9D\u8D56\u7F3A\u5931\uFF1A"+s.join(", ")+"\uFF08\u672A\u6CE8\u518C\uFF09");this._initErrors.push({name:t,error:o}),Xe("[PluginRegistry] \u8DF3\u8FC7 init\uFF08\u4F9D\u8D56\u7F3A\u5931\uFF0C\u5DF2\u9694\u79BB\uFF09\uFF1A"+t,o);continue}let i=this._contextFor(t);try{e.init(i),this._initOrder.push(t)}catch(o){let r=o instanceof Error?o:new Error(String(o));this._initErrors.push({name:t,error:r}),Xe("[PluginRegistry] \u63D2\u4EF6 init \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF0C\u4E0D\u8FDE\u5750\uFF09\uFF1A"+t,r)}}return this._phase="initialized",this._initResult()}_contextFor(t){let e=this._pluginContexts.get(t);if(e)return e;let s=this._context&&this._context[Wi],i;return s&&typeof s.deriveContextFor=="function"?i=s.deriveContextFor(t,t):i=this._context,this._pluginContexts.set(t,i),i}disposeAll(){if(this._disposed)return{disposed:[],errors:[]};let t=[],e=[],s=this._context&&this._context[Wi],i=s&&s.inputBridge;for(let o=this._initOrder.length-1;o>=0;o--){let r=this._initOrder[o],a=this._plugins.get(r);if(a&&typeof a.dispose=="function")try{a.dispose(),t.push(r)}catch(c){let l=c instanceof Error?c:new Error(String(c));e.push({name:r,error:l}),Xe("[PluginRegistry] \u63D2\u4EF6 dispose \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+r,l)}if(i&&typeof i.disposeScope=="function")try{i.disposeScope(r)}catch(c){Xe("[PluginRegistry] \u56DE\u6536\u63D2\u4EF6\u8F93\u5165\u8BA2\u9605\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+r,c)}}return this._disposed=!0,this._phase="disposed",{disposed:t,errors:e}}useContext(t){if(this._phase!=="idle")throw new Error("[PluginRegistry] useContext \u5FC5\u987B\u5728 initAll() \u4E4B\u524D\u8C03\u7528\uFF08\u5F53\u524D\u9636\u6BB5\uFF1A"+this._phase+"\uFF09\u3002\u8BF7\u5728\u4EFB\u4F55 initAll/disposeAll \u4E4B\u524D\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\u3002");if(t==null||typeof t!="object")throw new Error("[PluginRegistry] useContext \u9700\u8981\u4E00\u4E2A\u53D7\u63A7\u4E0A\u4E0B\u6587\u5BF9\u8C61\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context);\uFF09");return this._context=t,this}_missingDeps(t){return!Array.isArray(t.dependencies)||t.dependencies.length===0?[]:t.dependencies.filter(e=>!this._plugins.has(e))}_initResult(){return{ok:this._initErrors.length===0,initialized:this._initOrder.slice(),errors:this._initErrors.slice()}}};function zc(n,t){let e=2166136261,s=16777619,i=n>>>0;for(let r=0;r<32;r+=8){let a=i>>>r&255;e^=a,e=Math.imul(e,s)>>>0}let o=String(t);for(let r=0;r>>0,e^=a>>>8&255,e=Math.imul(e,s)>>>0}return e>>>0}function Jc(){if(typeof globalThis!="undefined"&&globalThis.performance&&typeof globalThis.performance.now=="function")return()=>globalThis.performance.now();if(typeof process!="undefined"&&process.hrtime&&typeof process.hrtime.bigint=="function"){let n=process.hrtime.bigint();return()=>Number(process.hrtime.bigint()-n)/1e6}return()=>Date.now()}function Xe(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function qi(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var xd=Object.freeze(Array.from(Vi)),Yr="core-protocol-v0";var $r=Object.freeze(["t_boot","t_plugins_ready","t_game_init","t_first_paint","t_input_bound","t_game_start"]),Hi=$r.reduce((n,t,e)=>(n[t]=e,n),Object.create(null)),Uc=new Set($r);function Xi(n){let t=2166136261;for(let e=0;e>>0).toString(16).padStart(8,"0")}var Kr=Xi("runtime-probe::seed::v1");function Bs(n){return n===null||typeof n!="object"?JSON.stringify(n):Array.isArray(n)?"["+n.map(Bs).join(",")+"]":"{"+Object.keys(n).sort().map(e=>JSON.stringify(e)+":"+Bs(n[e])).join(",")+"}"}function Qr(n){let t=Bs(n.extra==null?null:n.extra),e=Bs(Array.isArray(n.pluginSet)?n.pluginSet:[]);return["seq="+n.seq,"anchor="+n.anchor,"tMono="+n.tMono,"buildSha="+(n.buildSha||""),"pluginSet="+e,"extra="+t].join("|")}function Vc(n){return Math.round(n*1e3)/1e3}function Wc(n){if(!Array.isArray(n))return{ok:!1,reason:"records_not_array"};let t=Kr,e=-1;for(let s=0;stypeof E=="string").slice().sort():[],i=typeof t.sink=="function"?t.sink:null,o=t.autoBoot!==!1,r=typeof t.inputAnchorType=="string"?t.inputAnchorType:"pointerdown",a=()=>0,c=!1,l=0,u=Kr,h=[],f=new Set,d=-1,y=null,x=!1,v=!1,w=!1;function _(E,A){let T=null;if(!Uc.has(E))T="unknown_anchor";else{f.has(E)&&(T=T?T+";duplicate_anchor":"duplicate_anchor");let M=Hi[E];ME.time.nowMs(),c=!0,o&&!v&&_("t_boot",{auto:!0}),y=E.getInput().on(r,A=>{x||(x=!0,_("t_input_bound",{firstInput:!0,type:A.type}))}),_("t_input_bound",{stage:"registered",type:r})},dispose(){w||(y&&(y.cancel(),y=null),w=!0)},mark:_,getRecords(){return h.map(E=>({...E}))},toJSONL(){return h.map(E=>JSON.stringify(E)).join(`
-`)},verify(){return Wc(h)}}}function qc(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function ta(n){let t=n.LJS,e=n.engineMath,s=n.engineMode,i=n.recHook||(()=>{});if(s!=="real")return null;let o=e;return{math:{lerp:(a,c,l)=>(i("math.lerp"),o.lerp(a,c,l)),smoothStep:a=>(i("math.smoothStep"),o.smoothStep(a)),easing:Object.fromEntries(Object.keys(o.easing).map(a=>[a,c=>(i("math.easing."+a),o.easing[a](c))]))},particles:{spawnEmitter(a){i("particles.spawnEmitter");let c=t.screenToWorld(t.vec2(a.pos.x,a.pos.y)),l=t.cameraScale,u=a.emitTime!=null?a.emitTime:a.count!=null?1/60:0,h=a.emitRate!=null?a.emitRate:a.count!=null?a.count*60:100,f=(a.speed!=null?a.speed:0)/l/60,d=a.damping!=null?a.damping:1,y=a.colorStart||{r:1,g:1,b:1,a:1},x=a.colorEnd||{r:1,g:1,b:1,a:0},v=t.rgb(y.r,y.g,y.b,y.a),w=t.rgb(x.r,x.g,x.b,x.a),_=new t.ParticleEmitter(c,a.angle!=null?a.angle:0,(a.emitSize!=null?a.emitSize:0)/l,u,h,a.coneAngle!=null?a.coneAngle:Math.PI,void 0,v,v,w,w,a.particleTime!=null?a.particleTime:.5,(a.sizeStart!=null?a.sizeStart:6)/l,(a.sizeEnd!=null?a.sizeEnd:0)/l,f,0,d,1,a.gravityScale!=null?a.gravityScale:0,Math.PI,.1,0,!1,a.additive!=null?a.additive:!1,!0);return{isActive(){return _.isActive()},stop(){_.destroyed||_.destroy(!0)}}}},audio:{synth:{synthSfx:a=>{i("audio.synth.synthSfx");try{return t.zzfxG(...a)}catch(c){return console.error("[host][engine-audio] zzfxG \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(c&&c.message?c.message:c)),null}},synthSong:(a,c,l,u)=>{i("audio.synth.synthSong");try{return t.zzfxM(a,c,l,u)}catch(h){return console.error("[host][engine-audio] zzfxM \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(h&&h.message?h.message:h)),null}}}}}}function ue(n){return n<0?0:n>1?1:n}function ea(n){let t=n.Ease,e=t.POWER(2),s=t.POWER(3),i=t.OUT(e),o=t.IN_OUT(e),r=t.OUT(s),a=t.IN_OUT(s),c=t.OUT(t.BACK),l=t.OUT(t.ELASTIC);return{lerp:(u,h,f)=>n.lerp(u,h,f),smoothStep:u=>n.smoothStep(u),easing:{linear:u=>t.LINEAR(ue(u)),quadIn:u=>e(ue(u)),quadOut:u=>i(ue(u)),quadInOut:u=>o(ue(u)),cubicIn:u=>s(ue(u)),cubicOut:u=>r(ue(u)),cubicInOut:u=>a(ue(u)),backIn:u=>t.BACK(ue(u)),backOut:u=>c(ue(u)),elasticIn:u=>t.ELASTIC(ue(u)),elasticOut:u=>l(ue(u))}}}var Ye=2,zs=1/60;async function na(n){let t=n.canvas,e=n.statusEl||null,s=n.engine,i=n.seed>>>0,o=n.mode||"play",r=n.engineMode||"real",a=n.viewport.w,c=n.viewport.h,l=n.factory,u=n.buildFactoryOpts||(()=>{}),h=n.plugins||{},f=n.registerOrder||Object.values(h),d=n.onReady||(()=>{}),y=n.recHook||(()=>{});function x(D){e&&(e.textContent=D)}let v=[];window.addEventListener("error",D=>v.push({type:"error",message:String(D&&D.message||D)})),window.addEventListener("unhandledrejection",D=>v.push({type:"unhandledrejection",message:String(D&&D.reason&&D.reason.message||D&&D.reason||D)}));let w=null,_=!1;function S(){if(!_)return null;if(w)return w;let D=window.AudioContext||window.webkitAudioContext;return D?(w=new D,w):null}let E=0,A=null,T=null,R=null,M=null,Z=[],it={},ht=null;function gt(D,lt){try{R&&R.mark(D,lt)}catch(ee){v.push({type:"mark",message:String(ee&&ee.message||ee)})}}function jt(){T&&typeof T._refreshChecklist=="function"&&T._refreshChecklist(it)}async function qe(D,lt){A=Xr({context2d:D,seed:i,audioFactory:S,clock:()=>E,engineFactory:()=>ta({LJS:r==="real"?s:null,engineMath:r==="real"?ea(s):null,engineMode:r,recHook:y})});let ee=new Ns;for(let me of f)ee.register(me);ee.useContext(A.context),M=ee.initAll(),Z=ee.list().concat(["runtime-probe"]),R=Zr({pluginSet:Z,inputAnchorType:"pointerdown",autoBoot:!0});let ne=A.deriveContextFor("runtime-probe","runtime-probe");gt("t_boot",{by:"game-host",stage:"pre-init",engineMode:r}),gt("t_plugins_ready",{initialized:M.initialized.length,ok:M.ok});let Bi=u(A.context,{bundle:A,plugins:h,getRealAudioCtx:()=>w});T=l(Bi),await T.init({ctx:A.context,mainContext:D,canvas:lt(),seed:i}),ht=T&&typeof T._forensicsView=="function"?T._forensicsView():null,gt("t_game_init",{hasForensics:!!ht}),dt(),gt("t_first_paint",{frame:A.frameCount()});try{R.init(ne)}catch(me){v.push({type:"probe-init",message:String(me&&me.message||me)})}gt("t_game_start",{mode:o,engineMode:r}),jt(),d(dn,{bundle:A,game:T,probe:R,checklist:it,uncaught:v,pluginSet:Z,initRes:M,getGameForensics:()=>ht,mark:gt,stepOneFrame:dt})}let Lt=null;function dt(D){let lt=typeof D=="number"?D:zs;T&&(E+=lt*1e3,T.update(lt),r==="stub"&&Lt&&T.render(Lt),jt())}function Ot(D){for(let lt=0;lt{}),T&&typeof T._onAudioUnlock=="function"&&T._onAudioUnlock()}let dn={seed:i,mode:o,engineMode:r,protocol:Yr,frameCount:()=>A?A.frameCount():0,stepFrames:Ot,startRaf:()=>B(),stopRaf:()=>j(),tap(D,lt){He(),A&&(A.inputBridge._emit("pointerdown",{x:D,y:lt}),A.inputBridge._emit("pointerup",{x:D,y:lt}))},do(D){T&&typeof T._handleAction=="function"&&T._handleAction(D)},state:()=>ht?ht.state():{phase:"booting"}};function fn(D){let lt=A.inputBridge;function ee(ne,Bi){let me=D.getBoundingClientRect();return{x:(ne-me.left)/me.width*a,y:(Bi-me.top)/me.height*c}}D.addEventListener("pointerdown",ne=>{He(),lt._emit("pointerdown",ee(ne.clientX,ne.clientY))}),D.addEventListener("pointermove",ne=>{lt._emit("pointermove",ee(ne.clientX,ne.clientY))}),D.addEventListener("pointerup",ne=>{lt._emit("pointerup",ee(ne.clientX,ne.clientY))})}let ce=0,Le=!1,te=0;function L(D){if(!Le)return;te===0&&(te=D);let lt=(D-te)/1e3;te=D,lt>.05&&(lt=.05),dt(lt),ce=window.requestAnimationFrame(L)}function B(){r==="stub"&&(Le||(Le=!0,te=0,ce=window.requestAnimationFrame(L)))}function j(){Le=!1,ce&&window.cancelAnimationFrame(ce),ce=0}function H(D){D.width=a*Ye,D.height=c*Ye,D.style.width=a+"px",D.style.height=c+"px";let lt=D.getContext("2d",{willReadFrequently:!0});return lt.setTransform(Ye,0,0,Ye,0,0),lt}async function Nt(){let D=H(t);return Lt=D,await qe(D,()=>t),fn(t),o==="evidence"?x(`evidence \u5C31\u7EEA seed=${i} \xB7 \u7528 host \u9A71\u52A8\uFF08stepFrames/tap\uFF09`):(x(`seed=${i} \xB7 \u70B9\u5F00\u59CB\uFF08\u9996\u6B21\u70B9\u51FB\u5F00\u58F0\uFF09`),B()),dn}let ct=()=>{},le=()=>{};function Dt(){window.__gameHostEngineInitFired=!0}function Bt(){ct()}function rt(){}function _t(){le()}function Oe(){}async function In(D){await qe(D,()=>s.mainCanvas),fn(s.mainCanvas),ct=()=>{T&&(E+=zs*1e3,T.update(zs))},le=()=>{if(T){D.save(),D.setTransform(Ye,0,0,Ye,0,0);try{D.imageSmoothingEnabled=!1}catch{}T.render(D),D.restore()}},s.mainCanvas&&(s.mainCanvas.id="game-engine"),window.__engine={frame(){return s.frame},time(){return s.time},timeReal(){return s.timeReal},paused(){return s.paused},timeScale(){return s.timeScale},snapshot(){return{frame:s.frame,time:s.time,timeReal:s.timeReal,paused:s.paused,timeScale:s.timeScale}}},x(`engine RAF running \xB7 seed=${i} engine=real`)}if(r!=="real")return await Nt();if(!s){let D="real \u901A\u9053\u672A\u6CE8\u5165\u5F15\u64CE\uFF08opts.engine \u7F3A\u5931\uFF09\uFF1A\u8BF7\u7ECF entry \u5305\u88C5\u5C42\u542F\u52A8\uFF08host \u4E0D\u76F4\u63A5 import \u5F15\u64CE\uFF0CQ4/Option C\uFF09";throw x("ENGINE INJECT MISSING: "+D),new Error(D)}s.setGLEnable(!1),s.setShowSplashScreen(!1),s.setDebugWatermark(!1),s.setCanvasClearColor(s.BLACK),s.setCanvasFixedSize(s.vec2(a*Ye,c*Ye));let ts=document.createElement("div");return ts.id="engine-root",document.body.appendChild(ts),await s.engineInit(Dt,Bt,rt,_t,Oe,[],ts).then(()=>In(s.mainContext)).catch(D=>{throw window.__gameHostBootError=String(D&&D.message||D),x("ENGINE INIT FAILED: "+window.__gameHostBootError),D}),dn}var Yi=class{constructor(t){let e=t||{},s=typeof e.cellSize=="number"&&e.cellSize>0?e.cellSize:64;this._cellSize=s,this._cells=new Map,this._entries=new Map,this._seq=0}get size(){return this._entries.size}_cellRange(t){let e=this._cellSize,s=Math.floor((t.x-t.hw)/e),i=Math.floor((t.x+t.hw)/e),o=Math.floor((t.y-t.hh)/e),r=Math.floor((t.y+t.hh)/e);return{cx0:s,cy0:o,cx1:i,cy1:r}}insert(t,e){this._entries.has(t)&&this.remove(t);let{cx0:s,cy0:i,cx1:o,cy1:r}=this._cellRange(e),a=[];for(let l=i;l<=r;l++)for(let u=s;u<=o;u++){let h=u+","+l,f=this._cells.get(h);f||(f=new Set,this._cells.set(h,f)),f.add(t),a.push(h)}let c={x:e.x,y:e.y,hw:e.hw,hh:e.hh};this._entries.set(t,{id:t,box:c,seq:this._seq++,cells:a})}remove(t){let e=this._entries.get(t);if(!e)return!1;for(let s of e.cells){let i=this._cells.get(s);i&&(i.delete(t),i.size===0&&this._cells.delete(s))}return this._entries.delete(t),!0}query(t){let{cx0:e,cy0:s,cx1:i,cy1:o}=this._cellRange(t),r=new Set;for(let a=s;a<=o;a++)for(let c=e;c<=i;c++){let l=this._cells.get(c+","+a);if(l)for(let u of l)r.add(u)}return this._collect(r)}queryPoint(t,e){let s=this._cellSize,i=Math.floor(t/s),o=Math.floor(e/s),r=this._cells.get(i+","+o);return r?this._collect(new Set(r)):[]}clear(){this._cells.clear(),this._entries.clear(),this._seq=0}_collect(t){let e=[];for(let s of t){let i=this._entries.get(s);i&&e.push(i)}return e.sort((s,i)=>s.seq-i.seq),e.map(s=>({id:s.id,box:s.box}))}};function sa(n){let t=n||{},e=new Yi({cellSize:t.cellSize}),s=!1;return{name:"collision",version:"1.0.0",dependencies:[],spatial:e,init(o){},dispose(){s||(e.clear(),s=!0)}}}function ia(n){let t=!1;return{name:"physics-lite",version:"1.0.0",dependencies:[],init(s){},dispose(){t||(t=!0)}}}var Hc=["pointerdown","pointermove","pointerup","keydown","keyup"];function zt(n){return n<0?0:n>1?1:n}var Xc=n=>(n=zt(n),n*n),Yc=n=>(n=zt(n),1-(1-n)*(1-n)),$c=n=>(n=zt(n),n<.5?2*n*n:1-Math.pow(-2*n+2,2)/2),Kc=n=>(n=zt(n),n*n*n),Qc=n=>{n=zt(n);let t=1-n;return 1-t*t*t},Zc=n=>(n=zt(n),n<.5?4*n*n*n:1-Math.pow(-2*n+2,3)/2),aa=2*Math.PI/3,oa=2*Math.PI/4.5,tl=n=>(n=zt(n),n===0?0:n===1?1:-Math.pow(2,10*n-10)*Math.sin((n*10-10.75)*aa)),el=n=>(n=zt(n),n===0?0:n===1?1:Math.pow(2,-10*n)*Math.sin((n*10-.75)*aa)+1),nl=n=>(n=zt(n),n===0?0:n===1?1:n<.5?-(Math.pow(2,20*n-10)*Math.sin((20*n-11.125)*oa))/2:Math.pow(2,-20*n+10)*Math.sin((20*n-11.125)*oa)/2+1),Us=1.70158,Js=Us*1.525,ca=Us+1,sl=n=>(n=zt(n),ca*n*n*n-Us*n*n),il=n=>{n=zt(n);let t=n-1;return 1+ca*t*t*t+Us*t*t},ol=n=>(n=zt(n),n<.5?Math.pow(2*n,2)*((Js+1)*2*n-Js)/2:(Math.pow(2*n-2,2)*((Js+1)*(n*2-2)+Js)+2)/2),rl=n=>zt(n),ra=Object.freeze({linear:rl,quadIn:Xc,quadOut:Yc,quadInOut:$c,cubicIn:Kc,cubicOut:Qc,cubicInOut:Zc,elasticIn:tl,elasticOut:el,elasticInOut:nl,backIn:sl,backOut:il,backInOut:ol});var al=["linear","quadIn","quadOut","quadInOut","cubicIn","cubicOut","cubicInOut","elasticIn","elasticOut","elasticInOut","backIn","backOut","backInOut"];function cl(n){let t=n&&n.easing;if(!t)return ra;let e=i=>typeof t[i]=="function"?o=>t[i](zt(o)):ra[i],s={};for(let i of al)s[i]=e(i);return Object.freeze(s)}var $i=class{constructor(t,e,s){let i=s||{};this._time=e,this._windowMs=typeof i.windowMs=="number"&&i.windowMs>0?i.windowMs:120;let o=Array.isArray(i.types)&&i.types.length>0?i.types:Hc;this._records=new Map,this._subs=[],this._disposed=!1;for(let r of o){this._records.set(r,null);let a=t.on(r,c=>{this._records.set(r,c.tMs)});this._subs.push(a)}}consume(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs?(this._records.set(t,null),!0):(this._records.set(t,null),!1)}peek(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs}clear(){for(let t of this._records.keys())this._records.set(t,null)}dispose(){if(!this._disposed){for(let t of this._subs)try{t.cancel()}catch(e){}this._subs=[],this._disposed=!0}}};function la(n){let t=n||{},e=null,s=null,i=!1;return{name:"gamefeel",version:"1.0.0",dependencies:[],get inputBuffer(){return e},get easing(){return cl(s)},init(r){let a=r.getInput();e=new $i(a,r.time,{windowMs:t.inputBufferMs,types:t.inputTypes});let c=r.getEngine();s=c?c.math:null},dispose(){i||(e&&(e.dispose(),e=null),s=null,i=!0)}}}function Vs(n,t){let e=t<0?0:t>1?1:t;switch(n&&n.kind){case"constant":return n.value;case"linear":return n.from+(n.to-n.from)*e;case"easeInOut":{let s=e*e*(3-2*e);return n.from+(n.to-n.from)*s}case"decay":{let s=n.power==null?2:n.power,i=Math.pow(1-e,s);return n.to+(n.from-n.to)*i}default:return 0}}var ll=Object.freeze({burst:Object.freeze({mode:"burst",count:24,angle:0,spread:Math.PI,speedMin:80,speedMax:160,lifeMin:.4,lifeMax:.8,gravity:0,drag:0,sizeCurve:{kind:"decay",from:6,to:0,power:1.5},alphaCurve:{kind:"linear",from:1,to:0}}),trail:Object.freeze({mode:"continuous",rate:60,angle:Math.PI,spread:.25,speedMin:20,speedMax:50,lifeMin:.2,lifeMax:.5,gravity:0,drag:1.5,sizeCurve:{kind:"easeInOut",from:4,to:0},alphaCurve:{kind:"decay",from:.8,to:0,power:2}}),drift:Object.freeze({mode:"continuous",rate:12,angle:Math.PI/2,spread:.6,speedMin:10,speedMax:30,lifeMin:1.5,lifeMax:3,gravity:8,drag:.5,sizeCurve:{kind:"constant",value:3},alphaCurve:{kind:"decay",from:.7,to:0,power:1}})});function ul(n){let t=ll[n];return t?Ki(t):null}function Ki(n){let t={};for(let e of Object.keys(n)){let s=n[e];t[e]=s&&typeof s=="object"?Ki(s):s}return t}function hl(n,t,e){let s=n.mode==="continuous";return{pos:{x:t,y:e},angle:n.angle,coneAngle:n.spread,emitSize:0,emitTime:s?0:1/60,emitRate:s?n.rate||0:void 0,count:s?void 0:n.count||0,particleTime:(n.lifeMin+n.lifeMax)/2,speed:(n.speedMin+n.speedMax)/2,gravityScale:n.gravity||0,damping:n.drag!=null?1-n.drag/60:1,sizeStart:Vs(n.sizeCurve,0),sizeEnd:Vs(n.sizeCurve,1),colorStart:{r:1,g:1,b:1,a:Vs(n.alphaCurve,0)},colorEnd:{r:1,g:1,b:1,a:Vs(n.alphaCurve,1)},additive:!1}}function ua(n){let t=n||{},e=null,s=null,i=null,o=new Map,r=0,a={isActive(){return!1},stop(){}},c=0,l=1,u=0,h=0,f=0,d={x:0,y:0,remain:0,dur:0,amplitude:0,frequency:0,_phase:0},y={alpha:0,remain:0,dur:0,peak:0},x={scale:1,remain:0,dur:0,amplitude:0,frequency:0},v=!1;function w(A){if(u>0)if(u-=A,u<=0)u=0,l=1;else{let T=h>0?1-u/h:1;l=f+(1-f)*T}if(d.remain>0)if(d.remain-=A,d.remain<=0)d.remain=0,d.x=0,d.y=0;else{let T=d.remain/d.dur,R=d.amplitude*T;d._phase+=d.frequency*A*Math.PI*2,d.x=Math.sin(d._phase)*R,d.y=Math.cos(d._phase*1.3)*R}if(y.remain>0&&(y.remain-=A,y.remain<=0?(y.remain=0,y.alpha=0):y.alpha=y.peak*(y.remain/y.dur)),x.remain>0)if(x.remain-=A,x.remain<=0)x.remain=0,x.scale=1;else{let T=x.remain/x.dur,R=(1-T)*x.frequency*Math.PI*2;x.scale=1+Math.sin(R)*x.amplitude*T}}function _(A){c+=1,w(A)}function S(A){let T=A!==void 0?A:e?e.getContext2d():null;if(T&&y.alpha>0){T.globalAlpha=y.alpha,T.fillStyle="#ffffff";let R=T.canvas?T.canvas.width:0,M=T.canvas?T.canvas.height:0;T.fillRect(0,0,R,M),T.globalAlpha=1}}return{name:"particles-juice",version:"1.0.0",dependencies:[],init(A){var T;e=A,i=((T=A.getEngine())==null?void 0:T.particles)||null,typeof t.seed=="number"&&A.random.reseed(t.seed),t.autoStep!==!1&&(s=A.onFrame(R=>{_(R)}))},dispose(){v||(s&&(s.cancel(),s=null),o.forEach(A=>{try{A.stop()}catch{}}),o.clear(),l=1,u=0,d.remain=0,d.x=0,d.y=0,y.remain=0,y.alpha=0,x.remain=0,x.scale=1,v=!0)},spawnEmitter(A,T,R,M){let Z=typeof A=="string"?ul(A):Ki(A);if(!Z)return-1;M&&(Z=Object.assign(Z,M));let it=r++;if(!i)return o.set(it,a),it;let ht=i.spawnEmitter(hl(Z,T,R));return o.set(it,ht),it},stopEmitter(A){let T=o.get(A);if(T)try{T.stop()}catch{}},step(A){_(A)},render(A){S(A)},particleCount(){return 0},emitterCount(){let A=0;for(let T of o.values())T.isActive()&&(A+=1);return A},hitStop(A,T){h=Math.max(0,A),u=h,f=T==null?0:Math.max(0,Math.min(1,T)),l=h>0?f:1},getTimeScale(){return l},shakeScreen(A,T,R){d.dur=Math.max(0,A),d.remain=d.dur,d.amplitude=Math.max(0,T),d.frequency=R==null?30:R,d._phase=0,d.x=0,d.y=0},getShakeOffset(){return{x:d.x,y:d.y}},flashScreen(A,T){y.dur=Math.max(0,A),y.remain=y.dur,y.peak=T==null?.8:Math.max(0,Math.min(1,T)),y.alpha=y.dur>0?y.peak:0},getFlashAlpha(){return y.alpha},pulseScale(A,T,R){x.dur=Math.max(0,A),x.remain=x.dur,x.amplitude=T==null?.2:T,x.frequency=R==null?4:R,x.scale=1},getPulseScale(){return x.scale},juiceSnapshot(){return{timeScale:l,shake:{x:d.x,y:d.y},flashAlpha:y.alpha,pulseScale:x.scale}},probe(){return{particles:0,emitters:o.size,dropped:0,steps:c,disposed:v}}}}function ha(n){let t=yt(n.r)/255,e=yt(n.g)/255,s=yt(n.b)/255,i=Math.max(t,e,s),o=Math.min(t,e,s),r=(i+o)/2,a=0,c=0,l=i-o;return l>1e-12&&(c=r>.5?l/(2-i-o):l/(i+o),i===t?a=(e-s)/l%6:i===e?a=(s-t)/l+2:a=(t-e)/l+4,a*=60,a<0&&(a+=360)),{h:a,s:c,l:r}}function da(n){let t=(n.h%360+360)%360,e=$e(n.s),s=$e(n.l);if(e<1e-12){let a=Math.round(s*255);return{r:a,g:a,b:a}}let i=s<.5?s*(1+e):s+e-s*e,o=2*s-i,r=t/360;return{r:Math.round(Qi(o,i,r+1/3)*255),g:Math.round(Qi(o,i,r)*255),b:Math.round(Qi(o,i,r-1/3)*255)}}function Qi(n,t,e){let s=e;return s<0&&(s+=1),s>1&&(s-=1),s<1/6?n+(t-n)*6*s:s<1/2?t:s<2/3?n+(t-n)*(2/3-s)*6:n}function yt(n){return n<0?0:n>255?255:n}function $e(n){return n<0?0:n>1?1:n}function dl(n,t){let e=pl(n.from,t);if(e>=0&&e({r:yt(a.r),g:yt(a.g),b:yt(a.b)})),to:o}}function Zi(n,t,e){return n+(t-n)*e}function ml(n,t){let e=ha(n),s=e.h+(t.hue||0),i=$e(e.s*(t.sat==null?1:t.sat)),o=$e(e.l*(t.light==null?1:t.light));return da({h:s,s:i,l:o})}var bl=Object.freeze([Object.freeze([0,8,2,10]),Object.freeze([12,4,14,6]),Object.freeze([3,11,1,9]),Object.freeze([15,7,13,5])]);function fa(n){let t=n||{},e=null,s=!1,i={vignette:{enabled:to(t.vignette&&t.vignette.enabled,!1),strength:eo(t.vignette&&t.vignette.strength,.5)},dither:{enabled:to(t.dither&&t.dither.enabled,!1),strength:eo(t.dither&&t.dither.strength,.5)},scanline:{enabled:to(t.scanline&&t.scanline.enabled,!1),strength:eo(t.scanline&&t.scanline.strength,.5)}};function o(a){let c=a!==void 0?a:e?e.getContext2d():null;if(!c)return;let l=c.canvas?c.canvas.width:0,u=c.canvas?c.canvas.height:0;if(i.vignette.enabled&&i.vignette.strength>0&&l>0&&u>0){let h=c.createRadialGradient(l/2,u/2,Math.min(l,u)*.25,l/2,u/2,Math.max(l,u)*.75);h.addColorStop(0,"rgba(0,0,0,0)"),h.addColorStop(1,"rgba(0,0,0,"+i.vignette.strength.toFixed(3)+")"),c.fillStyle=h,c.fillRect(0,0,l,u)}if(i.scanline.enabled&&i.scanline.strength>0&&l>0&&u>0){c.fillStyle="rgba(0,0,0,"+(i.scanline.strength*.5).toFixed(3)+")";for(let h=0;h0&&l>0&&u>0&&typeof c.getImageData=="function"&&typeof c.putImageData=="function"){let h=c.getImageData(0,0,l,u);xl(h,i.dither.strength),c.putImageData(h,0,0)}}return{name:"palette-post",version:"1.0.0",dependencies:[],init(a){e=a},dispose(){s||(e=null,s=!0)},applyPaletteMap(a,c){return dl(a,c)},applyPaletteMapToBuffer(a,c){return fl(a,c)},lerpPaletteMap(a,c,l){return yl(a,c,l)},shiftHsl(a,c){return ml(a,c)},rgbToHsl(a){return ha(a)},hslToRgb(a){return da(a)},setPost(a){if(a)for(let c of["vignette","dither","scanline"])a[c]&&(typeof a[c].enabled=="boolean"&&(i[c].enabled=a[c].enabled),typeof a[c].strength=="number"&&(i[c].strength=$e(a[c].strength)))},getPost(){return{vignette:{enabled:i.vignette.enabled,strength:i.vignette.strength},dither:{enabled:i.dither.enabled,strength:i.dither.strength},scanline:{enabled:i.scanline.enabled,strength:i.scanline.strength}}},renderPost(a){o(a)},probe(){return{disposed:s,post:this.getPost()}}}}function xl(n,t){let e=$e(t);if(e<=0)return n;let{data:s,width:i}=n,r=255/(Math.max(2,Math.round(16-e*14))-1);for(let a=0;a+3>2)%i,l=Math.floor((a>>2)/i),u=(bl[l&3][c&3]/16-.5)*r;for(let h=0;h<3;h++){let f=s[a+h]+u,d=Math.round(f/r)*r;s[a+h]=d<0?0:d>255?255:d}}return n}function to(n,t){return typeof n=="boolean"?n:t}function eo(n,t){return typeof n=="number"?$e(n):t}var so=Object.freeze({blip:Object.freeze({name:"blip",params:Object.freeze([.6,0,880,0,.03,.06,1,1.5])}),thud:Object.freeze({name:"thud",params:Object.freeze([.8,0,90,0,.04,.18,0,1,0,0,0,0,0,4])}),chime:Object.freeze({name:"chime",params:Object.freeze([.5,0,660,.02,.12,.3,1,2])})}),pa=Object.keys(so);function vl(n){let t=[];return n==null||typeof n!="object"?{ok:!1,errors:["song \u5FC5\u987B\u662F\u5BF9\u8C61"]}:(!Array.isArray(n.instruments)||n.instruments.length===0?t.push("instruments \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.instruments.forEach((e,s)=>{(!Array.isArray(e)||e.some(i=>typeof i!="number"||!Number.isFinite(i)))&&t.push(`instruments[${s}] \u5FC5\u987B\u662F\u6709\u9650\u6570\u5B57\u6570\u7EC4\uFF08ZzFX \u53C2\u6570\u5305\uFF09`)}),!Array.isArray(n.patterns)||n.patterns.length===0?t.push("patterns \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.patterns.forEach((e,s)=>{if(!Array.isArray(e)||e.length===0){t.push(`patterns[${s}] \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4\uFF08\u81F3\u5C11\u4E00\u4E2A\u58F0\u90E8\u901A\u9053\uFF09`);return}e.forEach((i,o)=>{if(!Array.isArray(i)||i.length<2){t.push(`patterns[${s}][${o}] \u901A\u9053\u81F3\u5C11\u542B [\u4E50\u5668\u7D22\u5F15, \u58F0\u50CF]`);return}if(i.some(c=>typeof c!="number"||!Number.isFinite(c))){t.push(`patterns[${s}][${o}] \u901A\u9053\u5FC5\u987B\u5168\u4E3A\u6709\u9650\u6570\u5B57`);return}let r=i[0]|0;Array.isArray(n.instruments)&&(r<0||r>=n.instruments.length)&&t.push(`patterns[${s}][${o}] \u4E50\u5668\u7D22\u5F15 ${r} \u8D8A\u754C\uFF08instruments \u957F\u5EA6 ${n.instruments.length}\uFF09`);let a=i[1];(a<-1||a>1)&&t.push(`patterns[${s}][${o}] \u58F0\u50CF ${a} \u8D8A\u754C\uFF08\u5E94 -1..+1\uFF09`)})}),!Array.isArray(n.sequence)||n.sequence.length===0?t.push("sequence \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.sequence.forEach((e,s)=>{if(typeof e!="number"||!Number.isInteger(e)){t.push(`sequence[${s}] \u5FC5\u987B\u662F\u6574\u6570 pattern \u7D22\u5F15`);return}Array.isArray(n.patterns)&&(e<0||e>=n.patterns.length)&&t.push(`sequence[${s}] \u7D22\u5F15 ${e} \u8D8A\u754C\uFF08patterns \u957F\u5EA6 ${n.patterns.length}\uFF09`)}),n.bpm!=null&&(typeof n.bpm!="number"||!(n.bpm>0))&&t.push("bpm \u5FC5\u987B\u662F\u6B63\u6570"),{ok:t.length===0,errors:t})}function be(n){return typeof n!="number"||Number.isNaN(n)||n<0?0:n>1?1:n}function Sl(n,t){switch(n){case"ease-in":return t*t;case"ease-out":return Math.sqrt(t);case"constant":return 1;default:return t}}function ga(n,t){let e=be(t);return n==null||!Array.isArray(n.voices)?[]:n.voices.map(s=>{let i=String(s&&s.id!=null?s.id:""),o=Array.isArray(s&&s.channelIndices)?s.channelIndices.slice():[],r=typeof s.minIntensity=="number"?be(s.minIntensity):0,a=typeof s.maxIntensity=="number"?be(s.maxIntensity):1,c=typeof s.volumeCurve=="string"?s.volumeCurve:"linear",l=typeof s.baseVolume=="number"?be(s.baseVolume):1;if(ea)return{id:i,on:!1,volume:0,channelIndices:o};let u=a-r,h=u<=0?1:(e-r)/u,f=be(Sl(c,h)*l);return{id:i,on:!0,volume:f,channelIndices:o}})}function ya(n,t,e,s){try{let i=t[0]||[],o=t[1]||i,r=Math.max(i.length,o.length);if(r===0)return null;let c=n.createBuffer(2,r,44100);c.getChannelData(0).set(i),c.getChannelData(1).set(o.length?o:i);let l=n.createBufferSource();l.buffer=c,l.loop=!!s;let u=n.createGain();return u.gain.value=be(e*.3),l.connect(u),u.connect(n.destination),l.start(),{stop(){try{l.stop()}catch(h){}try{l.disconnect(),u.disconnect()}catch(h){}}}}catch(i){return io("[audio-music] \u53D7\u63A7\u97F3\u9891\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",i),null}}function ma(n){let t=n||{},e=typeof t.masterVolume=="number"?be(t.masterVolume):1,s=()=>null,i=null,o=null,r={voices:[]},a=1,c=null,l=!1,u=0,h=!1,f=!1;function d(){let S=s();return S==null?(u+=1,h||(no("[audio-music] \u65E0\u53D7\u63A7\u97F3\u9891\u4E0A\u4E0B\u6587\uFF08getAudioContext \u8FD4\u56DE null\uFF09\uFF0C\u5168\u90E8\u53D1\u58F0\u9759\u9ED8 no-op\uFF08\u8BC4\u4F30\u73AF\u5883\u65E0\u58F0\u5361\u65F6\u7684\u5BB9\u9519\u964D\u7EA7\uFF09"),h=!0),null):S}function y(){if(!o||!i)return null;try{let S=typeof o.bpm=="number"&&o.bpm>0?o.bpm:125;return i.synthSong(o.instruments,o.patterns,o.sequence,S)}catch(S){return io("[audio-music] \u66F2\u8C31\u6E32\u67D3\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",S),null}}function x(){let S=ga(r,a);if(S.length===0)return 1;let E=0;for(let A of S)A.on&&(E=Math.max(E,A.volume));return E}function v(S,E){typeof E=="number"&&(a=be(E));let A=d();if(A==null||!o)return;w();let T=y();if(!T)return;let R=be(e*x());c=ya(A,T,R,S),l=!!S&&c!=null}function w(){c&&(c.stop(),c=null),l=!1}return{name:"audio-music",version:"1.0.0",dependencies:[],init(S){s=()=>S.getAudioContext();let E=S.getEngine&&S.getEngine();i=E?E.audio.synth:null},dispose(){f||(w(),f=!0)},loadSong(S){let E=vl(S);return E.ok?o={instruments:S.instruments,patterns:S.patterns,sequence:S.sequence,bpm:typeof S.bpm=="number"?S.bpm:125}:no("[audio-music] \u66F2\u8C31\u6821\u9A8C\u5931\u8D25\uFF0C\u672A\u8F7D\u5165\uFF1A"+E.errors.join("\uFF1B")),E},play(S){v(!1,S)},stop(){w()},loop(S){v(!0,S)},setIntensityLayering(S){r=S&&Array.isArray(S.voices)?{voices:S.voices}:{voices:[]}},setIntensity(S){a=be(S)},resolveVoices(S){return ga(r,S)},playSfx(S){let E=so[S];if(!E){no("[audio-music] \u672A\u77E5\u97F3\u6548\u9884\u8BBE\uFF1A"+String(S));return}let A=d();if(A!=null)try{let T=i?i.synthSfx(E.params):null;if(!T)return;ya(A,[T,T],e,!1)}catch(T){io("[audio-music] \u97F3\u6548\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8 name="+S,T)}},getPreset(S){return so[S]},listPresets(){return pa.slice()},probe(){return{hasAudio:s()!=null,hasSong:o!=null,intensity:a,voiceCount:r.voices.length,looping:l,silentNoops:u,presetCount:pa.length}}}}function io(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function no(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var wl="zaomeng.save";function Tl(n){if(typeof TextEncoder!="undefined")return new TextEncoder().encode(n).length;if(typeof Buffer!="undefined"&&typeof Buffer.byteLength=="function")return Buffer.byteLength(n,"utf8");let t=0;for(let e=0;e=55296&&s<=56319?(t+=4,e++):t+=3}return t}function ro(){let n=new Map;return{getItem(t){return n.has(t)?n.get(t):null},setItem(t,e){n.set(t,e)},removeItem(t){n.delete(t)},keys(){return Array.from(n.keys())}}}function ba(){if(typeof localStorage=="undefined")throw new Error("[save-progress] createLocalStorageAdapter \u9700\u8981\u5168\u5C40 localStorage\uFF08\u4EC5\u6D4F\u89C8\u5668\u96C6\u6210\u6BB5\u53EF\u7528\uFF09\u3002node/host-dev \u8BF7\u7528\u7F3A\u7701\u5185\u5B58 adapter \u6216 createMemoryAdapter()\u3002");return{getItem(n){return localStorage.getItem(n)},setItem(n,t){localStorage.setItem(n,t)},removeItem(n){localStorage.removeItem(n)},keys(){let n=[];for(let t=0;t0?t.namespace:wl;if(e.indexOf(":")>=0)throw new Error('[save-progress] namespace \u4E0D\u5F97\u542B\u5206\u9694\u7B26 ":"\uFF08\u5F53\u524D="'+e+'"\uFF09');let s=typeof t.maxValueBytes=="number"&&t.maxValueBytes>0?Math.floor(t.maxValueBytes):32768,i=!Al(t.adapter),o=i?ro():t.adapter,r=e+":",a=0,c=0,l=!1;function u(d){return typeof d!="string"||d.length===0?r+String(d):r+d}function h(){try{let d=o.keys();return Array.isArray(d)?d.filter(y=>typeof y=="string"&&y.indexOf(r)===0):[]}catch(d){return es("[save-progress] adapter.keys() \u5F02\u5E38\uFF0C\u964D\u7EA7\u8FD4\u56DE\u7A7A\u96C6",d),[]}}return{name:"save-progress",version:"1.0.0",dependencies:[],init(d){h()},dispose(){},get(d,y){if(!oo(d))return y;let x;try{x=o.getItem(u(d))}catch(v){return es("[save-progress] adapter.getItem \u5F02\u5E38\uFF0C\u8FD4\u56DE\u9ED8\u8BA4\u503C key="+d,v),y}if(x==null)return y;try{return JSON.parse(x)}catch{return a+=1,l||(ns("[save-progress] \u68C0\u6D4B\u5230\u635F\u574F\u5B58\u6863\uFF08\u975E\u6CD5 JSON\uFF09\uFF0C\u5DF2\u5BB9\u9519\u56DE\u9000\u9ED8\u8BA4\u503C key="+d),l=!0),y}},set(d,y){if(!oo(d))return ns("[save-progress] set \u6536\u5230\u975E\u6CD5 key\uFF0C\u62D2\u7EDD\u5199\u5165\uFF1A"+String(d)),!1;let x;try{x=JSON.stringify(y)}catch{return c+=1,ns("[save-progress] \u503C\u4E0D\u53EF JSON \u5E8F\u5217\u5316\uFF08\u5FAA\u73AF\u5F15\u7528?\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1}if(x===void 0)return c+=1,ns("[save-progress] \u503C\u5E8F\u5217\u5316\u4E3A undefined\uFF08\u5982\u7EAF undefined/\u51FD\u6570\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1;let v=Tl(x);if(v>s)return c+=1,ns("[save-progress] \u503C\u8D85\u5B57\u8282\u4E0A\u9650\u62D2\u7EDD\u5199\u5165 key="+d+"\uFF08"+v+" > "+s+" bytes\uFF09"),!1;try{return o.setItem(u(d),x),!0}catch(w){return c+=1,es("[save-progress] adapter.setItem \u5F02\u5E38\uFF0C\u5199\u5165\u5931\u8D25 key="+d,w),!1}},remove(d){if(oo(d))try{o.removeItem(u(d))}catch(y){es("[save-progress] adapter.removeItem \u5F02\u5E38\uFF08\u5DF2\u5FFD\u7565\uFF09key="+d,y)}},clear(){let d=h(),y=0;for(let x of d)try{o.removeItem(x),y+=1}catch(v){es("[save-progress] clear \u65F6 removeItem \u5F02\u5E38\uFF08\u5DF2\u8DF3\u8FC7\uFF09fullKey="+x,v)}return y},probe(){return{namespace:e,maxValueBytes:s,usingMemoryAdapter:i,size:h().length,corruptRecoveries:a,rejectedWrites:c}}}}function oo(n){return typeof n=="string"&&n.length>0}function Al(n){return!!n&&typeof n.getItem=="function"&&typeof n.setItem=="function"&&typeof n.removeItem=="function"&&typeof n.keys=="function"}function es(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function ns(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var Cl={w:390,h:844};function va(n){let t=((n&&n.seed)!=null?n.seed:0)>>>0,e=sa({cellSize:96}),s=ia(),i=la({inputBufferMs:260,inputTypes:["pointerdown"]}),o=ua({seed:t,maxParticles:600}),r=fa({vignette:{enabled:!0,strength:.22}}),a=ma({masterVolume:.8}),c;try{c=ba()}catch(f){console.warn("[generic] localStorage \u4E0D\u53EF\u7528\uFF0C\u5B58\u6863\u9000\u5185\u5B58 adapter\uFF1A"+(f&&f.message)),c=ro()}let l=xa({namespace:"zaomeng-generic",adapter:c});return{plugins:{collision:e,physics:s,gamefeel:i,juice:o,palettePost:r,audioMusic:a,save:l},registerOrder:[e,s,i,o,r,l,a],viewport:Cl,buildFactoryOpts:(f,d)=>({runtime:{plugins:d.plugins,bundle:d.bundle,getRealAudioCtx:d.getRealAudioCtx}})}}function ss(n){let t=n||{},e=null,s=null,i=null,o=t.seed||42,r="booting",a=0,c=0,l=0,u="",h=[],f=null,d=null,y=0,x=.8,v=1,w=.5,_=null,S=[{shape:[[1,1,1,1]],color:1},{shape:[[1,1],[1,1]],color:2},{shape:[[0,1,0],[1,1,1]],color:3},{shape:[[0,1,1],[1,1,0]],color:4},{shape:[[1,1,0],[0,1,1]],color:5},{shape:[[1,0,0],[1,1,1]],color:6},{shape:[[0,0,1],[1,1,1]],color:7}],E=[null,"#00f0f0","#f0f000","#a000f0","#00f000","#f00000","#0000f0","#f0a000"];function A(){return e.random.next()}function T(L,B){return Math.floor(A()*(B-L+1))+L}function R(L){let B=S[L],j=B.shape.map(H=>H.slice());return{type:L,shape:j,x:Math.floor((10-j[0].length)/2),y:0,color:B.color}}function M(L){let B=L.length,j=L[0].length,H=[];for(let Nt=0;Nt=0;ct--)H[Nt].push(L[ct][Nt])}return H}function Z(L,B,j,H,Nt){let ct=Nt||L.shape;for(let le=0;le=10||rt>=18||rt>=0&&B[rt][Bt]!==0)return!0}return!1}function it(){let L=f;if(!L)return;let B=L.shape;for(let j=0;j=0&&ct<18&&(h[ct][Nt]=L.color)}if(l++,ht(),gt(),r!=="gameover"){let j=e.getEngine();if(j){if(j.particles)try{j.particles.spawnEmitter({pos:{x:L.x*39+19.5,y:L.y*46.9+23.45},count:10,speed:60,particleTime:.3,colorStart:{r:1,g:1,b:1,a:1},colorEnd:{r:1,g:1,b:1,a:0}})}catch{}if(j.audio&&j.audio.synth)try{j.audio.synth.synthSfx([1,.05,300,,,.15,,1.2])}catch{}}}}function ht(){let L=0;for(let B=17;B>=0;){let j=!0;for(let H=0;H<10;H++)if(h[B][H]===0){j=!1;break}if(j){for(let H=B;H>0;H--)h[H]=h[H-1].slice();h[0]=new Array(10).fill(0),L++}else B--}if(L>0){c+=L,L===1?a+=100:L===2?a+=300:L===3?a+=500:L===4&&(a+=800);let B=e.getEngine();if(B&&B.particles)try{B.particles.spawnEmitter({pos:{x:195,y:422},count:30,speed:120,particleTime:.6,colorStart:{r:.2,g:1,b:.2,a:1},colorEnd:{r:0,g:.8,b:0,a:0}})}catch{}if(B&&B.audio&&B.audio.synth)try{B.audio.synth.synthSfx([1,.1,500,,,.2,,1.5])}catch{}}}function gt(){if(!d){let B=T(0,6);d=R(B)}f=d;let L=T(0,6);if(d=R(L),Z(f,h,0,0,f.shape)){r="gameover",u="stack_to_top";return}f.x=Math.floor((10-f.shape[0].length)/2),f.y=0}function jt(){if(!(!f||r==="gameover")){if(!Z(f,h,0,1,f.shape)){f.y++;return}it()}}function qe(){if(!(!f||r==="gameover")){for(;!Z(f,h,0,1,f.shape);)f.y++;it()}}function Lt(L){!f||r==="gameover"||Z(f,h,L,0,f.shape)||(f.x+=L)}function dt(){if(!f||r==="gameover")return;let L=M(f.shape);Z(f,h,0,0,L)?Z(f,h,-1,0,L)?Z(f,h,1,0,L)||(f.shape=L,f.x+=1):(f.shape=L,f.x-=1):f.shape=L}function Ot(L){if(r!=="gameover")switch(L.key){case"ArrowLeft":Lt(-1);break;case"ArrowRight":Lt(1);break;case"ArrowUp":dt();break;case"ArrowDown":v=.05;break;case" ":qe();break}}function He(L){L.key==="ArrowDown"&&(v=1)}function dn(L){e=L.ctx,s=L.canvas,i=L.mainContext,h=new Array(18);for(let H=0;H<18;H++)h[H]=new Array(10).fill(0);e.random.reseed(o);let B=T(0,6);d=R(B),gt(),_=e.getInput().on("keydown",Ot),e.getInput().on("keyup",He),a=0,c=0,l=0,y=0,r="playing",u="";let j=e.getEngine();if(j&&j.math)try{j.math.lerp(0,1,.5)}catch{}}function fn(L){let B=e.time.nowMs();if(r==="gameover")return;y+=L;let j=x*v;y>=j&&(y-=j,jt())}function ce(L){L.fillStyle="#0a0a1a",L.fillRect(0,0,390,844);let B=39,j=46.8888,H=40,Nt=18*j,ct=40,Dt=(844-ct-20)/18,Bt=390/10;L.strokeStyle="#1a1a3a",L.lineWidth=1;for(let rt=0;rt<=18;rt++){let _t=ct+rt*Dt;L.beginPath(),L.moveTo(0,_t),L.lineTo(390,_t),L.stroke()}for(let rt=0;rt<=10;rt++){let _t=rt*Bt;L.beginPath(),L.moveTo(_t,ct),L.lineTo(_t,844),L.stroke()}for(let rt=0;rt<18;rt++)for(let _t=0;_t<10;_t++){let Oe=h[rt][_t];Oe>0&&(L.fillStyle=E[Oe],L.fillRect(_t*Bt,ct+rt*Dt,Bt-1,Dt-1))}if(f&&r!=="gameover"){let rt=f;L.fillStyle=E[rt.color];let _t=rt.shape;for(let Oe=0;Oe<_t.length;Oe++)for(let In=0;In<_t[0].length;In++)if(_t[Oe][In]!==0){let ts=(rt.x+In)*Bt,D=ct+(rt.y+Oe)*Dt;L.fillRect(ts,D,Bt-1,Dt-1)}}L.fillStyle="#ffffff",L.font="bold 16px monospace",L.fillText("Score: "+a,10,20),L.fillText("Lines: "+c,160,20),L.fillText("Pieces: "+l,290,20),r==="gameover"&&(L.fillStyle="rgba(0,0,0,0.7)",L.fillRect(0,200,390,200),L.fillStyle="#ff4444",L.font="bold 28px monospace",L.textAlign="center",L.fillText("GAME OVER",195,300),L.font="14px monospace",L.fillStyle="#aaaaaa",L.fillText("Tap to restart",195,340),L.textAlign="left")}function Le(){try{_&&_.cancel()}catch{}_=null}function te(){return{seed:o,state:()=>({phase:r,result:r==="gameover"?"lose":null,score:a,lines:c,piecesLocked:l,board:h.map(L=>L.slice())})}}return{init:dn,update:fn,render:ce,destroy:Le,_forensicsView:te}}var pd=ss,gd=ss;async function yd(n){let t=n||{},e=t.engine||await Promise.resolve().then(()=>(Mc(),Ic)),s=(t.seed!=null?t.seed:305441741)>>>0,i=va({seed:s});return na({canvas:t.canvas,statusEl:t.statusEl||null,engine:e,seed:s,mode:t.mode||"play",engineMode:"real",viewport:i.viewport,factory:ss,plugins:i.plugins,registerOrder:i.registerOrder,buildFactoryOpts:i.buildFactoryOpts,recHook:t.recHook||null,onReady:t.onReady||null})}return Bc(md);})();
+color = `+this.color),t}renderDebug(t=!0){let e=t?this.isHoverObject()?Ka:this.disabled?tc:this.interactive?rr:Za:Qa;C.drawRect(this.nativePos,this.size,ye,4,e)}click(t=!0){this.onClick(),t&&this.soundClick&&this.soundClick.play()}onUpdate(){}onRender(){}onEnter(){}onLeave(){}onPress(){}onRelease(){}onClick(){}onChange(){}},vi=class extends ae{constructor(t,e,s="",i="center",o=C.defaultFont){super(t,e),p(U(s),"ui text must be a string"),p(["left","center","right"].includes(i),"ui text align must be left, center, or right"),p(U(o),"ui text font must be a string"),this.text=s,this.align=i,this.font=o,this.canBeHover=!1,this.color=ye,this.shadowColor=ye,this.gradientColor=void 0,this.lineWidth=0,this.textFitScale=1}render(){super.render();let t=this.getTextSize();C.drawText(this.text,this.nativePos,t,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow,this.shadowColor,this.shadowBlur,this.shadowOffset)}},Mo=class extends ae{constructor(t,e,s=""){super(t,e),p(U(s),"ui text must be a string"),this.maxLength=0,this.text=s,this.interactive=!0,this.canBeHover=!0}click(){C.keyInputObject=this,this.onClick()}stopEditing(){this.isKeyInputObject()&&(this.soundRelease&&this.soundRelease.play(),C.activeObject=void 0,C.keyInputObject=void 0,this.onChange())}onKeyDown(t){let e=t.code,s=t.key;e==="Backspace"?this.text=this.text.slice(0,-1):e==="Enter"||e==="Escape"?this.stopEditing():s.length===1&&(!this.maxLength||this.text.lengththis.size.y,s=e?this.size.y:this.size.x,i=e?this.size.x:this.size.y,o=e?this.nativePos.x:this.nativePos.y,r=i-s,a=o-r/2,c=o+r/2,l=C.screenToNative(Ut);this.value=e?jt(l.x,a,c):jt(l.y,c,a)}else if(this.isNavigationObject()){let e=C.getNavigationOtherDirection();C.navigationTimer.active()||(this.value=F(this.value+e*.01))}this.value===t||this.onChange()}render(){super.render();let t=this.size.x>this.size.y,e=t?this.size.x:this.size.y,s=t?this.size.y:this.size.x;if(this.fillMode){let o=Q(s,this.cornerRadius*2),r=qt(o,e,this.value),a=(r-e)*(t?.5:-.5),c=this.nativePos.add(t?b(a,0):b(0,a)),l=this.disabled?this.disabledColor:this.handleColor,u=t?b(r,this.size.y):b(this.size.x,r);C.drawRect(c,u,l,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}else{let o=F(t?this.value:1-this.value),r=(e-s)*(o-.5),a=this.nativePos.add(t?b(r,0):b(0,r)),c=this.disabled?this.disabledColor:this.handleColor,l=b(s);C.drawRect(a,l,c,this.lineWidth,this.lineColor,this.cornerRadius,this.gradientColor)}let i=this.getTextSize();C.drawText(this.text,this.nativePos,i,this.textColor,this.textLineWidth,this.textLineColor,this.align,this.font,this.fontStyle,!0,this.textShadow)}navigatePressed(){this.value=this.value?0:1,this.onChange(),this.onRelease(),super.navigatePressed()}},jo=class extends ae{constructor(t,e,s,i=!1,o=!1,r=1){super(t,e||b()),p(U(s),"video src must be a string"),p(P(r),"video volume must be a number"),this.color=st,this.cornerRadius=0,this.volume=r,this.video=document.createElement("video"),this.video.loop=o,this.video.volume=F(r*wn),this.video.muted=!Xt,this.video.style.display="none",this.video.src=s,document.body.appendChild(this.video),i&&this.play()}async play(){try{await this.video.play()}catch{}}pause(){this.video.pause()}stop(){this.video.pause(),this.video.currentTime=0}isLoading(){return this.video.readyState=1,"ui layout columns must be a number >= 1"),p(P(s),"ui layout gap must be a number"),p(P(i),"ui layout padding must be a number"),this.columns=e,this.gap=s,this.padding=i,o&&(this.color=ye,this.gradientColor=void 0,this.lineWidth=0,this.shadowColor=ye),this.relayout()}addChild(t){return super.addChild(t),this.relayout(),t}removeChild(t){super.removeChild(t),this.relayout()}relayout(){let t=this.children.length;if(!t){this.size=b(this.padding*2);return}let e=this.columns,s=hs(t/e),i=new Array(e).fill(0),o=new Array(s).fill(0);for(let f=0;f=0&&m.objects.splice(t,1),super.destroy()}updatePhysics(){}render(){this.tileInfo?super.render():this.drawFixtures(this.color,this.lineColor,this.lineWidth)}renderDebugInfo(){let t=!this.getIsAwake(),e=this.getBodyType()===m.bodyTypeStatic,s=z(t?1:0,t?1:0,e?1:0,.5);this.drawFixtures(s)}drawFixtures(t=V,e=st,s=.1,i,o){this.getFixtureList().forEach(r=>{m.castShapeObject(r.GetShape()).GetType()!==m.instance.b2Shape.e_edge&&m.drawFixture(r,this.pos,this.angle,t,e,s,i,o)}),this.edgeLists.forEach(r=>mo(r,s,e,!1,this.pos,this.angle)),this.edgeLoops.forEach(r=>mo(r,s,e,!0,this.pos,this.angle))}beginContact(t){}endContact(t){}addShape(t,e=1,s=.2,i=0,o=!1){p(P(e),"density must be a number"),p(P(s),"friction must be a number"),p(P(i),"restitution must be a number");let r=new m.instance.b2FixtureDef;return r.set_shape(t),r.set_density(e),r.set_friction(s),r.set_restitution(i),r.set_isSensor(o),this.body.CreateFixture(r)}addBox(t=b(1),e=b(),s=0,i,o,r,a){p(O(t),"size must be a Vector2"),p(t.x>0&&t.y>0,"size must be positive"),p(O(e),"offset must be a Vector2"),p(P(s),"angle must be a number");let c=new m.instance.b2PolygonShape;return c.SetAsBox(t.x/2,t.y/2,m.vec2dTo(e),-s),this.addShape(c,i,o,r,a)}addPoly(t,e,s,i,o){p(pe(t),"points must be an array");function r(c){p(3<=c.length&&c.length<=8);let l=m.instance._malloc(c.length*8);for(let f=0,d=0;f>2]=c[f].x,d+=4,m.instance.HEAPF32[l+d>>2]=c[f].y,d+=4;let u=m.instance.wrapPointer(l,m.instance.b2Vec2),h=new m.instance.b2PolygonShape;return h.Set(u,c.length),m.instance._free(l),h}let a=r(t);return this.addShape(a,e,s,i,o)}addRegularPoly(t=1,e=8,s,i,o,r){p(P(t)&&t>0,"diameter must be a positive number"),p(P(e)&&e>2,"sides must be a positive number greater than 2");let a=[],c=t/2;for(let l=e;l--;)a.push(b(c,0).rotate((l+.5)/e*X*2));return this.addPoly(a,s,i,o,r)}addRandomPoly(t=1,e,s,i,o){p(P(t)&&t>0,"diameter must be a positive number");let r=or(3,9),a=[],c=t/2;for(let l=r;l--;)a.push(b(ft(c/2,c*1.5),0).rotate(l/r*X*2));return this.addPoly(a,e,s,i,o)}addCircle(t=1,e=b(),s,i,o,r){p(P(t)&&t>0,"diameter must be a positive number"),p(O(e),"offset must be a Vector2");let a=new m.instance.b2CircleShape;return a.set_m_p(m.vec2dTo(e)),a.set_m_radius(t/2),this.addShape(a,s,i,o,r)}addEdge(t,e,s,i,o,r){p(O(t),"point1 must be a Vector2"),p(O(e),"point2 must be a Vector2");let a=new m.instance.b2EdgeShape;return a.Set(m.vec2dTo(t),m.vec2dTo(e)),this.addShape(a,s,i,o,r)}addEdgeList(t,e,s,i,o){p(pe(t),"points must be an array");let r=[],a=[];for(let c=0;ct[ie(l,t.length)];for(let l=0;lthis.destroyFixture(t))}getCenterOfMass(){return m.vec2From(this.body.GetWorldCenter())}getLinearVelocity(){return m.vec2From(this.body.GetLinearVelocity())}getAngularVelocity(){return this.body.GetAngularVelocity()}getMass(){return this.body.GetMass()}getInertia(){return this.body.GetInertia()}getIsAwake(){return this.body.IsAwake()}getBodyType(){return this.body.GetType()}getSpeed(){return this.getLinearVelocity().length()}setTransform(t,e){this.pos=t,this.angle=e,this.body.SetTransform(m.vec2dTo(t),-e)}setPosition(t){this.setTransform(t,this.body.GetAngle())}setAngle(t){this.setTransform(m.vec2From(this.body.GetPosition()),t)}setLinearVelocity(t){this.body.SetLinearVelocity(m.vec2dTo(t))}setAngularVelocity(t){this.body.SetAngularVelocity(t)}setLinearDamping(t){this.body.SetLinearDamping(t)}setAngularDamping(t){this.body.SetAngularDamping(t)}setGravityScale(t=1){this.body.SetGravityScale(this.gravityScale=t)}setBullet(t=!0){this.body.SetBullet(t)}setAwake(t=!0){this.body.SetAwake(t)}setBodyType(t){this.body.SetType(t)}setSleepingAllowed(t=!0){this.body.SetSleepingAllowed(t)}setFixedRotation(t=!0){this.body.SetFixedRotation(t)}setCenterOfMass(t){this.setMassData(t)}setMass(t){this.setMassData(void 0,t)}setMomentOfInertia(t){this.setMassData(void 0,void 0,t)}resetMassData(){this.body.ResetMassData()}setMassData(t,e,s){let i=new m.instance.b2MassData;this.body.GetMassData(i),t!==void 0&&i.set_center(m.vec2dTo(t)),e!==void 0&&i.set_mass(e),s!==void 0&&i.set_I(s),this.body.SetMassData(i)}setFilterData(t=0,e=0,s=0){this.getFixtureList().forEach(i=>{let o=i.GetFilterData();o.set_categoryBits(t),o.set_maskBits(65535&~e),o.set_groupIndex(s)})}setSensor(t=!0){this.getFixtureList().forEach(e=>e.SetSensor(t))}applyForce(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyForce(m.vec2dTo(t),m.vec2dTo(e))}applyAcceleration(t,e){e||(e=this.getCenterOfMass()),this.setAwake();let s=t.scale(this.getMass());this.body.ApplyLinearImpulse(m.vec2dTo(s),m.vec2dTo(e))}applyImpulse(t,e){e||(e=this.getCenterOfMass()),this.setAwake(),this.body.ApplyLinearImpulse(m.vec2dTo(t),m.vec2dTo(e))}applyTorque(t){this.setAwake(),this.body.ApplyTorque(t)}applyAngularAcceleration(t){this.setAwake(),this.body.ApplyAngularImpulse(t*this.getInertia())}applyAngularImpulse(t){this.setAwake(),this.body.ApplyAngularImpulse(t)}hasFixtures(){return!m.isNull(this.body.GetFixtureList())}getFixtureList(){let t=[];for(let e=this.body.GetFixtureList();!m.isNull(e);)t.push(e),e=e.GetNext();return t}hasJoints(){return!m.isNull(this.body.GetJointList())}getJointList(){let t=[];for(let e=this.body.GetJointList();!m.isNull(e);)t.push(e),e=e.get_next();return t}},Si=class extends Rs{constructor(t,e,s,i=0,o,r=0){let a=m.bodyTypeStatic;super(t,e,s,i,o,a,r)}},Bo=class extends Rs{constructor(t,e,s,i=0,o,r=0){let a=m.bodyTypeKinematic;super(t,e,s,i,o,a,r)}},zo=class extends Si{constructor(t){p(t instanceof Ss,"tileLayer must be a TileCollisionLayer"),super(t.pos,t.size),this.tileLayer=t,this.addChild(t)}render(){}buildCollision(t=.2,e=0){this.destroyAllFixtures(),this.pos=this.tileLayer.pos.copy(),this.size=this.tileLayer.size.copy();let s=[],i=(r,a)=>r+a*this.size.x,o=(r,a)=>!s[i(r,a)]&&this.tileLayer.getCollisionData(b(r,a))>0;for(let r=0;ri.fractiono.pos.distanceSquared(t)0,"Tween duration must be > 0"),this.callback=t,this.start=e,this.end=s,this.duration=i,this.life=i,this.ease=o.ease||Ei.LINEAR,this.useRealTime=!!o.useRealTime,this.paused=!!o.paused,this.thenCallback=void 0,this.loopRemaining=0,Kt.push(this),t(this.interp(i))}setEase(t){return this.ease=t,this}then(t){return this.thenCallback=t,this.loopRemaining=0,this}loop(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Lc(this),this}pingPong(t=1/0){return this.loopRemaining=t,this.thenCallback=()=>Oc(this),this}pause(){this.paused=!0}resume(){this.paused=!1}restart(){this.life=this.duration,this.paused=!1,Kt.indexOf(this)<0&&Kt.push(this),this.callback(this.interp(this.duration))}isActive(){return!this.paused&&Kt.indexOf(this)>=0}getPercent(){return jt(this.duration-this.life,0,this.duration)}getValue(){return this.interp(this.life)}interp(t){let e=this.ease((this.duration-t)/this.duration);return La(this.start)?this.start.lerp(this.end,e):this.start+(this.end-this.start)*e}stop(){let t=Kt.indexOf(this);t>=0&&Kt.splice(t,1),this.thenCallback=void 0}},Ei={LINEAR:n=>n,POWER:n=>t=>t**n,SINE:n=>1-ct(n*(X/2)),CIRC:n=>1-(1-n*n)**.5,EXPO:n=>n===0?0:2**(10*n-10),BACK:n=>n*n*(2.70158*n-1.70158),ELASTIC:n=>n===0?0:n===1?1:-(2**(10*n-10))*nt((37-40*n)*X/6),SPRING:n=>1-(nt(X*(1-n)*(.2+2.5*(1-n)**3))*n**2.2+(1-n))*(1+1.2*n),BOUNCE:n=>{let t=1-n,e;return t<4/11?e=7.5625*t*t:t<8/11?e=7.5625*(t-=6/11)*t+.75:t<10/11?e=7.5625*(t-=9/11)*t+.9375:e=7.5625*(t-=10.5/11)*t+.984375,1-e},IN:n=>n,OUT:n=>t=>1-n(1-t),IN_OUT:n=>Ei.PIECEWISE(n,Ei.OUT(n)),PIECEWISE:(...n)=>{let t=n.length;return e=>{let s=e*t-1e-9>>0;return(n[s]((e-s/t)*t)+s)/t}},BEZIER:(n,t,e,s)=>{let i=o=>{let r=1-o,a=3*r*r*o,c=3*r*o*o,l=o**3;return[a*n+c*e+l,a*t+c*s+l]};return o=>{let r=0,a=1;for(let c=0;c<128;c++){let l=(r+a)/2,[u,h]=i(l);if(et(u-o)<1e-5)return h;u=this.size.x||e>=this.size.y?null:this.nodes[t+e*this.size.x]}worldToTile(t){let e=this.tileLayer?this.tileLayer.pos.x:0,s=this.tileLayer?this.tileLayer.pos.y:0;return b(St(t.x-e),St(t.y-s))}tileToWorld(t,e){let s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;return b(t+.5+s,e+.5+i)}buildNodeData(){let t=this.size.x,e=this.size.y,s=this.tileLayer?this.tileLayer.pos.x:0,i=this.tileLayer?this.tileLayer.pos.y:0;for(let o=0;o0&&(c?l>0&&bt(a.posWorld,lo,z(1,0,0,Q(.2,l*.05)),this.debugTime):bt(a.posWorld,lo,z(1,0,0,.25),this.debugTime))}}aStarSearch(t,e){p(t&&e,"aStarSearch needs both endpoints"),p(t!==e,"aStarSearch: start and end must differ \u2014 caller should handle trivial case"),p(t.walkable&&e.walkable,"aStarSearch: endpoints must be walkable");let s=[t];t.isOpen=!0;let i=0;for(;s.length>0;){let o=0,r=s[0].f;for(let c=1;cthis.maxLoop)break;a.isOpen=!1,s.splice(o,1),a.isClosed=!0,this.debug&&this.debugTime>0&&bt(a.posWorld,lo,z(1,1,1,.05),this.debugTime);for(let c=-1;c<=1;++c)for(let l=-1;l<=1;++l){if(l===0&&c===0)continue;let u=this.getNode(a.pos.x+l,a.pos.y+c);if(!u||!u.walkable||u.isClosed)continue;let h=1;if(l!==0&&c!==0){let v=this.getNode(a.pos.x+l,a.pos.y);if(!v||!v.walkable)continue;let w=this.getNode(a.pos.x,a.pos.y+c);if(!w||!w.walkable)continue;h=fd}let f=a.g+h+u.cost;if(!u.isOpen)u.isOpen=!0,s.push(u);else if(f>=u.g)continue;u.parent=a,u.g=f;let d=et(e.pos.x-u.pos.x),y=et(e.pos.y-u.pos.y),x=$(d,y)+(Math.SQRT2-1)*Q(d,y);u.f=u.g+x*this.heuristicWeight}}return e.parent!==null}getNearestClearNode(t,e=10,s=!0){p(O(t),"worldPos must be a Vector2"),s&&this.buildNodeData();let i=this.tileLayer?this.tileLayer.pos.x:0,o=this.tileLayer?this.tileLayer.pos.y:0,r=St(t.x-i),a=St(t.y-o);for(let c=0;c<=e;++c){let l=null,u=0;for(let h=-c;h<=c;++h)for(let f=-c;f<=c;++f){if(c>0&&et(f)!==c&&et(h)!==c)continue;let d=this.getNode(r+f,a+h);if(!d||!d.isClear())continue;let y=d.posWorld.x-t.x,x=d.posWorld.y-t.y,v=y*y+x*x;(!l||v0&&Vt(i.posWorld,.3,z(.5,0,.5,.5),this.debugTime),t.splice(e,1),e=$(1,e-1);continue}else if(c===2){this.debug&&this.debugTime>0&&Vt(i.posWorld,.3,z(1,0,0,.5),this.debugTime);let d,y;s.pos.y===i.pos.y&&o.pos.x===i.pos.x?(d=s.pos.x,y=o.pos.y):(d=o.pos.x,y=s.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t.splice(e,1),e=$(1,e-1);continue}}else if(c===5){this.debug&&this.debugTime>0&&Vt(i.posWorld,.3,z(1,1,0,.5),this.debugTime);let d=e>=2?t[e-2]:s,y,x,v,w;l===0||h===0?(y=o.pos.x,x=i.pos.y,v=s.pos.x,w=i.pos.y):(y=i.pos.x,x=o.pos.y,v=i.pos.x,w=s.pos.y);let _=y-d.pos.x,S=x-d.pos.y,E=v-d.pos.x,A=w-d.pos.y,T=_*_+S*S,R=E*E+A*A,M=T0&&Vt(i.posWorld,.3,z(0,1,0,.5),this.debugTime),l===h&&u===f){++e;continue}else{let d,y;s.pos.y===o.pos.y?(d=i.pos.x,y=s.pos.y):(d=s.pos.x,y=i.pos.y);let x=this.getNode(d,y);if(x&&x.isClear()){t[e]=x,e=$(1,e-1);continue}}++e}}smoothPathStringPull(t){if(t.length<=2)return;for(let i of t)if(!i.isClear())return;let e=t.slice();t.length=0,t.push(e[0]);let s=0;for(let i=1;i0&&Te(o.posWorld,t[t.length-1].posWorld,z(0,0,1,.3),.02,this.debugTime);continue}for(;s=1;--e){let s=t[e-1],i=t[e],o=t[e+1];(i.pos.x-s.pos.x)*(o.pos.y-s.pos.y)===(i.pos.y-s.pos.y)*(o.pos.x-s.pos.x)&&t.splice(e,1)}}isNodeClear(t,e){let s=this.getNode(t,e);return s!==null&&s.isClear()}isLineClear(t,e){p(O(t)&&O(e),"isLineClear needs Vector2 endpoints"),p(this.isNodeClear(t.x,t.y)&&this.isNodeClear(e.x,e.y),"isLineClear endpoints must be in-bounds and clear");let s=e.x-t.x,i=e.y-t.y,o=et(s),r=et(i),a=se(s),c=se(i),l=t.x,u=t.y;if(r===o){for(;l!==e.x;){if(l!==t.x&&(!this.isNodeClear(l,u)||!this.isNodeClear(l,u-c))||!this.isNodeClear(l,u+c))return!1;l+=a,u+=c}if(!this.isNodeClear(e.x,e.y-c))return!1}else if(ra.posWorld.copy());if(this.debug&&this.debugTime>0&&r.length>0){for(let a=1;apd,bootGameHost:()=>yd,default:()=>gd});var js=class{constructor(t){this._state=(t==null?2654435769:t)>>>0}next(){this._state=this._state+1831565813>>>0;let t=this._state;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}range(t,e){return t+this.next()*(e-t)}reseed(t){this._state=(t==null?2654435769:t)>>>0}},Ji=class{constructor(t){this._clock=t||Jc(),this._origin=this._clock()}nowMs(){return this._clock()}elapsedMs(){return this._clock()-this._origin}},Ui=class{constructor(t){this._time=t,this._subs=new Map}sourceFor(t){let e=this,s=t==null?null:t;return{on(i,o){if(e._assertType(i),typeof o!="function")throw new Error("[HostDevInputBridge] on \u7684 handler \u5FC5\u987B\u662F\u51FD\u6570");let r=e._subs.get(i)||[],a={handler:o,scope:s};return r.push(a),e._subs.set(i,r),{cancel(){let c=e._subs.get(i);if(!c)return;let l=c.indexOf(a);l>=0&&c.splice(l,1)}}},off(i,o){e._assertType(i);let r=e._subs.get(i);if(!r)return;let a=r.findIndex(c=>c.handler===o&&c.scope===s);a>=0&&r.splice(a,1)}}}_emit(t,e){this._assertType(t);let s=e||{},i={type:t,x:typeof s.x=="number"?s.x:0,y:typeof s.y=="number"?s.y:0,key:typeof s.key=="string"?s.key:"",tMs:this._time.nowMs()},o=this._subs.get(t);if(!o||o.length===0)return;let r=o.slice();for(let a of r)try{a.handler(i)}catch(c){Xe("[host-dev input] \u8F93\u5165 handler \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09type="+t,c)}}disposeScope(t){if(t==null)return 0;let e=0;for(let[s,i]of this._subs){let o=i.filter(r=>r.scope!==t);e+=i.length-o.length,o.length===0?this._subs.delete(s):this._subs.set(s,o)}return e}_subscriptionCount(){let t=0;for(let e of this._subs.values())t+=e.length;return t}_assertType(t){if(!Vi.has(t))throw new Error("[HostDevInputBridge] \u975E\u6CD5\u8F93\u5165\u4E8B\u4EF6\u7C7B\u578B\uFF1A"+String(t)+"\uFF08\u4EC5\u652F\u6301 "+Array.from(Vi).join("/")+"\uFF09")}},Vi=new Set(["pointerdown","pointermove","pointerup","keydown","keyup"]);function Xr(n){let t=n||{},e=new Ji(t.clock),s=new js(t.seed),i=t.seed==null?2654435769:t.seed>>>0,o=new Ui(e),r=typeof t.audioFactory=="function"?t.audioFactory:null,a=null,c=!1,l=typeof t.engineFactory=="function"?t.engineFactory:null,u=null,h=!1,f=new Map,d=0,y=0;function x(){if(a)return a;if(!r)return c||(qi("[host-dev audio] \u672A\u6CE8\u5165 audioFactory\uFF0CgetAudioContext \u8FD4\u56DE null\uFF08P6 \u987B\u5BB9\u9519\u964D\u7EA7\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u5DE5\u5382\uFF09"),c=!0),null;try{a=r()}catch(E){Xe("[host-dev audio] audioFactory \u629B\u9519\uFF0CgetAudioContext \u964D\u7EA7\u8FD4\u56DE null",E),a=null}return a}function v(){if(u)return u;if(!l)return h||(qi("[host-dev engine] \u672A\u6CE8\u5165 engineFactory\uFF0CgetEngine \u8FD4\u56DE null\uFF08\u63D2\u4EF6\u987B\u5BB9\u9519\u964D\u7EA7\uFF1A\u7C92\u5B50\u9000\u53D7\u63A7\u9762\u81EA\u7BA1/\u5408\u6210\u6838\u9000 vendored/\u6570\u5B66\u9000\u5185\u7F6E\uFF1B\u96C6\u6210\u6BB5\u6CE8\u5165\u771F\u5B9E\u80CC\u4E66\uFF09"),h=!0),null;try{u=l()}catch(E){Xe("[host-dev engine] engineFactory \u629B\u9519\uFF0CgetEngine \u964D\u7EA7\u8FD4\u56DE null",E),u=null}return u}function w(E,A){return{getContext2d(){return t.context2d==null?null:t.context2d},onFrame(R){let M=d++;return f.set(M,R),{cancel(){f.delete(M)}}},getInput(){return o.sourceFor(E)},getAudioContext(){return x()},getEngine(){return v()},time:e,random:A}}let _=w(null,s),S={context:_,tick(E){y+=1;let A=Array.from(f.values());for(let T of A)try{T(E,y)}catch(R){Xe("[host-dev tick] \u5E27\u56DE\u8C03\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09frame="+y,R)}},frameCount(){return y},inputBridge:o,deriveContextFor(E,A){let T=zc(i,E),R=new js(T);return w(A==null?E:A,R)}};return Object.defineProperty(_,Wi,{value:S,enumerable:!1,writable:!1,configurable:!1}),S}var Wi=Symbol("zaomeng.coreProtocol.contextBundle"),Ns=class{constructor(){this._plugins=new Map,this._initOrder=[],this._initErrors=[],this._phase="idle",this._disposed=!1,this._context=void 0,this._pluginContexts=new Map}register(t){if(!t||typeof t!="object")throw new Error("[PluginRegistry] register \u9700\u8981\u4E00\u4E2A\u63D2\u4EF6\u5BF9\u8C61");if(typeof t.name!="string"||t.name.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6\u7F3A\u5C11\u5408\u6CD5 name");if(typeof t.version!="string"||t.version.length===0)throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11\u5408\u6CD5 version");if(typeof t.init!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7F3A\u5C11 init \u51FD\u6570");if(t.dispose!=null&&typeof t.dispose!="function")throw new Error("[PluginRegistry] \u63D2\u4EF6 "+t.name+" \u7684 dispose \u5FC5\u987B\u662F\u51FD\u6570\u6216\u7701\u7565");if(this._plugins.has(t.name))throw new Error("[PluginRegistry] \u63D2\u4EF6\u91CD\u540D\u62D2\u7EDD\uFF1A"+t.name+" \u5DF2\u6CE8\u518C");return this._plugins.set(t.name,t),this}has(t){return this._plugins.has(t)}get(t){return this._plugins.get(t)}list(){return Array.from(this._plugins.keys())}initAll(){if(this._phase==="initialized")return qi("[PluginRegistry] initAll \u91CD\u590D\u8C03\u7528\uFF0C\u5DF2\u5FFD\u7565\uFF08\u5DF2\u5904\u4E8E initialized\uFF09"),this._initResult();if(this._phase==="disposed")throw new Error("[PluginRegistry] \u5DF2 dispose \u7684\u6CE8\u518C\u5668\u4E0D\u53EF\u518D initAll");if(this._context==null)throw new Error("[PluginRegistry] \u672A\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\uFF1A\u8BF7\u5728 initAll() \u4E4B\u524D\u8C03\u7528 useContext(context)\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context); reg.initAll();\uFF09");for(let[t,e]of this._plugins){let s=this._missingDeps(e);if(s.length>0){let o=new Error("[PluginRegistry] \u63D2\u4EF6 "+t+" \u4F9D\u8D56\u7F3A\u5931\uFF1A"+s.join(", ")+"\uFF08\u672A\u6CE8\u518C\uFF09");this._initErrors.push({name:t,error:o}),Xe("[PluginRegistry] \u8DF3\u8FC7 init\uFF08\u4F9D\u8D56\u7F3A\u5931\uFF0C\u5DF2\u9694\u79BB\uFF09\uFF1A"+t,o);continue}let i=this._contextFor(t);try{e.init(i),this._initOrder.push(t)}catch(o){let r=o instanceof Error?o:new Error(String(o));this._initErrors.push({name:t,error:r}),Xe("[PluginRegistry] \u63D2\u4EF6 init \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF0C\u4E0D\u8FDE\u5750\uFF09\uFF1A"+t,r)}}return this._phase="initialized",this._initResult()}_contextFor(t){let e=this._pluginContexts.get(t);if(e)return e;let s=this._context&&this._context[Wi],i;return s&&typeof s.deriveContextFor=="function"?i=s.deriveContextFor(t,t):i=this._context,this._pluginContexts.set(t,i),i}disposeAll(){if(this._disposed)return{disposed:[],errors:[]};let t=[],e=[],s=this._context&&this._context[Wi],i=s&&s.inputBridge;for(let o=this._initOrder.length-1;o>=0;o--){let r=this._initOrder[o],a=this._plugins.get(r);if(a&&typeof a.dispose=="function")try{a.dispose(),t.push(r)}catch(c){let l=c instanceof Error?c:new Error(String(c));e.push({name:r,error:l}),Xe("[PluginRegistry] \u63D2\u4EF6 dispose \u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+r,l)}if(i&&typeof i.disposeScope=="function")try{i.disposeScope(r)}catch(c){Xe("[PluginRegistry] \u56DE\u6536\u63D2\u4EF6\u8F93\u5165\u8BA2\u9605\u629B\u9519\uFF08\u5DF2\u9694\u79BB\uFF09\uFF1A"+r,c)}}return this._disposed=!0,this._phase="disposed",{disposed:t,errors:e}}useContext(t){if(this._phase!=="idle")throw new Error("[PluginRegistry] useContext \u5FC5\u987B\u5728 initAll() \u4E4B\u524D\u8C03\u7528\uFF08\u5F53\u524D\u9636\u6BB5\uFF1A"+this._phase+"\uFF09\u3002\u8BF7\u5728\u4EFB\u4F55 initAll/disposeAll \u4E4B\u524D\u6CE8\u5165\u53D7\u63A7\u4E0A\u4E0B\u6587\u3002");if(t==null||typeof t!="object")throw new Error("[PluginRegistry] useContext \u9700\u8981\u4E00\u4E2A\u53D7\u63A7\u4E0A\u4E0B\u6587\u5BF9\u8C61\u3002\uFF08host-dev \u7528\u6CD5\uFF1Aconst { context } = createHostDevContext(); reg.useContext(context);\uFF09");return this._context=t,this}_missingDeps(t){return!Array.isArray(t.dependencies)||t.dependencies.length===0?[]:t.dependencies.filter(e=>!this._plugins.has(e))}_initResult(){return{ok:this._initErrors.length===0,initialized:this._initOrder.slice(),errors:this._initErrors.slice()}}};function zc(n,t){let e=2166136261,s=16777619,i=n>>>0;for(let r=0;r<32;r+=8){let a=i>>>r&255;e^=a,e=Math.imul(e,s)>>>0}let o=String(t);for(let r=0;r>>0,e^=a>>>8&255,e=Math.imul(e,s)>>>0}return e>>>0}function Jc(){if(typeof globalThis!="undefined"&&globalThis.performance&&typeof globalThis.performance.now=="function")return()=>globalThis.performance.now();if(typeof process!="undefined"&&process.hrtime&&typeof process.hrtime.bigint=="function"){let n=process.hrtime.bigint();return()=>Number(process.hrtime.bigint()-n)/1e6}return()=>Date.now()}function Xe(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function qi(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var xd=Object.freeze(Array.from(Vi)),Yr="core-protocol-v0";var $r=Object.freeze(["t_boot","t_plugins_ready","t_game_init","t_first_paint","t_input_bound","t_game_start"]),Hi=$r.reduce((n,t,e)=>(n[t]=e,n),Object.create(null)),Uc=new Set($r);function Xi(n){let t=2166136261;for(let e=0;e>>0).toString(16).padStart(8,"0")}var Kr=Xi("runtime-probe::seed::v1");function Bs(n){return n===null||typeof n!="object"?JSON.stringify(n):Array.isArray(n)?"["+n.map(Bs).join(",")+"]":"{"+Object.keys(n).sort().map(e=>JSON.stringify(e)+":"+Bs(n[e])).join(",")+"}"}function Qr(n){let t=Bs(n.extra==null?null:n.extra),e=Bs(Array.isArray(n.pluginSet)?n.pluginSet:[]);return["seq="+n.seq,"anchor="+n.anchor,"tMono="+n.tMono,"buildSha="+(n.buildSha||""),"pluginSet="+e,"extra="+t].join("|")}function Vc(n){return Math.round(n*1e3)/1e3}function Wc(n){if(!Array.isArray(n))return{ok:!1,reason:"records_not_array"};let t=Kr,e=-1;for(let s=0;stypeof E=="string").slice().sort():[],i=typeof t.sink=="function"?t.sink:null,o=t.autoBoot!==!1,r=typeof t.inputAnchorType=="string"?t.inputAnchorType:"pointerdown",a=()=>0,c=!1,l=0,u=Kr,h=[],f=new Set,d=-1,y=null,x=!1,v=!1,w=!1;function _(E,A){let T=null;if(!Uc.has(E))T="unknown_anchor";else{f.has(E)&&(T=T?T+";duplicate_anchor":"duplicate_anchor");let M=Hi[E];ME.time.nowMs(),c=!0,o&&!v&&_("t_boot",{auto:!0}),y=E.getInput().on(r,A=>{x||(x=!0,_("t_input_bound",{firstInput:!0,type:A.type}))}),_("t_input_bound",{stage:"registered",type:r})},dispose(){w||(y&&(y.cancel(),y=null),w=!0)},mark:_,getRecords(){return h.map(E=>({...E}))},toJSONL(){return h.map(E=>JSON.stringify(E)).join(`
+`)},verify(){return Wc(h)}}}function qc(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function ta(n){let t=n.LJS,e=n.engineMath,s=n.engineMode,i=n.recHook||(()=>{});if(s!=="real")return null;let o=e;return{math:{lerp:(a,c,l)=>(i("math.lerp"),o.lerp(a,c,l)),smoothStep:a=>(i("math.smoothStep"),o.smoothStep(a)),easing:Object.fromEntries(Object.keys(o.easing).map(a=>[a,c=>(i("math.easing."+a),o.easing[a](c))]))},particles:{spawnEmitter(a){i("particles.spawnEmitter");let c=t.screenToWorld(t.vec2(a.pos.x,a.pos.y)),l=t.cameraScale,u=a.emitTime!=null?a.emitTime:a.count!=null?1/60:0,h=a.emitRate!=null?a.emitRate:a.count!=null?a.count*60:100,f=(a.speed!=null?a.speed:0)/l/60,d=a.damping!=null?a.damping:1,y=a.colorStart||{r:1,g:1,b:1,a:1},x=a.colorEnd||{r:1,g:1,b:1,a:0},v=t.rgb(y.r,y.g,y.b,y.a),w=t.rgb(x.r,x.g,x.b,x.a),_=new t.ParticleEmitter(c,a.angle!=null?a.angle:0,(a.emitSize!=null?a.emitSize:0)/l,u,h,a.coneAngle!=null?a.coneAngle:Math.PI,void 0,v,v,w,w,a.particleTime!=null?a.particleTime:.5,(a.sizeStart!=null?a.sizeStart:6)/l,(a.sizeEnd!=null?a.sizeEnd:0)/l,f,0,d,1,a.gravityScale!=null?a.gravityScale:0,Math.PI,.1,0,!1,a.additive!=null?a.additive:!1,!0);return{isActive(){return _.isActive()},stop(){_.destroyed||_.destroy(!0)}}}},audio:{synth:{synthSfx:a=>{i("audio.synth.synthSfx");try{return t.zzfxG(...a)}catch(c){return console.error("[host][engine-audio] zzfxG \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(c&&c.message?c.message:c)),null}},synthSong:(a,c,l,u)=>{i("audio.synth.synthSong");try{return t.zzfxM(a,c,l,u)}catch(h){return console.error("[host][engine-audio] zzfxM \u5408\u6210\u5F02\u5E38\uFF0C\u8FD4 null\uFF1A"+(h&&h.message?h.message:h)),null}}}}}}function ue(n){return n<0?0:n>1?1:n}function ea(n){let t=n.Ease,e=t.POWER(2),s=t.POWER(3),i=t.OUT(e),o=t.IN_OUT(e),r=t.OUT(s),a=t.IN_OUT(s),c=t.OUT(t.BACK),l=t.OUT(t.ELASTIC);return{lerp:(u,h,f)=>n.lerp(u,h,f),smoothStep:u=>n.smoothStep(u),easing:{linear:u=>t.LINEAR(ue(u)),quadIn:u=>e(ue(u)),quadOut:u=>i(ue(u)),quadInOut:u=>o(ue(u)),cubicIn:u=>s(ue(u)),cubicOut:u=>r(ue(u)),cubicInOut:u=>a(ue(u)),backIn:u=>t.BACK(ue(u)),backOut:u=>c(ue(u)),elasticIn:u=>t.ELASTIC(ue(u)),elasticOut:u=>l(ue(u))}}}var Ye=2,zs=1/60;async function na(n){let t=n.canvas,e=n.statusEl||null,s=n.engine,i=n.seed>>>0,o=n.mode||"play",r=n.engineMode||"real",a=n.viewport.w,c=n.viewport.h,l=n.factory,u=n.buildFactoryOpts||(()=>{}),h=n.plugins||{},f=n.registerOrder||Object.values(h),d=n.onReady||(()=>{}),y=n.recHook||(()=>{});function x(D){e&&(e.textContent=D)}let v=[];window.addEventListener("error",D=>v.push({type:"error",message:String(D&&D.message||D)})),window.addEventListener("unhandledrejection",D=>v.push({type:"unhandledrejection",message:String(D&&D.reason&&D.reason.message||D&&D.reason||D)}));let w=null,_=!1;function S(){if(!_)return null;if(w)return w;let D=window.AudioContext||window.webkitAudioContext;return D?(w=new D,w):null}let E=0,A=null,T=null,R=null,M=null,Z=[],it={},ht=null;function gt(D,ot){try{R&&R.mark(D,ot)}catch(ne){v.push({type:"mark",message:String(ne&&ne.message||ne)})}}function Nt(){T&&typeof T._refreshChecklist=="function"&&T._refreshChecklist(it)}async function He(D,ot){A=Xr({context2d:D,seed:i,audioFactory:S,clock:()=>E,engineFactory:()=>ta({LJS:r==="real"?s:null,engineMath:r==="real"?ea(s):null,engineMode:r,recHook:y})});let ne=new Ns;for(let me of f)ne.register(me);ne.useContext(A.context),M=ne.initAll(),Z=ne.list().concat(["runtime-probe"]),R=Zr({pluginSet:Z,inputAnchorType:"pointerdown",autoBoot:!0});let Rt=A.deriveContextFor("runtime-probe","runtime-probe");gt("t_boot",{by:"game-host",stage:"pre-init",engineMode:r}),gt("t_plugins_ready",{initialized:M.initialized.length,ok:M.ok});let Bi=u(A.context,{bundle:A,plugins:h,getRealAudioCtx:()=>w});T=l(Bi),await T.init({ctx:A.context,mainContext:D,canvas:ot(),seed:i}),ht=T&&typeof T._forensicsView=="function"?T._forensicsView():null,gt("t_game_init",{hasForensics:!!ht}),dt(),gt("t_first_paint",{frame:A.frameCount()});try{R.init(Rt)}catch(me){v.push({type:"probe-init",message:String(me&&me.message||me)})}gt("t_game_start",{mode:o,engineMode:r}),Nt(),d(dn,{bundle:A,game:T,probe:R,checklist:it,uncaught:v,pluginSet:Z,initRes:M,getGameForensics:()=>ht,mark:gt,stepOneFrame:dt})}let Ot=null;function dt(D){let ot=typeof D=="number"?D:zs;T&&(E+=ot*1e3,T.update(ot),r==="stub"&&Ot&&T.render(Ot),Nt())}function Dt(D){for(let ot=0;ot{}),T&&typeof T._onAudioUnlock=="function"&&T._onAudioUnlock()}let dn={seed:i,mode:o,engineMode:r,protocol:Yr,frameCount:()=>A?A.frameCount():0,stepFrames:Dt,startRaf:()=>B(),stopRaf:()=>j(),tap(D,ot){Le(),A&&(A.inputBridge._emit("pointerdown",{x:D,y:ot}),A.inputBridge._emit("pointerup",{x:D,y:ot}))},do(D){T&&typeof T._handleAction=="function"&&T._handleAction(D)},state:()=>ht?ht.state():{phase:"booting"}};function fn(D){let ot=A.inputBridge;function ne(Rt,Bi){let me=D.getBoundingClientRect();return{x:(Rt-me.left)/me.width*a,y:(Bi-me.top)/me.height*c}}D.addEventListener("pointerdown",Rt=>{Le(),ot._emit("pointerdown",ne(Rt.clientX,Rt.clientY))}),D.addEventListener("pointermove",Rt=>{ot._emit("pointermove",ne(Rt.clientX,Rt.clientY))}),D.addEventListener("pointerup",Rt=>{ot._emit("pointerup",ne(Rt.clientX,Rt.clientY))}),window.addEventListener("keydown",Rt=>{Le(),ot._emit("keydown",{key:Rt.key})}),window.addEventListener("keyup",Rt=>ot._emit("keyup",{key:Rt.key}))}let ce=0,Oe=!1,ee=0;function L(D){if(!Oe)return;ee===0&&(ee=D);let ot=(D-ee)/1e3;ee=D,ot>.05&&(ot=.05),dt(ot),ce=window.requestAnimationFrame(L)}function B(){r==="stub"&&(Oe||(Oe=!0,ee=0,ce=window.requestAnimationFrame(L)))}function j(){Oe=!1,ce&&window.cancelAnimationFrame(ce),ce=0}function H(D){D.width=a*Ye,D.height=c*Ye,D.style.width=a+"px",D.style.height=c+"px";let ot=D.getContext("2d",{willReadFrequently:!0});return ot.setTransform(Ye,0,0,Ye,0,0),ot}async function Bt(){let D=H(t);return Ot=D,await He(D,()=>t),fn(t),o==="evidence"?x(`evidence \u5C31\u7EEA seed=${i} \xB7 \u7528 host \u9A71\u52A8\uFF08stepFrames/tap\uFF09`):(x(`seed=${i} \xB7 \u70B9\u5F00\u59CB\uFF08\u9996\u6B21\u70B9\u51FB\u5F00\u58F0\uFF09`),B()),dn}let lt=()=>{},le=()=>{};function It(){window.__gameHostEngineInitFired=!0}function zt(){lt()}function at(){}function _t(){le()}function De(){}async function In(D){await He(D,()=>s.mainCanvas),fn(s.mainCanvas),lt=()=>{T&&(E+=zs*1e3,T.update(zs))},le=()=>{if(T){D.save(),D.setTransform(Ye,0,0,Ye,0,0);try{D.imageSmoothingEnabled=!1}catch{}T.render(D),D.restore()}},s.mainCanvas&&(s.mainCanvas.id="game-engine"),window.__engine={frame(){return s.frame},time(){return s.time},timeReal(){return s.timeReal},paused(){return s.paused},timeScale(){return s.timeScale},snapshot(){return{frame:s.frame,time:s.time,timeReal:s.timeReal,paused:s.paused,timeScale:s.timeScale}}},x(`engine RAF running \xB7 seed=${i} engine=real`)}if(r!=="real")return await Bt();if(!s){let D="real \u901A\u9053\u672A\u6CE8\u5165\u5F15\u64CE\uFF08opts.engine \u7F3A\u5931\uFF09\uFF1A\u8BF7\u7ECF entry \u5305\u88C5\u5C42\u542F\u52A8\uFF08host \u4E0D\u76F4\u63A5 import \u5F15\u64CE\uFF0CQ4/Option C\uFF09";throw x("ENGINE INJECT MISSING: "+D),new Error(D)}s.setGLEnable(!1),s.setShowSplashScreen(!1),s.setDebugWatermark(!1),s.setCanvasClearColor(s.BLACK),s.setCanvasFixedSize(s.vec2(a*Ye,c*Ye));let ts=document.createElement("div");return ts.id="engine-root",document.body.appendChild(ts),await s.engineInit(It,zt,at,_t,De,[],ts).then(()=>In(s.mainContext)).catch(D=>{throw window.__gameHostBootError=String(D&&D.message||D),x("ENGINE INIT FAILED: "+window.__gameHostBootError),D}),dn}var Yi=class{constructor(t){let e=t||{},s=typeof e.cellSize=="number"&&e.cellSize>0?e.cellSize:64;this._cellSize=s,this._cells=new Map,this._entries=new Map,this._seq=0}get size(){return this._entries.size}_cellRange(t){let e=this._cellSize,s=Math.floor((t.x-t.hw)/e),i=Math.floor((t.x+t.hw)/e),o=Math.floor((t.y-t.hh)/e),r=Math.floor((t.y+t.hh)/e);return{cx0:s,cy0:o,cx1:i,cy1:r}}insert(t,e){this._entries.has(t)&&this.remove(t);let{cx0:s,cy0:i,cx1:o,cy1:r}=this._cellRange(e),a=[];for(let l=i;l<=r;l++)for(let u=s;u<=o;u++){let h=u+","+l,f=this._cells.get(h);f||(f=new Set,this._cells.set(h,f)),f.add(t),a.push(h)}let c={x:e.x,y:e.y,hw:e.hw,hh:e.hh};this._entries.set(t,{id:t,box:c,seq:this._seq++,cells:a})}remove(t){let e=this._entries.get(t);if(!e)return!1;for(let s of e.cells){let i=this._cells.get(s);i&&(i.delete(t),i.size===0&&this._cells.delete(s))}return this._entries.delete(t),!0}query(t){let{cx0:e,cy0:s,cx1:i,cy1:o}=this._cellRange(t),r=new Set;for(let a=s;a<=o;a++)for(let c=e;c<=i;c++){let l=this._cells.get(c+","+a);if(l)for(let u of l)r.add(u)}return this._collect(r)}queryPoint(t,e){let s=this._cellSize,i=Math.floor(t/s),o=Math.floor(e/s),r=this._cells.get(i+","+o);return r?this._collect(new Set(r)):[]}clear(){this._cells.clear(),this._entries.clear(),this._seq=0}_collect(t){let e=[];for(let s of t){let i=this._entries.get(s);i&&e.push(i)}return e.sort((s,i)=>s.seq-i.seq),e.map(s=>({id:s.id,box:s.box}))}};function sa(n){let t=n||{},e=new Yi({cellSize:t.cellSize}),s=!1;return{name:"collision",version:"1.0.0",dependencies:[],spatial:e,init(o){},dispose(){s||(e.clear(),s=!0)}}}function ia(n){let t=!1;return{name:"physics-lite",version:"1.0.0",dependencies:[],init(s){},dispose(){t||(t=!0)}}}var Hc=["pointerdown","pointermove","pointerup","keydown","keyup"];function Jt(n){return n<0?0:n>1?1:n}var Xc=n=>(n=Jt(n),n*n),Yc=n=>(n=Jt(n),1-(1-n)*(1-n)),$c=n=>(n=Jt(n),n<.5?2*n*n:1-Math.pow(-2*n+2,2)/2),Kc=n=>(n=Jt(n),n*n*n),Qc=n=>{n=Jt(n);let t=1-n;return 1-t*t*t},Zc=n=>(n=Jt(n),n<.5?4*n*n*n:1-Math.pow(-2*n+2,3)/2),aa=2*Math.PI/3,oa=2*Math.PI/4.5,tl=n=>(n=Jt(n),n===0?0:n===1?1:-Math.pow(2,10*n-10)*Math.sin((n*10-10.75)*aa)),el=n=>(n=Jt(n),n===0?0:n===1?1:Math.pow(2,-10*n)*Math.sin((n*10-.75)*aa)+1),nl=n=>(n=Jt(n),n===0?0:n===1?1:n<.5?-(Math.pow(2,20*n-10)*Math.sin((20*n-11.125)*oa))/2:Math.pow(2,-20*n+10)*Math.sin((20*n-11.125)*oa)/2+1),Us=1.70158,Js=Us*1.525,ca=Us+1,sl=n=>(n=Jt(n),ca*n*n*n-Us*n*n),il=n=>{n=Jt(n);let t=n-1;return 1+ca*t*t*t+Us*t*t},ol=n=>(n=Jt(n),n<.5?Math.pow(2*n,2)*((Js+1)*2*n-Js)/2:(Math.pow(2*n-2,2)*((Js+1)*(n*2-2)+Js)+2)/2),rl=n=>Jt(n),ra=Object.freeze({linear:rl,quadIn:Xc,quadOut:Yc,quadInOut:$c,cubicIn:Kc,cubicOut:Qc,cubicInOut:Zc,elasticIn:tl,elasticOut:el,elasticInOut:nl,backIn:sl,backOut:il,backInOut:ol});var al=["linear","quadIn","quadOut","quadInOut","cubicIn","cubicOut","cubicInOut","elasticIn","elasticOut","elasticInOut","backIn","backOut","backInOut"];function cl(n){let t=n&&n.easing;if(!t)return ra;let e=i=>typeof t[i]=="function"?o=>t[i](Jt(o)):ra[i],s={};for(let i of al)s[i]=e(i);return Object.freeze(s)}var $i=class{constructor(t,e,s){let i=s||{};this._time=e,this._windowMs=typeof i.windowMs=="number"&&i.windowMs>0?i.windowMs:120;let o=Array.isArray(i.types)&&i.types.length>0?i.types:Hc;this._records=new Map,this._subs=[],this._disposed=!1;for(let r of o){this._records.set(r,null);let a=t.on(r,c=>{this._records.set(r,c.tMs)});this._subs.push(a)}}consume(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs?(this._records.set(t,null),!0):(this._records.set(t,null),!1)}peek(t,e){let s=typeof e=="number"?e:this._time.nowMs(),i=this._records.get(t);return i==null?!1:s-i<=this._windowMs}clear(){for(let t of this._records.keys())this._records.set(t,null)}dispose(){if(!this._disposed){for(let t of this._subs)try{t.cancel()}catch(e){}this._subs=[],this._disposed=!0}}};function la(n){let t=n||{},e=null,s=null,i=!1;return{name:"gamefeel",version:"1.0.0",dependencies:[],get inputBuffer(){return e},get easing(){return cl(s)},init(r){let a=r.getInput();e=new $i(a,r.time,{windowMs:t.inputBufferMs,types:t.inputTypes});let c=r.getEngine();s=c?c.math:null},dispose(){i||(e&&(e.dispose(),e=null),s=null,i=!0)}}}function Vs(n,t){let e=t<0?0:t>1?1:t;switch(n&&n.kind){case"constant":return n.value;case"linear":return n.from+(n.to-n.from)*e;case"easeInOut":{let s=e*e*(3-2*e);return n.from+(n.to-n.from)*s}case"decay":{let s=n.power==null?2:n.power,i=Math.pow(1-e,s);return n.to+(n.from-n.to)*i}default:return 0}}var ll=Object.freeze({burst:Object.freeze({mode:"burst",count:24,angle:0,spread:Math.PI,speedMin:80,speedMax:160,lifeMin:.4,lifeMax:.8,gravity:0,drag:0,sizeCurve:{kind:"decay",from:6,to:0,power:1.5},alphaCurve:{kind:"linear",from:1,to:0}}),trail:Object.freeze({mode:"continuous",rate:60,angle:Math.PI,spread:.25,speedMin:20,speedMax:50,lifeMin:.2,lifeMax:.5,gravity:0,drag:1.5,sizeCurve:{kind:"easeInOut",from:4,to:0},alphaCurve:{kind:"decay",from:.8,to:0,power:2}}),drift:Object.freeze({mode:"continuous",rate:12,angle:Math.PI/2,spread:.6,speedMin:10,speedMax:30,lifeMin:1.5,lifeMax:3,gravity:8,drag:.5,sizeCurve:{kind:"constant",value:3},alphaCurve:{kind:"decay",from:.7,to:0,power:1}})});function ul(n){let t=ll[n];return t?Ki(t):null}function Ki(n){let t={};for(let e of Object.keys(n)){let s=n[e];t[e]=s&&typeof s=="object"?Ki(s):s}return t}function hl(n,t,e){let s=n.mode==="continuous";return{pos:{x:t,y:e},angle:n.angle,coneAngle:n.spread,emitSize:0,emitTime:s?0:1/60,emitRate:s?n.rate||0:void 0,count:s?void 0:n.count||0,particleTime:(n.lifeMin+n.lifeMax)/2,speed:(n.speedMin+n.speedMax)/2,gravityScale:n.gravity||0,damping:n.drag!=null?1-n.drag/60:1,sizeStart:Vs(n.sizeCurve,0),sizeEnd:Vs(n.sizeCurve,1),colorStart:{r:1,g:1,b:1,a:Vs(n.alphaCurve,0)},colorEnd:{r:1,g:1,b:1,a:Vs(n.alphaCurve,1)},additive:!1}}function ua(n){let t=n||{},e=null,s=null,i=null,o=new Map,r=0,a={isActive(){return!1},stop(){}},c=0,l=1,u=0,h=0,f=0,d={x:0,y:0,remain:0,dur:0,amplitude:0,frequency:0,_phase:0},y={alpha:0,remain:0,dur:0,peak:0},x={scale:1,remain:0,dur:0,amplitude:0,frequency:0},v=!1;function w(A){if(u>0)if(u-=A,u<=0)u=0,l=1;else{let T=h>0?1-u/h:1;l=f+(1-f)*T}if(d.remain>0)if(d.remain-=A,d.remain<=0)d.remain=0,d.x=0,d.y=0;else{let T=d.remain/d.dur,R=d.amplitude*T;d._phase+=d.frequency*A*Math.PI*2,d.x=Math.sin(d._phase)*R,d.y=Math.cos(d._phase*1.3)*R}if(y.remain>0&&(y.remain-=A,y.remain<=0?(y.remain=0,y.alpha=0):y.alpha=y.peak*(y.remain/y.dur)),x.remain>0)if(x.remain-=A,x.remain<=0)x.remain=0,x.scale=1;else{let T=x.remain/x.dur,R=(1-T)*x.frequency*Math.PI*2;x.scale=1+Math.sin(R)*x.amplitude*T}}function _(A){c+=1,w(A)}function S(A){let T=A!==void 0?A:e?e.getContext2d():null;if(T&&y.alpha>0){T.globalAlpha=y.alpha,T.fillStyle="#ffffff";let R=T.canvas?T.canvas.width:0,M=T.canvas?T.canvas.height:0;T.fillRect(0,0,R,M),T.globalAlpha=1}}return{name:"particles-juice",version:"1.0.0",dependencies:[],init(A){var T;e=A,i=((T=A.getEngine())==null?void 0:T.particles)||null,typeof t.seed=="number"&&A.random.reseed(t.seed),t.autoStep!==!1&&(s=A.onFrame(R=>{_(R)}))},dispose(){v||(s&&(s.cancel(),s=null),o.forEach(A=>{try{A.stop()}catch{}}),o.clear(),l=1,u=0,d.remain=0,d.x=0,d.y=0,y.remain=0,y.alpha=0,x.remain=0,x.scale=1,v=!0)},spawnEmitter(A,T,R,M){let Z=typeof A=="string"?ul(A):Ki(A);if(!Z)return-1;M&&(Z=Object.assign(Z,M));let it=r++;if(!i)return o.set(it,a),it;let ht=i.spawnEmitter(hl(Z,T,R));return o.set(it,ht),it},stopEmitter(A){let T=o.get(A);if(T)try{T.stop()}catch{}},step(A){_(A)},render(A){S(A)},particleCount(){return 0},emitterCount(){let A=0;for(let T of o.values())T.isActive()&&(A+=1);return A},hitStop(A,T){h=Math.max(0,A),u=h,f=T==null?0:Math.max(0,Math.min(1,T)),l=h>0?f:1},getTimeScale(){return l},shakeScreen(A,T,R){d.dur=Math.max(0,A),d.remain=d.dur,d.amplitude=Math.max(0,T),d.frequency=R==null?30:R,d._phase=0,d.x=0,d.y=0},getShakeOffset(){return{x:d.x,y:d.y}},flashScreen(A,T){y.dur=Math.max(0,A),y.remain=y.dur,y.peak=T==null?.8:Math.max(0,Math.min(1,T)),y.alpha=y.dur>0?y.peak:0},getFlashAlpha(){return y.alpha},pulseScale(A,T,R){x.dur=Math.max(0,A),x.remain=x.dur,x.amplitude=T==null?.2:T,x.frequency=R==null?4:R,x.scale=1},getPulseScale(){return x.scale},juiceSnapshot(){return{timeScale:l,shake:{x:d.x,y:d.y},flashAlpha:y.alpha,pulseScale:x.scale}},probe(){return{particles:0,emitters:o.size,dropped:0,steps:c,disposed:v}}}}function ha(n){let t=yt(n.r)/255,e=yt(n.g)/255,s=yt(n.b)/255,i=Math.max(t,e,s),o=Math.min(t,e,s),r=(i+o)/2,a=0,c=0,l=i-o;return l>1e-12&&(c=r>.5?l/(2-i-o):l/(i+o),i===t?a=(e-s)/l%6:i===e?a=(s-t)/l+2:a=(t-e)/l+4,a*=60,a<0&&(a+=360)),{h:a,s:c,l:r}}function da(n){let t=(n.h%360+360)%360,e=$e(n.s),s=$e(n.l);if(e<1e-12){let a=Math.round(s*255);return{r:a,g:a,b:a}}let i=s<.5?s*(1+e):s+e-s*e,o=2*s-i,r=t/360;return{r:Math.round(Qi(o,i,r+1/3)*255),g:Math.round(Qi(o,i,r)*255),b:Math.round(Qi(o,i,r-1/3)*255)}}function Qi(n,t,e){let s=e;return s<0&&(s+=1),s>1&&(s-=1),s<1/6?n+(t-n)*6*s:s<1/2?t:s<2/3?n+(t-n)*(2/3-s)*6:n}function yt(n){return n<0?0:n>255?255:n}function $e(n){return n<0?0:n>1?1:n}function dl(n,t){let e=pl(n.from,t);if(e>=0&&e({r:yt(a.r),g:yt(a.g),b:yt(a.b)})),to:o}}function Zi(n,t,e){return n+(t-n)*e}function ml(n,t){let e=ha(n),s=e.h+(t.hue||0),i=$e(e.s*(t.sat==null?1:t.sat)),o=$e(e.l*(t.light==null?1:t.light));return da({h:s,s:i,l:o})}var bl=Object.freeze([Object.freeze([0,8,2,10]),Object.freeze([12,4,14,6]),Object.freeze([3,11,1,9]),Object.freeze([15,7,13,5])]);function fa(n){let t=n||{},e=null,s=!1,i={vignette:{enabled:to(t.vignette&&t.vignette.enabled,!1),strength:eo(t.vignette&&t.vignette.strength,.5)},dither:{enabled:to(t.dither&&t.dither.enabled,!1),strength:eo(t.dither&&t.dither.strength,.5)},scanline:{enabled:to(t.scanline&&t.scanline.enabled,!1),strength:eo(t.scanline&&t.scanline.strength,.5)}};function o(a){let c=a!==void 0?a:e?e.getContext2d():null;if(!c)return;let l=c.canvas?c.canvas.width:0,u=c.canvas?c.canvas.height:0;if(i.vignette.enabled&&i.vignette.strength>0&&l>0&&u>0){let h=c.createRadialGradient(l/2,u/2,Math.min(l,u)*.25,l/2,u/2,Math.max(l,u)*.75);h.addColorStop(0,"rgba(0,0,0,0)"),h.addColorStop(1,"rgba(0,0,0,"+i.vignette.strength.toFixed(3)+")"),c.fillStyle=h,c.fillRect(0,0,l,u)}if(i.scanline.enabled&&i.scanline.strength>0&&l>0&&u>0){c.fillStyle="rgba(0,0,0,"+(i.scanline.strength*.5).toFixed(3)+")";for(let h=0;h0&&l>0&&u>0&&typeof c.getImageData=="function"&&typeof c.putImageData=="function"){let h=c.getImageData(0,0,l,u);xl(h,i.dither.strength),c.putImageData(h,0,0)}}return{name:"palette-post",version:"1.0.0",dependencies:[],init(a){e=a},dispose(){s||(e=null,s=!0)},applyPaletteMap(a,c){return dl(a,c)},applyPaletteMapToBuffer(a,c){return fl(a,c)},lerpPaletteMap(a,c,l){return yl(a,c,l)},shiftHsl(a,c){return ml(a,c)},rgbToHsl(a){return ha(a)},hslToRgb(a){return da(a)},setPost(a){if(a)for(let c of["vignette","dither","scanline"])a[c]&&(typeof a[c].enabled=="boolean"&&(i[c].enabled=a[c].enabled),typeof a[c].strength=="number"&&(i[c].strength=$e(a[c].strength)))},getPost(){return{vignette:{enabled:i.vignette.enabled,strength:i.vignette.strength},dither:{enabled:i.dither.enabled,strength:i.dither.strength},scanline:{enabled:i.scanline.enabled,strength:i.scanline.strength}}},renderPost(a){o(a)},probe(){return{disposed:s,post:this.getPost()}}}}function xl(n,t){let e=$e(t);if(e<=0)return n;let{data:s,width:i}=n,r=255/(Math.max(2,Math.round(16-e*14))-1);for(let a=0;a+3>2)%i,l=Math.floor((a>>2)/i),u=(bl[l&3][c&3]/16-.5)*r;for(let h=0;h<3;h++){let f=s[a+h]+u,d=Math.round(f/r)*r;s[a+h]=d<0?0:d>255?255:d}}return n}function to(n,t){return typeof n=="boolean"?n:t}function eo(n,t){return typeof n=="number"?$e(n):t}var so=Object.freeze({blip:Object.freeze({name:"blip",params:Object.freeze([.6,0,880,0,.03,.06,1,1.5])}),thud:Object.freeze({name:"thud",params:Object.freeze([.8,0,90,0,.04,.18,0,1,0,0,0,0,0,4])}),chime:Object.freeze({name:"chime",params:Object.freeze([.5,0,660,.02,.12,.3,1,2])})}),pa=Object.keys(so);function vl(n){let t=[];return n==null||typeof n!="object"?{ok:!1,errors:["song \u5FC5\u987B\u662F\u5BF9\u8C61"]}:(!Array.isArray(n.instruments)||n.instruments.length===0?t.push("instruments \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.instruments.forEach((e,s)=>{(!Array.isArray(e)||e.some(i=>typeof i!="number"||!Number.isFinite(i)))&&t.push(`instruments[${s}] \u5FC5\u987B\u662F\u6709\u9650\u6570\u5B57\u6570\u7EC4\uFF08ZzFX \u53C2\u6570\u5305\uFF09`)}),!Array.isArray(n.patterns)||n.patterns.length===0?t.push("patterns \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.patterns.forEach((e,s)=>{if(!Array.isArray(e)||e.length===0){t.push(`patterns[${s}] \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4\uFF08\u81F3\u5C11\u4E00\u4E2A\u58F0\u90E8\u901A\u9053\uFF09`);return}e.forEach((i,o)=>{if(!Array.isArray(i)||i.length<2){t.push(`patterns[${s}][${o}] \u901A\u9053\u81F3\u5C11\u542B [\u4E50\u5668\u7D22\u5F15, \u58F0\u50CF]`);return}if(i.some(c=>typeof c!="number"||!Number.isFinite(c))){t.push(`patterns[${s}][${o}] \u901A\u9053\u5FC5\u987B\u5168\u4E3A\u6709\u9650\u6570\u5B57`);return}let r=i[0]|0;Array.isArray(n.instruments)&&(r<0||r>=n.instruments.length)&&t.push(`patterns[${s}][${o}] \u4E50\u5668\u7D22\u5F15 ${r} \u8D8A\u754C\uFF08instruments \u957F\u5EA6 ${n.instruments.length}\uFF09`);let a=i[1];(a<-1||a>1)&&t.push(`patterns[${s}][${o}] \u58F0\u50CF ${a} \u8D8A\u754C\uFF08\u5E94 -1..+1\uFF09`)})}),!Array.isArray(n.sequence)||n.sequence.length===0?t.push("sequence \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4"):n.sequence.forEach((e,s)=>{if(typeof e!="number"||!Number.isInteger(e)){t.push(`sequence[${s}] \u5FC5\u987B\u662F\u6574\u6570 pattern \u7D22\u5F15`);return}Array.isArray(n.patterns)&&(e<0||e>=n.patterns.length)&&t.push(`sequence[${s}] \u7D22\u5F15 ${e} \u8D8A\u754C\uFF08patterns \u957F\u5EA6 ${n.patterns.length}\uFF09`)}),n.bpm!=null&&(typeof n.bpm!="number"||!(n.bpm>0))&&t.push("bpm \u5FC5\u987B\u662F\u6B63\u6570"),{ok:t.length===0,errors:t})}function be(n){return typeof n!="number"||Number.isNaN(n)||n<0?0:n>1?1:n}function Sl(n,t){switch(n){case"ease-in":return t*t;case"ease-out":return Math.sqrt(t);case"constant":return 1;default:return t}}function ga(n,t){let e=be(t);return n==null||!Array.isArray(n.voices)?[]:n.voices.map(s=>{let i=String(s&&s.id!=null?s.id:""),o=Array.isArray(s&&s.channelIndices)?s.channelIndices.slice():[],r=typeof s.minIntensity=="number"?be(s.minIntensity):0,a=typeof s.maxIntensity=="number"?be(s.maxIntensity):1,c=typeof s.volumeCurve=="string"?s.volumeCurve:"linear",l=typeof s.baseVolume=="number"?be(s.baseVolume):1;if(ea)return{id:i,on:!1,volume:0,channelIndices:o};let u=a-r,h=u<=0?1:(e-r)/u,f=be(Sl(c,h)*l);return{id:i,on:!0,volume:f,channelIndices:o}})}function ya(n,t,e,s){try{let i=t[0]||[],o=t[1]||i,r=Math.max(i.length,o.length);if(r===0)return null;let c=n.createBuffer(2,r,44100);c.getChannelData(0).set(i),c.getChannelData(1).set(o.length?o:i);let l=n.createBufferSource();l.buffer=c,l.loop=!!s;let u=n.createGain();return u.gain.value=be(e*.3),l.connect(u),u.connect(n.destination),l.start(),{stop(){try{l.stop()}catch(h){}try{l.disconnect(),u.disconnect()}catch(h){}}}}catch(i){return io("[audio-music] \u53D7\u63A7\u97F3\u9891\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",i),null}}function ma(n){let t=n||{},e=typeof t.masterVolume=="number"?be(t.masterVolume):1,s=()=>null,i=null,o=null,r={voices:[]},a=1,c=null,l=!1,u=0,h=!1,f=!1;function d(){let S=s();return S==null?(u+=1,h||(no("[audio-music] \u65E0\u53D7\u63A7\u97F3\u9891\u4E0A\u4E0B\u6587\uFF08getAudioContext \u8FD4\u56DE null\uFF09\uFF0C\u5168\u90E8\u53D1\u58F0\u9759\u9ED8 no-op\uFF08\u8BC4\u4F30\u73AF\u5883\u65E0\u58F0\u5361\u65F6\u7684\u5BB9\u9519\u964D\u7EA7\uFF09"),h=!0),null):S}function y(){if(!o||!i)return null;try{let S=typeof o.bpm=="number"&&o.bpm>0?o.bpm:125;return i.synthSong(o.instruments,o.patterns,o.sequence,S)}catch(S){return io("[audio-music] \u66F2\u8C31\u6E32\u67D3\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8",S),null}}function x(){let S=ga(r,a);if(S.length===0)return 1;let E=0;for(let A of S)A.on&&(E=Math.max(E,A.volume));return E}function v(S,E){typeof E=="number"&&(a=be(E));let A=d();if(A==null||!o)return;w();let T=y();if(!T)return;let R=be(e*x());c=ya(A,T,R,S),l=!!S&&c!=null}function w(){c&&(c.stop(),c=null),l=!1}return{name:"audio-music",version:"1.0.0",dependencies:[],init(S){s=()=>S.getAudioContext();let E=S.getEngine&&S.getEngine();i=E?E.audio.synth:null},dispose(){f||(w(),f=!0)},loadSong(S){let E=vl(S);return E.ok?o={instruments:S.instruments,patterns:S.patterns,sequence:S.sequence,bpm:typeof S.bpm=="number"?S.bpm:125}:no("[audio-music] \u66F2\u8C31\u6821\u9A8C\u5931\u8D25\uFF0C\u672A\u8F7D\u5165\uFF1A"+E.errors.join("\uFF1B")),E},play(S){v(!1,S)},stop(){w()},loop(S){v(!0,S)},setIntensityLayering(S){r=S&&Array.isArray(S.voices)?{voices:S.voices}:{voices:[]}},setIntensity(S){a=be(S)},resolveVoices(S){return ga(r,S)},playSfx(S){let E=so[S];if(!E){no("[audio-music] \u672A\u77E5\u97F3\u6548\u9884\u8BBE\uFF1A"+String(S));return}let A=d();if(A!=null)try{let T=i?i.synthSfx(E.params):null;if(!T)return;ya(A,[T,T],e,!1)}catch(T){io("[audio-music] \u97F3\u6548\u64AD\u653E\u5F02\u5E38\uFF0C\u964D\u7EA7\u4E3A\u9759\u9ED8 name="+S,T)}},getPreset(S){return so[S]},listPresets(){return pa.slice()},probe(){return{hasAudio:s()!=null,hasSong:o!=null,intensity:a,voiceCount:r.voices.length,looping:l,silentNoops:u,presetCount:pa.length}}}}function io(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function no(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var wl="zaomeng.save";function Tl(n){if(typeof TextEncoder!="undefined")return new TextEncoder().encode(n).length;if(typeof Buffer!="undefined"&&typeof Buffer.byteLength=="function")return Buffer.byteLength(n,"utf8");let t=0;for(let e=0;e=55296&&s<=56319?(t+=4,e++):t+=3}return t}function ro(){let n=new Map;return{getItem(t){return n.has(t)?n.get(t):null},setItem(t,e){n.set(t,e)},removeItem(t){n.delete(t)},keys(){return Array.from(n.keys())}}}function ba(){if(typeof localStorage=="undefined")throw new Error("[save-progress] createLocalStorageAdapter \u9700\u8981\u5168\u5C40 localStorage\uFF08\u4EC5\u6D4F\u89C8\u5668\u96C6\u6210\u6BB5\u53EF\u7528\uFF09\u3002node/host-dev \u8BF7\u7528\u7F3A\u7701\u5185\u5B58 adapter \u6216 createMemoryAdapter()\u3002");return{getItem(n){return localStorage.getItem(n)},setItem(n,t){localStorage.setItem(n,t)},removeItem(n){localStorage.removeItem(n)},keys(){let n=[];for(let t=0;t0?t.namespace:wl;if(e.indexOf(":")>=0)throw new Error('[save-progress] namespace \u4E0D\u5F97\u542B\u5206\u9694\u7B26 ":"\uFF08\u5F53\u524D="'+e+'"\uFF09');let s=typeof t.maxValueBytes=="number"&&t.maxValueBytes>0?Math.floor(t.maxValueBytes):32768,i=!Al(t.adapter),o=i?ro():t.adapter,r=e+":",a=0,c=0,l=!1;function u(d){return typeof d!="string"||d.length===0?r+String(d):r+d}function h(){try{let d=o.keys();return Array.isArray(d)?d.filter(y=>typeof y=="string"&&y.indexOf(r)===0):[]}catch(d){return es("[save-progress] adapter.keys() \u5F02\u5E38\uFF0C\u964D\u7EA7\u8FD4\u56DE\u7A7A\u96C6",d),[]}}return{name:"save-progress",version:"1.0.0",dependencies:[],init(d){h()},dispose(){},get(d,y){if(!oo(d))return y;let x;try{x=o.getItem(u(d))}catch(v){return es("[save-progress] adapter.getItem \u5F02\u5E38\uFF0C\u8FD4\u56DE\u9ED8\u8BA4\u503C key="+d,v),y}if(x==null)return y;try{return JSON.parse(x)}catch{return a+=1,l||(ns("[save-progress] \u68C0\u6D4B\u5230\u635F\u574F\u5B58\u6863\uFF08\u975E\u6CD5 JSON\uFF09\uFF0C\u5DF2\u5BB9\u9519\u56DE\u9000\u9ED8\u8BA4\u503C key="+d),l=!0),y}},set(d,y){if(!oo(d))return ns("[save-progress] set \u6536\u5230\u975E\u6CD5 key\uFF0C\u62D2\u7EDD\u5199\u5165\uFF1A"+String(d)),!1;let x;try{x=JSON.stringify(y)}catch{return c+=1,ns("[save-progress] \u503C\u4E0D\u53EF JSON \u5E8F\u5217\u5316\uFF08\u5FAA\u73AF\u5F15\u7528?\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1}if(x===void 0)return c+=1,ns("[save-progress] \u503C\u5E8F\u5217\u5316\u4E3A undefined\uFF08\u5982\u7EAF undefined/\u51FD\u6570\uFF09\uFF0C\u62D2\u7EDD\u5199\u5165 key="+d),!1;let v=Tl(x);if(v>s)return c+=1,ns("[save-progress] \u503C\u8D85\u5B57\u8282\u4E0A\u9650\u62D2\u7EDD\u5199\u5165 key="+d+"\uFF08"+v+" > "+s+" bytes\uFF09"),!1;try{return o.setItem(u(d),x),!0}catch(w){return c+=1,es("[save-progress] adapter.setItem \u5F02\u5E38\uFF0C\u5199\u5165\u5931\u8D25 key="+d,w),!1}},remove(d){if(oo(d))try{o.removeItem(u(d))}catch(y){es("[save-progress] adapter.removeItem \u5F02\u5E38\uFF08\u5DF2\u5FFD\u7565\uFF09key="+d,y)}},clear(){let d=h(),y=0;for(let x of d)try{o.removeItem(x),y+=1}catch(v){es("[save-progress] clear \u65F6 removeItem \u5F02\u5E38\uFF08\u5DF2\u8DF3\u8FC7\uFF09fullKey="+x,v)}return y},probe(){return{namespace:e,maxValueBytes:s,usingMemoryAdapter:i,size:h().length,corruptRecoveries:a,rejectedWrites:c}}}}function oo(n){return typeof n=="string"&&n.length>0}function Al(n){return!!n&&typeof n.getItem=="function"&&typeof n.setItem=="function"&&typeof n.removeItem=="function"&&typeof n.keys=="function"}function es(n,t){let e=t&&t.stack?t.stack:t&&t.message?t.message:t;typeof console!="undefined"&&typeof console.error=="function"&&console.error(n+(e?"\uFF1A"+e:""))}function ns(n){typeof console!="undefined"&&typeof console.warn=="function"&&console.warn(n)}var Cl={w:390,h:844};function va(n){let t=((n&&n.seed)!=null?n.seed:0)>>>0,e=sa({cellSize:96}),s=ia(),i=la({inputBufferMs:260,inputTypes:["pointerdown"]}),o=ua({seed:t,maxParticles:600}),r=fa({vignette:{enabled:!0,strength:.22}}),a=ma({masterVolume:.8}),c;try{c=ba()}catch(f){console.warn("[generic] localStorage \u4E0D\u53EF\u7528\uFF0C\u5B58\u6863\u9000\u5185\u5B58 adapter\uFF1A"+(f&&f.message)),c=ro()}let l=xa({namespace:"zaomeng-generic",adapter:c});return{plugins:{collision:e,physics:s,gamefeel:i,juice:o,palettePost:r,audioMusic:a,save:l},registerOrder:[e,s,i,o,r,l,a],viewport:Cl,buildFactoryOpts:(f,d)=>({runtime:{plugins:d.plugins,bundle:d.bundle,getRealAudioCtx:d.getRealAudioCtx}})}}function ss(n){let t=n||{},e=null,s=null,i=null,o=t.seed||42,r="booting",a=0,c=0,l=0,u="",h=[],f=null,d=null,y=0,x=.8,v=1,w=.5,_=null,S=[{shape:[[1,1,1,1]],color:1},{shape:[[1,1],[1,1]],color:2},{shape:[[0,1,0],[1,1,1]],color:3},{shape:[[0,1,1],[1,1,0]],color:4},{shape:[[1,1,0],[0,1,1]],color:5},{shape:[[1,0,0],[1,1,1]],color:6},{shape:[[0,0,1],[1,1,1]],color:7}],E=[null,"#00f0f0","#f0f000","#a000f0","#00f000","#f00000","#0000f0","#f0a000"];function A(){return e.random.next()}function T(L,B){return Math.floor(A()*(B-L+1))+L}function R(L){let B=S[L],j=B.shape.map(H=>H.slice());return{type:L,shape:j,x:Math.floor((10-j[0].length)/2),y:0,color:B.color}}function M(L){let B=L.length,j=L[0].length,H=[];for(let Bt=0;Bt=0;lt--)H[Bt].push(L[lt][Bt])}return H}function Z(L,B,j,H,Bt){let lt=Bt||L.shape;for(let le=0;le=10||at>=18||at>=0&&B[at][zt]!==0)return!0}return!1}function it(){let L=f;if(!L)return;let B=L.shape;for(let j=0;j=0&<<18&&(h[lt][Bt]=L.color)}if(l++,ht(),gt(),r!=="gameover"){let j=e.getEngine();if(j){if(j.particles)try{j.particles.spawnEmitter({pos:{x:L.x*39+19.5,y:L.y*46.9+23.45},count:10,speed:60,particleTime:.3,colorStart:{r:1,g:1,b:1,a:1},colorEnd:{r:1,g:1,b:1,a:0}})}catch{}if(j.audio&&j.audio.synth)try{j.audio.synth.synthSfx([1,.05,300,,,.15,,1.2])}catch{}}}}function ht(){let L=0;for(let B=17;B>=0;){let j=!0;for(let H=0;H<10;H++)if(h[B][H]===0){j=!1;break}if(j){for(let H=B;H>0;H--)h[H]=h[H-1].slice();h[0]=new Array(10).fill(0),L++}else B--}if(L>0){c+=L,L===1?a+=100:L===2?a+=300:L===3?a+=500:L===4&&(a+=800);let B=e.getEngine();if(B&&B.particles)try{B.particles.spawnEmitter({pos:{x:195,y:422},count:30,speed:120,particleTime:.6,colorStart:{r:.2,g:1,b:.2,a:1},colorEnd:{r:0,g:.8,b:0,a:0}})}catch{}if(B&&B.audio&&B.audio.synth)try{B.audio.synth.synthSfx([1,.1,500,,,.2,,1.5])}catch{}}}function gt(){if(!d){let B=T(0,6);d=R(B)}f=d;let L=T(0,6);if(d=R(L),Z(f,h,0,0,f.shape)){r="gameover",u="stack_to_top";return}f.x=Math.floor((10-f.shape[0].length)/2),f.y=0}function Nt(){if(!(!f||r==="gameover")){if(!Z(f,h,0,1,f.shape)){f.y++;return}it()}}function He(){if(!(!f||r==="gameover")){for(;!Z(f,h,0,1,f.shape);)f.y++;it()}}function Ot(L){!f||r==="gameover"||Z(f,h,L,0,f.shape)||(f.x+=L)}function dt(){if(!f||r==="gameover")return;let L=M(f.shape);Z(f,h,0,0,L)?Z(f,h,-1,0,L)?Z(f,h,1,0,L)||(f.shape=L,f.x+=1):(f.shape=L,f.x-=1):f.shape=L}function Dt(L){if(r!=="gameover")switch(L.key){case"ArrowLeft":Ot(-1);break;case"ArrowRight":Ot(1);break;case"ArrowUp":dt();break;case"ArrowDown":v=.05;break;case" ":He();break}}function Le(L){L.key==="ArrowDown"&&(v=1)}function dn(L){e=L.ctx,s=L.canvas,i=L.mainContext,h=new Array(18);for(let H=0;H<18;H++)h[H]=new Array(10).fill(0);e.random.reseed(o);let B=T(0,6);d=R(B),gt(),_=e.getInput().on("keydown",Dt),e.getInput().on("keyup",Le),a=0,c=0,l=0,y=0,r="playing",u="";let j=e.getEngine();if(j&&j.math)try{j.math.lerp(0,1,.5)}catch{}}function fn(L){let B=e.time.nowMs();if(r==="gameover")return;y+=L;let j=x*v;y>=j&&(y-=j,Nt())}function ce(L){L.fillStyle="#0a0a1a",L.fillRect(0,0,390,844);let B=39,j=46.8888,H=40,Bt=18*j,lt=40,It=(844-lt-20)/18,zt=390/10;L.strokeStyle="#1a1a3a",L.lineWidth=1;for(let at=0;at<=18;at++){let _t=lt+at*It;L.beginPath(),L.moveTo(0,_t),L.lineTo(390,_t),L.stroke()}for(let at=0;at<=10;at++){let _t=at*zt;L.beginPath(),L.moveTo(_t,lt),L.lineTo(_t,844),L.stroke()}for(let at=0;at<18;at++)for(let _t=0;_t<10;_t++){let De=h[at][_t];De>0&&(L.fillStyle=E[De],L.fillRect(_t*zt,lt+at*It,zt-1,It-1))}if(f&&r!=="gameover"){let at=f;L.fillStyle=E[at.color];let _t=at.shape;for(let De=0;De<_t.length;De++)for(let In=0;In<_t[0].length;In++)if(_t[De][In]!==0){let ts=(at.x+In)*zt,D=lt+(at.y+De)*It;L.fillRect(ts,D,zt-1,It-1)}}L.fillStyle="#ffffff",L.font="bold 16px monospace",L.fillText("Score: "+a,10,20),L.fillText("Lines: "+c,160,20),L.fillText("Pieces: "+l,290,20),r==="gameover"&&(L.fillStyle="rgba(0,0,0,0.7)",L.fillRect(0,200,390,200),L.fillStyle="#ff4444",L.font="bold 28px monospace",L.textAlign="center",L.fillText("GAME OVER",195,300),L.font="14px monospace",L.fillStyle="#aaaaaa",L.fillText("Tap to restart",195,340),L.textAlign="left")}function Oe(){try{_&&_.cancel()}catch{}_=null}function ee(){return{seed:o,state:()=>({phase:r,result:r==="gameover"?"lose":null,score:a,lines:c,piecesLocked:l,board:h.map(L=>L.slice())})}}return{init:dn,update:fn,render:ce,destroy:Oe,_forensicsView:ee}}var pd=ss,gd=ss;async function yd(n){let t=n||{},e=t.engine||await Promise.resolve().then(()=>(Mc(),Ic)),s=(t.seed!=null?t.seed:305441741)>>>0,i=va({seed:s});return na({canvas:t.canvas,statusEl:t.statusEl||null,engine:e,seed:s,mode:t.mode||"play",engineMode:"real",viewport:i.viewport,factory:ss,plugins:i.plugins,registerOrder:i.registerOrder,buildFactoryOpts:i.buildFactoryOpts,recHook:t.recHook||null,onReady:t.onReady||null})}return Bc(md);})();
diff --git a/game-runtime/games/_wg1-gen/tetris/bundle.iife.js.meta.json b/game-runtime/games/_wg1-gen/tetris/bundle.iife.js.meta.json
index e71e7751..081a76ea 100644
--- a/game-runtime/games/_wg1-gen/tetris/bundle.iife.js.meta.json
+++ b/game-runtime/games/_wg1-gen/tetris/bundle.iife.js.meta.json
@@ -1 +1 @@
-{"inputs":{"src/core/plugin.js":{"bytes":44317,"imports":[],"format":"esm"},"src/plugins/runtime-probe/impl.js":{"bytes":16639,"imports":[],"format":"esm"},"host-dev/engine-caps.js":{"bytes":13897,"imports":[],"format":"esm"},"host-dev/engine-math.js":{"bytes":6155,"imports":[],"format":"esm"},"src/host/boot-game-host.js":{"bytes":27676,"imports":[{"path":"src/core/plugin.js","kind":"import-statement","original":"../core/plugin.js"},{"path":"src/plugins/runtime-probe/impl.js","kind":"import-statement","original":"../plugins/runtime-probe/impl.js"},{"path":"host-dev/engine-caps.js","kind":"import-statement","original":"../../host-dev/engine-caps.js"},{"path":"host-dev/engine-math.js","kind":"import-statement","original":"../../host-dev/engine-math.js"}],"format":"esm"},"src/plugins/collision/impl.js":{"bytes":24812,"imports":[],"format":"esm"},"src/plugins/physics-lite/impl.js":{"bytes":14507,"imports":[],"format":"esm"},"src/plugins/gamefeel/impl.js":{"bytes":21715,"imports":[],"format":"esm"},"src/plugins/particles-juice/impl.js":{"bytes":31830,"imports":[],"format":"esm"},"src/plugins/palette-post/impl.js":{"bytes":20240,"imports":[],"format":"esm"},"src/plugins/audio-music/impl.js":{"bytes":24659,"imports":[],"format":"esm"},"src/plugins/save-progress/impl.js":{"bytes":14608,"imports":[],"format":"esm"},"src/host/generic-host-config.js":{"bytes":7803,"imports":[{"path":"src/plugins/collision/impl.js","kind":"import-statement","original":"../plugins/collision/impl.js"},{"path":"src/plugins/physics-lite/impl.js","kind":"import-statement","original":"../plugins/physics-lite/impl.js"},{"path":"src/plugins/gamefeel/impl.js","kind":"import-statement","original":"../plugins/gamefeel/impl.js"},{"path":"src/plugins/particles-juice/impl.js","kind":"import-statement","original":"../plugins/particles-juice/impl.js"},{"path":"src/plugins/palette-post/impl.js","kind":"import-statement","original":"../plugins/palette-post/impl.js"},{"path":"src/plugins/audio-music/impl.js","kind":"import-statement","original":"../plugins/audio-music/impl.js"},{"path":"src/plugins/save-progress/impl.js","kind":"import-statement","original":"../plugins/save-progress/impl.js"}],"format":"esm"},"games/_wg1-gen/tetris/generated-factory.js":{"bytes":12500,"imports":[],"format":"esm"},"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytes":640153,"imports":[],"format":"esm"},"games/_wg1-gen/tetris/entry-bundle.js":{"bytes":6230,"imports":[{"path":"src/host/boot-game-host.js","kind":"import-statement","original":"../../../src/host/boot-game-host.js"},{"path":"src/host/generic-host-config.js","kind":"import-statement","original":"../../../src/host/generic-host-config.js"},{"path":"games/_wg1-gen/tetris/generated-factory.js","kind":"import-statement","original":"./generated-factory.js"},{"path":"node_modules/littlejsengine/dist/littlejs.esm.js","kind":"dynamic-import","original":"littlejsengine"}],"format":"esm"}},"outputs":{"games/_wg1-gen/tetris/bundle.iife.js":{"imports":[],"exports":[],"entryPoint":"games/_wg1-gen/tetris/entry-bundle.js","inputs":{"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytesInOutput":164219},"games/_wg1-gen/tetris/entry-bundle.js":{"bytesInOutput":507},"src/core/plugin.js":{"bytesInOutput":8989},"src/plugins/runtime-probe/impl.js":{"bytesInOutput":2794},"host-dev/engine-caps.js":{"bytesInOutput":1597},"host-dev/engine-math.js":{"bytesInOutput":498},"src/host/boot-game-host.js":{"bytesInOutput":5359},"src/plugins/collision/impl.js":{"bytesInOutput":1605},"src/plugins/physics-lite/impl.js":{"bytesInOutput":115},"src/plugins/gamefeel/impl.js":{"bytesInOutput":2533},"src/plugins/particles-juice/impl.js":{"bytesInOutput":4161},"src/plugins/palette-post/impl.js":{"bytesInOutput":4218},"src/plugins/audio-music/impl.js":{"bytesInOutput":6001},"src/plugins/save-progress/impl.js":{"bytesInOutput":3933},"src/host/generic-host-config.js":{"bytesInOutput":697},"games/_wg1-gen/tetris/generated-factory.js":{"bytesInOutput":4621}},"bytes":212418}}}
\ No newline at end of file
+{"inputs":{"src/core/plugin.js":{"bytes":44317,"imports":[],"format":"esm"},"src/plugins/runtime-probe/impl.js":{"bytes":16639,"imports":[],"format":"esm"},"host-dev/engine-caps.js":{"bytes":13897,"imports":[],"format":"esm"},"host-dev/engine-math.js":{"bytes":6155,"imports":[],"format":"esm"},"src/host/boot-game-host.js":{"bytes":28239,"imports":[{"path":"src/core/plugin.js","kind":"import-statement","original":"../core/plugin.js"},{"path":"src/plugins/runtime-probe/impl.js","kind":"import-statement","original":"../plugins/runtime-probe/impl.js"},{"path":"host-dev/engine-caps.js","kind":"import-statement","original":"../../host-dev/engine-caps.js"},{"path":"host-dev/engine-math.js","kind":"import-statement","original":"../../host-dev/engine-math.js"}],"format":"esm"},"src/plugins/collision/impl.js":{"bytes":24812,"imports":[],"format":"esm"},"src/plugins/physics-lite/impl.js":{"bytes":14507,"imports":[],"format":"esm"},"src/plugins/gamefeel/impl.js":{"bytes":21715,"imports":[],"format":"esm"},"src/plugins/particles-juice/impl.js":{"bytes":31830,"imports":[],"format":"esm"},"src/plugins/palette-post/impl.js":{"bytes":20240,"imports":[],"format":"esm"},"src/plugins/audio-music/impl.js":{"bytes":24659,"imports":[],"format":"esm"},"src/plugins/save-progress/impl.js":{"bytes":14608,"imports":[],"format":"esm"},"src/host/generic-host-config.js":{"bytes":7803,"imports":[{"path":"src/plugins/collision/impl.js","kind":"import-statement","original":"../plugins/collision/impl.js"},{"path":"src/plugins/physics-lite/impl.js","kind":"import-statement","original":"../plugins/physics-lite/impl.js"},{"path":"src/plugins/gamefeel/impl.js","kind":"import-statement","original":"../plugins/gamefeel/impl.js"},{"path":"src/plugins/particles-juice/impl.js","kind":"import-statement","original":"../plugins/particles-juice/impl.js"},{"path":"src/plugins/palette-post/impl.js","kind":"import-statement","original":"../plugins/palette-post/impl.js"},{"path":"src/plugins/audio-music/impl.js","kind":"import-statement","original":"../plugins/audio-music/impl.js"},{"path":"src/plugins/save-progress/impl.js","kind":"import-statement","original":"../plugins/save-progress/impl.js"}],"format":"esm"},"games/_wg1-gen/tetris/generated-factory.js":{"bytes":12500,"imports":[],"format":"esm"},"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytes":640153,"imports":[],"format":"esm"},"games/_wg1-gen/tetris/entry-bundle.js":{"bytes":6230,"imports":[{"path":"src/host/boot-game-host.js","kind":"import-statement","original":"../../../src/host/boot-game-host.js"},{"path":"src/host/generic-host-config.js","kind":"import-statement","original":"../../../src/host/generic-host-config.js"},{"path":"games/_wg1-gen/tetris/generated-factory.js","kind":"import-statement","original":"./generated-factory.js"},{"path":"node_modules/littlejsengine/dist/littlejs.esm.js","kind":"dynamic-import","original":"littlejsengine"}],"format":"esm"}},"outputs":{"games/_wg1-gen/tetris/bundle.iife.js":{"imports":[],"exports":[],"entryPoint":"games/_wg1-gen/tetris/entry-bundle.js","inputs":{"node_modules/littlejsengine/dist/littlejs.esm.js":{"bytesInOutput":164219},"games/_wg1-gen/tetris/entry-bundle.js":{"bytesInOutput":507},"src/core/plugin.js":{"bytesInOutput":8989},"src/plugins/runtime-probe/impl.js":{"bytesInOutput":2794},"host-dev/engine-caps.js":{"bytesInOutput":1597},"host-dev/engine-math.js":{"bytesInOutput":498},"src/host/boot-game-host.js":{"bytesInOutput":5506},"src/plugins/collision/impl.js":{"bytesInOutput":1605},"src/plugins/physics-lite/impl.js":{"bytesInOutput":115},"src/plugins/gamefeel/impl.js":{"bytesInOutput":2533},"src/plugins/particles-juice/impl.js":{"bytesInOutput":4161},"src/plugins/palette-post/impl.js":{"bytesInOutput":4218},"src/plugins/audio-music/impl.js":{"bytesInOutput":6001},"src/plugins/save-progress/impl.js":{"bytesInOutput":3933},"src/host/generic-host-config.js":{"bytesInOutput":697},"games/_wg1-gen/tetris/generated-factory.js":{"bytesInOutput":4621}},"bytes":212565}}}
\ No newline at end of file
diff --git a/game-runtime/games/_wg1-gen/tetris/evidence/after-play.png b/game-runtime/games/_wg1-gen/tetris/evidence/after-play.png
index ae0ed46b..9d409abe 100644
Binary files a/game-runtime/games/_wg1-gen/tetris/evidence/after-play.png and b/game-runtime/games/_wg1-gen/tetris/evidence/after-play.png differ
diff --git a/game-runtime/games/_wg1-gen/tetris/evidence/verdict.json b/game-runtime/games/_wg1-gen/tetris/evidence/verdict.json
index 39a3e82b..8ddd4ded 100644
--- a/game-runtime/games/_wg1-gen/tetris/evidence/verdict.json
+++ b/game-runtime/games/_wg1-gen/tetris/evidence/verdict.json
@@ -18,13 +18,13 @@
     },
     "D_render": {
       "pass": true,
-      "bright": 56257,
+      "bright": 202394,
       "maxCh": 255
     },
     "E_live": {
       "pass": true,
-      "distinctStates": 28,
-      "samples": 52
+      "distinctStates": 31,
+      "samples": 31
     },
     "B_uncaught": {
       "pass": true,
@@ -32,8 +32,18 @@
     },
     "F_wiring": {
       "pass": true,
-      "callCount": 3,
+      "callCount": 19,
       "sample": [
+        "particles.spawnEmitter",
+        "audio.synth.synthSfx",
+        "particles.spawnEmitter",
+        "audio.synth.synthSfx",
+        "particles.spawnEmitter",
+        "audio.synth.synthSfx",
+        "particles.spawnEmitter",
+        "audio.synth.synthSfx",
+        "particles.spawnEmitter",
+        "audio.synth.synthSfx",
         "particles.spawnEmitter",
         "audio.synth.synthSfx"
       ],
@@ -44,27 +54,28 @@
     },
     "G_input": {
       "pass": true,
-      "inputHash": "afbf31e7",
-      "controlHash": "5f498477",
-      "atFrame": 1311,
-      "ctrlFrame": -1
+      "inputHash": "e0e36b65",
+      "controlHash": "5e30ba3e",
+      "atFrame": 806,
+      "ctrlFrame": 811
     },
     "H_progress": {
-      "pass": false,
+      "pass": true,
       "checks": [
         {
           "path": "piecesLocked",
           "op": "increased",
           "before": 0,
-          "after": 1,
+          "after": 10,
           "pass": true,
           "why": "循环按键下落+硬降→锁定方块数上升;不下落/不锁定则不升"
         }
       ],
       "latch": {
-        "pass": false,
-        "reason": "真玩未到达 gameover 终态(终态不可达/无失败态/play-spec 未驱动到结束)",
-        "phaseNow": "playing"
+        "pass": true,
+        "dwelledMs": 600,
+        "after": "gameover",
+        "reason": ""
       },
       "state0": {
         "phase": "playing",
@@ -292,11 +303,11 @@
         ]
       },
       "state1": {
-        "phase": "playing",
-        "result": null,
+        "phase": "gameover",
+        "result": "lose",
         "score": 0,
         "lines": 0,
-        "piecesLocked": 1,
+        "piecesLocked": 10,
         "board": [
           [
             0,
@@ -315,7 +326,7 @@
             0,
             0,
             0,
-            0,
+            4,
             0,
             0,
             0,
@@ -327,8 +338,8 @@
             0,
             0,
             0,
-            0,
-            0,
+            4,
+            4,
             0,
             0,
             0,
@@ -340,7 +351,7 @@
             0,
             0,
             0,
-            0,
+            4,
             0,
             0,
             0,
@@ -349,152 +360,32 @@
           [
             0,
             0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0,
-            0
-          ],
-          [
-            0,
+            7,
             0,
             0,
             5,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
+            0,
+            0,
+            7,
+            0,
+            5,
+            5,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
+            0,
+            0,
+            7,
+            7,
             5,
             0,
             0,
@@ -505,10 +396,130 @@
           [
             0,
             0,
+            0,
+            2,
+            2,
+            0,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
+            0,
+            0,
+            0,
+            2,
+            2,
+            0,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
+            0,
+            0,
+            0,
+            0,
+            4,
+            0,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
+            0,
+            0,
+            0,
+            0,
+            4,
+            4,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
+            0,
+            0,
+            0,
+            2,
+            2,
+            4,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
+            0,
+            0,
+            0,
+            2,
+            2,
+            5,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
+            0,
+            0,
+            6,
+            6,
+            5,
+            5,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
+            0,
+            0,
+            6,
+            0,
+            5,
+            0,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
+            0,
+            0,
+            6,
+            5,
+            4,
+            0,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
             0,
             0,
             5,
             5,
+            4,
+            4,
+            0,
+            0,
+            0,
+            0
+          ],
+          [
+            0,
+            0,
+            5,
+            0,
+            0,
+            4,
             0,
             0,
             0,
@@ -518,6 +529,6 @@
       }
     }
   },
-  "pass": false,
+  "pass": true,
   "notes": []
 }
\ No newline at end of file