@zylem/game-lib 0.6.0 → 0.6.2

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.
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lib/core/utility/path-utils.ts","../src/lib/game/game-event-bus.ts","../src/lib/game/game-state.ts","../src/lib/debug/debug-state.ts","../src/lib/core/flags.ts","../src/lib/core/base-node.ts","../src/lib/systems/transformable.system.ts","../src/lib/entities/entity.ts","../src/lib/entities/delegates/loader.ts","../src/lib/entities/create.ts","../src/lib/core/entity-asset-loader.ts","../src/lib/entities/delegates/animation.ts","../src/lib/collision/collision-builder.ts","../src/lib/graphics/mesh.ts","../src/lib/core/utility/strings.ts","../src/lib/graphics/shaders/fragment/stars.glsl","../src/lib/graphics/shaders/fragment/fire.glsl","../src/lib/graphics/shaders/fragment/standard.glsl","../src/lib/graphics/shaders/fragment/debug.glsl","../src/lib/graphics/shaders/vertex/object-shader.glsl","../src/lib/graphics/shaders/vertex/debug.glsl","../src/lib/core/preset-shader.ts","../src/lib/graphics/material.ts","../src/lib/entities/builder.ts","../src/lib/entities/actor.ts","../src/lib/collision/world.ts","../src/lib/graphics/zylem-scene.ts","../src/lib/stage/stage-state.ts","../src/lib/core/utility/vector.ts","../src/lib/core/lifecycle-base.ts","../src/lib/stage/debug-entity-cursor.ts","../src/lib/stage/stage-debug-delegate.ts","../src/lib/stage/stage-camera-debug-delegate.ts","../src/lib/camera/perspective.ts","../src/lib/camera/third-person.ts","../src/lib/camera/fixed-2d.ts","../src/lib/graphics/shaders/vertex/standard.glsl","../src/lib/graphics/render-pass.ts","../src/lib/camera/camera-debug-delegate.ts","../src/lib/camera/zylem-camera.ts","../src/lib/stage/stage-camera-delegate.ts","../src/lib/stage/stage-loading-delegate.ts","../src/lib/core/utility/options-parser.ts","../src/lib/stage/stage-config.ts","../src/lib/stage/zylem-stage.ts","../src/lib/camera/camera.ts","../src/lib/stage/stage-default.ts","../src/lib/stage/stage.ts","../src/lib/game/game-default.ts","../src/lib/game/zylem-game.ts","../src/lib/input/keyboard-provider.ts","../src/lib/input/gamepad-provider.ts","../src/lib/input/input-manager.ts","../src/lib/core/three-addons/Timer.ts","../src/lib/device/aspect-ratio.ts","../src/lib/game/game-retro-resolutions.ts","../src/lib/game/game-config.ts","../src/lib/game/game-canvas.ts","../src/lib/game/game-debug-delegate.ts","../src/lib/game/game-loading-delegate.ts","../src/lib/game/game-renderer-observer.ts","../src/lib/game/game.ts","../src/lib/core/utility/nodes.ts","../src/lib/stage/stage-manager.ts","../src/lib/stage/stage-factory.ts","../src/lib/entities/text.ts","../src/lib/entities/delegates/debug.ts","../src/lib/entities/sprite.ts","../src/lib/entities/entity-factory.ts","../src/api/main.ts","../src/lib/stage/entity-spawner.ts","../src/lib/core/vessel.ts","../src/lib/entities/box.ts","../src/lib/entities/sphere.ts","../src/lib/entities/plane.ts","../src/lib/graphics/geometries/XZPlaneGeometry.ts","../src/lib/entities/zone.ts","../src/lib/entities/rect.ts","../src/lib/collision/utils.ts","../src/lib/actions/behaviors/ricochet/ricochet-2d-collision.ts","../src/lib/actions/behaviors/ricochet/ricochet.ts","../src/lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.ts","../src/lib/actions/behaviors/boundaries/boundary.ts","../src/lib/actions/behaviors/movement/movement-sequence-2d.ts","../src/lib/actions/capabilities/moveable.ts","../src/lib/actions/capabilities/rotatable.ts","../src/lib/actions/capabilities/transformable.ts","../src/lib/entities/destroy.ts","../src/lib/sounds/ricochet-sound.ts","../src/lib/sounds/ping-pong-sound.ts","../src/lib/actions/global-change.ts","../src/web-components/zylem-game.ts","../src/lib/types/entity-type-map.ts"],"sourcesContent":["/**\n * Lodash-style path utilities for getting/setting nested object values.\n */\n\n/**\n * Get a value from an object by path string.\n * @example getByPath({ player: { health: 100 } }, 'player.health') // 100\n */\nexport function getByPath<T = unknown>(obj: object, path: string): T | undefined {\n\tif (!path) return undefined;\n\tconst keys = path.split('.');\n\tlet current: any = obj;\n\tfor (const key of keys) {\n\t\tif (current == null || typeof current !== 'object') {\n\t\t\treturn undefined;\n\t\t}\n\t\tcurrent = current[key];\n\t}\n\treturn current as T;\n}\n\n/**\n * Set a value on an object by path string, creating intermediate objects as needed.\n * @example setByPath({}, 'player.health', 100) // { player: { health: 100 } }\n */\nexport function setByPath(obj: object, path: string, value: unknown): void {\n\tif (!path) return;\n\tconst keys = path.split('.');\n\tlet current: any = obj;\n\tfor (let i = 0; i < keys.length - 1; i++) {\n\t\tconst key = keys[i];\n\t\tif (current[key] == null || typeof current[key] !== 'object') {\n\t\t\tcurrent[key] = {};\n\t\t}\n\t\tcurrent = current[key];\n\t}\n\tcurrent[keys[keys.length - 1]] = value;\n}\n\n/**\n * Check if a path exists in an object.\n */\nexport function hasPath(obj: object, path: string): boolean {\n\tif (!path) return false;\n\tconst keys = path.split('.');\n\tlet current: any = obj;\n\tfor (const key of keys) {\n\t\tif (current == null || typeof current !== 'object' || !(key in current)) {\n\t\t\treturn false;\n\t\t}\n\t\tcurrent = current[key];\n\t}\n\treturn true;\n}\n","import { LoadingEvent } from '../core/interfaces';\n\n/**\n * Event types for the game event bus.\n */\nexport type GameEventType = \n\t| 'stage:loading:start'\n\t| 'stage:loading:progress'\n\t| 'stage:loading:complete'\n\t| 'game:state:updated';\n\n/**\n * Payload for stage loading events.\n */\nexport interface StageLoadingPayload extends LoadingEvent {\n\tstageName?: string;\n\tstageIndex?: number;\n}\n\n/**\n * Payload for game state update events.\n */\nexport interface GameStateUpdatedPayload {\n\tpath: string;\n\tvalue: unknown;\n\tpreviousValue?: unknown;\n}\n\n/**\n * Event map for typed event handling.\n */\nexport interface GameEventMap {\n\t'stage:loading:start': StageLoadingPayload;\n\t'stage:loading:progress': StageLoadingPayload;\n\t'stage:loading:complete': StageLoadingPayload;\n\t'game:state:updated': GameStateUpdatedPayload;\n}\n\ntype EventCallback<T> = (payload: T) => void;\n\n/**\n * Simple event bus for game-stage communication.\n * Used to decouple stage loading events from direct coupling.\n */\nexport class GameEventBus {\n\tprivate listeners: Map<GameEventType, Set<EventCallback<any>>> = new Map();\n\n\t/**\n\t * Subscribe to an event type.\n\t */\n\ton<K extends GameEventType>(event: K, callback: EventCallback<GameEventMap[K]>): () => void {\n\t\tif (!this.listeners.has(event)) {\n\t\t\tthis.listeners.set(event, new Set());\n\t\t}\n\t\tthis.listeners.get(event)!.add(callback);\n\t\treturn () => this.off(event, callback);\n\t}\n\n\t/**\n\t * Unsubscribe from an event type.\n\t */\n\toff<K extends GameEventType>(event: K, callback: EventCallback<GameEventMap[K]>): void {\n\t\tthis.listeners.get(event)?.delete(callback);\n\t}\n\n\t/**\n\t * Emit an event to all subscribers.\n\t */\n\temit<K extends GameEventType>(event: K, payload: GameEventMap[K]): void {\n\t\tconst callbacks = this.listeners.get(event);\n\t\tif (!callbacks) return;\n\t\tfor (const cb of callbacks) {\n\t\t\ttry {\n\t\t\t\tcb(payload);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(`Error in event handler for ${event}`, e);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Clear all listeners.\n\t */\n\tdispose(): void {\n\t\tthis.listeners.clear();\n\t}\n}\n\n/**\n * Singleton event bus instance for global game events.\n */\nexport const gameEventBus = new GameEventBus();\n","import { proxy, subscribe } from 'valtio/vanilla';\nimport { getByPath, setByPath } from '../core/utility/path-utils';\nimport { gameEventBus } from './game-event-bus';\n\n/**\n * Internal game state store using valtio proxy for reactivity.\n */\nconst state = proxy({\n\tid: '',\n\tglobals: {} as Record<string, unknown>,\n\ttime: 0,\n});\n\n/**\n * Track active subscriptions for cleanup on game dispose.\n */\nconst activeSubscriptions: Set<() => void> = new Set();\n\n/**\n * Set a global value by path.\n * Emits a 'game:state:updated' event when the value changes.\n * @example setGlobal('score', 100)\n * @example setGlobal('player.health', 50)\n */\nexport function setGlobal(path: string, value: unknown): void {\n\tconst previousValue = getByPath(state.globals, path);\n\tsetByPath(state.globals, path, value);\n\n\tgameEventBus.emit('game:state:updated', {\n\t\tpath,\n\t\tvalue,\n\t\tpreviousValue,\n\t});\n}\n\n/**\n * Create/initialize a global with a default value.\n * Only sets the value if it doesn't already exist.\n * Use this to ensure globals have initial values before game starts.\n * @example createGlobal('score', 0)\n * @example createGlobal('player.health', 100)\n */\nexport function createGlobal<T>(path: string, defaultValue: T): T {\n\tconst existing = getByPath<T>(state.globals, path);\n\tif (existing === undefined) {\n\t\tsetByPath(state.globals, path, defaultValue);\n\t\treturn defaultValue;\n\t}\n\treturn existing;\n}\n\n/**\n * Get a global value by path.\n * @example getGlobal('score') // 100\n * @example getGlobal<number>('player.health') // 50\n */\nexport function getGlobal<T = unknown>(path: string): T | undefined {\n\treturn getByPath<T>(state.globals, path);\n}\n\n/**\n * Subscribe to changes on a global value at a specific path.\n * Returns an unsubscribe function. Subscriptions are automatically\n * cleaned up when the game is disposed.\n * @example const unsub = onGlobalChange('score', (val) => console.log(val));\n */\nexport function onGlobalChange<T = unknown>(\n\tpath: string,\n\tcallback: (value: T) => void\n): () => void {\n\tlet previous = getByPath<T>(state.globals, path);\n\tconst unsub = subscribe(state.globals, () => {\n\t\tconst current = getByPath<T>(state.globals, path);\n\t\tif (current !== previous) {\n\t\t\tprevious = current;\n\t\t\tcallback(current as T);\n\t\t}\n\t});\n\tactiveSubscriptions.add(unsub);\n\treturn () => {\n\t\tunsub();\n\t\tactiveSubscriptions.delete(unsub);\n\t};\n}\n\n/**\n * Subscribe to changes on multiple global paths.\n * Callback fires when any of the paths change, receiving all current values.\n * Subscriptions are automatically cleaned up when the game is disposed.\n * @example const unsub = onGlobalChanges(['score', 'lives'], ([score, lives]) => console.log(score, lives));\n */\nexport function onGlobalChanges<T extends unknown[] = unknown[]>(\n\tpaths: string[],\n\tcallback: (values: T) => void\n): () => void {\n\tlet previousValues = paths.map(p => getByPath(state.globals, p));\n\tconst unsub = subscribe(state.globals, () => {\n\t\tconst currentValues = paths.map(p => getByPath(state.globals, p));\n\t\tconst hasChange = currentValues.some((val, i) => val !== previousValues[i]);\n\t\tif (hasChange) {\n\t\t\tpreviousValues = currentValues;\n\t\t\tcallback(currentValues as T);\n\t\t}\n\t});\n\tactiveSubscriptions.add(unsub);\n\treturn () => {\n\t\tunsub();\n\t\tactiveSubscriptions.delete(unsub);\n\t};\n}\n\n/**\n * Get the entire globals object (read-only snapshot).\n */\nexport function getGlobals<T = Record<string, unknown>>(): T {\n\treturn state.globals as T;\n}\n\n/**\n * Initialize globals from an object. Used internally during game setup.\n */\nexport function initGlobals(globals: Record<string, unknown>): void {\n\tfor (const [key, value] of Object.entries(globals)) {\n\t\tsetByPath(state.globals, key, value);\n\t}\n}\n\n/**\n * Reset all globals. Used internally on game dispose.\n */\nexport function resetGlobals(): void {\n\tstate.globals = {};\n}\n\n/**\n * Unsubscribe all active global subscriptions.\n * Used internally on game dispose to prevent old callbacks from firing.\n */\nexport function clearGlobalSubscriptions(): void {\n\tfor (const unsub of activeSubscriptions) {\n\t\tunsub();\n\t}\n\tactiveSubscriptions.clear();\n}\n\nexport { state };","import { proxy } from 'valtio';\nimport type { GameEntity } from '../entities/entity';\n\nexport type DebugTools = 'select' | 'translate' | 'rotate' | 'scale' | 'delete' | 'none';\n\nexport interface DebugState {\n\tenabled: boolean;\n\tpaused: boolean;\n\ttool: DebugTools;\n\tselectedEntity: GameEntity<any> | null;\n\thoveredEntity: GameEntity<any> | null;\n\tflags: Set<string>;\n}\n\nexport const debugState = proxy<DebugState>({\n\tenabled: false,\n\tpaused: false,\n\ttool: 'none',\n\tselectedEntity: null,\n\thoveredEntity: null,\n\tflags: new Set(),\n});\n\nexport function isPaused(): boolean {\n\treturn debugState.paused;\n}\n\nexport function setPaused(paused: boolean): void {\n\tdebugState.paused = paused;\n}\n\nexport function setDebugFlag(flag: string, value: boolean): void {\n\tif (value) {\n\t\tdebugState.flags.add(flag);\n\t} else {\n\t\tdebugState.flags.delete(flag);\n\t}\n}\n\nexport function getDebugTool(): DebugTools {\n\treturn debugState.tool;\n}\n\nexport function setDebugTool(tool: DebugTools): void {\n\tdebugState.tool = tool;\n}\n\nexport function getSelectedEntity(): GameEntity<any> | null {\n\treturn debugState.selectedEntity;\n}\n\nexport function setSelectedEntity(entity: GameEntity<any> | null): void {\n\tdebugState.selectedEntity = entity;\n}\n\nexport function getHoveredEntity(): GameEntity<any> | null {\n\treturn debugState.hoveredEntity;\n}\n\nexport function setHoveredEntity(entity: GameEntity<any> | null): void {\n\tdebugState.hoveredEntity = entity;\n}\n\nexport function resetHoveredEntity(): void {\n\tdebugState.hoveredEntity = null;\n}\n","/** Vite build flags */\nexport const DEBUG_FLAG = import.meta.env.VITE_DEBUG_FLAG === 'true';","import {\n\tCleanupContext,\n\tCleanupFunction,\n\tDestroyContext,\n\tDestroyFunction,\n\tLoadedContext,\n\tLoadedFunction,\n\tSetupContext,\n\tSetupFunction,\n\tUpdateContext,\n\tUpdateFunction,\n} from \"./base-node-life-cycle\";\nimport { DEBUG_FLAG } from \"./flags\";\nimport { nanoid } from \"nanoid\";\nimport { NodeInterface } from \"./node-interface\";\n\nexport type BaseNodeOptions<T = any> = BaseNode | Partial<T>;\n\n/**\n * Lifecycle callback arrays - each lifecycle event can have multiple callbacks\n * that execute in order.\n */\nexport interface LifecycleCallbacks<T> {\n\tsetup: Array<SetupFunction<T>>;\n\tloaded: Array<LoadedFunction<T>>;\n\tupdate: Array<UpdateFunction<T>>;\n\tdestroy: Array<DestroyFunction<T>>;\n\tcleanup: Array<CleanupFunction<T>>;\n}\n\nexport abstract class BaseNode<Options = any, T = any> implements NodeInterface {\n\tprotected parent: NodeInterface | null = null;\n\tprotected children: NodeInterface[] = [];\n\tpublic options: Options;\n\tpublic eid: number = 0;\n\tpublic uuid: string = '';\n\tpublic name: string = '';\n\tpublic markedForRemoval: boolean = false;\n\n\t/**\n\t * Lifecycle callback arrays - use onSetup(), onUpdate(), etc. to add callbacks\n\t */\n\tprotected lifecycleCallbacks: LifecycleCallbacks<this> = {\n\t\tsetup: [],\n\t\tloaded: [],\n\t\tupdate: [],\n\t\tdestroy: [],\n\t\tcleanup: [],\n\t};\n\n\tconstructor(args: BaseNodeOptions[] = []) {\n\t\tconst options = args\n\t\t\t.filter(arg => !(arg instanceof BaseNode))\n\t\t\t.reduce((acc, opt) => ({ ...acc, ...opt }), {});\n\t\tthis.options = options as Options;\n\t\tthis.uuid = nanoid();\n\t}\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Fluent API for adding lifecycle callbacks\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\t/**\n\t * Add setup callbacks to be executed in order during nodeSetup\n\t */\n\tpublic onSetup(...callbacks: Array<SetupFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.setup.push(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Add loaded callbacks to be executed in order during nodeLoaded\n\t */\n\tpublic onLoaded(...callbacks: Array<LoadedFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.loaded.push(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Add update callbacks to be executed in order during nodeUpdate\n\t */\n\tpublic onUpdate(...callbacks: Array<UpdateFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.update.push(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Add destroy callbacks to be executed in order during nodeDestroy\n\t */\n\tpublic onDestroy(...callbacks: Array<DestroyFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.destroy.push(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Add cleanup callbacks to be executed in order during nodeCleanup\n\t */\n\tpublic onCleanup(...callbacks: Array<CleanupFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.cleanup.push(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Prepend setup callbacks (run before existing ones)\n\t */\n\tpublic prependSetup(...callbacks: Array<SetupFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.setup.unshift(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Prepend update callbacks (run before existing ones)\n\t */\n\tpublic prependUpdate(...callbacks: Array<UpdateFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.update.unshift(...callbacks);\n\t\treturn this;\n\t}\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Tree structure\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\tpublic setParent(parent: NodeInterface | null): void {\n\t\tthis.parent = parent;\n\t}\n\n\tpublic getParent(): NodeInterface | null {\n\t\treturn this.parent;\n\t}\n\n\tpublic add(baseNode: NodeInterface): void {\n\t\tthis.children.push(baseNode);\n\t\tbaseNode.setParent(this);\n\t}\n\n\tpublic remove(baseNode: NodeInterface): void {\n\t\tconst index = this.children.indexOf(baseNode);\n\t\tif (index !== -1) {\n\t\t\tthis.children.splice(index, 1);\n\t\t\tbaseNode.setParent(null);\n\t\t}\n\t}\n\n\tpublic getChildren(): NodeInterface[] {\n\t\treturn this.children;\n\t}\n\n\tpublic isComposite(): boolean {\n\t\treturn this.children.length > 0;\n\t}\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Abstract methods for subclass implementation\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\tpublic abstract create(): T;\n\n\tprotected abstract _setup(params: SetupContext<this>): void;\n\n\tprotected abstract _loaded(params: LoadedContext<this>): Promise<void>;\n\n\tprotected abstract _update(params: UpdateContext<this>): void;\n\n\tprotected abstract _destroy(params: DestroyContext<this>): void;\n\n\tprotected abstract _cleanup(params: CleanupContext<this>): Promise<void>;\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Node lifecycle execution - runs internal + callback arrays\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\tpublic nodeSetup(params: SetupContext<this>) {\n\t\tif (DEBUG_FLAG) { /** */ }\n\t\tthis.markedForRemoval = false;\n\n\t\t// 1. Internal setup\n\t\tif (typeof this._setup === 'function') {\n\t\t\tthis._setup(params);\n\t\t}\n\n\t\t// 2. Run all setup callbacks in order\n\t\tfor (const callback of this.lifecycleCallbacks.setup) {\n\t\t\tcallback(params);\n\t\t}\n\n\t\t// 3. Setup children\n\t\tthis.children.forEach(child => child.nodeSetup(params));\n\t}\n\n\tpublic nodeUpdate(params: UpdateContext<this>): void {\n\t\tif (this.markedForRemoval) {\n\t\t\treturn;\n\t\t}\n\n\t\t// 1. Internal update\n\t\tif (typeof this._update === 'function') {\n\t\t\tthis._update(params);\n\t\t}\n\n\t\t// 2. Run all update callbacks in order\n\t\tfor (const callback of this.lifecycleCallbacks.update) {\n\t\t\tcallback(params);\n\t\t}\n\n\t\t// 3. Update children\n\t\tthis.children.forEach(child => child.nodeUpdate(params));\n\t}\n\n\tpublic nodeDestroy(params: DestroyContext<this>): void {\n\t\t// 1. Destroy children first\n\t\tthis.children.forEach(child => child.nodeDestroy(params));\n\n\t\t// 2. Run all destroy callbacks in order\n\t\tfor (const callback of this.lifecycleCallbacks.destroy) {\n\t\t\tcallback(params);\n\t\t}\n\n\t\t// 3. Internal destroy\n\t\tif (typeof this._destroy === 'function') {\n\t\t\tthis._destroy(params);\n\t\t}\n\n\t\tthis.markedForRemoval = true;\n\t}\n\n\tpublic async nodeLoaded(params: LoadedContext<this>): Promise<void> {\n\t\t// 1. Internal loaded\n\t\tif (typeof this._loaded === 'function') {\n\t\t\tawait this._loaded(params);\n\t\t}\n\n\t\t// 2. Run all loaded callbacks in order\n\t\tfor (const callback of this.lifecycleCallbacks.loaded) {\n\t\t\tcallback(params);\n\t\t}\n\t}\n\n\tpublic async nodeCleanup(params: CleanupContext<this>): Promise<void> {\n\t\t// 1. Run all cleanup callbacks in order\n\t\tfor (const callback of this.lifecycleCallbacks.cleanup) {\n\t\t\tcallback(params);\n\t\t}\n\n\t\t// 2. Internal cleanup\n\t\tif (typeof this._cleanup === 'function') {\n\t\t\tawait this._cleanup(params);\n\t\t}\n\t}\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Options\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\tpublic getOptions(): Options {\n\t\treturn this.options;\n\t}\n\n\tpublic setOptions(options: Partial<Options>): void {\n\t\tthis.options = { ...this.options, ...options };\n\t}\n}","import {\n\tdefineSystem,\n\tdefineQuery,\n\tdefineComponent,\n\tTypes,\n\tremoveQuery,\n\ttype IWorld,\n} from 'bitecs';\nimport { Quaternion } from 'three';\nimport { StageEntity } from '../interfaces/entity';\nimport RAPIER from '@dimforge/rapier3d-compat';\n\nexport type StageSystem = {\n\t_childrenMap: Map<number, StageEntity & { body: RAPIER.RigidBody }>;\n}\n\nexport const position = defineComponent({\n\tx: Types.f32,\n\ty: Types.f32,\n\tz: Types.f32\n});\n\nexport const rotation = defineComponent({\n\tx: Types.f32,\n\ty: Types.f32,\n\tz: Types.f32,\n\tw: Types.f32\n});\n\nexport const scale = defineComponent({\n\tx: Types.f32,\n\ty: Types.f32,\n\tz: Types.f32\n});\n\n// Reusable quaternion to avoid allocations per frame\nconst _tempQuaternion = new Quaternion();\n\nexport type TransformSystemResult = {\n\tsystem: ReturnType<typeof defineSystem>;\n\tdestroy: (world: IWorld) => void;\n};\n\nexport default function createTransformSystem(stage: StageSystem): TransformSystemResult {\n\tconst queryTerms = [position, rotation];\n\tconst transformQuery = defineQuery(queryTerms);\n\tconst stageEntities = stage._childrenMap;\n\n\tconst system = defineSystem((world) => {\n\t\tconst entities = transformQuery(world);\n\t\tif (stageEntities === undefined) {\n\t\t\treturn world;\n\t\t}\n\n\t\tfor (const [key, stageEntity] of stageEntities) {\n\t\t\t// Early bailout - combine conditions\n\t\t\tif (!stageEntity?.body || stageEntity.markedForRemoval) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst id = entities[key];\n\t\t\tconst body = stageEntity.body;\n\t\t\tconst target = stageEntity.group ?? stageEntity.mesh;\n\n\t\t\t// Position sync\n\t\t\tconst translation = body.translation();\n\t\t\tposition.x[id] = translation.x;\n\t\t\tposition.y[id] = translation.y;\n\t\t\tposition.z[id] = translation.z;\n\n\t\t\tif (target) {\n\t\t\t\ttarget.position.set(translation.x, translation.y, translation.z);\n\t\t\t}\n\n\t\t\t// Skip rotation if controlled externally\n\t\t\tif (stageEntity.controlledRotation) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Rotation sync - reuse quaternion\n\t\t\tconst rot = body.rotation();\n\t\t\trotation.x[id] = rot.x;\n\t\t\trotation.y[id] = rot.y;\n\t\t\trotation.z[id] = rot.z;\n\t\t\trotation.w[id] = rot.w;\n\n\t\t\tif (target) {\n\t\t\t\t_tempQuaternion.set(rot.x, rot.y, rot.z, rot.w);\n\t\t\t\ttarget.setRotationFromQuaternion(_tempQuaternion);\n\t\t\t}\n\t\t}\n\n\t\treturn world;\n\t});\n\n\tconst destroy = (world: IWorld) => {\n\t\t// Remove the query from bitecs world tracking\n\t\tremoveQuery(world, transformQuery);\n\t};\n\n\treturn { system, destroy };\n}","import { Mesh, Material, ShaderMaterial, Group, Color } from \"three\";\nimport { Collider, ColliderDesc, RigidBody, RigidBodyDesc } from \"@dimforge/rapier3d-compat\";\nimport { position, rotation, scale } from \"../systems/transformable.system\";\nimport { Vec3 } from \"../core/vector\";\nimport { MaterialBuilder, MaterialOptions } from \"../graphics/material\";\nimport { CollisionOptions } from \"../collision/collision-builder\";\nimport { BaseNode } from \"../core/base-node\";\nimport { DestroyContext, SetupContext, UpdateContext, LoadedContext, CleanupContext } from \"../core/base-node-life-cycle\";\nimport type { EntityMeshBuilder, EntityCollisionBuilder } from \"./builder\";\nimport { Behavior } from \"../actions/behaviors/behavior\";\n\nexport interface CollisionContext<T, O extends GameEntityOptions, TGlobals extends Record<string, unknown> = any> {\n\tentity: T;\n\tother: GameEntity<O>;\n\tglobals: TGlobals;\n}\n\nexport type BehaviorContext<T, O extends GameEntityOptions> =\n\tSetupContext<T, O> |\n\tUpdateContext<T, O> |\n\tCollisionContext<T, O> |\n\tDestroyContext<T, O>;\n\nexport type BehaviorCallback<T, O extends GameEntityOptions> = (params: BehaviorContext<T, O>) => void;\n\nexport interface CollisionDelegate<T, O extends GameEntityOptions> {\n\tcollision?: ((params: CollisionContext<T, O>) => void)[];\n}\n\nexport type IBuilder<BuilderOptions = any> = {\n\tpreBuild: (options: BuilderOptions) => BuilderOptions;\n\tbuild: (options: BuilderOptions) => BuilderOptions;\n\tpostBuild: (options: BuilderOptions) => BuilderOptions;\n}\n\nexport type GameEntityOptions = {\n\tname?: string;\n\tcolor?: Color;\n\tsize?: Vec3;\n\tposition?: Vec3;\n\tbatched?: boolean;\n\tcollision?: Partial<CollisionOptions>;\n\tmaterial?: Partial<MaterialOptions>;\n\tcustom?: { [key: string]: any };\n\tcollisionType?: string;\n\tcollisionGroup?: string;\n\tcollisionFilter?: string[];\n\t_builders?: {\n\t\tmeshBuilder?: IBuilder | EntityMeshBuilder | null;\n\t\tcollisionBuilder?: IBuilder | EntityCollisionBuilder | null;\n\t\tmaterialBuilder?: MaterialBuilder | null;\n\t};\n}\n\nexport abstract class GameEntityLifeCycle {\n\tabstract _setup(params: SetupContext<this>): void;\n\tabstract _update(params: UpdateContext<this>): void;\n\tabstract _destroy(params: DestroyContext<this>): void;\n}\n\nexport interface EntityDebugInfo {\n\tbuildInfo: () => Record<string, string>;\n}\n\nexport type BehaviorCallbackType = 'setup' | 'update' | 'destroy' | 'collision';\n\nexport class GameEntity<O extends GameEntityOptions> extends BaseNode<O> implements\n\tGameEntityLifeCycle,\n\tEntityDebugInfo {\n\tpublic behaviors: Behavior[] = [];\n\tpublic group: Group | undefined;\n\tpublic mesh: Mesh | undefined;\n\tpublic materials: Material[] | undefined;\n\tpublic bodyDesc: RigidBodyDesc | null = null;\n\tpublic body: RigidBody | null = null;\n\tpublic colliderDesc: ColliderDesc | undefined;\n\tpublic collider: Collider | undefined;\n\tpublic custom: Record<string, any> = {};\n\n\tpublic debugInfo: Record<string, any> = {};\n\tpublic debugMaterial: ShaderMaterial | undefined;\n\n\tpublic collisionDelegate: CollisionDelegate<this, O> = {\n\t\tcollision: [],\n\t};\n\tpublic collisionType?: string;\n\n\tpublic behaviorCallbackMap: Record<BehaviorCallbackType, BehaviorCallback<this, O>[]> = {\n\t\tsetup: [],\n\t\tupdate: [],\n\t\tdestroy: [],\n\t\tcollision: [],\n\t};\n\n\tconstructor() {\n\t\tsuper();\n\t}\n\n\tpublic create(): this {\n\t\tconst { position: setupPosition } = this.options;\n\t\tconst { x, y, z } = setupPosition || { x: 0, y: 0, z: 0 };\n\t\tthis.behaviors = [\n\t\t\t{ component: position, values: { x, y, z } },\n\t\t\t{ component: scale, values: { x: 0, y: 0, z: 0 } },\n\t\t\t{ component: rotation, values: { x: 0, y: 0, z: 0, w: 0 } },\n\t\t];\n\t\tthis.name = this.options.name || '';\n\t\treturn this;\n\t}\n\n\t/**\n\t * Add collision callbacks\n\t */\n\tpublic onCollision(...callbacks: ((params: CollisionContext<this, O>) => void)[]): this {\n\t\tconst existing = this.collisionDelegate.collision ?? [];\n\t\tthis.collisionDelegate.collision = [...existing, ...callbacks];\n\t\treturn this;\n\t}\n\n\t/**\n\t * Entity-specific setup - runs behavior callbacks\n\t * (User callbacks are handled by BaseNode's lifecycleCallbacks.setup)\n\t */\n\tpublic _setup(params: SetupContext<this>): void {\n\t\tthis.behaviorCallbackMap.setup.forEach(callback => {\n\t\t\tcallback({ ...params, me: this });\n\t\t});\n\t}\n\n\tprotected async _loaded(_params: LoadedContext<this>): Promise<void> { }\n\n\t/**\n\t * Entity-specific update - updates materials and runs behavior callbacks\n\t * (User callbacks are handled by BaseNode's lifecycleCallbacks.update)\n\t */\n\tpublic _update(params: UpdateContext<this>): void {\n\t\tthis.updateMaterials(params);\n\t\tthis.behaviorCallbackMap.update.forEach(callback => {\n\t\t\tcallback({ ...params, me: this });\n\t\t});\n\t}\n\n\t/**\n\t * Entity-specific destroy - runs behavior callbacks\n\t * (User callbacks are handled by BaseNode's lifecycleCallbacks.destroy)\n\t */\n\tpublic _destroy(params: DestroyContext<this>): void {\n\t\tthis.behaviorCallbackMap.destroy.forEach(callback => {\n\t\t\tcallback({ ...params, me: this });\n\t\t});\n\t}\n\n\tprotected async _cleanup(_params: CleanupContext<this>): Promise<void> { }\n\n\tpublic _collision(other: GameEntity<O>, globals?: any): void {\n\t\tif (this.collisionDelegate.collision?.length) {\n\t\t\tconst callbacks = this.collisionDelegate.collision;\n\t\t\tcallbacks.forEach(callback => {\n\t\t\t\tcallback({ entity: this, other, globals });\n\t\t\t});\n\t\t}\n\t\tthis.behaviorCallbackMap.collision.forEach(callback => {\n\t\t\tcallback({ entity: this, other, globals });\n\t\t});\n\t}\n\n\tpublic addBehavior(\n\t\tbehaviorCallback: ({ type: BehaviorCallbackType, handler: any })\n\t): this {\n\t\tconst handler = behaviorCallback.handler as unknown as BehaviorCallback<this, O>;\n\t\tif (handler) {\n\t\t\tthis.behaviorCallbackMap[behaviorCallback.type].push(handler);\n\t\t}\n\t\treturn this;\n\t}\n\n\tpublic addBehaviors(\n\t\tbehaviorCallbacks: ({ type: BehaviorCallbackType, handler: any })[]\n\t): this {\n\t\tbehaviorCallbacks.forEach(callback => {\n\t\t\tconst handler = callback.handler as unknown as BehaviorCallback<this, O>;\n\t\t\tif (handler) {\n\t\t\t\tthis.behaviorCallbackMap[callback.type].push(handler);\n\t\t\t}\n\t\t});\n\t\treturn this;\n\t}\n\n\tprotected updateMaterials(params: any) {\n\t\tif (!this.materials?.length) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const material of this.materials) {\n\t\t\tif (material instanceof ShaderMaterial) {\n\t\t\t\tif (material.uniforms) {\n\t\t\t\t\tmaterial.uniforms.iTime && (material.uniforms.iTime.value += params.delta);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic buildInfo(): Record<string, string> {\n\t\tconst info: Record<string, string> = {};\n\t\tinfo.name = this.name;\n\t\tinfo.uuid = this.uuid;\n\t\tinfo.eid = this.eid.toString();\n\t\treturn info;\n\t}\n}\n\n","// this class is not for asset loading, it is for loading entity specific data\n// this is to keep the entity class focused purely on entity logic\n\nexport function isLoadable(obj: any): obj is EntityLoaderDelegate {\n\treturn typeof obj?.load === \"function\" && typeof obj?.data === \"function\";\n}\n\nexport interface EntityLoaderDelegate {\n\tload(): Promise<void>;\n\tdata(): any;\n}\n\nexport class EntityLoader {\n\tentityReference: EntityLoaderDelegate;\n\n\tconstructor(entity: EntityLoaderDelegate) {\n\t\tthis.entityReference = entity;\n\t}\n\n\tasync load() {\n\t\tif (this.entityReference.load) {\n\t\t\tawait this.entityReference.load();\n\t\t}\n\t}\n\n\tasync data() {\n\t\tif (this.entityReference.data) {\n\t\t\treturn this.entityReference.data();\n\t\t}\n\t\treturn null;\n\t}\n}","import { GameEntityOptions, GameEntity } from \"./entity\";\nimport { BaseNode } from \"../core/base-node\";\nimport { EntityBuilder } from \"./builder\";\nimport { EntityCollisionBuilder } from \"./builder\";\nimport { EntityMeshBuilder } from \"./builder\";\nimport { EntityLoader, isLoadable } from \"./delegates/loader\";\n\nexport interface CreateGameEntityOptions<T extends GameEntity<any>, CreateOptions extends GameEntityOptions> {\n\targs: Array<any>;\n\tdefaultConfig: GameEntityOptions;\n\tEntityClass: new (options: any) => T;\n\tBuilderClass: new (options: any, entity: T, meshBuilder: any, collisionBuilder: any) => EntityBuilder<T, CreateOptions>;\n\tMeshBuilderClass?: new (data: any) => EntityMeshBuilder;\n\tCollisionBuilderClass?: new (data: any) => EntityCollisionBuilder;\n\tentityType: symbol;\n};\n\nexport async function createEntity<T extends GameEntity<any>, CreateOptions extends GameEntityOptions>(params: CreateGameEntityOptions<T, CreateOptions>): Promise<T> {\n\tconst {\n\t\targs,\n\t\tdefaultConfig,\n\t\tEntityClass,\n\t\tBuilderClass,\n\t\tentityType,\n\t\tMeshBuilderClass,\n\t\tCollisionBuilderClass,\n\t} = params;\n\n\tlet builder: EntityBuilder<T, CreateOptions> | null = null;\n\tlet configuration;\n\n\tconst configurationIndex = args.findIndex(node => !(node instanceof BaseNode));\n\tif (configurationIndex !== -1) {\n\t\tconst subArgs = args.splice(configurationIndex, 1);\n\t\tconfiguration = subArgs.find(node => !(node instanceof BaseNode));\n\t}\n\n\tconst mergedConfiguration = configuration ? { ...defaultConfig, ...configuration } : defaultConfig;\n\targs.push(mergedConfiguration);\n\n\tfor (const arg of args) {\n\t\tif (arg instanceof BaseNode) {\n\t\t\tcontinue;\n\t\t}\n\t\tlet entityData = null;\n\t\tconst entity = new EntityClass(arg);\n\t\ttry {\n\t\t\tif (isLoadable(entity)) {\n\t\t\t\tconst loader = new EntityLoader(entity);\n\t\t\t\tawait loader.load();\n\t\t\t\tentityData = await loader.data();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Error creating entity with loader:\", error);\n\t\t}\n\t\tbuilder = new BuilderClass(\n\t\t\targ,\n\t\t\tentity,\n\t\t\tMeshBuilderClass ? new MeshBuilderClass(entityData) : null,\n\t\t\tCollisionBuilderClass ? new CollisionBuilderClass(entityData) : null,\n\t\t);\n\t\tif (arg.material) {\n\t\t\tawait builder.withMaterial(arg.material, entityType);\n\t\t}\n\t}\n\n\tif (!builder) {\n\t\tthrow new Error(`missing options for ${String(entityType)}, builder is not initialized.`);\n\t}\n\n\treturn await builder.build();\n}\n\n","import { AnimationClip, Object3D } from 'three';\nimport { FBXLoader } from 'three/addons/loaders/FBXLoader.js';\nimport { GLTF, GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';\n\nenum FileExtensionTypes {\n\tFBX = 'fbx',\n\tGLTF = 'gltf'\n}\n\nexport interface AssetLoaderResult {\n\tobject?: Object3D;\n\tanimation?: AnimationClip;\n\tgltf?: GLTF;\n}\n\nexport interface IAssetLoader {\n\tload(file: string): Promise<AssetLoaderResult>;\n\tisSupported(file: string): boolean;\n}\n\nclass FBXAssetLoader implements IAssetLoader {\n\tprivate loader: FBXLoader = new FBXLoader();\n\n\tisSupported(file: string): boolean {\n\t\treturn file.toLowerCase().endsWith(FileExtensionTypes.FBX);\n\t}\n\n\tasync load(file: string): Promise<AssetLoaderResult> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.loader.load(\n\t\t\t\tfile,\n\t\t\t\t(object: Object3D) => {\n\t\t\t\t\tconst animation = object.animations[0];\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tobject,\n\t\t\t\t\t\tanimation\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tundefined,\n\t\t\t\treject\n\t\t\t);\n\t\t});\n\t}\n}\n\nclass GLTFAssetLoader implements IAssetLoader {\n\tprivate loader: GLTFLoader = new GLTFLoader();\n\n\tisSupported(file: string): boolean {\n\t\treturn file.toLowerCase().endsWith(FileExtensionTypes.GLTF);\n\t}\n\n\tasync load(file: string): Promise<AssetLoaderResult> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.loader.load(\n\t\t\t\tfile,\n\t\t\t\t(gltf: GLTF) => {\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tobject: gltf.scene,\n\t\t\t\t\t\tgltf\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tundefined,\n\t\t\t\treject\n\t\t\t);\n\t\t});\n\t}\n}\n\nexport class EntityAssetLoader {\n\tprivate loaders: IAssetLoader[] = [\n\t\tnew FBXAssetLoader(),\n\t\tnew GLTFAssetLoader()\n\t];\n\n\tasync loadFile(file: string): Promise<AssetLoaderResult> {\n\t\tconst loader = this.loaders.find(l => l.isSupported(file));\n\n\t\tif (!loader) {\n\t\t\tthrow new Error(`Unsupported file type: ${file}`);\n\t\t}\n\n\t\treturn loader.load(file);\n\t}\n}\n","import {\n\tAnimationAction,\n\tAnimationClip,\n\tAnimationMixer,\n\tLoopOnce,\n\tLoopRepeat,\n\tObject3D,\n} from 'three';\nimport { EntityAssetLoader, AssetLoaderResult } from '../../core/entity-asset-loader';\n\nexport type AnimationOptions = {\n\tkey: string;\n\tpauseAtEnd?: boolean;\n\tpauseAtPercentage?: number;\n\tfadeToKey?: string;\n\tfadeDuration?: number;\n};\n\ntype AnimationObject = {\n\tkey?: string;\n\tpath: string;\n};\n\nexport class AnimationDelegate {\n\tprivate _mixer: AnimationMixer | null = null;\n\tprivate _actions: Record<string, AnimationAction> = {};\n\tprivate _animations: AnimationClip[] = [];\n\tprivate _currentAction: AnimationAction | null = null;\n\n\tprivate _pauseAtPercentage = 0;\n\tprivate _isPaused = false;\n\tprivate _queuedKey: string | null = null;\n\tprivate _fadeDuration = 0.5;\n\n\tprivate _currentKey: string = '';\n\tprivate _assetLoader = new EntityAssetLoader();\n\n\tconstructor(private target: Object3D) { }\n\n\tasync loadAnimations(animations: AnimationObject[]): Promise<void> {\n\t\tif (!animations.length) return;\n\n\t\tconst results = await Promise.all(animations.map(a => this._assetLoader.loadFile(a.path)));\n\t\tthis._animations = results\n\t\t\t.filter((r): r is AssetLoaderResult => !!r.animation)\n\t\t\t.map(r => r.animation!);\n\n\t\tif (!this._animations.length) return;\n\n\t\tthis._mixer = new AnimationMixer(this.target);\n\t\tthis._animations.forEach((clip, i) => {\n\t\t\tconst key = animations[i].key || i.toString();\n\t\t\tthis._actions[key] = this._mixer!.clipAction(clip);\n\t\t});\n\n\t\tthis.playAnimation({ key: Object.keys(this._actions)[0] });\n\t}\n\n\tupdate(delta: number): void {\n\t\tif (!this._mixer || !this._currentAction) return;\n\n\t\tthis._mixer.update(delta);\n\n\t\tconst pauseAtTime = this._currentAction.getClip().duration * (this._pauseAtPercentage / 100);\n\t\tif (\n\t\t\t!this._isPaused &&\n\t\t\tthis._pauseAtPercentage > 0 &&\n\t\t\tthis._currentAction.time >= pauseAtTime\n\t\t) {\n\t\t\tthis._currentAction.time = pauseAtTime;\n\t\t\tthis._currentAction.paused = true;\n\t\t\tthis._isPaused = true;\n\n\t\t\tif (this._queuedKey !== null) {\n\t\t\t\tconst next = this._actions[this._queuedKey];\n\t\t\t\tnext.reset().play();\n\t\t\t\tthis._currentAction.crossFadeTo(next, this._fadeDuration, false);\n\t\t\t\tthis._currentAction = next;\n\t\t\t\tthis._currentKey = this._queuedKey;\n\t\t\t\tthis._queuedKey = null;\n\t\t\t}\n\t\t}\n\t}\n\n\tplayAnimation(opts: AnimationOptions): void {\n\t\tif (!this._mixer) return;\n\t\tconst { key, pauseAtPercentage = 0, pauseAtEnd = false, fadeToKey, fadeDuration = 0.5 } = opts;\n\t\tif (key === this._currentKey) return;\n\n\t\tthis._queuedKey = fadeToKey || null;\n\t\tthis._fadeDuration = fadeDuration;\n\n\t\tthis._pauseAtPercentage = pauseAtEnd ? 100 : pauseAtPercentage;\n\t\tthis._isPaused = false;\n\n\t\tconst prev = this._currentAction;\n\t\tif (prev) prev.stop();\n\n\t\tconst action = this._actions[key];\n\t\tif (!action) return;\n\n\t\tif (this._pauseAtPercentage > 0) {\n\t\t\taction.setLoop(LoopOnce, Infinity);\n\t\t\taction.clampWhenFinished = true;\n\t\t} else {\n\t\t\taction.setLoop(LoopRepeat, Infinity);\n\t\t\taction.clampWhenFinished = false;\n\t\t}\n\n\t\tif (prev) {\n\t\t\tprev.crossFadeTo(action, fadeDuration, false);\n\t\t}\n\t\taction.reset().play();\n\n\t\tthis._currentAction = action;\n\t\tthis._currentKey = key;\n\t}\n\n\t/**\n\t * Dispose of all animation resources\n\t */\n\tdispose(): void {\n\t\t// Stop all actions\n\t\tObject.values(this._actions).forEach(action => {\n\t\t\taction.stop();\n\t\t});\n\n\t\t// Stop and uncache mixer\n\t\tif (this._mixer) {\n\t\t\tthis._mixer.stopAllAction();\n\t\t\tthis._mixer.uncacheRoot(this.target);\n\t\t\tthis._mixer = null;\n\t\t}\n\n\t\t// Clear references\n\t\tthis._actions = {};\n\t\tthis._animations = [];\n\t\tthis._currentAction = null;\n\t\tthis._currentKey = '';\n\t}\n\n\tget currentAnimationKey() { return this._currentKey; }\n\tget animations() { return this._animations; }\n}\n","import { ActiveCollisionTypes, ColliderDesc, RigidBodyDesc, RigidBodyType, Vector3 } from \"@dimforge/rapier3d-compat\";\nimport { Vec3 } from \"../core/vector\";\n\n/**\n * Options for configuring entity collision behavior.\n */\nexport interface CollisionOptions {\n\tstatic?: boolean;\n\tsensor?: boolean;\n\tsize?: Vector3;\n\tposition?: Vector3;\n\tcollisionType?: string;\n\tcollisionFilter?: string[];\n}\n\nconst typeToGroup = new Map<string, number>();\nlet nextGroupId = 0;\n\nexport function getOrCreateCollisionGroupId(type: string): number {\n\tlet groupId = typeToGroup.get(type);\n\tif (groupId === undefined) {\n\t\tgroupId = nextGroupId++ % 16;\n\t\ttypeToGroup.set(type, groupId);\n\t}\n\treturn groupId;\n}\n\nexport function createCollisionFilter(allowedTypes: string[]): number {\n\tlet filter = 0;\n\tallowedTypes.forEach(type => {\n\t\tconst groupId = getOrCreateCollisionGroupId(type);\n\t\tfilter |= (1 << groupId);\n\t});\n\treturn filter;\n}\n\nexport class CollisionBuilder {\n\tstatic: boolean = false;\n\tsensor: boolean = false;\n\tgravity: Vec3 = new Vector3(0, 0, 0);\n\n\tbuild(options: Partial<CollisionOptions>): [RigidBodyDesc, ColliderDesc] {\n\t\tconst bodyDesc = this.bodyDesc({\n\t\t\tisDynamicBody: !this.static\n\t\t});\n\t\tconst collider = this.collider(options);\n\t\tconst type = options.collisionType;\n\t\tif (type) {\n\t\t\tlet groupId = getOrCreateCollisionGroupId(type);\n\t\t\tlet filter = 0b1111111111111111;\n\t\t\tif (options.collisionFilter) {\n\t\t\t\tfilter = createCollisionFilter(options.collisionFilter);\n\t\t\t}\n\t\t\tcollider.setCollisionGroups((groupId << 16) | filter);\n\t\t}\n\t\tconst { KINEMATIC_FIXED, DEFAULT } = ActiveCollisionTypes;\n\t\tcollider.activeCollisionTypes = (this.sensor) ? KINEMATIC_FIXED : DEFAULT;\n\t\treturn [bodyDesc, collider];\n\t}\n\n\twithCollision(collisionOptions: Partial<CollisionOptions>): this {\n\t\tthis.sensor = collisionOptions?.sensor ?? this.sensor;\n\t\tthis.static = collisionOptions?.static ?? this.static;\n\t\treturn this;\n\t}\n\n\tcollider(options: CollisionOptions): ColliderDesc {\n\t\tconst size = options.size ?? new Vector3(1, 1, 1);\n\t\tconst half = { x: size.x / 2, y: size.y / 2, z: size.z / 2 };\n\t\tlet colliderDesc = ColliderDesc.cuboid(half.x, half.y, half.z);\n\t\treturn colliderDesc;\n\t}\n\n\tbodyDesc({ isDynamicBody = true }): RigidBodyDesc {\n\t\tconst type = isDynamicBody ? RigidBodyType.Dynamic : RigidBodyType.Fixed;\n\t\tconst bodyDesc = new RigidBodyDesc(type)\n\t\t\t.setTranslation(0, 0, 0)\n\t\t\t.setGravityScale(1.0)\n\t\t\t.setCanSleep(false)\n\t\t\t.setCcdEnabled(true);\n\t\treturn bodyDesc;\n\t}\n}","import { BufferGeometry, Material, Mesh } from 'three';\nimport { GameEntityOptions } from '../entities/entity';\n\n/**\n * TODO: allow for multiple materials requires geometry groups\n * TODO: allow for instanced uniforms\n * TODO: allow for geometry groups\n * TODO: allow for batched meshes\n * import { InstancedUniformsMesh } from 'three-instanced-uniforms-mesh';\n * may not need geometry groups for shaders though\n * setGeometry<T extends BufferGeometry>(geometry: T) {\n * MeshBuilder.bachedMesh = new BatchedMesh(10, 5000, 10000, material);\n * }\n */\n\nexport type MeshBuilderOptions = Partial<Pick<GameEntityOptions, 'batched' | 'material'>>;\n\nexport class MeshBuilder {\n\n\t_build(meshOptions: MeshBuilderOptions, geometry: BufferGeometry, materials: Material[]): Mesh {\n\t\tconst { batched, material } = meshOptions;\n\t\tif (batched) {\n\t\t\tconsole.warn('warning: mesh batching is not implemented');\n\t\t}\n\t\tconst mesh = new Mesh(geometry, materials.at(-1));\n\t\tmesh.position.set(0, 0, 0);\n\t\tmesh.castShadow = true;\n\t\tmesh.receiveShadow = true;\n\t\treturn mesh;\n\t}\n\n\t_postBuild(): void {\n\t\treturn;\n\t}\n}","export function sortedStringify(obj: Record<string, any>) {\n\tconst sortedObj = Object.keys(obj)\n\t\t.sort()\n\t\t.reduce((acc: Record<string, any>, key: string) => {\n\t\t\tacc[key] = obj[key];\n\t\t\treturn acc;\n\t\t}, {} as Record<string, any>);\n\n\treturn JSON.stringify(sortedObj);\n}\n\nexport function shortHash(objString: string) {\n\tlet hash = 0;\n\tfor (let i = 0; i < objString.length; i++) {\n\t\thash = Math.imul(31, hash) + objString.charCodeAt(i) | 0;\n\t}\n\treturn hash.toString(36);\n}","export default \"#include <common>\\n\\nuniform vec3 iResolution;\\nuniform float iTime;\\nvarying vec2 vUv;\\n\\n// Credit goes to:\\n// https://www.shadertoy.com/view/mtyGWy\\n\\nvec3 palette( float t ) {\\n vec3 a = vec3(0.5, 0.5, 0.5);\\n vec3 b = vec3(0.5, 0.5, 0.5);\\n vec3 c = vec3(1.0, 1.0, 1.0);\\n vec3 d = vec3(0.263,0.416,0.557);\\n\\n return a + b*cos( 6.28318*(c*t+d) );\\n}\\n\\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord ) {\\n vec2 uv = (fragCoord * 2.0 - iResolution.xy) / iResolution.y;\\n vec2 uv0 = uv;\\n vec3 finalColor = vec3(0.0);\\n \\n for (float i = 0.0; i < 4.0; i++) {\\n uv = fract(uv * 1.5) - 0.5;\\n\\n float d = length(uv) * exp(-length(uv0));\\n\\n vec3 col = palette(length(uv0) + i*.4 + iTime*.4);\\n\\n d = sin(d*5. + iTime)/5.;\\n d = abs(d);\\n\\n d = pow(0.01 / d, 1.2);\\n\\n finalColor += col * d;\\n }\\n \\n fragColor = vec4(finalColor, 1.0);\\n}\\n \\nvoid main() {\\n mainImage(gl_FragColor, vUv);\\n}\"","export default \"#include <common>\\n \\nuniform vec3 iResolution;\\nuniform float iTime;\\nuniform vec2 iOffset;\\nvarying vec2 vUv;\\n\\nfloat snoise(vec3 uv, float res)\\n{\\n\\tconst vec3 s = vec3(1e0, 1e2, 1e3);\\n\\t\\n\\tuv *= res;\\n\\t\\n\\tvec3 uv0 = floor(mod(uv, res))*s;\\n\\tvec3 uv1 = floor(mod(uv+vec3(1.), res))*s;\\n\\t\\n\\tvec3 f = fract(uv); f = f*f*(3.0-2.0*f);\\n\\n\\tvec4 v = vec4(uv0.x+uv0.y+uv0.z, uv1.x+uv0.y+uv0.z,\\n\\t\\t \\t uv0.x+uv1.y+uv0.z, uv1.x+uv1.y+uv0.z);\\n\\n\\tvec4 r = fract(sin(v*1e-1)*1e3);\\n\\tfloat r0 = mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y);\\n\\t\\n\\tr = fract(sin((v + uv1.z - uv0.z)*1e-1)*1e3);\\n\\tfloat r1 = mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y);\\n\\t\\n\\treturn mix(r0, r1, f.z)*2.-1.;\\n}\\n\\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord ) {\\n\\tvec2 p = -.5 + fragCoord.xy / iResolution.xy;\\n\\tp.x *= iResolution.x/iResolution.y;\\n\\t\\n\\tfloat color = 3.0 - (3.*length(2.*p));\\n\\t\\n\\tvec3 coord = vec3(atan(p.x,p.y)/6.2832+.5, length(p)*.4, .5);\\n\\t\\n\\tfor(int i = 1; i <= 7; i++)\\n\\t{\\n\\t\\tfloat power = pow(2.0, float(i));\\n\\t\\tcolor += (1.5 / power) * snoise(coord + vec3(0.,-iTime*.05, iTime*.01), power*16.);\\n\\t}\\n\\tfragColor = vec4( color, pow(max(color,0.),2.)*0.4, pow(max(color,0.),3.)*0.15 , 1.0);\\n}\\n\\nvoid main() {\\n mainImage(gl_FragColor, vUv);\\n}\"","export default \"uniform sampler2D tDiffuse;\\nvarying vec2 vUv;\\n\\nvoid main() {\\n\\tvec4 texel = texture2D( tDiffuse, vUv );\\n\\n\\tgl_FragColor = texel;\\n}\"","export default \"varying vec3 vBarycentric;\\nuniform vec3 baseColor;\\nuniform vec3 wireframeColor;\\nuniform float wireframeThickness;\\n\\nfloat edgeFactor() {\\n vec3 d = fwidth(vBarycentric);\\n vec3 a3 = smoothstep(vec3(0.0), d * wireframeThickness, vBarycentric);\\n return min(min(a3.x, a3.y), a3.z);\\n}\\n\\nvoid main() {\\n float edge = edgeFactor();\\n\\n vec3 wireColor = wireframeColor;\\n\\n vec3 finalColor = mix(wireColor, baseColor, edge);\\n \\n gl_FragColor = vec4(finalColor, 1.0);\\n}\\n\"","export default \"uniform vec2 uvScale;\\nvarying vec2 vUv;\\n\\nvoid main() {\\n\\tvUv = uv;\\n\\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\\n\\tgl_Position = projectionMatrix * mvPosition;\\n}\"","export default \"varying vec3 vBarycentric;\\n\\nvoid main() {\\n vec3 barycentric = vec3(0.0);\\n int index = gl_VertexID % 3;\\n if (index == 0) barycentric = vec3(1.0, 0.0, 0.0);\\n else if (index == 1) barycentric = vec3(0.0, 1.0, 0.0);\\n else barycentric = vec3(0.0, 0.0, 1.0);\\n vBarycentric = barycentric;\\n \\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\\n}\\n\"","/* Fragment Shaders **/\nimport starsTest from '../graphics/shaders/fragment/stars.glsl';\nimport fireFragment from '../graphics/shaders/fragment/fire.glsl';\nimport fragmentShader from '../graphics/shaders/fragment/standard.glsl';\nimport debugFragment from '../graphics/shaders/fragment/debug.glsl';\n\n/* Vertex Shaders **/\nimport vertexShader from '../graphics/shaders/vertex/object-shader.glsl';\nimport debugVertexShader from '../graphics/shaders/vertex/debug.glsl';\n\nexport type ZylemShaderObject = { fragment: string, vertex: string };\n\nconst starShader: ZylemShaderObject = {\n\tfragment: starsTest,\n\tvertex: vertexShader\n};\n\nconst fireShader: ZylemShaderObject = {\n\tfragment: fireFragment,\n\tvertex: vertexShader\n};\n\nconst standardShader: ZylemShaderObject = {\n\tfragment: fragmentShader,\n\tvertex: vertexShader\n};\n\nconst debugShader: ZylemShaderObject = {\n\tfragment: debugFragment,\n\tvertex: debugVertexShader\n};\n\nexport type ZylemShaderType = 'standard' | 'fire' | 'star' | 'debug';\n\nconst shaderMap: Map<ZylemShaderType, ZylemShaderObject> = new Map();\nshaderMap.set('standard', standardShader);\nshaderMap.set('fire', fireShader);\nshaderMap.set('star', starShader);\nshaderMap.set('debug', debugShader);\n\nexport default shaderMap;","import {\n\tColor,\n\tMaterial,\n\tMeshPhongMaterial,\n\tMeshStandardMaterial,\n\tRepeatWrapping,\n\tShaderMaterial,\n\tTextureLoader,\n\tVector2,\n\tVector3\n} from 'three';\nimport { shortHash, sortedStringify } from '../core/utility/strings';\nimport shaderMap, { ZylemShaderObject, ZylemShaderType } from '../core/preset-shader';\n\nexport interface MaterialOptions {\n\tpath?: string;\n\trepeat?: Vector2;\n\tshader?: ZylemShaderType;\n\tcolor?: Color;\n}\n\ntype BatchGeometryMap = Map<symbol, number>;\n\ninterface BatchMaterialMapObject {\n\tgeometryMap: BatchGeometryMap;\n\tmaterial: Material;\n};\n\ntype BatchKey = ReturnType<typeof shortHash>;\n\nexport type TexturePath = string | null;\n\nexport class MaterialBuilder {\n\tstatic batchMaterialMap: Map<BatchKey, BatchMaterialMapObject> = new Map();\n\n\tmaterials: Material[] = [];\n\n\tbatchMaterial(options: Partial<MaterialOptions>, entityType: symbol) {\n\t\tconst batchKey = shortHash(sortedStringify(options));\n\t\tconst mappedObject = MaterialBuilder.batchMaterialMap.get(batchKey);\n\t\tif (mappedObject) {\n\t\t\tconst count = mappedObject.geometryMap.get(entityType);\n\t\t\tif (count) {\n\t\t\t\tmappedObject.geometryMap.set(entityType, count + 1);\n\t\t\t} else {\n\t\t\t\tmappedObject.geometryMap.set(entityType, 1);\n\t\t\t}\n\t\t} else {\n\t\t\tMaterialBuilder.batchMaterialMap.set(\n\t\t\t\tbatchKey, {\n\t\t\t\tgeometryMap: new Map([[entityType, 1]]),\n\t\t\t\tmaterial: this.materials[0]\n\t\t\t});\n\t\t}\n\t}\n\n\tasync build(options: Partial<MaterialOptions>, entityType: symbol) {\n\t\tconst { path, repeat, color, shader } = options;\n\t\tif (shader) this.withShader(shader);\n\t\tif (color) this.withColor(color);\n\t\tawait this.setTexture(path ?? null, repeat);\n\t\tif (this.materials.length === 0) {\n\t\t\tthis.setColor(new Color('#ffffff'));\n\t\t}\n\t\tthis.batchMaterial(options, entityType);\n\t}\n\n\twithColor(color: Color): this {\n\t\tthis.setColor(color);\n\t\treturn this;\n\t}\n\n\twithShader(shaderType: ZylemShaderType): this {\n\t\tthis.setShader(shaderType);\n\t\treturn this;\n\t}\n\n\tasync setTexture(texturePath: TexturePath = null, repeat: Vector2 = new Vector2(1, 1)) {\n\t\tif (!texturePath) {\n\t\t\treturn;\n\t\t}\n\t\tconst loader = new TextureLoader();\n\t\tconst texture = await loader.loadAsync(texturePath as string);\n\t\ttexture.repeat = repeat;\n\t\ttexture.wrapS = RepeatWrapping;\n\t\ttexture.wrapT = RepeatWrapping;\n\t\tconst material = new MeshPhongMaterial({\n\t\t\tmap: texture,\n\t\t});\n\t\tthis.materials.push(material);\n\t}\n\n\tsetColor(color: Color) {\n\t\tconst material = new MeshStandardMaterial({\n\t\t\tcolor: color,\n\t\t\temissiveIntensity: 0.5,\n\t\t\tlightMapIntensity: 0.5,\n\t\t\tfog: true,\n\t\t});\n\n\t\tthis.materials.push(material);\n\t}\n\n\tsetShader(customShader: ZylemShaderType) {\n\t\tconst { fragment, vertex } = shaderMap.get(customShader) ?? shaderMap.get('standard') as ZylemShaderObject;\n\n\t\tconst shader = new ShaderMaterial({\n\t\t\tuniforms: {\n\t\t\t\tiResolution: { value: new Vector3(1, 1, 1) },\n\t\t\t\tiTime: { value: 0 },\n\t\t\t\ttDiffuse: { value: null },\n\t\t\t\ttDepth: { value: null },\n\t\t\t\ttNormal: { value: null }\n\t\t\t},\n\t\t\tvertexShader: vertex,\n\t\t\tfragmentShader: fragment,\n\t\t});\n\t\tthis.materials.push(shader);\n\t}\n}\n","import { ColliderDesc } from \"@dimforge/rapier3d-compat\";\nimport { GameEntity, GameEntityOptions } from \"./entity\";\nimport { BufferGeometry, Group, Material, Mesh, Color } from \"three\";\nimport { CollisionBuilder } from \"../collision/collision-builder\";\nimport { MeshBuilder } from \"../graphics/mesh\";\nimport { MaterialBuilder, MaterialOptions } from \"../graphics/material\";\nimport { Vec3 } from \"../core/vector\";\n\nexport abstract class EntityCollisionBuilder extends CollisionBuilder {\n\tabstract collider(options: GameEntityOptions): ColliderDesc;\n}\n\nexport abstract class EntityMeshBuilder extends MeshBuilder {\n\tbuild(options: GameEntityOptions): BufferGeometry {\n\t\treturn new BufferGeometry();\n\t}\n\n\tpostBuild(): void {\n\t\treturn;\n\t}\n}\n\nexport abstract class EntityBuilder<T extends GameEntity<U> & P, U extends GameEntityOptions, P = any> {\n\tprotected meshBuilder: EntityMeshBuilder | null;\n\tprotected collisionBuilder: EntityCollisionBuilder | null;\n\tprotected materialBuilder: MaterialBuilder | null;\n\tprotected options: Partial<U>;\n\tprotected entity: T;\n\n\tconstructor(\n\t\toptions: Partial<U>,\n\t\tentity: T,\n\t\tmeshBuilder: EntityMeshBuilder | null,\n\t\tcollisionBuilder: EntityCollisionBuilder | null,\n\t) {\n\t\tthis.options = options;\n\t\tthis.entity = entity;\n\t\tthis.meshBuilder = meshBuilder;\n\t\tthis.collisionBuilder = collisionBuilder;\n\t\tthis.materialBuilder = new MaterialBuilder();\n\t\tconst builders: NonNullable<GameEntityOptions[\"_builders\"]> = {\n\t\t\tmeshBuilder: this.meshBuilder,\n\t\t\tcollisionBuilder: this.collisionBuilder,\n\t\t\tmaterialBuilder: this.materialBuilder,\n\t\t};\n\t\t(this.options as Partial<GameEntityOptions>)._builders = builders;\n\t}\n\n\twithPosition(setupPosition: Vec3): this {\n\t\tthis.options.position = setupPosition;\n\t\treturn this;\n\t}\n\n\tasync withMaterial(options: Partial<MaterialOptions>, entityType: symbol): Promise<this> {\n\t\tif (this.materialBuilder) {\n\t\t\tawait this.materialBuilder.build(options, entityType);\n\t\t}\n\t\treturn this;\n\t}\n\n\tapplyMaterialToGroup(group: Group, materials: Material[]): void {\n\t\tgroup.traverse((child) => {\n\t\t\tif (child instanceof Mesh) {\n\t\t\t\tif (child.type === 'SkinnedMesh' && materials[0] && !child.material.map) {\n\t\t\t\t\tchild.material = materials[0];\n\t\t\t\t}\n\t\t\t}\n\t\t\tchild.castShadow = true;\n\t\t\tchild.receiveShadow = true;\n\t\t});\n\t}\n\n\tasync build(): Promise<T> {\n\t\tconst entity = this.entity;\n\t\tif (this.materialBuilder) {\n\t\t\tentity.materials = this.materialBuilder.materials;\n\t\t}\n\t\tif (this.meshBuilder && entity.materials) {\n\t\t\tconst geometry = this.meshBuilder.build(this.options);\n\t\t\tentity.mesh = this.meshBuilder._build(this.options, geometry, entity.materials);\n\t\t\tthis.meshBuilder.postBuild();\n\t\t}\n\n\t\tif (entity.group && entity.materials) {\n\t\t\tthis.applyMaterialToGroup(entity.group, entity.materials);\n\t\t}\n\n\t\tif (this.collisionBuilder) {\n\t\t\tthis.collisionBuilder.withCollision(this.options?.collision || {});\n\t\t\tconst [bodyDesc, colliderDesc] = this.collisionBuilder.build(this.options as any);\n\t\t\tentity.bodyDesc = bodyDesc;\n\t\t\tentity.colliderDesc = colliderDesc;\n\n\t\t\tconst { x, y, z } = this.options.position || { x: 0, y: 0, z: 0 };\n\t\t\tentity.bodyDesc.setTranslation(x, y, z);\n\t\t}\n\t\tif (this.options.collisionType) {\n\t\t\tentity.collisionType = this.options.collisionType;\n\t\t}\n\n\t\tif (this.options.color instanceof Color) {\n\t\t\tconst applyColor = (material: Material) => {\n\t\t\t\tconst anyMat = material as any;\n\t\t\t\tif (anyMat && anyMat.color && anyMat.color.set) {\n\t\t\t\t\tanyMat.color.set(this.options.color as Color);\n\t\t\t\t}\n\t\t\t};\n\t\t\tif (entity.materials?.length) {\n\t\t\t\tfor (const mat of entity.materials) applyColor(mat);\n\t\t\t}\n\t\t\tif (entity.mesh && entity.mesh.material) {\n\t\t\t\tconst mat = entity.mesh.material as any;\n\t\t\t\tif (Array.isArray(mat)) mat.forEach(applyColor); else applyColor(mat);\n\t\t\t}\n\t\t\tif (entity.group) {\n\t\t\t\tentity.group.traverse((child) => {\n\t\t\t\t\tif (child instanceof Mesh && child.material) {\n\t\t\t\t\t\tconst mat = child.material as any;\n\t\t\t\t\t\tif (Array.isArray(mat)) mat.forEach(applyColor); else applyColor(mat);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn entity;\n\t}\n\n\tprotected abstract createEntity(options: Partial<U>): T;\n}","import { ActiveCollisionTypes, ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { BufferGeometry, Object3D, SkinnedMesh, Group, Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { createEntity } from './create';\nimport { UpdateContext, UpdateFunction } from '../core/base-node-life-cycle';\nimport { EntityAssetLoader } from '../core/entity-asset-loader';\nimport { EntityLoaderDelegate } from './delegates/loader';\nimport { Vec3 } from '../core/vector';\nimport { AnimationDelegate, AnimationOptions } from './delegates/animation';\nimport { MaterialOptions } from '../graphics/material';\nimport { DebugInfoProvider } from './delegates/debug';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\n\ntype AnimationObject = {\n\tkey?: string;\n\tpath: string;\n};\n\ntype ZylemActorOptions = GameEntityOptions & {\n\tstatic?: boolean;\n\tanimations?: AnimationObject[];\n\tmodels?: string[];\n\tscale?: Vec3;\n\tmaterial?: MaterialOptions;\n};\n\nconst actorDefaults: ZylemActorOptions = {\n\tposition: { x: 0, y: 0, z: 0 },\n\tcollision: {\n\t\tstatic: false,\n\t\tsize: new Vector3(0.5, 0.5, 0.5),\n\t\tposition: new Vector3(0, 0, 0),\n\t},\n\tmaterial: {\n\t\tshader: 'standard',\n\t},\n\tanimations: [],\n\tmodels: []\n};\n\nclass ActorCollisionBuilder extends EntityCollisionBuilder {\n\tprivate height: number = 1;\n\tprivate objectModel: Group | null = null;\n\n\tconstructor(data: any) {\n\t\tsuper();\n\t\tthis.objectModel = data.objectModel;\n\t}\n\n\tcreateColliderFromObjectModel(objectModel: Group | null): ColliderDesc {\n\t\tif (!objectModel) return ColliderDesc.capsule(1, 1);\n\n\t\tconst skinnedMesh = objectModel.children.find(child => child instanceof SkinnedMesh) as SkinnedMesh;\n\t\tconst geometry = skinnedMesh.geometry as BufferGeometry;\n\n\t\tif (geometry) {\n\t\t\tgeometry.computeBoundingBox();\n\t\t\tif (geometry.boundingBox) {\n\t\t\t\tconst maxY = geometry.boundingBox.max.y;\n\t\t\t\tconst minY = geometry.boundingBox.min.y;\n\t\t\t\tthis.height = maxY - minY;\n\t\t\t}\n\t\t}\n\t\tthis.height = 1;\n\t\tlet colliderDesc = ColliderDesc.capsule(this.height / 2, 1);\n\t\tcolliderDesc.setSensor(false);\n\t\tcolliderDesc.setTranslation(0, this.height + 0.5, 0);\n\t\tcolliderDesc.activeCollisionTypes = ActiveCollisionTypes.DEFAULT;\n\n\t\treturn colliderDesc;\n\t}\n\n\tcollider(options: ZylemActorOptions): ColliderDesc {\n\t\tlet colliderDesc = this.createColliderFromObjectModel(this.objectModel);\n\n\t\treturn colliderDesc;\n\t}\n}\n\nclass ActorBuilder extends EntityBuilder<ZylemActor, ZylemActorOptions> {\n\tprotected createEntity(options: Partial<ZylemActorOptions>): ZylemActor {\n\t\treturn new ZylemActor(options);\n\t}\n}\n\nexport const ACTOR_TYPE = Symbol('Actor');\n\nexport class ZylemActor extends GameEntity<ZylemActorOptions> implements EntityLoaderDelegate, DebugInfoProvider {\n\tstatic type = ACTOR_TYPE;\n\n\tprivate _object: Object3D | null = null;\n\tprivate _animationDelegate: AnimationDelegate | null = null;\n\tprivate _modelFileNames: string[] = [];\n\tprivate _assetLoader: EntityAssetLoader = new EntityAssetLoader();\n\n\tcontrolledRotation: boolean = false;\n\n\tconstructor(options?: ZylemActorOptions) {\n\t\tsuper();\n\t\tthis.options = { ...actorDefaults, ...options };\n\t\t// Add actor-specific update to the lifecycle callbacks\n\t\tthis.prependUpdate(this.actorUpdate.bind(this) as UpdateFunction<this>);\n\t\tthis.controlledRotation = true;\n\t}\n\n\tasync load(): Promise<void> {\n\t\tthis._modelFileNames = this.options.models || [];\n\t\tawait this.loadModels();\n\t\tif (this._object) {\n\t\t\tthis._animationDelegate = new AnimationDelegate(this._object);\n\t\t\tawait this._animationDelegate.loadAnimations(this.options.animations || []);\n\t\t}\n\t}\n\n\tasync data(): Promise<any> {\n\t\treturn {\n\t\t\tanimations: this._animationDelegate?.animations,\n\t\t\tobjectModel: this._object,\n\t\t};\n\t}\n\n\tasync actorUpdate(params: UpdateContext<ZylemActorOptions>): Promise<void> {\n\t\tthis._animationDelegate?.update(params.delta);\n\t}\n\n\t/**\n\t * Clean up actor resources including animations, models, and groups\n\t */\n\tactorDestroy(): void {\n\t\t// Stop and dispose animation delegate\n\t\tif (this._animationDelegate) {\n\t\t\tthis._animationDelegate.dispose();\n\t\t\tthis._animationDelegate = null;\n\t\t}\n\n\t\t// Dispose geometries and materials from loaded object\n\t\tif (this._object) {\n\t\t\tthis._object.traverse((child) => {\n\t\t\t\tif ((child as any).isMesh) {\n\t\t\t\t\tconst mesh = child as SkinnedMesh;\n\t\t\t\t\tmesh.geometry?.dispose();\n\t\t\t\t\tif (Array.isArray(mesh.material)) {\n\t\t\t\t\t\tmesh.material.forEach(m => m.dispose());\n\t\t\t\t\t} else if (mesh.material) {\n\t\t\t\t\t\tmesh.material.dispose();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._object = null;\n\t\t}\n\n\t\t// Clear group reference\n\t\tif (this.group) {\n\t\t\tthis.group.clear();\n\t\t\tthis.group = null as any;\n\t\t}\n\n\t\t// Clear file name references\n\t\tthis._modelFileNames = [];\n\t}\n\n\tprivate async loadModels(): Promise<void> {\n\t\tif (this._modelFileNames.length === 0) return;\n\t\tconst promises = this._modelFileNames.map(file => this._assetLoader.loadFile(file));\n\t\tconst results = await Promise.all(promises);\n\t\tif (results[0]?.object) {\n\t\t\tthis._object = results[0].object;\n\t\t}\n\t\tif (this._object) {\n\t\t\tthis.group = new Group();\n\t\t\tthis.group.attach(this._object);\n\t\t\tthis.group.scale.set(\n\t\t\t\tthis.options.scale?.x || 1,\n\t\t\t\tthis.options.scale?.y || 1,\n\t\t\t\tthis.options.scale?.z || 1\n\t\t\t);\n\t\t}\n\t}\n\n\tplayAnimation(animationOptions: AnimationOptions) {\n\t\tthis._animationDelegate?.playAnimation(animationOptions);\n\t}\n\n\tget object(): Object3D | null {\n\t\treturn this._object;\n\t}\n\n\t/**\n\t * Provide custom debug information for the actor\n\t * This will be merged with the default debug information\n\t */\n\tgetDebugInfo(): Record<string, any> {\n\t\tconst debugInfo: Record<string, any> = {\n\t\t\ttype: 'Actor',\n\t\t\tmodels: this._modelFileNames.length > 0 ? this._modelFileNames : 'none',\n\t\t\tmodelLoaded: !!this._object,\n\t\t\tscale: this.options.scale ?\n\t\t\t\t`${this.options.scale.x}, ${this.options.scale.y}, ${this.options.scale.z}` :\n\t\t\t\t'1, 1, 1',\n\t\t};\n\n\t\t// Add animation info if available\n\t\tif (this._animationDelegate) {\n\t\t\tdebugInfo.currentAnimation = this._animationDelegate.currentAnimationKey || 'none';\n\t\t\tdebugInfo.animationsCount = this.options.animations?.length || 0;\n\t\t}\n\n\t\t// Add mesh info if model is loaded\n\t\tif (this._object) {\n\t\t\tlet meshCount = 0;\n\t\t\tlet vertexCount = 0;\n\t\t\tthis._object.traverse((child) => {\n\t\t\t\tif ((child as any).isMesh) {\n\t\t\t\t\tmeshCount++;\n\t\t\t\t\tconst geometry = (child as SkinnedMesh).geometry;\n\t\t\t\t\tif (geometry && geometry.attributes.position) {\n\t\t\t\t\t\tvertexCount += geometry.attributes.position.count;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\tdebugInfo.meshCount = meshCount;\n\t\t\tdebugInfo.vertexCount = vertexCount;\n\t\t}\n\n\t\treturn debugInfo;\n\t}\n}\n\ntype ActorOptions = BaseNode | ZylemActorOptions;\n\nexport async function actor(...args: Array<ActorOptions>): Promise<ZylemActor> {\n\treturn await createEntity<ZylemActor, ZylemActorOptions>({\n\t\targs,\n\t\tdefaultConfig: actorDefaults,\n\t\tEntityClass: ZylemActor,\n\t\tBuilderClass: ActorBuilder,\n\t\tCollisionBuilderClass: ActorCollisionBuilder,\n\t\tentityType: ZylemActor.type\n\t});\n}","import { Vector3 } from 'three';\nimport RAPIER, { World } from '@dimforge/rapier3d-compat';\n\nimport { Entity } from '../interfaces/entity';\nimport { state } from '../game/game-state';\nimport { UpdateContext } from '../core/base-node-life-cycle';\nimport { ZylemActor } from '../entities/actor';\nimport { GameEntity } from '../entities/entity';\n\n/**\n * Interface for entities that handle collision events.\n */\nexport interface CollisionHandlerDelegate {\n\thandlePostCollision(params: any): boolean;\n\thandleIntersectionEvent(params: any): void;\n}\n\n/**\n * Type guard to check if an object implements CollisionHandlerDelegate.\n */\nexport function isCollisionHandlerDelegate(obj: any): obj is CollisionHandlerDelegate {\n\treturn typeof obj?.handlePostCollision === \"function\" && typeof obj?.handleIntersectionEvent === \"function\";\n}\n\nexport class ZylemWorld implements Entity<ZylemWorld> {\n\ttype = 'World';\n\tworld: World;\n\tcollisionMap: Map<string, GameEntity<any>> = new Map();\n\tcollisionBehaviorMap: Map<string, GameEntity<any>> = new Map();\n\t_removalMap: Map<string, GameEntity<any>> = new Map();\n\n\tstatic async loadPhysics(gravity: Vector3) {\n\t\tawait RAPIER.init();\n\t\tconst physicsWorld = new RAPIER.World(gravity);\n\t\treturn physicsWorld;\n\t}\n\n\tconstructor(world: World) {\n\t\tthis.world = world;\n\t}\n\n\taddEntity(entity: any) {\n\t\tconst rigidBody = this.world.createRigidBody(entity.bodyDesc);\n\t\tentity.body = rigidBody;\n\t\t// TODO: consider passing in more specific data\n\t\tentity.body.userData = { uuid: entity.uuid, ref: entity };\n\t\tif (this.world.gravity.x === 0 && this.world.gravity.y === 0 && this.world.gravity.z === 0) {\n\t\t\tentity.body.lockTranslations(true, true);\n\t\t\tentity.body.lockRotations(true, true);\n\t\t}\n\t\tconst collider = this.world.createCollider(entity.colliderDesc, entity.body);\n\t\tentity.collider = collider;\n\t\tif (entity.controlledRotation || entity instanceof ZylemActor) {\n\t\t\tentity.body.lockRotations(true, true);\n\t\t\tentity.characterController = this.world.createCharacterController(0.01);\n\t\t\tentity.characterController.setMaxSlopeClimbAngle(45 * Math.PI / 180);\n\t\t\tentity.characterController.setMinSlopeSlideAngle(30 * Math.PI / 180);\n\t\t\tentity.characterController.enableSnapToGround(0.01);\n\t\t\tentity.characterController.setSlideEnabled(true);\n\t\t\tentity.characterController.setApplyImpulsesToDynamicBodies(true);\n\t\t\tentity.characterController.setCharacterMass(1);\n\t\t}\n\t\tthis.collisionMap.set(entity.uuid, entity);\n\t}\n\n\tsetForRemoval(entity: any) {\n\t\tif (entity.body) {\n\t\t\tthis._removalMap.set(entity.uuid, entity);\n\t\t}\n\t}\n\n\tdestroyEntity(entity: GameEntity<any>) {\n\t\tif (entity.collider) {\n\t\t\tthis.world.removeCollider(entity.collider, true);\n\t\t}\n\t\tif (entity.body) {\n\t\t\tthis.world.removeRigidBody(entity.body);\n\t\t\tthis.collisionMap.delete(entity.uuid);\n\t\t\tthis._removalMap.delete(entity.uuid);\n\t\t}\n\t}\n\n\tsetup() { }\n\n\tupdate(params: UpdateContext<any>) {\n\t\tconst { delta } = params;\n\t\tif (!this.world) {\n\t\t\treturn;\n\t\t}\n\t\tthis.updateColliders(delta);\n\t\tthis.updatePostCollisionBehaviors(delta);\n\t\tthis.world.step();\n\t}\n\n\tupdatePostCollisionBehaviors(delta: number) {\n\t\tconst dictionaryRef = this.collisionBehaviorMap;\n\t\tfor (let [id, collider] of dictionaryRef) {\n\t\t\tconst gameEntity = collider as any;\n\t\t\tif (!isCollisionHandlerDelegate(gameEntity)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst active = gameEntity.handlePostCollision({ entity: gameEntity, delta });\n\t\t\tif (!active) {\n\t\t\t\tthis.collisionBehaviorMap.delete(id);\n\t\t\t}\n\t\t}\n\t}\n\n\tupdateColliders(delta: number) {\n\t\tconst dictionaryRef = this.collisionMap;\n\t\tfor (let [id, collider] of dictionaryRef) {\n\t\t\tconst gameEntity = collider as GameEntity<any>;\n\t\t\tif (!gameEntity.body) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (this._removalMap.get(gameEntity.uuid)) {\n\t\t\t\tthis.destroyEntity(gameEntity);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.world.contactsWith(gameEntity.body.collider(0), (otherCollider) => {\n\t\t\t\t// @ts-ignore\n\t\t\t\tconst uuid = otherCollider._parent.userData.uuid;\n\t\t\t\tconst entity = dictionaryRef.get(uuid);\n\t\t\t\tif (!entity) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (gameEntity._collision) {\n\t\t\t\t\tgameEntity._collision(entity, state.globals);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.world.intersectionsWith(gameEntity.body.collider(0), (otherCollider) => {\n\t\t\t\t// @ts-ignore\n\t\t\t\tconst uuid = otherCollider._parent.userData.uuid;\n\t\t\t\tconst entity = dictionaryRef.get(uuid);\n\t\t\t\tif (!entity) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (gameEntity._collision) {\n\t\t\t\t\tgameEntity._collision(entity, state.globals);\n\t\t\t\t}\n\t\t\t\tif (isCollisionHandlerDelegate(entity)) {\n\t\t\t\t\tentity.handleIntersectionEvent({ entity, other: gameEntity, delta });\n\t\t\t\t\tthis.collisionBehaviorMap.set(uuid, entity);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tdestroy() {\n\t\ttry {\n\t\t\tfor (const [, entity] of this.collisionMap) {\n\t\t\t\ttry { this.destroyEntity(entity); } catch { /* noop */ }\n\t\t\t}\n\t\t\tthis.collisionMap.clear();\n\t\t\tthis.collisionBehaviorMap.clear();\n\t\t\tthis._removalMap.clear();\n\t\t\t// @ts-ignore\n\t\t\tthis.world = undefined as any;\n\t\t} catch { /* noop */ }\n\t}\n\n}","import {\n\tScene,\n\tColor,\n\tAmbientLight,\n\tDirectionalLight,\n\tObject3D,\n\tVector3,\n\tTextureLoader,\n\tGridHelper\n} from 'three';\nimport { Entity, LifecycleFunction } from '../interfaces/entity';\nimport { GameEntity } from '../entities/entity';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { debugState } from '../debug/debug-state';\nimport { SetupFunction } from '../core/base-node-life-cycle';\nimport { getGlobals } from '../game/game-state';\n\ninterface SceneState {\n\tbackgroundColor: Color | string;\n\tbackgroundImage: string | null;\n}\n\nexport class ZylemScene implements Entity<ZylemScene> {\n\tpublic type = 'Scene';\n\n\t_setup?: SetupFunction<ZylemScene>;\n\tscene!: Scene;\n\tzylemCamera!: ZylemCamera;\n\tcontainerElement: HTMLElement | null = null;\n\tupdate: LifecycleFunction<ZylemScene> = () => { };\n\t_collision?: ((entity: any, other: any, globals?: any) => void) | undefined;\n\t_destroy?: ((globals?: any) => void) | undefined;\n\tname?: string | undefined;\n\ttag?: Set<string> | undefined;\n\n\tconstructor(id: string, camera: ZylemCamera, state: SceneState) {\n\t\tconst scene = new Scene();\n\t\tconst isColor = state.backgroundColor instanceof Color;\n\t\tconst backgroundColor = (isColor) ? state.backgroundColor : new Color(state.backgroundColor);\n\t\tscene.background = backgroundColor as Color;\n\t\tif (state.backgroundImage) {\n\t\t\tconst loader = new TextureLoader();\n\t\t\tconst texture = loader.load(state.backgroundImage);\n\t\t\tscene.background = texture;\n\t\t}\n\n\t\tthis.scene = scene;\n\t\tthis.zylemCamera = camera;\n\n\t\tthis.setupLighting(scene);\n\t\tthis.setupCamera(scene, camera);\n\t\tif (debugState.enabled) {\n\t\t\tthis.debugScene();\n\t\t}\n\t}\n\n\tsetup() {\n\t\tif (this._setup) {\n\t\t\tthis._setup({ me: this, camera: this.zylemCamera, globals: getGlobals() });\n\t\t}\n\t}\n\n\tdestroy() {\n\t\tif (this.zylemCamera && (this.zylemCamera as any).destroy) {\n\t\t\t(this.zylemCamera as any).destroy();\n\t\t}\n\t\tif (this.scene) {\n\t\t\tthis.scene.traverse((obj: any) => {\n\t\t\t\tif (obj.geometry) {\n\t\t\t\t\tobj.geometry.dispose?.();\n\t\t\t\t}\n\t\t\t\tif (obj.material) {\n\t\t\t\t\tif (Array.isArray(obj.material)) {\n\t\t\t\t\t\tobj.material.forEach((m: any) => m.dispose?.());\n\t\t\t\t\t} else {\n\t\t\t\t\t\tobj.material.dispose?.();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\t/**\n\t * Setup camera with the scene\n\t */\n\tsetupCamera(scene: Scene, camera: ZylemCamera) {\n\t\t// Add camera rig or camera directly to scene\n\t\tif (camera.cameraRig) {\n\t\t\tscene.add(camera.cameraRig);\n\t\t} else {\n\t\t\tscene.add(camera.camera as Object3D);\n\t\t}\n\t\t// Camera handles its own setup now\n\t\tcamera.setup(scene);\n\t}\n\n\t/**\n\t * Setup scene lighting\n\t */\n\tsetupLighting(scene: Scene) {\n\t\tconst ambientLight = new AmbientLight(0xffffff, 2);\n\t\tscene.add(ambientLight);\n\n\t\tconst directionalLight = new DirectionalLight(0xffffff, 2);\n\t\tdirectionalLight.name = 'Light';\n\t\tdirectionalLight.position.set(0, 100, 0);\n\t\tdirectionalLight.castShadow = true;\n\t\tdirectionalLight.shadow.camera.near = 0.1;\n\t\tdirectionalLight.shadow.camera.far = 2000;\n\t\tdirectionalLight.shadow.camera.left = -100;\n\t\tdirectionalLight.shadow.camera.right = 100;\n\t\tdirectionalLight.shadow.camera.top = 100;\n\t\tdirectionalLight.shadow.camera.bottom = -100;\n\t\tdirectionalLight.shadow.mapSize.width = 2048;\n\t\tdirectionalLight.shadow.mapSize.height = 2048;\n\t\tscene.add(directionalLight);\n\t}\n\n\t/**\n\t * Update renderer size - delegates to camera\n\t */\n\tupdateRenderer(width: number, height: number) {\n\t\tthis.zylemCamera.resize(width, height);\n\t}\n\n\t/**\n\t * Add object to scene\n\t */\n\tadd(object: Object3D, position: Vector3 = new Vector3(0, 0, 0)) {\n\t\tobject.position.set(position.x, position.y, position.z);\n\t\tthis.scene.add(object);\n\t}\n\n\t/**\n\t * Add game entity to scene\n\t */\n\taddEntity(entity: GameEntity<any>) {\n\t\tif (entity.group) {\n\t\t\tthis.add(entity.group, entity.options.position);\n\t\t} else if (entity.mesh) {\n\t\t\tthis.add(entity.mesh, entity.options.position);\n\t\t}\n\t}\n\n\t/**\n\t * Add debug helpers to scene\n\t */\n\tdebugScene() {\n\t\tconst size = 1000;\n\t\tconst divisions = 100;\n\n\t\tconst gridHelper = new GridHelper(size, divisions);\n\t\tthis.scene.add(gridHelper);\n\t}\n}","import { Color, Vector3 } from 'three';\nimport { proxy, subscribe } from 'valtio/vanilla';\nimport { BaseEntityInterface } from '../types/entity-types';\nimport { StageStateInterface } from '../types/stage-types';\nimport { getByPath, setByPath } from '../core/utility/path-utils';\n\n/**\n * Stage state proxy for reactive updates.\n */\nconst stageState = proxy({\n\tbackgroundColor: new Color(Color.NAMES.cornflowerblue),\n\tbackgroundImage: null,\n\tinputs: {\n\t\tp1: ['gamepad-1', 'keyboard-1'],\n\t\tp2: ['gamepad-2', 'keyboard-2'],\n\t},\n\tvariables: {},\n\tgravity: new Vector3(0, 0, 0),\n\tentities: [],\n} as StageStateInterface);\n\n// ============================================================\n// Stage state setters (internal use)\n// ============================================================\n\nconst setStageBackgroundColor = (value: Color) => {\n\tstageState.backgroundColor = value;\n};\n\nconst setStageBackgroundImage = (value: string | null) => {\n\tstageState.backgroundImage = value;\n};\n\nconst setEntitiesToStage = (entities: Partial<BaseEntityInterface>[]) => {\n\tstageState.entities = entities;\n};\n\n/** Replace the entire stage variables object (used on stage load). */\nconst setStageVariables = (variables: Record<string, any>) => {\n\tstageState.variables = { ...variables };\n};\n\n/** Reset all stage variables (used on stage unload). */\nconst resetStageVariables = () => {\n\tstageState.variables = {};\n};\n\nconst stageStateToString = (state: StageStateInterface) => {\n\tlet string = `\\n`;\n\tfor (const key in state) {\n\t\tconst value = state[key as keyof StageStateInterface];\n\t\tstring += `${key}:\\n`;\n\t\tif (key === 'entities') {\n\t\t\tfor (const entity of state.entities) {\n\t\t\t\tstring += ` ${entity.uuid}: ${entity.name}\\n`;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === 'object' && value !== null) {\n\t\t\tfor (const subKey in value as Record<string, any>) {\n\t\t\t\tconst subValue = value?.[subKey as keyof typeof value];\n\t\t\t\tif (subValue) {\n\t\t\t\t\tstring += ` ${subKey}: ${subValue}\\n`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (typeof value === 'string') {\n\t\t\tstring += ` ${key}: ${value}\\n`;\n\t\t}\n\t}\n\treturn string;\n};\n\n// ============================================================\n// Object-scoped variable storage (WeakMap-based)\n// ============================================================\n\n/**\n * WeakMap to store variables keyed by object reference.\n * Variables are automatically garbage collected when the target is collected.\n */\nconst variableStore = new WeakMap<object, Record<string, unknown>>();\n\n/**\n * Separate proxy store for reactivity. We need a regular Map for subscriptions\n * since WeakMap doesn't support iteration/subscriptions.\n */\nconst variableProxyStore = new Map<object, ReturnType<typeof proxy>>();\n\nfunction getOrCreateVariableProxy(target: object): Record<string, unknown> {\n\tlet store = variableProxyStore.get(target) as Record<string, unknown> | undefined;\n\tif (!store) {\n\t\tstore = proxy({});\n\t\tvariableProxyStore.set(target, store);\n\t}\n\treturn store;\n}\n\n/**\n * Set a variable on an object by path.\n * @example setVariable(stage1, 'totalAngle', 0.5)\n * @example setVariable(entity, 'enemy.count', 10)\n */\nexport function setVariable(target: object, path: string, value: unknown): void {\n\tconst store = getOrCreateVariableProxy(target);\n\tsetByPath(store, path, value);\n}\n\n/**\n * Create/initialize a variable with a default value on a target object.\n * Only sets the value if it doesn't already exist.\n * @example createVariable(stage1, 'totalAngle', 0)\n * @example createVariable(entity, 'enemy.count', 10)\n */\nexport function createVariable<T>(target: object, path: string, defaultValue: T): T {\n\tconst store = getOrCreateVariableProxy(target);\n\tconst existing = getByPath<T>(store, path);\n\tif (existing === undefined) {\n\t\tsetByPath(store, path, defaultValue);\n\t\treturn defaultValue;\n\t}\n\treturn existing;\n}\n\n/**\n * Get a variable from an object by path.\n * @example getVariable(stage1, 'totalAngle') // 0.5\n * @example getVariable<number>(entity, 'enemy.count') // 10\n */\nexport function getVariable<T = unknown>(target: object, path: string): T | undefined {\n\tconst store = variableProxyStore.get(target);\n\tif (!store) return undefined;\n\treturn getByPath<T>(store, path);\n}\n\n/**\n * Subscribe to changes on a variable at a specific path for a target object.\n * Returns an unsubscribe function.\n * @example const unsub = onVariableChange(stage1, 'score', (val) => console.log(val));\n */\nexport function onVariableChange<T = unknown>(\n\ttarget: object,\n\tpath: string,\n\tcallback: (value: T) => void\n): () => void {\n\tconst store = getOrCreateVariableProxy(target);\n\tlet previous = getByPath<T>(store, path);\n\treturn subscribe(store, () => {\n\t\tconst current = getByPath<T>(store, path);\n\t\tif (current !== previous) {\n\t\t\tprevious = current;\n\t\t\tcallback(current as T);\n\t\t}\n\t});\n}\n\n/**\n * Subscribe to changes on multiple variable paths for a target object.\n * Callback fires when any of the paths change, receiving all current values.\n * Returns an unsubscribe function.\n * @example const unsub = onVariableChanges(stage1, ['count', 'total'], ([count, total]) => console.log(count, total));\n */\nexport function onVariableChanges<T extends unknown[] = unknown[]>(\n\ttarget: object,\n\tpaths: string[],\n\tcallback: (values: T) => void\n): () => void {\n\tconst store = getOrCreateVariableProxy(target);\n\tlet previousValues = paths.map(p => getByPath(store, p));\n\treturn subscribe(store, () => {\n\t\tconst currentValues = paths.map(p => getByPath(store, p));\n\t\tconst hasChange = currentValues.some((val, i) => val !== previousValues[i]);\n\t\tif (hasChange) {\n\t\t\tpreviousValues = currentValues;\n\t\t\tcallback(currentValues as T);\n\t\t}\n\t});\n}\n\n/**\n * Clear all variables for a target object. Used on stage/entity dispose.\n */\nexport function clearVariables(target: object): void {\n\tvariableProxyStore.delete(target);\n}\n\n// ============================================================\n// Legacy stage variable functions (internal, for stage defaults)\n// ============================================================\n\nconst setStageVariable = (key: string, value: any) => {\n\tstageState.variables[key] = value;\n};\n\nconst getStageVariable = (key: string) => {\n\tif (stageState.variables.hasOwnProperty(key)) {\n\t\treturn stageState.variables[key];\n\t} else {\n\t\tconsole.warn(`Stage variable ${key} not found`);\n\t}\n};\n\nexport {\n\tstageState,\n\t\n\tsetStageBackgroundColor,\n\tsetStageBackgroundImage,\n\t\n\tstageStateToString,\n\tsetStageVariable,\n\tgetStageVariable,\n\tsetStageVariables,\n\tresetStageVariables,\n};","import { Color, Vector3 as ThreeVector3 } from 'three';\nimport { Vector3 } from '@dimforge/rapier3d-compat';\n\n// TODO: needs implementations\n/**\n * @deprecated This type is deprecated.\n */\nexport type Vect3 = ThreeVector3 | Vector3;\n\nexport const ZylemBlueColor = new Color('#0333EC');\nconst ZylemBlue = '#0333EC';\nconst ZylemBlueTransparent = '#0333ECA0';\nconst ZylemGoldText = '#DAA420';\n\ntype SizeVector = Vect3 | null;\n\nconst Vec0 = new Vector3(0, 0, 0);\nconst Vec1 = new Vector3(1, 1, 1);","import { DestroyContext, DestroyFunction, SetupContext, SetupFunction, UpdateContext, UpdateFunction } from './base-node-life-cycle';\n\n/**\n * Provides BaseNode-like lifecycle without ECS/children. Consumers implement\n * the protected hooks and may assign public setup/update/destroy callbacks.\n */\nexport abstract class LifeCycleBase<TSelf> {\n\tupdate: UpdateFunction<TSelf> = () => { };\n\tsetup: SetupFunction<TSelf> = () => { };\n\tdestroy: DestroyFunction<TSelf> = () => { };\n\n\tprotected abstract _setup(context: SetupContext<TSelf>): void;\n\tprotected abstract _update(context: UpdateContext<TSelf>): void;\n\tprotected abstract _destroy(context: DestroyContext<TSelf>): void;\n\n\tnodeSetup(context: SetupContext<TSelf>) {\n\t\tif (typeof (this as any)._setup === 'function') {\n\t\t\tthis._setup(context);\n\t\t}\n\t\tif (this.setup) {\n\t\t\tthis.setup(context);\n\t\t}\n\t}\n\n\tnodeUpdate(context: UpdateContext<TSelf>) {\n\t\tif (typeof (this as any)._update === 'function') {\n\t\t\tthis._update(context);\n\t\t}\n\t\tif (this.update) {\n\t\t\tthis.update(context);\n\t\t}\n\t}\n\n\tnodeDestroy(context: DestroyContext<TSelf>) {\n\t\tif (this.destroy) {\n\t\t\tthis.destroy(context);\n\t\t}\n\t\tif (typeof (this as any)._destroy === 'function') {\n\t\t\tthis._destroy(context);\n\t\t}\n\t}\n}\n\n\n","import {\n\tBox3,\n\tBoxGeometry,\n\tColor,\n\tEdgesGeometry,\n\tGroup,\n\tLineBasicMaterial,\n\tLineSegments,\n\tMesh,\n\tMeshBasicMaterial,\n\tObject3D,\n\tScene,\n\tVector3,\n} from 'three';\n\n/**\n * Debug overlay that displays an axis-aligned bounding box around a target Object3D.\n * Shows a semi-transparent fill plus a wireframe outline. Intended for SELECT/DELETE tools.\n */\nexport class DebugEntityCursor {\n\tprivate scene: Scene;\n\tprivate container: Group;\n\tprivate fillMesh: Mesh;\n\tprivate edgeLines: LineSegments;\n\tprivate currentColor: Color = new Color(0x00ff00);\n\tprivate bbox: Box3 = new Box3();\n\tprivate size: Vector3 = new Vector3();\n\tprivate center: Vector3 = new Vector3();\n\n\tconstructor(scene: Scene) {\n\t\tthis.scene = scene;\n\n\t\tconst initialGeometry = new BoxGeometry(1, 1, 1);\n\n\t\tthis.fillMesh = new Mesh(\n\t\t\tinitialGeometry,\n\t\t\tnew MeshBasicMaterial({\n\t\t\t\tcolor: this.currentColor,\n\t\t\t\ttransparent: true,\n\t\t\t\topacity: 0.12,\n\t\t\t\tdepthWrite: false,\n\t\t\t})\n\t\t);\n\n\t\tconst edges = new EdgesGeometry(initialGeometry);\n\t\tthis.edgeLines = new LineSegments(\n\t\t\tedges,\n\t\t\tnew LineBasicMaterial({ color: this.currentColor, linewidth: 1 })\n\t\t);\n\n\t\tthis.container = new Group();\n\t\tthis.container.name = 'DebugEntityCursor';\n\t\tthis.container.add(this.fillMesh);\n\t\tthis.container.add(this.edgeLines);\n\t\tthis.container.visible = false;\n\n\t\tthis.scene.add(this.container);\n\t}\n\n\tsetColor(color: Color | number): void {\n\t\tthis.currentColor.set(color as any);\n\t\t(this.fillMesh.material as MeshBasicMaterial).color.set(this.currentColor);\n\t\t(this.edgeLines.material as LineBasicMaterial).color.set(this.currentColor);\n\t}\n\n\t/**\n\t * Update the cursor to enclose the provided Object3D using a world-space AABB.\n\t */\n\tupdateFromObject(object: Object3D | null | undefined): void {\n\t\tif (!object) {\n\t\t\tthis.hide();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.bbox.setFromObject(object);\n\t\tif (!isFinite(this.bbox.min.x) || !isFinite(this.bbox.max.x)) {\n\t\t\tthis.hide();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.bbox.getSize(this.size);\n\t\tthis.bbox.getCenter(this.center);\n\n\t\tconst newGeom = new BoxGeometry(\n\t\t\tMath.max(this.size.x, 1e-6),\n\t\t\tMath.max(this.size.y, 1e-6),\n\t\t\tMath.max(this.size.z, 1e-6)\n\t\t);\n\t\tthis.fillMesh.geometry.dispose();\n\t\tthis.fillMesh.geometry = newGeom;\n\n\t\tconst newEdges = new EdgesGeometry(newGeom);\n\t\tthis.edgeLines.geometry.dispose();\n\t\tthis.edgeLines.geometry = newEdges;\n\n\t\tthis.container.position.copy(this.center);\n\t\tthis.container.visible = true;\n\t}\n\n\thide(): void {\n\t\tthis.container.visible = false;\n\t}\n\n\tdispose(): void {\n\t\tthis.scene.remove(this.container);\n\t\tthis.fillMesh.geometry.dispose();\n\t\t(this.fillMesh.material as MeshBasicMaterial).dispose();\n\t\tthis.edgeLines.geometry.dispose();\n\t\t(this.edgeLines.material as LineBasicMaterial).dispose();\n\t}\n}\n\n\n","import { Ray, RayColliderToi } from '@dimforge/rapier3d-compat';\nimport { BufferAttribute, BufferGeometry, LineBasicMaterial, LineSegments, Raycaster, Vector2, Vector3 } from 'three';\nimport { ZylemStage } from './zylem-stage';\nimport { debugState, DebugTools, getDebugTool, getHoveredEntity, resetHoveredEntity, setHoveredEntity, setSelectedEntity } from '../debug/debug-state';\nimport { DebugEntityCursor } from './debug-entity-cursor';\n\nexport type AddEntityFactory = (params: { position: Vector3; normal?: Vector3 }) => Promise<any> | any;\n\nexport interface StageDebugDelegateOptions {\n\tmaxRayDistance?: number;\n\taddEntityFactory?: AddEntityFactory | null;\n}\n\nconst SELECT_TOOL_COLOR = 0x22ff22;\nconst DELETE_TOOL_COLOR = 0xff3333;\n\nexport class StageDebugDelegate {\n\tprivate stage: ZylemStage;\n\tprivate options: Required<StageDebugDelegateOptions>;\n\tprivate mouseNdc: Vector2 = new Vector2(-2, -2);\n\tprivate raycaster: Raycaster = new Raycaster();\n\tprivate isMouseDown = false;\n\tprivate disposeFns: Array<() => void> = [];\n\tprivate debugCursor: DebugEntityCursor | null = null;\n\tprivate debugLines: LineSegments | null = null;\n\n\tconstructor(stage: ZylemStage, options?: StageDebugDelegateOptions) {\n\t\tthis.stage = stage;\n\t\tthis.options = {\n\t\t\tmaxRayDistance: options?.maxRayDistance ?? 5_000,\n\t\t\taddEntityFactory: options?.addEntityFactory ?? null,\n\t\t};\n\t\tif (this.stage.scene) {\n\t\t\tthis.debugLines = new LineSegments(\n\t\t\t\tnew BufferGeometry(),\n\t\t\t\tnew LineBasicMaterial({ vertexColors: true })\n\t\t\t);\n\t\t\tthis.stage.scene.scene.add(this.debugLines);\n\t\t\tthis.debugLines.visible = true;\n\n\t\t\tthis.debugCursor = new DebugEntityCursor(this.stage.scene.scene);\n\t\t}\n\t\tthis.attachDomListeners();\n\t}\n\n\tupdate(): void {\n\t\tif (!debugState.enabled) return;\n\t\tif (!this.stage.scene || !this.stage.world || !this.stage.cameraRef) return;\n\n\t\tconst { world, cameraRef } = this.stage;\n\n\t\tif (this.debugLines) {\n\t\t\tconst { vertices, colors } = world.world.debugRender();\n\t\t\tthis.debugLines.geometry.setAttribute('position', new BufferAttribute(vertices, 3));\n\t\t\tthis.debugLines.geometry.setAttribute('color', new BufferAttribute(colors, 4));\n\t\t}\n\t\tconst tool = getDebugTool();\n\t\tconst isCursorTool = tool === 'select' || tool === 'delete';\n\n\t\tthis.raycaster.setFromCamera(this.mouseNdc, cameraRef.camera);\n\t\tconst origin = this.raycaster.ray.origin.clone();\n\t\tconst direction = this.raycaster.ray.direction.clone().normalize();\n\n\t\tconst rapierRay = new Ray(\n\t\t\t{ x: origin.x, y: origin.y, z: origin.z },\n\t\t\t{ x: direction.x, y: direction.y, z: direction.z },\n\t\t);\n\t\tconst hit: RayColliderToi | null = world.world.castRay(rapierRay, this.options.maxRayDistance, true);\n\n\t\tif (hit && isCursorTool) {\n\t\t\t// @ts-ignore - access compat object's parent userData mapping back to GameEntity\n\t\t\tconst rigidBody = hit.collider?._parent;\n\t\t\tconst hoveredUuid: string | undefined = rigidBody?.userData?.uuid;\n\t\t\tif (hoveredUuid) {\n\t\t\t\tconst entity = this.stage._debugMap.get(hoveredUuid);\n\t\t\t\tif (entity) setHoveredEntity(entity as any);\n\t\t\t} else {\n\t\t\t\tresetHoveredEntity();\n\t\t\t}\n\n\t\t\tif (this.isMouseDown) {\n\t\t\t\tthis.handleActionOnHit(hoveredUuid ?? null, origin, direction, hit.toi);\n\t\t\t}\n\t\t}\n\t\tthis.isMouseDown = false;\n\n\t\tconst hoveredUuid = getHoveredEntity();\n\t\tif (!hoveredUuid) {\n\t\t\tthis.debugCursor?.hide();\n\t\t\treturn;\n\t\t}\n\t\tconst hoveredEntity: any = this.stage._debugMap.get(`${hoveredUuid}`);\n\t\tconst targetObject = hoveredEntity?.group ?? hoveredEntity?.mesh ?? null;\n\t\tif (!targetObject) {\n\t\t\tthis.debugCursor?.hide();\n\t\t\treturn;\n\t\t}\n\t\tswitch (tool) {\n\t\t\tcase 'select':\n\t\t\t\tthis.debugCursor?.setColor(SELECT_TOOL_COLOR);\n\t\t\t\tbreak;\n\t\t\tcase 'delete':\n\t\t\t\tthis.debugCursor?.setColor(DELETE_TOOL_COLOR);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.debugCursor?.setColor(0xffffff);\n\t\t\t\tbreak;\n\t\t}\n\t\tthis.debugCursor?.updateFromObject(targetObject);\n\t}\n\n\tdispose(): void {\n\t\tthis.disposeFns.forEach((fn) => fn());\n\t\tthis.disposeFns = [];\n\t\tthis.debugCursor?.dispose();\n\t\tif (this.debugLines && this.stage.scene) {\n\t\t\tthis.stage.scene.scene.remove(this.debugLines);\n\t\t\tthis.debugLines.geometry.dispose();\n\t\t\t(this.debugLines.material as LineBasicMaterial).dispose();\n\t\t\tthis.debugLines = null;\n\t\t}\n\t}\n\n\tprivate handleActionOnHit(hoveredUuid: string | null, origin: Vector3, direction: Vector3, toi: number) {\n\t\tconst tool = getDebugTool();\n\t\tswitch (tool) {\n\t\t\tcase 'select': {\n\t\t\t\tif (hoveredUuid) {\n\t\t\t\t\tconst entity = this.stage._debugMap.get(hoveredUuid);\n\t\t\t\t\tif (entity) setSelectedEntity(entity as any);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'delete': {\n\t\t\t\tif (hoveredUuid) {\n\t\t\t\t\tthis.stage.removeEntityByUuid(hoveredUuid);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'scale': {\n\t\t\t\tif (!this.options.addEntityFactory) break;\n\t\t\t\tconst hitPosition = origin.clone().add(direction.clone().multiplyScalar(toi));\n\t\t\t\tconst newNode = this.options.addEntityFactory({ position: hitPosition });\n\t\t\t\tif (newNode) {\n\t\t\t\t\tPromise.resolve(newNode).then((node) => {\n\t\t\t\t\t\tif (node) this.stage.spawnEntity(node);\n\t\t\t\t\t}).catch(() => { });\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate attachDomListeners() {\n\t\tconst canvas = this.stage.cameraRef?.renderer.domElement ?? this.stage.scene?.zylemCamera.renderer.domElement;\n\t\tif (!canvas) return;\n\n\t\tconst onMouseMove = (e: MouseEvent) => {\n\t\t\tconst rect = canvas.getBoundingClientRect();\n\t\t\tconst x = ((e.clientX - rect.left) / rect.width) * 2 - 1;\n\t\t\tconst y = -(((e.clientY - rect.top) / rect.height) * 2 - 1);\n\t\t\tthis.mouseNdc.set(x, y);\n\t\t};\n\n\t\tconst onMouseDown = (e: MouseEvent) => {\n\t\t\tthis.isMouseDown = true;\n\t\t};\n\n\t\tcanvas.addEventListener('mousemove', onMouseMove);\n\t\tcanvas.addEventListener('mousedown', onMouseDown);\n\n\t\tthis.disposeFns.push(() => canvas.removeEventListener('mousemove', onMouseMove));\n\t\tthis.disposeFns.push(() => canvas.removeEventListener('mousedown', onMouseDown));\n\t}\n}\n\n\n","import { Object3D } from 'three';\nimport { subscribe } from 'valtio/vanilla';\n\nimport type { CameraDebugDelegate, CameraDebugState } from '../camera/zylem-camera';\nimport { debugState } from '../debug/debug-state';\nimport type { ZylemStage } from './zylem-stage';\n\nconst cloneSelected = (selected: string[]): string[] => [...selected];\n\n/**\n * Debug delegate that bridges the stage's entity map and debug state to the camera.\n */\nexport class StageCameraDebugDelegate implements CameraDebugDelegate {\n\tprivate stage: ZylemStage;\n\n\tconstructor(stage: ZylemStage) {\n\t\tthis.stage = stage;\n\t}\n\n\tsubscribe(listener: (state: CameraDebugState) => void): () => void {\n\t\tconst notify = () => listener(this.snapshot());\n\t\tnotify();\n\t\treturn subscribe(debugState, notify);\n\t}\n\n\tresolveTarget(uuid: string): Object3D | null {\n\t\tconst entity: any = this.stage._debugMap.get(uuid)\n\t\t\t|| this.stage.world?.collisionMap.get(uuid)\n\t\t\t|| null;\n\t\tconst target = entity?.group ?? entity?.mesh ?? null;\n\t\treturn target ?? null;\n\t}\n\n\tprivate snapshot(): CameraDebugState {\n\t\treturn {\n\t\t\tenabled: debugState.enabled,\n\t\t\tselected: debugState.selectedEntity ? [debugState.selectedEntity.uuid] : [],\n\t\t};\n\t}\n}\n\n","export const Perspectives = {\n\tFirstPerson: 'first-person',\n\tThirdPerson: 'third-person',\n\tIsometric: 'isometric',\n\tFlat2D: 'flat-2d',\n\tFixed2D: 'fixed-2d',\n} as const;\n\nexport type PerspectiveType = (typeof Perspectives)[keyof typeof Perspectives];","import { Scene, Vector2, Vector3, WebGLRenderer } from 'three';\nimport { PerspectiveController, ZylemCamera } from './zylem-camera';\nimport { StageEntity } from '../interfaces/entity';\n\ninterface ThirdPersonCameraOptions {\n\ttarget: StageEntity;\n\tdistance: Vector3;\n\tscreenResolution: Vector2;\n\trenderer: WebGLRenderer;\n\tscene: Scene;\n}\n\nexport class ThirdPersonCamera implements PerspectiveController {\n\tdistance: Vector3;\n\tscreenResolution: Vector2 | null = null;\n\trenderer: WebGLRenderer | null = null;\n\tscene: Scene | null = null;\n\tcameraRef: ZylemCamera | null = null;\n\n\tconstructor() {\n\t\tthis.distance = new Vector3(0, 5, 8);\n\t}\n\n\t/**\n\t * Setup the third person camera controller\n\t */\n\tsetup(params: { screenResolution: Vector2; renderer: WebGLRenderer; scene: Scene; camera: ZylemCamera }) {\n\t\tconst { screenResolution, renderer, scene, camera } = params;\n\t\tthis.screenResolution = screenResolution;\n\t\tthis.renderer = renderer;\n\t\tthis.scene = scene;\n\t\tthis.cameraRef = camera;\n\t}\n\n\t/**\n\t * Update the third person camera\n\t */\n\tupdate(delta: number) {\n\t\tif (!this.cameraRef!.target) {\n\t\t\treturn;\n\t\t}\n\t\t// TODO: Implement third person camera following logic\n\t\tconst desiredCameraPosition = this.cameraRef!.target!.group.position.clone().add(this.distance);\n\t\tthis.cameraRef!.camera.position.lerp(desiredCameraPosition, 0.1);\n\t\tthis.cameraRef!.camera.lookAt(this.cameraRef!.target!.group.position);\n\t}\n\n\t/**\n\t * Handle resize events\n\t */\n\tresize(width: number, height: number) {\n\t\tif (this.screenResolution) {\n\t\t\tthis.screenResolution.set(width, height);\n\t\t}\n\t\t// TODO: Handle any third-person specific resize logic\n\t}\n\n\t/**\n\t * Set the distance from the target\n\t */\n\tsetDistance(distance: Vector3) {\n\t\tthis.distance = distance;\n\t}\n}","import { Scene, Vector2, WebGLRenderer } from 'three';\nimport { PerspectiveController, ZylemCamera } from './zylem-camera';\n\n/**\n * Fixed 2D Camera Controller\n * Maintains a static 2D camera view with no automatic following or movement\n */\nexport class Fixed2DCamera implements PerspectiveController {\n\tscreenResolution: Vector2 | null = null;\n\trenderer: WebGLRenderer | null = null;\n\tscene: Scene | null = null;\n\tcameraRef: ZylemCamera | null = null;\n\n\tconstructor() {\n\t\t// Fixed 2D camera doesn't need any initial setup parameters\n\t}\n\n\t/**\n\t * Setup the fixed 2D camera controller\n\t */\n\tsetup(params: { screenResolution: Vector2; renderer: WebGLRenderer; scene: Scene; camera: ZylemCamera }) {\n\t\tconst { screenResolution, renderer, scene, camera } = params;\n\t\tthis.screenResolution = screenResolution;\n\t\tthis.renderer = renderer;\n\t\tthis.scene = scene;\n\t\tthis.cameraRef = camera;\n\n\t\t// Position camera for 2D view (looking down the Z-axis)\n\t\tthis.cameraRef.camera.position.set(0, 0, 10);\n\t\tthis.cameraRef.camera.lookAt(0, 0, 0);\n\t}\n\n\t/**\n\t * Update the fixed 2D camera\n\t * Fixed cameras don't need to update position/rotation automatically\n\t */\n\tupdate(delta: number) {\n\t\t// Fixed 2D camera maintains its position and orientation\n\t\t// No automatic updates needed for a truly fixed camera\n\t}\n\n\t/**\n\t * Handle resize events for 2D camera\n\t */\n\tresize(width: number, height: number) {\n\t\tif (this.screenResolution) {\n\t\t\tthis.screenResolution.set(width, height);\n\t\t}\n\n\t\t// For orthographic cameras, we might need to adjust the frustum\n\t\t// This is handled in the main ZylemCamera resize method\n\t}\n}\n","export default \"varying vec2 vUv;\\n\\nvoid main() {\\n\\tvUv = uv;\\n\\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\\n}\"","import * as THREE from 'three';\nimport fragmentShader from './shaders/fragment/standard.glsl';\nimport vertexShader from './shaders/vertex/standard.glsl';\nimport { WebGLRenderer, WebGLRenderTarget } from 'three';\nimport { Pass, FullScreenQuad } from 'three/addons/postprocessing/Pass.js';\n\nexport default class RenderPass extends Pass {\n\tfsQuad: FullScreenQuad;\n\tresolution: THREE.Vector2;\n\tscene: THREE.Scene;\n\tcamera: THREE.Camera;\n\trgbRenderTarget: WebGLRenderTarget;\n\tnormalRenderTarget: WebGLRenderTarget;\n\tnormalMaterial: THREE.Material;\n\n\tconstructor(resolution: THREE.Vector2, scene: THREE.Scene, camera: THREE.Camera) {\n\t\tsuper();\n\t\tthis.resolution = resolution;\n\t\tthis.fsQuad = new FullScreenQuad(this.material());\n\t\tthis.scene = scene;\n\t\tthis.camera = camera;\n\n\t\tthis.rgbRenderTarget = new WebGLRenderTarget(resolution.x * 4, resolution.y * 4);\n\t\tthis.normalRenderTarget = new WebGLRenderTarget(resolution.x * 4, resolution.y * 4);\n\n\t\tthis.normalMaterial = new THREE.MeshNormalMaterial();\n\t}\n\n\trender(\n\t\trenderer: WebGLRenderer,\n\t\twriteBuffer: WebGLRenderTarget\n\t) {\n\t\trenderer.setRenderTarget(this.rgbRenderTarget);\n\t\trenderer.render(this.scene, this.camera);\n\n\t\tconst overrideMaterial_old = this.scene.overrideMaterial;\n\t\trenderer.setRenderTarget(this.normalRenderTarget);\n\t\tthis.scene.overrideMaterial = this.normalMaterial;\n\t\trenderer.render(this.scene, this.camera);\n\t\tthis.scene.overrideMaterial = overrideMaterial_old;\n\n\t\t// @ts-ignore\n\t\tconst uniforms = this.fsQuad.material.uniforms;\n\t\tuniforms.tDiffuse.value = this.rgbRenderTarget.texture;\n\t\tuniforms.tDepth.value = this.rgbRenderTarget.depthTexture;\n\t\tuniforms.tNormal.value = this.normalRenderTarget.texture;\n\t\tuniforms.iTime.value += 0.01;\n\n\t\tif (this.renderToScreen) {\n\t\t\trenderer.setRenderTarget(null);\n\t\t} else {\n\t\t\trenderer.setRenderTarget(writeBuffer);\n\t\t}\n\t\tthis.fsQuad.render(renderer);\n\t}\n\n\tmaterial() {\n\t\treturn new THREE.ShaderMaterial({\n\t\t\tuniforms: {\n\t\t\t\tiTime: { value: 0 },\n\t\t\t\ttDiffuse: { value: null },\n\t\t\t\ttDepth: { value: null },\n\t\t\t\ttNormal: { value: null },\n\t\t\t\tresolution: {\n\t\t\t\t\tvalue: new THREE.Vector4(\n\t\t\t\t\t\tthis.resolution.x,\n\t\t\t\t\t\tthis.resolution.y,\n\t\t\t\t\t\t1 / this.resolution.x,\n\t\t\t\t\t\t1 / this.resolution.y,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t\tvertexShader: vertexShader,\n\t\t\tfragmentShader: fragmentShader\n\t\t});\n\t}\n\n\tdispose() {\n\t\ttry {\n\t\t\tthis.fsQuad?.dispose?.();\n\t\t} catch { /* noop */ }\n\t\ttry {\n\t\t\t(this.rgbRenderTarget as any)?.dispose?.();\n\t\t\t(this.normalRenderTarget as any)?.dispose?.();\n\t\t} catch { /* noop */ }\n\t\ttry {\n\t\t\t(this.normalMaterial as any)?.dispose?.();\n\t\t} catch { /* noop */ }\n\t}\n}\n","import { Object3D, Vector3, Quaternion, Camera } from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\n\nexport interface CameraDebugState {\n\tenabled: boolean;\n\tselected: string[];\n}\n\nexport interface CameraDebugDelegate {\n\tsubscribe(listener: (state: CameraDebugState) => void): () => void;\n\tresolveTarget(uuid: string): Object3D | null;\n}\n\n/**\n * Manages orbit controls and debug state for a camera.\n * Orbit controls are only active when debug mode is enabled.\n */\nexport class CameraOrbitController {\n\tprivate camera: Camera;\n\tprivate domElement: HTMLElement;\n\t\n\tprivate orbitControls: OrbitControls | null = null;\n\tprivate orbitTarget: Object3D | null = null;\n\tprivate orbitTargetWorldPos: Vector3 = new Vector3();\n\n\tprivate debugDelegate: CameraDebugDelegate | null = null;\n\tprivate debugUnsubscribe: (() => void) | null = null;\n\tprivate debugStateSnapshot: CameraDebugState = { enabled: false, selected: [] };\n\n\t// Saved camera state for restoration when exiting debug mode\n\tprivate savedCameraPosition: Vector3 | null = null;\n\tprivate savedCameraQuaternion: Quaternion | null = null;\n\tprivate savedCameraZoom: number | null = null;\n\n\tconstructor(camera: Camera, domElement: HTMLElement) {\n\t\tthis.camera = camera;\n\t\tthis.domElement = domElement;\n\t}\n\n\t/**\n\t * Check if debug mode is currently active (orbit controls enabled).\n\t */\n\tget isActive(): boolean {\n\t\treturn this.debugStateSnapshot.enabled;\n\t}\n\n\t/**\n\t * Update orbit controls each frame.\n\t * Should be called from the camera's update loop.\n\t */\n\tupdate() {\n\t\tif (this.orbitControls && this.orbitTarget) {\n\t\t\tthis.orbitTarget.getWorldPosition(this.orbitTargetWorldPos);\n\t\t\tthis.orbitControls.target.copy(this.orbitTargetWorldPos);\n\t\t}\n\t\tthis.orbitControls?.update();\n\t}\n\n\t/**\n\t * Attach a delegate to react to debug state changes.\n\t */\n\tsetDebugDelegate(delegate: CameraDebugDelegate | null) {\n\t\tif (this.debugDelegate === delegate) {\n\t\t\treturn;\n\t\t}\n\t\tthis.detachDebugDelegate();\n\t\tthis.debugDelegate = delegate;\n\t\tif (!delegate) {\n\t\t\tthis.applyDebugState({ enabled: false, selected: [] });\n\t\t\treturn;\n\t\t}\n\t\tconst unsubscribe = delegate.subscribe((state) => {\n\t\t\tthis.applyDebugState(state);\n\t\t});\n\t\tthis.debugUnsubscribe = () => {\n\t\t\tunsubscribe?.();\n\t\t};\n\t}\n\n\t/**\n\t * Clean up resources.\n\t */\n\tdispose() {\n\t\tthis.disableOrbitControls();\n\t\tthis.detachDebugDelegate();\n\t}\n\n\t/**\n\t * Get the current debug state snapshot.\n\t */\n\tget debugState(): CameraDebugState {\n\t\treturn this.debugStateSnapshot;\n\t}\n\n\tprivate applyDebugState(state: CameraDebugState) {\n\t\tconst wasEnabled = this.debugStateSnapshot.enabled;\n\t\tthis.debugStateSnapshot = {\n\t\t\tenabled: state.enabled,\n\t\t\tselected: [...state.selected],\n\t\t};\n\t\t\n\t\tif (state.enabled && !wasEnabled) {\n\t\t\t// Entering debug mode: save camera state\n\t\t\tthis.saveCameraState();\n\t\t\tthis.enableOrbitControls();\n\t\t\tthis.updateOrbitTargetFromSelection(state.selected);\n\t\t} else if (!state.enabled && wasEnabled) {\n\t\t\t// Exiting debug mode: restore camera state\n\t\t\tthis.orbitTarget = null;\n\t\t\tthis.disableOrbitControls();\n\t\t\tthis.restoreCameraState();\n\t\t} else if (state.enabled) {\n\t\t\t// Still in debug mode, just update target\n\t\t\tthis.updateOrbitTargetFromSelection(state.selected);\n\t\t}\n\t}\n\n\tprivate enableOrbitControls() {\n\t\tif (this.orbitControls) {\n\t\t\treturn;\n\t\t}\n\t\tthis.orbitControls = new OrbitControls(this.camera, this.domElement);\n\t\tthis.orbitControls.enableDamping = true;\n\t\tthis.orbitControls.dampingFactor = 0.05;\n\t\tthis.orbitControls.screenSpacePanning = false;\n\t\tthis.orbitControls.minDistance = 1;\n\t\tthis.orbitControls.maxDistance = 500;\n\t\tthis.orbitControls.maxPolarAngle = Math.PI / 2;\n\t\t// Default target to origin\n\t\tthis.orbitControls.target.set(0, 0, 0);\n\t}\n\n\tprivate disableOrbitControls() {\n\t\tif (!this.orbitControls) {\n\t\t\treturn;\n\t\t}\n\t\tthis.orbitControls.dispose();\n\t\tthis.orbitControls = null;\n\t}\n\n\tprivate updateOrbitTargetFromSelection(selected: string[]) {\n\t\t// Default to origin when no entity is selected\n\t\tif (!this.debugDelegate || selected.length === 0) {\n\t\t\tthis.orbitTarget = null;\n\t\t\tif (this.orbitControls) {\n\t\t\t\tthis.orbitControls.target.set(0, 0, 0);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tfor (let i = selected.length - 1; i >= 0; i -= 1) {\n\t\t\tconst uuid = selected[i];\n\t\t\tconst targetObject = this.debugDelegate.resolveTarget(uuid);\n\t\t\tif (targetObject) {\n\t\t\t\tthis.orbitTarget = targetObject;\n\t\t\t\tif (this.orbitControls) {\n\t\t\t\t\ttargetObject.getWorldPosition(this.orbitTargetWorldPos);\n\t\t\t\t\tthis.orbitControls.target.copy(this.orbitTargetWorldPos);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.orbitTarget = null;\n\t}\n\n\tprivate detachDebugDelegate() {\n\t\tif (this.debugUnsubscribe) {\n\t\t\ttry {\n\t\t\t\tthis.debugUnsubscribe();\n\t\t\t} catch { /* noop */ }\n\t\t}\n\t\tthis.debugUnsubscribe = null;\n\t\tthis.debugDelegate = null;\n\t}\n\n\t/**\n\t * Save camera position, rotation, and zoom before entering debug mode.\n\t */\n\tprivate saveCameraState() {\n\t\tthis.savedCameraPosition = this.camera.position.clone();\n\t\tthis.savedCameraQuaternion = this.camera.quaternion.clone();\n\t\t// Save zoom for orthographic/perspective cameras\n\t\tif ('zoom' in this.camera) {\n\t\t\tthis.savedCameraZoom = (this.camera as any).zoom as number;\n\t\t}\n\t}\n\n\t/**\n\t * Restore camera position, rotation, and zoom when exiting debug mode.\n\t */\n\tprivate restoreCameraState() {\n\t\tif (this.savedCameraPosition) {\n\t\t\tthis.camera.position.copy(this.savedCameraPosition);\n\t\t\tthis.savedCameraPosition = null;\n\t\t}\n\t\tif (this.savedCameraQuaternion) {\n\t\t\tthis.camera.quaternion.copy(this.savedCameraQuaternion);\n\t\t\tthis.savedCameraQuaternion = null;\n\t\t}\n\t\tif (this.savedCameraZoom !== null && 'zoom' in this.camera) {\n\t\t\tthis.camera.zoom = this.savedCameraZoom;\n\t\t\t(this.camera as any).updateProjectionMatrix?.();\n\t\t\tthis.savedCameraZoom = null;\n\t\t}\n\t}\n}\n","import { Vector2, Camera, PerspectiveCamera, Vector3, Object3D, OrthographicCamera, WebGLRenderer, Scene } from 'three';\nimport { PerspectiveType, Perspectives } from './perspective';\nimport { ThirdPersonCamera } from './third-person';\nimport { Fixed2DCamera } from './fixed-2d';\nimport { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';\nimport RenderPass from '../graphics/render-pass';\nimport { StageEntity } from '../interfaces/entity';\nimport { CameraOrbitController, CameraDebugDelegate } from './camera-debug-delegate';\n\n// Re-export for backwards compatibility\nexport type { CameraDebugState, CameraDebugDelegate } from './camera-debug-delegate';\n\n/**\n * Interface for perspective-specific camera controllers\n */\nexport interface PerspectiveController {\n\tsetup(params: { screenResolution: Vector2; renderer: WebGLRenderer; scene: Scene; camera: ZylemCamera }): void;\n\tupdate(delta: number): void;\n\tresize(width: number, height: number): void;\n}\n\nexport class ZylemCamera {\n\tcameraRig: Object3D | null = null;\n\tcamera: Camera;\n\tscreenResolution: Vector2;\n\trenderer: WebGLRenderer;\n\tcomposer: EffectComposer;\n\t_perspective: PerspectiveType;\n\ttarget: StageEntity | null = null;\n\tsceneRef: Scene | null = null;\n\tfrustumSize = 10;\n\n\t// Perspective controller delegation\n\tperspectiveController: PerspectiveController | null = null;\n\n\t// Debug/orbit controls delegation\n\tprivate orbitController: CameraOrbitController | null = null;\n\n\tconstructor(perspective: PerspectiveType, screenResolution: Vector2, frustumSize: number = 10) {\n\t\tthis._perspective = perspective;\n\t\tthis.screenResolution = screenResolution;\n\t\tthis.frustumSize = frustumSize;\n\t\t// Initialize renderer\n\t\tthis.renderer = new WebGLRenderer({ antialias: false, alpha: true });\n\t\tthis.renderer.setSize(screenResolution.x, screenResolution.y);\n\t\tthis.renderer.shadowMap.enabled = true;\n\n\t\t// Initialize composer\n\t\tthis.composer = new EffectComposer(this.renderer);\n\n\t\t// Create camera based on perspective\n\t\tconst aspectRatio = screenResolution.x / screenResolution.y;\n\t\tthis.camera = this.createCameraForPerspective(aspectRatio);\n\n\t\t// Setup camera rig only for perspectives that need it (e.g., third-person following)\n\t\tif (this.needsRig()) {\n\t\t\tthis.cameraRig = new Object3D();\n\t\t\tthis.cameraRig.position.set(0, 3, 10);\n\t\t\tthis.cameraRig.add(this.camera);\n\t\t\tthis.camera.lookAt(new Vector3(0, 2, 0));\n\t\t} else {\n\t\t\t// Position camera directly for non-rig perspectives\n\t\t\tthis.camera.position.set(0, 0, 10);\n\t\t\tthis.camera.lookAt(new Vector3(0, 0, 0));\n\t\t}\n\n\t\t// Initialize perspective controller\n\t\tthis.initializePerspectiveController();\n\n\t\t// Initialize orbit controller (handles debug mode orbit controls)\n\t\tthis.orbitController = new CameraOrbitController(this.camera, this.renderer.domElement);\n\t}\n\n\t/**\n\t * Setup the camera with a scene\n\t */\n\tasync setup(scene: Scene) {\n\t\tthis.sceneRef = scene;\n\n\t\t// Setup render pass\n\t\tlet renderResolution = this.screenResolution.clone().divideScalar(2);\n\t\trenderResolution.x |= 0;\n\t\trenderResolution.y |= 0;\n\t\tconst pass = new RenderPass(renderResolution, scene, this.camera);\n\t\tthis.composer.addPass(pass);\n\n\t\t// Setup perspective controller\n\t\tif (this.perspectiveController) {\n\t\t\tthis.perspectiveController.setup({\n\t\t\t\tscreenResolution: this.screenResolution,\n\t\t\t\trenderer: this.renderer,\n\t\t\t\tscene: scene,\n\t\t\t\tcamera: this\n\t\t\t});\n\t\t}\n\n\t\t// Start render loop\n\t\tthis.renderer.setAnimationLoop((delta) => {\n\t\t\tthis.update(delta || 0);\n\t\t});\n\t}\n\n\t/**\n\t * Update camera and render\n\t */\n\tupdate(delta: number) {\n\t\t// Update orbit controls (if debug mode is enabled)\n\t\tthis.orbitController?.update();\n\n\t\t// Skip perspective controller updates when in debug mode\n\t\t// This keeps the debug camera isolated from game camera logic\n\t\tif (this.perspectiveController && !this.isDebugModeActive()) {\n\t\t\tthis.perspectiveController.update(delta);\n\t\t}\n\n\t\t// Render the scene\n\t\tthis.composer.render(delta);\n\t}\n\n\t/**\n\t * Check if debug mode is active (orbit controls taking over camera)\n\t */\n\tisDebugModeActive(): boolean {\n\t\treturn this.orbitController?.isActive ?? false;\n\t}\n\n\t/**\n\t * Dispose renderer, composer, controls, and detach from scene\n\t */\n\tdestroy() {\n\t\ttry {\n\t\t\tthis.renderer.setAnimationLoop(null as any);\n\t\t} catch { /* noop */ }\n\t\ttry {\n\t\t\tthis.orbitController?.dispose();\n\t\t} catch { /* noop */ }\n\t\ttry {\n\t\t\tthis.composer?.passes?.forEach((p: any) => p.dispose?.());\n\t\t\t// @ts-ignore dispose exists on EffectComposer but not typed here\n\t\t\tthis.composer?.dispose?.();\n\t\t} catch { /* noop */ }\n\t\ttry {\n\t\t\tthis.renderer.dispose();\n\t\t} catch { /* noop */ }\n\t\tthis.sceneRef = null;\n\t}\n\n\t/**\n\t * Attach a delegate to react to debug state changes.\n\t */\n\tsetDebugDelegate(delegate: CameraDebugDelegate | null) {\n\t\tthis.orbitController?.setDebugDelegate(delegate);\n\t}\n\n\t/**\n\t * Resize camera and renderer\n\t */\n\tresize(width: number, height: number) {\n\t\tthis.screenResolution.set(width, height);\n\t\tthis.renderer.setSize(width, height, false);\n\t\tthis.composer.setSize(width, height);\n\n\t\tif (this.camera instanceof PerspectiveCamera) {\n\t\t\tthis.camera.aspect = width / height;\n\t\t\tthis.camera.updateProjectionMatrix();\n\t\t}\n\n\t\tif (this.perspectiveController) {\n\t\t\tthis.perspectiveController.resize(width, height);\n\t\t}\n\t}\n\n\t/**\n\t * Update renderer pixel ratio (DPR)\n\t */\n\tsetPixelRatio(dpr: number) {\n\t\tconst safe = Math.max(1, Number.isFinite(dpr) ? dpr : 1);\n\t\tthis.renderer.setPixelRatio(safe);\n\t}\n\n\t/**\n\t * Create camera based on perspective type\n\t */\n\tprivate createCameraForPerspective(aspectRatio: number): Camera {\n\t\tswitch (this._perspective) {\n\t\t\tcase Perspectives.ThirdPerson:\n\t\t\t\treturn this.createThirdPersonCamera(aspectRatio);\n\t\t\tcase Perspectives.FirstPerson:\n\t\t\t\treturn this.createFirstPersonCamera(aspectRatio);\n\t\t\tcase Perspectives.Isometric:\n\t\t\t\treturn this.createIsometricCamera(aspectRatio);\n\t\t\tcase Perspectives.Flat2D:\n\t\t\t\treturn this.createFlat2DCamera(aspectRatio);\n\t\t\tcase Perspectives.Fixed2D:\n\t\t\t\treturn this.createFixed2DCamera(aspectRatio);\n\t\t\tdefault:\n\t\t\t\treturn this.createThirdPersonCamera(aspectRatio);\n\t\t}\n\t}\n\n\t/**\n\t * Initialize perspective-specific controller\n\t */\n\tprivate initializePerspectiveController() {\n\t\tswitch (this._perspective) {\n\t\t\tcase Perspectives.ThirdPerson:\n\t\t\t\tthis.perspectiveController = new ThirdPersonCamera();\n\t\t\t\tbreak;\n\t\t\tcase Perspectives.Fixed2D:\n\t\t\t\tthis.perspectiveController = new Fixed2DCamera();\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.perspectiveController = new ThirdPersonCamera();\n\t\t}\n\t}\n\n\tprivate createThirdPersonCamera(aspectRatio: number): PerspectiveCamera {\n\t\treturn new PerspectiveCamera(75, aspectRatio, 0.1, 1000);\n\t}\n\n\tprivate createFirstPersonCamera(aspectRatio: number): PerspectiveCamera {\n\t\treturn new PerspectiveCamera(75, aspectRatio, 0.1, 1000);\n\t}\n\n\tprivate createIsometricCamera(aspectRatio: number): OrthographicCamera {\n\t\treturn new OrthographicCamera(\n\t\t\tthis.frustumSize * aspectRatio / -2,\n\t\t\tthis.frustumSize * aspectRatio / 2,\n\t\t\tthis.frustumSize / 2,\n\t\t\tthis.frustumSize / -2,\n\t\t\t1,\n\t\t\t1000\n\t\t);\n\t}\n\n\tprivate createFlat2DCamera(aspectRatio: number): OrthographicCamera {\n\t\treturn new OrthographicCamera(\n\t\t\tthis.frustumSize * aspectRatio / -2,\n\t\t\tthis.frustumSize * aspectRatio / 2,\n\t\t\tthis.frustumSize / 2,\n\t\t\tthis.frustumSize / -2,\n\t\t\t1,\n\t\t\t1000\n\t\t);\n\t}\n\n\tprivate createFixed2DCamera(aspectRatio: number): OrthographicCamera {\n\t\treturn this.createFlat2DCamera(aspectRatio);\n\t}\n\n\t// Movement methods\n\tprivate moveCamera(position: Vector3) {\n\t\tif (this._perspective === Perspectives.Flat2D || this._perspective === Perspectives.Fixed2D) {\n\t\t\tthis.frustumSize = position.z;\n\t\t}\n\t\tif (this.cameraRig) {\n\t\t\tthis.cameraRig.position.set(position.x, position.y, position.z);\n\t\t} else {\n\t\t\tthis.camera.position.set(position.x, position.y, position.z);\n\t\t}\n\t}\n\n\tmove(position: Vector3) {\n\t\tthis.moveCamera(position);\n\t}\n\n\trotate(pitch: number, yaw: number, roll: number) {\n\t\tif (this.cameraRig) {\n\t\t\tthis.cameraRig.rotateX(pitch);\n\t\t\tthis.cameraRig.rotateY(yaw);\n\t\t\tthis.cameraRig.rotateZ(roll);\n\t\t} else {\n\t\t\t(this.camera as Object3D).rotateX(pitch);\n\t\t\t(this.camera as Object3D).rotateY(yaw);\n\t\t\t(this.camera as Object3D).rotateZ(roll);\n\t\t}\n\t}\n\n\t/**\n\t * Check if this perspective type needs a camera rig\n\t */\n\tprivate needsRig(): boolean {\n\t\treturn this._perspective === Perspectives.ThirdPerson;\n\t}\n\n\t/**\n\t * Get the DOM element for the renderer\n\t */\n\tgetDomElement(): HTMLCanvasElement {\n\t\treturn this.renderer.domElement;\n\t}\n}","import { Vector2 } from 'three';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { Perspectives, PerspectiveType } from '../camera/perspective';\nimport { CameraWrapper } from '../camera/camera';\nimport type { ZylemStage } from './zylem-stage';\n\n/**\n * Delegate for camera creation and management within a stage.\n * Accepts an injected stage reference for context.\n */\nexport class StageCameraDelegate {\n\tprivate stage: ZylemStage;\n\n\tconstructor(stage: ZylemStage) {\n\t\tthis.stage = stage;\n\t}\n\n\t/**\n\t * Create a default third-person camera based on window size.\n\t */\n\tcreateDefaultCamera(): ZylemCamera {\n\t\tconst width = window.innerWidth;\n\t\tconst height = window.innerHeight;\n\t\tconst screenResolution = new Vector2(width, height);\n\t\treturn new ZylemCamera(Perspectives.ThirdPerson, screenResolution);\n\t}\n\n\t/**\n\t * Resolve the camera to use for the stage.\n\t * Uses the provided camera, stage camera wrapper, or creates a default.\n\t * \n\t * @param cameraOverride Optional camera override\n\t * @param cameraWrapper Optional camera wrapper from stage options\n\t * @returns The resolved ZylemCamera instance\n\t */\n\tresolveCamera(cameraOverride?: ZylemCamera | null, cameraWrapper?: CameraWrapper): ZylemCamera {\n\t\tif (cameraOverride) {\n\t\t\treturn cameraOverride;\n\t\t}\n\t\tif (cameraWrapper) {\n\t\t\treturn cameraWrapper.cameraRef;\n\t\t}\n\t\treturn this.createDefaultCamera();\n\t}\n}\n","import { LoadingEvent } from '../core/interfaces';\nimport { gameEventBus, StageLoadingPayload } from '../game/game-event-bus';\n\n/**\n * Event name for stage loading events.\n * Dispatched via window for cross-application communication.\n */\nexport const STAGE_LOADING_EVENT = 'STAGE_LOADING_EVENT';\n\n/**\n * Delegate for managing loading events and progress within a stage.\n * Handles subscription to loading events and broadcasting progress.\n * Emits to game event bus for game-level observation.\n */\nexport class StageLoadingDelegate {\n\tprivate loadingHandlers: Array<(event: LoadingEvent) => void> = [];\n\tprivate stageName?: string;\n\tprivate stageIndex?: number;\n\n\t/**\n\t * Set stage context for event bus emissions.\n\t */\n\tsetStageContext(stageName: string, stageIndex: number): void {\n\t\tthis.stageName = stageName;\n\t\tthis.stageIndex = stageIndex;\n\t}\n\n\t/**\n\t * Subscribe to loading events.\n\t * \n\t * @param callback Invoked for each loading event (start, progress, complete)\n\t * @returns Unsubscribe function\n\t */\n\tonLoading(callback: (event: LoadingEvent) => void): () => void {\n\t\tthis.loadingHandlers.push(callback);\n\t\treturn () => {\n\t\t\tthis.loadingHandlers = this.loadingHandlers.filter((h) => h !== callback);\n\t\t};\n\t}\n\n\t/**\n\t * Emit a loading event to all subscribers and to the game event bus.\n\t * \n\t * @param event The loading event to broadcast\n\t */\n\temit(event: LoadingEvent): void {\n\t\t// Dispatch to direct subscribers\n\t\tfor (const handler of this.loadingHandlers) {\n\t\t\ttry {\n\t\t\t\thandler(event);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('Loading handler failed', e);\n\t\t\t}\n\t\t}\n\t\t\n\t\t// Emit to game event bus for game-level observation\n\t\tconst payload: StageLoadingPayload = {\n\t\t\t...event,\n\t\t\tstageName: this.stageName,\n\t\t\tstageIndex: this.stageIndex,\n\t\t};\n\t\t\n\t\tif (event.type === 'start') {\n\t\t\tgameEventBus.emit('stage:loading:start', payload);\n\t\t} else if (event.type === 'progress') {\n\t\t\tgameEventBus.emit('stage:loading:progress', payload);\n\t\t} else if (event.type === 'complete') {\n\t\t\tgameEventBus.emit('stage:loading:complete', payload);\n\t\t}\n\t}\n\n\t/**\n\t * Emit a start loading event.\n\t */\n\temitStart(message: string = 'Loading stage...'): void {\n\t\tthis.emit({ type: 'start', message, progress: 0 });\n\t}\n\n\t/**\n\t * Emit a progress loading event.\n\t */\n\temitProgress(message: string, current: number, total: number): void {\n\t\tconst progress = total > 0 ? current / total : 0;\n\t\tthis.emit({ type: 'progress', message, progress, current, total });\n\t}\n\n\t/**\n\t * Emit a complete loading event.\n\t */\n\temitComplete(message: string = 'Stage loaded'): void {\n\t\tthis.emit({ type: 'complete', message, progress: 1 });\n\t}\n\n\t/**\n\t * Clear all loading handlers.\n\t */\n\tdispose(): void {\n\t\tthis.loadingHandlers = [];\n\t}\n}\n","import { BaseNode } from '../base-node';\nimport { CameraWrapper } from '../../camera/camera';\n\n/**\n * Check if an item is a BaseNode (has a create function).\n */\nexport function isBaseNode(item: unknown): item is BaseNode {\n\treturn !!item && typeof item === 'object' && typeof (item as any).create === 'function';\n}\n\n/**\n * Check if an item is a Promise-like (thenable).\n */\nexport function isThenable(item: unknown): item is Promise<any> {\n\treturn !!item && typeof (item as any).then === 'function';\n}\n\n/**\n * Check if an item is a CameraWrapper.\n */\nexport function isCameraWrapper(item: unknown): item is CameraWrapper {\n\treturn !!item && typeof item === 'object' && (item as any).constructor?.name === 'CameraWrapper';\n}\n\n/**\n * Check if an item is a plain config object (not a special type).\n * Excludes BaseNode, CameraWrapper, functions, and promises.\n */\nexport function isConfigObject(item: unknown): boolean {\n\tif (!item || typeof item !== 'object') return false;\n\tif (isBaseNode(item)) return false;\n\tif (isCameraWrapper(item)) return false;\n\tif (isThenable(item)) return false;\n\tif (typeof (item as any).then === 'function') return false;\n\t// Must be a plain object\n\treturn (item as any).constructor === Object || (item as any).constructor?.name === 'Object';\n}\n\n/**\n * Check if an item is an entity input (BaseNode, Promise, or factory function).\n */\nexport function isEntityInput(item: unknown): boolean {\n\tif (!item) return false;\n\tif (isBaseNode(item)) return true;\n\tif (typeof item === 'function') return true;\n\tif (isThenable(item)) return true;\n\treturn false;\n}\n","import { Color, Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { CameraWrapper } from '../camera/camera';\nimport { isBaseNode, isCameraWrapper, isConfigObject, isEntityInput, isThenable } from '../core/utility/options-parser';\nimport { ZylemBlueColor } from '../core/utility/vector';\n\n/**\n * Stage configuration type for user-facing options.\n */\nexport type StageConfigLike = Partial<{\n\tinputs: Record<string, string[]>;\n\tbackgroundColor: Color | string;\n\tbackgroundImage: string | null;\n\tgravity: Vector3;\n\tvariables: Record<string, any>;\n}>;\n\n/**\n * Internal stage configuration class.\n */\nexport class StageConfig {\n\tconstructor(\n\t\tpublic inputs: Record<string, string[]>,\n\t\tpublic backgroundColor: Color | string,\n\t\tpublic backgroundImage: string | null,\n\t\tpublic gravity: Vector3,\n\t\tpublic variables: Record<string, any>,\n\t) { }\n}\n\n/**\n * Create default stage configuration.\n */\nexport function createDefaultStageConfig(): StageConfig {\n\treturn new StageConfig(\n\t\t{\n\t\t\tp1: ['gamepad-1', 'keyboard-1'],\n\t\t\tp2: ['gamepad-2', 'keyboard-2'],\n\t\t},\n\t\tZylemBlueColor,\n\t\tnull,\n\t\tnew Vector3(0, 0, 0),\n\t\t{},\n\t);\n}\n\n/**\n * Result of parsing stage options.\n */\nexport interface ParsedStageOptions {\n\tconfig: StageConfig;\n\tentities: BaseNode[];\n\tasyncEntities: Array<BaseNode | Promise<any> | (() => BaseNode | Promise<any>)>;\n\tcamera?: CameraWrapper;\n}\n\n/**\n * Parse stage options array and resolve configuration.\n * Separates config objects, camera wrappers, and entity inputs.\n * \n * @param options Stage options array\n * @returns Parsed stage options with resolved config, entities, and camera\n */\nexport function parseStageOptions(options: any[] = []): ParsedStageOptions {\n\tconst defaults = createDefaultStageConfig();\n\tlet config: Partial<StageConfig> = {};\n\tconst entities: BaseNode[] = [];\n\tconst asyncEntities: Array<BaseNode | Promise<any> | (() => BaseNode | Promise<any>)> = [];\n\tlet camera: CameraWrapper | undefined;\n\n\tfor (const item of options) {\n\t\tif (isCameraWrapper(item)) {\n\t\t\tcamera = item;\n\t\t} else if (isBaseNode(item)) {\n\t\t\tentities.push(item);\n\t\t} else if (isEntityInput(item) && !isBaseNode(item)) {\n\t\t\tasyncEntities.push(item);\n\t\t} else if (isConfigObject(item)) {\n\t\t\tconfig = { ...config, ...item };\n\t\t}\n\t}\n\n\t// Merge user config with defaults\n\tconst resolvedConfig = new StageConfig(\n\t\tconfig.inputs ?? defaults.inputs,\n\t\tconfig.backgroundColor ?? defaults.backgroundColor,\n\t\tconfig.backgroundImage ?? defaults.backgroundImage,\n\t\tconfig.gravity ?? defaults.gravity,\n\t\tconfig.variables ?? defaults.variables,\n\t);\n\n\treturn { config: resolvedConfig, entities, asyncEntities, camera };\n}\n\n/**\n * Factory for authoring stage configuration objects in user code.\n * Returns a plain object that can be passed to `createStage(...)`.\n */\nexport function stageConfig(config: StageConfigLike): StageConfigLike {\n\treturn { ...config };\n}\n","import { addComponent, addEntity, createWorld as createECS, removeEntity } from 'bitecs';\nimport { Color, Vector3, Vector2 } from 'three';\n\nimport { ZylemWorld } from '../collision/world';\nimport { ZylemScene } from '../graphics/zylem-scene';\nimport { resetStageVariables, setStageBackgroundColor, setStageBackgroundImage, setStageVariables, clearVariables } from './stage-state';\n\nimport { GameEntityInterface } from '../types/entity-types';\nimport { ZylemBlueColor } from '../core/utility/vector';\nimport { debugState } from '../debug/debug-state';\nimport { subscribe } from 'valtio/vanilla';\nimport { getGlobals } from \"../game/game-state\";\n\nimport { SetupContext, UpdateContext, DestroyContext } from '../core/base-node-life-cycle';\nimport { LifeCycleBase } from '../core/lifecycle-base';\nimport createTransformSystem, { StageSystem } from '../systems/transformable.system';\nimport { BaseNode } from '../core/base-node';\nimport { nanoid } from 'nanoid';\nimport { Stage } from './stage';\nimport { CameraWrapper } from '../camera/camera';\nimport { StageDebugDelegate } from './stage-debug-delegate';\nimport { StageCameraDebugDelegate } from './stage-camera-debug-delegate';\nimport { StageCameraDelegate } from './stage-camera-delegate';\nimport { StageLoadingDelegate } from './stage-loading-delegate';\nimport { GameEntity } from '../entities/entity';\nimport { BaseEntityInterface } from '../types/entity-types';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { LoadingEvent } from '../core/interfaces';\nimport { parseStageOptions } from './stage-config';\nimport { isBaseNode, isThenable } from '../core/utility/options-parser';\nexport type { LoadingEvent };\n\nexport interface ZylemStageConfig {\n\tinputs: Record<string, string[]>;\n\tbackgroundColor: Color | string;\n\tbackgroundImage: string | null;\n\tgravity: Vector3;\n\tvariables: Record<string, any>;\n\tstageRef?: Stage;\n}\n\ntype NodeLike = { create: Function };\nexport type StageEntityInput = NodeLike | Promise<any> | (() => NodeLike | Promise<any>);\n\nexport type StageOptionItem = Partial<ZylemStageConfig> | CameraWrapper | StageEntityInput;\nexport type StageOptions = [] | [Partial<ZylemStageConfig>, ...StageOptionItem[]];\n\nexport type StageState = ZylemStageConfig & { entities: GameEntityInterface[] };\n\nconst STAGE_TYPE = 'Stage';\n\n/**\n * ZylemStage orchestrates scene, physics world, entities, and lifecycle.\n *\n * Responsibilities:\n * - Manage stage configuration (background, inputs, gravity, variables)\n * - Initialize and own `ZylemScene` and `ZylemWorld`\n * - Spawn, track, and remove entities; emit entity-added events\n * - Drive per-frame updates and transform system\n */\nexport class ZylemStage extends LifeCycleBase<ZylemStage> {\n\tpublic type = STAGE_TYPE;\n\n\tstate: StageState = {\n\t\tbackgroundColor: ZylemBlueColor,\n\t\tbackgroundImage: null,\n\t\tinputs: {\n\t\t\tp1: ['gamepad-1', 'keyboard'],\n\t\t\tp2: ['gamepad-2', 'keyboard'],\n\t\t},\n\t\tgravity: new Vector3(0, 0, 0),\n\t\tvariables: {},\n\t\tentities: [],\n\t};\n\tgravity: Vector3;\n\n\tworld: ZylemWorld | null;\n\tscene: ZylemScene | null;\n\n\tchildren: Array<BaseNode> = [];\n\t_childrenMap: Map<number, BaseNode> = new Map();\n\t_removalMap: Map<number, BaseNode> = new Map();\n\n\tprivate pendingEntities: StageEntityInput[] = [];\n\tprivate pendingPromises: Promise<BaseNode>[] = [];\n\tprivate isLoaded: boolean = false;\n\n\t_debugMap: Map<string, BaseNode> = new Map();\n\n\tprivate entityAddedHandlers: Array<(entity: BaseNode) => void> = [];\n\n\tecs = createECS();\n\ttestSystem: any = null;\n\ttransformSystem: ReturnType<typeof createTransformSystem> | null = null;\n\tdebugDelegate: StageDebugDelegate | null = null;\n\tcameraDebugDelegate: StageCameraDebugDelegate | null = null;\n\tprivate debugStateUnsubscribe: (() => void) | null = null;\n\n\tuuid: string;\n\twrapperRef: Stage | null = null;\n\tcamera?: CameraWrapper;\n\tcameraRef?: ZylemCamera | null = null;\n\n\t// Delegates\n\tprivate cameraDelegate: StageCameraDelegate;\n\tprivate loadingDelegate: StageLoadingDelegate;\n\n\t/**\n\t * Create a new stage.\n\t * @param options Stage options: partial config, camera, and initial entities or factories\n\t */\n\tconstructor(options: StageOptions = []) {\n\t\tsuper();\n\t\tthis.world = null;\n\t\tthis.scene = null;\n\t\tthis.uuid = nanoid();\n\n\t\t// Initialize delegates\n\t\tthis.cameraDelegate = new StageCameraDelegate(this);\n\t\tthis.loadingDelegate = new StageLoadingDelegate();\n\n\t\t// Parse the options array using the stage-config module\n\t\tconst parsed = parseStageOptions(options);\n\t\tthis.camera = parsed.camera;\n\t\tthis.children = parsed.entities;\n\t\tthis.pendingEntities = parsed.asyncEntities;\n\t\t\n\t\t// Update state with resolved config\n\t\tthis.saveState({\n\t\t\t...this.state,\n\t\t\tinputs: parsed.config.inputs,\n\t\t\tbackgroundColor: parsed.config.backgroundColor,\n\t\t\tbackgroundImage: parsed.config.backgroundImage,\n\t\t\tgravity: parsed.config.gravity,\n\t\t\tvariables: parsed.config.variables,\n\t\t\tentities: [],\n\t\t});\n\n\t\tthis.gravity = parsed.config.gravity ?? new Vector3(0, 0, 0);\n\t}\n\n\tprivate handleEntityImmediatelyOrQueue(entity: BaseNode): void {\n\t\tif (this.isLoaded) {\n\t\t\tthis.spawnEntity(entity);\n\t\t} else {\n\t\t\tthis.children.push(entity);\n\t\t}\n\t}\n\n\tprivate handlePromiseWithSpawnOnResolve(promise: Promise<any>): void {\n\t\tif (this.isLoaded) {\n\t\t\tpromise\n\t\t\t\t.then((entity) => this.spawnEntity(entity))\n\t\t\t\t.catch((e) => console.error('Failed to build async entity', e));\n\t\t} else {\n\t\t\tthis.pendingPromises.push(promise as Promise<BaseNode>);\n\t\t}\n\t}\n\n\tprivate saveState(state: StageState) {\n\t\tthis.state = state;\n\t}\n\n\tprivate setState() {\n\t\tconst { backgroundColor, backgroundImage } = this.state;\n\t\tconst color = backgroundColor instanceof Color ? backgroundColor : new Color(backgroundColor);\n\t\tsetStageBackgroundColor(color);\n\t\tsetStageBackgroundImage(backgroundImage);\n\t\t// Initialize reactive stage variables on load\n\t\tsetStageVariables(this.state.variables ?? {});\n\t}\n\n\t/**\n\t * Load and initialize the stage's scene and world.\n\t * Uses generator pattern to yield control to event loop for real-time progress.\n\t * @param id DOM element id for the renderer container\n\t * @param camera Optional camera override\n\t */\n\tasync load(id: string, camera?: ZylemCamera | null) {\n\t\tthis.setState();\n\n\t\t// Use camera delegate to resolve camera\n\t\tconst zylemCamera = this.cameraDelegate.resolveCamera(camera, this.camera);\n\t\tthis.cameraRef = zylemCamera;\n\t\tthis.scene = new ZylemScene(id, zylemCamera, this.state);\n\n\t\tconst physicsWorld = await ZylemWorld.loadPhysics(this.gravity ?? new Vector3(0, 0, 0));\n\t\tthis.world = new ZylemWorld(physicsWorld);\n\n\t\tthis.scene.setup();\n\n\t\tthis.loadingDelegate.emitStart();\n\n\t\t// Run entity loading with generator pattern for real-time progress\n\t\tawait this.runEntityLoadGenerator();\n\n\t\tthis.transformSystem = createTransformSystem(this as unknown as StageSystem);\n\t\tthis.isLoaded = true;\n\t\tthis.loadingDelegate.emitComplete();\n\t}\n\n\t/**\n\t * Generator that yields between entity loads for real-time progress updates.\n\t */\n\tprivate *entityLoadGenerator(): Generator<{ current: number; total: number; name: string }> {\n\t\tconst total = this.children.length + this.pendingEntities.length + this.pendingPromises.length;\n\t\tlet current = 0;\n\n\t\tfor (const child of this.children) {\n\t\t\tthis.spawnEntity(child);\n\t\t\tcurrent++;\n\t\t\tyield { current, total, name: child.name || 'unknown' };\n\t\t}\n\n\t\tif (this.pendingEntities.length) {\n\t\t\tthis.enqueue(...this.pendingEntities);\n\t\t\tcurrent += this.pendingEntities.length;\n\t\t\tthis.pendingEntities = [];\n\t\t\tyield { current, total, name: 'pending entities' };\n\t\t}\n\n\t\tif (this.pendingPromises.length) {\n\t\t\tfor (const promise of this.pendingPromises) {\n\t\t\t\tpromise.then((entity) => {\n\t\t\t\t\tthis.spawnEntity(entity);\n\t\t\t\t}).catch((e) => console.error('Failed to resolve pending stage entity', e));\n\t\t\t}\n\t\t\tcurrent += this.pendingPromises.length;\n\t\t\tthis.pendingPromises = [];\n\t\t\tyield { current, total, name: 'async entities' };\n\t\t}\n\t}\n\n\t/**\n\t * Runs the entity load generator, yielding to the event loop between loads.\n\t * This allows the browser to process events and update the UI in real-time.\n\t */\n\tprivate async runEntityLoadGenerator(): Promise<void> {\n\t\tconst gen = this.entityLoadGenerator();\n\t\tfor (const progress of gen) {\n\t\t\tthis.loadingDelegate.emitProgress(`Loaded ${progress.name}`, progress.current, progress.total);\n\t\t\t// Yield to event loop so browser can process events and update UI\n\t\t\t// Use setTimeout(0) for more reliable async behavior than RAF\n\t\t\tawait new Promise<void>(resolve => setTimeout(resolve, 0));\n\t\t}\n\t}\n\n\n\tprotected _setup(params: SetupContext<ZylemStage>): void {\n\t\tif (!this.scene || !this.world) {\n\t\t\tthis.logMissingEntities();\n\t\t\treturn;\n\t\t}\n\t\t// Setup debug delegate based on current state\n\t\tthis.updateDebugDelegate();\n\n\t\t// Subscribe to debugState changes for runtime toggle\n\t\tthis.debugStateUnsubscribe = subscribe(debugState, () => {\n\t\t\tthis.updateDebugDelegate();\n\t\t});\n\t}\n\n\tprivate updateDebugDelegate(): void {\n\t\tif (debugState.enabled && !this.debugDelegate && this.scene && this.world) {\n\t\t\t// Create debug delegate when debug is enabled\n\t\t\tthis.debugDelegate = new StageDebugDelegate(this);\n\t\t\t\n\t\t\t// Create and attach camera debug delegate for orbit controls\n\t\t\tif (this.cameraRef && !this.cameraDebugDelegate) {\n\t\t\t\tthis.cameraDebugDelegate = new StageCameraDebugDelegate(this);\n\t\t\t\tthis.cameraRef.setDebugDelegate(this.cameraDebugDelegate);\n\t\t\t}\n\t\t} else if (!debugState.enabled && this.debugDelegate) {\n\t\t\t// Dispose debug delegate when debug is disabled\n\t\t\tthis.debugDelegate.dispose();\n\t\t\tthis.debugDelegate = null;\n\t\t\t\n\t\t\t// Detach camera debug delegate\n\t\t\tif (this.cameraRef) {\n\t\t\t\tthis.cameraRef.setDebugDelegate(null);\n\t\t\t}\n\t\t\tthis.cameraDebugDelegate = null;\n\t\t}\n\t}\n\n\tprotected _update(params: UpdateContext<ZylemStage>): void {\n\t\tconst { delta } = params;\n\t\tif (!this.scene || !this.world) {\n\t\t\tthis.logMissingEntities();\n\t\t\treturn;\n\t\t}\n\t\tthis.world.update(params);\n\t\tthis.transformSystem?.system(this.ecs);\n\t\tthis._childrenMap.forEach((child, eid) => {\n\t\t\tchild.nodeUpdate({\n\t\t\t\t...params,\n\t\t\t\tme: child,\n\t\t\t});\n\t\t\tif (child.markedForRemoval) {\n\t\t\t\tthis.removeEntityByUuid(child.uuid);\n\t\t\t}\n\t\t});\n\t\tthis.scene.update({ delta });\n\t}\n\n\tpublic outOfLoop() {\n\t\tthis.debugUpdate();\n\t}\n\n\t/** Update debug overlays and helpers if enabled. */\n\tpublic debugUpdate() {\n\t\tif (debugState.enabled) {\n\t\t\tthis.debugDelegate?.update();\n\t\t}\n\t}\n\n\t/** Cleanup owned resources when the stage is destroyed. */\n\tprotected _destroy(params: DestroyContext<ZylemStage>): void {\n\t\tthis._childrenMap.forEach((child) => {\n\t\t\ttry { child.nodeDestroy({ me: child, globals: getGlobals() }); } catch { /* noop */ }\n\t\t});\n\t\tthis._childrenMap.clear();\n\t\tthis._removalMap.clear();\n\t\tthis._debugMap.clear();\n\n\t\tthis.world?.destroy();\n\t\tthis.scene?.destroy();\n\n\t\t// Cleanup debug state subscription\n\t\tif (this.debugStateUnsubscribe) {\n\t\t\tthis.debugStateUnsubscribe();\n\t\t\tthis.debugStateUnsubscribe = null;\n\t\t}\n\n\t\tthis.debugDelegate?.dispose();\n\t\tthis.debugDelegate = null;\n\t\tthis.cameraRef?.setDebugDelegate(null);\n\t\tthis.cameraDebugDelegate = null;\n\n\t\tthis.isLoaded = false;\n\t\tthis.world = null as any;\n\t\tthis.scene = null as any;\n\t\tthis.cameraRef = null;\n\t\t// Cleanup transform system\n\t\tthis.transformSystem?.destroy(this.ecs);\n\t\tthis.transformSystem = null;\n\n\t\t// Clear reactive stage variables on unload\n\t\tresetStageVariables();\n\t\t// Clear object-scoped variables for this stage\n\t\tclearVariables(this);\n\t}\n\n\t/**\n\t * Create, register, and add an entity to the scene/world.\n\t * Safe to call only after `load` when scene/world exist.\n\t */\n\tasync spawnEntity(child: BaseNode) {\n\t\tif (!this.scene || !this.world) {\n\t\t\treturn;\n\t\t}\n\t\tconst entity = child.create();\n\t\tconst eid = addEntity(this.ecs);\n\t\tentity.eid = eid;\n\t\tthis.scene.addEntity(entity);\n\t\t// @ts-ignore\n\t\tif (child.behaviors) {\n\t\t\t// @ts-ignore\n\t\t\tfor (let behavior of child.behaviors) {\n\t\t\t\taddComponent(this.ecs, behavior.component, entity.eid);\n\t\t\t\tconst keys = Object.keys(behavior.values);\n\t\t\t\tfor (const key of keys) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tbehavior.component[key][entity.eid] = behavior.values[key];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (entity.colliderDesc) {\n\t\t\tthis.world.addEntity(entity);\n\t\t}\n\t\tchild.nodeSetup({\n\t\t\tme: child,\n\t\t\tglobals: getGlobals(),\n\t\t\tcamera: this.scene.zylemCamera,\n\t\t});\n\t\tthis.addEntityToStage(entity);\n\t}\n\n\tbuildEntityState(child: BaseNode): Partial<BaseEntityInterface> {\n\t\tif (child instanceof GameEntity) {\n\t\t\treturn { ...child.buildInfo() } as Partial<BaseEntityInterface>;\n\t\t}\n\t\treturn {\n\t\t\tuuid: child.uuid,\n\t\t\tname: child.name,\n\t\t\teid: child.eid,\n\t\t} as Partial<BaseEntityInterface>;\n\t}\n\n\t/** Add the entity to internal maps and notify listeners. */\n\taddEntityToStage(entity: BaseNode) {\n\t\tthis._childrenMap.set(entity.eid, entity);\n\t\tif (debugState.enabled) {\n\t\t\tthis._debugMap.set(entity.uuid, entity);\n\t\t}\n\t\tfor (const handler of this.entityAddedHandlers) {\n\t\t\ttry {\n\t\t\t\thandler(entity);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('onEntityAdded handler failed', e);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Subscribe to entity-added events.\n\t * @param callback Invoked for each entity when added\n\t * @param options.replayExisting If true and stage already loaded, replays existing entities\n\t * @returns Unsubscribe function\n\t */\n\tonEntityAdded(callback: (entity: BaseNode) => void, options?: { replayExisting?: boolean }) {\n\t\tthis.entityAddedHandlers.push(callback);\n\t\tif (options?.replayExisting && this.isLoaded) {\n\t\t\tthis._childrenMap.forEach((entity) => {\n\t\t\t\ttry { callback(entity); } catch (e) { console.error('onEntityAdded replay failed', e); }\n\t\t\t});\n\t\t}\n\t\treturn () => {\n\t\t\tthis.entityAddedHandlers = this.entityAddedHandlers.filter((h) => h !== callback);\n\t\t};\n\t}\n\n\tonLoading(callback: (event: LoadingEvent) => void) {\n\t\treturn this.loadingDelegate.onLoading(callback);\n\t}\n\n\t/**\n\t * Remove an entity and its resources by its UUID.\n\t * @returns true if removed, false if not found or stage not ready\n\t */\n\tremoveEntityByUuid(uuid: string): boolean {\n\t\tif (!this.scene || !this.world) return false;\n\t\t// Try mapping via world collision map first for physics-backed entities\n\t\t// @ts-ignore - collisionMap is public Map<string, GameEntity<any>>\n\t\tconst mapEntity = this.world.collisionMap.get(uuid) as any | undefined;\n\t\tconst entity: any = mapEntity ?? this._debugMap.get(uuid);\n\t\tif (!entity) return false;\n\n\t\tthis.world.destroyEntity(entity);\n\n\t\tif (entity.group) {\n\t\t\tthis.scene.scene.remove(entity.group);\n\t\t} else if (entity.mesh) {\n\t\t\tthis.scene.scene.remove(entity.mesh);\n\t\t}\n\n\t\tremoveEntity(this.ecs, entity.eid);\n\n\t\tlet foundKey: number | null = null;\n\t\tthis._childrenMap.forEach((value, key) => {\n\t\t\tif ((value as any).uuid === uuid) {\n\t\t\t\tfoundKey = key;\n\t\t\t}\n\t\t});\n\t\tif (foundKey !== null) {\n\t\t\tthis._childrenMap.delete(foundKey);\n\t\t}\n\t\tthis._debugMap.delete(uuid);\n\t\treturn true;\n\t}\n\n\t/** Get an entity by its name; returns null if not found. */\n\tgetEntityByName(name: string) {\n\t\tconst arr = Object.entries(Object.fromEntries(this._childrenMap)).map((entry) => entry[1]);\n\t\tconst entity = arr.find((child) => child.name === name);\n\t\tif (!entity) {\n\t\t\tconsole.warn(`Entity ${name} not found`);\n\t\t}\n\t\treturn entity ?? null;\n\t}\n\n\tlogMissingEntities() {\n\t\tconsole.warn('Zylem world or scene is null');\n\t}\n\n\t/** Resize renderer viewport. */\n\tresize(width: number, height: number) {\n\t\tif (this.scene) {\n\t\t\tthis.scene.updateRenderer(width, height);\n\t\t}\n\t}\n\n\t/**\n\t * Enqueue items to be spawned. Items can be:\n\t * - BaseNode instances (immediate or deferred until load)\n\t * - Factory functions returning BaseNode or Promise<BaseNode>\n\t * - Promises resolving to BaseNode\n\t */\n\tenqueue(...items: StageEntityInput[]) {\n\t\tfor (const item of items) {\n\t\t\tif (!item) continue;\n\t\t\tif (isBaseNode(item)) {\n\t\t\t\tthis.handleEntityImmediatelyOrQueue(item);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (typeof item === 'function') {\n\t\t\t\ttry {\n\t\t\t\t\tconst result = (item as (() => BaseNode | Promise<any>))();\n\t\t\t\t\tif (isBaseNode(result)) {\n\t\t\t\t\t\tthis.handleEntityImmediatelyOrQueue(result);\n\t\t\t\t\t} else if (isThenable(result)) {\n\t\t\t\t\t\tthis.handlePromiseWithSpawnOnResolve(result as Promise<any>);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error('Error executing entity factory', error);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isThenable(item)) {\n\t\t\t\tthis.handlePromiseWithSpawnOnResolve(item as Promise<any>);\n\t\t\t}\n\t\t}\n\t}\n}\n","import { Vector2, Vector3 } from \"three\";\nimport { PerspectiveType } from \"./perspective\";\nimport { ZylemCamera } from \"./zylem-camera\";\n\nexport interface CameraOptions {\n\tperspective?: PerspectiveType;\n\tposition?: Vector3;\n\ttarget?: Vector3;\n\tzoom?: number;\n\tscreenResolution?: Vector2;\n}\n\nexport class CameraWrapper {\n\tcameraRef: ZylemCamera;\n\n\tconstructor(camera: ZylemCamera) {\n\t\tthis.cameraRef = camera;\n\t}\n}\n\nexport function camera(options: CameraOptions): CameraWrapper {\n\tconst screenResolution = options.screenResolution || new Vector2(window.innerWidth, window.innerHeight);\n\tlet frustumSize = 10;\n\tif (options.perspective === 'fixed-2d') {\n\t\tfrustumSize = options.zoom || 10;\n\t}\n\tconst zylemCamera = new ZylemCamera(options.perspective || 'third-person', screenResolution, frustumSize);\n\n\t// Set initial position and target\n\tzylemCamera.move(options.position || new Vector3(0, 0, 0));\n\tzylemCamera.camera.lookAt(options.target || new Vector3(0, 0, 0));\n\n\treturn new CameraWrapper(zylemCamera);\n}","import { proxy } from 'valtio/vanilla';\nimport { Vector3 } from 'three';\nimport type { StageOptions, ZylemStageConfig } from './zylem-stage';\nimport { ZylemBlueColor } from '../core/utility/vector';\n\n/**\n * Reactive defaults for building `Stage` instances. These values are applied\n * automatically by the `stage()` builder and can be changed at runtime to\n * influence future stage creations.\n */\nconst initialDefaults: Partial<ZylemStageConfig> = {\n\tbackgroundColor: ZylemBlueColor,\n\tbackgroundImage: null,\n\tinputs: {\n\t\tp1: ['gamepad-1', 'keyboard'],\n\t\tp2: ['gamepad-2', 'keyboard'],\n\t},\n\tgravity: new Vector3(0, 0, 0),\n\tvariables: {},\n};\n\nconst stageDefaultsState = proxy<Partial<ZylemStageConfig>>({\n\t...initialDefaults,\n});\n\n/** Replace multiple defaults at once (shallow merge). */\nfunction setStageDefaults(partial: Partial<ZylemStageConfig>): void {\n\tObject.assign(stageDefaultsState, partial);\n}\n\n/** Reset defaults back to library defaults. */\nfunction resetStageDefaults(): void {\n\tObject.assign(stageDefaultsState, initialDefaults);\n}\n\nexport function getStageOptions(options: StageOptions): StageOptions {\n\tconst defaults = getStageDefaultConfig();\n\tlet originalConfig = {};\n\tif (typeof options[0] === 'object') {\n\t\toriginalConfig = options.shift() ?? {};\n\t}\n\tconst combinedConfig = { ...defaults, ...originalConfig };\n\treturn [combinedConfig, ...options] as StageOptions;\n}\n\n/** Get a plain object copy of the current defaults. */\nfunction getStageDefaultConfig(): Partial<ZylemStageConfig> {\n\treturn {\n\t\tbackgroundColor: stageDefaultsState.backgroundColor,\n\t\tbackgroundImage: stageDefaultsState.backgroundImage ?? null,\n\t\tinputs: stageDefaultsState.inputs ? { ...stageDefaultsState.inputs } : undefined,\n\t\tgravity: stageDefaultsState.gravity,\n\t\tvariables: stageDefaultsState.variables ? { ...stageDefaultsState.variables } : undefined,\n\t};\n}\n\n\n","import { BaseNode } from '../core/base-node';\nimport { DestroyFunction, SetupContext, SetupFunction, UpdateFunction } from '../core/base-node-life-cycle';\nimport { LoadingEvent, StageOptionItem, StageOptions, ZylemStage } from './zylem-stage';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { CameraWrapper } from '../camera/camera';\nimport { stageState } from './stage-state';\nimport { getStageOptions } from './stage-default';\nimport { EntityTypeMap } from '../types/entity-type-map';\n\ntype NodeLike = { create: Function };\ntype AnyNode = NodeLike | Promise<NodeLike>;\ntype EntityInput = AnyNode | (() => AnyNode) | (() => Promise<any>);\n\nexport class Stage {\n\twrappedStage: ZylemStage | null;\n\toptions: StageOptionItem[] = [];\n\t// Entities added after construction, consumed on each load\n\tprivate _pendingEntities: BaseNode[] = [];\n\n\t// Lifecycle callback arrays\n\tprivate setupCallbacks: Array<SetupFunction<ZylemStage>> = [];\n\tprivate updateCallbacks: Array<UpdateFunction<ZylemStage>> = [];\n\tprivate destroyCallbacks: Array<DestroyFunction<ZylemStage>> = [];\n\tprivate pendingLoadingCallbacks: Array<(event: LoadingEvent) => void> = [];\n\n\tconstructor(options: StageOptions) {\n\t\tthis.options = options;\n\t\tthis.wrappedStage = null;\n\t}\n\n\tasync load(id: string, camera?: ZylemCamera | CameraWrapper | null) {\n\t\tstageState.entities = [];\n\t\t// Combine original options with pending entities, then clear pending\n\t\tconst loadOptions = [...this.options, ...this._pendingEntities] as StageOptions;\n\t\tthis._pendingEntities = [];\n\t\t\n\t\tthis.wrappedStage = new ZylemStage(loadOptions);\n\t\tthis.wrappedStage.wrapperRef = this;\n\n\t\t// Flush pending loading callbacks BEFORE load so we catch start/progress events\n\t\tthis.pendingLoadingCallbacks.forEach(cb => {\n\t\t\tthis.wrappedStage!.onLoading(cb);\n\t\t});\n\t\tthis.pendingLoadingCallbacks = [];\n\n\t\tconst zylemCamera = camera instanceof CameraWrapper ? camera.cameraRef : camera;\n\t\tawait this.wrappedStage!.load(id, zylemCamera);\n\n\t\tthis.wrappedStage!.onEntityAdded((child) => {\n\t\t\tconst next = this.wrappedStage!.buildEntityState(child);\n\t\t\tstageState.entities = [...stageState.entities, next];\n\t\t}, { replayExisting: true });\n\n\t\t// Apply lifecycle callbacks to wrapped stage\n\t\tthis.applyLifecycleCallbacks();\n\n\t}\n\n\tprivate applyLifecycleCallbacks() {\n\t\tif (!this.wrappedStage) return;\n\n\t\t// Compose setup callbacks into a single function\n\t\tif (this.setupCallbacks.length > 0) {\n\t\t\tthis.wrappedStage.setup = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.setupCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\n\t\t// Compose update callbacks\n\t\tif (this.updateCallbacks.length > 0) {\n\t\t\tthis.wrappedStage.update = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.updateCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\n\t\t// Compose destroy callbacks\n\t\tif (this.destroyCallbacks.length > 0) {\n\t\t\tthis.wrappedStage.destroy = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.destroyCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\t}\n\n\tasync addEntities(entities: BaseNode[]) {\n\t\t// Store in pending, don't mutate options\n\t\tthis._pendingEntities.push(...entities);\n\t\tif (!this.wrappedStage) { return; }\n\t\tthis.wrappedStage!.enqueue(...entities);\n\t}\n\n\tadd(...inputs: Array<EntityInput>) {\n\t\tthis.addToBlueprints(...inputs);\n\t\tthis.addToStage(...inputs);\n\t}\n\n\tprivate addToBlueprints(...inputs: Array<EntityInput>) {\n\t\tif (this.wrappedStage) { return; }\n\t\t// Add to options (persistent) so they're available on reload\n\t\tthis.options.push(...(inputs as unknown as StageOptionItem[]));\n\t}\n\n\tprivate addToStage(...inputs: Array<EntityInput>) {\n\t\tif (!this.wrappedStage) { return; }\n\t\tthis.wrappedStage!.enqueue(...(inputs as any));\n\t}\n\n\tstart(params: SetupContext<ZylemStage>) {\n\t\tthis.wrappedStage?.nodeSetup(params);\n\t}\n\n\t// Fluent API for adding lifecycle callbacks\n\tonUpdate(...callbacks: UpdateFunction<ZylemStage>[]): this {\n\t\tthis.updateCallbacks.push(...callbacks);\n\t\t// If already loaded, recompose the update callback\n\t\tif (this.wrappedStage) {\n\t\t\tthis.wrappedStage.update = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.updateCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\t\treturn this;\n\t}\n\n\tonSetup(...callbacks: SetupFunction<ZylemStage>[]): this {\n\t\tthis.setupCallbacks.push(...callbacks);\n\t\t// If already loaded, recompose the setup callback\n\t\tif (this.wrappedStage) {\n\t\t\tthis.wrappedStage.setup = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.setupCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\t\treturn this;\n\t}\n\n\tonDestroy(...callbacks: DestroyFunction<ZylemStage>[]): this {\n\t\tthis.destroyCallbacks.push(...callbacks);\n\t\t// If already loaded, recompose the destroy callback\n\t\tif (this.wrappedStage) {\n\t\t\tthis.wrappedStage.destroy = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.destroyCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\t\treturn this;\n\t}\n\n\tonLoading(callback: (event: LoadingEvent) => void) {\n\t\tif (!this.wrappedStage) { \n\t\t\tthis.pendingLoadingCallbacks.push(callback);\n\t\t\treturn () => {\n\t\t\t\tthis.pendingLoadingCallbacks = this.pendingLoadingCallbacks.filter(c => c !== callback);\n\t\t\t};\n\t\t}\n\t\treturn this.wrappedStage.onLoading(callback);\n\t}\n\n\t/**\n\t * Find an entity by name on the current stage.\n\t * @param name The name of the entity to find\n\t * @param type Optional type symbol for type inference (e.g., TEXT_TYPE, SPRITE_TYPE)\n\t * @returns The entity if found, or undefined\n\t * @example stage.getEntityByName('scoreText', TEXT_TYPE)\n\t */\n\tgetEntityByName<T extends symbol | void = void>(\n\t\tname: string,\n\t\ttype?: T\n\t): T extends keyof EntityTypeMap ? EntityTypeMap[T] | undefined : BaseNode | undefined {\n\t\tconst entity = this.wrappedStage?.children.find(c => c.name === name);\n\t\treturn entity as any;\n\t}\n}\n\n/**\n * Create a stage with optional camera\n */\nexport function createStage(...options: StageOptions): Stage {\n\tconst _options = getStageOptions(options);\n\treturn new Stage([..._options] as StageOptions);\n}","import { proxy } from 'valtio/vanilla';\nimport { createStage, Stage } from '../stage/stage';\nimport type { BasicTypes, BaseGlobals, ZylemGameConfig, GameInputConfig } from './game-interfaces';\n\ntype InitialDefaults = Partial<ZylemGameConfig<Stage, any, BaseGlobals>>;\n/**\n * Reactive defaults for building `Game` instances. These values are applied\n * automatically by the `game()` builder via `convertNodes` and can be changed\n * at runtime to influence future game creations.\n */\nconst initialDefaults: () => InitialDefaults = (): InitialDefaults => {\n\treturn {\n\t\tid: 'zylem',\n\t\tglobals: {} as BaseGlobals,\n\t\tstages: [createStage()],\n\t\tdebug: false,\n\t\ttime: 0,\n\t\tinput: undefined,\n\t};\n}\n\nconst gameDefaultsState = proxy<Partial<ZylemGameConfig<Stage, any, BaseGlobals>>>(\n\t{ ...initialDefaults() }\n);\n\n/**\n * Get a plain object copy of the current defaults.\n */\nexport function getGameDefaultConfig<TGlobals extends Record<string, BasicTypes> = BaseGlobals>(): {\n\tid: string;\n\tglobals: TGlobals;\n\tstages: Stage[];\n\tdebug?: boolean;\n\ttime?: number;\n\tinput?: GameInputConfig;\n} {\n\treturn {\n\t\tid: (gameDefaultsState.id as string) ?? 'zylem',\n\t\tglobals: (gameDefaultsState.globals as TGlobals) ?? ({} as unknown as TGlobals),\n\t\tstages: (gameDefaultsState.stages as Stage[]) ?? [createStage()],\n\t\tdebug: gameDefaultsState.debug,\n\t\ttime: gameDefaultsState.time,\n\t\tinput: gameDefaultsState.input,\n\t};\n}\n\n\n","import { state, setGlobal, getGlobals, initGlobals, resetGlobals } from './game-state';\n\nimport { debugState, isPaused, setDebugFlag } from '../debug/debug-state';\n\nimport { Game } from './game';\nimport { UpdateContext, SetupContext, DestroyContext } from '../core/base-node-life-cycle';\nimport { InputManager } from '../input/input-manager';\nimport { Timer } from '../core/three-addons/Timer';\nimport { ZylemCamera } from '~/lib/camera/zylem-camera';\nimport { Stage } from '../stage/stage';\nimport { BaseGlobals, ZylemGameConfig } from './game-interfaces';\nimport { GameConfig, resolveGameConfig } from './game-config';\nimport { AspectRatioDelegate } from '../device/aspect-ratio';\nimport { GameCanvas } from './game-canvas';\nimport { GameDebugDelegate } from './game-debug-delegate';\nimport { GameLoadingDelegate, GameLoadingEvent, GAME_LOADING_EVENT } from './game-loading-delegate';\nimport { gameEventBus, StageLoadingPayload, GameStateUpdatedPayload } from './game-event-bus';\nimport { GameRendererObserver } from './game-renderer-observer';\nimport { ZylemStage } from '../core';\n\nexport type { GameLoadingEvent };\n\n/** Window event name for state dispatch events. */\nexport const ZYLEM_STATE_DISPATCH = 'zylem:state:dispatch';\n\n/** State dispatch event detail structure. */\nexport interface StateDispatchEvent {\n\tscope: 'game' | 'stage' | 'entity';\n\tpath: string;\n\tvalue: unknown;\n\tpreviousValue?: unknown;\n}\n\ntype ZylemGameOptions<TGlobals extends BaseGlobals> = ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals> & Partial<GameConfig>\n\nexport class ZylemGame<TGlobals extends BaseGlobals> {\n\tid: string;\n\tinitialGlobals = {} as TGlobals;\n\n\tcustomSetup: ((params: SetupContext<ZylemGame<TGlobals>, TGlobals>) => void) | null = null;\n\tcustomUpdate: ((params: UpdateContext<ZylemGame<TGlobals>, TGlobals>) => void) | null = null;\n\tcustomDestroy: ((params: DestroyContext<ZylemGame<TGlobals>, TGlobals>) => void) | null = null;\n\n\tstages: Stage[] = [];\n\tstageMap: Map<string, Stage> = new Map();\n\tcurrentStageId = '';\n\n\tpreviousTimeStamp: number = 0;\n\ttotalTime = 0;\n\n\ttimer: Timer;\n\tinputManager: InputManager;\n\n\twrapperRef: Game<TGlobals>;\n\tdefaultCamera: ZylemCamera | null = null;\n\tcontainer: HTMLElement | null = null;\n\tcanvas: HTMLCanvasElement | null = null;\n\taspectRatioDelegate: AspectRatioDelegate | null = null;\n\tresolvedConfig: GameConfig | null = null;\n\tgameCanvas: GameCanvas | null = null;\n\tprivate animationFrameId: number | null = null;\n\tprivate isDisposed = false;\n\tprivate debugDelegate: GameDebugDelegate | null = null;\n\tprivate loadingDelegate: GameLoadingDelegate = new GameLoadingDelegate();\n\tprivate rendererObserver: GameRendererObserver = new GameRendererObserver();\n\tprivate eventBusUnsubscribes: (() => void)[] = [];\n\n\tstatic FRAME_LIMIT = 120;\n\tstatic FRAME_DURATION = 1000 / ZylemGame.FRAME_LIMIT;\n\tstatic MAX_DELTA_SECONDS = 1 / 30;\n\n\tconstructor(options: ZylemGameOptions<TGlobals>, wrapperRef: Game<TGlobals>) {\n\t\tthis.wrapperRef = wrapperRef;\n\t\tthis.inputManager = new InputManager(options.input);\n\t\tthis.timer = new Timer();\n\t\tthis.timer.connect(document);\n\t\tconst config = resolveGameConfig(options as any);\n\t\tthis.id = config.id;\n\t\tthis.stages = (config.stages as any) || [];\n\t\tthis.container = config.container;\n\t\tthis.canvas = config.canvas ?? null;\n\t\tthis.resolvedConfig = config;\n\t\tthis.loadGameCanvas(config);\n\t\tthis.loadDebugOptions(options);\n\t\tthis.setGlobals(options);\n\t}\n\n\tloadGameCanvas(config: GameConfig) {\n\t\tthis.gameCanvas = new GameCanvas({\n\t\t\tid: config.id,\n\t\t\tcontainer: config.container,\n\t\t\tcontainerId: config.containerId,\n\t\t\tcanvas: this.canvas ?? undefined,\n\t\t\tbodyBackground: config.bodyBackground,\n\t\t\tfullscreen: config.fullscreen,\n\t\t\taspectRatio: config.aspectRatio,\n\t\t});\n\t\tthis.gameCanvas.applyBodyBackground();\n\t\tthis.gameCanvas.mountCanvas();\n\t\tthis.gameCanvas.centerIfFullscreen();\n\t\t\n\t\t// Setup renderer observer\n\t\tthis.rendererObserver.setGameCanvas(this.gameCanvas);\n\t\tif (this.resolvedConfig) {\n\t\t\tthis.rendererObserver.setConfig(this.resolvedConfig);\n\t\t}\n\t\tif (this.container) {\n\t\t\tthis.rendererObserver.setContainer(this.container);\n\t\t}\n\t\t\n\t\t// Subscribe to event bus for stage loading events\n\t\tthis.subscribeToEventBus();\n\t}\n\n\tloadDebugOptions(options: ZylemGameOptions<TGlobals>) {\n\t\tif (options.debug !== undefined) {\n\t\t\tdebugState.enabled = Boolean(options.debug);\n\t\t}\n\t\tthis.debugDelegate = new GameDebugDelegate();\n\t}\n\n\tloadStage(stage: Stage, stageIndex: number = 0): Promise<void> {\n\t\tthis.unloadCurrentStage();\n\t\tconst config = stage.options[0] as any;\n\t\t\n\t\t// Subscribe to stage loading events via delegate\n\t\tthis.loadingDelegate.wireStageLoading(stage, stageIndex);\n\n\t\t// Start stage loading and return promise for backward compatibility\n\t\treturn stage.load(this.id, config?.camera as ZylemCamera | null).then(() => {\n\t\t\tthis.stageMap.set(stage.wrappedStage!.uuid, stage);\n\t\t\tthis.currentStageId = stage.wrappedStage!.uuid;\n\t\t\tthis.defaultCamera = stage.wrappedStage!.cameraRef!;\n\t\t\t\n\t\t\t// Trigger renderer observer with new camera\n\t\t\tif (this.defaultCamera) {\n\t\t\t\tthis.rendererObserver.setCamera(this.defaultCamera);\n\t\t\t}\n\t\t});\n\t}\n\n\tunloadCurrentStage() {\n\t\tif (!this.currentStageId) return;\n\t\tconst current = this.getStage(this.currentStageId);\n\t\tif (!current) return;\n\t\t\n\t\tif (current?.wrappedStage) {\n\t\t\ttry {\n\t\t\t\tcurrent.wrappedStage.nodeDestroy({\n\t\t\t\t\tme: current.wrappedStage,\n\t\t\t\t\tglobals: state.globals as unknown as TGlobals,\n\t\t\t\t});\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('Failed to destroy previous stage', e);\n\t\t\t}\n\t\t\t// Clear the Stage wrapper's reference to the destroyed stage\n\t\t\tcurrent.wrappedStage = null;\n\t\t}\n\t\t\n\t\t// Remove from stage map\n\t\tthis.stageMap.delete(this.currentStageId);\n\t\t\n\t\t// Reset game state\n\t\tthis.currentStageId = '';\n\t\tthis.defaultCamera = null;\n\t\t\n\t\t// Reset renderer observer for stage transitions\n\t\tthis.rendererObserver.reset();\n\t}\n\n\tsetGlobals(options: ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals>) {\n\t\tthis.initialGlobals = { ...(options.globals as TGlobals) };\n\t\tfor (const variable in this.initialGlobals) {\n\t\t\tconst value = this.initialGlobals[variable];\n\t\t\tif (value === undefined) {\n\t\t\t\tconsole.error(`global ${variable} is undefined`);\n\t\t\t}\n\t\t\tsetGlobal(variable, value);\n\t\t}\n\t}\n\n\tparams(): UpdateContext<ZylemGame<TGlobals>, TGlobals> {\n\t\tconst stage = this.currentStage();\n\t\tconst delta = this.timer.getDelta();\n\t\tconst inputs = this.inputManager.getInputs(delta);\n\t\tconst camera = stage?.wrappedStage?.cameraRef || this.defaultCamera;\n\t\treturn {\n\t\t\tdelta,\n\t\t\tinputs,\n\t\t\tglobals: getGlobals<TGlobals>(),\n\t\t\tme: this,\n\t\t\tcamera: camera!,\n\t\t};\n\t}\n\n\tstart() {\n\t\tconst stage = this.currentStage();\n\t\tconst params = this.params();\n\t\tstage!.start({ ...params, me: stage!.wrappedStage as ZylemStage });\n\t\tif (this.customSetup) {\n\t\t\tthis.customSetup(params);\n\t\t}\n\t\tthis.loop(0);\n\t}\n\n\tloop(timestamp: number) {\n\t\tthis.debugDelegate?.begin();\n\t\tif (!isPaused()) {\n\t\t\tthis.timer.update(timestamp);\n\t\t\tconst stage = this.currentStage();\n\t\t\tconst params = this.params();\n\t\t\tconst clampedDelta = Math.min(Math.max(params.delta, 0), ZylemGame.MAX_DELTA_SECONDS);\n\t\t\tconst clampedParams = { ...params, delta: clampedDelta };\n\t\t\tif (this.customUpdate) {\n\t\t\t\tthis.customUpdate(clampedParams);\n\t\t\t}\n\t\t\tif (stage && stage.wrappedStage) {\n\t\t\t\tstage.wrappedStage!.nodeUpdate({ ...clampedParams, me: stage!.wrappedStage as ZylemStage });\n\t\t\t}\n\t\t\tthis.totalTime += clampedParams.delta;\n\t\t\tstate.time = this.totalTime;\n\t\t\tthis.previousTimeStamp = timestamp;\n\t\t}\n\t\tthis.debugDelegate?.end();\n\t\tthis.outOfLoop();\n\t\tif (!this.isDisposed) {\n\t\t\tthis.animationFrameId = requestAnimationFrame(this.loop.bind(this));\n\t\t}\n\t}\n\n\tdispose() {\n\t\tthis.isDisposed = true;\n\t\tif (this.animationFrameId !== null) {\n\t\t\tcancelAnimationFrame(this.animationFrameId);\n\t\t\tthis.animationFrameId = null;\n\t\t}\n\n\t\tthis.unloadCurrentStage();\n\n\t\t// Cleanup debug delegate\n\t\tif (this.debugDelegate) {\n\t\t\tthis.debugDelegate.dispose();\n\t\t\tthis.debugDelegate = null;\n\t\t}\n\n\t\t// Cleanup event bus subscriptions\n\t\tthis.eventBusUnsubscribes.forEach(unsub => unsub());\n\t\tthis.eventBusUnsubscribes = [];\n\n\t\t// Cleanup renderer observer\n\t\tthis.rendererObserver.dispose();\n\n\t\tthis.timer.dispose();\n\n\t\tif (this.customDestroy) {\n\t\t\tthis.customDestroy({\n\t\t\t\tme: this,\n\t\t\t\tglobals: state.globals as unknown as TGlobals\n\t\t\t});\n\t\t}\n\n\t\t// Clear global state\n\t\tresetGlobals();\n\t}\n\n\toutOfLoop() {\n\t\tconst currentStage = this.currentStage();\n\t\tif (!currentStage) return;\n\t\tcurrentStage.wrappedStage!.outOfLoop();\n\t}\n\n\tgetStage(id: string) {\n\t\treturn this.stageMap.get(id);\n\t}\n\n\tcurrentStage() {\n\t\treturn this.getStage(this.currentStageId);\n\t}\n\n\t/**\n\t * Subscribe to loading events from the game.\n\t * Events include stage context (stageName, stageIndex).\n\t * @param callback Invoked for each loading event\n\t * @returns Unsubscribe function\n\t */\n\tonLoading(callback: (event: GameLoadingEvent) => void): () => void {\n\t\treturn this.loadingDelegate.onLoading(callback);\n\t}\n\n\t/**\n\t * Subscribe to the game event bus for stage loading and state events.\n\t * Emits window events for cross-application communication.\n\t */\n\tprivate subscribeToEventBus(): void {\n\t\tconst emitLoadingWindowEvent = (payload: StageLoadingPayload) => {\n\t\t\tif (typeof window !== 'undefined') {\n\t\t\t\tconst event: GameLoadingEvent = {\n\t\t\t\t\ttype: payload.type,\n\t\t\t\t\tmessage: payload.message ?? '',\n\t\t\t\t\tprogress: payload.progress ?? 0,\n\t\t\t\t\tcurrent: payload.current,\n\t\t\t\t\ttotal: payload.total,\n\t\t\t\t\tstageName: payload.stageName,\n\t\t\t\t\tstageIndex: payload.stageIndex,\n\t\t\t\t};\n\t\t\t\twindow.dispatchEvent(new CustomEvent(GAME_LOADING_EVENT, { detail: event }));\n\t\t\t}\n\t\t};\n\n\t\tconst emitStateDispatchEvent = (payload: GameStateUpdatedPayload) => {\n\t\t\tif (typeof window !== 'undefined') {\n\t\t\t\tconst detail: StateDispatchEvent = {\n\t\t\t\t\tscope: 'game',\n\t\t\t\t\tpath: payload.path,\n\t\t\t\t\tvalue: payload.value,\n\t\t\t\t\tpreviousValue: payload.previousValue,\n\t\t\t\t};\n\t\t\t\twindow.dispatchEvent(new CustomEvent(ZYLEM_STATE_DISPATCH, { detail }));\n\t\t\t}\n\t\t};\n\n\t\tthis.eventBusUnsubscribes.push(\n\t\t\tgameEventBus.on('stage:loading:start', emitLoadingWindowEvent),\n\t\t\tgameEventBus.on('stage:loading:progress', emitLoadingWindowEvent),\n\t\t\tgameEventBus.on('stage:loading:complete', emitLoadingWindowEvent),\n\t\t\tgameEventBus.on('game:state:updated', emitStateDispatchEvent),\n\t\t);\n\t}\n}\n\n","import { InputProvider } from './input-provider';\nimport { AnalogState, ButtonState, InputGamepad } from './input';\n\nexport class KeyboardProvider implements InputProvider {\n\tprivate keyStates = new Map<string, boolean>();\n\tprivate keyButtonStates = new Map<string, ButtonState>();\n\tprivate mapping: Record<string, string[]> | null = null;\n\tprivate includeDefaultBase: boolean = true;\n\n\tconstructor(mapping?: Record<string, string[]>, options?: { includeDefaultBase?: boolean }) {\n\t\tthis.mapping = mapping ?? null;\n\t\tthis.includeDefaultBase = options?.includeDefaultBase ?? true;\n\t\twindow.addEventListener('keydown', ({ key }) => this.keyStates.set(key, true));\n\t\twindow.addEventListener('keyup', ({ key }) => this.keyStates.set(key, false));\n\t}\n\n\tprivate isKeyPressed(key: string): boolean {\n\t\treturn this.keyStates.get(key) || false;\n\t}\n\n\tprivate handleButtonState(key: string, delta: number): ButtonState {\n\t\tlet buttonState = this.keyButtonStates.get(key);\n\t\tconst isPressed = this.isKeyPressed(key);\n\n\t\tif (!buttonState) {\n\t\t\tbuttonState = { pressed: false, released: false, held: 0 };\n\t\t\tthis.keyButtonStates.set(key, buttonState);\n\t\t}\n\n\t\tif (isPressed) {\n\t\t\tif (buttonState.held === 0) {\n\t\t\t\tbuttonState.pressed = true;\n\t\t\t} else {\n\t\t\t\tbuttonState.pressed = false;\n\t\t\t}\n\t\t\tbuttonState.held += delta;\n\t\t\tbuttonState.released = false;\n\t\t} else {\n\t\t\tif (buttonState.held > 0) {\n\t\t\t\tbuttonState.released = true;\n\t\t\t\tbuttonState.held = 0;\n\t\t\t} else {\n\t\t\t\tbuttonState.released = false;\n\t\t\t}\n\t\t\tbuttonState.pressed = false;\n\t\t}\n\n\t\treturn buttonState;\n\t}\n\n\tprivate handleAnalogState(negativeKey: string, positiveKey: string, delta: number): AnalogState {\n\t\tconst value = this.getAxisValue(negativeKey, positiveKey);\n\t\treturn { value, held: delta };\n\t}\n\n\tprivate mergeButtonState(a: ButtonState | undefined, b: ButtonState | undefined): ButtonState {\n\t\treturn {\n\t\t\tpressed: a?.pressed || b?.pressed || false,\n\t\t\treleased: a?.released || b?.released || false,\n\t\t\theld: (a?.held || 0) + (b?.held || 0),\n\t\t};\n\t}\n\n\tprivate applyCustomMapping(input: Partial<InputGamepad>, delta: number): Partial<InputGamepad> {\n\t\tif (!this.mapping) return input;\n\t\tfor (const [key, targets] of Object.entries(this.mapping)) {\n\t\t\tif (!targets || targets.length === 0) continue;\n\t\t\tconst state = this.handleButtonState(key, delta);\n\t\t\tfor (const target of targets) {\n\t\t\t\tconst [rawCategory, rawName] = (target || '').split('.');\n\t\t\t\tif (!rawCategory || !rawName) continue;\n\t\t\t\tconst category = rawCategory.toLowerCase();\n\t\t\t\tconst nameKey = rawName.toLowerCase();\n\t\t\t\tif (category === 'buttons') {\n\t\t\t\t\tconst map: Record<string, keyof InputGamepad['buttons']> = {\n\t\t\t\t\t\t'a': 'A', 'b': 'B', 'x': 'X', 'y': 'Y',\n\t\t\t\t\t\t'start': 'Start', 'select': 'Select',\n\t\t\t\t\t\t'l': 'L', 'r': 'R',\n\t\t\t\t\t};\n\t\t\t\t\tconst prop = map[nameKey];\n\t\t\t\t\tif (!prop) continue;\n\t\t\t\t\tconst nextButtons = (input.buttons || {} as any);\n\t\t\t\t\tnextButtons[prop] = this.mergeButtonState(nextButtons[prop], state);\n\t\t\t\t\tinput.buttons = nextButtons;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (category === 'directions') {\n\t\t\t\t\tconst map: Record<string, keyof InputGamepad['directions']> = {\n\t\t\t\t\t\t'up': 'Up', 'down': 'Down', 'left': 'Left', 'right': 'Right',\n\t\t\t\t\t};\n\t\t\t\t\tconst prop = map[nameKey];\n\t\t\t\t\tif (!prop) continue;\n\t\t\t\t\tconst nextDirections = (input.directions || {} as any);\n\t\t\t\t\tnextDirections[prop] = this.mergeButtonState(nextDirections[prop], state);\n\t\t\t\t\tinput.directions = nextDirections;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (category === 'shoulders') {\n\t\t\t\t\tconst map: Record<string, keyof InputGamepad['shoulders']> = {\n\t\t\t\t\t\t'ltrigger': 'LTrigger', 'rtrigger': 'RTrigger',\n\t\t\t\t\t};\n\t\t\t\t\tconst prop = map[nameKey];\n\t\t\t\t\tif (!prop) continue;\n\t\t\t\t\tconst nextShoulders = (input.shoulders || {} as any);\n\t\t\t\t\tnextShoulders[prop] = this.mergeButtonState(nextShoulders[prop], state);\n\t\t\t\t\tinput.shoulders = nextShoulders;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn input;\n\t}\n\n\tgetInput(delta: number): Partial<InputGamepad> {\n\t\tconst base: Partial<InputGamepad> = {};\n\t\tif (this.includeDefaultBase) {\n\t\t\tbase.buttons = {\n\t\t\t\tA: this.handleButtonState('z', delta),\n\t\t\t\tB: this.handleButtonState('x', delta),\n\t\t\t\tX: this.handleButtonState('a', delta),\n\t\t\t\tY: this.handleButtonState('s', delta),\n\t\t\t\tStart: this.handleButtonState(' ', delta),\n\t\t\t\tSelect: this.handleButtonState('Enter', delta),\n\t\t\t\tL: this.handleButtonState('q', delta),\n\t\t\t\tR: this.handleButtonState('e', delta),\n\t\t\t};\n\t\t\tbase.directions = {\n\t\t\t\tUp: this.handleButtonState('ArrowUp', delta),\n\t\t\t\tDown: this.handleButtonState('ArrowDown', delta),\n\t\t\t\tLeft: this.handleButtonState('ArrowLeft', delta),\n\t\t\t\tRight: this.handleButtonState('ArrowRight', delta),\n\t\t\t};\n\t\t\tbase.axes = {\n\t\t\t\tHorizontal: this.handleAnalogState('ArrowLeft', 'ArrowRight', delta),\n\t\t\t\tVertical: this.handleAnalogState('ArrowUp', 'ArrowDown', delta),\n\t\t\t};\n\t\t\tbase.shoulders = {\n\t\t\t\tLTrigger: this.handleButtonState('Q', delta),\n\t\t\t\tRTrigger: this.handleButtonState('E', delta),\n\t\t\t};\n\t\t}\n\t\treturn this.applyCustomMapping(base, delta);\n\t}\n\n\tgetName(): string {\n\t\treturn 'keyboard';\n\t}\n\n\tprivate getAxisValue(negativeKey: string, positiveKey: string): number {\n\t\treturn (this.isKeyPressed(positiveKey) ? 1 : 0) - (this.isKeyPressed(negativeKey) ? 1 : 0);\n\t}\n\n\tisConnected(): boolean {\n\t\treturn true;\n\t}\n} ","import { InputProvider } from './input-provider';\nimport { AnalogState, ButtonState, InputGamepad } from './input';\n\nexport class GamepadProvider implements InputProvider {\n\tprivate gamepadIndex: number;\n\tprivate connected: boolean = false;\n\n\tprivate buttonStates: Record<number, ButtonState> = {};\n\n\tconstructor(gamepadIndex: number) {\n\t\tthis.gamepadIndex = gamepadIndex;\n\t\twindow.addEventListener('gamepadconnected', (e) => {\n\t\t\tif (e.gamepad.index === this.gamepadIndex) {\n\t\t\t\tthis.connected = true;\n\t\t\t}\n\t\t});\n\t\twindow.addEventListener('gamepaddisconnected', (e) => {\n\t\t\tif (e.gamepad.index === this.gamepadIndex) {\n\t\t\t\tthis.connected = false;\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate handleButtonState(index: number, gamepad: Gamepad, delta: number): ButtonState {\n\t\tconst isPressed = gamepad.buttons[index].pressed;\n\t\tlet buttonState = this.buttonStates[index];\n\n\t\tif (!buttonState) {\n\t\t\tbuttonState = { pressed: false, released: false, held: 0 };\n\t\t\tthis.buttonStates[index] = buttonState;\n\t\t}\n\n\t\tif (isPressed) {\n\t\t\tif (buttonState.held === 0) {\n\t\t\t\tbuttonState.pressed = true;\n\t\t\t} else {\n\t\t\t\tbuttonState.pressed = false;\n\t\t\t}\n\t\t\tbuttonState.held += delta;\n\t\t\tbuttonState.released = false;\n\t\t} else {\n\t\t\tif (buttonState.held > 0) {\n\t\t\t\tbuttonState.released = true;\n\t\t\t\tbuttonState.held = 0;\n\t\t\t} else {\n\t\t\t\tbuttonState.released = false;\n\t\t\t}\n\t\t\tbuttonState.pressed = false;\n\t\t}\n\n\t\treturn buttonState;\n\t}\n\n\tprivate handleAnalogState(index: number, gamepad: Gamepad, delta: number): AnalogState {\n\t\tconst value = gamepad.axes[index];\n\t\treturn { value, held: delta };\n\t}\n\n\tgetInput(delta: number): Partial<InputGamepad> {\n\t\tconst gamepad = navigator.getGamepads()[this.gamepadIndex];\n\t\tif (!gamepad) return {};\n\n\t\treturn {\n\t\t\tbuttons: {\n\t\t\t\tA: this.handleButtonState(0, gamepad, delta),\n\t\t\t\tB: this.handleButtonState(1, gamepad, delta),\n\t\t\t\tX: this.handleButtonState(2, gamepad, delta),\n\t\t\t\tY: this.handleButtonState(3, gamepad, delta),\n\t\t\t\tStart: this.handleButtonState(9, gamepad, delta),\n\t\t\t\tSelect: this.handleButtonState(8, gamepad, delta),\n\t\t\t\tL: this.handleButtonState(4, gamepad, delta),\n\t\t\t\tR: this.handleButtonState(5, gamepad, delta),\n\t\t\t},\n\t\t\tdirections: {\n\t\t\t\tUp: this.handleButtonState(12, gamepad, delta),\n\t\t\t\tDown: this.handleButtonState(13, gamepad, delta),\n\t\t\t\tLeft: this.handleButtonState(14, gamepad, delta),\n\t\t\t\tRight: this.handleButtonState(15, gamepad, delta),\n\t\t\t},\n\t\t\taxes: {\n\t\t\t\tHorizontal: this.handleAnalogState(0, gamepad, delta),\n\t\t\t\tVertical: this.handleAnalogState(1, gamepad, delta),\n\t\t\t},\n\t\t\tshoulders: {\n\t\t\t\tLTrigger: this.handleButtonState(6, gamepad, delta),\n\t\t\t\tRTrigger: this.handleButtonState(7, gamepad, delta),\n\t\t\t}\n\t\t};\n\t}\n\n\tgetName(): string {\n\t\treturn `gamepad-${this.gamepadIndex + 1}`;\n\t}\n\n\tisConnected(): boolean {\n\t\treturn this.connected;\n\t}\n} ","import { InputProvider } from './input-provider';\nimport { AnalogState, ButtonState, InputGamepad, InputPlayerNumber, Inputs } from './input';\nimport { KeyboardProvider } from './keyboard-provider';\nimport { GamepadProvider } from './gamepad-provider';\nimport { GameInputConfig } from '../game/game-interfaces';\n\n\nexport class InputManager {\n\tprivate inputMap: Map<InputPlayerNumber, InputProvider[]> = new Map();\n\tprivate currentInputs: Inputs = {} as Inputs;\n\tprivate previousInputs: Inputs = {} as Inputs;\n\n\tconstructor(config?: GameInputConfig) {\n\t\tif (config?.p1?.key) {\n\t\t\tthis.addInputProvider(1, new KeyboardProvider(config.p1.key, { includeDefaultBase: false }));\n\t\t} else {\n\t\t\tthis.addInputProvider(1, new KeyboardProvider());\n\t\t}\n\t\tthis.addInputProvider(1, new GamepadProvider(0));\n\t\tif (config?.p2?.key) {\n\t\t\tthis.addInputProvider(2, new KeyboardProvider(config.p2.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(2, new GamepadProvider(1));\n\t\tif (config?.p3?.key) {\n\t\t\tthis.addInputProvider(3, new KeyboardProvider(config.p3.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(3, new GamepadProvider(2));\n\t\tif (config?.p4?.key) {\n\t\t\tthis.addInputProvider(4, new KeyboardProvider(config.p4.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(4, new GamepadProvider(3));\n\t\tif (config?.p5?.key) {\n\t\t\tthis.addInputProvider(5, new KeyboardProvider(config.p5.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(5, new GamepadProvider(4));\n\t\tif (config?.p6?.key) {\n\t\t\tthis.addInputProvider(6, new KeyboardProvider(config.p6.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(6, new GamepadProvider(5));\n\t\tif (config?.p7?.key) {\n\t\t\tthis.addInputProvider(7, new KeyboardProvider(config.p7.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(7, new GamepadProvider(6));\n\t\tif (config?.p8?.key) {\n\t\t\tthis.addInputProvider(8, new KeyboardProvider(config.p8.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(8, new GamepadProvider(7));\n\t}\n\n\taddInputProvider(playerNumber: InputPlayerNumber, provider: InputProvider) {\n\t\tif (!this.inputMap.has(playerNumber)) {\n\t\t\tthis.inputMap.set(playerNumber, []);\n\t\t}\n\t\tthis.inputMap.get(playerNumber)?.push(provider);\n\t}\n\n\tgetInputs(delta: number): Inputs {\n\t\tconst inputs = {} as Inputs;\n\t\tthis.inputMap.forEach((providers, playerNumber) => {\n\t\t\tconst playerKey = `p${playerNumber}` as const;\n\n\t\t\tconst mergedInput = providers.reduce((acc, provider) => {\n\t\t\t\tconst input = provider.getInput(delta);\n\t\t\t\treturn this.mergeInputs(acc, input);\n\t\t\t}, {} as Partial<InputGamepad>);\n\n\t\t\tinputs[playerKey] = {\n\t\t\t\tplayerNumber: playerNumber as InputPlayerNumber,\n\t\t\t\t...mergedInput\n\t\t\t} as InputGamepad;\n\t\t});\n\t\treturn inputs;\n\t}\n\n\tmergeButtonState(a: ButtonState | undefined, b: ButtonState | undefined): ButtonState {\n\t\treturn {\n\t\t\tpressed: a?.pressed || b?.pressed || false,\n\t\t\treleased: a?.released || b?.released || false,\n\t\t\theld: (a?.held || 0) + (b?.held || 0),\n\t\t};\n\t}\n\n\tmergeAnalogState(a: AnalogState | undefined, b: AnalogState | undefined): AnalogState {\n\t\treturn {\n\t\t\tvalue: (a?.value || 0) + (b?.value || 0),\n\t\t\theld: (a?.held || 0) + (b?.held || 0),\n\t\t};\n\t}\n\n\tprivate mergeInputs(a: Partial<InputGamepad>, b: Partial<InputGamepad>): Partial<InputGamepad> {\n\t\treturn {\n\t\t\tbuttons: {\n\t\t\t\tA: this.mergeButtonState(a.buttons?.A, b.buttons?.A),\n\t\t\t\tB: this.mergeButtonState(a.buttons?.B, b.buttons?.B),\n\t\t\t\tX: this.mergeButtonState(a.buttons?.X, b.buttons?.X),\n\t\t\t\tY: this.mergeButtonState(a.buttons?.Y, b.buttons?.Y),\n\t\t\t\tStart: this.mergeButtonState(a.buttons?.Start, b.buttons?.Start),\n\t\t\t\tSelect: this.mergeButtonState(a.buttons?.Select, b.buttons?.Select),\n\t\t\t\tL: this.mergeButtonState(a.buttons?.L, b.buttons?.L),\n\t\t\t\tR: this.mergeButtonState(a.buttons?.R, b.buttons?.R),\n\t\t\t},\n\t\t\tdirections: {\n\t\t\t\tUp: this.mergeButtonState(a.directions?.Up, b.directions?.Up),\n\t\t\t\tDown: this.mergeButtonState(a.directions?.Down, b.directions?.Down),\n\t\t\t\tLeft: this.mergeButtonState(a.directions?.Left, b.directions?.Left),\n\t\t\t\tRight: this.mergeButtonState(a.directions?.Right, b.directions?.Right),\n\t\t\t},\n\t\t\taxes: {\n\t\t\t\tHorizontal: this.mergeAnalogState(a.axes?.Horizontal, b.axes?.Horizontal),\n\t\t\t\tVertical: this.mergeAnalogState(a.axes?.Vertical, b.axes?.Vertical),\n\t\t\t},\n\t\t\tshoulders: {\n\t\t\t\tLTrigger: this.mergeButtonState(a.shoulders?.LTrigger, b.shoulders?.LTrigger),\n\t\t\t\tRTrigger: this.mergeButtonState(a.shoulders?.RTrigger, b.shoulders?.RTrigger),\n\t\t\t}\n\t\t};\n\t}\n} ","/**\n * This class is an alternative to {@link Clock} with a different API design and behavior.\n * The goal is to avoid the conceptual flaws that became apparent in `Clock` over time.\n *\n * - `Timer` has an `update()` method that updates its internal state. That makes it possible to\n * call `getDelta()` and `getElapsed()` multiple times per simulation step without getting different values.\n * - The class can make use of the Page Visibility API to avoid large time delta values when the app\n * is inactive (e.g. tab switched or browser hidden).\n *\n * ```js\n * const timer = new Timer();\n * timer.connect( document ); // use Page Visibility API\n * ```\n *\n * @three_import import { Timer } from 'three/addons/misc/Timer.js';\n */\nclass Timer {\n\tprotected _previousTime: number;\n\tprotected _currentTime: number;\n\tprotected _startTime: number;\n\tprotected _delta: number;\n\tprotected _elapsed: number;\n\tprotected _timescale: number;\n\tprotected _document: Document | null;\n\tprotected _pageVisibilityHandler: (() => void) | null;\n\n\t/**\n\t * Constructs a new timer.\n\t */\n\tconstructor() {\n\n\t\tthis._previousTime = 0;\n\t\tthis._currentTime = 0;\n\t\tthis._startTime = now();\n\n\t\tthis._delta = 0;\n\t\tthis._elapsed = 0;\n\n\t\tthis._timescale = 1;\n\n\t\tthis._document = null;\n\t\tthis._pageVisibilityHandler = null;\n\n\t}\n\n\t/**\n\t * Connect the timer to the given document.Calling this method is not mandatory to\n\t * use the timer but enables the usage of the Page Visibility API to avoid large time\n\t * delta values.\n\t *\n\t * @param {Document} document - The document.\n\t */\n\tconnect(document: Document): void {\n\n\t\tthis._document = document;\n\n\t\t// use Page Visibility API to avoid large time delta values\n\n\t\tif (document.hidden !== undefined) {\n\n\t\t\tthis._pageVisibilityHandler = handleVisibilityChange.bind(this);\n\n\t\t\tdocument.addEventListener('visibilitychange', this._pageVisibilityHandler, false);\n\n\t\t}\n\n\t}\n\n\t/**\n\t * Disconnects the timer from the DOM and also disables the usage of the Page Visibility API.\n\t */\n\tdisconnect(): void {\n\n\t\tif (this._pageVisibilityHandler !== null) {\n\n\t\t\tthis._document!.removeEventListener('visibilitychange', this._pageVisibilityHandler);\n\t\t\tthis._pageVisibilityHandler = null;\n\n\t\t}\n\n\t\tthis._document = null;\n\n\t}\n\n\t/**\n\t * Returns the time delta in seconds.\n\t *\n\t * @return {number} The time delta in second.\n\t */\n\tgetDelta(): number {\n\n\t\treturn this._delta / 1000;\n\n\t}\n\n\t/**\n\t * Returns the elapsed time in seconds.\n\t *\n\t * @return {number} The elapsed time in second.\n\t */\n\tgetElapsed(): number {\n\n\t\treturn this._elapsed / 1000;\n\n\t}\n\n\t/**\n\t * Returns the timescale.\n\t *\n\t * @return {number} The timescale.\n\t */\n\tgetTimescale(): number {\n\n\t\treturn this._timescale;\n\n\t}\n\n\t/**\n\t * Sets the given timescale which scale the time delta computation\n\t * in `update()`.\n\t *\n\t * @param {number} timescale - The timescale to set.\n\t * @return {Timer} A reference to this timer.\n\t */\n\tsetTimescale(timescale: number): Timer {\n\n\t\tthis._timescale = timescale;\n\n\t\treturn this;\n\n\t}\n\n\t/**\n\t * Resets the time computation for the current simulation step.\n\t *\n\t * @return {Timer} A reference to this timer.\n\t */\n\treset(): Timer {\n\n\t\tthis._currentTime = now() - this._startTime;\n\n\t\treturn this;\n\n\t}\n\n\t/**\n\t * Can be used to free all internal resources. Usually called when\n\t * the timer instance isn't required anymore.\n\t */\n\tdispose(): void {\n\n\t\tthis.disconnect();\n\n\t}\n\n\t/**\n\t * Updates the internal state of the timer. This method should be called\n\t * once per simulation step and before you perform queries against the timer\n\t * (e.g. via `getDelta()`).\n\t *\n\t * @param {number} timestamp - The current time in milliseconds. Can be obtained\n\t * from the `requestAnimationFrame` callback argument. If not provided, the current\n\t * time will be determined with `performance.now`.\n\t * @return {Timer} A reference to this timer.\n\t */\n\tupdate(timestamp?: number): Timer {\n\n\t\tif (this._pageVisibilityHandler !== null && this._document!.hidden === true) {\n\n\t\t\tthis._delta = 0;\n\n\t\t} else {\n\n\t\t\tthis._previousTime = this._currentTime;\n\t\t\tthis._currentTime = (timestamp !== undefined ? timestamp : now()) - this._startTime;\n\n\t\t\tthis._delta = (this._currentTime - this._previousTime) * this._timescale;\n\t\t\tthis._elapsed += this._delta; // _elapsed is the accumulation of all previous deltas\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n}\n\n/**\n * A special version of a timer with a fixed time delta value.\n * Can be useful for testing and debugging purposes.\n *\n * @augments Timer\n */\nclass FixedTimer extends Timer {\n\n\t/**\n\t * Constructs a new timer.\n\t *\n\t * @param {number} [fps=60] - The fixed FPS of this timer.\n\t */\n\tconstructor(fps: number = 60) {\n\n\t\tsuper();\n\t\tthis._delta = (1 / fps) * 1000;\n\n\t}\n\n\tupdate(): FixedTimer {\n\n\t\tthis._elapsed += (this._delta * this._timescale); // _elapsed is the accumulation of all previous deltas\n\n\t\treturn this;\n\n\t}\n\n}\n\nfunction now(): number {\n\n\treturn performance.now();\n\n}\n\nfunction handleVisibilityChange(this: Timer): void {\n\n\tif (this._document!.hidden === false) this.reset();\n\n}\n\nexport { Timer, };","export const AspectRatio = {\n\tFourByThree: 4 / 3,\n\tSixteenByNine: 16 / 9,\n\tTwentyOneByNine: 21 / 9,\n\tOneByOne: 1 / 1,\n} as const;\n\nexport type AspectRatioValue = (typeof AspectRatio)[keyof typeof AspectRatio] | number;\n\n/**\n * AspectRatioDelegate manages sizing a canvas to fit within a container\n * while preserving a target aspect ratio. It notifies a consumer via\n * onResize when the final width/height are applied so renderers/cameras\n * can update their viewports.\n */\nexport class AspectRatioDelegate {\n\tcontainer: HTMLElement;\n\tcanvas: HTMLCanvasElement;\n\taspectRatio: number;\n\tonResize?: (width: number, height: number) => void;\n\tprivate handleResizeBound: () => void;\n\n\tconstructor(params: {\n\t\tcontainer: HTMLElement;\n\t\tcanvas: HTMLCanvasElement;\n\t\taspectRatio: AspectRatioValue;\n\t\tonResize?: (width: number, height: number) => void;\n\t}) {\n\t\tthis.container = params.container;\n\t\tthis.canvas = params.canvas;\n\t\tthis.aspectRatio = typeof params.aspectRatio === 'number' ? params.aspectRatio : params.aspectRatio;\n\t\tthis.onResize = params.onResize;\n\t\tthis.handleResizeBound = this.apply.bind(this);\n\t}\n\n\t/** Attach window resize listener and apply once. */\n\tattach() {\n\t\twindow.addEventListener('resize', this.handleResizeBound);\n\t\tthis.apply();\n\t}\n\n\t/** Detach window resize listener. */\n\tdetach() {\n\t\twindow.removeEventListener('resize', this.handleResizeBound);\n\t}\n\n\t/** Compute the largest size that fits container while preserving aspect. */\n\tmeasure(): { width: number; height: number } {\n\t\tconst containerWidth = this.container.clientWidth || window.innerWidth;\n\t\tconst containerHeight = this.container.clientHeight || window.innerHeight;\n\n\t\tconst containerRatio = containerWidth / containerHeight;\n\t\tif (containerRatio > this.aspectRatio) {\n\t\t\t// container is wider than target; limit by height\n\t\t\tconst height = containerHeight;\n\t\t\tconst width = Math.round(height * this.aspectRatio);\n\t\t\treturn { width, height };\n\t\t} else {\n\t\t\t// container is taller/narrower; limit by width\n\t\t\tconst width = containerWidth;\n\t\t\tconst height = Math.round(width / this.aspectRatio);\n\t\t\treturn { width, height };\n\t\t}\n\t}\n\n\t/** Apply measured size to canvas and notify. */\n\tapply() {\n\t\tconst { width, height } = this.measure();\n\t\t// Apply CSS size; renderer will update internal size via onResize callback\n\t\tthis.canvas.style.width = `${width}px`;\n\t\tthis.canvas.style.height = `${height}px`;\n\t\tthis.onResize?.(width, height);\n\t}\n}","export type RetroResolution = { key: string; width: number; height: number; notes?: string };\n\nexport type RetroPreset = {\n\tdisplayAspect: number;\n\tresolutions: RetroResolution[];\n};\n\n/**\n * Retro and console display presets.\n * displayAspect represents the intended display aspect (letterboxing target),\n * not necessarily the raw pixel aspect of internal buffers.\n */\nconst RetroPresets: Record<string, RetroPreset> = {\n\tNES: {\n\t\tdisplayAspect: 4 / 3,\n\t\tresolutions: [\n\t\t\t{ key: '256x240', width: 256, height: 240, notes: 'Standard NTSC; effective 240p.' },\n\t\t],\n\t},\n\tSNES: {\n\t\tdisplayAspect: 4 / 3,\n\t\tresolutions: [\n\t\t\t{ key: '256x224', width: 256, height: 224, notes: 'Common 240p-equivalent mode.' },\n\t\t\t{ key: '512x448', width: 512, height: 448, notes: 'Hi-res interlaced (480i).' },\n\t\t],\n\t},\n\tN64: {\n\t\tdisplayAspect: 4 / 3,\n\t\tresolutions: [\n\t\t\t{ key: '320x240', width: 320, height: 240, notes: 'Common 240p mode.' },\n\t\t\t{ key: '640x480', width: 640, height: 480, notes: 'Higher resolution (480i).' },\n\t\t],\n\t},\n\tPS1: {\n\t\tdisplayAspect: 4 / 3,\n\t\tresolutions: [\n\t\t\t{ key: '320x240', width: 320, height: 240, notes: 'Progressive 240p common.' },\n\t\t\t{ key: '640x480', width: 640, height: 480, notes: 'Interlaced 480i for higher detail.' },\n\t\t],\n\t},\n\tPS2: {\n\t\tdisplayAspect: 4 / 3,\n\t\tresolutions: [\n\t\t\t{ key: '640x480', width: 640, height: 480, notes: '480i/480p baseline.' },\n\t\t\t{ key: '720x480', width: 720, height: 480, notes: '480p (widescreen capable in some titles).' },\n\t\t\t{ key: '1280x720', width: 1280, height: 720, notes: '720p (select titles).' },\n\t\t],\n\t},\n\tPS5: {\n\t\tdisplayAspect: 16 / 9,\n\t\tresolutions: [\n\t\t\t{ key: '720x480', width: 720, height: 480, notes: 'Legacy compatibility.' },\n\t\t\t{ key: '1280x720', width: 1280, height: 720, notes: '720p.' },\n\t\t\t{ key: '1920x1080', width: 1920, height: 1080, notes: '1080p.' },\n\t\t\t{ key: '2560x1440', width: 2560, height: 1440, notes: '1440p.' },\n\t\t\t{ key: '3840x2160', width: 3840, height: 2160, notes: '4K (up to 120Hz).' },\n\t\t\t{ key: '7680x4320', width: 7680, height: 4320, notes: '8K (limited).' },\n\t\t],\n\t},\n\tXboxOne: {\n\t\tdisplayAspect: 16 / 9,\n\t\tresolutions: [\n\t\t\t{ key: '1280x720', width: 1280, height: 720, notes: '720p (original).' },\n\t\t\t{ key: '1920x1080', width: 1920, height: 1080, notes: '1080p (original).' },\n\t\t\t{ key: '3840x2160', width: 3840, height: 2160, notes: '4K UHD (S/X models).' },\n\t\t],\n\t},\n};\n\nexport type RetroPresetKey = keyof typeof RetroPresets;\n\nexport function getDisplayAspect(preset: RetroPresetKey): number {\n\treturn RetroPresets[preset].displayAspect;\n}\n\nexport function getPresetResolution(preset: RetroPresetKey, key?: string): RetroResolution | undefined {\n\tconst list = RetroPresets[preset]?.resolutions || [];\n\tif (!key) return list[0];\n\tconst normalized = key.toLowerCase().replace(/\\s+/g, '').replace('×', 'x');\n\treturn list.find(r => r.key.toLowerCase() === normalized);\n}\n\nexport function parseResolution(text: string): { width: number; height: number } | null {\n\tif (!text) return null;\n\tconst normalized = String(text).toLowerCase().trim().replace(/\\s+/g, '').replace('×', 'x');\n\tconst match = normalized.match(/^(\\d+)x(\\d+)$/);\n\tif (!match) return null;\n\tconst width = parseInt(match[1], 10);\n\tconst height = parseInt(match[2], 10);\n\tif (!Number.isFinite(width) || !Number.isFinite(height)) return null;\n\treturn { width, height };\n}\n\n\n","import { StageInterface } from \"../types\";\nimport { GameInputConfig } from \"./game-interfaces\";\nimport { AspectRatio, AspectRatioValue } from \"../device/aspect-ratio\";\nimport { getDisplayAspect, getPresetResolution, parseResolution, RetroPresetKey } from \"./game-retro-resolutions\";\n\nexport type GameConfigLike = Partial<{\n\tid: string;\n\tglobals: Record<string, any>;\n\tstages: StageInterface[];\n\tdebug: boolean;\n\ttime: number;\n\tinput: GameInputConfig;\n\t/** numeric value or key in AspectRatio */\n\taspectRatio: AspectRatioValue | keyof typeof AspectRatio;\n\t/** console/display preset to derive aspect ratio */\n\tpreset: RetroPresetKey;\n\t/** lock internal render buffer to this resolution (e.g., '256x240' or { width, height }) */\n\tresolution: string | { width: number; height: number };\n\tfullscreen: boolean;\n\t/** CSS background value for document body */\n\tbodyBackground: string;\n\t/** existing container by reference */\n\tcontainer: HTMLElement;\n\t/** create/find container by id */\n\tcontainerId: string;\n\t/** optional canvas if caller wants to manage it */\n\tcanvas: HTMLCanvasElement;\n}>;\n\nexport class GameConfig {\n\tconstructor(\n\t\tpublic id: string,\n\t\tpublic globals: Record<string, any>,\n\t\tpublic stages: StageInterface[],\n\t\tpublic debug: boolean,\n\t\tpublic time: number,\n\t\tpublic input: GameInputConfig | undefined,\n\t\tpublic aspectRatio: number,\n\t\tpublic internalResolution: { width: number; height: number } | undefined,\n\t\tpublic fullscreen: boolean,\n\t\tpublic bodyBackground: string | undefined,\n\t\tpublic container: HTMLElement,\n\t\tpublic containerId?: string,\n\t\tpublic canvas?: HTMLCanvasElement,\n\t) { }\n}\n\nfunction ensureContainer(containerId?: string, existing?: HTMLElement | null): HTMLElement {\n\tif (existing) return existing;\n\tif (containerId) {\n\t\tconst found = document.getElementById(containerId);\n\t\tif (found) return found;\n\t}\n\tconst id = containerId || 'zylem-root';\n\tconst el = document.createElement('main');\n\tel.setAttribute('id', id);\n\tel.style.position = 'relative';\n\tel.style.width = '100%';\n\tel.style.height = '100%';\n\tdocument.body.appendChild(el);\n\treturn el;\n}\n\nfunction createDefaultGameConfig(base?: Partial<Pick<GameConfig, 'id' | 'debug' | 'time' | 'input'>> & { stages?: StageInterface[]; globals?: Record<string, any> }): GameConfig {\n\tconst id = base?.id ?? 'zylem';\n\tconst container = ensureContainer(id);\n\treturn new GameConfig(\n\t\tid,\n\t\t(base?.globals ?? {}) as Record<string, any>,\n\t\t(base?.stages ?? []) as StageInterface[],\n\t\tBoolean(base?.debug),\n\t\tbase?.time ?? 0,\n\t\tbase?.input,\n\t\tAspectRatio.SixteenByNine,\n\t\tundefined,\n\t\ttrue,\n\t\t'#000000',\n\t\tcontainer,\n\t\tid,\n\t\tundefined,\n\t);\n}\n\nexport function resolveGameConfig(user?: GameConfigLike): GameConfig {\n\tconst defaults = createDefaultGameConfig({\n\t\tid: user?.id ?? 'zylem',\n\t\tdebug: Boolean(user?.debug),\n\t\ttime: (user?.time as number) ?? 0,\n\t\tinput: user?.input,\n\t\tstages: (user?.stages as StageInterface[]) ?? [],\n\t\tglobals: (user?.globals as Record<string, any>) ?? {},\n\t});\n\n\t// Resolve container\n\tconst containerId = (user?.containerId as string) ?? defaults.containerId;\n\tconst container = ensureContainer(containerId, user?.container ?? null);\n\n\t// Derive aspect ratio: explicit numeric -> preset -> default\n\tconst explicitAspect = user?.aspectRatio as any;\n\tlet aspectRatio = defaults.aspectRatio;\n\tif (typeof explicitAspect === 'number' || (explicitAspect && typeof explicitAspect === 'string')) {\n\t\taspectRatio = typeof explicitAspect === 'number' ? explicitAspect : (AspectRatio as any)[explicitAspect] ?? defaults.aspectRatio;\n\t} else if (user?.preset) {\n\t\ttry {\n\t\t\taspectRatio = getDisplayAspect(user.preset as RetroPresetKey) || defaults.aspectRatio;\n\t\t} catch {\n\t\t\taspectRatio = defaults.aspectRatio;\n\t\t}\n\t}\n\n\tconst fullscreen = (user?.fullscreen as boolean) ?? defaults.fullscreen;\n\tconst bodyBackground = (user?.bodyBackground as string) ?? defaults.bodyBackground;\n\n\t// Normalize internal resolution lock\n\tlet internalResolution: { width: number; height: number } | undefined;\n\tif (user?.resolution) {\n\t\tif (typeof user.resolution === 'string') {\n\t\t\tconst parsed = parseResolution(user.resolution);\n\t\t\tif (parsed) internalResolution = parsed;\n\t\t\t// fallback: allow preset resolution keys like '256x240' under a preset\n\t\t\tif (!internalResolution && user.preset) {\n\t\t\t\tconst res = getPresetResolution(user.preset as RetroPresetKey, user.resolution);\n\t\t\t\tif (res) internalResolution = { width: res.width, height: res.height };\n\t\t\t}\n\t\t} else if (typeof user.resolution === 'object') {\n\t\t\tconst w = (user.resolution as any).width;\n\t\t\tconst h = (user.resolution as any).height;\n\t\t\tif (Number.isFinite(w) && Number.isFinite(h)) {\n\t\t\t\tinternalResolution = { width: w, height: h };\n\t\t\t}\n\t\t}\n\t}\n\n\t// Prefer provided canvas if any\n\tconst canvas = user?.canvas ?? undefined;\n\n\treturn new GameConfig(\n\t\t(user?.id as string) ?? defaults.id,\n\t\t(user?.globals as Record<string, any>) ?? defaults.globals,\n\t\t(user?.stages as StageInterface[]) ?? defaults.stages,\n\t\tBoolean(user?.debug ?? defaults.debug),\n\t\t(user?.time as number) ?? defaults.time,\n\t\tuser?.input ?? defaults.input,\n\t\taspectRatio,\n\t\tinternalResolution,\n\t\tfullscreen,\n\t\tbodyBackground,\n\t\tcontainer,\n\t\tcontainerId,\n\t\tcanvas,\n\t);\n}\n\n/**\n * Factory for authoring configuration objects in user code.\n * Returns a plain object that can be passed to `game(...)`.\n */\nexport function gameConfig(config: GameConfigLike): GameConfigLike {\n\treturn { ...config };\n}","import { AspectRatioDelegate, AspectRatioValue } from '../device/aspect-ratio';\n\nexport interface GameCanvasOptions {\n\tid: string;\n\tcontainer?: HTMLElement;\n\tcontainerId?: string;\n\tcanvas?: HTMLCanvasElement;\n\tbodyBackground?: string;\n\tfullscreen?: boolean;\n\taspectRatio: AspectRatioValue | number;\n}\n\n/**\n * GameCanvas is a DOM delegate that owns:\n * - container lookup/creation and styling (including fullscreen centering)\n * - body background application\n * - canvas mounting into container\n * - aspect ratio sizing via AspectRatioDelegate\n */\nexport class GameCanvas {\n\tid: string;\n\tcontainer!: HTMLElement;\n\tcanvas!: HTMLCanvasElement;\n\tbodyBackground?: string;\n\tfullscreen: boolean;\n\taspectRatio: number;\n\tprivate ratioDelegate: AspectRatioDelegate | null = null;\n\n\tconstructor(options: GameCanvasOptions) {\n\t\tthis.id = options.id;\n\t\tthis.container = this.ensureContainer(options.containerId ?? options.id, options.container);\n\t\tthis.canvas = options.canvas ?? document.createElement('canvas');\n\t\tthis.bodyBackground = options.bodyBackground;\n\t\tthis.fullscreen = Boolean(options.fullscreen);\n\t\tthis.aspectRatio = typeof options.aspectRatio === 'number' ? options.aspectRatio : options.aspectRatio;\n\t}\n\n\tapplyBodyBackground() {\n\t\tif (this.bodyBackground) {\n\t\t\tdocument.body.style.background = this.bodyBackground;\n\t\t}\n\t}\n\n\tmountCanvas() {\n\t\twhile (this.container.firstChild) {\n\t\t\tthis.container.removeChild(this.container.firstChild);\n\t\t}\n\t\tthis.container.appendChild(this.canvas);\n\t}\n\n\tmountRenderer(rendererDom: HTMLCanvasElement, onResize: (width: number, height: number) => void) {\n\t\twhile (this.container.firstChild) {\n\t\t\tthis.container.removeChild(this.container.firstChild);\n\t\t}\n\t\tthis.container.appendChild(rendererDom);\n\t\tthis.canvas = rendererDom;\n\t\tthis.attachAspectRatio(onResize);\n\t}\n\n\tcenterIfFullscreen() {\n\t\tif (!this.fullscreen) return;\n\t\tconst style = this.container.style;\n\t\tstyle.display = 'flex';\n\t\tstyle.alignItems = 'center';\n\t\tstyle.justifyContent = 'center';\n\t\tstyle.position = 'relative';\n\t\tstyle.inset = '0';\n\t}\n\n\tattachAspectRatio(onResize: (width: number, height: number) => void) {\n\t\tif (!this.ratioDelegate) {\n\t\t\tthis.ratioDelegate = new AspectRatioDelegate({\n\t\t\t\tcontainer: this.container,\n\t\t\t\tcanvas: this.canvas,\n\t\t\t\taspectRatio: this.aspectRatio,\n\t\t\t\tonResize\n\t\t\t});\n\t\t\tthis.ratioDelegate.attach();\n\t\t} else {\n\t\t\tthis.ratioDelegate.canvas = this.canvas;\n\t\t\tthis.ratioDelegate.onResize = onResize;\n\t\t\tthis.ratioDelegate.aspectRatio = this.aspectRatio;\n\t\t\tthis.ratioDelegate.apply();\n\t\t}\n\t}\n\n\tdestroy() {\n\t\tthis.ratioDelegate?.detach();\n\t\tthis.ratioDelegate = null;\n\t}\n\n\tprivate ensureContainer(containerId?: string, existing?: HTMLElement | null): HTMLElement {\n\t\tif (existing) return existing;\n\t\tif (containerId) {\n\t\t\tconst found = document.getElementById(containerId);\n\t\t\tif (found) return found;\n\t\t}\n\t\tconst id = containerId || this.id || 'zylem-root';\n\t\tconst el = document.createElement('main');\n\t\tel.setAttribute('id', id);\n\t\tel.style.position = 'relative';\n\t\tel.style.width = '100%';\n\t\tel.style.height = '100%';\n\t\tdocument.body.appendChild(el);\n\t\treturn el;\n\t}\n}\n","import Stats from 'stats.js';\nimport { subscribe } from 'valtio/vanilla';\nimport { debugState } from '../debug/debug-state';\n\n/**\n * GameDebugDelegate handles debug UI for the game (Stats panel).\n * Subscribes to debugState changes for runtime toggle.\n */\nexport class GameDebugDelegate {\n private statsRef: Stats | null = null;\n private unsubscribe: (() => void) | null = null;\n\n constructor() {\n this.updateDebugUI();\n this.unsubscribe = subscribe(debugState, () => {\n this.updateDebugUI();\n });\n }\n\n /**\n * Called every frame - wraps stats.begin()\n */\n begin(): void {\n this.statsRef?.begin();\n }\n\n /**\n * Called every frame - wraps stats.end()\n */\n end(): void {\n this.statsRef?.end();\n }\n\n private updateDebugUI(): void {\n if (debugState.enabled && !this.statsRef) {\n // Enable debug UI\n this.statsRef = new Stats();\n this.statsRef.showPanel(0);\n this.statsRef.dom.style.position = 'absolute';\n this.statsRef.dom.style.bottom = '0';\n this.statsRef.dom.style.right = '0';\n this.statsRef.dom.style.top = 'auto';\n this.statsRef.dom.style.left = 'auto';\n document.body.appendChild(this.statsRef.dom);\n } else if (!debugState.enabled && this.statsRef) {\n // Disable debug UI\n if (this.statsRef.dom.parentNode) {\n this.statsRef.dom.parentNode.removeChild(this.statsRef.dom);\n }\n this.statsRef = null;\n }\n }\n\n dispose(): void {\n if (this.unsubscribe) {\n this.unsubscribe();\n this.unsubscribe = null;\n }\n if (this.statsRef?.dom?.parentNode) {\n this.statsRef.dom.parentNode.removeChild(this.statsRef.dom);\n }\n this.statsRef = null;\n }\n}\n","import { LoadingEvent } from '../core/interfaces';\n\n/**\n * Event name for game loading events.\n * Dispatched via window for cross-application communication.\n */\nexport const GAME_LOADING_EVENT = 'GAME_LOADING_EVENT';\n\n/**\n * Game-level loading event that includes stage context.\n */\nexport interface GameLoadingEvent {\n\ttype: 'start' | 'progress' | 'complete';\n\tstageName?: string;\n\tstageIndex?: number;\n\tmessage: string;\n\tprogress: number;\n\tcurrent?: number;\n\ttotal?: number;\n}\n\n/**\n * Delegate for managing game-level loading events.\n * Aggregates loading events from stages and includes stage context.\n * Also dispatches window custom events for cross-application communication.\n */\nexport class GameLoadingDelegate {\n\tprivate loadingHandlers: Array<(event: GameLoadingEvent) => void> = [];\n\tprivate stageLoadingUnsubscribes: (() => void)[] = [];\n\n\t/**\n\t * Subscribe to loading events from the game.\n\t * Events include stage context (stageName, stageIndex).\n\t * \n\t * @param callback Invoked for each loading event\n\t * @returns Unsubscribe function\n\t */\n\tonLoading(callback: (event: GameLoadingEvent) => void): () => void {\n\t\tthis.loadingHandlers.push(callback);\n\t\treturn () => {\n\t\t\tthis.loadingHandlers = this.loadingHandlers.filter((h) => h !== callback);\n\t\t};\n\t}\n\n\t/**\n\t * Emit a loading event to all subscribers and dispatch to window.\n\t */\n\temit(event: GameLoadingEvent): void {\n\t\t// Dispatch to direct subscribers\n\t\tfor (const handler of this.loadingHandlers) {\n console.log('Game loading event', event);\n\t\t\ttry {\n\t\t\t\thandler(event);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('Game loading handler failed', e);\n\t\t\t}\n\t\t}\n\t\t\n\t\t// Also dispatch as window event for cross-application communication\n\t\tif (typeof window !== 'undefined') {\n\t\t\twindow.dispatchEvent(new CustomEvent(GAME_LOADING_EVENT, { detail: event }));\n\t\t}\n\t}\n\n\t/**\n\t * Wire up a stage's loading events to this delegate.\n\t * \n\t * @param stage The stage to wire up\n\t * @param stageIndex The index of the stage\n\t */\n\twireStageLoading(stage: { uuid?: string; onLoading: (cb: (event: LoadingEvent) => void) => () => void | void }, stageIndex: number): void {\n const unsub = stage.onLoading((event: LoadingEvent) => {\n\t\t\tthis.emit({\n\t\t\t\ttype: event.type,\n\t\t\t\tmessage: event.message ?? '',\n\t\t\t\tprogress: event.progress ?? 0,\n\t\t\t\tcurrent: event.current,\n\t\t\t\ttotal: event.total,\n\t\t\t\tstageName: stage.uuid ?? `Stage ${stageIndex}`,\n\t\t\t\tstageIndex,\n\t\t\t});\n\t\t});\n\t\tif (typeof unsub === 'function') {\n\t\t\tthis.stageLoadingUnsubscribes.push(unsub);\n\t\t}\n\t}\n\n\t/**\n\t * Unsubscribe from all stage loading events.\n\t */\n\tunwireAllStages(): void {\n\t\tfor (const unsub of this.stageLoadingUnsubscribes) {\n\t\t\ttry {\n\t\t\t\tunsub();\n\t\t\t} catch { /* noop */ }\n\t\t}\n\t\tthis.stageLoadingUnsubscribes = [];\n\t}\n\n\t/**\n\t * Clean up all handlers.\n\t */\n\tdispose(): void {\n\t\tthis.unwireAllStages();\n\t\tthis.loadingHandlers = [];\n\t}\n}\n","import { ZylemCamera } from '../camera/zylem-camera';\nimport { GameCanvas } from './game-canvas';\nimport { GameConfig } from './game-config';\n\n/**\n * Observer that triggers renderer mounting when container and camera are both available.\n * Decouples renderer mounting from stage loading.\n */\nexport class GameRendererObserver {\n\tprivate container: HTMLElement | null = null;\n\tprivate camera: ZylemCamera | null = null;\n\tprivate gameCanvas: GameCanvas | null = null;\n\tprivate config: GameConfig | null = null;\n\tprivate mounted = false;\n\n\tsetGameCanvas(canvas: GameCanvas): void {\n\t\tthis.gameCanvas = canvas;\n\t\tthis.tryMount();\n\t}\n\n\tsetConfig(config: GameConfig): void {\n\t\tthis.config = config;\n\t\tthis.tryMount();\n\t}\n\n\tsetContainer(container: HTMLElement): void {\n\t\tthis.container = container;\n\t\tthis.tryMount();\n\t}\n\n\tsetCamera(camera: ZylemCamera): void {\n\t\tthis.camera = camera;\n\t\tthis.tryMount();\n\t}\n\n\t/**\n\t * Attempt to mount renderer if all dependencies are available.\n\t */\n\tprivate tryMount(): void {\n\t\tif (this.mounted) return;\n\t\tif (!this.container || !this.camera || !this.gameCanvas) return;\n\n\t\tconst dom = this.camera.getDomElement();\n\t\tconst internal = this.config?.internalResolution;\n\t\t\n\t\tthis.gameCanvas.mountRenderer(dom, (cssW, cssH) => {\n\t\t\tif (!this.camera) return;\n\t\t\tif (internal) {\n\t\t\t\tthis.camera.setPixelRatio(1);\n\t\t\t\tthis.camera.resize(internal.width, internal.height);\n\t\t\t} else {\n\t\t\t\tconst dpr = window.devicePixelRatio || 1;\n\t\t\t\tthis.camera.setPixelRatio(dpr);\n\t\t\t\tthis.camera.resize(cssW, cssH);\n\t\t\t}\n\t\t});\n\t\t\n\t\tthis.mounted = true;\n\t}\n\n\t/**\n\t * Reset state for stage transitions.\n\t */\n\treset(): void {\n\t\tthis.camera = null;\n\t\tthis.mounted = false;\n\t}\n\n\tdispose(): void {\n\t\tthis.container = null;\n\t\tthis.camera = null;\n\t\tthis.gameCanvas = null;\n\t\tthis.config = null;\n\t\tthis.mounted = false;\n\t}\n}\n","import { ZylemGame, GameLoadingEvent } from './zylem-game';\nimport { DestroyFunction, SetupFunction, UpdateFunction } from '../core/base-node-life-cycle';\nimport { IGame, LoadingEvent } from '../core/interfaces';\nimport { setPaused } from '../debug/debug-state';\nimport { BaseGlobals } from './game-interfaces';\nimport { convertNodes, GameOptions, hasStages, extractGlobalsFromOptions } from '../core/utility/nodes';\nimport { resolveGameConfig } from './game-config';\nimport { createStage, Stage } from '../stage/stage';\nimport { StageManager, stageState } from '../stage/stage-manager';\nimport { StageFactory } from '../stage/stage-factory';\nimport { initGlobals, clearGlobalSubscriptions, resetGlobals, onGlobalChange as onGlobalChangeInternal, onGlobalChanges as onGlobalChangesInternal } from './game-state';\n\nexport class Game<TGlobals extends BaseGlobals> implements IGame<TGlobals> {\n\tprivate wrappedGame: ZylemGame<TGlobals> | null = null;\n\n\toptions: GameOptions<TGlobals>;\n\n\t// Lifecycle callback arrays\n\tprivate setupCallbacks: Array<SetupFunction<ZylemGame<TGlobals>, TGlobals>> = [];\n\tprivate updateCallbacks: Array<UpdateFunction<ZylemGame<TGlobals>, TGlobals>> = [];\n\tprivate destroyCallbacks: Array<DestroyFunction<ZylemGame<TGlobals>, TGlobals>> = [];\n\tprivate pendingLoadingCallbacks: Array<(event: GameLoadingEvent) => void> = [];\n\n\t// Game-scoped global change subscriptions\n\tprivate globalChangeCallbacks: Array<{ path: string; callback: (value: unknown, stage: Stage | null) => void }> = [];\n\tprivate globalChangesCallbacks: Array<{ paths: string[]; callback: (values: unknown[], stage: Stage | null) => void }> = [];\n\tprivate activeGlobalSubscriptions: Array<() => void> = [];\n\n\trefErrorMessage = 'lost reference to game';\n\n\tconstructor(options: GameOptions<TGlobals>) {\n\t\tthis.options = options;\n\t\tif (!hasStages(options)) {\n\t\t\tthis.options.push(createStage());\n\t\t}\n\t\t// Initialize globals immediately so onGlobalChange subscriptions work\n\t\tconst globals = extractGlobalsFromOptions(options);\n\t\tif (globals) {\n\t\t\tinitGlobals(globals as Record<string, unknown>);\n\t\t}\n\t}\n\n\t// Fluent API for adding lifecycle callbacks\n\tonSetup(...callbacks: Array<SetupFunction<ZylemGame<TGlobals>, TGlobals>>): this {\n\t\tthis.setupCallbacks.push(...callbacks);\n\t\treturn this;\n\t}\n\n\tonUpdate(...callbacks: Array<UpdateFunction<ZylemGame<TGlobals>, TGlobals>>): this {\n\t\tthis.updateCallbacks.push(...callbacks);\n\t\treturn this;\n\t}\n\n\tonDestroy(...callbacks: Array<DestroyFunction<ZylemGame<TGlobals>, TGlobals>>): this {\n\t\tthis.destroyCallbacks.push(...callbacks);\n\t\treturn this;\n\t}\n\n\tasync start(): Promise<this> {\n\t\t// Re-initialize globals for this game\n\t\tresetGlobals();\n\t\tconst globals = extractGlobalsFromOptions(this.options);\n\t\tif (globals) {\n\t\t\tinitGlobals(globals as Record<string, unknown>);\n\t\t}\n\t\t\n\t\tconst game = await this.load();\n\t\tthis.wrappedGame = game;\n\t\tthis.setOverrides();\n\t\tthis.registerGlobalSubscriptions();\n\t\tgame.start();\n\t\treturn this;\n\t}\n\n\tprivate async load(): Promise<ZylemGame<TGlobals>> {\n\t\tconst options = await convertNodes<TGlobals>(this.options);\n\t\tconst resolved = resolveGameConfig(options as any);\n\t\tconst game = new ZylemGame<TGlobals>({\n\t\t\t...options as any,\n\t\t\t...resolved as any,\n\t\t} as any, this);\n\t\t\n\t\t// Apply pending loading callbacks BEFORE loadStage so events are captured\n\t\tfor (const callback of this.pendingLoadingCallbacks) {\n\t\t\tgame.onLoading(callback);\n\t\t}\n\t\t\n\t\tawait game.loadStage(options.stages[0]);\n\t\treturn game;\n\t}\n\n\tprivate setOverrides() {\n\t\tif (!this.wrappedGame) {\n\t\t\tconsole.error(this.refErrorMessage);\n\t\t\treturn;\n\t\t}\n\t\t// Pass callback arrays to wrapped game\n\t\tthis.wrappedGame.customSetup = (params) => {\n\t\t\tthis.setupCallbacks.forEach(cb => cb(params));\n\t\t};\n\t\tthis.wrappedGame.customUpdate = (params) => {\n\t\t\tthis.updateCallbacks.forEach(cb => cb(params));\n\t\t};\n\t\tthis.wrappedGame.customDestroy = (params) => {\n\t\t\tthis.destroyCallbacks.forEach(cb => cb(params));\n\t\t};\n\t}\n\n\t/**\n\t * Subscribe to changes on a global value. Subscriptions are registered\n\t * when the game starts and cleaned up when disposed.\n\t * The callback receives the value and the current stage.\n\t * @example game.onGlobalChange('score', (val, stage) => console.log(val));\n\t */\n\tonGlobalChange<T = unknown>(path: string, callback: (value: T, stage: Stage | null) => void): this {\n\t\tthis.globalChangeCallbacks.push({ path, callback: callback as (value: unknown, stage: Stage | null) => void });\n\t\treturn this;\n\t}\n\n\t/**\n\t * Subscribe to changes on multiple global paths. Subscriptions are registered\n\t * when the game starts and cleaned up when disposed.\n\t * The callback receives the values and the current stage.\n\t * @example game.onGlobalChanges(['score', 'lives'], ([score, lives], stage) => console.log(score, lives));\n\t */\n\tonGlobalChanges<T extends unknown[] = unknown[]>(paths: string[], callback: (values: T, stage: Stage | null) => void): this {\n\t\tthis.globalChangesCallbacks.push({ paths, callback: callback as (values: unknown[], stage: Stage | null) => void });\n\t\treturn this;\n\t}\n\n\t/**\n\t * Register all stored global change callbacks.\n\t * Called internally during start().\n\t */\n\tprivate registerGlobalSubscriptions() {\n\t\tfor (const { path, callback } of this.globalChangeCallbacks) {\n\t\t\tconst unsub = onGlobalChangeInternal(path, (value) => {\n\t\t\t\tcallback(value, this.getCurrentStage());\n\t\t\t});\n\t\t\tthis.activeGlobalSubscriptions.push(unsub);\n\t\t}\n\t\tfor (const { paths, callback } of this.globalChangesCallbacks) {\n\t\t\tconst unsub = onGlobalChangesInternal(paths, (values) => {\n\t\t\t\tcallback(values, this.getCurrentStage());\n\t\t\t});\n\t\t\tthis.activeGlobalSubscriptions.push(unsub);\n\t\t}\n\t}\n\n\t/**\n\t * Get the current stage wrapper.\n\t */\n\tgetCurrentStage(): Stage | null {\n\t\treturn this.wrappedGame?.currentStage() ?? null;\n\t}\n\n\tasync pause() {\n\t\tsetPaused(true);\n\t}\n\n\tasync resume() {\n\t\tsetPaused(false);\n\t\tif (this.wrappedGame) {\n\t\t\tthis.wrappedGame.previousTimeStamp = 0;\n\t\t\tthis.wrappedGame.timer.reset();\n\t\t}\n\t}\n\n\tasync reset() {\n\t\tif (!this.wrappedGame) {\n\t\t\tconsole.error(this.refErrorMessage);\n\t\t\treturn;\n\t\t}\n\t\tawait this.wrappedGame.loadStage(this.wrappedGame.stages[0]);\n\t}\n\n\tpreviousStage() {\n\t\tif (!this.wrappedGame) {\n\t\t\tconsole.error(this.refErrorMessage);\n\t\t\treturn;\n\t\t}\n\t\tconst currentStageId = this.wrappedGame.currentStageId;\n\t\tconst currentIndex = this.wrappedGame.stages.findIndex((s) => s.wrappedStage?.uuid === currentStageId);\n\t\tconst previousStage = this.wrappedGame.stages[currentIndex - 1];\n\t\tif (!previousStage) {\n\t\t\tconsole.error('previous stage called on first stage');\n\t\t\treturn;\n\t\t}\n\t\tthis.wrappedGame.loadStage(previousStage);\n\t}\n\n\tasync loadStageFromId(stageId: string) {\n\t\tif (!this.wrappedGame) {\n\t\t\tconsole.error(this.refErrorMessage);\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tconst blueprint = await StageManager.loadStageData(stageId);\n\t\t\tconst stage = await StageFactory.createFromBlueprint(blueprint);\n\t\t\tawait this.wrappedGame.loadStage(stage);\n\t\t\t\n\t\t\t// Update StageManager state\n\t\t\tstageState.current = blueprint;\n\t\t} catch (e) {\n\t\t\tconsole.error(`Failed to load stage ${stageId}`, e);\n\t\t}\n\t}\n\n\tnextStage() {\n\t\tif (!this.wrappedGame) {\n\t\t\tconsole.error(this.refErrorMessage);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t// Try to use StageManager first if we have a next stage in state\n\t\tif (stageState.next) {\n\t\t\tconst nextId = stageState.next.id;\n\t\t\tStageManager.transitionForward(nextId);\n\t\t\t// After transition, current is the new stage\n\t\t\tif (stageState.current) {\n\t\t\t\tStageFactory.createFromBlueprint(stageState.current).then((stage) => {\n\t\t\t\t\tthis.wrappedGame?.loadStage(stage);\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Fallback to legacy array-based navigation\n\t\tconst currentStageId = this.wrappedGame.currentStageId;\n\t\tconst currentIndex = this.wrappedGame.stages.findIndex((s) => s.wrappedStage?.uuid === currentStageId);\n\t\tconst nextStage = this.wrappedGame.stages[currentIndex + 1];\n\t\tif (!nextStage) {\n\t\t\tconsole.error('next stage called on last stage');\n\t\t\treturn;\n\t\t}\n\t\tthis.wrappedGame.loadStage(nextStage);\n\t}\n\n\tasync goToStage() { }\n\n\tasync end() { }\n\n\tdispose() {\n\t\t// Clear game-specific subscriptions\n\t\tfor (const unsub of this.activeGlobalSubscriptions) {\n\t\t\tunsub();\n\t\t}\n\t\tthis.activeGlobalSubscriptions = [];\n\t\t\n\t\tif (this.wrappedGame) {\n\t\t\tthis.wrappedGame.dispose();\n\t\t}\n\t\t// Clear all remaining global subscriptions and reset globals\n\t\tclearGlobalSubscriptions();\n\t\tresetGlobals();\n\t}\n\n\t/**\n\t * Subscribe to loading events from the game.\n\t * Events include stage context (stageName, stageIndex).\n\t * @param callback Invoked for each loading event\n\t * @returns Unsubscribe function\n\t */\n\tonLoading(callback: (event: GameLoadingEvent) => void): () => void {\n\t\tif (this.wrappedGame) {\n\t\t\treturn this.wrappedGame.onLoading(callback);\n\t\t}\n\t\t// Store callback to be applied when game is created\n\t\tthis.pendingLoadingCallbacks.push(callback);\n\t\treturn () => {\n\t\t\tthis.pendingLoadingCallbacks = this.pendingLoadingCallbacks.filter(c => c !== callback);\n\t\t\tif (this.wrappedGame) {\n\t\t\t\t// If already started, also unsubscribe from wrapped game\n\t\t\t\t// Note: this won't perfectly track existing subscriptions, but prevents future calls\n\t\t\t}\n\t\t};\n\t}\n}\n\n/**\n * create a new game\n * @param options GameOptions - Array of IGameOptions, Stage, GameEntity, or BaseNode objects\n * @param options.id Game name string (when using IGameOptions)\n * @param options.globals Game globals object (when using IGameOptions)\n * @param options.stages Array of stage objects (when using IGameOptions)\n * @returns Game\n */\nexport function createGame<TGlobals extends BaseGlobals>(...options: GameOptions<TGlobals>): Game<TGlobals> {\n\treturn new Game<TGlobals>(options);\n}","import { BaseNode } from '../base-node';\nimport { Stage } from '../../stage/stage';\nimport { GameEntity, GameEntityLifeCycle } from '../../entities/entity';\nimport { BaseGlobals, ZylemGameConfig } from '../../game/game-interfaces';\nimport { GameConfigLike } from '~/lib/game/game-config';\n\n// export function isStageContext(value: unknown): value is StageContext {\n// \treturn !!value && typeof value === 'object' && 'instance' in (value as any) && 'stageBlueprint' in (value as any);\n// }\n\nexport type GameOptions<TGlobals extends BaseGlobals> = Array<\n\tZylemGameConfig<Stage, any, TGlobals> |\n\tGameConfigLike |\n\tStage |\n\tGameEntityLifeCycle |\n\tBaseNode\n>;\n\nexport async function convertNodes<TGlobals extends BaseGlobals>(\n\t_options: GameOptions<TGlobals>\n): Promise<{ id: string, globals: TGlobals, stages: Stage[] }> {\n\tconst { getGameDefaultConfig } = await import('../../game/game-default');\n\tlet converted = { ...getGameDefaultConfig<TGlobals>() } as { id: string, globals: TGlobals, stages: Stage[] };\n\tconst configurations: ZylemGameConfig<Stage, any, TGlobals>[] = [];\n\tconst stages: Stage[] = [];\n\tconst entities: (BaseNode | GameEntity<any>)[] = [];\n\n\tObject.values(_options).forEach((node) => {\n\t\tif (node instanceof Stage) {\n\t\t\tstages.push(node);\n\t\t} else if (node instanceof GameEntity) {\n\t\t\tentities.push(node);\n\t\t} else if (node instanceof BaseNode) {\n\t\t\tentities.push(node);\n\t\t} else if ((node as any)?.constructor?.name === 'Object' && typeof node === 'object') {\n\t\t\tconst configuration = Object.assign({ ...getGameDefaultConfig<TGlobals>() }, { ...node });\n\t\t\tconfigurations.push(configuration as ZylemGameConfig<Stage, any, TGlobals>);\n\t\t}\n\t});\n\tconfigurations.forEach((configuration) => {\n\t\tconverted = Object.assign(converted, { ...configuration });\n\t});\n\tstages.forEach((stageInstance) => {\n\t\tstageInstance.addEntities(entities as BaseNode[]);\n\t});\n\tif (stages.length) {\n\t\tconverted.stages = stages;\n\t} else {\n\t\tconverted.stages[0].addEntities(entities as BaseNode[]);\n\t}\n\treturn converted as unknown as { id: string, globals: TGlobals, stages: Stage[] };\n}\n\nexport function hasStages<TGlobals extends BaseGlobals>(_options: GameOptions<TGlobals>): Boolean {\n\tconst stage = _options.find(option => option instanceof Stage);\n\treturn Boolean(stage);\n}\n\n/**\n * Extract globals object from game options array.\n * Used to initialize globals before game starts.\n */\nexport function extractGlobalsFromOptions<TGlobals extends BaseGlobals>(\n\t_options: GameOptions<TGlobals>\n): TGlobals | undefined {\n\tfor (const option of _options) {\n\t\tif (option && typeof option === 'object' && !(option instanceof Stage) && !(option instanceof BaseNode) && !(option instanceof GameEntity)) {\n\t\t\tconst config = option as ZylemGameConfig<Stage, any, TGlobals>;\n\t\t\tif (config.globals) {\n\t\t\t\treturn config.globals;\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}","import { proxy } from 'valtio/vanilla';\nimport { get, set } from 'idb-keyval';\nimport { pack, unpack } from 'msgpackr';\nimport { StageBlueprint } from '../core/blueprints';\n\n// The State\nexport const stageState = proxy({\n previous: null as StageBlueprint | null,\n current: null as StageBlueprint | null,\n next: null as StageBlueprint | null,\n isLoading: false,\n});\n\n// The Logic\nexport const StageManager = {\n staticRegistry: new Map<string, StageBlueprint>(),\n\n registerStaticStage(id: string, blueprint: StageBlueprint) {\n this.staticRegistry.set(id, blueprint);\n },\n\n async loadStageData(stageId: string): Promise<StageBlueprint> {\n // 1. Check Local Storage (User Save)\n try {\n const saved = await get(stageId);\n if (saved) {\n // msgpackr returns a buffer, we need to unpack it\n return unpack(saved);\n }\n } catch (e) {\n console.warn(`Failed to load stage ${stageId} from storage`, e);\n }\n\n // 2. Fallback to Static File (Initial Load)\n if (this.staticRegistry.has(stageId)) {\n return this.staticRegistry.get(stageId)!;\n }\n\n // Note: This assumes a convention where stages are importable.\n // You might need a registry or a specific path structure.\n // For now, we'll assume a dynamic import from a known location or a registry.\n // Since dynamic imports with variables can be tricky in bundlers, \n // we might need a map of stage IDs to import functions if the path isn't static enough.\n \n // TODO: Implement a robust way to resolve stage paths.\n // For now, throwing an error if not found in storage, as the static loading strategy \n // depends on project structure.\n throw new Error(`Stage ${stageId} not found in storage and static loading not fully implemented.`);\n },\n\n async transitionForward(nextStageId: string, loadStaticStage?: (id: string) => Promise<StageBlueprint>) {\n if (stageState.isLoading) return;\n \n stageState.isLoading = true;\n\n try {\n // Save current state to disk before unloading\n if (stageState.current) {\n await set(stageState.current.id, pack(stageState.current));\n }\n\n // Shift Window\n stageState.previous = stageState.current;\n stageState.current = stageState.next;\n \n // If we don't have a next stage preloaded (or if we just shifted it to current),\n // we might need to load the *new* next stage. \n // But the architecture doc says \"Fetch new Next\".\n // Let's assume we want to load the requested nextStageId as the *new Current* \n // if it wasn't already in 'next'. \n // Actually, the sliding window usually implies we move towards 'next'.\n // If 'next' was already populated with nextStageId, we just move it to 'current'.\n \n if (stageState.current?.id !== nextStageId) {\n // If the shift didn't result in the desired stage (e.g. we jumped), load it directly.\n // Or if 'next' was null.\n if (loadStaticStage) {\n stageState.current = await loadStaticStage(nextStageId);\n } else {\n stageState.current = await this.loadStageData(nextStageId);\n }\n }\n\n // Ideally we would pre-fetch the stage *after* this one into 'next'.\n // But we don't know what comes after 'nextStageId' without a map.\n // For now, we leave 'next' null or let the game logic trigger a preload.\n stageState.next = null; \n \n } catch (error) {\n console.error(\"Failed to transition stage:\", error);\n } finally {\n stageState.isLoading = false;\n }\n },\n \n /**\n * Manually set the next stage to pre-load it.\n */\n async preloadNext(stageId: string, loadStaticStage?: (id: string) => Promise<StageBlueprint>) {\n if (loadStaticStage) {\n stageState.next = await loadStaticStage(stageId);\n } else {\n stageState.next = await this.loadStageData(stageId);\n }\n }\n};\n","import { StageBlueprint } from '../core/blueprints';\nimport { createStage, Stage } from './stage';\nimport { EntityFactory } from '../entities/entity-factory';\n\nexport const StageFactory = {\n async createFromBlueprint(blueprint: StageBlueprint): Promise<Stage> {\n // Create a new Stage instance\n // We might need to pass options from blueprint if StageSchema has them\n const stage = createStage({\n // Map blueprint properties to stage options if needed\n // e.g. name: blueprint.name\n });\n \n // Assign ID if possible, though Stage might generate its own UUID.\n // If we want to track it by blueprint ID, we might need to store it on the stage.\n // stage.id = blueprint.id; // Stage doesn't have public ID setter easily maybe?\n\n if (blueprint.entities) {\n for (const entityBlueprint of blueprint.entities) {\n try {\n const entity = await EntityFactory.createFromBlueprint(entityBlueprint);\n stage.add(entity);\n } catch (e) {\n console.error(`Failed to create entity ${entityBlueprint.id} for stage ${blueprint.id}`, e);\n }\n }\n }\n\n return stage;\n }\n};\n","import { Color, Group, Sprite as ThreeSprite, SpriteMaterial, CanvasTexture, LinearFilter, Vector2, PerspectiveCamera, OrthographicCamera, ClampToEdgeWrapping } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { createEntity } from './create';\nimport { UpdateContext, SetupContext } from '../core/base-node-life-cycle';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { DebugDelegate } from './delegates/debug';\n\ntype ZylemTextOptions = GameEntityOptions & {\n\ttext?: string;\n\tfontFamily?: string;\n\tfontSize?: number;\n\tfontColor?: Color | string;\n\tbackgroundColor?: Color | string | null;\n\tpadding?: number;\n\tstickToViewport?: boolean;\n\tscreenPosition?: Vector2;\n\tzDistance?: number;\n};\n\nconst textDefaults: ZylemTextOptions = {\n\tposition: undefined,\n\ttext: '',\n\tfontFamily: 'Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace',\n\tfontSize: 18,\n\tfontColor: '#FFFFFF',\n\tbackgroundColor: null,\n\tpadding: 4,\n\tstickToViewport: true,\n\tscreenPosition: new Vector2(24, 24),\n\tzDistance: 1,\n};\n\nexport class TextBuilder extends EntityBuilder<ZylemText, ZylemTextOptions> {\n\tprotected createEntity(options: Partial<ZylemTextOptions>): ZylemText {\n\t\treturn new ZylemText(options);\n\t}\n}\n\nexport const TEXT_TYPE = Symbol('Text');\n\nexport class ZylemText extends GameEntity<ZylemTextOptions> {\n\tstatic type = TEXT_TYPE;\n\n\tprivate _sprite: ThreeSprite | null = null;\n\tprivate _texture: CanvasTexture | null = null;\n\tprivate _canvas: HTMLCanvasElement | null = null;\n\tprivate _ctx: CanvasRenderingContext2D | null = null;\n\tprivate _cameraRef: ZylemCamera | null = null;\n\tprivate _lastCanvasW: number = 0;\n\tprivate _lastCanvasH: number = 0;\n\n\tconstructor(options?: ZylemTextOptions) {\n\t\tsuper();\n\t\tthis.options = { ...textDefaults, ...options } as ZylemTextOptions;\n\t\t// Add text-specific lifecycle callbacks (only registered once)\n\t\tthis.prependSetup(this.textSetup.bind(this) as any);\n\t\tthis.prependUpdate(this.textUpdate.bind(this) as any);\n\t\tthis.onDestroy(this.textDestroy.bind(this) as any);\n\t}\n\n\tpublic create(): this {\n\t\t// Clear previous state to prevent issues on reload\n\t\tthis._sprite = null;\n\t\tthis._texture = null;\n\t\tthis._canvas = null;\n\t\tthis._ctx = null;\n\t\tthis._lastCanvasW = 0;\n\t\tthis._lastCanvasH = 0;\n\t\tthis.group = new Group();\n\t\t\n\t\t// Recreate the sprite\n\t\tthis.createSprite();\n\t\t\n\t\t// Call parent create\n\t\treturn super.create();\n\t}\n\n\tprivate createSprite() {\n\t\tthis._canvas = document.createElement('canvas');\n\t\tthis._ctx = this._canvas.getContext('2d');\n\t\tthis._texture = new CanvasTexture(this._canvas);\n\t\tthis._texture.minFilter = LinearFilter;\n\t\tthis._texture.magFilter = LinearFilter;\n\t\tconst material = new SpriteMaterial({\n\t\t\tmap: this._texture,\n\t\t\ttransparent: true,\n\t\t\tdepthTest: false,\n\t\t\tdepthWrite: false,\n\t\t\talphaTest: 0.5,\n\t\t});\n\t\tthis._sprite = new ThreeSprite(material);\n\t\tthis.group?.add(this._sprite);\n\t\tthis.redrawText(this.options.text ?? '');\n\t}\n\n\tprivate measureAndResizeCanvas(text: string, fontSize: number, fontFamily: string, padding: number) {\n\t\tif (!this._canvas || !this._ctx) return { sizeChanged: false };\n\t\tthis._ctx.font = `${fontSize}px ${fontFamily}`;\n\t\tconst metrics = this._ctx.measureText(text);\n\t\tconst textWidth = Math.ceil(metrics.width);\n\t\tconst textHeight = Math.ceil(fontSize * 1.4);\n\t\tconst nextW = Math.max(2, textWidth + padding * 2);\n\t\tconst nextH = Math.max(2, textHeight + padding * 2);\n\t\tconst sizeChanged = nextW !== this._lastCanvasW || nextH !== this._lastCanvasH;\n\t\tthis._canvas.width = nextW;\n\t\tthis._canvas.height = nextH;\n\t\tthis._lastCanvasW = nextW;\n\t\tthis._lastCanvasH = nextH;\n\t\treturn { sizeChanged };\n\t}\n\n\tprivate drawCenteredText(text: string, fontSize: number, fontFamily: string) {\n\t\tif (!this._canvas || !this._ctx) return;\n\t\tthis._ctx.font = `${fontSize}px ${fontFamily}`;\n\t\tthis._ctx.textAlign = 'center';\n\t\tthis._ctx.textBaseline = 'middle';\n\t\tthis._ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);\n\t\tif (this.options.backgroundColor) {\n\t\t\tthis._ctx.fillStyle = this.toCssColor(this.options.backgroundColor);\n\t\t\tthis._ctx.fillRect(0, 0, this._canvas.width, this._canvas.height);\n\t\t}\n\t\tthis._ctx.fillStyle = this.toCssColor(this.options.fontColor ?? '#FFFFFF');\n\t\tthis._ctx.fillText(text, this._canvas.width / 2, this._canvas.height / 2);\n\t}\n\n\tprivate updateTexture(sizeChanged: boolean) {\n\t\tif (!this._texture || !this._canvas) return;\n\t\tif (sizeChanged) {\n\t\t\tthis._texture.dispose();\n\t\t\tthis._texture = new CanvasTexture(this._canvas);\n\t\t\tthis._texture.minFilter = LinearFilter;\n\t\t\tthis._texture.magFilter = LinearFilter;\n\t\t\tthis._texture.wrapS = ClampToEdgeWrapping;\n\t\t\tthis._texture.wrapT = ClampToEdgeWrapping;\n\t\t}\n\t\tthis._texture.image = this._canvas;\n\t\tthis._texture.needsUpdate = true;\n\t\tif (this._sprite && this._sprite.material) {\n\t\t\t(this._sprite.material as any).map = this._texture;\n\t\t\tthis._sprite.material.needsUpdate = true;\n\t\t}\n\t}\n\n\tprivate redrawText(_text: string) {\n\t\tif (!this._canvas || !this._ctx) return;\n\t\tconst fontSize = this.options.fontSize ?? 18;\n\t\tconst fontFamily = this.options.fontFamily ?? (textDefaults.fontFamily as string);\n\t\tconst padding = this.options.padding ?? 4;\n\n\t\tconst { sizeChanged } = this.measureAndResizeCanvas(_text, fontSize, fontFamily, padding);\n\t\tthis.drawCenteredText(_text, fontSize, fontFamily);\n\t\tthis.updateTexture(Boolean(sizeChanged));\n\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tprivate toCssColor(color: Color | string): string {\n\t\tif (typeof color === 'string') return color;\n\t\tconst c = color instanceof Color ? color : new Color(color as any);\n\t\treturn `#${c.getHexString()}`;\n\t}\n\n\tprivate textSetup(params: SetupContext<ZylemTextOptions>) {\n\t\tthis._cameraRef = (params.camera as unknown) as ZylemCamera | null;\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\t(this._cameraRef.camera as any).add(this.group);\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tprivate textUpdate(params: UpdateContext<ZylemTextOptions>) {\n\t\tif (!this._sprite) return;\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tprivate getResolution() {\n\t\treturn {\n\t\t\twidth: this._cameraRef?.screenResolution.x ?? 1,\n\t\t\theight: this._cameraRef?.screenResolution.y ?? 1,\n\t\t};\n\t}\n\n\tprivate getScreenPixels(sp: Vector2, width: number, height: number) {\n\t\tconst isPercentX = sp.x >= 0 && sp.x <= 1;\n\t\tconst isPercentY = sp.y >= 0 && sp.y <= 1;\n\t\treturn {\n\t\t\tpx: isPercentX ? sp.x * width : sp.x,\n\t\t\tpy: isPercentY ? sp.y * height : sp.y,\n\t\t};\n\t}\n\n\tprivate computeWorldExtents(camera: PerspectiveCamera | OrthographicCamera, zDist: number) {\n\t\tlet worldHalfW = 1;\n\t\tlet worldHalfH = 1;\n\t\tif ((camera as PerspectiveCamera).isPerspectiveCamera) {\n\t\t\tconst pc = camera as PerspectiveCamera;\n\t\t\tconst halfH = Math.tan((pc.fov * Math.PI) / 180 / 2) * zDist;\n\t\t\tconst halfW = halfH * pc.aspect;\n\t\t\tworldHalfW = halfW;\n\t\t\tworldHalfH = halfH;\n\t\t} else if ((camera as OrthographicCamera).isOrthographicCamera) {\n\t\t\tconst oc = camera as OrthographicCamera;\n\t\t\tworldHalfW = (oc.right - oc.left) / 2;\n\t\t\tworldHalfH = (oc.top - oc.bottom) / 2;\n\t\t}\n\t\treturn { worldHalfW, worldHalfH };\n\t}\n\n\tprivate updateSpriteScale(worldHalfH: number, viewportHeight: number) {\n\t\tif (!this._canvas || !this._sprite) return;\n\t\tconst planeH = worldHalfH * 2;\n\t\tconst unitsPerPixel = planeH / viewportHeight;\n\t\tconst pixelH = this._canvas.height;\n\t\tconst scaleY = Math.max(0.0001, pixelH * unitsPerPixel);\n\t\tconst aspect = this._canvas.width / this._canvas.height;\n\t\tconst scaleX = scaleY * aspect;\n\t\tthis._sprite.scale.set(scaleX, scaleY, 1);\n\t}\n\n\tprivate updateStickyTransform() {\n\t\tif (!this._sprite || !this._cameraRef) return;\n\t\tconst camera = this._cameraRef.camera as PerspectiveCamera | OrthographicCamera;\n\t\tconst { width, height } = this.getResolution();\n\t\tconst sp = this.options.screenPosition ?? new Vector2(24, 24);\n\t\tconst { px, py } = this.getScreenPixels(sp, width, height);\n\t\tconst zDist = Math.max(0.001, this.options.zDistance ?? 1);\n\t\tconst { worldHalfW, worldHalfH } = this.computeWorldExtents(camera, zDist);\n\n\t\tconst ndcX = (px / width) * 2 - 1;\n\t\tconst ndcY = 1 - (py / height) * 2;\n\t\tconst localX = ndcX * worldHalfW;\n\t\tconst localY = ndcY * worldHalfH;\n\t\tthis.group?.position.set(localX, localY, -zDist);\n\t\tthis.updateSpriteScale(worldHalfH, height);\n\t}\n\n\tupdateText(_text: string) {\n\t\tthis.options.text = _text;\n\t\tthis.redrawText(_text);\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tbuildInfo(): Record<string, any> {\n\t\tconst delegate = new DebugDelegate(this as any);\n\t\tconst baseInfo = delegate.buildDebugInfo();\n\n\t\treturn {\n\t\t\t...baseInfo,\n\t\t\ttype: String(ZylemText.type),\n\t\t\ttext: this.options.text ?? '',\n\t\t\tsticky: this.options.stickToViewport,\n\t\t};\n\t}\n\n\t/**\n\t * Dispose of Three.js resources when the entity is destroyed.\n\t */\n\tprivate async textDestroy(): Promise<void> {\n\t\t// Dispose texture\n\t\tthis._texture?.dispose();\n\t\t\n\t\t// Dispose sprite material\n\t\tif (this._sprite?.material) {\n\t\t\t(this._sprite.material as SpriteMaterial).dispose();\n\t\t}\n\t\t\n\t\t// Remove sprite from group\n\t\tif (this._sprite) {\n\t\t\tthis._sprite.removeFromParent();\n\t\t}\n\t\t\n\t\t// Remove group from parent (camera or scene)\n\t\tthis.group?.removeFromParent();\n\t\t\n\t\t// Clear references\n\t\tthis._sprite = null;\n\t\tthis._texture = null;\n\t\tthis._canvas = null;\n\t\tthis._ctx = null;\n\t\tthis._cameraRef = null;\n\t}\n}\n\ntype TextOptions = BaseNode | Partial<ZylemTextOptions>;\n\nexport async function text(...args: Array<TextOptions>): Promise<ZylemText> {\n\treturn createEntity<ZylemText, ZylemTextOptions>({\n\t\targs,\n\t\tdefaultConfig: { ...textDefaults },\n\t\tEntityClass: ZylemText,\n\t\tBuilderClass: TextBuilder,\n\t\tentityType: ZylemText.type,\n\t});\n}\n\n\n","import { GameEntity, GameEntityOptions } from '../entity';\nimport { MeshStandardMaterial, MeshBasicMaterial, MeshPhongMaterial } from 'three';\n\n/**\n * Interface for entities that provide custom debug information\n */\nexport interface DebugInfoProvider {\n\tgetDebugInfo(): Record<string, any>;\n}\n\n/**\n * Helper to check if an object implements DebugInfoProvider\n */\nfunction hasDebugInfo(obj: any): obj is DebugInfoProvider {\n\treturn obj && typeof obj.getDebugInfo === 'function';\n}\n\n/**\n * Debug delegate that provides debug information for entities\n */\nexport class DebugDelegate {\n\tprivate entity: GameEntity<any>;\n\n\tconstructor(entity: GameEntity<any>) {\n\t\tthis.entity = entity;\n\t}\n\n\t/**\n\t * Get formatted position string\n\t */\n\tprivate getPositionString(): string {\n\t\tif (this.entity.mesh) {\n\t\t\tconst { x, y, z } = this.entity.mesh.position;\n\t\t\treturn `${x.toFixed(2)}, ${y.toFixed(2)}, ${z.toFixed(2)}`;\n\t\t}\n\t\tconst { x, y, z } = this.entity.options.position || { x: 0, y: 0, z: 0 };\n\t\treturn `${x.toFixed(2)}, ${y.toFixed(2)}, ${z.toFixed(2)}`;\n\t}\n\n\t/**\n\t * Get formatted rotation string (in degrees)\n\t */\n\tprivate getRotationString(): string {\n\t\tif (this.entity.mesh) {\n\t\t\tconst { x, y, z } = this.entity.mesh.rotation;\n\t\t\tconst toDeg = (rad: number) => (rad * 180 / Math.PI).toFixed(1);\n\t\t\treturn `${toDeg(x)}°, ${toDeg(y)}°, ${toDeg(z)}°`;\n\t\t}\n\t\tconst { x, y, z } = this.entity.options.rotation || { x: 0, y: 0, z: 0 };\n\t\tconst toDeg = (rad: number) => (rad * 180 / Math.PI).toFixed(1);\n\t\treturn `${toDeg(x)}°, ${toDeg(y)}°, ${toDeg(z)}°`;\n\t}\n\n\t/**\n\t * Get material information\n\t */\n\tprivate getMaterialInfo(): Record<string, any> {\n\t\tif (!this.entity.mesh || !this.entity.mesh.material) {\n\t\t\treturn { type: 'none' };\n\t\t}\n\n\t\tconst material = Array.isArray(this.entity.mesh.material)\n\t\t\t? this.entity.mesh.material[0]\n\t\t\t: this.entity.mesh.material;\n\n\t\tconst info: Record<string, any> = {\n\t\t\ttype: material.type\n\t\t};\n\n\t\tif (material instanceof MeshStandardMaterial ||\n\t\t\tmaterial instanceof MeshBasicMaterial ||\n\t\t\tmaterial instanceof MeshPhongMaterial) {\n\t\t\tinfo.color = `#${material.color.getHexString()}`;\n\t\t\tinfo.opacity = material.opacity;\n\t\t\tinfo.transparent = material.transparent;\n\t\t}\n\n\t\tif ('roughness' in material) {\n\t\t\tinfo.roughness = material.roughness;\n\t\t}\n\n\t\tif ('metalness' in material) {\n\t\t\tinfo.metalness = material.metalness;\n\t\t}\n\n\t\treturn info;\n\t}\n\n\tprivate getPhysicsInfo(): Record<string, any> | null {\n\t\tif (!this.entity.body) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst info: Record<string, any> = {\n\t\t\ttype: this.entity.body.bodyType(),\n\t\t\tmass: this.entity.body.mass(),\n\t\t\tisEnabled: this.entity.body.isEnabled(),\n\t\t\tisSleeping: this.entity.body.isSleeping()\n\t\t};\n\n\t\tconst velocity = this.entity.body.linvel();\n\t\tinfo.velocity = `${velocity.x.toFixed(2)}, ${velocity.y.toFixed(2)}, ${velocity.z.toFixed(2)}`;\n\n\t\treturn info;\n\t}\n\n\tpublic buildDebugInfo(): Record<string, any> {\n\t\tconst defaultInfo: Record<string, any> = {\n\t\t\tname: this.entity.name || this.entity.uuid,\n\t\t\tuuid: this.entity.uuid,\n\t\t\tposition: this.getPositionString(),\n\t\t\trotation: this.getRotationString(),\n\t\t\tmaterial: this.getMaterialInfo()\n\t\t};\n\n\t\tconst physicsInfo = this.getPhysicsInfo();\n\t\tif (physicsInfo) {\n\t\t\tdefaultInfo.physics = physicsInfo;\n\t\t}\n\n\t\tif (this.entity.behaviors.length > 0) {\n\t\t\tdefaultInfo.behaviors = this.entity.behaviors.map(b => b.constructor.name);\n\t\t}\n\n\t\tif (hasDebugInfo(this.entity)) {\n\t\t\tconst customInfo = this.entity.getDebugInfo();\n\t\t\treturn { ...defaultInfo, ...customInfo };\n\t\t}\n\n\t\treturn defaultInfo;\n\t}\n}\n\nclass EnhancedDebugInfoBuilder {\n\tprivate customBuilder?: (options: GameEntityOptions) => Record<string, any>;\n\n\tconstructor(customBuilder?: (options: GameEntityOptions) => Record<string, any>) {\n\t\tthis.customBuilder = customBuilder;\n\t}\n\n\tbuildInfo(options: GameEntityOptions, entity?: GameEntity<any>): Record<string, any> {\n\t\tif (this.customBuilder) {\n\t\t\treturn this.customBuilder(options);\n\t\t}\n\n\t\tif (entity) {\n\t\t\tconst delegate = new DebugDelegate(entity);\n\t\t\treturn delegate.buildDebugInfo();\n\t\t}\n\n\t\tconst { x, y, z } = options.position || { x: 0, y: 0, z: 0 };\n\t\treturn {\n\t\t\tname: (options as any).name || 'unnamed',\n\t\t\tposition: `${x.toFixed(2)}, ${y.toFixed(2)}, ${z.toFixed(2)}`\n\t\t};\n\t}\n}\n","import { ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { Color, Euler, Group, Quaternion, Vector3 } from 'three';\nimport {\n\tTextureLoader,\n\tSpriteMaterial,\n\tSprite as ThreeSprite,\n} from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { createEntity } from './create';\nimport { DestroyContext, DestroyFunction, UpdateContext, UpdateFunction } from '../core/base-node-life-cycle';\nimport { DebugDelegate } from './delegates/debug';\n\nexport type SpriteImage = { name: string; file: string };\nexport type SpriteAnimation = {\n\tname: string;\n\tframes: string[];\n\tspeed: number | number[];\n\tloop: boolean;\n};\n\ntype ZylemSpriteOptions = GameEntityOptions & {\n\timages?: SpriteImage[];\n\tanimations?: SpriteAnimation[];\n\tsize?: Vector3;\n\tcollisionSize?: Vector3;\n};\n\nconst spriteDefaults: ZylemSpriteOptions = {\n\tsize: new Vector3(1, 1, 1),\n\tposition: new Vector3(0, 0, 0),\n\tcollision: {\n\t\tstatic: false,\n\t},\n\tmaterial: {\n\t\tcolor: new Color('#ffffff'),\n\t\tshader: 'standard'\n\t},\n\timages: [],\n\tanimations: [],\n};\n\nexport class SpriteCollisionBuilder extends EntityCollisionBuilder {\n\tcollider(options: ZylemSpriteOptions): ColliderDesc {\n\t\tconst size = options.collisionSize || options.size || new Vector3(1, 1, 1);\n\t\tconst half = { x: size.x / 2, y: size.y / 2, z: size.z / 2 };\n\t\tlet colliderDesc = ColliderDesc.cuboid(half.x, half.y, half.z);\n\t\treturn colliderDesc;\n\t}\n}\n\nexport class SpriteBuilder extends EntityBuilder<ZylemSprite, ZylemSpriteOptions> {\n\tprotected createEntity(options: Partial<ZylemSpriteOptions>): ZylemSprite {\n\t\treturn new ZylemSprite(options);\n\t}\n}\n\nexport const SPRITE_TYPE = Symbol('Sprite');\n\nexport class ZylemSprite extends GameEntity<ZylemSpriteOptions> {\n\tstatic type = SPRITE_TYPE;\n\n\tprotected sprites: ThreeSprite[] = [];\n\tprotected spriteMap: Map<string, number> = new Map();\n\tprotected currentSpriteIndex: number = 0;\n\tprotected animations: Map<string, any> = new Map();\n\tprotected currentAnimation: any = null;\n\tprotected currentAnimationFrame: string = '';\n\tprotected currentAnimationIndex: number = 0;\n\tprotected currentAnimationTime: number = 0;\n\n\tconstructor(options?: ZylemSpriteOptions) {\n\t\tsuper();\n\t\tthis.options = { ...spriteDefaults, ...options };\n\t\t// Add sprite-specific lifecycle callbacks (only registered once)\n\t\tthis.prependUpdate(this.spriteUpdate.bind(this) as any);\n\t\tthis.onDestroy(this.spriteDestroy.bind(this) as any);\n\t}\n\n\tpublic create(): this {\n\t\t// Clear previous state to prevent accumulation on reload\n\t\tthis.sprites = [];\n\t\tthis.spriteMap.clear();\n\t\tthis.animations.clear();\n\t\tthis.currentAnimation = null;\n\t\tthis.currentAnimationFrame = '';\n\t\tthis.currentAnimationIndex = 0;\n\t\tthis.currentAnimationTime = 0;\n\t\tthis.group = undefined;\n\t\t\n\t\t// Recreate sprites and animations\n\t\tthis.createSpritesFromImages(this.options?.images || []);\n\t\tthis.createAnimations(this.options?.animations || []);\n\t\t\n\t\t// Call parent create\n\t\treturn super.create();\n\t}\n\n\tprotected createSpritesFromImages(images: SpriteImage[]) {\n\t\tconst textureLoader = new TextureLoader();\n\t\timages.forEach((image, index) => {\n\t\t\tconst spriteMap = textureLoader.load(image.file);\n\t\t\tconst material = new SpriteMaterial({\n\t\t\t\tmap: spriteMap,\n\t\t\t\ttransparent: true,\n\t\t\t});\n\t\t\tconst _sprite = new ThreeSprite(material);\n\t\t\t_sprite.position.normalize();\n\t\t\tthis.sprites.push(_sprite);\n\t\t\tthis.spriteMap.set(image.name, index);\n\t\t});\n\t\tthis.group = new Group();\n\t\tthis.group.add(...this.sprites);\n\t}\n\n\tprotected createAnimations(animations: SpriteAnimation[]) {\n\t\tanimations.forEach(animation => {\n\t\t\tconst { name, frames, loop = false, speed = 1 } = animation;\n\t\t\tconst internalAnimation = {\n\t\t\t\tframes: frames.map((frame, index) => ({\n\t\t\t\t\tkey: frame,\n\t\t\t\t\tindex,\n\t\t\t\t\ttime: (typeof speed === 'number' ? speed : speed[index]) * (index + 1),\n\t\t\t\t\tduration: typeof speed === 'number' ? speed : speed[index]\n\t\t\t\t})),\n\t\t\t\tloop,\n\t\t\t};\n\t\t\tthis.animations.set(name, internalAnimation);\n\t\t});\n\t}\n\n\tsetSprite(key: string) {\n\t\tconst spriteIndex = this.spriteMap.get(key);\n\t\tconst useIndex = spriteIndex ?? 0;\n\t\tthis.currentSpriteIndex = useIndex;\n\t\tthis.sprites.forEach((_sprite, i) => {\n\t\t\t_sprite.visible = this.currentSpriteIndex === i;\n\t\t});\n\t}\n\n\tsetAnimation(name: string, delta: number) {\n\t\tconst animation = this.animations.get(name);\n\t\tif (!animation) return;\n\n\t\tconst { loop, frames } = animation;\n\t\tconst frame = frames[this.currentAnimationIndex];\n\n\t\tif (name === this.currentAnimation) {\n\t\t\tthis.currentAnimationFrame = frame.key;\n\t\t\tthis.currentAnimationTime += delta;\n\t\t\tthis.setSprite(this.currentAnimationFrame);\n\t\t} else {\n\t\t\tthis.currentAnimation = name;\n\t\t}\n\n\t\tif (this.currentAnimationTime > frame.time) {\n\t\t\tthis.currentAnimationIndex++;\n\t\t}\n\n\t\tif (this.currentAnimationIndex >= frames.length) {\n\t\t\tif (loop) {\n\t\t\t\tthis.currentAnimationIndex = 0;\n\t\t\t\tthis.currentAnimationTime = 0;\n\t\t\t} else {\n\t\t\t\tthis.currentAnimationTime = frames[this.currentAnimationIndex].time;\n\t\t\t}\n\t\t}\n\t}\n\n\tasync spriteUpdate(params: UpdateContext<ZylemSpriteOptions>): Promise<void> {\n\t\tthis.sprites.forEach(_sprite => {\n\t\t\tif (_sprite.material) {\n\t\t\t\tconst q = this.body?.rotation();\n\t\t\t\tif (q) {\n\t\t\t\t\tconst quat = new Quaternion(q.x, q.y, q.z, q.w);\n\t\t\t\t\tconst euler = new Euler().setFromQuaternion(quat, 'XYZ');\n\t\t\t\t\t_sprite.material.rotation = euler.z;\n\t\t\t\t}\n\t\t\t\t_sprite.scale.set(this.options.size?.x ?? 1, this.options.size?.y ?? 1, this.options.size?.z ?? 1);\n\t\t\t}\n\t\t});\n\t}\n\n\tasync spriteDestroy(params: DestroyContext<ZylemSpriteOptions>): Promise<void> {\n\t\tthis.sprites.forEach(_sprite => {\n\t\t\t_sprite.removeFromParent();\n\t\t});\n\t\tthis.group?.remove(...this.sprites);\n\t\tthis.group?.removeFromParent();\n\t}\n\n\tbuildInfo(): Record<string, any> {\n\t\tconst delegate = new DebugDelegate(this as any);\n\t\tconst baseInfo = delegate.buildDebugInfo();\n\t\treturn {\n\t\t\t...baseInfo,\n\t\t\ttype: String(ZylemSprite.type),\n\t\t};\n\t}\n}\n\ntype SpriteOptions = BaseNode | Partial<ZylemSpriteOptions>;\n\nexport async function sprite(...args: Array<SpriteOptions>): Promise<ZylemSprite> {\n\treturn createEntity<ZylemSprite, ZylemSpriteOptions>({\n\t\targs,\n\t\tdefaultConfig: spriteDefaults,\n\t\tEntityClass: ZylemSprite,\n\t\tBuilderClass: SpriteBuilder,\n\t\tCollisionBuilderClass: SpriteCollisionBuilder,\n\t\tentityType: ZylemSprite.type\n\t});\n}","import { EntityBlueprint } from '../core/blueprints';\nimport { GameEntity, GameEntityOptions } from './entity';\nimport { text } from './text';\nimport { sprite } from './sprite';\n\ntype EntityCreator = (options: any) => Promise<GameEntity<any>>;\n\nexport const EntityFactory = {\n registry: new Map<string, EntityCreator>(),\n\n register(type: string, creator: EntityCreator) {\n this.registry.set(type, creator);\n },\n\n async createFromBlueprint(blueprint: EntityBlueprint): Promise<GameEntity<any>> {\n const creator = this.registry.get(blueprint.type);\n if (!creator) {\n throw new Error(`Unknown entity type: ${blueprint.type}`);\n }\n\n const options: GameEntityOptions = {\n ...blueprint.data,\n position: blueprint.position ? { x: blueprint.position[0], y: blueprint.position[1], z: 0 } : undefined,\n name: blueprint.id,\n };\n\n const entity = await creator(options);\n \n return entity;\n }\n};\n\nEntityFactory.register('text', async (opts) => await text(opts) as unknown as GameEntity<any>);\nEntityFactory.register('sprite', async (opts) => await sprite(opts) as unknown as GameEntity<any>);\n","// Core game functionality\nexport { createGame, Game } from '../lib/game/game';\nexport type { ZylemGameConfig } from '../lib/game/game-interfaces';\nexport { gameConfig } from '../lib/game/game-config';\n\nexport { createStage } from '../lib/stage/stage';\nexport { entitySpawner } from '../lib/stage/entity-spawner';\nexport type { StageOptions, LoadingEvent } from '../lib/stage/zylem-stage';\nexport type { StageBlueprint } from '../lib/core/blueprints';\nexport { StageManager, stageState } from '../lib/stage/stage-manager';\n\nexport { vessel } from '../lib/core/vessel';\n\n// Camera\nexport { camera } from '../lib/camera/camera';\nexport type { PerspectiveType } from '../lib/camera/perspective';\nexport { Perspectives } from '../lib/camera/perspective';\n\n// Utility types\nexport type { Vect3 } from '../lib/core/utility/vector';\n\n// Entities\nexport { box } from '../lib/entities/box';\nexport { sphere } from '../lib/entities/sphere';\nexport { sprite } from '../lib/entities/sprite';\nexport { plane } from '../lib/entities/plane';\nexport { zone } from '../lib/entities/zone';\nexport { actor } from '../lib/entities/actor';\nexport { text } from '../lib/entities/text';\nexport { rect } from '../lib/entities/rect';\nexport { ZylemBox } from '../lib/entities/box';\n\n// Behaviors\nexport type { Behavior } from '../lib/actions/behaviors/behavior';\nexport { ricochet2DInBounds } from '../lib/actions/behaviors/ricochet/ricochet-2d-in-bounds';\nexport { ricochet2DCollision } from '../lib/actions/behaviors/ricochet/ricochet-2d-collision';\nexport { boundary2d } from '../lib/actions/behaviors/boundaries/boundary';\nexport { movementSequence2D } from '../lib/actions/behaviors/movement/movement-sequence-2d';\n\n// Capabilities\nexport { makeMoveable } from '../lib/actions/capabilities/moveable';\nexport { makeRotatable } from '../lib/actions/capabilities/rotatable';\nexport { makeTransformable } from '../lib/actions/capabilities/transformable';\nexport { rotatable } from '../lib/actions/capabilities/rotatable';\nexport { moveable } from '../lib/actions/capabilities/moveable';\nexport { rotateInDirection } from '../lib/actions/capabilities/rotatable';\nexport { move } from '../lib/actions/capabilities/moveable';\nexport { resetVelocity } from '../lib/actions/capabilities/moveable';\n\n\n// Destruction utilities\n// Destruction utilities\nexport { destroy } from '../lib/entities/destroy';\n\n// Sounds\nexport { ricochetSound, pingPongBeep } from '../lib/sounds';\n\n// External dependencies - these will be in separate vendor chunks\nexport { Howl } from 'howler';\nexport * as THREE from 'three';\nexport * as RAPIER from '@dimforge/rapier3d-compat';\n\n// Update helpers\nexport { globalChange, globalChanges, variableChange, variableChanges } from '../lib/actions/global-change';\n\n// State management - standalone functions\nexport { setGlobal, getGlobal, createGlobal, onGlobalChange, onGlobalChanges, getGlobals, clearGlobalSubscriptions } from '../lib/game/game-state';\nexport { setVariable, getVariable, createVariable, onVariableChange, onVariableChanges } from '../lib/stage/stage-state';\n\n// Debug state - exposed for direct mutation by editor integration\nexport { debugState, setDebugTool, setPaused, type DebugTools } from '../lib/debug/debug-state';\n\n// Web Components\nexport { ZylemGameElement, type ZylemGameState } from '../web-components/zylem-game';\n\n// Lifecycle types\nexport type { SetupContext, UpdateContext } from '../lib/core/base-node-life-cycle';\n\n// Interfaces\nexport type { StageEntity } from '../lib/interfaces/entity';\n\n// Entity type symbols for getEntityByName type inference\nexport { \n\tTEXT_TYPE, SPRITE_TYPE, BOX_TYPE, SPHERE_TYPE, \n\tRECT_TYPE, PLANE_TYPE, ZONE_TYPE, ACTOR_TYPE \n} from '../lib/types/entity-type-map';\n","import { Euler, Quaternion, Vector2 } from \"three\";\nimport { GameEntity } from \"../entities\";\nimport { Stage } from \"./stage\";\n\nexport interface EntitySpawner {\n\tspawn: (stage: Stage, x: number, y: number) => Promise<GameEntity<any>>;\n\tspawnRelative: (source: any, stage: Stage, offset?: Vector2) => Promise<any | void>;\n}\n\nexport function entitySpawner(factory: (x: number, y: number) => Promise<any> | GameEntity<any>): EntitySpawner {\n\treturn {\n\t\tspawn: async (stage: Stage, x: number, y: number) => {\n\t\t\tconst instance = await Promise.resolve(factory(x, y));\n\t\t\tstage.add(instance);\n\t\t\treturn instance;\n\t\t},\n\t\tspawnRelative: async (source: any, stage: Stage, offset: Vector2 = new Vector2(0, 1)) => {\n\t\t\tif (!source.body) {\n\t\t\t\tconsole.warn('body missing for entity during spawnRelative');\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst { x, y, z } = source.body.translation();\n\t\t\tlet rz = (source as any)._rotation2DAngle ?? 0;\n\t\t\ttry {\n\t\t\t\tconst r = source.body.rotation();\n\t\t\t\tconst q = new Quaternion(r.x, r.y, r.z, r.w);\n\t\t\t\tconst e = new Euler().setFromQuaternion(q, 'XYZ');\n\t\t\t\trz = e.z;\n\t\t\t} catch { /* use fallback angle */ }\n\n\t\t\tconst offsetX = Math.sin(-rz) * (offset.x ?? 0);\n\t\t\tconst offsetY = Math.cos(-rz) * (offset.y ?? 0);\n\n\t\t\tconst instance = await Promise.resolve(factory(x + offsetX, y + offsetY));\n\t\t\tstage.add(instance);\n\t\t\treturn instance;\n\t\t}\n\t};\n}","import { BaseNode } from './base-node';\nimport {\n\tSetupContext,\n\tUpdateContext,\n\tDestroyContext,\n\tLoadedContext,\n\tCleanupContext,\n} from './base-node-life-cycle';\n\nconst VESSEL_TYPE = Symbol('vessel');\n\nexport class Vessel extends BaseNode<{}, Vessel> {\n\tstatic type = VESSEL_TYPE;\n\n\tprotected _setup(_params: SetupContext<this>): void { }\n\n\tprotected async _loaded(_params: LoadedContext<this>): Promise<void> { }\n\n\tprotected _update(_params: UpdateContext<this>): void { }\n\n\tprotected _destroy(_params: DestroyContext<this>): void { }\n\n\tprotected async _cleanup(_params: CleanupContext<this>): Promise<void> { }\n\n\tpublic create(): this {\n\t\treturn this;\n\t}\n}\n\nexport function vessel(...args: Array<BaseNode>): BaseNode<{}, Vessel> {\n\tconst instance = new Vessel();\n\targs.forEach(arg => instance.add(arg));\n\treturn instance as unknown as BaseNode<{}, Vessel>;\n}\n","import { ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { BoxGeometry, Color } from 'three';\nimport { Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { EntityMeshBuilder } from './builder';\nimport { DebugDelegate } from './delegates/debug';\nimport { createEntity } from './create';\n\ntype ZylemBoxOptions = GameEntityOptions;\n\nconst boxDefaults: ZylemBoxOptions = {\n\tsize: new Vector3(1, 1, 1),\n\tposition: new Vector3(0, 0, 0),\n\tcollision: {\n\t\tstatic: false,\n\t},\n\tmaterial: {\n\t\tcolor: new Color('#ffffff'),\n\t\tshader: 'standard'\n\t},\n};\n\nexport class BoxCollisionBuilder extends EntityCollisionBuilder {\n\tcollider(options: GameEntityOptions): ColliderDesc {\n\t\tconst size = options.size || new Vector3(1, 1, 1);\n\t\tconst half = { x: size.x / 2, y: size.y / 2, z: size.z / 2 };\n\t\tlet colliderDesc = ColliderDesc.cuboid(half.x, half.y, half.z);\n\t\treturn colliderDesc;\n\t}\n}\n\nexport class BoxMeshBuilder extends EntityMeshBuilder {\n\tbuild(options: GameEntityOptions): BoxGeometry {\n\t\tconst size = options.size ?? new Vector3(1, 1, 1);\n\t\treturn new BoxGeometry(size.x, size.y, size.z);\n\t}\n}\n\nexport class BoxBuilder extends EntityBuilder<ZylemBox, ZylemBoxOptions> {\n\tprotected createEntity(options: Partial<ZylemBoxOptions>): ZylemBox {\n\t\treturn new ZylemBox(options);\n\t}\n}\n\nexport const BOX_TYPE = Symbol('Box');\n\nexport class ZylemBox extends GameEntity<ZylemBoxOptions> {\n\tstatic type = BOX_TYPE;\n\n\tconstructor(options?: ZylemBoxOptions) {\n\t\tsuper();\n\t\tthis.options = { ...boxDefaults, ...options };\n\t}\n\n\tbuildInfo(): Record<string, any> {\n\t\tconst delegate = new DebugDelegate(this as any);\n\t\tconst baseInfo = delegate.buildDebugInfo();\n\n\t\tconst { x: sizeX, y: sizeY, z: sizeZ } = this.options.size ?? { x: 1, y: 1, z: 1 };\n\t\treturn {\n\t\t\t...baseInfo,\n\t\t\ttype: String(ZylemBox.type),\n\t\t\tsize: `${sizeX}, ${sizeY}, ${sizeZ}`,\n\t\t};\n\t}\n}\n\ntype BoxOptions = BaseNode | ZylemBoxOptions;\n\nexport async function box(...args: Array<BoxOptions>): Promise<ZylemBox> {\n\treturn createEntity<ZylemBox, ZylemBoxOptions>({\n\t\targs,\n\t\tdefaultConfig: boxDefaults,\n\t\tEntityClass: ZylemBox,\n\t\tBuilderClass: BoxBuilder,\n\t\tMeshBuilderClass: BoxMeshBuilder,\n\t\tCollisionBuilderClass: BoxCollisionBuilder,\n\t\tentityType: ZylemBox.type\n\t});\n}","import { ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { Color, SphereGeometry } from 'three';\nimport { Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { EntityMeshBuilder } from './builder';\nimport { DebugDelegate } from './delegates/debug';\nimport { createEntity } from './create';\n\ntype ZylemSphereOptions = GameEntityOptions & {\n\tradius?: number;\n};\n\nconst sphereDefaults: ZylemSphereOptions = {\n\tradius: 1,\n\tposition: new Vector3(0, 0, 0),\n\tcollision: {\n\t\tstatic: false,\n\t},\n\tmaterial: {\n\t\tcolor: new Color('#ffffff'),\n\t\tshader: 'standard'\n\t},\n};\n\nexport class SphereCollisionBuilder extends EntityCollisionBuilder {\n\tcollider(options: ZylemSphereOptions): ColliderDesc {\n\t\tconst radius = options.radius ?? 1;\n\t\tlet colliderDesc = ColliderDesc.ball(radius);\n\t\treturn colliderDesc;\n\t}\n}\n\nexport class SphereMeshBuilder extends EntityMeshBuilder {\n\tbuild(options: ZylemSphereOptions): SphereGeometry {\n\t\tconst radius = options.radius ?? 1;\n\t\treturn new SphereGeometry(radius);\n\t}\n}\n\nexport class SphereBuilder extends EntityBuilder<ZylemSphere, ZylemSphereOptions> {\n\tprotected createEntity(options: Partial<ZylemSphereOptions>): ZylemSphere {\n\t\treturn new ZylemSphere(options);\n\t}\n}\n\nexport const SPHERE_TYPE = Symbol('Sphere');\n\nexport class ZylemSphere extends GameEntity<ZylemSphereOptions> {\n\tstatic type = SPHERE_TYPE;\n\n\tconstructor(options?: ZylemSphereOptions) {\n\t\tsuper();\n\t\tthis.options = { ...sphereDefaults, ...options };\n\t}\n\n\tbuildInfo(): Record<string, any> {\n\t\tconst delegate = new DebugDelegate(this as any);\n\t\tconst baseInfo = delegate.buildDebugInfo();\n\t\tconst radius = this.options.radius ?? 1;\n\t\treturn {\n\t\t\t...baseInfo,\n\t\t\ttype: String(ZylemSphere.type),\n\t\t\tradius: radius.toFixed(2),\n\t\t};\n\t}\n}\n\ntype SphereOptions = BaseNode | Partial<ZylemSphereOptions>;\n\nexport async function sphere(...args: Array<SphereOptions>): Promise<ZylemSphere> {\n\treturn createEntity<ZylemSphere, ZylemSphereOptions>({\n\t\targs,\n\t\tdefaultConfig: sphereDefaults,\n\t\tEntityClass: ZylemSphere,\n\t\tBuilderClass: SphereBuilder,\n\t\tMeshBuilderClass: SphereMeshBuilder,\n\t\tCollisionBuilderClass: SphereCollisionBuilder,\n\t\tentityType: ZylemSphere.type\n\t});\n}","import { ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { Color, PlaneGeometry, Vector2, Vector3 } from 'three';\nimport { TexturePath } from '../graphics/material';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { EntityMeshBuilder } from './builder';\nimport { XZPlaneGeometry } from '../graphics/geometries/XZPlaneGeometry';\nimport { createEntity } from './create';\n\ntype ZylemPlaneOptions = GameEntityOptions & {\n\ttile?: Vector2;\n\trepeat?: Vector2;\n\ttexture?: TexturePath;\n\tsubdivisions?: number;\n};\n\nconst DEFAULT_SUBDIVISIONS = 4;\n\nconst planeDefaults: ZylemPlaneOptions = {\n\ttile: new Vector2(10, 10),\n\trepeat: new Vector2(1, 1),\n\tposition: new Vector3(0, 0, 0),\n\tcollision: {\n\t\tstatic: true,\n\t},\n\tmaterial: {\n\t\tcolor: new Color('#ffffff'),\n\t\tshader: 'standard'\n\t},\n\tsubdivisions: DEFAULT_SUBDIVISIONS\n};\n\nexport class PlaneCollisionBuilder extends EntityCollisionBuilder {\n\tcollider(options: ZylemPlaneOptions): ColliderDesc {\n\t\tconst tile = options.tile ?? new Vector2(1, 1);\n\t\tconst subdivisions = options.subdivisions ?? DEFAULT_SUBDIVISIONS;\n\t\tconst size = new Vector3(tile.x, 1, tile.y);\n\n\t\tconst heightData = (options._builders?.meshBuilder as unknown as PlaneMeshBuilder)?.heightData;\n\t\tconst scale = new Vector3(size.x, 1, size.z);\n\t\tlet colliderDesc = ColliderDesc.heightfield(\n\t\t\tsubdivisions,\n\t\t\tsubdivisions,\n\t\t\theightData,\n\t\t\tscale\n\t\t);\n\n\t\treturn colliderDesc;\n\t}\n}\n\nexport class PlaneMeshBuilder extends EntityMeshBuilder {\n\theightData: Float32Array = new Float32Array();\n\tcolumnsRows = new Map();\n\n\tbuild(options: ZylemPlaneOptions): XZPlaneGeometry {\n\t\tconst tile = options.tile ?? new Vector2(1, 1);\n\t\tconst subdivisions = options.subdivisions ?? DEFAULT_SUBDIVISIONS;\n\t\tconst size = new Vector3(tile.x, 1, tile.y);\n\n\t\tconst geometry = new XZPlaneGeometry(size.x, size.z, subdivisions, subdivisions);\n\t\tconst vertexGeometry = new PlaneGeometry(size.x, size.z, subdivisions, subdivisions);\n\t\tconst dx = size.x / subdivisions;\n\t\tconst dy = size.z / subdivisions;\n\t\tconst originalVertices = geometry.attributes.position.array;\n\t\tconst vertices = vertexGeometry.attributes.position.array;\n\t\tconst columsRows = new Map();\n\t\tfor (let i = 0; i < vertices.length; i += 3) {\n\t\t\tlet row = Math.floor(Math.abs((vertices as any)[i] + (size.x / 2)) / dx);\n\t\t\tlet column = Math.floor(Math.abs((vertices as any)[i + 1] - (size.z / 2)) / dy);\n\t\t\tconst randomHeight = Math.random() * 4;\n\t\t\t(vertices as any)[i + 2] = randomHeight;\n\t\t\toriginalVertices[i + 1] = randomHeight;\n\t\t\tif (!columsRows.get(column)) {\n\t\t\t\tcolumsRows.set(column, new Map());\n\t\t\t}\n\t\t\tcolumsRows.get(column).set(row, randomHeight);\n\t\t}\n\t\tthis.columnsRows = columsRows;\n\t\treturn geometry;\n\t}\n\n\tpostBuild(): void {\n\t\tconst heights = [];\n\t\tfor (let i = 0; i <= DEFAULT_SUBDIVISIONS; ++i) {\n\t\t\tfor (let j = 0; j <= DEFAULT_SUBDIVISIONS; ++j) {\n\t\t\t\tconst row = this.columnsRows.get(j);\n\t\t\t\tif (!row) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst data = row.get(i);\n\t\t\t\theights.push(data);\n\t\t\t}\n\t\t}\n\t\tthis.heightData = new Float32Array(heights as unknown as number[]);\n\t}\n}\n\nexport class PlaneBuilder extends EntityBuilder<ZylemPlane, ZylemPlaneOptions> {\n\tprotected createEntity(options: Partial<ZylemPlaneOptions>): ZylemPlane {\n\t\treturn new ZylemPlane(options);\n\t}\n}\n\nexport const PLANE_TYPE = Symbol('Plane');\n\nexport class ZylemPlane extends GameEntity<ZylemPlaneOptions> {\n\tstatic type = PLANE_TYPE;\n\n\tconstructor(options?: ZylemPlaneOptions) {\n\t\tsuper();\n\t\tthis.options = { ...planeDefaults, ...options };\n\t}\n}\n\ntype PlaneOptions = BaseNode | Partial<ZylemPlaneOptions>;\n\nexport async function plane(...args: Array<PlaneOptions>): Promise<ZylemPlane> {\n\treturn createEntity<ZylemPlane, ZylemPlaneOptions>({\n\t\targs,\n\t\tdefaultConfig: planeDefaults,\n\t\tEntityClass: ZylemPlane,\n\t\tBuilderClass: PlaneBuilder,\n\t\tMeshBuilderClass: PlaneMeshBuilder,\n\t\tCollisionBuilderClass: PlaneCollisionBuilder,\n\t\tentityType: ZylemPlane.type\n\t});\n}\n","// @ts-nocheck\nimport { BufferGeometry, Float32BufferAttribute } from 'three';\n\nclass XZPlaneGeometry extends BufferGeometry {\n\n\tconstructor(width = 1, height = 1, widthSegments = 1, heightSegments = 1) {\n\n\t\tsuper();\n\n\t\tthis.type = 'XZPlaneGeometry';\n\n\t\tthis.parameters = {\n\t\t\twidth: width,\n\t\t\theight: height,\n\t\t\twidthSegments: widthSegments,\n\t\t\theightSegments: heightSegments\n\t\t};\n\n\t\tconst width_half = width / 2;\n\t\tconst height_half = height / 2;\n\n\t\tconst gridX = Math.floor(widthSegments);\n\t\tconst gridY = Math.floor(heightSegments);\n\n\t\tconst gridX1 = gridX + 1;\n\t\tconst gridY1 = gridY + 1;\n\n\t\tconst segment_width = width / gridX;\n\t\tconst segment_height = height / gridY;\n\n\t\tconst indices = [];\n\t\tconst vertices = [];\n\t\tconst normals = [];\n\t\tconst uvs = [];\n\n\t\tfor (let iy = 0; iy < gridY1; iy++) {\n\n\t\t\tconst z = iy * segment_height - height_half;\n\n\t\t\tfor (let ix = 0; ix < gridX1; ix++) {\n\n\t\t\t\tconst x = ix * segment_width - width_half;\n\n\t\t\t\tvertices.push(x, 0, z);\n\n\t\t\t\tnormals.push(0, 1, 0);\n\n\t\t\t\tuvs.push(ix / gridX);\n\t\t\t\tuvs.push(1 - (iy / gridY));\n\n\t\t\t}\n\n\t\t}\n\n\t\tfor (let iy = 0; iy < gridY; iy++) {\n\n\t\t\tfor (let ix = 0; ix < gridX; ix++) {\n\n\t\t\t\tconst a = ix + gridX1 * iy;\n\t\t\t\tconst b = ix + gridX1 * (iy + 1);\n\t\t\t\tconst c = (ix + 1) + gridX1 * (iy + 1);\n\t\t\t\tconst d = (ix + 1) + gridX1 * iy;\n\n\t\t\t\tindices.push(a, b, d);\n\t\t\t\tindices.push(b, c, d);\n\n\t\t\t}\n\n\t\t}\n\n\t\tthis.setIndex(indices);\n\t\tthis.setAttribute('position', new Float32BufferAttribute(vertices, 3));\n\t\tthis.setAttribute('normal', new Float32BufferAttribute(normals, 3));\n\t\tthis.setAttribute('uv', new Float32BufferAttribute(uvs, 2));\n\n\t}\n\n\tcopy(source) {\n\n\t\tsuper.copy(source);\n\n\t\tthis.parameters = Object.assign({}, source.parameters);\n\n\t\treturn this;\n\t}\n\n\tstatic fromJSON(data) {\n\t\treturn new XZPlaneGeometry(data.width, data.height, data.widthSegments, data.heightSegments);\n\t}\n\n}\n\nexport { XZPlaneGeometry };","import { ActiveCollisionTypes, ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { createEntity } from './create';\nimport { CollisionHandlerDelegate } from '../collision/world';\nimport { state } from '../game/game-state';\n\nexport type OnHeldParams = {\n\tdelta: number;\n\tself: ZylemZone;\n\tvisitor: GameEntity<any>;\n\theldTime: number;\n\tglobals: any;\n}\n\nexport type OnEnterParams = Pick<OnHeldParams, 'self' | 'visitor' | 'globals'>;\nexport type OnExitParams = Pick<OnHeldParams, 'self' | 'visitor' | 'globals'>;\n\ntype ZylemZoneOptions = GameEntityOptions & {\n\tsize?: Vector3;\n\tstatic?: boolean;\n\tonEnter?: (params: OnEnterParams) => void;\n\tonHeld?: (params: OnHeldParams) => void;\n\tonExit?: (params: OnExitParams) => void;\n};\n\nconst zoneDefaults: ZylemZoneOptions = {\n\tsize: new Vector3(1, 1, 1),\n\tposition: new Vector3(0, 0, 0),\n\tcollision: {\n\t\tstatic: true,\n\t},\n\tmaterial: {\n\t\tshader: 'standard'\n\t},\n};\n\nexport class ZoneCollisionBuilder extends EntityCollisionBuilder {\n\tcollider(options: ZylemZoneOptions): ColliderDesc {\n\t\tconst size = options.size || new Vector3(1, 1, 1);\n\t\tconst half = { x: size.x / 2, y: size.y / 2, z: size.z / 2 };\n\t\tlet colliderDesc = ColliderDesc.cuboid(half.x, half.y, half.z);\n\t\tcolliderDesc.setSensor(true);\n\t\tcolliderDesc.activeCollisionTypes = ActiveCollisionTypes.KINEMATIC_FIXED;\n\t\treturn colliderDesc;\n\t}\n}\n\nexport class ZoneBuilder extends EntityBuilder<ZylemZone, ZylemZoneOptions> {\n\tprotected createEntity(options: Partial<ZylemZoneOptions>): ZylemZone {\n\t\treturn new ZylemZone(options);\n\t}\n}\n\nexport const ZONE_TYPE = Symbol('Zone');\n\nexport class ZylemZone extends GameEntity<ZylemZoneOptions> implements CollisionHandlerDelegate {\n\tstatic type = ZONE_TYPE;\n\n\tprivate _enteredZone: Map<string, number> = new Map();\n\tprivate _exitedZone: Map<string, number> = new Map();\n\tprivate _zoneEntities: Map<string, any> = new Map();\n\n\tconstructor(options?: ZylemZoneOptions) {\n\t\tsuper();\n\t\tthis.options = { ...zoneDefaults, ...options };\n\t}\n\n\tpublic handlePostCollision({ delta }: { delta: number }): boolean {\n\t\tthis._enteredZone.forEach((val, key) => {\n\t\t\tthis.exited(delta, key);\n\t\t});\n\t\treturn this._enteredZone.size > 0;\n\t}\n\n\tpublic handleIntersectionEvent({ other, delta }: { other: any, delta: number }) {\n\t\tconst hasEntered = this._enteredZone.get(other.uuid);\n\t\tif (!hasEntered) {\n\t\t\tthis.entered(other);\n\t\t\tthis._zoneEntities.set(other.uuid, other);\n\t\t} else {\n\t\t\tthis.held(delta, other);\n\t\t}\n\t}\n\n\tonEnter(callback: (params: OnEnterParams) => void) {\n\t\tthis.options.onEnter = callback;\n\t\treturn this;\n\t}\n\n\tonHeld(callback: (params: OnHeldParams) => void) {\n\t\tthis.options.onHeld = callback;\n\t\treturn this;\n\t}\n\n\tonExit(callback: (params: OnExitParams) => void) {\n\t\tthis.options.onExit = callback;\n\t\treturn this;\n\t}\n\n\tentered(other: any) {\n\t\tthis._enteredZone.set(other.uuid, 1);\n\t\tif (this.options.onEnter) {\n\t\t\tthis.options.onEnter({\n\t\t\t\tself: this,\n\t\t\t\tvisitor: other,\n\t\t\t\tglobals: state.globals\n\t\t\t});\n\t\t}\n\t}\n\n\texited(delta: number, key: string) {\n\t\tconst hasExited = this._exitedZone.get(key);\n\t\tif (hasExited && hasExited > 1 + delta) {\n\t\t\tthis._exitedZone.delete(key);\n\t\t\tthis._enteredZone.delete(key);\n\t\t\tconst other = this._zoneEntities.get(key);\n\t\t\tif (this.options.onExit) {\n\t\t\t\tthis.options.onExit({\n\t\t\t\t\tself: this,\n\t\t\t\t\tvisitor: other,\n\t\t\t\t\tglobals: state.globals\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthis._exitedZone.set(key, 1 + delta);\n\t}\n\n\theld(delta: number, other: any) {\n\t\tconst heldTime = this._enteredZone.get(other.uuid) ?? 0;\n\t\tthis._enteredZone.set(other.uuid, heldTime + delta);\n\t\tthis._exitedZone.set(other.uuid, 1);\n\t\tif (this.options.onHeld) {\n\t\t\tthis.options.onHeld({\n\t\t\t\tdelta,\n\t\t\t\tself: this,\n\t\t\t\tvisitor: other,\n\t\t\t\tglobals: state.globals,\n\t\t\t\theldTime\n\t\t\t});\n\t\t}\n\t}\n}\n\ntype ZoneOptions = BaseNode | Partial<ZylemZoneOptions>;\n\nexport async function zone(...args: Array<ZoneOptions>): Promise<ZylemZone> {\n\treturn createEntity<ZylemZone, ZylemZoneOptions>({\n\t\targs,\n\t\tdefaultConfig: zoneDefaults,\n\t\tEntityClass: ZylemZone,\n\t\tBuilderClass: ZoneBuilder,\n\t\tCollisionBuilderClass: ZoneCollisionBuilder,\n\t\tentityType: ZylemZone.type\n\t});\n}","import { Color, Group, Sprite as ThreeSprite, SpriteMaterial, CanvasTexture, LinearFilter, Vector2, PerspectiveCamera, OrthographicCamera, ClampToEdgeWrapping, ShaderMaterial, Mesh, PlaneGeometry, Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { createEntity } from './create';\nimport { UpdateContext, SetupContext } from '../core/base-node-life-cycle';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { DebugDelegate } from './delegates/debug';\n\ntype ZylemRectOptions = GameEntityOptions & {\n\twidth?: number;\n\theight?: number;\n\tfillColor?: Color | string | null;\n\tstrokeColor?: Color | string | null;\n\tstrokeWidth?: number;\n\tradius?: number;\n\tpadding?: number;\n\tstickToViewport?: boolean;\n\tscreenPosition?: Vector2;\n\tzDistance?: number;\n\tanchor?: Vector2; // 0-100 per axis, default top-left (0,0)\n\tbounds?: {\n\t\tscreen?: { x: number; y: number; width: number; height: number };\n\t\tworld?: { left: number; right: number; top: number; bottom: number; z?: number };\n\t};\n};\n\nconst rectDefaults: ZylemRectOptions = {\n\tposition: undefined,\n\twidth: 120,\n\theight: 48,\n\tfillColor: '#FFFFFF',\n\tstrokeColor: null,\n\tstrokeWidth: 0,\n\tradius: 0,\n\tpadding: 0,\n\tstickToViewport: true,\n\tscreenPosition: new Vector2(24, 24),\n\tzDistance: 1,\n\tanchor: new Vector2(0, 0),\n};\n\nexport class RectBuilder extends EntityBuilder<ZylemRect, ZylemRectOptions> {\n\tprotected createEntity(options: Partial<ZylemRectOptions>): ZylemRect {\n\t\treturn new ZylemRect(options);\n\t}\n}\n\nexport const RECT_TYPE = Symbol('Rect');\n\nexport class ZylemRect extends GameEntity<ZylemRectOptions> {\n\tstatic type = RECT_TYPE;\n\n\tprivate _sprite: ThreeSprite | null = null;\n\tprivate _mesh: Mesh | null = null;\n\tprivate _texture: CanvasTexture | null = null;\n\tprivate _canvas: HTMLCanvasElement | null = null;\n\tprivate _ctx: CanvasRenderingContext2D | null = null;\n\tprivate _cameraRef: ZylemCamera | null = null;\n\tprivate _lastCanvasW: number = 0;\n\tprivate _lastCanvasH: number = 0;\n\n\tconstructor(options?: ZylemRectOptions) {\n\t\tsuper();\n\t\tthis.options = { ...rectDefaults, ...options } as ZylemRectOptions;\n\t\tthis.group = new Group();\n\t\tthis.createSprite();\n\t\t// Add rect-specific lifecycle callbacks\n\t\tthis.prependSetup(this.rectSetup.bind(this) as any);\n\t\tthis.prependUpdate(this.rectUpdate.bind(this) as any);\n\t}\n\n\tprivate createSprite() {\n\t\tthis._canvas = document.createElement('canvas');\n\t\tthis._ctx = this._canvas.getContext('2d');\n\t\tthis._texture = new CanvasTexture(this._canvas);\n\t\tthis._texture.minFilter = LinearFilter;\n\t\tthis._texture.magFilter = LinearFilter;\n\t\tconst material = new SpriteMaterial({\n\t\t\tmap: this._texture,\n\t\t\ttransparent: true,\n\t\t\tdepthTest: false,\n\t\t\tdepthWrite: false,\n\t\t\talphaTest: 0.5,\n\t\t});\n\t\tthis._sprite = new ThreeSprite(material);\n\t\tthis.group?.add(this._sprite);\n\t\tthis.redrawRect();\n\t}\n\n\tprivate redrawRect() {\n\t\tif (!this._canvas || !this._ctx) return;\n\t\tconst width = Math.max(2, Math.floor((this.options.width ?? 120)));\n\t\tconst height = Math.max(2, Math.floor((this.options.height ?? 48)));\n\t\tconst padding = this.options.padding ?? 0;\n\t\tconst strokeWidth = this.options.strokeWidth ?? 0;\n\t\tconst totalW = width + padding * 2 + strokeWidth;\n\t\tconst totalH = height + padding * 2 + strokeWidth;\n\t\tconst nextW = Math.max(2, totalW);\n\t\tconst nextH = Math.max(2, totalH);\n\t\tconst sizeChanged = nextW !== this._lastCanvasW || nextH !== this._lastCanvasH;\n\t\tthis._canvas.width = nextW;\n\t\tthis._canvas.height = nextH;\n\t\tthis._lastCanvasW = nextW;\n\t\tthis._lastCanvasH = nextH;\n\n\t\tthis._ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);\n\n\t\tconst radius = Math.max(0, this.options.radius ?? 0);\n\t\tconst rectX = Math.floor(padding + strokeWidth / 2);\n\t\tconst rectY = Math.floor(padding + strokeWidth / 2);\n\t\tconst rectW = Math.floor(width);\n\t\tconst rectH = Math.floor(height);\n\n\t\tthis._ctx.beginPath();\n\t\tif (radius > 0) {\n\t\t\tthis.roundedRectPath(this._ctx, rectX, rectY, rectW, rectH, radius);\n\t\t} else {\n\t\t\tthis._ctx.rect(rectX, rectY, rectW, rectH);\n\t\t}\n\n\t\tif (this.options.fillColor) {\n\t\t\tthis._ctx.fillStyle = this.toCssColor(this.options.fillColor);\n\t\t\tthis._ctx.fill();\n\t\t}\n\n\t\tif ((this.options.strokeColor && (strokeWidth > 0))) {\n\t\t\tthis._ctx.lineWidth = strokeWidth;\n\t\t\tthis._ctx.strokeStyle = this.toCssColor(this.options.strokeColor);\n\t\t\tthis._ctx.stroke();\n\t\t}\n\n\t\tif (this._texture) {\n\t\t\tif (sizeChanged) {\n\t\t\t\tthis._texture.dispose();\n\t\t\t\tthis._texture = new CanvasTexture(this._canvas);\n\t\t\t\tthis._texture.minFilter = LinearFilter;\n\t\t\t\tthis._texture.magFilter = LinearFilter;\n\t\t\t\tthis._texture.wrapS = ClampToEdgeWrapping;\n\t\t\t\tthis._texture.wrapT = ClampToEdgeWrapping;\n\t\t\t\tif (this._sprite && this._sprite.material instanceof ShaderMaterial) {\n\t\t\t\t\tconst shader = this._sprite.material as ShaderMaterial;\n\t\t\t\t\tif (shader.uniforms?.tDiffuse) shader.uniforms.tDiffuse.value = this._texture;\n\t\t\t\t\tif (shader.uniforms?.iResolution) shader.uniforms.iResolution.value.set(this._canvas.width, this._canvas.height, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._texture.image = this._canvas;\n\t\t\tthis._texture.needsUpdate = true;\n\t\t\tif (this._sprite && this._sprite.material) {\n\t\t\t\t(this._sprite.material as any).map = this._texture;\n\t\t\t\tthis._sprite.material.needsUpdate = true;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate roundedRectPath(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number) {\n\t\tconst radius = Math.min(r, Math.floor(Math.min(w, h) / 2));\n\t\tctx.moveTo(x + radius, y);\n\t\tctx.lineTo(x + w - radius, y);\n\t\tctx.quadraticCurveTo(x + w, y, x + w, y + radius);\n\t\tctx.lineTo(x + w, y + h - radius);\n\t\tctx.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);\n\t\tctx.lineTo(x + radius, y + h);\n\t\tctx.quadraticCurveTo(x, y + h, x, y + h - radius);\n\t\tctx.lineTo(x, y + radius);\n\t\tctx.quadraticCurveTo(x, y, x + radius, y);\n\t}\n\n\tprivate toCssColor(color: Color | string): string {\n\t\tif (typeof color === 'string') return color;\n\t\tconst c = color instanceof Color ? color : new Color(color as any);\n\t\treturn `#${c.getHexString()}`;\n\t}\n\n\tprivate rectSetup(params: SetupContext<ZylemRectOptions>) {\n\t\tthis._cameraRef = (params.camera as unknown) as ZylemCamera | null;\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\t(this._cameraRef.camera as any).add(this.group);\n\t\t}\n\n\t\tif (this.materials?.length && this._sprite) {\n\t\t\tconst mat = this.materials[0];\n\t\t\tif (mat instanceof ShaderMaterial) {\n\t\t\t\tmat.transparent = true;\n\t\t\t\tmat.depthTest = false;\n\t\t\t\tmat.depthWrite = false;\n\t\t\t\tif (this._texture) {\n\t\t\t\t\tif (mat.uniforms?.tDiffuse) mat.uniforms.tDiffuse.value = this._texture;\n\t\t\t\t\tif (mat.uniforms?.iResolution && this._canvas) mat.uniforms.iResolution.value.set(this._canvas.width, this._canvas.height, 1);\n\t\t\t\t}\n\t\t\t\tthis._mesh = new Mesh(new PlaneGeometry(1, 1), mat);\n\t\t\t\tthis.group?.add(this._mesh);\n\t\t\t\tthis._sprite.visible = false;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate rectUpdate(params: UpdateContext<ZylemRectOptions>) {\n\t\tif (!this._sprite) return;\n\n\t\t// If bounds provided, compute screen-space rect from it and update size/position\n\t\tif (this._cameraRef && this.options.bounds) {\n\t\t\tconst dom = this._cameraRef.renderer.domElement;\n\t\t\tconst screen = this.computeScreenBoundsFromOptions(this.options.bounds);\n\t\t\tif (screen) {\n\t\t\t\tconst { x, y, width, height } = screen;\n\t\t\t\tconst desiredW = Math.max(2, Math.floor(width));\n\t\t\t\tconst desiredH = Math.max(2, Math.floor(height));\n\t\t\t\tconst changed = desiredW !== (this.options.width ?? 0) || desiredH !== (this.options.height ?? 0);\n\t\t\t\tthis.options.screenPosition = new Vector2(Math.floor(x), Math.floor(y));\n\t\t\t\tthis.options.width = desiredW;\n\t\t\t\tthis.options.height = desiredH;\n\t\t\t\tthis.options.anchor = new Vector2(0, 0);\n\t\t\t\tif (changed) {\n\t\t\t\t\tthis.redrawRect();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tprivate updateStickyTransform() {\n\t\tif (!this._sprite || !this._cameraRef) return;\n\t\tconst camera = this._cameraRef.camera;\n\t\tconst dom = this._cameraRef.renderer.domElement;\n\t\tconst width = dom.clientWidth;\n\t\tconst height = dom.clientHeight;\n\t\tconst px = (this.options.screenPosition ?? new Vector2(24, 24)).x;\n\t\tconst py = (this.options.screenPosition ?? new Vector2(24, 24)).y;\n\t\tconst zDist = Math.max(0.001, this.options.zDistance ?? 1);\n\n\t\tlet worldHalfW = 1;\n\t\tlet worldHalfH = 1;\n\t\tif ((camera as PerspectiveCamera).isPerspectiveCamera) {\n\t\t\tconst pc = camera as PerspectiveCamera;\n\t\t\tconst halfH = Math.tan((pc.fov * Math.PI) / 180 / 2) * zDist;\n\t\t\tconst halfW = halfH * pc.aspect;\n\t\t\tworldHalfW = halfW;\n\t\t\tworldHalfH = halfH;\n\t\t} else if ((camera as OrthographicCamera).isOrthographicCamera) {\n\t\t\tconst oc = camera as OrthographicCamera;\n\t\t\tworldHalfW = (oc.right - oc.left) / 2;\n\t\t\tworldHalfH = (oc.top - oc.bottom) / 2;\n\t\t}\n\n\t\tconst ndcX = (px / width) * 2 - 1;\n\t\tconst ndcY = 1 - (py / height) * 2;\n\t\tconst localX = ndcX * worldHalfW;\n\t\tconst localY = ndcY * worldHalfH;\n\n\t\tlet scaleX = 1;\n\t\tlet scaleY = 1;\n\t\tif (this._canvas) {\n\t\t\tconst planeH = worldHalfH * 2;\n\t\t\tconst unitsPerPixel = planeH / height;\n\t\t\tconst pixelH = this._canvas.height;\n\t\t\tscaleY = Math.max(0.0001, pixelH * unitsPerPixel);\n\t\t\tconst aspect = this._canvas.width / this._canvas.height;\n\t\t\tscaleX = scaleY * aspect;\n\t\t\tthis._sprite.scale.set(scaleX, scaleY, 1);\n\t\t\tif (this._mesh) this._mesh.scale.set(scaleX, scaleY, 1);\n\t\t}\n\n\t\tconst anchor = this.options.anchor ?? new Vector2(0, 0);\n\t\tconst ax = Math.min(100, Math.max(0, anchor.x)) / 100; // 0..1\n\t\tconst ay = Math.min(100, Math.max(0, anchor.y)) / 100; // 0..1\n\t\tconst offsetX = (0.5 - ax) * scaleX;\n\t\tconst offsetY = (ay - 0.5) * scaleY;\n\t\tthis.group?.position.set(localX + offsetX, localY + offsetY, -zDist);\n\t}\n\n\tprivate worldToScreen(point: Vector3) {\n\t\tif (!this._cameraRef) return { x: 0, y: 0 };\n\t\tconst camera = this._cameraRef.camera;\n\t\tconst dom = this._cameraRef.renderer.domElement;\n\t\tconst v = point.clone().project(camera);\n\t\tconst x = (v.x + 1) / 2 * dom.clientWidth;\n\t\tconst y = (1 - v.y) / 2 * dom.clientHeight;\n\t\treturn { x, y };\n\t}\n\n\tprivate computeScreenBoundsFromOptions(bounds: NonNullable<ZylemRectOptions['bounds']>): { x: number; y: number; width: number; height: number } | null {\n\t\tif (!this._cameraRef) return null;\n\t\tconst dom = this._cameraRef.renderer.domElement;\n\t\tif (bounds.screen) {\n\t\t\treturn { ...bounds.screen };\n\t\t}\n\t\tif (bounds.world) {\n\t\t\tconst { left, right, top, bottom, z = 0 } = bounds.world;\n\t\t\tconst tl = this.worldToScreen(new Vector3(left, top, z));\n\t\t\tconst br = this.worldToScreen(new Vector3(right, bottom, z));\n\t\t\tconst x = Math.min(tl.x, br.x);\n\t\t\tconst y = Math.min(tl.y, br.y);\n\t\t\tconst width = Math.abs(br.x - tl.x);\n\t\t\tconst height = Math.abs(br.y - tl.y);\n\t\t\treturn { x, y, width, height };\n\t\t}\n\t\treturn null;\n\t}\n\n\tupdateRect(options?: Partial<Pick<ZylemRectOptions, 'width' | 'height' | 'fillColor' | 'strokeColor' | 'strokeWidth' | 'radius'>>) {\n\t\tthis.options = { ...this.options, ...options } as ZylemRectOptions;\n\t\tthis.redrawRect();\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tbuildInfo(): Record<string, any> {\n\t\tconst delegate = new DebugDelegate(this as any);\n\t\tconst baseInfo = delegate.buildDebugInfo();\n\n\t\treturn {\n\t\t\t...baseInfo,\n\t\t\ttype: String(ZylemRect.type),\n\t\t\twidth: this.options.width ?? 0,\n\t\t\theight: this.options.height ?? 0,\n\t\t\tsticky: this.options.stickToViewport,\n\t\t};\n\t}\n}\n\ntype RectOptions = BaseNode | Partial<ZylemRectOptions>;\n\nexport async function rect(...args: Array<RectOptions>): Promise<ZylemRect> {\n\treturn createEntity<ZylemRect, ZylemRectOptions>({\n\t\targs,\n\t\tdefaultConfig: { ...rectDefaults },\n\t\tEntityClass: ZylemRect,\n\t\tBuilderClass: RectBuilder,\n\t\tentityType: ZylemRect.type,\n\t});\n}\n\n\n","import type { GameEntity } from \"../entities/entity\";\nimport { getOrCreateCollisionGroupId } from \"./collision-builder\";\n\n/**\n * A branded bitmask representing a set of collision types.\n */\nexport type CollisionMask = number & { readonly __brand: \"CollisionMask\" };\n\nexport type NameSelector = string | string[] | RegExp;\n\nexport type CollisionSelector =\n\t| { name: NameSelector }\n\t| { mask: CollisionMask | RegExp }\n\t| { test: (other: GameEntity<any>) => boolean };\n\n/**\n * Returns true if the `other` entity matches the provided selector.\n */\nexport function matchesCollisionSelector(other: GameEntity<any>, selector?: CollisionSelector): boolean {\n\tif (!selector) return true;\n\tconst otherName = other.name ?? '';\n\tif ('name' in selector) {\n\t\tconst sel = selector.name as NameSelector;\n\t\tif (sel instanceof RegExp) {\n\t\t\treturn sel.test(otherName);\n\t\t} else if (Array.isArray(sel)) {\n\t\t\treturn sel.some(s => s === otherName);\n\t\t} else {\n\t\t\treturn otherName === sel;\n\t\t}\n\t} else if ('mask' in selector) {\n\t\tconst m = selector.mask as CollisionMask | RegExp;\n\t\tif (m instanceof RegExp) {\n\t\t\tconst type = other.collisionType ?? '';\n\t\t\treturn m.test(type);\n\t\t} else {\n\t\t\tconst type = other.collisionType ?? '';\n\t\t\tconst gid = getOrCreateCollisionGroupId(type);\n\t\t\treturn ((m as number) & (1 << gid)) !== 0;\n\t\t}\n\t} else if ('test' in selector) {\n\t\treturn !!selector.test(other);\n\t}\n\treturn true;\n}\n","import { CollisionContext, GameEntity } from '../../../entities/entity';\nimport { MoveableEntity } from '../../capabilities/moveable';\nimport { matchesCollisionSelector } from '../../../collision/utils';\nimport { Ricochet2DCollisionOptions, clamp, Ricochet2DCollisionCallback } from './ricochet';\n\n/**\n * Behavior for ricocheting an entity off other objects in 2D\n */\nexport function ricochet2DCollision(\n\toptions: Partial<Ricochet2DCollisionOptions> = {},\n\tcallback?: Ricochet2DCollisionCallback\n): { type: 'collision'; handler: (ctx: CollisionContext<MoveableEntity, GameEntity<any>>) => void } {\n\treturn {\n\t\ttype: 'collision',\n\t\thandler: (collisionContext: CollisionContext<MoveableEntity, GameEntity<any>>) => {\n\t\t\t_handleRicochet2DCollision(collisionContext, options, callback);\n\t\t},\n\t};\n}\n\nfunction _handleRicochet2DCollision(\n\tcollisionContext: CollisionContext<MoveableEntity, GameEntity<any>>,\n\toptions: Partial<Ricochet2DCollisionOptions>,\n\tcallback?: Ricochet2DCollisionCallback\n) {\n\tconst { entity, other } = collisionContext;\n\tconst self = entity as unknown as GameEntity<any> & MoveableEntity;\n\tif (other.collider?.isSensor()) return;\n\n\tconst {\n\t\tminSpeed = 2,\n\t\tmaxSpeed = 20,\n\t\tseparation = 0,\n\t\tcollisionWith = undefined,\n\t} = {\n\t\t...options,\n\t} as Ricochet2DCollisionOptions;\n\tconst reflectionMode: 'simple' | 'angled' = (options as any)?.reflectionMode ?? 'angled';\n\tconst maxAngleDeg = (options as any)?.maxAngleDeg ?? 60;\n\tconst speedUpFactor = (options as any)?.speedUpFactor ?? 1.05;\n\tconst minOffsetForAngle = (options as any)?.minOffsetForAngle ?? 0.15; // 0..1\n\tconst centerRetentionFactor = (options as any)?.centerRetentionFactor ?? 0.5; // keep some Y on center hits\n\n\tif (!matchesCollisionSelector(other, collisionWith)) return;\n\n\tconst selfPos = self.getPosition();\n\tconst otherPos = other.body?.translation();\n\tconst vel = self.getVelocity();\n\tif (!selfPos || !otherPos || !vel) return;\n\n\tlet newVelX = vel.x;\n\tlet newVelY = vel.y;\n\tlet newX = selfPos.x;\n\tlet newY = selfPos.y;\n\n\tconst dx = selfPos.x - otherPos.x;\n\tconst dy = selfPos.y - otherPos.y;\n\n\tlet extentX: number | null = null;\n\tlet extentY: number | null = null;\n\tconst colliderShape: any = other.collider?.shape as any;\n\tif (colliderShape) {\n\t\tif (colliderShape.halfExtents) {\n\t\t\textentX = Math.abs(colliderShape.halfExtents.x ?? colliderShape.halfExtents[0] ?? null);\n\t\t\textentY = Math.abs(colliderShape.halfExtents.y ?? colliderShape.halfExtents[1] ?? null);\n\t\t}\n\t\tif ((extentX == null || extentY == null) && (typeof colliderShape.radius === 'number')) {\n\t\t\textentX = extentX ?? Math.abs(colliderShape.radius);\n\t\t\textentY = extentY ?? Math.abs(colliderShape.radius);\n\t\t}\n\t}\n\tif ((extentX == null || extentY == null) && typeof (other.collider as any)?.halfExtents === 'function') {\n\t\tconst he = (other.collider as any).halfExtents();\n\t\tif (he) {\n\t\t\textentX = extentX ?? Math.abs(he.x);\n\t\t\textentY = extentY ?? Math.abs(he.y);\n\t\t}\n\t}\n\tif ((extentX == null || extentY == null) && typeof (other.collider as any)?.radius === 'function') {\n\t\tconst r = (other.collider as any).radius();\n\t\tif (typeof r === 'number') {\n\t\t\textentX = extentX ?? Math.abs(r);\n\t\t\textentY = extentY ?? Math.abs(r);\n\t\t}\n\t}\n\n\tlet relX = 0;\n\tlet relY = 0;\n\tif (extentX && extentY) {\n\t\trelX = clamp(dx / extentX, -1, 1);\n\t\trelY = clamp(dy / extentY, -1, 1);\n\t} else {\n\t\trelX = Math.sign(dx);\n\t\trelY = Math.sign(dy);\n\t}\n\tlet bounceVertical = Math.abs(dy) >= Math.abs(dx);\n\n\tlet selfExtentX: number | null = null;\n\tlet selfExtentY: number | null = null;\n\tconst selfShape: any = self.collider?.shape as any;\n\tif (selfShape) {\n\t\tif (selfShape.halfExtents) {\n\t\t\tselfExtentX = Math.abs(selfShape.halfExtents.x ?? selfShape.halfExtents[0] ?? null);\n\t\t\tselfExtentY = Math.abs(selfShape.halfExtents.y ?? selfShape.halfExtents[1] ?? null);\n\t\t}\n\t\tif ((selfExtentX == null || selfExtentY == null) && (typeof selfShape.radius === 'number')) {\n\t\t\tselfExtentX = selfExtentX ?? Math.abs(selfShape.radius);\n\t\t\tselfExtentY = selfExtentY ?? Math.abs(selfShape.radius);\n\t\t}\n\t}\n\tif ((selfExtentX == null || selfExtentY == null) && typeof (self.collider as any)?.halfExtents === 'function') {\n\t\tconst heS = (self.collider as any).halfExtents();\n\t\tif (heS) {\n\t\t\tselfExtentX = selfExtentX ?? Math.abs(heS.x);\n\t\t\tselfExtentY = selfExtentY ?? Math.abs(heS.y);\n\t\t}\n\t}\n\tif ((selfExtentX == null || selfExtentY == null) && typeof (self.collider as any)?.radius === 'function') {\n\t\tconst rS = (self.collider as any).radius();\n\t\tif (typeof rS === 'number') {\n\t\t\tselfExtentX = selfExtentX ?? Math.abs(rS);\n\t\t\tselfExtentY = selfExtentY ?? Math.abs(rS);\n\t\t}\n\t}\n\n\tif (extentX != null && extentY != null && selfExtentX != null && selfExtentY != null) {\n\t\tconst penX = (selfExtentX + extentX) - Math.abs(dx);\n\t\tconst penY = (selfExtentY + extentY) - Math.abs(dy);\n\t\tif (!Number.isNaN(penX) && !Number.isNaN(penY)) {\n\t\t\tbounceVertical = penY <= penX;\n\t\t}\n\t}\n\n\tlet usedAngleDeflection = false;\n\tif (bounceVertical) {\n\t\tconst resolvedY = (extentY ?? 0) + (selfExtentY ?? 0) + separation;\n\t\tnewY = otherPos.y + (dy > 0 ? resolvedY : -resolvedY);\n\t\tnewX = selfPos.x;\n\n\t\tconst isHorizontalPaddle = extentX != null && extentY != null && extentX > extentY;\n\t\tif (isHorizontalPaddle && reflectionMode === 'angled') {\n\t\t\tconst maxAngleRad = (maxAngleDeg * Math.PI) / 180;\n\t\t\tconst deadzone = Math.max(0, Math.min(1, minOffsetForAngle));\n\t\t\tconst clampedOffsetX = clamp(relX, -1, 1);\n\t\t\tconst absOff = Math.abs(clampedOffsetX);\n\t\t\tconst baseSpeed = Math.sqrt(vel.x * vel.x + vel.y * vel.y);\n\t\t\tconst speed = clamp(baseSpeed * speedUpFactor, minSpeed, maxSpeed);\n\t\t\tif (absOff > deadzone) {\n\t\t\t\tconst t = (absOff - deadzone) / (1 - deadzone);\n\t\t\t\tconst angle = Math.sign(clampedOffsetX) * (t * maxAngleRad);\n\t\t\t\tconst cosA = Math.cos(angle);\n\t\t\t\tconst sinA = Math.sin(angle);\n\t\t\t\tconst vy = Math.abs(speed * cosA);\n\t\t\t\tconst vx = speed * sinA;\n\t\t\t\tnewVelY = dy > 0 ? vy : -vy;\n\t\t\t\tnewVelX = vx;\n\t\t\t} else {\n\t\t\t\tconst vx = vel.x * centerRetentionFactor;\n\t\t\t\tconst vyMagSquared = Math.max(0, speed * speed - vx * vx);\n\t\t\t\tconst vy = Math.sqrt(vyMagSquared);\n\t\t\t\tnewVelY = dy > 0 ? vy : -vy;\n\t\t\t\tnewVelX = vx;\n\t\t\t}\n\t\t\tusedAngleDeflection = true;\n\t\t} else {\n\t\t\t// Simple vertical reflection (or non-paddle surface)\n\t\t\tnewVelY = dy > 0 ? Math.abs(vel.y) : -Math.abs(vel.y);\n\t\t\tif (reflectionMode === 'simple') usedAngleDeflection = true;\n\t\t}\n\t} else {\n\t\tconst resolvedX = (extentX ?? 0) + (selfExtentX ?? 0) + separation;\n\t\tnewX = otherPos.x + (dx > 0 ? resolvedX : -resolvedX);\n\t\tnewY = selfPos.y;\n\n\t\tif (reflectionMode === 'angled') {\n\t\t\tconst maxAngleRad = (maxAngleDeg * Math.PI) / 180;\n\t\t\tconst deadzone = Math.max(0, Math.min(1, minOffsetForAngle));\n\t\t\tconst clampedOffsetY = clamp(relY, -1, 1);\n\t\t\tconst absOff = Math.abs(clampedOffsetY);\n\t\t\tconst baseSpeed = Math.sqrt(vel.x * vel.x + vel.y * vel.y);\n\t\t\tconst speed = clamp(baseSpeed * speedUpFactor, minSpeed, maxSpeed);\n\t\t\tif (absOff > deadzone) {\n\t\t\t\tconst t = (absOff - deadzone) / (1 - deadzone);\n\t\t\t\tconst angle = Math.sign(clampedOffsetY) * (t * maxAngleRad);\n\t\t\t\tconst cosA = Math.cos(angle);\n\t\t\t\tconst sinA = Math.sin(angle);\n\t\t\t\tconst vx = Math.abs(speed * cosA);\n\t\t\t\tconst vy = speed * sinA;\n\t\t\t\tnewVelX = dx > 0 ? vx : -vx;\n\t\t\t\tnewVelY = vy;\n\t\t\t} else {\n\t\t\t\tconst vy = vel.y * centerRetentionFactor;\n\t\t\t\tconst vxMagSquared = Math.max(0, speed * speed - vy * vy);\n\t\t\t\tconst vx = Math.sqrt(vxMagSquared);\n\t\t\t\tnewVelX = dx > 0 ? vx : -vx;\n\t\t\t\tnewVelY = vy;\n\t\t\t}\n\t\t\tusedAngleDeflection = true;\n\t\t} else {\n\t\t\tnewVelX = dx > 0 ? Math.abs(vel.x) : -Math.abs(vel.x);\n\t\t\tnewVelY = vel.y;\n\t\t\tusedAngleDeflection = true;\n\t\t}\n\t}\n\n\tif (!usedAngleDeflection) {\n\t\tconst additionBaseX = Math.abs(newVelX);\n\t\tconst additionBaseY = Math.abs(newVelY);\n\t\tconst addX = Math.sign(relX) * Math.abs(relX) * additionBaseX;\n\t\tconst addY = Math.sign(relY) * Math.abs(relY) * additionBaseY;\n\t\tnewVelX += addX;\n\t\tnewVelY += addY;\n\t}\n\tconst currentSpeed = Math.sqrt(newVelX * newVelX + newVelY * newVelY);\n\tif (currentSpeed > 0) {\n\t\tconst targetSpeed = clamp(currentSpeed, minSpeed, maxSpeed);\n\t\tif (targetSpeed !== currentSpeed) {\n\t\t\tconst scale = targetSpeed / currentSpeed;\n\t\t\tnewVelX *= scale;\n\t\t\tnewVelY *= scale;\n\t\t}\n\t}\n\n\tif (newX !== selfPos.x || newY !== selfPos.y) {\n\t\tself.setPosition(newX, newY, selfPos.z);\n\t\tself.moveXY(newVelX, newVelY);\n\t\tif (callback) {\n\t\t\tconst velocityAfter = self.getVelocity();\n\t\t\tif (velocityAfter) {\n\t\t\t\tcallback({\n\t\t\t\t\tposition: { x: newX, y: newY, z: selfPos.z },\n\t\t\t\t\t...collisionContext,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n}","import { Vector } from '@dimforge/rapier3d-compat';\nimport { MoveableEntity } from '../../capabilities/moveable';\nimport { CollisionContext, GameEntity } from '../../../entities/entity';\nimport { UpdateContext } from '../../../core/base-node-life-cycle';\nimport { CollisionSelector } from '../../../collision/utils';\n\nexport interface RicochetEvent extends Partial<UpdateContext<MoveableEntity>> {\n\tboundary?: 'top' | 'bottom' | 'left' | 'right';\n\tposition: Vector;\n\tvelocityBefore: Vector;\n\tvelocityAfter: Vector;\n}\n\nexport interface RicochetCollisionEvent extends CollisionContext<MoveableEntity, GameEntity<any>> {\n\tposition: Vector;\n}\n\nexport interface Ricochet2DInBoundsOptions {\n\trestitution?: number;\n\tminSpeed?: number;\n\tmaxSpeed?: number;\n\tboundaries: {\n\t\ttop: number;\n\t\tbottom: number;\n\t\tleft: number;\n\t\tright: number;\n\t};\n\tseparation?: number;\n}\n\nexport interface Ricochet2DCollisionOptions {\n\trestitution?: number;\n\tminSpeed?: number;\n\tmaxSpeed?: number;\n\tseparation?: number;\n\tcollisionWith?: CollisionSelector;\n\t/**\n\t * Choose between simple axis inversion or angled (paddle-style) reflection.\n\t * Defaults to 'angled'.\n\t */\n\treflectionMode?: 'simple' | 'angled';\n}\n\nexport type Ricochet2DCallback = (event: RicochetEvent) => void;\nexport type Ricochet2DCollisionCallback = (event: RicochetCollisionEvent) => void;\n\nexport function clamp(value: number, min: number, max: number): number {\n\treturn Math.max(min, Math.min(max, value));\n}\n\nexport { ricochet2DInBounds } from './ricochet-2d-in-bounds';\nexport { ricochet2DCollision } from './ricochet-2d-collision';","import { UpdateContext } from '../../../core/base-node-life-cycle';\nimport { MoveableEntity } from '../../capabilities/moveable';\nimport { Ricochet2DInBoundsOptions, Ricochet2DCallback, clamp } from './ricochet';\nimport { BehaviorCallbackType } from '../../../entities/entity';\n\n/**\n * Behavior for ricocheting an entity within fixed 2D boundaries\n */\nexport function ricochet2DInBounds(\n\toptions: Partial<Ricochet2DInBoundsOptions> = {},\n\tcallback?: Ricochet2DCallback\n): { type: BehaviorCallbackType; handler: (ctx: UpdateContext<MoveableEntity>) => void } {\n\treturn {\n\t\ttype: 'update' as BehaviorCallbackType,\n\t\thandler: (updateContext: UpdateContext<MoveableEntity>) => {\n\t\t\t_handleRicochet2DInBounds(updateContext, options, callback);\n\t\t},\n\t};\n}\n\nfunction _handleRicochet2DInBounds(\n\tupdateContext: UpdateContext<MoveableEntity>,\n\toptions: Partial<Ricochet2DInBoundsOptions>,\n\tcallback?: Ricochet2DCallback\n) {\n\tconst { me } = updateContext;\n\tconst {\n\t\trestitution = 0,\n\t\tminSpeed = 2,\n\t\tmaxSpeed = 20,\n\t\tboundaries = { top: 5, bottom: -5, left: -6.5, right: 6.5 },\n\t\tseparation = 0.0\n\t} = { ...options } as Ricochet2DInBoundsOptions;\n\n\tconst position = me.getPosition();\n\tconst velocity = me.getVelocity();\n\tif (!position || !velocity) return;\n\n\tlet newVelX = velocity.x;\n\tlet newVelY = velocity.y;\n\tlet newX = position.x;\n\tlet newY = position.y;\n\tlet ricochetBoundary: 'top' | 'bottom' | 'left' | 'right' | null = null;\n\n\tif (position.x <= boundaries.left) {\n\t\tnewVelX = Math.abs(velocity.x);\n\t\tnewX = boundaries.left + separation;\n\t\tricochetBoundary = 'left';\n\t} else if (position.x >= boundaries.right) {\n\t\tnewVelX = -Math.abs(velocity.x);\n\t\tnewX = boundaries.right - separation;\n\t\tricochetBoundary = 'right';\n\t}\n\n\tif (position.y <= boundaries.bottom) {\n\t\tnewVelY = Math.abs(velocity.y);\n\t\tnewY = boundaries.bottom + separation;\n\t\tricochetBoundary = 'bottom';\n\t} else if (position.y >= boundaries.top) {\n\t\tnewVelY = -Math.abs(velocity.y);\n\t\tnewY = boundaries.top - separation;\n\t\tricochetBoundary = 'top';\n\t}\n\n\tconst currentSpeed = Math.sqrt(newVelX * newVelX + newVelY * newVelY);\n\tif (currentSpeed > 0) {\n\t\tconst targetSpeed = clamp(currentSpeed, minSpeed, maxSpeed);\n\t\tif (targetSpeed !== currentSpeed) {\n\t\t\tconst scale = targetSpeed / currentSpeed;\n\t\t\tnewVelX *= scale;\n\t\t\tnewVelY *= scale;\n\t\t}\n\t}\n\n\tif (restitution) {\n\t\tnewVelX *= restitution;\n\t\tnewVelY *= restitution;\n\t}\n\n\tif (newX !== position.x || newY !== position.y) {\n\t\tme.setPosition(newX, newY, position.z);\n\t\tme.moveXY(newVelX, newVelY);\n\n\t\tif (callback && ricochetBoundary) {\n\t\t\tconst velocityAfter = me.getVelocity();\n\t\t\tif (velocityAfter) {\n\t\t\t\tcallback({\n\t\t\t\t\tboundary: ricochetBoundary,\n\t\t\t\t\tposition: { x: newX, y: newY, z: position.z },\n\t\t\t\t\tvelocityBefore: velocity,\n\t\t\t\t\tvelocityAfter,\n\t\t\t\t\t...updateContext,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n}","import { UpdateContext } from \"../../../core/base-node-life-cycle\";\nimport { MoveableEntity } from \"../../capabilities/moveable\";\nimport { Vector } from \"@dimforge/rapier3d-compat\";\nimport { BehaviorCallbackType } from \"../../../entities/entity\";\n\nexport interface BoundaryEvent {\n\tme: MoveableEntity;\n\tboundary: BoundaryHits;\n\tposition: Vector;\n\tupdateContext: UpdateContext<MoveableEntity>;\n}\n\nexport interface BoundaryOptions {\n\tboundaries: {\n\t\ttop: number;\n\t\tbottom: number;\n\t\tleft: number;\n\t\tright: number;\n\t};\n\tonBoundary?: (event: BoundaryEvent) => void;\n\tstopMovement?: boolean;\n}\n\nconst defaultBoundaryOptions: BoundaryOptions = {\n\tboundaries: {\n\t\ttop: 0,\n\t\tbottom: 0,\n\t\tleft: 0,\n\t\tright: 0\n\t},\n\tstopMovement: true\n};\n\n/**\n * Checks if the entity has hit a boundary and stops its movement if it has\n * \n * @param options Configuration options for the boundary behavior\n * @param options.boundaries The boundaries of the stage\n * @param options.onBoundary A callback function that is called when the entity hits a boundary\n * @param options.stopMovement Whether to stop the entity's movement when it hits a boundary\n * @returns A behavior callback with type 'update' and a handler function\n */\nexport function boundary2d(\n\toptions: Partial<BoundaryOptions> = {}\n): { type: BehaviorCallbackType; handler: (ctx: UpdateContext<MoveableEntity>) => void } {\n\treturn {\n\t\ttype: 'update' as BehaviorCallbackType,\n\t\thandler: (updateContext: UpdateContext<MoveableEntity>) => {\n\t\t\t_boundary2d(updateContext, options);\n\t\t}\n\t};\n}\n\ntype BoundaryHit = 'top' | 'bottom' | 'left' | 'right';\n\ntype BoundaryHits = Record<BoundaryHit, boolean>;\n\nfunction _boundary2d(updateContext: UpdateContext<MoveableEntity>, options: Partial<BoundaryOptions>) {\n\tconst { me: entity } = updateContext;\n\tconst { boundaries, onBoundary } = {\n\t\t...defaultBoundaryOptions,\n\t\t...options\n\t};\n\n\tconst position = entity.getPosition();\n\tif (!position) return;\n\n\tlet boundariesHit: BoundaryHits = { top: false, bottom: false, left: false, right: false };\n\n\tif (position.x <= boundaries.left) {\n\t\tboundariesHit.left = true;\n\t} else if (position.x >= boundaries.right) {\n\t\tboundariesHit.right = true;\n\t}\n\n\tif (position.y <= boundaries.bottom) {\n\t\tboundariesHit.bottom = true;\n\t} else if (position.y >= boundaries.top) {\n\t\tboundariesHit.top = true;\n\t}\n\n\tconst stopMovement = options.stopMovement ?? true;\n\tif (stopMovement && boundariesHit) {\n\t\tconst velocity = entity.getVelocity() ?? { x: 0, y: 0, z: 0 };\n\t\tlet { x: newX, y: newY } = velocity;\n\t\tif (velocity?.y < 0 && boundariesHit.bottom) {\n\t\t\tnewY = 0;\n\t\t} else if (velocity?.y > 0 && boundariesHit.top) {\n\t\t\tnewY = 0;\n\t\t}\n\t\tif (velocity?.x < 0 && boundariesHit.left) {\n\t\t\tnewX = 0;\n\t\t} else if (velocity?.x > 0 && boundariesHit.right) {\n\t\t\tnewX = 0;\n\t\t}\n\t\tentity.moveXY(newX, newY);\n\t}\n\tif (onBoundary && boundariesHit) {\n\t\tonBoundary({\n\t\t\tme: entity,\n\t\t\tboundary: boundariesHit,\n\t\t\tposition: { x: position.x, y: position.y, z: position.z },\n\t\t\tupdateContext\n\t\t});\n\t}\n}","import { UpdateContext } from \"../../../core/base-node-life-cycle\";\nimport { MoveableEntity } from \"../../capabilities/moveable\";\nimport { BehaviorCallbackType } from \"../../../entities/entity\";\n\nexport interface MovementSequence2DStep {\n\tname: string;\n\tmoveX?: number;\n\tmoveY?: number;\n\ttimeInSeconds: number;\n}\n\nexport interface MovementSequence2DOptions {\n\tsequence: MovementSequence2DStep[];\n\tloop?: boolean;\n}\n\nexport type MovementSequence2DCallback = (\n\tcurrent: MovementSequence2DStep,\n\tindex: number,\n\tctx: UpdateContext<MoveableEntity>\n) => void;\n\ntype MovementSequence2DState = {\n\tcurrentIndex: number;\n\ttimeRemaining: number;\n\tlastNotifiedIndex: number;\n\tdone: boolean;\n};\n\nconst STATE_KEY = \"__movementSequence2D\" as const;\n\n/**\n * Behavior that sequences 2D movements over time.\n * Each step sets linear velocity via `moveXY` for a duration, then advances.\n * Defaults to looping when the end is reached.\n */\nexport function movementSequence2D(\n\topts: MovementSequence2DOptions,\n\tonStep?: MovementSequence2DCallback\n): { type: BehaviorCallbackType; handler: (ctx: UpdateContext<MoveableEntity>) => void } {\n\tconst { sequence, loop = true } = opts;\n\n\treturn {\n\t\ttype: 'update' as BehaviorCallbackType,\n\t\thandler: (ctx: UpdateContext<MoveableEntity>) => {\n\t\t\tconst { me, delta } = ctx;\n\t\t\tif (!sequence || sequence.length === 0) return;\n\n\t\t\tconst custom: any = (me as any).custom ?? ((me as any).custom = {});\n\t\t\tlet state: MovementSequence2DState = custom[STATE_KEY];\n\t\t\tif (!state) {\n\t\t\t\tstate = {\n\t\t\t\t\tcurrentIndex: 0,\n\t\t\t\t\ttimeRemaining: sequence[0].timeInSeconds,\n\t\t\t\t\tlastNotifiedIndex: -1,\n\t\t\t\t\tdone: false\n\t\t\t\t};\n\t\t\t\tcustom[STATE_KEY] = state;\n\t\t\t}\n\n\t\t\tif (state.done) return;\n\n\t\t\tlet current = sequence[state.currentIndex];\n\t\t\tconst moveX = current.moveX ?? 0;\n\t\t\tconst moveY = current.moveY ?? 0;\n\t\t\tme.moveXY(moveX, moveY);\n\n\t\t\tif (state.lastNotifiedIndex !== state.currentIndex) {\n\t\t\t\tstate.lastNotifiedIndex = state.currentIndex;\n\t\t\t\tonStep?.(current, state.currentIndex, ctx);\n\t\t\t}\n\n\t\t\tlet timeLeft = state.timeRemaining - delta;\n\t\t\twhile (timeLeft <= 0) {\n\t\t\t\tconst overflow = -timeLeft;\n\t\t\t\tstate.currentIndex += 1;\n\t\t\t\tif (state.currentIndex >= sequence.length) {\n\t\t\t\t\tif (!loop) {\n\t\t\t\t\t\tstate.done = true;\n\t\t\t\t\t\tme.moveXY(0, 0);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tstate.currentIndex = 0;\n\t\t\t\t}\n\t\t\t\tcurrent = sequence[state.currentIndex];\n\t\t\t\ttimeLeft = current.timeInSeconds - overflow;\n\t\t\t}\n\t\t\tstate.timeRemaining = timeLeft;\n\t\t}\n\t};\n}\n\n\n","import { Vector3 } from 'three';\nimport { RigidBody, Vector } from '@dimforge/rapier3d-compat';\n\nexport interface EntityWithBody {\n\tbody: RigidBody | null;\n}\n\n/**\n * Move an entity along the X axis, preserving other velocities\n */\nexport function moveX(entity: EntityWithBody, delta: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(delta, currentVelocity.y, currentVelocity.z);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the Y axis, preserving other velocities\n */\nexport function moveY(entity: EntityWithBody, delta: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(currentVelocity.x, delta, currentVelocity.z);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the Z axis, preserving other velocities\n */\nexport function moveZ(entity: EntityWithBody, delta: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(currentVelocity.x, currentVelocity.y, delta);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the X and Y axis, preserving Z velocity\n */\nexport function moveXY(entity: EntityWithBody, deltaX: number, deltaY: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(deltaX, deltaY, currentVelocity.z);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the X and Z axis, preserving Y velocity\n */\nexport function moveXZ(entity: EntityWithBody, deltaX: number, deltaZ: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(deltaX, currentVelocity.y, deltaZ);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move entity based on a vector, adding to existing velocities\n */\nexport function move(entity: EntityWithBody, vector: Vector3): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(\n\t\tcurrentVelocity.x + vector.x,\n\t\tcurrentVelocity.y + vector.y,\n\t\tcurrentVelocity.z + vector.z\n\t);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Reset entity velocity\n */\nexport function resetVelocity(entity: EntityWithBody): void {\n\tif (!entity.body) return;\n\tentity.body.setLinvel(new Vector3(0, 0, 0), true);\n\tentity.body.setLinearDamping(5);\n}\n\n/**\n * Move entity forward in 2D space, preserving Z velocity\n */\nexport function moveForwardXY(entity: EntityWithBody, delta: number, rotation2DAngle: number): void {\n\tconst deltaX = Math.sin(-rotation2DAngle) * delta;\n\tconst deltaY = Math.cos(-rotation2DAngle) * delta;\n\tmoveXY(entity, deltaX, deltaY);\n}\n\n/**\n * Get entity position\n */\nexport function getPosition(entity: EntityWithBody): Vector | null {\n\tif (!entity.body) return null;\n\treturn entity.body.translation();\n}\n\n/**\n * Get entity velocity\n */\nexport function getVelocity(entity: EntityWithBody): Vector | null {\n\tif (!entity.body) return null;\n\treturn entity.body.linvel();\n}\n\n/**\n * Set entity position\n */\nexport function setPosition(entity: EntityWithBody, x: number, y: number, z: number): void {\n\tif (!entity.body) return;\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity X position\n */\nexport function setPositionX(entity: EntityWithBody, x: number): void {\n\tif (!entity.body) return;\n\tconst { y, z } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity Y position\n */\nexport function setPositionY(entity: EntityWithBody, y: number): void {\n\tif (!entity.body) return;\n\tconst { x, z } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity Z position\n */\nexport function setPositionZ(entity: EntityWithBody, z: number): void {\n\tif (!entity.body) return;\n\tconst { x, y } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Wrap entity around 2D bounds\n */\nexport function wrapAroundXY(entity: EntityWithBody, boundsX: number, boundsY: number): void {\n\tconst position = getPosition(entity);\n\tif (!position) return;\n\n\tconst { x, y } = position;\n\tconst newX = x > boundsX ? -boundsX : (x < -boundsX ? boundsX : x);\n\tconst newY = y > boundsY ? -boundsY : (y < -boundsY ? boundsY : y);\n\n\tif (newX !== x || newY !== y) {\n\t\tsetPosition(entity, newX, newY, 0);\n\t}\n}\n\n/**\n * Wrap entity around 3D bounds\n */\nexport function wrapAround3D(entity: EntityWithBody, boundsX: number, boundsY: number, boundsZ: number): void {\n\tconst position = getPosition(entity);\n\tif (!position) return;\n\n\tconst { x, y, z } = position;\n\tconst newX = x > boundsX ? -boundsX : (x < -boundsX ? boundsX : x);\n\tconst newY = y > boundsY ? -boundsY : (y < -boundsY ? boundsY : y);\n\tconst newZ = z > boundsZ ? -boundsZ : (z < -boundsZ ? boundsZ : z);\n\n\tif (newX !== x || newY !== y || newZ !== z) {\n\t\tsetPosition(entity, newX, newY, newZ);\n\t}\n}\n\n/**\n * Enhanced moveable entity with bound methods\n */\nexport interface MoveableEntity extends EntityWithBody {\n\tmoveX(delta: number): void;\n\tmoveY(delta: number): void;\n\tmoveZ(delta: number): void;\n\tmoveXY(deltaX: number, deltaY: number): void;\n\tmoveXZ(deltaX: number, deltaZ: number): void;\n\tmove(vector: Vector3): void;\n\tresetVelocity(): void;\n\tmoveForwardXY(delta: number, rotation2DAngle: number): void;\n\tgetPosition(): Vector | null;\n\tgetVelocity(): Vector | null;\n\tsetPosition(x: number, y: number, z: number): void;\n\tsetPositionX(x: number): void;\n\tsetPositionY(y: number): void;\n\tsetPositionZ(z: number): void;\n\twrapAroundXY(boundsX: number, boundsY: number): void;\n\twrapAround3D(boundsX: number, boundsY: number, boundsZ: number): void;\n}\n\n/**\n * Class decorator to enhance an entity with additive movement methods\n */\nexport function moveable<T extends { new(...args: any[]): EntityWithBody }>(constructor: T) {\n\treturn class extends constructor implements MoveableEntity {\n\t\tmoveX(delta: number): void {\n\t\t\tmoveX(this, delta);\n\t\t}\n\t\tmoveY(delta: number): void {\n\t\t\tmoveY(this, delta);\n\t\t}\n\t\tmoveZ(delta: number): void {\n\t\t\tmoveZ(this, delta);\n\t\t}\n\t\tmoveXY(deltaX: number, deltaY: number): void {\n\t\t\tmoveXY(this, deltaX, deltaY);\n\t\t}\n\t\tmoveXZ(deltaX: number, deltaZ: number): void {\n\t\t\tmoveXZ(this, deltaX, deltaZ);\n\t\t}\n\t\tmove(vector: Vector3): void {\n\t\t\tmove(this, vector);\n\t\t}\n\t\tresetVelocity(): void {\n\t\t\tresetVelocity(this);\n\t\t}\n\t\tmoveForwardXY(delta: number, rotation2DAngle: number): void {\n\t\t\tmoveForwardXY(this, delta, rotation2DAngle);\n\t\t}\n\t\tgetPosition(): Vector | null {\n\t\t\treturn getPosition(this);\n\t\t}\n\t\tgetVelocity(): Vector | null {\n\t\t\treturn getVelocity(this);\n\t\t}\n\t\tsetPosition(x: number, y: number, z: number): void {\n\t\t\tsetPosition(this, x, y, z);\n\t\t}\n\t\tsetPositionX(x: number): void {\n\t\t\tsetPositionX(this, x);\n\t\t}\n\t\tsetPositionY(y: number): void {\n\t\t\tsetPositionY(this, y);\n\t\t}\n\t\tsetPositionZ(z: number): void {\n\t\t\tsetPositionZ(this, z);\n\t\t}\n\t\twrapAroundXY(boundsX: number, boundsY: number): void {\n\t\t\twrapAroundXY(this, boundsX, boundsY);\n\t\t}\n\t\twrapAround3D(boundsX: number, boundsY: number, boundsZ: number): void {\n\t\t\twrapAround3D(this, boundsX, boundsY, boundsZ);\n\t\t}\n\t};\n}\n\n/**\n * Enhance an entity with additive movement methods (retained for compatibility)\n */\nexport function makeMoveable<T extends EntityWithBody>(entity: T): T & MoveableEntity {\n\tconst moveable = entity as T & MoveableEntity;\n\n\tmoveable.moveX = (delta: number) => moveX(entity, delta);\n\tmoveable.moveY = (delta: number) => moveY(entity, delta);\n\tmoveable.moveZ = (delta: number) => moveZ(entity, delta);\n\tmoveable.moveXY = (deltaX: number, deltaY: number) => moveXY(entity, deltaX, deltaY);\n\tmoveable.moveXZ = (deltaX: number, deltaZ: number) => moveXZ(entity, deltaX, deltaZ);\n\tmoveable.move = (vector: Vector3) => move(entity, vector);\n\tmoveable.resetVelocity = () => resetVelocity(entity);\n\tmoveable.moveForwardXY = (delta: number, rotation2DAngle: number) => moveForwardXY(entity, delta, rotation2DAngle);\n\tmoveable.getPosition = () => getPosition(entity);\n\tmoveable.getVelocity = () => getVelocity(entity);\n\tmoveable.setPosition = (x: number, y: number, z: number) => setPosition(entity, x, y, z);\n\tmoveable.setPositionX = (x: number) => setPositionX(entity, x);\n\tmoveable.setPositionY = (y: number) => setPositionY(entity, y);\n\tmoveable.setPositionZ = (z: number) => setPositionZ(entity, z);\n\tmoveable.wrapAroundXY = (boundsX: number, boundsY: number) => wrapAroundXY(entity, boundsX, boundsY);\n\tmoveable.wrapAround3D = (boundsX: number, boundsY: number, boundsZ: number) => wrapAround3D(entity, boundsX, boundsY, boundsZ);\n\n\treturn moveable;\n}\n\n/**\n * Wrap a standalone function with movement capabilities\n */\nexport function withMovement<T extends (...args: any[]) => any>(\n\tfn: T,\n\tentity: EntityWithBody\n): (...args: Parameters<T>) => ReturnType<T> & MoveableEntity {\n\tconst wrapped = (...args: Parameters<T>) => {\n\t\tconst result = fn(...args);\n\t\tconst moveableEntity = makeMoveable(entity);\n\t\treturn Object.assign(result, moveableEntity);\n\t};\n\treturn wrapped as (...args: Parameters<T>) => ReturnType<T> & MoveableEntity;\n}","import { Euler, Vector3, MathUtils, Quaternion } from 'three';\nimport { RigidBody } from '@dimforge/rapier3d-compat';\n\nexport interface RotatableEntity {\n\tbody: RigidBody | null;\n\tgroup: any;\n}\n\n/**\n * Rotate an entity in the direction of a movement vector\n */\nexport function rotateInDirection(entity: RotatableEntity, moveVector: Vector3): void {\n\tif (!entity.body) return;\n\tconst rotate = Math.atan2(-moveVector.x, moveVector.z);\n\trotateYEuler(entity, rotate);\n}\n\n/**\n * Rotate an entity around the Y axis using Euler angles\n */\nexport function rotateYEuler(entity: RotatableEntity, amount: number): void {\n\trotateEuler(entity, new Vector3(0, -amount, 0));\n}\n\n/**\n * Rotate an entity using Euler angles\n */\nexport function rotateEuler(entity: RotatableEntity, rotation: Vector3): void {\n\tif (!entity.group) return;\n\tconst euler = new Euler(rotation.x, rotation.y, rotation.z);\n\tentity.group.setRotationFromEuler(euler);\n}\n\n/**\n * Rotate an entity around the Y axis\n */\nexport function rotateY(entity: RotatableEntity, delta: number): void {\n\tsetRotationY(entity, delta);\n}\n\n/**\n * Rotate an entity around the Z axis\n */\nexport function rotateZ(entity: RotatableEntity, delta: number): void {\n\tsetRotationZ(entity, delta);\n}\n\n/**\n * Set rotation around Y axis\n */\nexport function setRotationY(entity: RotatableEntity, y: number): void {\n\tif (!entity.body) return;\n\tconst halfAngle = y / 2;\n\tconst w = Math.cos(halfAngle);\n\tconst yComponent = Math.sin(halfAngle);\n\tentity.body.setRotation({ w: w, x: 0, y: yComponent, z: 0 }, true);\n}\n\n/**\n * Set rotation around Y axis\n */\nexport function setRotationDegreesY(entity: RotatableEntity, y: number): void {\n\tif (!entity.body) return;\n\tsetRotationY(entity, MathUtils.degToRad(y));\n}\n\n/**\n * Set rotation around X axis\n */\nexport function setRotationX(entity: RotatableEntity, x: number): void {\n\tif (!entity.body) return;\n\tconst halfAngle = x / 2;\n\tconst w = Math.cos(halfAngle);\n\tconst xComponent = Math.sin(halfAngle);\n\tentity.body.setRotation({ w: w, x: xComponent, y: 0, z: 0 }, true);\n}\n\n/**\n * Set rotation around X axis\n */\nexport function setRotationDegreesX(entity: RotatableEntity, x: number): void {\n\tif (!entity.body) return;\n\tsetRotationX(entity, MathUtils.degToRad(x));\n}\n\n/**\n * Set rotation around Z axis\n */\nexport function setRotationZ(entity: RotatableEntity, z: number): void {\n\tif (!entity.body) return;\n\tconst halfAngle = z / 2;\n\tconst w = Math.cos(halfAngle);\n\tconst zComponent = Math.sin(halfAngle);\n\tentity.body.setRotation({ w: w, x: 0, y: 0, z: zComponent }, true);\n}\n\n/**\n * Set rotation around Z axis\n */\nexport function setRotationDegreesZ(entity: RotatableEntity, z: number): void {\n\tif (!entity.body) return;\n\tsetRotationZ(entity, MathUtils.degToRad(z));\n}\n\n/**\n * Set rotation for all axes\n */\nexport function setRotation(entity: RotatableEntity, x: number, y: number, z: number): void {\n\tif (!entity.body) return;\n\tconst quat = new Quaternion().setFromEuler(new Euler(x, y, z));\n\tentity.body.setRotation({ w: quat.w, x: quat.x, y: quat.y, z: quat.z }, true);\n}\n\n/**\n * Set rotation for all axes\n */\nexport function setRotationDegrees(entity: RotatableEntity, x: number, y: number, z: number): void {\n\tif (!entity.body) return;\n\tsetRotation(entity, MathUtils.degToRad(x), MathUtils.degToRad(y), MathUtils.degToRad(z));\n}\n\n/**\n * Get current rotation\n */\nexport function getRotation(entity: RotatableEntity): any {\n\tif (!entity.body) return null;\n\treturn entity.body.rotation();\n}\n\n/**\n * Rotatable entity API with bound methods\n */\nexport interface RotatableEntityAPI extends RotatableEntity {\n\trotateInDirection(moveVector: Vector3): void;\n\trotateYEuler(amount: number): void;\n\trotateEuler(rotation: Vector3): void;\n\trotateY(delta: number): void;\n\trotateZ(delta: number): void;\n\tsetRotationY(y: number): void;\n\tsetRotationX(x: number): void;\n\tsetRotationZ(z: number): void;\n\tsetRotationDegrees(x: number, y: number, z: number): void;\n\tsetRotationDegreesY(y: number): void;\n\tsetRotationDegreesX(x: number): void;\n\tsetRotationDegreesZ(z: number): void;\n\tsetRotation(x: number, y: number, z: number): void;\n\tgetRotation(): any;\n}\n\n/**\n * Class decorator to enhance an entity with rotatable methods\n */\nexport function rotatable<T extends { new(...args: any[]): RotatableEntity }>(constructor: T) {\n\treturn class extends constructor implements RotatableEntityAPI {\n\t\trotateInDirection(moveVector: Vector3): void {\n\t\t\trotateInDirection(this, moveVector);\n\t\t}\n\t\trotateYEuler(amount: number): void {\n\t\t\trotateYEuler(this, amount);\n\t\t}\n\t\trotateEuler(rotation: Vector3): void {\n\t\t\trotateEuler(this, rotation);\n\t\t}\n\t\trotateY(delta: number): void {\n\t\t\trotateY(this, delta);\n\t\t}\n\t\trotateZ(delta: number): void {\n\t\t\trotateZ(this, delta);\n\t\t}\n\t\tsetRotationY(y: number): void {\n\t\t\tsetRotationY(this, y);\n\t\t}\n\t\tsetRotationX(x: number): void {\n\t\t\tsetRotationX(this, x);\n\t\t}\n\t\tsetRotationZ(z: number): void {\n\t\t\tsetRotationZ(this, z);\n\t\t}\n\t\tsetRotationDegrees(x: number, y: number, z: number): void {\n\t\t\tsetRotationDegrees(this, x, y, z);\n\t\t}\n\t\tsetRotationDegreesY(y: number): void {\n\t\t\tsetRotationDegreesY(this, y);\n\t\t}\n\t\tsetRotationDegreesX(x: number): void {\n\t\t\tsetRotationDegreesX(this, x);\n\t\t}\n\t\tsetRotationDegreesZ(z: number): void {\n\t\t\tsetRotationDegreesZ(this, z);\n\t\t}\n\t\tsetRotation(x: number, y: number, z: number): void {\n\t\t\tsetRotation(this, x, y, z);\n\t\t}\n\t\tgetRotation(): any {\n\t\t\treturn getRotation(this);\n\t\t}\n\t};\n}\n\n/**\n * Enhance an entity instance with rotatable methods\n */\nexport function makeRotatable<T extends RotatableEntity>(entity: T): T & RotatableEntityAPI {\n\tconst rotatableEntity = entity as T & RotatableEntityAPI;\n\n\trotatableEntity.rotateInDirection = (moveVector: Vector3) => rotateInDirection(entity, moveVector);\n\trotatableEntity.rotateYEuler = (amount: number) => rotateYEuler(entity, amount);\n\trotatableEntity.rotateEuler = (rotation: Vector3) => rotateEuler(entity, rotation);\n\trotatableEntity.rotateY = (delta: number) => rotateY(entity, delta);\n\trotatableEntity.rotateZ = (delta: number) => rotateZ(entity, delta);\n\trotatableEntity.setRotationY = (y: number) => setRotationY(entity, y);\n\trotatableEntity.setRotationX = (x: number) => setRotationX(entity, x);\n\trotatableEntity.setRotationZ = (z: number) => setRotationZ(entity, z);\n\trotatableEntity.setRotationDegreesY = (y: number) => setRotationDegreesY(entity, y);\n\trotatableEntity.setRotationDegreesX = (x: number) => setRotationDegreesX(entity, x);\n\trotatableEntity.setRotationDegreesZ = (z: number) => setRotationDegreesZ(entity, z);\n\trotatableEntity.setRotationDegrees = (x: number, y: number, z: number) => setRotationDegrees(entity, x, y, z);\n\trotatableEntity.setRotation = (x: number, y: number, z: number) => setRotation(entity, x, y, z);\n\trotatableEntity.getRotation = () => getRotation(entity);\n\n\treturn rotatableEntity;\n}","import { makeMoveable, EntityWithBody, MoveableEntity } from './moveable';\nimport { makeRotatable, RotatableEntity, RotatableEntityAPI } from './rotatable';\n\n/**\n * Enhance an entity with both movement and rotation capabilities.\n */\nexport function makeTransformable<\n\tT extends RotatableEntity & EntityWithBody\n>(entity: T): T & MoveableEntity & RotatableEntityAPI {\n\tconst withMovement = makeMoveable(entity);\n\tconst withRotation = makeRotatable(withMovement);\n\treturn withRotation;\n}\n\n\n","import { DestroyContext, DestroyFunction } from \"../core/base-node-life-cycle\";\nimport { getGlobals } from \"../game/game-state\";\n\nexport function destroyEntity<T>(entity: T, globals: any, destroyFunction: DestroyFunction<T>): void {\n\tconst context: DestroyContext<T> = {\n\t\tme: entity,\n\t\tglobals\n\t};\n\tdestroyFunction(context);\n}\n\nexport function destroy(entity: any, globals?: any): void {\n\tconst resolvedGlobals = globals ?? getGlobals();\n\tdestroyEntity(entity, resolvedGlobals, entity.nodeDestroy.bind(entity));\n}","/**\n * Plays a ricochet sound effect when boundary collision occurs\n */\nexport function ricochetSound(frequency: number = 800, duration: number = 0.05) {\n\t_ricochetSound(frequency, duration);\n}\n\nfunction _ricochetSound(frequency: number, duration: number) {\n\tconst audioCtx = new (window.AudioContext || (window as any).webkitAudioContext)();\n\tconst oscillator = audioCtx.createOscillator();\n\tconst gain = audioCtx.createGain();\n\n\toscillator.type = 'sawtooth';\n\toscillator.frequency.value = frequency;\n\n\tgain.gain.setValueAtTime(0.05, audioCtx.currentTime);\n\tgain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + duration);\n\n\toscillator.connect(gain);\n\tgain.connect(audioCtx.destination);\n\n\toscillator.start();\n\toscillator.stop(audioCtx.currentTime + duration);\n} ","/**\n * Plays a ping-pong beep sound effect.\n */\nexport function pingPongBeep(frequency: number = 440, duration: number = 0.1) {\n\t_pingPongBeep(frequency, duration);\n}\n\nfunction _pingPongBeep(frequency: number, duration: number) {\n\tconst audioCtx = new (window.AudioContext || (window as any).webkitAudioContext)();\n\tconst oscillator = audioCtx.createOscillator();\n\tconst gain = audioCtx.createGain();\n\n\toscillator.type = 'square';\n\toscillator.frequency.value = frequency;\n\n\tgain.gain.setValueAtTime(0.05, audioCtx.currentTime);\n\tgain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + duration);\n\n\toscillator.connect(gain);\n\tgain.connect(audioCtx.destination);\n\n\toscillator.start();\n\toscillator.stop(audioCtx.currentTime + duration);\n} ","import { UpdateContext } from \"../core/base-node-life-cycle\";\n\n/**\n * Listen for a single global key change inside an onUpdate pipeline.\n * Usage: onUpdate(globalChange('p1Score', (value) => { ... }))\n */\nexport function globalChange<T = any>(\n\tkey: string,\n\tcallback: (value: T, ctx: UpdateContext<any>) => void\n) {\n\tlet previousValue: T | undefined = undefined;\n\treturn (ctx: UpdateContext<any>) => {\n\t\tconst currentValue = ctx.globals?.[key] as T;\n\t\tif (previousValue !== currentValue) {\n\t\t\t// Ignore the very first undefined->value transition only if both are undefined\n\t\t\tif (!(previousValue === undefined && currentValue === undefined)) {\n\t\t\t\tcallback(currentValue, ctx);\n\t\t\t}\n\t\t\tpreviousValue = currentValue;\n\t\t}\n\t};\n}\n\n/**\n * Listen for multiple global key changes inside an onUpdate pipeline.\n * Calls back when any of the provided keys changes.\n * Usage: onUpdate(globalChanges(['p1Score','p2Score'], ([p1,p2]) => { ... }))\n */\nexport function globalChanges<T = any>(\n\tkeys: string[],\n\tcallback: (values: T[], ctx: UpdateContext<any>) => void\n) {\n\tlet previousValues: (T | undefined)[] = new Array(keys.length).fill(undefined);\n\treturn (ctx: UpdateContext<any>) => {\n\t\tconst currentValues = keys.map((k) => ctx.globals?.[k] as T);\n\t\tconst hasAnyChange = currentValues.some((val, idx) => previousValues[idx] !== val);\n\t\tif (hasAnyChange) {\n\t\t\t// Ignore initial all-undefined state\n\t\t\tconst allPrevUndef = previousValues.every((v) => v === undefined);\n\t\t\tconst allCurrUndef = currentValues.every((v) => v === undefined);\n\t\t\tif (!(allPrevUndef && allCurrUndef)) {\n\t\t\t\tcallback(currentValues as T[], ctx);\n\t\t\t}\n\t\t\tpreviousValues = currentValues;\n\t\t}\n\t};\n}\n\n\n/**\n * Listen for a single stage variable change inside an onUpdate pipeline.\n * Usage: onUpdate(variableChange('score', (value, ctx) => { ... }))\n */\nexport function variableChange<T = any>(\n\tkey: string,\n\tcallback: (value: T, ctx: UpdateContext<any>) => void\n) {\n\tlet previousValue: T | undefined = undefined;\n\treturn (ctx: UpdateContext<any>) => {\n\t\t// @ts-ignore - stage is optional on UpdateContext\n\t\tconst currentValue = (ctx.stage?.getVariable?.(key) ?? undefined) as T;\n\t\tif (previousValue !== currentValue) {\n\t\t\tif (!(previousValue === undefined && currentValue === undefined)) {\n\t\t\t\tcallback(currentValue, ctx);\n\t\t\t}\n\t\t\tpreviousValue = currentValue;\n\t\t}\n\t};\n}\n\n/**\n * Listen for multiple stage variable changes; fires when any changes.\n * Usage: onUpdate(variableChanges(['a','b'], ([a,b], ctx) => { ... }))\n */\nexport function variableChanges<T = any>(\n\tkeys: string[],\n\tcallback: (values: T[], ctx: UpdateContext<any>) => void\n) {\n\tlet previousValues: (T | undefined)[] = new Array(keys.length).fill(undefined);\n\treturn (ctx: UpdateContext<any>) => {\n\t\t// @ts-ignore - stage is optional on UpdateContext\n\t\tconst reader = (k: string) => ctx.stage?.getVariable?.(k) as T;\n\t\tconst currentValues = keys.map(reader);\n\t\tconst hasAnyChange = currentValues.some((val, idx) => previousValues[idx] !== val);\n\t\tif (hasAnyChange) {\n\t\t\tconst allPrevUndef = previousValues.every((v) => v === undefined);\n\t\t\tconst allCurrUndef = currentValues.every((v) => v === undefined);\n\t\t\tif (!(allPrevUndef && allCurrUndef)) {\n\t\t\t\tcallback(currentValues as T[], ctx);\n\t\t\t}\n\t\t\tpreviousValues = currentValues;\n\t\t}\n\t};\n}\n\n\n","import { Game } from '../lib/game/game';\nimport { debugState, setDebugTool, setPaused, type DebugTools } from '../lib/debug/debug-state';\n\n/**\n * State interface for editor-to-game communication\n */\nexport interface ZylemGameState {\n gameState?: {\n debugFlag?: boolean;\n [key: string]: unknown;\n };\n toolbarState?: {\n tool?: DebugTools;\n paused?: boolean;\n };\n [key: string]: unknown;\n}\n\nexport class ZylemGameElement extends HTMLElement {\n private _game: Game<any> | null = null;\n private _state: ZylemGameState = {};\n private container: HTMLElement;\n\n constructor() {\n super();\n this.attachShadow({ mode: 'open' });\n this.container = document.createElement('div');\n this.container.style.width = '100%';\n this.container.style.height = '100%';\n this.container.style.position = 'relative';\n this.shadowRoot!.appendChild(this.container);\n }\n\n set game(game: Game<any>) {\n // Dispose previous game if one exists\n if (this._game) {\n this._game.dispose();\n }\n \n this._game = game;\n game.options.push({ container: this.container });\n game.start();\n }\n\n get game(): Game<any> | null {\n return this._game;\n }\n\n set state(value: ZylemGameState) {\n this._state = value;\n this.syncDebugState();\n this.syncToolbarState();\n }\n\n get state(): ZylemGameState {\n return this._state;\n }\n\n /**\n * Sync the web component's state with the game-lib's internal debug state\n */\n private syncDebugState(): void {\n const debugFlag = this._state.gameState?.debugFlag;\n if (debugFlag !== undefined) {\n debugState.enabled = debugFlag;\n }\n }\n\n /**\n * Sync toolbar state with game-lib's debug state\n */\n private syncToolbarState(): void {\n const { tool, paused } = this._state.toolbarState ?? {};\n if (tool !== undefined) {\n setDebugTool(tool);\n }\n if (paused !== undefined) {\n setPaused(paused);\n }\n }\n\n disconnectedCallback() {\n if (this._game) {\n this._game.dispose();\n this._game = null;\n }\n }\n}\n\ncustomElements.define('zylem-game', ZylemGameElement);\n","import { ZylemSprite, SPRITE_TYPE } from '../entities/sprite';\nimport { ZylemSphere, SPHERE_TYPE } from '../entities/sphere';\nimport { ZylemRect, RECT_TYPE } from '../entities/rect';\nimport { ZylemText, TEXT_TYPE } from '../entities/text';\nimport { ZylemBox, BOX_TYPE } from '../entities/box';\nimport { ZylemPlane, PLANE_TYPE } from '../entities/plane';\nimport { ZylemZone, ZONE_TYPE } from '../entities/zone';\nimport { ZylemActor, ACTOR_TYPE } from '../entities/actor';\nimport { BaseNode } from '../core/base-node';\n\n/**\n * Maps entity type symbols to their class types.\n * Used by getEntityByName to infer return types.\n */\nexport interface EntityTypeMap {\n\t[SPRITE_TYPE]: ZylemSprite;\n\t[SPHERE_TYPE]: ZylemSphere;\n\t[RECT_TYPE]: ZylemRect;\n\t[TEXT_TYPE]: ZylemText;\n\t[BOX_TYPE]: ZylemBox;\n\t[PLANE_TYPE]: ZylemPlane;\n\t[ZONE_TYPE]: ZylemZone;\n\t[ACTOR_TYPE]: ZylemActor;\n}\n\n/**\n * Type helper: if T is a known type symbol, return the mapped entity type.\n * Otherwise return BaseNode.\n */\nexport type EntityForType<T> = T extends keyof EntityTypeMap\n\t? EntityTypeMap[T]\n\t: BaseNode;\n\n// Re-export type symbols for convenience\nexport {\n\tSPRITE_TYPE,\n\tSPHERE_TYPE,\n\tRECT_TYPE,\n\tTEXT_TYPE,\n\tBOX_TYPE,\n\tPLANE_TYPE,\n\tZONE_TYPE,\n\tACTOR_TYPE,\n};\n"],"mappings":";;;;;;;;;;;AAQO,SAAS,UAAuB,KAAa,MAA6B;AAChF,MAAI,CAAC,KAAM,QAAO;AAClB,QAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,MAAI,UAAe;AACnB,aAAW,OAAO,MAAM;AACvB,QAAI,WAAW,QAAQ,OAAO,YAAY,UAAU;AACnD,aAAO;AAAA,IACR;AACA,cAAU,QAAQ,GAAG;AAAA,EACtB;AACA,SAAO;AACR;AAMO,SAAS,UAAU,KAAa,MAAc,OAAsB;AAC1E,MAAI,CAAC,KAAM;AACX,QAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,MAAI,UAAe;AACnB,WAAS,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK;AACzC,UAAM,MAAM,KAAK,CAAC;AAClB,QAAI,QAAQ,GAAG,KAAK,QAAQ,OAAO,QAAQ,GAAG,MAAM,UAAU;AAC7D,cAAQ,GAAG,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BAAgB,CAAC;AACtD,QAAI,SAAS,QAAW;AACtB,mBAAa,IAAI;AAAA,IACnB;AACA,QAAI,WAAW,QAAW;AACxB,gBAAU,MAAM;AAAA,IAClB;AAAA,EACF;AAAA,EAEA,uBAAuB;AACrB,QAAI,KAAK,OAAO;AACd,WAAK,MAAM,QAAQ;AACnB,WAAK,QAAQ;AAAA,IACf;AAAA,EACF;AACF;AAEA,eAAe,OAAO,cAAc,gBAAgB;;;AClFpD;","names":["proxy","destroy","Mesh","debug_default","init_debug","init_debug","debug_default","Color","ShaderMaterial","Vector3","BufferGeometry","Mesh","Color","ActiveCollisionTypes","ColliderDesc","Group","Vector3","Color","Vector3","TextureLoader","camera","state","position","Color","Vector3","proxy","subscribe","Color","Vector3","Color","Group","Mesh","Vector3","BufferGeometry","LineBasicMaterial","LineSegments","Vector2","hoveredUuid","rect","subscribe","Vector3","camera","camera","standard_default","init_standard","init_standard","camera","standard_default","Vector3","camera","state","Vector3","Object3D","WebGLRenderer","position","Vector2","Vector3","camera","Color","Vector3","subscribe","nanoid","state","camera","Vector2","Vector3","camera","proxy","Vector3","camera","proxy","initialDefaults","state","document","text","subscribe","camera","camera","getGameDefaultConfig","proxy","stageState","Color","Group","Vector2","MeshStandardMaterial","MeshBasicMaterial","MeshPhongMaterial","x","y","z","toDeg","Vector2","Group","text","Color","camera","ColliderDesc","Color","Group","Quaternion","Vector3","TextureLoader","SpriteMaterial","ThreeSprite","Vector3","Color","ColliderDesc","TextureLoader","SpriteMaterial","ThreeSprite","Group","Quaternion","stageState","Euler","Quaternion","Vector2","ColliderDesc","BoxGeometry","Color","Vector3","Vector3","Color","ColliderDesc","BoxGeometry","ColliderDesc","Color","Vector3","Vector3","Color","ColliderDesc","ColliderDesc","Color","Vector2","Vector3","BufferGeometry","Vector2","Vector3","Color","scale","ColliderDesc","ActiveCollisionTypes","ColliderDesc","Vector3","Color","Group","ThreeSprite","SpriteMaterial","CanvasTexture","LinearFilter","Vector2","ClampToEdgeWrapping","ShaderMaterial","Mesh","PlaneGeometry","Vector3","Vector2","Group","CanvasTexture","LinearFilter","SpriteMaterial","ThreeSprite","ClampToEdgeWrapping","ShaderMaterial","Color","Mesh","PlaneGeometry","camera","Vector3","scale","position","scale","position","state","moveX","moveY","Vector3","position","moveable","Euler","Vector3","Quaternion","rotation","THREE","RAPIER"]}
1
+ {"version":3,"sources":["../src/lib/core/utility/path-utils.ts","../src/lib/game/game-event-bus.ts","../src/lib/game/game-state.ts","../src/lib/debug/debug-state.ts","../src/lib/input/input-state.ts","../src/lib/input/keyboard-provider.ts","../src/lib/input/gamepad-provider.ts","../src/lib/input/input-manager.ts","../src/lib/core/three-addons/Timer.ts","../src/lib/device/aspect-ratio.ts","../src/lib/game/game-retro-resolutions.ts","../src/lib/game/game-config.ts","../src/lib/game/game-canvas.ts","../src/lib/game/game-debug-delegate.ts","../../../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/src/index.ts","../src/lib/events/event-emitter-delegate.ts","../src/lib/events/zylem-events.ts","../src/lib/events/index.ts","../src/lib/game/game-loading-delegate.ts","../src/lib/game/game-renderer-observer.ts","../src/lib/game/zylem-game.ts","../src/lib/core/flags.ts","../src/lib/core/base-node.ts","../src/lib/systems/transformable.system.ts","../src/lib/entities/entity.ts","../src/lib/entities/delegates/loader.ts","../src/lib/entities/create.ts","../src/lib/core/loaders/texture-loader.ts","../src/lib/core/loaders/gltf-loader.ts","../src/lib/core/loaders/fbx-loader.ts","../src/lib/core/loaders/obj-loader.ts","../src/lib/core/loaders/audio-loader.ts","../src/lib/core/loaders/file-loader.ts","../src/lib/core/loaders/index.ts","../src/lib/core/asset-manager.ts","../src/lib/core/entity-asset-loader.ts","../src/lib/entities/delegates/animation.ts","../src/lib/collision/collision-builder.ts","../src/lib/graphics/mesh.ts","../src/lib/core/utility/strings.ts","../src/lib/graphics/shaders/vertex/object.shader.ts","../src/lib/graphics/shaders/standard.shader.ts","../src/lib/graphics/material.ts","../src/lib/entities/builder.ts","../src/lib/entities/common.ts","../src/lib/entities/actor.ts","../src/lib/collision/world.ts","../src/lib/graphics/zylem-scene.ts","../src/lib/core/utility/vector.ts","../src/lib/stage/stage-state.ts","../src/lib/core/lifecycle-base.ts","../src/lib/stage/debug-entity-cursor.ts","../src/lib/stage/stage-debug-delegate.ts","../src/lib/stage/stage-camera-debug-delegate.ts","../src/lib/camera/perspective.ts","../src/lib/camera/third-person.ts","../src/lib/camera/fixed-2d.ts","../src/lib/graphics/render-pass.ts","../src/lib/camera/camera-debug-delegate.ts","../src/lib/camera/zylem-camera.ts","../src/lib/stage/stage-camera-delegate.ts","../src/lib/stage/stage-loading-delegate.ts","../src/lib/stage/stage-entity-model-delegate.ts","../src/lib/core/utility/options-parser.ts","../src/lib/stage/stage-config.ts","../src/lib/stage/zylem-stage.ts","../src/lib/camera/camera.ts","../src/lib/stage/stage-default.ts","../src/lib/stage/stage.ts","../src/lib/game/game-default.ts","../src/lib/core/utility/nodes.ts","../src/lib/stage/stage-manager.ts","../src/lib/entities/delegates/debug.ts","../src/lib/entities/text.ts","../src/lib/entities/sprite.ts","../src/lib/entities/entity-factory.ts","../src/lib/stage/stage-factory.ts","../src/lib/game/game.ts","../src/lib/stage/entity-spawner.ts","../src/lib/core/vessel.ts","../src/lib/entities/box.ts","../src/lib/entities/sphere.ts","../src/lib/graphics/geometries/XZPlaneGeometry.ts","../src/lib/entities/plane.ts","../src/lib/entities/zone.ts","../src/lib/entities/rect.ts","../src/lib/entities/disk.ts","../src/lib/behaviors/behavior-descriptor.ts","../src/lib/behaviors/use-behavior.ts","../src/lib/behaviors/components.ts","../src/lib/behaviors/physics-step.behavior.ts","../src/lib/behaviors/physics-sync.behavior.ts","../src/lib/behaviors/thruster/components.ts","../src/lib/behaviors/thruster/thruster-fsm.ts","../src/lib/behaviors/thruster/thruster-movement.behavior.ts","../src/lib/behaviors/thruster/thruster.descriptor.ts","../src/lib/behaviors/thruster/index.ts","../src/lib/behaviors/screen-wrap/screen-wrap-fsm.ts","../src/lib/behaviors/screen-wrap/screen-wrap.descriptor.ts","../src/lib/behaviors/screen-wrap/index.ts","../src/lib/behaviors/world-boundary-2d/world-boundary-2d-fsm.ts","../src/lib/behaviors/world-boundary-2d/world-boundary-2d.descriptor.ts","../src/lib/behaviors/world-boundary-2d/index.ts","../src/lib/behaviors/ricochet-2d/ricochet-2d-fsm.ts","../src/lib/behaviors/ricochet-2d/ricochet-2d.descriptor.ts","../src/lib/behaviors/ricochet-2d/index.ts","../src/lib/behaviors/movement-sequence-2d/movement-sequence-2d-fsm.ts","../src/lib/behaviors/movement-sequence-2d/movement-sequence-2d.descriptor.ts","../src/lib/behaviors/movement-sequence-2d/index.ts","../src/lib/coordinators/boundary-ricochet.coordinator.ts","../src/lib/behaviors/index.ts","../src/lib/actions/capabilities/moveable.ts","../src/lib/actions/capabilities/rotatable.ts","../src/lib/actions/capabilities/transformable.ts","../src/lib/entities/destroy.ts","../src/lib/sounds/ricochet-sound.ts","../src/lib/sounds/ping-pong-sound.ts","../src/lib/sounds/index.ts","../src/lib/actions/global-change.ts","../src/web-components/zylem-game.ts","../src/lib/types/entity-type-map.ts","../src/lib/graphics/shaders/fire.shader.ts","../src/lib/graphics/shaders/star.shader.ts","../src/lib/graphics/shaders/vertex/debug.shader.ts","../src/lib/graphics/shaders/debug.shader.ts","../src/api/main.ts"],"sourcesContent":["/**\n * Lodash-style path utilities for getting/setting nested object values.\n */\n\n/**\n * Get a value from an object by path string.\n * @example getByPath({ player: { health: 100 } }, 'player.health') // 100\n */\nexport function getByPath<T = unknown>(obj: object, path: string): T | undefined {\n\tif (!path) return undefined;\n\tconst keys = path.split('.');\n\tlet current: any = obj;\n\tfor (const key of keys) {\n\t\tif (current == null || typeof current !== 'object') {\n\t\t\treturn undefined;\n\t\t}\n\t\tcurrent = current[key];\n\t}\n\treturn current as T;\n}\n\n/**\n * Set a value on an object by path string, creating intermediate objects as needed.\n * @example setByPath({}, 'player.health', 100) // { player: { health: 100 } }\n */\nexport function setByPath(obj: object, path: string, value: unknown): void {\n\tif (!path) return;\n\tconst keys = path.split('.');\n\tlet current: any = obj;\n\tfor (let i = 0; i < keys.length - 1; i++) {\n\t\tconst key = keys[i];\n\t\tif (current[key] == null || typeof current[key] !== 'object') {\n\t\t\tcurrent[key] = {};\n\t\t}\n\t\tcurrent = current[key];\n\t}\n\tcurrent[keys[keys.length - 1]] = value;\n}\n\n/**\n * Check if a path exists in an object.\n */\nexport function hasPath(obj: object, path: string): boolean {\n\tif (!path) return false;\n\tconst keys = path.split('.');\n\tlet current: any = obj;\n\tfor (const key of keys) {\n\t\tif (current == null || typeof current !== 'object' || !(key in current)) {\n\t\t\treturn false;\n\t\t}\n\t\tcurrent = current[key];\n\t}\n\treturn true;\n}\n","import { LoadingEvent } from '../core/interfaces';\n\n/**\n * Event types for the game event bus.\n */\nexport type GameEventType = \n\t| 'stage:loading:start'\n\t| 'stage:loading:progress'\n\t| 'stage:loading:complete'\n\t| 'game:state:updated';\n\n/**\n * Payload for stage loading events.\n */\nexport interface StageLoadingPayload extends LoadingEvent {\n\tstageName?: string;\n\tstageIndex?: number;\n}\n\n/**\n * Payload for game state update events.\n */\nexport interface GameStateUpdatedPayload {\n\tpath: string;\n\tvalue: unknown;\n\tpreviousValue?: unknown;\n}\n\n/**\n * Event map for typed event handling.\n */\nexport interface GameEventMap {\n\t'stage:loading:start': StageLoadingPayload;\n\t'stage:loading:progress': StageLoadingPayload;\n\t'stage:loading:complete': StageLoadingPayload;\n\t'game:state:updated': GameStateUpdatedPayload;\n}\n\ntype EventCallback<T> = (payload: T) => void;\n\n/**\n * Simple event bus for game-stage communication.\n * Used to decouple stage loading events from direct coupling.\n */\nexport class GameEventBus {\n\tprivate listeners: Map<GameEventType, Set<EventCallback<any>>> = new Map();\n\n\t/**\n\t * Subscribe to an event type.\n\t */\n\ton<K extends GameEventType>(event: K, callback: EventCallback<GameEventMap[K]>): () => void {\n\t\tif (!this.listeners.has(event)) {\n\t\t\tthis.listeners.set(event, new Set());\n\t\t}\n\t\tthis.listeners.get(event)!.add(callback);\n\t\treturn () => this.off(event, callback);\n\t}\n\n\t/**\n\t * Unsubscribe from an event type.\n\t */\n\toff<K extends GameEventType>(event: K, callback: EventCallback<GameEventMap[K]>): void {\n\t\tthis.listeners.get(event)?.delete(callback);\n\t}\n\n\t/**\n\t * Emit an event to all subscribers.\n\t */\n\temit<K extends GameEventType>(event: K, payload: GameEventMap[K]): void {\n\t\tconst callbacks = this.listeners.get(event);\n\t\tif (!callbacks) return;\n\t\tfor (const cb of callbacks) {\n\t\t\ttry {\n\t\t\t\tcb(payload);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(`Error in event handler for ${event}`, e);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Clear all listeners.\n\t */\n\tdispose(): void {\n\t\tthis.listeners.clear();\n\t}\n}\n\n/**\n * Singleton event bus instance for global game events.\n */\nexport const gameEventBus = new GameEventBus();\n","import { proxy, subscribe } from 'valtio/vanilla';\nimport { getByPath, setByPath } from '../core/utility/path-utils';\nimport { gameEventBus } from './game-event-bus';\n\n/**\n * Internal game state store using valtio proxy for reactivity.\n */\nconst state = proxy({\n\tid: '',\n\tglobals: {} as Record<string, unknown>,\n\ttime: 0,\n});\n\n/**\n * Track active subscriptions for cleanup on game dispose.\n */\nconst activeSubscriptions: Set<() => void> = new Set();\n\n/**\n * Set a global value by path.\n * Emits a 'game:state:updated' event when the value changes.\n * @example setGlobal('score', 100)\n * @example setGlobal('player.health', 50)\n */\nexport function setGlobal(path: string, value: unknown): void {\n\tconst previousValue = getByPath(state.globals, path);\n\tsetByPath(state.globals, path, value);\n\n\tgameEventBus.emit('game:state:updated', {\n\t\tpath,\n\t\tvalue,\n\t\tpreviousValue,\n\t});\n}\n\n/**\n * Create/initialize a global with a default value.\n * Only sets the value if it doesn't already exist.\n * Use this to ensure globals have initial values before game starts.\n * @example createGlobal('score', 0)\n * @example createGlobal('player.health', 100)\n */\nexport function createGlobal<T>(path: string, defaultValue: T): T {\n\tconst existing = getByPath<T>(state.globals, path);\n\tif (existing === undefined) {\n\t\tsetByPath(state.globals, path, defaultValue);\n\t\treturn defaultValue;\n\t}\n\treturn existing;\n}\n\n/**\n * Get a global value by path.\n * @example getGlobal('score') // 100\n * @example getGlobal<number>('player.health') // 50\n */\nexport function getGlobal<T = unknown>(path: string): T | undefined {\n\treturn getByPath<T>(state.globals, path);\n}\n\n/**\n * Subscribe to changes on a global value at a specific path.\n * Returns an unsubscribe function. Subscriptions are automatically\n * cleaned up when the game is disposed.\n * @example const unsub = onGlobalChange('score', (val) => console.log(val));\n */\nexport function onGlobalChange<T = unknown>(\n\tpath: string,\n\tcallback: (value: T) => void\n): () => void {\n\tlet previous = getByPath<T>(state.globals, path);\n\tconst unsub = subscribe(state.globals, () => {\n\t\tconst current = getByPath<T>(state.globals, path);\n\t\tif (current !== previous) {\n\t\t\tprevious = current;\n\t\t\tcallback(current as T);\n\t\t}\n\t});\n\tactiveSubscriptions.add(unsub);\n\treturn () => {\n\t\tunsub();\n\t\tactiveSubscriptions.delete(unsub);\n\t};\n}\n\n/**\n * Subscribe to changes on multiple global paths.\n * Callback fires when any of the paths change, receiving all current values.\n * Subscriptions are automatically cleaned up when the game is disposed.\n * @example const unsub = onGlobalChanges(['score', 'lives'], ([score, lives]) => console.log(score, lives));\n */\nexport function onGlobalChanges<T extends unknown[] = unknown[]>(\n\tpaths: string[],\n\tcallback: (values: T) => void\n): () => void {\n\tlet previousValues = paths.map(p => getByPath(state.globals, p));\n\tconst unsub = subscribe(state.globals, () => {\n\t\tconst currentValues = paths.map(p => getByPath(state.globals, p));\n\t\tconst hasChange = currentValues.some((val, i) => val !== previousValues[i]);\n\t\tif (hasChange) {\n\t\t\tpreviousValues = currentValues;\n\t\t\tcallback(currentValues as T);\n\t\t}\n\t});\n\tactiveSubscriptions.add(unsub);\n\treturn () => {\n\t\tunsub();\n\t\tactiveSubscriptions.delete(unsub);\n\t};\n}\n\n/**\n * Get the entire globals object (read-only snapshot).\n */\nexport function getGlobals<T = Record<string, unknown>>(): T {\n\treturn state.globals as T;\n}\n\n/**\n * Initialize globals from an object. Used internally during game setup.\n */\nexport function initGlobals(globals: Record<string, unknown>): void {\n\tfor (const [key, value] of Object.entries(globals)) {\n\t\tsetByPath(state.globals, key, value);\n\t}\n}\n\n/**\n * Reset all globals. Used internally on game dispose.\n */\nexport function resetGlobals(): void {\n\tstate.globals = {};\n}\n\n/**\n * Unsubscribe all active global subscriptions.\n * Used internally on game dispose to prevent old callbacks from firing.\n */\nexport function clearGlobalSubscriptions(): void {\n\tfor (const unsub of activeSubscriptions) {\n\t\tunsub();\n\t}\n\tactiveSubscriptions.clear();\n}\n\nexport { state };","import { proxy } from 'valtio';\nimport type { GameEntity } from '../entities/entity';\n\nexport type DebugTools = 'select' | 'translate' | 'rotate' | 'scale' | 'delete' | 'none';\n\nexport interface DebugState {\n\tenabled: boolean;\n\tpaused: boolean;\n\ttool: DebugTools;\n\tselectedEntity: GameEntity<any> | null;\n\thoveredEntity: GameEntity<any> | null;\n\tflags: Set<string>;\n}\n\nexport const debugState = proxy<DebugState>({\n\tenabled: false,\n\tpaused: false,\n\ttool: 'none',\n\tselectedEntity: null,\n\thoveredEntity: null,\n\tflags: new Set(),\n});\n\nexport function isPaused(): boolean {\n\treturn debugState.paused;\n}\n\nexport function setPaused(paused: boolean): void {\n\tdebugState.paused = paused;\n}\n\nexport function setDebugFlag(flag: string, value: boolean): void {\n\tif (value) {\n\t\tdebugState.flags.add(flag);\n\t} else {\n\t\tdebugState.flags.delete(flag);\n\t}\n}\n\nexport function getDebugTool(): DebugTools {\n\treturn debugState.tool;\n}\n\nexport function setDebugTool(tool: DebugTools): void {\n\tdebugState.tool = tool;\n}\n\nexport function getSelectedEntity(): GameEntity<any> | null {\n\treturn debugState.selectedEntity;\n}\n\nexport function setSelectedEntity(entity: GameEntity<any> | null): void {\n\tdebugState.selectedEntity = entity;\n}\n\nexport function getHoveredEntity(): GameEntity<any> | null {\n\treturn debugState.hoveredEntity;\n}\n\nexport function setHoveredEntity(entity: GameEntity<any> | null): void {\n\tdebugState.hoveredEntity = entity;\n}\n\nexport function resetHoveredEntity(): void {\n\tdebugState.hoveredEntity = null;\n}\n","import { InputGamepad, ButtonState, AnalogState, InputPlayerNumber } from './input';\n\n/**\n * Represents a direct property path for efficient state updates.\n * Avoids string parsing on every frame.\n */\ninterface PropertyPath {\n\tcategory: 'buttons' | 'directions' | 'shoulders' | 'axes';\n\tproperty: string;\n}\n\n/**\n * Pre-computed mapping from keyboard key to input properties.\n * Built once at initialization to avoid per-frame string parsing.\n */\ntype CompiledMapping = Map<string, PropertyPath[]>;\n\n/**\n * Creates a default ButtonState\n */\nfunction createButtonState(): ButtonState {\n\treturn { pressed: false, released: false, held: 0 };\n}\n\n/**\n * Creates a default AnalogState\n */\nfunction createAnalogState(): AnalogState {\n\treturn { value: 0, held: 0 };\n}\n\n/**\n * Creates a fresh InputGamepad state object\n */\nexport function createInputGamepadState(playerNumber: InputPlayerNumber): InputGamepad {\n\treturn {\n\t\tplayerNumber,\n\t\tbuttons: {\n\t\t\tA: createButtonState(),\n\t\t\tB: createButtonState(),\n\t\t\tX: createButtonState(),\n\t\t\tY: createButtonState(),\n\t\t\tStart: createButtonState(),\n\t\t\tSelect: createButtonState(),\n\t\t\tL: createButtonState(),\n\t\t\tR: createButtonState(),\n\t\t},\n\t\tdirections: {\n\t\t\tUp: createButtonState(),\n\t\t\tDown: createButtonState(),\n\t\t\tLeft: createButtonState(),\n\t\t\tRight: createButtonState(),\n\t\t},\n\t\tshoulders: {\n\t\t\tLTrigger: createButtonState(),\n\t\t\tRTrigger: createButtonState(),\n\t\t},\n\t\taxes: {\n\t\t\tHorizontal: createAnalogState(),\n\t\t\tVertical: createAnalogState(),\n\t\t},\n\t};\n}\n\n/**\n * Compiles a keyboard mapping into efficient property paths.\n * This is done once at initialization instead of every frame.\n * \n * @param mapping - Raw mapping from config (e.g., { 'w': ['directions.Up'] })\n * @returns Compiled mapping for O(1) lookups\n */\nexport function compileMapping(mapping: Record<string, string[]> | null): CompiledMapping {\n\tconst compiled = new Map<string, PropertyPath[]>();\n\t\n\tif (!mapping) return compiled;\n\n\tfor (const [key, targets] of Object.entries(mapping)) {\n\t\tif (!targets || targets.length === 0) continue;\n\t\t\n\t\tconst paths: PropertyPath[] = [];\n\t\t\n\t\tfor (const target of targets) {\n\t\t\tconst [rawCategory, rawName] = (target || '').split('.');\n\t\t\tif (!rawCategory || !rawName) continue;\n\t\t\t\n\t\t\tconst category = rawCategory.toLowerCase();\n\t\t\tconst nameKey = rawName.toLowerCase();\n\t\t\t\n\t\t\t// Map category and property name\n\t\t\tif (category === 'buttons') {\n\t\t\t\tconst propertyMap: Record<string, string> = {\n\t\t\t\t\t'a': 'A', 'b': 'B', 'x': 'X', 'y': 'Y',\n\t\t\t\t\t'start': 'Start', 'select': 'Select',\n\t\t\t\t\t'l': 'L', 'r': 'R',\n\t\t\t\t};\n\t\t\t\tconst prop = propertyMap[nameKey];\n\t\t\t\tif (prop) {\n\t\t\t\t\tpaths.push({ category: 'buttons', property: prop });\n\t\t\t\t}\n\t\t\t} else if (category === 'directions') {\n\t\t\t\tconst propertyMap: Record<string, string> = {\n\t\t\t\t\t'up': 'Up', 'down': 'Down', 'left': 'Left', 'right': 'Right',\n\t\t\t\t};\n\t\t\t\tconst prop = propertyMap[nameKey];\n\t\t\t\tif (prop) {\n\t\t\t\t\tpaths.push({ category: 'directions', property: prop });\n\t\t\t\t}\n\t\t\t} else if (category === 'shoulders') {\n\t\t\t\tconst propertyMap: Record<string, string> = {\n\t\t\t\t\t'ltrigger': 'LTrigger', 'rtrigger': 'RTrigger',\n\t\t\t\t};\n\t\t\t\tconst prop = propertyMap[nameKey];\n\t\t\t\tif (prop) {\n\t\t\t\t\tpaths.push({ category: 'shoulders', property: prop });\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (paths.length > 0) {\n\t\t\tcompiled.set(key, paths);\n\t\t}\n\t}\n\t\n\treturn compiled;\n}\n\n/**\n * Merges two ButtonStates efficiently\n */\nexport function mergeButtonState(a: ButtonState | undefined, b: ButtonState | undefined): ButtonState {\n\tif (!a && !b) return createButtonState();\n\tif (!a) return { ...b! };\n\tif (!b) return { ...a };\n\t\n\treturn {\n\t\tpressed: a.pressed || b.pressed,\n\t\treleased: a.released || b.released,\n\t\theld: a.held + b.held,\n\t};\n}\n\n/**\n * Merges two AnalogStates efficiently\n */\nexport function mergeAnalogState(a: AnalogState | undefined, b: AnalogState | undefined): AnalogState {\n\tif (!a && !b) return createAnalogState();\n\tif (!a) return { ...b! };\n\tif (!b) return { ...a };\n\t\n\treturn {\n\t\tvalue: a.value + b.value,\n\t\theld: a.held + b.held,\n\t};\n}\n\n/**\n * Merges two InputGamepad objects efficiently.\n * Reuses the target object structure to minimize allocations.\n */\nexport function mergeInputGamepads(target: InputGamepad, source: Partial<InputGamepad>): void {\n\t// Merge buttons\n\tif (source.buttons) {\n\t\ttarget.buttons.A = mergeButtonState(target.buttons.A, source.buttons.A);\n\t\ttarget.buttons.B = mergeButtonState(target.buttons.B, source.buttons.B);\n\t\ttarget.buttons.X = mergeButtonState(target.buttons.X, source.buttons.X);\n\t\ttarget.buttons.Y = mergeButtonState(target.buttons.Y, source.buttons.Y);\n\t\ttarget.buttons.Start = mergeButtonState(target.buttons.Start, source.buttons.Start);\n\t\ttarget.buttons.Select = mergeButtonState(target.buttons.Select, source.buttons.Select);\n\t\ttarget.buttons.L = mergeButtonState(target.buttons.L, source.buttons.L);\n\t\ttarget.buttons.R = mergeButtonState(target.buttons.R, source.buttons.R);\n\t}\n\t\n\t// Merge directions\n\tif (source.directions) {\n\t\ttarget.directions.Up = mergeButtonState(target.directions.Up, source.directions.Up);\n\t\ttarget.directions.Down = mergeButtonState(target.directions.Down, source.directions.Down);\n\t\ttarget.directions.Left = mergeButtonState(target.directions.Left, source.directions.Left);\n\t\ttarget.directions.Right = mergeButtonState(target.directions.Right, source.directions.Right);\n\t}\n\t\n\t// Merge shoulders\n\tif (source.shoulders) {\n\t\ttarget.shoulders.LTrigger = mergeButtonState(target.shoulders.LTrigger, source.shoulders.LTrigger);\n\t\ttarget.shoulders.RTrigger = mergeButtonState(target.shoulders.RTrigger, source.shoulders.RTrigger);\n\t}\n\t\n\t// Merge axes\n\tif (source.axes) {\n\t\ttarget.axes.Horizontal = mergeAnalogState(target.axes.Horizontal, source.axes.Horizontal);\n\t\ttarget.axes.Vertical = mergeAnalogState(target.axes.Vertical, source.axes.Vertical);\n\t}\n}\n","import { InputProvider } from './input-provider';\nimport { AnalogState, ButtonState, InputGamepad } from './input';\nimport { compileMapping, createInputGamepadState, mergeButtonState } from './input-state';\n\nexport class KeyboardProvider implements InputProvider {\n\tprivate keyStates = new Map<string, boolean>();\n\tprivate keyButtonStates = new Map<string, ButtonState>();\n\tprivate mapping: Record<string, string[]> | null = null;\n\tprivate compiledMapping: Map<string, Array<{ category: string; property: string }>>;\n\tprivate includeDefaultBase: boolean = true;\n\n\tconstructor(mapping?: Record<string, string[]>, options?: { includeDefaultBase?: boolean }) {\n\t\tconsole.log('[KeyboardProvider] Constructor called with mapping:', mapping, 'options:', options);\n\t\tthis.mapping = mapping ?? null;\n\t\tthis.includeDefaultBase = options?.includeDefaultBase ?? true;\n\t\t\n\t\t// Pre-compute the mapping at construction time\n\t\tconsole.log('[KeyboardProvider] About to call compileMapping with:', this.mapping);\n\t\tthis.compiledMapping = compileMapping(this.mapping);\n\t\tconsole.log('[KeyboardProvider] compileMapping returned, size:', this.compiledMapping.size);\n\t\t\n\t\twindow.addEventListener('keydown', ({ key }) => this.keyStates.set(key, true));\n\t\twindow.addEventListener('keyup', ({ key }) => this.keyStates.set(key, false));\n\t}\n\n\tprivate isKeyPressed(key: string): boolean {\n\t\treturn this.keyStates.get(key) || false;\n\t}\n\n\tprivate handleButtonState(key: string, delta: number): ButtonState {\n\t\tlet buttonState = this.keyButtonStates.get(key);\n\t\tconst isPressed = this.isKeyPressed(key);\n\n\t\tif (!buttonState) {\n\t\t\tbuttonState = { pressed: false, released: false, held: 0 };\n\t\t\tthis.keyButtonStates.set(key, buttonState);\n\t\t}\n\n\t\tif (isPressed) {\n\t\t\tif (buttonState.held === 0) {\n\t\t\t\tbuttonState.pressed = true;\n\t\t\t} else {\n\t\t\t\tbuttonState.pressed = false;\n\t\t\t}\n\t\t\tbuttonState.held += delta;\n\t\t\tbuttonState.released = false;\n\t\t} else {\n\t\t\tif (buttonState.held > 0) {\n\t\t\t\tbuttonState.released = true;\n\t\t\t\tbuttonState.held = 0;\n\t\t\t} else {\n\t\t\t\tbuttonState.released = false;\n\t\t\t}\n\t\t\tbuttonState.pressed = false;\n\t\t}\n\n\t\treturn buttonState;\n\t}\n\n\tprivate handleAnalogState(negativeKey: string, positiveKey: string, delta: number): AnalogState {\n\t\tconst value = this.getAxisValue(negativeKey, positiveKey);\n\t\treturn { value, held: delta };\n\t}\n\n\t/**\n\t * Optimized custom mapping application using pre-computed paths.\n\t * No string parsing happens here - all lookups are O(1).\n\t */\n\tprivate applyCustomMapping(input: Partial<InputGamepad>, delta: number): Partial<InputGamepad> {\n\t\tif (this.compiledMapping.size === 0) return input;\n\n\t\tfor (const [key, paths] of this.compiledMapping.entries()) {\n\t\t\tconst state = this.handleButtonState(key, delta);\n\t\t\t\n\t\t\tfor (const path of paths) {\n\t\t\t\tconst { category, property } = path;\n\t\t\t\t\n\t\t\t\tif (category === 'buttons') {\n\t\t\t\t\tif (!input.buttons) input.buttons = {} as any;\n\t\t\t\t\tconst nextButtons = input.buttons as any;\n\t\t\t\t\tnextButtons[property] = mergeButtonState(nextButtons[property], state);\n\t\t\t\t} else if (category === 'directions') {\n\t\t\t\t\tif (!input.directions) input.directions = {} as any;\n\t\t\t\t\tconst nextDirections = input.directions as any;\n\t\t\t\t\tnextDirections[property] = mergeButtonState(nextDirections[property], state);\n\t\t\t\t} else if (category === 'shoulders') {\n\t\t\t\t\tif (!input.shoulders) input.shoulders = {} as any;\n\t\t\t\t\tconst nextShoulders = input.shoulders as any;\n\t\t\t\t\tnextShoulders[property] = mergeButtonState(nextShoulders[property], state);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn input;\n\t}\n\n\tgetInput(delta: number): Partial<InputGamepad> {\n\t\tconst base: Partial<InputGamepad> = {};\n\t\tif (this.includeDefaultBase) {\n\t\t\tbase.buttons = {\n\t\t\t\tA: this.handleButtonState('z', delta),\n\t\t\t\tB: this.handleButtonState('x', delta),\n\t\t\t\tX: this.handleButtonState('a', delta),\n\t\t\t\tY: this.handleButtonState('s', delta),\n\t\t\t\tStart: this.handleButtonState(' ', delta),\n\t\t\t\tSelect: this.handleButtonState('Enter', delta),\n\t\t\t\tL: this.handleButtonState('q', delta),\n\t\t\t\tR: this.handleButtonState('e', delta),\n\t\t\t};\n\t\t\tbase.directions = {\n\t\t\t\tUp: this.handleButtonState('ArrowUp', delta),\n\t\t\t\tDown: this.handleButtonState('ArrowDown', delta),\n\t\t\t\tLeft: this.handleButtonState('ArrowLeft', delta),\n\t\t\t\tRight: this.handleButtonState('ArrowRight', delta),\n\t\t\t};\n\t\t\tbase.axes = {\n\t\t\t\tHorizontal: this.handleAnalogState('ArrowLeft', 'ArrowRight', delta),\n\t\t\t\tVertical: this.handleAnalogState('ArrowUp', 'ArrowDown', delta),\n\t\t\t};\n\t\t\tbase.shoulders = {\n\t\t\t\tLTrigger: this.handleButtonState('Q', delta),\n\t\t\t\tRTrigger: this.handleButtonState('E', delta),\n\t\t\t};\n\t\t}\n\t\tconst result = this.applyCustomMapping(base, delta);\n\t\t\n\t\t// DEBUG: Log when keys are pressed\n\t\tif (this.isKeyPressed('w') || this.isKeyPressed('s') || this.isKeyPressed('ArrowUp') || this.isKeyPressed('ArrowDown')) {\n\t\t\tconsole.log('[KeyboardProvider] includeDefaultBase:', this.includeDefaultBase);\n\t\t\tconsole.log('[KeyboardProvider] compiledMapping size:', this.compiledMapping.size);\n\t\t\tconsole.log('[KeyboardProvider] result.directions:', result.directions);\n\t\t}\n\t\t\n\t\treturn result;\n\t}\n\n\tgetName(): string {\n\t\treturn 'keyboard';\n\t}\n\n\tprivate getAxisValue(negativeKey: string, positiveKey: string): number {\n\t\treturn (this.isKeyPressed(positiveKey) ? 1 : 0) - (this.isKeyPressed(negativeKey) ? 1 : 0);\n\t}\n\n\tisConnected(): boolean {\n\t\treturn true;\n\t}\n} ","import { InputProvider } from './input-provider';\nimport { AnalogState, ButtonState, InputGamepad } from './input';\n\nexport class GamepadProvider implements InputProvider {\n\tprivate gamepadIndex: number;\n\tprivate connected: boolean = false;\n\n\tprivate buttonStates: Record<number, ButtonState> = {};\n\n\tconstructor(gamepadIndex: number) {\n\t\tthis.gamepadIndex = gamepadIndex;\n\t\twindow.addEventListener('gamepadconnected', (e) => {\n\t\t\tif (e.gamepad.index === this.gamepadIndex) {\n\t\t\t\tthis.connected = true;\n\t\t\t}\n\t\t});\n\t\twindow.addEventListener('gamepaddisconnected', (e) => {\n\t\t\tif (e.gamepad.index === this.gamepadIndex) {\n\t\t\t\tthis.connected = false;\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate handleButtonState(index: number, gamepad: Gamepad, delta: number): ButtonState {\n\t\tconst isPressed = gamepad.buttons[index].pressed;\n\t\tlet buttonState = this.buttonStates[index];\n\n\t\tif (!buttonState) {\n\t\t\tbuttonState = { pressed: false, released: false, held: 0 };\n\t\t\tthis.buttonStates[index] = buttonState;\n\t\t}\n\n\t\tif (isPressed) {\n\t\t\tif (buttonState.held === 0) {\n\t\t\t\tbuttonState.pressed = true;\n\t\t\t} else {\n\t\t\t\tbuttonState.pressed = false;\n\t\t\t}\n\t\t\tbuttonState.held += delta;\n\t\t\tbuttonState.released = false;\n\t\t} else {\n\t\t\tif (buttonState.held > 0) {\n\t\t\t\tbuttonState.released = true;\n\t\t\t\tbuttonState.held = 0;\n\t\t\t} else {\n\t\t\t\tbuttonState.released = false;\n\t\t\t}\n\t\t\tbuttonState.pressed = false;\n\t\t}\n\n\t\treturn buttonState;\n\t}\n\n\tprivate handleAnalogState(index: number, gamepad: Gamepad, delta: number): AnalogState {\n\t\tconst value = gamepad.axes[index];\n\t\treturn { value, held: delta };\n\t}\n\n\tgetInput(delta: number): Partial<InputGamepad> {\n\t\tconst gamepad = navigator.getGamepads()[this.gamepadIndex];\n\t\tif (!gamepad) return {};\n\n\t\treturn {\n\t\t\tbuttons: {\n\t\t\t\tA: this.handleButtonState(0, gamepad, delta),\n\t\t\t\tB: this.handleButtonState(1, gamepad, delta),\n\t\t\t\tX: this.handleButtonState(2, gamepad, delta),\n\t\t\t\tY: this.handleButtonState(3, gamepad, delta),\n\t\t\t\tStart: this.handleButtonState(9, gamepad, delta),\n\t\t\t\tSelect: this.handleButtonState(8, gamepad, delta),\n\t\t\t\tL: this.handleButtonState(4, gamepad, delta),\n\t\t\t\tR: this.handleButtonState(5, gamepad, delta),\n\t\t\t},\n\t\t\tdirections: {\n\t\t\t\tUp: this.handleButtonState(12, gamepad, delta),\n\t\t\t\tDown: this.handleButtonState(13, gamepad, delta),\n\t\t\t\tLeft: this.handleButtonState(14, gamepad, delta),\n\t\t\t\tRight: this.handleButtonState(15, gamepad, delta),\n\t\t\t},\n\t\t\taxes: {\n\t\t\t\tHorizontal: this.handleAnalogState(0, gamepad, delta),\n\t\t\t\tVertical: this.handleAnalogState(1, gamepad, delta),\n\t\t\t},\n\t\t\tshoulders: {\n\t\t\t\tLTrigger: this.handleButtonState(6, gamepad, delta),\n\t\t\t\tRTrigger: this.handleButtonState(7, gamepad, delta),\n\t\t\t}\n\t\t};\n\t}\n\n\tgetName(): string {\n\t\treturn `gamepad-${this.gamepadIndex + 1}`;\n\t}\n\n\tisConnected(): boolean {\n\t\treturn this.connected;\n\t}\n} ","import { InputProvider } from './input-provider';\nimport { AnalogState, ButtonState, InputGamepad, InputPlayerNumber, Inputs } from './input';\nimport { KeyboardProvider } from './keyboard-provider';\nimport { GamepadProvider } from './gamepad-provider';\nimport { GameInputConfig } from '../game/game-interfaces';\nimport { mergeButtonState, mergeAnalogState } from './input-state';\n\n\nexport class InputManager {\n\tprivate inputMap: Map<InputPlayerNumber, InputProvider[]> = new Map();\n\tprivate currentInputs: Inputs = {} as Inputs;\n\tprivate previousInputs: Inputs = {} as Inputs;\n\n\tconstructor(config?: GameInputConfig) {\n\t\tconsole.log('[InputManager] Constructor called with config:', config);\n\t\tconsole.log('[InputManager] config?.p1:', config?.p1);\n\t\tconsole.log('[InputManager] config?.p1?.key:', config?.p1?.key);\n\t\t\n\t\tif (config?.p1?.key) {\n\t\t\tconsole.log('[InputManager] Creating P1 KeyboardProvider with custom mapping:', config.p1.key);\n\t\t\tthis.addInputProvider(1, new KeyboardProvider(config.p1.key, { includeDefaultBase: false }));\n\t\t} else {\n\t\t\tconsole.log('[InputManager] Creating P1 KeyboardProvider with default mapping');\n\t\t\tthis.addInputProvider(1, new KeyboardProvider());\n\t\t}\n\t\tthis.addInputProvider(1, new GamepadProvider(0));\n\t\tif (config?.p2?.key) {\n\t\t\tthis.addInputProvider(2, new KeyboardProvider(config.p2.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(2, new GamepadProvider(1));\n\t\tif (config?.p3?.key) {\n\t\t\tthis.addInputProvider(3, new KeyboardProvider(config.p3.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(3, new GamepadProvider(2));\n\t\tif (config?.p4?.key) {\n\t\t\tthis.addInputProvider(4, new KeyboardProvider(config.p4.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(4, new GamepadProvider(3));\n\t\tif (config?.p5?.key) {\n\t\t\tthis.addInputProvider(5, new KeyboardProvider(config.p5.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(5, new GamepadProvider(4));\n\t\tif (config?.p6?.key) {\n\t\t\tthis.addInputProvider(6, new KeyboardProvider(config.p6.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(6, new GamepadProvider(5));\n\t\tif (config?.p7?.key) {\n\t\t\tthis.addInputProvider(7, new KeyboardProvider(config.p7.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(7, new GamepadProvider(6));\n\t\tif (config?.p8?.key) {\n\t\t\tthis.addInputProvider(8, new KeyboardProvider(config.p8.key, { includeDefaultBase: false }));\n\t\t}\n\t\tthis.addInputProvider(8, new GamepadProvider(7));\n\t}\n\n\taddInputProvider(playerNumber: InputPlayerNumber, provider: InputProvider) {\n\t\tif (!this.inputMap.has(playerNumber)) {\n\t\t\tthis.inputMap.set(playerNumber, []);\n\t\t}\n\t\tthis.inputMap.get(playerNumber)?.push(provider);\n\t}\n\n\tgetInputs(delta: number): Inputs {\n\t\tconst inputs = {} as Inputs;\n\t\tthis.inputMap.forEach((providers, playerNumber) => {\n\t\t\tconst playerKey = `p${playerNumber}` as const;\n\n\t\t\tconst mergedInput = providers.reduce((acc, provider) => {\n\t\t\t\tconst input = provider.getInput(delta);\n\t\t\t\treturn this.mergeInputs(acc, input);\n\t\t\t}, {} as Partial<InputGamepad>);\n\n\t\t\tinputs[playerKey] = {\n\t\t\t\tplayerNumber: playerNumber as InputPlayerNumber,\n\t\t\t\t...mergedInput\n\t\t\t} as InputGamepad;\n\t\t});\n\t\treturn inputs;\n\t}\n\n\tprivate mergeInputs(a: Partial<InputGamepad>, b: Partial<InputGamepad>): Partial<InputGamepad> {\n\t\treturn {\n\t\t\tbuttons: {\n\t\t\t\tA: mergeButtonState(a.buttons?.A, b.buttons?.A),\n\t\t\t\tB: mergeButtonState(a.buttons?.B, b.buttons?.B),\n\t\t\t\tX: mergeButtonState(a.buttons?.X, b.buttons?.X),\n\t\t\t\tY: mergeButtonState(a.buttons?.Y, b.buttons?.Y),\n\t\t\t\tStart: mergeButtonState(a.buttons?.Start, b.buttons?.Start),\n\t\t\t\tSelect: mergeButtonState(a.buttons?.Select, b.buttons?.Select),\n\t\t\t\tL: mergeButtonState(a.buttons?.L, b.buttons?.L),\n\t\t\t\tR: mergeButtonState(a.buttons?.R, b.buttons?.R),\n\t\t\t},\n\t\t\tdirections: {\n\t\t\t\tUp: mergeButtonState(a.directions?.Up, b.directions?.Up),\n\t\t\t\tDown: mergeButtonState(a.directions?.Down, b.directions?.Down),\n\t\t\t\tLeft: mergeButtonState(a.directions?.Left, b.directions?.Left),\n\t\t\t\tRight: mergeButtonState(a.directions?.Right, b.directions?.Right),\n\t\t\t},\n\t\t\taxes: {\n\t\t\t\tHorizontal: mergeAnalogState(a.axes?.Horizontal, b.axes?.Horizontal),\n\t\t\t\tVertical: mergeAnalogState(a.axes?.Vertical, b.axes?.Vertical),\n\t\t\t},\n\t\t\tshoulders: {\n\t\t\t\tLTrigger: mergeButtonState(a.shoulders?.LTrigger, b.shoulders?.LTrigger),\n\t\t\t\tRTrigger: mergeButtonState(a.shoulders?.RTrigger, b.shoulders?.RTrigger),\n\t\t\t}\n\t\t};\n\t}\n} ","/**\n * This class is an alternative to {@link Clock} with a different API design and behavior.\n * The goal is to avoid the conceptual flaws that became apparent in `Clock` over time.\n *\n * - `Timer` has an `update()` method that updates its internal state. That makes it possible to\n * call `getDelta()` and `getElapsed()` multiple times per simulation step without getting different values.\n * - The class can make use of the Page Visibility API to avoid large time delta values when the app\n * is inactive (e.g. tab switched or browser hidden).\n *\n * ```js\n * const timer = new Timer();\n * timer.connect( document ); // use Page Visibility API\n * ```\n *\n * @three_import import { Timer } from 'three/addons/misc/Timer.js';\n */\nclass Timer {\n\tprotected _previousTime: number;\n\tprotected _currentTime: number;\n\tprotected _startTime: number;\n\tprotected _delta: number;\n\tprotected _elapsed: number;\n\tprotected _timescale: number;\n\tprotected _document: Document | null;\n\tprotected _pageVisibilityHandler: (() => void) | null;\n\n\t/**\n\t * Constructs a new timer.\n\t */\n\tconstructor() {\n\n\t\tthis._previousTime = 0;\n\t\tthis._currentTime = 0;\n\t\tthis._startTime = now();\n\n\t\tthis._delta = 0;\n\t\tthis._elapsed = 0;\n\n\t\tthis._timescale = 1;\n\n\t\tthis._document = null;\n\t\tthis._pageVisibilityHandler = null;\n\n\t}\n\n\t/**\n\t * Connect the timer to the given document.Calling this method is not mandatory to\n\t * use the timer but enables the usage of the Page Visibility API to avoid large time\n\t * delta values.\n\t *\n\t * @param {Document} document - The document.\n\t */\n\tconnect(document: Document): void {\n\n\t\tthis._document = document;\n\n\t\t// use Page Visibility API to avoid large time delta values\n\n\t\tif (document.hidden !== undefined) {\n\n\t\t\tthis._pageVisibilityHandler = handleVisibilityChange.bind(this);\n\n\t\t\tdocument.addEventListener('visibilitychange', this._pageVisibilityHandler, false);\n\n\t\t}\n\n\t}\n\n\t/**\n\t * Disconnects the timer from the DOM and also disables the usage of the Page Visibility API.\n\t */\n\tdisconnect(): void {\n\n\t\tif (this._pageVisibilityHandler !== null) {\n\n\t\t\tthis._document!.removeEventListener('visibilitychange', this._pageVisibilityHandler);\n\t\t\tthis._pageVisibilityHandler = null;\n\n\t\t}\n\n\t\tthis._document = null;\n\n\t}\n\n\t/**\n\t * Returns the time delta in seconds.\n\t *\n\t * @return {number} The time delta in second.\n\t */\n\tgetDelta(): number {\n\n\t\treturn this._delta / 1000;\n\n\t}\n\n\t/**\n\t * Returns the elapsed time in seconds.\n\t *\n\t * @return {number} The elapsed time in second.\n\t */\n\tgetElapsed(): number {\n\n\t\treturn this._elapsed / 1000;\n\n\t}\n\n\t/**\n\t * Returns the timescale.\n\t *\n\t * @return {number} The timescale.\n\t */\n\tgetTimescale(): number {\n\n\t\treturn this._timescale;\n\n\t}\n\n\t/**\n\t * Sets the given timescale which scale the time delta computation\n\t * in `update()`.\n\t *\n\t * @param {number} timescale - The timescale to set.\n\t * @return {Timer} A reference to this timer.\n\t */\n\tsetTimescale(timescale: number): Timer {\n\n\t\tthis._timescale = timescale;\n\n\t\treturn this;\n\n\t}\n\n\t/**\n\t * Resets the time computation for the current simulation step.\n\t *\n\t * @return {Timer} A reference to this timer.\n\t */\n\treset(): Timer {\n\n\t\tthis._currentTime = now() - this._startTime;\n\n\t\treturn this;\n\n\t}\n\n\t/**\n\t * Can be used to free all internal resources. Usually called when\n\t * the timer instance isn't required anymore.\n\t */\n\tdispose(): void {\n\n\t\tthis.disconnect();\n\n\t}\n\n\t/**\n\t * Updates the internal state of the timer. This method should be called\n\t * once per simulation step and before you perform queries against the timer\n\t * (e.g. via `getDelta()`).\n\t *\n\t * @param {number} timestamp - The current time in milliseconds. Can be obtained\n\t * from the `requestAnimationFrame` callback argument. If not provided, the current\n\t * time will be determined with `performance.now`.\n\t * @return {Timer} A reference to this timer.\n\t */\n\tupdate(timestamp?: number): Timer {\n\n\t\tif (this._pageVisibilityHandler !== null && this._document!.hidden === true) {\n\n\t\t\tthis._delta = 0;\n\n\t\t} else {\n\n\t\t\tthis._previousTime = this._currentTime;\n\t\t\tthis._currentTime = (timestamp !== undefined ? timestamp : now()) - this._startTime;\n\n\t\t\tthis._delta = (this._currentTime - this._previousTime) * this._timescale;\n\t\t\tthis._elapsed += this._delta; // _elapsed is the accumulation of all previous deltas\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n}\n\n/**\n * A special version of a timer with a fixed time delta value.\n * Can be useful for testing and debugging purposes.\n *\n * @augments Timer\n */\nclass FixedTimer extends Timer {\n\n\t/**\n\t * Constructs a new timer.\n\t *\n\t * @param {number} [fps=60] - The fixed FPS of this timer.\n\t */\n\tconstructor(fps: number = 60) {\n\n\t\tsuper();\n\t\tthis._delta = (1 / fps) * 1000;\n\n\t}\n\n\tupdate(): FixedTimer {\n\n\t\tthis._elapsed += (this._delta * this._timescale); // _elapsed is the accumulation of all previous deltas\n\n\t\treturn this;\n\n\t}\n\n}\n\nfunction now(): number {\n\n\treturn performance.now();\n\n}\n\nfunction handleVisibilityChange(this: Timer): void {\n\n\tif (this._document!.hidden === false) this.reset();\n\n}\n\nexport { Timer, };","export const AspectRatio = {\n\tFourByThree: 4 / 3,\n\tSixteenByNine: 16 / 9,\n\tTwentyOneByNine: 21 / 9,\n\tOneByOne: 1 / 1,\n} as const;\n\nexport type AspectRatioValue = (typeof AspectRatio)[keyof typeof AspectRatio] | number;\n\n/**\n * AspectRatioDelegate manages sizing a canvas to fit within a container\n * while preserving a target aspect ratio. It notifies a consumer via\n * onResize when the final width/height are applied so renderers/cameras\n * can update their viewports.\n */\nexport class AspectRatioDelegate {\n\tcontainer: HTMLElement;\n\tcanvas: HTMLCanvasElement;\n\taspectRatio: number;\n\tonResize?: (width: number, height: number) => void;\n\tprivate handleResizeBound: () => void;\n\n\tconstructor(params: {\n\t\tcontainer: HTMLElement;\n\t\tcanvas: HTMLCanvasElement;\n\t\taspectRatio: AspectRatioValue;\n\t\tonResize?: (width: number, height: number) => void;\n\t}) {\n\t\tthis.container = params.container;\n\t\tthis.canvas = params.canvas;\n\t\tthis.aspectRatio = typeof params.aspectRatio === 'number' ? params.aspectRatio : params.aspectRatio;\n\t\tthis.onResize = params.onResize;\n\t\tthis.handleResizeBound = this.apply.bind(this);\n\t}\n\n\t/** Attach window resize listener and apply once. */\n\tattach() {\n\t\twindow.addEventListener('resize', this.handleResizeBound);\n\t\tthis.apply();\n\t}\n\n\t/** Detach window resize listener. */\n\tdetach() {\n\t\twindow.removeEventListener('resize', this.handleResizeBound);\n\t}\n\n\t/** Compute the largest size that fits container while preserving aspect. */\n\tmeasure(): { width: number; height: number } {\n\t\tconst containerWidth = this.container.clientWidth || window.innerWidth;\n\t\tconst containerHeight = this.container.clientHeight || window.innerHeight;\n\n\t\tconst containerRatio = containerWidth / containerHeight;\n\t\tif (containerRatio > this.aspectRatio) {\n\t\t\t// container is wider than target; limit by height\n\t\t\tconst height = containerHeight;\n\t\t\tconst width = Math.round(height * this.aspectRatio);\n\t\t\treturn { width, height };\n\t\t} else {\n\t\t\t// container is taller/narrower; limit by width\n\t\t\tconst width = containerWidth;\n\t\t\tconst height = Math.round(width / this.aspectRatio);\n\t\t\treturn { width, height };\n\t\t}\n\t}\n\n\t/** Apply measured size to canvas and notify. */\n\tapply() {\n\t\tconst { width, height } = this.measure();\n\t\t// Apply CSS size; renderer will update internal size via onResize callback\n\t\tthis.canvas.style.width = `${width}px`;\n\t\tthis.canvas.style.height = `${height}px`;\n\t\tthis.onResize?.(width, height);\n\t}\n}","export type RetroResolution = { key: string; width: number; height: number; notes?: string };\n\nexport type RetroPreset = {\n\tdisplayAspect: number;\n\tresolutions: RetroResolution[];\n};\n\n/**\n * Retro and console display presets.\n * displayAspect represents the intended display aspect (letterboxing target),\n * not necessarily the raw pixel aspect of internal buffers.\n */\nconst RetroPresets: Record<string, RetroPreset> = {\n\tNES: {\n\t\tdisplayAspect: 4 / 3,\n\t\tresolutions: [\n\t\t\t{ key: '256x240', width: 256, height: 240, notes: 'Standard NTSC; effective 240p.' },\n\t\t],\n\t},\n\tSNES: {\n\t\tdisplayAspect: 4 / 3,\n\t\tresolutions: [\n\t\t\t{ key: '256x224', width: 256, height: 224, notes: 'Common 240p-equivalent mode.' },\n\t\t\t{ key: '512x448', width: 512, height: 448, notes: 'Hi-res interlaced (480i).' },\n\t\t],\n\t},\n\tN64: {\n\t\tdisplayAspect: 4 / 3,\n\t\tresolutions: [\n\t\t\t{ key: '320x240', width: 320, height: 240, notes: 'Common 240p mode.' },\n\t\t\t{ key: '640x480', width: 640, height: 480, notes: 'Higher resolution (480i).' },\n\t\t],\n\t},\n\tPS1: {\n\t\tdisplayAspect: 4 / 3,\n\t\tresolutions: [\n\t\t\t{ key: '320x240', width: 320, height: 240, notes: 'Progressive 240p common.' },\n\t\t\t{ key: '640x480', width: 640, height: 480, notes: 'Interlaced 480i for higher detail.' },\n\t\t],\n\t},\n\tPS2: {\n\t\tdisplayAspect: 4 / 3,\n\t\tresolutions: [\n\t\t\t{ key: '640x480', width: 640, height: 480, notes: '480i/480p baseline.' },\n\t\t\t{ key: '720x480', width: 720, height: 480, notes: '480p (widescreen capable in some titles).' },\n\t\t\t{ key: '1280x720', width: 1280, height: 720, notes: '720p (select titles).' },\n\t\t],\n\t},\n\tPS5: {\n\t\tdisplayAspect: 16 / 9,\n\t\tresolutions: [\n\t\t\t{ key: '720x480', width: 720, height: 480, notes: 'Legacy compatibility.' },\n\t\t\t{ key: '1280x720', width: 1280, height: 720, notes: '720p.' },\n\t\t\t{ key: '1920x1080', width: 1920, height: 1080, notes: '1080p.' },\n\t\t\t{ key: '2560x1440', width: 2560, height: 1440, notes: '1440p.' },\n\t\t\t{ key: '3840x2160', width: 3840, height: 2160, notes: '4K (up to 120Hz).' },\n\t\t\t{ key: '7680x4320', width: 7680, height: 4320, notes: '8K (limited).' },\n\t\t],\n\t},\n\tXboxOne: {\n\t\tdisplayAspect: 16 / 9,\n\t\tresolutions: [\n\t\t\t{ key: '1280x720', width: 1280, height: 720, notes: '720p (original).' },\n\t\t\t{ key: '1920x1080', width: 1920, height: 1080, notes: '1080p (original).' },\n\t\t\t{ key: '3840x2160', width: 3840, height: 2160, notes: '4K UHD (S/X models).' },\n\t\t],\n\t},\n};\n\nexport type RetroPresetKey = keyof typeof RetroPresets;\n\nexport function getDisplayAspect(preset: RetroPresetKey): number {\n\treturn RetroPresets[preset].displayAspect;\n}\n\nexport function getPresetResolution(preset: RetroPresetKey, key?: string): RetroResolution | undefined {\n\tconst list = RetroPresets[preset]?.resolutions || [];\n\tif (!key) return list[0];\n\tconst normalized = key.toLowerCase().replace(/\\s+/g, '').replace('×', 'x');\n\treturn list.find(r => r.key.toLowerCase() === normalized);\n}\n\nexport function parseResolution(text: string): { width: number; height: number } | null {\n\tif (!text) return null;\n\tconst normalized = String(text).toLowerCase().trim().replace(/\\s+/g, '').replace('×', 'x');\n\tconst match = normalized.match(/^(\\d+)x(\\d+)$/);\n\tif (!match) return null;\n\tconst width = parseInt(match[1], 10);\n\tconst height = parseInt(match[2], 10);\n\tif (!Number.isFinite(width) || !Number.isFinite(height)) return null;\n\treturn { width, height };\n}\n\n\n","import { StageInterface } from \"../types\";\nimport { GameInputConfig } from \"./game-interfaces\";\nimport { AspectRatio, AspectRatioValue } from \"../device/aspect-ratio\";\nimport { getDisplayAspect, getPresetResolution, parseResolution, RetroPresetKey } from \"./game-retro-resolutions\";\n\nexport type GameConfigLike = Partial<{\n\tid: string;\n\tglobals: Record<string, any>;\n\tstages: StageInterface[];\n\tdebug: boolean;\n\ttime: number;\n\tinput: GameInputConfig;\n\t/** numeric value or key in AspectRatio */\n\taspectRatio: AspectRatioValue | keyof typeof AspectRatio;\n\t/** console/display preset to derive aspect ratio */\n\tpreset: RetroPresetKey;\n\t/** lock internal render buffer to this resolution (e.g., '256x240' or { width, height }) */\n\tresolution: string | { width: number; height: number };\n\tfullscreen: boolean;\n\t/** CSS background value for document body */\n\tbodyBackground: string;\n\t/** existing container by reference */\n\tcontainer: HTMLElement;\n\t/** create/find container by id */\n\tcontainerId: string;\n\t/** optional canvas if caller wants to manage it */\n\tcanvas: HTMLCanvasElement;\n}>;\n\nexport class GameConfig {\n\tconstructor(\n\t\tpublic id: string,\n\t\tpublic globals: Record<string, any>,\n\t\tpublic stages: StageInterface[],\n\t\tpublic debug: boolean,\n\t\tpublic time: number,\n\t\tpublic input: GameInputConfig | undefined,\n\t\tpublic aspectRatio: number,\n\t\tpublic internalResolution: { width: number; height: number } | undefined,\n\t\tpublic fullscreen: boolean,\n\t\tpublic bodyBackground: string | undefined,\n\t\tpublic container: HTMLElement,\n\t\tpublic containerId?: string,\n\t\tpublic canvas?: HTMLCanvasElement,\n\t) { }\n}\n\nfunction ensureContainer(containerId?: string, existing?: HTMLElement | null): HTMLElement {\n\tif (existing) return existing;\n\tif (containerId) {\n\t\tconst found = document.getElementById(containerId);\n\t\tif (found) return found;\n\t}\n\tconst id = containerId || 'zylem-root';\n\tconst el = document.createElement('main');\n\tel.setAttribute('id', id);\n\tel.style.position = 'relative';\n\tel.style.width = '100%';\n\tel.style.height = '100%';\n\tdocument.body.appendChild(el);\n\treturn el;\n}\n\nfunction createDefaultGameConfig(base?: Partial<Pick<GameConfig, 'id' | 'debug' | 'time' | 'input'>> & { stages?: StageInterface[]; globals?: Record<string, any> }): GameConfig {\n\tconst id = base?.id ?? 'zylem';\n\tconst container = ensureContainer(id);\n\treturn new GameConfig(\n\t\tid,\n\t\t(base?.globals ?? {}) as Record<string, any>,\n\t\t(base?.stages ?? []) as StageInterface[],\n\t\tBoolean(base?.debug),\n\t\tbase?.time ?? 0,\n\t\tbase?.input,\n\t\tAspectRatio.SixteenByNine,\n\t\tundefined,\n\t\ttrue,\n\t\t'#000000',\n\t\tcontainer,\n\t\tid,\n\t\tundefined,\n\t);\n}\n\nexport function resolveGameConfig(user?: GameConfigLike): GameConfig {\n\tconst defaults = createDefaultGameConfig({\n\t\tid: user?.id ?? 'zylem',\n\t\tdebug: Boolean(user?.debug),\n\t\ttime: (user?.time as number) ?? 0,\n\t\tinput: user?.input,\n\t\tstages: (user?.stages as StageInterface[]) ?? [],\n\t\tglobals: (user?.globals as Record<string, any>) ?? {},\n\t});\n\n\t// Resolve container\n\tconst containerId = (user?.containerId as string) ?? defaults.containerId;\n\tconst container = ensureContainer(containerId, user?.container ?? null);\n\n\t// Derive aspect ratio: explicit numeric -> preset -> default\n\tconst explicitAspect = user?.aspectRatio as any;\n\tlet aspectRatio = defaults.aspectRatio;\n\tif (typeof explicitAspect === 'number' || (explicitAspect && typeof explicitAspect === 'string')) {\n\t\taspectRatio = typeof explicitAspect === 'number' ? explicitAspect : (AspectRatio as any)[explicitAspect] ?? defaults.aspectRatio;\n\t} else if (user?.preset) {\n\t\ttry {\n\t\t\taspectRatio = getDisplayAspect(user.preset as RetroPresetKey) || defaults.aspectRatio;\n\t\t} catch {\n\t\t\taspectRatio = defaults.aspectRatio;\n\t\t}\n\t}\n\n\tconst fullscreen = (user?.fullscreen as boolean) ?? defaults.fullscreen;\n\tconst bodyBackground = (user?.bodyBackground as string) ?? defaults.bodyBackground;\n\n\t// Normalize internal resolution lock\n\tlet internalResolution: { width: number; height: number } | undefined;\n\tif (user?.resolution) {\n\t\tif (typeof user.resolution === 'string') {\n\t\t\tconst parsed = parseResolution(user.resolution);\n\t\t\tif (parsed) internalResolution = parsed;\n\t\t\t// fallback: allow preset resolution keys like '256x240' under a preset\n\t\t\tif (!internalResolution && user.preset) {\n\t\t\t\tconst res = getPresetResolution(user.preset as RetroPresetKey, user.resolution);\n\t\t\t\tif (res) internalResolution = { width: res.width, height: res.height };\n\t\t\t}\n\t\t} else if (typeof user.resolution === 'object') {\n\t\t\tconst w = (user.resolution as any).width;\n\t\t\tconst h = (user.resolution as any).height;\n\t\t\tif (Number.isFinite(w) && Number.isFinite(h)) {\n\t\t\t\tinternalResolution = { width: w, height: h };\n\t\t\t}\n\t\t}\n\t}\n\n\t// Prefer provided canvas if any\n\tconst canvas = user?.canvas ?? undefined;\n\n\treturn new GameConfig(\n\t\t(user?.id as string) ?? defaults.id,\n\t\t(user?.globals as Record<string, any>) ?? defaults.globals,\n\t\t(user?.stages as StageInterface[]) ?? defaults.stages,\n\t\tBoolean(user?.debug ?? defaults.debug),\n\t\t(user?.time as number) ?? defaults.time,\n\t\tuser?.input ?? defaults.input,\n\t\taspectRatio,\n\t\tinternalResolution,\n\t\tfullscreen,\n\t\tbodyBackground,\n\t\tcontainer,\n\t\tcontainerId,\n\t\tcanvas,\n\t);\n}\n\n/**\n * Factory for authoring configuration objects in user code.\n * Returns a plain object that can be passed to `game(...)`.\n */\nexport function gameConfig(config: GameConfigLike): GameConfigLike {\n\treturn { ...config };\n}","import { AspectRatioDelegate, AspectRatioValue } from '../device/aspect-ratio';\n\nexport interface GameCanvasOptions {\n\tid: string;\n\tcontainer?: HTMLElement;\n\tcontainerId?: string;\n\tcanvas?: HTMLCanvasElement;\n\tbodyBackground?: string;\n\tfullscreen?: boolean;\n\taspectRatio: AspectRatioValue | number;\n}\n\n/**\n * GameCanvas is a DOM delegate that owns:\n * - container lookup/creation and styling (including fullscreen centering)\n * - body background application\n * - canvas mounting into container\n * - aspect ratio sizing via AspectRatioDelegate\n */\nexport class GameCanvas {\n\tid: string;\n\tcontainer!: HTMLElement;\n\tcanvas!: HTMLCanvasElement;\n\tbodyBackground?: string;\n\tfullscreen: boolean;\n\taspectRatio: number;\n\tprivate ratioDelegate: AspectRatioDelegate | null = null;\n\n\tconstructor(options: GameCanvasOptions) {\n\t\tthis.id = options.id;\n\t\tthis.container = this.ensureContainer(options.containerId ?? options.id, options.container);\n\t\tthis.canvas = options.canvas ?? document.createElement('canvas');\n\t\tthis.bodyBackground = options.bodyBackground;\n\t\tthis.fullscreen = Boolean(options.fullscreen);\n\t\tthis.aspectRatio = typeof options.aspectRatio === 'number' ? options.aspectRatio : options.aspectRatio;\n\t}\n\n\tapplyBodyBackground() {\n\t\tif (this.bodyBackground) {\n\t\t\tdocument.body.style.background = this.bodyBackground;\n\t\t}\n\t}\n\n\tmountCanvas() {\n\t\twhile (this.container.firstChild) {\n\t\t\tthis.container.removeChild(this.container.firstChild);\n\t\t}\n\t\tthis.container.appendChild(this.canvas);\n\t}\n\n\tmountRenderer(rendererDom: HTMLCanvasElement, onResize: (width: number, height: number) => void) {\n\t\twhile (this.container.firstChild) {\n\t\t\tthis.container.removeChild(this.container.firstChild);\n\t\t}\n\t\tthis.container.appendChild(rendererDom);\n\t\tthis.canvas = rendererDom;\n\t\tthis.attachAspectRatio(onResize);\n\t}\n\n\tcenterIfFullscreen() {\n\t\tif (!this.fullscreen) return;\n\t\tconst style = this.container.style;\n\t\tstyle.display = 'flex';\n\t\tstyle.alignItems = 'center';\n\t\tstyle.justifyContent = 'center';\n\t\tstyle.position = 'relative';\n\t\tstyle.inset = '0';\n\t}\n\n\tattachAspectRatio(onResize: (width: number, height: number) => void) {\n\t\tif (!this.ratioDelegate) {\n\t\t\tthis.ratioDelegate = new AspectRatioDelegate({\n\t\t\t\tcontainer: this.container,\n\t\t\t\tcanvas: this.canvas,\n\t\t\t\taspectRatio: this.aspectRatio,\n\t\t\t\tonResize\n\t\t\t});\n\t\t\tthis.ratioDelegate.attach();\n\t\t} else {\n\t\t\tthis.ratioDelegate.canvas = this.canvas;\n\t\t\tthis.ratioDelegate.onResize = onResize;\n\t\t\tthis.ratioDelegate.aspectRatio = this.aspectRatio;\n\t\t\tthis.ratioDelegate.apply();\n\t\t}\n\t}\n\n\tdestroy() {\n\t\tthis.ratioDelegate?.detach();\n\t\tthis.ratioDelegate = null;\n\t}\n\n\tprivate ensureContainer(containerId?: string, existing?: HTMLElement | null): HTMLElement {\n\t\tif (existing) return existing;\n\t\tif (containerId) {\n\t\t\tconst found = document.getElementById(containerId);\n\t\t\tif (found) return found;\n\t\t}\n\t\tconst id = containerId || this.id || 'zylem-root';\n\t\tconst el = document.createElement('main');\n\t\tel.setAttribute('id', id);\n\t\tel.style.position = 'relative';\n\t\tel.style.width = '100%';\n\t\tel.style.height = '100%';\n\t\tdocument.body.appendChild(el);\n\t\treturn el;\n\t}\n}\n","import Stats from 'stats.js';\nimport { subscribe } from 'valtio/vanilla';\nimport { debugState } from '../debug/debug-state';\n\n/**\n * GameDebugDelegate handles debug UI for the game (Stats panel).\n * Subscribes to debugState changes for runtime toggle.\n */\nexport class GameDebugDelegate {\n private statsRef: Stats | null = null;\n private unsubscribe: (() => void) | null = null;\n\n constructor() {\n this.updateDebugUI();\n this.unsubscribe = subscribe(debugState, () => {\n this.updateDebugUI();\n });\n }\n\n /**\n * Called every frame - wraps stats.begin()\n */\n begin(): void {\n this.statsRef?.begin();\n }\n\n /**\n * Called every frame - wraps stats.end()\n */\n end(): void {\n this.statsRef?.end();\n }\n\n private updateDebugUI(): void {\n if (debugState.enabled && !this.statsRef) {\n // Enable debug UI\n this.statsRef = new Stats();\n this.statsRef.showPanel(0);\n this.statsRef.dom.style.position = 'absolute';\n this.statsRef.dom.style.bottom = '0';\n this.statsRef.dom.style.right = '0';\n this.statsRef.dom.style.top = 'auto';\n this.statsRef.dom.style.left = 'auto';\n document.body.appendChild(this.statsRef.dom);\n } else if (!debugState.enabled && this.statsRef) {\n // Disable debug UI\n if (this.statsRef.dom.parentNode) {\n this.statsRef.dom.parentNode.removeChild(this.statsRef.dom);\n }\n this.statsRef = null;\n }\n }\n\n dispose(): void {\n if (this.unsubscribe) {\n this.unsubscribe();\n this.unsubscribe = null;\n }\n if (this.statsRef?.dom?.parentNode) {\n this.statsRef.dom.parentNode.removeChild(this.statsRef.dom);\n }\n this.statsRef = null;\n }\n}\n","export type EventType = string | symbol;\n\n// An event handler can take an optional event argument\n// and should not return a value\nexport type Handler<T = unknown> = (event: T) => void;\nexport type WildcardHandler<T = Record<string, unknown>> = (\n\ttype: keyof T,\n\tevent: T[keyof T]\n) => void;\n\n// An array of all currently registered event handlers for a type\nexport type EventHandlerList<T = unknown> = Array<Handler<T>>;\nexport type WildCardEventHandlerList<T = Record<string, unknown>> = Array<\n\tWildcardHandler<T>\n>;\n\n// A map of event types and their corresponding event handlers.\nexport type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<\n\tkeyof Events | '*',\n\tEventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>\n>;\n\nexport interface Emitter<Events extends Record<EventType, unknown>> {\n\tall: EventHandlerMap<Events>;\n\n\ton<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void;\n\ton(type: '*', handler: WildcardHandler<Events>): void;\n\n\toff<Key extends keyof Events>(\n\t\ttype: Key,\n\t\thandler?: Handler<Events[Key]>\n\t): void;\n\toff(type: '*', handler: WildcardHandler<Events>): void;\n\n\temit<Key extends keyof Events>(type: Key, event: Events[Key]): void;\n\temit<Key extends keyof Events>(\n\t\ttype: undefined extends Events[Key] ? Key : never\n\t): void;\n}\n\n/**\n * Mitt: Tiny (~200b) functional event emitter / pubsub.\n * @name mitt\n * @returns {Mitt}\n */\nexport default function mitt<Events extends Record<EventType, unknown>>(\n\tall?: EventHandlerMap<Events>\n): Emitter<Events> {\n\ttype GenericEventHandler =\n\t\t| Handler<Events[keyof Events]>\n\t\t| WildcardHandler<Events>;\n\tall = all || new Map();\n\n\treturn {\n\t\t/**\n\t\t * A Map of event names to registered handler functions.\n\t\t */\n\t\tall,\n\n\t\t/**\n\t\t * Register an event handler for the given type.\n\t\t * @param {string|symbol} type Type of event to listen for, or `'*'` for all events\n\t\t * @param {Function} handler Function to call in response to given event\n\t\t * @memberOf mitt\n\t\t */\n\t\ton<Key extends keyof Events>(type: Key, handler: GenericEventHandler) {\n\t\t\tconst handlers: Array<GenericEventHandler> | undefined = all!.get(type);\n\t\t\tif (handlers) {\n\t\t\t\thandlers.push(handler);\n\t\t\t} else {\n\t\t\t\tall!.set(type, [handler] as EventHandlerList<Events[keyof Events]>);\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Remove an event handler for the given type.\n\t\t * If `handler` is omitted, all handlers of the given type are removed.\n\t\t * @param {string|symbol} type Type of event to unregister `handler` from (`'*'` to remove a wildcard handler)\n\t\t * @param {Function} [handler] Handler function to remove\n\t\t * @memberOf mitt\n\t\t */\n\t\toff<Key extends keyof Events>(type: Key, handler?: GenericEventHandler) {\n\t\t\tconst handlers: Array<GenericEventHandler> | undefined = all!.get(type);\n\t\t\tif (handlers) {\n\t\t\t\tif (handler) {\n\t\t\t\t\thandlers.splice(handlers.indexOf(handler) >>> 0, 1);\n\t\t\t\t} else {\n\t\t\t\t\tall!.set(type, []);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Invoke all handlers for the given type.\n\t\t * If present, `'*'` handlers are invoked after type-matched handlers.\n\t\t *\n\t\t * Note: Manually firing '*' handlers is not supported.\n\t\t *\n\t\t * @param {string|symbol} type The event type to invoke\n\t\t * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler\n\t\t * @memberOf mitt\n\t\t */\n\t\temit<Key extends keyof Events>(type: Key, evt?: Events[Key]) {\n\t\t\tlet handlers = all!.get(type);\n\t\t\tif (handlers) {\n\t\t\t\t(handlers as EventHandlerList<Events[keyof Events]>)\n\t\t\t\t\t.slice()\n\t\t\t\t\t.map((handler) => {\n\t\t\t\t\t\thandler(evt!);\n\t\t\t\t\t});\n\t\t\t}\n\n\t\t\thandlers = all!.get('*');\n\t\t\tif (handlers) {\n\t\t\t\t(handlers as WildCardEventHandlerList<Events>)\n\t\t\t\t\t.slice()\n\t\t\t\t\t.map((handler) => {\n\t\t\t\t\t\thandler(type, evt!);\n\t\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n}\n","import mitt, { Emitter } from 'mitt';\n\n/**\n * Event scope identifier for routing events.\n */\nexport type EventScope = 'game' | 'stage' | 'entity';\n\n/**\n * Reusable delegate for event emission and subscription.\n * Use via composition in Game, Stage, and Entity classes.\n * \n * @example\n * class Game {\n * private eventDelegate = new EventEmitterDelegate<GameEvents>();\n * \n * dispatch<K extends keyof GameEvents>(event: K, payload: GameEvents[K]) {\n * this.eventDelegate.dispatch(event, payload);\n * }\n * }\n */\nexport class EventEmitterDelegate<TEvents extends Record<string, unknown>> {\n\tprivate emitter: Emitter<TEvents>;\n\tprivate unsubscribes: (() => void)[] = [];\n\n\tconstructor() {\n\t\tthis.emitter = mitt<TEvents>();\n\t}\n\n\t/**\n\t * Dispatch an event to all listeners.\n\t */\n\tdispatch<K extends keyof TEvents>(event: K, payload: TEvents[K]): void {\n\t\tthis.emitter.emit(event, payload);\n\t}\n\n\t/**\n\t * Subscribe to an event. Returns an unsubscribe function.\n\t */\n\tlisten<K extends keyof TEvents>(\n\t\tevent: K,\n\t\thandler: (payload: TEvents[K]) => void\n\t): () => void {\n\t\tthis.emitter.on(event, handler);\n\t\tconst unsub = () => this.emitter.off(event, handler);\n\t\tthis.unsubscribes.push(unsub);\n\t\treturn unsub;\n\t}\n\n\t/**\n\t * Subscribe to all events.\n\t */\n\tlistenAll(handler: (type: keyof TEvents, payload: TEvents[keyof TEvents]) => void): () => void {\n\t\tthis.emitter.on('*', handler as any);\n\t\tconst unsub = () => this.emitter.off('*', handler as any);\n\t\tthis.unsubscribes.push(unsub);\n\t\treturn unsub;\n\t}\n\n\t/**\n\t * Clean up all subscriptions.\n\t */\n\tdispose(): void {\n\t\tthis.unsubscribes.forEach(fn => fn());\n\t\tthis.unsubscribes = [];\n\t\tthis.emitter.all.clear();\n\t}\n}\n","import mitt from 'mitt';\nimport type { LoadingEvent } from '../core/interfaces';\n\n/**\n * Payload for game loading events with stage context.\n */\nexport interface GameLoadingPayload extends LoadingEvent {\n\tstageName?: string;\n\tstageIndex?: number;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Game Events\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** Payload for stage configuration sent to editor. */\nexport interface StageConfigPayload {\n\tid: string;\n\tbackgroundColor: string;\n\tbackgroundImage: string | null;\n\tgravity: { x: number; y: number; z: number };\n\tinputs: Record<string, string[]>;\n\tvariables: Record<string, unknown>;\n}\n\n/** Payload for entity configuration sent to editor. */\nexport interface EntityConfigPayload {\n\tuuid: string;\n\tname: string;\n\ttype: string;\n\tposition: { x: number; y: number; z: number };\n\trotation: { x: number; y: number; z: number };\n\tscale: { x: number; y: number; z: number };\n}\n\n/** Payload for state dispatch events from game to editor. */\nexport interface StateDispatchPayload {\n\tscope: 'game' | 'stage' | 'entity';\n\tpath: string;\n\tvalue: unknown;\n\tpreviousValue?: unknown;\n\tconfig?: {\n\t\tid: string;\n\t\taspectRatio: number;\n\t\tfullscreen: boolean;\n\t\tbodyBackground: string | undefined;\n\t\tinternalResolution: { width: number; height: number } | undefined;\n\t\tdebug: boolean;\n\t} | null;\n\tstageConfig?: StageConfigPayload | null;\n\tentities?: EntityConfigPayload[] | null;\n}\n\nexport type GameEvents = {\n\t'loading:start': GameLoadingPayload;\n\t'loading:progress': GameLoadingPayload;\n\t'loading:complete': GameLoadingPayload;\n\t'paused': { paused: boolean };\n\t'debug': { enabled: boolean };\n\t'state:dispatch': StateDispatchPayload;\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Stage Events\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport type StageEvents = {\n\t'stage:loaded': { stageId: string };\n\t'stage:unloaded': { stageId: string };\n\t'stage:variable:changed': { key: string; value: unknown };\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Entity Events\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport type EntityEvents = {\n\t'entity:spawned': { entityId: string; name: string };\n\t'entity:destroyed': { entityId: string };\n\t'entity:collision': { entityId: string; otherId: string };\n\t'entity:model:loading': { entityId: string; files: string[] };\n\t'entity:model:loaded': { entityId: string; success: boolean; meshCount?: number };\n\t'entity:animation:loaded': { entityId: string; animationCount: number };\n};\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Combined Event Map\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport type ZylemEvents = GameEvents & StageEvents & EntityEvents;\n\n/**\n * Global event bus for cross-package communication.\n * \n * Usage:\n * ```ts\n * import { zylemEventBus } from '@zylem/game-lib';\n * \n * // Subscribe\n * const unsub = zylemEventBus.on('loading:progress', (e) => console.log(e));\n * \n * // Emit\n * zylemEventBus.emit('loading:progress', { type: 'progress', progress: 0.5 });\n * \n * // Cleanup\n * unsub();\n * ```\n */\nexport const zylemEventBus = mitt<ZylemEvents>();\n","export { EventEmitterDelegate, type EventScope } from './event-emitter-delegate';\nexport {\n\tzylemEventBus,\n\ttype ZylemEvents,\n\ttype GameEvents,\n\ttype StageEvents,\n\ttype EntityEvents,\n\ttype GameLoadingPayload,\n\ttype StateDispatchPayload,\n\ttype StageConfigPayload,\n\ttype EntityConfigPayload,\n} from './zylem-events';\n","import { LoadingEvent } from '../core/interfaces';\nimport { zylemEventBus, type GameLoadingPayload } from '../events';\n\n/**\n * Game-level loading event that includes stage context.\n */\nexport interface GameLoadingEvent {\n\ttype: 'start' | 'progress' | 'complete';\n\tstageName?: string;\n\tstageIndex?: number;\n\tmessage: string;\n\tprogress: number;\n\tcurrent?: number;\n\ttotal?: number;\n}\n\n/**\n * Delegate for managing game-level loading events.\n * Aggregates loading events from stages and includes stage context.\n * Emits to zylemEventBus for cross-application communication.\n */\nexport class GameLoadingDelegate {\n\tprivate loadingHandlers: Array<(event: GameLoadingEvent) => void> = [];\n\tprivate stageLoadingUnsubscribes: (() => void)[] = [];\n\n\t/**\n\t * Subscribe to loading events from the game.\n\t * Events include stage context (stageName, stageIndex).\n\t * \n\t * @param callback Invoked for each loading event\n\t * @returns Unsubscribe function\n\t */\n\tonLoading(callback: (event: GameLoadingEvent) => void): () => void {\n\t\tthis.loadingHandlers.push(callback);\n\t\treturn () => {\n\t\t\tthis.loadingHandlers = this.loadingHandlers.filter((h) => h !== callback);\n\t\t};\n\t}\n\n\t/**\n\t * Emit a loading event to all subscribers and to zylemEventBus.\n\t */\n\temit(event: GameLoadingEvent): void {\n\t\t// Dispatch to direct subscribers\n\t\tfor (const handler of this.loadingHandlers) {\n\t\t\ttry {\n\t\t\t\thandler(event);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('Game loading handler failed', e);\n\t\t\t}\n\t\t}\n\t\t\n\t\t// Emit to zylemEventBus for cross-package communication\n\t\tconst eventName = `loading:${event.type}` as 'loading:start' | 'loading:progress' | 'loading:complete';\n\t\t(zylemEventBus as any).emit(eventName, event as GameLoadingPayload);\n\t}\n\n\t/**\n\t * Wire up a stage's loading events to this delegate.\n\t * \n\t * @param stage The stage to wire up\n\t * @param stageIndex The index of the stage\n\t */\n\twireStageLoading(stage: { uuid?: string; onLoading: (cb: (event: LoadingEvent) => void) => () => void | void }, stageIndex: number): void {\n const unsub = stage.onLoading((event: LoadingEvent) => {\n\t\t\tthis.emit({\n\t\t\t\ttype: event.type,\n\t\t\t\tmessage: event.message ?? '',\n\t\t\t\tprogress: event.progress ?? 0,\n\t\t\t\tcurrent: event.current,\n\t\t\t\ttotal: event.total,\n\t\t\t\tstageName: stage.uuid ?? `Stage ${stageIndex}`,\n\t\t\t\tstageIndex,\n\t\t\t});\n\t\t});\n\t\tif (typeof unsub === 'function') {\n\t\t\tthis.stageLoadingUnsubscribes.push(unsub);\n\t\t}\n\t}\n\n\t/**\n\t * Unsubscribe from all stage loading events.\n\t */\n\tunwireAllStages(): void {\n\t\tfor (const unsub of this.stageLoadingUnsubscribes) {\n\t\t\ttry {\n\t\t\t\tunsub();\n\t\t\t} catch { /* noop */ }\n\t\t}\n\t\tthis.stageLoadingUnsubscribes = [];\n\t}\n\n\t/**\n\t * Clean up all handlers.\n\t */\n\tdispose(): void {\n\t\tthis.unwireAllStages();\n\t\tthis.loadingHandlers = [];\n\t}\n}\n","import { ZylemCamera } from '../camera/zylem-camera';\nimport { GameCanvas } from './game-canvas';\nimport { GameConfig } from './game-config';\n\n/**\n * Observer that triggers renderer mounting when container and camera are both available.\n * Decouples renderer mounting from stage loading.\n */\nexport class GameRendererObserver {\n\tprivate container: HTMLElement | null = null;\n\tprivate camera: ZylemCamera | null = null;\n\tprivate gameCanvas: GameCanvas | null = null;\n\tprivate config: GameConfig | null = null;\n\tprivate mounted = false;\n\n\tsetGameCanvas(canvas: GameCanvas): void {\n\t\tthis.gameCanvas = canvas;\n\t\tthis.tryMount();\n\t}\n\n\tsetConfig(config: GameConfig): void {\n\t\tthis.config = config;\n\t\tthis.tryMount();\n\t}\n\n\tsetContainer(container: HTMLElement): void {\n\t\tthis.container = container;\n\t\tthis.tryMount();\n\t}\n\n\tsetCamera(camera: ZylemCamera): void {\n\t\tthis.camera = camera;\n\t\tthis.tryMount();\n\t}\n\n\t/**\n\t * Attempt to mount renderer if all dependencies are available.\n\t */\n\tprivate tryMount(): void {\n\t\tif (this.mounted) return;\n\t\tif (!this.container || !this.camera || !this.gameCanvas) return;\n\n\t\tconst dom = this.camera.getDomElement();\n\t\tconst internal = this.config?.internalResolution;\n\t\t\n\t\tthis.gameCanvas.mountRenderer(dom, (cssW, cssH) => {\n\t\t\tif (!this.camera) return;\n\t\t\tif (internal) {\n\t\t\t\tthis.camera.setPixelRatio(1);\n\t\t\t\tthis.camera.resize(internal.width, internal.height);\n\t\t\t} else {\n\t\t\t\tconst dpr = window.devicePixelRatio || 1;\n\t\t\t\tthis.camera.setPixelRatio(dpr);\n\t\t\t\tthis.camera.resize(cssW, cssH);\n\t\t\t}\n\t\t});\n\t\t\n\t\tthis.mounted = true;\n\t}\n\n\t/**\n\t * Reset state for stage transitions.\n\t */\n\treset(): void {\n\t\tthis.camera = null;\n\t\tthis.mounted = false;\n\t}\n\n\tdispose(): void {\n\t\tthis.container = null;\n\t\tthis.camera = null;\n\t\tthis.gameCanvas = null;\n\t\tthis.config = null;\n\t\tthis.mounted = false;\n\t}\n}\n","import { state, setGlobal, getGlobals, initGlobals, resetGlobals } from './game-state';\n\nimport { debugState, isPaused, setDebugFlag } from '../debug/debug-state';\n\nimport { Game } from './game';\nimport { UpdateContext, SetupContext, DestroyContext } from '../core/base-node-life-cycle';\nimport { InputManager } from '../input/input-manager';\nimport { Timer } from '../core/three-addons/Timer';\nimport { ZylemCamera } from '~/lib/camera/zylem-camera';\nimport { Stage } from '../stage/stage';\nimport { BaseGlobals, ZylemGameConfig } from './game-interfaces';\nimport { GameConfig, resolveGameConfig } from './game-config';\nimport { AspectRatioDelegate } from '../device/aspect-ratio';\nimport { GameCanvas } from './game-canvas';\nimport { GameDebugDelegate } from './game-debug-delegate';\nimport { GameLoadingDelegate, GameLoadingEvent } from './game-loading-delegate';\nimport { gameEventBus, GameStateUpdatedPayload } from './game-event-bus';\nimport { zylemEventBus, type StateDispatchPayload, type StageConfigPayload, type EntityConfigPayload } from '../events';\nimport { GameRendererObserver } from './game-renderer-observer';\nimport { ZylemStage } from '../core';\n\nexport type { GameLoadingEvent };\n\ntype ZylemGameOptions<TGlobals extends BaseGlobals> = ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals> & Partial<GameConfig>\n\nexport class ZylemGame<TGlobals extends BaseGlobals> {\n\tid: string;\n\tinitialGlobals = {} as TGlobals;\n\n\tcustomSetup: ((params: SetupContext<ZylemGame<TGlobals>, TGlobals>) => void) | null = null;\n\tcustomUpdate: ((params: UpdateContext<ZylemGame<TGlobals>, TGlobals>) => void) | null = null;\n\tcustomDestroy: ((params: DestroyContext<ZylemGame<TGlobals>, TGlobals>) => void) | null = null;\n\n\tstages: Stage[] = [];\n\tstageMap: Map<string, Stage> = new Map();\n\tcurrentStageId = '';\n\n\tpreviousTimeStamp: number = 0;\n\ttotalTime = 0;\n\n\ttimer: Timer;\n\tinputManager: InputManager;\n\n\twrapperRef: Game<TGlobals>;\n\tdefaultCamera: ZylemCamera | null = null;\n\tcontainer: HTMLElement | null = null;\n\tcanvas: HTMLCanvasElement | null = null;\n\taspectRatioDelegate: AspectRatioDelegate | null = null;\n\tresolvedConfig: GameConfig | null = null;\n\tgameCanvas: GameCanvas | null = null;\n\tprivate animationFrameId: number | null = null;\n\tprivate isDisposed = false;\n\tprivate debugDelegate: GameDebugDelegate | null = null;\n\tprivate loadingDelegate: GameLoadingDelegate = new GameLoadingDelegate();\n\tprivate rendererObserver: GameRendererObserver = new GameRendererObserver();\n\tprivate eventBusUnsubscribes: (() => void)[] = [];\n\n\tstatic FRAME_LIMIT = 120;\n\tstatic FRAME_DURATION = 1000 / ZylemGame.FRAME_LIMIT;\n\tstatic MAX_DELTA_SECONDS = 1 / 30;\n\n\tconstructor(options: ZylemGameOptions<TGlobals>, wrapperRef: Game<TGlobals>) {\n\t\tthis.wrapperRef = wrapperRef;\n\t\tthis.timer = new Timer();\n\t\tthis.timer.connect(document);\n\t\t\n\t\tconsole.log('[ZylemGame] options:', options);\n\t\tconsole.log('[ZylemGame] options.input:', options.input);\n\t\t\n\t\t// Resolve config first to get the proper input configuration\n\t\tconst config = resolveGameConfig(options as any);\n\t\tconsole.log(config);\n\t\tconsole.log('[ZylemGame] config.input:', config.input);\n\t\t\n\t\t// Now create InputManager with the resolved config's input settings\n\t\tthis.inputManager = new InputManager(config.input);\n\t\t\n\t\tthis.id = config.id;\n\t\tthis.stages = (config.stages as any) || [];\n\t\tthis.container = config.container;\n\t\tthis.canvas = config.canvas ?? null;\n\t\tthis.resolvedConfig = config;\n\t\tthis.loadGameCanvas(config);\n\t\tthis.loadDebugOptions(options);\n\t\tthis.setGlobals(options);\n\t}\n\n\tloadGameCanvas(config: GameConfig) {\n\t\tthis.gameCanvas = new GameCanvas({\n\t\t\tid: config.id,\n\t\t\tcontainer: config.container,\n\t\t\tcontainerId: config.containerId,\n\t\t\tcanvas: this.canvas ?? undefined,\n\t\t\tbodyBackground: config.bodyBackground,\n\t\t\tfullscreen: config.fullscreen,\n\t\t\taspectRatio: config.aspectRatio,\n\t\t});\n\t\tthis.gameCanvas.applyBodyBackground();\n\t\tthis.gameCanvas.mountCanvas();\n\t\tthis.gameCanvas.centerIfFullscreen();\n\t\t\n\t\t// Setup renderer observer\n\t\tthis.rendererObserver.setGameCanvas(this.gameCanvas);\n\t\tif (this.resolvedConfig) {\n\t\t\tthis.rendererObserver.setConfig(this.resolvedConfig);\n\t\t}\n\t\tif (this.container) {\n\t\t\tthis.rendererObserver.setContainer(this.container);\n\t\t}\n\t\t\n\t\t// Subscribe to event bus for stage loading events\n\t\tthis.subscribeToEventBus();\n\t}\n\n\tloadDebugOptions(options: ZylemGameOptions<TGlobals>) {\n\t\tif (options.debug !== undefined) {\n\t\t\tdebugState.enabled = Boolean(options.debug);\n\t\t}\n\t\tthis.debugDelegate = new GameDebugDelegate();\n\t}\n\n\tloadStage(stage: Stage, stageIndex: number = 0): Promise<void> {\n\t\tthis.unloadCurrentStage();\n\t\tconst config = stage.options[0] as any;\n\t\t\n\t\t// Subscribe to stage loading events via delegate\n\t\tthis.loadingDelegate.wireStageLoading(stage, stageIndex);\n\n\t\t// Start stage loading and return promise for backward compatibility\n\t\treturn stage.load(this.id, config?.camera as ZylemCamera | null).then(() => {\n\t\t\tthis.stageMap.set(stage.wrappedStage!.uuid, stage);\n\t\t\tthis.currentStageId = stage.wrappedStage!.uuid;\n\t\t\tthis.defaultCamera = stage.wrappedStage!.cameraRef!;\n\t\t\t\n\t\t\t// Trigger renderer observer with new camera\n\t\t\tif (this.defaultCamera) {\n\t\t\t\tthis.rendererObserver.setCamera(this.defaultCamera);\n\t\t\t}\n\n\t\t\t// Emit state dispatch after stage is loaded so editor receives initial config\n\t\t\tthis.emitStateDispatch('@stage:loaded');\n\t\t});\n\t}\n\n\tunloadCurrentStage() {\n\t\tif (!this.currentStageId) return;\n\t\tconst current = this.getStage(this.currentStageId);\n\t\tif (!current) return;\n\t\t\n\t\tif (current?.wrappedStage) {\n\t\t\ttry {\n\t\t\t\tcurrent.wrappedStage.nodeDestroy({\n\t\t\t\t\tme: current.wrappedStage,\n\t\t\t\t\tglobals: state.globals as unknown as TGlobals,\n\t\t\t\t});\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('Failed to destroy previous stage', e);\n\t\t\t}\n\t\t\t// Clear the Stage wrapper's reference to the destroyed stage\n\t\t\tcurrent.wrappedStage = null;\n\t\t}\n\t\t\n\t\t// Remove from stage map\n\t\tthis.stageMap.delete(this.currentStageId);\n\t\t\n\t\t// Reset game state\n\t\tthis.currentStageId = '';\n\t\tthis.defaultCamera = null;\n\t\t\n\t\t// Reset renderer observer for stage transitions\n\t\tthis.rendererObserver.reset();\n\t}\n\n\tsetGlobals(options: ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals>) {\n\t\tthis.initialGlobals = { ...(options.globals as TGlobals) };\n\t\tfor (const variable in this.initialGlobals) {\n\t\t\tconst value = this.initialGlobals[variable];\n\t\t\tif (value === undefined) {\n\t\t\t\tconsole.error(`global ${variable} is undefined`);\n\t\t\t}\n\t\t\tsetGlobal(variable, value);\n\t\t}\n\t}\n\n\tparams(): UpdateContext<ZylemGame<TGlobals>, TGlobals> {\n\t\tconst stage = this.currentStage();\n\t\tconst delta = this.timer.getDelta();\n\t\tconst inputs = this.inputManager.getInputs(delta);\n\t\tconst camera = stage?.wrappedStage?.cameraRef || this.defaultCamera;\n\t\treturn {\n\t\t\tdelta,\n\t\t\tinputs,\n\t\t\tglobals: getGlobals<TGlobals>(),\n\t\t\tme: this,\n\t\t\tcamera: camera!,\n\t\t};\n\t}\n\n\tstart() {\n\t\tconst stage = this.currentStage();\n\t\tconst params = this.params();\n\t\tstage!.start({ ...params, me: stage!.wrappedStage as ZylemStage });\n\t\tif (this.customSetup) {\n\t\t\tthis.customSetup(params);\n\t\t}\n\t\tthis.loop(0);\n\t}\n\n\t/**\n\t * Execute a single frame update.\n\t * This method can be called directly for testing or from the game loop.\n\t * @param deltaTime Optional delta time in seconds. If not provided, uses timer delta.\n\t */\n\tstep(deltaTime?: number): void {\n\t\tconst stage = this.currentStage();\n\t\tif (!stage || !stage.wrappedStage) return;\n\n\t\tconst params = this.params();\n\t\tconst delta = deltaTime !== undefined ? deltaTime : params.delta;\n\t\tconst clampedDelta = Math.min(Math.max(delta, 0), ZylemGame.MAX_DELTA_SECONDS);\n\t\tconst clampedParams = { ...params, delta: clampedDelta };\n\n\t\tif (this.customUpdate) {\n\t\t\tthis.customUpdate(clampedParams);\n\t\t}\n\n\t\tstage.wrappedStage?.nodeUpdate({ ...clampedParams, me: stage.wrappedStage as ZylemStage });\n\n\t\tthis.totalTime += clampedDelta;\n\t\tstate.time = this.totalTime;\n\t}\n\n\tloop(timestamp: number) {\n\t\tthis.debugDelegate?.begin();\n\t\tif (!isPaused()) {\n\t\t\tthis.timer.update(timestamp);\n\t\t\tthis.step();\n\t\t\tthis.previousTimeStamp = timestamp;\n\t\t}\n\t\tthis.debugDelegate?.end();\n\t\tthis.outOfLoop();\n\t\tif (!this.isDisposed) {\n\t\t\tthis.animationFrameId = requestAnimationFrame(this.loop.bind(this));\n\t\t}\n\t}\n\n\tdispose() {\n\t\tthis.isDisposed = true;\n\t\tif (this.animationFrameId !== null) {\n\t\t\tcancelAnimationFrame(this.animationFrameId);\n\t\t\tthis.animationFrameId = null;\n\t\t}\n\n\t\tthis.unloadCurrentStage();\n\n\t\tif (this.debugDelegate) {\n\t\t\tthis.debugDelegate.dispose();\n\t\t\tthis.debugDelegate = null;\n\t\t}\n\n\t\tthis.eventBusUnsubscribes.forEach(unsub => unsub());\n\t\tthis.eventBusUnsubscribes = [];\n\n\t\tthis.rendererObserver.dispose();\n\n\t\tthis.timer.dispose();\n\n\t\tif (this.customDestroy) {\n\t\t\tthis.customDestroy({\n\t\t\t\tme: this,\n\t\t\t\tglobals: state.globals as unknown as TGlobals\n\t\t\t});\n\t\t}\n\n\t\tresetGlobals();\n\t}\n\n\toutOfLoop() {\n\t\tconst currentStage = this.currentStage();\n\t\tif (!currentStage) return;\n\t\tcurrentStage.wrappedStage!.outOfLoop();\n\t}\n\n\tgetStage(id: string) {\n\t\treturn this.stageMap.get(id);\n\t}\n\n\tcurrentStage() {\n\t\treturn this.getStage(this.currentStageId);\n\t}\n\n\t/**\n\t * Subscribe to loading events from the game.\n\t * Events include stage context (stageName, stageIndex).\n\t * @param callback Invoked for each loading event\n\t * @returns Unsubscribe function\n\t */\n\tonLoading(callback: (event: GameLoadingEvent) => void): () => void {\n\t\treturn this.loadingDelegate.onLoading(callback);\n\t}\n\n\t/**\n\t * Build the stage config payload for the current stage.\n\t */\n\tprivate buildStageConfigPayload(): StageConfigPayload | null {\n\t\tconst stage = this.currentStage();\n\t\tif (!stage?.wrappedStage) return null;\n\n\t\tconst state = stage.wrappedStage.state;\n\t\tconst bgColor = state.backgroundColor;\n\t\tconst colorStr = typeof bgColor === 'string' ? bgColor : `#${bgColor.getHexString()}`;\n\n\t\treturn {\n\t\t\tid: stage.wrappedStage.uuid,\n\t\t\tbackgroundColor: colorStr,\n\t\t\tbackgroundImage: state.backgroundImage,\n\t\t\tgravity: {\n\t\t\t\tx: state.gravity.x,\n\t\t\t\ty: state.gravity.y,\n\t\t\t\tz: state.gravity.z,\n\t\t\t},\n\t\t\tinputs: state.inputs,\n\t\t\tvariables: state.variables,\n\t\t};\n\t}\n\n\t/**\n\t * Build the entities payload for the current stage.\n\t */\n\tprivate buildEntitiesPayload(): EntityConfigPayload[] | null {\n\t\tconst stage = this.currentStage();\n\t\tif (!stage?.wrappedStage) return null;\n\n\t\tconst entities: EntityConfigPayload[] = [];\n\t\tstage.wrappedStage._childrenMap.forEach((child) => {\n\t\t\t// Get type string from the entity's constructor\n\t\t\tconst entityType = (child.constructor as any).type;\n\t\t\tconst typeStr = entityType ? String(entityType).replace('Symbol(', '').replace(')', '') : 'Unknown';\n\n\t\t\t// Get transform data\n\t\t\tconst position = (child as any).position ?? { x: 0, y: 0, z: 0 };\n\t\t\tconst rotation = (child as any).rotation ?? { x: 0, y: 0, z: 0 };\n\t\t\tconst scale = (child as any).scale ?? { x: 1, y: 1, z: 1 };\n\n\t\t\tentities.push({\n\t\t\t\tuuid: child.uuid,\n\t\t\t\tname: child.name || 'Unnamed',\n\t\t\t\ttype: typeStr,\n\t\t\t\tposition: { x: position.x ?? 0, y: position.y ?? 0, z: position.z ?? 0 },\n\t\t\t\trotation: { x: rotation.x ?? 0, y: rotation.y ?? 0, z: rotation.z ?? 0 },\n\t\t\t\tscale: { x: scale.x ?? 1, y: scale.y ?? 1, z: scale.z ?? 1 },\n\t\t\t});\n\t\t});\n\n\t\treturn entities;\n\t}\n\n\t/**\n\t * Emit a state:dispatch event to the zylemEventBus.\n\t * Called after stage load and on global state changes.\n\t */\n\tprivate emitStateDispatch(path: string, value?: unknown, previousValue?: unknown): void {\n\t\tconst statePayload: StateDispatchPayload = {\n\t\t\tscope: 'game',\n\t\t\tpath,\n\t\t\tvalue,\n\t\t\tpreviousValue,\n\t\t\tconfig: this.resolvedConfig ? {\n\t\t\t\tid: this.resolvedConfig.id,\n\t\t\t\taspectRatio: this.resolvedConfig.aspectRatio,\n\t\t\t\tfullscreen: this.resolvedConfig.fullscreen,\n\t\t\t\tbodyBackground: this.resolvedConfig.bodyBackground,\n\t\t\t\tinternalResolution: this.resolvedConfig.internalResolution,\n\t\t\t\tdebug: this.resolvedConfig.debug,\n\t\t\t} : null,\n\t\t\tstageConfig: this.buildStageConfigPayload(),\n\t\t\tentities: this.buildEntitiesPayload(),\n\t\t};\n\t\tzylemEventBus.emit('state:dispatch', statePayload);\n\t}\n\n\t/**\n\t * Subscribe to the game event bus for stage loading and state events.\n\t * Emits events to zylemEventBus for cross-package communication.\n\t */\n\tprivate subscribeToEventBus(): void {\n\t\tthis.eventBusUnsubscribes.push(\n\t\t\tgameEventBus.on('game:state:updated', (payload: GameStateUpdatedPayload) => {\n\t\t\t\tthis.emitStateDispatch(payload.path, payload.value, payload.previousValue);\n\t\t\t}),\n\t\t);\n\t}\n}\n\n","/** Vite build flags */\nexport const DEBUG_FLAG = import.meta.env.VITE_DEBUG_FLAG === 'true';","import {\n\tCleanupContext,\n\tCleanupFunction,\n\tDestroyContext,\n\tDestroyFunction,\n\tLoadedContext,\n\tLoadedFunction,\n\tSetupContext,\n\tSetupFunction,\n\tUpdateContext,\n\tUpdateFunction,\n} from \"./base-node-life-cycle\";\nimport { DEBUG_FLAG } from \"./flags\";\nimport { nanoid } from \"nanoid\";\nimport { NodeInterface } from \"./node-interface\";\n\nexport type BaseNodeOptions<T = any> = BaseNode | Partial<T>;\n\n/**\n * Lifecycle callback arrays - each lifecycle event can have multiple callbacks\n * that execute in order.\n */\nexport interface LifecycleCallbacks<T> {\n\tsetup: Array<SetupFunction<T>>;\n\tloaded: Array<LoadedFunction<T>>;\n\tupdate: Array<UpdateFunction<T>>;\n\tdestroy: Array<DestroyFunction<T>>;\n\tcleanup: Array<CleanupFunction<T>>;\n}\n\nexport abstract class BaseNode<Options = any, T = any> implements NodeInterface {\n\tprotected parent: NodeInterface | null = null;\n\tprotected children: NodeInterface[] = [];\n\tpublic options: Options;\n\tpublic eid: number = 0;\n\tpublic uuid: string = '';\n\tpublic name: string = '';\n\tpublic markedForRemoval: boolean = false;\n\n\t/**\n\t * Lifecycle callback arrays - use onSetup(), onUpdate(), etc. to add callbacks\n\t */\n\tprotected lifecycleCallbacks: LifecycleCallbacks<this> = {\n\t\tsetup: [],\n\t\tloaded: [],\n\t\tupdate: [],\n\t\tdestroy: [],\n\t\tcleanup: [],\n\t};\n\n\tconstructor(args: BaseNodeOptions[] = []) {\n\t\tconst options = args\n\t\t\t.filter(arg => !(arg instanceof BaseNode))\n\t\t\t.reduce((acc, opt) => ({ ...acc, ...opt }), {});\n\t\tthis.options = options as Options;\n\t\tthis.uuid = nanoid();\n\t}\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Fluent API for adding lifecycle callbacks\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\t/**\n\t * Add setup callbacks to be executed in order during nodeSetup\n\t */\n\tpublic onSetup(...callbacks: Array<SetupFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.setup.push(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Add loaded callbacks to be executed in order during nodeLoaded\n\t */\n\tpublic onLoaded(...callbacks: Array<LoadedFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.loaded.push(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Add update callbacks to be executed in order during nodeUpdate\n\t */\n\tpublic onUpdate(...callbacks: Array<UpdateFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.update.push(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Add destroy callbacks to be executed in order during nodeDestroy\n\t */\n\tpublic onDestroy(...callbacks: Array<DestroyFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.destroy.push(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Add cleanup callbacks to be executed in order during nodeCleanup\n\t */\n\tpublic onCleanup(...callbacks: Array<CleanupFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.cleanup.push(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Prepend setup callbacks (run before existing ones)\n\t */\n\tpublic prependSetup(...callbacks: Array<SetupFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.setup.unshift(...callbacks);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Prepend update callbacks (run before existing ones)\n\t */\n\tpublic prependUpdate(...callbacks: Array<UpdateFunction<this>>): this {\n\t\tthis.lifecycleCallbacks.update.unshift(...callbacks);\n\t\treturn this;\n\t}\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Tree structure\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\tpublic setParent(parent: NodeInterface | null): void {\n\t\tthis.parent = parent;\n\t}\n\n\tpublic getParent(): NodeInterface | null {\n\t\treturn this.parent;\n\t}\n\n\tpublic add(baseNode: NodeInterface): void {\n\t\tthis.children.push(baseNode);\n\t\tbaseNode.setParent(this);\n\t}\n\n\tpublic remove(baseNode: NodeInterface): void {\n\t\tconst index = this.children.indexOf(baseNode);\n\t\tif (index !== -1) {\n\t\t\tthis.children.splice(index, 1);\n\t\t\tbaseNode.setParent(null);\n\t\t}\n\t}\n\n\tpublic getChildren(): NodeInterface[] {\n\t\treturn this.children;\n\t}\n\n\tpublic isComposite(): boolean {\n\t\treturn this.children.length > 0;\n\t}\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Abstract methods for subclass implementation\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\tpublic abstract create(): T;\n\n\tprotected abstract _setup(params: SetupContext<this>): void;\n\n\tprotected abstract _loaded(params: LoadedContext<this>): Promise<void>;\n\n\tprotected abstract _update(params: UpdateContext<this>): void;\n\n\tprotected abstract _destroy(params: DestroyContext<this>): void;\n\n\tprotected abstract _cleanup(params: CleanupContext<this>): Promise<void>;\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Node lifecycle execution - runs internal + callback arrays\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\tpublic nodeSetup(params: SetupContext<this>) {\n\t\tif (DEBUG_FLAG) { /** */ }\n\t\tthis.markedForRemoval = false;\n\n\t\t// 1. Internal setup\n\t\tif (typeof this._setup === 'function') {\n\t\t\tthis._setup(params);\n\t\t}\n\n\t\t// 2. Run all setup callbacks in order\n\t\tfor (const callback of this.lifecycleCallbacks.setup) {\n\t\t\tcallback(params);\n\t\t}\n\n\t\t// 3. Setup children\n\t\tthis.children.forEach(child => child.nodeSetup(params));\n\t}\n\n\tpublic nodeUpdate(params: UpdateContext<this>): void {\n\t\tif (this.markedForRemoval) {\n\t\t\treturn;\n\t\t}\n\n\t\t// 1. Internal update\n\t\tif (typeof this._update === 'function') {\n\t\t\tthis._update(params);\n\t\t}\n\n\t\t// 2. Run all update callbacks in order\n\t\tfor (const callback of this.lifecycleCallbacks.update) {\n\t\t\tcallback(params);\n\t\t}\n\n\t\t// 3. Update children\n\t\tthis.children.forEach(child => child.nodeUpdate(params));\n\t}\n\n\tpublic nodeDestroy(params: DestroyContext<this>): void {\n\t\t// 1. Destroy children first\n\t\tthis.children.forEach(child => child.nodeDestroy(params));\n\n\t\t// 2. Run all destroy callbacks in order\n\t\tfor (const callback of this.lifecycleCallbacks.destroy) {\n\t\t\tcallback(params);\n\t\t}\n\n\t\t// 3. Internal destroy\n\t\tif (typeof this._destroy === 'function') {\n\t\t\tthis._destroy(params);\n\t\t}\n\n\t\tthis.markedForRemoval = true;\n\t}\n\n\tpublic async nodeLoaded(params: LoadedContext<this>): Promise<void> {\n\t\t// 1. Internal loaded\n\t\tif (typeof this._loaded === 'function') {\n\t\t\tawait this._loaded(params);\n\t\t}\n\n\t\t// 2. Run all loaded callbacks in order\n\t\tfor (const callback of this.lifecycleCallbacks.loaded) {\n\t\t\tcallback(params);\n\t\t}\n\t}\n\n\tpublic async nodeCleanup(params: CleanupContext<this>): Promise<void> {\n\t\t// 1. Run all cleanup callbacks in order\n\t\tfor (const callback of this.lifecycleCallbacks.cleanup) {\n\t\t\tcallback(params);\n\t\t}\n\n\t\t// 2. Internal cleanup\n\t\tif (typeof this._cleanup === 'function') {\n\t\t\tawait this._cleanup(params);\n\t\t}\n\t}\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Options\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\tpublic getOptions(): Options {\n\t\treturn this.options;\n\t}\n\n\tpublic setOptions(options: Partial<Options>): void {\n\t\tthis.options = { ...this.options, ...options };\n\t}\n}","import {\n\tdefineSystem,\n\tdefineQuery,\n\tdefineComponent,\n\tTypes,\n\tremoveQuery,\n\ttype IWorld,\n} from 'bitecs';\nimport { Quaternion } from 'three';\nimport { StageEntity } from '../interfaces/entity';\nimport RAPIER from '@dimforge/rapier3d-compat';\n\nexport type StageSystem = {\n\t_childrenMap: Map<number, StageEntity & { body: RAPIER.RigidBody }>;\n}\n\nexport const position = defineComponent({\n\tx: Types.f32,\n\ty: Types.f32,\n\tz: Types.f32\n});\n\nexport const rotation = defineComponent({\n\tx: Types.f32,\n\ty: Types.f32,\n\tz: Types.f32,\n\tw: Types.f32\n});\n\nexport const scale = defineComponent({\n\tx: Types.f32,\n\ty: Types.f32,\n\tz: Types.f32\n});\n\n// Reusable quaternion to avoid allocations per frame\nconst _tempQuaternion = new Quaternion();\n\nexport type TransformSystemResult = {\n\tsystem: ReturnType<typeof defineSystem>;\n\tdestroy: (world: IWorld) => void;\n};\n\nexport default function createTransformSystem(stage: StageSystem): TransformSystemResult {\n\tconst queryTerms = [position, rotation];\n\tconst transformQuery = defineQuery(queryTerms);\n\tconst stageEntities = stage._childrenMap;\n\n\tconst system = defineSystem((world) => {\n\t\tconst entities = transformQuery(world);\n\t\tif (stageEntities === undefined) {\n\t\t\treturn world;\n\t\t}\n\n\t\tfor (const [key, stageEntity] of stageEntities) {\n\t\t\t// Early bailout - combine conditions\n\t\t\tif (!stageEntity?.body || stageEntity.markedForRemoval) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst id = entities[key];\n\t\t\tconst body = stageEntity.body;\n\t\t\tconst target = stageEntity.group ?? stageEntity.mesh;\n\n\t\t\t// Position sync\n\t\t\tconst translation = body.translation();\n\t\t\tposition.x[id] = translation.x;\n\t\t\tposition.y[id] = translation.y;\n\t\t\tposition.z[id] = translation.z;\n\n\t\t\tif (target) {\n\t\t\t\ttarget.position.set(translation.x, translation.y, translation.z);\n\t\t\t}\n\n\t\t\t// Skip rotation if controlled externally\n\t\t\tif (stageEntity.controlledRotation) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Rotation sync - reuse quaternion\n\t\t\tconst rot = body.rotation();\n\t\t\trotation.x[id] = rot.x;\n\t\t\trotation.y[id] = rot.y;\n\t\t\trotation.z[id] = rot.z;\n\t\t\trotation.w[id] = rot.w;\n\n\t\t\tif (target) {\n\t\t\t\t_tempQuaternion.set(rot.x, rot.y, rot.z, rot.w);\n\t\t\t\ttarget.setRotationFromQuaternion(_tempQuaternion);\n\t\t\t}\n\t\t}\n\n\t\treturn world;\n\t});\n\n\tconst destroy = (world: IWorld) => {\n\t\t// Remove the query from bitecs world tracking\n\t\tremoveQuery(world, transformQuery);\n\t};\n\n\treturn { system, destroy };\n}","import { Mesh, Material, ShaderMaterial, Group, Color } from 'three';\nimport {\n Collider,\n ColliderDesc,\n RigidBody,\n RigidBodyDesc,\n} from '@dimforge/rapier3d-compat';\nimport { position, rotation, scale } from '../systems/transformable.system';\nimport { Vec3 } from '../core/vector';\nimport { MaterialBuilder, MaterialOptions } from '../graphics/material';\nimport { CollisionOptions } from '../collision/collision-builder';\nimport { BaseNode } from '../core/base-node';\nimport {\n DestroyContext,\n SetupContext,\n UpdateContext,\n LoadedContext,\n CleanupContext,\n} from '../core/base-node-life-cycle';\nimport type { EntityMeshBuilder, EntityCollisionBuilder } from './builder';\nimport { Behavior } from '../actions/behaviors/behavior';\nimport {\n EventEmitterDelegate,\n zylemEventBus,\n type EntityEvents,\n} from '../events';\nimport type {\n BehaviorDescriptor,\n BehaviorRef,\n BehaviorHandle,\n} from '../behaviors/behavior-descriptor';\n\nexport interface CollisionContext<\n T,\n O extends GameEntityOptions,\n TGlobals extends Record<string, unknown> = any,\n> {\n entity: T;\n // Use 'any' for other's options type to break recursive type variance issues\n other: GameEntity<O | any>;\n globals: TGlobals;\n}\n\nexport type BehaviorContext<T, O extends GameEntityOptions> =\n | SetupContext<T, O>\n | UpdateContext<T, O>\n | CollisionContext<T, O>\n | DestroyContext<T, O>;\n\nexport type BehaviorCallback<T, O extends GameEntityOptions> = (\n params: BehaviorContext<T, O>,\n) => void;\n\nexport interface CollisionDelegate<T, O extends GameEntityOptions> {\n // Use 'any' for entity and options types to avoid contravariance issues\n // with function parameters. Type safety is still enforced at the call site via onCollision()\n collision?: ((params: CollisionContext<any, any>) => void)[];\n}\n\nexport type IBuilder<BuilderOptions = any> = {\n preBuild: (options: BuilderOptions) => BuilderOptions;\n build: (options: BuilderOptions) => BuilderOptions;\n postBuild: (options: BuilderOptions) => BuilderOptions;\n};\n\nexport type GameEntityOptions = {\n name?: string;\n color?: Color;\n size?: Vec3;\n position?: Vec3;\n batched?: boolean;\n collision?: Partial<CollisionOptions>;\n material?: Partial<MaterialOptions>;\n custom?: { [key: string]: any };\n collisionType?: string;\n collisionGroup?: string;\n collisionFilter?: string[];\n _builders?: {\n meshBuilder?: IBuilder | EntityMeshBuilder | null;\n collisionBuilder?: IBuilder | EntityCollisionBuilder | null;\n materialBuilder?: MaterialBuilder | null;\n };\n};\n\nexport abstract class GameEntityLifeCycle {\n abstract _setup(params: SetupContext<this>): void;\n abstract _update(params: UpdateContext<this>): void;\n abstract _destroy(params: DestroyContext<this>): void;\n}\n\nexport interface EntityDebugInfo {\n buildInfo: () => Record<string, string>;\n}\n\nexport type BehaviorCallbackType = 'setup' | 'update' | 'destroy' | 'collision';\n\nexport class GameEntity<O extends GameEntityOptions>\n extends BaseNode<O>\n implements GameEntityLifeCycle, EntityDebugInfo\n{\n public behaviors: Behavior[] = [];\n public group: Group | undefined;\n public mesh: Mesh | undefined;\n public materials: Material[] | undefined;\n public bodyDesc: RigidBodyDesc | null = null;\n public body: RigidBody | null = null;\n public colliderDesc: ColliderDesc | undefined;\n public collider: Collider | undefined;\n public custom: Record<string, any> = {};\n\n public debugInfo: Record<string, any> = {};\n public debugMaterial: ShaderMaterial | undefined;\n\n public collisionDelegate: CollisionDelegate<this, O> = {\n collision: [],\n };\n public collisionType?: string;\n\n /**\n * @deprecated Use the new ECS-based behavior system instead.\n * Use 'any' for callback types to avoid contravariance issues\n * with function parameters. Type safety is enforced where callbacks are registered.\n */\n public behaviorCallbackMap: Record<\n BehaviorCallbackType,\n BehaviorCallback<any, any>[]\n > = {\n setup: [],\n update: [],\n destroy: [],\n collision: [],\n };\n\n // Event delegate for dispatch/listen API\n protected eventDelegate = new EventEmitterDelegate<EntityEvents>();\n\n // Behavior references (new ECS pattern)\n private behaviorRefs: BehaviorRef[] = [];\n\n constructor() {\n super();\n }\n\n public create(): this {\n const { position: setupPosition } = this.options;\n const { x, y, z } = setupPosition || { x: 0, y: 0, z: 0 };\n this.behaviors = [\n { component: position, values: { x, y, z } },\n { component: scale, values: { x: 0, y: 0, z: 0 } },\n { component: rotation, values: { x: 0, y: 0, z: 0, w: 0 } },\n ];\n this.name = this.options.name || '';\n return this;\n }\n\n /**\n * Add collision callbacks\n */\n public onCollision(\n ...callbacks: ((params: CollisionContext<this, O>) => void)[]\n ): this {\n const existing = this.collisionDelegate.collision ?? [];\n this.collisionDelegate.collision = [...existing, ...callbacks];\n return this;\n }\n\n /**\n * Use a behavior on this entity via typed descriptor.\n * Behaviors will be auto-registered as systems when the entity is spawned.\n * @param descriptor The behavior descriptor (import from behaviors module)\n * @param options Optional overrides for the behavior's default options\n * @returns BehaviorHandle with behavior-specific methods for lazy FSM access\n */\n public use<\n O extends Record<string, any>,\n H extends Record<string, any> = Record<string, never>,\n >(\n descriptor: BehaviorDescriptor<O, H>,\n options?: Partial<O>,\n ): BehaviorHandle<O, H> {\n const behaviorRef: BehaviorRef<O> = {\n descriptor: descriptor as BehaviorDescriptor<O, any>,\n options: { ...descriptor.defaultOptions, ...options } as O,\n };\n this.behaviorRefs.push(behaviorRef as BehaviorRef<any>);\n\n // Create base handle\n const baseHandle = {\n getFSM: () => behaviorRef.fsm ?? null,\n getOptions: () => behaviorRef.options,\n ref: behaviorRef,\n };\n\n // Merge behavior-specific methods if createHandle is provided\n const customMethods = descriptor.createHandle?.(behaviorRef) ?? ({} as H);\n\n return {\n ...baseHandle,\n ...customMethods,\n } as BehaviorHandle<O, H>;\n }\n\n /**\n * Get all behavior references attached to this entity.\n * Used by the stage to auto-register required systems.\n */\n public getBehaviorRefs(): BehaviorRef[] {\n return this.behaviorRefs;\n }\n\n /**\n * Entity-specific setup - runs behavior callbacks\n * (User callbacks are handled by BaseNode's lifecycleCallbacks.setup)\n */\n public _setup(params: SetupContext<this>): void {\n this.behaviorCallbackMap.setup.forEach((callback) => {\n callback({ ...params, me: this });\n });\n }\n\n protected async _loaded(_params: LoadedContext<this>): Promise<void> {}\n\n /**\n * Entity-specific update - updates materials and runs behavior callbacks\n * (User callbacks are handled by BaseNode's lifecycleCallbacks.update)\n */\n public _update(params: UpdateContext<this>): void {\n this.updateMaterials(params);\n this.behaviorCallbackMap.update.forEach((callback) => {\n callback({ ...params, me: this });\n });\n }\n\n /**\n * Entity-specific destroy - runs behavior callbacks\n * (User callbacks are handled by BaseNode's lifecycleCallbacks.destroy)\n */\n public _destroy(params: DestroyContext<this>): void {\n this.behaviorCallbackMap.destroy.forEach((callback) => {\n callback({ ...params, me: this });\n });\n }\n\n protected async _cleanup(_params: CleanupContext<this>): Promise<void> {}\n\n public _collision(other: GameEntity<O>, globals?: any): void {\n if (this.collisionDelegate.collision?.length) {\n const callbacks = this.collisionDelegate.collision;\n callbacks.forEach((callback) => {\n callback({ entity: this, other, globals });\n });\n }\n this.behaviorCallbackMap.collision.forEach((callback) => {\n callback({ entity: this, other, globals });\n });\n }\n\n /**\n * @deprecated Use the new ECS-based behavior system instead.\n * See `lib/behaviors/thruster/thruster-movement.behavior.ts` for an example.\n */\n public addBehavior(behaviorCallback: {\n type: BehaviorCallbackType;\n handler: any;\n }): this {\n const handler = behaviorCallback.handler as unknown as BehaviorCallback<\n this,\n O\n >;\n if (handler) {\n this.behaviorCallbackMap[behaviorCallback.type].push(handler);\n }\n return this;\n }\n\n /**\n * @deprecated Use the new ECS-based behavior system instead.\n * See `lib/behaviors/thruster/thruster-movement.behavior.ts` for an example.\n */\n public addBehaviors(\n behaviorCallbacks: { type: BehaviorCallbackType; handler: any }[],\n ): this {\n behaviorCallbacks.forEach((callback) => {\n const handler = callback.handler as unknown as BehaviorCallback<this, O>;\n if (handler) {\n this.behaviorCallbackMap[callback.type].push(handler);\n }\n });\n return this;\n }\n\n protected updateMaterials(params: any) {\n if (!this.materials?.length) {\n return;\n }\n for (const material of this.materials) {\n if (material instanceof ShaderMaterial) {\n if (material.uniforms) {\n material.uniforms.iTime &&\n (material.uniforms.iTime.value += params.delta);\n }\n }\n }\n }\n\n public buildInfo(): Record<string, string> {\n const info: Record<string, string> = {};\n info.name = this.name;\n info.uuid = this.uuid;\n info.eid = this.eid.toString();\n return info;\n }\n\n // ─────────────────────────────────────────────────────────────────────────────\n // Events API\n // ─────────────────────────────────────────────────────────────────────────────\n\n /**\n * Dispatch an event from this entity.\n * Events are emitted both locally and to the global event bus.\n */\n dispatch<K extends keyof EntityEvents>(\n event: K,\n payload: EntityEvents[K],\n ): void {\n this.eventDelegate.dispatch(event, payload);\n (zylemEventBus as any).emit(event, payload);\n }\n\n /**\n * Listen for events on this entity instance.\n * @returns Unsubscribe function\n */\n listen<K extends keyof EntityEvents>(\n event: K,\n handler: (payload: EntityEvents[K]) => void,\n ): () => void {\n return this.eventDelegate.listen(event, handler);\n }\n\n /**\n * Clean up entity event subscriptions.\n */\n disposeEvents(): void {\n this.eventDelegate.dispose();\n }\n}\n","// this class is not for asset loading, it is for loading entity specific data\n// this is to keep the entity class focused purely on entity logic\n\nexport function isLoadable(obj: any): obj is EntityLoaderDelegate {\n\treturn typeof obj?.load === \"function\" && typeof obj?.data === \"function\";\n}\n\nexport interface EntityLoaderDelegate {\n\t/** Initiates loading (may be async internally, but call returns immediately) */\n\tload(): void;\n\t/** Returns data synchronously (may be null if still loading) */\n\tdata(): any;\n}\n\nexport class EntityLoader {\n\tentityReference: EntityLoaderDelegate;\n\n\tconstructor(entity: EntityLoaderDelegate) {\n\t\tthis.entityReference = entity;\n\t}\n\n\tload(): void {\n\t\tif (this.entityReference.load) {\n\t\t\tthis.entityReference.load();\n\t\t}\n\t}\n\n\tdata(): any {\n\t\tif (this.entityReference.data) {\n\t\t\treturn this.entityReference.data();\n\t\t}\n\t\treturn null;\n\t}\n}","import { GameEntityOptions, GameEntity } from \"./entity\";\nimport { BaseNode } from \"../core/base-node\";\nimport { EntityBuilder } from \"./builder\";\nimport { EntityCollisionBuilder } from \"./builder\";\nimport { EntityMeshBuilder } from \"./builder\";\nimport { EntityLoader, isLoadable } from \"./delegates/loader\";\n\nexport interface CreateGameEntityOptions<T extends GameEntity<any>, CreateOptions extends GameEntityOptions> {\n\targs: Array<any>;\n\tdefaultConfig: GameEntityOptions;\n\tEntityClass: new (options: any) => T;\n\tBuilderClass: new (options: any, entity: T, meshBuilder: any, collisionBuilder: any) => EntityBuilder<T, CreateOptions>;\n\tMeshBuilderClass?: new (data: any) => EntityMeshBuilder;\n\tCollisionBuilderClass?: new (data: any) => EntityCollisionBuilder;\n\tentityType: symbol;\n};\n\nexport function createEntity<T extends GameEntity<any>, CreateOptions extends GameEntityOptions>(params: CreateGameEntityOptions<T, CreateOptions>): T {\n\tconst {\n\t\targs,\n\t\tdefaultConfig,\n\t\tEntityClass,\n\t\tBuilderClass,\n\t\tentityType,\n\t\tMeshBuilderClass,\n\t\tCollisionBuilderClass,\n\t} = params;\n\n\tlet builder: EntityBuilder<T, CreateOptions> | null = null;\n\tlet configuration;\n\n\tconst configurationIndex = args.findIndex(node => !(node instanceof BaseNode));\n\tif (configurationIndex !== -1) {\n\t\tconst subArgs = args.splice(configurationIndex, 1);\n\t\tconfiguration = subArgs.find(node => !(node instanceof BaseNode));\n\t}\n\n\tconst mergedConfiguration = configuration ? { ...defaultConfig, ...configuration } : defaultConfig;\n\targs.push(mergedConfiguration);\n\n\tfor (const arg of args) {\n\t\tif (arg instanceof BaseNode) {\n\t\t\tcontinue;\n\t\t}\n\t\tlet entityData = null;\n\t\tconst entity = new EntityClass(arg);\n\t\ttry {\n\t\t\tif (isLoadable(entity)) {\n\t\t\t\tconst loader = new EntityLoader(entity);\n\t\t\t\tloader.load();\n\t\t\t\tentityData = loader.data();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Error creating entity with loader:\", error);\n\t\t}\n\t\tbuilder = new BuilderClass(\n\t\t\targ,\n\t\t\tentity,\n\t\t\tMeshBuilderClass ? new MeshBuilderClass(entityData) : null,\n\t\t\tCollisionBuilderClass ? new CollisionBuilderClass(entityData) : null,\n\t\t);\n\t\tif (arg.material) {\n\t\t\tbuilder.withMaterial(arg.material, entityType);\n\t\t}\n\t}\n\n\tif (!builder) {\n\t\tthrow new Error(`missing options for ${String(entityType)}, builder is not initialized.`);\n\t}\n\n\treturn builder.build();\n}\n\n","/**\n * Texture loader adapter for the Asset Manager\n */\n\nimport { TextureLoader, Texture, RepeatWrapping, Vector2, Wrapping } from 'three';\nimport { LoaderAdapter, AssetLoadOptions } from '../asset-types';\n\nexport interface TextureOptions extends AssetLoadOptions {\n\trepeat?: Vector2;\n\twrapS?: Wrapping;\n\twrapT?: Wrapping;\n}\n\nexport class TextureLoaderAdapter implements LoaderAdapter<Texture> {\n\tprivate loader: TextureLoader;\n\n\tconstructor() {\n\t\tthis.loader = new TextureLoader();\n\t}\n\n\tisSupported(url: string): boolean {\n\t\tconst ext = url.split('.').pop()?.toLowerCase();\n\t\treturn ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'tga'].includes(ext || '');\n\t}\n\n\tasync load(url: string, options?: TextureOptions): Promise<Texture> {\n\t\tconst texture = await this.loader.loadAsync(url, (event) => {\n\t\t\tif (options?.onProgress && event.lengthComputable) {\n\t\t\t\toptions.onProgress(event.loaded / event.total);\n\t\t\t}\n\t\t});\n\n\t\t// Apply texture options\n\t\tif (options?.repeat) {\n\t\t\ttexture.repeat.copy(options.repeat);\n\t\t}\n\t\ttexture.wrapS = options?.wrapS ?? RepeatWrapping;\n\t\ttexture.wrapT = options?.wrapT ?? RepeatWrapping;\n\n\t\treturn texture;\n\t}\n\n\t/**\n\t * Clone a texture for independent usage\n\t */\n\tclone(texture: Texture): Texture {\n\t\tconst cloned = texture.clone();\n\t\tcloned.needsUpdate = true;\n\t\treturn cloned;\n\t}\n}\n","/**\n * GLTF loader adapter for the Asset Manager\n * Uses native fetch (already async/non-blocking in browsers) + parseAsync\n */\n\nimport { GLTF, GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';\nimport { LoaderAdapter, AssetLoadOptions, ModelLoadResult } from '../asset-types';\n\nexport interface GLTFLoadOptions extends AssetLoadOptions {\n\t/** \n\t * Use async fetch + parseAsync pattern instead of loader.load()\n\t * Note: fetch() is already non-blocking in browsers, so this mainly\n\t * provides a cleaner async/await pattern rather than performance gains\n\t */\n\tuseAsyncFetch?: boolean;\n}\n\nexport class GLTFLoaderAdapter implements LoaderAdapter<ModelLoadResult> {\n\tprivate loader: GLTFLoader;\n\n\tconstructor() {\n\t\tthis.loader = new GLTFLoader();\n\t}\n\n\tisSupported(url: string): boolean {\n\t\tconst ext = url.split('.').pop()?.toLowerCase();\n\t\treturn ['gltf', 'glb'].includes(ext || '');\n\t}\n\n\tasync load(url: string, options?: GLTFLoadOptions): Promise<ModelLoadResult> {\n\t\tif (options?.useAsyncFetch) {\n\t\t\treturn this.loadWithAsyncFetch(url, options);\n\t\t}\n\t\treturn this.loadMainThread(url, options);\n\t}\n\n\t/**\n\t * Load using native fetch + parseAsync\n\t * Both fetch and parsing are async, keeping the main thread responsive\n\t */\n\tprivate async loadWithAsyncFetch(url: string, options?: GLTFLoadOptions): Promise<ModelLoadResult> {\n\t\ttry {\n\t\t\tconst response = await fetch(url);\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`);\n\t\t\t}\n\t\t\tconst buffer = await response.arrayBuffer();\n\n\t\t\t// Parse on main thread using GLTFLoader.parseAsync\n\t\t\t// The url is passed as the path for resolving relative resources\n\t\t\tconst gltf = await this.loader.parseAsync(buffer, url);\n\n\t\t\treturn {\n\t\t\t\tobject: gltf.scene,\n\t\t\t\tanimations: gltf.animations,\n\t\t\t\tgltf\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tconsole.error(`Async fetch GLTF load failed for ${url}, falling back to loader.load():`, error);\n\t\t\treturn this.loadMainThread(url, options);\n\t\t}\n\t}\n\n\tprivate async loadMainThread(url: string, options?: GLTFLoadOptions): Promise<ModelLoadResult> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.loader.load(\n\t\t\t\turl,\n\t\t\t\t(gltf: GLTF) => {\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tobject: gltf.scene,\n\t\t\t\t\t\tanimations: gltf.animations,\n\t\t\t\t\t\tgltf\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t(event) => {\n\t\t\t\t\tif (options?.onProgress && event.lengthComputable) {\n\t\t\t\t\t\toptions.onProgress(event.loaded / event.total);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t(error) => reject(error)\n\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * Clone a loaded GLTF scene for reuse\n\t */\n\tclone(result: ModelLoadResult): ModelLoadResult {\n\t\treturn {\n\t\t\tobject: result.object.clone(),\n\t\t\tanimations: result.animations?.map(anim => anim.clone()),\n\t\t\tgltf: result.gltf\n\t\t};\n\t}\n}\n","/**\n * FBX loader adapter for the Asset Manager\n * Uses native fetch (already async/non-blocking in browsers) + parse\n */\n\nimport { Object3D } from 'three';\nimport { FBXLoader } from 'three/addons/loaders/FBXLoader.js';\nimport { LoaderAdapter, AssetLoadOptions, ModelLoadResult } from '../asset-types';\n\nexport interface FBXLoadOptions extends AssetLoadOptions {\n\t/** \n\t * Use async fetch + parse pattern instead of loader.load()\n\t * Note: fetch() is already non-blocking in browsers\n\t */\n\tuseAsyncFetch?: boolean;\n}\n\nexport class FBXLoaderAdapter implements LoaderAdapter<ModelLoadResult> {\n\tprivate loader: FBXLoader;\n\n\tconstructor() {\n\t\tthis.loader = new FBXLoader();\n\t}\n\n\tisSupported(url: string): boolean {\n\t\tconst ext = url.split('.').pop()?.toLowerCase();\n\t\treturn ext === 'fbx';\n\t}\n\n\tasync load(url: string, options?: FBXLoadOptions): Promise<ModelLoadResult> {\n\t\tif (options?.useAsyncFetch) {\n\t\t\treturn this.loadWithAsyncFetch(url, options);\n\t\t}\n\t\treturn this.loadMainThread(url, options);\n\t}\n\n\t/**\n\t * Load using native fetch + parse\n\t */\n\tprivate async loadWithAsyncFetch(url: string, _options?: FBXLoadOptions): Promise<ModelLoadResult> {\n\t\ttry {\n\t\t\tconst response = await fetch(url);\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`);\n\t\t\t}\n\t\t\tconst buffer = await response.arrayBuffer();\n\n\t\t\t// Parse on main thread using FBXLoader.parse\n\t\t\tconst object = this.loader.parse(buffer, url);\n\n\t\t\treturn {\n\t\t\t\tobject,\n\t\t\t\tanimations: (object as any).animations || []\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tconsole.error(`Async fetch FBX load failed for ${url}, falling back to loader.load():`, error);\n\t\t\treturn this.loadMainThread(url, _options);\n\t\t}\n\t}\n\n\tprivate async loadMainThread(url: string, options?: FBXLoadOptions): Promise<ModelLoadResult> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.loader.load(\n\t\t\t\turl,\n\t\t\t\t(object: Object3D) => {\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tobject,\n\t\t\t\t\t\tanimations: (object as any).animations || []\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t(event) => {\n\t\t\t\t\tif (options?.onProgress && event.lengthComputable) {\n\t\t\t\t\t\toptions.onProgress(event.loaded / event.total);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t(error) => reject(error)\n\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * Clone a loaded FBX object for reuse\n\t */\n\tclone(result: ModelLoadResult): ModelLoadResult {\n\t\treturn {\n\t\t\tobject: result.object.clone(),\n\t\t\tanimations: result.animations?.map(anim => anim.clone())\n\t\t};\n\t}\n}\n","/**\n * OBJ loader adapter for the Asset Manager\n * Supports optional MTL (material) file loading\n */\n\nimport { Object3D, Group } from 'three';\nimport { OBJLoader } from 'three/addons/loaders/OBJLoader.js';\nimport { MTLLoader } from 'three/addons/loaders/MTLLoader.js';\nimport { LoaderAdapter, AssetLoadOptions, ModelLoadResult } from '../asset-types';\n\nexport interface OBJLoadOptions extends AssetLoadOptions {\n\t/** Path to MTL material file */\n\tmtlPath?: string;\n}\n\nexport class OBJLoaderAdapter implements LoaderAdapter<ModelLoadResult> {\n\tprivate loader: OBJLoader;\n\tprivate mtlLoader: MTLLoader;\n\n\tconstructor() {\n\t\tthis.loader = new OBJLoader();\n\t\tthis.mtlLoader = new MTLLoader();\n\t}\n\n\tisSupported(url: string): boolean {\n\t\tconst ext = url.split('.').pop()?.toLowerCase();\n\t\treturn ext === 'obj';\n\t}\n\n\tasync load(url: string, options?: OBJLoadOptions): Promise<ModelLoadResult> {\n\t\t// Load MTL first if provided\n\t\tif (options?.mtlPath) {\n\t\t\tawait this.loadMTL(options.mtlPath);\n\t\t}\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.loader.load(\n\t\t\t\turl,\n\t\t\t\t(object: Group) => {\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tobject,\n\t\t\t\t\t\tanimations: []\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t(event) => {\n\t\t\t\t\tif (options?.onProgress && event.lengthComputable) {\n\t\t\t\t\t\toptions.onProgress(event.loaded / event.total);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t(error) => reject(error)\n\t\t\t);\n\t\t});\n\t}\n\n\tprivate async loadMTL(url: string): Promise<void> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.mtlLoader.load(\n\t\t\t\turl,\n\t\t\t\t(materials) => {\n\t\t\t\t\tmaterials.preload();\n\t\t\t\t\tthis.loader.setMaterials(materials);\n\t\t\t\t\tresolve();\n\t\t\t\t},\n\t\t\t\tundefined,\n\t\t\t\t(error) => reject(error)\n\t\t\t);\n\t\t});\n\t}\n\n\t/**\n\t * Clone a loaded OBJ object for reuse\n\t */\n\tclone(result: ModelLoadResult): ModelLoadResult {\n\t\treturn {\n\t\t\tobject: result.object.clone(),\n\t\t\tanimations: []\n\t\t};\n\t}\n}\n","/**\n * Audio loader adapter for the Asset Manager\n */\n\nimport { AudioLoader } from 'three';\nimport { LoaderAdapter, AssetLoadOptions } from '../asset-types';\n\nexport class AudioLoaderAdapter implements LoaderAdapter<AudioBuffer> {\n\tprivate loader: AudioLoader;\n\n\tconstructor() {\n\t\tthis.loader = new AudioLoader();\n\t}\n\n\tisSupported(url: string): boolean {\n\t\tconst ext = url.split('.').pop()?.toLowerCase();\n\t\treturn ['mp3', 'ogg', 'wav', 'flac', 'aac', 'm4a'].includes(ext || '');\n\t}\n\n\tasync load(url: string, options?: AssetLoadOptions): Promise<AudioBuffer> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.loader.load(\n\t\t\t\turl,\n\t\t\t\t(buffer) => resolve(buffer),\n\t\t\t\t(event) => {\n\t\t\t\t\tif (options?.onProgress && event.lengthComputable) {\n\t\t\t\t\t\toptions.onProgress(event.loaded / event.total);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t(error) => reject(error)\n\t\t\t);\n\t\t});\n\t}\n}\n","/**\n * File loader adapter for the Asset Manager\n */\n\nimport { FileLoader } from 'three';\nimport { LoaderAdapter, AssetLoadOptions } from '../asset-types';\n\nexport interface FileLoadOptions extends AssetLoadOptions {\n\tresponseType?: 'text' | 'arraybuffer' | 'blob' | 'json';\n}\n\nexport class FileLoaderAdapter implements LoaderAdapter<string | ArrayBuffer> {\n\tprivate loader: FileLoader;\n\n\tconstructor() {\n\t\tthis.loader = new FileLoader();\n\t}\n\n\tisSupported(_url: string): boolean {\n\t\t// FileLoader can handle any file type\n\t\treturn true;\n\t}\n\n\tasync load(url: string, options?: FileLoadOptions): Promise<string | ArrayBuffer> {\n\t\tconst responseType = options?.responseType ?? 'text';\n\t\tthis.loader.setResponseType(responseType as any);\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.loader.load(\n\t\t\t\turl,\n\t\t\t\t(data) => resolve(data as string | ArrayBuffer),\n\t\t\t\t(event) => {\n\t\t\t\t\tif (options?.onProgress && event.lengthComputable) {\n\t\t\t\t\t\toptions.onProgress(event.loaded / event.total);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t(error) => reject(error)\n\t\t\t);\n\t\t});\n\t}\n}\n\n/**\n * JSON loader using FileLoader\n */\nexport class JsonLoaderAdapter implements LoaderAdapter<unknown> {\n\tprivate fileLoader: FileLoaderAdapter;\n\n\tconstructor() {\n\t\tthis.fileLoader = new FileLoaderAdapter();\n\t}\n\n\tisSupported(url: string): boolean {\n\t\tconst ext = url.split('.').pop()?.toLowerCase();\n\t\treturn ext === 'json';\n\t}\n\n\tasync load<T = unknown>(url: string, options?: AssetLoadOptions): Promise<T> {\n\t\tconst data = await this.fileLoader.load(url, { ...options, responseType: 'json' });\n\t\treturn data as T;\n\t}\n}\n","/**\n * Loader adapters barrel export\n */\n\nexport { TextureLoaderAdapter, type TextureOptions } from './texture-loader';\nexport { GLTFLoaderAdapter, type GLTFLoadOptions } from './gltf-loader';\nexport { FBXLoaderAdapter, type FBXLoadOptions } from './fbx-loader';\nexport { OBJLoaderAdapter, type OBJLoadOptions } from './obj-loader';\nexport { AudioLoaderAdapter } from './audio-loader';\nexport { FileLoaderAdapter, JsonLoaderAdapter, type FileLoadOptions } from './file-loader';\n","/**\n * Centralized Asset Manager for Zylem\n * \n * Provides caching, parallel loading, and unified access to all asset types.\n * All asset loading should funnel through this manager.\n */\n\nimport { Texture, Object3D, LoadingManager, Cache } from 'three';\nimport { GLTF } from 'three/addons/loaders/GLTFLoader.js';\nimport mitt, { Emitter } from 'mitt';\n\nimport {\n\tAssetType,\n\tAssetLoadOptions,\n\tAssetManagerEvents,\n\tBatchLoadItem,\n\tModelLoadResult\n} from './asset-types';\n\nimport {\n\tTextureLoaderAdapter,\n\tGLTFLoaderAdapter,\n\tFBXLoaderAdapter,\n\tOBJLoaderAdapter,\n\tAudioLoaderAdapter,\n\tFileLoaderAdapter,\n\tJsonLoaderAdapter,\n\tTextureOptions,\n\tGLTFLoadOptions,\n\tFBXLoadOptions,\n\tOBJLoadOptions,\n\tFileLoadOptions\n} from './loaders';\n\n/**\n * Asset cache entry\n */\ninterface CacheEntry<T> {\n\tpromise: Promise<T>;\n\tresult?: T;\n\tloadedAt: number;\n}\n\n/**\n * AssetManager - Singleton for all asset loading\n * \n * Features:\n * - URL-based caching with deduplication\n * - Typed load methods for each asset type\n * - Batch loading with Promise.all() for parallelism\n * - Progress events via LoadingManager\n * - Clone support for shared assets (textures, models)\n */\nexport class AssetManager {\n\tprivate static instance: AssetManager | null = null;\n\n\t// Caches for different asset types\n\tprivate textureCache: Map<string, CacheEntry<Texture>> = new Map();\n\tprivate modelCache: Map<string, CacheEntry<ModelLoadResult>> = new Map();\n\tprivate audioCache: Map<string, CacheEntry<AudioBuffer>> = new Map();\n\tprivate fileCache: Map<string, CacheEntry<string | ArrayBuffer>> = new Map();\n\tprivate jsonCache: Map<string, CacheEntry<unknown>> = new Map();\n\n\t// Loaders\n\tprivate textureLoader: TextureLoaderAdapter;\n\tprivate gltfLoader: GLTFLoaderAdapter;\n\tprivate fbxLoader: FBXLoaderAdapter;\n\tprivate objLoader: OBJLoaderAdapter;\n\tprivate audioLoader: AudioLoaderAdapter;\n\tprivate fileLoader: FileLoaderAdapter;\n\tprivate jsonLoader: JsonLoaderAdapter;\n\n\t// Loading manager for progress tracking\n\tprivate loadingManager: LoadingManager;\n\n\t// Event emitter\n\tprivate events: Emitter<AssetManagerEvents>;\n\n\t// Stats\n\tprivate stats = {\n\t\ttexturesLoaded: 0,\n\t\tmodelsLoaded: 0,\n\t\taudioLoaded: 0,\n\t\tfilesLoaded: 0,\n\t\tcacheHits: 0,\n\t\tcacheMisses: 0\n\t};\n\n\tprivate constructor() {\n\t\t// Initialize loaders\n\t\tthis.textureLoader = new TextureLoaderAdapter();\n\t\tthis.gltfLoader = new GLTFLoaderAdapter();\n\t\tthis.fbxLoader = new FBXLoaderAdapter();\n\t\tthis.objLoader = new OBJLoaderAdapter();\n\t\tthis.audioLoader = new AudioLoaderAdapter();\n\t\tthis.fileLoader = new FileLoaderAdapter();\n\t\tthis.jsonLoader = new JsonLoaderAdapter();\n\n\t\t// Initialize loading manager\n\t\tthis.loadingManager = new LoadingManager();\n\t\tthis.loadingManager.onProgress = (url, loaded, total) => {\n\t\t\tthis.events.emit('batch:progress', { loaded, total });\n\t\t};\n\n\t\t// Initialize event emitter\n\t\tthis.events = mitt<AssetManagerEvents>();\n\n\t\t// Enable Three.js built-in cache\n\t\tCache.enabled = true;\n\t}\n\n\t/**\n\t * Get the singleton instance\n\t */\n\tstatic getInstance(): AssetManager {\n\t\tif (!AssetManager.instance) {\n\t\t\tAssetManager.instance = new AssetManager();\n\t\t}\n\t\treturn AssetManager.instance;\n\t}\n\n\t/**\n\t * Reset the singleton (useful for testing)\n\t */\n\tstatic resetInstance(): void {\n\t\tif (AssetManager.instance) {\n\t\t\tAssetManager.instance.clearCache();\n\t\t\tAssetManager.instance = null;\n\t\t}\n\t}\n\n\t// ==================== TEXTURE LOADING ====================\n\n\t/**\n\t * Load a texture with caching\n\t */\n\tasync loadTexture(url: string, options?: TextureOptions): Promise<Texture> {\n\t\treturn this.loadWithCache(\n\t\t\turl,\n\t\t\tAssetType.TEXTURE,\n\t\t\tthis.textureCache,\n\t\t\t() => this.textureLoader.load(url, options),\n\t\t\toptions,\n\t\t\t(texture) => options?.clone ? this.textureLoader.clone(texture) : texture\n\t\t);\n\t}\n\n\t// ==================== MODEL LOADING ====================\n\n\t/**\n\t * Load a GLTF/GLB model with caching\n\t */\n\tasync loadGLTF(url: string, options?: GLTFLoadOptions): Promise<ModelLoadResult> {\n\t\treturn this.loadWithCache(\n\t\t\turl,\n\t\t\tAssetType.GLTF,\n\t\t\tthis.modelCache,\n\t\t\t() => this.gltfLoader.load(url, options),\n\t\t\toptions,\n\t\t\t(result) => options?.clone ? this.gltfLoader.clone(result) : result\n\t\t);\n\t}\n\n\t/**\n\t * Load an FBX model with caching\n\t */\n\tasync loadFBX(url: string, options?: FBXLoadOptions): Promise<ModelLoadResult> {\n\t\treturn this.loadWithCache(\n\t\t\turl,\n\t\t\tAssetType.FBX,\n\t\t\tthis.modelCache,\n\t\t\t() => this.fbxLoader.load(url, options),\n\t\t\toptions,\n\t\t\t(result) => options?.clone ? this.fbxLoader.clone(result) : result\n\t\t);\n\t}\n\n\t/**\n\t * Load an OBJ model with caching\n\t */\n\tasync loadOBJ(url: string, options?: OBJLoadOptions): Promise<ModelLoadResult> {\n\t\t// Include mtlPath in cache key for OBJ files\n\t\tconst cacheKey = options?.mtlPath ? `${url}:${options.mtlPath}` : url;\n\t\treturn this.loadWithCache(\n\t\t\tcacheKey,\n\t\t\tAssetType.OBJ,\n\t\t\tthis.modelCache,\n\t\t\t() => this.objLoader.load(url, options),\n\t\t\toptions,\n\t\t\t(result) => options?.clone ? this.objLoader.clone(result) : result\n\t\t);\n\t}\n\n\t/**\n\t * Auto-detect model type and load\n\t */\n\tasync loadModel(url: string, options?: AssetLoadOptions): Promise<ModelLoadResult> {\n\t\tconst ext = url.split('.').pop()?.toLowerCase();\n\t\t\n\t\tswitch (ext) {\n\t\t\tcase 'gltf':\n\t\t\tcase 'glb':\n\t\t\t\treturn this.loadGLTF(url, options);\n\t\t\tcase 'fbx':\n\t\t\t\treturn this.loadFBX(url, options);\n\t\t\tcase 'obj':\n\t\t\t\treturn this.loadOBJ(url, options);\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unsupported model format: ${ext}`);\n\t\t}\n\t}\n\n\t// ==================== AUDIO LOADING ====================\n\n\t/**\n\t * Load an audio buffer with caching\n\t */\n\tasync loadAudio(url: string, options?: AssetLoadOptions): Promise<AudioBuffer> {\n\t\treturn this.loadWithCache(\n\t\t\turl,\n\t\t\tAssetType.AUDIO,\n\t\t\tthis.audioCache,\n\t\t\t() => this.audioLoader.load(url, options),\n\t\t\toptions\n\t\t);\n\t}\n\n\t// ==================== FILE LOADING ====================\n\n\t/**\n\t * Load a raw file with caching\n\t */\n\tasync loadFile(url: string, options?: FileLoadOptions): Promise<string | ArrayBuffer> {\n\t\tconst cacheKey = options?.responseType ? `${url}:${options.responseType}` : url;\n\t\treturn this.loadWithCache(\n\t\t\tcacheKey,\n\t\t\tAssetType.FILE,\n\t\t\tthis.fileCache,\n\t\t\t() => this.fileLoader.load(url, options),\n\t\t\toptions\n\t\t);\n\t}\n\n\t/**\n\t * Load a JSON file with caching\n\t */\n\tasync loadJSON<T = unknown>(url: string, options?: AssetLoadOptions): Promise<T> {\n\t\treturn this.loadWithCache(\n\t\t\turl,\n\t\t\tAssetType.JSON,\n\t\t\tthis.jsonCache,\n\t\t\t() => this.jsonLoader.load<T>(url, options),\n\t\t\toptions\n\t\t) as Promise<T>;\n\t}\n\n\t// ==================== BATCH LOADING ====================\n\n\t/**\n\t * Load multiple assets in parallel\n\t */\n\tasync loadBatch(items: BatchLoadItem[]): Promise<Map<string, any>> {\n\t\tconst results = new Map<string, any>();\n\t\t\n\t\tconst promises = items.map(async (item) => {\n\t\t\ttry {\n\t\t\t\tlet result: any;\n\t\t\t\t\n\t\t\t\tswitch (item.type) {\n\t\t\t\t\tcase AssetType.TEXTURE:\n\t\t\t\t\t\tresult = await this.loadTexture(item.url, item.options);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase AssetType.GLTF:\n\t\t\t\t\t\tresult = await this.loadGLTF(item.url, item.options);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase AssetType.FBX:\n\t\t\t\t\t\tresult = await this.loadFBX(item.url, item.options);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase AssetType.OBJ:\n\t\t\t\t\t\tresult = await this.loadOBJ(item.url, item.options);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase AssetType.AUDIO:\n\t\t\t\t\t\tresult = await this.loadAudio(item.url, item.options);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase AssetType.FILE:\n\t\t\t\t\t\tresult = await this.loadFile(item.url, item.options);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase AssetType.JSON:\n\t\t\t\t\t\tresult = await this.loadJSON(item.url, item.options);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthrow new Error(`Unknown asset type: ${item.type}`);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tresults.set(item.url, result);\n\t\t\t} catch (error) {\n\t\t\t\tthis.events.emit('asset:error', {\n\t\t\t\t\turl: item.url,\n\t\t\t\t\ttype: item.type,\n\t\t\t\t\terror: error as Error\n\t\t\t\t});\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t});\n\n\t\tawait Promise.all(promises);\n\t\t\n\t\tthis.events.emit('batch:complete', { urls: items.map(i => i.url) });\n\t\t\n\t\treturn results;\n\t}\n\n\t/**\n\t * Preload assets without returning results\n\t */\n\tasync preload(items: BatchLoadItem[]): Promise<void> {\n\t\tawait this.loadBatch(items);\n\t}\n\n\t// ==================== CACHE MANAGEMENT ====================\n\n\t/**\n\t * Check if an asset is cached\n\t */\n\tisCached(url: string): boolean {\n\t\treturn this.textureCache.has(url) ||\n\t\t\tthis.modelCache.has(url) ||\n\t\t\tthis.audioCache.has(url) ||\n\t\t\tthis.fileCache.has(url) ||\n\t\t\tthis.jsonCache.has(url);\n\t}\n\n\t/**\n\t * Clear all caches or a specific URL\n\t */\n\tclearCache(url?: string): void {\n\t\tif (url) {\n\t\t\tthis.textureCache.delete(url);\n\t\t\tthis.modelCache.delete(url);\n\t\t\tthis.audioCache.delete(url);\n\t\t\tthis.fileCache.delete(url);\n\t\t\tthis.jsonCache.delete(url);\n\t\t} else {\n\t\t\tthis.textureCache.clear();\n\t\t\tthis.modelCache.clear();\n\t\t\tthis.audioCache.clear();\n\t\t\tthis.fileCache.clear();\n\t\t\tthis.jsonCache.clear();\n\t\t\tCache.clear();\n\t\t}\n\t}\n\n\t/**\n\t * Get cache statistics\n\t */\n\tgetStats(): typeof this.stats {\n\t\treturn { ...this.stats };\n\t}\n\n\t// ==================== EVENTS ====================\n\n\t/**\n\t * Subscribe to asset manager events\n\t */\n\ton<K extends keyof AssetManagerEvents>(\n\t\tevent: K,\n\t\thandler: (payload: AssetManagerEvents[K]) => void\n\t): void {\n\t\tthis.events.on(event, handler);\n\t}\n\n\t/**\n\t * Unsubscribe from asset manager events\n\t */\n\toff<K extends keyof AssetManagerEvents>(\n\t\tevent: K,\n\t\thandler: (payload: AssetManagerEvents[K]) => void\n\t): void {\n\t\tthis.events.off(event, handler);\n\t}\n\n\t// ==================== PRIVATE HELPERS ====================\n\n\t/**\n\t * Generic cache wrapper for loading assets\n\t */\n\tprivate async loadWithCache<T>(\n\t\turl: string,\n\t\ttype: AssetType,\n\t\tcache: Map<string, CacheEntry<T>>,\n\t\tloader: () => Promise<T>,\n\t\toptions?: AssetLoadOptions,\n\t\tcloner?: (result: T) => T\n\t): Promise<T> {\n\t\t// Check for force reload\n\t\tif (options?.forceReload) {\n\t\t\tcache.delete(url);\n\t\t}\n\n\t\t// Check cache\n\t\tconst cached = cache.get(url);\n\t\tif (cached) {\n\t\t\tthis.stats.cacheHits++;\n\t\t\tthis.events.emit('asset:loaded', { url, type, fromCache: true });\n\t\t\t\n\t\t\tconst result = await cached.promise;\n\t\t\treturn cloner ? cloner(result) : result;\n\t\t}\n\n\t\t// Cache miss - start loading\n\t\tthis.stats.cacheMisses++;\n\t\tthis.events.emit('asset:loading', { url, type });\n\n\t\tconst promise = loader();\n\t\tconst entry: CacheEntry<T> = {\n\t\t\tpromise,\n\t\t\tloadedAt: Date.now()\n\t\t};\n\t\tcache.set(url, entry);\n\n\t\ttry {\n\t\t\tconst result = await promise;\n\t\t\tentry.result = result;\n\t\t\t\n\t\t\t// Update stats\n\t\t\tthis.updateStats(type);\n\t\t\t\n\t\t\tthis.events.emit('asset:loaded', { url, type, fromCache: false });\n\t\t\t\n\t\t\treturn cloner ? cloner(result) : result;\n\t\t} catch (error) {\n\t\t\t// Remove failed entry from cache\n\t\t\tcache.delete(url);\n\t\t\tthis.events.emit('asset:error', { url, type, error: error as Error });\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate updateStats(type: AssetType): void {\n\t\tswitch (type) {\n\t\t\tcase AssetType.TEXTURE:\n\t\t\t\tthis.stats.texturesLoaded++;\n\t\t\t\tbreak;\n\t\t\tcase AssetType.GLTF:\n\t\t\tcase AssetType.FBX:\n\t\t\tcase AssetType.OBJ:\n\t\t\t\tthis.stats.modelsLoaded++;\n\t\t\t\tbreak;\n\t\t\tcase AssetType.AUDIO:\n\t\t\t\tthis.stats.audioLoaded++;\n\t\t\t\tbreak;\n\t\t\tcase AssetType.FILE:\n\t\t\tcase AssetType.JSON:\n\t\t\t\tthis.stats.filesLoaded++;\n\t\t\t\tbreak;\n\t\t}\n\t}\n}\n\n/**\n * Singleton instance export for convenience\n */\nexport const assetManager = AssetManager.getInstance();","/**\n * Entity Asset Loader - Refactored to use AssetManager\n * \n * This module provides a compatibility layer for existing code that uses EntityAssetLoader.\n * All loading now goes through the centralized AssetManager for caching.\n */\n\nimport { AnimationClip, Object3D } from 'three';\nimport { GLTF } from 'three/addons/loaders/GLTFLoader.js';\nimport { assetManager } from './asset-manager';\n\nexport interface AssetLoaderResult {\n\tobject?: Object3D;\n\tanimation?: AnimationClip;\n\tgltf?: GLTF;\n}\n\n/**\n * EntityAssetLoader - Uses AssetManager for all model loading\n * \n * This class is now a thin wrapper around AssetManager, providing backward\n * compatibility for existing code while benefiting from centralized caching.\n */\nexport class EntityAssetLoader {\n\t/**\n\t * Load a model file (FBX, GLTF, GLB, OBJ) using the asset manager\n\t */\n\tasync loadFile(file: string): Promise<AssetLoaderResult> {\n\t\tconst ext = file.split('.').pop()?.toLowerCase();\n\n\t\tswitch (ext) {\n\t\t\tcase 'fbx': {\n\t\t\t\tconst result = await assetManager.loadFBX(file);\n\t\t\t\treturn {\n\t\t\t\t\tobject: result.object,\n\t\t\t\t\tanimation: result.animations?.[0]\n\t\t\t\t};\n\t\t\t}\n\t\t\tcase 'gltf':\n\t\t\tcase 'glb': {\n\t\t\t\tconst result = await assetManager.loadGLTF(file);\n\t\t\t\treturn {\n\t\t\t\t\tobject: result.object,\n\t\t\t\t\tgltf: result.gltf\n\t\t\t\t};\n\t\t\t}\n\t\t\tcase 'obj': {\n\t\t\t\tconst result = await assetManager.loadOBJ(file);\n\t\t\t\treturn {\n\t\t\t\t\tobject: result.object\n\t\t\t\t};\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unsupported file type: ${file}`);\n\t\t}\n\t}\n}\n","import {\n\tAnimationAction,\n\tAnimationClip,\n\tAnimationMixer,\n\tLoopOnce,\n\tLoopRepeat,\n\tObject3D,\n} from 'three';\nimport { EntityAssetLoader, AssetLoaderResult } from '../../core/entity-asset-loader';\n\nexport type AnimationOptions = {\n\tkey: string;\n\tpauseAtEnd?: boolean;\n\tpauseAtPercentage?: number;\n\tfadeToKey?: string;\n\tfadeDuration?: number;\n};\n\ntype AnimationObject = {\n\tkey?: string;\n\tpath: string;\n};\n\nexport class AnimationDelegate {\n\tprivate _mixer: AnimationMixer | null = null;\n\tprivate _actions: Record<string, AnimationAction> = {};\n\tprivate _animations: AnimationClip[] = [];\n\tprivate _currentAction: AnimationAction | null = null;\n\n\tprivate _pauseAtPercentage = 0;\n\tprivate _isPaused = false;\n\tprivate _queuedKey: string | null = null;\n\tprivate _fadeDuration = 0.5;\n\n\tprivate _currentKey: string = '';\n\tprivate _assetLoader = new EntityAssetLoader();\n\n\tconstructor(private target: Object3D) { }\n\n\tasync loadAnimations(animations: AnimationObject[]): Promise<void> {\n\t\tif (!animations.length) return;\n\n\t\tconst results = await Promise.all(animations.map(a => this._assetLoader.loadFile(a.path)));\n\t\tthis._animations = results\n\t\t\t.filter((r): r is AssetLoaderResult => !!r.animation)\n\t\t\t.map(r => r.animation!);\n\n\t\tif (!this._animations.length) return;\n\n\t\tthis._mixer = new AnimationMixer(this.target);\n\t\tthis._animations.forEach((clip, i) => {\n\t\t\tconst key = animations[i].key || i.toString();\n\t\t\tthis._actions[key] = this._mixer!.clipAction(clip);\n\t\t});\n\n\t\tthis.playAnimation({ key: Object.keys(this._actions)[0] });\n\t}\n\n\tupdate(delta: number): void {\n\t\tif (!this._mixer || !this._currentAction) return;\n\n\t\tthis._mixer.update(delta);\n\n\t\tconst pauseAtTime = this._currentAction.getClip().duration * (this._pauseAtPercentage / 100);\n\t\tif (\n\t\t\t!this._isPaused &&\n\t\t\tthis._pauseAtPercentage > 0 &&\n\t\t\tthis._currentAction.time >= pauseAtTime\n\t\t) {\n\t\t\tthis._currentAction.time = pauseAtTime;\n\t\t\tthis._currentAction.paused = true;\n\t\t\tthis._isPaused = true;\n\n\t\t\tif (this._queuedKey !== null) {\n\t\t\t\tconst next = this._actions[this._queuedKey];\n\t\t\t\tnext.reset().play();\n\t\t\t\tthis._currentAction.crossFadeTo(next, this._fadeDuration, false);\n\t\t\t\tthis._currentAction = next;\n\t\t\t\tthis._currentKey = this._queuedKey;\n\t\t\t\tthis._queuedKey = null;\n\t\t\t}\n\t\t}\n\t}\n\n\tplayAnimation(opts: AnimationOptions): void {\n\t\tif (!this._mixer) return;\n\t\tconst { key, pauseAtPercentage = 0, pauseAtEnd = false, fadeToKey, fadeDuration = 0.5 } = opts;\n\t\tif (key === this._currentKey) return;\n\n\t\tthis._queuedKey = fadeToKey || null;\n\t\tthis._fadeDuration = fadeDuration;\n\n\t\tthis._pauseAtPercentage = pauseAtEnd ? 100 : pauseAtPercentage;\n\t\tthis._isPaused = false;\n\n\t\tconst prev = this._currentAction;\n\t\tif (prev) prev.stop();\n\n\t\tconst action = this._actions[key];\n\t\tif (!action) return;\n\n\t\tif (this._pauseAtPercentage > 0) {\n\t\t\taction.setLoop(LoopOnce, Infinity);\n\t\t\taction.clampWhenFinished = true;\n\t\t} else {\n\t\t\taction.setLoop(LoopRepeat, Infinity);\n\t\t\taction.clampWhenFinished = false;\n\t\t}\n\n\t\tif (prev) {\n\t\t\tprev.crossFadeTo(action, fadeDuration, false);\n\t\t}\n\t\taction.reset().play();\n\n\t\tthis._currentAction = action;\n\t\tthis._currentKey = key;\n\t}\n\n\t/**\n\t * Dispose of all animation resources\n\t */\n\tdispose(): void {\n\t\t// Stop all actions\n\t\tObject.values(this._actions).forEach(action => {\n\t\t\taction.stop();\n\t\t});\n\n\t\t// Stop and uncache mixer\n\t\tif (this._mixer) {\n\t\t\tthis._mixer.stopAllAction();\n\t\t\tthis._mixer.uncacheRoot(this.target);\n\t\t\tthis._mixer = null;\n\t\t}\n\n\t\t// Clear references\n\t\tthis._actions = {};\n\t\tthis._animations = [];\n\t\tthis._currentAction = null;\n\t\tthis._currentKey = '';\n\t}\n\n\tget currentAnimationKey() { return this._currentKey; }\n\tget animations() { return this._animations; }\n}\n","import { ActiveCollisionTypes, ColliderDesc, RigidBodyDesc, RigidBodyType, Vector3 } from \"@dimforge/rapier3d-compat\";\nimport { Vec3 } from \"../core/vector\";\n\n/**\n * Options for configuring entity collision behavior.\n */\nexport interface CollisionOptions {\n\tstatic?: boolean;\n\tsensor?: boolean;\n\tsize?: Vector3;\n\tposition?: Vector3;\n\tcollisionType?: string;\n\tcollisionFilter?: string[];\n}\n\nconst typeToGroup = new Map<string, number>();\nlet nextGroupId = 0;\n\nexport function getOrCreateCollisionGroupId(type: string): number {\n\tlet groupId = typeToGroup.get(type);\n\tif (groupId === undefined) {\n\t\tgroupId = nextGroupId++ % 16;\n\t\ttypeToGroup.set(type, groupId);\n\t}\n\treturn groupId;\n}\n\nexport function createCollisionFilter(allowedTypes: string[]): number {\n\tlet filter = 0;\n\tallowedTypes.forEach(type => {\n\t\tconst groupId = getOrCreateCollisionGroupId(type);\n\t\tfilter |= (1 << groupId);\n\t});\n\treturn filter;\n}\n\nexport class CollisionBuilder {\n\tstatic: boolean = false;\n\tsensor: boolean = false;\n\tgravity: Vec3 = new Vector3(0, 0, 0);\n\n\tbuild(options: Partial<CollisionOptions>): [RigidBodyDesc, ColliderDesc] {\n\t\tconst bodyDesc = this.bodyDesc({\n\t\t\tisDynamicBody: !this.static\n\t\t});\n\t\tconst collider = this.collider(options);\n\t\tconst type = options.collisionType;\n\t\tif (type) {\n\t\t\tlet groupId = getOrCreateCollisionGroupId(type);\n\t\t\tlet filter = 0b1111111111111111;\n\t\t\tif (options.collisionFilter) {\n\t\t\t\tfilter = createCollisionFilter(options.collisionFilter);\n\t\t\t}\n\t\t\tcollider.setCollisionGroups((groupId << 16) | filter);\n\t\t}\n\t\tconst { KINEMATIC_FIXED, DEFAULT } = ActiveCollisionTypes;\n\t\tcollider.activeCollisionTypes = (this.sensor) ? KINEMATIC_FIXED : DEFAULT;\n\t\treturn [bodyDesc, collider];\n\t}\n\n\twithCollision(collisionOptions: Partial<CollisionOptions>): this {\n\t\tthis.sensor = collisionOptions?.sensor ?? this.sensor;\n\t\tthis.static = collisionOptions?.static ?? this.static;\n\t\treturn this;\n\t}\n\n\tcollider(options: CollisionOptions): ColliderDesc {\n\t\tconst size = options.size ?? new Vector3(1, 1, 1);\n\t\tconst half = { x: size.x / 2, y: size.y / 2, z: size.z / 2 };\n\t\tlet colliderDesc = ColliderDesc.cuboid(half.x, half.y, half.z);\n\t\treturn colliderDesc;\n\t}\n\n\tbodyDesc({ isDynamicBody = true }): RigidBodyDesc {\n\t\tconst type = isDynamicBody ? RigidBodyType.Dynamic : RigidBodyType.Fixed;\n\t\tconst bodyDesc = new RigidBodyDesc(type)\n\t\t\t.setTranslation(0, 0, 0)\n\t\t\t.setGravityScale(1.0)\n\t\t\t.setCanSleep(false)\n\t\t\t.setCcdEnabled(true);\n\t\treturn bodyDesc;\n\t}\n}","import { BufferGeometry, Material, Mesh } from 'three';\nimport { GameEntityOptions } from '../entities/entity';\n\n/**\n * TODO: allow for multiple materials requires geometry groups\n * TODO: allow for instanced uniforms\n * TODO: allow for geometry groups\n * TODO: allow for batched meshes\n * import { InstancedUniformsMesh } from 'three-instanced-uniforms-mesh';\n * may not need geometry groups for shaders though\n * setGeometry<T extends BufferGeometry>(geometry: T) {\n * MeshBuilder.bachedMesh = new BatchedMesh(10, 5000, 10000, material);\n * }\n */\n\nexport type MeshBuilderOptions = Partial<Pick<GameEntityOptions, 'batched' | 'material'>>;\n\nexport class MeshBuilder {\n\n\t_build(meshOptions: MeshBuilderOptions, geometry: BufferGeometry, materials: Material[]): Mesh {\n\t\tconst { batched, material } = meshOptions;\n\t\tif (batched) {\n\t\t\tconsole.warn('warning: mesh batching is not implemented');\n\t\t}\n\t\tconst mesh = new Mesh(geometry, materials.at(-1));\n\t\tmesh.position.set(0, 0, 0);\n\t\tmesh.castShadow = true;\n\t\tmesh.receiveShadow = true;\n\t\treturn mesh;\n\t}\n\n\t_postBuild(): void {\n\t\treturn;\n\t}\n}","export function sortedStringify(obj: Record<string, any>) {\n\tconst sortedObj = Object.keys(obj)\n\t\t.sort()\n\t\t.reduce((acc: Record<string, any>, key: string) => {\n\t\t\tacc[key] = obj[key];\n\t\t\treturn acc;\n\t\t}, {} as Record<string, any>);\n\n\treturn JSON.stringify(sortedObj);\n}\n\nexport function shortHash(objString: string) {\n\tlet hash = 0;\n\tfor (let i = 0; i < objString.length; i++) {\n\t\thash = Math.imul(31, hash) + objString.charCodeAt(i) | 0;\n\t}\n\treturn hash.toString(36);\n}","export const objectVertexShader = `\nuniform vec2 uvScale;\nvarying vec2 vUv;\n\nvoid main() {\n\tvUv = uv;\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tgl_Position = projectionMatrix * mvPosition;\n}\n`;\n","import { objectVertexShader } from './vertex/object.shader';\n\nconst fragment = `\nuniform sampler2D tDiffuse;\nvarying vec2 vUv;\n\nvoid main() {\n\tvec4 texel = texture2D( tDiffuse, vUv );\n\n\tgl_FragColor = texel;\n}\n`;\n\nexport const standardShader = {\n vertex: objectVertexShader,\n fragment\n};\n","import {\n\tColor,\n\tMaterial,\n\tMeshPhongMaterial,\n\tMeshStandardMaterial,\n\tNormalBlending,\n\tRepeatWrapping,\n\tShaderMaterial,\n\tVector2,\n\tVector3\n} from 'three';\nimport { shortHash, sortedStringify } from '../core/utility/strings';\nimport { standardShader } from './shaders/standard.shader';\nimport { assetManager } from '../core/asset-manager';\n\nexport type ZylemShaderObject = { fragment: string, vertex: string };\n\nexport interface MaterialOptions {\n\tpath?: string;\n\trepeat?: Vector2;\n\tshader?: ZylemShaderObject;\n\tcolor?: Color;\n}\n\ntype BatchGeometryMap = Map<symbol, number>;\n\ninterface BatchMaterialMapObject {\n\tgeometryMap: BatchGeometryMap;\n\tmaterial: Material;\n};\n\ntype BatchKey = ReturnType<typeof shortHash>;\n\nexport type TexturePath = string | null;\n\nexport class MaterialBuilder {\n\tstatic batchMaterialMap: Map<BatchKey, BatchMaterialMapObject> = new Map();\n\n\tmaterials: Material[] = [];\n\n\tbatchMaterial(options: Partial<MaterialOptions>, entityType: symbol) {\n\t\tconst batchKey = shortHash(sortedStringify(options));\n\t\tconst mappedObject = MaterialBuilder.batchMaterialMap.get(batchKey);\n\t\tif (mappedObject) {\n\t\t\tconst count = mappedObject.geometryMap.get(entityType);\n\t\t\tif (count) {\n\t\t\t\tmappedObject.geometryMap.set(entityType, count + 1);\n\t\t\t} else {\n\t\t\t\tmappedObject.geometryMap.set(entityType, 1);\n\t\t\t}\n\t\t} else {\n\t\t\tMaterialBuilder.batchMaterialMap.set(\n\t\t\t\tbatchKey, {\n\t\t\t\tgeometryMap: new Map([[entityType, 1]]),\n\t\t\t\tmaterial: this.materials[0]\n\t\t\t});\n\t\t}\n\t}\n\n\tbuild(options: Partial<MaterialOptions>, entityType: symbol): void {\n\t\tconst { path, repeat, color, shader } = options;\n\t\t// If shader is provided, use it; otherwise execute standard logic\n\t\tif (shader) {\n\t\t\tthis.withShader(shader);\n\t\t} else if (path) {\n\t\t\t// If path provided but no shader, standard texture logic applies\n\t\t\tthis.setTexture(path, repeat);\n\t\t}\n\t\t\n\t\tif (color) {\n\t\t\t// standard color material if no custom shader\n\t\t\tthis.withColor(color);\n\t\t}\n\n\t\tif (this.materials.length === 0) {\n\t\t\tthis.setColor(new Color('#ffffff'));\n\t\t}\n\t\tthis.batchMaterial(options, entityType);\n\t}\n\n\twithColor(color: Color): this {\n\t\tthis.setColor(color);\n\t\treturn this;\n\t}\n\n\twithShader(shader: ZylemShaderObject): this {\n\t\tthis.setShader(shader);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Set texture - loads in background (deferred).\n\t * Material is created immediately with null map, texture applies when loaded.\n\t */\n\tsetTexture(texturePath: TexturePath = null, repeat: Vector2 = new Vector2(1, 1)): void {\n\t\tif (!texturePath) {\n\t\t\treturn;\n\t\t}\n\t\t// Create material immediately with null map\n\t\tconst material = new MeshPhongMaterial({\n\t\t\tmap: null,\n\t\t});\n\t\tthis.materials.push(material);\n\n\t\t// Load texture in background and apply when ready\n\t\tassetManager.loadTexture(texturePath as string, { \n\t\t\tclone: true,\n\t\t\trepeat \n\t\t}).then(texture => {\n\t\t\ttexture.wrapS = RepeatWrapping;\n\t\t\ttexture.wrapT = RepeatWrapping;\n\t\t\tmaterial.map = texture;\n\t\t\tmaterial.needsUpdate = true;\n\t\t});\n\t}\n\n\tsetColor(color: Color) {\n\t\tconst material = new MeshStandardMaterial({\n\t\t\tcolor: color,\n\t\t\temissiveIntensity: 0.5,\n\t\t\tlightMapIntensity: 0.5,\n\t\t\tfog: true,\n\t\t});\n\n\t\tthis.materials.push(material);\n\t}\n\n\tsetShader(customShader: ZylemShaderObject) {\n\t\tconst { fragment, vertex } = customShader ?? standardShader;\n\n\t\tconst shader = new ShaderMaterial({\n\t\t\tuniforms: {\n\t\t\t\tiResolution: { value: new Vector3(1, 1, 1) },\n\t\t\t\tiTime: { value: 0 },\n\t\t\t\ttDiffuse: { value: null },\n\t\t\t\ttDepth: { value: null },\n\t\t\t\ttNormal: { value: null }\n\t\t\t},\n\t\t\tvertexShader: vertex,\n\t\t\tfragmentShader: fragment,\n\t\t\ttransparent: true,\n\t\t\t// blending: NormalBlending\n\t\t});\n\t\tthis.materials.push(shader);\n\t}\n}\n","import { ColliderDesc } from \"@dimforge/rapier3d-compat\";\nimport { GameEntity, GameEntityOptions } from \"./entity\";\nimport { BufferGeometry, Group, Material, Mesh, Color } from \"three\";\nimport { CollisionBuilder } from \"../collision/collision-builder\";\nimport { MeshBuilder } from \"../graphics/mesh\";\nimport { MaterialBuilder, MaterialOptions } from \"../graphics/material\";\nimport { Vec3 } from \"../core/vector\";\n\nexport abstract class EntityCollisionBuilder extends CollisionBuilder {\n\tabstract collider(options: GameEntityOptions): ColliderDesc;\n}\n\nexport abstract class EntityMeshBuilder extends MeshBuilder {\n\tbuild(options: GameEntityOptions): BufferGeometry {\n\t\treturn new BufferGeometry();\n\t}\n\n\tpostBuild(): void {\n\t\treturn;\n\t}\n}\n\nexport abstract class EntityBuilder<T extends GameEntity<U> & P, U extends GameEntityOptions, P = any> {\n\tprotected meshBuilder: EntityMeshBuilder | null;\n\tprotected collisionBuilder: EntityCollisionBuilder | null;\n\tprotected materialBuilder: MaterialBuilder | null;\n\tprotected options: Partial<U>;\n\tprotected entity: T;\n\n\tconstructor(\n\t\toptions: Partial<U>,\n\t\tentity: T,\n\t\tmeshBuilder: EntityMeshBuilder | null,\n\t\tcollisionBuilder: EntityCollisionBuilder | null,\n\t) {\n\t\tthis.options = options;\n\t\tthis.entity = entity;\n\t\tthis.meshBuilder = meshBuilder;\n\t\tthis.collisionBuilder = collisionBuilder;\n\t\tthis.materialBuilder = new MaterialBuilder();\n\t\tconst builders: NonNullable<GameEntityOptions[\"_builders\"]> = {\n\t\t\tmeshBuilder: this.meshBuilder,\n\t\t\tcollisionBuilder: this.collisionBuilder,\n\t\t\tmaterialBuilder: this.materialBuilder,\n\t\t};\n\t\t(this.options as Partial<GameEntityOptions>)._builders = builders;\n\t}\n\n\twithPosition(setupPosition: Vec3): this {\n\t\tthis.options.position = setupPosition;\n\t\treturn this;\n\t}\n\n\twithMaterial(options: Partial<MaterialOptions>, entityType: symbol): this {\n\t\tif (this.materialBuilder) {\n\t\t\tthis.materialBuilder.build(options, entityType);\n\t\t}\n\t\treturn this;\n\t}\n\n\tapplyMaterialToGroup(group: Group, materials: Material[]): void {\n\t\tgroup.traverse((child) => {\n\t\t\tif (child instanceof Mesh) {\n\t\t\t\tif (child.type === 'SkinnedMesh' && materials[0] && !child.material.map) {\n\t\t\t\t\tchild.material = materials[0];\n\t\t\t\t}\n\t\t\t}\n\t\t\tchild.castShadow = true;\n\t\t\tchild.receiveShadow = true;\n\t\t});\n\t}\n\n\tbuild(): T {\n\t\tconst entity = this.entity;\n\t\tif (this.materialBuilder) {\n\t\t\tentity.materials = this.materialBuilder.materials;\n\t\t}\n\t\tif (this.meshBuilder && entity.materials) {\n\t\t\tconst geometry = this.meshBuilder.build(this.options);\n\t\t\tentity.mesh = this.meshBuilder._build(this.options, geometry, entity.materials);\n\t\t\tthis.meshBuilder.postBuild();\n\t\t}\n\n\t\tif (entity.group && entity.materials) {\n\t\t\tthis.applyMaterialToGroup(entity.group, entity.materials);\n\t\t}\n\n\t\tif (this.collisionBuilder) {\n\t\t\tthis.collisionBuilder.withCollision(this.options?.collision || {});\n\t\t\tconst [bodyDesc, colliderDesc] = this.collisionBuilder.build(this.options as any);\n\t\t\tentity.bodyDesc = bodyDesc;\n\t\t\tentity.colliderDesc = colliderDesc;\n\n\t\t\tconst { x, y, z } = this.options.position || { x: 0, y: 0, z: 0 };\n\t\t\tentity.bodyDesc.setTranslation(x, y, z);\n\t\t}\n\t\tif (this.options.collisionType) {\n\t\t\tentity.collisionType = this.options.collisionType;\n\t\t}\n\n\t\tif (this.options.color instanceof Color) {\n\t\t\tconst applyColor = (material: Material) => {\n\t\t\t\tconst anyMat = material as any;\n\t\t\t\tif (anyMat && anyMat.color && anyMat.color.set) {\n\t\t\t\t\tanyMat.color.set(this.options.color as Color);\n\t\t\t\t}\n\t\t\t};\n\t\t\tif (entity.materials?.length) {\n\t\t\t\tfor (const mat of entity.materials) applyColor(mat);\n\t\t\t}\n\t\t\tif (entity.mesh && entity.mesh.material) {\n\t\t\t\tconst mat = entity.mesh.material as any;\n\t\t\t\tif (Array.isArray(mat)) mat.forEach(applyColor); else applyColor(mat);\n\t\t\t}\n\t\t\tif (entity.group) {\n\t\t\t\tentity.group.traverse((child) => {\n\t\t\t\t\tif (child instanceof Mesh && child.material) {\n\t\t\t\t\t\tconst mat = child.material as any;\n\t\t\t\t\t\tif (Array.isArray(mat)) mat.forEach(applyColor); else applyColor(mat);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn entity;\n\t}\n\n\tprotected abstract createEntity(options: Partial<U>): T;\n}","import { Color, Vector3 } from 'three';\nimport { standardShader } from '../graphics/shaders/standard.shader';\nimport { GameEntityOptions } from './entity';\n\nexport const commonDefaults: Partial<GameEntityOptions> = {\n position: new Vector3(0, 0, 0),\n material: {\n color: new Color('#ffffff'),\n shader: standardShader\n },\n collision: {\n static: false,\n },\n};\n","import { ActiveCollisionTypes, ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { BufferGeometry, Object3D, SkinnedMesh, Mesh, MeshStandardMaterial, Group, Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { createEntity } from './create';\nimport { UpdateContext, UpdateFunction } from '../core/base-node-life-cycle';\nimport { EntityAssetLoader } from '../core/entity-asset-loader';\nimport { EntityLoaderDelegate } from './delegates/loader';\nimport { Vec3 } from '../core/vector';\nimport { AnimationDelegate, AnimationOptions } from './delegates/animation';\nimport { MaterialOptions } from '../graphics/material';\nimport { DebugInfoProvider } from './delegates/debug';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { commonDefaults } from './common';\nimport { standardShader } from '~/api/main';\n\ntype AnimationObject = {\n\tkey?: string;\n\tpath: string;\n};\n\nexport type CollisionShapeType = 'capsule' | 'model';\n\ntype ZylemActorOptions = GameEntityOptions & {\n\tstatic?: boolean;\n\tanimations?: AnimationObject[];\n\tmodels?: string[];\n\tscale?: Vec3;\n\tmaterial?: MaterialOptions;\n\tcollisionShape?: CollisionShapeType;\n};\n\nconst actorDefaults: ZylemActorOptions = {\n\t...commonDefaults,\n\tcollision: {\n\t\tstatic: false,\n\t\tsize: new Vector3(0.5, 0.5, 0.5),\n\t\tposition: new Vector3(0, 0, 0),\n\t},\n\tmaterial: {\n\t\tshader: standardShader\n\t},\n\tanimations: [],\n\tmodels: [],\n\tcollisionShape: 'capsule',\n};\n\nclass ActorCollisionBuilder extends EntityCollisionBuilder {\n\tprivate objectModel: Group | null = null;\n\tprivate collisionShape: CollisionShapeType = 'capsule';\n\n\tconstructor(data: any) {\n\t\tsuper();\n\t\tthis.objectModel = data.objectModel;\n\t\tthis.collisionShape = data.collisionShape ?? 'capsule';\n\t}\n\n\tcollider(options: ZylemActorOptions): ColliderDesc {\n\t\tif (this.collisionShape === 'model') {\n\t\t\treturn this.createColliderFromModel(this.objectModel, options);\n\t\t}\n\t\treturn this.createCapsuleCollider(options);\n\t}\n\n\t/**\n\t * Create a capsule collider based on size options (character controller style).\n\t */\n\tprivate createCapsuleCollider(options: ZylemActorOptions): ColliderDesc {\n\t\tconst size = options.collision?.size ?? options.size ?? { x: 0.5, y: 1, z: 0.5 };\n\t\tconst halfHeight = ((size as any).y || 1);\n\t\tconst radius = Math.max((size as any).x || 0.5, (size as any).z || 0.5);\n\t\tlet colliderDesc = ColliderDesc.capsule(halfHeight, radius);\n\t\tcolliderDesc.setSensor(false);\n\t\tcolliderDesc.setTranslation(0, halfHeight + radius, 0);\n\t\tcolliderDesc.activeCollisionTypes = ActiveCollisionTypes.DEFAULT;\n\t\treturn colliderDesc;\n\t}\n\n\t/**\n\t * Create a collider based on model geometry (works with Mesh and SkinnedMesh).\n\t * If collision.size and collision.position are provided, use those instead of computing from geometry.\n\t */\n\tprivate createColliderFromModel(objectModel: Group | null, options: ZylemActorOptions): ColliderDesc {\n\t\tconst collisionSize = options.collision?.size;\n\t\tconst collisionPosition = options.collision?.position;\n\n\t\t// If user provided explicit size, use that instead of computing from model\n\t\tif (collisionSize) {\n\t\t\tconst halfWidth = (collisionSize as any).x / 2;\n\t\t\tconst halfHeight = (collisionSize as any).y / 2;\n\t\t\tconst halfDepth = (collisionSize as any).z / 2;\n\n\t\t\tlet colliderDesc = ColliderDesc.cuboid(halfWidth, halfHeight, halfDepth);\n\t\t\tcolliderDesc.setSensor(false);\n\n\t\t\t// Use user-provided position or default to center\n\t\t\tconst posX = collisionPosition ? (collisionPosition as any).x : 0;\n\t\t\tconst posY = collisionPosition ? (collisionPosition as any).y : halfHeight;\n\t\t\tconst posZ = collisionPosition ? (collisionPosition as any).z : 0;\n\t\t\tcolliderDesc.setTranslation(posX, posY, posZ);\n\t\t\tcolliderDesc.activeCollisionTypes = ActiveCollisionTypes.DEFAULT;\n\t\t\treturn colliderDesc;\n\t\t}\n\n\t\t// Fall back to computing from model geometry\n\t\tif (!objectModel) return this.createCapsuleCollider(options);\n\n\t\t// Find first Mesh (SkinnedMesh or regular Mesh)\n\t\tlet foundGeometry: BufferGeometry | null = null;\n\t\tobjectModel.traverse((child) => {\n\t\t\tif (!foundGeometry && (child as any).isMesh) {\n\t\t\t\tfoundGeometry = (child as Mesh).geometry as BufferGeometry;\n\t\t\t}\n\t\t});\n\n\t\tif (!foundGeometry) return this.createCapsuleCollider(options);\n\n\t\tconst geometry: BufferGeometry = foundGeometry;\n\t\tgeometry.computeBoundingBox();\n\t\tconst box = geometry.boundingBox;\n\t\tif (!box) return this.createCapsuleCollider(options);\n\n\t\tconst height = box.max.y - box.min.y;\n\t\tconst width = box.max.x - box.min.x;\n\t\tconst depth = box.max.z - box.min.z;\n\n\t\t// Create box collider based on mesh bounds\n\t\tlet colliderDesc = ColliderDesc.cuboid(width / 2, height / 2, depth / 2);\n\t\tcolliderDesc.setSensor(false);\n\t\t// Position collider at center of model\n\t\tconst centerY = (box.max.y + box.min.y) / 2;\n\t\tcolliderDesc.setTranslation(0, centerY, 0);\n\t\tcolliderDesc.activeCollisionTypes = ActiveCollisionTypes.DEFAULT;\n\t\treturn colliderDesc;\n\t}\n}\n\nclass ActorBuilder extends EntityBuilder<ZylemActor, ZylemActorOptions> {\n\tprotected createEntity(options: Partial<ZylemActorOptions>): ZylemActor {\n\t\treturn new ZylemActor(options);\n\t}\n}\n\nexport const ACTOR_TYPE = Symbol('Actor');\n\nexport class ZylemActor extends GameEntity<ZylemActorOptions> implements EntityLoaderDelegate, DebugInfoProvider {\n\tstatic type = ACTOR_TYPE;\n\n\tprivate _object: Object3D | null = null;\n\tprivate _animationDelegate: AnimationDelegate | null = null;\n\tprivate _modelFileNames: string[] = [];\n\tprivate _assetLoader: EntityAssetLoader = new EntityAssetLoader();\n\n\tcontrolledRotation: boolean = false;\n\n\tconstructor(options?: ZylemActorOptions) {\n\t\tsuper();\n\t\tthis.options = { ...actorDefaults, ...options };\n\t\t// Add actor-specific update to the lifecycle callbacks\n\t\tthis.prependUpdate(this.actorUpdate.bind(this) as UpdateFunction<this>);\n\t\tthis.controlledRotation = true;\n\t}\n\n\t/**\n\t * Initiates model and animation loading in background (deferred).\n\t * Call returns immediately; assets will be ready on subsequent updates.\n\t */\n\tload(): void {\n\t\tthis._modelFileNames = this.options.models || [];\n\t\t// Start async loading in background\n\t\tthis.loadModelsDeferred();\n\t}\n\n\t/**\n\t * Returns current data synchronously.\n\t * May return null values if loading is still in progress.\n\t */\n\tdata(): any {\n\t\treturn {\n\t\t\tanimations: this._animationDelegate?.animations,\n\t\t\tobjectModel: this._object,\n\t\t\tcollisionShape: this.options.collisionShape,\n\t\t};\n\t}\n\n\tactorUpdate(params: UpdateContext<ZylemActorOptions>): void {\n\t\tthis._animationDelegate?.update(params.delta);\n\t}\n\n\t/**\n\t * Clean up actor resources including animations, models, and groups\n\t */\n\tactorDestroy(): void {\n\t\t// Stop and dispose animation delegate\n\t\tif (this._animationDelegate) {\n\t\t\tthis._animationDelegate.dispose();\n\t\t\tthis._animationDelegate = null;\n\t\t}\n\n\t\t// Dispose geometries and materials from loaded object\n\t\tif (this._object) {\n\t\t\tthis._object.traverse((child) => {\n\t\t\t\tif ((child as any).isMesh) {\n\t\t\t\t\tconst mesh = child as SkinnedMesh;\n\t\t\t\t\tmesh.geometry?.dispose();\n\t\t\t\t\tif (Array.isArray(mesh.material)) {\n\t\t\t\t\t\tmesh.material.forEach(m => m.dispose());\n\t\t\t\t\t} else if (mesh.material) {\n\t\t\t\t\t\tmesh.material.dispose();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._object = null;\n\t\t}\n\n\t\t// Clear group reference\n\t\tif (this.group) {\n\t\t\tthis.group.clear();\n\t\t\tthis.group = null as any;\n\t\t}\n\n\t\t// Clear file name references\n\t\tthis._modelFileNames = [];\n\t}\n\n\t/**\n\t * Deferred loading - starts async load and updates entity when complete.\n\t * Called by synchronous load() method.\n\t */\n\tprivate loadModelsDeferred(): void {\n\t\tif (this._modelFileNames.length === 0) return;\n\n\t\t// Emit loading started event\n\t\tthis.dispatch('entity:model:loading', {\n\t\t\tentityId: this.uuid,\n\t\t\tfiles: this._modelFileNames\n\t\t});\n\n\t\tconst promises = this._modelFileNames.map(file => this._assetLoader.loadFile(file));\n\t\tPromise.all(promises).then(results => {\n\t\t\tif (results[0]?.object) {\n\t\t\t\tthis._object = results[0].object;\n\t\t\t}\n\t\t\t// Count meshes for the loaded event\n\t\t\tlet meshCount = 0;\n\t\t\tif (this._object) {\n\t\t\t\tthis._object.traverse((child) => {\n\t\t\t\t\tif ((child as any).isMesh) meshCount++;\n\t\t\t\t});\n\t\t\t\tthis.group = new Group();\n\t\t\t\tthis.group.attach(this._object);\n\t\t\t\tthis.group.scale.set(\n\t\t\t\t\tthis.options.scale?.x || 1,\n\t\t\t\t\tthis.options.scale?.y || 1,\n\t\t\t\t\tthis.options.scale?.z || 1\n\t\t\t\t);\n\n\t\t\t\t// Apply material overrides if specified\n\t\t\t\tthis.applyMaterialOverrides();\n\n\t\t\t\t// Load animations after model is ready\n\t\t\t\tthis._animationDelegate = new AnimationDelegate(this._object);\n\t\t\t\tthis._animationDelegate.loadAnimations(this.options.animations || []).then(() => {\n\t\t\t\t\tthis.dispatch('entity:animation:loaded', {\n\t\t\t\t\t\tentityId: this.uuid,\n\t\t\t\t\t\tanimationCount: this.options.animations?.length || 0\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t}\n\n\t\t\t// Emit model loaded event\n\t\t\tthis.dispatch('entity:model:loaded', {\n\t\t\t\tentityId: this.uuid,\n\t\t\t\tsuccess: !!this._object,\n\t\t\t\tmeshCount\n\t\t\t});\n\t\t});\n\t}\n\n\tplayAnimation(animationOptions: AnimationOptions) {\n\t\tthis._animationDelegate?.playAnimation(animationOptions);\n\t}\n\n\t/**\n\t * Apply material overrides from options to all meshes in the loaded model.\n\t * Only applies if material options are explicitly specified (not just defaults).\n\t */\n\tprivate applyMaterialOverrides(): void {\n\t\tconst materialOptions = this.options.material;\n\t\t// Only apply if user specified material options beyond defaults\n\t\tif (!materialOptions || (!materialOptions.color && !materialOptions.path)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this._object) return;\n\n\t\tthis._object.traverse((child) => {\n\t\t\tif ((child as any).isMesh) {\n\t\t\t\tconst mesh = child as Mesh;\n\t\t\t\tif (materialOptions.color) {\n\t\t\t\t\t// Create new material with the specified color\n\t\t\t\t\tconst newMaterial = new MeshStandardMaterial({\n\t\t\t\t\t\tcolor: materialOptions.color,\n\t\t\t\t\t\temissiveIntensity: 0.5,\n\t\t\t\t\t\tlightMapIntensity: 0.5,\n\t\t\t\t\t\tfog: true,\n\t\t\t\t\t});\n\t\t\t\t\tmesh.castShadow = true;\n\t\t\t\t\tmesh.receiveShadow = true;\n\t\t\t\t\tmesh.material = newMaterial;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tget object(): Object3D | null {\n\t\treturn this._object;\n\t}\n\n\t/**\n\t * Provide custom debug information for the actor\n\t * This will be merged with the default debug information\n\t */\n\tgetDebugInfo(): Record<string, any> {\n\t\tconst debugInfo: Record<string, any> = {\n\t\t\ttype: 'Actor',\n\t\t\tmodels: this._modelFileNames.length > 0 ? this._modelFileNames : 'none',\n\t\t\tmodelLoaded: !!this._object,\n\t\t\tscale: this.options.scale ?\n\t\t\t\t`${this.options.scale.x}, ${this.options.scale.y}, ${this.options.scale.z}` :\n\t\t\t\t'1, 1, 1',\n\t\t};\n\n\t\t// Add animation info if available\n\t\tif (this._animationDelegate) {\n\t\t\tdebugInfo.currentAnimation = this._animationDelegate.currentAnimationKey || 'none';\n\t\t\tdebugInfo.animationsCount = this.options.animations?.length || 0;\n\t\t}\n\n\t\t// Add mesh info if model is loaded\n\t\tif (this._object) {\n\t\t\tlet meshCount = 0;\n\t\t\tlet vertexCount = 0;\n\t\t\tthis._object.traverse((child) => {\n\t\t\t\tif ((child as any).isMesh) {\n\t\t\t\t\tmeshCount++;\n\t\t\t\t\tconst geometry = (child as SkinnedMesh).geometry;\n\t\t\t\t\tif (geometry && geometry.attributes.position) {\n\t\t\t\t\t\tvertexCount += geometry.attributes.position.count;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t\tdebugInfo.meshCount = meshCount;\n\t\t\tdebugInfo.vertexCount = vertexCount;\n\t\t}\n\n\t\treturn debugInfo;\n\t}\n}\n\ntype ActorOptions = BaseNode | ZylemActorOptions;\n\nexport function createActor(...args: Array<ActorOptions>): ZylemActor {\n\treturn createEntity<ZylemActor, ZylemActorOptions>({\n\t\targs,\n\t\tdefaultConfig: actorDefaults,\n\t\tEntityClass: ZylemActor,\n\t\tBuilderClass: ActorBuilder,\n\t\tCollisionBuilderClass: ActorCollisionBuilder,\n\t\tentityType: ZylemActor.type\n\t});\n}","import { Vector3 } from 'three';\nimport RAPIER, { World } from '@dimforge/rapier3d-compat';\n\nimport { Entity } from '../interfaces/entity';\nimport { state } from '../game/game-state';\nimport { UpdateContext } from '../core/base-node-life-cycle';\nimport { ZylemActor } from '../entities/actor';\nimport { GameEntity } from '../entities/entity';\n\n/**\n * Interface for entities that handle collision events.\n */\nexport interface CollisionHandlerDelegate {\n\thandlePostCollision(params: any): boolean;\n\thandleIntersectionEvent(params: any): void;\n}\n\n/**\n * Type guard to check if an object implements CollisionHandlerDelegate.\n */\nexport function isCollisionHandlerDelegate(obj: any): obj is CollisionHandlerDelegate {\n\treturn typeof obj?.handlePostCollision === \"function\" && typeof obj?.handleIntersectionEvent === \"function\";\n}\n\nexport class ZylemWorld implements Entity<ZylemWorld> {\n\ttype = 'World';\n\tworld: World;\n\tcollisionMap: Map<string, GameEntity<any>> = new Map();\n\tcollisionBehaviorMap: Map<string, GameEntity<any>> = new Map();\n\t_removalMap: Map<string, GameEntity<any>> = new Map();\n\n\tstatic async loadPhysics(gravity: Vector3) {\n\t\tawait RAPIER.init();\n\t\tconst physicsWorld = new RAPIER.World(gravity);\n\t\treturn physicsWorld;\n\t}\n\n\tconstructor(world: World) {\n\t\tthis.world = world;\n\t}\n\n\taddEntity(entity: any) {\n\t\tconst rigidBody = this.world.createRigidBody(entity.bodyDesc);\n\t\tentity.body = rigidBody;\n\t\t// TODO: consider passing in more specific data\n\t\tentity.body.userData = { uuid: entity.uuid, ref: entity };\n\t\tif (this.world.gravity.x === 0 && this.world.gravity.y === 0 && this.world.gravity.z === 0) {\n\t\t\tentity.body.lockTranslations(true, true);\n\t\t\tentity.body.lockRotations(true, true);\n\t\t}\n\t\tconst collider = this.world.createCollider(entity.colliderDesc, entity.body);\n\t\tentity.collider = collider;\n\t\tif (entity.controlledRotation || entity instanceof ZylemActor) {\n\t\t\tentity.body.lockRotations(true, true);\n\t\t\tentity.characterController = this.world.createCharacterController(0.01);\n\t\t\tentity.characterController.setMaxSlopeClimbAngle(45 * Math.PI / 180);\n\t\t\tentity.characterController.setMinSlopeSlideAngle(30 * Math.PI / 180);\n\t\t\tentity.characterController.enableSnapToGround(0.01);\n\t\t\tentity.characterController.setSlideEnabled(true);\n\t\t\tentity.characterController.setApplyImpulsesToDynamicBodies(true);\n\t\t\tentity.characterController.setCharacterMass(1);\n\t\t}\n\t\tthis.collisionMap.set(entity.uuid, entity);\n\t}\n\n\tsetForRemoval(entity: any) {\n\t\tif (entity.body) {\n\t\t\tthis._removalMap.set(entity.uuid, entity);\n\t\t}\n\t}\n\n\tdestroyEntity(entity: GameEntity<any>) {\n\t\tif (entity.collider) {\n\t\t\tthis.world.removeCollider(entity.collider, true);\n\t\t}\n\t\tif (entity.body) {\n\t\t\tthis.world.removeRigidBody(entity.body);\n\t\t\tthis.collisionMap.delete(entity.uuid);\n\t\t\tthis._removalMap.delete(entity.uuid);\n\t\t}\n\t}\n\n\tsetup() { }\n\n\tupdate(params: UpdateContext<any>) {\n\t\tconst { delta } = params;\n\t\tif (!this.world) {\n\t\t\treturn;\n\t\t}\n\t\tthis.updateColliders(delta);\n\t\tthis.updatePostCollisionBehaviors(delta);\n\t\tthis.world.step();\n\t}\n\n\tupdatePostCollisionBehaviors(delta: number) {\n\t\tconst dictionaryRef = this.collisionBehaviorMap;\n\t\tfor (let [id, collider] of dictionaryRef) {\n\t\t\tconst gameEntity = collider as any;\n\t\t\tif (!isCollisionHandlerDelegate(gameEntity)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst active = gameEntity.handlePostCollision({ entity: gameEntity, delta });\n\t\t\tif (!active) {\n\t\t\t\tthis.collisionBehaviorMap.delete(id);\n\t\t\t}\n\t\t}\n\t}\n\n\tupdateColliders(delta: number) {\n\t\tconst dictionaryRef = this.collisionMap;\n\t\tfor (let [id, collider] of dictionaryRef) {\n\t\t\tconst gameEntity = collider as GameEntity<any>;\n\t\t\tif (!gameEntity.body) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (this._removalMap.get(gameEntity.uuid)) {\n\t\t\t\tthis.destroyEntity(gameEntity);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.world.contactsWith(gameEntity.body.collider(0), (otherCollider) => {\n\t\t\t\tif (!otherCollider) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// @ts-ignore\n\t\t\t\tconst uuid = otherCollider._parent.userData.uuid;\n\t\t\t\tconst entity = dictionaryRef.get(uuid);\n\t\t\t\tif (!entity) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (gameEntity._collision) {\n\t\t\t\t\tgameEntity._collision(entity, state.globals);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.world.intersectionsWith(gameEntity.body.collider(0), (otherCollider) => {\n\t\t\t\tif (!otherCollider) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// @ts-ignore\n\t\t\t\tconst uuid = otherCollider._parent.userData.uuid;\n\t\t\t\tconst entity = dictionaryRef.get(uuid);\n\t\t\t\tif (!entity) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (gameEntity._collision) {\n\t\t\t\t\tgameEntity._collision(entity, state.globals);\n\t\t\t\t}\n\t\t\t\tif (isCollisionHandlerDelegate(entity)) {\n\t\t\t\t\tentity.handleIntersectionEvent({ entity, other: gameEntity, delta });\n\t\t\t\t\tthis.collisionBehaviorMap.set(uuid, entity);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tdestroy() {\n\t\ttry {\n\t\t\tfor (const [, entity] of this.collisionMap) {\n\t\t\t\ttry { this.destroyEntity(entity); } catch { /* noop */ }\n\t\t\t}\n\t\t\tthis.collisionMap.clear();\n\t\t\tthis.collisionBehaviorMap.clear();\n\t\t\tthis._removalMap.clear();\n\t\t\t// @ts-ignore\n\t\t\tthis.world = undefined as any;\n\t\t} catch { /* noop */ }\n\t}\n\n}","import {\n\tScene,\n\tColor,\n\tAmbientLight,\n\tDirectionalLight,\n\tObject3D,\n\tVector3,\n\tGridHelper,\n\tSphereGeometry,\n\tBoxGeometry,\n\tShaderMaterial,\n\tMesh,\n\tBackSide\n} from 'three';\nimport { Entity, LifecycleFunction } from '../interfaces/entity';\nimport { GameEntity } from '../entities/entity';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { debugState } from '../debug/debug-state';\nimport { SetupFunction } from '../core/base-node-life-cycle';\nimport { getGlobals } from '../game/game-state';\nimport { assetManager } from '../core/asset-manager';\nimport { ZylemShaderObject } from './material';\n\ninterface SceneState {\n\tbackgroundColor: Color | string;\n\tbackgroundImage: string | null;\n\tbackgroundShader?: ZylemShaderObject | null;\n}\n\nexport class ZylemScene implements Entity<ZylemScene> {\n\tpublic type = 'Scene';\n\n\t_setup?: SetupFunction<ZylemScene>;\n\tscene!: Scene;\n\tzylemCamera!: ZylemCamera;\n\tcontainerElement: HTMLElement | null = null;\n\tupdate: LifecycleFunction<ZylemScene> = () => { };\n\t_collision?: ((entity: any, other: any, globals?: any) => void) | undefined;\n\t_destroy?: ((globals?: any) => void) | undefined;\n\tname?: string | undefined;\n\ttag?: Set<string> | undefined;\n\n\t// Skybox for background shaders\n\tprivate skyboxMaterial: ShaderMaterial | null = null;\n\n\tconstructor(id: string, camera: ZylemCamera, state: SceneState) {\n\t\tconst scene = new Scene();\n\t\tconst isColor = state.backgroundColor instanceof Color;\n\t\tconst backgroundColor = (isColor) ? state.backgroundColor : new Color(state.backgroundColor);\n\t\tscene.background = backgroundColor as Color;\n\t\t\n\t\tconsole.log('ZylemScene state.backgroundShader:', state.backgroundShader);\n\t\t\n\t\tif (state.backgroundShader) {\n\t\t\tthis.setupBackgroundShader(scene, state.backgroundShader);\n\t\t} else if (state.backgroundImage) {\n\t\t\t// Load background image asynchronously via asset manager\n\t\t\tassetManager.loadTexture(state.backgroundImage).then(texture => {\n\t\t\t\tscene.background = texture;\n\t\t\t});\n\t\t}\n\n\t\tthis.scene = scene;\n\t\tthis.zylemCamera = camera;\n\n\t\tthis.setupLighting(scene);\n\t\tthis.setupCamera(scene, camera);\n\t\tif (debugState.enabled) {\n\t\t\tthis.debugScene();\n\t\t}\n\t}\n\n\t/**\n\t * Create a large inverted box with the shader for skybox effect\n\t * Uses the pos.xyww trick to ensure skybox is always at maximum depth\n\t */\n\tprivate setupBackgroundShader(scene: Scene, shader: ZylemShaderObject) {\n\t\t// Clear the solid color background\n\t\tscene.background = null;\n\n\t\t// Skybox vertex shader with depth trick (pos.xyww ensures depth = 1.0)\n\t\tconst skyboxVertexShader = `\n\t\t\tvarying vec2 vUv;\n\t\t\tvarying vec3 vWorldPosition;\n\t\t\t\n\t\t\tvoid main() {\n\t\t\t\tvUv = uv;\n\t\t\t\tvec4 worldPosition = modelMatrix * vec4(position, 1.0);\n\t\t\t\tvWorldPosition = worldPosition.xyz;\n\t\t\t\tvec4 pos = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n\t\t\t\tgl_Position = pos.xyww; // Ensures depth is always 1.0 (farthest)\n\t\t\t}\n\t\t`;\n\n\t\t// Create shader material with skybox-specific settings\n\t\tthis.skyboxMaterial = new ShaderMaterial({\n\t\t\tvertexShader: skyboxVertexShader,\n\t\t\tfragmentShader: shader.fragment,\n\t\t\tuniforms: {\n\t\t\t\tiTime: { value: 0.0 },\n\t\t\t},\n\t\t\tside: BackSide, // Render on inside of geometry\n\t\t\tdepthWrite: false, // Don't write to depth buffer\n\t\t\tdepthTest: true, // But do test depth\n\t\t});\n\n\t\t// Use BoxGeometry for skybox (like the CodePen example)\n\t\tconst geometry = new BoxGeometry(1, 1, 1);\n\t\tconst skybox = new Mesh(geometry, this.skyboxMaterial);\n\t\tskybox.scale.setScalar(100000); // Scale up significantly\n\t\tskybox.frustumCulled = false; // Always render\n\t\tscene.add(skybox);\n\t\t\n\t\tconsole.log('Skybox created with pos.xyww technique');\n\t}\n\n\tsetup() {\n\t\tif (this._setup) {\n\t\t\tthis._setup({ me: this, camera: this.zylemCamera, globals: getGlobals() });\n\t\t}\n\t}\n\n\tdestroy() {\n\t\tif (this.zylemCamera && (this.zylemCamera as any).destroy) {\n\t\t\t(this.zylemCamera as any).destroy();\n\t\t}\n\t\tif (this.skyboxMaterial) {\n\t\t\tthis.skyboxMaterial.dispose();\n\t\t}\n\t\tif (this.scene) {\n\t\t\tthis.scene.traverse((obj: any) => {\n\t\t\t\tif (obj.geometry) {\n\t\t\t\t\tobj.geometry.dispose?.();\n\t\t\t\t}\n\t\t\t\tif (obj.material) {\n\t\t\t\t\tif (Array.isArray(obj.material)) {\n\t\t\t\t\t\tobj.material.forEach((m: any) => m.dispose?.());\n\t\t\t\t\t} else {\n\t\t\t\t\t\tobj.material.dispose?.();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\t/**\n\t * Setup camera with the scene\n\t */\n\tsetupCamera(scene: Scene, camera: ZylemCamera) {\n\t\t// Add camera rig or camera directly to scene\n\t\tif (camera.cameraRig) {\n\t\t\tscene.add(camera.cameraRig);\n\t\t} else {\n\t\t\tscene.add(camera.camera as Object3D);\n\t\t}\n\t\t// Camera handles its own setup now\n\t\tcamera.setup(scene);\n\t}\n\n\t/**\n\t * Setup scene lighting\n\t */\n\tsetupLighting(scene: Scene) {\n\t\tconst ambientLight = new AmbientLight(0xffffff, 2);\n\t\tscene.add(ambientLight);\n\n\t\tconst directionalLight = new DirectionalLight(0xffffff, 2);\n\t\tdirectionalLight.name = 'Light';\n\t\tdirectionalLight.position.set(0, 100, 0);\n\t\tdirectionalLight.castShadow = true;\n\t\tdirectionalLight.shadow.camera.near = 0.1;\n\t\tdirectionalLight.shadow.camera.far = 2000;\n\t\tdirectionalLight.shadow.camera.left = -100;\n\t\tdirectionalLight.shadow.camera.right = 100;\n\t\tdirectionalLight.shadow.camera.top = 100;\n\t\tdirectionalLight.shadow.camera.bottom = -100;\n\t\tdirectionalLight.shadow.mapSize.width = 2048;\n\t\tdirectionalLight.shadow.mapSize.height = 2048;\n\t\tscene.add(directionalLight);\n\t}\n\n\t/**\n\t * Update renderer size - delegates to camera\n\t */\n\tupdateRenderer(width: number, height: number) {\n\t\tthis.zylemCamera.resize(width, height);\n\t}\n\n\t/**\n\t * Add object to scene\n\t */\n\tadd(object: Object3D, position: Vector3 = new Vector3(0, 0, 0)) {\n\t\tobject.position.set(position.x, position.y, position.z);\n\t\tthis.scene.add(object);\n\t}\n\n\t/**\n\t * Add game entity to scene\n\t */\n\taddEntity(entity: GameEntity<any>) {\n\t\tif (entity.group) {\n\t\t\tthis.add(entity.group, entity.options.position);\n\t\t} else if (entity.mesh) {\n\t\t\tthis.add(entity.mesh, entity.options.position);\n\t\t}\n\t}\n\n\t/**\n\t * Add an entity's group or mesh to the scene (for late-loaded models).\n\t * Uses entity's current body position if physics is active.\n\t */\n\taddEntityGroup(entity: GameEntity<any>): void {\n\t\tconst position = entity.body\n\t\t\t? new Vector3(\n\t\t\t\tentity.body.translation().x,\n\t\t\t\tentity.body.translation().y,\n\t\t\t\tentity.body.translation().z\n\t\t\t )\n\t\t\t: entity.options.position;\n\n\t\tif (entity.group) {\n\t\t\tthis.add(entity.group, position);\n\t\t} else if (entity.mesh) {\n\t\t\tthis.add(entity.mesh, position);\n\t\t}\n\t}\n\n\t/**\n\t * Add debug helpers to scene\n\t */\n\tdebugScene() {\n\t\tconst size = 1000;\n\t\tconst divisions = 100;\n\n\t\tconst gridHelper = new GridHelper(size, divisions);\n\t\tthis.scene.add(gridHelper);\n\t}\n\n\t/**\n\t * Update skybox shader uniforms\n\t */\n\tupdateSkybox(delta: number) {\n\t\tif (this.skyboxMaterial?.uniforms?.iTime) {\n\t\t\tthis.skyboxMaterial.uniforms.iTime.value += delta;\n\t\t}\n\t}\n}","import { Color, Vector3 as ThreeVector3 } from 'three';\nimport { Vector3 } from '@dimforge/rapier3d-compat';\n\n// TODO: needs implementations\n/**\n * @deprecated This type is deprecated.\n */\nexport type Vect3 = ThreeVector3 | Vector3;\n\nexport const ZylemBlueColor = new Color('#0333EC');\nexport const ZylemBlue = '#0333EC';\nexport const ZylemBlueTransparent = '#0333ECA0';\nexport const ZylemGoldText = '#DAA420';\n\nexport const Vec0 = new Vector3(0, 0, 0);\nexport const Vec1 = new Vector3(1, 1, 1);","import { Color, Vector3 } from 'three';\nimport { proxy, subscribe } from 'valtio/vanilla';\nimport { BaseEntityInterface, GameEntityInterface } from '../types/entity-types';\nimport { StageStateInterface } from '../types/stage-types';\nimport { getByPath, setByPath } from '../core/utility/path-utils';\nimport { ZylemBlueColor } from '../core/utility/vector';\n\n/**\n * Initial stage state with default values.\n * Exported for use in ZylemStage construction.\n */\nexport const initialStageState = {\n\tbackgroundColor: ZylemBlueColor,\n\tbackgroundImage: null,\n\tbackgroundShader: null,\n\tinputs: {\n\t\tp1: ['gamepad-1', 'keyboard'],\n\t\tp2: ['gamepad-2', 'keyboard'],\n\t},\n\tgravity: new Vector3(0, 0, 0),\n\tvariables: {},\n\tentities: [] as GameEntityInterface[],\n};\n\n/**\n * Stage state proxy for reactive updates.\n */\nconst stageState = proxy({\n\tbackgroundColor: new Color(Color.NAMES.cornflowerblue),\n\tbackgroundImage: null,\n\tinputs: {\n\t\tp1: ['gamepad-1', 'keyboard-1'],\n\t\tp2: ['gamepad-2', 'keyboard-2'],\n\t},\n\tvariables: {},\n\tgravity: new Vector3(0, 0, 0),\n\tentities: [],\n} as StageStateInterface);\n\n// ============================================================\n// Stage state setters (internal use)\n// ============================================================\n\nconst setStageBackgroundColor = (value: Color) => {\n\tstageState.backgroundColor = value;\n};\n\nconst setStageBackgroundImage = (value: string | null) => {\n\tstageState.backgroundImage = value;\n};\n\nconst setEntitiesToStage = (entities: Partial<BaseEntityInterface>[]) => {\n\tstageState.entities = entities;\n};\n\n/** Replace the entire stage variables object (used on stage load). */\nconst setStageVariables = (variables: Record<string, any>) => {\n\tstageState.variables = { ...variables };\n};\n\n/** Reset all stage variables (used on stage unload). */\nconst resetStageVariables = () => {\n\tstageState.variables = {};\n};\n\nconst stageStateToString = (state: StageStateInterface) => {\n\tlet string = `\\n`;\n\tfor (const key in state) {\n\t\tconst value = state[key as keyof StageStateInterface];\n\t\tstring += `${key}:\\n`;\n\t\tif (key === 'entities') {\n\t\t\tfor (const entity of state.entities) {\n\t\t\t\tstring += ` ${entity.uuid}: ${entity.name}\\n`;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === 'object' && value !== null) {\n\t\t\tfor (const subKey in value as Record<string, any>) {\n\t\t\t\tconst subValue = value?.[subKey as keyof typeof value];\n\t\t\t\tif (subValue) {\n\t\t\t\t\tstring += ` ${subKey}: ${subValue}\\n`;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (typeof value === 'string') {\n\t\t\tstring += ` ${key}: ${value}\\n`;\n\t\t}\n\t}\n\treturn string;\n};\n\n// ============================================================\n// Object-scoped variable storage (WeakMap-based)\n// ============================================================\n\n/**\n * WeakMap to store variables keyed by object reference.\n * Variables are automatically garbage collected when the target is collected.\n */\nconst variableStore = new WeakMap<object, Record<string, unknown>>();\n\n/**\n * Separate proxy store for reactivity. We need a regular Map for subscriptions\n * since WeakMap doesn't support iteration/subscriptions.\n */\nconst variableProxyStore = new Map<object, ReturnType<typeof proxy>>();\n\nfunction getOrCreateVariableProxy(target: object): Record<string, unknown> {\n\tlet store = variableProxyStore.get(target) as Record<string, unknown> | undefined;\n\tif (!store) {\n\t\tstore = proxy({});\n\t\tvariableProxyStore.set(target, store);\n\t}\n\treturn store;\n}\n\n/**\n * Set a variable on an object by path.\n * @example setVariable(stage1, 'totalAngle', 0.5)\n * @example setVariable(entity, 'enemy.count', 10)\n */\nexport function setVariable(target: object, path: string, value: unknown): void {\n\tconst store = getOrCreateVariableProxy(target);\n\tsetByPath(store, path, value);\n}\n\n/**\n * Create/initialize a variable with a default value on a target object.\n * Only sets the value if it doesn't already exist.\n * @example createVariable(stage1, 'totalAngle', 0)\n * @example createVariable(entity, 'enemy.count', 10)\n */\nexport function createVariable<T>(target: object, path: string, defaultValue: T): T {\n\tconst store = getOrCreateVariableProxy(target);\n\tconst existing = getByPath<T>(store, path);\n\tif (existing === undefined) {\n\t\tsetByPath(store, path, defaultValue);\n\t\treturn defaultValue;\n\t}\n\treturn existing;\n}\n\n/**\n * Get a variable from an object by path.\n * @example getVariable(stage1, 'totalAngle') // 0.5\n * @example getVariable<number>(entity, 'enemy.count') // 10\n */\nexport function getVariable<T = unknown>(target: object, path: string): T | undefined {\n\tconst store = variableProxyStore.get(target);\n\tif (!store) return undefined;\n\treturn getByPath<T>(store, path);\n}\n\n/**\n * Subscribe to changes on a variable at a specific path for a target object.\n * Returns an unsubscribe function.\n * @example const unsub = onVariableChange(stage1, 'score', (val) => console.log(val));\n */\nexport function onVariableChange<T = unknown>(\n\ttarget: object,\n\tpath: string,\n\tcallback: (value: T) => void\n): () => void {\n\tconst store = getOrCreateVariableProxy(target);\n\tlet previous = getByPath<T>(store, path);\n\treturn subscribe(store, () => {\n\t\tconst current = getByPath<T>(store, path);\n\t\tif (current !== previous) {\n\t\t\tprevious = current;\n\t\t\tcallback(current as T);\n\t\t}\n\t});\n}\n\n/**\n * Subscribe to changes on multiple variable paths for a target object.\n * Callback fires when any of the paths change, receiving all current values.\n * Returns an unsubscribe function.\n * @example const unsub = onVariableChanges(stage1, ['count', 'total'], ([count, total]) => console.log(count, total));\n */\nexport function onVariableChanges<T extends unknown[] = unknown[]>(\n\ttarget: object,\n\tpaths: string[],\n\tcallback: (values: T) => void\n): () => void {\n\tconst store = getOrCreateVariableProxy(target);\n\tlet previousValues = paths.map(p => getByPath(store, p));\n\treturn subscribe(store, () => {\n\t\tconst currentValues = paths.map(p => getByPath(store, p));\n\t\tconst hasChange = currentValues.some((val, i) => val !== previousValues[i]);\n\t\tif (hasChange) {\n\t\t\tpreviousValues = currentValues;\n\t\t\tcallback(currentValues as T);\n\t\t}\n\t});\n}\n\n/**\n * Clear all variables for a target object. Used on stage/entity dispose.\n */\nexport function clearVariables(target: object): void {\n\tvariableProxyStore.delete(target);\n}\n\n// ============================================================\n// Legacy stage variable functions (internal, for stage defaults)\n// ============================================================\n\nconst setStageVariable = (key: string, value: any) => {\n\tstageState.variables[key] = value;\n};\n\nconst getStageVariable = (key: string) => {\n\tif (stageState.variables.hasOwnProperty(key)) {\n\t\treturn stageState.variables[key];\n\t} else {\n\t\tconsole.warn(`Stage variable ${key} not found`);\n\t}\n};\n\nexport {\n\tstageState,\n\t\n\tsetStageBackgroundColor,\n\tsetStageBackgroundImage,\n\t\n\tstageStateToString,\n\tsetStageVariable,\n\tgetStageVariable,\n\tsetStageVariables,\n\tresetStageVariables,\n};","import { DestroyContext, DestroyFunction, SetupContext, SetupFunction, UpdateContext, UpdateFunction } from './base-node-life-cycle';\n\n/**\n * Provides BaseNode-like lifecycle without ECS/children. Consumers implement\n * the protected hooks and may assign public setup/update/destroy callbacks.\n */\nexport abstract class LifeCycleBase<TSelf> {\n\tupdate: UpdateFunction<TSelf> = () => { };\n\tsetup: SetupFunction<TSelf> = () => { };\n\tdestroy: DestroyFunction<TSelf> = () => { };\n\n\tprotected abstract _setup(context: SetupContext<TSelf>): void;\n\tprotected abstract _update(context: UpdateContext<TSelf>): void;\n\tprotected abstract _destroy(context: DestroyContext<TSelf>): void;\n\n\tnodeSetup(context: SetupContext<TSelf>) {\n\t\tif (typeof (this as any)._setup === 'function') {\n\t\t\tthis._setup(context);\n\t\t}\n\t\tif (this.setup) {\n\t\t\tthis.setup(context);\n\t\t}\n\t}\n\n\tnodeUpdate(context: UpdateContext<TSelf>) {\n\t\tif (typeof (this as any)._update === 'function') {\n\t\t\tthis._update(context);\n\t\t}\n\t\tif (this.update) {\n\t\t\tthis.update(context);\n\t\t}\n\t}\n\n\tnodeDestroy(context: DestroyContext<TSelf>) {\n\t\tif (this.destroy) {\n\t\t\tthis.destroy(context);\n\t\t}\n\t\tif (typeof (this as any)._destroy === 'function') {\n\t\t\tthis._destroy(context);\n\t\t}\n\t}\n}\n\n\n","import {\n\tBox3,\n\tBoxGeometry,\n\tColor,\n\tEdgesGeometry,\n\tGroup,\n\tLineBasicMaterial,\n\tLineSegments,\n\tMesh,\n\tMeshBasicMaterial,\n\tObject3D,\n\tScene,\n\tVector3,\n} from 'three';\n\n/**\n * Debug overlay that displays an axis-aligned bounding box around a target Object3D.\n * Shows a semi-transparent fill plus a wireframe outline. Intended for SELECT/DELETE tools.\n */\nexport class DebugEntityCursor {\n\tprivate scene: Scene;\n\tprivate container: Group;\n\tprivate fillMesh: Mesh;\n\tprivate edgeLines: LineSegments;\n\tprivate currentColor: Color = new Color(0x00ff00);\n\tprivate bbox: Box3 = new Box3();\n\tprivate size: Vector3 = new Vector3();\n\tprivate center: Vector3 = new Vector3();\n\n\tconstructor(scene: Scene) {\n\t\tthis.scene = scene;\n\n\t\tconst initialGeometry = new BoxGeometry(1, 1, 1);\n\n\t\tthis.fillMesh = new Mesh(\n\t\t\tinitialGeometry,\n\t\t\tnew MeshBasicMaterial({\n\t\t\t\tcolor: this.currentColor,\n\t\t\t\ttransparent: true,\n\t\t\t\topacity: 0.12,\n\t\t\t\tdepthWrite: false,\n\t\t\t})\n\t\t);\n\n\t\tconst edges = new EdgesGeometry(initialGeometry);\n\t\tthis.edgeLines = new LineSegments(\n\t\t\tedges,\n\t\t\tnew LineBasicMaterial({ color: this.currentColor, linewidth: 1 })\n\t\t);\n\n\t\tthis.container = new Group();\n\t\tthis.container.name = 'DebugEntityCursor';\n\t\tthis.container.add(this.fillMesh);\n\t\tthis.container.add(this.edgeLines);\n\t\tthis.container.visible = false;\n\n\t\tthis.scene.add(this.container);\n\t}\n\n\tsetColor(color: Color | number): void {\n\t\tthis.currentColor.set(color as any);\n\t\t(this.fillMesh.material as MeshBasicMaterial).color.set(this.currentColor);\n\t\t(this.edgeLines.material as LineBasicMaterial).color.set(this.currentColor);\n\t}\n\n\t/**\n\t * Update the cursor to enclose the provided Object3D using a world-space AABB.\n\t */\n\tupdateFromObject(object: Object3D | null | undefined): void {\n\t\tif (!object) {\n\t\t\tthis.hide();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.bbox.setFromObject(object);\n\t\tif (!isFinite(this.bbox.min.x) || !isFinite(this.bbox.max.x)) {\n\t\t\tthis.hide();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.bbox.getSize(this.size);\n\t\tthis.bbox.getCenter(this.center);\n\n\t\tconst newGeom = new BoxGeometry(\n\t\t\tMath.max(this.size.x, 1e-6),\n\t\t\tMath.max(this.size.y, 1e-6),\n\t\t\tMath.max(this.size.z, 1e-6)\n\t\t);\n\t\tthis.fillMesh.geometry.dispose();\n\t\tthis.fillMesh.geometry = newGeom;\n\n\t\tconst newEdges = new EdgesGeometry(newGeom);\n\t\tthis.edgeLines.geometry.dispose();\n\t\tthis.edgeLines.geometry = newEdges;\n\n\t\tthis.container.position.copy(this.center);\n\t\tthis.container.visible = true;\n\t}\n\n\thide(): void {\n\t\tthis.container.visible = false;\n\t}\n\n\tdispose(): void {\n\t\tthis.scene.remove(this.container);\n\t\tthis.fillMesh.geometry.dispose();\n\t\t(this.fillMesh.material as MeshBasicMaterial).dispose();\n\t\tthis.edgeLines.geometry.dispose();\n\t\t(this.edgeLines.material as LineBasicMaterial).dispose();\n\t}\n}\n\n\n","import { Ray, RayColliderToi } from '@dimforge/rapier3d-compat';\nimport { BufferAttribute, BufferGeometry, LineBasicMaterial, LineSegments, Raycaster, Vector2, Vector3 } from 'three';\nimport { ZylemStage } from './zylem-stage';\nimport { debugState, DebugTools, getDebugTool, getHoveredEntity, resetHoveredEntity, setHoveredEntity, setSelectedEntity } from '../debug/debug-state';\nimport { DebugEntityCursor } from './debug-entity-cursor';\n\nexport type AddEntityFactory = (params: { position: Vector3; normal?: Vector3 }) => Promise<any> | any;\n\nexport interface StageDebugDelegateOptions {\n\tmaxRayDistance?: number;\n\taddEntityFactory?: AddEntityFactory | null;\n}\n\nconst SELECT_TOOL_COLOR = 0x22ff22;\nconst DELETE_TOOL_COLOR = 0xff3333;\n\nexport class StageDebugDelegate {\n\tprivate stage: ZylemStage;\n\tprivate options: Required<StageDebugDelegateOptions>;\n\tprivate mouseNdc: Vector2 = new Vector2(-2, -2);\n\tprivate raycaster: Raycaster = new Raycaster();\n\tprivate isMouseDown = false;\n\tprivate disposeFns: Array<() => void> = [];\n\tprivate debugCursor: DebugEntityCursor | null = null;\n\tprivate debugLines: LineSegments | null = null;\n\n\tconstructor(stage: ZylemStage, options?: StageDebugDelegateOptions) {\n\t\tthis.stage = stage;\n\t\tthis.options = {\n\t\t\tmaxRayDistance: options?.maxRayDistance ?? 5_000,\n\t\t\taddEntityFactory: options?.addEntityFactory ?? null,\n\t\t};\n\t\tthis.attachDomListeners();\n\t}\n\n\tprivate initDebugVisuals(): void {\n\t\tif (this.debugLines || !this.stage.scene) return;\n\n\t\tthis.debugLines = new LineSegments(\n\t\t\tnew BufferGeometry(),\n\t\t\tnew LineBasicMaterial({ vertexColors: true })\n\t\t);\n\t\tthis.stage.scene.scene.add(this.debugLines);\n\t\tthis.debugLines.visible = true;\n\n\t\tthis.debugCursor = new DebugEntityCursor(this.stage.scene.scene);\n\t}\n\n\tprivate disposeDebugVisuals(): void {\n\t\tif (this.debugLines && this.stage.scene) {\n\t\t\tthis.stage.scene.scene.remove(this.debugLines);\n\t\t\tthis.debugLines.geometry.dispose();\n\t\t\t(this.debugLines.material as LineBasicMaterial).dispose();\n\t\t\tthis.debugLines = null;\n\t\t}\n\t\tthis.debugCursor?.dispose();\n\t\tthis.debugCursor = null;\n\t}\n\n\tupdate(): void {\n\t\tif (!debugState.enabled) {\n\t\t\tif (this.debugLines) {\n\t\t\t\tthis.disposeDebugVisuals();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (!this.stage.scene || !this.stage.world || !this.stage.cameraRef) return;\n\n\t\t// Initialize visuals if not already created\n\t\tif (!this.debugLines) {\n\t\t\tthis.initDebugVisuals();\n\t\t}\n\n\t\tconst { world, cameraRef } = this.stage;\n\n\t\tif (this.debugLines) {\n\t\t\tconst { vertices, colors } = world.world.debugRender();\n\t\t\tthis.debugLines.geometry.setAttribute('position', new BufferAttribute(vertices, 3));\n\t\t\tthis.debugLines.geometry.setAttribute('color', new BufferAttribute(colors, 4));\n\t\t}\n\t\tconst tool = getDebugTool();\n\t\tconst isCursorTool = tool === 'select' || tool === 'delete';\n\n\t\tthis.raycaster.setFromCamera(this.mouseNdc, cameraRef.camera);\n\t\tconst origin = this.raycaster.ray.origin.clone();\n\t\tconst direction = this.raycaster.ray.direction.clone().normalize();\n\n\t\tconst rapierRay = new Ray(\n\t\t\t{ x: origin.x, y: origin.y, z: origin.z },\n\t\t\t{ x: direction.x, y: direction.y, z: direction.z },\n\t\t);\n\t\tconst hit: RayColliderToi | null = world.world.castRay(rapierRay, this.options.maxRayDistance, true);\n\n\t\tif (hit && isCursorTool) {\n\t\t\t// @ts-ignore - access compat object's parent userData mapping back to GameEntity\n\t\t\tconst rigidBody = hit.collider?._parent;\n\t\t\tconst hoveredUuid: string | undefined = rigidBody?.userData?.uuid;\n\t\t\tif (hoveredUuid) {\n\t\t\t\tconst entity = this.stage._debugMap.get(hoveredUuid);\n\t\t\t\tif (entity) setHoveredEntity(entity as any);\n\t\t\t} else {\n\t\t\t\tresetHoveredEntity();\n\t\t\t}\n\n\t\t\tif (this.isMouseDown) {\n\t\t\t\tthis.handleActionOnHit(hoveredUuid ?? null, origin, direction, hit.toi);\n\t\t\t}\n\t\t}\n\t\tthis.isMouseDown = false;\n\n\t\tconst hoveredUuid = getHoveredEntity();\n\t\tif (!hoveredUuid) {\n\t\t\tthis.debugCursor?.hide();\n\t\t\treturn;\n\t\t}\n\t\tconst hoveredEntity: any = this.stage._debugMap.get(`${hoveredUuid}`);\n\t\tconst targetObject = hoveredEntity?.group ?? hoveredEntity?.mesh ?? null;\n\t\tif (!targetObject) {\n\t\t\tthis.debugCursor?.hide();\n\t\t\treturn;\n\t\t}\n\t\tswitch (tool) {\n\t\t\tcase 'select':\n\t\t\t\tthis.debugCursor?.setColor(SELECT_TOOL_COLOR);\n\t\t\t\tbreak;\n\t\t\tcase 'delete':\n\t\t\t\tthis.debugCursor?.setColor(DELETE_TOOL_COLOR);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.debugCursor?.setColor(0xffffff);\n\t\t\t\tbreak;\n\t\t}\n\t\tthis.debugCursor?.updateFromObject(targetObject);\n\t}\n\n\tdispose(): void {\n\t\tthis.disposeFns.forEach((fn) => fn());\n\t\tthis.disposeFns = [];\n\t\tthis.disposeDebugVisuals();\n\t}\n\n\tprivate handleActionOnHit(hoveredUuid: string | null, origin: Vector3, direction: Vector3, toi: number) {\n\t\tconst tool = getDebugTool();\n\t\tswitch (tool) {\n\t\t\tcase 'select': {\n\t\t\t\tif (hoveredUuid) {\n\t\t\t\t\tconst entity = this.stage._debugMap.get(hoveredUuid);\n\t\t\t\t\tif (entity) setSelectedEntity(entity as any);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'delete': {\n\t\t\t\tif (hoveredUuid) {\n\t\t\t\t\tthis.stage.removeEntityByUuid(hoveredUuid);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'scale': {\n\t\t\t\tif (!this.options.addEntityFactory) break;\n\t\t\t\tconst hitPosition = origin.clone().add(direction.clone().multiplyScalar(toi));\n\t\t\t\tconst newNode = this.options.addEntityFactory({ position: hitPosition });\n\t\t\t\tif (newNode) {\n\t\t\t\t\tPromise.resolve(newNode).then((node) => {\n\t\t\t\t\t\tif (node) this.stage.spawnEntity(node);\n\t\t\t\t\t}).catch(() => { });\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate attachDomListeners() {\n\t\tconst canvas = this.stage.cameraRef?.renderer.domElement ?? this.stage.scene?.zylemCamera.renderer.domElement;\n\t\tif (!canvas) return;\n\n\t\tconst onMouseMove = (e: MouseEvent) => {\n\t\t\tconst rect = canvas.getBoundingClientRect();\n\t\t\tconst x = ((e.clientX - rect.left) / rect.width) * 2 - 1;\n\t\t\tconst y = -(((e.clientY - rect.top) / rect.height) * 2 - 1);\n\t\t\tthis.mouseNdc.set(x, y);\n\t\t};\n\n\t\tconst onMouseDown = (e: MouseEvent) => {\n\t\t\tthis.isMouseDown = true;\n\t\t};\n\n\t\tcanvas.addEventListener('mousemove', onMouseMove);\n\t\tcanvas.addEventListener('mousedown', onMouseDown);\n\n\t\tthis.disposeFns.push(() => canvas.removeEventListener('mousemove', onMouseMove));\n\t\tthis.disposeFns.push(() => canvas.removeEventListener('mousedown', onMouseDown));\n\t}\n}\n\n\n","import { Object3D } from 'three';\nimport { subscribe } from 'valtio/vanilla';\n\nimport type { CameraDebugDelegate, CameraDebugState } from '../camera/zylem-camera';\nimport { debugState } from '../debug/debug-state';\nimport type { ZylemStage } from './zylem-stage';\n\nconst cloneSelected = (selected: string[]): string[] => [...selected];\n\n/**\n * Debug delegate that bridges the stage's entity map and debug state to the camera.\n */\nexport class StageCameraDebugDelegate implements CameraDebugDelegate {\n\tprivate stage: ZylemStage;\n\n\tconstructor(stage: ZylemStage) {\n\t\tthis.stage = stage;\n\t}\n\n\tsubscribe(listener: (state: CameraDebugState) => void): () => void {\n\t\tconst notify = () => listener(this.snapshot());\n\t\tnotify();\n\t\treturn subscribe(debugState, notify);\n\t}\n\n\tresolveTarget(uuid: string): Object3D | null {\n\t\tconst entity: any = this.stage._debugMap.get(uuid)\n\t\t\t|| this.stage.world?.collisionMap.get(uuid)\n\t\t\t|| null;\n\t\tconst target = entity?.group ?? entity?.mesh ?? null;\n\t\treturn target ?? null;\n\t}\n\n\tprivate snapshot(): CameraDebugState {\n\t\treturn {\n\t\t\tenabled: debugState.enabled,\n\t\t\tselected: debugState.selectedEntity ? [debugState.selectedEntity.uuid] : [],\n\t\t};\n\t}\n}\n\n","export const Perspectives = {\n\tFirstPerson: 'first-person',\n\tThirdPerson: 'third-person',\n\tIsometric: 'isometric',\n\tFlat2D: 'flat-2d',\n\tFixed2D: 'fixed-2d',\n} as const;\n\nexport type PerspectiveType = (typeof Perspectives)[keyof typeof Perspectives];","import { Scene, Vector2, Vector3, WebGLRenderer } from 'three';\nimport { PerspectiveController, ZylemCamera } from './zylem-camera';\nimport { StageEntity } from '../interfaces/entity';\n\ninterface ThirdPersonCameraOptions {\n\ttarget: StageEntity;\n\tdistance: Vector3;\n\tscreenResolution: Vector2;\n\trenderer: WebGLRenderer;\n\tscene: Scene;\n}\n\nexport class ThirdPersonCamera implements PerspectiveController {\n\tdistance: Vector3;\n\tscreenResolution: Vector2 | null = null;\n\trenderer: WebGLRenderer | null = null;\n\tscene: Scene | null = null;\n\tcameraRef: ZylemCamera | null = null;\n\n\tconstructor() {\n\t\tthis.distance = new Vector3(0, 5, 8);\n\t}\n\n\t/**\n\t * Setup the third person camera controller\n\t */\n\tsetup(params: { screenResolution: Vector2; renderer: WebGLRenderer; scene: Scene; camera: ZylemCamera }) {\n\t\tconst { screenResolution, renderer, scene, camera } = params;\n\t\tthis.screenResolution = screenResolution;\n\t\tthis.renderer = renderer;\n\t\tthis.scene = scene;\n\t\tthis.cameraRef = camera;\n\t}\n\n\t/**\n\t * Update the third person camera\n\t */\n\tupdate(delta: number) {\n\t\tif (!this.cameraRef!.target) {\n\t\t\treturn;\n\t\t}\n\t\t// TODO: Implement third person camera following logic\n\t\tconst desiredCameraPosition = this.cameraRef!.target!.group.position.clone().add(this.distance);\n\t\tthis.cameraRef!.camera.position.lerp(desiredCameraPosition, 0.1);\n\t\tthis.cameraRef!.camera.lookAt(this.cameraRef!.target!.group.position);\n\t}\n\n\t/**\n\t * Handle resize events\n\t */\n\tresize(width: number, height: number) {\n\t\tif (this.screenResolution) {\n\t\t\tthis.screenResolution.set(width, height);\n\t\t}\n\t\t// TODO: Handle any third-person specific resize logic\n\t}\n\n\t/**\n\t * Set the distance from the target\n\t */\n\tsetDistance(distance: Vector3) {\n\t\tthis.distance = distance;\n\t}\n}","import { Scene, Vector2, WebGLRenderer } from 'three';\nimport { PerspectiveController, ZylemCamera } from './zylem-camera';\n\n/**\n * Fixed 2D Camera Controller\n * Maintains a static 2D camera view with no automatic following or movement\n */\nexport class Fixed2DCamera implements PerspectiveController {\n\tscreenResolution: Vector2 | null = null;\n\trenderer: WebGLRenderer | null = null;\n\tscene: Scene | null = null;\n\tcameraRef: ZylemCamera | null = null;\n\n\tconstructor() {\n\t\t// Fixed 2D camera doesn't need any initial setup parameters\n\t}\n\n\t/**\n\t * Setup the fixed 2D camera controller\n\t */\n\tsetup(params: { screenResolution: Vector2; renderer: WebGLRenderer; scene: Scene; camera: ZylemCamera }) {\n\t\tconst { screenResolution, renderer, scene, camera } = params;\n\t\tthis.screenResolution = screenResolution;\n\t\tthis.renderer = renderer;\n\t\tthis.scene = scene;\n\t\tthis.cameraRef = camera;\n\n\t\t// Position camera for 2D view (looking down the Z-axis)\n\t\tthis.cameraRef.camera.position.set(0, 0, 10);\n\t\tthis.cameraRef.camera.lookAt(0, 0, 0);\n\t}\n\n\t/**\n\t * Update the fixed 2D camera\n\t * Fixed cameras don't need to update position/rotation automatically\n\t */\n\tupdate(delta: number) {\n\t\t// Fixed 2D camera maintains its position and orientation\n\t\t// No automatic updates needed for a truly fixed camera\n\t}\n\n\t/**\n\t * Handle resize events for 2D camera\n\t */\n\tresize(width: number, height: number) {\n\t\tif (this.screenResolution) {\n\t\t\tthis.screenResolution.set(width, height);\n\t\t}\n\n\t\t// For orthographic cameras, we might need to adjust the frustum\n\t\t// This is handled in the main ZylemCamera resize method\n\t}\n}\n","import * as THREE from 'three';\nimport { standardShader } from './shaders/standard.shader';\nimport { WebGLRenderer, WebGLRenderTarget } from 'three';\nimport { Pass, FullScreenQuad } from 'three/addons/postprocessing/Pass.js';\n\nexport default class RenderPass extends Pass {\n\tfsQuad: FullScreenQuad;\n\tresolution: THREE.Vector2;\n\tscene: THREE.Scene;\n\tcamera: THREE.Camera;\n\trgbRenderTarget: WebGLRenderTarget;\n\tnormalRenderTarget: WebGLRenderTarget;\n\tnormalMaterial: THREE.Material;\n\n\tconstructor(resolution: THREE.Vector2, scene: THREE.Scene, camera: THREE.Camera) {\n\t\tsuper();\n\t\tthis.resolution = resolution;\n\t\tthis.fsQuad = new FullScreenQuad(this.material());\n\t\tthis.scene = scene;\n\t\tthis.camera = camera;\n\n\t\tthis.rgbRenderTarget = new WebGLRenderTarget(resolution.x * 4, resolution.y * 4);\n\t\tthis.normalRenderTarget = new WebGLRenderTarget(resolution.x * 4, resolution.y * 4);\n\n\t\tthis.normalMaterial = new THREE.MeshNormalMaterial();\n\t}\n\n\trender(\n\t\trenderer: WebGLRenderer,\n\t\twriteBuffer: WebGLRenderTarget\n\t) {\n\t\trenderer.setRenderTarget(this.rgbRenderTarget);\n\t\trenderer.render(this.scene, this.camera);\n\n\t\tconst overrideMaterial_old = this.scene.overrideMaterial;\n\t\trenderer.setRenderTarget(this.normalRenderTarget);\n\t\tthis.scene.overrideMaterial = this.normalMaterial;\n\t\trenderer.render(this.scene, this.camera);\n\t\tthis.scene.overrideMaterial = overrideMaterial_old;\n\n\t\t// @ts-ignore\n\t\tconst uniforms = this.fsQuad.material.uniforms;\n\t\tuniforms.tDiffuse.value = this.rgbRenderTarget.texture;\n\t\tuniforms.tDepth.value = this.rgbRenderTarget.depthTexture;\n\t\tuniforms.tNormal.value = this.normalRenderTarget.texture;\n\t\tuniforms.iTime.value += 0.01;\n\n\t\tif (this.renderToScreen) {\n\t\t\trenderer.setRenderTarget(null);\n\t\t} else {\n\t\t\trenderer.setRenderTarget(writeBuffer);\n\t\t}\n\t\tthis.fsQuad.render(renderer);\n\t}\n\n\tmaterial() {\n\t\treturn new THREE.ShaderMaterial({\n\t\t\tuniforms: {\n\t\t\t\tiTime: { value: 0 },\n\t\t\t\ttDiffuse: { value: null },\n\t\t\t\ttDepth: { value: null },\n\t\t\t\ttNormal: { value: null },\n\t\t\t\tresolution: {\n\t\t\t\t\tvalue: new THREE.Vector4(\n\t\t\t\t\t\tthis.resolution.x,\n\t\t\t\t\t\tthis.resolution.y,\n\t\t\t\t\t\t1 / this.resolution.x,\n\t\t\t\t\t\t1 / this.resolution.y,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t\tvertexShader: standardShader.vertex,\n\t\t\tfragmentShader: standardShader.fragment\n\t\t});\n\t}\n\n\tdispose() {\n\t\ttry {\n\t\t\tthis.fsQuad?.dispose?.();\n\t\t} catch { /* noop */ }\n\t\ttry {\n\t\t\t(this.rgbRenderTarget as any)?.dispose?.();\n\t\t\t(this.normalRenderTarget as any)?.dispose?.();\n\t\t} catch { /* noop */ }\n\t\ttry {\n\t\t\t(this.normalMaterial as any)?.dispose?.();\n\t\t} catch { /* noop */ }\n\t}\n}\n","import { Object3D, Vector3, Quaternion, Camera, Scene } from 'three';\nimport { OrbitControls } from 'three/addons/controls/OrbitControls.js';\n\nexport interface CameraDebugState {\n\tenabled: boolean;\n\tselected: string[];\n}\n\nexport interface CameraDebugDelegate {\n\tsubscribe(listener: (state: CameraDebugState) => void): () => void;\n\tresolveTarget(uuid: string): Object3D | null;\n}\n\n/**\n * Manages orbit controls and debug state for a camera.\n * Orbit controls are only active when debug mode is enabled.\n */\nexport class CameraOrbitController {\n\tprivate camera: Camera;\n\tprivate domElement: HTMLElement;\n\tprivate cameraRig: Object3D | null = null;\n\tprivate sceneRef: Scene | null = null;\n\t\n\tprivate orbitControls: OrbitControls | null = null;\n\tprivate orbitTarget: Object3D | null = null;\n\tprivate orbitTargetWorldPos: Vector3 = new Vector3();\n\n\tprivate debugDelegate: CameraDebugDelegate | null = null;\n\tprivate debugUnsubscribe: (() => void) | null = null;\n\tprivate debugStateSnapshot: CameraDebugState = { enabled: false, selected: [] };\n\n\t// Saved camera state for restoration when exiting debug mode\n\tprivate savedCameraPosition: Vector3 | null = null;\n\tprivate savedCameraQuaternion: Quaternion | null = null;\n\tprivate savedCameraZoom: number | null = null;\n\tprivate savedCameraLocalPosition: Vector3 | null = null;\n\n\t// Saved debug camera state for restoration when re-entering debug mode\n\tprivate savedDebugCameraPosition: Vector3 | null = null;\n\tprivate savedDebugCameraQuaternion: Quaternion | null = null;\n\tprivate savedDebugCameraZoom: number | null = null;\n\tprivate savedDebugOrbitTarget: Vector3 | null = null;\n\n\tconstructor(camera: Camera, domElement: HTMLElement, cameraRig?: Object3D | null) {\n\t\tthis.camera = camera;\n\t\tthis.domElement = domElement;\n\t\tthis.cameraRig = cameraRig ?? null;\n\t}\n\n\t/**\n\t * Set the scene reference for adding/removing camera when detaching from rig.\n\t */\n\tsetScene(scene: Scene | null): void {\n\t\tthis.sceneRef = scene;\n\t}\n\n\t/**\n\t * Check if debug mode is currently active (orbit controls enabled).\n\t */\n\tget isActive(): boolean {\n\t\treturn this.debugStateSnapshot.enabled;\n\t}\n\n\t/**\n\t * Update orbit controls each frame.\n\t * Should be called from the camera's update loop.\n\t */\n\tupdate() {\n\t\tif (this.orbitControls && this.orbitTarget) {\n\t\t\tthis.orbitTarget.getWorldPosition(this.orbitTargetWorldPos);\n\t\t\tthis.orbitControls.target.copy(this.orbitTargetWorldPos);\n\t\t}\n\t\tthis.orbitControls?.update();\n\t}\n\n\t/**\n\t * Attach a delegate to react to debug state changes.\n\t */\n\tsetDebugDelegate(delegate: CameraDebugDelegate | null) {\n\t\tif (this.debugDelegate === delegate) {\n\t\t\treturn;\n\t\t}\n\t\tthis.detachDebugDelegate();\n\t\tthis.debugDelegate = delegate;\n\t\tif (!delegate) {\n\t\t\tthis.applyDebugState({ enabled: false, selected: [] });\n\t\t\treturn;\n\t\t}\n\t\tconst unsubscribe = delegate.subscribe((state) => {\n\t\t\tthis.applyDebugState(state);\n\t\t});\n\t\tthis.debugUnsubscribe = () => {\n\t\t\tunsubscribe?.();\n\t\t};\n\t}\n\n\t/**\n\t * Clean up resources.\n\t */\n\tdispose() {\n\t\tthis.disableOrbitControls();\n\t\tthis.detachDebugDelegate();\n\t}\n\n\t/**\n\t * Get the current debug state snapshot.\n\t */\n\tget debugState(): CameraDebugState {\n\t\treturn this.debugStateSnapshot;\n\t}\n\n\tprivate applyDebugState(state: CameraDebugState) {\n\t\tconst wasEnabled = this.debugStateSnapshot.enabled;\n\t\tthis.debugStateSnapshot = {\n\t\t\tenabled: state.enabled,\n\t\t\tselected: [...state.selected],\n\t\t};\n\t\tif (state.enabled && !wasEnabled) {\n\t\t\t// Entering debug mode: save game camera state, detach from rig, restore debug camera state if available\n\t\t\tthis.saveCameraState();\n\t\t\tthis.detachCameraFromRig();\n\t\t\tthis.enableOrbitControls();\n\t\t\tthis.restoreDebugCameraState();\n\t\t\tthis.updateOrbitTargetFromSelection(state.selected);\n\t\t} else if (!state.enabled && wasEnabled) {\n\t\t\t// Exiting debug mode: save debug camera state, then restore game camera state\n\t\t\tthis.saveDebugCameraState();\n\t\t\tthis.orbitTarget = null;\n\t\t\tthis.disableOrbitControls();\n\t\t\tthis.reattachCameraToRig();\n\t\t\tthis.restoreCameraState();\n\t\t} else if (state.enabled) {\n\t\t\t// Still in debug mode, just update target\n\t\t\tthis.updateOrbitTargetFromSelection(state.selected);\n\t\t}\n\t}\n\n\tprivate enableOrbitControls() {\n\t\tif (this.orbitControls) {\n\t\t\treturn;\n\t\t}\n\t\tthis.orbitControls = new OrbitControls(this.camera, this.domElement);\n\t\tthis.orbitControls.enableDamping = true;\n\t\tthis.orbitControls.dampingFactor = 0.05;\n\t\tthis.orbitControls.screenSpacePanning = false;\n\t\tthis.orbitControls.minDistance = 1;\n\t\tthis.orbitControls.maxDistance = 500;\n\t\tthis.orbitControls.maxPolarAngle = Math.PI / 2;\n\t\t// Default target to origin\n\t\tthis.orbitControls.target.set(0, 0, 0);\n\t}\n\n\tprivate disableOrbitControls() {\n\t\tif (!this.orbitControls) {\n\t\t\treturn;\n\t\t}\n\t\tthis.orbitControls.dispose();\n\t\tthis.orbitControls = null;\n\t}\n\n\tprivate updateOrbitTargetFromSelection(selected: string[]) {\n\t\t// Default to origin when no entity is selected\n\t\tif (!this.debugDelegate || selected.length === 0) {\n\t\t\tthis.orbitTarget = null;\n\t\t\tif (this.orbitControls) {\n\t\t\t\tthis.orbitControls.target.set(0, 0, 0);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tfor (let i = selected.length - 1; i >= 0; i -= 1) {\n\t\t\tconst uuid = selected[i];\n\t\t\tconst targetObject = this.debugDelegate.resolveTarget(uuid);\n\t\t\tif (targetObject) {\n\t\t\t\tthis.orbitTarget = targetObject;\n\t\t\t\tif (this.orbitControls) {\n\t\t\t\t\ttargetObject.getWorldPosition(this.orbitTargetWorldPos);\n\t\t\t\t\tthis.orbitControls.target.copy(this.orbitTargetWorldPos);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.orbitTarget = null;\n\t}\n\n\tprivate detachDebugDelegate() {\n\t\tif (this.debugUnsubscribe) {\n\t\t\ttry {\n\t\t\t\tthis.debugUnsubscribe();\n\t\t\t} catch { /* noop */ }\n\t\t}\n\t\tthis.debugUnsubscribe = null;\n\t\tthis.debugDelegate = null;\n\t}\n\n\t/**\n\t * Save camera position, rotation, and zoom before entering debug mode.\n\t */\n\tprivate saveCameraState() {\n\t\tthis.savedCameraPosition = this.camera.position.clone();\n\t\tthis.savedCameraQuaternion = this.camera.quaternion.clone();\n\t\t// Save zoom for orthographic/perspective cameras\n\t\tif ('zoom' in this.camera) {\n\t\t\tthis.savedCameraZoom = (this.camera as any).zoom as number;\n\t\t}\n\t}\n\n\t/**\n\t * Restore camera position, rotation, and zoom when exiting debug mode.\n\t */\n\tprivate restoreCameraState() {\n\t\tif (this.savedCameraPosition) {\n\t\t\tthis.camera.position.copy(this.savedCameraPosition);\n\t\t\tthis.savedCameraPosition = null;\n\t\t}\n\t\tif (this.savedCameraQuaternion) {\n\t\t\tthis.camera.quaternion.copy(this.savedCameraQuaternion);\n\t\t\tthis.savedCameraQuaternion = null;\n\t\t}\n\t\tif (this.savedCameraZoom !== null && 'zoom' in this.camera) {\n\t\t\tthis.camera.zoom = this.savedCameraZoom;\n\t\t\t(this.camera as any).updateProjectionMatrix?.();\n\t\t\tthis.savedCameraZoom = null;\n\t\t}\n\t}\n\n\t/**\n\t * Save debug camera state when exiting debug mode.\n\t */\n\tprivate saveDebugCameraState() {\n\t\tthis.savedDebugCameraPosition = this.camera.position.clone();\n\t\tthis.savedDebugCameraQuaternion = this.camera.quaternion.clone();\n\t\tif ('zoom' in this.camera) {\n\t\t\tthis.savedDebugCameraZoom = (this.camera as any).zoom as number;\n\t\t}\n\t\tif (this.orbitControls) {\n\t\t\tthis.savedDebugOrbitTarget = this.orbitControls.target.clone();\n\t\t}\n\t}\n\n\t/**\n\t * Restore debug camera state when re-entering debug mode.\n\t */\n\tprivate restoreDebugCameraState() {\n\t\tif (this.savedDebugCameraPosition) {\n\t\t\tthis.camera.position.copy(this.savedDebugCameraPosition);\n\t\t}\n\t\tif (this.savedDebugCameraQuaternion) {\n\t\t\tthis.camera.quaternion.copy(this.savedDebugCameraQuaternion);\n\t\t}\n\t\tif (this.savedDebugCameraZoom !== null && 'zoom' in this.camera) {\n\t\t\tthis.camera.zoom = this.savedDebugCameraZoom;\n\t\t\t(this.camera as any).updateProjectionMatrix?.();\n\t\t}\n\t\tif (this.savedDebugOrbitTarget && this.orbitControls) {\n\t\t\tthis.orbitControls.target.copy(this.savedDebugOrbitTarget);\n\t\t}\n\t}\n\n\t/**\n\t * Detach camera from its rig to allow free orbit movement in debug mode.\n\t * Preserves the camera's world position.\n\t */\n\tprivate detachCameraFromRig(): void {\n\t\tif (!this.cameraRig || this.camera.parent !== this.cameraRig) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Save the camera's local position for later restoration\n\t\tthis.savedCameraLocalPosition = this.camera.position.clone();\n\n\t\t// Get camera's world position before detaching\n\t\tconst worldPos = new Vector3();\n\t\tthis.camera.getWorldPosition(worldPos);\n\n\t\t// Remove camera from rig\n\t\tthis.cameraRig.remove(this.camera);\n\n\t\t// Add camera directly to scene if scene ref is available\n\t\tif (this.sceneRef) {\n\t\t\tthis.sceneRef.add(this.camera);\n\t\t}\n\n\t\t// Set camera's position to its previous world position\n\t\tthis.camera.position.copy(worldPos);\n\t}\n\n\t/**\n\t * Reattach camera to its rig when exiting debug mode.\n\t * Restores the camera's local position relative to the rig.\n\t */\n\tprivate reattachCameraToRig(): void {\n\t\tif (!this.cameraRig || this.camera.parent === this.cameraRig) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Remove camera from scene if it's there\n\t\tif (this.sceneRef && this.camera.parent === this.sceneRef) {\n\t\t\tthis.sceneRef.remove(this.camera);\n\t\t}\n\n\t\t// Add camera back to rig\n\t\tthis.cameraRig.add(this.camera);\n\n\t\t// Restore camera's local position\n\t\tif (this.savedCameraLocalPosition) {\n\t\t\tthis.camera.position.copy(this.savedCameraLocalPosition);\n\t\t\tthis.savedCameraLocalPosition = null;\n\t\t}\n\t}\n}\n","import { Vector2, Camera, PerspectiveCamera, Vector3, Object3D, OrthographicCamera, WebGLRenderer, Scene } from 'three';\nimport { PerspectiveType, Perspectives } from './perspective';\nimport { ThirdPersonCamera } from './third-person';\nimport { Fixed2DCamera } from './fixed-2d';\nimport { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';\nimport RenderPass from '../graphics/render-pass';\nimport { StageEntity } from '../interfaces/entity';\nimport { CameraOrbitController, CameraDebugDelegate } from './camera-debug-delegate';\n\n// Re-export for backwards compatibility\nexport type { CameraDebugState, CameraDebugDelegate } from './camera-debug-delegate';\n\n/**\n * Interface for perspective-specific camera controllers\n */\nexport interface PerspectiveController {\n\tsetup(params: { screenResolution: Vector2; renderer: WebGLRenderer; scene: Scene; camera: ZylemCamera }): void;\n\tupdate(delta: number): void;\n\tresize(width: number, height: number): void;\n}\n\nexport class ZylemCamera {\n\tcameraRig: Object3D | null = null;\n\tcamera: Camera;\n\tscreenResolution: Vector2;\n\trenderer: WebGLRenderer;\n\tcomposer: EffectComposer;\n\t_perspective: PerspectiveType;\n\ttarget: StageEntity | null = null;\n\tsceneRef: Scene | null = null;\n\tfrustumSize = 10;\n\n\t// Perspective controller delegation\n\tperspectiveController: PerspectiveController | null = null;\n\n\t// Debug/orbit controls delegation\n\tprivate orbitController: CameraOrbitController | null = null;\n\n\tconstructor(perspective: PerspectiveType, screenResolution: Vector2, frustumSize: number = 10) {\n\t\tthis._perspective = perspective;\n\t\tthis.screenResolution = screenResolution;\n\t\tthis.frustumSize = frustumSize;\n\t\t// Initialize renderer\n\t\tthis.renderer = new WebGLRenderer({ antialias: false, alpha: true });\n\t\tthis.renderer.setSize(screenResolution.x, screenResolution.y);\n\t\tthis.renderer.shadowMap.enabled = true;\n\n\t\t// Initialize composer\n\t\tthis.composer = new EffectComposer(this.renderer);\n\n\t\t// Create camera based on perspective\n\t\tconst aspectRatio = screenResolution.x / screenResolution.y;\n\t\tthis.camera = this.createCameraForPerspective(aspectRatio);\n\n\t\t// Setup camera rig only for perspectives that need it (e.g., third-person following)\n\t\tif (this.needsRig()) {\n\t\t\tthis.cameraRig = new Object3D();\n\t\t\tthis.cameraRig.position.set(0, 3, 10);\n\t\t\tthis.cameraRig.add(this.camera);\n\t\t\tthis.camera.lookAt(new Vector3(0, 2, 0));\n\t\t} else {\n\t\t\t// Position camera directly for non-rig perspectives\n\t\t\tthis.camera.position.set(0, 0, 10);\n\t\t\tthis.camera.lookAt(new Vector3(0, 0, 0));\n\t\t}\n\n\t\t// Initialize perspective controller\n\t\tthis.initializePerspectiveController();\n\n\t\t// Initialize orbit controller (handles debug mode orbit controls)\n\t\tthis.orbitController = new CameraOrbitController(this.camera, this.renderer.domElement, this.cameraRig);\n\t}\n\n\t/**\n\t * Setup the camera with a scene\n\t */\n\tasync setup(scene: Scene) {\n\t\tthis.sceneRef = scene;\n\n\t\t// Setup render pass\n\t\tlet renderResolution = this.screenResolution.clone().divideScalar(2);\n\t\trenderResolution.x |= 0;\n\t\trenderResolution.y |= 0;\n\t\tconst pass = new RenderPass(renderResolution, scene, this.camera);\n\t\tthis.composer.addPass(pass);\n\n\t\t// Setup perspective controller\n\t\tif (this.perspectiveController) {\n\t\t\tthis.perspectiveController.setup({\n\t\t\t\tscreenResolution: this.screenResolution,\n\t\t\t\trenderer: this.renderer,\n\t\t\t\tscene: scene,\n\t\t\t\tcamera: this\n\t\t\t});\n\t\t}\n\n\t\t// Set scene reference for orbit controller (needed for camera rig detachment)\n\t\tthis.orbitController?.setScene(scene);\n\n\t\t// Start render loop\n\t\tthis.renderer.setAnimationLoop((delta) => {\n\t\t\tthis.update(delta || 0);\n\t\t});\n\t}\n\n\t/**\n\t * Update camera and render\n\t */\n\tupdate(delta: number) {\n\t\t// Update orbit controls (if debug mode is enabled)\n\t\tthis.orbitController?.update();\n\n\t\t// Skip perspective controller updates when in debug mode\n\t\t// This keeps the debug camera isolated from game camera logic\n\t\tif (this.perspectiveController && !this.isDebugModeActive()) {\n\t\t\tthis.perspectiveController.update(delta);\n\t\t}\n\n\t\t// Render the scene\n\t\tthis.composer.render(delta);\n\t}\n\n\t/**\n\t * Check if debug mode is active (orbit controls taking over camera)\n\t */\n\tisDebugModeActive(): boolean {\n\t\treturn this.orbitController?.isActive ?? false;\n\t}\n\n\t/**\n\t * Dispose renderer, composer, controls, and detach from scene\n\t */\n\tdestroy() {\n\t\ttry {\n\t\t\tthis.renderer.setAnimationLoop(null as any);\n\t\t} catch { /* noop */ }\n\t\ttry {\n\t\t\tthis.orbitController?.dispose();\n\t\t} catch { /* noop */ }\n\t\ttry {\n\t\t\tthis.composer?.passes?.forEach((p: any) => p.dispose?.());\n\t\t\t// @ts-ignore dispose exists on EffectComposer but not typed here\n\t\t\tthis.composer?.dispose?.();\n\t\t} catch { /* noop */ }\n\t\ttry {\n\t\t\tthis.renderer.dispose();\n\t\t} catch { /* noop */ }\n\t\tthis.sceneRef = null;\n\t}\n\n\t/**\n\t * Attach a delegate to react to debug state changes.\n\t */\n\tsetDebugDelegate(delegate: CameraDebugDelegate | null) {\n\t\tthis.orbitController?.setDebugDelegate(delegate);\n\t}\n\n\t/**\n\t * Resize camera and renderer\n\t */\n\tresize(width: number, height: number) {\n\t\tthis.screenResolution.set(width, height);\n\t\tthis.renderer.setSize(width, height, false);\n\t\tthis.composer.setSize(width, height);\n\n\t\tif (this.camera instanceof PerspectiveCamera) {\n\t\t\tthis.camera.aspect = width / height;\n\t\t\tthis.camera.updateProjectionMatrix();\n\t\t}\n\n\t\tif (this.perspectiveController) {\n\t\t\tthis.perspectiveController.resize(width, height);\n\t\t}\n\t}\n\n\t/**\n\t * Update renderer pixel ratio (DPR)\n\t */\n\tsetPixelRatio(dpr: number) {\n\t\tconst safe = Math.max(1, Number.isFinite(dpr) ? dpr : 1);\n\t\tthis.renderer.setPixelRatio(safe);\n\t}\n\n\t/**\n\t * Create camera based on perspective type\n\t */\n\tprivate createCameraForPerspective(aspectRatio: number): Camera {\n\t\tswitch (this._perspective) {\n\t\t\tcase Perspectives.ThirdPerson:\n\t\t\t\treturn this.createThirdPersonCamera(aspectRatio);\n\t\t\tcase Perspectives.FirstPerson:\n\t\t\t\treturn this.createFirstPersonCamera(aspectRatio);\n\t\t\tcase Perspectives.Isometric:\n\t\t\t\treturn this.createIsometricCamera(aspectRatio);\n\t\t\tcase Perspectives.Flat2D:\n\t\t\t\treturn this.createFlat2DCamera(aspectRatio);\n\t\t\tcase Perspectives.Fixed2D:\n\t\t\t\treturn this.createFixed2DCamera(aspectRatio);\n\t\t\tdefault:\n\t\t\t\treturn this.createThirdPersonCamera(aspectRatio);\n\t\t}\n\t}\n\n\t/**\n\t * Initialize perspective-specific controller\n\t */\n\tprivate initializePerspectiveController() {\n\t\tswitch (this._perspective) {\n\t\t\tcase Perspectives.ThirdPerson:\n\t\t\t\tthis.perspectiveController = new ThirdPersonCamera();\n\t\t\t\tbreak;\n\t\t\tcase Perspectives.Fixed2D:\n\t\t\t\tthis.perspectiveController = new Fixed2DCamera();\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthis.perspectiveController = new ThirdPersonCamera();\n\t\t}\n\t}\n\n\tprivate createThirdPersonCamera(aspectRatio: number): PerspectiveCamera {\n\t\treturn new PerspectiveCamera(75, aspectRatio, 0.1, 1000);\n\t}\n\n\tprivate createFirstPersonCamera(aspectRatio: number): PerspectiveCamera {\n\t\treturn new PerspectiveCamera(75, aspectRatio, 0.1, 1000);\n\t}\n\n\tprivate createIsometricCamera(aspectRatio: number): OrthographicCamera {\n\t\treturn new OrthographicCamera(\n\t\t\tthis.frustumSize * aspectRatio / -2,\n\t\t\tthis.frustumSize * aspectRatio / 2,\n\t\t\tthis.frustumSize / 2,\n\t\t\tthis.frustumSize / -2,\n\t\t\t1,\n\t\t\t1000\n\t\t);\n\t}\n\n\tprivate createFlat2DCamera(aspectRatio: number): OrthographicCamera {\n\t\treturn new OrthographicCamera(\n\t\t\tthis.frustumSize * aspectRatio / -2,\n\t\t\tthis.frustumSize * aspectRatio / 2,\n\t\t\tthis.frustumSize / 2,\n\t\t\tthis.frustumSize / -2,\n\t\t\t1,\n\t\t\t1000\n\t\t);\n\t}\n\n\tprivate createFixed2DCamera(aspectRatio: number): OrthographicCamera {\n\t\treturn this.createFlat2DCamera(aspectRatio);\n\t}\n\n\t// Movement methods\n\tprivate moveCamera(position: Vector3) {\n\t\tif (this._perspective === Perspectives.Flat2D || this._perspective === Perspectives.Fixed2D) {\n\t\t\tthis.frustumSize = position.z;\n\t\t}\n\t\tif (this.cameraRig) {\n\t\t\tthis.cameraRig.position.set(position.x, position.y, position.z);\n\t\t} else {\n\t\t\tthis.camera.position.set(position.x, position.y, position.z);\n\t\t}\n\t}\n\n\tmove(position: Vector3) {\n\t\tthis.moveCamera(position);\n\t}\n\n\trotate(pitch: number, yaw: number, roll: number) {\n\t\tif (this.cameraRig) {\n\t\t\tthis.cameraRig.rotateX(pitch);\n\t\t\tthis.cameraRig.rotateY(yaw);\n\t\t\tthis.cameraRig.rotateZ(roll);\n\t\t} else {\n\t\t\t(this.camera as Object3D).rotateX(pitch);\n\t\t\t(this.camera as Object3D).rotateY(yaw);\n\t\t\t(this.camera as Object3D).rotateZ(roll);\n\t\t}\n\t}\n\n\t/**\n\t * Check if this perspective type needs a camera rig\n\t */\n\tprivate needsRig(): boolean {\n\t\treturn this._perspective === Perspectives.ThirdPerson;\n\t}\n\n\t/**\n\t * Get the DOM element for the renderer\n\t */\n\tgetDomElement(): HTMLCanvasElement {\n\t\treturn this.renderer.domElement;\n\t}\n}","import { Vector2 } from 'three';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { Perspectives, PerspectiveType } from '../camera/perspective';\nimport { CameraWrapper } from '../camera/camera';\nimport type { ZylemStage } from './zylem-stage';\n\n/**\n * Delegate for camera creation and management within a stage.\n * Accepts an injected stage reference for context.\n */\nexport class StageCameraDelegate {\n\tprivate stage: ZylemStage;\n\n\tconstructor(stage: ZylemStage) {\n\t\tthis.stage = stage;\n\t}\n\n\t/**\n\t * Create a default third-person camera based on window size.\n\t */\n\tcreateDefaultCamera(): ZylemCamera {\n\t\tconst width = window.innerWidth;\n\t\tconst height = window.innerHeight;\n\t\tconst screenResolution = new Vector2(width, height);\n\t\treturn new ZylemCamera(Perspectives.ThirdPerson, screenResolution);\n\t}\n\n\t/**\n\t * Resolve the camera to use for the stage.\n\t * Uses the provided camera, stage camera wrapper, or creates a default.\n\t * \n\t * @param cameraOverride Optional camera override\n\t * @param cameraWrapper Optional camera wrapper from stage options\n\t * @returns The resolved ZylemCamera instance\n\t */\n\tresolveCamera(cameraOverride?: ZylemCamera | null, cameraWrapper?: CameraWrapper): ZylemCamera {\n\t\tif (cameraOverride) {\n\t\t\treturn cameraOverride;\n\t\t}\n\t\tif (cameraWrapper) {\n\t\t\treturn cameraWrapper.cameraRef;\n\t\t}\n\t\treturn this.createDefaultCamera();\n\t}\n}\n","import { LoadingEvent } from '../core/interfaces';\nimport { gameEventBus, StageLoadingPayload } from '../game/game-event-bus';\n\n/**\n * Event name for stage loading events.\n * Dispatched via window for cross-application communication.\n */\nexport const STAGE_LOADING_EVENT = 'STAGE_LOADING_EVENT';\n\n/**\n * Delegate for managing loading events and progress within a stage.\n * Handles subscription to loading events and broadcasting progress.\n * Emits to game event bus for game-level observation.\n */\nexport class StageLoadingDelegate {\n\tprivate loadingHandlers: Array<(event: LoadingEvent) => void> = [];\n\tprivate stageName?: string;\n\tprivate stageIndex?: number;\n\n\t/**\n\t * Set stage context for event bus emissions.\n\t */\n\tsetStageContext(stageName: string, stageIndex: number): void {\n\t\tthis.stageName = stageName;\n\t\tthis.stageIndex = stageIndex;\n\t}\n\n\t/**\n\t * Subscribe to loading events.\n\t * \n\t * @param callback Invoked for each loading event (start, progress, complete)\n\t * @returns Unsubscribe function\n\t */\n\tonLoading(callback: (event: LoadingEvent) => void): () => void {\n\t\tthis.loadingHandlers.push(callback);\n\t\treturn () => {\n\t\t\tthis.loadingHandlers = this.loadingHandlers.filter((h) => h !== callback);\n\t\t};\n\t}\n\n\t/**\n\t * Emit a loading event to all subscribers and to the game event bus.\n\t * \n\t * @param event The loading event to broadcast\n\t */\n\temit(event: LoadingEvent): void {\n\t\t// Dispatch to direct subscribers\n\t\tfor (const handler of this.loadingHandlers) {\n\t\t\ttry {\n\t\t\t\thandler(event);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('Loading handler failed', e);\n\t\t\t}\n\t\t}\n\t\t\n\t\t// Emit to game event bus for game-level observation\n\t\tconst payload: StageLoadingPayload = {\n\t\t\t...event,\n\t\t\tstageName: this.stageName,\n\t\t\tstageIndex: this.stageIndex,\n\t\t};\n\t\t\n\t\tif (event.type === 'start') {\n\t\t\tgameEventBus.emit('stage:loading:start', payload);\n\t\t} else if (event.type === 'progress') {\n\t\t\tgameEventBus.emit('stage:loading:progress', payload);\n\t\t} else if (event.type === 'complete') {\n\t\t\tgameEventBus.emit('stage:loading:complete', payload);\n\t\t}\n\t}\n\n\t/**\n\t * Emit a start loading event.\n\t */\n\temitStart(message: string = 'Loading stage...'): void {\n\t\tthis.emit({ type: 'start', message, progress: 0 });\n\t}\n\n\t/**\n\t * Emit a progress loading event.\n\t */\n\temitProgress(message: string, current: number, total: number): void {\n\t\tconst progress = total > 0 ? current / total : 0;\n\t\tthis.emit({ type: 'progress', message, progress, current, total });\n\t}\n\n\t/**\n\t * Emit a complete loading event.\n\t */\n\temitComplete(message: string = 'Stage loaded'): void {\n\t\tthis.emit({ type: 'complete', message, progress: 1 });\n\t}\n\n\t/**\n\t * Clear all loading handlers.\n\t */\n\tdispose(): void {\n\t\tthis.loadingHandlers = [];\n\t}\n}\n","import { zylemEventBus } from '../events';\nimport { ZylemScene } from '../graphics/zylem-scene';\nimport { GameEntity } from '../entities/entity';\n\n/**\n * Delegate for handling deferred model loading in entities.\n * Subscribes to model:loaded events and adds entity groups to the scene\n * when they become available after async loading completes.\n */\nexport class StageEntityModelDelegate {\n\tprivate scene: ZylemScene | null = null;\n\tprivate pendingEntities: Map<string, GameEntity<any>> = new Map();\n\tprivate modelLoadedHandler: ((payload: { entityId: string; success: boolean }) => void) | null = null;\n\n\t/**\n\t * Initialize the delegate with the scene reference and start listening.\n\t */\n\tattach(scene: ZylemScene): void {\n\t\tthis.scene = scene;\n\t\tthis.modelLoadedHandler = (payload) => {\n\t\t\tthis.handleModelLoaded(payload.entityId, payload.success);\n\t\t};\n\t\tzylemEventBus.on('entity:model:loaded', this.modelLoadedHandler);\n\t}\n\n\t/**\n\t * Register an entity for observation.\n\t * When its model loads, the group will be added to the scene.\n\t */\n\tobserve(entity: GameEntity<any>): void {\n\t\tthis.pendingEntities.set(entity.uuid, entity);\n\t}\n\n\t/**\n\t * Unregister an entity (e.g., when removed before model loads).\n\t */\n\tunobserve(entityId: string): void {\n\t\tthis.pendingEntities.delete(entityId);\n\t}\n\n\t/**\n\t * Handle model loaded event - add group to scene if entity is pending.\n\t */\n\tprivate handleModelLoaded(entityId: string, success: boolean): void {\n\t\tconst entity = this.pendingEntities.get(entityId);\n\t\tif (!entity || !success) {\n\t\t\tthis.pendingEntities.delete(entityId);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.scene?.addEntityGroup(entity);\n\t\tthis.pendingEntities.delete(entityId);\n\t}\n\n\t/**\n\t * Cleanup all subscriptions and pending entities.\n\t */\n\tdispose(): void {\n\t\tif (this.modelLoadedHandler) {\n\t\t\tzylemEventBus.off('entity:model:loaded', this.modelLoadedHandler);\n\t\t\tthis.modelLoadedHandler = null;\n\t\t}\n\t\tthis.pendingEntities.clear();\n\t\tthis.scene = null;\n\t}\n}\n","import { BaseNode } from '../base-node';\nimport { CameraWrapper } from '../../camera/camera';\n\n/**\n * Check if an item is a BaseNode (has a create function).\n */\nexport function isBaseNode(item: unknown): item is BaseNode {\n\treturn !!item && typeof item === 'object' && typeof (item as any).create === 'function';\n}\n\n/**\n * Check if an item is a Promise-like (thenable).\n */\nexport function isThenable(item: unknown): item is Promise<any> {\n\treturn !!item && typeof (item as any).then === 'function';\n}\n\n/**\n * Check if an item is a CameraWrapper.\n */\nexport function isCameraWrapper(item: unknown): item is CameraWrapper {\n\treturn !!item && typeof item === 'object' && (item as any).constructor?.name === 'CameraWrapper';\n}\n\n/**\n * Check if an item is a plain config object (not a special type).\n * Excludes BaseNode, CameraWrapper, functions, and promises.\n */\nexport function isConfigObject(item: unknown): boolean {\n\tif (!item || typeof item !== 'object') return false;\n\tif (isBaseNode(item)) return false;\n\tif (isCameraWrapper(item)) return false;\n\tif (isThenable(item)) return false;\n\tif (typeof (item as any).then === 'function') return false;\n\t// Must be a plain object\n\treturn (item as any).constructor === Object || (item as any).constructor?.name === 'Object';\n}\n\n/**\n * Check if an item is an entity input (BaseNode, Promise, or factory function).\n */\nexport function isEntityInput(item: unknown): boolean {\n\tif (!item) return false;\n\tif (isBaseNode(item)) return true;\n\tif (typeof item === 'function') return true;\n\tif (isThenable(item)) return true;\n\treturn false;\n}\n","import { Color, Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { CameraWrapper } from '../camera/camera';\nimport { isBaseNode, isCameraWrapper, isConfigObject, isEntityInput, isThenable } from '../core/utility/options-parser';\nimport { ZylemBlueColor } from '../core/utility/vector';\nimport type { ZylemShaderObject } from '../graphics/material';\n\n/**\n * Stage configuration type for user-facing options.\n */\nexport type StageConfigLike = Partial<{\n\tinputs: Record<string, string[]>;\n\tbackgroundColor: Color | string;\n\tbackgroundImage: string | null;\n\tbackgroundShader: ZylemShaderObject;\n\tgravity: Vector3;\n\tvariables: Record<string, any>;\n}>;\n\n/**\n * Internal stage configuration class.\n */\nexport class StageConfig {\n\tconstructor(\n\t\tpublic inputs: Record<string, string[]>,\n\t\tpublic backgroundColor: Color | string,\n\t\tpublic backgroundImage: string | null,\n\t\tpublic backgroundShader: ZylemShaderObject | null,\n\t\tpublic gravity: Vector3,\n\t\tpublic variables: Record<string, any>,\n\t) { }\n}\n\n/**\n * Create default stage configuration.\n */\nexport function createDefaultStageConfig(): StageConfig {\n\treturn new StageConfig(\n\t\t{\n\t\t\tp1: ['gamepad-1', 'keyboard-1'],\n\t\t\tp2: ['gamepad-2', 'keyboard-2'],\n\t\t},\n\t\tZylemBlueColor,\n\t\tnull,\n\t\tnull,\n\t\tnew Vector3(0, 0, 0),\n\t\t{},\n\t);\n}\n\n/**\n * Result of parsing stage options.\n */\nexport interface ParsedStageOptions {\n\tconfig: StageConfig;\n\tentities: BaseNode[];\n\tasyncEntities: Array<BaseNode | Promise<any> | (() => BaseNode | Promise<any>)>;\n\tcamera?: CameraWrapper;\n}\n\n/**\n * Parse stage options array and resolve configuration.\n * Separates config objects, camera wrappers, and entity inputs.\n * \n * @param options Stage options array\n * @returns Parsed stage options with resolved config, entities, and camera\n */\nexport function parseStageOptions(options: any[] = []): ParsedStageOptions {\n\tconst defaults = createDefaultStageConfig();\n\tlet config: Partial<StageConfig> = {};\n\tconst entities: BaseNode[] = [];\n\tconst asyncEntities: Array<BaseNode | Promise<any> | (() => BaseNode | Promise<any>)> = [];\n\tlet camera: CameraWrapper | undefined;\n\n\tfor (const item of options) {\n\t\tif (isCameraWrapper(item)) {\n\t\t\tcamera = item;\n\t\t} else if (isBaseNode(item)) {\n\t\t\tentities.push(item);\n\t\t} else if (isEntityInput(item) && !isBaseNode(item)) {\n\t\t\tasyncEntities.push(item);\n\t\t} else if (isConfigObject(item)) {\n\t\t\tconfig = { ...config, ...item };\n\t\t}\n\t}\n\n\t// Merge user config with defaults\n\tconst resolvedConfig = new StageConfig(\n\t\tconfig.inputs ?? defaults.inputs,\n\t\tconfig.backgroundColor ?? defaults.backgroundColor,\n\t\tconfig.backgroundImage ?? defaults.backgroundImage,\n\t\tconfig.backgroundShader ?? defaults.backgroundShader,\n\t\tconfig.gravity ?? defaults.gravity,\n\t\tconfig.variables ?? defaults.variables,\n\t);\n\n\treturn { config: resolvedConfig, entities, asyncEntities, camera };\n}\n\n/**\n * Factory for authoring stage configuration objects in user code.\n * Returns a plain object that can be passed to `createStage(...)`.\n */\nexport function stageConfig(config: StageConfigLike): StageConfigLike {\n\treturn { ...config };\n}\n","import { addEntity, createWorld as createECS, removeEntity } from 'bitecs';\nimport { Color, Vector3, Vector2 } from 'three';\n\nimport { ZylemWorld } from '../collision/world';\nimport { ZylemScene } from '../graphics/zylem-scene';\nimport { resetStageVariables, setStageBackgroundColor, setStageBackgroundImage, setStageVariables, clearVariables, initialStageState } from './stage-state';\n\nimport { GameEntityInterface } from '../types/entity-types';\nimport { ZylemBlueColor } from '../core/utility/vector';\nimport { debugState } from '../debug/debug-state';\nimport { subscribe } from 'valtio/vanilla';\nimport { getGlobals } from \"../game/game-state\";\n\nimport { SetupContext, UpdateContext, DestroyContext } from '../core/base-node-life-cycle';\nimport { LifeCycleBase } from '../core/lifecycle-base';\nimport createTransformSystem, { StageSystem } from '../systems/transformable.system';\nimport { BaseNode } from '../core/base-node';\nimport { nanoid } from 'nanoid';\nimport { Stage } from './stage';\nimport { CameraWrapper } from '../camera/camera';\nimport { StageDebugDelegate } from './stage-debug-delegate';\nimport { StageCameraDebugDelegate } from './stage-camera-debug-delegate';\nimport { StageCameraDelegate } from './stage-camera-delegate';\nimport { StageLoadingDelegate } from './stage-loading-delegate';\nimport { StageEntityModelDelegate } from './stage-entity-model-delegate';\nimport { GameEntity } from '../entities/entity';\nimport { BaseEntityInterface } from '../types/entity-types';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { LoadingEvent } from '../core/interfaces';\nimport { parseStageOptions } from './stage-config';\nimport { isBaseNode, isThenable } from '../core/utility/options-parser';\nimport type { BehaviorSystem, BehaviorSystemFactory } from '../behaviors/behavior-system';\nexport type { LoadingEvent };\n\nexport interface ZylemStageConfig {\n\tinputs: Record<string, string[]>;\n\tbackgroundColor: Color | string;\n\tbackgroundImage: string | null;\n\tbackgroundShader: any | null;\n\tgravity: Vector3;\n\tvariables: Record<string, any>;\n\tstageRef?: Stage;\n}\n\ntype NodeLike = { create: Function };\nexport type StageEntityInput = NodeLike | Promise<any> | (() => NodeLike | Promise<any>);\n\nexport type StageOptionItem = Partial<ZylemStageConfig> | CameraWrapper | StageEntityInput;\nexport type StageOptions = [] | [Partial<ZylemStageConfig>, ...StageOptionItem[]];\n\nexport type StageState = ZylemStageConfig & { entities: GameEntityInterface[] };\n\nconst STAGE_TYPE = 'Stage';\n\n/**\n * ZylemStage orchestrates scene, physics world, entities, and lifecycle.\n *\n * Responsibilities:\n * - Manage stage configuration (background, inputs, gravity, variables)\n * - Initialize and own `ZylemScene` and `ZylemWorld`\n * - Spawn, track, and remove entities; emit entity-added events\n * - Drive per-frame updates and transform system\n */\nexport class ZylemStage extends LifeCycleBase<ZylemStage> {\n\tpublic type = STAGE_TYPE;\n\n\tstate: StageState = { ...initialStageState };\n\tgravity: Vector3;\n\n\tworld: ZylemWorld | null;\n\tscene: ZylemScene | null;\n\n\tchildren: Array<BaseNode> = [];\n\t_childrenMap: Map<number, BaseNode> = new Map();\n\t_removalMap: Map<number, BaseNode> = new Map();\n\n\tprivate pendingEntities: StageEntityInput[] = [];\n\tprivate pendingPromises: Promise<BaseNode>[] = [];\n\tprivate isLoaded: boolean = false;\n\n\t_debugMap: Map<string, BaseNode> = new Map();\n\n\tprivate entityAddedHandlers: Array<(entity: BaseNode) => void> = [];\n\n\tecs = createECS();\n\ttestSystem: any = null;\n\ttransformSystem: ReturnType<typeof createTransformSystem> | null = null;\n\tprivate behaviorSystems: BehaviorSystem[] = [];\n\tprivate registeredSystemKeys: Set<symbol> = new Set();\n\tdebugDelegate: StageDebugDelegate | null = null;\n\tcameraDebugDelegate: StageCameraDebugDelegate | null = null;\n\tprivate debugStateUnsubscribe: (() => void) | null = null;\n\n\tuuid: string;\n\twrapperRef: Stage | null = null;\n\tcamera?: CameraWrapper;\n\tcameraRef?: ZylemCamera | null = null;\n\n\t// Delegates\n\tprivate cameraDelegate: StageCameraDelegate;\n\tprivate loadingDelegate: StageLoadingDelegate;\n\tprivate entityModelDelegate: StageEntityModelDelegate;\n\n\t/**\n\t * Create a new stage.\n\t * @param options Stage options: partial config, camera, and initial entities or factories\n\t */\n\tconstructor(options: StageOptions = []) {\n\t\tsuper();\n\t\tthis.world = null;\n\t\tthis.scene = null;\n\t\tthis.uuid = nanoid();\n\n\t\t// Initialize delegates\n\t\tthis.cameraDelegate = new StageCameraDelegate(this);\n\t\tthis.loadingDelegate = new StageLoadingDelegate();\n\t\tthis.entityModelDelegate = new StageEntityModelDelegate();\n\n\t\t// Parse the options array using the stage-config module\n\t\tconst parsed = parseStageOptions(options);\n\t\tthis.camera = parsed.camera;\n\t\tthis.children = parsed.entities;\n\t\tthis.pendingEntities = parsed.asyncEntities;\n\t\t\n\t\t// Update state with resolved config\n\t\tthis.saveState({\n\t\t\t...this.state,\n\t\t\tinputs: parsed.config.inputs,\n\t\t\tbackgroundColor: parsed.config.backgroundColor,\n\t\t\tbackgroundImage: parsed.config.backgroundImage,\n\t\t\tbackgroundShader: parsed.config.backgroundShader,\n\t\t\tgravity: parsed.config.gravity,\n\t\t\tvariables: parsed.config.variables,\n\t\t\tentities: [],\n\t\t});\n\n\t\tthis.gravity = parsed.config.gravity ?? new Vector3(0, 0, 0);\n\t}\n\n\tprivate handleEntityImmediatelyOrQueue(entity: BaseNode): void {\n\t\tif (this.isLoaded) {\n\t\t\tthis.spawnEntity(entity);\n\t\t} else {\n\t\t\tthis.children.push(entity);\n\t\t}\n\t}\n\n\tprivate handlePromiseWithSpawnOnResolve(promise: Promise<any>): void {\n\t\tif (this.isLoaded) {\n\t\t\tpromise\n\t\t\t\t.then((entity) => this.spawnEntity(entity))\n\t\t\t\t.catch((e) => console.error('Failed to build async entity', e));\n\t\t} else {\n\t\t\tthis.pendingPromises.push(promise as Promise<BaseNode>);\n\t\t}\n\t}\n\n\tprivate saveState(state: StageState) {\n\t\tthis.state = state;\n\t}\n\n\tprivate setState() {\n\t\tconst { backgroundColor, backgroundImage } = this.state;\n\t\tconst color = backgroundColor instanceof Color ? backgroundColor : new Color(backgroundColor);\n\t\tsetStageBackgroundColor(color);\n\t\tsetStageBackgroundImage(backgroundImage);\n\t\t// Initialize reactive stage variables on load\n\t\tsetStageVariables(this.state.variables ?? {});\n\t}\n\n\t/**\n\t * Load and initialize the stage's scene and world.\n\t * Uses generator pattern to yield control to event loop for real-time progress.\n\t * @param id DOM element id for the renderer container\n\t * @param camera Optional camera override\n\t */\n\tasync load(id: string, camera?: ZylemCamera | null) {\n\t\tthis.setState();\n\n\t\t// Use camera delegate to resolve camera\n\t\tconst zylemCamera = this.cameraDelegate.resolveCamera(camera, this.camera);\n\t\tthis.cameraRef = zylemCamera;\n\t\tthis.scene = new ZylemScene(id, zylemCamera, this.state);\n\n\t\tconst physicsWorld = await ZylemWorld.loadPhysics(this.gravity ?? new Vector3(0, 0, 0));\n\t\tthis.world = new ZylemWorld(physicsWorld);\n\n\t\tthis.scene.setup();\n\t\tthis.entityModelDelegate.attach(this.scene);\n\n\t\tthis.loadingDelegate.emitStart();\n\n\t\t// Run entity loading with generator pattern for real-time progress\n\t\tawait this.runEntityLoadGenerator();\n\n\t\tthis.transformSystem = createTransformSystem(this as unknown as StageSystem);\n\t\tthis.isLoaded = true;\n\t\tthis.loadingDelegate.emitComplete();\n\t}\n\n\t/**\n\t * Generator that yields between entity loads for real-time progress updates.\n\t */\n\tprivate *entityLoadGenerator(): Generator<{ current: number; total: number; name: string }> {\n\t\tconst total = this.children.length + this.pendingEntities.length + this.pendingPromises.length;\n\t\tlet current = 0;\n\n\t\tfor (const child of this.children) {\n\t\t\tthis.spawnEntity(child);\n\t\t\tcurrent++;\n\t\t\tyield { current, total, name: child.name || 'unknown' };\n\t\t}\n\n\t\tif (this.pendingEntities.length) {\n\t\t\tthis.enqueue(...this.pendingEntities);\n\t\t\tcurrent += this.pendingEntities.length;\n\t\t\tthis.pendingEntities = [];\n\t\t\tyield { current, total, name: 'pending entities' };\n\t\t}\n\n\t\tif (this.pendingPromises.length) {\n\t\t\tfor (const promise of this.pendingPromises) {\n\t\t\t\tpromise.then((entity) => {\n\t\t\t\t\tthis.spawnEntity(entity);\n\t\t\t\t}).catch((e) => console.error('Failed to resolve pending stage entity', e));\n\t\t\t}\n\t\t\tcurrent += this.pendingPromises.length;\n\t\t\tthis.pendingPromises = [];\n\t\t\tyield { current, total, name: 'async entities' };\n\t\t}\n\t}\n\n\t/**\n\t * Runs the entity load generator, yielding to the event loop between loads.\n\t * This allows the browser to process events and update the UI in real-time.\n\t */\n\tprivate async runEntityLoadGenerator(): Promise<void> {\n\t\tconst gen = this.entityLoadGenerator();\n\t\tfor (const progress of gen) {\n\t\t\tthis.loadingDelegate.emitProgress(`Loaded ${progress.name}`, progress.current, progress.total);\n\t\t\t// Yield to event loop so browser can process events and update UI\n\t\t\t// Use setTimeout(0) for more reliable async behavior than RAF\n\t\t\tawait new Promise<void>(resolve => setTimeout(resolve, 0));\n\t\t}\n\t}\n\n\n\tprotected _setup(params: SetupContext<ZylemStage>): void {\n\t\tif (!this.scene || !this.world) {\n\t\t\tthis.logMissingEntities();\n\t\t\treturn;\n\t\t}\n\t\t// Setup debug delegate based on current state\n\t\tthis.updateDebugDelegate();\n\n\t\t// Subscribe to debugState changes for runtime toggle\n\t\tthis.debugStateUnsubscribe = subscribe(debugState, () => {\n\t\t\tthis.updateDebugDelegate();\n\t\t});\n\t}\n\n\tprivate updateDebugDelegate(): void {\n\t\tif (debugState.enabled && !this.debugDelegate && this.scene && this.world) {\n\t\t\t// Create debug delegate when debug is enabled\n\t\t\tthis.debugDelegate = new StageDebugDelegate(this);\n\t\t\t\n\t\t\t// Create and attach camera debug delegate for orbit controls\n\t\t\tif (this.cameraRef && !this.cameraDebugDelegate) {\n\t\t\t\tthis.cameraDebugDelegate = new StageCameraDebugDelegate(this);\n\t\t\t\tthis.cameraRef.setDebugDelegate(this.cameraDebugDelegate);\n\t\t\t}\n\t\t} else if (!debugState.enabled && this.debugDelegate) {\n\t\t\t// Dispose debug delegate when debug is disabled\n\t\t\tthis.debugDelegate.dispose();\n\t\t\tthis.debugDelegate = null;\n\t\t\t\n\t\t\t// Detach camera debug delegate\n\t\t\tif (this.cameraRef) {\n\t\t\t\tthis.cameraRef.setDebugDelegate(null);\n\t\t\t}\n\t\t\tthis.cameraDebugDelegate = null;\n\t\t}\n\t}\n\n\tprotected _update(params: UpdateContext<ZylemStage>): void {\n\t\tconst { delta } = params;\n\t\tif (!this.scene || !this.world) {\n\t\t\tthis.logMissingEntities();\n\t\t\treturn;\n\t\t}\n\t\tthis.world.update(params);\n\t\tthis.transformSystem?.system(this.ecs);\n\t\t// Run registered ECS behavior systems\n\t\tfor (const system of this.behaviorSystems) {\n\t\t\tsystem.update(this.ecs, delta);\n\t\t}\n\t\tthis._childrenMap.forEach((child, eid) => {\n\t\t\tchild.nodeUpdate({\n\t\t\t\t...params,\n\t\t\t\tme: child,\n\t\t\t});\n\t\t\tif (child.markedForRemoval) {\n\t\t\t\tthis.removeEntityByUuid(child.uuid);\n\t\t\t}\n\t\t});\n\t\tthis.scene.update({ delta });\n\t\tthis.scene.updateSkybox(delta);\n\t}\n\n\tpublic outOfLoop() {\n\t\tthis.debugUpdate();\n\t}\n\n\t/** Update debug overlays and helpers if enabled. */\n\tpublic debugUpdate() {\n\t\tif (debugState.enabled) {\n\t\t\tthis.debugDelegate?.update();\n\t\t}\n\t}\n\n\t/** Cleanup owned resources when the stage is destroyed. */\n\tprotected _destroy(params: DestroyContext<ZylemStage>): void {\n\t\t// Cleanup behavior systems\n\t\tfor (const system of this.behaviorSystems) {\n\t\t\tsystem.destroy?.(this.ecs);\n\t\t}\n\t\tthis.behaviorSystems = [];\n\t\tthis.registeredSystemKeys.clear();\n\t\tthis._childrenMap.forEach((child) => {\n\t\t\ttry { child.nodeDestroy({ me: child, globals: getGlobals() }); } catch { /* noop */ }\n\t\t});\n\t\tthis._childrenMap.clear();\n\t\tthis._removalMap.clear();\n\t\tthis._debugMap.clear();\n\n\t\tthis.world?.destroy();\n\t\tthis.scene?.destroy();\n\n\t\t// Cleanup debug state subscription\n\t\tif (this.debugStateUnsubscribe) {\n\t\t\tthis.debugStateUnsubscribe();\n\t\t\tthis.debugStateUnsubscribe = null;\n\t\t}\n\n\t\tthis.debugDelegate?.dispose();\n\t\tthis.debugDelegate = null;\n\t\tthis.cameraRef?.setDebugDelegate(null);\n\t\tthis.cameraDebugDelegate = null;\n\n\t\tthis.entityModelDelegate.dispose();\n\n\t\tthis.isLoaded = false;\n\t\tthis.world = null as any;\n\t\tthis.scene = null as any;\n\t\tthis.cameraRef = null;\n\t\t// Cleanup transform system\n\t\tthis.transformSystem?.destroy(this.ecs);\n\t\tthis.transformSystem = null;\n\n\t\t// Clear reactive stage variables on unload\n\t\tresetStageVariables();\n\t\t// Clear object-scoped variables for this stage\n\t\tclearVariables(this);\n\t}\n\n\t/**\n\t * Create, register, and add an entity to the scene/world.\n\t * Safe to call only after `load` when scene/world exist.\n\t */\n\tasync spawnEntity(child: BaseNode) {\n\t\tif (!this.scene || !this.world) {\n\t\t\treturn;\n\t\t}\n\t\tconst entity = child.create();\n\t\tconst eid = addEntity(this.ecs);\n\t\tentity.eid = eid;\n\t\tthis.scene.addEntity(entity);\n\n\t\t// Auto-register behavior systems from entity refs\n\t\tif (typeof entity.getBehaviorRefs === 'function') {\n\t\t\tfor (const ref of entity.getBehaviorRefs()) {\n\t\t\t\tconst key = ref.descriptor.key;\n\t\t\t\tif (!this.registeredSystemKeys.has(key)) {\n\t\t\t\t\tconst system = ref.descriptor.systemFactory({ world: this.world, ecs: this.ecs });\n\t\t\t\t\tthis.behaviorSystems.push(system);\n\t\t\t\t\tthis.registeredSystemKeys.add(key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (entity.colliderDesc) {\n\t\t\tthis.world.addEntity(entity);\n\t\t}\n\t\tchild.nodeSetup({\n\t\t\tme: child,\n\t\t\tglobals: getGlobals(),\n\t\t\tcamera: this.scene.zylemCamera,\n\t\t});\n\t\tthis.addEntityToStage(entity);\n\t\tthis.entityModelDelegate.observe(entity);\n\t}\n\n\tbuildEntityState(child: BaseNode): Partial<BaseEntityInterface> {\n\t\tif (child instanceof GameEntity) {\n\t\t\treturn { ...child.buildInfo() } as Partial<BaseEntityInterface>;\n\t\t}\n\t\treturn {\n\t\t\tuuid: child.uuid,\n\t\t\tname: child.name,\n\t\t\teid: child.eid,\n\t\t} as Partial<BaseEntityInterface>;\n\t}\n\n\t/** Add the entity to internal maps and notify listeners. */\n\taddEntityToStage(entity: BaseNode) {\n\t\tthis._childrenMap.set(entity.eid, entity);\n\t\tif (debugState.enabled) {\n\t\t\tthis._debugMap.set(entity.uuid, entity);\n\t\t}\n\t\tfor (const handler of this.entityAddedHandlers) {\n\t\t\ttry {\n\t\t\t\thandler(entity);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('onEntityAdded handler failed', e);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Subscribe to entity-added events.\n\t * @param callback Invoked for each entity when added\n\t * @param options.replayExisting If true and stage already loaded, replays existing entities\n\t * @returns Unsubscribe function\n\t */\n\tonEntityAdded(callback: (entity: BaseNode) => void, options?: { replayExisting?: boolean }) {\n\t\tthis.entityAddedHandlers.push(callback);\n\t\tif (options?.replayExisting && this.isLoaded) {\n\t\t\tthis._childrenMap.forEach((entity) => {\n\t\t\t\ttry { callback(entity); } catch (e) { console.error('onEntityAdded replay failed', e); }\n\t\t\t});\n\t\t}\n\t\treturn () => {\n\t\t\tthis.entityAddedHandlers = this.entityAddedHandlers.filter((h) => h !== callback);\n\t\t};\n\t}\n\n\tonLoading(callback: (event: LoadingEvent) => void) {\n\t\treturn this.loadingDelegate.onLoading(callback);\n\t}\n\n\t/**\n\t * Register an ECS behavior system to run each frame.\n\t * @param systemOrFactory A BehaviorSystem instance or factory function\n\t * @returns this for chaining\n\t */\n\tregisterSystem(systemOrFactory: BehaviorSystem | BehaviorSystemFactory): this {\n\t\tlet system: BehaviorSystem;\n\t\tif (typeof systemOrFactory === 'function') {\n\t\t\tsystem = systemOrFactory({ world: this.world, ecs: this.ecs });\n\t\t} else {\n\t\t\tsystem = systemOrFactory;\n\t\t}\n\t\tthis.behaviorSystems.push(system);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Remove an entity and its resources by its UUID.\n\t * @returns true if removed, false if not found or stage not ready\n\t */\n\tremoveEntityByUuid(uuid: string): boolean {\n\t\tif (!this.scene || !this.world) return false;\n\t\t// Try mapping via world collision map first for physics-backed entities\n\t\t// @ts-ignore - collisionMap is public Map<string, GameEntity<any>>\n\t\tconst mapEntity = this.world.collisionMap.get(uuid) as any | undefined;\n\t\tconst entity: any = mapEntity ?? this._debugMap.get(uuid);\n\t\tif (!entity) return false;\n\n\t\tthis.entityModelDelegate.unobserve(uuid);\n\n\t\tthis.world.destroyEntity(entity);\n\n\t\tif (entity.group) {\n\t\t\tthis.scene.scene.remove(entity.group);\n\t\t} else if (entity.mesh) {\n\t\t\tthis.scene.scene.remove(entity.mesh);\n\t\t}\n\n\t\tremoveEntity(this.ecs, entity.eid);\n\n\t\tlet foundKey: number | null = null;\n\t\tthis._childrenMap.forEach((value, key) => {\n\t\t\tif ((value as any).uuid === uuid) {\n\t\t\t\tfoundKey = key;\n\t\t\t}\n\t\t});\n\t\tif (foundKey !== null) {\n\t\t\tthis._childrenMap.delete(foundKey);\n\t\t}\n\t\tthis._debugMap.delete(uuid);\n\t\treturn true;\n\t}\n\n\t/** Get an entity by its name; returns null if not found. */\n\tgetEntityByName(name: string) {\n\t\tconst arr = Object.entries(Object.fromEntries(this._childrenMap)).map((entry) => entry[1]);\n\t\tconst entity = arr.find((child) => child.name === name);\n\t\tif (!entity) {\n\t\t\tconsole.warn(`Entity ${name} not found`);\n\t\t}\n\t\treturn entity ?? null;\n\t}\n\n\tlogMissingEntities() {\n\t\tconsole.warn('Zylem world or scene is null');\n\t}\n\n\t/** Resize renderer viewport. */\n\tresize(width: number, height: number) {\n\t\tif (this.scene) {\n\t\t\tthis.scene.updateRenderer(width, height);\n\t\t}\n\t}\n\n\t/**\n\t * Enqueue items to be spawned. Items can be:\n\t * - BaseNode instances (immediate or deferred until load)\n\t * - Factory functions returning BaseNode or Promise<BaseNode>\n\t * - Promises resolving to BaseNode\n\t */\n\tenqueue(...items: StageEntityInput[]) {\n\t\tfor (const item of items) {\n\t\t\tif (!item) continue;\n\t\t\tif (isBaseNode(item)) {\n\t\t\t\tthis.handleEntityImmediatelyOrQueue(item);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (typeof item === 'function') {\n\t\t\t\ttry {\n\t\t\t\t\tconst result = (item as (() => BaseNode | Promise<any>))();\n\t\t\t\t\tif (isBaseNode(result)) {\n\t\t\t\t\t\tthis.handleEntityImmediatelyOrQueue(result);\n\t\t\t\t\t} else if (isThenable(result)) {\n\t\t\t\t\t\tthis.handlePromiseWithSpawnOnResolve(result as Promise<any>);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error('Error executing entity factory', error);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isThenable(item)) {\n\t\t\t\tthis.handlePromiseWithSpawnOnResolve(item as Promise<any>);\n\t\t\t}\n\t\t}\n\t}\n}\n","import { Vector2, Vector3 } from \"three\";\nimport { PerspectiveType } from \"./perspective\";\nimport { ZylemCamera } from \"./zylem-camera\";\n\nexport interface CameraOptions {\n\tperspective?: PerspectiveType;\n\tposition?: Vector3;\n\ttarget?: Vector3;\n\tzoom?: number;\n\tscreenResolution?: Vector2;\n}\n\nexport class CameraWrapper {\n\tcameraRef: ZylemCamera;\n\n\tconstructor(camera: ZylemCamera) {\n\t\tthis.cameraRef = camera;\n\t}\n}\n\nexport function createCamera(options: CameraOptions): CameraWrapper {\n\tconst screenResolution = options.screenResolution || new Vector2(window.innerWidth, window.innerHeight);\n\tlet frustumSize = 10;\n\tif (options.perspective === 'fixed-2d') {\n\t\tfrustumSize = options.zoom || 10;\n\t}\n\tconst zylemCamera = new ZylemCamera(options.perspective || 'third-person', screenResolution, frustumSize);\n\n\t// Set initial position and target\n\tzylemCamera.move(options.position || new Vector3(0, 0, 0));\n\tzylemCamera.camera.lookAt(options.target || new Vector3(0, 0, 0));\n\n\treturn new CameraWrapper(zylemCamera);\n}","import { proxy } from 'valtio/vanilla';\nimport { Vector3 } from 'three';\nimport type { StageOptions, ZylemStageConfig } from './zylem-stage';\nimport { ZylemBlueColor } from '../core/utility/vector';\n\n/**\n * Reactive defaults for building `Stage` instances. These values are applied\n * automatically by the `stage()` builder and can be changed at runtime to\n * influence future stage creations.\n */\nconst initialDefaults: Partial<ZylemStageConfig> = {\n\tbackgroundColor: ZylemBlueColor,\n\tbackgroundImage: null,\n\tinputs: {\n\t\tp1: ['gamepad-1', 'keyboard'],\n\t\tp2: ['gamepad-2', 'keyboard'],\n\t},\n\tgravity: new Vector3(0, 0, 0),\n\tvariables: {},\n};\n\nconst stageDefaultsState = proxy<Partial<ZylemStageConfig>>({\n\t...initialDefaults,\n});\n\n/** Replace multiple defaults at once (shallow merge). */\nfunction setStageDefaults(partial: Partial<ZylemStageConfig>): void {\n\tObject.assign(stageDefaultsState, partial);\n}\n\n/** Reset defaults back to library defaults. */\nfunction resetStageDefaults(): void {\n\tObject.assign(stageDefaultsState, initialDefaults);\n}\n\nexport function getStageOptions(options: StageOptions): StageOptions {\n\tconst defaults = getStageDefaultConfig();\n\tlet originalConfig = {};\n\tif (typeof options[0] === 'object') {\n\t\toriginalConfig = options.shift() ?? {};\n\t}\n\tconst combinedConfig = { ...defaults, ...originalConfig };\n\treturn [combinedConfig, ...options] as StageOptions;\n}\n\n/** Get a plain object copy of the current defaults. */\nfunction getStageDefaultConfig(): Partial<ZylemStageConfig> {\n\treturn {\n\t\tbackgroundColor: stageDefaultsState.backgroundColor,\n\t\tbackgroundImage: stageDefaultsState.backgroundImage ?? null,\n\t\tinputs: stageDefaultsState.inputs ? { ...stageDefaultsState.inputs } : undefined,\n\t\tgravity: stageDefaultsState.gravity,\n\t\tvariables: stageDefaultsState.variables ? { ...stageDefaultsState.variables } : undefined,\n\t};\n}\n\n\n","import { BaseNode } from '../core/base-node';\nimport { DestroyFunction, SetupContext, SetupFunction, UpdateFunction } from '../core/base-node-life-cycle';\nimport { LoadingEvent, StageOptionItem, StageOptions, ZylemStage } from './zylem-stage';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { CameraWrapper } from '../camera/camera';\nimport { stageState } from './stage-state';\nimport { getStageOptions } from './stage-default';\nimport { EntityTypeMap } from '../types/entity-type-map';\nimport { EventEmitterDelegate, zylemEventBus, type StageEvents } from '../events';\n\ntype NodeLike = { create: Function };\ntype AnyNode = NodeLike | Promise<NodeLike>;\ntype EntityInput = AnyNode | (() => AnyNode) | (() => Promise<any>);\n\nexport class Stage {\n\twrappedStage: ZylemStage | null;\n\toptions: StageOptionItem[] = [];\n\t// Entities added after construction, consumed on each load\n\tprivate _pendingEntities: BaseNode[] = [];\n\n\t// Lifecycle callback arrays\n\tprivate setupCallbacks: Array<SetupFunction<ZylemStage>> = [];\n\tprivate updateCallbacks: Array<UpdateFunction<ZylemStage>> = [];\n\tprivate destroyCallbacks: Array<DestroyFunction<ZylemStage>> = [];\n\tprivate pendingLoadingCallbacks: Array<(event: LoadingEvent) => void> = [];\n\n\t// Event delegate for dispatch/listen API\n\tprivate eventDelegate = new EventEmitterDelegate<StageEvents>();\n\n\tconstructor(options: StageOptions) {\n\t\tthis.options = options;\n\t\tthis.wrappedStage = null;\n\t}\n\n\tasync load(id: string, camera?: ZylemCamera | CameraWrapper | null) {\n\t\tstageState.entities = [];\n\t\t// Combine original options with pending entities, then clear pending\n\t\tconst loadOptions = [...this.options, ...this._pendingEntities] as StageOptions;\n\t\tthis._pendingEntities = [];\n\t\t\n\t\tthis.wrappedStage = new ZylemStage(loadOptions);\n\t\tthis.wrappedStage.wrapperRef = this;\n\n\t\t// Flush pending loading callbacks BEFORE load so we catch start/progress events\n\t\tthis.pendingLoadingCallbacks.forEach(cb => {\n\t\t\tthis.wrappedStage!.onLoading(cb);\n\t\t});\n\t\tthis.pendingLoadingCallbacks = [];\n\n\t\tconst zylemCamera = camera instanceof CameraWrapper ? camera.cameraRef : camera;\n\t\tawait this.wrappedStage!.load(id, zylemCamera);\n\n\t\tthis.wrappedStage!.onEntityAdded((child) => {\n\t\t\tconst next = this.wrappedStage!.buildEntityState(child);\n\t\t\tstageState.entities = [...stageState.entities, next];\n\t\t}, { replayExisting: true });\n\n\t\t// Apply lifecycle callbacks to wrapped stage\n\t\tthis.applyLifecycleCallbacks();\n\n\t}\n\n\tprivate applyLifecycleCallbacks() {\n\t\tif (!this.wrappedStage) return;\n\n\t\t// Compose setup callbacks into a single function\n\t\tif (this.setupCallbacks.length > 0) {\n\t\t\tthis.wrappedStage.setup = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.setupCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\n\t\t// Compose update callbacks\n\t\tif (this.updateCallbacks.length > 0) {\n\t\t\tthis.wrappedStage.update = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.updateCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\n\t\t// Compose destroy callbacks\n\t\tif (this.destroyCallbacks.length > 0) {\n\t\t\tthis.wrappedStage.destroy = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.destroyCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\t}\n\n\tasync addEntities(entities: BaseNode[]) {\n\t\t// Store in pending, don't mutate options\n\t\tthis._pendingEntities.push(...entities);\n\t\tif (!this.wrappedStage) { return; }\n\t\tthis.wrappedStage!.enqueue(...entities);\n\t}\n\n\tadd(...inputs: Array<EntityInput>) {\n\t\tthis.addToBlueprints(...inputs);\n\t\tthis.addToStage(...inputs);\n\t}\n\n\tprivate addToBlueprints(...inputs: Array<EntityInput>) {\n\t\tif (this.wrappedStage) { return; }\n\t\t// Add to options (persistent) so they're available on reload\n\t\tthis.options.push(...(inputs as unknown as StageOptionItem[]));\n\t}\n\n\tprivate addToStage(...inputs: Array<EntityInput>) {\n\t\tif (!this.wrappedStage) { return; }\n\t\tthis.wrappedStage!.enqueue(...(inputs as any));\n\t}\n\n\tstart(params: SetupContext<ZylemStage>) {\n\t\tthis.wrappedStage?.nodeSetup(params);\n\t}\n\n\t// Fluent API for adding lifecycle callbacks\n\tonUpdate(...callbacks: UpdateFunction<ZylemStage>[]): this {\n\t\tthis.updateCallbacks.push(...callbacks);\n\t\t// If already loaded, recompose the update callback\n\t\tif (this.wrappedStage) {\n\t\t\tthis.wrappedStage.update = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.updateCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\t\treturn this;\n\t}\n\n\tonSetup(...callbacks: SetupFunction<ZylemStage>[]): this {\n\t\tthis.setupCallbacks.push(...callbacks);\n\t\t// If already loaded, recompose the setup callback\n\t\tif (this.wrappedStage) {\n\t\t\tthis.wrappedStage.setup = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.setupCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\t\treturn this;\n\t}\n\n\tonDestroy(...callbacks: DestroyFunction<ZylemStage>[]): this {\n\t\tthis.destroyCallbacks.push(...callbacks);\n\t\t// If already loaded, recompose the destroy callback\n\t\tif (this.wrappedStage) {\n\t\t\tthis.wrappedStage.destroy = (params) => {\n\t\t\t\tconst extended = { ...params, stage: this } as any;\n\t\t\t\tthis.destroyCallbacks.forEach(cb => cb(extended));\n\t\t\t};\n\t\t}\n\t\treturn this;\n\t}\n\n\tonLoading(callback: (event: LoadingEvent) => void) {\n\t\tif (!this.wrappedStage) { \n\t\t\tthis.pendingLoadingCallbacks.push(callback);\n\t\t\treturn () => {\n\t\t\t\tthis.pendingLoadingCallbacks = this.pendingLoadingCallbacks.filter(c => c !== callback);\n\t\t\t};\n\t\t}\n\t\treturn this.wrappedStage.onLoading(callback);\n\t}\n\n\t/**\n\t * Find an entity by name on the current stage.\n\t * @param name The name of the entity to find\n\t * @param type Optional type symbol for type inference (e.g., TEXT_TYPE, SPRITE_TYPE)\n\t * @returns The entity if found, or undefined\n\t * @example stage.getEntityByName('scoreText', TEXT_TYPE)\n\t */\n\tgetEntityByName<T extends symbol | void = void>(\n\t\tname: string,\n\t\ttype?: T\n\t): T extends keyof EntityTypeMap ? EntityTypeMap[T] | undefined : BaseNode | undefined {\n\t\tconst entity = this.wrappedStage?.children.find(c => c.name === name);\n\t\treturn entity as any;\n\t}\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Events API\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\t/**\n\t * Dispatch an event from the stage.\n\t * Events are emitted both locally and to the global event bus.\n\t */\n\tdispatch<K extends keyof StageEvents>(event: K, payload: StageEvents[K]): void {\n\t\tthis.eventDelegate.dispatch(event, payload);\n\t\t(zylemEventBus as any).emit(event, payload);\n\t}\n\n\t/**\n\t * Listen for events on this stage instance.\n\t * @returns Unsubscribe function\n\t */\n\tlisten<K extends keyof StageEvents>(event: K, handler: (payload: StageEvents[K]) => void): () => void {\n\t\treturn this.eventDelegate.listen(event, handler);\n\t}\n\n\t/**\n\t * Clean up stage resources including event subscriptions.\n\t */\n\tdispose(): void {\n\t\tthis.eventDelegate.dispose();\n\t}\n}\n\n/**\n * Create a stage with optional camera\n */\nexport function createStage(...options: StageOptions): Stage {\n\tconst _options = getStageOptions(options);\n\treturn new Stage([..._options] as StageOptions);\n}","import { proxy } from 'valtio/vanilla';\nimport { createStage, Stage } from '../stage/stage';\nimport type { BasicTypes, BaseGlobals, ZylemGameConfig, GameInputConfig } from './game-interfaces';\n\ntype InitialDefaults = Partial<ZylemGameConfig<Stage, any, BaseGlobals>>;\n/**\n * Reactive defaults for building `Game` instances. These values are applied\n * automatically by the `game()` builder via `convertNodes` and can be changed\n * at runtime to influence future game creations.\n */\nconst initialDefaults: () => InitialDefaults = (): InitialDefaults => {\n\treturn {\n\t\tid: 'zylem',\n\t\tglobals: {} as BaseGlobals,\n\t\tstages: [createStage()],\n\t\tdebug: false,\n\t\ttime: 0,\n\t\tinput: undefined,\n\t};\n}\n\nconst gameDefaultsState = proxy<Partial<ZylemGameConfig<Stage, any, BaseGlobals>>>(\n\t{ ...initialDefaults() }\n);\n\n/**\n * Get a plain object copy of the current defaults.\n */\nexport function getGameDefaultConfig<TGlobals extends Record<string, BasicTypes> = BaseGlobals>(): {\n\tid: string;\n\tglobals: TGlobals;\n\tstages: Stage[];\n\tdebug?: boolean;\n\ttime?: number;\n\tinput?: GameInputConfig;\n} {\n\treturn {\n\t\tid: (gameDefaultsState.id as string) ?? 'zylem',\n\t\tglobals: (gameDefaultsState.globals as TGlobals) ?? ({} as unknown as TGlobals),\n\t\tstages: (gameDefaultsState.stages as Stage[]) ?? [createStage()],\n\t\tdebug: gameDefaultsState.debug,\n\t\ttime: gameDefaultsState.time,\n\t\tinput: gameDefaultsState.input,\n\t};\n}\n\n\n","import { BaseNode } from '../base-node';\nimport { Stage } from '../../stage/stage';\nimport { GameEntity, GameEntityLifeCycle } from '../../entities/entity';\nimport { BaseGlobals, ZylemGameConfig, GameInputConfig } from '../../game/game-interfaces';\nimport { GameConfigLike } from '~/lib/game/game-config';\n\n// export function isStageContext(value: unknown): value is StageContext {\n// \treturn !!value && typeof value === 'object' && 'instance' in (value as any) && 'stageBlueprint' in (value as any);\n// }\n\nexport type GameOptions<TGlobals extends BaseGlobals> = Array<\n\tZylemGameConfig<Stage, any, TGlobals> |\n\tGameConfigLike |\n\tStage |\n\tGameEntityLifeCycle |\n\tBaseNode\n>;\n\n/** \n * TODO: need to revisit the way configurations are handled\n * \n * - default config is applied first\n * - then only one config should be allowed. \n * - if multiple configs are provided, the last one is used\n * - then any nodes provided are applied\n * \n **/\n\nexport async function convertNodes<TGlobals extends BaseGlobals>(\n\t_options: GameOptions<TGlobals>\n): Promise<{ id: string, globals: TGlobals, stages: Stage[], input?: GameInputConfig }> {\n\tconst { getGameDefaultConfig } = await import('../../game/game-default');\n\tlet convertedDefault = { ...getGameDefaultConfig<TGlobals>() } as { id: string, globals: TGlobals, stages: Stage[], input?: GameInputConfig };\n\tconst configurations: ZylemGameConfig<Stage, any, TGlobals>[] = [];\n\tconst stages: Stage[] = [];\n\tconst entities: (BaseNode | GameEntity<any>)[] = [];\n\n\tObject.values(_options).forEach((node) => {\n\t\tif (node instanceof Stage) {\n\t\t\tstages.push(node);\n\t\t} else if (node instanceof GameEntity) {\n\t\t\tentities.push(node);\n\t\t} else if (node instanceof BaseNode) {\n\t\t\tentities.push(node);\n\t\t} else if ((node as any)?.constructor?.name === 'Object' && typeof node === 'object') {\n\t\t\tconst configuration = Object.assign({ ...getGameDefaultConfig<TGlobals>() }, { ...node });\n\t\t\tconfigurations.push(configuration as ZylemGameConfig<Stage, any, TGlobals>);\n\t\t}\n\t});\n\n\tconfigurations.forEach((configuration) => {\n\t\tconvertedDefault = Object.assign(convertedDefault, { ...configuration });\n\t});\n\n\tconst converted = convertedDefault;\n\tconverted.input = configurations[0].input;\n\t\n\tstages.forEach((stageInstance) => {\n\t\tstageInstance.addEntities(entities as BaseNode[]);\n\t});\n\tif (stages.length) {\n\t\tconverted.stages = stages;\n\t} else {\n\t\tconverted.stages[0].addEntities(entities as BaseNode[]);\n\t}\n\treturn converted as unknown as { id: string, globals: TGlobals, stages: Stage[], input?: GameInputConfig };\n}\n\nexport function hasStages<TGlobals extends BaseGlobals>(_options: GameOptions<TGlobals>): Boolean {\n\tconst stage = _options.find(option => option instanceof Stage);\n\treturn Boolean(stage);\n}\n\n/**\n * Extract globals object from game options array.\n * Used to initialize globals before game starts.\n */\nexport function extractGlobalsFromOptions<TGlobals extends BaseGlobals>(\n\t_options: GameOptions<TGlobals>\n): TGlobals | undefined {\n\tfor (const option of _options) {\n\t\tif (option && typeof option === 'object' && !(option instanceof Stage) && !(option instanceof BaseNode) && !(option instanceof GameEntity)) {\n\t\t\tconst config = option as ZylemGameConfig<Stage, any, TGlobals>;\n\t\t\tif (config.globals) {\n\t\t\t\treturn config.globals;\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}","import { proxy } from 'valtio/vanilla';\nimport { get, set } from 'idb-keyval';\nimport { pack, unpack } from 'msgpackr';\nimport { StageBlueprint } from '../core/blueprints';\n\n// The State\nexport const stageState = proxy({\n previous: null as StageBlueprint | null,\n current: null as StageBlueprint | null,\n next: null as StageBlueprint | null,\n isLoading: false,\n});\n\n// The Logic\nexport const StageManager = {\n staticRegistry: new Map<string, StageBlueprint>(),\n\n registerStaticStage(id: string, blueprint: StageBlueprint) {\n this.staticRegistry.set(id, blueprint);\n },\n\n async loadStageData(stageId: string): Promise<StageBlueprint> {\n // 1. Check Local Storage (User Save)\n try {\n const saved = await get(stageId);\n if (saved) {\n // msgpackr returns a buffer, we need to unpack it\n return unpack(saved);\n }\n } catch (e) {\n console.warn(`Failed to load stage ${stageId} from storage`, e);\n }\n\n // 2. Fallback to Static File (Initial Load)\n if (this.staticRegistry.has(stageId)) {\n return this.staticRegistry.get(stageId)!;\n }\n\n // Note: This assumes a convention where stages are importable.\n // You might need a registry or a specific path structure.\n // For now, we'll assume a dynamic import from a known location or a registry.\n // Since dynamic imports with variables can be tricky in bundlers, \n // we might need a map of stage IDs to import functions if the path isn't static enough.\n \n // TODO: Implement a robust way to resolve stage paths.\n // For now, throwing an error if not found in storage, as the static loading strategy \n // depends on project structure.\n throw new Error(`Stage ${stageId} not found in storage and static loading not fully implemented.`);\n },\n\n async transitionForward(nextStageId: string, loadStaticStage?: (id: string) => Promise<StageBlueprint>) {\n if (stageState.isLoading) return;\n \n stageState.isLoading = true;\n\n try {\n // Save current state to disk before unloading\n if (stageState.current) {\n await set(stageState.current.id, pack(stageState.current));\n }\n\n // Shift Window\n stageState.previous = stageState.current;\n stageState.current = stageState.next;\n \n // If we don't have a next stage preloaded (or if we just shifted it to current),\n // we might need to load the *new* next stage. \n // But the architecture doc says \"Fetch new Next\".\n // Let's assume we want to load the requested nextStageId as the *new Current* \n // if it wasn't already in 'next'. \n // Actually, the sliding window usually implies we move towards 'next'.\n // If 'next' was already populated with nextStageId, we just move it to 'current'.\n \n if (stageState.current?.id !== nextStageId) {\n // If the shift didn't result in the desired stage (e.g. we jumped), load it directly.\n // Or if 'next' was null.\n if (loadStaticStage) {\n stageState.current = await loadStaticStage(nextStageId);\n } else {\n stageState.current = await this.loadStageData(nextStageId);\n }\n }\n\n // Ideally we would pre-fetch the stage *after* this one into 'next'.\n // But we don't know what comes after 'nextStageId' without a map.\n // For now, we leave 'next' null or let the game logic trigger a preload.\n stageState.next = null; \n \n } catch (error) {\n console.error(\"Failed to transition stage:\", error);\n } finally {\n stageState.isLoading = false;\n }\n },\n \n /**\n * Manually set the next stage to pre-load it.\n */\n async preloadNext(stageId: string, loadStaticStage?: (id: string) => Promise<StageBlueprint>) {\n if (loadStaticStage) {\n stageState.next = await loadStaticStage(stageId);\n } else {\n stageState.next = await this.loadStageData(stageId);\n }\n }\n};\n","import { GameEntity, GameEntityOptions } from '../entity';\nimport { MeshStandardMaterial, MeshBasicMaterial, MeshPhongMaterial } from 'three';\n\n/**\n * Interface for entities that provide custom debug information\n */\nexport interface DebugInfoProvider {\n\tgetDebugInfo(): Record<string, any>;\n}\n\n/**\n * Helper to check if an object implements DebugInfoProvider\n */\nfunction hasDebugInfo(obj: any): obj is DebugInfoProvider {\n\treturn obj && typeof obj.getDebugInfo === 'function';\n}\n\n/**\n * Debug delegate that provides debug information for entities\n */\nexport class DebugDelegate {\n\tprivate entity: GameEntity<any>;\n\n\tconstructor(entity: GameEntity<any>) {\n\t\tthis.entity = entity;\n\t}\n\n\t/**\n\t * Get formatted position string\n\t */\n\tprivate getPositionString(): string {\n\t\tif (this.entity.mesh) {\n\t\t\tconst { x, y, z } = this.entity.mesh.position;\n\t\t\treturn `${x.toFixed(2)}, ${y.toFixed(2)}, ${z.toFixed(2)}`;\n\t\t}\n\t\tconst { x, y, z } = this.entity.options.position || { x: 0, y: 0, z: 0 };\n\t\treturn `${x.toFixed(2)}, ${y.toFixed(2)}, ${z.toFixed(2)}`;\n\t}\n\n\t/**\n\t * Get formatted rotation string (in degrees)\n\t */\n\tprivate getRotationString(): string {\n\t\tif (this.entity.mesh) {\n\t\t\tconst { x, y, z } = this.entity.mesh.rotation;\n\t\t\tconst toDeg = (rad: number) => (rad * 180 / Math.PI).toFixed(1);\n\t\t\treturn `${toDeg(x)}°, ${toDeg(y)}°, ${toDeg(z)}°`;\n\t\t}\n\t\tconst { x, y, z } = this.entity.options.rotation || { x: 0, y: 0, z: 0 };\n\t\tconst toDeg = (rad: number) => (rad * 180 / Math.PI).toFixed(1);\n\t\treturn `${toDeg(x)}°, ${toDeg(y)}°, ${toDeg(z)}°`;\n\t}\n\n\t/**\n\t * Get material information\n\t */\n\tprivate getMaterialInfo(): Record<string, any> {\n\t\tif (!this.entity.mesh || !this.entity.mesh.material) {\n\t\t\treturn { type: 'none' };\n\t\t}\n\n\t\tconst material = Array.isArray(this.entity.mesh.material)\n\t\t\t? this.entity.mesh.material[0]\n\t\t\t: this.entity.mesh.material;\n\n\t\tconst info: Record<string, any> = {\n\t\t\ttype: material.type\n\t\t};\n\n\t\tif (material instanceof MeshStandardMaterial ||\n\t\t\tmaterial instanceof MeshBasicMaterial ||\n\t\t\tmaterial instanceof MeshPhongMaterial) {\n\t\t\tinfo.color = `#${material.color.getHexString()}`;\n\t\t\tinfo.opacity = material.opacity;\n\t\t\tinfo.transparent = material.transparent;\n\t\t}\n\n\t\tif ('roughness' in material) {\n\t\t\tinfo.roughness = material.roughness;\n\t\t}\n\n\t\tif ('metalness' in material) {\n\t\t\tinfo.metalness = material.metalness;\n\t\t}\n\n\t\treturn info;\n\t}\n\n\tprivate getPhysicsInfo(): Record<string, any> | null {\n\t\tif (!this.entity.body) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst info: Record<string, any> = {\n\t\t\ttype: this.entity.body.bodyType(),\n\t\t\tmass: this.entity.body.mass(),\n\t\t\tisEnabled: this.entity.body.isEnabled(),\n\t\t\tisSleeping: this.entity.body.isSleeping()\n\t\t};\n\n\t\tconst velocity = this.entity.body.linvel();\n\t\tinfo.velocity = `${velocity.x.toFixed(2)}, ${velocity.y.toFixed(2)}, ${velocity.z.toFixed(2)}`;\n\n\t\treturn info;\n\t}\n\n\tpublic buildDebugInfo(): Record<string, any> {\n\t\tconst defaultInfo: Record<string, any> = {\n\t\t\tname: this.entity.name || this.entity.uuid,\n\t\t\tuuid: this.entity.uuid,\n\t\t\tposition: this.getPositionString(),\n\t\t\trotation: this.getRotationString(),\n\t\t\tmaterial: this.getMaterialInfo()\n\t\t};\n\n\t\tconst physicsInfo = this.getPhysicsInfo();\n\t\tif (physicsInfo) {\n\t\t\tdefaultInfo.physics = physicsInfo;\n\t\t}\n\n\t\tif (this.entity.behaviors.length > 0) {\n\t\t\tdefaultInfo.behaviors = this.entity.behaviors.map(b => b.constructor.name);\n\t\t}\n\n\t\tif (hasDebugInfo(this.entity)) {\n\t\t\tconst customInfo = this.entity.getDebugInfo();\n\t\t\treturn { ...defaultInfo, ...customInfo };\n\t\t}\n\n\t\treturn defaultInfo;\n\t}\n}\n\nclass EnhancedDebugInfoBuilder {\n\tprivate customBuilder?: (options: GameEntityOptions) => Record<string, any>;\n\n\tconstructor(customBuilder?: (options: GameEntityOptions) => Record<string, any>) {\n\t\tthis.customBuilder = customBuilder;\n\t}\n\n\tbuildInfo(options: GameEntityOptions, entity?: GameEntity<any>): Record<string, any> {\n\t\tif (this.customBuilder) {\n\t\t\treturn this.customBuilder(options);\n\t\t}\n\n\t\tif (entity) {\n\t\t\tconst delegate = new DebugDelegate(entity);\n\t\t\treturn delegate.buildDebugInfo();\n\t\t}\n\n\t\tconst { x, y, z } = options.position || { x: 0, y: 0, z: 0 };\n\t\treturn {\n\t\t\tname: (options as any).name || 'unnamed',\n\t\t\tposition: `${x.toFixed(2)}, ${y.toFixed(2)}, ${z.toFixed(2)}`\n\t\t};\n\t}\n}\n","import { Color, Group, Sprite as ThreeSprite, SpriteMaterial, CanvasTexture, LinearFilter, Vector2, PerspectiveCamera, OrthographicCamera, ClampToEdgeWrapping } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { createEntity } from './create';\nimport { UpdateContext, SetupContext } from '../core/base-node-life-cycle';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { DebugDelegate } from './delegates/debug';\n\ntype ZylemTextOptions = GameEntityOptions & {\n\ttext?: string;\n\tfontFamily?: string;\n\tfontSize?: number;\n\tfontColor?: Color | string;\n\tbackgroundColor?: Color | string | null;\n\tpadding?: number;\n\tstickToViewport?: boolean;\n\tscreenPosition?: Vector2;\n\tzDistance?: number;\n};\n\nconst textDefaults: ZylemTextOptions = {\n\tposition: undefined,\n\ttext: '',\n\tfontFamily: 'Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace',\n\tfontSize: 18,\n\tfontColor: '#FFFFFF',\n\tbackgroundColor: null,\n\tpadding: 4,\n\tstickToViewport: true,\n\tscreenPosition: new Vector2(24, 24),\n\tzDistance: 1,\n};\n\nexport class TextBuilder extends EntityBuilder<ZylemText, ZylemTextOptions> {\n\tprotected createEntity(options: Partial<ZylemTextOptions>): ZylemText {\n\t\treturn new ZylemText(options);\n\t}\n}\n\nexport const TEXT_TYPE = Symbol('Text');\n\nexport class ZylemText extends GameEntity<ZylemTextOptions> {\n\tstatic type = TEXT_TYPE;\n\n\tprivate _sprite: ThreeSprite | null = null;\n\tprivate _texture: CanvasTexture | null = null;\n\tprivate _canvas: HTMLCanvasElement | null = null;\n\tprivate _ctx: CanvasRenderingContext2D | null = null;\n\tprivate _cameraRef: ZylemCamera | null = null;\n\tprivate _lastCanvasW: number = 0;\n\tprivate _lastCanvasH: number = 0;\n\n\tconstructor(options?: ZylemTextOptions) {\n\t\tsuper();\n\t\tthis.options = { ...textDefaults, ...options } as ZylemTextOptions;\n\t\t// Add text-specific lifecycle callbacks (only registered once)\n\t\tthis.prependSetup(this.textSetup.bind(this) as any);\n\t\tthis.prependUpdate(this.textUpdate.bind(this) as any);\n\t\tthis.onDestroy(this.textDestroy.bind(this) as any);\n\t}\n\n\tpublic create(): this {\n\t\t// Clear previous state to prevent issues on reload\n\t\tthis._sprite = null;\n\t\tthis._texture = null;\n\t\tthis._canvas = null;\n\t\tthis._ctx = null;\n\t\tthis._lastCanvasW = 0;\n\t\tthis._lastCanvasH = 0;\n\t\tthis.group = new Group();\n\t\t\n\t\t// Recreate the sprite\n\t\tthis.createSprite();\n\t\t\n\t\t// Call parent create\n\t\treturn super.create();\n\t}\n\n\tprivate createSprite() {\n\t\tthis._canvas = document.createElement('canvas');\n\t\tthis._ctx = this._canvas.getContext('2d');\n\t\tthis._texture = new CanvasTexture(this._canvas);\n\t\tthis._texture.minFilter = LinearFilter;\n\t\tthis._texture.magFilter = LinearFilter;\n\t\tconst material = new SpriteMaterial({\n\t\t\tmap: this._texture,\n\t\t\ttransparent: true,\n\t\t\tdepthTest: false,\n\t\t\tdepthWrite: false,\n\t\t\talphaTest: 0.5,\n\t\t});\n\t\tthis._sprite = new ThreeSprite(material);\n\t\tthis.group?.add(this._sprite);\n\t\tthis.redrawText(this.options.text ?? '');\n\t}\n\n\tprivate measureAndResizeCanvas(text: string, fontSize: number, fontFamily: string, padding: number) {\n\t\tif (!this._canvas || !this._ctx) return { sizeChanged: false };\n\t\tthis._ctx.font = `${fontSize}px ${fontFamily}`;\n\t\tconst metrics = this._ctx.measureText(text);\n\t\tconst textWidth = Math.ceil(metrics.width);\n\t\tconst textHeight = Math.ceil(fontSize * 1.4);\n\t\tconst nextW = Math.max(2, textWidth + padding * 2);\n\t\tconst nextH = Math.max(2, textHeight + padding * 2);\n\t\tconst sizeChanged = nextW !== this._lastCanvasW || nextH !== this._lastCanvasH;\n\t\tthis._canvas.width = nextW;\n\t\tthis._canvas.height = nextH;\n\t\tthis._lastCanvasW = nextW;\n\t\tthis._lastCanvasH = nextH;\n\t\treturn { sizeChanged };\n\t}\n\n\tprivate drawCenteredText(text: string, fontSize: number, fontFamily: string) {\n\t\tif (!this._canvas || !this._ctx) return;\n\t\tthis._ctx.font = `${fontSize}px ${fontFamily}`;\n\t\tthis._ctx.textAlign = 'center';\n\t\tthis._ctx.textBaseline = 'middle';\n\t\tthis._ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);\n\t\tif (this.options.backgroundColor) {\n\t\t\tthis._ctx.fillStyle = this.toCssColor(this.options.backgroundColor);\n\t\t\tthis._ctx.fillRect(0, 0, this._canvas.width, this._canvas.height);\n\t\t}\n\t\tthis._ctx.fillStyle = this.toCssColor(this.options.fontColor ?? '#FFFFFF');\n\t\tthis._ctx.fillText(text, this._canvas.width / 2, this._canvas.height / 2);\n\t}\n\n\tprivate updateTexture(sizeChanged: boolean) {\n\t\tif (!this._texture || !this._canvas) return;\n\t\tif (sizeChanged) {\n\t\t\tthis._texture.dispose();\n\t\t\tthis._texture = new CanvasTexture(this._canvas);\n\t\t\tthis._texture.minFilter = LinearFilter;\n\t\t\tthis._texture.magFilter = LinearFilter;\n\t\t\tthis._texture.wrapS = ClampToEdgeWrapping;\n\t\t\tthis._texture.wrapT = ClampToEdgeWrapping;\n\t\t}\n\t\tthis._texture.image = this._canvas;\n\t\tthis._texture.needsUpdate = true;\n\t\tif (this._sprite && this._sprite.material) {\n\t\t\t(this._sprite.material as any).map = this._texture;\n\t\t\tthis._sprite.material.needsUpdate = true;\n\t\t}\n\t}\n\n\tprivate redrawText(_text: string) {\n\t\tif (!this._canvas || !this._ctx) return;\n\t\tconst fontSize = this.options.fontSize ?? 18;\n\t\tconst fontFamily = this.options.fontFamily ?? (textDefaults.fontFamily as string);\n\t\tconst padding = this.options.padding ?? 4;\n\n\t\tconst { sizeChanged } = this.measureAndResizeCanvas(_text, fontSize, fontFamily, padding);\n\t\tthis.drawCenteredText(_text, fontSize, fontFamily);\n\t\tthis.updateTexture(Boolean(sizeChanged));\n\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tprivate toCssColor(color: Color | string): string {\n\t\tif (typeof color === 'string') return color;\n\t\tconst c = color instanceof Color ? color : new Color(color as any);\n\t\treturn `#${c.getHexString()}`;\n\t}\n\n\tprivate textSetup(params: SetupContext<ZylemTextOptions>) {\n\t\tthis._cameraRef = (params.camera as unknown) as ZylemCamera | null;\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\t(this._cameraRef.camera as any).add(this.group);\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tprivate textUpdate(params: UpdateContext<ZylemTextOptions>) {\n\t\tif (!this._sprite) return;\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tprivate getResolution() {\n\t\treturn {\n\t\t\twidth: this._cameraRef?.screenResolution.x ?? 1,\n\t\t\theight: this._cameraRef?.screenResolution.y ?? 1,\n\t\t};\n\t}\n\n\tprivate getScreenPixels(sp: Vector2, width: number, height: number) {\n\t\tconst isPercentX = sp.x >= 0 && sp.x <= 1;\n\t\tconst isPercentY = sp.y >= 0 && sp.y <= 1;\n\t\treturn {\n\t\t\tpx: isPercentX ? sp.x * width : sp.x,\n\t\t\tpy: isPercentY ? sp.y * height : sp.y,\n\t\t};\n\t}\n\n\tprivate computeWorldExtents(camera: PerspectiveCamera | OrthographicCamera, zDist: number) {\n\t\tlet worldHalfW = 1;\n\t\tlet worldHalfH = 1;\n\t\tif ((camera as PerspectiveCamera).isPerspectiveCamera) {\n\t\t\tconst pc = camera as PerspectiveCamera;\n\t\t\tconst halfH = Math.tan((pc.fov * Math.PI) / 180 / 2) * zDist;\n\t\t\tconst halfW = halfH * pc.aspect;\n\t\t\tworldHalfW = halfW;\n\t\t\tworldHalfH = halfH;\n\t\t} else if ((camera as OrthographicCamera).isOrthographicCamera) {\n\t\t\tconst oc = camera as OrthographicCamera;\n\t\t\tworldHalfW = (oc.right - oc.left) / 2;\n\t\t\tworldHalfH = (oc.top - oc.bottom) / 2;\n\t\t}\n\t\treturn { worldHalfW, worldHalfH };\n\t}\n\n\tprivate updateSpriteScale(worldHalfH: number, viewportHeight: number) {\n\t\tif (!this._canvas || !this._sprite) return;\n\t\tconst planeH = worldHalfH * 2;\n\t\tconst unitsPerPixel = planeH / viewportHeight;\n\t\tconst pixelH = this._canvas.height;\n\t\tconst scaleY = Math.max(0.0001, pixelH * unitsPerPixel);\n\t\tconst aspect = this._canvas.width / this._canvas.height;\n\t\tconst scaleX = scaleY * aspect;\n\t\tthis._sprite.scale.set(scaleX, scaleY, 1);\n\t}\n\n\tprivate updateStickyTransform() {\n\t\tif (!this._sprite || !this._cameraRef) return;\n\t\tconst camera = this._cameraRef.camera as PerspectiveCamera | OrthographicCamera;\n\t\tconst { width, height } = this.getResolution();\n\t\tconst sp = this.options.screenPosition ?? new Vector2(24, 24);\n\t\tconst { px, py } = this.getScreenPixels(sp, width, height);\n\t\tconst zDist = Math.max(0.001, this.options.zDistance ?? 1);\n\t\tconst { worldHalfW, worldHalfH } = this.computeWorldExtents(camera, zDist);\n\n\t\tconst ndcX = (px / width) * 2 - 1;\n\t\tconst ndcY = 1 - (py / height) * 2;\n\t\tconst localX = ndcX * worldHalfW;\n\t\tconst localY = ndcY * worldHalfH;\n\t\tthis.group?.position.set(localX, localY, -zDist);\n\t\tthis.updateSpriteScale(worldHalfH, height);\n\t}\n\n\tupdateText(_text: string) {\n\t\tthis.options.text = _text;\n\t\tthis.redrawText(_text);\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tbuildInfo(): Record<string, any> {\n\t\tconst delegate = new DebugDelegate(this as any);\n\t\tconst baseInfo = delegate.buildDebugInfo();\n\n\t\treturn {\n\t\t\t...baseInfo,\n\t\t\ttype: String(ZylemText.type),\n\t\t\ttext: this.options.text ?? '',\n\t\t\tsticky: this.options.stickToViewport,\n\t\t};\n\t}\n\n\t/**\n\t * Dispose of Three.js resources when the entity is destroyed.\n\t */\n\tprivate textDestroy(): void {\n\t\t// Dispose texture\n\t\tthis._texture?.dispose();\n\t\t\n\t\t// Dispose sprite material\n\t\tif (this._sprite?.material) {\n\t\t\t(this._sprite.material as SpriteMaterial).dispose();\n\t\t}\n\t\t\n\t\t// Remove sprite from group\n\t\tif (this._sprite) {\n\t\t\tthis._sprite.removeFromParent();\n\t\t}\n\t\t\n\t\t// Remove group from parent (camera or scene)\n\t\tthis.group?.removeFromParent();\n\t\t\n\t\t// Clear references\n\t\tthis._sprite = null;\n\t\tthis._texture = null;\n\t\tthis._canvas = null;\n\t\tthis._ctx = null;\n\t\tthis._cameraRef = null;\n\t}\n}\n\ntype TextOptions = BaseNode | Partial<ZylemTextOptions>;\n\nexport function createText(...args: Array<TextOptions>): ZylemText {\n\treturn createEntity<ZylemText, ZylemTextOptions>({\n\t\targs,\n\t\tdefaultConfig: { ...textDefaults },\n\t\tEntityClass: ZylemText,\n\t\tBuilderClass: TextBuilder,\n\t\tentityType: ZylemText.type,\n\t});\n}\n\n\n","import { ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { Color, Euler, Group, Quaternion, Vector3 } from 'three';\nimport {\n\tTextureLoader,\n\tSpriteMaterial,\n\tSprite as ThreeSprite,\n} from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { createEntity } from './create';\nimport { DestroyContext, DestroyFunction, UpdateContext, UpdateFunction } from '../core/base-node-life-cycle';\nimport { DebugDelegate } from './delegates/debug';\nimport { standardShader } from '../graphics/shaders/standard.shader';\n\nexport type SpriteImage = { name: string; file: string };\nexport type SpriteAnimation = {\n\tname: string;\n\tframes: string[];\n\tspeed: number | number[];\n\tloop: boolean;\n};\n\ntype ZylemSpriteOptions = GameEntityOptions & {\n\timages?: SpriteImage[];\n\tanimations?: SpriteAnimation[];\n\tsize?: Vector3;\n\tcollisionSize?: Vector3;\n};\n\nimport { commonDefaults } from './common';\n\nconst spriteDefaults: ZylemSpriteOptions = {\n\t...commonDefaults,\n\tsize: new Vector3(1, 1, 1),\n\timages: [],\n\tanimations: [],\n};\n\nexport class SpriteCollisionBuilder extends EntityCollisionBuilder {\n\tcollider(options: ZylemSpriteOptions): ColliderDesc {\n\t\tconst size = options.collisionSize || options.size || new Vector3(1, 1, 1);\n\t\tconst half = { x: size.x / 2, y: size.y / 2, z: size.z / 2 };\n\t\tlet colliderDesc = ColliderDesc.cuboid(half.x, half.y, half.z);\n\t\treturn colliderDesc;\n\t}\n}\n\nexport class SpriteBuilder extends EntityBuilder<ZylemSprite, ZylemSpriteOptions> {\n\tprotected createEntity(options: Partial<ZylemSpriteOptions>): ZylemSprite {\n\t\treturn new ZylemSprite(options);\n\t}\n}\n\nexport const SPRITE_TYPE = Symbol('Sprite');\n\nexport class ZylemSprite extends GameEntity<ZylemSpriteOptions> {\n\tstatic type = SPRITE_TYPE;\n\n\tprotected sprites: ThreeSprite[] = [];\n\tprotected spriteMap: Map<string, number> = new Map();\n\tprotected currentSpriteIndex: number = 0;\n\tprotected animations: Map<string, any> = new Map();\n\tprotected currentAnimation: any = null;\n\tprotected currentAnimationFrame: string = '';\n\tprotected currentAnimationIndex: number = 0;\n\tprotected currentAnimationTime: number = 0;\n\n\tconstructor(options?: ZylemSpriteOptions) {\n\t\tsuper();\n\t\tthis.options = { ...spriteDefaults, ...options };\n\t\t// Add sprite-specific lifecycle callbacks (only registered once)\n\t\tthis.prependUpdate(this.spriteUpdate.bind(this) as any);\n\t\tthis.onDestroy(this.spriteDestroy.bind(this) as any);\n\t}\n\n\tpublic create(): this {\n\t\t// Clear previous state to prevent accumulation on reload\n\t\tthis.sprites = [];\n\t\tthis.spriteMap.clear();\n\t\tthis.animations.clear();\n\t\tthis.currentAnimation = null;\n\t\tthis.currentAnimationFrame = '';\n\t\tthis.currentAnimationIndex = 0;\n\t\tthis.currentAnimationTime = 0;\n\t\tthis.group = undefined;\n\t\t\n\t\t// Recreate sprites and animations\n\t\tthis.createSpritesFromImages(this.options?.images || []);\n\t\tthis.createAnimations(this.options?.animations || []);\n\t\t\n\t\t// Call parent create\n\t\treturn super.create();\n\t}\n\n\tprotected createSpritesFromImages(images: SpriteImage[]) {\n\t\t// Use synchronous load() which returns a texture that updates when ready\n\t\t// This maintains compatibility with the synchronous create() method\n\t\tconst textureLoader = new TextureLoader();\n\t\timages.forEach((image, index) => {\n\t\t\tconst spriteMap = textureLoader.load(image.file);\n\t\t\tconst material = new SpriteMaterial({\n\t\t\t\tmap: spriteMap,\n\t\t\t\ttransparent: true,\n\t\t\t});\n\t\t\tconst _sprite = new ThreeSprite(material);\n\t\t\t_sprite.position.normalize();\n\t\t\tthis.sprites.push(_sprite);\n\t\t\tthis.spriteMap.set(image.name, index);\n\t\t});\n\t\tthis.group = new Group();\n\t\tthis.group.add(...this.sprites);\n\t}\n\n\tprotected createAnimations(animations: SpriteAnimation[]) {\n\t\tanimations.forEach(animation => {\n\t\t\tconst { name, frames, loop = false, speed = 1 } = animation;\n\t\t\tconst internalAnimation = {\n\t\t\t\tframes: frames.map((frame, index) => ({\n\t\t\t\t\tkey: frame,\n\t\t\t\t\tindex,\n\t\t\t\t\ttime: (typeof speed === 'number' ? speed : speed[index]) * (index + 1),\n\t\t\t\t\tduration: typeof speed === 'number' ? speed : speed[index]\n\t\t\t\t})),\n\t\t\t\tloop,\n\t\t\t};\n\t\t\tthis.animations.set(name, internalAnimation);\n\t\t});\n\t}\n\n\tsetSprite(key: string) {\n\t\tconst spriteIndex = this.spriteMap.get(key);\n\t\tconst useIndex = spriteIndex ?? 0;\n\t\tthis.currentSpriteIndex = useIndex;\n\t\tthis.sprites.forEach((_sprite, i) => {\n\t\t\t_sprite.visible = this.currentSpriteIndex === i;\n\t\t});\n\t}\n\n\tsetAnimation(name: string, delta: number) {\n\t\tconst animation = this.animations.get(name);\n\t\tif (!animation) return;\n\n\t\tconst { loop, frames } = animation;\n\t\tconst frame = frames[this.currentAnimationIndex];\n\n\t\tif (name === this.currentAnimation) {\n\t\t\tthis.currentAnimationFrame = frame.key;\n\t\t\tthis.currentAnimationTime += delta;\n\t\t\tthis.setSprite(this.currentAnimationFrame);\n\t\t} else {\n\t\t\tthis.currentAnimation = name;\n\t\t}\n\n\t\tif (this.currentAnimationTime > frame.time) {\n\t\t\tthis.currentAnimationIndex++;\n\t\t}\n\n\t\tif (this.currentAnimationIndex >= frames.length) {\n\t\t\tif (loop) {\n\t\t\t\tthis.currentAnimationIndex = 0;\n\t\t\t\tthis.currentAnimationTime = 0;\n\t\t\t} else {\n\t\t\t\tthis.currentAnimationTime = frames[this.currentAnimationIndex].time;\n\t\t\t}\n\t\t}\n\t}\n\n\tspriteUpdate(params: UpdateContext<ZylemSpriteOptions>): void {\n\t\tthis.sprites.forEach(_sprite => {\n\t\t\tif (_sprite.material) {\n\t\t\t\tconst q = this.body?.rotation();\n\t\t\t\tif (q) {\n\t\t\t\t\tconst quat = new Quaternion(q.x, q.y, q.z, q.w);\n\t\t\t\t\tconst euler = new Euler().setFromQuaternion(quat, 'XYZ');\n\t\t\t\t\t_sprite.material.rotation = euler.z;\n\t\t\t\t}\n\t\t\t\t_sprite.scale.set(this.options.size?.x ?? 1, this.options.size?.y ?? 1, this.options.size?.z ?? 1);\n\t\t\t}\n\t\t});\n\t}\n\n\tspriteDestroy(params: DestroyContext<ZylemSpriteOptions>): void {\n\t\tthis.sprites.forEach(_sprite => {\n\t\t\t_sprite.removeFromParent();\n\t\t});\n\t\tthis.group?.remove(...this.sprites);\n\t\tthis.group?.removeFromParent();\n\t}\n\n\tbuildInfo(): Record<string, any> {\n\t\tconst delegate = new DebugDelegate(this as any);\n\t\tconst baseInfo = delegate.buildDebugInfo();\n\t\treturn {\n\t\t\t...baseInfo,\n\t\t\ttype: String(ZylemSprite.type),\n\t\t};\n\t}\n}\n\ntype SpriteOptions = BaseNode | Partial<ZylemSpriteOptions>;\n\nexport function createSprite(...args: Array<SpriteOptions>): ZylemSprite {\n\treturn createEntity<ZylemSprite, ZylemSpriteOptions>({\n\t\targs,\n\t\tdefaultConfig: spriteDefaults,\n\t\tEntityClass: ZylemSprite,\n\t\tBuilderClass: SpriteBuilder,\n\t\tCollisionBuilderClass: SpriteCollisionBuilder,\n\t\tentityType: ZylemSprite.type\n\t});\n}","import { EntityBlueprint } from '../core/blueprints';\nimport { GameEntity, GameEntityOptions } from './entity';\nimport { createText } from './text';\nimport { createSprite } from './sprite';\n\ntype EntityCreator = (options: any) => GameEntity<any>;\n\nexport const EntityFactory = {\n registry: new Map<string, EntityCreator>(),\n\n register(type: string, creator: EntityCreator) {\n this.registry.set(type, creator);\n },\n\n createFromBlueprint(blueprint: EntityBlueprint): GameEntity<any> {\n const creator = this.registry.get(blueprint.type);\n if (!creator) {\n throw new Error(`Unknown entity type: ${blueprint.type}`);\n }\n\n const options: GameEntityOptions = {\n ...blueprint.data,\n position: blueprint.position ? { x: blueprint.position[0], y: blueprint.position[1], z: 0 } : undefined,\n name: blueprint.id,\n };\n\n const entity = creator(options);\n \n return entity;\n }\n};\n\nEntityFactory.register('text', (opts) => createText(opts) as unknown as GameEntity<any>);\nEntityFactory.register('sprite', (opts) => createSprite(opts) as unknown as GameEntity<any>);\n\n/**\n * Factory interface for generating entity copies\n */\nexport interface TemplateFactory<E extends GameEntity<O>, O extends GameEntityOptions = GameEntityOptions> {\n\t/** The template entity used for cloning */\n\treadonly template: E;\n\t\n\t/**\n\t * Generate multiple copies of the template entity\n\t * @param count Number of copies to generate\n\t * @returns Array of new entity instances\n\t */\n\tgenerate(count: number): E[];\n}\n\n/**\n * Create an entity factory from a template entity.\n * \n * @param template The entity to use as a template for cloning\n * @returns Factory object with generate() method\n * \n * @example\n * ```typescript\n * const asteroidTemplate = createSprite({ images: [{ name: 'asteroid', file: asteroidImg }] });\n * const asteroidFactory = createEntityFactory(asteroidTemplate);\n * const asteroids = asteroidFactory.generate(10);\n * \n * asteroids.forEach((asteroid, i) => {\n * asteroid.setPosition(Math.random() * 20 - 10, Math.random() * 15 - 7.5, 0);\n * stage.add(asteroid);\n * });\n * ```\n */\nexport function createEntityFactory<E extends GameEntity<O>, O extends GameEntityOptions = GameEntityOptions>(\n\ttemplate: E\n): TemplateFactory<E, O> {\n\treturn {\n\t\ttemplate,\n\t\t\n\t\tgenerate(count: number): E[] {\n\t\t\tconst entities: E[] = [];\n\t\t\t\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\t// Clone the template entity using its constructor and options\n\t\t\t\tconst EntityClass = template.constructor as new (options: O) => E;\n\t\t\t\tconst options = { ...template.options } as O;\n\t\t\t\tconst clone = new EntityClass(options).create() as E;\n\t\t\t\t\n\t\t\t\t// Copy behavior refs from template\n\t\t\t\tconst templateRefs = template.getBehaviorRefs();\n\t\t\t\tfor (const ref of templateRefs) {\n\t\t\t\t\tclone.use(ref.descriptor, ref.options);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// Copy lifecycle callbacks from template\n\t\t\t\tconst templateCallbacks = (template as any).lifecycleCallbacks;\n\t\t\t\tif (templateCallbacks) {\n\t\t\t\t\tconst cloneCallbacks = (clone as any).lifecycleCallbacks;\n\t\t\t\t\tif (cloneCallbacks) {\n\t\t\t\t\t\tcloneCallbacks.setup.push(...templateCallbacks.setup);\n\t\t\t\t\t\tcloneCallbacks.update.push(...templateCallbacks.update);\n\t\t\t\t\t\tcloneCallbacks.destroy.push(...templateCallbacks.destroy);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tentities.push(clone);\n\t\t\t}\n\t\t\t\n\t\t\treturn entities;\n\t\t}\n\t};\n}\n","import { StageBlueprint } from '../core/blueprints';\nimport { createStage, Stage } from './stage';\nimport { EntityFactory } from '../entities/entity-factory';\n\nexport const StageFactory = {\n async createFromBlueprint(blueprint: StageBlueprint): Promise<Stage> {\n // Create a new Stage instance\n // We might need to pass options from blueprint if StageSchema has them\n const stage = createStage({\n // Map blueprint properties to stage options if needed\n // e.g. name: blueprint.name\n });\n \n // Assign ID if possible, though Stage might generate its own UUID.\n // If we want to track it by blueprint ID, we might need to store it on the stage.\n // stage.id = blueprint.id; // Stage doesn't have public ID setter easily maybe?\n\n if (blueprint.entities) {\n for (const entityBlueprint of blueprint.entities) {\n try {\n const entity = await EntityFactory.createFromBlueprint(entityBlueprint);\n stage.add(entity);\n } catch (e) {\n console.error(`Failed to create entity ${entityBlueprint.id} for stage ${blueprint.id}`, e);\n }\n }\n }\n\n return stage;\n }\n};\n","import { ZylemGame, GameLoadingEvent } from './zylem-game';\nimport { DestroyFunction, SetupFunction, UpdateFunction } from '../core/base-node-life-cycle';\nimport { IGame } from '../core/interfaces';\nimport { setPaused } from '../debug/debug-state';\nimport { BaseGlobals } from './game-interfaces';\nimport { convertNodes, GameOptions, hasStages, extractGlobalsFromOptions } from '../core/utility/nodes';\nimport { resolveGameConfig } from './game-config';\nimport { createStage, Stage } from '../stage/stage';\nimport { StageManager, stageState } from '../stage/stage-manager';\nimport { StageFactory } from '../stage/stage-factory';\nimport { initGlobals, clearGlobalSubscriptions, resetGlobals, onGlobalChange as onGlobalChangeInternal, onGlobalChanges as onGlobalChangesInternal } from './game-state';\nimport { EventEmitterDelegate, zylemEventBus, type GameEvents } from '../events';\n\nexport class Game<TGlobals extends BaseGlobals> implements IGame<TGlobals> {\n\tprivate wrappedGame: ZylemGame<TGlobals> | null = null;\n\n\toptions: GameOptions<TGlobals>;\n\n\t// Lifecycle callback arrays\n\tprivate setupCallbacks: Array<SetupFunction<ZylemGame<TGlobals>, TGlobals>> = [];\n\tprivate updateCallbacks: Array<UpdateFunction<ZylemGame<TGlobals>, TGlobals>> = [];\n\tprivate destroyCallbacks: Array<DestroyFunction<ZylemGame<TGlobals>, TGlobals>> = [];\n\tprivate pendingLoadingCallbacks: Array<(event: GameLoadingEvent) => void> = [];\n\n\t// Game-scoped global change subscriptions\n\tprivate globalChangeCallbacks: Array<{ path: string; callback: (value: unknown, stage: Stage | null) => void }> = [];\n\tprivate globalChangesCallbacks: Array<{ paths: string[]; callback: (values: unknown[], stage: Stage | null) => void }> = [];\n\tprivate activeGlobalSubscriptions: Array<() => void> = [];\n\n\t// Event delegate for dispatch/listen API\n\tprivate eventDelegate = new EventEmitterDelegate<GameEvents>();\n\n\trefErrorMessage = 'lost reference to game';\n\n\tconstructor(options: GameOptions<TGlobals>) {\n\t\tthis.options = options;\n\t\tif (!hasStages(options)) {\n\t\t\tthis.options.push(createStage());\n\t\t}\n\t\t// Initialize globals immediately so onGlobalChange subscriptions work\n\t\tconst globals = extractGlobalsFromOptions(options);\n\t\tif (globals) {\n\t\t\tinitGlobals(globals as Record<string, unknown>);\n\t\t}\n\t}\n\n\t// Fluent API for adding lifecycle callbacks\n\tonSetup(...callbacks: Array<SetupFunction<ZylemGame<TGlobals>, TGlobals>>): this {\n\t\tthis.setupCallbacks.push(...callbacks);\n\t\treturn this;\n\t}\n\n\tonUpdate(...callbacks: Array<UpdateFunction<ZylemGame<TGlobals>, TGlobals>>): this {\n\t\tthis.updateCallbacks.push(...callbacks);\n\t\treturn this;\n\t}\n\n\tonDestroy(...callbacks: Array<DestroyFunction<ZylemGame<TGlobals>, TGlobals>>): this {\n\t\tthis.destroyCallbacks.push(...callbacks);\n\t\treturn this;\n\t}\n\n\tasync start(): Promise<this> {\n\t\t// Re-initialize globals for this game\n\t\tresetGlobals();\n\t\tconst globals = extractGlobalsFromOptions(this.options);\n\t\tif (globals) {\n\t\t\tinitGlobals(globals as Record<string, unknown>);\n\t\t}\n\t\t\n\t\tconst game = await this.load();\n\t\tthis.wrappedGame = game;\n\t\tthis.setOverrides();\n\t\tthis.registerGlobalSubscriptions();\n\t\tgame.start();\n\t\treturn this;\n\t}\n\n\tprivate async load(): Promise<ZylemGame<TGlobals>> {\n\t\tconst options = await convertNodes<TGlobals>(this.options);\n\t\tconst resolved = resolveGameConfig(options as any);\n\t\tconst game = new ZylemGame<TGlobals>({\n\t\t\t...options as any,\n\t\t\t...resolved as any,\n\t\t} as any, this);\n\t\t\n\t\t// Apply pending loading callbacks BEFORE loadStage so events are captured\n\t\tfor (const callback of this.pendingLoadingCallbacks) {\n\t\t\tgame.onLoading(callback);\n\t\t}\n\t\t\n\t\tawait game.loadStage(options.stages[0]);\n\t\treturn game;\n\t}\n\n\tprivate setOverrides() {\n\t\tif (!this.wrappedGame) {\n\t\t\tconsole.error(this.refErrorMessage);\n\t\t\treturn;\n\t\t}\n\t\t// Pass callback arrays to wrapped game\n\t\tthis.wrappedGame.customSetup = (params) => {\n\t\t\tthis.setupCallbacks.forEach(cb => cb(params));\n\t\t};\n\t\tthis.wrappedGame.customUpdate = (params) => {\n\t\t\tthis.updateCallbacks.forEach(cb => cb(params));\n\t\t};\n\t\tthis.wrappedGame.customDestroy = (params) => {\n\t\t\tthis.destroyCallbacks.forEach(cb => cb(params));\n\t\t};\n\t}\n\n\t/**\n\t * Subscribe to changes on a global value. Subscriptions are registered\n\t * when the game starts and cleaned up when disposed.\n\t * The callback receives the value and the current stage.\n\t * @example game.onGlobalChange('score', (val, stage) => console.log(val));\n\t */\n\tonGlobalChange<T = unknown>(path: string, callback: (value: T, stage: Stage | null) => void): this {\n\t\tthis.globalChangeCallbacks.push({ path, callback: callback as (value: unknown, stage: Stage | null) => void });\n\t\treturn this;\n\t}\n\n\t/**\n\t * Subscribe to changes on multiple global paths. Subscriptions are registered\n\t * when the game starts and cleaned up when disposed.\n\t * The callback receives the values and the current stage.\n\t * @example game.onGlobalChanges(['score', 'lives'], ([score, lives], stage) => console.log(score, lives));\n\t */\n\tonGlobalChanges<T extends unknown[] = unknown[]>(paths: string[], callback: (values: T, stage: Stage | null) => void): this {\n\t\tthis.globalChangesCallbacks.push({ paths, callback: callback as (values: unknown[], stage: Stage | null) => void });\n\t\treturn this;\n\t}\n\n\t/**\n\t * Register all stored global change callbacks.\n\t * Called internally during start().\n\t */\n\tprivate registerGlobalSubscriptions() {\n\t\tfor (const { path, callback } of this.globalChangeCallbacks) {\n\t\t\tconst unsub = onGlobalChangeInternal(path, (value) => {\n\t\t\t\tcallback(value, this.getCurrentStage());\n\t\t\t});\n\t\t\tthis.activeGlobalSubscriptions.push(unsub);\n\t\t}\n\t\tfor (const { paths, callback } of this.globalChangesCallbacks) {\n\t\t\tconst unsub = onGlobalChangesInternal(paths, (values) => {\n\t\t\t\tcallback(values, this.getCurrentStage());\n\t\t\t});\n\t\t\tthis.activeGlobalSubscriptions.push(unsub);\n\t\t}\n\t}\n\n\t/**\n\t * Get the current stage wrapper.\n\t */\n\tgetCurrentStage(): Stage | null {\n\t\treturn this.wrappedGame?.currentStage() ?? null;\n\t}\n\n\tasync pause() {\n\t\tsetPaused(true);\n\t}\n\n\tasync resume() {\n\t\tsetPaused(false);\n\t\tif (this.wrappedGame) {\n\t\t\tthis.wrappedGame.previousTimeStamp = 0;\n\t\t\tthis.wrappedGame.timer.reset();\n\t\t}\n\t}\n\n\t/**\n\t * Execute a single frame update.\n\t * Useful for testing or manual frame stepping.\n\t * @param deltaTime Optional delta time in seconds (defaults to 1/60)\n\t */\n\tstep(deltaTime: number = 1/60): void {\n\t\tif (!this.wrappedGame) {\n\t\t\tconsole.error(this.refErrorMessage);\n\t\t\treturn;\n\t\t}\n\t\tthis.wrappedGame.step(deltaTime);\n\t}\n\n\tasync reset() {\n\t\tif (!this.wrappedGame) {\n\t\t\tconsole.error(this.refErrorMessage);\n\t\t\treturn;\n\t\t}\n\t\tawait this.wrappedGame.loadStage(this.wrappedGame.stages[0]);\n\t}\n\n\tpreviousStage() {\n\t\tif (!this.wrappedGame) {\n\t\t\tconsole.error(this.refErrorMessage);\n\t\t\treturn;\n\t\t}\n\t\tconst currentStageId = this.wrappedGame.currentStageId;\n\t\tconst currentIndex = this.wrappedGame.stages.findIndex((s) => s.wrappedStage?.uuid === currentStageId);\n\t\tconst previousStage = this.wrappedGame.stages[currentIndex - 1];\n\t\tif (!previousStage) {\n\t\t\tconsole.error('previous stage called on first stage');\n\t\t\treturn;\n\t\t}\n\t\tthis.wrappedGame.loadStage(previousStage);\n\t}\n\n\tasync loadStageFromId(stageId: string) {\n\t\tif (!this.wrappedGame) {\n\t\t\tconsole.error(this.refErrorMessage);\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tconst blueprint = await StageManager.loadStageData(stageId);\n\t\t\tconst stage = await StageFactory.createFromBlueprint(blueprint);\n\t\t\tawait this.wrappedGame.loadStage(stage);\n\t\t\t\n\t\t\t// Update StageManager state\n\t\t\tstageState.current = blueprint;\n\t\t} catch (e) {\n\t\t\tconsole.error(`Failed to load stage ${stageId}`, e);\n\t\t}\n\t}\n\n\tnextStage() {\n\t\tif (!this.wrappedGame) {\n\t\t\tconsole.error(this.refErrorMessage);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\t// Try to use StageManager first if we have a next stage in state\n\t\tif (stageState.next) {\n\t\t\tconsole.log('next stage called');\n\t\t\tconst nextId = stageState.next.id;\n\t\t\tStageManager.transitionForward(nextId);\n\t\t\t// After transition, current is the new stage\n\t\t\tif (stageState.current) {\n\t\t\t\tStageFactory.createFromBlueprint(stageState.current).then((stage) => {\n\t\t\t\t\tthis.wrappedGame?.loadStage(stage);\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Fallback to legacy array-based navigation\n\t\tconst currentStageId = this.wrappedGame.currentStageId;\n\t\tconst currentIndex = this.wrappedGame.stages.findIndex((s) => s.wrappedStage?.uuid === currentStageId);\n\t\tconst nextStage = this.wrappedGame.stages[currentIndex + 1];\n\t\tif (!nextStage) {\n\t\t\tconsole.error('next stage called on last stage');\n\t\t\treturn;\n\t\t}\n\t\tthis.wrappedGame.loadStage(nextStage);\n\t}\n\n\tasync goToStage() { }\n\n\tasync end() { }\n\n\tdispose() {\n\t\t// Clear event delegate subscriptions\n\t\tthis.eventDelegate.dispose();\n\n\t\t// Clear game-specific subscriptions\n\t\tfor (const unsub of this.activeGlobalSubscriptions) {\n\t\t\tunsub();\n\t\t}\n\t\tthis.activeGlobalSubscriptions = [];\n\t\t\n\t\tif (this.wrappedGame) {\n\t\t\tthis.wrappedGame.dispose();\n\t\t}\n\t\t// Clear all remaining global subscriptions and reset globals\n\t\tclearGlobalSubscriptions();\n\t\tresetGlobals();\n\t}\n\n\t// ─────────────────────────────────────────────────────────────────────────────\n\t// Events API\n\t// ─────────────────────────────────────────────────────────────────────────────\n\n\t/**\n\t * Dispatch an event from the game.\n\t * Events are emitted both locally and to the global event bus.\n\t */\n\tdispatch<K extends keyof GameEvents>(event: K, payload: GameEvents[K]): void {\n\t\tthis.eventDelegate.dispatch(event, payload);\n\t\t// Emit to global bus for cross-package communication\n\t\t(zylemEventBus as any).emit(event, payload);\n\t}\n\n\t/**\n\t * Listen for events on this game instance.\n\t * @returns Unsubscribe function\n\t */\n\tlisten<K extends keyof GameEvents>(event: K, handler: (payload: GameEvents[K]) => void): () => void {\n\t\treturn this.eventDelegate.listen(event, handler);\n\t}\n\n\t/**\n\t * Subscribe to loading events from the game.\n\t * Events include stage context (stageName, stageIndex).\n\t * @param callback Invoked for each loading event\n\t * @returns Unsubscribe function\n\t */\n\tonLoading(callback: (event: GameLoadingEvent) => void): () => void {\n\t\tif (this.wrappedGame) {\n\t\t\treturn this.wrappedGame.onLoading(callback);\n\t\t}\n\t\t// Store callback to be applied when game is created\n\t\tthis.pendingLoadingCallbacks.push(callback);\n\t\treturn () => {\n\t\t\tthis.pendingLoadingCallbacks = this.pendingLoadingCallbacks.filter(c => c !== callback);\n\t\t\tif (this.wrappedGame) {\n\t\t\t\t// If already started, also unsubscribe from wrapped game\n\t\t\t\t// Note: this won't perfectly track existing subscriptions, but prevents future calls\n\t\t\t}\n\t\t};\n\t}\n}\n\n/**\n * create a new game\n * @param options GameOptions - Array of IGameOptions, Stage, GameEntity, or BaseNode objects\n * @param options.id Game name string (when using IGameOptions)\n * @param options.globals Game globals object (when using IGameOptions)\n * @param options.stages Array of stage objects (when using IGameOptions)\n * @returns Game\n */\nexport function createGame<TGlobals extends BaseGlobals>(...options: GameOptions<TGlobals>): Game<TGlobals> {\n\treturn new Game<TGlobals>(options);\n}","import { Euler, Quaternion, Vector2 } from \"three\";\nimport { GameEntity } from \"../entities\";\nimport { Stage } from \"./stage\";\n\nexport interface EntitySpawner {\n\tspawn: (stage: Stage, x: number, y: number) => Promise<GameEntity<any>>;\n\tspawnRelative: (source: any, stage: Stage, offset?: Vector2) => Promise<any | void>;\n}\n\nexport function entitySpawner(factory: (x: number, y: number) => Promise<any> | GameEntity<any>): EntitySpawner {\n\treturn {\n\t\tspawn: async (stage: Stage, x: number, y: number) => {\n\t\t\tconst instance = await Promise.resolve(factory(x, y));\n\t\t\tstage.add(instance);\n\t\t\treturn instance;\n\t\t},\n\t\tspawnRelative: async (source: any, stage: Stage, offset: Vector2 = new Vector2(0, 1)) => {\n\t\t\tif (!source.body) {\n\t\t\t\tconsole.warn('body missing for entity during spawnRelative');\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tconst { x, y, z } = source.body.translation();\n\t\t\tlet rz = (source as any)._rotation2DAngle ?? 0;\n\t\t\ttry {\n\t\t\t\tconst r = source.body.rotation();\n\t\t\t\tconst q = new Quaternion(r.x, r.y, r.z, r.w);\n\t\t\t\tconst e = new Euler().setFromQuaternion(q, 'XYZ');\n\t\t\t\trz = e.z;\n\t\t\t} catch { /* use fallback angle */ }\n\n\t\t\tconst offsetX = Math.sin(-rz) * (offset.x ?? 0);\n\t\t\tconst offsetY = Math.cos(-rz) * (offset.y ?? 0);\n\n\t\t\tconst instance = await Promise.resolve(factory(x + offsetX, y + offsetY));\n\t\t\tstage.add(instance);\n\t\t\treturn instance;\n\t\t}\n\t};\n}","import { BaseNode } from './base-node';\nimport {\n\tSetupContext,\n\tUpdateContext,\n\tDestroyContext,\n\tLoadedContext,\n\tCleanupContext,\n} from './base-node-life-cycle';\n\nconst VESSEL_TYPE = Symbol('vessel');\n\nexport class Vessel extends BaseNode<{}, Vessel> {\n\tstatic type = VESSEL_TYPE;\n\n\tprotected _setup(_params: SetupContext<this>): void { }\n\n\tprotected async _loaded(_params: LoadedContext<this>): Promise<void> { }\n\n\tprotected _update(_params: UpdateContext<this>): void { }\n\n\tprotected _destroy(_params: DestroyContext<this>): void { }\n\n\tprotected async _cleanup(_params: CleanupContext<this>): Promise<void> { }\n\n\tpublic create(): this {\n\t\treturn this;\n\t}\n}\n\nexport function vessel(...args: Array<BaseNode>): BaseNode<{}, Vessel> {\n\tconst instance = new Vessel();\n\targs.forEach(arg => instance.add(arg));\n\treturn instance as unknown as BaseNode<{}, Vessel>;\n}\n","import { ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { BoxGeometry, Color } from 'three';\nimport { Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { EntityMeshBuilder } from './builder';\nimport { DebugDelegate } from './delegates/debug';\nimport { createEntity } from './create';\n\ntype ZylemBoxOptions = GameEntityOptions;\n\nimport { commonDefaults } from './common';\n\nconst boxDefaults: ZylemBoxOptions = {\n\t...commonDefaults,\n\tsize: new Vector3(1, 1, 1),\n};\n\nexport class BoxCollisionBuilder extends EntityCollisionBuilder {\n\tcollider(options: GameEntityOptions): ColliderDesc {\n\t\tconst size = options.size || new Vector3(1, 1, 1);\n\t\tconst half = { x: size.x / 2, y: size.y / 2, z: size.z / 2 };\n\t\tlet colliderDesc = ColliderDesc.cuboid(half.x, half.y, half.z);\n\t\treturn colliderDesc;\n\t}\n}\n\nexport class BoxMeshBuilder extends EntityMeshBuilder {\n\tbuild(options: GameEntityOptions): BoxGeometry {\n\t\tconst size = options.size ?? new Vector3(1, 1, 1);\n\t\treturn new BoxGeometry(size.x, size.y, size.z);\n\t}\n}\n\nexport class BoxBuilder extends EntityBuilder<ZylemBox, ZylemBoxOptions> {\n\tprotected createEntity(options: Partial<ZylemBoxOptions>): ZylemBox {\n\t\treturn new ZylemBox(options);\n\t}\n}\n\nexport const BOX_TYPE = Symbol('Box');\n\nexport class ZylemBox extends GameEntity<ZylemBoxOptions> {\n\tstatic type = BOX_TYPE;\n\n\tconstructor(options?: ZylemBoxOptions) {\n\t\tsuper();\n\t\tthis.options = { ...boxDefaults, ...options };\n\t}\n\n\tbuildInfo(): Record<string, any> {\n\t\tconst delegate = new DebugDelegate(this as any);\n\t\tconst baseInfo = delegate.buildDebugInfo();\n\n\t\tconst { x: sizeX, y: sizeY, z: sizeZ } = this.options.size ?? { x: 1, y: 1, z: 1 };\n\t\treturn {\n\t\t\t...baseInfo,\n\t\t\ttype: String(ZylemBox.type),\n\t\t\tsize: `${sizeX}, ${sizeY}, ${sizeZ}`,\n\t\t};\n\t}\n}\n\ntype BoxOptions = BaseNode | ZylemBoxOptions;\n\nexport function createBox(...args: Array<BoxOptions>): ZylemBox {\n\treturn createEntity<ZylemBox, ZylemBoxOptions>({\n\t\targs,\n\t\tdefaultConfig: boxDefaults,\n\t\tEntityClass: ZylemBox,\n\t\tBuilderClass: BoxBuilder,\n\t\tMeshBuilderClass: BoxMeshBuilder,\n\t\tCollisionBuilderClass: BoxCollisionBuilder,\n\t\tentityType: ZylemBox.type\n\t});\n}","import { ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { Color, SphereGeometry } from 'three';\nimport { Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { EntityMeshBuilder } from './builder';\nimport { DebugDelegate } from './delegates/debug';\nimport { standardShader } from '../graphics/shaders/standard.shader';\nimport { createEntity } from './create';\n\ntype ZylemSphereOptions = GameEntityOptions & {\n\tradius?: number;\n};\n\nimport { commonDefaults } from './common';\n\nconst sphereDefaults: ZylemSphereOptions = {\n\t...commonDefaults,\n\tradius: 1,\n};\n\nexport class SphereCollisionBuilder extends EntityCollisionBuilder {\n\tcollider(options: ZylemSphereOptions): ColliderDesc {\n\t\tconst radius = options.radius ?? 1;\n\t\tlet colliderDesc = ColliderDesc.ball(radius);\n\t\treturn colliderDesc;\n\t}\n}\n\nexport class SphereMeshBuilder extends EntityMeshBuilder {\n\tbuild(options: ZylemSphereOptions): SphereGeometry {\n\t\tconst radius = options.radius ?? 1;\n\t\treturn new SphereGeometry(radius);\n\t}\n}\n\nexport class SphereBuilder extends EntityBuilder<ZylemSphere, ZylemSphereOptions> {\n\tprotected createEntity(options: Partial<ZylemSphereOptions>): ZylemSphere {\n\t\treturn new ZylemSphere(options);\n\t}\n}\n\nexport const SPHERE_TYPE = Symbol('Sphere');\n\nexport class ZylemSphere extends GameEntity<ZylemSphereOptions> {\n\tstatic type = SPHERE_TYPE;\n\n\tconstructor(options?: ZylemSphereOptions) {\n\t\tsuper();\n\t\tthis.options = { ...sphereDefaults, ...options };\n\t}\n\n\tbuildInfo(): Record<string, any> {\n\t\tconst delegate = new DebugDelegate(this as any);\n\t\tconst baseInfo = delegate.buildDebugInfo();\n\t\tconst radius = this.options.radius ?? 1;\n\t\treturn {\n\t\t\t...baseInfo,\n\t\t\ttype: String(ZylemSphere.type),\n\t\t\tradius: radius.toFixed(2),\n\t\t};\n\t}\n}\n\ntype SphereOptions = BaseNode | Partial<ZylemSphereOptions>;\n\nexport function createSphere(...args: Array<SphereOptions>): ZylemSphere {\n\treturn createEntity<ZylemSphere, ZylemSphereOptions>({\n\t\targs,\n\t\tdefaultConfig: sphereDefaults,\n\t\tEntityClass: ZylemSphere,\n\t\tBuilderClass: SphereBuilder,\n\t\tMeshBuilderClass: SphereMeshBuilder,\n\t\tCollisionBuilderClass: SphereCollisionBuilder,\n\t\tentityType: ZylemSphere.type\n\t});\n}","// @ts-nocheck\nimport { BufferGeometry, Float32BufferAttribute } from 'three';\n\nclass XZPlaneGeometry extends BufferGeometry {\n\n\tconstructor(width = 1, height = 1, widthSegments = 1, heightSegments = 1) {\n\n\t\tsuper();\n\n\t\tthis.type = 'XZPlaneGeometry';\n\n\t\tthis.parameters = {\n\t\t\twidth: width,\n\t\t\theight: height,\n\t\t\twidthSegments: widthSegments,\n\t\t\theightSegments: heightSegments\n\t\t};\n\n\t\tconst width_half = width / 2;\n\t\tconst height_half = height / 2;\n\n\t\tconst gridX = Math.floor(widthSegments);\n\t\tconst gridY = Math.floor(heightSegments);\n\n\t\tconst gridX1 = gridX + 1;\n\t\tconst gridY1 = gridY + 1;\n\n\t\tconst segment_width = width / gridX;\n\t\tconst segment_height = height / gridY;\n\n\t\tconst indices = [];\n\t\tconst vertices = [];\n\t\tconst normals = [];\n\t\tconst uvs = [];\n\n\t\tfor (let iy = 0; iy < gridY1; iy++) {\n\n\t\t\tconst z = iy * segment_height - height_half;\n\n\t\t\tfor (let ix = 0; ix < gridX1; ix++) {\n\n\t\t\t\tconst x = ix * segment_width - width_half;\n\n\t\t\t\tvertices.push(x, 0, z);\n\n\t\t\t\tnormals.push(0, 1, 0);\n\n\t\t\t\tuvs.push(ix / gridX);\n\t\t\t\tuvs.push(1 - (iy / gridY));\n\n\t\t\t}\n\n\t\t}\n\n\t\tfor (let iy = 0; iy < gridY; iy++) {\n\n\t\t\tfor (let ix = 0; ix < gridX; ix++) {\n\n\t\t\t\tconst a = ix + gridX1 * iy;\n\t\t\t\tconst b = ix + gridX1 * (iy + 1);\n\t\t\t\tconst c = (ix + 1) + gridX1 * (iy + 1);\n\t\t\t\tconst d = (ix + 1) + gridX1 * iy;\n\n\t\t\t\tindices.push(a, b, d);\n\t\t\t\tindices.push(b, c, d);\n\n\t\t\t}\n\n\t\t}\n\n\t\tthis.setIndex(indices);\n\t\tthis.setAttribute('position', new Float32BufferAttribute(vertices, 3));\n\t\tthis.setAttribute('normal', new Float32BufferAttribute(normals, 3));\n\t\tthis.setAttribute('uv', new Float32BufferAttribute(uvs, 2));\n\n\t}\n\n\tcopy(source) {\n\n\t\tsuper.copy(source);\n\n\t\tthis.parameters = Object.assign({}, source.parameters);\n\n\t\treturn this;\n\t}\n\n\tstatic fromJSON(data) {\n\t\treturn new XZPlaneGeometry(data.width, data.height, data.widthSegments, data.heightSegments);\n\t}\n\n}\n\nexport { XZPlaneGeometry };","import { ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { PlaneGeometry, Vector2, Vector3 } from 'three';\nimport { TexturePath } from '../graphics/material';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { EntityMeshBuilder } from './builder';\nimport { XZPlaneGeometry } from '../graphics/geometries/XZPlaneGeometry';\nimport { createEntity } from './create';\n\ntype ZylemPlaneOptions = GameEntityOptions & {\n\ttile?: Vector2;\n\trepeat?: Vector2;\n\ttexture?: TexturePath;\n\tsubdivisions?: number;\n\trandomizeHeight?: boolean;\n\theightMap?: number[];\n\theightScale?: number;\n};\n\nconst DEFAULT_SUBDIVISIONS = 4;\n\nimport { commonDefaults } from './common';\n\nconst planeDefaults: ZylemPlaneOptions = {\n\t...commonDefaults,\n\ttile: new Vector2(10, 10),\n\trepeat: new Vector2(1, 1),\n\tcollision: {\n\t\tstatic: true,\n\t},\n\tsubdivisions: DEFAULT_SUBDIVISIONS,\n\trandomizeHeight: false,\n\theightScale: 1,\n};\n\nexport class PlaneCollisionBuilder extends EntityCollisionBuilder {\n\tcollider(options: ZylemPlaneOptions): ColliderDesc {\n\t\tconst tile = options.tile ?? new Vector2(1, 1);\n\t\tconst subdivisions = options.subdivisions ?? DEFAULT_SUBDIVISIONS;\n\t\tconst size = new Vector3(tile.x, 1, tile.y);\n\n\t\tconst heightData = (options._builders?.meshBuilder as unknown as PlaneMeshBuilder)?.heightData;\n\t\tconst scale = new Vector3(size.x, 1, size.z);\n\t\tlet colliderDesc = ColliderDesc.heightfield(\n\t\t\tsubdivisions,\n\t\t\tsubdivisions,\n\t\t\theightData,\n\t\t\tscale\n\t\t);\n\n\t\treturn colliderDesc;\n\t}\n}\n\nexport class PlaneMeshBuilder extends EntityMeshBuilder {\n\theightData: Float32Array = new Float32Array();\n\tcolumnsRows = new Map();\n\tprivate subdivisions: number = DEFAULT_SUBDIVISIONS;\n\n\tbuild(options: ZylemPlaneOptions): XZPlaneGeometry {\n\t\tconst tile = options.tile ?? new Vector2(1, 1);\n\t\tconst subdivisions = options.subdivisions ?? DEFAULT_SUBDIVISIONS;\n\t\tthis.subdivisions = subdivisions;\n\t\tconst size = new Vector3(tile.x, 1, tile.y);\n\t\tconst heightScale = options.heightScale ?? 1;\n\n\t\tconst geometry = new XZPlaneGeometry(size.x, size.z, subdivisions, subdivisions);\n\t\tconst vertexGeometry = new PlaneGeometry(size.x, size.z, subdivisions, subdivisions);\n\t\tconst dx = size.x / subdivisions;\n\t\tconst dy = size.z / subdivisions;\n\t\tconst originalVertices = geometry.attributes.position.array;\n\t\tconst vertices = vertexGeometry.attributes.position.array;\n\t\tconst columsRows = new Map();\n\n\t\t// Get height data source\n\t\tconst heightMapData = options.heightMap;\n\t\tconst useRandomHeight = options.randomizeHeight ?? false;\n\n\t\tfor (let i = 0; i < vertices.length; i += 3) {\n\t\t\tconst vertexIndex = i / 3;\n\t\t\tlet row = Math.floor(Math.abs((vertices as any)[i] + (size.x / 2)) / dx);\n\t\t\tlet column = Math.floor(Math.abs((vertices as any)[i + 1] - (size.z / 2)) / dy);\n\n\t\t\tlet height = 0;\n\t\t\tif (heightMapData && heightMapData.length > 0) {\n\t\t\t\t// Loop the height map data if it doesn't cover all vertices\n\t\t\t\tconst heightIndex = vertexIndex % heightMapData.length;\n\t\t\t\theight = heightMapData[heightIndex] * heightScale;\n\t\t\t} else if (useRandomHeight) {\n\t\t\t\theight = Math.random() * 4 * heightScale;\n\t\t\t}\n\n\t\t\t(vertices as any)[i + 2] = height;\n\t\t\toriginalVertices[i + 1] = height;\n\t\t\tif (!columsRows.get(column)) {\n\t\t\t\tcolumsRows.set(column, new Map());\n\t\t\t}\n\t\t\tcolumsRows.get(column).set(row, height);\n\t\t}\n\t\tthis.columnsRows = columsRows;\n\t\treturn geometry;\n\t}\n\n\tpostBuild(): void {\n\t\tconst heights = [];\n\t\tfor (let i = 0; i <= this.subdivisions; ++i) {\n\t\t\tfor (let j = 0; j <= this.subdivisions; ++j) {\n\t\t\t\tconst row = this.columnsRows.get(j);\n\t\t\t\tif (!row) {\n\t\t\t\t\theights.push(0);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst data = row.get(i);\n\t\t\t\theights.push(data ?? 0);\n\t\t\t}\n\t\t}\n\t\tthis.heightData = new Float32Array(heights as unknown as number[]);\n\t}\n}\n\nexport class PlaneBuilder extends EntityBuilder<ZylemPlane, ZylemPlaneOptions> {\n\tprotected createEntity(options: Partial<ZylemPlaneOptions>): ZylemPlane {\n\t\treturn new ZylemPlane(options);\n\t}\n}\n\nexport const PLANE_TYPE = Symbol('Plane');\n\nexport class ZylemPlane extends GameEntity<ZylemPlaneOptions> {\n\tstatic type = PLANE_TYPE;\n\n\tconstructor(options?: ZylemPlaneOptions) {\n\t\tsuper();\n\t\tthis.options = { ...planeDefaults, ...options };\n\t}\n}\n\ntype PlaneOptions = BaseNode | Partial<ZylemPlaneOptions>;\n\nexport function createPlane(...args: Array<PlaneOptions>): ZylemPlane {\n\treturn createEntity<ZylemPlane, ZylemPlaneOptions>({\n\t\targs,\n\t\tdefaultConfig: planeDefaults,\n\t\tEntityClass: ZylemPlane,\n\t\tBuilderClass: PlaneBuilder,\n\t\tMeshBuilderClass: PlaneMeshBuilder,\n\t\tCollisionBuilderClass: PlaneCollisionBuilder,\n\t\tentityType: ZylemPlane.type\n\t});\n}\n","import { ActiveCollisionTypes, ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { createEntity } from './create';\nimport { CollisionHandlerDelegate } from '../collision/world';\nimport { state } from '../game/game-state';\nimport { commonDefaults } from './common';\n\nexport type OnHeldParams = {\n\tdelta: number;\n\tself: ZylemZone;\n\tvisitor: GameEntity<any>;\n\theldTime: number;\n\tglobals: any;\n}\n\nexport type OnEnterParams = Pick<OnHeldParams, 'self' | 'visitor' | 'globals'>;\nexport type OnExitParams = Pick<OnHeldParams, 'self' | 'visitor' | 'globals'>;\n\ntype ZylemZoneOptions = GameEntityOptions & {\n\tsize?: Vector3;\n\tstatic?: boolean;\n\tonEnter?: (params: OnEnterParams) => void;\n\tonHeld?: (params: OnHeldParams) => void;\n\tonExit?: (params: OnExitParams) => void;\n};\n\nconst zoneDefaults: ZylemZoneOptions = {\n\t...commonDefaults,\n\tsize: new Vector3(1, 1, 1),\n\tcollision: {\n\t\tstatic: true,\n\t},\n};\n\nexport class ZoneCollisionBuilder extends EntityCollisionBuilder {\n\tcollider(options: ZylemZoneOptions): ColliderDesc {\n\t\tconst size = options.size || new Vector3(1, 1, 1);\n\t\tconst half = { x: size.x / 2, y: size.y / 2, z: size.z / 2 };\n\t\tlet colliderDesc = ColliderDesc.cuboid(half.x, half.y, half.z);\n\t\tcolliderDesc.setSensor(true);\n\t\tcolliderDesc.activeCollisionTypes = ActiveCollisionTypes.KINEMATIC_FIXED;\n\t\treturn colliderDesc;\n\t}\n}\n\nexport class ZoneBuilder extends EntityBuilder<ZylemZone, ZylemZoneOptions> {\n\tprotected createEntity(options: Partial<ZylemZoneOptions>): ZylemZone {\n\t\treturn new ZylemZone(options);\n\t}\n}\n\nexport const ZONE_TYPE = Symbol('Zone');\n\nexport class ZylemZone extends GameEntity<ZylemZoneOptions> implements CollisionHandlerDelegate {\n\tstatic type = ZONE_TYPE;\n\n\tprivate _enteredZone: Map<string, number> = new Map();\n\tprivate _exitedZone: Map<string, number> = new Map();\n\tprivate _zoneEntities: Map<string, any> = new Map();\n\n\tconstructor(options?: ZylemZoneOptions) {\n\t\tsuper();\n\t\tthis.options = { ...zoneDefaults, ...options };\n\t}\n\n\tpublic handlePostCollision({ delta }: { delta: number }): boolean {\n\t\tthis._enteredZone.forEach((val, key) => {\n\t\t\tthis.exited(delta, key);\n\t\t});\n\t\treturn this._enteredZone.size > 0;\n\t}\n\n\tpublic handleIntersectionEvent({ other, delta }: { other: any, delta: number }) {\n\t\tconst hasEntered = this._enteredZone.get(other.uuid);\n\t\tif (!hasEntered) {\n\t\t\tthis.entered(other);\n\t\t\tthis._zoneEntities.set(other.uuid, other);\n\t\t} else {\n\t\t\tthis.held(delta, other);\n\t\t}\n\t}\n\n\tonEnter(callback: (params: OnEnterParams) => void) {\n\t\tthis.options.onEnter = callback;\n\t\treturn this;\n\t}\n\n\tonHeld(callback: (params: OnHeldParams) => void) {\n\t\tthis.options.onHeld = callback;\n\t\treturn this;\n\t}\n\n\tonExit(callback: (params: OnExitParams) => void) {\n\t\tthis.options.onExit = callback;\n\t\treturn this;\n\t}\n\n\tentered(other: any) {\n\t\tthis._enteredZone.set(other.uuid, 1);\n\t\tif (this.options.onEnter) {\n\t\t\tthis.options.onEnter({\n\t\t\t\tself: this,\n\t\t\t\tvisitor: other,\n\t\t\t\tglobals: state.globals\n\t\t\t});\n\t\t}\n\t}\n\n\texited(delta: number, key: string) {\n\t\tconst hasExited = this._exitedZone.get(key);\n\t\tif (hasExited && hasExited > 1 + delta) {\n\t\t\tthis._exitedZone.delete(key);\n\t\t\tthis._enteredZone.delete(key);\n\t\t\tconst other = this._zoneEntities.get(key);\n\t\t\tif (this.options.onExit) {\n\t\t\t\tthis.options.onExit({\n\t\t\t\t\tself: this,\n\t\t\t\t\tvisitor: other,\n\t\t\t\t\tglobals: state.globals\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tthis._exitedZone.set(key, 1 + delta);\n\t}\n\n\theld(delta: number, other: any) {\n\t\tconst heldTime = this._enteredZone.get(other.uuid) ?? 0;\n\t\tthis._enteredZone.set(other.uuid, heldTime + delta);\n\t\tthis._exitedZone.set(other.uuid, 1);\n\t\tif (this.options.onHeld) {\n\t\t\tthis.options.onHeld({\n\t\t\t\tdelta,\n\t\t\t\tself: this,\n\t\t\t\tvisitor: other,\n\t\t\t\tglobals: state.globals,\n\t\t\t\theldTime\n\t\t\t});\n\t\t}\n\t}\n}\n\ntype ZoneOptions = BaseNode | Partial<ZylemZoneOptions>;\n\nexport function createZone(...args: Array<ZoneOptions>): ZylemZone {\n\treturn createEntity<ZylemZone, ZylemZoneOptions>({\n\t\targs,\n\t\tdefaultConfig: zoneDefaults,\n\t\tEntityClass: ZylemZone,\n\t\tBuilderClass: ZoneBuilder,\n\t\tCollisionBuilderClass: ZoneCollisionBuilder,\n\t\tentityType: ZylemZone.type\n\t});\n}","import { Color, Group, Sprite as ThreeSprite, SpriteMaterial, CanvasTexture, LinearFilter, Vector2, PerspectiveCamera, OrthographicCamera, ClampToEdgeWrapping, ShaderMaterial, Mesh, PlaneGeometry, Vector3 } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { createEntity } from './create';\nimport { UpdateContext, SetupContext } from '../core/base-node-life-cycle';\nimport { ZylemCamera } from '../camera/zylem-camera';\nimport { DebugDelegate } from './delegates/debug';\n\ntype ZylemRectOptions = GameEntityOptions & {\n\twidth?: number;\n\theight?: number;\n\tfillColor?: Color | string | null;\n\tstrokeColor?: Color | string | null;\n\tstrokeWidth?: number;\n\tradius?: number;\n\tpadding?: number;\n\tstickToViewport?: boolean;\n\tscreenPosition?: Vector2;\n\tzDistance?: number;\n\tanchor?: Vector2; // 0-100 per axis, default top-left (0,0)\n\tbounds?: {\n\t\tscreen?: { x: number; y: number; width: number; height: number };\n\t\tworld?: { left: number; right: number; top: number; bottom: number; z?: number };\n\t};\n};\n\nconst rectDefaults: ZylemRectOptions = {\n\tposition: undefined,\n\twidth: 120,\n\theight: 48,\n\tfillColor: '#FFFFFF',\n\tstrokeColor: null,\n\tstrokeWidth: 0,\n\tradius: 0,\n\tpadding: 0,\n\tstickToViewport: true,\n\tscreenPosition: new Vector2(24, 24),\n\tzDistance: 1,\n\tanchor: new Vector2(0, 0),\n};\n\nexport class RectBuilder extends EntityBuilder<ZylemRect, ZylemRectOptions> {\n\tprotected createEntity(options: Partial<ZylemRectOptions>): ZylemRect {\n\t\treturn new ZylemRect(options);\n\t}\n}\n\nexport const RECT_TYPE = Symbol('Rect');\n\nexport class ZylemRect extends GameEntity<ZylemRectOptions> {\n\tstatic type = RECT_TYPE;\n\n\tprivate _sprite: ThreeSprite | null = null;\n\tprivate _mesh: Mesh | null = null;\n\tprivate _texture: CanvasTexture | null = null;\n\tprivate _canvas: HTMLCanvasElement | null = null;\n\tprivate _ctx: CanvasRenderingContext2D | null = null;\n\tprivate _cameraRef: ZylemCamera | null = null;\n\tprivate _lastCanvasW: number = 0;\n\tprivate _lastCanvasH: number = 0;\n\n\tconstructor(options?: ZylemRectOptions) {\n\t\tsuper();\n\t\tthis.options = { ...rectDefaults, ...options } as ZylemRectOptions;\n\t\tthis.group = new Group();\n\t\tthis.createSprite();\n\t\t// Add rect-specific lifecycle callbacks\n\t\tthis.prependSetup(this.rectSetup.bind(this) as any);\n\t\tthis.prependUpdate(this.rectUpdate.bind(this) as any);\n\t}\n\n\tprivate createSprite() {\n\t\tthis._canvas = document.createElement('canvas');\n\t\tthis._ctx = this._canvas.getContext('2d');\n\t\tthis._texture = new CanvasTexture(this._canvas);\n\t\tthis._texture.minFilter = LinearFilter;\n\t\tthis._texture.magFilter = LinearFilter;\n\t\tconst material = new SpriteMaterial({\n\t\t\tmap: this._texture,\n\t\t\ttransparent: true,\n\t\t\tdepthTest: false,\n\t\t\tdepthWrite: false,\n\t\t\talphaTest: 0.5,\n\t\t});\n\t\tthis._sprite = new ThreeSprite(material);\n\t\tthis.group?.add(this._sprite);\n\t\tthis.redrawRect();\n\t}\n\n\tprivate redrawRect() {\n\t\tif (!this._canvas || !this._ctx) return;\n\t\tconst width = Math.max(2, Math.floor((this.options.width ?? 120)));\n\t\tconst height = Math.max(2, Math.floor((this.options.height ?? 48)));\n\t\tconst padding = this.options.padding ?? 0;\n\t\tconst strokeWidth = this.options.strokeWidth ?? 0;\n\t\tconst totalW = width + padding * 2 + strokeWidth;\n\t\tconst totalH = height + padding * 2 + strokeWidth;\n\t\tconst nextW = Math.max(2, totalW);\n\t\tconst nextH = Math.max(2, totalH);\n\t\tconst sizeChanged = nextW !== this._lastCanvasW || nextH !== this._lastCanvasH;\n\t\tthis._canvas.width = nextW;\n\t\tthis._canvas.height = nextH;\n\t\tthis._lastCanvasW = nextW;\n\t\tthis._lastCanvasH = nextH;\n\n\t\tthis._ctx.clearRect(0, 0, this._canvas.width, this._canvas.height);\n\n\t\tconst radius = Math.max(0, this.options.radius ?? 0);\n\t\tconst rectX = Math.floor(padding + strokeWidth / 2);\n\t\tconst rectY = Math.floor(padding + strokeWidth / 2);\n\t\tconst rectW = Math.floor(width);\n\t\tconst rectH = Math.floor(height);\n\n\t\tthis._ctx.beginPath();\n\t\tif (radius > 0) {\n\t\t\tthis.roundedRectPath(this._ctx, rectX, rectY, rectW, rectH, radius);\n\t\t} else {\n\t\t\tthis._ctx.rect(rectX, rectY, rectW, rectH);\n\t\t}\n\n\t\tif (this.options.fillColor) {\n\t\t\tthis._ctx.fillStyle = this.toCssColor(this.options.fillColor);\n\t\t\tthis._ctx.fill();\n\t\t}\n\n\t\tif ((this.options.strokeColor && (strokeWidth > 0))) {\n\t\t\tthis._ctx.lineWidth = strokeWidth;\n\t\t\tthis._ctx.strokeStyle = this.toCssColor(this.options.strokeColor);\n\t\t\tthis._ctx.stroke();\n\t\t}\n\n\t\tif (this._texture) {\n\t\t\tif (sizeChanged) {\n\t\t\t\tthis._texture.dispose();\n\t\t\t\tthis._texture = new CanvasTexture(this._canvas);\n\t\t\t\tthis._texture.minFilter = LinearFilter;\n\t\t\t\tthis._texture.magFilter = LinearFilter;\n\t\t\t\tthis._texture.wrapS = ClampToEdgeWrapping;\n\t\t\t\tthis._texture.wrapT = ClampToEdgeWrapping;\n\t\t\t\tif (this._sprite && this._sprite.material instanceof ShaderMaterial) {\n\t\t\t\t\tconst shader = this._sprite.material as ShaderMaterial;\n\t\t\t\t\tif (shader.uniforms?.tDiffuse) shader.uniforms.tDiffuse.value = this._texture;\n\t\t\t\t\tif (shader.uniforms?.iResolution) shader.uniforms.iResolution.value.set(this._canvas.width, this._canvas.height, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis._texture.image = this._canvas;\n\t\t\tthis._texture.needsUpdate = true;\n\t\t\tif (this._sprite && this._sprite.material) {\n\t\t\t\t(this._sprite.material as any).map = this._texture;\n\t\t\t\tthis._sprite.material.needsUpdate = true;\n\t\t\t}\n\t\t}\n\t}\n\n\tgetWidth() {\n\t\treturn this.options.width ?? 0;\n\t}\n\n\tgetHeight() {\n\t\treturn this.options.height ?? 0;\n\t}\n\n\tprivate roundedRectPath(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number) {\n\t\tconst radius = Math.min(r, Math.floor(Math.min(w, h) / 2));\n\t\tctx.moveTo(x + radius, y);\n\t\tctx.lineTo(x + w - radius, y);\n\t\tctx.quadraticCurveTo(x + w, y, x + w, y + radius);\n\t\tctx.lineTo(x + w, y + h - radius);\n\t\tctx.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);\n\t\tctx.lineTo(x + radius, y + h);\n\t\tctx.quadraticCurveTo(x, y + h, x, y + h - radius);\n\t\tctx.lineTo(x, y + radius);\n\t\tctx.quadraticCurveTo(x, y, x + radius, y);\n\t}\n\n\tprivate toCssColor(color: Color | string): string {\n\t\tif (typeof color === 'string') return color;\n\t\tconst c = color instanceof Color ? color : new Color(color as any);\n\t\treturn `#${c.getHexString()}`;\n\t}\n\n\tprivate rectSetup(params: SetupContext<ZylemRectOptions>) {\n\t\tthis._cameraRef = (params.camera as unknown) as ZylemCamera | null;\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\t(this._cameraRef.camera as any).add(this.group);\n\t\t}\n\n\t\tif (this.materials?.length && this._sprite) {\n\t\t\tconst mat = this.materials[0];\n\t\t\tif (mat instanceof ShaderMaterial) {\n\t\t\t\tmat.transparent = true;\n\t\t\t\tmat.depthTest = false;\n\t\t\t\tmat.depthWrite = false;\n\t\t\t\tif (this._texture) {\n\t\t\t\t\tif (mat.uniforms?.tDiffuse) mat.uniforms.tDiffuse.value = this._texture;\n\t\t\t\t\tif (mat.uniforms?.iResolution && this._canvas) mat.uniforms.iResolution.value.set(this._canvas.width, this._canvas.height, 1);\n\t\t\t\t}\n\t\t\t\tthis._mesh = new Mesh(new PlaneGeometry(1, 1), mat);\n\t\t\t\tthis.group?.add(this._mesh);\n\t\t\t\tthis._sprite.visible = false;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate rectUpdate(params: UpdateContext<ZylemRectOptions>) {\n\t\tif (!this._sprite) return;\n\n\t\t// If bounds provided, compute screen-space rect from it and update size/position\n\t\tif (this._cameraRef && this.options.bounds) {\n\t\t\tconst dom = this._cameraRef.renderer.domElement;\n\t\t\tconst screen = this.computeScreenBoundsFromOptions(this.options.bounds);\n\t\t\tif (screen) {\n\t\t\t\tconst { x, y, width, height } = screen;\n\t\t\t\tconst desiredW = Math.max(2, Math.floor(width));\n\t\t\t\tconst desiredH = Math.max(2, Math.floor(height));\n\t\t\t\tconst changed = desiredW !== (this.options.width ?? 0) || desiredH !== (this.options.height ?? 0);\n\t\t\t\tthis.options.screenPosition = new Vector2(Math.floor(x), Math.floor(y));\n\t\t\t\tthis.options.width = desiredW;\n\t\t\t\tthis.options.height = desiredH;\n\t\t\t\tthis.options.anchor = new Vector2(0, 0);\n\t\t\t\tif (changed) {\n\t\t\t\t\tthis.redrawRect();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tprivate updateStickyTransform() {\n\t\tif (!this._sprite || !this._cameraRef) return;\n\t\tconst camera = this._cameraRef.camera;\n\t\tconst dom = this._cameraRef.renderer.domElement;\n\t\tconst width = dom.clientWidth;\n\t\tconst height = dom.clientHeight;\n\t\tconst px = (this.options.screenPosition ?? new Vector2(24, 24)).x;\n\t\tconst py = (this.options.screenPosition ?? new Vector2(24, 24)).y;\n\t\tconst zDist = Math.max(0.001, this.options.zDistance ?? 1);\n\n\t\tlet worldHalfW = 1;\n\t\tlet worldHalfH = 1;\n\t\tif ((camera as PerspectiveCamera).isPerspectiveCamera) {\n\t\t\tconst pc = camera as PerspectiveCamera;\n\t\t\tconst halfH = Math.tan((pc.fov * Math.PI) / 180 / 2) * zDist;\n\t\t\tconst halfW = halfH * pc.aspect;\n\t\t\tworldHalfW = halfW;\n\t\t\tworldHalfH = halfH;\n\t\t} else if ((camera as OrthographicCamera).isOrthographicCamera) {\n\t\t\tconst oc = camera as OrthographicCamera;\n\t\t\tworldHalfW = (oc.right - oc.left) / 2;\n\t\t\tworldHalfH = (oc.top - oc.bottom) / 2;\n\t\t}\n\n\t\tconst ndcX = (px / width) * 2 - 1;\n\t\tconst ndcY = 1 - (py / height) * 2;\n\t\tconst localX = ndcX * worldHalfW;\n\t\tconst localY = ndcY * worldHalfH;\n\n\t\tlet scaleX = 1;\n\t\tlet scaleY = 1;\n\t\tif (this._canvas) {\n\t\t\tconst planeH = worldHalfH * 2;\n\t\t\tconst unitsPerPixel = planeH / height;\n\t\t\tconst pixelH = this._canvas.height;\n\t\t\tscaleY = Math.max(0.0001, pixelH * unitsPerPixel);\n\t\t\tconst aspect = this._canvas.width / this._canvas.height;\n\t\t\tscaleX = scaleY * aspect;\n\t\t\tthis._sprite.scale.set(scaleX, scaleY, 1);\n\t\t\tif (this._mesh) this._mesh.scale.set(scaleX, scaleY, 1);\n\t\t}\n\n\t\tconst anchor = this.options.anchor ?? new Vector2(0, 0);\n\t\tconst ax = Math.min(100, Math.max(0, anchor.x)) / 100; // 0..1\n\t\tconst ay = Math.min(100, Math.max(0, anchor.y)) / 100; // 0..1\n\t\tconst offsetX = (0.5 - ax) * scaleX;\n\t\tconst offsetY = (ay - 0.5) * scaleY;\n\t\tthis.group?.position.set(localX + offsetX, localY + offsetY, -zDist);\n\t}\n\n\tprivate worldToScreen(point: Vector3) {\n\t\tif (!this._cameraRef) return { x: 0, y: 0 };\n\t\tconst camera = this._cameraRef.camera;\n\t\tconst dom = this._cameraRef.renderer.domElement;\n\t\tconst v = point.clone().project(camera);\n\t\tconst x = (v.x + 1) / 2 * dom.clientWidth;\n\t\tconst y = (1 - v.y) / 2 * dom.clientHeight;\n\t\treturn { x, y };\n\t}\n\n\tprivate computeScreenBoundsFromOptions(bounds: NonNullable<ZylemRectOptions['bounds']>): { x: number; y: number; width: number; height: number } | null {\n\t\tif (!this._cameraRef) return null;\n\t\tconst dom = this._cameraRef.renderer.domElement;\n\t\tif (bounds.screen) {\n\t\t\treturn { ...bounds.screen };\n\t\t}\n\t\tif (bounds.world) {\n\t\t\tconst { left, right, top, bottom, z = 0 } = bounds.world;\n\t\t\tconst tl = this.worldToScreen(new Vector3(left, top, z));\n\t\t\tconst br = this.worldToScreen(new Vector3(right, bottom, z));\n\t\t\tconst x = Math.min(tl.x, br.x);\n\t\t\tconst y = Math.min(tl.y, br.y);\n\t\t\tconst width = Math.abs(br.x - tl.x);\n\t\t\tconst height = Math.abs(br.y - tl.y);\n\t\t\treturn { x, y, width, height };\n\t\t}\n\t\treturn null;\n\t}\n\n\tupdateRect(options?: Partial<Pick<ZylemRectOptions, 'width' | 'height' | 'fillColor' | 'strokeColor' | 'strokeWidth' | 'radius'>>) {\n\t\tthis.options = { ...this.options, ...options } as ZylemRectOptions;\n\t\tthis.redrawRect();\n\t\tif (this.options.stickToViewport && this._cameraRef) {\n\t\t\tthis.updateStickyTransform();\n\t\t}\n\t}\n\n\tbuildInfo(): Record<string, any> {\n\t\tconst delegate = new DebugDelegate(this as any);\n\t\tconst baseInfo = delegate.buildDebugInfo();\n\n\t\treturn {\n\t\t\t...baseInfo,\n\t\t\ttype: String(ZylemRect.type),\n\t\t\twidth: this.options.width ?? 0,\n\t\t\theight: this.options.height ?? 0,\n\t\t\tsticky: this.options.stickToViewport,\n\t\t};\n\t}\n}\n\ntype RectOptions = BaseNode | Partial<ZylemRectOptions>;\n\nexport function createRect(...args: Array<RectOptions>): ZylemRect {\n\treturn createEntity<ZylemRect, ZylemRectOptions>({\n\t\targs,\n\t\tdefaultConfig: { ...rectDefaults },\n\t\tEntityClass: ZylemRect,\n\t\tBuilderClass: RectBuilder,\n\t\tentityType: ZylemRect.type,\n\t});\n}\n\n\n","import { ColliderDesc } from '@dimforge/rapier3d-compat';\nimport { Group, RingGeometry } from 'three';\nimport { BaseNode } from '../core/base-node';\nimport { GameEntityOptions, GameEntity } from './entity';\nimport { EntityBuilder } from './builder';\nimport { EntityCollisionBuilder } from './builder';\nimport { EntityMeshBuilder } from './builder';\nimport { DebugDelegate } from './delegates/debug';\nimport { createEntity } from './create';\nimport { commonDefaults } from './common';\n\ntype ZylemDiskOptions = GameEntityOptions & {\n\tinnerRadius?: number;\n\touterRadius?: number;\n\tthetaSegments?: number;\n};\n\nconst diskDefaults: ZylemDiskOptions = {\n\t...commonDefaults,\n\tinnerRadius: 0,\n\touterRadius: 1,\n\tthetaSegments: 32,\n};\n\nexport class DiskCollisionBuilder extends EntityCollisionBuilder {\n\tcollider(options: ZylemDiskOptions): ColliderDesc {\n\t\tconst outerRadius = options.outerRadius ?? 1;\n\t\tconst height = 0.1; // thin disk\n\t\t// Use cylinder collider for disk (very flat)\n\t\tlet colliderDesc = ColliderDesc.cylinder(height / 2, outerRadius);\n\t\treturn colliderDesc;\n\t}\n}\n\nexport class DiskMeshBuilder extends EntityMeshBuilder {\n\tbuild(options: ZylemDiskOptions): RingGeometry {\n\t\tconst innerRadius = options.innerRadius ?? 0;\n\t\tconst outerRadius = options.outerRadius ?? 1;\n\t\tconst thetaSegments = options.thetaSegments ?? 32;\n\t\tconst geometry = new RingGeometry(innerRadius, outerRadius, thetaSegments);\n\t\t// Rotate from XY plane to XZ plane to match cylinder collider\n\t\tgeometry.rotateX(-Math.PI / 2);\n\t\treturn geometry;\n\t}\n}\n\nexport class DiskBuilder extends EntityBuilder<ZylemDisk, ZylemDiskOptions> {\n\tprotected createEntity(options: Partial<ZylemDiskOptions>): ZylemDisk {\n\t\treturn new ZylemDisk(options);\n\t}\n\n\tbuild(): ZylemDisk {\n\t\tconst entity = super.build();\n\t\t// Wrap mesh in group for proper transform sync\n\t\tif (entity.mesh && !entity.group) {\n\t\t\tentity.group = new Group();\n\t\t\tentity.group.add(entity.mesh);\n\t\t}\n\t\treturn entity;\n\t}\n}\n\nexport const DISK_TYPE = Symbol('Disk');\n\nexport class ZylemDisk extends GameEntity<ZylemDiskOptions> {\n\tstatic type = DISK_TYPE;\n\n\tconstructor(options?: ZylemDiskOptions) {\n\t\tsuper();\n\t\tthis.options = { ...diskDefaults, ...options };\n\t}\n\n\tbuildInfo(): Record<string, any> {\n\t\tconst delegate = new DebugDelegate(this as any);\n\t\tconst baseInfo = delegate.buildDebugInfo();\n\t\tconst innerRadius = this.options.innerRadius ?? 0;\n\t\tconst outerRadius = this.options.outerRadius ?? 1;\n\t\treturn {\n\t\t\t...baseInfo,\n\t\t\ttype: String(ZylemDisk.type),\n\t\t\tinnerRadius: innerRadius.toFixed(2),\n\t\t\touterRadius: outerRadius.toFixed(2),\n\t\t};\n\t}\n}\n\ntype DiskOptions = BaseNode | Partial<ZylemDiskOptions>;\n\nexport function createDisk(...args: Array<DiskOptions>): ZylemDisk {\n\treturn createEntity<ZylemDisk, ZylemDiskOptions>({\n\t\targs,\n\t\tdefaultConfig: diskDefaults,\n\t\tEntityClass: ZylemDisk,\n\t\tBuilderClass: DiskBuilder,\n\t\tMeshBuilderClass: DiskMeshBuilder,\n\t\tCollisionBuilderClass: DiskCollisionBuilder,\n\t\tentityType: ZylemDisk.type\n\t});\n}\n","/**\n * BehaviorDescriptor\n *\n * Type-safe behavior descriptors that provide options inference.\n * Used with entity.use() to declaratively attach behaviors to entities.\n *\n * Each behavior can define its own handle type via `createHandle`,\n * providing behavior-specific methods with full type safety.\n */\n\nimport type { BehaviorSystemFactory } from './behavior-system';\n\n/**\n * Base handle returned by entity.use() for lazy access to behavior runtime.\n * FSM is null until entity is spawned and components are initialized.\n */\nexport interface BaseBehaviorHandle<\n O extends Record<string, any> = Record<string, any>,\n> {\n /** Get the FSM instance (null until entity is spawned) */\n getFSM(): any | null;\n /** Get the current options */\n getOptions(): O;\n /** Access the underlying behavior ref */\n readonly ref: BehaviorRef<O>;\n}\n\n/**\n * Reference to a behavior stored on an entity\n */\nexport interface BehaviorRef<\n O extends Record<string, any> = Record<string, any>,\n> {\n /** The behavior descriptor */\n descriptor: BehaviorDescriptor<O, any>;\n /** Merged options (defaults + overrides) */\n options: O;\n /** Optional FSM instance - set lazily when entity is spawned */\n fsm?: any;\n}\n\n/**\n * A typed behavior descriptor that associates a symbol key with:\n * - Default options (providing type inference)\n * - A system factory to create the behavior system\n * - An optional handle factory for behavior-specific methods\n */\nexport interface BehaviorDescriptor<\n O extends Record<string, any> = Record<string, any>,\n H extends Record<string, any> = Record<string, never>,\n I = unknown,\n> {\n /** Unique symbol identifying this behavior */\n readonly key: symbol;\n /** Default options (used for type inference) */\n readonly defaultOptions: O;\n /** Factory to create the behavior system */\n readonly systemFactory: BehaviorSystemFactory;\n /**\n * Optional factory to create behavior-specific handle methods.\n * These methods are merged into the handle returned by entity.use().\n */\n readonly createHandle?: (ref: BehaviorRef<O>) => H;\n}\n\n/**\n * The full handle type returned by entity.use().\n * Combines base handle with behavior-specific methods.\n */\nexport type BehaviorHandle<\n O extends Record<string, any> = Record<string, any>,\n H extends Record<string, any> = Record<string, never>,\n> = BaseBehaviorHandle<O> & H;\n\n/**\n * Configuration for defining a new behavior\n */\nexport interface DefineBehaviorConfig<\n O extends Record<string, any>,\n H extends Record<string, any> = Record<string, never>,\n I = unknown,\n> {\n /** Human-readable name for debugging */\n name: string;\n /** Default options - these define the type */\n defaultOptions: O;\n /** Factory function to create the system */\n systemFactory: BehaviorSystemFactory;\n /**\n * Optional factory to create behavior-specific handle methods.\n * The returned object is merged into the handle returned by entity.use().\n *\n * @example\n * ```typescript\n * createHandle: (ref) => ({\n * getLastHits: () => ref.fsm?.getLastHits() ?? null,\n * getMovement: (moveX, moveY) => ref.fsm?.getMovement(moveX, moveY) ?? { moveX, moveY },\n * }),\n * ```\n */\n createHandle?: (ref: BehaviorRef<O>) => H;\n}\n\n/**\n * Define a typed behavior descriptor.\n *\n * @example\n * ```typescript\n * export const WorldBoundary2DBehavior = defineBehavior({\n * name: 'world-boundary-2d',\n * defaultOptions: { boundaries: { top: 0, bottom: 0, left: 0, right: 0 } },\n * systemFactory: (ctx) => new WorldBoundary2DSystem(ctx.world),\n * createHandle: (ref) => ({\n * getLastHits: () => ref.fsm?.getLastHits() ?? null,\n * getMovement: (moveX: number, moveY: number) =>\n * ref.fsm?.getMovement(moveX, moveY) ?? { moveX, moveY },\n * }),\n * });\n *\n * // Usage - handle has getLastHits and getMovement with full types\n * const boundary = ship.use(WorldBoundary2DBehavior, { ... });\n * const hits = boundary.getLastHits(); // Fully typed!\n * ```\n */\nexport function defineBehavior<\n O extends Record<string, any>,\n H extends Record<string, any> = Record<string, never>,\n I = unknown,\n>(\n config: DefineBehaviorConfig<O, H, I>,\n): BehaviorDescriptor<O, H, I> {\n return {\n key: Symbol.for(`zylem:behavior:${config.name}`),\n defaultOptions: config.defaultOptions,\n systemFactory: config.systemFactory,\n createHandle: config.createHandle,\n };\n}\n","import { GameEntity } from '../entities/entity';\nimport { BehaviorDescriptor } from './behavior-descriptor';\n\n/**\n * Type-safe helper to apply a behavior to an entity and return the entity cast to the behavior's interface.\n * \n * @param entity The entity to apply the behavior to\n * @param descriptor The behavior descriptor\n * @param options Behavior options\n * @returns The entity, cast to E & I (where I is the behavior's interface)\n */\nexport function useBehavior<\n E extends GameEntity<any>,\n O extends Record<string, any>,\n H extends Record<string, any>,\n I // Entity Interface\n>(\n entity: E,\n descriptor: BehaviorDescriptor<O, H, I>,\n options?: Partial<O>\n): E & I {\n entity.use(descriptor, options);\n return entity as unknown as E & I;\n}\n","/**\n * Core ECS Components\n * \n * These are pure data interfaces with no logic.\n * They work alongside the existing bitecs components in transformable.system.ts\n */\n\nimport type { RigidBody } from '@dimforge/rapier3d-compat';\nimport { Vector3, Quaternion } from 'three';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// TransformComponent (render-facing)\n// Written only by PhysicsSyncBehavior, read by rendering/animation\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface TransformComponent {\n\tposition: Vector3;\n\trotation: Quaternion;\n}\n\nexport function createTransformComponent(): TransformComponent {\n\treturn {\n\t\tposition: new Vector3(),\n\t\trotation: new Quaternion(),\n\t};\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// PhysicsBodyComponent (bridge to Rapier, not state)\n// ECS does not store velocity, mass, etc. - Rapier owns all physical truth\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface PhysicsBodyComponent {\n\tbody: RigidBody;\n}\n\nexport function createPhysicsBodyComponent(body: RigidBody): PhysicsBodyComponent {\n\treturn { body };\n}\n","/**\n * PhysicsStepBehavior\n * \n * Single authoritative place where Rapier advances.\n * Runs after all force-producing behaviors.\n */\n\nimport type { World } from '@dimforge/rapier3d-compat';\nimport type { Behavior } from './thruster/thruster-movement.behavior';\n\n/**\n * PhysicsStepBehavior - Authoritative physics step\n * \n * This behavior is responsible for advancing the Rapier physics simulation.\n * It should run AFTER all force-producing behaviors (like ThrusterMovementBehavior).\n */\nexport class PhysicsStepBehavior implements Behavior {\n\tconstructor(private physicsWorld: World) {}\n\n\tupdate(dt: number): void {\n\t\tthis.physicsWorld.timestep = dt;\n\t\tthis.physicsWorld.step();\n\t}\n}\n","/**\n * PhysicsSyncBehavior\n * \n * Syncs physics state (position, rotation) from Rapier bodies to ECS TransformComponents.\n * This is what keeps Three.js honest - rendering reads from TransformComponent.\n */\n\nimport type { ZylemWorld } from '../collision/world';\nimport type { TransformComponent, PhysicsBodyComponent } from './components';\nimport type { Behavior } from './thruster/thruster-movement.behavior';\n\n/**\n * Entity with physics body and transform components\n */\ninterface PhysicsSyncEntity {\n\tphysics: PhysicsBodyComponent;\n\ttransform: TransformComponent;\n}\n\n/**\n * PhysicsSyncBehavior - Physics → ECS sync\n * \n * Responsibilities:\n * - Query entities with PhysicsBodyComponent and TransformComponent\n * - Copy position from body.translation() to transform.position\n * - Copy rotation from body.rotation() to transform.rotation\n * \n * This runs AFTER PhysicsStepBehavior, before rendering.\n */\nexport class PhysicsSyncBehavior implements Behavior {\n\tconstructor(private world: ZylemWorld) {}\n\n\t/**\n\t * Query entities that have both physics body and transform components\n\t */\n\tprivate queryEntities(): PhysicsSyncEntity[] {\n\t\tconst entities: PhysicsSyncEntity[] = [];\n\t\t\n\t\tfor (const [, entity] of this.world.collisionMap) {\n\t\t\tconst gameEntity = entity as any;\n\t\t\tif (gameEntity.physics?.body && gameEntity.transform) {\n\t\t\t\tentities.push({\n\t\t\t\t\tphysics: gameEntity.physics,\n\t\t\t\t\ttransform: gameEntity.transform,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn entities;\n\t}\n\n\tupdate(_dt: number): void {\n\t\tconst entities = this.queryEntities();\n\n\t\tfor (const e of entities) {\n\t\t\tconst body = e.physics.body;\n\t\t\tconst transform = e.transform;\n\n\t\t\t// Sync position\n\t\t\tconst p = body.translation();\n\t\t\ttransform.position.set(p.x, p.y, p.z);\n\n\t\t\t// Sync rotation\n\t\t\tconst r = body.rotation();\n\t\t\ttransform.rotation.set(r.x, r.y, r.z, r.w);\n\t\t}\n\t}\n}\n","/**\n * Thruster-specific ECS Components\n * \n * These components are specific to the thruster movement system.\n */\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ThrusterMovementComponent (capability / hardware spec)\n// Defines the thrust capabilities of an entity\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface ThrusterMovementComponent {\n\t/** Linear thrust force in Newtons (or scaled units) */\n\tlinearThrust: number;\n\t/** Angular thrust torque scalar */\n\tangularThrust: number;\n\t/** Optional linear damping override */\n\tlinearDamping?: number;\n\t/** Optional angular damping override */\n\tangularDamping?: number;\n}\n\nexport function createThrusterMovementComponent(\n\tlinearThrust: number,\n\tangularThrust: number,\n\toptions?: { linearDamping?: number; angularDamping?: number }\n): ThrusterMovementComponent {\n\treturn {\n\t\tlinearThrust,\n\t\tangularThrust,\n\t\tlinearDamping: options?.linearDamping,\n\t\tangularDamping: options?.angularDamping,\n\t};\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ThrusterInputComponent (intent)\n// Written by: Player controller, AI controller, FSM adapter\n// Read by: ThrusterMovementBehavior\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface ThrusterInputComponent {\n\t/** Forward thrust intent: 0..1 */\n\tthrust: number;\n\t/** Rotation intent: -1..1 */\n\trotate: number;\n}\n\nexport function createThrusterInputComponent(): ThrusterInputComponent {\n\treturn {\n\t\tthrust: 0,\n\t\trotate: 0,\n\t};\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ThrusterStateComponent (optional but useful)\n// Useful for: damage, EMP, overheating, UI feedback\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface ThrusterStateComponent {\n\t/** Whether the thruster is enabled */\n\tenabled: boolean;\n\t/** Current thrust after FSM/gating */\n\tcurrentThrust: number;\n}\n\nexport function createThrusterStateComponent(): ThrusterStateComponent {\n\treturn {\n\t\tenabled: true,\n\t\tcurrentThrust: 0,\n\t};\n}\n","/**\n * ThrusterFSM\n * \n * State machine controller for thruster behavior.\n * FSM does NOT touch physics or ThrusterMovementBehavior - it only writes ThrusterInputComponent.\n */\n\nimport { StateMachine, t, type ITransition } from 'typescript-fsm';\nimport type { ThrusterInputComponent } from './components';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// FSM State Model\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport enum ThrusterState {\n\tIdle = 'idle',\n\tActive = 'active',\n\tBoosting = 'boosting',\n\tDisabled = 'disabled',\n\tDocked = 'docked',\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// FSM Events\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport enum ThrusterEvent {\n\tActivate = 'activate',\n\tDeactivate = 'deactivate',\n\tBoost = 'boost',\n\tEndBoost = 'endBoost',\n\tDisable = 'disable',\n\tEnable = 'enable',\n\tDock = 'dock',\n\tUndock = 'undock',\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// FSM Context Object\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface ThrusterFSMContext {\n\tinput: ThrusterInputComponent;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Player Input (raw input from controller/keyboard)\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface PlayerInput {\n\tthrust: number;\n\trotate: number;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ThrusterFSM Controller\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport class ThrusterFSM {\n\tmachine: StateMachine<ThrusterState, ThrusterEvent, never>;\n\n\tconstructor(private ctx: ThrusterFSMContext) {\n\t\tthis.machine = new StateMachine<ThrusterState, ThrusterEvent, never>(\n\t\t\tThrusterState.Idle,\n\t\t\t[\n\t\t\t\t// Core transitions\n\t\t\t\tt(ThrusterState.Idle, ThrusterEvent.Activate, ThrusterState.Active),\n\t\t\t\tt(ThrusterState.Active, ThrusterEvent.Deactivate, ThrusterState.Idle),\n\t\t\t\tt(ThrusterState.Active, ThrusterEvent.Boost, ThrusterState.Boosting),\n\t\t\t\tt(ThrusterState.Active, ThrusterEvent.Disable, ThrusterState.Disabled),\n\t\t\t\tt(ThrusterState.Active, ThrusterEvent.Dock, ThrusterState.Docked),\n\t\t\t\tt(ThrusterState.Boosting, ThrusterEvent.EndBoost, ThrusterState.Active),\n\t\t\t\tt(ThrusterState.Boosting, ThrusterEvent.Disable, ThrusterState.Disabled),\n\t\t\t\tt(ThrusterState.Disabled, ThrusterEvent.Enable, ThrusterState.Idle),\n\t\t\t\tt(ThrusterState.Docked, ThrusterEvent.Undock, ThrusterState.Idle),\n\t\t\t\t// Self-transitions (no-ops for redundant events)\n\t\t\t\tt(ThrusterState.Idle, ThrusterEvent.Deactivate, ThrusterState.Idle),\n\t\t\t\tt(ThrusterState.Active, ThrusterEvent.Activate, ThrusterState.Active),\n\t\t\t]\n\t\t);\n\t}\n\n\t/**\n\t * Get current state\n\t */\n\tgetState(): ThrusterState {\n\t\treturn this.machine.getState();\n\t}\n\n\t/**\n\t * Dispatch an event to transition state\n\t */\n\tdispatch(event: ThrusterEvent): void {\n\t\tif (this.machine.can(event)) {\n\t\t\tthis.machine.dispatch(event);\n\t\t}\n\t}\n\n\t/**\n\t * Update FSM state based on player input.\n\t * Auto-transitions between Idle/Active to report current state.\n\t * Does NOT modify input - just observes and reports.\n\t */\n\tupdate(playerInput: PlayerInput): void {\n\t\tconst state = this.machine.getState();\n\t\tconst hasInput = Math.abs(playerInput.thrust) > 0.01 || Math.abs(playerInput.rotate) > 0.01;\n\n\t\t// Auto-transition to report state based on input\n\t\tif (hasInput && state === ThrusterState.Idle) {\n\t\t\tthis.dispatch(ThrusterEvent.Activate);\n\t\t} else if (!hasInput && state === ThrusterState.Active) {\n\t\t\tthis.dispatch(ThrusterEvent.Deactivate);\n\t\t}\n\t}\n}\n","/**\n * ThrusterMovementBehavior\n * \n * This is the heart of the thruster movement system - a pure, stateless force generator.\n * Works identically for player, AI, and replay.\n */\n\nimport type { ZylemWorld } from '../../collision/world';\nimport type { PhysicsBodyComponent } from '../components';\nimport type { ThrusterMovementComponent, ThrusterInputComponent } from './components';\n\n/**\n * Zylem-style Behavior interface\n */\nexport interface Behavior {\n\tupdate(dt: number): void;\n}\n\n/**\n * Entity with thruster components\n */\nexport interface ThrusterEntity {\n\tphysics: PhysicsBodyComponent;\n\tthruster: ThrusterMovementComponent;\n\t$thruster: ThrusterInputComponent;\n}\n\n/**\n * ThrusterMovementBehavior - Force generator for thruster-equipped entities\n * \n * Responsibilities:\n * - Query entities with PhysicsBody, ThrusterMovement, and ThrusterInput components\n * - Apply velocities based on thrust input (2D mode)\n * - Apply angular velocity based on rotation input\n */\nexport class ThrusterMovementBehavior implements Behavior {\n\tconstructor(private world: ZylemWorld) {}\n\n\t/**\n\t * Query function - returns entities with required thruster components\n\t */\n\tprivate queryEntities(): ThrusterEntity[] {\n\t\tconst entities: ThrusterEntity[] = [];\n\t\t\n\t\tfor (const [, entity] of this.world.collisionMap) {\n\t\t\tconst gameEntity = entity as any;\n\t\t\tif (\n\t\t\t\tgameEntity.physics?.body &&\n\t\t\t\tgameEntity.thruster &&\n\t\t\t\tgameEntity.$thruster\n\t\t\t) {\n\t\t\t\tentities.push({\n\t\t\t\t\tphysics: gameEntity.physics,\n\t\t\t\t\tthruster: gameEntity.thruster,\n\t\t\t\t\t$thruster: gameEntity.$thruster,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn entities;\n\t}\n\n\tupdate(_dt: number): void {\n\t\tconst entities = this.queryEntities();\n\n\t\tfor (const e of entities) {\n\t\t\tconst body = e.physics.body;\n\t\t\tconst thruster = e.thruster;\n\t\t\tconst input = e.$thruster;\n\n\t\t\t// Get Z rotation from quaternion (for 2D sprites)\n\t\t\tconst q = body.rotation();\n\t\t\tconst rotationZ = Math.atan2(2 * (q.w * q.z + q.x * q.y), 1 - 2 * (q.y * q.y + q.z * q.z));\n\n\t\t\t// --- Linear thrust (Asteroids-style: adds velocity in forward direction) ---\n\t\t\tif (input.thrust !== 0) {\n\t\t\t\tconst currentVel = body.linvel();\n\t\t\t\t\n\t\t\t\tif (input.thrust > 0) {\n\t\t\t\t\t// Forward thrust: add velocity in facing direction\n\t\t\t\t\tconst forwardX = Math.sin(-rotationZ);\n\t\t\t\t\tconst forwardY = Math.cos(-rotationZ);\n\t\t\t\t\tconst thrustAmount = thruster.linearThrust * input.thrust * 0.1;\n\t\t\t\t\tbody.setLinvel({\n\t\t\t\t\t\tx: currentVel.x + forwardX * thrustAmount,\n\t\t\t\t\t\ty: currentVel.y + forwardY * thrustAmount,\n\t\t\t\t\t\tz: currentVel.z\n\t\t\t\t\t}, true);\n\t\t\t\t} else {\n\t\t\t\t\t// Brake: reduce current velocity (slow down)\n\t\t\t\t\tconst brakeAmount = 0.9; // 10% reduction per frame\n\t\t\t\t\tbody.setLinvel({\n\t\t\t\t\t\tx: currentVel.x * brakeAmount,\n\t\t\t\t\t\ty: currentVel.y * brakeAmount,\n\t\t\t\t\t\tz: currentVel.z\n\t\t\t\t\t}, true);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// --- Angular thrust (Z-axis for 2D) ---\n\t\t\tif (input.rotate !== 0) {\n\t\t\t\tbody.setAngvel({ x: 0, y: 0, z: -thruster.angularThrust * input.rotate }, true);\n\t\t\t} else {\n\t\t\t\t// Stop rotation when no input\n\t\t\t\tconst angVel = body.angvel();\n\t\t\t\tbody.setAngvel({ x: angVel.x, y: angVel.y, z: 0 }, true);\n\t\t\t}\n\t\t}\n\t}\n}\n\n","/**\n * Thruster Behavior Descriptor\n * \n * Type-safe descriptor for the thruster behavior system using the new entity.use() API.\n * This wraps the existing ThrusterMovementBehavior and components.\n */\n\nimport type { IWorld } from 'bitecs';\nimport { defineBehavior } from '../behavior-descriptor';\nimport type { BehaviorSystem } from '../behavior-system';\nimport { ThrusterMovementBehavior, ThrusterEntity } from './thruster-movement.behavior';\nimport { ThrusterFSM } from './thruster-fsm';\nimport type { ThrusterMovementComponent, ThrusterInputComponent } from './components';\n\n/**\n * Thruster behavior options (typed for entity.use() autocomplete)\n */\nexport interface ThrusterBehaviorOptions {\n\t/** Forward thrust force (default: 10) */\n\tlinearThrust: number;\n\t/** Rotation torque (default: 5) */\n\tangularThrust: number;\n}\n\nconst defaultOptions: ThrusterBehaviorOptions = {\n\tlinearThrust: 10,\n\tangularThrust: 5,\n};\n\n/**\n * Adapter that wraps ThrusterMovementBehavior as a BehaviorSystem.\n * \n * This bridges the entity.use() pattern with the ECS component-based approach:\n * - Reads options from entity behaviorRefs\n * - Initializes ThrusterMovementComponent and ThrusterInputComponent on entities\n * - Creates FSM lazily and attaches to BehaviorRef for access via handle.getFSM()\n * - Delegates physics to ThrusterMovementBehavior\n * \n * NOTE: Input is controlled by the user via entity.onUpdate() - set entity.input.thrust/rotate\n */\nclass ThrusterBehaviorSystem implements BehaviorSystem {\n\tprivate movementBehavior: ThrusterMovementBehavior;\n\n\tconstructor(private world: any) {\n\t\tthis.movementBehavior = new ThrusterMovementBehavior(world);\n\t}\n\n\tupdate(ecs: IWorld, delta: number): void {\n\t\tif (!this.world?.collisionMap) return;\n\n\t\t// Initialize ECS components on entities with thruster behavior refs\n\t\tfor (const [, entity] of this.world.collisionMap) {\n\t\t\tconst gameEntity = entity as any;\n\t\t\t\n\t\t\tif (typeof gameEntity.getBehaviorRefs !== 'function') continue;\n\t\t\t\n\t\t\tconst refs = gameEntity.getBehaviorRefs();\n\t\t\tconst thrusterRef = refs.find((r: any) => \n\t\t\t\tr.descriptor.key === Symbol.for('zylem:behavior:thruster')\n\t\t\t);\n\t\t\t\n\t\t\tif (!thrusterRef || !gameEntity.body) continue;\n\n\t\t\tconst options = thrusterRef.options as ThrusterBehaviorOptions;\n\n\t\t\t// Ensure entity has thruster components (initialized once)\n\t\t\tif (!gameEntity.thruster) {\n\t\t\t\tgameEntity.thruster = {\n\t\t\t\t\tlinearThrust: options.linearThrust,\n\t\t\t\t\tangularThrust: options.angularThrust,\n\t\t\t\t} as ThrusterMovementComponent;\n\t\t\t}\n\n\t\t\tif (!gameEntity.$thruster) {\n\t\t\t\tgameEntity.$thruster = {\n\t\t\t\t\tthrust: 0,\n\t\t\t\t\trotate: 0,\n\t\t\t\t} as ThrusterInputComponent;\n\t\t\t}\n\n\t\t\tif (!gameEntity.physics) {\n\t\t\t\tgameEntity.physics = { body: gameEntity.body };\n\t\t\t}\n\n\t\t\t// Create FSM lazily and attach to the BehaviorRef for handle.getFSM()\n\t\t\tif (!thrusterRef.fsm && gameEntity.$thruster) {\n\t\t\t\tthrusterRef.fsm = new ThrusterFSM({ input: gameEntity.$thruster });\n\t\t\t}\n\n\t\t\t// Update FSM to sync state with input (auto-transitions)\n\t\t\tif (thrusterRef.fsm && gameEntity.$thruster) {\n\t\t\t\tthrusterRef.fsm.update({\n\t\t\t\t\tthrust: gameEntity.$thruster.thrust,\n\t\t\t\t\trotate: gameEntity.$thruster.rotate,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Delegate to the existing movement behavior\n\t\tthis.movementBehavior.update(delta);\n\t}\n\n\tdestroy(_ecs: IWorld): void {\n\t\t// Cleanup if needed\n\t}\n}\n\n/**\n * ThrusterBehavior - typed descriptor for thruster movement.\n * \n * Uses the existing ThrusterMovementBehavior under the hood.\n * \n * @example\n * ```typescript\n * import { ThrusterBehavior } from \"@zylem/game-lib\";\n * \n * const ship = createSprite({ ... });\n * ship.use(ThrusterBehavior, { linearThrust: 15, angularThrust: 8 });\n * ```\n */\nexport const ThrusterBehavior = defineBehavior<ThrusterBehaviorOptions, Record<string, never>, ThrusterEntity>({\n\tname: 'thruster',\n\tdefaultOptions,\n\tsystemFactory: (ctx) => new ThrusterBehaviorSystem(ctx.world),\n});\n","/**\n * Thruster Behavior Module Index\n * \n * Re-exports all thruster-related components and behaviors.\n */\n\n// Components\nexport {\n\ttype ThrusterMovementComponent,\n\ttype ThrusterInputComponent,\n\ttype ThrusterStateComponent,\n\tcreateThrusterMovementComponent,\n\tcreateThrusterInputComponent,\n\tcreateThrusterStateComponent,\n} from './components';\n\n// FSM\nexport {\n\tThrusterState,\n\tThrusterEvent,\n\tThrusterFSM,\n\ttype ThrusterFSMContext,\n\ttype PlayerInput,\n} from './thruster-fsm';\n\n// Behaviors\nexport {\n\tThrusterMovementBehavior,\n\ttype Behavior,\n\ttype ThrusterEntity,\n} from './thruster-movement.behavior';\n\n// Typed Descriptor (new entity.use() API)\nexport { ThrusterBehavior, type ThrusterBehaviorOptions } from './thruster.descriptor';\n","/**\n * ScreenWrapFSM\n * \n * State machine for screen wrap behavior.\n * Reports position relative to bounds edges.\n */\n\nimport { StateMachine, t } from 'typescript-fsm';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// FSM State Model\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport enum ScreenWrapState {\n\tCenter = 'center',\n\tNearEdgeLeft = 'near-edge-left',\n\tNearEdgeRight = 'near-edge-right',\n\tNearEdgeTop = 'near-edge-top',\n\tNearEdgeBottom = 'near-edge-bottom',\n\tWrapped = 'wrapped',\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// FSM Events\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport enum ScreenWrapEvent {\n\tEnterCenter = 'enter-center',\n\tApproachLeft = 'approach-left',\n\tApproachRight = 'approach-right',\n\tApproachTop = 'approach-top',\n\tApproachBottom = 'approach-bottom',\n\tWrap = 'wrap',\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ScreenWrapFSM\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport class ScreenWrapFSM {\n\tmachine: StateMachine<ScreenWrapState, ScreenWrapEvent, never>;\n\n\tconstructor() {\n\t\tthis.machine = new StateMachine<ScreenWrapState, ScreenWrapEvent, never>(\n\t\t\tScreenWrapState.Center,\n\t\t\t[\n\t\t\t\t// From Center\n\t\t\t\tt(ScreenWrapState.Center, ScreenWrapEvent.ApproachLeft, ScreenWrapState.NearEdgeLeft),\n\t\t\t\tt(ScreenWrapState.Center, ScreenWrapEvent.ApproachRight, ScreenWrapState.NearEdgeRight),\n\t\t\t\tt(ScreenWrapState.Center, ScreenWrapEvent.ApproachTop, ScreenWrapState.NearEdgeTop),\n\t\t\t\tt(ScreenWrapState.Center, ScreenWrapEvent.ApproachBottom, ScreenWrapState.NearEdgeBottom),\n\t\t\t\t\n\t\t\t\t// From NearEdge to Wrapped\n\t\t\t\tt(ScreenWrapState.NearEdgeLeft, ScreenWrapEvent.Wrap, ScreenWrapState.Wrapped),\n\t\t\t\tt(ScreenWrapState.NearEdgeRight, ScreenWrapEvent.Wrap, ScreenWrapState.Wrapped),\n\t\t\t\tt(ScreenWrapState.NearEdgeTop, ScreenWrapEvent.Wrap, ScreenWrapState.Wrapped),\n\t\t\t\tt(ScreenWrapState.NearEdgeBottom, ScreenWrapEvent.Wrap, ScreenWrapState.Wrapped),\n\n\t\t\t\t// From NearEdge back to Center\n\t\t\t\tt(ScreenWrapState.NearEdgeLeft, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\t\t\t\tt(ScreenWrapState.NearEdgeRight, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\t\t\t\tt(ScreenWrapState.NearEdgeTop, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\t\t\t\tt(ScreenWrapState.NearEdgeBottom, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\n\t\t\t\t// From Wrapped back to Center\n\t\t\t\tt(ScreenWrapState.Wrapped, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\n\t\t\t\t// From Wrapped to NearEdge (landed near opposite edge)\n\t\t\t\tt(ScreenWrapState.Wrapped, ScreenWrapEvent.ApproachLeft, ScreenWrapState.NearEdgeLeft),\n\t\t\t\tt(ScreenWrapState.Wrapped, ScreenWrapEvent.ApproachRight, ScreenWrapState.NearEdgeRight),\n\t\t\t\tt(ScreenWrapState.Wrapped, ScreenWrapEvent.ApproachTop, ScreenWrapState.NearEdgeTop),\n\t\t\t\tt(ScreenWrapState.Wrapped, ScreenWrapEvent.ApproachBottom, ScreenWrapState.NearEdgeBottom),\n\n\t\t\t\t// Self-transitions (no-ops for redundant events)\n\t\t\t\tt(ScreenWrapState.Center, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\t\t\t\tt(ScreenWrapState.NearEdgeLeft, ScreenWrapEvent.ApproachLeft, ScreenWrapState.NearEdgeLeft),\n\t\t\t\tt(ScreenWrapState.NearEdgeRight, ScreenWrapEvent.ApproachRight, ScreenWrapState.NearEdgeRight),\n\t\t\t\tt(ScreenWrapState.NearEdgeTop, ScreenWrapEvent.ApproachTop, ScreenWrapState.NearEdgeTop),\n\t\t\t\tt(ScreenWrapState.NearEdgeBottom, ScreenWrapEvent.ApproachBottom, ScreenWrapState.NearEdgeBottom),\n\t\t\t]\n\t\t);\n\t}\n\n\tgetState(): ScreenWrapState {\n\t\treturn this.machine.getState();\n\t}\n\n\tdispatch(event: ScreenWrapEvent): void {\n\t\tif (this.machine.can(event)) {\n\t\t\tthis.machine.dispatch(event);\n\t\t}\n\t}\n\n\t/**\n\t * Update FSM based on entity position relative to bounds\n\t */\n\tupdate(position: { x: number; y: number }, bounds: {\n\t\tminX: number; maxX: number; minY: number; maxY: number;\n\t\tedgeThreshold: number;\n\t}, wrapped: boolean): void {\n\t\tconst { x, y } = position;\n\t\tconst { minX, maxX, minY, maxY, edgeThreshold } = bounds;\n\n\t\tif (wrapped) {\n\t\t\tthis.dispatch(ScreenWrapEvent.Wrap);\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if near edges\n\t\tconst nearLeft = x < minX + edgeThreshold;\n\t\tconst nearRight = x > maxX - edgeThreshold;\n\t\tconst nearBottom = y < minY + edgeThreshold;\n\t\tconst nearTop = y > maxY - edgeThreshold;\n\n\t\tif (nearLeft) {\n\t\t\tthis.dispatch(ScreenWrapEvent.ApproachLeft);\n\t\t} else if (nearRight) {\n\t\t\tthis.dispatch(ScreenWrapEvent.ApproachRight);\n\t\t} else if (nearTop) {\n\t\t\tthis.dispatch(ScreenWrapEvent.ApproachTop);\n\t\t} else if (nearBottom) {\n\t\t\tthis.dispatch(ScreenWrapEvent.ApproachBottom);\n\t\t} else {\n\t\t\tthis.dispatch(ScreenWrapEvent.EnterCenter);\n\t\t}\n\t}\n}\n","/**\n * ScreenWrapBehavior\n * \n * When an entity exits the defined 2D bounds, it wraps around to the opposite edge.\n * Asteroids-style screen wrapping with FSM for edge detection.\n */\n\nimport type { IWorld } from 'bitecs';\nimport { defineBehavior } from '../behavior-descriptor';\nimport type { BehaviorSystem } from '../behavior-system';\nimport { ScreenWrapFSM } from './screen-wrap-fsm';\n\n/**\n * Screen wrap options (typed for entity.use() autocomplete)\n */\nexport interface ScreenWrapOptions {\n\t/** Width of the wrapping area (default: 20) */\n\twidth: number;\n\t/** Height of the wrapping area (default: 15) */\n\theight: number;\n\t/** Center X position (default: 0) */\n\tcenterX: number;\n\t/** Center Y position (default: 0) */\n\tcenterY: number;\n\t/** Distance from edge to trigger NearEdge state (default: 2) */\n\tedgeThreshold: number;\n}\n\nconst defaultOptions: ScreenWrapOptions = {\n\twidth: 20,\n\theight: 15,\n\tcenterX: 0,\n\tcenterY: 0,\n\tedgeThreshold: 2,\n};\n\n/**\n * ScreenWrapSystem - Wraps entities around 2D bounds\n */\nclass ScreenWrapSystem implements BehaviorSystem {\n\tconstructor(private world: any) {}\n\n\tupdate(ecs: IWorld, delta: number): void {\n\t\tif (!this.world?.collisionMap) return;\n\n\t\tfor (const [, entity] of this.world.collisionMap) {\n\t\t\tconst gameEntity = entity as any;\n\t\t\t\n\t\t\tif (typeof gameEntity.getBehaviorRefs !== 'function') continue;\n\t\t\t\n\t\t\tconst refs = gameEntity.getBehaviorRefs();\n\t\t\tconst wrapRef = refs.find((r: any) => \n\t\t\t\tr.descriptor.key === Symbol.for('zylem:behavior:screen-wrap')\n\t\t\t);\n\t\t\t\n\t\t\tif (!wrapRef || !gameEntity.body) continue;\n\n\t\t\tconst options = wrapRef.options as ScreenWrapOptions;\n\n\t\t\t// Create FSM lazily\n\t\t\tif (!wrapRef.fsm) {\n\t\t\t\twrapRef.fsm = new ScreenWrapFSM();\n\t\t\t}\n\n\t\t\tconst wrapped = this.wrapEntity(gameEntity, options);\n\n\t\t\t// Update FSM with position and wrap state\n\t\t\tconst pos = gameEntity.body.translation();\n\t\t\tconst { width, height, centerX, centerY, edgeThreshold } = options;\n\t\t\tconst halfWidth = width / 2;\n\t\t\tconst halfHeight = height / 2;\n\n\t\t\twrapRef.fsm.update(\n\t\t\t\t{ x: pos.x, y: pos.y },\n\t\t\t\t{\n\t\t\t\t\tminX: centerX - halfWidth,\n\t\t\t\t\tmaxX: centerX + halfWidth,\n\t\t\t\t\tminY: centerY - halfHeight,\n\t\t\t\t\tmaxY: centerY + halfHeight,\n\t\t\t\t\tedgeThreshold,\n\t\t\t\t},\n\t\t\t\twrapped\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate wrapEntity(entity: any, options: ScreenWrapOptions): boolean {\n\t\tconst body = entity.body;\n\t\tif (!body) return false;\n\n\t\tconst { width, height, centerX, centerY } = options;\n\t\tconst halfWidth = width / 2;\n\t\tconst halfHeight = height / 2;\n\n\t\tconst minX = centerX - halfWidth;\n\t\tconst maxX = centerX + halfWidth;\n\t\tconst minY = centerY - halfHeight;\n\t\tconst maxY = centerY + halfHeight;\n\n\t\tconst pos = body.translation();\n\t\tlet newX = pos.x;\n\t\tlet newY = pos.y;\n\t\tlet wrapped = false;\n\n\t\t// Wrap X\n\t\tif (pos.x < minX) {\n\t\t\tnewX = maxX - (minX - pos.x);\n\t\t\twrapped = true;\n\t\t} else if (pos.x > maxX) {\n\t\t\tnewX = minX + (pos.x - maxX);\n\t\t\twrapped = true;\n\t\t}\n\n\t\t// Wrap Y\n\t\tif (pos.y < minY) {\n\t\t\tnewY = maxY - (minY - pos.y);\n\t\t\twrapped = true;\n\t\t} else if (pos.y > maxY) {\n\t\t\tnewY = minY + (pos.y - maxY);\n\t\t\twrapped = true;\n\t\t}\n\n\t\tif (wrapped) {\n\t\t\tbody.setTranslation({ x: newX, y: newY, z: pos.z }, true);\n\t\t}\n\n\t\treturn wrapped;\n\t}\n\n\tdestroy(_ecs: IWorld): void {\n\t\t// Cleanup if needed\n\t}\n}\n\n/**\n * ScreenWrapBehavior - Wraps entities around 2D bounds\n * \n * @example\n * ```typescript\n * import { ScreenWrapBehavior } from \"@zylem/game-lib\";\n * \n * const ship = createSprite({ ... });\n * const wrapRef = ship.use(ScreenWrapBehavior, { width: 20, height: 15 });\n * \n * // Access FSM to observe edge state\n * const fsm = wrapRef.getFSM();\n * console.log(fsm?.getState()); // 'center', 'near-edge-left', 'wrapped', etc.\n * ```\n */\nexport const ScreenWrapBehavior = defineBehavior({\n\tname: 'screen-wrap',\n\tdefaultOptions,\n\tsystemFactory: (ctx) => new ScreenWrapSystem(ctx.world),\n});\n\n","/**\n * Screen Wrap Behavior Module\n */\n\nexport { ScreenWrapBehavior, type ScreenWrapOptions } from './screen-wrap.descriptor';\nexport { ScreenWrapFSM, ScreenWrapState, ScreenWrapEvent } from './screen-wrap-fsm';\n","/**\n * WorldBoundary2DFSM\n *\n * Minimal FSM + extended state to track which world boundaries were hit.\n *\n * Notes:\n * - \"Hit boundaries\" is inherently a *set* (can hit left+bottom in one frame),\n * so we store it as extended state (`lastHits`) rather than a single FSM state.\n * - The FSM state is still useful for coarse status like \"inside\" vs \"touching\".\n */\n\nimport { StateMachine, t } from 'typescript-fsm';\n\nexport type WorldBoundary2DHit = 'top' | 'bottom' | 'left' | 'right';\nexport type WorldBoundary2DHits = Record<WorldBoundary2DHit, boolean>;\n\nexport interface WorldBoundary2DPosition {\n\tx: number;\n\ty: number;\n}\n\nexport interface WorldBoundary2DBounds {\n\ttop: number;\n\tbottom: number;\n\tleft: number;\n\tright: number;\n}\n\nexport enum WorldBoundary2DState {\n\tInside = 'inside',\n\tTouching = 'touching',\n}\n\nexport enum WorldBoundary2DEvent {\n\tEnterInside = 'enter-inside',\n\tTouchBoundary = 'touch-boundary',\n}\n\n/**\n * Compute which boundaries are being hit for a position and bounds.\n * This matches the semantics of the legacy `boundary2d` behavior:\n * - left hit if x <= left\n * - right hit if x >= right\n * - bottom hit if y <= bottom\n * - top hit if y >= top\n */\nexport function computeWorldBoundary2DHits(\n\tposition: WorldBoundary2DPosition,\n\tbounds: WorldBoundary2DBounds\n): WorldBoundary2DHits {\n\tconst hits: WorldBoundary2DHits = {\n\t\ttop: false,\n\t\tbottom: false,\n\t\tleft: false,\n\t\tright: false,\n\t};\n\n\tif (position.x <= bounds.left) hits.left = true;\n\telse if (position.x >= bounds.right) hits.right = true;\n\n\tif (position.y <= bounds.bottom) hits.bottom = true;\n\telse if (position.y >= bounds.top) hits.top = true;\n\n\treturn hits;\n}\n\nexport function hasAnyWorldBoundary2DHit(hits: WorldBoundary2DHits): boolean {\n\treturn !!(hits.left || hits.right || hits.top || hits.bottom);\n}\n\n/**\n * FSM wrapper with \"extended state\" (lastHits / lastPosition).\n * Systems should call `update(...)` once per frame.\n */\nexport class WorldBoundary2DFSM {\n\tpublic readonly machine: StateMachine<WorldBoundary2DState, WorldBoundary2DEvent, never>;\n\n\tprivate lastHits: WorldBoundary2DHits = { top: false, bottom: false, left: false, right: false };\n\tprivate lastPosition: WorldBoundary2DPosition | null = null;\n\tprivate lastUpdatedAtMs: number | null = null;\n\n\tconstructor() {\n\t\tthis.machine = new StateMachine<WorldBoundary2DState, WorldBoundary2DEvent, never>(\n\t\t\tWorldBoundary2DState.Inside,\n\t\t\t[\n\t\t\t\tt(WorldBoundary2DState.Inside, WorldBoundary2DEvent.TouchBoundary, WorldBoundary2DState.Touching),\n\t\t\t\tt(WorldBoundary2DState.Touching, WorldBoundary2DEvent.EnterInside, WorldBoundary2DState.Inside),\n\n\t\t\t\t// Self transitions (no-ops)\n\t\t\t\tt(WorldBoundary2DState.Inside, WorldBoundary2DEvent.EnterInside, WorldBoundary2DState.Inside),\n\t\t\t\tt(WorldBoundary2DState.Touching, WorldBoundary2DEvent.TouchBoundary, WorldBoundary2DState.Touching),\n\t\t\t]\n\t\t);\n\t}\n\n\tgetState(): WorldBoundary2DState {\n\t\treturn this.machine.getState();\n\t}\n\n\t/**\n\t * Returns the last computed hits (always available after first update call).\n\t */\n\tgetLastHits(): WorldBoundary2DHits {\n\t\treturn this.lastHits;\n\t}\n\n\t/**\n\t * Returns adjusted movement values based on boundary hits.\n\t * If the entity is touching a boundary and trying to move further into it,\n\t * that axis component is zeroed out.\n\t *\n\t * @param moveX - The desired X movement\n\t * @param moveY - The desired Y movement\n\t * @returns Adjusted { moveX, moveY } with boundary-blocked axes zeroed\n\t */\n\tgetMovement(moveX: number, moveY: number): { moveX: number; moveY: number } {\n\t\tconst hits = this.lastHits;\n\n\t\tlet adjustedX = moveX;\n\t\tlet adjustedY = moveY;\n\n\t\t// If moving left and hitting left, or moving right and hitting right, zero X\n\t\tif ((hits.left && moveX < 0) || (hits.right && moveX > 0)) {\n\t\t\tadjustedX = 0;\n\t\t}\n\n\t\t// If moving down and hitting bottom, or moving up and hitting top, zero Y\n\t\tif ((hits.bottom && moveY < 0) || (hits.top && moveY > 0)) {\n\t\t\tadjustedY = 0;\n\t\t}\n\n\t\treturn { moveX: adjustedX, moveY: adjustedY };\n\t}\n\n\t/**\n\t * Returns the last position passed to `update`, if any.\n\t */\n\tgetLastPosition(): WorldBoundary2DPosition | null {\n\t\treturn this.lastPosition;\n\t}\n\n\t/**\n\t * Best-effort timestamp (ms) of the last `update(...)` call.\n\t * This is optional metadata; systems can ignore it.\n\t */\n\tgetLastUpdatedAtMs(): number | null {\n\t\treturn this.lastUpdatedAtMs;\n\t}\n\n\t/**\n\t * Update FSM + extended state based on current position and bounds.\n\t * Returns the computed hits for convenience.\n\t */\n\tupdate(position: WorldBoundary2DPosition, bounds: WorldBoundary2DBounds): WorldBoundary2DHits {\n\t\tconst hits = computeWorldBoundary2DHits(position, bounds);\n\n\t\tthis.lastHits = hits;\n\t\tthis.lastPosition = { x: position.x, y: position.y };\n\t\tthis.lastUpdatedAtMs = Date.now();\n\n\t\tif (hasAnyWorldBoundary2DHit(hits)) {\n\t\t\tthis.dispatch(WorldBoundary2DEvent.TouchBoundary);\n\t\t} else {\n\t\t\tthis.dispatch(WorldBoundary2DEvent.EnterInside);\n\t\t}\n\n\t\treturn hits;\n\t}\n\n\tprivate dispatch(event: WorldBoundary2DEvent): void {\n\t\tif (this.machine.can(event)) {\n\t\t\tthis.machine.dispatch(event);\n\t\t}\n\t}\n}\n","/**\n * WorldBoundary2DBehavior\n *\n * Tracks which 2D world boundaries an entity is touching.\n * Use `getMovement()` on the behavior handle to adjust movement based on hits.\n *\n * Source of truth: `entity.body` (Rapier rigid body), consistent with other new behaviors.\n */\n\nimport type { IWorld } from 'bitecs';\nimport { defineBehavior, type BehaviorRef } from '../behavior-descriptor';\nimport type { BehaviorSystem } from '../behavior-system';\nimport {\n\tWorldBoundary2DFSM,\n\ttype WorldBoundary2DBounds,\n\ttype WorldBoundary2DHits,\n} from './world-boundary-2d-fsm';\n\nexport interface WorldBoundary2DOptions {\n\t/**\n\t * World boundaries (in world units).\n\t * - left hit if x <= left\n\t * - right hit if x >= right\n\t * - bottom hit if y <= bottom\n\t * - top hit if y >= top\n\t */\n\tboundaries: WorldBoundary2DBounds;\n}\n\n/**\n * Handle methods provided by WorldBoundary2DBehavior\n */\nexport interface WorldBoundary2DHandle {\n\t/**\n\t * Get the last computed boundary hits.\n\t * Returns null until entity is spawned and FSM is initialized.\n\t */\n\tgetLastHits(): WorldBoundary2DHits | null;\n\n\t/**\n\t * Get adjusted movement values based on boundary hits.\n\t * Zeros out movement into boundaries the entity is touching.\n\t */\n\tgetMovement(moveX: number, moveY: number): { moveX: number; moveY: number };\n}\n\nconst defaultOptions: WorldBoundary2DOptions = {\n\tboundaries: { top: 0, bottom: 0, left: 0, right: 0 },\n};\n\n/**\n * Creates behavior-specific handle methods for WorldBoundary2DBehavior.\n */\nfunction createWorldBoundary2DHandle(\n\tref: BehaviorRef<WorldBoundary2DOptions>\n): WorldBoundary2DHandle {\n\treturn {\n\t\tgetLastHits: () => {\n\t\t\tconst fsm = ref.fsm as WorldBoundary2DFSM | undefined;\n\t\t\treturn fsm?.getLastHits() ?? null;\n\t\t},\n\t\tgetMovement: (moveX: number, moveY: number) => {\n\t\t\tconst fsm = ref.fsm as WorldBoundary2DFSM | undefined;\n\t\t\treturn fsm?.getMovement(moveX, moveY) ?? { moveX, moveY };\n\t\t},\n\t};\n}\n\n/**\n * WorldBoundary2DSystem\n *\n * Stage-level system that:\n * - finds entities with this behavior attached\n * - computes and tracks boundary hits using the FSM\n */\nclass WorldBoundary2DSystem implements BehaviorSystem {\n\tconstructor(private world: any) {}\n\n\tupdate(_ecs: IWorld, _delta: number): void {\n\t\tif (!this.world?.collisionMap) return;\n\n\t\tfor (const [, entity] of this.world.collisionMap) {\n\t\t\tconst gameEntity = entity as any;\n\n\t\t\tif (typeof gameEntity.getBehaviorRefs !== 'function') continue;\n\n\t\t\tconst refs = gameEntity.getBehaviorRefs();\n\t\t\tconst boundaryRef = refs.find(\n\t\t\t\t(r: any) => r.descriptor.key === Symbol.for('zylem:behavior:world-boundary-2d')\n\t\t\t);\n\n\t\t\tif (!boundaryRef || !gameEntity.body) continue;\n\n\t\t\tconst options = boundaryRef.options as WorldBoundary2DOptions;\n\n\t\t\t// Create FSM lazily on first update after spawn\n\t\t\tif (!boundaryRef.fsm) {\n\t\t\t\tboundaryRef.fsm = new WorldBoundary2DFSM();\n\t\t\t}\n\n\t\t\tconst body = gameEntity.body;\n\t\t\tconst pos = body.translation();\n\n\t\t\t// Update FSM with current position - consumers use getMovement() to act on hits\n\t\t\tboundaryRef.fsm.update(\n\t\t\t\t{ x: pos.x, y: pos.y },\n\t\t\t\toptions.boundaries\n\t\t\t);\n\t\t}\n\t}\n\n\tdestroy(_ecs: IWorld): void {\n\t\t// No explicit cleanup required (FSMs are stored on behavior refs)\n\t}\n}\n\n/**\n * WorldBoundary2DBehavior\n *\n * @example\n * ```ts\n * import { WorldBoundary2DBehavior } from \"@zylem/game-lib\";\n *\n * const ship = createSprite({ ... });\n * const boundary = ship.use(WorldBoundary2DBehavior, {\n * boundaries: { left: -10, right: 10, bottom: -7.5, top: 7.5 },\n * });\n *\n * ship.onUpdate(({ me }) => {\n * let moveX = ..., moveY = ...;\n * const hits = boundary.getLastHits(); // Fully typed!\n * ({ moveX, moveY } = boundary.getMovement(moveX, moveY));\n * me.moveXY(moveX, moveY);\n * });\n * ```\n */\nexport const WorldBoundary2DBehavior = defineBehavior({\n\tname: 'world-boundary-2d',\n\tdefaultOptions,\n\tsystemFactory: (ctx) => new WorldBoundary2DSystem(ctx.world),\n\tcreateHandle: createWorldBoundary2DHandle,\n});\n","/**\n * World Boundary 2D Module\n *\n * Barrel exports for the `world-boundary-2d` behavior and its FSM helpers.\n */\nexport { WorldBoundary2DBehavior } from './world-boundary-2d.descriptor';\n\nexport {\n\tWorldBoundary2DFSM,\n\tcomputeWorldBoundary2DHits,\n\thasAnyWorldBoundary2DHit,\n\ttype WorldBoundary2DHit,\n\ttype WorldBoundary2DHits,\n\ttype WorldBoundary2DPosition,\n\ttype WorldBoundary2DBounds,\n\tWorldBoundary2DState,\n\tWorldBoundary2DEvent,\n} from './world-boundary-2d-fsm';\n\nexport type {\n\tWorldBoundary2DOptions,\n\tWorldBoundary2DHandle,\n} from './world-boundary-2d.descriptor';\n","/**\n * Ricochet2DFSM\n *\n * FSM + extended state to track ricochet events and results.\n * The FSM state tracks whether a ricochet is currently occurring.\n */\nimport { BaseEntityInterface } from \"../../types/entity-types\";\nimport { StateMachine, t } from 'typescript-fsm';\n\nexport interface Ricochet2DResult {\n\t/** The reflected velocity vector */\n\tvelocity: { x: number; y: number; z?: number };\n\t/** The resulting speed after reflection */\n\tspeed: number;\n\t/** The collision normal used for reflection */\n\tnormal: { x: number; y: number; z?: number };\n}\n\nexport interface Ricochet2DCollisionContext {\n\tentity?: BaseEntityInterface;\n\totherEntity?: BaseEntityInterface;\n\t/** Current velocity of the entity (optional if entity is provided) */\n\tselfVelocity?: { x: number; y: number; z?: number };\n\t/** Contact information from the collision */\n\tcontact: {\n\t\t/** The collision normal */\n\t\tnormal?: { x: number; y: number; z?: number };\n\t\t/**\n\t\t * Optional position where the collision occurred.\n\t\t * If provided, used for precise offset calculation.\n\t\t */\n\t\tposition?: { x: number; y: number; z?: number };\n\t};\n\t/**\n\t * Optional position of the entity that owns this behavior.\n\t * Used with contact.position for offset calculations.\n\t */\n\tselfPosition?: { x: number; y: number; z?: number };\n\t/**\n\t * Optional position of the other entity in the collision.\n\t * Used for paddle-style deflection: offset = (contactY - otherY) / halfHeight.\n\t */\n\totherPosition?: { x: number; y: number; z?: number };\n\t/**\n\t * Optional size of the other entity (e.g., paddle size).\n\t * If provided, used to normalize the offset based on the collision face.\n\t */\n\totherSize?: { x: number; y: number; z?: number };\n}\n\nexport enum Ricochet2DState {\n\tIdle = 'idle',\n\tRicocheting = 'ricocheting',\n}\n\nexport enum Ricochet2DEvent {\n\tStartRicochet = 'start-ricochet',\n\tEndRicochet = 'end-ricochet',\n}\n\nfunction clamp(value: number, min: number, max: number): number {\n\treturn Math.max(min, Math.min(max, value));\n}\n\n/**\n * FSM wrapper with extended state (lastResult).\n * Systems or consumers call `computeRicochet(...)` when a collision occurs.\n */\nexport class Ricochet2DFSM {\n\tpublic readonly machine: StateMachine<Ricochet2DState, Ricochet2DEvent, never>;\n\n\tprivate lastResult: Ricochet2DResult | null = null;\n\tprivate lastUpdatedAtMs: number | null = null;\n\n\tconstructor() {\n\t\tthis.machine = new StateMachine<Ricochet2DState, Ricochet2DEvent, never>(\n\t\t\tRicochet2DState.Idle,\n\t\t\t[\n\t\t\t\tt(Ricochet2DState.Idle, Ricochet2DEvent.StartRicochet, Ricochet2DState.Ricocheting),\n\t\t\t\tt(Ricochet2DState.Ricocheting, Ricochet2DEvent.EndRicochet, Ricochet2DState.Idle),\n\n\t\t\t\t// Self transitions (no-ops)\n\t\t\t\tt(Ricochet2DState.Idle, Ricochet2DEvent.EndRicochet, Ricochet2DState.Idle),\n\t\t\t\tt(Ricochet2DState.Ricocheting, Ricochet2DEvent.StartRicochet, Ricochet2DState.Ricocheting),\n\t\t\t]\n\t\t);\n\t}\n\n\tgetState(): Ricochet2DState {\n\t\treturn this.machine.getState();\n\t}\n\n\t/**\n\t * Returns the last computed ricochet result, or null if none.\n\t */\n\tgetLastResult(): Ricochet2DResult | null {\n\t\treturn this.lastResult;\n\t}\n\n\t/**\n\t * Best-effort timestamp (ms) of the last computation.\n\t */\n\tgetLastUpdatedAtMs(): number | null {\n\t\treturn this.lastUpdatedAtMs;\n\t}\n\n\t/**\n\t * Compute a ricochet result from collision context.\n\t * Returns the result for the consumer to apply, or null if invalid input.\n\t */\n\tcomputeRicochet(\n\t\tctx: Ricochet2DCollisionContext,\n\t\toptions: {\n\t\t\tminSpeed?: number;\n\t\t\tmaxSpeed?: number;\n\t\t\tspeedMultiplier?: number;\n\t\t\treflectionMode?: 'simple' | 'angled';\n\t\t\tmaxAngleDeg?: number;\n\t\t} = {}\n\t): Ricochet2DResult | null {\n\t\tconst {\n\t\t\tminSpeed = 2,\n\t\t\tmaxSpeed = 20,\n\t\t\tspeedMultiplier = 1.05,\n\t\t\treflectionMode = 'angled',\n\t\t\tmaxAngleDeg = 60,\n\t\t} = options;\n\n\t\t// Extract data from entities if provided\n\t\tconst { selfVelocity, selfPosition, otherPosition, otherSize } = this.extractDataFromEntities(ctx);\n\n\t\tif (!selfVelocity) {\n\t\t\tthis.dispatch(Ricochet2DEvent.EndRicochet);\n\t\t\treturn null;\n\t\t}\n\n\t\tconst speed = Math.hypot(selfVelocity.x, selfVelocity.y);\n\t\tif (speed === 0) {\n\t\t\tthis.dispatch(Ricochet2DEvent.EndRicochet);\n\t\t\treturn null;\n\t\t}\n\n\t\t// Compute or extract collision normal\n\t\tconst normal = ctx.contact.normal ?? this.computeNormalFromPositions(selfPosition, otherPosition);\n\t\tif (!normal) {\n\t\t\tthis.dispatch(Ricochet2DEvent.EndRicochet);\n\t\t\treturn null;\n\t\t}\n\n\t\t// Compute basic reflection\n\t\tlet reflected = this.computeBasicReflection(selfVelocity, normal);\n\n\t\t// Apply angled deflection if requested\n\t\tif (reflectionMode === 'angled') {\n\t\t\treflected = this.computeAngledDeflection(\n\t\t\t\tselfVelocity,\n\t\t\t\tnormal,\n\t\t\t\tspeed,\n\t\t\t\tmaxAngleDeg,\n\t\t\t\tspeedMultiplier,\n\t\t\t\tselfPosition,\n\t\t\t\totherPosition,\n\t\t\t\totherSize,\n\t\t\t\tctx.contact.position\n\t\t\t);\n\t\t}\n\n\t\t// Apply final speed constraints\n\t\treflected = this.applySpeedClamp(reflected, minSpeed, maxSpeed);\n\n\t\tconst result: Ricochet2DResult = {\n\t\t\tvelocity: { x: reflected.x, y: reflected.y, z: 0 },\n\t\t\tspeed: Math.hypot(reflected.x, reflected.y),\n\t\t\tnormal: { x: normal.x, y: normal.y, z: 0 },\n\t\t};\n\n\t\tthis.lastResult = result;\n\t\tthis.lastUpdatedAtMs = Date.now();\n\t\tthis.dispatch(Ricochet2DEvent.StartRicochet);\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Extract velocity, position, and size data from entities or context.\n\t */\n\tprivate extractDataFromEntities(ctx: Ricochet2DCollisionContext) {\n\t\tlet selfVelocity = ctx.selfVelocity;\n\t\tlet selfPosition = ctx.selfPosition;\n\t\tlet otherPosition = ctx.otherPosition;\n\t\tlet otherSize = ctx.otherSize;\n\n\t\tif (ctx.entity?.body) {\n\t\t\tconst vel = ctx.entity.body.linvel();\n\t\t\tselfVelocity = selfVelocity ?? { x: vel.x, y: vel.y, z: vel.z };\n\t\t\tconst pos = ctx.entity.body.translation();\n\t\t\tselfPosition = selfPosition ?? { x: pos.x, y: pos.y, z: pos.z };\n\t\t}\n\n\t\tif (ctx.otherEntity?.body) {\n\t\t\tconst pos = ctx.otherEntity.body.translation();\n\t\t\totherPosition = otherPosition ?? { x: pos.x, y: pos.y, z: pos.z };\n\t\t}\n\n\t\tif (ctx.otherEntity && 'size' in ctx.otherEntity) {\n\t\t\tconst size = (ctx.otherEntity as any).size;\n\t\t\tif (size && typeof size.x === 'number') {\n\t\t\t\totherSize = otherSize ?? { x: size.x, y: size.y, z: size.z };\n\t\t\t}\n\t\t}\n\n\t\treturn { selfVelocity, selfPosition, otherPosition, otherSize };\n\t}\n\n\t/**\n\t * Compute collision normal from entity positions using AABB heuristic.\n\t */\n\tprivate computeNormalFromPositions(\n\t\tselfPosition?: { x: number; y: number; z?: number },\n\t\totherPosition?: { x: number; y: number; z?: number }\n\t): { x: number; y: number; z?: number } | null {\n\t\tif (!selfPosition || !otherPosition) return null;\n\n\t\tconst dx = selfPosition.x - otherPosition.x;\n\t\tconst dy = selfPosition.y - otherPosition.y;\n\n\t\t// Simple \"which face was hit\" logic for box collisions\n\t\tif (Math.abs(dx) > Math.abs(dy)) {\n\t\t\treturn { x: dx > 0 ? 1 : -1, y: 0, z: 0 };\n\t\t} else {\n\t\t\treturn { x: 0, y: dy > 0 ? 1 : -1, z: 0 };\n\t\t}\n\t}\n\n\t/**\n\t * Compute basic reflection using the formula: v' = v - 2(v·n)n\n\t */\n\tprivate computeBasicReflection(\n\t\tvelocity: { x: number; y: number },\n\t\tnormal: { x: number; y: number; z?: number }\n\t): { x: number; y: number } {\n\t\tconst vx = velocity.x;\n\t\tconst vy = velocity.y;\n\t\tconst dotProduct = vx * normal.x + vy * normal.y;\n\n\t\treturn {\n\t\t\tx: vx - 2 * dotProduct * normal.x,\n\t\t\ty: vy - 2 * dotProduct * normal.y,\n\t\t};\n\t}\n\n\t/**\n\t * Compute angled deflection for paddle-style reflections.\n\t */\n\tprivate computeAngledDeflection(\n\t\tvelocity: { x: number; y: number },\n\t\tnormal: { x: number; y: number; z?: number },\n\t\tspeed: number,\n\t\tmaxAngleDeg: number,\n\t\tspeedMultiplier: number,\n\t\tselfPosition?: { x: number; y: number; z?: number },\n\t\totherPosition?: { x: number; y: number; z?: number },\n\t\totherSize?: { x: number; y: number; z?: number },\n\t\tcontactPosition?: { x: number; y: number; z?: number }\n\t): { x: number; y: number } {\n\t\tconst maxAngleRad = (maxAngleDeg * Math.PI) / 180;\n\n\t\t// Tangent vector (perpendicular to normal)\n\t\tlet tx = -normal.y;\n\t\tlet ty = normal.x;\n\n\t\t// Ensure tangent points in positive direction of the deflection axis\n\t\t// so that positive offset (right/top) results in positive deflection\n\t\tif (Math.abs(normal.x) > Math.abs(normal.y)) {\n\t\t\t// Vertical face (Normal is X-aligned). Deflection axis is Y.\n\t\t\t// We want ty > 0.\n\t\t\tif (ty < 0) {\n\t\t\t\ttx = -tx;\n\t\t\t\tty = -ty;\n\t\t\t}\n\t\t} else {\n\t\t\t// Horizontal face (Normal is Y-aligned). Deflection axis is X.\n\t\t\t// We want tx > 0.\n\t\t\tif (tx < 0) {\n\t\t\t\ttx = -tx;\n\t\t\t\tty = -ty;\n\t\t\t}\n\t\t}\n\n\t\t// Compute offset based on hit position\n\t\tconst offset = this.computeHitOffset(\n\t\t\tvelocity,\n\t\t\tnormal,\n\t\t\tspeed,\n\t\t\ttx,\n\t\t\tty,\n\t\t\tselfPosition,\n\t\t\totherPosition,\n\t\t\totherSize,\n\t\t\tcontactPosition\n\t\t);\n\n\t\tconst angle = clamp(offset, -1, 1) * maxAngleRad;\n\n\t\tconst cosA = Math.cos(angle);\n\t\tconst sinA = Math.sin(angle);\n\n\t\tconst newSpeed = speed * speedMultiplier;\n\n\t\treturn {\n\t\t\tx: newSpeed * (normal.x * cosA + tx * sinA),\n\t\t\ty: newSpeed * (normal.y * cosA + ty * sinA),\n\t\t};\n\t}\n\n\t/**\n\t * Compute hit offset for angled deflection (-1 to 1).\n\t */\n\tprivate computeHitOffset(\n\t\tvelocity: { x: number; y: number },\n\t\tnormal: { x: number; y: number; z?: number },\n\t\tspeed: number,\n\t\ttx: number,\n\t\tty: number,\n\t\tselfPosition?: { x: number; y: number; z?: number },\n\t\totherPosition?: { x: number; y: number; z?: number },\n\t\totherSize?: { x: number; y: number; z?: number },\n\t\tcontactPosition?: { x: number; y: number; z?: number }\n\t): number {\n\t\t// Use position-based offset if available\n\t\tif (otherPosition && otherSize) {\n\t\t\tconst useY = Math.abs(normal.x) > Math.abs(normal.y);\n\t\t\tconst halfExtent = useY ? otherSize.y / 2 : otherSize.x / 2;\n\n\t\t\tif (useY) {\n\t\t\t\tconst selfY = selfPosition?.y ?? contactPosition?.y ?? 0;\n\t\t\t\tconst paddleY = otherPosition.y;\n\t\t\t\treturn (selfY - paddleY) / halfExtent;\n\t\t\t} else {\n\t\t\t\tconst selfX = selfPosition?.x ?? contactPosition?.x ?? 0;\n\t\t\t\tconst paddleX = otherPosition.x;\n\t\t\t\treturn (selfX - paddleX) / halfExtent;\n\t\t\t}\n\t\t}\n\n\t\t// Fallback: use velocity-based offset\n\t\treturn (velocity.x * tx + velocity.y * ty) / speed;\n\t}\n\n\t/**\n\t * Apply speed constraints to the reflected velocity.\n\t */\n\tprivate applySpeedClamp(\n\t\tvelocity: { x: number; y: number },\n\t\tminSpeed: number,\n\t\tmaxSpeed: number\n\t): { x: number; y: number } {\n\t\tconst currentSpeed = Math.hypot(velocity.x, velocity.y);\n\t\tif (currentSpeed === 0) return velocity;\n\n\t\tconst targetSpeed = clamp(currentSpeed, minSpeed, maxSpeed);\n\t\tconst scale = targetSpeed / currentSpeed;\n\n\t\treturn {\n\t\t\tx: velocity.x * scale,\n\t\t\ty: velocity.y * scale,\n\t\t};\n\t}\n\n\t/**\n\t * Clear the ricochet state (call after consumer has applied the result).\n\t */\n\tclearRicochet(): void {\n\t\tthis.dispatch(Ricochet2DEvent.EndRicochet);\n\t}\n\n\tprivate dispatch(event: Ricochet2DEvent): void {\n\t\tif (this.machine.can(event)) {\n\t\t\tthis.machine.dispatch(event);\n\t\t}\n\t}\n}\n","/**\n * Ricochet2DBehavior\n *\n * Computes 2D ricochet/reflection results for entities during collisions.\n * The behavior computes the result; the consumer decides how to apply it.\n *\n * Use `getRicochet(ctx)` on the behavior handle to compute reflection results.\n */\n\nimport type { IWorld } from 'bitecs';\nimport { defineBehavior, type BehaviorRef } from '../behavior-descriptor';\nimport type { BehaviorSystem } from '../behavior-system';\nimport { Ricochet2DFSM, type Ricochet2DResult, type Ricochet2DCollisionContext } from './ricochet-2d-fsm';\nexport type { Ricochet2DResult };\n\nexport interface Ricochet2DOptions {\n\t/**\n\t * Minimum speed after reflection.\n\t * Default: 2\n\t */\n\tminSpeed: number;\n\n\t/**\n\t * Maximum speed after reflection.\n\t * Default: 20\n\t */\n\tmaxSpeed: number;\n\n\t/**\n\t * Speed multiplier applied during angled reflection.\n\t * Default: 1.05\n\t */\n\tspeedMultiplier: number;\n\n\t/**\n\t * Reflection mode:\n\t * - 'simple': Basic axis inversion\n\t * - 'angled': Paddle-style deflection based on contact point\n\t * Default: 'angled'\n\t */\n\treflectionMode: 'simple' | 'angled';\n\n\t/**\n\t * Maximum deflection angle in degrees for angled mode.\n\t * Default: 60\n\t */\n\tmaxAngleDeg: number;\n}\n\n/**\n * Handle methods provided by Ricochet2DBehavior\n */\nexport interface Ricochet2DHandle {\n\t/**\n\t * Compute a ricochet/reflection result from collision context.\n\t * Returns the result for the consumer to apply, or null if invalid input.\n\t *\n\t * @param ctx - Collision context with selfVelocity and contact normal\n\t * @returns Ricochet result with velocity, speed, and normal, or null\n\t */\n\tgetRicochet(ctx: Ricochet2DCollisionContext): Ricochet2DResult | null;\n\n\t/**\n\t * Get the last computed ricochet result, or null if none.\n\t */\n\tgetLastResult(): Ricochet2DResult | null;\n}\n\nconst defaultOptions: Ricochet2DOptions = {\n\tminSpeed: 2,\n\tmaxSpeed: 20,\n\tspeedMultiplier: 1.05,\n\treflectionMode: 'angled',\n\tmaxAngleDeg: 60,\n};\n\n/**\n * Creates behavior-specific handle methods for Ricochet2DBehavior.\n */\nfunction createRicochet2DHandle(\n\tref: BehaviorRef<Ricochet2DOptions>\n): Ricochet2DHandle {\n\treturn {\n\t\tgetRicochet: (ctx: Ricochet2DCollisionContext) => {\n\t\t\tconst fsm = ref.fsm as Ricochet2DFSM | undefined;\n\t\t\tif (!fsm) return null;\n\t\t\treturn fsm.computeRicochet(ctx, ref.options);\n\t\t},\n\t\tgetLastResult: () => {\n\t\t\tconst fsm = ref.fsm as Ricochet2DFSM | undefined;\n\t\t\treturn fsm?.getLastResult() ?? null;\n\t\t},\n\t};\n}\n\n/**\n * Ricochet2DSystem\n *\n * Stage-level system that:\n * - finds entities with this behavior attached\n * - lazily creates FSM instances for each entity\n *\n * Note: This behavior is consumer-driven. The system only manages FSM lifecycle.\n * Consumers call `getRicochet(ctx)` during collision callbacks to compute results.\n */\nclass Ricochet2DSystem implements BehaviorSystem {\n\tconstructor(private world: any) {}\n\n\tupdate(_ecs: IWorld, _delta: number): void {\n\t\tif (!this.world?.collisionMap) return;\n\n\t\tfor (const [, entity] of this.world.collisionMap) {\n\t\t\tconst gameEntity = entity as any;\n\n\t\t\tif (typeof gameEntity.getBehaviorRefs !== 'function') continue;\n\n\t\t\tconst refs = gameEntity.getBehaviorRefs();\n\t\t\tconst ricochetRef = refs.find(\n\t\t\t\t(r: any) => r.descriptor.key === Symbol.for('zylem:behavior:ricochet-2d')\n\t\t\t);\n\n\t\t\tif (!ricochetRef) continue;\n\n\t\t\t// Create FSM lazily on first update after spawn\n\t\t\tif (!ricochetRef.fsm) {\n\t\t\t\tricochetRef.fsm = new Ricochet2DFSM();\n\t\t\t}\n\t\t}\n\t}\n\n\tdestroy(_ecs: IWorld): void {\n\t\t// No explicit cleanup required (FSMs are stored on behavior refs)\n\t}\n}\n\n/**\n * Ricochet2DBehavior\n *\n * @example\n * ```ts\n * import { Ricochet2DBehavior } from \"@zylem/game-lib\";\n *\n * const ball = createSphere({ ... });\n * const ricochet = ball.use(Ricochet2DBehavior, {\n * minSpeed: 3,\n * maxSpeed: 15,\n * reflectionMode: 'angled',\n * });\n *\n * ball.onCollision(({ entity, other }) => {\n * const velocity = entity.body.linvel();\n * const result = ricochet.getRicochet({\n * selfVelocity: velocity,\n * contact: { normal: { x: 1, y: 0 } }, // from collision data\n * });\n *\n * if (result) {\n * entity.body.setLinvel(result.velocity, true);\n * }\n * });\n * ```\n */\nexport const Ricochet2DBehavior = defineBehavior({\n\tname: 'ricochet-2d',\n\tdefaultOptions,\n\tsystemFactory: (ctx) => new Ricochet2DSystem(ctx.world),\n\tcreateHandle: createRicochet2DHandle,\n});\n","/**\n * Ricochet 2D Behavior Module\n *\n * Exports FSM, types, and behavior descriptor for 2D ricochet/reflection.\n */\n\n// FSM and types\nexport {\n\tRicochet2DFSM,\n\tRicochet2DState,\n\tRicochet2DEvent,\n\ttype Ricochet2DResult,\n\ttype Ricochet2DCollisionContext,\n} from './ricochet-2d-fsm';\n\n// Behavior descriptor, options, and handle\nexport {\n\tRicochet2DBehavior,\n\ttype Ricochet2DOptions,\n\ttype Ricochet2DHandle,\n} from './ricochet-2d.descriptor';\n\n","/**\n * MovementSequence2DFSM\n *\n * FSM + extended state to manage timed movement sequences.\n * Tracks current step, time remaining, and computes movement for consumer.\n */\n\nimport { StateMachine, t } from 'typescript-fsm';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Types\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface MovementSequence2DStep {\n\t/** Identifier for this step */\n\tname: string;\n\t/** X velocity for this step */\n\tmoveX?: number;\n\t/** Y velocity for this step */\n\tmoveY?: number;\n\t/** Duration in seconds */\n\ttimeInSeconds: number;\n}\n\nexport interface MovementSequence2DMovement {\n\tmoveX: number;\n\tmoveY: number;\n}\n\nexport interface MovementSequence2DProgress {\n\tstepIndex: number;\n\ttotalSteps: number;\n\tstepTimeRemaining: number;\n\tdone: boolean;\n}\n\nexport interface MovementSequence2DCurrentStep {\n\tname: string;\n\tindex: number;\n\tmoveX: number;\n\tmoveY: number;\n\ttimeRemaining: number;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// FSM State Model\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport enum MovementSequence2DState {\n\tIdle = 'idle',\n\tRunning = 'running',\n\tPaused = 'paused',\n\tCompleted = 'completed',\n}\n\nexport enum MovementSequence2DEvent {\n\tStart = 'start',\n\tPause = 'pause',\n\tResume = 'resume',\n\tComplete = 'complete',\n\tReset = 'reset',\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// FSM Implementation\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport class MovementSequence2DFSM {\n\tpublic readonly machine: StateMachine<MovementSequence2DState, MovementSequence2DEvent, never>;\n\n\tprivate sequence: MovementSequence2DStep[] = [];\n\tprivate loop: boolean = true;\n\tprivate currentIndex: number = 0;\n\tprivate timeRemaining: number = 0;\n\n\tconstructor() {\n\t\tthis.machine = new StateMachine<MovementSequence2DState, MovementSequence2DEvent, never>(\n\t\t\tMovementSequence2DState.Idle,\n\t\t\t[\n\t\t\t\t// From Idle\n\t\t\t\tt(MovementSequence2DState.Idle, MovementSequence2DEvent.Start, MovementSequence2DState.Running),\n\n\t\t\t\t// From Running\n\t\t\t\tt(MovementSequence2DState.Running, MovementSequence2DEvent.Pause, MovementSequence2DState.Paused),\n\t\t\t\tt(MovementSequence2DState.Running, MovementSequence2DEvent.Complete, MovementSequence2DState.Completed),\n\t\t\t\tt(MovementSequence2DState.Running, MovementSequence2DEvent.Reset, MovementSequence2DState.Idle),\n\n\t\t\t\t// From Paused\n\t\t\t\tt(MovementSequence2DState.Paused, MovementSequence2DEvent.Resume, MovementSequence2DState.Running),\n\t\t\t\tt(MovementSequence2DState.Paused, MovementSequence2DEvent.Reset, MovementSequence2DState.Idle),\n\n\t\t\t\t// From Completed\n\t\t\t\tt(MovementSequence2DState.Completed, MovementSequence2DEvent.Reset, MovementSequence2DState.Idle),\n\t\t\t\tt(MovementSequence2DState.Completed, MovementSequence2DEvent.Start, MovementSequence2DState.Running),\n\n\t\t\t\t// Self-transitions (no-ops)\n\t\t\t\tt(MovementSequence2DState.Idle, MovementSequence2DEvent.Pause, MovementSequence2DState.Idle),\n\t\t\t\tt(MovementSequence2DState.Idle, MovementSequence2DEvent.Resume, MovementSequence2DState.Idle),\n\t\t\t\tt(MovementSequence2DState.Running, MovementSequence2DEvent.Start, MovementSequence2DState.Running),\n\t\t\t\tt(MovementSequence2DState.Running, MovementSequence2DEvent.Resume, MovementSequence2DState.Running),\n\t\t\t\tt(MovementSequence2DState.Paused, MovementSequence2DEvent.Pause, MovementSequence2DState.Paused),\n\t\t\t\tt(MovementSequence2DState.Completed, MovementSequence2DEvent.Complete, MovementSequence2DState.Completed),\n\t\t\t]\n\t\t);\n\t}\n\n\t/**\n\t * Initialize the sequence. Call this once with options.\n\t */\n\tinit(sequence: MovementSequence2DStep[], loop: boolean): void {\n\t\tthis.sequence = sequence;\n\t\tthis.loop = loop;\n\t\tthis.currentIndex = 0;\n\t\tthis.timeRemaining = sequence.length > 0 ? sequence[0].timeInSeconds : 0;\n\t}\n\n\tgetState(): MovementSequence2DState {\n\t\treturn this.machine.getState();\n\t}\n\n\t/**\n\t * Start the sequence (from Idle or Completed).\n\t */\n\tstart(): void {\n\t\tif (this.machine.getState() === MovementSequence2DState.Idle ||\n\t\t this.machine.getState() === MovementSequence2DState.Completed) {\n\t\t\tthis.currentIndex = 0;\n\t\t\tthis.timeRemaining = this.sequence.length > 0 ? this.sequence[0].timeInSeconds : 0;\n\t\t}\n\t\tthis.dispatch(MovementSequence2DEvent.Start);\n\t}\n\n\t/**\n\t * Pause the sequence.\n\t */\n\tpause(): void {\n\t\tthis.dispatch(MovementSequence2DEvent.Pause);\n\t}\n\n\t/**\n\t * Resume a paused sequence.\n\t */\n\tresume(): void {\n\t\tthis.dispatch(MovementSequence2DEvent.Resume);\n\t}\n\n\t/**\n\t * Reset to Idle state.\n\t */\n\treset(): void {\n\t\tthis.dispatch(MovementSequence2DEvent.Reset);\n\t\tthis.currentIndex = 0;\n\t\tthis.timeRemaining = this.sequence.length > 0 ? this.sequence[0].timeInSeconds : 0;\n\t}\n\n\t/**\n\t * Update the sequence with delta time.\n\t * Returns the current movement to apply.\n\t * Automatically starts if in Idle state.\n\t */\n\tupdate(delta: number): MovementSequence2DMovement {\n\t\tif (this.sequence.length === 0) {\n\t\t\treturn { moveX: 0, moveY: 0 };\n\t\t}\n\n\t\t// Auto-start if idle\n\t\tif (this.machine.getState() === MovementSequence2DState.Idle) {\n\t\t\tthis.start();\n\t\t}\n\n\t\t// Don't advance if paused or completed\n\t\tif (this.machine.getState() !== MovementSequence2DState.Running) {\n\t\t\tif (this.machine.getState() === MovementSequence2DState.Completed) {\n\t\t\t\treturn { moveX: 0, moveY: 0 };\n\t\t\t}\n\t\t\t// Paused - return current step's movement (but don't advance time)\n\t\t\tconst step = this.sequence[this.currentIndex];\n\t\t\treturn { moveX: step?.moveX ?? 0, moveY: step?.moveY ?? 0 };\n\t\t}\n\n\t\t// Advance time\n\t\tlet timeLeft = this.timeRemaining - delta;\n\n\t\t// Handle step transitions\n\t\twhile (timeLeft <= 0) {\n\t\t\tconst overflow = -timeLeft;\n\t\t\tthis.currentIndex += 1;\n\n\t\t\tif (this.currentIndex >= this.sequence.length) {\n\t\t\t\tif (!this.loop) {\n\t\t\t\t\tthis.dispatch(MovementSequence2DEvent.Complete);\n\t\t\t\t\treturn { moveX: 0, moveY: 0 };\n\t\t\t\t}\n\t\t\t\tthis.currentIndex = 0;\n\t\t\t}\n\n\t\t\ttimeLeft = this.sequence[this.currentIndex].timeInSeconds - overflow;\n\t\t}\n\n\t\tthis.timeRemaining = timeLeft;\n\n\t\tconst step = this.sequence[this.currentIndex];\n\t\treturn { moveX: step?.moveX ?? 0, moveY: step?.moveY ?? 0 };\n\t}\n\n\t/**\n\t * Get the current movement without advancing time.\n\t */\n\tgetMovement(): MovementSequence2DMovement {\n\t\tif (this.sequence.length === 0 ||\n\t\t this.machine.getState() === MovementSequence2DState.Completed) {\n\t\t\treturn { moveX: 0, moveY: 0 };\n\t\t}\n\t\tconst step = this.sequence[this.currentIndex];\n\t\treturn { moveX: step?.moveX ?? 0, moveY: step?.moveY ?? 0 };\n\t}\n\n\t/**\n\t * Get current step info.\n\t */\n\tgetCurrentStep(): MovementSequence2DCurrentStep | null {\n\t\tif (this.sequence.length === 0) return null;\n\t\tconst step = this.sequence[this.currentIndex];\n\t\tif (!step) return null;\n\t\treturn {\n\t\t\tname: step.name,\n\t\t\tindex: this.currentIndex,\n\t\t\tmoveX: step.moveX ?? 0,\n\t\t\tmoveY: step.moveY ?? 0,\n\t\t\ttimeRemaining: this.timeRemaining,\n\t\t};\n\t}\n\n\t/**\n\t * Get sequence progress.\n\t */\n\tgetProgress(): MovementSequence2DProgress {\n\t\treturn {\n\t\t\tstepIndex: this.currentIndex,\n\t\t\ttotalSteps: this.sequence.length,\n\t\t\tstepTimeRemaining: this.timeRemaining,\n\t\t\tdone: this.machine.getState() === MovementSequence2DState.Completed,\n\t\t};\n\t}\n\n\tprivate dispatch(event: MovementSequence2DEvent): void {\n\t\tif (this.machine.can(event)) {\n\t\t\tthis.machine.dispatch(event);\n\t\t}\n\t}\n}\n","/**\n * MovementSequence2DBehavior\n *\n * Sequences 2D movements over time. Each step defines velocity and duration.\n * The behavior computes movement; the consumer applies it.\n */\n\nimport type { IWorld } from 'bitecs';\nimport { defineBehavior, type BehaviorRef } from '../behavior-descriptor';\nimport type { BehaviorSystem } from '../behavior-system';\nimport {\n\tMovementSequence2DFSM,\n\ttype MovementSequence2DStep,\n\ttype MovementSequence2DMovement,\n\ttype MovementSequence2DCurrentStep,\n\ttype MovementSequence2DProgress,\n} from './movement-sequence-2d-fsm';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Options\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport interface MovementSequence2DOptions {\n\t/**\n\t * The sequence of movement steps.\n\t * Each step has name, moveX, moveY, and timeInSeconds.\n\t */\n\tsequence: MovementSequence2DStep[];\n\n\t/**\n\t * Whether to loop when the sequence ends.\n\t * Default: true\n\t */\n\tloop: boolean;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Handle\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Handle methods provided by MovementSequence2DBehavior\n */\nexport interface MovementSequence2DHandle {\n\t/**\n\t * Get the current movement velocity.\n\t * Returns { moveX: 0, moveY: 0 } if sequence is empty or completed.\n\t */\n\tgetMovement(): MovementSequence2DMovement;\n\n\t/**\n\t * Get the current step info.\n\t * Returns null if sequence is empty.\n\t */\n\tgetCurrentStep(): MovementSequence2DCurrentStep | null;\n\n\t/**\n\t * Get sequence progress.\n\t */\n\tgetProgress(): MovementSequence2DProgress;\n\n\t/**\n\t * Pause the sequence. Movement values remain but time doesn't advance.\n\t */\n\tpause(): void;\n\n\t/**\n\t * Resume a paused sequence.\n\t */\n\tresume(): void;\n\n\t/**\n\t * Reset the sequence to the beginning.\n\t */\n\treset(): void;\n}\n\nconst defaultOptions: MovementSequence2DOptions = {\n\tsequence: [],\n\tloop: true,\n};\n\n/**\n * Creates behavior-specific handle methods for MovementSequence2DBehavior.\n */\nfunction createMovementSequence2DHandle(\n\tref: BehaviorRef<MovementSequence2DOptions>\n): MovementSequence2DHandle {\n\treturn {\n\t\tgetMovement: () => {\n\t\t\tconst fsm = ref.fsm as MovementSequence2DFSM | undefined;\n\t\t\treturn fsm?.getMovement() ?? { moveX: 0, moveY: 0 };\n\t\t},\n\t\tgetCurrentStep: () => {\n\t\t\tconst fsm = ref.fsm as MovementSequence2DFSM | undefined;\n\t\t\treturn fsm?.getCurrentStep() ?? null;\n\t\t},\n\t\tgetProgress: () => {\n\t\t\tconst fsm = ref.fsm as MovementSequence2DFSM | undefined;\n\t\t\treturn fsm?.getProgress() ?? { stepIndex: 0, totalSteps: 0, stepTimeRemaining: 0, done: true };\n\t\t},\n\t\tpause: () => {\n\t\t\tconst fsm = ref.fsm as MovementSequence2DFSM | undefined;\n\t\t\tfsm?.pause();\n\t\t},\n\t\tresume: () => {\n\t\t\tconst fsm = ref.fsm as MovementSequence2DFSM | undefined;\n\t\t\tfsm?.resume();\n\t\t},\n\t\treset: () => {\n\t\t\tconst fsm = ref.fsm as MovementSequence2DFSM | undefined;\n\t\t\tfsm?.reset();\n\t\t},\n\t};\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// System\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * MovementSequence2DSystem\n *\n * Stage-level system that:\n * - Finds entities with this behavior attached\n * - Updates FSM with delta time each frame\n * - Consumers read getMovement() to get current velocity\n */\nclass MovementSequence2DSystem implements BehaviorSystem {\n\tconstructor(private world: any) {}\n\n\tupdate(_ecs: IWorld, delta: number): void {\n\t\tif (!this.world?.collisionMap) return;\n\n\t\tfor (const [, entity] of this.world.collisionMap) {\n\t\t\tconst gameEntity = entity as any;\n\n\t\t\tif (typeof gameEntity.getBehaviorRefs !== 'function') continue;\n\n\t\t\tconst refs = gameEntity.getBehaviorRefs();\n\t\t\tconst sequenceRef = refs.find(\n\t\t\t\t(r: any) => r.descriptor.key === Symbol.for('zylem:behavior:movement-sequence-2d')\n\t\t\t);\n\n\t\t\tif (!sequenceRef) continue;\n\n\t\t\tconst options = sequenceRef.options as MovementSequence2DOptions;\n\n\t\t\t// Create and init FSM lazily on first update\n\t\t\tif (!sequenceRef.fsm) {\n\t\t\t\tsequenceRef.fsm = new MovementSequence2DFSM();\n\t\t\t\tsequenceRef.fsm.init(options.sequence, options.loop);\n\t\t\t}\n\n\t\t\t// Update FSM - advances time and handles step transitions\n\t\t\tsequenceRef.fsm.update(delta);\n\t\t}\n\t}\n\n\tdestroy(_ecs: IWorld): void {}\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Behavior Definition\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * MovementSequence2DBehavior\n *\n * @example\n * ```ts\n * import { MovementSequence2DBehavior } from \"@zylem/game-lib\";\n *\n * const enemy = makeMoveable(createSprite({ ... }));\n * const sequence = enemy.use(MovementSequence2DBehavior, {\n * sequence: [\n * { name: 'right', moveX: 3, moveY: 0, timeInSeconds: 2 },\n * { name: 'left', moveX: -3, moveY: 0, timeInSeconds: 2 },\n * ],\n * loop: true,\n * });\n *\n * enemy.onUpdate(({ me }) => {\n * const { moveX, moveY } = sequence.getMovement();\n * me.moveXY(moveX, moveY);\n * });\n * ```\n */\nexport const MovementSequence2DBehavior = defineBehavior({\n\tname: 'movement-sequence-2d',\n\tdefaultOptions,\n\tsystemFactory: (ctx) => new MovementSequence2DSystem(ctx.world),\n\tcreateHandle: createMovementSequence2DHandle,\n});\n","/**\n * Movement Sequence 2D Behavior Module\n *\n * Exports FSM, types, and behavior descriptor for 2D movement sequencing.\n */\n\n// FSM and types\nexport {\n\tMovementSequence2DFSM,\n\tMovementSequence2DState,\n\tMovementSequence2DEvent,\n\ttype MovementSequence2DStep,\n\ttype MovementSequence2DMovement,\n\ttype MovementSequence2DProgress,\n\ttype MovementSequence2DCurrentStep,\n} from './movement-sequence-2d-fsm';\n\n// Behavior descriptor, options, and handle\nexport {\n\tMovementSequence2DBehavior,\n\ttype MovementSequence2DOptions,\n\ttype MovementSequence2DHandle,\n} from './movement-sequence-2d.descriptor';\n","import { GameEntity } from '../entities/entity';\nimport { Ricochet2DHandle, Ricochet2DResult } from '../behaviors/ricochet-2d/ricochet-2d.descriptor';\nimport { WorldBoundary2DHandle } from '../behaviors/world-boundary-2d/world-boundary-2d.descriptor';\nimport { MoveableEntity } from '../actions/capabilities/moveable';\n\n/**\n * Coordinator that bridges WorldBoundary2DBehavior and Ricochet2DBehavior.\n * \n * Automatically handles:\n * 1. Checking boundary hits\n * 2. Computing collision normals\n * 3. Requesting ricochet result\n * 4. Applying movement\n */\nexport class BoundaryRicochetCoordinator {\n constructor(\n private entity: GameEntity<any> & MoveableEntity,\n private boundary: WorldBoundary2DHandle,\n private ricochet: Ricochet2DHandle\n ) {}\n\n /**\n * Update loop - call this every frame\n */\n public update(): Ricochet2DResult | null {\n const hits = this.boundary.getLastHits();\n if (!hits) return null;\n\n const anyHit = hits.left || hits.right || hits.top || hits.bottom;\n if (!anyHit) return null;\n\n // Compute collision normal from boundary hits\n let normalX = 0;\n let normalY = 0;\n if (hits.left) normalX = 1;\n if (hits.right) normalX = -1;\n if (hits.bottom) normalY = 1;\n if (hits.top) normalY = -1;\n\n // Compute ricochet result\n return this.ricochet.getRicochet({\n entity: this.entity,\n contact: { normal: { x: normalX, y: normalY } },\n });\n }\n}\n","/**\n * Behaviors Module Index\n *\n * Re-exports all ECS components and behaviors.\n */\n\n// Core Behavior System Interface\nexport type { BehaviorSystem, BehaviorSystemFactory } from './behavior-system';\n\n// Behavior Descriptor Pattern\nexport { defineBehavior } from './behavior-descriptor';\nexport type {\n BehaviorDescriptor,\n BehaviorRef,\n BehaviorHandle,\n DefineBehaviorConfig,\n} from './behavior-descriptor';\n\nexport { useBehavior } from './use-behavior';\n\n// Core ECS Components\nexport {\n type TransformComponent,\n type PhysicsBodyComponent,\n createTransformComponent,\n createPhysicsBodyComponent,\n} from './components';\n\n// Physics Behaviors\nexport { PhysicsStepBehavior } from './physics-step.behavior';\nexport { PhysicsSyncBehavior } from './physics-sync.behavior';\n\n// Thruster Module (components, FSM, and behaviors)\nexport * from './thruster';\n\n// Screen Wrap Module\nexport * from './screen-wrap';\n\n// World Boundary 2D Module\nexport * from './world-boundary-2d';\n\n// Ricochet 2D Module\nexport * from './ricochet-2d';\n\n// Movement Sequence 2D Module\nexport * from './movement-sequence-2d';\n\n// Coordinators\nexport * from '../coordinators/boundary-ricochet.coordinator';\n","import { Vector3 } from 'three';\nimport { RigidBody, Vector } from '@dimforge/rapier3d-compat';\n\nexport interface EntityWithBody {\n\tbody: RigidBody | null;\n}\n\n/**\n * Move an entity along the X axis, preserving other velocities\n */\nexport function moveX(entity: EntityWithBody, delta: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(delta, currentVelocity.y, currentVelocity.z);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the Y axis, preserving other velocities\n */\nexport function moveY(entity: EntityWithBody, delta: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(currentVelocity.x, delta, currentVelocity.z);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the Z axis, preserving other velocities\n */\nexport function moveZ(entity: EntityWithBody, delta: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(currentVelocity.x, currentVelocity.y, delta);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the X and Y axis, preserving Z velocity\n */\nexport function moveXY(entity: EntityWithBody, deltaX: number, deltaY: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(deltaX, deltaY, currentVelocity.z);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move an entity along the X and Z axis, preserving Y velocity\n */\nexport function moveXZ(entity: EntityWithBody, deltaX: number, deltaZ: number): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(deltaX, currentVelocity.y, deltaZ);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Move entity based on a vector, adding to existing velocities\n */\nexport function move(entity: EntityWithBody, vector: Vector3): void {\n\tif (!entity.body) return;\n\tconst currentVelocity = entity.body.linvel();\n\tconst newVelocity = new Vector3(\n\t\tcurrentVelocity.x + vector.x,\n\t\tcurrentVelocity.y + vector.y,\n\t\tcurrentVelocity.z + vector.z\n\t);\n\tentity.body.setLinvel(newVelocity, true);\n}\n\n/**\n * Reset entity velocity\n */\nexport function resetVelocity(entity: EntityWithBody): void {\n\tif (!entity.body) return;\n\tentity.body.setLinvel(new Vector3(0, 0, 0), true);\n\tentity.body.setLinearDamping(5);\n}\n\n/**\n * Move entity forward in 2D space, preserving Z velocity\n */\nexport function moveForwardXY(entity: EntityWithBody, delta: number, rotation2DAngle: number): void {\n\tconst deltaX = Math.sin(-rotation2DAngle) * delta;\n\tconst deltaY = Math.cos(-rotation2DAngle) * delta;\n\tmoveXY(entity, deltaX, deltaY);\n}\n\n/**\n * Get entity position\n */\nexport function getPosition(entity: EntityWithBody): Vector | null {\n\tif (!entity.body) return null;\n\treturn entity.body.translation();\n}\n\n/**\n * Get entity velocity\n */\nexport function getVelocity(entity: EntityWithBody): Vector | null {\n\tif (!entity.body) return null;\n\treturn entity.body.linvel();\n}\n\n/**\n * Set entity position\n */\nexport function setPosition(entity: EntityWithBody, x: number, y: number, z: number): void {\n\tif (!entity.body) return;\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity X position\n */\nexport function setPositionX(entity: EntityWithBody, x: number): void {\n\tif (!entity.body) return;\n\tconst { y, z } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity Y position\n */\nexport function setPositionY(entity: EntityWithBody, y: number): void {\n\tif (!entity.body) return;\n\tconst { x, z } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity Z position\n */\nexport function setPositionZ(entity: EntityWithBody, z: number): void {\n\tif (!entity.body) return;\n\tconst { x, y } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Wrap entity around 2D bounds\n */\nexport function wrapAroundXY(entity: EntityWithBody, boundsX: number, boundsY: number): void {\n\tconst position = getPosition(entity);\n\tif (!position) return;\n\n\tconst { x, y } = position;\n\tconst newX = x > boundsX ? -boundsX : (x < -boundsX ? boundsX : x);\n\tconst newY = y > boundsY ? -boundsY : (y < -boundsY ? boundsY : y);\n\n\tif (newX !== x || newY !== y) {\n\t\tsetPosition(entity, newX, newY, 0);\n\t}\n}\n\n/**\n * Wrap entity around 3D bounds\n */\nexport function wrapAround3D(entity: EntityWithBody, boundsX: number, boundsY: number, boundsZ: number): void {\n\tconst position = getPosition(entity);\n\tif (!position) return;\n\n\tconst { x, y, z } = position;\n\tconst newX = x > boundsX ? -boundsX : (x < -boundsX ? boundsX : x);\n\tconst newY = y > boundsY ? -boundsY : (y < -boundsY ? boundsY : y);\n\tconst newZ = z > boundsZ ? -boundsZ : (z < -boundsZ ? boundsZ : z);\n\n\tif (newX !== x || newY !== y || newZ !== z) {\n\t\tsetPosition(entity, newX, newY, newZ);\n\t}\n}\n\n/**\n * Enhanced moveable entity with bound methods\n */\nexport interface MoveableEntity extends EntityWithBody {\n\tmoveX(delta: number): void;\n\tmoveY(delta: number): void;\n\tmoveZ(delta: number): void;\n\tmoveXY(deltaX: number, deltaY: number): void;\n\tmoveXZ(deltaX: number, deltaZ: number): void;\n\tmove(vector: Vector3): void;\n\tresetVelocity(): void;\n\tmoveForwardXY(delta: number, rotation2DAngle: number): void;\n\tgetPosition(): Vector | null;\n\tgetVelocity(): Vector | null;\n\tsetPosition(x: number, y: number, z: number): void;\n\tsetPositionX(x: number): void;\n\tsetPositionY(y: number): void;\n\tsetPositionZ(z: number): void;\n\twrapAroundXY(boundsX: number, boundsY: number): void;\n\twrapAround3D(boundsX: number, boundsY: number, boundsZ: number): void;\n}\n\n/**\n * Class decorator to enhance an entity with additive movement methods\n */\nexport function moveable<T extends { new(...args: any[]): EntityWithBody }>(constructor: T) {\n\treturn class extends constructor implements MoveableEntity {\n\t\tmoveX(delta: number): void {\n\t\t\tmoveX(this, delta);\n\t\t}\n\t\tmoveY(delta: number): void {\n\t\t\tmoveY(this, delta);\n\t\t}\n\t\tmoveZ(delta: number): void {\n\t\t\tmoveZ(this, delta);\n\t\t}\n\t\tmoveXY(deltaX: number, deltaY: number): void {\n\t\t\tmoveXY(this, deltaX, deltaY);\n\t\t}\n\t\tmoveXZ(deltaX: number, deltaZ: number): void {\n\t\t\tmoveXZ(this, deltaX, deltaZ);\n\t\t}\n\t\tmove(vector: Vector3): void {\n\t\t\tmove(this, vector);\n\t\t}\n\t\tresetVelocity(): void {\n\t\t\tresetVelocity(this);\n\t\t}\n\t\tmoveForwardXY(delta: number, rotation2DAngle: number): void {\n\t\t\tmoveForwardXY(this, delta, rotation2DAngle);\n\t\t}\n\t\tgetPosition(): Vector | null {\n\t\t\treturn getPosition(this);\n\t\t}\n\t\tgetVelocity(): Vector | null {\n\t\t\treturn getVelocity(this);\n\t\t}\n\t\tsetPosition(x: number, y: number, z: number): void {\n\t\t\tsetPosition(this, x, y, z);\n\t\t}\n\t\tsetPositionX(x: number): void {\n\t\t\tsetPositionX(this, x);\n\t\t}\n\t\tsetPositionY(y: number): void {\n\t\t\tsetPositionY(this, y);\n\t\t}\n\t\tsetPositionZ(z: number): void {\n\t\t\tsetPositionZ(this, z);\n\t\t}\n\t\twrapAroundXY(boundsX: number, boundsY: number): void {\n\t\t\twrapAroundXY(this, boundsX, boundsY);\n\t\t}\n\t\twrapAround3D(boundsX: number, boundsY: number, boundsZ: number): void {\n\t\t\twrapAround3D(this, boundsX, boundsY, boundsZ);\n\t\t}\n\t};\n}\n\n/**\n * Enhance an entity with additive movement methods (retained for compatibility)\n */\nexport function makeMoveable<T extends EntityWithBody>(entity: T): T & MoveableEntity {\n\tconst moveable = entity as T & MoveableEntity;\n\n\tmoveable.moveX = (delta: number) => moveX(entity, delta);\n\tmoveable.moveY = (delta: number) => moveY(entity, delta);\n\tmoveable.moveZ = (delta: number) => moveZ(entity, delta);\n\tmoveable.moveXY = (deltaX: number, deltaY: number) => moveXY(entity, deltaX, deltaY);\n\tmoveable.moveXZ = (deltaX: number, deltaZ: number) => moveXZ(entity, deltaX, deltaZ);\n\tmoveable.move = (vector: Vector3) => move(entity, vector);\n\tmoveable.resetVelocity = () => resetVelocity(entity);\n\tmoveable.moveForwardXY = (delta: number, rotation2DAngle: number) => moveForwardXY(entity, delta, rotation2DAngle);\n\tmoveable.getPosition = () => getPosition(entity);\n\tmoveable.getVelocity = () => getVelocity(entity);\n\tmoveable.setPosition = (x: number, y: number, z: number) => setPosition(entity, x, y, z);\n\tmoveable.setPositionX = (x: number) => setPositionX(entity, x);\n\tmoveable.setPositionY = (y: number) => setPositionY(entity, y);\n\tmoveable.setPositionZ = (z: number) => setPositionZ(entity, z);\n\tmoveable.wrapAroundXY = (boundsX: number, boundsY: number) => wrapAroundXY(entity, boundsX, boundsY);\n\tmoveable.wrapAround3D = (boundsX: number, boundsY: number, boundsZ: number) => wrapAround3D(entity, boundsX, boundsY, boundsZ);\n\n\treturn moveable;\n}\n\n/**\n * Wrap a standalone function with movement capabilities\n */\nexport function withMovement<T extends (...args: any[]) => any>(\n\tfn: T,\n\tentity: EntityWithBody\n): (...args: Parameters<T>) => ReturnType<T> & MoveableEntity {\n\tconst wrapped = (...args: Parameters<T>) => {\n\t\tconst result = fn(...args);\n\t\tconst moveableEntity = makeMoveable(entity);\n\t\treturn Object.assign(result, moveableEntity);\n\t};\n\treturn wrapped as (...args: Parameters<T>) => ReturnType<T> & MoveableEntity;\n}","import { Euler, Vector3, MathUtils, Quaternion } from 'three';\nimport { RigidBody } from '@dimforge/rapier3d-compat';\n\nexport interface RotatableEntity {\n\tbody: RigidBody | null;\n\tgroup: any;\n}\n\n/**\n * Rotate an entity in the direction of a movement vector\n */\nexport function rotateInDirection(entity: RotatableEntity, moveVector: Vector3): void {\n\tif (!entity.body) return;\n\tconst rotate = Math.atan2(-moveVector.x, moveVector.z);\n\trotateYEuler(entity, rotate);\n}\n\n/**\n * Rotate an entity around the Y axis using Euler angles\n */\nexport function rotateYEuler(entity: RotatableEntity, amount: number): void {\n\trotateEuler(entity, new Vector3(0, -amount, 0));\n}\n\n/**\n * Rotate an entity using Euler angles\n */\nexport function rotateEuler(entity: RotatableEntity, rotation: Vector3): void {\n\tif (!entity.group) return;\n\tconst euler = new Euler(rotation.x, rotation.y, rotation.z);\n\tentity.group.setRotationFromEuler(euler);\n}\n\n/**\n * Rotate an entity around the Y axis\n */\nexport function rotateY(entity: RotatableEntity, delta: number): void {\n\tsetRotationY(entity, delta);\n}\n\n/**\n * Rotate an entity around the Z axis\n */\nexport function rotateZ(entity: RotatableEntity, delta: number): void {\n\tsetRotationZ(entity, delta);\n}\n\n/**\n * Set rotation around Y axis\n */\nexport function setRotationY(entity: RotatableEntity, y: number): void {\n\tif (!entity.body) return;\n\tconst halfAngle = y / 2;\n\tconst w = Math.cos(halfAngle);\n\tconst yComponent = Math.sin(halfAngle);\n\tentity.body.setRotation({ w: w, x: 0, y: yComponent, z: 0 }, true);\n}\n\n/**\n * Set rotation around Y axis\n */\nexport function setRotationDegreesY(entity: RotatableEntity, y: number): void {\n\tif (!entity.body) return;\n\tsetRotationY(entity, MathUtils.degToRad(y));\n}\n\n/**\n * Set rotation around X axis\n */\nexport function setRotationX(entity: RotatableEntity, x: number): void {\n\tif (!entity.body) return;\n\tconst halfAngle = x / 2;\n\tconst w = Math.cos(halfAngle);\n\tconst xComponent = Math.sin(halfAngle);\n\tentity.body.setRotation({ w: w, x: xComponent, y: 0, z: 0 }, true);\n}\n\n/**\n * Set rotation around X axis\n */\nexport function setRotationDegreesX(entity: RotatableEntity, x: number): void {\n\tif (!entity.body) return;\n\tsetRotationX(entity, MathUtils.degToRad(x));\n}\n\n/**\n * Set rotation around Z axis\n */\nexport function setRotationZ(entity: RotatableEntity, z: number): void {\n\tif (!entity.body) return;\n\tconst halfAngle = z / 2;\n\tconst w = Math.cos(halfAngle);\n\tconst zComponent = Math.sin(halfAngle);\n\tentity.body.setRotation({ w: w, x: 0, y: 0, z: zComponent }, true);\n}\n\n/**\n * Set rotation around Z axis\n */\nexport function setRotationDegreesZ(entity: RotatableEntity, z: number): void {\n\tif (!entity.body) return;\n\tsetRotationZ(entity, MathUtils.degToRad(z));\n}\n\n/**\n * Set rotation for all axes\n */\nexport function setRotation(entity: RotatableEntity, x: number, y: number, z: number): void {\n\tif (!entity.body) return;\n\tconst quat = new Quaternion().setFromEuler(new Euler(x, y, z));\n\tentity.body.setRotation({ w: quat.w, x: quat.x, y: quat.y, z: quat.z }, true);\n}\n\n/**\n * Set rotation for all axes\n */\nexport function setRotationDegrees(entity: RotatableEntity, x: number, y: number, z: number): void {\n\tif (!entity.body) return;\n\tsetRotation(entity, MathUtils.degToRad(x), MathUtils.degToRad(y), MathUtils.degToRad(z));\n}\n\n/**\n * Get current rotation\n */\nexport function getRotation(entity: RotatableEntity): any {\n\tif (!entity.body) return null;\n\treturn entity.body.rotation();\n}\n\n/**\n * Rotatable entity API with bound methods\n */\nexport interface RotatableEntityAPI extends RotatableEntity {\n\trotateInDirection(moveVector: Vector3): void;\n\trotateYEuler(amount: number): void;\n\trotateEuler(rotation: Vector3): void;\n\trotateY(delta: number): void;\n\trotateZ(delta: number): void;\n\tsetRotationY(y: number): void;\n\tsetRotationX(x: number): void;\n\tsetRotationZ(z: number): void;\n\tsetRotationDegrees(x: number, y: number, z: number): void;\n\tsetRotationDegreesY(y: number): void;\n\tsetRotationDegreesX(x: number): void;\n\tsetRotationDegreesZ(z: number): void;\n\tsetRotation(x: number, y: number, z: number): void;\n\tgetRotation(): any;\n}\n\n/**\n * Class decorator to enhance an entity with rotatable methods\n */\nexport function rotatable<T extends { new(...args: any[]): RotatableEntity }>(constructor: T) {\n\treturn class extends constructor implements RotatableEntityAPI {\n\t\trotateInDirection(moveVector: Vector3): void {\n\t\t\trotateInDirection(this, moveVector);\n\t\t}\n\t\trotateYEuler(amount: number): void {\n\t\t\trotateYEuler(this, amount);\n\t\t}\n\t\trotateEuler(rotation: Vector3): void {\n\t\t\trotateEuler(this, rotation);\n\t\t}\n\t\trotateY(delta: number): void {\n\t\t\trotateY(this, delta);\n\t\t}\n\t\trotateZ(delta: number): void {\n\t\t\trotateZ(this, delta);\n\t\t}\n\t\tsetRotationY(y: number): void {\n\t\t\tsetRotationY(this, y);\n\t\t}\n\t\tsetRotationX(x: number): void {\n\t\t\tsetRotationX(this, x);\n\t\t}\n\t\tsetRotationZ(z: number): void {\n\t\t\tsetRotationZ(this, z);\n\t\t}\n\t\tsetRotationDegrees(x: number, y: number, z: number): void {\n\t\t\tsetRotationDegrees(this, x, y, z);\n\t\t}\n\t\tsetRotationDegreesY(y: number): void {\n\t\t\tsetRotationDegreesY(this, y);\n\t\t}\n\t\tsetRotationDegreesX(x: number): void {\n\t\t\tsetRotationDegreesX(this, x);\n\t\t}\n\t\tsetRotationDegreesZ(z: number): void {\n\t\t\tsetRotationDegreesZ(this, z);\n\t\t}\n\t\tsetRotation(x: number, y: number, z: number): void {\n\t\t\tsetRotation(this, x, y, z);\n\t\t}\n\t\tgetRotation(): any {\n\t\t\treturn getRotation(this);\n\t\t}\n\t};\n}\n\n/**\n * Enhance an entity instance with rotatable methods\n */\nexport function makeRotatable<T extends RotatableEntity>(entity: T): T & RotatableEntityAPI {\n\tconst rotatableEntity = entity as T & RotatableEntityAPI;\n\n\trotatableEntity.rotateInDirection = (moveVector: Vector3) => rotateInDirection(entity, moveVector);\n\trotatableEntity.rotateYEuler = (amount: number) => rotateYEuler(entity, amount);\n\trotatableEntity.rotateEuler = (rotation: Vector3) => rotateEuler(entity, rotation);\n\trotatableEntity.rotateY = (delta: number) => rotateY(entity, delta);\n\trotatableEntity.rotateZ = (delta: number) => rotateZ(entity, delta);\n\trotatableEntity.setRotationY = (y: number) => setRotationY(entity, y);\n\trotatableEntity.setRotationX = (x: number) => setRotationX(entity, x);\n\trotatableEntity.setRotationZ = (z: number) => setRotationZ(entity, z);\n\trotatableEntity.setRotationDegreesY = (y: number) => setRotationDegreesY(entity, y);\n\trotatableEntity.setRotationDegreesX = (x: number) => setRotationDegreesX(entity, x);\n\trotatableEntity.setRotationDegreesZ = (z: number) => setRotationDegreesZ(entity, z);\n\trotatableEntity.setRotationDegrees = (x: number, y: number, z: number) => setRotationDegrees(entity, x, y, z);\n\trotatableEntity.setRotation = (x: number, y: number, z: number) => setRotation(entity, x, y, z);\n\trotatableEntity.getRotation = () => getRotation(entity);\n\n\treturn rotatableEntity;\n}","import { makeMoveable, EntityWithBody, MoveableEntity } from './moveable';\nimport { makeRotatable, RotatableEntity, RotatableEntityAPI } from './rotatable';\n\n/**\n * Enhance an entity with both movement and rotation capabilities.\n */\nexport function makeTransformable<\n\tT extends RotatableEntity & EntityWithBody\n>(entity: T): T & MoveableEntity & RotatableEntityAPI {\n\tconst withMovement = makeMoveable(entity);\n\tconst withRotation = makeRotatable(withMovement);\n\treturn withRotation;\n}\n\n\n","import { DestroyContext, DestroyFunction } from \"../core/base-node-life-cycle\";\nimport { getGlobals } from \"../game/game-state\";\n\nexport function destroyEntity<T>(entity: T, globals: any, destroyFunction: DestroyFunction<T>): void {\n\tconst context: DestroyContext<T> = {\n\t\tme: entity,\n\t\tglobals\n\t};\n\tdestroyFunction(context);\n}\n\nexport function destroy(entity: any, globals?: any): void {\n\tconst resolvedGlobals = globals ?? getGlobals();\n\tdestroyEntity(entity, resolvedGlobals, entity.nodeDestroy.bind(entity));\n}","/**\n * Plays a ricochet sound effect when boundary collision occurs\n */\nexport function ricochetSound(frequency: number = 800, duration: number = 0.05) {\n\t_ricochetSound(frequency, duration);\n}\n\nfunction _ricochetSound(frequency: number, duration: number) {\n\tconst audioCtx = new (window.AudioContext || (window as any).webkitAudioContext)();\n\tconst oscillator = audioCtx.createOscillator();\n\tconst gain = audioCtx.createGain();\n\n\toscillator.type = 'sawtooth';\n\toscillator.frequency.value = frequency;\n\n\tgain.gain.setValueAtTime(0.05, audioCtx.currentTime);\n\tgain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + duration);\n\n\toscillator.connect(gain);\n\tgain.connect(audioCtx.destination);\n\n\toscillator.start();\n\toscillator.stop(audioCtx.currentTime + duration);\n} ","/**\n * Plays a ping-pong beep sound effect.\n */\nexport function pingPongBeep(frequency: number = 440, duration: number = 0.1) {\n\t_pingPongBeep(frequency, duration);\n}\n\nfunction _pingPongBeep(frequency: number, duration: number) {\n\tconst audioCtx = new (window.AudioContext || (window as any).webkitAudioContext)();\n\tconst oscillator = audioCtx.createOscillator();\n\tconst gain = audioCtx.createGain();\n\n\toscillator.type = 'square';\n\toscillator.frequency.value = frequency;\n\n\tgain.gain.setValueAtTime(0.05, audioCtx.currentTime);\n\tgain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + duration);\n\n\toscillator.connect(gain);\n\tgain.connect(audioCtx.destination);\n\n\toscillator.start();\n\toscillator.stop(audioCtx.currentTime + duration);\n} ","export { ricochetSound } from \"./ricochet-sound\";\nexport { pingPongBeep } from \"./ping-pong-sound\"; ","import { UpdateContext } from \"../core/base-node-life-cycle\";\n\n/**\n * Listen for a single global key change inside an onUpdate pipeline.\n * Usage: onUpdate(globalChange('p1Score', (value) => { ... }))\n */\nexport function globalChange<T = any>(\n\tkey: string,\n\tcallback: (value: T, ctx: UpdateContext<any>) => void\n) {\n\tlet previousValue: T | undefined = undefined;\n\treturn (ctx: UpdateContext<any>) => {\n\t\tconst currentValue = ctx.globals?.[key] as T;\n\t\tif (previousValue !== currentValue) {\n\t\t\t// Ignore the very first undefined->value transition only if both are undefined\n\t\t\tif (!(previousValue === undefined && currentValue === undefined)) {\n\t\t\t\tcallback(currentValue, ctx);\n\t\t\t}\n\t\t\tpreviousValue = currentValue;\n\t\t}\n\t};\n}\n\n/**\n * Listen for multiple global key changes inside an onUpdate pipeline.\n * Calls back when any of the provided keys changes.\n * Usage: onUpdate(globalChanges(['p1Score','p2Score'], ([p1,p2]) => { ... }))\n */\nexport function globalChanges<T = any>(\n\tkeys: string[],\n\tcallback: (values: T[], ctx: UpdateContext<any>) => void\n) {\n\tlet previousValues: (T | undefined)[] = new Array(keys.length).fill(undefined);\n\treturn (ctx: UpdateContext<any>) => {\n\t\tconst currentValues = keys.map((k) => ctx.globals?.[k] as T);\n\t\tconst hasAnyChange = currentValues.some((val, idx) => previousValues[idx] !== val);\n\t\tif (hasAnyChange) {\n\t\t\t// Ignore initial all-undefined state\n\t\t\tconst allPrevUndef = previousValues.every((v) => v === undefined);\n\t\t\tconst allCurrUndef = currentValues.every((v) => v === undefined);\n\t\t\tif (!(allPrevUndef && allCurrUndef)) {\n\t\t\t\tcallback(currentValues as T[], ctx);\n\t\t\t}\n\t\t\tpreviousValues = currentValues;\n\t\t}\n\t};\n}\n\n\n/**\n * Listen for a single stage variable change inside an onUpdate pipeline.\n * Usage: onUpdate(variableChange('score', (value, ctx) => { ... }))\n */\nexport function variableChange<T = any>(\n\tkey: string,\n\tcallback: (value: T, ctx: UpdateContext<any>) => void\n) {\n\tlet previousValue: T | undefined = undefined;\n\treturn (ctx: UpdateContext<any>) => {\n\t\t// @ts-ignore - stage is optional on UpdateContext\n\t\tconst currentValue = (ctx.stage?.getVariable?.(key) ?? undefined) as T;\n\t\tif (previousValue !== currentValue) {\n\t\t\tif (!(previousValue === undefined && currentValue === undefined)) {\n\t\t\t\tcallback(currentValue, ctx);\n\t\t\t}\n\t\t\tpreviousValue = currentValue;\n\t\t}\n\t};\n}\n\n/**\n * Listen for multiple stage variable changes; fires when any changes.\n * Usage: onUpdate(variableChanges(['a','b'], ([a,b], ctx) => { ... }))\n */\nexport function variableChanges<T = any>(\n\tkeys: string[],\n\tcallback: (values: T[], ctx: UpdateContext<any>) => void\n) {\n\tlet previousValues: (T | undefined)[] = new Array(keys.length).fill(undefined);\n\treturn (ctx: UpdateContext<any>) => {\n\t\t// @ts-ignore - stage is optional on UpdateContext\n\t\tconst reader = (k: string) => ctx.stage?.getVariable?.(k) as T;\n\t\tconst currentValues = keys.map(reader);\n\t\tconst hasAnyChange = currentValues.some((val, idx) => previousValues[idx] !== val);\n\t\tif (hasAnyChange) {\n\t\t\tconst allPrevUndef = previousValues.every((v) => v === undefined);\n\t\t\tconst allCurrUndef = currentValues.every((v) => v === undefined);\n\t\t\tif (!(allPrevUndef && allCurrUndef)) {\n\t\t\t\tcallback(currentValues as T[], ctx);\n\t\t\t}\n\t\t\tpreviousValues = currentValues;\n\t\t}\n\t};\n}\n\n\n","import { Game } from '../lib/game/game';\nimport { debugState, setDebugTool, setPaused, type DebugTools } from '../lib/debug/debug-state';\n\n/**\n * State interface for editor-to-game communication\n */\nexport interface ZylemGameState {\n gameState?: {\n debugFlag?: boolean;\n [key: string]: unknown;\n };\n toolbarState?: {\n tool?: DebugTools;\n paused?: boolean;\n };\n [key: string]: unknown;\n}\n\nexport class ZylemGameElement extends HTMLElement {\n private _game: Game<any> | null = null;\n private _state: ZylemGameState = {};\n private container: HTMLElement;\n\n constructor() {\n super();\n this.attachShadow({ mode: 'open' });\n this.container = document.createElement('div');\n this.container.style.width = '100%';\n this.container.style.height = '100%';\n this.container.style.position = 'relative';\n this.container.style.outline = 'none'; // Remove focus outline\n this.container.tabIndex = 0; // Make focusable for keyboard input\n this.shadowRoot!.appendChild(this.container);\n }\n\n /**\n * Focus the game container for keyboard input\n */\n public focus(): void {\n this.container.focus();\n }\n\n set game(game: Game<any>) {\n // Dispose previous game if one exists\n if (this._game) {\n this._game.dispose();\n }\n \n this._game = game;\n game.options.push({ container: this.container });\n game.start();\n }\n\n get game(): Game<any> | null {\n return this._game;\n }\n\n set state(value: ZylemGameState) {\n this._state = value;\n this.syncDebugState();\n this.syncToolbarState();\n }\n\n get state(): ZylemGameState {\n return this._state;\n }\n\n /**\n * Sync the web component's state with the game-lib's internal debug state\n */\n private syncDebugState(): void {\n const debugFlag = this._state.gameState?.debugFlag;\n if (debugFlag !== undefined) {\n debugState.enabled = debugFlag;\n }\n }\n\n /**\n * Sync toolbar state with game-lib's debug state\n */\n private syncToolbarState(): void {\n const { tool, paused } = this._state.toolbarState ?? {};\n if (tool !== undefined) {\n setDebugTool(tool);\n }\n if (paused !== undefined) {\n setPaused(paused);\n }\n }\n\n disconnectedCallback() {\n if (this._game) {\n this._game.dispose();\n this._game = null;\n }\n }\n}\n\ncustomElements.define('zylem-game', ZylemGameElement);\n","import { ZylemSprite, SPRITE_TYPE } from '../entities/sprite';\nimport { ZylemSphere, SPHERE_TYPE } from '../entities/sphere';\nimport { ZylemRect, RECT_TYPE } from '../entities/rect';\nimport { ZylemText, TEXT_TYPE } from '../entities/text';\nimport { ZylemBox, BOX_TYPE } from '../entities/box';\nimport { ZylemPlane, PLANE_TYPE } from '../entities/plane';\nimport { ZylemZone, ZONE_TYPE } from '../entities/zone';\nimport { ZylemActor, ACTOR_TYPE } from '../entities/actor';\nimport { ZylemDisk, DISK_TYPE } from '../entities/disk';\nimport { BaseNode } from '../core/base-node';\n\n/**\n * Maps entity type symbols to their class types.\n * Used by getEntityByName to infer return types.\n */\nexport interface EntityTypeMap {\n\t[SPRITE_TYPE]: ZylemSprite;\n\t[SPHERE_TYPE]: ZylemSphere;\n\t[RECT_TYPE]: ZylemRect;\n\t[TEXT_TYPE]: ZylemText;\n\t[BOX_TYPE]: ZylemBox;\n\t[PLANE_TYPE]: ZylemPlane;\n\t[ZONE_TYPE]: ZylemZone;\n\t[ACTOR_TYPE]: ZylemActor;\n\t[DISK_TYPE]: ZylemDisk;\n}\n\n/**\n * Type helper: if T is a known type symbol, return the mapped entity type.\n * Otherwise return BaseNode.\n */\nexport type EntityForType<T> = T extends keyof EntityTypeMap\n\t? EntityTypeMap[T]\n\t: BaseNode;\n\n// Re-export type symbols for convenience\nexport {\n\tSPRITE_TYPE,\n\tSPHERE_TYPE,\n\tRECT_TYPE,\n\tTEXT_TYPE,\n\tBOX_TYPE,\n\tPLANE_TYPE,\n\tZONE_TYPE,\n\tACTOR_TYPE,\n\tDISK_TYPE,\n};\n","import { objectVertexShader } from './vertex/object.shader';\n\nconst fragment = `\n#include <common>\n \nuniform vec3 iResolution;\nuniform float iTime;\nuniform vec2 iOffset;\nvarying vec2 vUv;\n\nfloat snoise(vec3 uv, float res)\n{\n\tconst vec3 s = vec3(1e0, 1e2, 1e3);\n\t\n\tuv *= res;\n\t\n\tvec3 uv0 = floor(mod(uv, res))*s;\n\tvec3 uv1 = floor(mod(uv+vec3(1.), res))*s;\n\t\n\tvec3 f = fract(uv); f = f*f*(3.0-2.0*f);\n\n\tvec4 v = vec4(uv0.x+uv0.y+uv0.z, uv1.x+uv0.y+uv0.z,\n\t\t \t uv0.x+uv1.y+uv0.z, uv1.x+uv1.y+uv0.z);\n\n\tvec4 r = fract(sin(v*1e-1)*1e3);\n\tfloat r0 = mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y);\n\t\n\tr = fract(sin((v + uv1.z - uv0.z)*1e-1)*1e3);\n\tfloat r1 = mix(mix(r.x, r.y, f.x), mix(r.z, r.w, f.x), f.y);\n\t\n\treturn mix(r0, r1, f.z)*2.-1.;\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord ) {\n\tvec2 p = -.5 + fragCoord.xy / iResolution.xy;\n\tp.x *= iResolution.x/iResolution.y;\n\t\n\tfloat color = 3.0 - (3.*length(2.*p));\n\t\n\tvec3 coord = vec3(atan(p.x,p.y)/6.2832+.5, length(p)*.4, .5);\n\t\n\tfor(int i = 1; i <= 7; i++)\n\t{\n\t\tfloat power = pow(2.0, float(i));\n\t\tcolor += (1.5 / power) * snoise(coord + vec3(0.,-iTime*.05, iTime*.01), power*16.);\n\t}\n\tfragColor = vec4( color, pow(max(color,0.),2.)*0.4, pow(max(color,0.),3.)*0.15 , 1.0);\n}\n\nvoid main() {\n mainImage(gl_FragColor, vUv);\n}\n`;\n\nexport const fireShader = {\n vertex: objectVertexShader,\n fragment\n};\n","import { objectVertexShader } from './vertex/object.shader';\n\nconst fragment = `\n#include <common>\n\nuniform vec3 iResolution;\nuniform float iTime;\nvarying vec2 vUv;\n\n// Credit goes to:\n// https://www.shadertoy.com/view/mtyGWy\n\nvec3 palette( float t ) {\n vec3 a = vec3(0.5, 0.5, 0.5);\n vec3 b = vec3(0.5, 0.5, 0.5);\n vec3 c = vec3(1.0, 1.0, 1.0);\n vec3 d = vec3(0.263,0.416,0.557);\n\n return a + b*cos( 6.28318*(c*t+d) );\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord ) {\n vec2 uv = (fragCoord * 2.0 - iResolution.xy) / iResolution.y;\n vec2 uv0 = uv;\n vec3 finalColor = vec3(0.0);\n \n for (float i = 0.0; i < 4.0; i++) {\n uv = fract(uv * 1.5) - 0.5;\n\n float d = length(uv) * exp(-length(uv0));\n\n vec3 col = palette(length(uv0) + i*.4 + iTime*.4);\n\n d = sin(d*5. + iTime)/5.;\n d = abs(d);\n\n d = pow(0.01 / d, 1.2);\n\n finalColor += col * d;\n }\n \n fragColor = vec4(finalColor, 1.0);\n}\n \nvoid main() {\n mainImage(gl_FragColor, vUv);\n}\n`;\n\nexport const starShader = {\n vertex: objectVertexShader,\n fragment\n};\n","export const debugVertexShader = `\nuniform vec2 uvScale;\nvarying vec2 vUv;\n\nvoid main() {\n\tvUv = uv;\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tgl_Position = projectionMatrix * mvPosition;\n}\n`;\n","import { debugVertexShader } from './vertex/debug.shader';\n\nconst fragment = `\nvarying vec3 vBarycentric;\nuniform vec3 baseColor;\nuniform vec3 wireframeColor;\nuniform float wireframeThickness;\n\nfloat edgeFactor() {\n vec3 d = fwidth(vBarycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * wireframeThickness, vBarycentric);\n return min(min(a3.x, a3.y), a3.z);\n}\n\nvoid main() {\n float edge = edgeFactor();\n\n vec3 wireColor = wireframeColor;\n\n vec3 finalColor = mix(wireColor, baseColor, edge);\n \n gl_FragColor = vec4(finalColor, 1.0);\n}\n`;\n\nexport const debugShader = {\n vertex: debugVertexShader,\n fragment\n};\n","// Core game functionality\nexport { createGame, Game } from '../lib/game/game';\nexport type { ZylemGameConfig } from '../lib/game/game-interfaces';\nexport { gameConfig } from '../lib/game/game-config';\n\nexport { createStage } from '../lib/stage/stage';\nexport { entitySpawner } from '../lib/stage/entity-spawner';\nexport type { StageOptions, LoadingEvent } from '../lib/stage/zylem-stage';\nexport type { StageBlueprint } from '../lib/core/blueprints';\nexport { StageManager, stageState } from '../lib/stage/stage-manager';\n\nexport { vessel } from '../lib/core/vessel';\n\n// Camera\nexport { createCamera } from '../lib/camera/camera';\nexport type { PerspectiveType } from '../lib/camera/perspective';\nexport { Perspectives } from '../lib/camera/perspective';\n\n// Utility types\nexport type { Vect3 } from '../lib/core/utility/vector';\n\n// Entities\nexport { createBox } from '../lib/entities/box';\nexport { createSphere } from '../lib/entities/sphere';\nexport { createSprite } from '../lib/entities/sprite';\nexport { createPlane } from '../lib/entities/plane';\nexport { createZone } from '../lib/entities/zone';\nexport { createActor } from '../lib/entities/actor';\nexport { createText } from '../lib/entities/text';\nexport { createRect } from '../lib/entities/rect';\nexport { createDisk } from '../lib/entities/disk';\nexport { createEntityFactory, type TemplateFactory } from '../lib/entities/entity-factory';\nexport { ZylemBox } from '../lib/entities/box';\n\n// ECS Components & Behaviors (new thruster system)\nexport * from '../lib/behaviors';\n\n// Capabilities\nexport { makeMoveable } from '../lib/actions/capabilities/moveable';\nexport { makeRotatable } from '../lib/actions/capabilities/rotatable';\nexport { makeTransformable } from '../lib/actions/capabilities/transformable';\nexport { rotatable } from '../lib/actions/capabilities/rotatable';\nexport { moveable } from '../lib/actions/capabilities/moveable';\nexport { rotateInDirection } from '../lib/actions/capabilities/rotatable';\nexport { move } from '../lib/actions/capabilities/moveable';\nexport { resetVelocity } from '../lib/actions/capabilities/moveable';\n\n\n// Destruction utilities\n// Destruction utilities\nexport { destroy } from '../lib/entities/destroy';\n\n// Sounds\nexport { ricochetSound, pingPongBeep } from '../lib/sounds';\n\n// External dependencies - these will be in separate vendor chunks\nexport { Howl } from 'howler';\nexport * as THREE from 'three';\nexport * as RAPIER from '@dimforge/rapier3d-compat';\n\n// Update helpers\nexport { globalChange, globalChanges, variableChange, variableChanges } from '../lib/actions/global-change';\n\n// State management - standalone functions\nexport { setGlobal, getGlobal, createGlobal, onGlobalChange, onGlobalChanges, getGlobals, clearGlobalSubscriptions } from '../lib/game/game-state';\nexport { setVariable, getVariable, createVariable, onVariableChange, onVariableChanges } from '../lib/stage/stage-state';\n\n// Debug state - exposed for direct mutation by editor integration\nexport { debugState, setDebugTool, setPaused, type DebugTools } from '../lib/debug/debug-state';\n\n// Web Components\nexport { ZylemGameElement, type ZylemGameState } from '../web-components/zylem-game';\n\n// Lifecycle types\nexport type { SetupContext, UpdateContext } from '../lib/core/base-node-life-cycle';\n\n// Interfaces\nexport type { StageEntity } from '../lib/interfaces/entity';\n\n// Entity type symbols for getEntityByName type inference\nexport { \n\tTEXT_TYPE, SPRITE_TYPE, BOX_TYPE, SPHERE_TYPE, \n\tRECT_TYPE, PLANE_TYPE, ZONE_TYPE, ACTOR_TYPE \n} from '../lib/types/entity-type-map';\n\n// Events\nexport {\n\tEventEmitterDelegate,\n\tzylemEventBus,\n\ttype ZylemEvents,\n\ttype GameEvents,\n\ttype StageEvents,\n\ttype EntityEvents,\n\ttype GameLoadingPayload,\n\ttype StateDispatchPayload,\n\ttype StageConfigPayload,\n\ttype EntityConfigPayload,\n} from '../lib/events';\n\n// Shaders\nexport { fireShader } from '../lib/graphics/shaders/fire.shader';\nexport { starShader } from '../lib/graphics/shaders/star.shader';\nexport { standardShader } from '../lib/graphics/shaders/standard.shader';\nexport { debugShader } from '../lib/graphics/shaders/debug.shader';\nexport { objectVertexShader } from '../lib/graphics/shaders/vertex/object.shader';\nexport type { ZylemShaderObject } from '../lib/graphics/material';\n"],"mappings":";;;;;;;;;;;AAQO,SAAS,UAAuB,KAAa,MAA6B;AAChF,MAAI,CAAC,KAAM,QAAO;AAClB,QAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,MAAI,UAAe;AACnB,aAAW,OAAO,MAAM;AACvB,QAAI,WAAW,QAAQ,OAAO,YAAY,UAAU;AACnD,aAAO;AAAA,IACR;AACA,cAAU,QAAQ,GAAG;AAAA,EACtB;AACA,SAAO;AACR;AAMO,SAAS,UAAU,KAAa,MAAc,OAAsB;AAC1E,MAAI,CAAC,KAAM;AACX,QAAM,OAAO,KAAK,MAAM,GAAG;AAC3B,MAAI,UAAe;AACnB,WAAS,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK;AACzC,UAAM,MAAM,KAAK,CAAC;AAClB,QAAI,QAAQ,GAAG,KAAK,QAAQ,OAAO,QAAQ,GAAG,MAAM,UAAU;AAC7D,cAAQ,GAAG,IAAI,CAAC;AAAA,IACjB;AACA,cAAU,QAAQ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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+CV,IAAM,aAAa;AAAA,MACtB,QAAQ;AAAA,MACR,UAAAA;AAAA,IACJ;AAAA;AAAA;;;ACpDA,IAAa;AAAb;AAAA;AAAA;AAAO,IAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAjC,IAEMC,WAuBO;AAzBb,IAAAC,qBAAA;AAAA;AAAA;AAAA;AAEA,IAAMD,YAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBV,IAAM,cAAc;AAAA,MACvB,QAAQ;AAAA,MACR,UAAAA;AAAA,IACJ;AAAA;AAAA;;;AC4BA,SAAS,YAAY;AACrB,YAAYE,YAAW;AACvB,YAAYC,aAAY;AA1DxB;AAAA;AACA;AAEA;AAEA;AACA;AAGA;AAEA;AAGA;AAEA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKA;AAGA;AAQA;AAGA;AACA;AAGA;AAGA,IAAAC;AASA;AAMA;AAcA;AACA;AACA;AACA,IAAAC;AACA;AAAA;AAAA;","names":["proxy","state","document","subscribe","all","Map","on","type","handler","handlers","get","push","set","off","splice","indexOf","emit","evt","slice","map","state","position","rotation","scale","destroy","Mesh","Color","RepeatWrapping","ShaderMaterial","Vector2","Vector3","fragment","BufferGeometry","Mesh","Color","Color","Vector3","ActiveCollisionTypes","ColliderDesc","MeshStandardMaterial","Group","Vector3","colliderDesc","Color","Vector3","ShaderMaterial","Mesh","state","position","Color","Vector3","Color","Vector3","proxy","subscribe","BoxGeometry","Color","Group","Mesh","Vector3","BufferGeometry","LineBasicMaterial","LineSegments","Vector2","hoveredUuid","subscribe","Vector3","Vector3","state","Vector3","Object3D","WebGLRenderer","position","Vector2","Vector3","Color","Vector3","subscribe","nanoid","state","Vector2","Vector3","proxy","Vector3","proxy","initialDefaults","getGameDefaultConfig","proxy","stageState","MeshStandardMaterial","MeshBasicMaterial","MeshPhongMaterial","x","y","z","toDeg","Color","Group","Vector2","ColliderDesc","Group","Quaternion","Vector3","TextureLoader","SpriteMaterial","ThreeSprite","stageState","Euler","Quaternion","Vector2","ColliderDesc","BoxGeometry","Vector3","ColliderDesc","SphereGeometry","BufferGeometry","ColliderDesc","Vector2","Vector3","scale","ActiveCollisionTypes","ColliderDesc","Vector3","Color","Group","ThreeSprite","SpriteMaterial","CanvasTexture","LinearFilter","Vector2","ClampToEdgeWrapping","ShaderMaterial","Mesh","PlaneGeometry","Vector3","ColliderDesc","Group","Vector3","Quaternion","init_components","ThrusterState","ThrusterEvent","state","init_components","StateMachine","t","ScreenWrapState","ScreenWrapEvent","position","defaultOptions","StateMachine","t","position","WorldBoundary2DState","WorldBoundary2DEvent","moveX","moveY","moveX","moveY","defaultOptions","StateMachine","t","Ricochet2DState","Ricochet2DEvent","scale","defaultOptions","StateMachine","t","MovementSequence2DState","MovementSequence2DEvent","step","defaultOptions","Vector3","position","moveable","Euler","Vector3","Quaternion","rotation","init_zylem_game","fragment","fragment","fragment","init_debug_shader","THREE","RAPIER","init_zylem_game","init_debug_shader"]}