@zylem/game-lib 0.8.0 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/actions.d.ts +6 -6
  2. package/dist/api/game-lib.api.json +3105 -1223
  3. package/dist/api/game-lib.api.md +197 -96
  4. package/dist/api/game-lib.d.ts +448 -96
  5. package/dist/api/game-lib.typedoc.json +134986 -201814
  6. package/dist/{base-node-life-cycle-D2NuN1VB.d.ts → base-node-life-cycle-BK9xebT9.d.ts} +6 -0
  7. package/dist/bridge.d.ts +97 -0
  8. package/dist/bridge.js +1 -0
  9. package/dist/chunk-2VSVOPQN.js +19 -0
  10. package/dist/chunk-3I537JFL.js +1 -0
  11. package/dist/chunk-47DG7I7M.js +1 -0
  12. package/dist/chunk-7QF6YTEZ.js +1 -0
  13. package/dist/chunk-AIQ6IVT5.js +1 -0
  14. package/dist/chunk-C5NEGC3S.js +1 -0
  15. package/dist/chunk-CV75NSES.js +1 -0
  16. package/dist/chunk-EVYHPR3J.js +1 -0
  17. package/dist/chunk-GKHAJ3MW.js +1 -0
  18. package/dist/chunk-HNCTOJP7.js +1 -0
  19. package/dist/{chunk-M3XNO56P.js → chunk-JNFFTNMH.js} +1 -1
  20. package/dist/{chunk-XNDS4YFR.js → chunk-LGS5N5M4.js} +1 -1
  21. package/dist/chunk-LKFF6XJC.js +1 -0
  22. package/dist/{chunk-RXDTAWI2.js → chunk-PCFF4LLO.js} +1 -1
  23. package/dist/chunk-Q27ULMXY.js +24 -0
  24. package/dist/chunk-TV3AZKT4.js +9 -0
  25. package/dist/chunk-UG22Z42P.js +1 -0
  26. package/dist/chunk-W5SXED5T.js +1 -0
  27. package/dist/chunk-WVSYUWTT.js +1 -0
  28. package/dist/chunk-YAOXFYOD.js +1 -0
  29. package/dist/{collision-builder-jF-toPIl.d.ts → collision-builder-B_tm8OVy.d.ts} +13 -2
  30. package/dist/core.d.ts +15 -15
  31. package/dist/core.js +1 -1
  32. package/dist/debug-state-Dp9CQQZ4.d.ts +49 -0
  33. package/dist/debug.d.ts +27 -8
  34. package/dist/debug.js +1 -1
  35. package/dist/{default-controls-0-vCnli7.d.ts → default-controls-CAKJ5zlo.d.ts} +2 -2
  36. package/dist/{entity-DZbFQ1Wg.d.ts → entity-B9yZeBm4.d.ts} +7 -1
  37. package/dist/{entity-BdSI8CL3.d.ts → entity-BGEq1yfC.d.ts} +32 -4
  38. package/dist/{entity-type-map-Bd69SpAS.d.ts → entity-type-map-CW6RHQkx.d.ts} +5 -5
  39. package/dist/entity.d.ts +12 -10
  40. package/dist/entity.js +1 -1
  41. package/dist/events.d.ts +2 -65
  42. package/dist/events.js +1 -1
  43. package/dist/{game-C1FHVqXl.d.ts → game-NHkubIfI.d.ts} +89 -32
  44. package/dist/game-default-5TB3T5N7.js +1 -0
  45. package/dist/{game-interfaces-mchNYSZE.d.ts → game-interfaces-vF5sRi1n.d.ts} +7 -1
  46. package/dist/globals.d.ts +1 -1
  47. package/dist/graphics.d.ts +5 -5
  48. package/dist/input-ui.d.ts +4 -4
  49. package/dist/input-ui.js +1 -1
  50. package/dist/input.d.ts +47 -4
  51. package/dist/input.js +1 -1
  52. package/dist/{material-9vJ6SZaI.d.ts → material-DbSuZBbP.d.ts} +1 -1
  53. package/dist/public.d.ts +16 -14
  54. package/dist/public.js +1 -1
  55. package/dist/runtime.d.ts +3 -3
  56. package/dist/runtime.js +1 -1
  57. package/dist/schema/game-config.schema.json +18 -0
  58. package/dist/schema/input-config.schema.json +18 -0
  59. package/dist/schema.d.ts +12 -0
  60. package/dist/schema.js +1 -1
  61. package/dist/{vector-CiSHbivc.d.ts → vector-DN6zlPoE.d.ts} +28 -0
  62. package/dist/web-components.d.ts +12 -12
  63. package/dist/web-components.js +1 -1
  64. package/dist/{zylem-camera-C3bn6BTI.d.ts → zylem-camera-Du2UPW9O.d.ts} +13 -1
  65. package/package.json +8 -3
  66. package/dist/chunk-7FR5JSQ2.js +0 -1
  67. package/dist/chunk-COM6HJ2L.js +0 -1
  68. package/dist/chunk-E3UBSUPX.js +0 -1
  69. package/dist/chunk-FKIKN7RP.js +0 -24
  70. package/dist/chunk-G4HONLWC.js +0 -1
  71. package/dist/chunk-IKWE2W6L.js +0 -1
  72. package/dist/chunk-JEHFHUH4.js +0 -0
  73. package/dist/chunk-JNKPTL77.js +0 -1
  74. package/dist/chunk-JQKS42G4.js +0 -1
  75. package/dist/chunk-MSC2BEO5.js +0 -1
  76. package/dist/chunk-TAUWDQZF.js +0 -9
  77. package/dist/chunk-VS2D4B3W.js +0 -1
  78. package/dist/chunk-XNHVRFAK.js +0 -1
  79. package/dist/chunk-YHEWKN7N.js +0 -1
  80. package/dist/debug-state-BPT6jEog.d.ts +0 -17
  81. package/dist/game-default-QHROHW2O.js +0 -1
@@ -48,8 +48,14 @@ interface InputGamepad {
48
48
  };
49
49
  /** Screen-space cursor position (normalized 0..1). Only populated by MouseProvider. */
50
50
  pointer?: {
51
+ /** Window-normalized X (0 = left, 1 = right). */
51
52
  x: number;
53
+ /** Window-normalized Y (0 = top, 1 = bottom). */
52
54
  y: number;
55
+ /** Canvas-center-relative X (−1 = left edge, +1 = right edge). */
56
+ centerX: number;
57
+ /** Canvas-center-relative Y (−1 = top edge, +1 = bottom edge). */
58
+ centerY: number;
53
59
  };
54
60
  }
55
61
  type Inputs = Record<InputPlayer, InputGamepad>;
@@ -0,0 +1,97 @@
1
+ import { GameConfigPayload, GameLoadingPayload, GameVariablePayload, GameNoticePayload, StageSnapshotPayload, EntitySummaryPayload, EntityThumbnailPayload } from '@zylem/bridge';
2
+ export { BRIDGE_READY_EVENT, BridgeChannel, BridgeDebugTool, BridgeHandler, GameLoadingPayload as BridgeLoadingPayload, BridgeMessageType, BridgeMessages, BridgeVec3, EditorToGameMessages, EntitySummaryPayload, EntityThumbnailPayload, GameConfigPayload, GameToEditorMessages, GameVariablePayload, StageConfigPayload, StageSnapshotPayload, ZylemBridge, announceBridgeReady, getZylemBridge } from '@zylem/bridge';
3
+ import { G as GameEntity } from './entity-BGEq1yfC.js';
4
+ import 'three';
5
+ import '@zylem/behaviors/core';
6
+ import './vector-DN6zlPoE.js';
7
+ import './material-DbSuZBbP.js';
8
+ import 'three/webgpu';
9
+ import './collision-builder-B_tm8OVy.js';
10
+ import './base-node-life-cycle-BK9xebT9.js';
11
+ import './stage-transition-CmGpV4tc.js';
12
+ import './events.js';
13
+ import 'mitt';
14
+
15
+ /**
16
+ * Game-side adapter for the shared editor ↔ game bridge.
17
+ *
18
+ * Owns the editor→game command subscriptions (debug/tool/playback, entity
19
+ * select/focus/transform, stage variables) and exposes typed publish helpers
20
+ * the running game uses to stream config, stage snapshots, entity upserts,
21
+ * and thumbnails to the editor. High-frequency publishes go through the
22
+ * channel's `queue`, which coalesces to at most one message per animation
23
+ * frame.
24
+ */
25
+
26
+ /**
27
+ * Host context supplied by the running game so bridge commands can act on
28
+ * live stage state without the bridge importing game internals.
29
+ */
30
+ interface GameBridgeHost {
31
+ /** Resolve a live entity by UUID from the current stage. */
32
+ resolveEntity(uuid: string): GameEntity<any> | null;
33
+ /** Write a stage variable (editor `stage:variable:set`). */
34
+ setStageVariable?(key: string, value: unknown): void;
35
+ }
36
+ declare class GameBridge {
37
+ private channel;
38
+ private unsubscribes;
39
+ private host;
40
+ /**
41
+ * Values the editor is already known to hold, either because it commanded
42
+ * them or because we published them. Anything matching here is skipped, so
43
+ * an editor command can never echo back as a game update.
44
+ */
45
+ private editorKnown;
46
+ constructor();
47
+ /**
48
+ * Subscribe to editor commands and announce the game side as ready.
49
+ * @param host Live-game context for entity/stage lookups
50
+ * @param announceTarget DOM node the `zylem:bridge:ready` event bubbles from
51
+ */
52
+ connect(host: GameBridgeHost, announceTarget?: EventTarget): void;
53
+ disconnect(): void;
54
+ /**
55
+ * Publish only the parts of `debugState` the editor does not already know.
56
+ * Values that arrived as editor commands are recorded on `editorKnown`
57
+ * first, so they are never echoed back.
58
+ */
59
+ private publishDebugStateChanges;
60
+ /**
61
+ * Whether anything is listening for entity list updates. Building entity
62
+ * summaries is pure editor overhead, so publishers skip it when no editor
63
+ * is attached.
64
+ */
65
+ wantsEntityUpdates(): boolean;
66
+ /**
67
+ * Whether anything is listening for thumbnails. Each thumbnail costs an
68
+ * offscreen render plus a pixel readback on the renderer the game draws
69
+ * with, so this gate matters far more than the others.
70
+ */
71
+ wantsThumbnails(): boolean;
72
+ /**
73
+ * Run a callback when an editor first subscribes to entity data, so the
74
+ * game can backfill state produced while nothing was listening.
75
+ *
76
+ * @returns An unsubscribe function.
77
+ */
78
+ onEditorAttached(callback: () => void): () => void;
79
+ publishConfig(config: GameConfigPayload): void;
80
+ publishLoading(payload: GameLoadingPayload): void;
81
+ publishStatus(status: {
82
+ paused?: boolean;
83
+ debug?: boolean;
84
+ }): void;
85
+ publishVariable(payload: GameVariablePayload): void;
86
+ /** Surface a diagnostic message in the editor console. */
87
+ publishNotice(level: GameNoticePayload['level'], message: string): void;
88
+ publishStageSnapshot(snapshot: StageSnapshotPayload): void;
89
+ /** RAF-coalesced entity add/update stream; merged by uuid per frame. */
90
+ queueEntityUpsert(entities: EntitySummaryPayload[]): void;
91
+ /** RAF-coalesced entity removal stream. */
92
+ queueEntityRemoved(uuids: string[]): void;
93
+ /** RAF-coalesced thumbnail stream; merged by uuid per frame. */
94
+ queueThumbnails(thumbnails: EntityThumbnailPayload[]): void;
95
+ }
96
+
97
+ export { GameBridge, type GameBridgeHost };
package/dist/bridge.js ADDED
@@ -0,0 +1 @@
1
+ import{a as b,b as c,c as d}from"./chunk-HNCTOJP7.js";import{c as a}from"./chunk-GKHAJ3MW.js";import"./chunk-LKFF6XJC.js";import"./chunk-W5SXED5T.js";export{d as BRIDGE_READY_EVENT,a as GameBridge,c as announceBridgeReady,b as getZylemBridge};
@@ -0,0 +1,19 @@
1
+ import{a as y}from"./chunk-C5NEGC3S.js";import{AmbientLight as R,Object3D as U,PerspectiveCamera as T,RenderTarget as O,Scene as C,Color as P,LinearFilter as w,SpotLight as W,Vector3 as E}from"three";function d(a,e,t,n={}){let s=e*4,i=new Uint8ClampedArray(t*s),r=null;if(n.srgb){r=new Uint8Array(256);for(let o=0;o<256;o+=1){let c=o/255,u=c<=.0031308?c*12.92:1.055*Math.pow(c,1/2.4)-.055;r[o]=Math.round(Math.max(0,Math.min(1,u))*255)}}for(let o=0;o<t;o+=1){let c=(n.flipY?t-1-o:o)*s,u=o*s;if(r===null){i.set(a.subarray(c,c+s),u);continue}for(let l=0;l<s;l+=4)i[u+l]=r[a[c+l]],i[u+l+1]=r[a[c+l+1]],i[u+l+2]=r[a[c+l+2]],i[u+l+3]=a[c+l+3]}return i}var x=`
2
+ const encodeReadbackPixels = ${d.toString()};
3
+
4
+ self.onmessage = async (event) => {
5
+ const { id, buffer, width, height, options } = event.data;
6
+ try {
7
+ const src = new Uint8ClampedArray(buffer);
8
+ const pixels = encodeReadbackPixels(src, width, height, options);
9
+ const canvas = new OffscreenCanvas(width, height);
10
+ const ctx = canvas.getContext('2d');
11
+ if (!ctx) throw new Error('OffscreenCanvas 2d context unavailable');
12
+ ctx.putImageData(new ImageData(pixels, width, height), 0, 0);
13
+ const blob = await canvas.convertToBlob({ type: 'image/png' });
14
+ self.postMessage({ id, blob });
15
+ } catch (error) {
16
+ self.postMessage({ id, error: String(error) });
17
+ }
18
+ };
19
+ `,h=class{worker=null;workerFailed=!1;nextId=1;pending=new Map;isSupported(){return!this.workerFailed&&typeof Worker<"u"&&typeof OffscreenCanvas<"u"&&typeof URL<"u"&&typeof Blob<"u"}async encodeThumbnail(e,t,n,s={}){if(!this.isSupported())return null;let i=this.ensureWorker();if(!i)return null;let r=new Uint8Array(e.byteLength);r.set(e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength));let o=this.nextId++;try{let c=await new Promise((u,l)=>{this.pending.set(o,{resolve:u,reject:l}),i.postMessage({id:o,buffer:r.buffer,width:t,height:n,options:s},[r.buffer])});return URL.createObjectURL(c)}catch{return null}}dispose(){this.worker&&(this.worker.terminate(),this.worker=null);for(let{reject:e}of this.pending.values())e(new Error("EntityPayloadWorker disposed"));this.pending.clear()}ensureWorker(){if(this.worker)return this.worker;try{let e=new Blob([x],{type:"text/javascript"}),t=URL.createObjectURL(e),n=new Worker(t,{type:"module"});return URL.revokeObjectURL(t),n.onmessage=s=>{let{id:i}=s.data,r=this.pending.get(i);r&&(this.pending.delete(i),"blob"in s.data?r.resolve(s.data.blob):r.reject(new Error(s.data.error)))},n.onerror=()=>{this.workerFailed=!0,this.dispose()},this.worker=n,n}catch{return this.workerFailed=!0,null}}},v=new h;var S=128,L=256,M=1,k=32,p=class{cache=new Map;inFlight=new Map;renderer=null;size;maxEntries;queue=[];activeRenders=0;constructor(e=S,t=L){this.size=e,this.maxEntries=t}setRenderer(e){this.renderer=e}get(e){let t=this.cache.get(e);return t?(this.touch(e,t),t):null}invalidate(e){let t=this.cache.get(e);t&&f(t.dataUrl),this.cache.delete(e),this.inFlight.delete(e),this.queue=this.queue.filter(n=>n.uuid!==e?!0:(n.resolve(null),!1))}clear(){this.cache.forEach(e=>f(e.dataUrl)),this.cache.clear(),this.inFlight.clear();for(let e of this.queue)e.resolve(null);this.queue=[]}get cacheSize(){return this.cache.size}get pendingCount(){return this.queue.length}async ensure(e,t){let n=this.cache.get(e);if(n)return this.touch(e,n),n;let s=this.inFlight.get(e);if(s)return s;if(!t||!this.renderer)return null;let i=new Promise(r=>{if(this.queue.push({uuid:e,object:t,resolve:r}),this.queue.length>k){let o=this.queue.splice(0,this.queue.length-k);for(let c of o)this.inFlight.delete(c.uuid),c.resolve(null)}this.drainQueue()});return this.inFlight.set(e,i),i}drainQueue(){for(;this.activeRenders<M&&this.queue.length>0;){let e=this.queue.shift();if(!e)return;this.activeRenders+=1,this.render(e.uuid,e.object).then(t=>{t&&(this.cache.set(e.uuid,t),this.evictOverflow()),e.resolve(t)}).catch(t=>{console.warn("EntityThumbnailCache: failed to render thumbnail",e.uuid,t),e.resolve(null)}).finally(()=>{this.activeRenders-=1,this.inFlight.delete(e.uuid),this.drainQueue()})}}touch(e,t){this.cache.delete(e),this.cache.set(e,t)}evictOverflow(){for(;this.cache.size>this.maxEntries;){let e=this.cache.keys().next();if(e.done)return;let t=this.cache.get(e.value);t&&f(t.dataUrl),this.cache.delete(e.value)}}async render(e,t){let n=this.renderer;if(!n)return null;let s=new C;s.background=new P(3815994);let i=t.clone(!0);i.position.set(0,0,0),i.rotation.set(0,0,0),i.updateMatrixWorld(!0),s.add(i);let r=new T(50,1,.1,100),o=y(i,r);F(s,r,o);let c=new O(this.size,this.size,{minFilter:w,magFilter:w}),u=n.getRenderTarget(),l=n.getScissorTest();try{n.setScissorTest(!1),n.setRenderTarget(c),n.render(s,r)}finally{n.setRenderTarget(u),n.setScissorTest(l)}let b=await n.readRenderTargetPixelsAsync(c,0,0,this.size,this.size);c.dispose(),s.remove(i);let m={flipY:A(n),srgb:!0},g=await v.encodeThumbnail(b,this.size,this.size,m)??D(b,this.size,this.size,m);return g?{uuid:e,dataUrl:g,bounds:{width:o.width,height:o.height,depth:o.depth}}:null}},N=new p;function f(a){a.startsWith("blob:")&&typeof URL<"u"&&URL.revokeObjectURL(a)}function A(a){return a?.backend?.isWebGLBackend===!0}function F(a,e,t){a.add(new R(16777215,.7)),e.updateMatrixWorld(!0);let n=new E().setFromMatrixColumn(e.matrixWorld,0),s=new E().setFromMatrixColumn(e.matrixWorld,1),i=e.position.distanceTo(t.center)||1,r=new W(16777215,5);r.position.copy(e.position).addScaledVector(n,i*.35).addScaledVector(s,i*.45),r.decay=0,r.distance=0,r.penumbra=.5,r.angle=j(Math.atan(t.maxDim/i)+.25,.4,Math.PI/3),r.castShadow=!1;let o=new U;o.position.copy(t.center),a.add(o),r.target=o,a.add(r)}function j(a,e,t){return Math.min(t,Math.max(e,a))}function D(a,e,t,n={}){if(typeof document>"u")return null;let s=document.createElement("canvas");s.width=e,s.height=t;let i=s.getContext("2d");if(!i)return null;let r=a instanceof Uint8Array?a:new Uint8Array(a.buffer,a.byteOffset,a.byteLength),o=i.createImageData(e,t);return o.data.set(d(r,e,t,n)),i.putImageData(o,0,0),s.toDataURL("image/png")}export{p as a,N as b};
@@ -0,0 +1 @@
1
+ import{b as V,d as ve,e as G,j as Se}from"./chunk-CM5YRNBJ.js";import{a as de,b as he}from"./chunk-AIQ6IVT5.js";import{a as Q,b as Ce,c as xe}from"./chunk-EVYHPR3J.js";import{c as v,d as D,e as me,f as fe,g as ye,h as f,i as be,j as L}from"./chunk-7WRQ2UAN.js";import{p as ge}from"./chunk-XRP4JJXL.js";import{StageBodyKind as _e}from"@zylem/behaviors/core";import{Color as st,Vector2 as Oe,Vector3 as Ee}from"three";function F(i){if(!i||typeof i!="object")return!1;let e=Object.getPrototypeOf(i);return e===Object.prototype||e===null}function y(i){if(i==null||typeof i=="function"||typeof i!="object")return i;if(i instanceof st||i instanceof Oe||i instanceof Ee)return i.clone();if(i instanceof Float32Array)return new Float32Array(i);if(Array.isArray(i))return i.map(e=>y(e));if(F(i)){let e={};for(let[t,o]of Object.entries(i))t!=="_builders"&&(e[t]=y(o));return e}return i}function S(i,e){let t=y(i);if(!e)return t;if(!F(t)||!F(e))return y(e);let o=t;for(let[n,s]of Object.entries(e)){if(n==="_builders"||s===void 0)continue;let r=o[n];if(n==="shader"){o[n]=y(s);continue}if(r instanceof Oe&&me(s)){o[n]=be(s,r);continue}if(r instanceof Ee&&fe(s)){o[n]=L(s,r);continue}if(F(r)&&F(s)){o[n]=S(r,s);continue}o[n]=y(s)}return o}function Me(i){return i&&i.__kind==="collision"}function ee(i){return i.cloneComponent()}function rt(i,e){let t={kind:i?_e.Static:_e.Dynamic,position:[0,0,0],gravityScale:e.gravityScale??1,canSleep:e.canSleep??!1,ccdEnabled:e.ccdEnabled??!0},o=Q(e.lockRotations);o&&(t.lockRotation=o);let n=Q(e.lockTranslations);return n&&(t.lockTranslation=n),t}function at(i,e){if(e.offset){let t=f(e.offset,v);i.offset=[t.x,t.y,t.z]}e.sensor&&(i.sensor=!0),e.collisionType&&(i.collisionGroups=Ce(e.collisionType,e.collisionFilter))}function _(i,e,t){return at(i,e),{__kind:"collision",bodyDesc:rt(e.static??!1,e),colliderDesc:i,cloneComponent:t}}function lt(i={}){let e=f(i.size,D),t={shape:{type:"box",halfExtents:[e.x/2,e.y/2,e.z/2]}},o=y(i);return _(t,i,()=>lt(o))}function ct(i={}){let e={shape:{type:"sphere",radius:i.radius??1}},t=y(i);return _(e,i,()=>ct(t))}function ut(i={}){let e=i.radius??1,o={shape:{type:"cone",halfHeight:(i.height??2)/2,radius:e}},n=y(i);return _(o,i,()=>ut(n))}function pt(i={}){let e=i.radius??1,o={shape:{type:"cone",halfHeight:(i.height??2)/2,radius:e}},n=y(i);return _(o,i,()=>pt(n))}function dt(i={}){let e=Math.max(i.radiusTop??1,i.radiusBottom??1),o={shape:{type:"cylinder",halfHeight:(i.height??2)/2,radius:e}},n=y(i);return _(o,i,()=>dt(n))}function ht(i={}){let e=i.radius??.5,o={shape:{type:"capsule",halfHeight:(i.length??1)/2,radius:e}},n=y(i);return _(o,i,()=>ht(n))}function mt(i={}){let e=ye(i.tile,{x:10,y:10}),t=i.subdivisions??10,o=(t+1)*(t+1),n=i.heightData??new Float32Array(o),s={shape:{type:"heightfield",rows:t,cols:t,heights:n,scale:[e.x,1,e.y]}},r={...i,static:i.static??!0},a=y(r);return _(s,r,()=>mt(a))}function ft(i={}){let e=f(i.size,D),t={shape:{type:"box",halfExtents:[e.x/2,e.y/2,e.z/2]},sensor:!0},o={...i,static:i.static??!0,sensor:!0},n=y(o);return _(t,o,()=>ft(n))}import{Mesh as ze,ShaderMaterial as Et,Group as _t}from"three";var Ae=import.meta.env.VITE_DEBUG_FLAG==="true";import{nanoid as yt}from"nanoid";var C=class i{parent=null;children=[];options;uuid="";name="";markedForRemoval=!1;lifecycleCallbacks={setup:[],loaded:[],update:[],destroy:[],cleanup:[]};trackLifecycleRegistrations=!1;userLifecycleRegistrations=[];constructor(e=[]){let t=e.filter(o=>!(o instanceof i)).reduce((o,n)=>({...o,...n}),{});this.options=t,this.uuid=yt()}onSetup(...e){return this.lifecycleCallbacks.setup.push(...e),this.recordLifecycleRegistration("onSetup",e),this}onLoaded(...e){return this.lifecycleCallbacks.loaded.push(...e),this.recordLifecycleRegistration("onLoaded",e),this}onUpdate(...e){return this.lifecycleCallbacks.update.push(...e),this.recordLifecycleRegistration("onUpdate",e),this}onDestroy(...e){return this.lifecycleCallbacks.destroy.push(...e),this.recordLifecycleRegistration("onDestroy",e),this}onCleanup(...e){return this.lifecycleCallbacks.cleanup.push(...e),this.recordLifecycleRegistration("onCleanup",e),this}prependSetup(...e){return this.lifecycleCallbacks.setup.unshift(...e),this.recordLifecycleRegistration("prependSetup",e),this}prependUpdate(...e){return this.lifecycleCallbacks.update.unshift(...e),this.recordLifecycleRegistration("prependUpdate",e),this}setParent(e){this.parent=e}getParent(){return this.parent}add(e){this.children.push(e),e.setParent(this)}remove(e){let t=this.children.indexOf(e);t!==-1&&(this.children.splice(t,1),e.setParent(null))}getChildren(){return this.children}isComposite(){return this.children.length>0}enableUserLifecycleTracking(){this.trackLifecycleRegistrations=!0}replayUserLifecycleRegistrationsTo(e,t){for(let o of this.userLifecycleRegistrations){let n=t?o.callbacks.map(s=>t(s)):[...o.callbacks];switch(o.method){case"onSetup":e.onSetup(...n);break;case"onLoaded":e.onLoaded(...n);break;case"onUpdate":e.onUpdate(...n);break;case"onDestroy":e.onDestroy(...n);break;case"onCleanup":e.onCleanup(...n);break;case"prependSetup":e.prependSetup(...n);break;case"prependUpdate":e.prependUpdate(...n);break}}}cloneChildrenInto(e){for(let t of this.children)e.add(bt(t))}nodeSetup(e){this.markedForRemoval=!1,typeof this._setup=="function"&&this._setup(e);for(let t of this.lifecycleCallbacks.setup)t(e);this.children.forEach(t=>t.nodeSetup(e))}nodeUpdate(e){if(!this.markedForRemoval){typeof this._update=="function"&&this._update(e),typeof this._tickActions=="function"&&this._tickActions(e.delta);for(let t of this.lifecycleCallbacks.update)t(e);this.children.forEach(t=>t.nodeUpdate(e))}}nodeDestroy(e){if(!this.markedForRemoval){this.children.forEach(t=>t.nodeDestroy(e));for(let t of this.lifecycleCallbacks.destroy)t(e);typeof this._destroy=="function"&&this._destroy(e),this.markedForRemoval=!0;for(let t of this.lifecycleCallbacks.cleanup)t(e);typeof this._cleanup=="function"&&this._cleanup(e)}}async nodeLoaded(e){typeof this._loaded=="function"&&await this._loaded(e);for(let t of this.lifecycleCallbacks.loaded)t(e)}nodeCleanup(e){this.children.forEach(t=>t.nodeCleanup?.(e));for(let t of this.lifecycleCallbacks.cleanup)t(e);typeof this._cleanup=="function"&&this._cleanup(e)}getOptions(){return this.options}setOptions(e){this.options={...this.options,...e}}recordLifecycleRegistration(e,t){!this.trackLifecycleRegistrations||t.length===0||this.userLifecycleRegistrations.push({method:e,callbacks:[...t]})}};function bt(i){let e=i?.clone;if(typeof e!="function")throw new Error(`Cannot clone child node "${i.name||i.uuid||"unknown"}": missing clone() support.`);return e.call(i)}import{createTransformStore as Mt}from"@zylem/behaviors/core";import{makeMoveable as gt}from"@zylem/behaviors/core";function Pe(i){let e=gt(i);return ge(e)}import{clearVelocityIntent as je}from"@zylem/behaviors/core";import{Color as St,Vector3 as Ot}from"three";var we=Symbol("explicitSpawnPosition");function De(i){return i.filter(e=>!(e instanceof C)).some(e=>e!=null&&typeof e=="object"&&"position"in e)}function Be(i){i[we]=!0}function Ct(i){return i._spawnPositionExplicit?!0:i.options[we]===!0}function xt(i){return i.options.hideUntilPositioned!==!1}function Re(i){return i._spawnPlacementPending===!0}function vt(i){return i._spawnPositionExplicit===!0||i._spawnPlacementReady===!0}function U(i){let e=i.group??i.mesh;if(e){if(i.physicsAttached&&i.body)try{let t=i.body.translation();e.position.set(t.x,t.y,t.z);return}catch{}if(i.wasmStageRef&&(i.runtimeHandle??-1)>=0){let t=i.wasmStageRef.getPose(i.runtimeHandle);if(t){e.position.set(t.position[0],t.position[1],t.position[2]);return}}if(i.options.position){let t=f(i.options.position,v);e.position.set(t.x,t.y,t.z)}}}function T(i,e){i.group&&(i.group.visible=e),i.mesh&&(i.mesh.visible=e)}function Hi(i){if(i._spawnInProgress=!0,i._spawnPlacementReady=!1,!xt(i)){i._spawnPlacementPending=!1;return}i._spawnPositionExplicit=Ct(i),i._spawnPlacementPending=!0,T(i,!1)}function Yi(i){i._spawnInProgress=!1}function Fe(i){i._spawnPlacementReady=!0}function te(i){if(i._spawnPlacementPending){if(U(i),i._spawnPlacementPending=!1,i.options.visible===!1){T(i,!1);return}T(i,!0)}}function Wi(i){!Re(i)||i.options.hideUntilPositioned===!0&&!vt(i)||te(i)}function Te(i){U(i),i._spawnPlacementPending=!1,T(i,!0)}function ke(i){Re(i)&&T(i,!1)}var N={position:new Ot(0,0,0),material:{color:new St("#ffffff"),shader:V},collision:{static:!1}};function eo(i,e){let t=i.filter(n=>!(n instanceof C)),o=S(e);for(let n of t)o=S(o,n);return De(i)&&Be(o),o}function At(i){return i!=null&&typeof i=="object"}function Ie(i){return{phase:i?.phase??"stay",cooldownMs:i?.cooldownMs}}function Pt(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var P=class extends C{group;mesh;materials;bodyDesc=null;body=null;physicsAttached=!1;physicsWorldRef=null;colliderDesc;custom={};colliderDescs=[];compoundMeshes=[];debugInfo={};debugMaterial;collisionDelegate={collision:[],cooldowns:new Map,nextId:0};collisionType;packKey=null;bundleKey=null;instanceId=-1;isInstanced=!1;isBundled=!1;runtimeHandle=-1;runtimeAttached=!1;wasmStageRef=null;eventDelegate=new de;behaviorRefs=[];cloneFactory=null;trackAddedComponents=!1;trackedComponents=[];transformStore;_spawnPlacementPending=!1;_spawnPositionExplicit=!1;_spawnPlacementReady=!1;_spawnInProgress=!1;moveX;moveY;moveZ;moveXY;moveXZ;move;resetVelocity;moveForwardXY;getPosition;getVelocity;setPosition;setPositionX;setPositionY;setPositionZ;wrapAroundXY;wrapAround3D;rotateInDirection;rotateYEuler;rotateEuler;rotateX;rotateY;rotateZ;setRotationY;setRotationX;setRotationZ;setRotationDegrees;setRotationDegreesY;setRotationDegreesX;setRotationDegreesZ;setRotation;getRotation;constructor(){super(),this.transformStore=Mt(),Pe(this),this.wrapSpawnPlacementMutators()}wrapSpawnPlacementMutators(){let e=()=>{Fe(this),!this._spawnInProgress&&(U(this),te(this))},t=s=>(r,a,l)=>{!this.body&&!(this.wasmStageRef&&this.runtimeHandle>=0)||(s(r,a,l),e())},o=s=>r=>{!this.body&&!(this.wasmStageRef&&this.runtimeHandle>=0)||(s(r),e())};this.setPosition=t(this.setPosition.bind(this)),this.setPositionX=o(this.setPositionX.bind(this)),this.setPositionY=o(this.setPositionY.bind(this)),this.setPositionZ=o(this.setPositionZ.bind(this));let n=this.setPose.bind(this);this.setPose=s=>{let r=n(s);return r&&s.position!=null&&e(),r}}reveal(){this.options.visible=!0,Te(this)}getPose(){if(this.wasmStageRef&&this.runtimeHandle>=0){let n=this.wasmStageRef.getPose(this.runtimeHandle);if(n)return{position:{x:n.position[0],y:n.position[1],z:n.position[2]},rotation:{x:n.rotation[0],y:n.rotation[1],z:n.rotation[2],w:n.rotation[3]}}}let e=this.body;if(!e)return null;let t=e.translation(),o=e.rotation();return{position:{x:t.x,y:t.y,z:t.z},rotation:{x:o.x,y:o.y,z:o.z,w:o.w}}}setPose(e){if(this.wasmStageRef&&this.runtimeHandle>=0){let o=!0;if(e.position){let n=f(e.position);o=this.wasmStageRef.setPosition(this.runtimeHandle,n.x,n.y,n.z)&&o}if(e.rotation){let{x:n,y:s,z:r,w:a}=e.rotation;o=this.wasmStageRef.setRotation(this.runtimeHandle,n,s,r,a)&&o}return o}let t=this.body;if(!t)return!1;if(e.position){let o=f(e.position);t.setTranslation({x:o.x,y:o.y,z:o.z},!0)}return e.rotation&&t.setRotation(e.rotation,!0),!0}add(...e){for(let t of e)t instanceof ze?(this.addMeshComponent(t),this.trackComponent(t)):Me(t)?(this.addCollisionComponent(t),this.trackComponent(t)):super.add(t);return this}addMeshComponent(e){if(this.mesh)this.compoundMeshes.push(e),this.group||(this.group=new _t,this.group.add(this.mesh)),this.group.add(e);else if(this.mesh=e,this.materials||(this.materials=[]),e.material){let t=e.material;Array.isArray(t)?this.materials.push(...t):this.materials.push(t)}}addCollisionComponent(e){if(this.bodyDesc)this.colliderDescs.push(e.colliderDesc);else{this.bodyDesc=e.bodyDesc,this.colliderDesc=e.colliderDesc,this.colliderDescs.push(e.colliderDesc);let t=f(this.options?.position,v);this.bodyDesc.position=[t.x,t.y,t.z]}}trackComponent(e){if(this.trackAddedComponents){if(e instanceof ze){this.trackedComponents.push({kind:"mesh",component:Le(e)});return}this.trackedComponents.push({kind:"collision",component:ee(e)})}}_actions=[];runAction(e){return this._actions.push(e),e}action(e){return e.persistent=!0,this._actions.push(e),e}clearActions(){this._actions.length=0}_tickActions(e){if(this._actions.length===0)return;let t=this.transformStore;t.velocity.x=0,t.velocity.y=0,t.velocity.z=0,je(t,"actions"),t.angularVelocity.x=0,t.angularVelocity.y=0,t.angularVelocity.z=0,t.dirty.angularVelocity=!1;for(let o=this._actions.length-1;o>=0;o--){let n=this._actions[o];n.tick(this,e),n.done&&!n.persistent&&this._actions.splice(o,1)}this._actions.length===0&&(t.velocity.x=0,t.velocity.y=0,t.velocity.z=0,je(t,"actions"),t.angularVelocity.x=0,t.angularVelocity.y=0,t.angularVelocity.z=0,t.dirty.angularVelocity=!1)}create(){return this.name=this.options.name||"",this}clone(e){if(!this.cloneFactory)throw new Error(`Cannot clone ${this.constructor.name}: clone() is only supported for entities created by official factory helpers.`);let t=this.cloneFactory(S(this.options,e)),o=this.copyBehaviorRefsTo(t),n=r=>Dt(r,o);this.replayUserLifecycleRegistrationsTo(t,n);let s=this.getCollisionRegistrations();if(s.length>0)for(let r of s)t.onCollision(n(r.callback),r.options);for(let r of this.trackedComponents){if(r.kind==="mesh"){t.add(Le(r.component));continue}t.add(ee(r.component))}return this.cloneChildrenInto(t),t}finalizeCloneSupport(e){return this.cloneFactory=e,this.enableUserLifecycleTracking(),this.trackAddedComponents=!0,this}onCollision(...e){let t=[...this.collisionDelegate.collision??[]],o=this.collisionDelegate.nextId??0;if(e.length===1||e.length===2&&(e[1]==null||At(e[1]))){let n=e[0];if(!n)return this;let s=e[1];return t.push({id:o,callback:n,options:Ie(s)}),o+=1,this.collisionDelegate.collision=t,this.collisionDelegate.nextId=o,this}for(let n of e)t.push({id:o,callback:n,options:Ie()}),o+=1;return this.collisionDelegate.collision=t,this.collisionDelegate.nextId=o,this}use(e,t){let o={descriptor:e,options:{...e.defaultOptions,...t}};this.behaviorRefs.push(o);let n={getFSM:()=>o.fsm??null,getOptions:()=>o.options,ref:o},s=e.createHandle?.(o)??{};return{...n,...s}}getBehaviorRefs(){return this.behaviorRefs}getCollisionCallbacks(){return this.getCollisionRegistrations().map(e=>e.callback)}getCollisionRegistrations(){return(this.collisionDelegate.collision??[]).map(e=>({id:e.id,callback:e.callback,options:{...e.options}}))}copyBehaviorRefsTo(e){let t=new Map;for(let o of this.behaviorRefs){e.use(o.descriptor,y(o.options));let n=e.getBehaviorRefs().at(-1);n&&t.set(o,n)}return t}_setup(e){for(let t=this._actions.length-1;t>=0;t--){let o=this._actions[t];o.done&&!o.persistent?this._actions.splice(t,1):o.reset()}}async _loaded(e){}_update(e){this.updateMaterials(e)}_destroy(e){}_cleanup(e){this.disposeEvents();for(let t of this.compoundMeshes)t.geometry?.dispose(),Array.isArray(t.material)?t.material.forEach(o=>o.dispose()):t.material?.dispose();this.compoundMeshes.length=0,this.debugMaterial?.dispose(),this.debugMaterial=void 0,this.group?.removeFromParent()}_collision(e,t,o={phase:"stay",nowMs:Pt()}){if(!this.collisionDelegate.collision?.length)return;let n=this.collisionDelegate.cooldowns??new Map;this.collisionDelegate.cooldowns=n;for(let s of this.collisionDelegate.collision){if(s.options.phase!==o.phase)continue;let r=s.options.cooldownMs;if(r!=null){let a=`${s.id}:${e.uuid}`,l=n.get(a);if(l!=null&&o.nowMs-l<r)continue;n.set(a,o.nowMs)}s.callback({entity:this,other:e,globals:t})}}updateMaterials(e){if(this.materials?.length)for(let t of this.materials)t instanceof Et&&t.uniforms&&t.uniforms.iTime&&(t.uniforms.iTime.value+=e.delta)}buildInfo(){let e={};return e.name=this.name,e.uuid=this.uuid,e}dispatch(e,t){this.eventDelegate.dispatch(e,t),he.emit(e,t)}listen(e,t){return this.eventDelegate.listen(e,t)}disposeEvents(){this.eventDelegate.dispose()}};function wt(i){let e=new P;return e.options={...N,...i},ie(e,t=>wt(t??{}))}function Le(i){let e=i.clone(!0),t=[],o=[];i.traverse(n=>t.push(n)),e.traverse(n=>o.push(n));for(let n=0;n<t.length;n++){let s=t[n],r=o[n];s?.geometry?.clone&&(r.geometry=s.geometry.clone()),s?.material&&(r.material=Array.isArray(s.material)?s.material.map(a=>a.clone()):s.material.clone())}return e}function Dt(i,e){return e.size===0?i:((...t)=>{let o=Array.from(e.entries()).map(([n,s])=>({sourceRef:n,options:n.options,fsm:n.fsm,hasFSM:Object.prototype.hasOwnProperty.call(n,"fsm"),targetRef:s}));for(let n of o)n.sourceRef.options=n.targetRef.options,n.targetRef.fsm===void 0?delete n.sourceRef.fsm:n.sourceRef.fsm=n.targetRef.fsm;try{return i(...t)}finally{for(let n=o.length-1;n>=0;n--){let s=o[n];s.sourceRef.options=s.options,s.hasFSM?s.sourceRef.fsm=s.fsm:delete s.sourceRef.fsm}}})}function ie(i,e){return i.finalizeCloneSupport(e),i}function Ve(i){return typeof i?.load=="function"&&typeof i?.data=="function"}var Z=class{entityReference;constructor(e){this.entityReference=e}load(){this.entityReference.load&&this.entityReference.load()}data(){return this.entityReference.data?this.entityReference.data():null}};function Ge(i){let{args:e,defaultConfig:t,EntityClass:o,BuilderClass:n,entityType:s,MeshBuilderClass:r,CollisionBuilderClass:a,cloneFactory:l}=i,p=null,d,c=e.findIndex(b=>!(b instanceof C));c!==-1&&(d=e.splice(c,1).find(h=>!(h instanceof C)));let u=d?S(t,d):S(t);e.push(u);for(let b of e){if(b instanceof C)continue;let h=null,R=new o(b);try{if(Ve(R)){let I=new Z(R);I.load(),h=I.data()}}catch(I){console.error("Error creating entity with loader:",I)}p=new n(b,R,r?new r(h):null,a?new a(h):null),b.material&&p.withMaterial(b.material,s)}if(!p)throw new Error(`missing options for ${String(s)}, builder is not initialized.`);let m=p.build();return d!=null&&typeof d=="object"&&"position"in d&&(m._spawnPositionExplicit=!0),ie(m,b=>l(b))}import{Box3 as le,BufferAttribute as Vt,SkinnedMesh as Gt,MeshStandardMaterial as Ut,Group as Nt,Vector3 as M,Matrix4 as Ke}from"three";var B=class{async loadFile(e,t){switch(ve(e)){case"fbx":{let n=await G.loadFBX(e,t);return{object:n.object,animation:n.animations?.[0]}}case"gltf":case"glb":{let n=await G.loadGLTF(e,t);return{object:n.object,gltf:n.gltf}}case"obj":return{object:(await G.loadOBJ(e,t)).object};default:throw new Error(`Unsupported file type: ${e}`)}}};import{AnimationMixer as Bt,Bone as Ue,LoopOnce as Rt,LoopRepeat as Ft}from"three";function Tt(i){let e=i.lastIndexOf(".");return e>=0?i.slice(0,e):i}function Ne(i,e){if(!i?.name?.endsWith(".position"))return!1;let t=Tt(i.name),o=e.get(t);return o instanceof Ue?!(o.parent instanceof Ue):/hips\.position$/i.test(i.name)||/root\.position$/i.test(i.name)}function kt(i,e,t,o){for(let n of i.tracks){if(!Ne(n,e)||!n.values||n.values.length<3)continue;let s=n.values[0],r=o??n.values[1],a=n.values[2];for(let l=0;l<n.values.length;l+=3)n.values[l]=s,t&&(n.values[l+1]=r),n.values[l+2]=a}return i}function zt(i,e){for(let t of i.tracks)if(Ne(t,e)&&!(!t.values||t.values.length<3))return t.values[1];return null}var H=class{constructor(e){this.target=e}_mixer=null;_actions={};_animations=[];_currentAction=null;_pauseAtPercentage=0;_isPaused=!1;_queuedKey=null;_fadeDuration=.5;_currentKey="";_assetLoader=new B;async loadAnimations(e,t={}){if(!e.length)return;let o=t.stripRootMotionY??!1,n=t.referenceRootY,s=t.referenceAnimationPath,r=await Promise.all(e.map(c=>this._assetLoader.loadFile(c.path))),a=new Map;this.target.traverse(c=>{c.name&&a.set(c.name,c)});let l=[];if(r.forEach((c,u)=>{c.animation&&l.push({key:e[u].key||u.toString(),clip:c.animation,path:e[u].path})}),!l.length)return;let p=n;if(o&&p===void 0){let c=s?l.findIndex(m=>m.path===s):0,u=c>=0?[c,...l.map((m,g)=>g).filter(m=>m!==c)]:l.map((m,g)=>g);for(let m of u){let g=zt(l[m].clip,a);if(g!==null){p=g;break}}}let d=l.map(({key:c,clip:u})=>({key:c,clip:kt(u,a,o,p)}));this._animations=d.map(c=>c.clip),this._mixer=new Bt(this.target),d.forEach(({key:c,clip:u})=>{this._actions[c]=this._mixer.clipAction(u)}),this.playAnimation({key:d[0].key})}update(e){if(!this._mixer||!this._currentAction)return;this._mixer.update(e);let t=this._currentAction.getClip().duration*(this._pauseAtPercentage/100);if(!this._isPaused&&this._pauseAtPercentage>0&&this._currentAction.time>=t&&(this._currentAction.time=t,this._currentAction.paused=!0,this._isPaused=!0,this._queuedKey!==null)){let o=this._actions[this._queuedKey];o.reset().play(),this._currentAction.crossFadeTo(o,this._fadeDuration,!1),this._currentAction=o,this._currentKey=this._queuedKey,this._queuedKey=null}}playAnimation(e){if(!this._mixer)return;let{key:t,pauseAtPercentage:o=0,pauseAtEnd:n=!1,fadeToKey:s,fadeDuration:r=.5}=e;if(t===this._currentKey)return;let a=this._actions[t];if(!a)return;if(a===this._currentAction){this._currentKey=t;return}this._queuedKey=s||null,this._fadeDuration=r,this._pauseAtPercentage=n?100:o,this._isPaused=!1;let l=this._currentAction;this._pauseAtPercentage>0?(a.setLoop(Rt,1/0),a.clampWhenFinished=!0):(a.setLoop(Ft,1/0),a.clampWhenFinished=!1),a.reset().play(),l&&l.crossFadeTo(a,r,!1),this._currentAction=a,this._currentKey=t}dispose(){Object.values(this._actions).forEach(e=>{e.stop()}),this._mixer&&(this._mixer.stopAllAction(),this._mixer.uncacheRoot(this.target),this._mixer=null),this._actions={},this._animations=[],this._currentAction=null,this._currentKey=""}get currentAnimationKey(){return this._currentKey}get animations(){return this._animations}};import{BufferGeometry as It,Mesh as Ze,Color as Lt}from"three";import{Mesh as jt}from"three";var Y=class{_build(e,t,o){let n=new jt(t,o.at(-1));return n.position.set(0,0,0),n.castShadow=!0,n.receiveShadow=!0,n}_postBuild(){}};var W=class extends xe{},He=class extends Y{build(e){return new It}postBuild(){}},K=class{meshBuilder;collisionBuilder;materialBuilder;options;entity;constructor(e,t,o,n){this.options=e,this.entity=t,this.meshBuilder=o,this.collisionBuilder=n,this.materialBuilder=new Se;let s={meshBuilder:this.meshBuilder,collisionBuilder:this.collisionBuilder,materialBuilder:this.materialBuilder};this.options._builders=s,t&&t.options&&(t.options._builders=s)}withPosition(e){return this.options.position=e,this}withMaterial(e,t){return this.materialBuilder&&this.materialBuilder.build(e,t),this}applyMaterialToGroup(e,t){e.traverse(o=>{o instanceof Ze&&o.type==="SkinnedMesh"&&t[0]&&!o.material.map&&(o.material=t[0]),o.castShadow=!0,o.receiveShadow=!0})}build(){let e=this.entity;if(this.materialBuilder&&(e.materials=this.materialBuilder.materials),this.meshBuilder&&e.materials){let t=this.meshBuilder.build(this.options);e.mesh=this.meshBuilder._build(this.options,t,e.materials),this.meshBuilder.postBuild()}if(e.group&&e.materials&&this.applyMaterialToGroup(e.group,e.materials),this.collisionBuilder){this.collisionBuilder.withCollision(this.options?.collision||{});let[t,o]=this.collisionBuilder.build(this.options);e.bodyDesc=t,e.colliderDesc=o,e.colliderDescs.push(o);let{x:n,y:s,z:r}=f(this.options.position,v);e.bodyDesc.position=[n,s,r]}if(this.options.collisionType&&(e.collisionType=this.options.collisionType),this.options.color instanceof Lt){let t=o=>{let n=o;n&&n.color&&n.color.set&&n.color.set(this.options.color)};if(e.materials?.length)for(let o of e.materials)t(o);if(e.mesh&&e.mesh.material){let o=e.mesh.material;Array.isArray(o)?o.forEach(t):t(o)}e.group&&e.group.traverse(o=>{if(o instanceof Ze&&o.material){let n=o.material;Array.isArray(n)?n.forEach(t):t(n)}})}return e}};var Xe={...N,material:{shader:V},animations:[],models:[],collisionShape:"capsule"};function k(i){return L(i.scale,D)}var Zt=1e-4,Ht=/foot$/i,oe=new M,q=new M,Ye=new M,X=new M,We=new Ke;function Yt(i){let e=1/0,t=!1;return i.traverse(o=>{if(!o.isSkinnedMesh)return;let n=o,s=n.geometry,r=s.attributes.position,a=s.attributes.skinIndex,l=s.attributes.skinWeight,p=n.skeleton;if(!r||!a||!l||!p)return;t=!0,p.update(),n.updateMatrixWorld(!0);let d=p.boneMatrices;if(d)for(let c=0;c<r.count;c++){Ye.fromBufferAttribute(r,c).applyMatrix4(n.bindMatrix),X.set(0,0,0);for(let u=0;u<4;u++){let m=l.getComponent(c,u);if(m===0)continue;let g=a.getComponent(c,u);We.fromArray(d,g*16),X.addScaledVector(q.copy(Ye).applyMatrix4(We),m)}X.applyMatrix4(n.bindMatrixInverse).applyMatrix4(n.matrixWorld),e=Math.min(e,X.y)}}),!t||!Number.isFinite(e)?null:e}function Wt(i,e){e.updateMatrixWorld(!0);let t=e.getWorldPosition(oe).y,o=Yt(i)??1/0;if(i.traverse(n=>{!n.isBone||!Ht.test(n.name)||(n.getWorldPosition(oe),o=Math.min(o,oe.y))}),Number.isFinite(o)||i.traverse(n=>{if(!n.isSkinnedMesh)return;let s=n;if(s.computeBoundingBox(),!s.boundingBox)return;let{min:r,max:a}=s.boundingBox;for(let l of[[r.x,r.y,r.z],[r.x,r.y,a.z],[r.x,a.y,r.z],[r.x,a.y,a.z],[a.x,r.y,r.z],[a.x,r.y,a.z],[a.x,a.y,r.z],[a.x,a.y,a.z]])q.set(l[0],l[1],l[2]),q.applyMatrix4(s.matrixWorld),o=Math.min(o,q.y)}),!Number.isFinite(o)){let n=new le().setFromObject(i);if(n.isEmpty())return null;o=n.min.y}return o-t}function Kt(i,e,t){return i.stripRootMotionY!==void 0?i.stripRootMotionY:!!(e&&t.some(o=>o===e))}function j(i){let e=i.collision?.position;return e?f(e,v):null}function ne(i){return!!i.collision?.size}function Xt(i){i.hasWarnedDynamicTrimesh||(i.hasWarnedDynamicTrimesh=!0,console.warn(`Actor "${i.name||i.uuid}" requested collisionShape="trimesh" on a dynamic body; falling back to bounds.`))}function $e(i,e,t){let o=i==="model"?"bounds":i??"capsule";return o==="trimesh"&&!e?(t?.(),"bounds"):o}function qe(i,e){let t=i.x||.5,o=i.y||1,n=i.z||.5,s=Math.max(t,n)/2,r=o/2;return{shape:{type:"capsule",halfHeight:Math.max(0,r-s),radius:s},offset:[e.x,e.y,e.z],sensor:!1}}function w(i){let e=f(i.collision?.size??i.size,{x:.5,y:1,z:.5}),t=e.y||1,o=j(i);return qe({x:e.x||.5,y:t,z:e.z||.5},o??{x:0,y:t/2,z:0})}function Je(i){let e=i.collision?.size;if(!e)return null;let t=f(e,v),o=t.x/2,n=t.y/2,s=t.z/2,r=j(i);return{shape:{type:"box",halfExtents:[o,n,s]},offset:[r?.x??0,r?.y??n,r?.z??0],sensor:!1}}function Qe(i,e,t){let n=e.matrixWorld.clone().invert().multiply(i.matrixWorld);return new Ke().makeScale(t.x,t.y,t.z).multiply(n)}function se(i,e,t){i.updateMatrixWorld(!0);let o=!1,n=new le;if(i.traverse(a=>{if(!a.isMesh)return;let l=a,p=l.geometry;if(!p)return;let d=null;if(l instanceof Gt?(l.computeBoundingBox(),d=l.boundingBox?.clone()??null):(p.computeBoundingBox(),d=p.boundingBox?.clone()??null),!d)return;let c=d.applyMatrix4(Qe(l,e,t));if(!o){n.copy(c),o=!0;return}n.union(c)}),!o||n.isEmpty())return null;let s=new M,r=new M;return n.getSize(s),n.getCenter(r),{size:s,center:r}}function $t(i,e,t){i.updateMatrixWorld(!0);let o=[],n=[],s=new le,r=new M,a=!1;if(i.traverse(p=>{if(!p.isMesh)return;let d=p,c=d.geometry;if(!c)return;let u=c.getAttribute("position");if(!(u instanceof Vt))return;let m=Qe(d,e,t),g=o.length/3;for(let h=0;h<u.count;h++)r.set(u.getX(h),u.getY(h),u.getZ(h)),r.applyMatrix4(m),o.push(r.x,r.y,r.z),s.expandByPoint(r);let b=c.getIndex();if(b)for(let h=0;h<b.count;h++)n.push(g+b.getX(h));else for(let h=0;h<u.count;h++)n.push(g+h);a=!0}),!a||o.length===0||n.length===0)return null;let l=new M;return s.getCenter(l),{vertices:new Float32Array(o),indices:new Uint32Array(n),center:l}}function et(i,e,t){let o=Je(t);if(o)return o;if(!i||!e)return w(t);let n=se(i,e,k(t));if(!n)return w(t);let s=j(t);return{shape:{type:"box",halfExtents:[n.size.x/2,n.size.y/2,n.size.z/2]},offset:[s?.x??n.center.x,s?.y??n.center.y,s?.z??n.center.z],sensor:!1}}function tt(i,e,t,o,n){if(ne(n)||!i||!e)return w(n);let s=se(i,e,k(n));if(!s)return w(n);let a=j(n);if(!a){let l=t&&o?se(t,o,k(n)):null;a=l?{x:l.center.x,y:l.center.y,z:l.center.z}:{x:s.center.x,y:s.center.y,z:s.center.z}}return qe({x:s.size.x,y:s.size.y,z:s.size.z},a)}function it(i,e,t){let o=Je(t);if(o)return o;if(!i||!e)return w(t);let n=$t(i,e,k(t));if(!n)return w(t);let s=j(t);return{shape:{type:"trimesh",vertices:n.vertices,indices:n.indices},offset:s?[s.x-n.center.x,s.y-n.center.y,s.z-n.center.z]:[0,0,0],sensor:!1}}function $(i){i&&i.traverse(e=>{if(!e.isMesh)return;let t=e;t.geometry?.dispose(),Array.isArray(t.material)?t.material.forEach(o=>o.dispose()):t.material?.dispose()})}var re=class extends W{objectModel=null;collisionSource=null;collisionShape="capsule";constructor(e){super(),this.objectModel=e.objectModel,this.collisionSource=e.collisionSource??e.objectModel??null,this.collisionShape=e.collisionShape??"capsule"}collider(e){let t=$e(this.collisionShape,!!e.collision?.static);return t==="bounds"?et(this.objectModel,this.objectModel,e):t==="trimesh"?it(this.objectModel,this.objectModel,e):tt(this.collisionSource,this.collisionSource,this.objectModel,this.objectModel,e)}},ae=class extends K{createEntity(e){return new z(e)}},qt=Symbol("Actor"),z=class extends P{static type=qt;_object=null;_collisionSource=null;_animationDelegate=null;_modelFileNames=[];_assetLoader=new B;_loadGeneration=0;_loadStatus="idle";controlledRotation=!1;hasWarnedDynamicTrimesh=!1;constructor(e){super(),this.options=S(Xe,e),this.prependUpdate(this.actorUpdate.bind(this)),this.controlledRotation=!0}create(){return this._loadStatus==="idle"&&(this.options.models?.length??0)>0&&this.load(),super.create()}load(){this._loadStatus==="loading"||this._loadStatus==="loaded"||(this._modelFileNames=[...this.options.models||[]],this._modelFileNames.length!==0&&(this.disposeRuntimeState(!0),this._loadStatus="loading",this.loadModelsDeferred(++this._loadGeneration)))}data(){return{animations:this._animationDelegate?.animations,objectModel:this._object,collisionSource:this._collisionSource??this._object,collisionShape:this.options.collisionShape}}needsDeferredModelCollision(){return this.requiresLoadedCollisionSource()?!this.getRuntimeCollisionSource():!1}synchronizeRuntimeCollider(){let e=this.getResolvedCollisionShape(),t;if(e==="bounds")t=et(this._object,this.group??this._object,this.options);else if(e==="trimesh")t=it(this._object,this.group??this._object,this.options);else{let o=this.getRuntimeCollisionSource();t=tt(o,o,this._object,this._object,this.options)}this.colliderDesc=t,this.colliderDescs.length>0?this.colliderDescs[0]=t:this.colliderDescs.push(t)}actorUpdate(e){this._animationDelegate?.update(e.delta)}actorDestroy(){this._loadGeneration+=1,this._loadStatus="idle",this.disposeRuntimeState(!0),this._modelFileNames=[]}_cleanup(e){super._cleanup(e),this.actorDestroy()}playAnimation(e){this._animationDelegate?.playAnimation(e)}get object(){return this._object}get collisionSource(){return this._collisionSource??this._object}getDebugInfo(){let e={type:"Actor",models:this._modelFileNames.length>0?this._modelFileNames:"none",modelLoaded:!!this._object,scale:(()=>{let t=f(this.options.scale,D);return`${t.x}, ${t.y}, ${t.z}`})(),collisionShape:this.getResolvedCollisionShape()};if(this._animationDelegate&&(e.currentAnimation=this._animationDelegate.currentAnimationKey||"none",e.animationsCount=this.options.animations?.length||0),this._object){let t=0,o=0;this._object.traverse(n=>{if(!n.isMesh)return;t++;let s=n.geometry;s?.attributes.position&&(o+=s.attributes.position.count)}),e.meshCount=t,e.vertexCount=o}return e}getResolvedCollisionShape(){return $e(this.options.collisionShape,!!this.options.collision?.static,()=>Xt(this))}requiresLoadedCollisionSource(){let e=this.getResolvedCollisionShape();return e==="bounds"||e==="trimesh"?!ne(this.options):e==="capsule"?!ne(this.options)&&this.getCollisionSourceSelection().file!==null:!1}getRuntimeCollisionSource(){let e=this.getResolvedCollisionShape();return e==="bounds"||e==="trimesh"?this._object:this._collisionSource??this._object}getCollisionSourceSelection(){let e=this.options.models?.[0]??null,t=this.options.animations?.[0]?.path??null;return t?{file:t,reuseVisibleModel:t===e}:{file:e,reuseVisibleModel:!0}}disposeRuntimeState(e){this._animationDelegate&&(this._animationDelegate.dispose(),this._animationDelegate=null);let t=this._collisionSource;$(this._object),t&&t!==this._object&&$(t),this._object=null,this._collisionSource=null,e&&this.group&&(this.group.clear(),this.group=void 0)}loadModelsDeferred(e){this.dispatch("entity:model:loading",{entityId:this.uuid,files:this._modelFileNames});let t=this.getCollisionSourceSelection(),o=this._modelFileNames.map(s=>this._assetLoader.loadFile(s,{clone:!0})),n=t.file&&!t.reuseVisibleModel?this._assetLoader.loadFile(t.file,{clone:!0}):Promise.resolve(null);Promise.all([Promise.all(o),n]).then(([s,r])=>{if(e!==this._loadGeneration){s.forEach(l=>$(l.object??null)),r?.object&&$(r.object);return}this._object=s[0]?.object??null,this._collisionSource=t.reuseVisibleModel?this._object:r?.object??this._object,this._loadStatus=this._object?"loaded":"idle";let a=0;if(this._object){this._object.traverse(u=>{u.isMesh&&a++}),this.group=new Nt,this.group.add(this._object),this.group.scale.copy(k(this.options)),ke(this),this.applyMaterialOverrides(),this._animationDelegate=new H(this._object);let l=this.options.animations||[],p=this.options.models?.[0],d=l.map(u=>u.path),c=Kt(this.options,p,d);l.length>0?this._animationDelegate.loadAnimations(l,{stripRootMotionY:c,referenceAnimationPath:p}).then(()=>{e===this._loadGeneration&&(this.alignVisualModelToGround(),this.dispatch("entity:animation:loaded",{entityId:this.uuid,animationCount:l.length}))}):this.alignVisualModelToGround()}this.dispatch("entity:model:loaded",{entityId:this.uuid,success:!!this._object,meshCount:a})}).catch(s=>{e===this._loadGeneration&&(this._loadStatus="idle",console.error("Failed to load actor model",s),this.dispatch("entity:model:loaded",{entityId:this.uuid,success:!1,meshCount:0,errorMessage:s instanceof Error?s.message:String(s)}))})}alignVisualModelToGround(){if(!this._object||!this.group)return;this._animationDelegate?.update(0),this._object.updateMatrixWorld(!0);let e=Wt(this._object,this.group);if(e===null||Math.abs(e)<Zt)return;let t=this.group.scale.y||1;this._object.position.y-=e/t}applyMaterialOverrides(){let e=this.options.material;!e||!e.color&&!e.path&&e.opacity===void 0||this._object&&this._object.traverse(t=>{if(!t.isMesh)return;let o=t;o.material=Array.isArray(o.material)?o.material.map(n=>this.tintMaterial(n,e)):this.tintMaterial(o.material,e),e.color&&(o.castShadow=!0,o.receiveShadow=!0)})}tintMaterial(e,t){let o="color"in e,n=!!t.color,s=t.opacity!==void 0;if(!n&&!s)return e;if(n&&!o)return new Ut({color:t.color,emissiveIntensity:.5,lightMapIntensity:.5,fog:!0,opacity:t.opacity??1,transparent:s&&t.opacity<1});let r=e.clone();if(n&&"color"in r&&r.color.copy(t.color),s&&"opacity"in r&&"transparent"in r){let a=r;a.opacity=t.opacity,a.transparent=t.opacity<1}return r.needsUpdate=!0,r}};function Jt(...i){return Ge({args:i,defaultConfig:Xe,EntityClass:z,BuilderClass:ae,CollisionBuilderClass:re,entityType:z.type,cloneFactory:e=>Jt(e??{})})}import{Color as li,Fog as ci,FogExp2 as ui,Group as pi}from"three";import{Color as Qt}from"three";import{Fn as nt,fog as ei,positionWorld as ot,positionView as ti,uniform as x,float as ii,vec3 as O,clamp as ce,mix as E,max as oi,smoothstep as ni,floor as si,fract as ue,dot as ri}from"three/tsl";var J=class{values;u={time:x(0),heightEnabled:x(0),heightLevel:x(0),heightFalloff:x(0),noiseEnabled:x(0),noiseScale:x(0),noiseStrength:x(0),noiseSpeed:x(0)};attachedScene=null;constructor(e){this.values={...e},this.syncUniforms()}setValues(e){Object.assign(this.values,e),this.syncUniforms()}tick(e){this.values.time+=e,this.u.time.value=this.values.time}scan(e){if(this.attachedScene===e)return;let t=e.fog;t&&(e.fogNode=this.buildFogNode(t),this.attachedScene=e)}unpatchAll(){this.attachedScene&&(this.attachedScene.fogNode=null,this.attachedScene=null)}syncUniforms(){this.u.time.value=this.values.time,this.u.heightEnabled.value=this.values.heightEnabled,this.u.heightLevel.value=this.values.heightLevel,this.u.heightFalloff.value=this.values.heightFalloff,this.u.noiseEnabled.value=this.values.noiseEnabled,this.u.noiseScale.value=this.values.noiseScale,this.u.noiseStrength.value=this.values.noiseStrength,this.u.noiseSpeed.value=this.values.noiseSpeed}buildFogNode(e){let t=e.isFogExp2===!0,o=x(new Qt(e.color)),n=ti.z.negate(),s=t?this.exp2Factor(x(e.density),n):ni(x(e.near),x(e.far),n),r=this.u.heightLevel.sub(ot.y),a=ce(r.mul(oi(this.u.heightFalloff,0)),0,1),l=E(s,s.mul(a),this.u.heightEnabled),p=ot.mul(this.u.noiseScale).add(O(this.u.time.mul(this.u.noiseSpeed),0,this.u.time.mul(this.u.noiseSpeed).mul(.5))),c=ai(p).sub(.5).mul(2).mul(ce(this.u.noiseStrength,0,1)),u=ce(l.add(l.mul(c)),0,1),m=E(l,u,this.u.noiseEnabled);return ei(o,m)}exp2Factor(e,t){return e.mul(e).mul(t).mul(t).negate().exp().oneMinus()}},A=nt(([i])=>{let e=ue(i.mul(O(443.8975,397.2973,491.1871))),t=e.add(ri(e,e.yzx.add(19.27)));return ue(t.x.add(t.y).mul(t.z))}),ai=nt(([i])=>{let e=si(i),t=ue(i),o=t.mul(t).mul(ii(3).sub(t.mul(2))),n=A(e.add(O(0,0,0))),s=A(e.add(O(1,0,0))),r=A(e.add(O(0,1,0))),a=A(e.add(O(1,1,0))),l=A(e.add(O(0,0,1))),p=A(e.add(O(1,0,1))),d=A(e.add(O(0,1,1))),c=A(e.add(O(1,1,1))),u=E(n,s,o.x),m=E(r,a,o.x),g=E(l,p,o.x),b=E(d,c,o.x),h=E(u,m,o.y),R=E(g,b,o.y);return E(h,R,o.z)});var di=Symbol("Fog"),hi="#9aa3ad",mi=.015,fi=10,yi=250,bi=5,gi=.2,Ci=.05,xi=.15,vi=.1,pe=class extends P{static type=di;threeFog=null;attachedScene=null;patcher;patcherEnabled;constructor(e={}){super(),this.options={...e};let t=this.resolveUniformValues(this.options);this.patcher=new J(t),this.patcherEnabled=Oi(this.options)}create(){return super.create(),this.threeFog=Si(this.options),this.group=new pi,this.group.name=this.name?`Fog:${this.name}`:"Fog",this}attachToScene(e){this.threeFog&&(this.attachedScene=e,e.fog=this.threeFog,this.patcherEnabled&&this.patcher.scan(e))}_update(e){super._update(e),!(!this.attachedScene||!this.patcherEnabled)&&(this.patcher.tick(e.delta),this.patcher.scan(this.attachedScene))}_cleanup(e){this.patcher.unpatchAll(),this.attachedScene&&this.attachedScene.fog===this.threeFog&&(this.attachedScene.fog=null),this.attachedScene=null,this.threeFog=null,super._cleanup(e)}resolveUniformValues(e){let t=e.height,o=e.noise;return{time:0,heightEnabled:t?.enabled?1:0,heightLevel:t?.level??bi,heightFalloff:t?.falloff??gi,noiseEnabled:o?1:0,noiseScale:o?.scale??Ci,noiseStrength:o?.strength??xi,noiseSpeed:o?.speed??vi}}};function Si(i){let e=new li(i.color??hi);return(i.type??"linear")==="exp2"?new ui(e,i.density??mi):new ci(e,i.start??fi,i.end??yi)}function Oi(i){let e=!!i.height?.enabled,t=!!i.noise;return e||t}function _n(i={}){return new pe(i)}export{C as a,S as b,lt as c,ct as d,ut as e,pt as f,dt as g,ht as h,mt as i,ft as j,Re as k,Hi as l,Yi as m,Wi as n,ke as o,N as p,eo as q,P as r,wt as s,ie as t,Ge as u,W as v,He as w,K as x,qt as y,z,Jt as A,di as B,pe as C,_n as D};
@@ -0,0 +1 @@
1
+ import{b as a}from"./chunk-EVYHPR3J.js";import{c as r,d as u,h as t}from"./chunk-7WRQ2UAN.js";import{StageBodyKind as T,StageBoundaryDim as V,StageEventType as F,StageRicochetDim as H,StageRicochetReflection as z,StageTopDownPlane as A,createSimulation as I}from"@zylem/behaviors/core";import{StageBodyKind as g}from"@zylem/behaviors/core";var n={kind:g.Dynamic,position:[0,0,0],rotation:[0,0,0,1],linearDamping:0,angularDamping:0,gravityScale:1,canSleep:!1,ccdEnabled:!0,lockRotation:[!1,!1,!1],lockTranslation:[!1,!1,!1]};function c(e={}){let i=t(e.position,r);return{kind:e.kind??n.kind,position:[i.x,i.y,i.z],rotation:e.rotation??n.rotation,linearDamping:e.linearDamping??n.linearDamping,angularDamping:e.angularDamping??n.angularDamping,gravityScale:e.gravityScale??n.gravityScale,canSleep:e.canSleep??n.canSleep,ccdEnabled:e.ccdEnabled??n.ccdEnabled,lockRotation:e.lockRotation??n.lockRotation,lockTranslation:e.lockTranslation??n.lockTranslation}}function l(e,i){let o=t(i.offset,r);return{shape:e,offset:[o.x,o.y,o.z],friction:i.friction??.5,restitution:i.restitution??0,sensor:i.sensor??!1,collisionGroups:a(i.collisionType,i.collisionFilter)}}function p(e,i={}){let o=t(e,u);return l({type:"box",halfExtents:[o.x/2,o.y/2,o.z/2]},i)}function C(e,i={}){return l({type:"sphere",radius:e},i)}function s(e,i,o={}){return l({type:"capsule",halfHeight:e,radius:i},o)}function f(e,i,o={}){return l({type:"cylinder",halfHeight:e,radius:i},o)}function y(e,i={}){return l({type:"convexHull",vertices:e},i)}function S(e,i,o={}){return l({type:"trimesh",vertices:e,indices:i},o)}function b(e,i,o,d,m={}){return l({type:"heightfield",rows:e,cols:i,heights:o,scale:d},m)}function R(e,i){return{body:e,colliders:i}}export{c as a,p as b,C as c,s as d,f as e,y as f,S as g,b as h,R as i,T as j,V as k,F as l,H as m,z as n,A as o,I as p};
@@ -0,0 +1 @@
1
+ function n(r,t){let e=t-r;for(;e>Math.PI;)e-=2*Math.PI;for(;e<-Math.PI;)e+=2*Math.PI;return e}function a(r,t,e=45){let o=e*Math.PI/180;return{targetYaw:-r*o,targetPitch:-t*o}}function m(r,t,e,o,s={}){let{targetYaw:i,targetPitch:c}=a(r,t,s.maxLookDegrees??45),u=s.lookSensitivity??2;return{lookX:n(e,i)/u,lookY:n(o,c)/u}}export{n as a,a as b,m as c};
@@ -0,0 +1 @@
1
+ import{a as n}from"./chunk-QXVH6POE.js";var s=class{emitter;unsubscribes=[];constructor(){this.emitter=n()}dispatch(e,t){this.emitter.emit(e,t)}listen(e,t){this.emitter.on(e,t);let i=()=>this.emitter.off(e,t);return this.unsubscribes.push(i),i}listenAll(e){this.emitter.on("*",e);let t=()=>this.emitter.off("*",e);return this.unsubscribes.push(t),t}dispose(){this.unsubscribes.forEach(e=>e()),this.unsubscribes=[],this.emitter.all.clear()}};var o=n();export{s as a,o as b};
@@ -0,0 +1 @@
1
+ import{Box3 as d,PerspectiveCamera as h,Vector3 as a}from"three";var m=new d,s=new a,x=new a,p=new a;function u(c){m.setFromObject(c),m.getSize(s),m.getCenter(x);let t=Math.max(s.x,1e-4),o=Math.max(s.y,1e-4),n=Math.max(s.z,1e-4),e=Math.max(t,o,n);return{width:t,height:o,depth:n,center:x.clone(),maxDim:e}}function b(c,t,o=1.35){let n=t.fov*(Math.PI/180),e=c/(2*Math.tan(n/2))*o;return Math.max(e,.5)}function j(c,t,o=1.35){let n=u(c),e=b(n.maxDim,t,o);return t.position.copy(n.center).add(new a(e,e,e)),t.lookAt(n.center),t.near=Math.max(e/100,.01),t.far=Math.max(e*20,100),t.updateProjectionMatrix(),n}function M(c,t,o,n=1.5){let e=u(c),r=p.copy(o);r.lengthSq()<1e-8&&r.set(1,1,1),r.normalize();let i=e.maxDim*n;return t instanceof h&&(i=b(e.maxDim,t,n),t.near=Math.max(i/100,.01),t.far=Math.max(i*20,100),t.updateProjectionMatrix()),t.position.copy(e.center).addScaledVector(r,i),t.lookAt(e.center),e}export{j as a,M as b};
@@ -0,0 +1 @@
1
+ import{a as P}from"./chunk-LGS5N5M4.js";import{a as Dt,b as Z,c as Y,d as N,e as W,f as X,g as U,h as j,j as q,p as m,q as w,r as c,t as x,u as R,v as $,w as K,x as D}from"./chunk-3I537JFL.js";import{j as kt}from"./chunk-CM5YRNBJ.js";import{d as V,j as Rt}from"./chunk-4QLJUQSJ.js";import{a as It,b as gt,c as zt,d as Lt,g as Bt,h as xt,i as E,j as Ht}from"./chunk-7WRQ2UAN.js";import{Vector3 as Fe}from"three";import{BoxGeometry as ze,CapsuleGeometry as Le,ConeGeometry as Ft,CylinderGeometry as Be,Mesh as I,MeshStandardMaterial as He,SphereGeometry as ke}from"three";function z(i,t=Symbol("mesh")){if(i.material||i.color){let e=new kt;if(e.build({...i.material,color:i.color??i.material?.color},t),e.materials.length>0)return e.materials}return[new He]}function L(i,t){if(t.position){let e=xt(t.position,zt);i.position.set(e.x,e.y,e.z)}return i.castShadow=!0,i.receiveShadow=!0,i}function Q(i={}){let t=xt(i.size,Lt),e=new ze(t.x,t.y,t.z),o=z(i);return L(new I(e,o.at(-1)),i)}function J(i={}){let t=new ke(i.radius??1),e=z(i);return L(new I(t,e.at(-1)),i)}function tt(i={}){let t=new Ft(i.radius??1,i.height??2,i.radialSegments??32),e=z(i);return L(new I(t,e.at(-1)),i)}function et(i={}){let t=new Ft(i.radius??1,i.height??2,4),e=z(i);return L(new I(t,e.at(-1)),i)}function it(i={}){let t=new Be(i.radiusTop??1,i.radiusBottom??1,i.height??2,i.radialSegments??32),e=z(i);return L(new I(t,e.at(-1)),i)}function ot(i={}){let t=new Le(i.radius??.5,i.length??1,i.capSegments??10,i.radialSegments??20),e=z(i);return L(new I(t,e.at(-1)),i)}var Gt={...m,size:new Fe(1,1,1)},At=Symbol("Box"),nt=class i extends c{static type=At;constructor(t){super(),this.options={...Gt,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),{x:o,y:n,z:s}=this.options.size??{x:1,y:1,z:1};return{...e,type:String(i.type),size:`${o}, ${n}, ${s}`}}};function Vt(...i){let t=w(i,Gt),e=new nt(t);return e.add(Q({size:t.size,material:t.material,color:t.color}),Y({size:t.size,static:t.collision?.static,sensor:t.collision?.sensor,canSleep:t.collision?.canSleep,ccdEnabled:t.collision?.ccdEnabled,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Vt(o??{}))}var Yt={...m,radius:1},Nt=Symbol("Sphere"),st=class i extends c{static type=Nt;constructor(t){super(),this.options={...Yt,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1;return{...e,type:String(i.type),radius:o.toFixed(2)}}};function Wt(...i){let t=w(i,Yt),e=new st(t);return e.add(J({radius:t.radius,material:t.material,color:t.color}),N({radius:t.radius,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Wt(o??{}))}import{PlaneGeometry as Ae,Vector2 as Xt,Vector3 as Ut}from"three";import{BufferGeometry as Ge,Float32BufferAttribute as bt}from"three";var rt=class i extends Ge{constructor(t=1,e=1,o=1,n=1){super(),this.type="XZPlaneGeometry",this.parameters={width:t,height:e,widthSegments:o,heightSegments:n};let s=t/2,a=e/2,r=Math.floor(o),l=Math.floor(n),p=r+1,O=l+1,u=t/r,d=e/l,b=[],f=[],y=[],_=[];for(let g=0;g<O;g++){let h=g*d-a;for(let C=0;C<p;C++){let T=C*u-s;f.push(T,0,h),y.push(0,1,0),_.push(C/r),_.push(1-g/l)}}for(let g=0;g<l;g++)for(let h=0;h<r;h++){let C=h+p*g,T=h+p*(g+1),S=h+1+p*(g+1),v=h+1+p*g;b.push(C,T,v),b.push(T,S,v)}this.setIndex(b),this.setAttribute("position",new bt(f,3)),this.setAttribute("normal",new bt(y,3)),this.setAttribute("uv",new bt(_,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new i(t.width,t.height,t.widthSegments,t.heightSegments)}};var at=4,jt={...m,tile:new Xt(10,10),repeat:new Xt(1,1),collision:{static:!0},subdivisions:at,randomizeHeight:!1,heightScale:1};function qt(i){let t=i.subdivisions??at,e=i.heightMap2D,o=i.heightMap,n=i.subdivisionsX??t,s=i.subdivisionsZ??t;return e&&e.length>0&&e[0]?.length>0?(s=e.length-1,n=e[0].length-1):o&&o.length>0&&(n=o.length-1),{subdivisionsX:n,subdivisionsZ:s}}var Ot=class extends ${collider(t){let e=E(t.tile,gt),{subdivisionsX:o,subdivisionsZ:n}=qt(t),s=new Ut(e.x,1,e.y),a=t._builders?.meshBuilder?.heightData??new Float32Array((o+1)*(n+1));return{shape:{type:"heightfield",rows:o,cols:n,heights:a,scale:[s.x,1,s.z]}}}},Pt=class extends K{heightData=new Float32Array;columnsRows=new Map;subdivisionsX=at;subdivisionsZ=at;build(t){let e=E(t.tile,gt),{subdivisionsX:o,subdivisionsZ:n}=qt(t);this.subdivisionsX=o,this.subdivisionsZ=n;let s=new Ut(e.x,1,e.y),a=t.heightScale??1,r=new rt(s.x,s.z,o,n),l=new Ae(s.x,s.z,o,n),p=o>0?s.x/o:1,O=n>0?s.z/n:1,u=r.attributes.position.array,d=l.attributes.position.array,b=new Map,f=t.heightMap2D,y=t.heightMap,_=t.randomizeHeight??!1,g=(h,C)=>h<0?0:h>C?C:h;for(let h=0;h<d.length;h+=3){let C=d[h],T=d[h+1],S=g(Math.round((C+s.x/2)/p),o),v=g(Math.round((s.z/2-T)/O),n),M=0;if(f){let Mt=f[v];Mt&&(M=Mt[S]??0)}else y&&y.length>0?M=y[S]??0:_&&(M=Math.random()*4);let G=M*a;d[h+2]=G,u[h+1]=G,b.get(v)||b.set(v,new Map),b.get(v).set(S,G)}return this.columnsRows=b,r}postBuild(){let t=[];for(let e=0;e<=this.subdivisionsX;++e)for(let o=0;o<=this.subdivisionsZ;++o){let n=this.columnsRows.get(o);t.push(n?.get(e)??0)}this.heightData=new Float32Array(t)}},St=class extends D{createEntity(t){return new B(t)}},$t=Symbol("Plane"),B=class extends c{static type=$t;constructor(t){super(),this.options=Z(jt,t)}};function Kt(...i){return R({args:i,defaultConfig:jt,EntityClass:B,BuilderClass:St,MeshBuilderClass:Pt,CollisionBuilderClass:Ot,entityType:B.type,cloneFactory:t=>Kt(t??{})})}import{Vector3 as Ve}from"three";var Qt={...m,size:new Ve(1,1,1),collision:{static:!0}},Jt=Symbol("Zone"),lt=class extends c{static type=Jt;_enteredZone=new Map;_exitedZone=new Map;_zoneEntities=new Map;constructor(t){super(),this.options=Z(Qt,t)}handlePostCollision({delta:t}){return this._enteredZone.forEach((e,o)=>{this.exited(t,o)}),this._enteredZone.size>0}handleIntersectionEvent({other:t,delta:e}){this._enteredZone.get(t.uuid)?this.held(e,t):(this.entered(t),this._zoneEntities.set(t.uuid,t))}onEnter(t){return this.options.onEnter=t,this}onHeld(t){return this.options.onHeld=t,this}onExit(t){return this.options.onExit=t,this}entered(t){this._enteredZone.set(t.uuid,1),this.options.onEnter&&this.options.onEnter({self:this,visitor:t,globals:V.globals})}exited(t,e){let o=this._exitedZone.get(e);if(o&&o>1+t){this._exitedZone.delete(e),this._enteredZone.delete(e);let n=this._zoneEntities.get(e);this.options.onExit&&this.options.onExit({self:this,visitor:n,globals:V.globals});return}this._exitedZone.set(e,1+t)}held(t,e){let o=this._enteredZone.get(e.uuid)??0;this._enteredZone.set(e.uuid,o+t),this._exitedZone.set(e.uuid,1),this.options.onHeld&&this.options.onHeld({delta:t,self:this,visitor:e,globals:V.globals,heldTime:o})}};function te(...i){let t=w(i,Qt),e=new lt(t);return e.add(q({size:t.size,static:t.collision?.static??!0,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>te(o??{}))}import{Color as ee,Group as Ye,Sprite as Ne,SpriteMaterial as We,CanvasTexture as ie,LinearFilter as ct,Vector2 as pt,ClampToEdgeWrapping as oe,ShaderMaterial as ne,Mesh as Xe,PlaneGeometry as Ue,Vector3 as se}from"three";var H={position:void 0,width:120,height:48,fillColor:"#FFFFFF",strokeColor:null,strokeWidth:0,radius:0,padding:0,stickToViewport:!0,screenPosition:new pt(24,24),zDistance:1,anchor:new pt(0,0)},wt=class extends D{createEntity(t){return new k(t)}},re=Symbol("Rect"),k=class i extends c{static type=re;_sprite=null;_mesh=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=Z(H,t),this.options.screenPosition=E(this.options.screenPosition,H.screenPosition),this.options.anchor=E(this.options.anchor,H.anchor),this.group=new Ye,this.createSprite(),this.prependSetup(this.rectSetup.bind(this)),this.prependUpdate(this.rectUpdate.bind(this))}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new ie(this._canvas),this._texture.minFilter=ct,this._texture.magFilter=ct;let t=new We({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new Ne(t),this.group?.add(this._sprite),this.redrawRect()}redrawRect(){if(!this._canvas||!this._ctx)return;let t=Math.max(2,Math.floor(this.options.width??120)),e=Math.max(2,Math.floor(this.options.height??48)),o=this.options.padding??0,n=this.options.strokeWidth??0,s=t+o*2+n,a=e+o*2+n,r=Math.max(2,s),l=Math.max(2,a),p=r!==this._lastCanvasW||l!==this._lastCanvasH;this._canvas.width=r,this._canvas.height=l,this._lastCanvasW=r,this._lastCanvasH=l,this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height);let O=Math.max(0,this.options.radius??0),u=Math.floor(o+n/2),d=Math.floor(o+n/2),b=Math.floor(t),f=Math.floor(e);if(this._ctx.beginPath(),O>0?this.roundedRectPath(this._ctx,u,d,b,f,O):this._ctx.rect(u,d,b,f),this.options.fillColor&&(this._ctx.fillStyle=this.toCssColor(this.options.fillColor),this._ctx.fill()),this.options.strokeColor&&n>0&&(this._ctx.lineWidth=n,this._ctx.strokeStyle=this.toCssColor(this.options.strokeColor),this._ctx.stroke()),this._texture){if(p&&(this._texture.dispose(),this._texture=new ie(this._canvas),this._texture.minFilter=ct,this._texture.magFilter=ct,this._texture.wrapS=oe,this._texture.wrapT=oe,this._sprite&&this._sprite.material instanceof ne)){let y=this._sprite.material;y.uniforms?.tDiffuse&&(y.uniforms.tDiffuse.value=this._texture),y.uniforms?.iResolution&&y.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)}this._texture.image=this._canvas,this._texture.needsUpdate=!0,this._sprite&&this._sprite.material&&(this._sprite.material.map=this._texture,this._sprite.material.needsUpdate=!0)}}getWidth(){return this.options.width??0}getHeight(){return this.options.height??0}roundedRectPath(t,e,o,n,s,a){let r=Math.min(a,Math.floor(Math.min(n,s)/2));t.moveTo(e+r,o),t.lineTo(e+n-r,o),t.quadraticCurveTo(e+n,o,e+n,o+r),t.lineTo(e+n,o+s-r),t.quadraticCurveTo(e+n,o+s,e+n-r,o+s),t.lineTo(e+r,o+s),t.quadraticCurveTo(e,o+s,e,o+s-r),t.lineTo(e,o+r),t.quadraticCurveTo(e,o,e+r,o)}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof ee?t:new ee(t)).getHexString()}`}getResolution(){try{let t=this._cameraRef?.renderer?.domElement;if(t)return{width:t.clientWidth||1,height:t.clientHeight||1}}catch{}return{width:this._cameraRef?.screenResolution?.x??1,height:this._cameraRef?.screenResolution?.y??1}}rectSetup(t){if(this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&this._cameraRef.camera.add(this.group),this.materials?.length&&this._sprite){let e=this.materials[0];e instanceof ne&&(e.transparent=!0,e.depthTest=!1,e.depthWrite=!1,this._texture&&(e.uniforms?.tDiffuse&&(e.uniforms.tDiffuse.value=this._texture),e.uniforms?.iResolution&&this._canvas&&e.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)),this._mesh=new Xe(new Ue(1,1),e),this.group?.add(this._mesh),this._sprite.visible=!1)}}rectUpdate(t){if(this._sprite){if(this._cameraRef&&this.options.bounds){let e=this.computeScreenBoundsFromOptions(this.options.bounds);if(e){let{x:o,y:n,width:s,height:a}=e,r=Math.max(2,Math.floor(s)),l=Math.max(2,Math.floor(a)),p=r!==(this.options.width??0)||l!==(this.options.height??0);this.options.screenPosition=new pt(Math.floor(o),Math.floor(n)),this.options.width=r,this.options.height=l,this.options.anchor=new pt(0,0),p&&this.redrawRect()}}this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:o}=this.getResolution(),n=E(this.options.screenPosition,H.screenPosition),s=n.x,a=n.y,r=Math.max(.001,this.options.zDistance??1),l=1,p=1;if(t.isPerspectiveCamera){let S=t,v=Math.tan(S.fov*Math.PI/180/2)*r;l=v*S.aspect,p=v}else if(t.isOrthographicCamera){let S=t;l=(S.right-S.left)/2,p=(S.top-S.bottom)/2}let O=s/e*2-1,u=1-a/o*2,d=O*l,b=u*p,f=1,y=1;if(this._canvas){let v=p*2/o,M=this._canvas.height;y=Math.max(1e-4,M*v);let G=this._canvas.width/this._canvas.height;f=y*G,this._sprite.scale.set(f,y,1),this._mesh&&this._mesh.scale.set(f,y,1)}let _=E(this.options.anchor,H.anchor),g=Math.min(100,Math.max(0,_.x))/100,h=Math.min(100,Math.max(0,_.y))/100,C=(.5-g)*f,T=(h-.5)*y;this.group?.position.set(d+C,b+T,-r)}worldToScreen(t){if(!this._cameraRef)return{x:0,y:0};let e=this._cameraRef.camera,{width:o,height:n}=this.getResolution(),s=t.clone().project(e),a=(s.x+1)/2*o,r=(1-s.y)/2*n;return{x:a,y:r}}computeScreenBoundsFromOptions(t){if(!this._cameraRef)return null;if(t.screen)return{...t.screen};if(t.world){let{left:e,right:o,top:n,bottom:s,z:a=0}=t.world,r=this.worldToScreen(new se(e,n,a)),l=this.worldToScreen(new se(o,s,a)),p=Math.min(r.x,l.x),O=Math.min(r.y,l.y),u=Math.abs(l.x-r.x),d=Math.abs(l.y-r.y);return{x:p,y:O,width:u,height:d}}return null}updateRect(t){this.options={...this.options,...t},this.redrawRect(),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new P(this).buildDebugInfo(),type:String(i.type),width:this.options.width??0,height:this.options.height??0,sticky:this.options.stickToViewport}}};function ae(...i){return R({args:i,defaultConfig:{...H},EntityClass:k,BuilderClass:wt,entityType:k.type,cloneFactory:t=>ae(t??{})})}import{Group as je,RingGeometry as qe}from"three";var le={...m,innerRadius:0,outerRadius:1,thetaSegments:32},Ct=class extends ${collider(t){let e=t.outerRadius??1;return{shape:{type:"cylinder",halfHeight:.1/2,radius:e}}}},vt=class extends K{build(t){let e=t.innerRadius??0,o=t.outerRadius??1,n=t.thetaSegments??32,s=new qe(e,o,n);return s.rotateX(-Math.PI/2),s}},_t=class extends D{createEntity(t){return new F(t)}build(){let t=super.build();return t.mesh&&!t.group&&(t.group=new je,t.group.add(t.mesh)),t}},ce=Symbol("Disk"),F=class i extends c{static type=ce;constructor(t){super(),this.options={...le,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.innerRadius??0,n=this.options.outerRadius??1;return{...e,type:String(i.type),innerRadius:o.toFixed(2),outerRadius:n.toFixed(2)}}};function pe(...i){return R({args:i,defaultConfig:le,EntityClass:F,BuilderClass:_t,MeshBuilderClass:vt,CollisionBuilderClass:Ct,entityType:F.type,cloneFactory:t=>pe(t??{})})}var he={...m,radius:1,height:2,radialSegments:32},me=Symbol("Cone"),ht=class i extends c{static type=me;constructor(t){super(),this.options={...he,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1,n=this.options.height??2;return{...e,type:String(i.type),radius:o.toFixed(2),height:n.toFixed(2)}}};function ue(...i){let t=w(i,he),e=new ht(t);return e.add(tt({radius:t.radius,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),W({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>ue(o??{}))}var de={...m,radius:1,height:2},ye=Symbol("Pyramid"),mt=class i extends c{static type=ye;constructor(t){super(),this.options={...de,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1,n=this.options.height??2;return{...e,type:String(i.type),radius:o.toFixed(2),height:n.toFixed(2)}}};function fe(...i){let t=w(i,de),e=new mt(t);return e.add(et({radius:t.radius,height:t.height,material:t.material,color:t.color}),X({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>fe(o??{}))}var ge={...m,radiusTop:1,radiusBottom:1,height:2,radialSegments:32},xe=Symbol("Cylinder"),ut=class i extends c{static type=xe;constructor(t){super(),this.options={...ge,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radiusTop??1,n=this.options.radiusBottom??1,s=this.options.height??2;return{...e,type:String(i.type),radiusTop:o.toFixed(2),radiusBottom:n.toFixed(2),height:s.toFixed(2)}}};function be(...i){let t=w(i,ge),e=new ut(t);return e.add(it({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),U({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>be(o??{}))}var Oe={...m,radius:.5,length:1,capSegments:10,radialSegments:20},Pe=Symbol("Pill"),dt=class i extends c{static type=Pe;constructor(t){super(),this.options={...Oe,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??.5,n=this.options.length??1;return{...e,type:String(i.type),radius:o.toFixed(2),length:n.toFixed(2)}}};function Se(...i){let t=w(i,Oe),e=new dt(t);return e.add(ot({radius:t.radius,length:t.length,capSegments:t.capSegments,radialSegments:t.radialSegments,material:t.material,color:t.color}),j({radius:t.radius,length:t.length,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Se(o??{}))}import{Group as $e,Quaternion as Ke,Vector3 as Qe}from"three";import{ParticleEmitterBehavior as Et}from"@zylem/behaviors/particle-emitter";var Je={...m,effect:{create(){throw new Error("createParticleSystem(...) requires an effect or preset definition.")}},preset:void 0,autoplay:!0,localOffset:void 0,followPosition:!0,followRotation:!0,autoDestroy:!1},we=Symbol("ParticleSystem");function ti(i){return{effect:i.preset??i.effect,autoplay:i.autoplay,localOffset:i.localOffset,followPosition:i.followPosition,followRotation:i.followRotation,autoDestroy:i.autoDestroy}}var yt=class i extends c{static type=we;particleHandle=null;constructor(t,e=!0){super(),this.options=Z(Je,t),this.group=new $e;let o=this.options.position;o&&this.group.position.copy(Ht(o)),this.__zylemParticleSystemEntity=!0,this.bindStandaloneTransforms(),e&&(this.particleHandle=this.use(Et,ti(this.options)))}bindStandaloneTransforms(){let t=()=>{this.options.position=new Qe(this.group?.position.x??0,this.group?.position.y??0,this.group?.position.z??0)},e=()=>{this.group&&(this._rotation2DAngle=this.group.rotation.z)};this.setPosition=(o,n,s)=>{this.group?.position.set(o,n,s),t()},this.setPositionX=o=>{this.group&&(this.group.position.x=o,t())},this.setPositionY=o=>{this.group&&(this.group.position.y=o,t())},this.setPositionZ=o=>{this.group&&(this.group.position.z=o,t())},this.getPosition=()=>this.group?{x:this.group.position.x,y:this.group.position.y,z:this.group.position.z}:null,this.setRotation=(o,n,s)=>{this.group?.rotation.set(o,n,s),e()},this.setRotationX=o=>{this.group&&(this.group.rotation.x=o,e())},this.setRotationY=o=>{this.group&&(this.group.rotation.y=o,e())},this.setRotationZ=o=>{this.group&&(this.group.rotation.z=o,e())},this.setRotationDegrees=(o,n,s)=>{this.group?.rotation.set(o*Math.PI/180,n*Math.PI/180,s*Math.PI/180),e()},this.setRotationDegreesX=o=>{this.group&&(this.group.rotation.x=o*Math.PI/180,e())},this.setRotationDegreesY=o=>{this.group&&(this.group.rotation.y=o*Math.PI/180,e())},this.setRotationDegreesZ=o=>{this.group&&(this.group.rotation.z=o*Math.PI/180,e())},this.rotateX=o=>{this.group?.rotateX(o),e()},this.rotateY=o=>{this.group?.rotateY(o),e()},this.rotateZ=o=>{this.group?.rotateZ(o),e()},this.getRotation=()=>{if(!this.group)return null;let o=new Ke;return this.group.getWorldQuaternion(o),o}}resolveParticleHandle(){if(this.particleHandle)return this.particleHandle;let t=this.getBehaviorRefs().find(n=>n.descriptor.key===Et.key);if(!t)return null;let e={getFSM:()=>t.fsm??null,getOptions:()=>t.options,ref:t},o=Et.createHandle?.(t)??{};return this.particleHandle={...e,...o},this.particleHandle}play(){this.resolveParticleHandle()?.play()}stop(){this.resolveParticleHandle()?.stop()}pause(){this.resolveParticleHandle()?.pause()}restart(){this.resolveParticleHandle()?.restart()}burst(){this.resolveParticleHandle()?.burst()}isPlaying(){return this.resolveParticleHandle()?.isPlaying()??!1}getSystem(){return this.resolveParticleHandle()?.getSystem()}buildInfo(){return{...super.buildInfo(),type:String(i.type)}}};function Ce(i,t=!0){let e=new yt(i,t);return x(e,o=>Ce(o,!1))}function ei(i){return Ce(i,!0)}import{AmbientLight as ii,DirectionalLight as oi,Group as ni,HemisphereLight as si,Object3D as ri,PointLight as ai,SpotLight as li}from"three";var ve=Symbol("Light"),ci={x:0,y:0,z:0},A=16777215,pi={mapSize:2048,near:.1,far:500,bias:0,radius:1,left:-100,right:100,top:100,bottom:-100},hi={mapSize:1024,near:.1,far:500,bias:0,radius:1},ft=class extends c{static type=ve;light=null;lightTarget=null;constructor(t){super(),this.options={...t}}create(){super.create();let t=new ni,{light:e,target:o}=mi(this.options);return t.add(e),o&&t.add(o),this.group=t,this.light=e,this.lightTarget=o,this}_cleanup(t){this.light?.shadow?.map?.dispose?.(),this.light=null,this.lightTarget=null,super._cleanup(t)}};function mi(i){switch(i.type){case"ambient":return{light:ui(i),target:null};case"hemisphere":return{light:di(i),target:null};case"directional":return yi(i);case"point":return{light:fi(i),target:null};case"spot":return gi(i)}}function ui(i){let t=new ii(i.color??A,i.intensity??1);return i.name&&(t.name=i.name),t}function di(i){let t=i.skyColor??i.color??A,e=i.groundColor??0,o=new si(t,e,i.intensity??1);return i.name&&(o.name=i.name),o}function yi(i){let t=new oi(i.color??A,i.intensity??1);i.name&&(t.name=i.name),xi(t,i.castShadow??!1,i.shadow);let e=_e(i.position,i.target);return e&&(t.target=e),{light:t,target:e}}function fi(i){let t=new ai(i.color??A,i.intensity??1,i.distance,i.decay);return i.name&&(t.name=i.name),Ee(t,i.castShadow??!1,i.shadow),t}function gi(i){let t=new li(i.color??A,i.intensity??1,i.distance,i.angle,i.penumbra,i.decay);i.name&&(t.name=i.name),Ee(t,i.castShadow??!1,i.shadow);let e=_e(i.position,i.target);return e&&(t.target=e),{light:t,target:e}}function _e(i,t){if(!t)return null;let e=i??ci,o=new ri;return o.position.set(t.x-e.x,t.y-e.y,t.z-e.z),o}function xi(i,t,e){if(!t){i.castShadow=!1;return}i.castShadow=!0;let o={...pi,...e??{}};i.shadow.mapSize.set(o.mapSize,o.mapSize),i.shadow.camera.near=o.near,i.shadow.camera.far=o.far,i.shadow.camera.left=o.left,i.shadow.camera.right=o.right,i.shadow.camera.top=o.top,i.shadow.camera.bottom=o.bottom,i.shadow.bias=o.bias,i.shadow.radius=o.radius,i.shadow.camera.updateProjectionMatrix()}function Ee(i,t,e){if(!t){i.castShadow=!1;return}i.castShadow=!0;let o={...hi,...e??{}};i.shadow.mapSize.set(o.mapSize,o.mapSize),i.shadow.camera.near=o.near,i.shadow.camera.far=o.far,i.shadow.bias=o.bias,i.shadow.radius=o.radius,i.shadow.camera.updateProjectionMatrix()}function bi(i){return new ft(i)}import{Group as Oi,Sprite as Pi,SpriteMaterial as Si,CanvasTexture as wi,LinearFilter as Ze,Color as Te,ClampToEdgeWrapping as Me}from"three";import{getCooldown as Re}from"@zylem/behaviors/cooldown";var Ci={"top-left":{fx:0,fy:0},"top-center":{fx:.5,fy:0},"top-right":{fx:1,fy:0},"center-left":{fx:0,fy:.5},center:{fx:.5,fy:.5},"center-right":{fx:1,fy:.5},"bottom-left":{fx:0,fy:1},"bottom-center":{fx:.5,fy:1},"bottom-right":{fx:1,fy:1}},De=192,vi={xs:8,sm:16,md:32,lg:48,xl:64},Zt={position:void 0,cooldown:"",iconSize:"md",fillColor:"#333333",showTimer:!0,stickToViewport:!0,screenAnchor:"top-left",screenPosition:{x:0,y:0},zDistance:1,overlayColor:"rgba(0, 0, 0, 0.65)"},_i=Symbol("CooldownIcon"),Tt=class extends c{static type=_i;_sprite=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_iconTexture=null;_iconImage=null;_lastRenderedProgress=-1;constructor(t){super(),this.options=Z(Zt,t),this.options.screenPosition=E(this.options.screenPosition,Zt.screenPosition),this.group=new Oi,this.createSprite(),this.prependSetup(this.iconSetup.bind(this)),this.prependUpdate(this.iconUpdate.bind(this)),this.onCleanup(this.iconDestroy.bind(this))}createSprite(){this._canvas=document.createElement("canvas"),this._canvas.width=256,this._canvas.height=256,this._ctx=this._canvas.getContext("2d"),this._texture=new wi(this._canvas),this._texture.minFilter=Ze,this._texture.magFilter=Ze,this._texture.wrapS=Me,this._texture.wrapT=Me;let e=new Si({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1});if(this._sprite=new Pi(e),this.group?.add(this._sprite),this.options.icon){let o=new Image;o.crossOrigin="anonymous",o.onload=()=>{this._iconImage=o,this.redraw(this._lastRenderedProgress>=0?this._lastRenderedProgress:1)},o.src=this.options.icon}this.redraw(1)}redraw(t){if(!this._canvas||!this._ctx)return;let e=this._ctx,o=this._canvas.width,n=this._canvas.height,s=o/2,a=n/2,r=Math.min(s,a);if(e.clearRect(0,0,o,n),this._iconImage?e.drawImage(this._iconImage,0,0,o,n):(e.fillStyle=this.toCssColor(this.options.fillColor??"#333333"),e.fillRect(0,0,o,n)),t<1){let l=(1-t)*Math.PI*2,p=-Math.PI/2,O=p+l;if(e.save(),e.fillStyle=this.options.overlayColor??"rgba(0, 0, 0, 0.65)",e.beginPath(),e.moveTo(s,a),e.arc(s,a,r+1,p,O,!1),e.closePath(),e.fill(),e.restore(),this.options.showTimer){let u=Re(this.options.cooldown);if(u){let d=Math.max(0,u.duration-u.elapsed),b=d>=10?Math.ceil(d).toString():d.toFixed(1),f=Math.floor(o*.3);e.font=`bold ${f}px sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillStyle="#FFFFFF",e.strokeStyle="#000000",e.lineWidth=2,e.strokeText(b,s,a),e.fillText(b,s,a)}}}this._texture&&(this._texture.needsUpdate=!0),this._lastRenderedProgress=t}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof Te?t:new Te(t)).getHexString()}`}getResolution(){try{let t=this._cameraRef?.renderer?.domElement;if(t)return{width:t.clientWidth||1,height:t.clientHeight||1}}catch{}return{width:this._cameraRef?.screenResolution?.x??1,height:this._cameraRef?.screenResolution?.y??1}}iconSetup(t){this._sprite||this.createSprite(),this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&(this._cameraRef.camera.add(this.group),this.updateStickyTransform())}iconUpdate(t){let o=Re(this.options.cooldown)?.progress??1;(Math.abs(o-this._lastRenderedProgress)>.02||o===1&&this._lastRenderedProgress!==1)&&this.redraw(o),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}resolveScreenPosition(t,e){let o=this.options.screenAnchor??"top-left",n=Bt(this.options.screenPosition,It),s=n.x,a=n.y,{fx:r,fy:l}=Ci[o],p=r*t,O=l*e,u=e/De;return{px:p+s*u,py:O+a*u}}resolveIconSize(t){let e=this.options.iconSize??"md",o,n;typeof e=="string"?o=n=vi[e]:typeof e=="number"?o=n=e:(o=e.width,n=e.height);let s=t/De;return{widthPx:o*s,heightPx:n*s}}computeWorldExtents(t,e){let o=1,n=1;if(t.isPerspectiveCamera){let s=t,a=Math.tan(s.fov*Math.PI/180/2)*e;o=a*s.aspect,n=a}else if(t.isOrthographicCamera){let s=t;o=(s.right-s.left)/2,n=(s.top-s.bottom)/2}return{worldHalfW:o,worldHalfH:n}}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:o}=this.getResolution(),{px:n,py:s}=this.resolveScreenPosition(e,o),a=Math.max(.001,this.options.zDistance??1),{worldHalfW:r,worldHalfH:l}=this.computeWorldExtents(t,a),p=n/e*2-1,O=1-s/o*2,u=p*r,d=O*l;{let f=l*2/o,{widthPx:y,heightPx:_}=this.resolveIconSize(o),g=Math.max(1e-4,y*f),h=Math.max(1e-4,_*f);this._sprite.scale.set(g,h,1)}this.group?.position.set(u,d,-a)}iconDestroy(){this._texture?.dispose(),this._sprite?.material&&this._sprite.material.dispose(),this._sprite&&this._sprite.removeFromParent(),this.group?.removeFromParent(),this._iconTexture?.dispose(),this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._cameraRef=null,this._iconTexture=null,this._iconImage=null}};function Ie(...i){let t=i.filter(o=>!(o instanceof Dt)),e={...Zt};for(let o of t)e={...e,...o};return x(new Tt(e),o=>Ie(o??{}))}function Ei(i,t,e){e({me:i,globals:t})}function Zi(i,t){let e=t??Rt();Ei(i,e,i.nodeDestroy.bind(i))}export{Q as a,J as b,tt as c,et as d,it as e,ot as f,At as g,nt as h,Vt as i,Nt as j,st as k,Wt as l,$t as m,B as n,Kt as o,Jt as p,lt as q,te as r,re as s,k as t,ae as u,ce as v,F as w,pe as x,me as y,ht as z,ue as A,ye as B,mt as C,fe as D,xe as E,ut as F,be as G,Pe as H,dt as I,Se as J,we as K,yt as L,ei as M,ve as N,ft as O,bi as P,Ie as Q,Zi as R};
@@ -0,0 +1 @@
1
+ import{c as r,d as l,h as s}from"./chunk-7WRQ2UAN.js";import{StageBodyKind as a}from"@zylem/behaviors/core";function c(t){if(t!==void 0)return typeof t=="boolean"?[t,t,t]:t}var f=new Map,d=0;function p(t){let o=f.get(t);return o===void 0&&(o=d++%16,f.set(t,o)),o}function b(t){let o=0;return t.forEach(n=>{let i=p(n);o|=1<<i}),o}function y(t,o){if(!t)return 4294967295;let n=p(t),i=o?b(o):65535;return(1<<n&65535)<<16|i&65535}var u=class{static=!1;sensor=!1;gravityScale;lockRotations;lockTranslations;build(o){let n=this.bodyDesc({isDynamicBody:!this.static}),i=this.collider(o);return this.sensor&&(i.sensor=!0),o.collisionType&&(i.collisionGroups=y(o.collisionType,o.collisionFilter)),[n,i]}withCollision(o){return this.sensor=o?.sensor??this.sensor,this.static=o?.static??this.static,this.gravityScale=o?.gravityScale??this.gravityScale,this.lockRotations=o?.lockRotations??this.lockRotations,this.lockTranslations=o?.lockTranslations??this.lockTranslations,this}collider(o){let n=s(o.size,l),i=s(o.position,r);return{shape:{type:"box",halfExtents:[n.x/2,n.y/2,n.z/2]},offset:[i.x,i.y,i.z]}}bodyDesc({isDynamicBody:o=!0}){let n={kind:o?a.Dynamic:a.Static,position:[0,0,0],gravityScale:this.gravityScale??1,canSleep:!1,ccdEnabled:!0},i=c(this.lockRotations);i&&(n.lockRotation=i);let e=c(this.lockTranslations);return e&&(n.lockTranslation=e),n}};export{c as a,y as b,u as c};
@@ -0,0 +1 @@
1
+ import{b as c}from"./chunk-LKFF6XJC.js";import{a as n,e as l,g as r,i as h}from"./chunk-W5SXED5T.js";import{subscribe as p}from"valtio/vanilla";import{announceBridgeReady as m,getZylemBridge as b}from"@zylem/bridge";function g(i){return(i?.group??i?.mesh)?.scale}function w(i){let e=i?.scale??g(i)??{};return{x:e.x??1,y:e.y??1,z:e.z??1}}function v(i,e){if(typeof i?.setScale=="function"){i.setScale(e.x,e.y,e.z);return}g(i)?.set?.(e.x,e.y,e.z)}function G(i,e){b().channel.send("game:notice",{level:i,message:e})}var y=class{channel;unsubscribes=[];host=null;editorKnown={};constructor(){this.channel=b().channel}connect(e,a){this.disconnect(),this.host=e,this.unsubscribes.push(this.channel.on("debug:set",({enabled:t})=>{this.editorKnown.debug=t,n.enabled=t}),this.channel.on("tool:set",({tool:t})=>{r(t)}),this.channel.on("playback:set",({paused:t})=>{this.editorKnown.paused=t,l(t)}),this.channel.on("entity:select",({uuid:t})=>{this.editorKnown.selectedUuid=t,h(t)}),this.channel.on("entity:focus",({uuid:t})=>{c(t)}),this.channel.on("entity:transform",({uuid:t,position:o,rotation:d,scale:u})=>{let s=this.host?.resolveEntity(t);s&&(o&&typeof s.setPosition=="function"&&s.setPosition(o.x,o.y,o.z),d&&(s.setRotationX?.(d.x),s.setRotationY?.(d.y),s.setRotationZ?.(d.z)),u&&v(s,u))}),this.channel.on("stage:variable:set",({key:t,value:o})=>{this.host?.setStageVariable?.(t,o)}),p(n,()=>this.publishDebugStateChanges())),this.publishDebugStateChanges(),m(a)}disconnect(){for(let e of this.unsubscribes)e();this.unsubscribes=[],this.host=null,this.editorKnown={}}publishDebugStateChanges(){let e={};n.paused!==this.editorKnown.paused&&(this.editorKnown.paused=n.paused,e.paused=n.paused),n.enabled!==this.editorKnown.debug&&(this.editorKnown.debug=n.enabled,e.debug=n.enabled),(e.paused!==void 0||e.debug!==void 0)&&this.publishStatus(e),(n.selectedEntityId!==this.editorKnown.selectedUuid||n.hoveredEntityId!==this.editorKnown.hoveredUuid)&&(this.editorKnown.selectedUuid=n.selectedEntityId,this.editorKnown.hoveredUuid=n.hoveredEntityId,this.channel.queue("entity:selection",{selectedUuid:n.selectedEntityId,hoveredUuid:n.hoveredEntityId}))}wantsEntityUpdates(){return this.channel.hasSubscribers("entity:upsert")||this.channel.hasSubscribers("stage:snapshot")}wantsThumbnails(){return this.channel.hasSubscribers("entity:thumbnail")}onEditorAttached(e){return this.channel.onSubscriberAdded(a=>{(a==="entity:upsert"||a==="entity:thumbnail")&&e()})}publishConfig(e){this.channel.send("game:config",e)}publishLoading(e){this.channel.send("game:loading",e)}publishStatus(e){this.channel.queue("game:status",e)}publishVariable(e){this.channel.queue("game:variable",e)}publishNotice(e,a){this.channel.send("game:notice",{level:e,message:a})}publishStageSnapshot(e){this.channel.send("stage:snapshot",e)}queueEntityUpsert(e){e.length&&this.channel.queue("entity:upsert",e)}queueEntityRemoved(e){e.length&&this.channel.queue("entity:removed",{uuids:e})}queueThumbnails(e){e.length&&this.channel.queue("entity:thumbnail",e)}};export{w as a,G as b,y as c};
@@ -0,0 +1 @@
1
+ import{getZylemBridge as d,announceBridgeReady as o,BRIDGE_READY_EVENT as g}from"@zylem/bridge";export{d as a,o as b,g as c};
@@ -1 +1 @@
1
- import{Type as e}from"@sinclair/typebox";var n=e.Tuple([e.Number(),e.Number()],{title:"Vector2",description:"A 2D position as [x, y]."}),s=e.Object({id:e.String(),type:e.String({minLength:1}),position:e.Optional(n),data:e.Optional(e.Record(e.String(),e.Any()))},{$id:"EntityBlueprint",title:"EntityBlueprint",additionalProperties:!1}),D=e.Object({id:e.String(),name:e.Optional(e.String()),entities:e.Array(s),assets:e.Optional(e.Array(e.String()))},{$id:"StageBlueprint",title:"StageBlueprint",additionalProperties:!1}),S=e.Object({value:e.Optional(e.String()),color:e.Optional(e.String()),fontSize:e.Optional(e.Number()),fontFamily:e.Optional(e.String())},{title:"TextEntityData",additionalProperties:!0}),m=e.Tuple([e.Number(),e.Number(),e.Number()],{title:"Vector3Tuple"}),g=e.Object({points:e.Array(m,{minItems:2}),color:e.Optional(e.String()),colors:e.Optional(e.Array(e.String())),linewidth:e.Optional(e.Number()),worldUnits:e.Optional(e.Boolean()),alphaToCoverage:e.Optional(e.Boolean()),opacity:e.Optional(e.Number()),transparent:e.Optional(e.Boolean()),dashed:e.Optional(e.Boolean()),dashSize:e.Optional(e.Number()),gapSize:e.Optional(e.Number()),pickThreshold:e.Optional(e.Number())},{title:"LineEntityData",additionalProperties:!0}),u=e.Object({imagePath:e.Optional(e.String()),width:e.Optional(e.Number()),height:e.Optional(e.Number())},{title:"SpriteEntityData",additionalProperties:!0}),h=e.Union([e.Object({id:e.String(),type:e.Literal("text"),position:e.Optional(n),data:e.Optional(S)}),e.Object({id:e.String(),type:e.Literal("sprite"),position:e.Optional(n),data:e.Optional(u)}),e.Object({id:e.String(),type:e.Literal("line"),position:e.Optional(n),data:e.Optional(g)}),e.Object({id:e.String(),type:e.String({minLength:1}),position:e.Optional(n),data:e.Optional(e.Record(e.String(),e.Unknown()))})],{$id:"EntityJson",title:"EntityJson"}),B=e.Object({id:e.String(),name:e.Optional(e.String()),entities:e.Array(h),assets:e.Optional(e.Array(e.String()))},{$id:"StageJson",title:"StageJson",additionalProperties:!1});import{Type as t}from"@sinclair/typebox";var y=t.Record(t.String(),t.Array(t.String()),{title:"KeyboardMapping"}),O=t.Record(t.String(),t.Array(t.String()),{title:"MouseMapping"}),a=t.Record(t.String(),t.Union([t.String(),t.Number()]),{title:"VirtualTouchStyle"}),p=t.Object({top:t.Optional(t.Union([t.String(),t.Number()])),right:t.Optional(t.Union([t.String(),t.Number()])),bottom:t.Optional(t.Union([t.String(),t.Number()])),left:t.Optional(t.Union([t.String(),t.Number()])),transform:t.Optional(t.String())},{title:"VirtualTouchPosition",additionalProperties:!1}),f=t.Object({enabled:t.Optional(t.Boolean()),className:t.Optional(t.String()),style:t.Optional(a),position:t.Optional(p),size:t.Optional(t.Number()),label:t.Optional(t.String()),svg:t.Optional(t.String())},{title:"VirtualTouchButtonConfig",additionalProperties:!1}),r=t.Object({enabled:t.Optional(t.Boolean()),className:t.Optional(t.String()),style:t.Optional(a),position:t.Optional(p),size:t.Optional(t.Number()),thumbSize:t.Optional(t.Number()),maxDistance:t.Optional(t.Number()),deadzone:t.Optional(t.Number()),directionThreshold:t.Optional(t.Number()),horizontalAxis:t.Optional(t.Union([t.Literal("Horizontal"),t.Literal("SecondaryHorizontal")])),verticalAxis:t.Optional(t.Union([t.Literal("Vertical"),t.Literal("SecondaryVertical")])),emitDirections:t.Optional(t.Boolean()),svg:t.Optional(t.Object({base:t.Optional(t.String()),thumb:t.Optional(t.String())}))},{title:"VirtualTouchJoystickConfig",additionalProperties:!1}),j=t.Union([f,t.Literal(!1)]),d=t.Record(t.String(),j,{title:"VirtualTouchButtonsConfig",description:"Keys are touch button slots: A, B, X, Y, Start, Select, L, R, LTrigger, RTrigger, Up, Down, Left, Right."}),C=t.Object({left:t.Optional(t.Union([r,t.Literal(!1)])),right:t.Optional(t.Union([r,t.Literal(!1)]))},{title:"VirtualTouchJoysticksConfig",additionalProperties:!1}),b=t.Object({enabled:t.Optional(t.Union([t.Boolean(),t.Literal("auto")])),className:t.Optional(t.String()),style:t.Optional(a),joysticks:t.Optional(t.Union([C,t.Literal(!1)])),buttons:t.Optional(t.Union([d,t.Literal(!1)]))},{title:"VirtualTouchConfig",additionalProperties:!1}),x=t.Object({mapping:t.Optional(O),pointerLock:t.Optional(t.Boolean()),sensitivity:t.Optional(t.Number())},{title:"MouseConfig",additionalProperties:!1}),J=t.Object({key:t.Optional(y),mouse:t.Optional(x),touch:t.Optional(b),includeDefaults:t.Optional(t.Boolean())},{title:"GameInputPlayerConfig",additionalProperties:!1}),l=t.Record(t.String(),J,{$id:"GameInputConfig",title:"GameInputConfig",description:"Keys are player slots: p1, p2, p3, p4, p5, p6, p7, p8."});import{Type as i}from"@sinclair/typebox";var T=i.Union([i.String(),i.Number()],{title:"ColorJson",description:"CSS color string or numeric hex (Three.js Color-compatible)."}),E=i.Tuple([i.Number(),i.Number(),i.Number()],{title:"Vec3Components"}),L=i.Object({meshopt:i.Optional(i.Boolean()),ktx2TranscoderPath:i.Optional(i.String())},{title:"StageGLTFAssetLoaderConfig",additionalProperties:!1}),V=i.Object({gltf:i.Optional(L)},{title:"StageAssetLoaderConfig",additionalProperties:!1}),G=i.Object({inputs:i.Optional(i.Record(i.String(),i.Array(i.String()))),backgroundColor:i.Optional(T),backgroundImage:i.Optional(i.Union([i.String(),i.Null()])),gravity:i.Optional(E),variables:i.Optional(i.Record(i.String(),i.Unknown())),physicsRate:i.Optional(i.Number({exclusiveMinimum:0})),assetLoaders:i.Optional(V),defaultLighting:i.Optional(i.Boolean())},{$id:"StageConfigJson",title:"StageConfigJson",additionalProperties:!1});import{Type as o}from"@sinclair/typebox";var c=o.Union([o.String(),o.Object({width:o.Number({exclusiveMinimum:0}),height:o.Number({exclusiveMinimum:0})}),o.Literal("native")],{title:"ResolutionInput"}),N=o.Object({aspectRatio:o.Optional(o.Union([o.Number(),o.String()])),preset:o.Optional(o.String()),resolution:o.Optional(c),controls:o.Optional(o.Boolean())},{title:"GameDeviceConfigJson",additionalProperties:!1}),P=o.Object({id:o.Optional(o.String()),globals:o.Optional(o.Record(o.String(),o.Unknown())),debug:o.Optional(o.Boolean()),time:o.Optional(o.Number()),input:o.Optional(l),aspectRatio:o.Optional(o.Union([o.Number(),o.String()])),preset:o.Optional(o.String()),resolution:o.Optional(c),mobile:o.Optional(N),fullscreen:o.Optional(o.Boolean()),bodyBackground:o.Optional(o.String()),containerId:o.Optional(o.String())},{$id:"GameConfigJson",title:"GameConfigJson",additionalProperties:!1});export{n as a,s as b,D as c,S as d,m as e,g as f,u as g,h,B as i,y as j,O as k,a as l,p as m,f as n,r as o,d as p,C as q,b as r,x as s,J as t,l as u,T as v,E as w,L as x,V as y,G as z,c as A,N as B,P as C};
1
+ import{Type as e}from"@sinclair/typebox";var n=e.Tuple([e.Number(),e.Number()],{title:"Vector2",description:"A 2D position as [x, y]."}),s=e.Object({id:e.String(),type:e.String({minLength:1}),position:e.Optional(n),data:e.Optional(e.Record(e.String(),e.Any()))},{$id:"EntityBlueprint",title:"EntityBlueprint",additionalProperties:!1}),D=e.Object({id:e.String(),name:e.Optional(e.String()),entities:e.Array(s),assets:e.Optional(e.Array(e.String()))},{$id:"StageBlueprint",title:"StageBlueprint",additionalProperties:!1}),S=e.Object({value:e.Optional(e.String()),color:e.Optional(e.String()),fontSize:e.Optional(e.Number()),fontFamily:e.Optional(e.String())},{title:"TextEntityData",additionalProperties:!0}),m=e.Tuple([e.Number(),e.Number(),e.Number()],{title:"Vector3Tuple"}),g=e.Object({points:e.Array(m,{minItems:2}),color:e.Optional(e.String()),colors:e.Optional(e.Array(e.String())),linewidth:e.Optional(e.Number()),worldUnits:e.Optional(e.Boolean()),alphaToCoverage:e.Optional(e.Boolean()),opacity:e.Optional(e.Number()),transparent:e.Optional(e.Boolean()),dashed:e.Optional(e.Boolean()),dashSize:e.Optional(e.Number()),gapSize:e.Optional(e.Number()),pickThreshold:e.Optional(e.Number())},{title:"LineEntityData",additionalProperties:!0}),u=e.Object({imagePath:e.Optional(e.String()),width:e.Optional(e.Number()),height:e.Optional(e.Number())},{title:"SpriteEntityData",additionalProperties:!0}),h=e.Union([e.Object({id:e.String(),type:e.Literal("text"),position:e.Optional(n),data:e.Optional(S)}),e.Object({id:e.String(),type:e.Literal("sprite"),position:e.Optional(n),data:e.Optional(u)}),e.Object({id:e.String(),type:e.Literal("line"),position:e.Optional(n),data:e.Optional(g)}),e.Object({id:e.String(),type:e.String({minLength:1}),position:e.Optional(n),data:e.Optional(e.Record(e.String(),e.Unknown()))})],{$id:"EntityJson",title:"EntityJson"}),B=e.Object({id:e.String(),name:e.Optional(e.String()),entities:e.Array(h),assets:e.Optional(e.Array(e.String()))},{$id:"StageJson",title:"StageJson",additionalProperties:!1});import{Type as t}from"@sinclair/typebox";var y=t.Record(t.String(),t.Array(t.String()),{title:"KeyboardMapping"}),O=t.Record(t.String(),t.Array(t.String()),{title:"MouseMapping"}),a=t.Record(t.String(),t.Union([t.String(),t.Number()]),{title:"VirtualTouchStyle"}),p=t.Object({top:t.Optional(t.Union([t.String(),t.Number()])),right:t.Optional(t.Union([t.String(),t.Number()])),bottom:t.Optional(t.Union([t.String(),t.Number()])),left:t.Optional(t.Union([t.String(),t.Number()])),transform:t.Optional(t.String())},{title:"VirtualTouchPosition",additionalProperties:!1}),f=t.Object({enabled:t.Optional(t.Boolean()),className:t.Optional(t.String()),style:t.Optional(a),position:t.Optional(p),size:t.Optional(t.Number()),label:t.Optional(t.String()),svg:t.Optional(t.String())},{title:"VirtualTouchButtonConfig",additionalProperties:!1}),r=t.Object({enabled:t.Optional(t.Boolean()),className:t.Optional(t.String()),style:t.Optional(a),position:t.Optional(p),size:t.Optional(t.Number()),thumbSize:t.Optional(t.Number()),maxDistance:t.Optional(t.Number()),deadzone:t.Optional(t.Number()),directionThreshold:t.Optional(t.Number()),horizontalAxis:t.Optional(t.Union([t.Literal("Horizontal"),t.Literal("SecondaryHorizontal")])),verticalAxis:t.Optional(t.Union([t.Literal("Vertical"),t.Literal("SecondaryVertical")])),emitDirections:t.Optional(t.Boolean()),svg:t.Optional(t.Object({base:t.Optional(t.String()),thumb:t.Optional(t.String())}))},{title:"VirtualTouchJoystickConfig",additionalProperties:!1}),j=t.Union([f,t.Literal(!1)]),d=t.Record(t.String(),j,{title:"VirtualTouchButtonsConfig",description:"Keys are touch button slots: A, B, X, Y, Start, Select, L, R, LTrigger, RTrigger, Up, Down, Left, Right."}),C=t.Object({left:t.Optional(t.Union([r,t.Literal(!1)])),right:t.Optional(t.Union([r,t.Literal(!1)]))},{title:"VirtualTouchJoysticksConfig",additionalProperties:!1}),b=t.Object({enabled:t.Optional(t.Union([t.Boolean(),t.Literal("auto")])),className:t.Optional(t.String()),style:t.Optional(a),joysticks:t.Optional(t.Union([C,t.Literal(!1)])),buttons:t.Optional(t.Union([d,t.Literal(!1)]))},{title:"VirtualTouchConfig",additionalProperties:!1}),x=t.Object({mapping:t.Optional(O),pointerLock:t.Optional(t.Boolean()),sensitivity:t.Optional(t.Number()),lookMode:t.Optional(t.Union([t.Literal("delta"),t.Literal("screenCenter")])),maxLookDegrees:t.Optional(t.Number()),lookSensitivity:t.Optional(t.Number())},{title:"MouseConfig",additionalProperties:!1}),J=t.Object({key:t.Optional(y),mouse:t.Optional(x),touch:t.Optional(b),includeDefaults:t.Optional(t.Boolean())},{title:"GameInputPlayerConfig",additionalProperties:!1}),l=t.Record(t.String(),J,{$id:"GameInputConfig",title:"GameInputConfig",description:"Keys are player slots: p1, p2, p3, p4, p5, p6, p7, p8."});import{Type as i}from"@sinclair/typebox";var T=i.Union([i.String(),i.Number()],{title:"ColorJson",description:"CSS color string or numeric hex (Three.js Color-compatible)."}),L=i.Tuple([i.Number(),i.Number(),i.Number()],{title:"Vec3Components"}),E=i.Object({meshopt:i.Optional(i.Boolean()),ktx2TranscoderPath:i.Optional(i.String())},{title:"StageGLTFAssetLoaderConfig",additionalProperties:!1}),V=i.Object({gltf:i.Optional(E)},{title:"StageAssetLoaderConfig",additionalProperties:!1}),G=i.Object({inputs:i.Optional(i.Record(i.String(),i.Array(i.String()))),backgroundColor:i.Optional(T),backgroundImage:i.Optional(i.Union([i.String(),i.Null()])),gravity:i.Optional(L),variables:i.Optional(i.Record(i.String(),i.Unknown())),physicsRate:i.Optional(i.Number({exclusiveMinimum:0})),assetLoaders:i.Optional(V),defaultLighting:i.Optional(i.Boolean())},{$id:"StageConfigJson",title:"StageConfigJson",additionalProperties:!1});import{Type as o}from"@sinclair/typebox";var c=o.Union([o.String(),o.Object({width:o.Number({exclusiveMinimum:0}),height:o.Number({exclusiveMinimum:0})}),o.Literal("native")],{title:"ResolutionInput"}),N=o.Object({aspectRatio:o.Optional(o.Union([o.Number(),o.String()])),preset:o.Optional(o.String()),resolution:o.Optional(c),controls:o.Optional(o.Boolean())},{title:"GameDeviceConfigJson",additionalProperties:!1}),P=o.Object({id:o.Optional(o.String()),globals:o.Optional(o.Record(o.String(),o.Unknown())),debug:o.Optional(o.Boolean()),time:o.Optional(o.Number()),input:o.Optional(l),aspectRatio:o.Optional(o.Union([o.Number(),o.String()])),preset:o.Optional(o.String()),resolution:o.Optional(c),mobile:o.Optional(N),fullscreen:o.Optional(o.Boolean()),bodyBackground:o.Optional(o.String()),containerId:o.Optional(o.String())},{$id:"GameConfigJson",title:"GameConfigJson",additionalProperties:!1});export{n as a,s as b,D as c,S as d,m as e,g as f,u as g,h,B as i,y as j,O as k,a as l,p as m,f as n,r as o,d as p,C as q,b as r,x as s,J as t,l as u,T as v,L as w,E as x,V as y,G as z,c as A,N as B,P as C};
@@ -1 +1 @@
1
- import{b as d,k as v,l as V,m as y,o as D,p as S,q as B,s as b}from"./chunk-XNHVRFAK.js";import{c as k}from"./chunk-CM5YRNBJ.js";import{c as h,d as _,h as u,i as T,j as C}from"./chunk-7WRQ2UAN.js";import{Color as $,Group as nt,Sprite as st,SpriteMaterial as rt,CanvasTexture as U,LinearFilter as E,Vector2 as ot,ClampToEdgeWrapping as H}from"three";import{MeshStandardMaterial as K,MeshBasicMaterial as tt,MeshPhongMaterial as et}from"three";function it(i){return i&&typeof i.getDebugInfo=="function"}var c=class{entity;constructor(t){this.entity=t}getPositionString(){if(this.entity.mesh){let{x:r,y:s,z:o}=this.entity.mesh.position;return`${r.toFixed(2)}, ${s.toFixed(2)}, ${o.toFixed(2)}`}let{x:t,y:e,z:n}=this.entity.options.position||{x:0,y:0,z:0};return`${t.toFixed(2)}, ${e.toFixed(2)}, ${n.toFixed(2)}`}getRotationString(){if(this.entity.mesh){let{x:s,y:o,z:a}=this.entity.mesh.rotation,p=l=>(l*180/Math.PI).toFixed(1);return`${p(s)}\xB0, ${p(o)}\xB0, ${p(a)}\xB0`}let{x:t,y:e,z:n}=this.entity.options.rotation||{x:0,y:0,z:0},r=s=>(s*180/Math.PI).toFixed(1);return`${r(t)}\xB0, ${r(e)}\xB0, ${r(n)}\xB0`}getMaterialInfo(){if(!this.entity.mesh||!this.entity.mesh.material)return{type:"none"};let t=Array.isArray(this.entity.mesh.material)?this.entity.mesh.material[0]:this.entity.mesh.material,e={type:t.type};return(t instanceof K||t instanceof tt||t instanceof et)&&(e.color=`#${t.color.getHexString()}`,e.opacity=t.opacity,e.transparent=t.transparent),"roughness"in t&&(e.roughness=t.roughness),"metalness"in t&&(e.metalness=t.metalness),e}getPhysicsInfo(){if(!this.entity.body)return null;let t={type:this.entity.body.bodyType(),mass:this.entity.body.mass(),isEnabled:this.entity.body.isEnabled(),isSleeping:this.entity.body.isSleeping()},e=this.entity.body.linvel();return t.velocity=`${e.x.toFixed(2)}, ${e.y.toFixed(2)}, ${e.z.toFixed(2)}`,t}buildDebugInfo(){let t={name:this.entity.name||this.entity.uuid,uuid:this.entity.uuid,position:this.getPositionString(),rotation:this.getRotationString(),material:this.getMaterialInfo()},e=this.getPhysicsInfo();if(e&&(t.physics=e),it(this.entity)){let n=this.entity.getDebugInfo();return{...t,...n}}return t}};var f={position:void 0,text:"",fontFamily:'Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',fontSize:18,fontColor:"#FFFFFF",backgroundColor:null,padding:4,stickToViewport:!0,screenPosition:new ot(24,24),zDistance:1},O=class extends b{createEntity(t){return new g(t)}},at=Symbol("Text"),g=class i extends y{static type=at;_sprite=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=d(f,t),this.options.screenPosition=T(this.options.screenPosition,f.screenPosition),this.prependSetup(this.textSetup.bind(this)),this.prependUpdate(this.textUpdate.bind(this)),this.onCleanup(this.textDestroy.bind(this))}create(){return this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._lastCanvasW=0,this._lastCanvasH=0,this.group=new nt,this.createSprite(),super.create()}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new U(this._canvas),this._texture.minFilter=E,this._texture.magFilter=E;let t=new rt({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new st(t),this.group?.add(this._sprite),this.redrawText(this.options.text??"")}measureAndResizeCanvas(t,e,n,r){if(!this._canvas||!this._ctx)return{sizeChanged:!1};this._ctx.font=`${e}px ${n}`;let s=this._ctx.measureText(t),o=Math.ceil(s.width),a=Math.ceil(e*1.4),p=Math.max(2,o+r*2),l=Math.max(2,a+r*2),w=p!==this._lastCanvasW||l!==this._lastCanvasH;return this._canvas.width=p,this._canvas.height=l,this._lastCanvasW=p,this._lastCanvasH=l,{sizeChanged:w}}drawCenteredText(t,e,n){!this._canvas||!this._ctx||(this._ctx.font=`${e}px ${n}`,this._ctx.textAlign="center",this._ctx.textBaseline="middle",this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this.options.backgroundColor&&(this._ctx.fillStyle=this.toCssColor(this.options.backgroundColor),this._ctx.fillRect(0,0,this._canvas.width,this._canvas.height)),this._ctx.fillStyle=this.toCssColor(this.options.fontColor??"#FFFFFF"),this._ctx.fillText(t,this._canvas.width/2,this._canvas.height/2))}updateTexture(t){!this._texture||!this._canvas||(t&&(this._texture.dispose(),this._texture=new U(this._canvas),this._texture.minFilter=E,this._texture.magFilter=E,this._texture.wrapS=H,this._texture.wrapT=H),this._texture.image=this._canvas,this._texture.needsUpdate=!0,this._sprite&&this._sprite.material&&(this._sprite.material.map=this._texture,this._sprite.material.needsUpdate=!0))}redrawText(t){if(!this._canvas||!this._ctx)return;let e=this.options.fontSize??18,n=this.options.fontFamily??f.fontFamily,r=this.options.padding??4,{sizeChanged:s}=this.measureAndResizeCanvas(t,e,n,r);this.drawCenteredText(t,e,n),this.updateTexture(!!s),this.options.stickToViewport&&this._cameraRef?this.updateStickyTransform():this.updateWorldSpriteScale()}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof $?t:new $(t)).getHexString()}`}textSetup(t){this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&(this._cameraRef.camera.add(this.group),this.updateStickyTransform())}textUpdate(t){this._sprite&&this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}getResolution(){return{width:this._cameraRef?.screenResolution.x??1,height:this._cameraRef?.screenResolution.y??1}}getScreenPixels(t,e,n){let r=t.x>=0&&t.x<=1,s=t.y>=0&&t.y<=1;return{px:r?t.x*e:t.x,py:s?t.y*n:t.y}}computeWorldExtents(t,e){let n=1,r=1;if(t.isPerspectiveCamera){let s=t,o=Math.tan(s.fov*Math.PI/180/2)*e;n=o*s.aspect,r=o}else if(t.isOrthographicCamera){let s=t;n=(s.right-s.left)/2,r=(s.top-s.bottom)/2}return{worldHalfW:n,worldHalfH:r}}updateSpriteScale(t,e){if(!this._canvas||!this._sprite)return;let r=t*2/e,s=this._canvas.height,o=Math.max(1e-4,s*r),a=this._canvas.width/this._canvas.height,p=o*a;this._sprite.scale.set(p,o,1)}updateWorldSpriteScale(){if(!this._canvas||!this._sprite)return;let t=this._canvas.width/Math.max(1,this._canvas.height),e=Math.max(1,this.options.fontSize??18),n=Math.max(.25,e/32),r=n*t;this._sprite.scale.set(r,n,1)}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:n}=this.getResolution(),r=T(this.options.screenPosition,f.screenPosition),{px:s,py:o}=this.getScreenPixels(r,e,n),a=Math.max(.001,this.options.zDistance??1),{worldHalfW:p,worldHalfH:l}=this.computeWorldExtents(t,a),w=s/e*2-1,Q=1-o/n*2,q=w*p,J=Q*l;this.group?.position.set(q,J,-a),this.updateSpriteScale(l,n)}updateText(t){this.options.text=t,this.redrawText(t),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type),text:this.options.text??"",sticky:this.options.stickToViewport}}textDestroy(){this._texture?.dispose(),this._sprite?.material&&this._sprite.material.dispose(),this._sprite&&this._sprite.removeFromParent(),this.group?.removeFromParent(),this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._cameraRef=null}};function I(...i){return S({args:i,defaultConfig:{...f},EntityClass:g,BuilderClass:O,entityType:g.type,cloneFactory:t=>I(t??{})})}import{Euler as pt,Group as lt,Quaternion as ct,Vector3 as mt}from"three";import{TextureLoader as ht,SpriteMaterial as ut,Sprite as dt,SRGBColorSpace as yt}from"three";var W={...v,size:new mt(1,1,1),images:[],animations:[]},R=class extends B{collider(t){let e=C(t.collisionSize,t.size??_);return{shape:{type:"box",halfExtents:[e.x/2,e.y/2,e.z/2]}}}},F=class extends b{createEntity(t){return new x(t)}},ft=Symbol("Sprite"),x=class i extends y{static type=ft;sprites=[];spriteMap=new Map;currentSpriteIndex=0;animations=new Map;currentAnimation=null;currentAnimationFrame="";currentAnimationIndex=0;currentAnimationTime=0;constructor(t){super(),this.options=d(W,t),this.prependSetup(this.spriteSetup.bind(this)),this.prependUpdate(this.spriteUpdate.bind(this)),this.onCleanup(this.spriteDestroy.bind(this))}create(){return this.sprites=[],this.spriteMap.clear(),this.animations.clear(),this.currentAnimation=null,this.currentAnimationFrame="",this.currentAnimationIndex=0,this.currentAnimationTime=0,this.group=void 0,this.createSpritesFromImages(this.options?.images||[]),this.createAnimations(this.options?.animations||[]),super.create()}createSpritesFromImages(t){let e=new ht,n=C(this.options.size,_);t.forEach((r,s)=>{let o=e.load(r.file);o.colorSpace=yt,o.anisotropy=k;let a=new ut({map:o,transparent:!0}),p=new dt(a);p.position.normalize(),p.scale.set(n.x,n.y,n.z),p.visible=s===0,this.sprites.push(p),this.spriteMap.set(r.name,s)}),this.group=new lt,this.group.add(...this.sprites)}createAnimations(t){t.forEach(e=>{let{name:n,frames:r,loop:s=!1,speed:o=1}=e,a={frames:r.map((p,l)=>({key:p,index:l,time:(typeof o=="number"?o:o[l])*(l+1),duration:typeof o=="number"?o:o[l]})),loop:s};this.animations.set(n,a)})}setSprite(t){let n=this.spriteMap.get(t)??0;this.currentSpriteIndex=n,this.sprites.forEach((r,s)=>{r.visible=this.currentSpriteIndex===s})}setAnimation(t,e){let n=this.animations.get(t);if(!n)return;let{loop:r,frames:s}=n,o=s[this.currentAnimationIndex];t===this.currentAnimation?(this.currentAnimationFrame=o.key,this.currentAnimationTime+=e,this.setSprite(this.currentAnimationFrame)):this.currentAnimation=t,this.currentAnimationTime>o.time&&this.currentAnimationIndex++,this.currentAnimationIndex>=s.length&&(r?(this.currentAnimationIndex=0,this.currentAnimationTime=0):this.currentAnimationTime=s[this.currentAnimationIndex].time)}getCurrentRotationQuaternion(){return this.transformStore?.dirty.rotation?this.transformStore.rotation:this.body?.rotation?.()??null}syncSpriteMaterials(){let t=this.getCurrentRotationQuaternion();this.sprites.forEach(e=>{if(e.material&&t){let r=new ct(t.x,t.y,t.z,t.w),s=new pt().setFromQuaternion(r,"XYZ");e.material.rotation=s.z}let n=C(this.options.size,_);e.scale.set(n.x,n.y,n.z)})}spriteSetup(t){this.syncSpriteMaterials()}spriteUpdate(t){this.syncSpriteMaterials()}spriteDestroy(t){this.sprites.forEach(e=>{e.removeFromParent()}),this.group?.remove(...this.sprites),this.group?.removeFromParent()}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type)}}};function P(...i){return S({args:i,defaultConfig:W,EntityClass:x,BuilderClass:F,CollisionBuilderClass:R,entityType:x.type,cloneFactory:t=>P(t??{})})}import{Color as X,Group as xt}from"three";import{Line2NodeMaterial as _t}from"three/webgpu";import{Line2 as Ct}from"three/addons/lines/webgpu/Line2.js";import{Color as N}from"three";import{LineGeometry as gt}from"three/addons/lines/LineGeometry.js";function z(i){let t=[];for(let e of i){let{x:n,y:r,z:s}=u(e,h);t.push(n,r,s)}return t}function L(i,t,e){if(!i||i.length===0)return;let n=[],r=new N(e);for(let s=0;s<t;s++){let o=i[s]??i[i.length-1]??e,a=new N(o??r);n.push(a.r,a.g,a.b)}return n}function Y(i){let t=new gt,e=z(i.points);t.setPositions(e);let n=L(i.colors,i.points.length,"#ffffff");return n&&t.setColors(n),t}var m={...v,points:[{x:0,y:0,z:0},{x:1,y:0,z:0}],linewidth:1,worldUnits:!0,alphaToCoverage:!1,opacity:1,transparent:!1,dashed:!1,dashSize:1,gapSize:1,pickThreshold:0},vt=Symbol("Line");function M(i,t){if(!i||i.length<2)throw new Error(`${t}: at least two points are required`);return i}function j(i){return i instanceof X?i.clone():new X(i??"#ffffff")}function St(i){let t=!!i.colors?.length,e=new _t({color:j(i.color).getHex(),linewidth:i.linewidth??m.linewidth,worldUnits:i.worldUnits??m.worldUnits,vertexColors:t,dashed:i.dashed??!1,dashSize:i.dashSize??m.dashSize,gapSize:i.gapSize??m.gapSize,transparent:i.transparent??!1,opacity:i.opacity??1});return e.alphaToCoverage=i.alphaToCoverage??!1,e}function bt(i){return!i.point||!i.pointOnLine||i.faceIndex==null?null:{point:i.point.clone(),pointOnLine:i.pointOnLine.clone(),faceIndex:i.faceIndex,distance:i.distance}}function Et(i,t,e={}){let n=t.getLineObject();if(!n)return null;let r=e.threshold??t.options.pickThreshold??0,s=i.params.Line2??{threshold:0};s.threshold=r,i.params.Line2=s;let a=i.intersectObject(n,!1)[0];return a?bt(a):null}var Z=class i extends y{static type=vt;_line=null;_geometry=null;_material=null;constructor(t){super();let e=d(m,t);e.points=M(e.points,"ZylemLine").map(n=>u(n,h)),this.options=e}create(){return this.disposeLineResources(),this.group=new xt,this.rebuildLine(),this.applyGroupPosition(),super.create()}setPoints(t,e){if(M(t,"setPoints"),this.options.points=t.map(r=>u(r,h)),e&&(this.options.colors=e),!this._line||!this._geometry||!this._material)return this;this._geometry.setPositions(z(this.options.points));let n=L(this.options.colors,this.options.points.length,j(this.options.color));return n&&this._geometry.setColors(n),this._material.vertexColors=!!this.options.colors?.length,this.options.dashed&&this._line.computeLineDistances(),this._geometry.computeBoundingBox(),this._geometry.computeBoundingSphere(),this}getLineObject(){return this._line}pickFromRaycaster(t,e={}){return Et(t,this,e)}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type),points:this.options.points.length,linewidth:this.options.linewidth??m.linewidth,worldUnits:this.options.worldUnits??m.worldUnits}}rebuildLine(){this._geometry=Y({points:this.options.points,colors:this.options.colors}),this._material=St(this.options),this._line=new Ct(this._geometry,this._material),this.options.dashed&&this._line.computeLineDistances(),this.group?.add(this._line)}applyGroupPosition(){if(!this.group)return;let t=u(this.options.position,h);this.group.position.set(t.x,t.y,t.z)}_cleanup(t){this.disposeLineResources(),super._cleanup(t)}disposeLineResources(){this._line?.removeFromParent(),this._geometry?.dispose(),this._material?.dispose(),this._line=null,this._geometry=null,this._material=null}};function G(...i){let t=V(i,m);M(t.points,"createLine");let e=new Z(t);return D(e,n=>G(n??{}))}var A={registry:new Map,register(i,t){this.registry.set(i,t)},createFromBlueprint(i){let t=this.registry.get(i.type);if(!t)throw new Error(`Unknown entity type: ${i.type}`);let e={...i.data,position:i.position?{x:i.position[0],y:i.position[1],z:0}:void 0,name:i.id};return t(e)}};A.register("text",i=>I(i));A.register("sprite",i=>P(i));A.register("line",i=>G(i));function Ce(i){return{template:i,generate(t){let e=[];for(let n=0;n<t;n++)e.push(i.clone());return e}}}export{c as a,at as b,g as c,I as d,ft as e,x as f,P as g,vt as h,Et as i,Z as j,G as k,A as l,Ce as m};
1
+ import{b as d,p as v,q as V,r as y,t as D,u as S,v as B,x as b}from"./chunk-3I537JFL.js";import{c as k}from"./chunk-CM5YRNBJ.js";import{c as h,d as _,h as u,i as T,j as C}from"./chunk-7WRQ2UAN.js";import{Color as $,Group as nt,Sprite as st,SpriteMaterial as rt,CanvasTexture as U,LinearFilter as E,Vector2 as ot,ClampToEdgeWrapping as H}from"three";import{MeshStandardMaterial as K,MeshBasicMaterial as tt,MeshPhongMaterial as et}from"three";function it(i){return i&&typeof i.getDebugInfo=="function"}var c=class{entity;constructor(t){this.entity=t}getPositionString(){if(this.entity.mesh){let{x:r,y:s,z:o}=this.entity.mesh.position;return`${r.toFixed(2)}, ${s.toFixed(2)}, ${o.toFixed(2)}`}let{x:t,y:e,z:n}=this.entity.options.position||{x:0,y:0,z:0};return`${t.toFixed(2)}, ${e.toFixed(2)}, ${n.toFixed(2)}`}getRotationString(){if(this.entity.mesh){let{x:s,y:o,z:a}=this.entity.mesh.rotation,p=l=>(l*180/Math.PI).toFixed(1);return`${p(s)}\xB0, ${p(o)}\xB0, ${p(a)}\xB0`}let{x:t,y:e,z:n}=this.entity.options.rotation||{x:0,y:0,z:0},r=s=>(s*180/Math.PI).toFixed(1);return`${r(t)}\xB0, ${r(e)}\xB0, ${r(n)}\xB0`}getMaterialInfo(){if(!this.entity.mesh||!this.entity.mesh.material)return{type:"none"};let t=Array.isArray(this.entity.mesh.material)?this.entity.mesh.material[0]:this.entity.mesh.material,e={type:t.type};return(t instanceof K||t instanceof tt||t instanceof et)&&(e.color=`#${t.color.getHexString()}`,e.opacity=t.opacity,e.transparent=t.transparent),"roughness"in t&&(e.roughness=t.roughness),"metalness"in t&&(e.metalness=t.metalness),e}getPhysicsInfo(){if(!this.entity.body)return null;let t={type:this.entity.body.bodyType(),mass:this.entity.body.mass(),isEnabled:this.entity.body.isEnabled(),isSleeping:this.entity.body.isSleeping()},e=this.entity.body.linvel();return t.velocity=`${e.x.toFixed(2)}, ${e.y.toFixed(2)}, ${e.z.toFixed(2)}`,t}buildDebugInfo(){let t={name:this.entity.name||this.entity.uuid,uuid:this.entity.uuid,position:this.getPositionString(),rotation:this.getRotationString(),material:this.getMaterialInfo()},e=this.getPhysicsInfo();if(e&&(t.physics=e),it(this.entity)){let n=this.entity.getDebugInfo();return{...t,...n}}return t}};var f={position:void 0,text:"",fontFamily:'Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',fontSize:18,fontColor:"#FFFFFF",backgroundColor:null,padding:4,stickToViewport:!0,screenPosition:new ot(24,24),zDistance:1},O=class extends b{createEntity(t){return new g(t)}},at=Symbol("Text"),g=class i extends y{static type=at;_sprite=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=d(f,t),this.options.screenPosition=T(this.options.screenPosition,f.screenPosition),this.prependSetup(this.textSetup.bind(this)),this.prependUpdate(this.textUpdate.bind(this)),this.onCleanup(this.textDestroy.bind(this))}create(){return this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._lastCanvasW=0,this._lastCanvasH=0,this.group=new nt,this.createSprite(),super.create()}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new U(this._canvas),this._texture.minFilter=E,this._texture.magFilter=E;let t=new rt({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new st(t),this.group?.add(this._sprite),this.redrawText(this.options.text??"")}measureAndResizeCanvas(t,e,n,r){if(!this._canvas||!this._ctx)return{sizeChanged:!1};this._ctx.font=`${e}px ${n}`;let s=this._ctx.measureText(t),o=Math.ceil(s.width),a=Math.ceil(e*1.4),p=Math.max(2,o+r*2),l=Math.max(2,a+r*2),w=p!==this._lastCanvasW||l!==this._lastCanvasH;return this._canvas.width=p,this._canvas.height=l,this._lastCanvasW=p,this._lastCanvasH=l,{sizeChanged:w}}drawCenteredText(t,e,n){!this._canvas||!this._ctx||(this._ctx.font=`${e}px ${n}`,this._ctx.textAlign="center",this._ctx.textBaseline="middle",this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this.options.backgroundColor&&(this._ctx.fillStyle=this.toCssColor(this.options.backgroundColor),this._ctx.fillRect(0,0,this._canvas.width,this._canvas.height)),this._ctx.fillStyle=this.toCssColor(this.options.fontColor??"#FFFFFF"),this._ctx.fillText(t,this._canvas.width/2,this._canvas.height/2))}updateTexture(t){!this._texture||!this._canvas||(t&&(this._texture.dispose(),this._texture=new U(this._canvas),this._texture.minFilter=E,this._texture.magFilter=E,this._texture.wrapS=H,this._texture.wrapT=H),this._texture.image=this._canvas,this._texture.needsUpdate=!0,this._sprite&&this._sprite.material&&(this._sprite.material.map=this._texture,this._sprite.material.needsUpdate=!0))}redrawText(t){if(!this._canvas||!this._ctx)return;let e=this.options.fontSize??18,n=this.options.fontFamily??f.fontFamily,r=this.options.padding??4,{sizeChanged:s}=this.measureAndResizeCanvas(t,e,n,r);this.drawCenteredText(t,e,n),this.updateTexture(!!s),this.options.stickToViewport&&this._cameraRef?this.updateStickyTransform():this.updateWorldSpriteScale()}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof $?t:new $(t)).getHexString()}`}textSetup(t){this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&(this._cameraRef.camera.add(this.group),this.updateStickyTransform())}textUpdate(t){this._sprite&&this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}getResolution(){return{width:this._cameraRef?.screenResolution.x??1,height:this._cameraRef?.screenResolution.y??1}}getScreenPixels(t,e,n){let r=t.x>=0&&t.x<=1,s=t.y>=0&&t.y<=1;return{px:r?t.x*e:t.x,py:s?t.y*n:t.y}}computeWorldExtents(t,e){let n=1,r=1;if(t.isPerspectiveCamera){let s=t,o=Math.tan(s.fov*Math.PI/180/2)*e;n=o*s.aspect,r=o}else if(t.isOrthographicCamera){let s=t;n=(s.right-s.left)/2,r=(s.top-s.bottom)/2}return{worldHalfW:n,worldHalfH:r}}updateSpriteScale(t,e){if(!this._canvas||!this._sprite)return;let r=t*2/e,s=this._canvas.height,o=Math.max(1e-4,s*r),a=this._canvas.width/this._canvas.height,p=o*a;this._sprite.scale.set(p,o,1)}updateWorldSpriteScale(){if(!this._canvas||!this._sprite)return;let t=this._canvas.width/Math.max(1,this._canvas.height),e=Math.max(1,this.options.fontSize??18),n=Math.max(.25,e/32),r=n*t;this._sprite.scale.set(r,n,1)}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:n}=this.getResolution(),r=T(this.options.screenPosition,f.screenPosition),{px:s,py:o}=this.getScreenPixels(r,e,n),a=Math.max(.001,this.options.zDistance??1),{worldHalfW:p,worldHalfH:l}=this.computeWorldExtents(t,a),w=s/e*2-1,Q=1-o/n*2,q=w*p,J=Q*l;this.group?.position.set(q,J,-a),this.updateSpriteScale(l,n)}updateText(t){this.options.text=t,this.redrawText(t),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type),text:this.options.text??"",sticky:this.options.stickToViewport}}textDestroy(){this._texture?.dispose(),this._sprite?.material&&this._sprite.material.dispose(),this._sprite&&this._sprite.removeFromParent(),this.group?.removeFromParent(),this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._cameraRef=null}};function I(...i){return S({args:i,defaultConfig:{...f},EntityClass:g,BuilderClass:O,entityType:g.type,cloneFactory:t=>I(t??{})})}import{Euler as pt,Group as lt,Quaternion as ct,Vector3 as mt}from"three";import{TextureLoader as ht,SpriteMaterial as ut,Sprite as dt,SRGBColorSpace as yt}from"three";var W={...v,size:new mt(1,1,1),images:[],animations:[]},R=class extends B{collider(t){let e=C(t.collisionSize,t.size??_);return{shape:{type:"box",halfExtents:[e.x/2,e.y/2,e.z/2]}}}},F=class extends b{createEntity(t){return new x(t)}},ft=Symbol("Sprite"),x=class i extends y{static type=ft;sprites=[];spriteMap=new Map;currentSpriteIndex=0;animations=new Map;currentAnimation=null;currentAnimationFrame="";currentAnimationIndex=0;currentAnimationTime=0;constructor(t){super(),this.options=d(W,t),this.prependSetup(this.spriteSetup.bind(this)),this.prependUpdate(this.spriteUpdate.bind(this)),this.onCleanup(this.spriteDestroy.bind(this))}create(){return this.sprites=[],this.spriteMap.clear(),this.animations.clear(),this.currentAnimation=null,this.currentAnimationFrame="",this.currentAnimationIndex=0,this.currentAnimationTime=0,this.group=void 0,this.createSpritesFromImages(this.options?.images||[]),this.createAnimations(this.options?.animations||[]),super.create()}createSpritesFromImages(t){let e=new ht,n=C(this.options.size,_);t.forEach((r,s)=>{let o=e.load(r.file);o.colorSpace=yt,o.anisotropy=k;let a=new ut({map:o,transparent:!0}),p=new dt(a);p.position.normalize(),p.scale.set(n.x,n.y,n.z),p.visible=s===0,this.sprites.push(p),this.spriteMap.set(r.name,s)}),this.group=new lt,this.group.add(...this.sprites)}createAnimations(t){t.forEach(e=>{let{name:n,frames:r,loop:s=!1,speed:o=1}=e,a={frames:r.map((p,l)=>({key:p,index:l,time:(typeof o=="number"?o:o[l])*(l+1),duration:typeof o=="number"?o:o[l]})),loop:s};this.animations.set(n,a)})}setSprite(t){let n=this.spriteMap.get(t)??0;this.currentSpriteIndex=n,this.sprites.forEach((r,s)=>{r.visible=this.currentSpriteIndex===s})}setAnimation(t,e){let n=this.animations.get(t);if(!n)return;let{loop:r,frames:s}=n,o=s[this.currentAnimationIndex];t===this.currentAnimation?(this.currentAnimationFrame=o.key,this.currentAnimationTime+=e,this.setSprite(this.currentAnimationFrame)):this.currentAnimation=t,this.currentAnimationTime>o.time&&this.currentAnimationIndex++,this.currentAnimationIndex>=s.length&&(r?(this.currentAnimationIndex=0,this.currentAnimationTime=0):this.currentAnimationTime=s[this.currentAnimationIndex].time)}getCurrentRotationQuaternion(){return this.transformStore?.dirty.rotation?this.transformStore.rotation:this.body?.rotation?.()??null}syncSpriteMaterials(){let t=this.getCurrentRotationQuaternion();this.sprites.forEach(e=>{if(e.material&&t){let r=new ct(t.x,t.y,t.z,t.w),s=new pt().setFromQuaternion(r,"XYZ");e.material.rotation=s.z}let n=C(this.options.size,_);e.scale.set(n.x,n.y,n.z)})}spriteSetup(t){this.syncSpriteMaterials()}spriteUpdate(t){this.syncSpriteMaterials()}spriteDestroy(t){this.sprites.forEach(e=>{e.removeFromParent()}),this.group?.remove(...this.sprites),this.group?.removeFromParent()}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type)}}};function P(...i){return S({args:i,defaultConfig:W,EntityClass:x,BuilderClass:F,CollisionBuilderClass:R,entityType:x.type,cloneFactory:t=>P(t??{})})}import{Color as X,Group as xt}from"three";import{Line2NodeMaterial as _t}from"three/webgpu";import{Line2 as Ct}from"three/addons/lines/webgpu/Line2.js";import{Color as N}from"three";import{LineGeometry as gt}from"three/addons/lines/LineGeometry.js";function z(i){let t=[];for(let e of i){let{x:n,y:r,z:s}=u(e,h);t.push(n,r,s)}return t}function L(i,t,e){if(!i||i.length===0)return;let n=[],r=new N(e);for(let s=0;s<t;s++){let o=i[s]??i[i.length-1]??e,a=new N(o??r);n.push(a.r,a.g,a.b)}return n}function Y(i){let t=new gt,e=z(i.points);t.setPositions(e);let n=L(i.colors,i.points.length,"#ffffff");return n&&t.setColors(n),t}var m={...v,points:[{x:0,y:0,z:0},{x:1,y:0,z:0}],linewidth:1,worldUnits:!0,alphaToCoverage:!1,opacity:1,transparent:!1,dashed:!1,dashSize:1,gapSize:1,pickThreshold:0},vt=Symbol("Line");function M(i,t){if(!i||i.length<2)throw new Error(`${t}: at least two points are required`);return i}function j(i){return i instanceof X?i.clone():new X(i??"#ffffff")}function St(i){let t=!!i.colors?.length,e=new _t({color:j(i.color).getHex(),linewidth:i.linewidth??m.linewidth,worldUnits:i.worldUnits??m.worldUnits,vertexColors:t,dashed:i.dashed??!1,dashSize:i.dashSize??m.dashSize,gapSize:i.gapSize??m.gapSize,transparent:i.transparent??!1,opacity:i.opacity??1});return e.alphaToCoverage=i.alphaToCoverage??!1,e}function bt(i){return!i.point||!i.pointOnLine||i.faceIndex==null?null:{point:i.point.clone(),pointOnLine:i.pointOnLine.clone(),faceIndex:i.faceIndex,distance:i.distance}}function Et(i,t,e={}){let n=t.getLineObject();if(!n)return null;let r=e.threshold??t.options.pickThreshold??0,s=i.params.Line2??{threshold:0};s.threshold=r,i.params.Line2=s;let a=i.intersectObject(n,!1)[0];return a?bt(a):null}var Z=class i extends y{static type=vt;_line=null;_geometry=null;_material=null;constructor(t){super();let e=d(m,t);e.points=M(e.points,"ZylemLine").map(n=>u(n,h)),this.options=e}create(){return this.disposeLineResources(),this.group=new xt,this.rebuildLine(),this.applyGroupPosition(),super.create()}setPoints(t,e){if(M(t,"setPoints"),this.options.points=t.map(r=>u(r,h)),e&&(this.options.colors=e),!this._line||!this._geometry||!this._material)return this;this._geometry.setPositions(z(this.options.points));let n=L(this.options.colors,this.options.points.length,j(this.options.color));return n&&this._geometry.setColors(n),this._material.vertexColors=!!this.options.colors?.length,this.options.dashed&&this._line.computeLineDistances(),this._geometry.computeBoundingBox(),this._geometry.computeBoundingSphere(),this}getLineObject(){return this._line}pickFromRaycaster(t,e={}){return Et(t,this,e)}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type),points:this.options.points.length,linewidth:this.options.linewidth??m.linewidth,worldUnits:this.options.worldUnits??m.worldUnits}}rebuildLine(){this._geometry=Y({points:this.options.points,colors:this.options.colors}),this._material=St(this.options),this._line=new Ct(this._geometry,this._material),this.options.dashed&&this._line.computeLineDistances(),this.group?.add(this._line)}applyGroupPosition(){if(!this.group)return;let t=u(this.options.position,h);this.group.position.set(t.x,t.y,t.z)}_cleanup(t){this.disposeLineResources(),super._cleanup(t)}disposeLineResources(){this._line?.removeFromParent(),this._geometry?.dispose(),this._material?.dispose(),this._line=null,this._geometry=null,this._material=null}};function G(...i){let t=V(i,m);M(t.points,"createLine");let e=new Z(t);return D(e,n=>G(n??{}))}var A={registry:new Map,register(i,t){this.registry.set(i,t)},createFromBlueprint(i){let t=this.registry.get(i.type);if(!t)throw new Error(`Unknown entity type: ${i.type}`);let e={...i.data,position:i.position?{x:i.position[0],y:i.position[1],z:0}:void 0,name:i.id};return t(e)}};A.register("text",i=>I(i));A.register("sprite",i=>P(i));A.register("line",i=>G(i));function Ce(i){return{template:i,generate(t){let e=[];for(let n=0;n<t;n++)e.push(i.clone());return e}}}export{c as a,at as b,g as c,I as d,ft as e,x as f,P as g,vt as h,Et as i,Z as j,G as k,A as l,Ce as m};
@@ -0,0 +1 @@
1
+ import{a as o,i}from"./chunk-W5SXED5T.js";var e=null;function a(t){return e=t,()=>{e===t&&(e=null)}}function u(t){if(!e)return console.warn("focusEntity: no active stage focus context"),!1;let n=e.resolveEntity(t);if(!n)return console.warn(`focusEntity: entity ${t} not found`),!1;let r=n.group??n.mesh??null;return r?(o.enabled||(o.enabled=!0),e.ensureDebugReady?.(),i(t),e.frameObject(r),!0):(console.warn(`focusEntity: entity ${t} has no group/mesh`),!1)}export{a,u as b};
@@ -1,4 +1,4 @@
1
- import{j as y}from"./chunk-MSC2BEO5.js";var r={baseFill:"rgba(12,18,24,0.72)",joystickStroke:"rgba(245,247,255,0.72)",joystickInnerStroke:"rgba(255,255,255,0.18)",joystickAccentFill:"rgba(255,255,255,0.04)",joystickTabFill:"rgba(245,247,255,0.45)",thumbFill:"rgba(22,30,38,0.92)",thumbStroke:"rgba(245,247,255,0.85)",thumbInnerFill:"rgba(255,255,255,0.08)",defaultButtonAccent:"rgba(245,247,255,0.92)"},b={baseFill:"rgba(8,14,24,0.70)",joystickStroke:"rgba(207,250,254,0.85)",joystickInnerStroke:"rgba(45,212,191,0.35)",joystickAccentFill:"rgba(20,184,166,0.08)",joystickTabFill:"rgba(207,250,254,0.55)",thumbFill:"rgba(13,148,136,0.88)",thumbStroke:"rgba(240,253,250,0.95)",thumbInnerFill:"rgba(240,253,250,0.16)",defaultButtonAccent:"#67e8f9",buttonAccents:{A:"#8b5cf6",B:"#fb7185",X:"#22d3ee",Y:"#facc15"}},m={default:r,lagoon:b};function l(e){return e?typeof e=="string"?m[e]??r:e:r}function f(e,t,o){return o||(e.buttonAccents?.[t]??e.defaultButtonAccent)}function h(e){let t=l(e);return`
1
+ import{k as y}from"./chunk-UG22Z42P.js";var r={baseFill:"rgba(12,18,24,0.72)",joystickStroke:"rgba(245,247,255,0.72)",joystickInnerStroke:"rgba(255,255,255,0.18)",joystickAccentFill:"rgba(255,255,255,0.04)",joystickTabFill:"rgba(245,247,255,0.45)",thumbFill:"rgba(22,30,38,0.92)",thumbStroke:"rgba(245,247,255,0.85)",thumbInnerFill:"rgba(255,255,255,0.08)",defaultButtonAccent:"rgba(245,247,255,0.92)"},b={baseFill:"rgba(8,14,24,0.70)",joystickStroke:"rgba(207,250,254,0.85)",joystickInnerStroke:"rgba(45,212,191,0.35)",joystickAccentFill:"rgba(20,184,166,0.08)",joystickTabFill:"rgba(207,250,254,0.55)",thumbFill:"rgba(13,148,136,0.88)",thumbStroke:"rgba(240,253,250,0.95)",thumbInnerFill:"rgba(240,253,250,0.16)",defaultButtonAccent:"#67e8f9",buttonAccents:{A:"#8b5cf6",B:"#fb7185",X:"#22d3ee",Y:"#facc15"}},m={default:r,lagoon:b};function l(e){return e?typeof e=="string"?m[e]??r:e:r}function f(e,t,o){return o||(e.buttonAccents?.[t]??e.defaultButtonAccent)}function h(e){let t=l(e);return`
2
2
  <svg viewBox="0 0 140 140" width="100%" height="100%" aria-hidden="true">
3
3
  <circle cx="70" cy="70" r="62" fill="${t.baseFill}" stroke="${t.joystickStroke}" stroke-width="4" />
4
4
  <circle cx="70" cy="70" r="42" fill="${t.joystickAccentFill}" stroke="${t.joystickInnerStroke}" stroke-width="2" />