@zylem/game-lib 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) 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 +628 -145
  5. package/dist/actions.js.map +1 -1
  6. package/dist/behavior/platformer-3d.d.ts +296 -0
  7. package/dist/behavior/platformer-3d.js +518 -0
  8. package/dist/behavior/platformer-3d.js.map +1 -0
  9. package/dist/behavior/ricochet-2d.d.ts +274 -0
  10. package/dist/behavior/ricochet-2d.js +394 -0
  11. package/dist/behavior/ricochet-2d.js.map +1 -0
  12. package/dist/behavior/screen-wrap.d.ts +86 -0
  13. package/dist/behavior/screen-wrap.js +195 -0
  14. package/dist/behavior/screen-wrap.js.map +1 -0
  15. package/dist/behavior/thruster.d.ts +10 -0
  16. package/dist/behavior/thruster.js +234 -0
  17. package/dist/behavior/thruster.js.map +1 -0
  18. package/dist/behavior/world-boundary-2d.d.ts +141 -0
  19. package/dist/behavior/world-boundary-2d.js +181 -0
  20. package/dist/behavior/world-boundary-2d.js.map +1 -0
  21. package/dist/behavior-descriptor-BWNWmIjv.d.ts +142 -0
  22. package/dist/{blueprints-Cq3Ko6_G.d.ts → blueprints-BWGz8fII.d.ts} +2 -2
  23. package/dist/camera-B5e4c78l.d.ts +468 -0
  24. package/dist/camera.d.ts +3 -2
  25. package/dist/camera.js +900 -211
  26. package/dist/camera.js.map +1 -1
  27. package/dist/composition-DrzFrbqI.d.ts +218 -0
  28. package/dist/{core-bO8TzV7u.d.ts → core-DAkskq6Y.d.ts} +60 -62
  29. package/dist/core.d.ts +10 -6
  30. package/dist/core.js +6896 -5020
  31. package/dist/core.js.map +1 -1
  32. package/dist/{entities-DvByhMGU.d.ts → entities-DC9ce_vx.d.ts} +113 -3
  33. package/dist/entities.d.ts +5 -3
  34. package/dist/entities.js +3727 -3167
  35. package/dist/entities.js.map +1 -1
  36. package/dist/entity-BpbZqg19.d.ts +1100 -0
  37. package/dist/global-change-Dc8uCKi2.d.ts +25 -0
  38. package/dist/main.d.ts +418 -15
  39. package/dist/main.js +11384 -8515
  40. package/dist/main.js.map +1 -1
  41. package/dist/{stage-types-Bd-KtcYT.d.ts → stage-types-BFsm3qsZ.d.ts} +205 -13
  42. package/dist/stage.d.ts +10 -7
  43. package/dist/stage.js +5311 -3880
  44. package/dist/stage.js.map +1 -1
  45. package/dist/thruster-DhRaJnoL.d.ts +172 -0
  46. package/dist/world-Be5m1XC1.d.ts +31 -0
  47. package/package.json +29 -13
  48. package/dist/behaviors.d.ts +0 -854
  49. package/dist/behaviors.js +0 -1209
  50. package/dist/behaviors.js.map +0 -1
  51. package/dist/camera-CeJPAgGg.d.ts +0 -116
  52. package/dist/moveable-B_vyA6cw.d.ts +0 -67
  53. package/dist/transformable-CUhvyuYO.d.ts +0 -67
  54. package/dist/world-C8tQ7Plj.d.ts +0 -774
@@ -1,23 +1,56 @@
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';
1
+ import { J as UpdateFunction, S as SetupFunction, Z as ZylemShader, I as GameEntity, K as DestroyFunction, L as SetupContext, U as UpdateContext, M as DestroyContext, N as BaseNode, O as LoadingEvent, P as GameEntityOptions, Q as StageEvents } from './entity-BpbZqg19.js';
2
2
  import * as bitecs from 'bitecs';
3
3
  import { defineSystem, IWorld } from 'bitecs';
4
- import { Scene, Color, Object3D, Vector3 } from 'three';
4
+ import { Scene, Color, Object3D, Vector3, BufferGeometry, Material } from 'three';
5
+ import { Z as ZylemWorld } from './world-Be5m1XC1.js';
5
6
  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 { Z as ZylemCamera, C as CameraManager, R as RendererManager, a as CameraDebugDelegate, b as CameraDebugState, c as CameraWrapper } from './camera-B5e4c78l.js';
7
8
  import { G as GameEntityInterface, B as BaseEntityInterface } from './entity-types-DAu8sGJH.js';
8
9
  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
+ 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, C as CONE_TYPE, j as ZylemCone, k as PYRAMID_TYPE, l as ZylemPyramid, m as CYLINDER_TYPE, n as ZylemCylinder, o as PILL_TYPE, p as ZylemPill } from './entities-DC9ce_vx.js';
11
+ import { B as BehaviorSystem, a as BehaviorSystemFactory } from './behavior-descriptor-BWNWmIjv.js';
12
+
13
+ type BasicTypes = number | string | boolean;
14
+ type BaseGlobals = Record<string, BasicTypes>;
15
+ type KeyboardMapping = Record<string, string[]>;
16
+ type MouseMapping = Record<string, string[]>;
17
+ interface GameInputPlayerConfig {
18
+ key?: KeyboardMapping;
19
+ mouse?: MouseMapping;
20
+ includeDefaults?: boolean;
21
+ }
22
+ interface GameInputConfig {
23
+ p1?: GameInputPlayerConfig;
24
+ p2?: GameInputPlayerConfig;
25
+ p3?: GameInputPlayerConfig;
26
+ p4?: GameInputPlayerConfig;
27
+ p5?: GameInputPlayerConfig;
28
+ p6?: GameInputPlayerConfig;
29
+ p7?: GameInputPlayerConfig;
30
+ p8?: GameInputPlayerConfig;
31
+ }
32
+ interface ZylemGameConfig<StageInterface, GameInterface, TGlobals extends BaseGlobals> {
33
+ id: string;
34
+ globals?: TGlobals;
35
+ stages?: StageInterface[];
36
+ update?: UpdateFunction<GameInterface>;
37
+ debug?: boolean;
38
+ time?: number;
39
+ input?: GameInputConfig;
40
+ }
10
41
 
11
42
  interface SceneState {
12
43
  backgroundColor: Color | string;
13
44
  backgroundImage: string | null;
14
- backgroundShader?: ZylemShaderObject | null;
45
+ backgroundShader?: ZylemShader | null;
15
46
  }
16
47
  declare class ZylemScene implements Entity<ZylemScene> {
17
48
  type: string;
18
49
  _setup?: SetupFunction<ZylemScene>;
19
50
  scene: Scene;
51
+ /** @deprecated Use cameraManager instead */
20
52
  zylemCamera: ZylemCamera;
53
+ cameraManager: CameraManager | null;
21
54
  containerElement: HTMLElement | null;
22
55
  update: LifecycleFunction<ZylemScene>;
23
56
  _collision?: ((entity: any, other: any, globals?: any) => void) | undefined;
@@ -28,21 +61,30 @@ declare class ZylemScene implements Entity<ZylemScene> {
28
61
  constructor(id: string, camera: ZylemCamera, state: SceneState);
29
62
  /**
30
63
  * 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
64
+ * Supports both GLSL (ShaderMaterial) and TSL (MeshBasicNodeMaterial) shaders
32
65
  */
33
66
  private setupBackgroundShader;
34
67
  setup(): void;
35
68
  destroy(): void;
36
69
  /**
37
- * Setup camera with the scene
70
+ * Setup camera with the scene.
71
+ * Supports both legacy single camera and CameraManager modes.
72
+ */
73
+ setupCamera(scene: Scene, camera: ZylemCamera, rendererManager?: RendererManager): void;
74
+ /**
75
+ * Setup with a CameraManager (multi-camera support).
76
+ */
77
+ setupCameraManager(scene: Scene, cameraManager: CameraManager, rendererManager: RendererManager): Promise<void>;
78
+ /**
79
+ * Add a camera (rig or direct) to the scene graph.
38
80
  */
39
- setupCamera(scene: Scene, camera: ZylemCamera): void;
81
+ private addCameraToScene;
40
82
  /**
41
83
  * Setup scene lighting
42
84
  */
43
85
  setupLighting(scene: Scene): void;
44
86
  /**
45
- * Update renderer size - delegates to camera
87
+ * Update renderer size - delegates to camera manager or camera
46
88
  */
47
89
  updateRenderer(width: number, height: number): void;
48
90
  /**
@@ -63,11 +105,97 @@ declare class ZylemScene implements Entity<ZylemScene> {
63
105
  */
64
106
  debugScene(): void;
65
107
  /**
66
- * Update skybox shader uniforms
108
+ * Update skybox shader uniforms (only applies to GLSL ShaderMaterial)
109
+ * TSL shaders use the time node which auto-updates
67
110
  */
68
111
  updateSkybox(delta: number): void;
69
112
  }
70
113
 
114
+ /**
115
+ * Configuration for batch key generation
116
+ */
117
+ interface BatchKeyConfig {
118
+ geometryType: string;
119
+ dimensions: Record<string, number>;
120
+ materialPath?: string | null;
121
+ shaderType?: 'standard' | 'custom';
122
+ colorHex?: number;
123
+ }
124
+ /**
125
+ * Manages instanced mesh batching for entities
126
+ */
127
+ declare class InstanceManager {
128
+ private batches;
129
+ private entityToBatch;
130
+ private scene;
131
+ /** Default initial capacity for new batches */
132
+ static DEFAULT_CAPACITY: number;
133
+ /** Factor to grow batch when full */
134
+ static GROWTH_FACTOR: number;
135
+ /**
136
+ * Set the scene to add instanced meshes to
137
+ */
138
+ setScene(scene: Object3D): void;
139
+ /**
140
+ * Generate a batch key from configuration
141
+ */
142
+ static generateBatchKey(config: BatchKeyConfig): string;
143
+ /**
144
+ * Register an entity with the instance manager
145
+ * @returns The instance index, or -1 if registration failed
146
+ */
147
+ register(entity: GameEntity<any>, geometry: BufferGeometry, material: Material, batchKey: string): number;
148
+ /**
149
+ * Unregister an entity from the instance manager
150
+ */
151
+ unregister(entity: GameEntity<any>): void;
152
+ /**
153
+ * Mark an entity's transform as dirty (needs syncing)
154
+ */
155
+ markDirty(entity: GameEntity<any>): void;
156
+ /**
157
+ * Update all dirty instance transforms
158
+ * Call this once per frame
159
+ */
160
+ /**
161
+ * Update all active instance transforms
162
+ * Call this once per frame
163
+ */
164
+ update(): void;
165
+ private updateInstanceMatrix;
166
+ /**
167
+ * Get batch info for an entity
168
+ */
169
+ getBatchInfo(entity: GameEntity<any>): {
170
+ batchKey: string;
171
+ instanceId: number;
172
+ } | null;
173
+ /**
174
+ * Get statistics about current batching
175
+ */
176
+ getStats(): {
177
+ batchCount: number;
178
+ totalInstances: number;
179
+ batches: {
180
+ key: string;
181
+ count: number;
182
+ capacity: number;
183
+ }[];
184
+ };
185
+ /**
186
+ * Dispose all batches and release resources
187
+ */
188
+ dispose(): void;
189
+ /**
190
+ * Create a new batch group
191
+ */
192
+ private createBatch;
193
+ /**
194
+ * Grow a batch's capacity
195
+ */
196
+ private growBatch;
197
+ }
198
+
71
199
  /**
72
200
  * Provides BaseNode-like lifecycle without ECS/children. Consumers implement
73
201
  * the protected hooks and may assign public setup/update/destroy callbacks.
@@ -165,6 +293,7 @@ declare class ZylemStage extends LifeCycleBase<ZylemStage> {
165
293
  gravity: Vector3;
166
294
  world: ZylemWorld | null;
167
295
  scene: ZylemScene | null;
296
+ instanceManager: InstanceManager | null;
168
297
  children: Array<BaseNode>;
169
298
  _childrenMap: Map<number, BaseNode>;
170
299
  _removalMap: Map<number, BaseNode>;
@@ -184,7 +313,12 @@ declare class ZylemStage extends LifeCycleBase<ZylemStage> {
184
313
  uuid: string;
185
314
  wrapperRef: Stage | null;
186
315
  camera?: CameraWrapper;
316
+ cameras: CameraWrapper[];
187
317
  cameraRef?: ZylemCamera | null;
318
+ /** Camera manager for multi-camera support */
319
+ cameraManagerRef: CameraManager | null;
320
+ /** Shared renderer manager (injected by the game) */
321
+ rendererManager: RendererManager | null;
188
322
  private cameraDelegate;
189
323
  private loadingDelegate;
190
324
  private entityModelDelegate;
@@ -203,7 +337,7 @@ declare class ZylemStage extends LifeCycleBase<ZylemStage> {
203
337
  * @param id DOM element id for the renderer container
204
338
  * @param camera Optional camera override
205
339
  */
206
- load(id: string, camera?: ZylemCamera | null): Promise<void>;
340
+ load(id: string, camera?: ZylemCamera | null, rendererManager?: RendererManager | null): Promise<void>;
207
341
  /**
208
342
  * Generator that yields between entity loads for real-time progress updates.
209
343
  */
@@ -226,6 +360,11 @@ declare class ZylemStage extends LifeCycleBase<ZylemStage> {
226
360
  * Safe to call only after `load` when scene/world exist.
227
361
  */
228
362
  spawnEntity(child: BaseNode): Promise<void>;
363
+ /**
364
+ * Try to register an entity for instanced rendering.
365
+ * Batching is enabled by default unless explicitly disabled with batched: false.
366
+ */
367
+ private tryRegisterInstance;
229
368
  buildEntityState(child: BaseNode): Partial<BaseEntityInterface>;
230
369
  /** Add the entity to internal maps and notify listeners. */
231
370
  addEntityToStage(entity: BaseNode): void;
@@ -253,6 +392,22 @@ declare class ZylemStage extends LifeCycleBase<ZylemStage> {
253
392
  /** Get an entity by its name; returns null if not found. */
254
393
  getEntityByName(name: string): BaseNode<any, any> | null;
255
394
  logMissingEntities(): void;
395
+ /**
396
+ * Add a camera to this stage's camera manager.
397
+ */
398
+ addCamera(camera: ZylemCamera, name?: string): string | null;
399
+ /**
400
+ * Remove a camera from this stage's camera manager.
401
+ */
402
+ removeCamera(nameOrRef: string | ZylemCamera): boolean;
403
+ /**
404
+ * Set the active camera by name or reference.
405
+ */
406
+ setActiveCamera(nameOrRef: string | ZylemCamera): boolean;
407
+ /**
408
+ * Get a camera by name from the camera manager.
409
+ */
410
+ getCamera(name: string): ZylemCamera | null;
256
411
  /** Resize renderer viewport. */
257
412
  resize(width: number, height: number): void;
258
413
  /**
@@ -292,6 +447,10 @@ interface EntityTypeMap {
292
447
  [ZONE_TYPE]: ZylemZone;
293
448
  [ACTOR_TYPE]: ZylemActor;
294
449
  [DISK_TYPE]: ZylemDisk;
450
+ [CONE_TYPE]: ZylemCone;
451
+ [PYRAMID_TYPE]: ZylemPyramid;
452
+ [CYLINDER_TYPE]: ZylemCylinder;
453
+ [PILL_TYPE]: ZylemPill;
295
454
  }
296
455
 
297
456
  type NodeLike = {
@@ -308,8 +467,23 @@ declare class Stage {
308
467
  private destroyCallbacks;
309
468
  private pendingLoadingCallbacks;
310
469
  private eventDelegate;
470
+ /** Per-stage input configuration overrides. Merged with game-level defaults on stage load. */
471
+ inputConfig: GameInputConfig | null;
472
+ /**
473
+ * Callback set by the game to trigger input reconfiguration
474
+ * when this stage's input config changes at runtime.
475
+ * @internal
476
+ */
477
+ onInputConfigChanged: (() => void) | null;
311
478
  constructor(options: StageOptions);
312
- load(id: string, camera?: ZylemCamera | CameraWrapper | null): Promise<void>;
479
+ /**
480
+ * Set composable input configuration for this stage.
481
+ * Multiple configs are deep-merged (later configs win on key conflicts).
482
+ * If this stage is currently active, the change takes effect immediately.
483
+ * @example stage.setInputConfiguration(useArrowsForAxes('p1'), useWASDForDirections('p2'));
484
+ */
485
+ setInputConfiguration(...configs: GameInputConfig[]): this;
486
+ load(id: string, camera?: ZylemCamera | CameraWrapper | null, rendererManager?: RendererManager | null): Promise<void>;
313
487
  private applyLifecycleCallbacks;
314
488
  addEntities(entities: BaseNode[]): Promise<void>;
315
489
  add(...inputs: Array<EntityInput>): void;
@@ -328,6 +502,24 @@ declare class Stage {
328
502
  * @example stage.getEntityByName('scoreText', TEXT_TYPE)
329
503
  */
330
504
  getEntityByName<T extends symbol | void = void>(name: string, type?: T): T extends keyof EntityTypeMap ? EntityTypeMap[T] | undefined : BaseNode | undefined;
505
+ /**
506
+ * Add a camera to this stage.
507
+ * @param camera The ZylemCamera or CameraWrapper to add
508
+ * @param name Optional name for lookup
509
+ */
510
+ addCamera(camera: ZylemCamera | CameraWrapper, name?: string): string | null;
511
+ /**
512
+ * Remove a camera from this stage by name or reference.
513
+ */
514
+ removeCamera(nameOrRef: string | ZylemCamera | CameraWrapper): boolean;
515
+ /**
516
+ * Set the active camera by name or reference.
517
+ */
518
+ setActiveCamera(nameOrRef: string | ZylemCamera | CameraWrapper): boolean;
519
+ /**
520
+ * Get a camera by name from the camera manager.
521
+ */
522
+ getCamera(name: string): ZylemCamera | null;
331
523
  /**
332
524
  * Dispatch an event from the stage.
333
525
  * Events are emitted both locally and to the global event bus.
@@ -372,4 +564,4 @@ interface StageInterface {
372
564
  state: StageStateInterface;
373
565
  }
374
566
 
375
- export { type StageStateInterface as S, type StageOptions as a, Stage as b, createStage as c, createDisk as d, type StageInterface as e };
567
+ export { type BaseGlobals as B, type GameInputConfig as G, type StageStateInterface as S, type ZylemGameConfig as Z, type StageOptions as a, Stage as b, createStage as c, createDisk as d, type StageInterface as e };
package/dist/stage.d.ts CHANGED
@@ -1,16 +1,19 @@
1
- import { S as StageStateInterface } from './stage-types-Bd-KtcYT.js';
2
- export { a as StageOptions, c as createStage } from './stage-types-Bd-KtcYT.js';
3
- export { S as StageBlueprint, e as entitySpawner } from './blueprints-Cq3Ko6_G.js';
4
- import './world-C8tQ7Plj.js';
1
+ import { S as StageStateInterface } from './stage-types-BFsm3qsZ.js';
2
+ export { a as StageOptions, c as createStage } from './stage-types-BFsm3qsZ.js';
3
+ export { S as StageBlueprint, e as entitySpawner } from './blueprints-BWGz8fII.js';
4
+ import './entity-BpbZqg19.js';
5
5
  import 'three';
6
6
  import '@dimforge/rapier3d-compat';
7
- import './entity-Bq_eNEDI.js';
8
7
  import 'bitecs';
9
8
  import 'mitt';
10
- import './camera-CeJPAgGg.js';
9
+ import './behavior-descriptor-BWNWmIjv.js';
10
+ import './world-Be5m1XC1.js';
11
+ import './entity-Bq_eNEDI.js';
12
+ import './camera-B5e4c78l.js';
13
+ import 'three/webgpu';
11
14
  import 'three/examples/jsm/postprocessing/EffectComposer.js';
12
15
  import './entity-types-DAu8sGJH.js';
13
- import './entities-DvByhMGU.js';
16
+ import './entities-DC9ce_vx.js';
14
17
  import '@sinclair/typebox';
15
18
 
16
19
  /**