@zylem/game-lib 0.6.2 → 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.
- package/LICENSE +21 -0
- package/README.md +9 -16
- package/dist/actions.d.ts +30 -21
- package/dist/actions.js +628 -145
- package/dist/actions.js.map +1 -1
- package/dist/behavior/platformer-3d.d.ts +296 -0
- package/dist/behavior/platformer-3d.js +518 -0
- package/dist/behavior/platformer-3d.js.map +1 -0
- package/dist/behavior/ricochet-2d.d.ts +274 -0
- package/dist/behavior/ricochet-2d.js +394 -0
- package/dist/behavior/ricochet-2d.js.map +1 -0
- package/dist/behavior/screen-wrap.d.ts +86 -0
- package/dist/behavior/screen-wrap.js +195 -0
- package/dist/behavior/screen-wrap.js.map +1 -0
- package/dist/behavior/thruster.d.ts +10 -0
- package/dist/behavior/thruster.js +234 -0
- package/dist/behavior/thruster.js.map +1 -0
- package/dist/behavior/world-boundary-2d.d.ts +141 -0
- package/dist/behavior/world-boundary-2d.js +181 -0
- package/dist/behavior/world-boundary-2d.js.map +1 -0
- package/dist/behavior-descriptor-BWNWmIjv.d.ts +142 -0
- package/dist/{blueprints-Cq3Ko6_G.d.ts → blueprints-BWGz8fII.d.ts} +2 -2
- package/dist/camera-B5e4c78l.d.ts +468 -0
- package/dist/camera.d.ts +3 -2
- package/dist/camera.js +900 -211
- package/dist/camera.js.map +1 -1
- package/dist/composition-DrzFrbqI.d.ts +218 -0
- package/dist/{core-bO8TzV7u.d.ts → core-DAkskq6Y.d.ts} +60 -62
- package/dist/core.d.ts +10 -6
- package/dist/core.js +6896 -5020
- package/dist/core.js.map +1 -1
- package/dist/{entities-DvByhMGU.d.ts → entities-DC9ce_vx.d.ts} +113 -3
- package/dist/entities.d.ts +5 -3
- package/dist/entities.js +3727 -3167
- package/dist/entities.js.map +1 -1
- package/dist/entity-BpbZqg19.d.ts +1100 -0
- package/dist/global-change-Dc8uCKi2.d.ts +25 -0
- package/dist/main.d.ts +418 -15
- package/dist/main.js +11384 -8515
- package/dist/main.js.map +1 -1
- package/dist/{stage-types-Bd-KtcYT.d.ts → stage-types-BFsm3qsZ.d.ts} +205 -13
- package/dist/stage.d.ts +10 -7
- package/dist/stage.js +5311 -3880
- package/dist/stage.js.map +1 -1
- package/dist/thruster-DhRaJnoL.d.ts +172 -0
- package/dist/world-Be5m1XC1.d.ts +31 -0
- package/package.json +29 -13
- package/dist/behaviors.d.ts +0 -854
- package/dist/behaviors.js +0 -1209
- package/dist/behaviors.js.map +0 -1
- package/dist/camera-CeJPAgGg.d.ts +0 -116
- package/dist/moveable-B_vyA6cw.d.ts +0 -67
- package/dist/transformable-CUhvyuYO.d.ts +0 -67
- package/dist/world-C8tQ7Plj.d.ts +0 -774
|
@@ -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.
|
|
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
|
-
"./
|
|
46
|
-
"types": "./dist/
|
|
47
|
-
"import": "./dist/
|
|
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": [
|
|
@@ -65,14 +81,6 @@
|
|
|
65
81
|
"files": [
|
|
66
82
|
"dist"
|
|
67
83
|
],
|
|
68
|
-
"scripts": {
|
|
69
|
-
"build": "tsup",
|
|
70
|
-
"dev": "tsup --watch",
|
|
71
|
-
"lint": "biome check .",
|
|
72
|
-
"typecheck": "tsc --noEmit",
|
|
73
|
-
"test": "vitest --reporter=verbose",
|
|
74
|
-
"coverage": "vitest run --coverage"
|
|
75
|
-
},
|
|
76
84
|
"dependencies": {
|
|
77
85
|
"@dimforge/rapier3d-compat": "^0.11.2",
|
|
78
86
|
"@sinclair/typebox": "^0.34.41",
|
|
@@ -106,5 +114,13 @@
|
|
|
106
114
|
"typescript": "5.8.2",
|
|
107
115
|
"vite-plugin-solid": "^2.11.8",
|
|
108
116
|
"vitest": "^4.0.9"
|
|
117
|
+
},
|
|
118
|
+
"scripts": {
|
|
119
|
+
"build": "tsup",
|
|
120
|
+
"dev": "tsup --watch",
|
|
121
|
+
"lint": "biome check .",
|
|
122
|
+
"typecheck": "tsc --noEmit",
|
|
123
|
+
"test": "vitest --reporter=verbose",
|
|
124
|
+
"coverage": "vitest run --coverage"
|
|
109
125
|
}
|
|
110
|
-
}
|
|
126
|
+
}
|