@zylem/game-lib 0.6.3 → 0.7.0
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/README.md +3 -1
- package/dist/actions.d.ts +255 -8
- package/dist/actions.js +1 -772
- package/dist/audio.d.ts +13 -0
- package/dist/audio.js +1 -0
- package/dist/base-node-life-cycle-CnJ-7zX-.d.ts +143 -0
- package/dist/behavior.d.ts +3 -0
- package/dist/behavior.js +1 -0
- package/dist/chunk-4QLJUQSJ.js +1 -0
- package/dist/chunk-73VZQZUL.js +1 -0
- package/dist/chunk-A34ZG3L4.js +1 -0
- package/dist/chunk-CDPY4VOQ.js +1 -0
- package/dist/chunk-DR6XXZE7.js +19 -0
- package/dist/chunk-FM5TBEPO.js +1 -0
- package/dist/chunk-G2IIMSUH.js +1 -0
- package/dist/chunk-MSC2BEO5.js +1 -0
- package/dist/chunk-NIH5CONO.js +1 -0
- package/dist/chunk-ONWXGBWB.js +1 -0
- package/dist/chunk-QEDQDR27.js +1 -0
- package/dist/chunk-QXVH6POE.js +1 -0
- package/dist/chunk-RXDTAWI2.js +29 -0
- package/dist/chunk-WKHW2QO2.js +1 -0
- package/dist/chunk-XRP4JJXL.js +1 -0
- package/dist/chunk-YHEWKN7N.js +1 -0
- package/dist/chunk-YHKXQ2ZN.js +1 -0
- package/dist/core.d.ts +206 -13
- package/dist/core.js +24 -9160
- package/dist/debug.d.ts +24 -0
- package/dist/debug.js +1 -0
- package/dist/default-controls-BGc61yYl.d.ts +111 -0
- package/dist/entity-DNkYKfdp.d.ts +1043 -0
- package/dist/entity-type-map-C94h2TDW.d.ts +781 -0
- package/dist/entity.d.ts +265 -0
- package/dist/entity.js +1 -0
- package/dist/events.d.ts +172 -0
- package/dist/events.js +1 -0
- package/dist/game-Cuj5gy7U.d.ts +1590 -0
- package/dist/game-default-PZLLHYL7.js +1 -0
- package/dist/game-interfaces-tfpM5NBk.d.ts +90 -0
- package/dist/globals.d.ts +104 -0
- package/dist/globals.js +1 -0
- package/dist/graphics.d.ts +83 -0
- package/dist/graphics.js +1 -0
- package/dist/input-ui.d.ts +34 -0
- package/dist/input-ui.js +1 -0
- package/dist/input.d.ts +72 -0
- package/dist/input.js +1 -0
- package/dist/material-Wz83vTTp.d.ts +151 -0
- package/dist/runtime.d.ts +433 -0
- package/dist/runtime.js +1 -0
- package/dist/web-components.d.ts +67 -0
- package/dist/web-components.js +9 -0
- package/dist/world-C9zdyl5d.d.ts +103 -0
- package/dist/zylem-stage-runtime-Cs-UDEVU.d.ts +777 -0
- package/package.json +54 -41
- package/dist/actions.js.map +0 -1
- package/dist/behavior/platformer-3d.d.ts +0 -296
- package/dist/behavior/platformer-3d.js +0 -518
- package/dist/behavior/platformer-3d.js.map +0 -1
- package/dist/behavior/ricochet-2d.d.ts +0 -274
- package/dist/behavior/ricochet-2d.js +0 -394
- package/dist/behavior/ricochet-2d.js.map +0 -1
- package/dist/behavior/screen-wrap.d.ts +0 -86
- package/dist/behavior/screen-wrap.js +0 -195
- package/dist/behavior/screen-wrap.js.map +0 -1
- package/dist/behavior/thruster.d.ts +0 -10
- package/dist/behavior/thruster.js +0 -234
- package/dist/behavior/thruster.js.map +0 -1
- package/dist/behavior/world-boundary-2d.d.ts +0 -141
- package/dist/behavior/world-boundary-2d.js +0 -181
- package/dist/behavior/world-boundary-2d.js.map +0 -1
- package/dist/behavior-descriptor-BWNWmIjv.d.ts +0 -142
- package/dist/blueprints-BWGz8fII.d.ts +0 -26
- package/dist/camera-B5e4c78l.d.ts +0 -468
- package/dist/camera.d.ts +0 -6
- package/dist/camera.js +0 -1406
- package/dist/camera.js.map +0 -1
- package/dist/composition-DrzFrbqI.d.ts +0 -218
- package/dist/core-DAkskq6Y.d.ts +0 -498
- package/dist/core.js.map +0 -1
- package/dist/entities-DC9ce_vx.d.ts +0 -416
- package/dist/entities.d.ts +0 -9
- package/dist/entities.js +0 -4069
- package/dist/entities.js.map +0 -1
- package/dist/entity-BpbZqg19.d.ts +0 -1100
- package/dist/entity-Bq_eNEDI.d.ts +0 -28
- package/dist/entity-types-DAu8sGJH.d.ts +0 -26
- package/dist/global-change-Dc8uCKi2.d.ts +0 -25
- package/dist/main.d.ts +0 -654
- package/dist/main.js +0 -13355
- package/dist/main.js.map +0 -1
- package/dist/stage-types-BFsm3qsZ.d.ts +0 -567
- package/dist/stage.d.ts +0 -51
- package/dist/stage.js +0 -5738
- package/dist/stage.js.map +0 -1
- package/dist/thruster-DhRaJnoL.d.ts +0 -172
- package/dist/world-Be5m1XC1.d.ts +0 -31
package/dist/entity.d.ts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
export { A as ACTOR_TYPE, $ as AmbientLightOptions, B as BOX_TYPE, z as CONE_TYPE, J as CYLINDER_TYPE, C as CollisionShapeType, D as DISK_TYPE, a1 as DirectionalLightOptions, ad as EntityForType, ac as EntityTypeMap, a7 as FOG_TYPE, a0 as HemisphereLightOptions, Y as LIGHT_TYPE, a4 as LightShadowOptions, n as OnEnterParams, o as OnExitParams, O as OnHeldParams, U as PARTICLE_SYSTEM_TYPE, M as PILL_TYPE, P as PLANE_TYPE, G as PYRAMID_TYPE, a2 as PointLightOptions, R as RECT_TYPE, S as SPHERE_TYPE, f as SPRITE_TYPE, a3 as SpotLightOptions, h as SpriteAnimation, g as SpriteImage, T as TEXT_TYPE, m as ZONE_TYPE, q as ZylemActor, Z as ZylemBox, y as ZylemCone, I as ZylemCylinder, w as ZylemDisk, a6 as ZylemFog, aa as ZylemFogHeightOptions, ab as ZylemFogNoiseOptions, a8 as ZylemFogOptions, a9 as ZylemFogType, X as ZylemLight, _ as ZylemLightOptions, Q as ZylemParticleSystem, V as ZylemParticleSystemOptions, L as ZylemPill, j as ZylemPlane, F as ZylemPyramid, u as ZylemRect, b as ZylemSphere, e as ZylemSprite, s as ZylemText, l as ZylemZone, p as createActor, c as createBox, x as createCone, H as createCylinder, v as createDisk, a5 as createFog, W as createLight, N as createParticleSystem, K as createPill, i as createPlane, E as createPyramid, t as createRect, a as createSphere, d as createSprite, r as createText, k as createZone } from './entity-type-map-C94h2TDW.js';
|
|
2
|
+
import { G as GameEntity, I as GameEntityOptions, J as EntityBuilder, K as EntityMeshBuilder, L as EntityCollisionBuilder, M as BaseNode } from './entity-DNkYKfdp.js';
|
|
3
|
+
export { Y as CollisionComponent, O as boxCollision, Q as coneCollision, N as create, T as cylinderCollision, U as pillCollision, V as planeCollision, R as pyramidCollision, P as sphereCollision, X as zoneCollision } from './entity-DNkYKfdp.js';
|
|
4
|
+
import { Color, Mesh } from 'three';
|
|
5
|
+
import { b as Vec2Input, a as Vec3Input, M as MaterialOptions } from './material-Wz83vTTp.js';
|
|
6
|
+
import './base-node-life-cycle-CnJ-7zX-.js';
|
|
7
|
+
import './world-C9zdyl5d.js';
|
|
8
|
+
import '@dimforge/rapier3d-compat';
|
|
9
|
+
import '@zylem/behaviors/particle-emitter';
|
|
10
|
+
import './events.js';
|
|
11
|
+
import 'mitt';
|
|
12
|
+
import '@zylem/behaviors/core';
|
|
13
|
+
import 'three/webgpu';
|
|
14
|
+
|
|
15
|
+
interface CreateGameEntityOptions<T extends GameEntity<any>, CreateOptions extends GameEntityOptions> {
|
|
16
|
+
args: Array<any>;
|
|
17
|
+
defaultConfig: GameEntityOptions;
|
|
18
|
+
EntityClass: new (options: any) => T;
|
|
19
|
+
BuilderClass: new (options: any, entity: T, meshBuilder: any, collisionBuilder: any) => EntityBuilder<T, CreateOptions>;
|
|
20
|
+
MeshBuilderClass?: new (data: any) => EntityMeshBuilder;
|
|
21
|
+
CollisionBuilderClass?: new (data: any) => EntityCollisionBuilder;
|
|
22
|
+
entityType: symbol;
|
|
23
|
+
cloneFactory: (options?: Partial<CreateOptions>) => T;
|
|
24
|
+
}
|
|
25
|
+
declare function createEntity<T extends GameEntity<any>, CreateOptions extends GameEntityOptions>(params: CreateGameEntityOptions<T, CreateOptions>): T;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Factory interface for generating entity copies
|
|
29
|
+
*/
|
|
30
|
+
interface TemplateFactory<E extends GameEntity<O>, O extends GameEntityOptions = GameEntityOptions> {
|
|
31
|
+
/** The template entity used for cloning */
|
|
32
|
+
readonly template: E;
|
|
33
|
+
/**
|
|
34
|
+
* Generate multiple copies of the template entity
|
|
35
|
+
* @param count Number of copies to generate
|
|
36
|
+
* @returns Array of new entity instances
|
|
37
|
+
*/
|
|
38
|
+
generate(count: number): E[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create an entity factory from a template entity.
|
|
42
|
+
*
|
|
43
|
+
* @param template The entity to use as a template for cloning
|
|
44
|
+
* @returns Factory object with generate() method
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const asteroidTemplate = createSprite({ images: [{ name: 'asteroid', file: asteroidImg }] });
|
|
49
|
+
* const asteroidFactory = createEntityFactory(asteroidTemplate);
|
|
50
|
+
* const asteroids = asteroidFactory.generate(10);
|
|
51
|
+
*
|
|
52
|
+
* asteroids.forEach((asteroid, i) => {
|
|
53
|
+
* asteroid.setPosition(Math.random() * 20 - 10, Math.random() * 15 - 7.5, 0);
|
|
54
|
+
* stage.add(asteroid);
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function createEntityFactory<E extends GameEntity<O>, O extends GameEntityOptions = GameEntityOptions>(template: E): TemplateFactory<E, O>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* CooldownIcon -- a WoW-style cooldown icon UI entity.
|
|
62
|
+
*
|
|
63
|
+
* Renders a square icon with a semi-transparent clockwise sweep overlay
|
|
64
|
+
* that reflects cooldown progress from the CooldownStore. Optionally shows
|
|
65
|
+
* remaining time text in the center.
|
|
66
|
+
*
|
|
67
|
+
* Modeled after ZylemRect's canvas-based viewport-attached sprite pattern.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Reference point on the viewport for positioning UI elements.
|
|
72
|
+
* The offset in `screenPosition` is applied relative to this anchor.
|
|
73
|
+
*/
|
|
74
|
+
type ScreenAnchor = 'top-left' | 'top-center' | 'top-right' | 'center-left' | 'center' | 'center-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
75
|
+
/** Preset icon sizes in view units. */
|
|
76
|
+
declare const ICON_SIZE_PRESETS: {
|
|
77
|
+
readonly xs: 8;
|
|
78
|
+
readonly sm: 16;
|
|
79
|
+
readonly md: 32;
|
|
80
|
+
readonly lg: 48;
|
|
81
|
+
readonly xl: 64;
|
|
82
|
+
};
|
|
83
|
+
/** Named size preset. */
|
|
84
|
+
type IconSizePreset = keyof typeof ICON_SIZE_PRESETS;
|
|
85
|
+
/**
|
|
86
|
+
* Icon size expressed as a named preset, a square unit value, or
|
|
87
|
+
* a `{ width, height }` object for non-square icons.
|
|
88
|
+
*
|
|
89
|
+
* All numeric values are in **view units** (viewport height = 192 units).
|
|
90
|
+
*/
|
|
91
|
+
type IconSize = IconSizePreset | number | {
|
|
92
|
+
width: number;
|
|
93
|
+
height: number;
|
|
94
|
+
};
|
|
95
|
+
type ZylemCooldownIconOptions = GameEntityOptions & {
|
|
96
|
+
/** Name of the cooldown in the CooldownStore */
|
|
97
|
+
cooldown: string;
|
|
98
|
+
/** Texture path for the icon background (optional) */
|
|
99
|
+
icon?: string;
|
|
100
|
+
/** Solid fill color when no icon texture is provided */
|
|
101
|
+
fillColor?: Color | string;
|
|
102
|
+
/**
|
|
103
|
+
* Size of the icon in view units, a named preset, or a `{ width, height }` object.
|
|
104
|
+
*
|
|
105
|
+
* Presets: `'xs'` (8), `'sm'` (16), `'md'` (32), `'lg'` (48), `'xl'` (64).
|
|
106
|
+
* A bare number creates a square icon of that many units.
|
|
107
|
+
* The viewport height equals 192 units; width scales with aspect ratio.
|
|
108
|
+
*
|
|
109
|
+
* @default 'md'
|
|
110
|
+
*/
|
|
111
|
+
iconSize?: IconSize;
|
|
112
|
+
/** Whether to show remaining time text */
|
|
113
|
+
showTimer?: boolean;
|
|
114
|
+
/** Whether to attach to the camera viewport (default: true) */
|
|
115
|
+
stickToViewport?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Viewport anchor the icon is positioned relative to.
|
|
118
|
+
* @default 'top-left'
|
|
119
|
+
*/
|
|
120
|
+
screenAnchor?: ScreenAnchor;
|
|
121
|
+
/**
|
|
122
|
+
* Offset from the {@link screenAnchor} in **view units**.
|
|
123
|
+
* Positive x = right, positive y = down.
|
|
124
|
+
* Accepts a `Vector2`, plain `{ x, y }` object, or tuple.
|
|
125
|
+
* @default { x: 0, y: 0 }
|
|
126
|
+
*/
|
|
127
|
+
screenPosition?: Vec2Input;
|
|
128
|
+
/** Distance from camera (default: 1) */
|
|
129
|
+
zDistance?: number;
|
|
130
|
+
/** Color of the sweep overlay (default: semi-transparent black) */
|
|
131
|
+
overlayColor?: string;
|
|
132
|
+
};
|
|
133
|
+
declare class ZylemCooldownIcon extends GameEntity<ZylemCooldownIconOptions> {
|
|
134
|
+
static type: symbol;
|
|
135
|
+
private _sprite;
|
|
136
|
+
private _texture;
|
|
137
|
+
private _canvas;
|
|
138
|
+
private _ctx;
|
|
139
|
+
private _cameraRef;
|
|
140
|
+
private _iconTexture;
|
|
141
|
+
private _iconImage;
|
|
142
|
+
private _lastRenderedProgress;
|
|
143
|
+
constructor(options?: ZylemCooldownIconOptions);
|
|
144
|
+
private createSprite;
|
|
145
|
+
private redraw;
|
|
146
|
+
private toCssColor;
|
|
147
|
+
private getResolution;
|
|
148
|
+
private iconSetup;
|
|
149
|
+
private iconUpdate;
|
|
150
|
+
/**
|
|
151
|
+
* Resolve screen position to pixels.
|
|
152
|
+
* Computes the anchor point in pixels, then adds the view-unit offset.
|
|
153
|
+
*/
|
|
154
|
+
private resolveScreenPosition;
|
|
155
|
+
/**
|
|
156
|
+
* Resolve `iconSize` to screen pixels using the view-unit grid.
|
|
157
|
+
* Viewport height = {@link VIEW_UNITS_HEIGHT} units; width scales with aspect ratio.
|
|
158
|
+
*/
|
|
159
|
+
private resolveIconSize;
|
|
160
|
+
/** Compute the world-space half-extents at a given distance from the camera. */
|
|
161
|
+
private computeWorldExtents;
|
|
162
|
+
private updateStickyTransform;
|
|
163
|
+
/**
|
|
164
|
+
* Dispose Three.js / DOM resources when the entity is destroyed.
|
|
165
|
+
*/
|
|
166
|
+
private iconDestroy;
|
|
167
|
+
}
|
|
168
|
+
type CooldownIconOptions = BaseNode | Partial<ZylemCooldownIconOptions>;
|
|
169
|
+
/**
|
|
170
|
+
* Create a WoW-style cooldown icon UI entity.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const attackIcon = createCooldownIcon({
|
|
175
|
+
* cooldown: 'attack',
|
|
176
|
+
* icon: swordIconPath,
|
|
177
|
+
* screenAnchor: 'top-center', // reference point on the viewport
|
|
178
|
+
* screenPosition: { x: 0, y: 10 }, // offset in view units from anchor
|
|
179
|
+
* iconSize: 'sm', // preset (16 × 16 view units)
|
|
180
|
+
* // iconSize: 24, // square (24 × 24 view units)
|
|
181
|
+
* // iconSize: { width: 16, height: 24 }, // custom rectangle
|
|
182
|
+
* });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
declare function createCooldownIcon(...args: Array<CooldownIconOptions>): ZylemCooldownIcon;
|
|
186
|
+
|
|
187
|
+
declare function destroy(entity: any, globals?: any): void;
|
|
188
|
+
|
|
189
|
+
/** Shared options that every mesh factory accepts. */
|
|
190
|
+
interface BaseMeshOptions {
|
|
191
|
+
/** Offset position relative to the entity origin */
|
|
192
|
+
position?: Vec3Input;
|
|
193
|
+
/** Material options (texture, shader, etc.) */
|
|
194
|
+
material?: Partial<MaterialOptions>;
|
|
195
|
+
/** Convenience color override */
|
|
196
|
+
color?: Color;
|
|
197
|
+
}
|
|
198
|
+
interface BoxMeshOptions extends BaseMeshOptions {
|
|
199
|
+
/** Box dimensions (default: 1x1x1) */
|
|
200
|
+
size?: Vec3Input;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Create a box mesh.
|
|
204
|
+
*/
|
|
205
|
+
declare function boxMesh(opts?: BoxMeshOptions): Mesh;
|
|
206
|
+
interface SphereMeshOptions extends BaseMeshOptions {
|
|
207
|
+
/** Sphere radius (default: 1) */
|
|
208
|
+
radius?: number;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Create a sphere mesh.
|
|
212
|
+
*/
|
|
213
|
+
declare function sphereMesh(opts?: SphereMeshOptions): Mesh;
|
|
214
|
+
interface ConeMeshOptions extends BaseMeshOptions {
|
|
215
|
+
/** Base radius (default: 1) */
|
|
216
|
+
radius?: number;
|
|
217
|
+
/** Height (default: 2) */
|
|
218
|
+
height?: number;
|
|
219
|
+
/** Radial segments (default: 32) */
|
|
220
|
+
radialSegments?: number;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Create a cone mesh.
|
|
224
|
+
*/
|
|
225
|
+
declare function coneMesh(opts?: ConeMeshOptions): Mesh;
|
|
226
|
+
interface PyramidMeshOptions extends BaseMeshOptions {
|
|
227
|
+
/** Base radius (default: 1) */
|
|
228
|
+
radius?: number;
|
|
229
|
+
/** Height (default: 2) */
|
|
230
|
+
height?: number;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Create a pyramid mesh (4-sided cone).
|
|
234
|
+
*/
|
|
235
|
+
declare function pyramidMesh(opts?: PyramidMeshOptions): Mesh;
|
|
236
|
+
interface CylinderMeshOptions extends BaseMeshOptions {
|
|
237
|
+
/** Top radius (default: 1) */
|
|
238
|
+
radiusTop?: number;
|
|
239
|
+
/** Bottom radius (default: 1) */
|
|
240
|
+
radiusBottom?: number;
|
|
241
|
+
/** Height (default: 2) */
|
|
242
|
+
height?: number;
|
|
243
|
+
/** Radial segments (default: 32) */
|
|
244
|
+
radialSegments?: number;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Create a cylinder mesh.
|
|
248
|
+
*/
|
|
249
|
+
declare function cylinderMesh(opts?: CylinderMeshOptions): Mesh;
|
|
250
|
+
interface PillMeshOptions extends BaseMeshOptions {
|
|
251
|
+
/** Capsule hemisphere radius (default: 0.5) */
|
|
252
|
+
radius?: number;
|
|
253
|
+
/** Cylindrical section length (default: 1) */
|
|
254
|
+
length?: number;
|
|
255
|
+
/** Cap segments (default: 10) */
|
|
256
|
+
capSegments?: number;
|
|
257
|
+
/** Radial segments (default: 20) */
|
|
258
|
+
radialSegments?: number;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Create a pill (capsule) mesh.
|
|
262
|
+
*/
|
|
263
|
+
declare function pillMesh(opts?: PillMeshOptions): Mesh;
|
|
264
|
+
|
|
265
|
+
export { GameEntity, GameEntityOptions, type IconSize, type IconSizePreset, type ScreenAnchor, type TemplateFactory, boxMesh, coneMesh, createCooldownIcon, createEntity, createEntityFactory, cylinderMesh, destroy, pillMesh, pyramidMesh, sphereMesh };
|
package/dist/entity.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as P,b as Ve,c as Ye,d as Ne,e as We,f as Xe,g as Ue,i as je}from"./chunk-NIH5CONO.js";import{a as It,b as Z,c as Y,d as N,e as W,f as X,g as U,h as j,i as Gt,j as q,k as m,l as C,m as p,n as Be,o as x,p as R,q as $,r as K,s as D,t as He,u as Le,v as Fe,w as Ge,x as Ae,y as ke}from"./chunk-ONWXGBWB.js";import{h as At}from"./chunk-DR6XXZE7.js";import"./chunk-YHEWKN7N.js";import"./chunk-QXVH6POE.js";import"./chunk-73VZQZUL.js";import"./chunk-YHKXQ2ZN.js";import{d as V,j as Dt}from"./chunk-4QLJUQSJ.js";import{a as zt,b as gt,c as Bt,d as Ht,g as Lt,h as xt,i as E,j as Ft}from"./chunk-G2IIMSUH.js";import"./chunk-XRP4JJXL.js";import{Vector3 as ti}from"three";import{BoxGeometry as qe,CapsuleGeometry as $e,ConeGeometry as kt,CylinderGeometry as Ke,Mesh as I,MeshStandardMaterial as Qe,SphereGeometry as Je}from"three";function z(i,t=Symbol("mesh")){if(i.material||i.color){let e=new At;if(e.build({...i.material,color:i.color??i.material?.color},t),e.materials.length>0)return e.materials}return[new Qe]}function B(i,t){if(t.position){let e=xt(t.position,Bt);i.position.set(e.x,e.y,e.z)}return i.castShadow=!0,i.receiveShadow=!0,i}function Q(i={}){let t=xt(i.size,Ht),e=new qe(t.x,t.y,t.z),o=z(i);return B(new I(e,o.at(-1)),i)}function J(i={}){let t=new Je(i.radius??1),e=z(i);return B(new I(t,e.at(-1)),i)}function tt(i={}){let t=new kt(i.radius??1,i.height??2,i.radialSegments??32),e=z(i);return B(new I(t,e.at(-1)),i)}function et(i={}){let t=new kt(i.radius??1,i.height??2,4),e=z(i);return B(new I(t,e.at(-1)),i)}function it(i={}){let t=new Ke(i.radiusTop??1,i.radiusBottom??1,i.height??2,i.radialSegments??32),e=z(i);return B(new I(t,e.at(-1)),i)}function ot(i={}){let t=new $e(i.radius??.5,i.length??1,i.capSegments??10,i.radialSegments??20),e=z(i);return B(new I(t,e.at(-1)),i)}var Vt={...m,size:new ti(1,1,1)},Yt=Symbol("Box"),st=class i extends p{static type=Yt;constructor(t){super(),this.options={...Vt,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),{x:o,y:s,z:n}=this.options.size??{x:1,y:1,z:1};return{...e,type:String(i.type),size:`${o}, ${s}, ${n}`}}};function Nt(...i){let t=C(i,Vt),e=new st(t);return e.add(Q({size:t.size,material:t.material,color:t.color}),Y({size:t.size,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Nt(o??{}))}var Wt={...m,radius:1},Xt=Symbol("Sphere"),nt=class i extends p{static type=Xt;constructor(t){super(),this.options={...Wt,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1;return{...e,type:String(i.type),radius:o.toFixed(2)}}};function Ut(...i){let t=C(i,Wt),e=new nt(t);return e.add(J({radius:t.radius,material:t.material,color:t.color}),N({radius:t.radius,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Ut(o??{}))}import{ColliderDesc as ii}from"@dimforge/rapier3d-compat";import{PlaneGeometry as oi,Vector2 as jt,Vector3 as Ot}from"three";import{BufferGeometry as ei,Float32BufferAttribute as bt}from"three";var rt=class i extends ei{constructor(t=1,e=1,o=1,s=1){super(),this.type="XZPlaneGeometry",this.parameters={width:t,height:e,widthSegments:o,heightSegments:s};let n=t/2,a=e/2,r=Math.floor(o),l=Math.floor(s),c=r+1,O=l+1,u=t/r,d=e/l,b=[],f=[],y=[],v=[];for(let g=0;g<O;g++){let h=g*d-a;for(let S=0;S<c;S++){let M=S*u-n;f.push(M,0,h),y.push(0,1,0),v.push(S/r),v.push(1-g/l)}}for(let g=0;g<l;g++)for(let h=0;h<r;h++){let S=h+c*g,M=h+c*(g+1),w=h+1+c*(g+1),_=h+1+c*g;b.push(S,M,_),b.push(M,w,_)}this.setIndex(b),this.setAttribute("position",new bt(f,3)),this.setAttribute("normal",new bt(y,3)),this.setAttribute("uv",new bt(v,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new i(t.width,t.height,t.widthSegments,t.heightSegments)}};var at=4,qt={...m,tile:new jt(10,10),repeat:new jt(1,1),collision:{static:!0},subdivisions:at,randomizeHeight:!1,heightScale:1};function $t(i){let t=i.subdivisions??at,e=i.heightMap2D,o=i.heightMap,s=i.subdivisionsX??t,n=i.subdivisionsZ??t;return e&&e.length>0&&e[0]?.length>0?(n=e.length-1,s=e[0].length-1):o&&o.length>0&&(s=o.length-1),{subdivisionsX:s,subdivisionsZ:n}}var Pt=class extends ${collider(t){let e=E(t.tile,gt),{subdivisionsX:o,subdivisionsZ:s}=$t(t),n=new Ot(e.x,1,e.y),a=t._builders?.meshBuilder?.heightData,r=new Ot(n.x,1,n.z);return ii.heightfield(o,s,a,r)}},wt=class extends K{heightData=new Float32Array;columnsRows=new Map;subdivisionsX=at;subdivisionsZ=at;build(t){let e=E(t.tile,gt),{subdivisionsX:o,subdivisionsZ:s}=$t(t);this.subdivisionsX=o,this.subdivisionsZ=s;let n=new Ot(e.x,1,e.y),a=t.heightScale??1,r=new rt(n.x,n.z,o,s),l=new oi(n.x,n.z,o,s),c=o>0?n.x/o:1,O=s>0?n.z/s:1,u=r.attributes.position.array,d=l.attributes.position.array,b=new Map,f=t.heightMap2D,y=t.heightMap,v=t.randomizeHeight??!1,g=(h,S)=>h<0?0:h>S?S:h;for(let h=0;h<d.length;h+=3){let S=d[h],M=d[h+1],w=g(Math.round((S+n.x/2)/c),o),_=g(Math.round((n.z/2-M)/O),s),T=0;if(f){let Rt=f[_];Rt&&(T=Rt[w]??0)}else y&&y.length>0?T=y[w]??0:v&&(T=Math.random()*4);let A=T*a;d[h+2]=A,u[h+1]=A,b.get(_)||b.set(_,new Map),b.get(_).set(w,A)}return this.columnsRows=b,r}postBuild(){let t=[];for(let e=0;e<=this.subdivisionsX;++e)for(let o=0;o<=this.subdivisionsZ;++o){let s=this.columnsRows.get(o);t.push(s?.get(e)??0)}this.heightData=new Float32Array(t)}},Ct=class extends D{createEntity(t){return new H(t)}},Kt=Symbol("Plane"),H=class extends p{static type=Kt;constructor(t){super(),this.options=Z(qt,t)}};function Qt(...i){return R({args:i,defaultConfig:qt,EntityClass:H,BuilderClass:Ct,MeshBuilderClass:wt,CollisionBuilderClass:Pt,entityType:H.type,cloneFactory:t=>Qt(t??{})})}import{Vector3 as si}from"three";var Jt={...m,size:new si(1,1,1),collision:{static:!0}},te=Symbol("Zone"),lt=class extends p{static type=te;_enteredZone=new Map;_exitedZone=new Map;_zoneEntities=new Map;constructor(t){super(),this.options=Z(Jt,t)}handlePostCollision({delta:t}){return this._enteredZone.forEach((e,o)=>{this.exited(t,o)}),this._enteredZone.size>0}handleIntersectionEvent({other:t,delta:e}){this._enteredZone.get(t.uuid)?this.held(e,t):(this.entered(t),this._zoneEntities.set(t.uuid,t))}onEnter(t){return this.options.onEnter=t,this}onHeld(t){return this.options.onHeld=t,this}onExit(t){return this.options.onExit=t,this}entered(t){this._enteredZone.set(t.uuid,1),this.options.onEnter&&this.options.onEnter({self:this,visitor:t,globals:V.globals})}exited(t,e){let o=this._exitedZone.get(e);if(o&&o>1+t){this._exitedZone.delete(e),this._enteredZone.delete(e);let s=this._zoneEntities.get(e);this.options.onExit&&this.options.onExit({self:this,visitor:s,globals:V.globals});return}this._exitedZone.set(e,1+t)}held(t,e){let o=this._enteredZone.get(e.uuid)??0;this._enteredZone.set(e.uuid,o+t),this._exitedZone.set(e.uuid,1),this.options.onHeld&&this.options.onHeld({delta:t,self:this,visitor:e,globals:V.globals,heldTime:o})}};function ee(...i){let t=C(i,Jt),e=new lt(t);return e.add(q({size:t.size,static:t.collision?.static??!0,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>ee(o??{}))}import{Color as ie,Group as ni,Sprite as ri,SpriteMaterial as ai,CanvasTexture as oe,LinearFilter as pt,Vector2 as ct,ClampToEdgeWrapping as se,ShaderMaterial as ne,Mesh as li,PlaneGeometry as pi,Vector3 as re}from"three";var L={position:void 0,width:120,height:48,fillColor:"#FFFFFF",strokeColor:null,strokeWidth:0,radius:0,padding:0,stickToViewport:!0,screenPosition:new ct(24,24),zDistance:1,anchor:new ct(0,0)},St=class extends D{createEntity(t){return new F(t)}},ae=Symbol("Rect"),F=class i extends p{static type=ae;_sprite=null;_mesh=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=Z(L,t),this.options.screenPosition=E(this.options.screenPosition,L.screenPosition),this.options.anchor=E(this.options.anchor,L.anchor),this.group=new ni,this.createSprite(),this.prependSetup(this.rectSetup.bind(this)),this.prependUpdate(this.rectUpdate.bind(this))}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new oe(this._canvas),this._texture.minFilter=pt,this._texture.magFilter=pt;let t=new ai({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new ri(t),this.group?.add(this._sprite),this.redrawRect()}redrawRect(){if(!this._canvas||!this._ctx)return;let t=Math.max(2,Math.floor(this.options.width??120)),e=Math.max(2,Math.floor(this.options.height??48)),o=this.options.padding??0,s=this.options.strokeWidth??0,n=t+o*2+s,a=e+o*2+s,r=Math.max(2,n),l=Math.max(2,a),c=r!==this._lastCanvasW||l!==this._lastCanvasH;this._canvas.width=r,this._canvas.height=l,this._lastCanvasW=r,this._lastCanvasH=l,this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height);let O=Math.max(0,this.options.radius??0),u=Math.floor(o+s/2),d=Math.floor(o+s/2),b=Math.floor(t),f=Math.floor(e);if(this._ctx.beginPath(),O>0?this.roundedRectPath(this._ctx,u,d,b,f,O):this._ctx.rect(u,d,b,f),this.options.fillColor&&(this._ctx.fillStyle=this.toCssColor(this.options.fillColor),this._ctx.fill()),this.options.strokeColor&&s>0&&(this._ctx.lineWidth=s,this._ctx.strokeStyle=this.toCssColor(this.options.strokeColor),this._ctx.stroke()),this._texture){if(c&&(this._texture.dispose(),this._texture=new oe(this._canvas),this._texture.minFilter=pt,this._texture.magFilter=pt,this._texture.wrapS=se,this._texture.wrapT=se,this._sprite&&this._sprite.material instanceof ne)){let y=this._sprite.material;y.uniforms?.tDiffuse&&(y.uniforms.tDiffuse.value=this._texture),y.uniforms?.iResolution&&y.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)}this._texture.image=this._canvas,this._texture.needsUpdate=!0,this._sprite&&this._sprite.material&&(this._sprite.material.map=this._texture,this._sprite.material.needsUpdate=!0)}}getWidth(){return this.options.width??0}getHeight(){return this.options.height??0}roundedRectPath(t,e,o,s,n,a){let r=Math.min(a,Math.floor(Math.min(s,n)/2));t.moveTo(e+r,o),t.lineTo(e+s-r,o),t.quadraticCurveTo(e+s,o,e+s,o+r),t.lineTo(e+s,o+n-r),t.quadraticCurveTo(e+s,o+n,e+s-r,o+n),t.lineTo(e+r,o+n),t.quadraticCurveTo(e,o+n,e,o+n-r),t.lineTo(e,o+r),t.quadraticCurveTo(e,o,e+r,o)}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof ie?t:new ie(t)).getHexString()}`}getResolution(){try{let t=this._cameraRef?.renderer?.domElement;if(t)return{width:t.clientWidth||1,height:t.clientHeight||1}}catch{}return{width:this._cameraRef?.screenResolution?.x??1,height:this._cameraRef?.screenResolution?.y??1}}rectSetup(t){if(this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&this._cameraRef.camera.add(this.group),this.materials?.length&&this._sprite){let e=this.materials[0];e instanceof ne&&(e.transparent=!0,e.depthTest=!1,e.depthWrite=!1,this._texture&&(e.uniforms?.tDiffuse&&(e.uniforms.tDiffuse.value=this._texture),e.uniforms?.iResolution&&this._canvas&&e.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)),this._mesh=new li(new pi(1,1),e),this.group?.add(this._mesh),this._sprite.visible=!1)}}rectUpdate(t){if(this._sprite){if(this._cameraRef&&this.options.bounds){let e=this.computeScreenBoundsFromOptions(this.options.bounds);if(e){let{x:o,y:s,width:n,height:a}=e,r=Math.max(2,Math.floor(n)),l=Math.max(2,Math.floor(a)),c=r!==(this.options.width??0)||l!==(this.options.height??0);this.options.screenPosition=new ct(Math.floor(o),Math.floor(s)),this.options.width=r,this.options.height=l,this.options.anchor=new ct(0,0),c&&this.redrawRect()}}this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:o}=this.getResolution(),s=E(this.options.screenPosition,L.screenPosition),n=s.x,a=s.y,r=Math.max(.001,this.options.zDistance??1),l=1,c=1;if(t.isPerspectiveCamera){let w=t,_=Math.tan(w.fov*Math.PI/180/2)*r;l=_*w.aspect,c=_}else if(t.isOrthographicCamera){let w=t;l=(w.right-w.left)/2,c=(w.top-w.bottom)/2}let O=n/e*2-1,u=1-a/o*2,d=O*l,b=u*c,f=1,y=1;if(this._canvas){let _=c*2/o,T=this._canvas.height;y=Math.max(1e-4,T*_);let A=this._canvas.width/this._canvas.height;f=y*A,this._sprite.scale.set(f,y,1),this._mesh&&this._mesh.scale.set(f,y,1)}let v=E(this.options.anchor,L.anchor),g=Math.min(100,Math.max(0,v.x))/100,h=Math.min(100,Math.max(0,v.y))/100,S=(.5-g)*f,M=(h-.5)*y;this.group?.position.set(d+S,b+M,-r)}worldToScreen(t){if(!this._cameraRef)return{x:0,y:0};let e=this._cameraRef.camera,{width:o,height:s}=this.getResolution(),n=t.clone().project(e),a=(n.x+1)/2*o,r=(1-n.y)/2*s;return{x:a,y:r}}computeScreenBoundsFromOptions(t){if(!this._cameraRef)return null;if(t.screen)return{...t.screen};if(t.world){let{left:e,right:o,top:s,bottom:n,z:a=0}=t.world,r=this.worldToScreen(new re(e,s,a)),l=this.worldToScreen(new re(o,n,a)),c=Math.min(r.x,l.x),O=Math.min(r.y,l.y),u=Math.abs(l.x-r.x),d=Math.abs(l.y-r.y);return{x:c,y:O,width:u,height:d}}return null}updateRect(t){this.options={...this.options,...t},this.redrawRect(),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new P(this).buildDebugInfo(),type:String(i.type),width:this.options.width??0,height:this.options.height??0,sticky:this.options.stickToViewport}}};function le(...i){return R({args:i,defaultConfig:{...L},EntityClass:F,BuilderClass:St,entityType:F.type,cloneFactory:t=>le(t??{})})}import{ColliderDesc as ci}from"@dimforge/rapier3d-compat";import{Group as hi,RingGeometry as mi}from"three";var pe={...m,innerRadius:0,outerRadius:1,thetaSegments:32},_t=class extends ${collider(t){let e=t.outerRadius??1;return ci.cylinder(.1/2,e)}},vt=class extends K{build(t){let e=t.innerRadius??0,o=t.outerRadius??1,s=t.thetaSegments??32,n=new mi(e,o,s);return n.rotateX(-Math.PI/2),n}},Et=class extends D{createEntity(t){return new G(t)}build(){let t=super.build();return t.mesh&&!t.group&&(t.group=new hi,t.group.add(t.mesh)),t}},ce=Symbol("Disk"),G=class i extends p{static type=ce;constructor(t){super(),this.options={...pe,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.innerRadius??0,s=this.options.outerRadius??1;return{...e,type:String(i.type),innerRadius:o.toFixed(2),outerRadius:s.toFixed(2)}}};function he(...i){return R({args:i,defaultConfig:pe,EntityClass:G,BuilderClass:Et,MeshBuilderClass:vt,CollisionBuilderClass:_t,entityType:G.type,cloneFactory:t=>he(t??{})})}var me={...m,radius:1,height:2,radialSegments:32},ue=Symbol("Cone"),ht=class i extends p{static type=ue;constructor(t){super(),this.options={...me,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1,s=this.options.height??2;return{...e,type:String(i.type),radius:o.toFixed(2),height:s.toFixed(2)}}};function de(...i){let t=C(i,me),e=new ht(t);return e.add(tt({radius:t.radius,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),W({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>de(o??{}))}var ye={...m,radius:1,height:2},fe=Symbol("Pyramid"),mt=class i extends p{static type=fe;constructor(t){super(),this.options={...ye,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??1,s=this.options.height??2;return{...e,type:String(i.type),radius:o.toFixed(2),height:s.toFixed(2)}}};function ge(...i){let t=C(i,ye),e=new mt(t);return e.add(et({radius:t.radius,height:t.height,material:t.material,color:t.color}),X({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>ge(o??{}))}var xe={...m,radiusTop:1,radiusBottom:1,height:2,radialSegments:32},be=Symbol("Cylinder"),ut=class i extends p{static type=be;constructor(t){super(),this.options={...xe,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radiusTop??1,s=this.options.radiusBottom??1,n=this.options.height??2;return{...e,type:String(i.type),radiusTop:o.toFixed(2),radiusBottom:s.toFixed(2),height:n.toFixed(2)}}};function Oe(...i){let t=C(i,xe),e=new ut(t);return e.add(it({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),U({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Oe(o??{}))}var Pe={...m,radius:.5,length:1,capSegments:10,radialSegments:20},we=Symbol("Pill"),dt=class i extends p{static type=we;constructor(t){super(),this.options={...Pe,...t}}buildInfo(){let e=new P(this).buildDebugInfo(),o=this.options.radius??.5,s=this.options.length??1;return{...e,type:String(i.type),radius:o.toFixed(2),length:s.toFixed(2)}}};function Ce(...i){let t=C(i,Pe),e=new dt(t);return e.add(ot({radius:t.radius,length:t.length,capSegments:t.capSegments,radialSegments:t.radialSegments,material:t.material,color:t.color}),j({radius:t.radius,length:t.length,static:t.collision?.static,sensor:t.collision?.sensor,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),x(e,o=>Ce(o??{}))}import{Group as ui,Quaternion as di,Vector3 as yi}from"three";import{ParticleEmitterBehavior as Zt}from"@zylem/behaviors/particle-emitter";var fi={...m,effect:{create(){throw new Error("createParticleSystem(...) requires an effect or preset definition.")}},preset:void 0,autoplay:!0,localOffset:void 0,followPosition:!0,followRotation:!0,autoDestroy:!1},Se=Symbol("ParticleSystem");function gi(i){return{effect:i.preset??i.effect,autoplay:i.autoplay,localOffset:i.localOffset,followPosition:i.followPosition,followRotation:i.followRotation,autoDestroy:i.autoDestroy}}var yt=class i extends p{static type=Se;particleHandle=null;constructor(t,e=!0){super(),this.options=Z(fi,t),this.group=new ui;let o=this.options.position;o&&this.group.position.copy(Ft(o)),this.__zylemParticleSystemEntity=!0,this.bindStandaloneTransforms(),e&&(this.particleHandle=this.use(Zt,gi(this.options)))}bindStandaloneTransforms(){let t=()=>{this.options.position=new yi(this.group?.position.x??0,this.group?.position.y??0,this.group?.position.z??0)},e=()=>{this.group&&(this._rotation2DAngle=this.group.rotation.z)};this.setPosition=(o,s,n)=>{this.group?.position.set(o,s,n),t()},this.setPositionX=o=>{this.group&&(this.group.position.x=o,t())},this.setPositionY=o=>{this.group&&(this.group.position.y=o,t())},this.setPositionZ=o=>{this.group&&(this.group.position.z=o,t())},this.getPosition=()=>this.group?{x:this.group.position.x,y:this.group.position.y,z:this.group.position.z}:null,this.setRotation=(o,s,n)=>{this.group?.rotation.set(o,s,n),e()},this.setRotationX=o=>{this.group&&(this.group.rotation.x=o,e())},this.setRotationY=o=>{this.group&&(this.group.rotation.y=o,e())},this.setRotationZ=o=>{this.group&&(this.group.rotation.z=o,e())},this.setRotationDegrees=(o,s,n)=>{this.group?.rotation.set(o*Math.PI/180,s*Math.PI/180,n*Math.PI/180),e()},this.setRotationDegreesX=o=>{this.group&&(this.group.rotation.x=o*Math.PI/180,e())},this.setRotationDegreesY=o=>{this.group&&(this.group.rotation.y=o*Math.PI/180,e())},this.setRotationDegreesZ=o=>{this.group&&(this.group.rotation.z=o*Math.PI/180,e())},this.rotateX=o=>{this.group?.rotateX(o),e()},this.rotateY=o=>{this.group?.rotateY(o),e()},this.rotateZ=o=>{this.group?.rotateZ(o),e()},this.getRotation=()=>{if(!this.group)return null;let o=new di;return this.group.getWorldQuaternion(o),o}}resolveParticleHandle(){if(this.particleHandle)return this.particleHandle;let t=this.getBehaviorRefs().find(s=>s.descriptor.key===Zt.key);if(!t)return null;let e={getFSM:()=>t.fsm??null,getOptions:()=>t.options,ref:t},o=Zt.createHandle?.(t)??{};return this.particleHandle={...e,...o},this.particleHandle}play(){this.resolveParticleHandle()?.play()}stop(){this.resolveParticleHandle()?.stop()}pause(){this.resolveParticleHandle()?.pause()}restart(){this.resolveParticleHandle()?.restart()}burst(){this.resolveParticleHandle()?.burst()}isPlaying(){return this.resolveParticleHandle()?.isPlaying()??!1}getSystem(){return this.resolveParticleHandle()?.getSystem()}buildInfo(){return{...super.buildInfo(),type:String(i.type)}}};function _e(i,t=!0){let e=new yt(i,t);return x(e,o=>_e(o,!1))}function xi(i){return _e(i,!0)}import{AmbientLight as bi,DirectionalLight as Oi,Group as Pi,HemisphereLight as wi,Object3D as Ci,PointLight as Si,SpotLight as _i}from"three";var ve=Symbol("Light"),vi={x:0,y:0,z:0},k=16777215,Ei={mapSize:2048,near:.1,far:500,bias:0,radius:1,left:-100,right:100,top:100,bottom:-100},Zi={mapSize:1024,near:.1,far:500,bias:0,radius:1},ft=class extends p{static type=ve;light=null;lightTarget=null;constructor(t){super(),this.options={...t}}create(){super.create();let t=new Pi,{light:e,target:o}=Mi(this.options);return t.add(e),o&&t.add(o),this.group=t,this.light=e,this.lightTarget=o,this}_cleanup(t){this.light?.shadow?.map?.dispose?.(),this.light=null,this.lightTarget=null,super._cleanup(t)}};function Mi(i){switch(i.type){case"ambient":return{light:Ti(i),target:null};case"hemisphere":return{light:Ri(i),target:null};case"directional":return Di(i);case"point":return{light:Ii(i),target:null};case"spot":return zi(i)}}function Ti(i){let t=new bi(i.color??k,i.intensity??1);return i.name&&(t.name=i.name),t}function Ri(i){let t=i.skyColor??i.color??k,e=i.groundColor??0,o=new wi(t,e,i.intensity??1);return i.name&&(o.name=i.name),o}function Di(i){let t=new Oi(i.color??k,i.intensity??1);i.name&&(t.name=i.name),Bi(t,i.castShadow??!1,i.shadow);let e=Ee(i.position,i.target);return e&&(t.target=e),{light:t,target:e}}function Ii(i){let t=new Si(i.color??k,i.intensity??1,i.distance,i.decay);return i.name&&(t.name=i.name),Ze(t,i.castShadow??!1,i.shadow),t}function zi(i){let t=new _i(i.color??k,i.intensity??1,i.distance,i.angle,i.penumbra,i.decay);i.name&&(t.name=i.name),Ze(t,i.castShadow??!1,i.shadow);let e=Ee(i.position,i.target);return e&&(t.target=e),{light:t,target:e}}function Ee(i,t){if(!t)return null;let e=i??vi,o=new Ci;return o.position.set(t.x-e.x,t.y-e.y,t.z-e.z),o}function Bi(i,t,e){if(!t){i.castShadow=!1;return}i.castShadow=!0;let o={...Ei,...e??{}};i.shadow.mapSize.set(o.mapSize,o.mapSize),i.shadow.camera.near=o.near,i.shadow.camera.far=o.far,i.shadow.camera.left=o.left,i.shadow.camera.right=o.right,i.shadow.camera.top=o.top,i.shadow.camera.bottom=o.bottom,i.shadow.bias=o.bias,i.shadow.radius=o.radius,i.shadow.camera.updateProjectionMatrix()}function Ze(i,t,e){if(!t){i.castShadow=!1;return}i.castShadow=!0;let o={...Zi,...e??{}};i.shadow.mapSize.set(o.mapSize,o.mapSize),i.shadow.camera.near=o.near,i.shadow.camera.far=o.far,i.shadow.bias=o.bias,i.shadow.radius=o.radius,i.shadow.camera.updateProjectionMatrix()}function Hi(i){return new ft(i)}import{Group as Li,Sprite as Fi,SpriteMaterial as Gi,CanvasTexture as Ai,LinearFilter as Me,Color as Te,ClampToEdgeWrapping as Re}from"three";import{getCooldown as De}from"@zylem/behaviors/cooldown";var ki={"top-left":{fx:0,fy:0},"top-center":{fx:.5,fy:0},"top-right":{fx:1,fy:0},"center-left":{fx:0,fy:.5},center:{fx:.5,fy:.5},"center-right":{fx:1,fy:.5},"bottom-left":{fx:0,fy:1},"bottom-center":{fx:.5,fy:1},"bottom-right":{fx:1,fy:1}},Ie=192,Vi={xs:8,sm:16,md:32,lg:48,xl:64},Mt={position:void 0,cooldown:"",iconSize:"md",fillColor:"#333333",showTimer:!0,stickToViewport:!0,screenAnchor:"top-left",screenPosition:{x:0,y:0},zDistance:1,overlayColor:"rgba(0, 0, 0, 0.65)"},Yi=Symbol("CooldownIcon"),Tt=class extends p{static type=Yi;_sprite=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_iconTexture=null;_iconImage=null;_lastRenderedProgress=-1;constructor(t){super(),this.options=Z(Mt,t),this.options.screenPosition=E(this.options.screenPosition,Mt.screenPosition),this.group=new Li,this.createSprite(),this.prependSetup(this.iconSetup.bind(this)),this.prependUpdate(this.iconUpdate.bind(this)),this.onCleanup(this.iconDestroy.bind(this))}createSprite(){this._canvas=document.createElement("canvas"),this._canvas.width=256,this._canvas.height=256,this._ctx=this._canvas.getContext("2d"),this._texture=new Ai(this._canvas),this._texture.minFilter=Me,this._texture.magFilter=Me,this._texture.wrapS=Re,this._texture.wrapT=Re;let e=new Gi({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1});if(this._sprite=new Fi(e),this.group?.add(this._sprite),this.options.icon){let o=new Image;o.crossOrigin="anonymous",o.onload=()=>{this._iconImage=o,this.redraw(this._lastRenderedProgress>=0?this._lastRenderedProgress:1)},o.src=this.options.icon}this.redraw(1)}redraw(t){if(!this._canvas||!this._ctx)return;let e=this._ctx,o=this._canvas.width,s=this._canvas.height,n=o/2,a=s/2,r=Math.min(n,a);if(e.clearRect(0,0,o,s),this._iconImage?e.drawImage(this._iconImage,0,0,o,s):(e.fillStyle=this.toCssColor(this.options.fillColor??"#333333"),e.fillRect(0,0,o,s)),t<1){let l=(1-t)*Math.PI*2,c=-Math.PI/2,O=c+l;if(e.save(),e.fillStyle=this.options.overlayColor??"rgba(0, 0, 0, 0.65)",e.beginPath(),e.moveTo(n,a),e.arc(n,a,r+1,c,O,!1),e.closePath(),e.fill(),e.restore(),this.options.showTimer){let u=De(this.options.cooldown);if(u){let d=Math.max(0,u.duration-u.elapsed),b=d>=10?Math.ceil(d).toString():d.toFixed(1),f=Math.floor(o*.3);e.font=`bold ${f}px sans-serif`,e.textAlign="center",e.textBaseline="middle",e.fillStyle="#FFFFFF",e.strokeStyle="#000000",e.lineWidth=2,e.strokeText(b,n,a),e.fillText(b,n,a)}}}this._texture&&(this._texture.needsUpdate=!0),this._lastRenderedProgress=t}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof Te?t:new Te(t)).getHexString()}`}getResolution(){try{let t=this._cameraRef?.renderer?.domElement;if(t)return{width:t.clientWidth||1,height:t.clientHeight||1}}catch{}return{width:this._cameraRef?.screenResolution?.x??1,height:this._cameraRef?.screenResolution?.y??1}}iconSetup(t){this._sprite||this.createSprite(),this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&(this._cameraRef.camera.add(this.group),this.updateStickyTransform())}iconUpdate(t){let o=De(this.options.cooldown)?.progress??1;(Math.abs(o-this._lastRenderedProgress)>.02||o===1&&this._lastRenderedProgress!==1)&&this.redraw(o),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}resolveScreenPosition(t,e){let o=this.options.screenAnchor??"top-left",s=Lt(this.options.screenPosition,zt),n=s.x,a=s.y,{fx:r,fy:l}=ki[o],c=r*t,O=l*e,u=e/Ie;return{px:c+n*u,py:O+a*u}}resolveIconSize(t){let e=this.options.iconSize??"md",o,s;typeof e=="string"?o=s=Vi[e]:typeof e=="number"?o=s=e:(o=e.width,s=e.height);let n=t/Ie;return{widthPx:o*n,heightPx:s*n}}computeWorldExtents(t,e){let o=1,s=1;if(t.isPerspectiveCamera){let n=t,a=Math.tan(n.fov*Math.PI/180/2)*e;o=a*n.aspect,s=a}else if(t.isOrthographicCamera){let n=t;o=(n.right-n.left)/2,s=(n.top-n.bottom)/2}return{worldHalfW:o,worldHalfH:s}}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:o}=this.getResolution(),{px:s,py:n}=this.resolveScreenPosition(e,o),a=Math.max(.001,this.options.zDistance??1),{worldHalfW:r,worldHalfH:l}=this.computeWorldExtents(t,a),c=s/e*2-1,O=1-n/o*2,u=c*r,d=O*l;{let f=l*2/o,{widthPx:y,heightPx:v}=this.resolveIconSize(o),g=Math.max(1e-4,y*f),h=Math.max(1e-4,v*f);this._sprite.scale.set(g,h,1)}this.group?.position.set(u,d,-a)}iconDestroy(){this._texture?.dispose(),this._sprite?.material&&this._sprite.material.dispose(),this._sprite&&this._sprite.removeFromParent(),this.group?.removeFromParent(),this._iconTexture?.dispose(),this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._cameraRef=null,this._iconTexture=null,this._iconImage=null}};function ze(...i){let t=i.filter(o=>!(o instanceof It)),e={...Mt};for(let o of t)e={...e,...o};return x(new Tt(e),o=>ze(o??{}))}function Ni(i,t,e){e({me:i,globals:t})}function Wi(i,t){let e=t??Dt();Ni(i,e,i.nodeDestroy.bind(i))}export{He as ACTOR_TYPE,Yt as BOX_TYPE,ue as CONE_TYPE,be as CYLINDER_TYPE,ce as DISK_TYPE,Ge as FOG_TYPE,ve as LIGHT_TYPE,Se as PARTICLE_SYSTEM_TYPE,we as PILL_TYPE,Kt as PLANE_TYPE,fe as PYRAMID_TYPE,ae as RECT_TYPE,Xt as SPHERE_TYPE,We as SPRITE_TYPE,Ve as TEXT_TYPE,te as ZONE_TYPE,Le as ZylemActor,st as ZylemBox,ht as ZylemCone,ut as ZylemCylinder,G as ZylemDisk,Ae as ZylemFog,ft as ZylemLight,yt as ZylemParticleSystem,dt as ZylemPill,H as ZylemPlane,mt as ZylemPyramid,F as ZylemRect,nt as ZylemSphere,Xe as ZylemSprite,Ye as ZylemText,lt as ZylemZone,Y as boxCollision,Q as boxMesh,W as coneCollision,tt as coneMesh,Be as create,Fe as createActor,Nt as createBox,de as createCone,ze as createCooldownIcon,Oe as createCylinder,he as createDisk,R as createEntity,je as createEntityFactory,ke as createFog,Hi as createLight,xi as createParticleSystem,Ce as createPill,Qt as createPlane,ge as createPyramid,le as createRect,Ut as createSphere,Ue as createSprite,Ne as createText,ee as createZone,U as cylinderCollision,it as cylinderMesh,Wi as destroy,j as pillCollision,ot as pillMesh,Gt as planeCollision,X as pyramidCollision,et as pyramidMesh,N as sphereCollision,J as sphereMesh,q as zoneCollision};
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as mitt from 'mitt';
|
|
2
|
+
import { g as LoadingEvent } from './base-node-life-cycle-CnJ-7zX-.js';
|
|
3
|
+
import 'three';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Reusable delegate for event emission and subscription.
|
|
7
|
+
* Use via composition in Game, Stage, and Entity classes.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* class Game {
|
|
11
|
+
* private eventDelegate = new EventEmitterDelegate<GameEvents>();
|
|
12
|
+
*
|
|
13
|
+
* dispatch<K extends keyof GameEvents>(event: K, payload: GameEvents[K]) {
|
|
14
|
+
* this.eventDelegate.dispatch(event, payload);
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
declare class EventEmitterDelegate<TEvents extends Record<string, unknown>> {
|
|
19
|
+
private emitter;
|
|
20
|
+
private unsubscribes;
|
|
21
|
+
constructor();
|
|
22
|
+
/**
|
|
23
|
+
* Dispatch an event to all listeners.
|
|
24
|
+
*/
|
|
25
|
+
dispatch<K extends keyof TEvents>(event: K, payload: TEvents[K]): void;
|
|
26
|
+
/**
|
|
27
|
+
* Subscribe to an event. Returns an unsubscribe function.
|
|
28
|
+
*/
|
|
29
|
+
listen<K extends keyof TEvents>(event: K, handler: (payload: TEvents[K]) => void): () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Subscribe to all events.
|
|
32
|
+
*/
|
|
33
|
+
listenAll(handler: (type: keyof TEvents, payload: TEvents[keyof TEvents]) => void): () => void;
|
|
34
|
+
/**
|
|
35
|
+
* Clean up all subscriptions.
|
|
36
|
+
*/
|
|
37
|
+
dispose(): void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Payload for game loading events with stage context.
|
|
42
|
+
*/
|
|
43
|
+
interface GameLoadingPayload extends LoadingEvent {
|
|
44
|
+
stageName?: string;
|
|
45
|
+
stageIndex?: number;
|
|
46
|
+
}
|
|
47
|
+
/** Payload for stage configuration sent to editor. */
|
|
48
|
+
interface StageConfigPayload {
|
|
49
|
+
id: string;
|
|
50
|
+
backgroundColor: string;
|
|
51
|
+
backgroundImage: string | null;
|
|
52
|
+
gravity: {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
z: number;
|
|
56
|
+
};
|
|
57
|
+
inputs: Record<string, string[]>;
|
|
58
|
+
variables: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/** Payload for entity configuration sent to editor. */
|
|
61
|
+
interface EntityConfigPayload {
|
|
62
|
+
uuid: string;
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
position: {
|
|
66
|
+
x: number;
|
|
67
|
+
y: number;
|
|
68
|
+
z: number;
|
|
69
|
+
};
|
|
70
|
+
rotation: {
|
|
71
|
+
x: number;
|
|
72
|
+
y: number;
|
|
73
|
+
z: number;
|
|
74
|
+
};
|
|
75
|
+
scale: {
|
|
76
|
+
x: number;
|
|
77
|
+
y: number;
|
|
78
|
+
z: number;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** Payload for state dispatch events from game to editor. */
|
|
82
|
+
interface StateDispatchPayload {
|
|
83
|
+
scope: 'game' | 'stage' | 'entity';
|
|
84
|
+
path: string;
|
|
85
|
+
value: unknown;
|
|
86
|
+
previousValue?: unknown;
|
|
87
|
+
config?: {
|
|
88
|
+
id: string;
|
|
89
|
+
aspectRatio: number;
|
|
90
|
+
fullscreen: boolean;
|
|
91
|
+
bodyBackground: string | undefined;
|
|
92
|
+
internalResolution: {
|
|
93
|
+
width: number;
|
|
94
|
+
height: number;
|
|
95
|
+
} | undefined;
|
|
96
|
+
debug: boolean;
|
|
97
|
+
} | null;
|
|
98
|
+
stageConfig?: StageConfigPayload | null;
|
|
99
|
+
entities?: EntityConfigPayload[] | null;
|
|
100
|
+
}
|
|
101
|
+
type GameEvents = {
|
|
102
|
+
'loading:start': GameLoadingPayload;
|
|
103
|
+
'loading:progress': GameLoadingPayload;
|
|
104
|
+
'loading:complete': GameLoadingPayload;
|
|
105
|
+
'paused': {
|
|
106
|
+
paused: boolean;
|
|
107
|
+
};
|
|
108
|
+
'debug': {
|
|
109
|
+
enabled: boolean;
|
|
110
|
+
};
|
|
111
|
+
'state:dispatch': StateDispatchPayload;
|
|
112
|
+
};
|
|
113
|
+
type StageEvents = {
|
|
114
|
+
'stage:loaded': {
|
|
115
|
+
stageId: string;
|
|
116
|
+
};
|
|
117
|
+
'stage:unloaded': {
|
|
118
|
+
stageId: string;
|
|
119
|
+
};
|
|
120
|
+
'stage:variable:changed': {
|
|
121
|
+
key: string;
|
|
122
|
+
value: unknown;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
type EntityEvents = {
|
|
126
|
+
'entity:spawned': {
|
|
127
|
+
entityId: string;
|
|
128
|
+
name: string;
|
|
129
|
+
};
|
|
130
|
+
'entity:destroyed': {
|
|
131
|
+
entityId: string;
|
|
132
|
+
};
|
|
133
|
+
'entity:collision': {
|
|
134
|
+
entityId: string;
|
|
135
|
+
otherId: string;
|
|
136
|
+
};
|
|
137
|
+
'entity:model:loading': {
|
|
138
|
+
entityId: string;
|
|
139
|
+
files: string[];
|
|
140
|
+
};
|
|
141
|
+
'entity:model:loaded': {
|
|
142
|
+
entityId: string;
|
|
143
|
+
success: boolean;
|
|
144
|
+
meshCount?: number;
|
|
145
|
+
errorMessage?: string;
|
|
146
|
+
};
|
|
147
|
+
'entity:animation:loaded': {
|
|
148
|
+
entityId: string;
|
|
149
|
+
animationCount: number;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
type ZylemEvents = GameEvents & StageEvents & EntityEvents;
|
|
153
|
+
/**
|
|
154
|
+
* Global event bus for cross-package communication.
|
|
155
|
+
*
|
|
156
|
+
* Usage:
|
|
157
|
+
* ```ts
|
|
158
|
+
* import { zylemEventBus } from '@zylem/game-lib/events';
|
|
159
|
+
*
|
|
160
|
+
* // Subscribe
|
|
161
|
+
* const unsub = zylemEventBus.on('loading:progress', (e) => console.log(e));
|
|
162
|
+
*
|
|
163
|
+
* // Emit
|
|
164
|
+
* zylemEventBus.emit('loading:progress', { type: 'progress', progress: 0.5 });
|
|
165
|
+
*
|
|
166
|
+
* // Cleanup
|
|
167
|
+
* unsub();
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
declare const zylemEventBus: mitt.Emitter<ZylemEvents>;
|
|
171
|
+
|
|
172
|
+
export { type EntityConfigPayload, type EntityEvents, EventEmitterDelegate, type GameEvents, type GameLoadingPayload, type StageConfigPayload, type StageEvents, type StateDispatchPayload, type ZylemEvents, zylemEventBus };
|
package/dist/events.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as t,b as e}from"./chunk-YHEWKN7N.js";import"./chunk-QXVH6POE.js";export{t as EventEmitterDelegate,e as zylemEventBus};
|