@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
@@ -0,0 +1,172 @@
1
+ import { StateMachine } from 'typescript-fsm';
2
+ import { Z as ZylemWorld } from './world-Be5m1XC1.js';
3
+ import { RigidBody } from '@dimforge/rapier3d-compat';
4
+ import { Vector3, Quaternion } from 'three';
5
+ import { b as BehaviorDescriptor } from './behavior-descriptor-BWNWmIjv.js';
6
+
7
+ /**
8
+ * Core ECS Components
9
+ *
10
+ * These are pure data interfaces with no logic.
11
+ * They work alongside the existing bitecs components in transformable.system.ts
12
+ */
13
+
14
+ interface TransformComponent {
15
+ position: Vector3;
16
+ rotation: Quaternion;
17
+ }
18
+ declare function createTransformComponent(): TransformComponent;
19
+ interface PhysicsBodyComponent {
20
+ body: RigidBody;
21
+ }
22
+ declare function createPhysicsBodyComponent(body: RigidBody): PhysicsBodyComponent;
23
+
24
+ /**
25
+ * Thruster-specific ECS Components
26
+ *
27
+ * These components are specific to the thruster movement system.
28
+ */
29
+ interface ThrusterMovementComponent {
30
+ /** Linear thrust force in Newtons (or scaled units) */
31
+ linearThrust: number;
32
+ /** Angular thrust torque scalar */
33
+ angularThrust: number;
34
+ /** Optional linear damping override */
35
+ linearDamping?: number;
36
+ /** Optional angular damping override */
37
+ angularDamping?: number;
38
+ }
39
+ declare function createThrusterMovementComponent(linearThrust: number, angularThrust: number, options?: {
40
+ linearDamping?: number;
41
+ angularDamping?: number;
42
+ }): ThrusterMovementComponent;
43
+ interface ThrusterInputComponent {
44
+ /** Forward thrust intent: 0..1 */
45
+ thrust: number;
46
+ /** Rotation intent: -1..1 */
47
+ rotate: number;
48
+ }
49
+ declare function createThrusterInputComponent(): ThrusterInputComponent;
50
+ interface ThrusterStateComponent {
51
+ /** Whether the thruster is enabled */
52
+ enabled: boolean;
53
+ /** Current thrust after FSM/gating */
54
+ currentThrust: number;
55
+ }
56
+ declare function createThrusterStateComponent(): ThrusterStateComponent;
57
+
58
+ /**
59
+ * ThrusterFSM
60
+ *
61
+ * State machine controller for thruster behavior.
62
+ * FSM does NOT touch physics or ThrusterMovementBehavior - it only writes ThrusterInputComponent.
63
+ */
64
+
65
+ declare enum ThrusterState {
66
+ Idle = "idle",
67
+ Active = "active",
68
+ Boosting = "boosting",
69
+ Disabled = "disabled",
70
+ Docked = "docked"
71
+ }
72
+ declare enum ThrusterEvent {
73
+ Activate = "activate",
74
+ Deactivate = "deactivate",
75
+ Boost = "boost",
76
+ EndBoost = "endBoost",
77
+ Disable = "disable",
78
+ Enable = "enable",
79
+ Dock = "dock",
80
+ Undock = "undock"
81
+ }
82
+ interface ThrusterFSMContext {
83
+ input: ThrusterInputComponent;
84
+ }
85
+ interface PlayerInput {
86
+ thrust: number;
87
+ rotate: number;
88
+ }
89
+ declare class ThrusterFSM {
90
+ private ctx;
91
+ machine: StateMachine<ThrusterState, ThrusterEvent, never>;
92
+ constructor(ctx: ThrusterFSMContext);
93
+ /**
94
+ * Get current state
95
+ */
96
+ getState(): ThrusterState;
97
+ /**
98
+ * Dispatch an event to transition state
99
+ */
100
+ dispatch(event: ThrusterEvent): void;
101
+ /**
102
+ * Update FSM state based on player input.
103
+ * Auto-transitions between Idle/Active to report current state.
104
+ * Does NOT modify input - just observes and reports.
105
+ */
106
+ update(playerInput: PlayerInput): void;
107
+ }
108
+
109
+ /**
110
+ * ThrusterMovementBehavior
111
+ *
112
+ * This is the heart of the thruster movement system - a pure, stateless force generator.
113
+ * Works identically for player, AI, and replay.
114
+ */
115
+
116
+ /**
117
+ * Zylem-style Behavior interface
118
+ */
119
+ interface Behavior {
120
+ update(dt: number): void;
121
+ }
122
+ /**
123
+ * Entity with thruster components
124
+ */
125
+ interface ThrusterEntity {
126
+ physics: PhysicsBodyComponent;
127
+ thruster: ThrusterMovementComponent;
128
+ $thruster: ThrusterInputComponent;
129
+ }
130
+ /**
131
+ * ThrusterMovementBehavior - Force generator for thruster-equipped entities
132
+ *
133
+ * Responsibilities:
134
+ * - Query entities with PhysicsBody, ThrusterMovement, and ThrusterInput components
135
+ * - Apply velocities based on thrust input (2D mode)
136
+ * - Apply angular velocity based on rotation input
137
+ */
138
+ declare class ThrusterMovementBehavior implements Behavior {
139
+ private world;
140
+ constructor(world: ZylemWorld);
141
+ /**
142
+ * Query function - returns entities with required thruster components
143
+ */
144
+ private queryEntities;
145
+ update(_dt: number): void;
146
+ }
147
+
148
+ /**
149
+ * Thruster behavior options (typed for entity.use() autocomplete)
150
+ */
151
+ interface ThrusterBehaviorOptions {
152
+ /** Forward thrust force (default: 10) */
153
+ linearThrust: number;
154
+ /** Rotation torque (default: 5) */
155
+ angularThrust: number;
156
+ }
157
+ /**
158
+ * ThrusterBehavior - typed descriptor for thruster movement.
159
+ *
160
+ * Uses the existing ThrusterMovementBehavior under the hood.
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * import { ThrusterBehavior } from "@zylem/game-lib";
165
+ *
166
+ * const ship = createSprite({ ... });
167
+ * ship.use(ThrusterBehavior, { linearThrust: 15, angularThrust: 8 });
168
+ * ```
169
+ */
170
+ declare const ThrusterBehavior: BehaviorDescriptor<ThrusterBehaviorOptions, Record<string, never>, ThrusterEntity>;
171
+
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 };
@@ -0,0 +1,31 @@
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-BpbZqg19.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
+ declare class ZylemWorld implements Entity<ZylemWorld> {
14
+ type: string;
15
+ world: World;
16
+ collisionMap: Map<string, GameEntity<any>>;
17
+ collisionBehaviorMap: Map<string, GameEntity<any>>;
18
+ _removalMap: Map<string, GameEntity<any>>;
19
+ static loadPhysics(gravity: Vector3): Promise<RAPIER__default.World>;
20
+ constructor(world: World);
21
+ addEntity(entity: any): void;
22
+ setForRemoval(entity: any): void;
23
+ destroyEntity(entity: GameEntity<any>): void;
24
+ setup(): void;
25
+ update(params: UpdateContext<any>): void;
26
+ updatePostCollisionBehaviors(delta: number): void;
27
+ updateColliders(delta: number): void;
28
+ destroy(): void;
29
+ }
30
+
31
+ 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.0",
3
+ "version": "0.6.3",
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",
@@ -42,9 +42,25 @@
42
42
  "types": "./dist/actions.d.ts",
43
43
  "import": "./dist/actions.js"
44
44
  },
45
- "./behaviors": {
46
- "types": "./dist/behaviors.d.ts",
47
- "import": "./dist/behaviors.js"
45
+ "./behavior/thruster": {
46
+ "types": "./dist/behavior/thruster.d.ts",
47
+ "import": "./dist/behavior/thruster.js"
48
+ },
49
+ "./behavior/screen-wrap": {
50
+ "types": "./dist/behavior/screen-wrap.d.ts",
51
+ "import": "./dist/behavior/screen-wrap.js"
52
+ },
53
+ "./behavior/world-boundary-2d": {
54
+ "types": "./dist/behavior/world-boundary-2d.d.ts",
55
+ "import": "./dist/behavior/world-boundary-2d.js"
56
+ },
57
+ "./behavior/ricochet-2d": {
58
+ "types": "./dist/behavior/ricochet-2d.d.ts",
59
+ "import": "./dist/behavior/ricochet-2d.js"
60
+ },
61
+ "./behavior/platformer-3d": {
62
+ "types": "./dist/behavior/platformer-3d.d.ts",
63
+ "import": "./dist/behavior/platformer-3d.js"
48
64
  }
49
65
  },
50
66
  "keywords": [
@@ -76,6 +92,7 @@
76
92
  "nanoid": "^5.1.5",
77
93
  "stats.js": "^0.17.0",
78
94
  "three": "^0.180.0",
95
+ "typescript-fsm": "^1.6.0",
79
96
  "valtio": "^2.1.7"
80
97
  },
81
98
  "peerDependencies": {
@@ -1,106 +0,0 @@
1
- import { G as GameEntity, m as CollisionContext, U as UpdateContext, B as BehaviorCallbackType } from './entity-COvRtFNG.js';
2
- import { M as MoveableEntity } from './moveable-B_vyA6cw.js';
3
- import { Vector } from '@dimforge/rapier3d-compat';
4
- import 'three';
5
- import 'bitecs';
6
-
7
- /**
8
- * A branded bitmask representing a set of collision types.
9
- */
10
- type CollisionMask = number & {
11
- readonly __brand: "CollisionMask";
12
- };
13
- type NameSelector = string | string[] | RegExp;
14
- type CollisionSelector = {
15
- name: NameSelector;
16
- } | {
17
- mask: CollisionMask | RegExp;
18
- } | {
19
- test: (other: GameEntity<any>) => boolean;
20
- };
21
-
22
- /**
23
- * Behavior for ricocheting an entity off other objects in 2D
24
- */
25
- declare function ricochet2DCollision(options?: Partial<Ricochet2DCollisionOptions>, callback?: Ricochet2DCollisionCallback): {
26
- type: 'collision';
27
- handler: (ctx: CollisionContext<MoveableEntity, GameEntity<any>>) => void;
28
- };
29
-
30
- interface RicochetEvent extends Partial<UpdateContext<MoveableEntity>> {
31
- boundary?: 'top' | 'bottom' | 'left' | 'right';
32
- position: Vector;
33
- velocityBefore: Vector;
34
- velocityAfter: Vector;
35
- }
36
- interface RicochetCollisionEvent extends CollisionContext<MoveableEntity, GameEntity<any>> {
37
- position: Vector;
38
- }
39
- interface Ricochet2DInBoundsOptions {
40
- restitution?: number;
41
- minSpeed?: number;
42
- maxSpeed?: number;
43
- boundaries: {
44
- top: number;
45
- bottom: number;
46
- left: number;
47
- right: number;
48
- };
49
- separation?: number;
50
- }
51
- interface Ricochet2DCollisionOptions {
52
- restitution?: number;
53
- minSpeed?: number;
54
- maxSpeed?: number;
55
- separation?: number;
56
- collisionWith?: CollisionSelector;
57
- /**
58
- * Choose between simple axis inversion or angled (paddle-style) reflection.
59
- * Defaults to 'angled'.
60
- */
61
- reflectionMode?: 'simple' | 'angled';
62
- }
63
- type Ricochet2DCallback = (event: RicochetEvent) => void;
64
- type Ricochet2DCollisionCallback = (event: RicochetCollisionEvent) => void;
65
-
66
- /**
67
- * Behavior for ricocheting an entity within fixed 2D boundaries
68
- */
69
- declare function ricochet2DInBounds(options?: Partial<Ricochet2DInBoundsOptions>, callback?: Ricochet2DCallback): {
70
- type: BehaviorCallbackType;
71
- handler: (ctx: UpdateContext<MoveableEntity>) => void;
72
- };
73
-
74
- interface BoundaryEvent {
75
- me: MoveableEntity;
76
- boundary: BoundaryHits;
77
- position: Vector;
78
- updateContext: UpdateContext<MoveableEntity>;
79
- }
80
- interface BoundaryOptions {
81
- boundaries: {
82
- top: number;
83
- bottom: number;
84
- left: number;
85
- right: number;
86
- };
87
- onBoundary?: (event: BoundaryEvent) => void;
88
- stopMovement?: boolean;
89
- }
90
- /**
91
- * Checks if the entity has hit a boundary and stops its movement if it has
92
- *
93
- * @param options Configuration options for the boundary behavior
94
- * @param options.boundaries The boundaries of the stage
95
- * @param options.onBoundary A callback function that is called when the entity hits a boundary
96
- * @param options.stopMovement Whether to stop the entity's movement when it hits a boundary
97
- * @returns A behavior callback with type 'update' and a handler function
98
- */
99
- declare function boundary2d(options?: Partial<BoundaryOptions>): {
100
- type: BehaviorCallbackType;
101
- handler: (ctx: UpdateContext<MoveableEntity>) => void;
102
- };
103
- type BoundaryHit = 'top' | 'bottom' | 'left' | 'right';
104
- type BoundaryHits = Record<BoundaryHit, boolean>;
105
-
106
- export { boundary2d, ricochet2DCollision, ricochet2DInBounds };