@zylem/game-lib 0.6.0 → 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/README.md +9 -16
  2. package/dist/actions.d.ts +30 -21
  3. package/dist/actions.js +628 -145
  4. package/dist/actions.js.map +1 -1
  5. package/dist/behavior/platformer-3d.d.ts +296 -0
  6. package/dist/behavior/platformer-3d.js +518 -0
  7. package/dist/behavior/platformer-3d.js.map +1 -0
  8. package/dist/behavior/ricochet-2d.d.ts +274 -0
  9. package/dist/behavior/ricochet-2d.js +394 -0
  10. package/dist/behavior/ricochet-2d.js.map +1 -0
  11. package/dist/behavior/screen-wrap.d.ts +86 -0
  12. package/dist/behavior/screen-wrap.js +195 -0
  13. package/dist/behavior/screen-wrap.js.map +1 -0
  14. package/dist/behavior/thruster.d.ts +10 -0
  15. package/dist/behavior/thruster.js +234 -0
  16. package/dist/behavior/thruster.js.map +1 -0
  17. package/dist/behavior/world-boundary-2d.d.ts +141 -0
  18. package/dist/behavior/world-boundary-2d.js +181 -0
  19. package/dist/behavior/world-boundary-2d.js.map +1 -0
  20. package/dist/behavior-descriptor-BWNWmIjv.d.ts +142 -0
  21. package/dist/{blueprints-BOCc3Wve.d.ts → blueprints-BWGz8fII.d.ts} +2 -2
  22. package/dist/camera-B5e4c78l.d.ts +468 -0
  23. package/dist/camera.d.ts +3 -2
  24. package/dist/camera.js +962 -166
  25. package/dist/camera.js.map +1 -1
  26. package/dist/composition-DrzFrbqI.d.ts +218 -0
  27. package/dist/{core-CZhozNRH.d.ts → core-DAkskq6Y.d.ts} +97 -65
  28. package/dist/core.d.ts +12 -6
  29. package/dist/core.js +4449 -1052
  30. package/dist/core.js.map +1 -1
  31. package/dist/{entities-BAxfJOkk.d.ts → entities-DC9ce_vx.d.ts} +154 -45
  32. package/dist/entities.d.ts +5 -2
  33. package/dist/entities.js +2505 -722
  34. package/dist/entities.js.map +1 -1
  35. package/dist/entity-BpbZqg19.d.ts +1100 -0
  36. package/dist/entity-types-DAu8sGJH.d.ts +26 -0
  37. package/dist/global-change-Dc8uCKi2.d.ts +25 -0
  38. package/dist/main.d.ts +472 -29
  39. package/dist/main.js +11877 -6124
  40. package/dist/main.js.map +1 -1
  41. package/dist/{stage-types-CD21XoIU.d.ts → stage-types-BFsm3qsZ.d.ts} +255 -26
  42. package/dist/stage.d.ts +11 -6
  43. package/dist/stage.js +3462 -491
  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 +21 -4
  48. package/dist/behaviors.d.ts +0 -106
  49. package/dist/behaviors.js +0 -398
  50. package/dist/behaviors.js.map +0 -1
  51. package/dist/camera-CpbDr4-V.d.ts +0 -116
  52. package/dist/entity-COvRtFNG.d.ts +0 -395
  53. package/dist/moveable-B_vyA6cw.d.ts +0 -67
  54. package/dist/transformable-CUhvyuYO.d.ts +0 -67
@@ -1,52 +1,23 @@
1
- import { I as InputGamepad, c as UpdateFunction, f as InputPlayerNumber, g as Inputs, h as ButtonState, A as AnalogState, S as SetupContext, U as UpdateContext, d as DestroyContext, i as GameEntityLifeCycle, e as BaseNode, j as IGame, b as SetupFunction, D as DestroyFunction, k as LoadedContext, C as CleanupContext } from './entity-COvRtFNG.js';
2
- import { Z as ZylemCamera } from './camera-CpbDr4-V.js';
3
- import { d as StageInterface, b as Stage } from './stage-types-CD21XoIU.js';
1
+ import { ak as InputPlayerNumber, al as InputProvider, am as Inputs, L as SetupContext, U as UpdateContext, M as DestroyContext, an as GameEntityLifeCycle, N as BaseNode, ao as IGame, S as SetupFunction, J as UpdateFunction, K as DestroyFunction, aa as GameEvents, ap as LoadedContext, aq as CleanupContext, ar as NodeInterface } from './entity-BpbZqg19.js';
2
+ import { G as GameInputConfig, e as StageInterface, B as BaseGlobals, b as Stage, Z as ZylemGameConfig } from './stage-types-BFsm3qsZ.js';
3
+ import { Z as ZylemCamera, R as RendererManager } from './camera-B5e4c78l.js';
4
4
  import { Vector3 } from 'three';
5
5
  import { Vector3 as Vector3$1 } from '@dimforge/rapier3d-compat';
6
-
7
- interface InputProvider {
8
- getInput(delta: number): Partial<InputGamepad>;
9
- isConnected(): boolean;
10
- getName(): string;
11
- }
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
- }
21
- interface GameInputConfig {
22
- p1?: GameInputPlayerConfig;
23
- p2?: GameInputPlayerConfig;
24
- p3?: GameInputPlayerConfig;
25
- p4?: GameInputPlayerConfig;
26
- p5?: GameInputPlayerConfig;
27
- p6?: GameInputPlayerConfig;
28
- p7?: GameInputPlayerConfig;
29
- p8?: GameInputPlayerConfig;
30
- }
31
- interface ZylemGameConfig<StageInterface, GameInterface, TGlobals extends BaseGlobals> {
32
- id: string;
33
- globals?: TGlobals;
34
- stages?: StageInterface[];
35
- update?: UpdateFunction<GameInterface>;
36
- debug?: boolean;
37
- time?: number;
38
- input?: GameInputConfig;
39
- }
6
+ import './global-change-Dc8uCKi2.js';
40
7
 
41
8
  declare class InputManager {
42
9
  private inputMap;
43
10
  private currentInputs;
44
11
  private previousInputs;
45
12
  constructor(config?: GameInputConfig);
13
+ /**
14
+ * Reconfigure keyboard providers at runtime without affecting gamepad providers.
15
+ * Disposes existing keyboard providers and creates new ones from the given config.
16
+ */
17
+ configure(config: GameInputConfig): void;
46
18
  addInputProvider(playerNumber: InputPlayerNumber, provider: InputProvider): void;
47
19
  getInputs(delta: number): Inputs;
48
- mergeButtonState(a: ButtonState | undefined, b: ButtonState | undefined): ButtonState;
49
- mergeAnalogState(a: AnalogState | undefined, b: AnalogState | undefined): AnalogState;
20
+ private buildPlayerEntries;
50
21
  private mergeInputs;
51
22
  }
52
23
 
@@ -313,7 +284,10 @@ declare class ZylemGame<TGlobals extends BaseGlobals> {
313
284
  timer: Timer;
314
285
  inputManager: InputManager;
315
286
  wrapperRef: Game<TGlobals>;
287
+ globalInputConfig: GameInputConfig | undefined;
316
288
  defaultCamera: ZylemCamera | null;
289
+ /** Shared renderer manager for all stages */
290
+ rendererManager: RendererManager | null;
317
291
  container: HTMLElement | null;
318
292
  canvas: HTMLCanvasElement | null;
319
293
  aspectRatioDelegate: AspectRatioDelegate | null;
@@ -332,10 +306,25 @@ declare class ZylemGame<TGlobals extends BaseGlobals> {
332
306
  loadGameCanvas(config: GameConfig): void;
333
307
  loadDebugOptions(options: ZylemGameOptions<TGlobals>): void;
334
308
  loadStage(stage: Stage, stageIndex?: number): Promise<void>;
309
+ /**
310
+ * Merges game-level global input config with the stage's per-stage overrides
311
+ * and reconfigures the InputManager.
312
+ */
313
+ applyInputConfig(stage: Stage): void;
314
+ /**
315
+ * Update the game-level global input config and re-apply to the current stage.
316
+ */
317
+ setGlobalInputConfig(config: GameInputConfig): void;
335
318
  unloadCurrentStage(): void;
336
319
  setGlobals(options: ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals>): void;
337
320
  params(): UpdateContext<ZylemGame<TGlobals>, TGlobals>;
338
321
  start(): void;
322
+ /**
323
+ * Execute a single frame update.
324
+ * This method can be called directly for testing or from the game loop.
325
+ * @param deltaTime Optional delta time in seconds. If not provided, uses timer delta.
326
+ */
327
+ step(deltaTime?: number): void;
339
328
  loop(timestamp: number): void;
340
329
  dispose(): void;
341
330
  outOfLoop(): void;
@@ -348,9 +337,28 @@ declare class ZylemGame<TGlobals extends BaseGlobals> {
348
337
  * @returns Unsubscribe function
349
338
  */
350
339
  onLoading(callback: (event: GameLoadingEvent) => void): () => void;
340
+ /**
341
+ * Build the stage config payload for the current stage.
342
+ */
343
+ private buildStageConfigPayload;
344
+ /**
345
+ * Build the entities payload for the current stage.
346
+ */
347
+ private buildEntitiesPayload;
348
+ /**
349
+ * Emit a state:dispatch event to the zylemEventBus.
350
+ * Called after stage load and on global state changes.
351
+ */
352
+ private emitStateDispatch;
353
+ /**
354
+ * Inspect a stage's options to determine the renderer type.
355
+ * Looks for CameraWrapper instances in the stage options and uses
356
+ * the first camera's rendererType. Falls back to 'webgl'.
357
+ */
358
+ private resolveRendererType;
351
359
  /**
352
360
  * Subscribe to the game event bus for stage loading and state events.
353
- * Emits window events for cross-application communication.
361
+ * Emits events to zylemEventBus for cross-package communication.
354
362
  */
355
363
  private subscribeToEventBus;
356
364
  }
@@ -367,11 +375,22 @@ declare class Game<TGlobals extends BaseGlobals> implements IGame<TGlobals> {
367
375
  private globalChangeCallbacks;
368
376
  private globalChangesCallbacks;
369
377
  private activeGlobalSubscriptions;
378
+ private eventDelegate;
379
+ /** Pending global input config set before the game starts. */
380
+ private pendingInputConfig;
370
381
  refErrorMessage: string;
371
382
  constructor(options: GameOptions<TGlobals>);
372
383
  onSetup(...callbacks: Array<SetupFunction<ZylemGame<TGlobals>, TGlobals>>): this;
373
384
  onUpdate(...callbacks: Array<UpdateFunction<ZylemGame<TGlobals>, TGlobals>>): this;
374
385
  onDestroy(...callbacks: Array<DestroyFunction<ZylemGame<TGlobals>, TGlobals>>): this;
386
+ /**
387
+ * Set composable input configuration as global defaults for the entire game.
388
+ * Multiple configs are deep-merged (later configs win on key conflicts).
389
+ * Per-stage overrides (via stage.setInputConfiguration) are merged on top.
390
+ * Can be called before or after start().
391
+ * @example game.setInputConfiguration(useArrowsForAxes('p1'), useWASDForDirections('p2'));
392
+ */
393
+ setInputConfiguration(...configs: GameInputConfig[]): this;
375
394
  start(): Promise<this>;
376
395
  private load;
377
396
  private setOverrides;
@@ -400,6 +419,12 @@ declare class Game<TGlobals extends BaseGlobals> implements IGame<TGlobals> {
400
419
  getCurrentStage(): Stage | null;
401
420
  pause(): Promise<void>;
402
421
  resume(): Promise<void>;
422
+ /**
423
+ * Execute a single frame update.
424
+ * Useful for testing or manual frame stepping.
425
+ * @param deltaTime Optional delta time in seconds (defaults to 1/60)
426
+ */
427
+ step(deltaTime?: number): void;
403
428
  reset(): Promise<void>;
404
429
  previousStage(): void;
405
430
  loadStageFromId(stageId: string): Promise<void>;
@@ -407,6 +432,16 @@ declare class Game<TGlobals extends BaseGlobals> implements IGame<TGlobals> {
407
432
  goToStage(): Promise<void>;
408
433
  end(): Promise<void>;
409
434
  dispose(): void;
435
+ /**
436
+ * Dispatch an event from the game.
437
+ * Events are emitted both locally and to the global event bus.
438
+ */
439
+ dispatch<K extends keyof GameEvents>(event: K, payload: GameEvents[K]): void;
440
+ /**
441
+ * Listen for events on this game instance.
442
+ * @returns Unsubscribe function
443
+ */
444
+ listen<K extends keyof GameEvents>(event: K, handler: (payload: GameEvents[K]) => void): () => void;
410
445
  /**
411
446
  * Subscribe to loading events from the game.
412
447
  * Events include stage context (stageName, stageIndex).
@@ -425,42 +460,39 @@ declare class Game<TGlobals extends BaseGlobals> implements IGame<TGlobals> {
425
460
  */
426
461
  declare function createGame<TGlobals extends BaseGlobals>(...options: GameOptions<TGlobals>): Game<TGlobals>;
427
462
 
463
+ /**
464
+ * A Vessel is an empty container entity that holds child entities.
465
+ * It has no geometry, physics, or rendering of its own, but propagates
466
+ * lifecycle events to its children and provides a logical grouping mechanism.
467
+ *
468
+ * Child entities added to a Vessel will be individually spawned into the
469
+ * stage's physics world and render scene when the Vessel is spawned.
470
+ */
428
471
  declare class Vessel extends BaseNode<{}, Vessel> {
429
472
  static type: symbol;
430
473
  protected _setup(_params: SetupContext<this>): void;
431
474
  protected _loaded(_params: LoadedContext<this>): Promise<void>;
432
475
  protected _update(_params: UpdateContext<this>): void;
433
476
  protected _destroy(_params: DestroyContext<this>): void;
434
- protected _cleanup(_params: CleanupContext<this>): Promise<void>;
477
+ protected _cleanup(_params: CleanupContext<this>): void;
435
478
  create(): this;
479
+ /**
480
+ * Add one or more child entities to this vessel.
481
+ * Overrides parent to support multiple arguments.
482
+ * @returns this for chaining
483
+ */
484
+ add(...nodes: NodeInterface[]): this;
436
485
  }
437
- declare function vessel(...args: Array<BaseNode>): BaseNode<{}, Vessel>;
438
-
439
486
  /**
440
- * @deprecated This type is deprecated.
487
+ * Create a vessel containing the given child entities.
488
+ * @param args Child BaseNode entities to add
489
+ * @returns A new Vessel with the children added
441
490
  */
442
- type Vect3 = Vector3 | Vector3$1;
491
+ declare function vessel(...args: Array<BaseNode>): Vessel;
443
492
 
444
493
  /**
445
- * Listen for a single global key change inside an onUpdate pipeline.
446
- * Usage: onUpdate(globalChange('p1Score', (value) => { ... }))
447
- */
448
- declare function globalChange<T = any>(key: string, callback: (value: T, ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
449
- /**
450
- * Listen for multiple global key changes inside an onUpdate pipeline.
451
- * Calls back when any of the provided keys changes.
452
- * Usage: onUpdate(globalChanges(['p1Score','p2Score'], ([p1,p2]) => { ... }))
453
- */
454
- declare function globalChanges<T = any>(keys: string[], callback: (values: T[], ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
455
- /**
456
- * Listen for a single stage variable change inside an onUpdate pipeline.
457
- * Usage: onUpdate(variableChange('score', (value, ctx) => { ... }))
458
- */
459
- declare function variableChange<T = any>(key: string, callback: (value: T, ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
460
- /**
461
- * Listen for multiple stage variable changes; fires when any changes.
462
- * Usage: onUpdate(variableChanges(['a','b'], ([a,b], ctx) => { ... }))
494
+ * @deprecated This type is deprecated.
463
495
  */
464
- declare function variableChanges<T = any>(keys: string[], callback: (values: T[], ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
496
+ type Vect3 = Vector3 | Vector3$1;
465
497
 
466
- export { Game as G, type Vect3 as V, type ZylemGameConfig as Z, globalChange as a, globalChanges as b, createGame as c, variableChange as d, variableChanges as e, gameConfig as g, vessel as v };
498
+ export { Game as G, type Vect3 as V, createGame as c, gameConfig as g, vessel as v };
package/dist/core.d.ts CHANGED
@@ -1,10 +1,16 @@
1
- export { V as Vect3, Z as ZylemGameConfig, c as createGame, a as globalChange, b as globalChanges, d as variableChange, e as variableChanges, v as vessel } from './core-CZhozNRH.js';
2
- import './entity-COvRtFNG.js';
1
+ export { V as Vect3, c as createGame, v as vessel } from './core-DAkskq6Y.js';
2
+ export { Z as ZylemGameConfig } from './stage-types-BFsm3qsZ.js';
3
+ export { g as globalChange, a as globalChanges, v as variableChange, b as variableChanges } from './global-change-Dc8uCKi2.js';
4
+ import './entity-BpbZqg19.js';
3
5
  import 'three';
4
6
  import '@dimforge/rapier3d-compat';
5
7
  import 'bitecs';
6
- import './camera-CpbDr4-V.js';
7
- import 'three/examples/jsm/postprocessing/EffectComposer.js';
8
+ import 'mitt';
9
+ import './behavior-descriptor-BWNWmIjv.js';
10
+ import './camera-B5e4c78l.js';
8
11
  import './entity-Bq_eNEDI.js';
9
- import './stage-types-CD21XoIU.js';
10
- import './entities-BAxfJOkk.js';
12
+ import 'three/webgpu';
13
+ import 'three/examples/jsm/postprocessing/EffectComposer.js';
14
+ import './world-Be5m1XC1.js';
15
+ import './entity-types-DAu8sGJH.js';
16
+ import './entities-DC9ce_vx.js';