@zylem/game-lib 0.6.3 → 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 (74) hide show
  1. package/dist/actions.d.ts +5 -5
  2. package/dist/actions.js +196 -32
  3. package/dist/actions.js.map +1 -1
  4. package/dist/behavior/jumper-2d.d.ts +114 -0
  5. package/dist/behavior/jumper-2d.js +711 -0
  6. package/dist/behavior/jumper-2d.js.map +1 -0
  7. package/dist/behavior/platformer-3d.d.ts +14 -14
  8. package/dist/behavior/platformer-3d.js +347 -104
  9. package/dist/behavior/platformer-3d.js.map +1 -1
  10. package/dist/behavior/ricochet-2d.d.ts +4 -3
  11. package/dist/behavior/ricochet-2d.js +53 -22
  12. package/dist/behavior/ricochet-2d.js.map +1 -1
  13. package/dist/behavior/ricochet-3d.d.ts +117 -0
  14. package/dist/behavior/ricochet-3d.js +443 -0
  15. package/dist/behavior/ricochet-3d.js.map +1 -0
  16. package/dist/behavior/screen-visibility.d.ts +79 -0
  17. package/dist/behavior/screen-visibility.js +358 -0
  18. package/dist/behavior/screen-visibility.js.map +1 -0
  19. package/dist/behavior/screen-wrap.d.ts +4 -3
  20. package/dist/behavior/screen-wrap.js +100 -49
  21. package/dist/behavior/screen-wrap.js.map +1 -1
  22. package/dist/behavior/shooter-2d.d.ts +79 -0
  23. package/dist/behavior/shooter-2d.js +180 -0
  24. package/dist/behavior/shooter-2d.js.map +1 -0
  25. package/dist/behavior/thruster.d.ts +5 -4
  26. package/dist/behavior/thruster.js +133 -75
  27. package/dist/behavior/thruster.js.map +1 -1
  28. package/dist/behavior/top-down-movement.d.ts +56 -0
  29. package/dist/behavior/top-down-movement.js +125 -0
  30. package/dist/behavior/top-down-movement.js.map +1 -0
  31. package/dist/behavior/world-boundary-2d.d.ts +4 -3
  32. package/dist/behavior/world-boundary-2d.js +90 -36
  33. package/dist/behavior/world-boundary-2d.js.map +1 -1
  34. package/dist/behavior/world-boundary-3d.d.ts +76 -0
  35. package/dist/behavior/world-boundary-3d.js +274 -0
  36. package/dist/behavior/world-boundary-3d.js.map +1 -0
  37. package/dist/{behavior-descriptor-BWNWmIjv.d.ts → behavior-descriptor-BXnVR8Ki.d.ts} +22 -5
  38. package/dist/{blueprints-BWGz8fII.d.ts → blueprints-DmbK2dki.d.ts} +2 -2
  39. package/dist/camera-4XO5gbQH.d.ts +905 -0
  40. package/dist/camera.d.ts +1 -1
  41. package/dist/camera.js +876 -289
  42. package/dist/camera.js.map +1 -1
  43. package/dist/{composition-DrzFrbqI.d.ts → composition-BASvMKrW.d.ts} +1 -1
  44. package/dist/{core-DAkskq6Y.d.ts → core-CARRaS55.d.ts} +57 -14
  45. package/dist/core.d.ts +9 -8
  46. package/dist/core.js +4519 -1255
  47. package/dist/core.js.map +1 -1
  48. package/dist/{entities-DC9ce_vx.d.ts → entities-ChFirVL9.d.ts} +22 -28
  49. package/dist/entities.d.ts +4 -4
  50. package/dist/entities.js +1231 -314
  51. package/dist/entities.js.map +1 -1
  52. package/dist/{entity-BpbZqg19.d.ts → entity-vj-HTjzU.d.ts} +80 -11
  53. package/dist/{global-change-Dc8uCKi2.d.ts → global-change-2JvMaz44.d.ts} +1 -1
  54. package/dist/main.d.ts +718 -19
  55. package/dist/main.js +12129 -5959
  56. package/dist/main.js.map +1 -1
  57. package/dist/physics-pose-DCc4oE44.d.ts +25 -0
  58. package/dist/physics-protocol-BDD3P5W2.d.ts +200 -0
  59. package/dist/physics-worker.d.ts +21 -0
  60. package/dist/physics-worker.js +306 -0
  61. package/dist/physics-worker.js.map +1 -0
  62. package/dist/physics.d.ts +205 -0
  63. package/dist/physics.js +577 -0
  64. package/dist/physics.js.map +1 -0
  65. package/dist/{stage-types-BFsm3qsZ.d.ts → stage-types-C19IhuzA.d.ts} +253 -89
  66. package/dist/stage.d.ts +9 -8
  67. package/dist/stage.js +3782 -1041
  68. package/dist/stage.js.map +1 -1
  69. package/dist/sync-state-machine-CZyspBpj.d.ts +16 -0
  70. package/dist/{thruster-DhRaJnoL.d.ts → thruster-23lzoPZd.d.ts} +16 -8
  71. package/dist/world-DfgxoNMt.d.ts +105 -0
  72. package/package.json +25 -1
  73. package/dist/camera-B5e4c78l.d.ts +0 -468
  74. package/dist/world-Be5m1XC1.d.ts +0 -31
@@ -2,7 +2,7 @@ import { Vector3, Vector2, Color, Material, BufferGeometry, Mesh, Group, ShaderM
2
2
  import { Vector3 as Vector3$1, RigidBodyDesc, ColliderDesc, RigidBody, Vector, Collider } from '@dimforge/rapier3d-compat';
3
3
  import { IComponent } from 'bitecs';
4
4
  import * as mitt from 'mitt';
5
- import { b as BehaviorDescriptor, c as BehaviorHandle, d as BehaviorRef } from './behavior-descriptor-BWNWmIjv.js';
5
+ import { c as BehaviorDescriptor, d as BehaviorHandle, e as BehaviorRef } from './behavior-descriptor-BXnVR8Ki.js';
6
6
 
7
7
  /** Input
8
8
  *
@@ -46,6 +46,13 @@ interface InputGamepad {
46
46
  axes: {
47
47
  Horizontal: AnalogState;
48
48
  Vertical: AnalogState;
49
+ SecondaryHorizontal: AnalogState;
50
+ SecondaryVertical: AnalogState;
51
+ };
52
+ /** Screen-space cursor position (normalized 0..1). Only populated by MouseProvider. */
53
+ pointer?: {
54
+ x: number;
55
+ y: number;
49
56
  };
50
57
  }
51
58
  type Inputs = Record<InputPlayer, InputGamepad>;
@@ -174,6 +181,8 @@ declare abstract class BaseNode<Options = any, T = any> implements NodeInterface
174
181
  * onSetup/onUpdate/etc. methods which are typed with `this`.
175
182
  */
176
183
  protected lifecycleCallbacks: LifecycleCallbacks<any>;
184
+ private trackLifecycleRegistrations;
185
+ private userLifecycleRegistrations;
177
186
  constructor(args?: BaseNodeOptions[]);
178
187
  /**
179
188
  * Add setup callbacks to be executed in order during nodeSetup
@@ -209,6 +218,9 @@ declare abstract class BaseNode<Options = any, T = any> implements NodeInterface
209
218
  remove(baseNode: NodeInterface): void;
210
219
  getChildren(): NodeInterface[];
211
220
  isComposite(): boolean;
221
+ enableUserLifecycleTracking(): void;
222
+ protected replayUserLifecycleRegistrationsTo(target: BaseNode<any, any>, wrap?: <T extends Function>(callback: T) => T): void;
223
+ protected cloneChildrenInto(target: BaseNode<any, any>): void;
212
224
  abstract create(): T;
213
225
  protected abstract _setup(params: SetupContext<this>): void;
214
226
  protected abstract _loaded(params: LoadedContext<this>): Promise<void>;
@@ -222,6 +234,7 @@ declare abstract class BaseNode<Options = any, T = any> implements NodeInterface
222
234
  nodeCleanup(params: CleanupContext<this>): void;
223
235
  getOptions(): Options;
224
236
  setOptions(options: Partial<Options>): void;
237
+ private recordLifecycleRegistration;
225
238
  }
226
239
 
227
240
  type Vec3 = Vector3 | Vector3$1;
@@ -261,6 +274,8 @@ interface MaterialOptions {
261
274
  repeat?: Vector2;
262
275
  shader?: ZylemShader;
263
276
  color?: Color;
277
+ /** Opacity from 0 (fully transparent) to 1 (fully opaque). */
278
+ opacity?: number;
264
279
  /**
265
280
  * When true, prefer TSL/NodeMaterial (for WebGPU)
266
281
  * When false, prefer GLSL/ShaderMaterial (for WebGL)
@@ -276,33 +291,40 @@ type BatchKey = ReturnType<typeof shortHash>;
276
291
  type TexturePath = string | null;
277
292
  declare class MaterialBuilder {
278
293
  static batchMaterialMap: Map<BatchKey, BatchMaterialMapObject>;
294
+ /**
295
+ * Clear the static batch material cache.
296
+ * Should be called during game disposal to prevent stale material references
297
+ * from persisting across demo/stage switches.
298
+ */
299
+ static clearBatchCache(): void;
279
300
  materials: Material[];
280
301
  /** Whether to use TSL/NodeMaterial (for WebGPU compatibility) */
281
302
  private useTSL;
282
303
  constructor(useTSL?: boolean);
283
304
  batchMaterial(options: Partial<MaterialOptions>, entityType: symbol): void;
284
305
  build(options: Partial<MaterialOptions>, entityType: symbol): void;
285
- withColor(color: Color, useTSL?: boolean): this;
286
- withShader(shader: ZylemShaderObject): this;
287
- withTSLShader(shader: ZylemTSLShader): this;
306
+ withColor(color: Color, useTSL?: boolean, opacity?: number): this;
307
+ withShader(shader: ZylemShaderObject, opacity?: number): this;
308
+ withTSLShader(shader: ZylemTSLShader, opacity?: number): this;
309
+ private applyOpacity;
288
310
  /**
289
311
  * Set texture - loads in background (deferred).
290
312
  * Material is created immediately with null map, texture applies when loaded.
291
313
  */
292
- setTexture(texturePath?: TexturePath, repeat?: Vector2, useTSL?: boolean): void;
314
+ setTexture(texturePath?: TexturePath, repeat?: Vector2, useTSL?: boolean, opacity?: number): void;
293
315
  /**
294
316
  * Set normal map for the current material
295
317
  */
296
318
  setNormalMap(normalMapPath: string, repeat?: Vector2): void;
297
- setColor(color: Color, useTSL?: boolean): void;
319
+ setColor(color: Color, useTSL?: boolean, opacity?: number): void;
298
320
  /**
299
321
  * Set GLSL shader (WebGL only)
300
322
  */
301
- setShader(customShader: ZylemShaderObject): void;
323
+ setShader(customShader: ZylemShaderObject, opacity?: number): void;
302
324
  /**
303
325
  * Set TSL shader (WebGPU compatible)
304
326
  */
305
- setTSLShader(tslShader: ZylemTSLShader): void;
327
+ setTSLShader(tslShader: ZylemTSLShader, opacity?: number): void;
306
328
  }
307
329
 
308
330
  /**
@@ -524,6 +546,14 @@ type ZylemEvents = GameEvents & StageEvents & EntityEvents;
524
546
  */
525
547
  declare const zylemEventBus: mitt.Emitter<ZylemEvents>;
526
548
 
549
+ type VelocityIntentMode = 'replace' | 'add';
550
+ interface VelocityIntent {
551
+ x?: number;
552
+ y?: number;
553
+ z?: number;
554
+ mode: VelocityIntentMode;
555
+ priority?: number;
556
+ }
527
557
  /**
528
558
  * Transform state managed by Valtio for batched physics updates.
529
559
  *
@@ -562,11 +592,18 @@ interface TransformState {
562
592
  y: number;
563
593
  z: number;
564
594
  };
595
+ /** Per-source velocity intents composed once per frame */
596
+ velocityChannels: Record<string, VelocityIntent>;
565
597
  /** Dirty flags to track what needs to be applied */
566
598
  dirty: {
567
599
  position: boolean;
568
600
  rotation: boolean;
601
+ /** @deprecated Use per-axis velocityX/Y/Z flags for new code */
569
602
  velocity: boolean;
603
+ velocityX: boolean;
604
+ velocityY: boolean;
605
+ velocityZ: boolean;
606
+ velocityChannels: boolean;
570
607
  angularVelocity: boolean;
571
608
  };
572
609
  }
@@ -771,6 +808,7 @@ interface CollisionComponent {
771
808
  __kind: 'collision';
772
809
  bodyDesc: RigidBodyDesc;
773
810
  colliderDesc: ColliderDesc;
811
+ cloneComponent: () => CollisionComponent;
774
812
  }
775
813
  interface BaseCollisionOptions {
776
814
  /** Whether the body is static (fixed) or dynamic */
@@ -892,8 +930,28 @@ interface CollisionContext<T, O extends GameEntityOptions, TGlobals extends Reco
892
930
  other: GameEntity<O | any>;
893
931
  globals: TGlobals;
894
932
  }
933
+ type CollisionPhase = 'enter' | 'stay';
934
+ interface CollisionRegistrationOptions {
935
+ phase?: CollisionPhase;
936
+ cooldownMs?: number;
937
+ }
938
+ interface NormalizedCollisionRegistrationOptions {
939
+ phase: CollisionPhase;
940
+ cooldownMs?: number;
941
+ }
942
+ interface CollisionRegistration<T, O extends GameEntityOptions> {
943
+ id: number;
944
+ callback: (params: CollisionContext<T, O>) => void;
945
+ options: NormalizedCollisionRegistrationOptions;
946
+ }
947
+ interface CollisionDispatchMetadata {
948
+ phase: CollisionPhase;
949
+ nowMs: number;
950
+ }
895
951
  interface CollisionDelegate<T, O extends GameEntityOptions> {
896
- collision?: ((params: CollisionContext<any, any>) => void)[];
952
+ collision?: CollisionRegistration<any, any>[];
953
+ cooldowns?: Map<string, number>;
954
+ nextId?: number;
897
955
  }
898
956
  type IBuilder<BuilderOptions = any> = {
899
957
  preBuild: (options: BuilderOptions) => BuilderOptions;
@@ -935,6 +993,7 @@ declare class GameEntity<O extends GameEntityOptions> extends BaseNode<O> implem
935
993
  materials: Material[] | undefined;
936
994
  bodyDesc: RigidBodyDesc | null;
937
995
  body: RigidBody | null;
996
+ physicsAttached: boolean;
938
997
  colliderDesc: ColliderDesc | undefined;
939
998
  collider: Collider | undefined;
940
999
  custom: Record<string, any>;
@@ -956,6 +1015,9 @@ declare class GameEntity<O extends GameEntityOptions> extends BaseNode<O> implem
956
1015
  isInstanced: boolean;
957
1016
  protected eventDelegate: EventEmitterDelegate<EntityEvents>;
958
1017
  private behaviorRefs;
1018
+ private cloneFactory;
1019
+ private trackAddedComponents;
1020
+ private trackedComponents;
959
1021
  transformStore: TransformState;
960
1022
  moveX: (delta: number) => void;
961
1023
  moveY: (delta: number) => void;
@@ -1002,6 +1064,7 @@ declare class GameEntity<O extends GameEntityOptions> extends BaseNode<O> implem
1002
1064
  add(...components: Array<NodeInterface | Mesh | CollisionComponent>): this;
1003
1065
  private addMeshComponent;
1004
1066
  private addCollisionComponent;
1067
+ private trackComponent;
1005
1068
  private _actions;
1006
1069
  /**
1007
1070
  * Run a fire-and-forget action. Auto-removed when done.
@@ -1023,9 +1086,12 @@ declare class GameEntity<O extends GameEntityOptions> extends BaseNode<O> implem
1023
1086
  */
1024
1087
  _tickActions(delta: number): void;
1025
1088
  create(): this;
1089
+ clone(overrides?: Partial<O>): this;
1090
+ finalizeCloneSupport(factory: (options?: Partial<O>) => GameEntity<O>): this;
1026
1091
  /**
1027
1092
  * Add collision callbacks
1028
1093
  */
1094
+ onCollision(callback: (params: CollisionContext<this, O>) => void, options?: CollisionRegistrationOptions): this;
1029
1095
  onCollision(...callbacks: ((params: CollisionContext<this, O>) => void)[]): this;
1030
1096
  /**
1031
1097
  * Use a behavior on this entity via typed descriptor.
@@ -1040,6 +1106,9 @@ declare class GameEntity<O extends GameEntityOptions> extends BaseNode<O> implem
1040
1106
  * Used by the stage to auto-register required systems.
1041
1107
  */
1042
1108
  getBehaviorRefs(): BehaviorRef[];
1109
+ getCollisionCallbacks(): Array<(params: CollisionContext<this, O>) => void>;
1110
+ getCollisionRegistrations(): Array<CollisionRegistration<this, O>>;
1111
+ private copyBehaviorRefsTo;
1043
1112
  /**
1044
1113
  * Entity-specific setup - resets actions for a fresh stage session.
1045
1114
  * (User callbacks are handled by BaseNode's lifecycleCallbacks.setup)
@@ -1066,7 +1135,7 @@ declare class GameEntity<O extends GameEntityOptions> extends BaseNode<O> implem
1066
1135
  * and must persist across stage reloads. Actions are reset in _setup().
1067
1136
  */
1068
1137
  protected _cleanup(_params: CleanupContext<this>): void;
1069
- _collision(other: GameEntity<O>, globals?: any): void;
1138
+ _collision(other: GameEntity<O>, globals?: any, dispatch?: CollisionDispatchMetadata): void;
1070
1139
  protected updateMaterials(params: any): void;
1071
1140
  buildInfo(): Record<string, string>;
1072
1141
  /**
@@ -1097,4 +1166,4 @@ declare class GameEntity<O extends GameEntityOptions> extends BaseNode<O> implem
1097
1166
  */
1098
1167
  declare function create(options?: Partial<GameEntityOptions>): GameEntity<GameEntityOptions>;
1099
1168
 
1100
- export { sphereCollision as $, type Action as A, setRotationZ as B, setRotationDegrees as C, setRotationDegreesY as D, setRotationDegreesX as E, setRotationDegreesZ as F, setRotation as G, getRotation as H, GameEntity as I, type UpdateFunction as J, type DestroyFunction as K, type SetupContext as L, type DestroyContext as M, BaseNode as N, type LoadingEvent as O, type GameEntityOptions as P, type StageEvents as Q, type MaterialOptions as R, type SetupFunction as S, type TransformState as T, type UpdateContext as U, type Vec3 as V, type MoveableEntity as W, type InputPlayer as X, create as Y, type ZylemShader as Z, boxCollision as _, moveX as a, coneCollision as a0, pyramidCollision as a1, cylinderCollision as a2, pillCollision as a3, planeCollision as a4, zoneCollision as a5, type CollisionComponent as a6, EventEmitterDelegate as a7, zylemEventBus as a8, type ZylemEvents as a9, type GameEvents as aa, type EntityEvents as ab, type GameLoadingPayload as ac, type StateDispatchPayload as ad, type StageConfigPayload as ae, type EntityConfigPayload as af, type ZylemShaderObject as ag, type ZylemTSLShader as ah, isTSLShader as ai, isGLSLShader as aj, type InputPlayerNumber as ak, type InputProvider as al, type Inputs as am, GameEntityLifeCycle as an, type IGame as ao, type LoadedContext as ap, type CleanupContext as aq, type NodeInterface as ar, type TexturePath as as, moveY as b, createTransformStore as c, moveZ as d, moveXY as e, moveXZ as f, resetVelocity as g, moveForwardXY as h, getPosition as i, getVelocity as j, setPositionX as k, setPositionY as l, move as m, setPositionZ as n, wrapAround3D as o, rotateInDirection as p, rotateYEuler as q, resetTransformStore as r, setPosition as s, rotateEuler as t, rotateX as u, rotateY as v, wrapAroundXY as w, rotateZ as x, setRotationY as y, setRotationX as z };
1169
+ export { sphereCollision as $, type Action as A, setRotationZ as B, setRotationDegrees as C, setRotationDegreesY as D, setRotationDegreesX as E, setRotationDegreesZ as F, setRotation as G, getRotation as H, GameEntity as I, type UpdateFunction as J, type DestroyFunction as K, type SetupContext as L, type DestroyContext as M, type LoadingEvent as N, BaseNode as O, type GameEntityOptions as P, type StageEvents as Q, type MaterialOptions as R, type SetupFunction as S, type TransformState as T, type UpdateContext as U, type Vec3 as V, type MoveableEntity as W, type InputPlayer as X, create as Y, type ZylemShader as Z, boxCollision as _, moveX as a, coneCollision as a0, pyramidCollision as a1, cylinderCollision as a2, pillCollision as a3, planeCollision as a4, zoneCollision as a5, type CollisionComponent as a6, EventEmitterDelegate as a7, zylemEventBus as a8, type ZylemEvents as a9, type GameEvents as aa, type EntityEvents as ab, type GameLoadingPayload as ac, type StateDispatchPayload as ad, type StageConfigPayload as ae, type EntityConfigPayload as af, type ZylemShaderObject as ag, type ZylemTSLShader as ah, isTSLShader as ai, isGLSLShader as aj, type InputPlayerNumber as ak, type InputProvider as al, type Inputs as am, GameEntityLifeCycle as an, type IGame as ao, type LoadedContext as ap, type CleanupContext as aq, type NodeInterface as ar, type TexturePath as as, moveY as b, createTransformStore as c, moveZ as d, moveXY as e, moveXZ as f, resetVelocity as g, moveForwardXY as h, getPosition as i, getVelocity as j, setPositionX as k, setPositionY as l, move as m, setPositionZ as n, wrapAround3D as o, rotateInDirection as p, rotateYEuler as q, resetTransformStore as r, setPosition as s, rotateEuler as t, rotateX as u, rotateY as v, wrapAroundXY as w, rotateZ as x, setRotationY as y, setRotationX as z };
@@ -1,4 +1,4 @@
1
- import { U as UpdateContext } from './entity-BpbZqg19.js';
1
+ import { U as UpdateContext } from './entity-vj-HTjzU.js';
2
2
 
3
3
  /**
4
4
  * Listen for a single global key change inside an onUpdate pipeline.