@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,50 +1,23 @@
1
- import { I as InputGamepad, U as UpdateFunction, u as InputPlayerNumber, v as Inputs, a as SetupContext, b as UpdateContext, c as DestroyContext, w as GameEntityLifeCycle, B as BaseNode, x as IGame, S as SetupFunction, D as DestroyFunction, j as GameEvents, y as LoadedContext, C as CleanupContext } from './world-C8tQ7Plj.js';
2
- import { Z as ZylemCamera } from './camera-CeJPAgGg.js';
3
- import { e as StageInterface, b as Stage } from './stage-types-Bd-KtcYT.js';
1
+ import { ak as InputPlayerNumber, al as InputProvider, am as Inputs, L as SetupContext, U as UpdateContext, M as DestroyContext, an as GameEntityLifeCycle, O 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-vj-HTjzU.js';
2
+ import { G as GameInputConfig, e as StageInterface, B as BaseGlobals, b as Stage, Z as ZylemGameConfig } from './stage-types-C19IhuzA.js';
3
+ import { Z as ZylemCamera, R as RendererManager } from './camera-4XO5gbQH.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-2JvMaz44.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 and mouse providers at runtime without affecting gamepad providers.
15
+ * Disposes existing keyboard/mouse 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;
20
+ private buildPlayerEntries;
48
21
  private mergeInputs;
49
22
  }
50
23
 
@@ -142,6 +115,7 @@ declare class Timer {
142
115
  declare const AspectRatio: {
143
116
  readonly FourByThree: number;
144
117
  readonly SixteenByNine: number;
118
+ readonly NineBySixteen: number;
145
119
  readonly TwentyOneByNine: number;
146
120
  readonly OneByOne: number;
147
121
  };
@@ -158,6 +132,7 @@ declare class AspectRatioDelegate {
158
132
  aspectRatio: number;
159
133
  onResize?: (width: number, height: number) => void;
160
134
  private handleResizeBound;
135
+ private resizeObserver;
161
136
  constructor(params: {
162
137
  container: HTMLElement;
163
138
  canvas: HTMLCanvasElement;
@@ -177,6 +152,11 @@ declare class AspectRatioDelegate {
177
152
  apply(): void;
178
153
  }
179
154
 
155
+ interface ViewportSize {
156
+ width: number;
157
+ height: number;
158
+ }
159
+
180
160
  type RetroResolution = {
181
161
  key: string;
182
162
  width: number;
@@ -188,13 +168,36 @@ type RetroPreset = {
188
168
  resolutions: RetroResolution[];
189
169
  };
190
170
  /**
191
- * Retro and console display presets.
171
+ * Retro, console, and device display presets.
192
172
  * displayAspect represents the intended display aspect (letterboxing target),
193
173
  * not necessarily the raw pixel aspect of internal buffers.
194
174
  */
195
175
  declare const RetroPresets: Record<string, RetroPreset>;
196
176
  type RetroPresetKey = keyof typeof RetroPresets;
177
+ declare function getDisplayAspect(preset: RetroPresetKey): number;
178
+ declare function getPresetResolution(preset: RetroPresetKey, key?: string): RetroResolution | undefined;
179
+ declare function parseResolution(text: string): {
180
+ width: number;
181
+ height: number;
182
+ } | null;
197
183
 
184
+ type ResolutionInput = string | {
185
+ width: number;
186
+ height: number;
187
+ };
188
+ type DeviceProfile = 'auto' | 'desktop' | 'mobile';
189
+ interface ResolveGameConfigRuntime {
190
+ deviceProfile?: DeviceProfile;
191
+ viewportSize?: ViewportSize;
192
+ }
193
+ type GameDeviceConfig = Partial<{
194
+ /** numeric value or key in AspectRatio */
195
+ aspectRatio: AspectRatioValue | keyof typeof AspectRatio;
196
+ /** console/display preset to derive aspect ratio */
197
+ preset: RetroPresetKey;
198
+ /** lock internal render buffer for this device profile */
199
+ resolution: ResolutionInput;
200
+ }>;
198
201
  type GameConfigLike = Partial<{
199
202
  id: string;
200
203
  globals: Record<string, any>;
@@ -206,11 +209,10 @@ type GameConfigLike = Partial<{
206
209
  aspectRatio: AspectRatioValue | keyof typeof AspectRatio;
207
210
  /** console/display preset to derive aspect ratio */
208
211
  preset: RetroPresetKey;
209
- /** lock internal render buffer to this resolution (e.g., '256x240' or { width, height }) */
210
- resolution: string | {
211
- width: number;
212
- height: number;
213
- };
212
+ /** lock internal render buffer to this desktop/default resolution */
213
+ resolution: ResolutionInput;
214
+ /** mobile-specific aspect/preset/resolution overrides */
215
+ mobile: GameDeviceConfig;
214
216
  fullscreen: boolean;
215
217
  /** CSS background value for document body */
216
218
  bodyBackground: string;
@@ -279,6 +281,8 @@ declare class GameCanvas {
279
281
  mountRenderer(rendererDom: HTMLCanvasElement, onResize: (width: number, height: number) => void): void;
280
282
  centerIfFullscreen(): void;
281
283
  attachAspectRatio(onResize: (width: number, height: number) => void): void;
284
+ setAspectRatio(aspectRatio: number): void;
285
+ reapplyLayout(): void;
282
286
  destroy(): void;
283
287
  private ensureContainer;
284
288
  }
@@ -311,7 +315,10 @@ declare class ZylemGame<TGlobals extends BaseGlobals> {
311
315
  timer: Timer;
312
316
  inputManager: InputManager;
313
317
  wrapperRef: Game<TGlobals>;
318
+ globalInputConfig: GameInputConfig | undefined;
314
319
  defaultCamera: ZylemCamera | null;
320
+ /** Shared renderer manager for all stages */
321
+ rendererManager: RendererManager | null;
315
322
  container: HTMLElement | null;
316
323
  canvas: HTMLCanvasElement | null;
317
324
  aspectRatioDelegate: AspectRatioDelegate | null;
@@ -323,13 +330,29 @@ declare class ZylemGame<TGlobals extends BaseGlobals> {
323
330
  private loadingDelegate;
324
331
  private rendererObserver;
325
332
  private eventBusUnsubscribes;
333
+ private readonly gameUpdateParams;
334
+ private readonly stageSetupParams;
335
+ private readonly stageUpdateParams;
336
+ private readonly frameCallback;
337
+ private readonly sourceOptions;
338
+ private displayRuntime;
326
339
  static FRAME_LIMIT: number;
327
340
  static FRAME_DURATION: number;
328
341
  static MAX_DELTA_SECONDS: number;
329
- constructor(options: ZylemGameOptions<TGlobals>, wrapperRef: Game<TGlobals>);
342
+ constructor(options: ZylemGameOptions<TGlobals>, wrapperRef: Game<TGlobals>, displayRuntime?: ResolveGameConfigRuntime);
343
+ setDisplayRuntime(runtime: ResolveGameConfigRuntime): void;
330
344
  loadGameCanvas(config: GameConfig): void;
331
345
  loadDebugOptions(options: ZylemGameOptions<TGlobals>): void;
332
346
  loadStage(stage: Stage, stageIndex?: number): Promise<void>;
347
+ /**
348
+ * Merges game-level global input config with the stage's per-stage overrides
349
+ * and reconfigures the InputManager.
350
+ */
351
+ applyInputConfig(stage: Stage): void;
352
+ /**
353
+ * Update the game-level global input config and re-apply to the current stage.
354
+ */
355
+ setGlobalInputConfig(config: GameInputConfig): void;
333
356
  unloadCurrentStage(): void;
334
357
  setGlobals(options: ZylemGameConfig<Stage, ZylemGame<TGlobals>, TGlobals>): void;
335
358
  params(): UpdateContext<ZylemGame<TGlobals>, TGlobals>;
@@ -365,6 +388,12 @@ declare class ZylemGame<TGlobals extends BaseGlobals> {
365
388
  * Called after stage load and on global state changes.
366
389
  */
367
390
  private emitStateDispatch;
391
+ /**
392
+ * Inspect a stage's options to determine the renderer type.
393
+ * Looks for CameraWrapper instances in the stage options and uses
394
+ * the first camera's rendererType. Falls back to 'webgl'.
395
+ */
396
+ private resolveRendererType;
368
397
  /**
369
398
  * Subscribe to the game event bus for stage loading and state events.
370
399
  * Emits events to zylemEventBus for cross-package communication.
@@ -385,12 +414,26 @@ declare class Game<TGlobals extends BaseGlobals> implements IGame<TGlobals> {
385
414
  private globalChangesCallbacks;
386
415
  private activeGlobalSubscriptions;
387
416
  private eventDelegate;
417
+ /** Pending global input config set before the game starts. */
418
+ private pendingInputConfig;
419
+ private displayRuntime;
388
420
  refErrorMessage: string;
389
421
  constructor(options: GameOptions<TGlobals>);
390
422
  onSetup(...callbacks: Array<SetupFunction<ZylemGame<TGlobals>, TGlobals>>): this;
391
423
  onUpdate(...callbacks: Array<UpdateFunction<ZylemGame<TGlobals>, TGlobals>>): this;
392
424
  onDestroy(...callbacks: Array<DestroyFunction<ZylemGame<TGlobals>, TGlobals>>): this;
425
+ /**
426
+ * Set composable input configuration as global defaults for the entire game.
427
+ * Multiple configs are deep-merged (later configs win on key conflicts).
428
+ * Per-stage overrides (via stage.setInputConfiguration) are merged on top.
429
+ * Can be called before or after start().
430
+ * @example game.setInputConfiguration(useArrowsForAxes('p1'), useWASDForDirections('p2'));
431
+ */
432
+ setInputConfiguration(...configs: GameInputConfig[]): this;
393
433
  start(): Promise<this>;
434
+ setDisplayRuntime(runtime: Partial<ResolveGameConfigRuntime>): this;
435
+ setDeviceProfile(profile: DeviceProfile): this;
436
+ setViewportSize(width: number, height: number): this;
394
437
  private load;
395
438
  private setOverrides;
396
439
  /**
@@ -459,42 +502,40 @@ declare class Game<TGlobals extends BaseGlobals> implements IGame<TGlobals> {
459
502
  */
460
503
  declare function createGame<TGlobals extends BaseGlobals>(...options: GameOptions<TGlobals>): Game<TGlobals>;
461
504
 
505
+ /**
506
+ * A Vessel is an empty container entity that holds child entities.
507
+ * It has no geometry, physics, or rendering of its own, but propagates
508
+ * lifecycle events to its children and provides a logical grouping mechanism.
509
+ *
510
+ * Child entities added to a Vessel will be individually spawned into the
511
+ * stage's physics world and render scene when the Vessel is spawned.
512
+ */
462
513
  declare class Vessel extends BaseNode<{}, Vessel> {
463
514
  static type: symbol;
464
515
  protected _setup(_params: SetupContext<this>): void;
465
516
  protected _loaded(_params: LoadedContext<this>): Promise<void>;
466
517
  protected _update(_params: UpdateContext<this>): void;
467
518
  protected _destroy(_params: DestroyContext<this>): void;
468
- protected _cleanup(_params: CleanupContext<this>): Promise<void>;
519
+ protected _cleanup(_params: CleanupContext<this>): void;
469
520
  create(): this;
521
+ clone(): this;
522
+ /**
523
+ * Add one or more child entities to this vessel.
524
+ * Overrides parent to support multiple arguments.
525
+ * @returns this for chaining
526
+ */
527
+ add(...nodes: NodeInterface[]): this;
470
528
  }
471
- declare function vessel(...args: Array<BaseNode>): BaseNode<{}, Vessel>;
472
-
473
529
  /**
474
- * @deprecated This type is deprecated.
530
+ * Create a vessel containing the given child entities.
531
+ * @param args Child BaseNode entities to add
532
+ * @returns A new Vessel with the children added
475
533
  */
476
- type Vect3 = Vector3 | Vector3$1;
534
+ declare function vessel(...args: Array<BaseNode>): Vessel;
477
535
 
478
536
  /**
479
- * Listen for a single global key change inside an onUpdate pipeline.
480
- * Usage: onUpdate(globalChange('p1Score', (value) => { ... }))
481
- */
482
- declare function globalChange<T = any>(key: string, callback: (value: T, ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
483
- /**
484
- * Listen for multiple global key changes inside an onUpdate pipeline.
485
- * Calls back when any of the provided keys changes.
486
- * Usage: onUpdate(globalChanges(['p1Score','p2Score'], ([p1,p2]) => { ... }))
487
- */
488
- declare function globalChanges<T = any>(keys: string[], callback: (values: T[], ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
489
- /**
490
- * Listen for a single stage variable change inside an onUpdate pipeline.
491
- * Usage: onUpdate(variableChange('score', (value, ctx) => { ... }))
492
- */
493
- declare function variableChange<T = any>(key: string, callback: (value: T, ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
494
- /**
495
- * Listen for multiple stage variable changes; fires when any changes.
496
- * Usage: onUpdate(variableChanges(['a','b'], ([a,b], ctx) => { ... }))
537
+ * @deprecated This type is deprecated.
497
538
  */
498
- declare function variableChanges<T = any>(keys: string[], callback: (values: T[], ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
539
+ type Vect3 = Vector3 | Vector3$1;
499
540
 
500
- 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 };
541
+ export { AspectRatio as A, type DeviceProfile as D, Game as G, type ResolutionInput as R, type Vect3 as V, type GameConfigLike as a, type GameDeviceConfig as b, createGame as c, type ResolveGameConfigRuntime as d, type AspectRatioValue as e, getDisplayAspect as f, gameConfig as g, getPresetResolution as h, type RetroPreset as i, type RetroPresetKey as j, type RetroResolution as k, parseResolution as p, vessel as v };
package/dist/core.d.ts CHANGED
@@ -1,12 +1,17 @@
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-bO8TzV7u.js';
2
- import './world-C8tQ7Plj.js';
1
+ export { V as Vect3, c as createGame, v as vessel } from './core-CARRaS55.js';
2
+ export { Z as ZylemGameConfig } from './stage-types-C19IhuzA.js';
3
+ export { g as globalChange, a as globalChanges, v as variableChange, b as variableChanges } from './global-change-2JvMaz44.js';
4
+ import './entity-vj-HTjzU.js';
3
5
  import 'three';
4
6
  import '@dimforge/rapier3d-compat';
5
- import './entity-Bq_eNEDI.js';
6
7
  import 'bitecs';
7
8
  import 'mitt';
8
- import './camera-CeJPAgGg.js';
9
+ import './behavior-descriptor-BXnVR8Ki.js';
10
+ import './camera-4XO5gbQH.js';
11
+ import './entity-Bq_eNEDI.js';
12
+ import 'three/webgpu';
9
13
  import 'three/examples/jsm/postprocessing/EffectComposer.js';
10
- import './stage-types-Bd-KtcYT.js';
14
+ import './world-DfgxoNMt.js';
11
15
  import './entity-types-DAu8sGJH.js';
12
- import './entities-DvByhMGU.js';
16
+ import './physics-pose-DCc4oE44.js';
17
+ import './entities-ChFirVL9.js';