@zylem/game-lib 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -16
  3. package/dist/actions.d.ts +30 -21
  4. package/dist/actions.js +793 -146
  5. package/dist/actions.js.map +1 -1
  6. package/dist/behavior/jumper-2d.d.ts +114 -0
  7. package/dist/behavior/jumper-2d.js +711 -0
  8. package/dist/behavior/jumper-2d.js.map +1 -0
  9. package/dist/behavior/platformer-3d.d.ts +296 -0
  10. package/dist/behavior/platformer-3d.js +761 -0
  11. package/dist/behavior/platformer-3d.js.map +1 -0
  12. package/dist/behavior/ricochet-2d.d.ts +275 -0
  13. package/dist/behavior/ricochet-2d.js +425 -0
  14. package/dist/behavior/ricochet-2d.js.map +1 -0
  15. package/dist/behavior/ricochet-3d.d.ts +117 -0
  16. package/dist/behavior/ricochet-3d.js +443 -0
  17. package/dist/behavior/ricochet-3d.js.map +1 -0
  18. package/dist/behavior/screen-visibility.d.ts +79 -0
  19. package/dist/behavior/screen-visibility.js +358 -0
  20. package/dist/behavior/screen-visibility.js.map +1 -0
  21. package/dist/behavior/screen-wrap.d.ts +87 -0
  22. package/dist/behavior/screen-wrap.js +246 -0
  23. package/dist/behavior/screen-wrap.js.map +1 -0
  24. package/dist/behavior/shooter-2d.d.ts +79 -0
  25. package/dist/behavior/shooter-2d.js +180 -0
  26. package/dist/behavior/shooter-2d.js.map +1 -0
  27. package/dist/behavior/thruster.d.ts +11 -0
  28. package/dist/behavior/thruster.js +292 -0
  29. package/dist/behavior/thruster.js.map +1 -0
  30. package/dist/behavior/top-down-movement.d.ts +56 -0
  31. package/dist/behavior/top-down-movement.js +125 -0
  32. package/dist/behavior/top-down-movement.js.map +1 -0
  33. package/dist/behavior/world-boundary-2d.d.ts +142 -0
  34. package/dist/behavior/world-boundary-2d.js +235 -0
  35. package/dist/behavior/world-boundary-2d.js.map +1 -0
  36. package/dist/behavior/world-boundary-3d.d.ts +76 -0
  37. package/dist/behavior/world-boundary-3d.js +274 -0
  38. package/dist/behavior/world-boundary-3d.js.map +1 -0
  39. package/dist/behavior-descriptor-BXnVR8Ki.d.ts +159 -0
  40. package/dist/{blueprints-Cq3Ko6_G.d.ts → blueprints-DmbK2dki.d.ts} +2 -2
  41. package/dist/camera-4XO5gbQH.d.ts +905 -0
  42. package/dist/camera.d.ts +3 -2
  43. package/dist/camera.js +1653 -377
  44. package/dist/camera.js.map +1 -1
  45. package/dist/composition-BASvMKrW.d.ts +218 -0
  46. package/dist/{core-bO8TzV7u.d.ts → core-CARRaS55.d.ts} +110 -69
  47. package/dist/core.d.ts +11 -6
  48. package/dist/core.js +10766 -5626
  49. package/dist/core.js.map +1 -1
  50. package/dist/{entities-DvByhMGU.d.ts → entities-ChFirVL9.d.ts} +133 -29
  51. package/dist/entities.d.ts +5 -3
  52. package/dist/entities.js +4679 -3202
  53. package/dist/entities.js.map +1 -1
  54. package/dist/entity-vj-HTjzU.d.ts +1169 -0
  55. package/dist/global-change-2JvMaz44.d.ts +25 -0
  56. package/dist/main.d.ts +1118 -16
  57. package/dist/main.js +17538 -8499
  58. package/dist/main.js.map +1 -1
  59. package/dist/physics-pose-DCc4oE44.d.ts +25 -0
  60. package/dist/physics-protocol-BDD3P5W2.d.ts +200 -0
  61. package/dist/physics-worker.d.ts +21 -0
  62. package/dist/physics-worker.js +306 -0
  63. package/dist/physics-worker.js.map +1 -0
  64. package/dist/physics.d.ts +205 -0
  65. package/dist/physics.js +577 -0
  66. package/dist/physics.js.map +1 -0
  67. package/dist/stage-types-C19IhuzA.d.ts +731 -0
  68. package/dist/stage.d.ts +11 -7
  69. package/dist/stage.js +8024 -3852
  70. package/dist/stage.js.map +1 -1
  71. package/dist/sync-state-machine-CZyspBpj.d.ts +16 -0
  72. package/dist/thruster-23lzoPZd.d.ts +180 -0
  73. package/dist/world-DfgxoNMt.d.ts +105 -0
  74. package/package.json +53 -13
  75. package/dist/behaviors.d.ts +0 -854
  76. package/dist/behaviors.js +0 -1209
  77. package/dist/behaviors.js.map +0 -1
  78. package/dist/camera-CeJPAgGg.d.ts +0 -116
  79. package/dist/moveable-B_vyA6cw.d.ts +0 -67
  80. package/dist/stage-types-Bd-KtcYT.d.ts +0 -375
  81. package/dist/transformable-CUhvyuYO.d.ts +0 -67
  82. package/dist/world-C8tQ7Plj.d.ts +0 -774
@@ -1,375 +0,0 @@
1
- import { S as SetupFunction, Z as ZylemShaderObject, G as GameEntity, U as UpdateFunction, D as DestroyFunction, a as SetupContext, b as UpdateContext, c as DestroyContext, d as ZylemWorld, B as BaseNode, L as LoadingEvent, e as BehaviorSystem, f as BehaviorSystemFactory, g as GameEntityOptions, h as StageEvents } from './world-C8tQ7Plj.js';
2
- import * as bitecs from 'bitecs';
3
- import { defineSystem, IWorld } from 'bitecs';
4
- import { Scene, Color, Object3D, Vector3 } from 'three';
5
- import { E as Entity, L as LifecycleFunction, S as StageEntity } from './entity-Bq_eNEDI.js';
6
- import { Z as ZylemCamera, C as CameraDebugDelegate, a as CameraDebugState, b as CameraWrapper } from './camera-CeJPAgGg.js';
7
- import { G as GameEntityInterface, B as BaseEntityInterface } from './entity-types-DAu8sGJH.js';
8
- import RAPIER__default from '@dimforge/rapier3d-compat';
9
- import { S as SPRITE_TYPE, Z as ZylemSprite, a as SPHERE_TYPE, b as ZylemSphere, R as RECT_TYPE, c as ZylemRect, T as TEXT_TYPE, d as ZylemText, B as BOX_TYPE, e as ZylemBox, P as PLANE_TYPE, f as ZylemPlane, g as ZONE_TYPE, h as ZylemZone, A as ACTOR_TYPE, i as ZylemActor } from './entities-DvByhMGU.js';
10
-
11
- interface SceneState {
12
- backgroundColor: Color | string;
13
- backgroundImage: string | null;
14
- backgroundShader?: ZylemShaderObject | null;
15
- }
16
- declare class ZylemScene implements Entity<ZylemScene> {
17
- type: string;
18
- _setup?: SetupFunction<ZylemScene>;
19
- scene: Scene;
20
- zylemCamera: ZylemCamera;
21
- containerElement: HTMLElement | null;
22
- update: LifecycleFunction<ZylemScene>;
23
- _collision?: ((entity: any, other: any, globals?: any) => void) | undefined;
24
- _destroy?: ((globals?: any) => void) | undefined;
25
- name?: string | undefined;
26
- tag?: Set<string> | undefined;
27
- private skyboxMaterial;
28
- constructor(id: string, camera: ZylemCamera, state: SceneState);
29
- /**
30
- * Create a large inverted box with the shader for skybox effect
31
- * Uses the pos.xyww trick to ensure skybox is always at maximum depth
32
- */
33
- private setupBackgroundShader;
34
- setup(): void;
35
- destroy(): void;
36
- /**
37
- * Setup camera with the scene
38
- */
39
- setupCamera(scene: Scene, camera: ZylemCamera): void;
40
- /**
41
- * Setup scene lighting
42
- */
43
- setupLighting(scene: Scene): void;
44
- /**
45
- * Update renderer size - delegates to camera
46
- */
47
- updateRenderer(width: number, height: number): void;
48
- /**
49
- * Add object to scene
50
- */
51
- add(object: Object3D, position?: Vector3): void;
52
- /**
53
- * Add game entity to scene
54
- */
55
- addEntity(entity: GameEntity<any>): void;
56
- /**
57
- * Add an entity's group or mesh to the scene (for late-loaded models).
58
- * Uses entity's current body position if physics is active.
59
- */
60
- addEntityGroup(entity: GameEntity<any>): void;
61
- /**
62
- * Add debug helpers to scene
63
- */
64
- debugScene(): void;
65
- /**
66
- * Update skybox shader uniforms
67
- */
68
- updateSkybox(delta: number): void;
69
- }
70
-
71
- /**
72
- * Provides BaseNode-like lifecycle without ECS/children. Consumers implement
73
- * the protected hooks and may assign public setup/update/destroy callbacks.
74
- */
75
- declare abstract class LifeCycleBase<TSelf> {
76
- update: UpdateFunction<TSelf>;
77
- setup: SetupFunction<TSelf>;
78
- destroy: DestroyFunction<TSelf>;
79
- protected abstract _setup(context: SetupContext<TSelf>): void;
80
- protected abstract _update(context: UpdateContext<TSelf>): void;
81
- protected abstract _destroy(context: DestroyContext<TSelf>): void;
82
- nodeSetup(context: SetupContext<TSelf>): void;
83
- nodeUpdate(context: UpdateContext<TSelf>): void;
84
- nodeDestroy(context: DestroyContext<TSelf>): void;
85
- }
86
-
87
- type StageSystem = {
88
- _childrenMap: Map<number, StageEntity & {
89
- body: RAPIER__default.RigidBody;
90
- }>;
91
- };
92
- type TransformSystemResult = {
93
- system: ReturnType<typeof defineSystem>;
94
- destroy: (world: IWorld) => void;
95
- };
96
- declare function createTransformSystem(stage: StageSystem): TransformSystemResult;
97
-
98
- type AddEntityFactory = (params: {
99
- position: Vector3;
100
- normal?: Vector3;
101
- }) => Promise<any> | any;
102
- interface StageDebugDelegateOptions {
103
- maxRayDistance?: number;
104
- addEntityFactory?: AddEntityFactory | null;
105
- }
106
- declare class StageDebugDelegate {
107
- private stage;
108
- private options;
109
- private mouseNdc;
110
- private raycaster;
111
- private isMouseDown;
112
- private disposeFns;
113
- private debugCursor;
114
- private debugLines;
115
- constructor(stage: ZylemStage, options?: StageDebugDelegateOptions);
116
- private initDebugVisuals;
117
- private disposeDebugVisuals;
118
- update(): void;
119
- dispose(): void;
120
- private handleActionOnHit;
121
- private attachDomListeners;
122
- }
123
-
124
- /**
125
- * Debug delegate that bridges the stage's entity map and debug state to the camera.
126
- */
127
- declare class StageCameraDebugDelegate implements CameraDebugDelegate {
128
- private stage;
129
- constructor(stage: ZylemStage);
130
- subscribe(listener: (state: CameraDebugState) => void): () => void;
131
- resolveTarget(uuid: string): Object3D | null;
132
- private snapshot;
133
- }
134
-
135
- interface ZylemStageConfig {
136
- inputs: Record<string, string[]>;
137
- backgroundColor: Color | string;
138
- backgroundImage: string | null;
139
- backgroundShader: any | null;
140
- gravity: Vector3;
141
- variables: Record<string, any>;
142
- stageRef?: Stage;
143
- }
144
- type NodeLike$1 = {
145
- create: Function;
146
- };
147
- type StageEntityInput = NodeLike$1 | Promise<any> | (() => NodeLike$1 | Promise<any>);
148
- type StageOptionItem = Partial<ZylemStageConfig> | CameraWrapper | StageEntityInput;
149
- type StageOptions = [] | [Partial<ZylemStageConfig>, ...StageOptionItem[]];
150
- type StageState = ZylemStageConfig & {
151
- entities: GameEntityInterface[];
152
- };
153
- /**
154
- * ZylemStage orchestrates scene, physics world, entities, and lifecycle.
155
- *
156
- * Responsibilities:
157
- * - Manage stage configuration (background, inputs, gravity, variables)
158
- * - Initialize and own `ZylemScene` and `ZylemWorld`
159
- * - Spawn, track, and remove entities; emit entity-added events
160
- * - Drive per-frame updates and transform system
161
- */
162
- declare class ZylemStage extends LifeCycleBase<ZylemStage> {
163
- type: string;
164
- state: StageState;
165
- gravity: Vector3;
166
- world: ZylemWorld | null;
167
- scene: ZylemScene | null;
168
- children: Array<BaseNode>;
169
- _childrenMap: Map<number, BaseNode>;
170
- _removalMap: Map<number, BaseNode>;
171
- private pendingEntities;
172
- private pendingPromises;
173
- private isLoaded;
174
- _debugMap: Map<string, BaseNode>;
175
- private entityAddedHandlers;
176
- ecs: bitecs.IWorld;
177
- testSystem: any;
178
- transformSystem: ReturnType<typeof createTransformSystem> | null;
179
- private behaviorSystems;
180
- private registeredSystemKeys;
181
- debugDelegate: StageDebugDelegate | null;
182
- cameraDebugDelegate: StageCameraDebugDelegate | null;
183
- private debugStateUnsubscribe;
184
- uuid: string;
185
- wrapperRef: Stage | null;
186
- camera?: CameraWrapper;
187
- cameraRef?: ZylemCamera | null;
188
- private cameraDelegate;
189
- private loadingDelegate;
190
- private entityModelDelegate;
191
- /**
192
- * Create a new stage.
193
- * @param options Stage options: partial config, camera, and initial entities or factories
194
- */
195
- constructor(options?: StageOptions);
196
- private handleEntityImmediatelyOrQueue;
197
- private handlePromiseWithSpawnOnResolve;
198
- private saveState;
199
- private setState;
200
- /**
201
- * Load and initialize the stage's scene and world.
202
- * Uses generator pattern to yield control to event loop for real-time progress.
203
- * @param id DOM element id for the renderer container
204
- * @param camera Optional camera override
205
- */
206
- load(id: string, camera?: ZylemCamera | null): Promise<void>;
207
- /**
208
- * Generator that yields between entity loads for real-time progress updates.
209
- */
210
- private entityLoadGenerator;
211
- /**
212
- * Runs the entity load generator, yielding to the event loop between loads.
213
- * This allows the browser to process events and update the UI in real-time.
214
- */
215
- private runEntityLoadGenerator;
216
- protected _setup(params: SetupContext<ZylemStage>): void;
217
- private updateDebugDelegate;
218
- protected _update(params: UpdateContext<ZylemStage>): void;
219
- outOfLoop(): void;
220
- /** Update debug overlays and helpers if enabled. */
221
- debugUpdate(): void;
222
- /** Cleanup owned resources when the stage is destroyed. */
223
- protected _destroy(params: DestroyContext<ZylemStage>): void;
224
- /**
225
- * Create, register, and add an entity to the scene/world.
226
- * Safe to call only after `load` when scene/world exist.
227
- */
228
- spawnEntity(child: BaseNode): Promise<void>;
229
- buildEntityState(child: BaseNode): Partial<BaseEntityInterface>;
230
- /** Add the entity to internal maps and notify listeners. */
231
- addEntityToStage(entity: BaseNode): void;
232
- /**
233
- * Subscribe to entity-added events.
234
- * @param callback Invoked for each entity when added
235
- * @param options.replayExisting If true and stage already loaded, replays existing entities
236
- * @returns Unsubscribe function
237
- */
238
- onEntityAdded(callback: (entity: BaseNode) => void, options?: {
239
- replayExisting?: boolean;
240
- }): () => void;
241
- onLoading(callback: (event: LoadingEvent) => void): () => void;
242
- /**
243
- * Register an ECS behavior system to run each frame.
244
- * @param systemOrFactory A BehaviorSystem instance or factory function
245
- * @returns this for chaining
246
- */
247
- registerSystem(systemOrFactory: BehaviorSystem | BehaviorSystemFactory): this;
248
- /**
249
- * Remove an entity and its resources by its UUID.
250
- * @returns true if removed, false if not found or stage not ready
251
- */
252
- removeEntityByUuid(uuid: string): boolean;
253
- /** Get an entity by its name; returns null if not found. */
254
- getEntityByName(name: string): BaseNode<any, any> | null;
255
- logMissingEntities(): void;
256
- /** Resize renderer viewport. */
257
- resize(width: number, height: number): void;
258
- /**
259
- * Enqueue items to be spawned. Items can be:
260
- * - BaseNode instances (immediate or deferred until load)
261
- * - Factory functions returning BaseNode or Promise<BaseNode>
262
- * - Promises resolving to BaseNode
263
- */
264
- enqueue(...items: StageEntityInput[]): void;
265
- }
266
-
267
- type ZylemDiskOptions = GameEntityOptions & {
268
- innerRadius?: number;
269
- outerRadius?: number;
270
- thetaSegments?: number;
271
- };
272
- declare const DISK_TYPE: unique symbol;
273
- declare class ZylemDisk extends GameEntity<ZylemDiskOptions> {
274
- static type: symbol;
275
- constructor(options?: ZylemDiskOptions);
276
- buildInfo(): Record<string, any>;
277
- }
278
- type DiskOptions = BaseNode | Partial<ZylemDiskOptions>;
279
- declare function createDisk(...args: Array<DiskOptions>): ZylemDisk;
280
-
281
- /**
282
- * Maps entity type symbols to their class types.
283
- * Used by getEntityByName to infer return types.
284
- */
285
- interface EntityTypeMap {
286
- [SPRITE_TYPE]: ZylemSprite;
287
- [SPHERE_TYPE]: ZylemSphere;
288
- [RECT_TYPE]: ZylemRect;
289
- [TEXT_TYPE]: ZylemText;
290
- [BOX_TYPE]: ZylemBox;
291
- [PLANE_TYPE]: ZylemPlane;
292
- [ZONE_TYPE]: ZylemZone;
293
- [ACTOR_TYPE]: ZylemActor;
294
- [DISK_TYPE]: ZylemDisk;
295
- }
296
-
297
- type NodeLike = {
298
- create: Function;
299
- };
300
- type AnyNode = NodeLike | Promise<NodeLike>;
301
- type EntityInput = AnyNode | (() => AnyNode) | (() => Promise<any>);
302
- declare class Stage {
303
- wrappedStage: ZylemStage | null;
304
- options: StageOptionItem[];
305
- private _pendingEntities;
306
- private setupCallbacks;
307
- private updateCallbacks;
308
- private destroyCallbacks;
309
- private pendingLoadingCallbacks;
310
- private eventDelegate;
311
- constructor(options: StageOptions);
312
- load(id: string, camera?: ZylemCamera | CameraWrapper | null): Promise<void>;
313
- private applyLifecycleCallbacks;
314
- addEntities(entities: BaseNode[]): Promise<void>;
315
- add(...inputs: Array<EntityInput>): void;
316
- private addToBlueprints;
317
- private addToStage;
318
- start(params: SetupContext<ZylemStage>): void;
319
- onUpdate(...callbacks: UpdateFunction<ZylemStage>[]): this;
320
- onSetup(...callbacks: SetupFunction<ZylemStage>[]): this;
321
- onDestroy(...callbacks: DestroyFunction<ZylemStage>[]): this;
322
- onLoading(callback: (event: LoadingEvent) => void): () => void;
323
- /**
324
- * Find an entity by name on the current stage.
325
- * @param name The name of the entity to find
326
- * @param type Optional type symbol for type inference (e.g., TEXT_TYPE, SPRITE_TYPE)
327
- * @returns The entity if found, or undefined
328
- * @example stage.getEntityByName('scoreText', TEXT_TYPE)
329
- */
330
- getEntityByName<T extends symbol | void = void>(name: string, type?: T): T extends keyof EntityTypeMap ? EntityTypeMap[T] | undefined : BaseNode | undefined;
331
- /**
332
- * Dispatch an event from the stage.
333
- * Events are emitted both locally and to the global event bus.
334
- */
335
- dispatch<K extends keyof StageEvents>(event: K, payload: StageEvents[K]): void;
336
- /**
337
- * Listen for events on this stage instance.
338
- * @returns Unsubscribe function
339
- */
340
- listen<K extends keyof StageEvents>(event: K, handler: (payload: StageEvents[K]) => void): () => void;
341
- /**
342
- * Clean up stage resources including event subscriptions.
343
- */
344
- dispose(): void;
345
- }
346
- /**
347
- * Create a stage with optional camera
348
- */
349
- declare function createStage(...options: StageOptions): Stage;
350
-
351
- /**
352
- * Stage state interface - minimal to prevent circular dependencies
353
- */
354
- interface StageStateInterface {
355
- backgroundColor: Color;
356
- backgroundImage: string | null;
357
- inputs: {
358
- p1: string[];
359
- p2: string[];
360
- };
361
- variables: Record<string, any>;
362
- gravity: Vector3;
363
- entities: Partial<BaseEntityInterface>[];
364
- stageRef?: any;
365
- }
366
- /**
367
- * Minimal stage interface to break circular dependencies
368
- */
369
- interface StageInterface {
370
- uuid: string;
371
- children: any[];
372
- state: StageStateInterface;
373
- }
374
-
375
- export { type StageStateInterface as S, type StageOptions as a, Stage as b, createStage as c, createDisk as d, type StageInterface as e };
@@ -1,67 +0,0 @@
1
- import { E as EntityWithBody, M as MoveableEntity } from './moveable-B_vyA6cw.js';
2
- import { Vector3 } from 'three';
3
- import { RigidBody } from '@dimforge/rapier3d-compat';
4
-
5
- interface RotatableEntity {
6
- body: RigidBody | null;
7
- group: any;
8
- }
9
- /**
10
- * Rotate an entity in the direction of a movement vector
11
- */
12
- declare function rotateInDirection(entity: RotatableEntity, moveVector: Vector3): void;
13
- /**
14
- * Rotatable entity API with bound methods
15
- */
16
- interface RotatableEntityAPI extends RotatableEntity {
17
- rotateInDirection(moveVector: Vector3): void;
18
- rotateYEuler(amount: number): void;
19
- rotateEuler(rotation: Vector3): void;
20
- rotateY(delta: number): void;
21
- rotateZ(delta: number): void;
22
- setRotationY(y: number): void;
23
- setRotationX(x: number): void;
24
- setRotationZ(z: number): void;
25
- setRotationDegrees(x: number, y: number, z: number): void;
26
- setRotationDegreesY(y: number): void;
27
- setRotationDegreesX(x: number): void;
28
- setRotationDegreesZ(z: number): void;
29
- setRotation(x: number, y: number, z: number): void;
30
- getRotation(): any;
31
- }
32
- /**
33
- * Class decorator to enhance an entity with rotatable methods
34
- */
35
- declare function rotatable<T extends {
36
- new (...args: any[]): RotatableEntity;
37
- }>(constructor: T): {
38
- new (...args: any[]): {
39
- rotateInDirection(moveVector: Vector3): void;
40
- rotateYEuler(amount: number): void;
41
- rotateEuler(rotation: Vector3): void;
42
- rotateY(delta: number): void;
43
- rotateZ(delta: number): void;
44
- setRotationY(y: number): void;
45
- setRotationX(x: number): void;
46
- setRotationZ(z: number): void;
47
- setRotationDegrees(x: number, y: number, z: number): void;
48
- setRotationDegreesY(y: number): void;
49
- setRotationDegreesX(x: number): void;
50
- setRotationDegreesZ(z: number): void;
51
- setRotation(x: number, y: number, z: number): void;
52
- getRotation(): any;
53
- body: RigidBody | null;
54
- group: any;
55
- };
56
- } & T;
57
- /**
58
- * Enhance an entity instance with rotatable methods
59
- */
60
- declare function makeRotatable<T extends RotatableEntity>(entity: T): T & RotatableEntityAPI;
61
-
62
- /**
63
- * Enhance an entity with both movement and rotation capabilities.
64
- */
65
- declare function makeTransformable<T extends RotatableEntity & EntityWithBody>(entity: T): T & MoveableEntity & RotatableEntityAPI;
66
-
67
- export { makeTransformable as a, rotateInDirection as b, makeRotatable as m, rotatable as r };