@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
@@ -0,0 +1,16 @@
1
+ import { SyncCallback, StateMachine, ITransition, ILogger } from 'typescript-fsm';
2
+
3
+ /**
4
+ * Local wrapper around typescript-fsm's SyncStateMachine.
5
+ *
6
+ * typescript-fsm@1.6.0 incorrectly reports callback-less transitions as
7
+ * unhandled even after moving to the next state, which causes noisy
8
+ * `No transition...` console errors for valid FSM dispatches.
9
+ */
10
+ declare class SyncStateMachine<STATE extends string | number | symbol, EVENT extends string | number | symbol, CALLBACK extends Record<EVENT, SyncCallback> = Record<EVENT, SyncCallback>> extends StateMachine<STATE, EVENT, CALLBACK> {
11
+ constructor(init: STATE, transitions?: ITransition<STATE, EVENT, CALLBACK[EVENT]>[], logger?: ILogger);
12
+ dispatch<E extends EVENT>(_event: E, ..._args: unknown[]): Promise<void>;
13
+ syncDispatch<E extends EVENT>(event: E, ...args: unknown[]): boolean;
14
+ }
15
+
16
+ export { SyncStateMachine as S };
@@ -1,8 +1,8 @@
1
- import { StateMachine } from 'typescript-fsm';
2
- import { Z as ZylemWorld } from './world-Be5m1XC1.js';
1
+ import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
2
+ import { Z as ZylemWorld } from './world-DfgxoNMt.js';
3
3
  import { RigidBody } from '@dimforge/rapier3d-compat';
4
4
  import { Vector3, Quaternion } from 'three';
5
- import { b as BehaviorDescriptor } from './behavior-descriptor-BWNWmIjv.js';
5
+ import { c as BehaviorDescriptor } from './behavior-descriptor-BXnVR8Ki.js';
6
6
 
7
7
  /**
8
8
  * Core ECS Components
@@ -45,6 +45,10 @@ interface ThrusterInputComponent {
45
45
  thrust: number;
46
46
  /** Rotation intent: -1..1 */
47
47
  rotate: number;
48
+ /** World-space X thrust intent: -1..1 */
49
+ thrustX: number;
50
+ /** World-space Y thrust intent: -1..1 */
51
+ thrustY: number;
48
52
  }
49
53
  declare function createThrusterInputComponent(): ThrusterInputComponent;
50
54
  interface ThrusterStateComponent {
@@ -85,10 +89,12 @@ interface ThrusterFSMContext {
85
89
  interface PlayerInput {
86
90
  thrust: number;
87
91
  rotate: number;
92
+ thrustX?: number;
93
+ thrustY?: number;
88
94
  }
89
95
  declare class ThrusterFSM {
90
96
  private ctx;
91
- machine: StateMachine<ThrusterState, ThrusterEvent, never>;
97
+ machine: SyncStateMachine<ThrusterState, ThrusterEvent, never>;
92
98
  constructor(ctx: ThrusterFSMContext);
93
99
  /**
94
100
  * Get current state
@@ -139,10 +145,10 @@ declare class ThrusterMovementBehavior implements Behavior {
139
145
  private world;
140
146
  constructor(world: ZylemWorld);
141
147
  /**
142
- * Query function - returns entities with required thruster components
148
+ * Update a single thruster-enabled entity.
143
149
  */
144
- private queryEntities;
145
- update(_dt: number): void;
150
+ updateEntity(gameEntity: any, _dt: number): void;
151
+ update(dt: number): void;
146
152
  }
147
153
 
148
154
  /**
@@ -153,6 +159,8 @@ interface ThrusterBehaviorOptions {
153
159
  linearThrust: number;
154
160
  /** Rotation torque (default: 5) */
155
161
  angularThrust: number;
162
+ /** Optional linear damping override */
163
+ linearDamping?: number;
156
164
  }
157
165
  /**
158
166
  * ThrusterBehavior - typed descriptor for thruster movement.
@@ -169,4 +177,4 @@ interface ThrusterBehaviorOptions {
169
177
  */
170
178
  declare const ThrusterBehavior: BehaviorDescriptor<ThrusterBehaviorOptions, Record<string, never>, ThrusterEntity>;
171
179
 
172
- export { type Behavior as B, type PhysicsBodyComponent as P, type TransformComponent as T, createPhysicsBodyComponent as a, type ThrusterMovementComponent as b, createTransformComponent as c, type ThrusterInputComponent as d, type ThrusterStateComponent as e, createThrusterMovementComponent as f, createThrusterInputComponent as g, createThrusterStateComponent as h, ThrusterState as i, ThrusterEvent as j, ThrusterFSM as k, type ThrusterFSMContext as l, type PlayerInput as m, ThrusterMovementBehavior as n, type ThrusterEntity as o, ThrusterBehavior as p, type ThrusterBehaviorOptions as q };
180
+ export { type Behavior as B, type PhysicsBodyComponent as P, type ThrusterInputComponent as T, type TransformComponent as a, createPhysicsBodyComponent as b, createTransformComponent as c, type ThrusterMovementComponent as d, type ThrusterStateComponent as e, createThrusterMovementComponent as f, createThrusterInputComponent as g, createThrusterStateComponent as h, ThrusterState as i, ThrusterEvent as j, ThrusterFSM as k, type ThrusterFSMContext as l, type PlayerInput as m, ThrusterMovementBehavior as n, type ThrusterEntity as o, ThrusterBehavior as p, type ThrusterBehaviorOptions as q };
@@ -0,0 +1,105 @@
1
+ import { Vector3 } from 'three';
2
+ import RAPIER__default, { World } from '@dimforge/rapier3d-compat';
3
+ import { E as Entity } from './entity-Bq_eNEDI.js';
4
+ import { I as GameEntity, U as UpdateContext } from './entity-vj-HTjzU.js';
5
+
6
+ /**
7
+ * Interface for entities that handle collision events.
8
+ */
9
+ interface CollisionHandlerDelegate {
10
+ handlePostCollision(params: any): boolean;
11
+ handleIntersectionEvent(params: any): void;
12
+ }
13
+ /**
14
+ * Physics world wrapper supporting two modes:
15
+ *
16
+ * - **Direct mode** (default): Rapier world lives on the main thread.
17
+ * This is the original behavior with the Phase-1 fixed-timestep accumulator.
18
+ *
19
+ * - **Worker mode**: Physics runs in a Web Worker via {@link PhysicsProxy}.
20
+ * Entity bodies are replaced with {@link PhysicsBodyHandle} instances that
21
+ * cache transforms and queue write commands. Collision events are delivered
22
+ * asynchronously (one frame latency).
23
+ */
24
+ declare class ZylemWorld implements Entity<ZylemWorld> {
25
+ type: string;
26
+ /** Rapier world instance (null in worker mode). */
27
+ world: World;
28
+ collisionMap: Map<string, GameEntity<any>>;
29
+ collisionBehaviorMap: Map<string, GameEntity<any>>;
30
+ _removalMap: Map<string, GameEntity<any>>;
31
+ private activeCollisionPairs;
32
+ private currentCollisionTimeMs;
33
+ /** Fixed timestep in seconds used for each physics step. */
34
+ readonly fixedTimestep: number;
35
+ /** Unprocessed time carried over between frames. */
36
+ private accumulator;
37
+ /** Maximum number of physics steps allowed per frame to prevent spiral-of-death. */
38
+ private static readonly MAX_STEPS_PER_FRAME;
39
+ /**
40
+ * Interpolation alpha (0..1) representing the fraction of an unprocessed
41
+ * timestep remaining after the last physics step. Can be used to interpolate
42
+ * rendering transforms between the previous and current physics state.
43
+ */
44
+ interpolationAlpha: number;
45
+ /** When true, physics runs in a Web Worker via the proxy. */
46
+ readonly workerMode: boolean;
47
+ /** Physics worker proxy (only set in worker mode). */
48
+ private proxy;
49
+ /** Pending step promise (worker mode). */
50
+ private _pendingStep;
51
+ private readonly trackedDirectBodies;
52
+ static loadPhysics(gravity: Vector3): Promise<RAPIER__default.World>;
53
+ /**
54
+ * Initialize physics in worker mode. Returns a ZylemWorld that
55
+ * delegates all physics to a Web Worker.
56
+ *
57
+ * @param gravity World gravity.
58
+ * @param physicsRate Physics tick rate in Hz.
59
+ * @param workerUrl Optional URL to the worker script.
60
+ */
61
+ static loadPhysicsWorker(gravity: Vector3, physicsRate?: number, workerUrl?: URL): Promise<ZylemWorld>;
62
+ /**
63
+ * @param world The Rapier physics world instance (null in worker mode).
64
+ * @param physicsRate Physics update rate in Hz (default 60).
65
+ * @param useWorker Whether to use worker mode (default false).
66
+ */
67
+ constructor(world: World, physicsRate?: number, useWorker?: boolean);
68
+ addEntity(entity: any): void;
69
+ setForRemoval(entity: any): void;
70
+ destroyEntity(entity: GameEntity<any>): void;
71
+ setup(): void;
72
+ /**
73
+ * Advance the physics simulation.
74
+ *
75
+ * In direct mode, uses the fixed-timestep accumulator on the main thread.
76
+ * In worker mode, sends a step command and awaits the result.
77
+ */
78
+ update(params: UpdateContext<any>): void;
79
+ /**
80
+ * In worker mode, the step is async. Call this to await the
81
+ * pending step before reading transform data.
82
+ */
83
+ awaitStep(): Promise<void>;
84
+ private addEntityDirect;
85
+ private destroyEntityDirect;
86
+ private updateDirect;
87
+ private captureDirectBodyPreviousPoses;
88
+ private captureDirectBodyCurrentPoses;
89
+ private patchDirectBodyPoseTracking;
90
+ private addEntityWorker;
91
+ private destroyEntityWorker;
92
+ private updateWorker;
93
+ updatePostCollisionBehaviors(delta: number): void;
94
+ private processPendingRemovals;
95
+ private removeEntityFromTracking;
96
+ private pruneActiveCollisionPairs;
97
+ private collectCollisionPairsFromWorld;
98
+ private processCollisionPairs;
99
+ private dispatchCollisionPhase;
100
+ private dispatchIntersectionDelegates;
101
+ destroy(): void;
102
+ private clearEntityPhysicsState;
103
+ }
104
+
105
+ export { type CollisionHandlerDelegate as C, ZylemWorld as Z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zylem/game-lib",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "type": "module",
5
5
  "description": "A powerful and easy-to-use framework for creating simple 3D digital interactive applications using TypeScript.",
6
6
  "license": "MIT",
@@ -46,18 +46,42 @@
46
46
  "types": "./dist/behavior/thruster.d.ts",
47
47
  "import": "./dist/behavior/thruster.js"
48
48
  },
49
+ "./behavior/top-down-movement": {
50
+ "types": "./dist/behavior/top-down-movement.d.ts",
51
+ "import": "./dist/behavior/top-down-movement.js"
52
+ },
53
+ "./behavior/shooter-2d": {
54
+ "types": "./dist/behavior/shooter-2d.d.ts",
55
+ "import": "./dist/behavior/shooter-2d.js"
56
+ },
49
57
  "./behavior/screen-wrap": {
50
58
  "types": "./dist/behavior/screen-wrap.d.ts",
51
59
  "import": "./dist/behavior/screen-wrap.js"
52
60
  },
61
+ "./behavior/screen-visibility": {
62
+ "types": "./dist/behavior/screen-visibility.d.ts",
63
+ "import": "./dist/behavior/screen-visibility.js"
64
+ },
53
65
  "./behavior/world-boundary-2d": {
54
66
  "types": "./dist/behavior/world-boundary-2d.d.ts",
55
67
  "import": "./dist/behavior/world-boundary-2d.js"
56
68
  },
69
+ "./behavior/world-boundary-3d": {
70
+ "types": "./dist/behavior/world-boundary-3d.d.ts",
71
+ "import": "./dist/behavior/world-boundary-3d.js"
72
+ },
57
73
  "./behavior/ricochet-2d": {
58
74
  "types": "./dist/behavior/ricochet-2d.d.ts",
59
75
  "import": "./dist/behavior/ricochet-2d.js"
60
76
  },
77
+ "./behavior/ricochet-3d": {
78
+ "types": "./dist/behavior/ricochet-3d.d.ts",
79
+ "import": "./dist/behavior/ricochet-3d.js"
80
+ },
81
+ "./behavior/jumper-2d": {
82
+ "types": "./dist/behavior/jumper-2d.d.ts",
83
+ "import": "./dist/behavior/jumper-2d.js"
84
+ },
61
85
  "./behavior/platformer-3d": {
62
86
  "types": "./dist/behavior/platformer-3d.d.ts",
63
87
  "import": "./dist/behavior/platformer-3d.js"