@zylem/game-lib 0.5.1 → 0.6.2
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/dist/behaviors.d.ts +834 -88
- package/dist/behaviors.js +1166 -355
- package/dist/behaviors.js.map +1 -1
- package/dist/blueprints-Cq3Ko6_G.d.ts +26 -0
- package/dist/{camera-Dk-fOVZE.d.ts → camera-CeJPAgGg.d.ts} +20 -46
- package/dist/camera.d.ts +2 -2
- package/dist/camera.js +340 -129
- package/dist/camera.js.map +1 -1
- package/dist/{core-C2mjetAd.d.ts → core-bO8TzV7u.d.ts} +113 -44
- package/dist/core.d.ts +8 -5
- package/dist/core.js +6180 -3678
- package/dist/core.js.map +1 -1
- package/dist/entities-DvByhMGU.d.ts +306 -0
- package/dist/entities.d.ts +5 -267
- package/dist/entities.js +3239 -1893
- package/dist/entities.js.map +1 -1
- package/dist/entity-Bq_eNEDI.d.ts +28 -0
- package/dist/entity-types-DAu8sGJH.d.ts +26 -0
- package/dist/main.d.ts +147 -31
- package/dist/main.js +9364 -5479
- package/dist/main.js.map +1 -1
- package/dist/{stage-CrmY7V0i.d.ts → stage-types-Bd-KtcYT.d.ts} +149 -61
- package/dist/stage.d.ts +42 -20
- package/dist/stage.js +4103 -2027
- package/dist/stage.js.map +1 -1
- package/dist/world-C8tQ7Plj.d.ts +774 -0
- package/package.json +2 -1
- package/dist/entity-bQElAdpo.d.ts +0 -347
- package/dist/entity-spawner-DNnLYnZq.d.ts +0 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zylem/game-lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.2",
|
|
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",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"nanoid": "^5.1.5",
|
|
85
85
|
"stats.js": "^0.17.0",
|
|
86
86
|
"three": "^0.180.0",
|
|
87
|
+
"typescript-fsm": "^1.6.0",
|
|
87
88
|
"valtio": "^2.1.7"
|
|
88
89
|
},
|
|
89
90
|
"peerDependencies": {
|
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
import { Vector3, Vector2, Color, Material, BufferGeometry, Mesh, Group, ShaderMaterial } from 'three';
|
|
2
|
-
import { Vector3 as Vector3$1, RigidBodyDesc, ColliderDesc, RigidBody, Collider } from '@dimforge/rapier3d-compat';
|
|
3
|
-
import { IComponent } from 'bitecs';
|
|
4
|
-
|
|
5
|
-
/** Input
|
|
6
|
-
*
|
|
7
|
-
* Maximum number of local players is 8.
|
|
8
|
-
* All input can be mapped to a gamepad or keyboard but shares the common
|
|
9
|
-
* interface represented as a gamepad.
|
|
10
|
-
*/
|
|
11
|
-
type InputPlayerNumber = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
12
|
-
type InputPlayer = `p${InputPlayerNumber}`;
|
|
13
|
-
interface ButtonState {
|
|
14
|
-
pressed: boolean;
|
|
15
|
-
released: boolean;
|
|
16
|
-
held: number;
|
|
17
|
-
}
|
|
18
|
-
interface AnalogState {
|
|
19
|
-
value: number;
|
|
20
|
-
held: number;
|
|
21
|
-
}
|
|
22
|
-
interface InputGamepad {
|
|
23
|
-
playerNumber: InputPlayerNumber;
|
|
24
|
-
buttons: {
|
|
25
|
-
A: ButtonState;
|
|
26
|
-
B: ButtonState;
|
|
27
|
-
X: ButtonState;
|
|
28
|
-
Y: ButtonState;
|
|
29
|
-
Start: ButtonState;
|
|
30
|
-
Select: ButtonState;
|
|
31
|
-
L: ButtonState;
|
|
32
|
-
R: ButtonState;
|
|
33
|
-
};
|
|
34
|
-
directions: {
|
|
35
|
-
Up: ButtonState;
|
|
36
|
-
Down: ButtonState;
|
|
37
|
-
Left: ButtonState;
|
|
38
|
-
Right: ButtonState;
|
|
39
|
-
};
|
|
40
|
-
shoulders: {
|
|
41
|
-
LTrigger: ButtonState;
|
|
42
|
-
RTrigger: ButtonState;
|
|
43
|
-
};
|
|
44
|
-
axes: {
|
|
45
|
-
Horizontal: AnalogState;
|
|
46
|
-
Vertical: AnalogState;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
type Inputs = Record<InputPlayer, InputGamepad>;
|
|
50
|
-
|
|
51
|
-
type LoadingEvent = {
|
|
52
|
-
type: 'start' | 'progress' | 'complete';
|
|
53
|
-
message?: string;
|
|
54
|
-
progress?: number;
|
|
55
|
-
total?: number;
|
|
56
|
-
current?: number;
|
|
57
|
-
};
|
|
58
|
-
interface IGame<TGlobals extends Record<string, unknown> = any> {
|
|
59
|
-
start: () => Promise<this>;
|
|
60
|
-
nextStage: () => Promise<void>;
|
|
61
|
-
previousStage: () => Promise<void>;
|
|
62
|
-
reset: () => Promise<void>;
|
|
63
|
-
pause: () => Promise<void>;
|
|
64
|
-
resume: () => Promise<void>;
|
|
65
|
-
onLoading: (callback: (event: LoadingEvent) => void) => void;
|
|
66
|
-
loadStageFromId: (stageId: string) => Promise<void>;
|
|
67
|
-
end: () => Promise<void>;
|
|
68
|
-
goToStage: () => void;
|
|
69
|
-
}
|
|
70
|
-
interface IStage {
|
|
71
|
-
onUpdate: (callback: UpdateFunction<IStage>) => void;
|
|
72
|
-
onSetup: (callback: SetupFunction<IStage>) => void;
|
|
73
|
-
onDestroy: (callback: DestroyFunction<IStage>) => void;
|
|
74
|
-
}
|
|
75
|
-
interface ICamera {
|
|
76
|
-
move: (position: Vector3) => void;
|
|
77
|
-
rotate: (pitch: number, yaw: number, roll: number) => void;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
type GlobalRecord = Record<string, unknown>;
|
|
81
|
-
/** Setup */
|
|
82
|
-
interface SetupContext<T, TGlobals extends GlobalRecord = any> {
|
|
83
|
-
me: T;
|
|
84
|
-
globals: TGlobals;
|
|
85
|
-
inputs?: Inputs;
|
|
86
|
-
camera?: ICamera;
|
|
87
|
-
stage?: IStage;
|
|
88
|
-
game?: IGame<TGlobals>;
|
|
89
|
-
}
|
|
90
|
-
interface SetupFunction<T, TGlobals extends GlobalRecord = any> {
|
|
91
|
-
(context: SetupContext<T, TGlobals>): void;
|
|
92
|
-
}
|
|
93
|
-
/** Loaded */
|
|
94
|
-
interface LoadedContext<T, TGlobals extends GlobalRecord = any> {
|
|
95
|
-
me: T;
|
|
96
|
-
globals: TGlobals;
|
|
97
|
-
}
|
|
98
|
-
interface LoadedFunction<T, TGlobals extends GlobalRecord = any> {
|
|
99
|
-
(context: LoadedContext<T, TGlobals>): void;
|
|
100
|
-
}
|
|
101
|
-
/** Update */
|
|
102
|
-
type UpdateContext<T, TGlobals extends GlobalRecord = any> = {
|
|
103
|
-
me: T;
|
|
104
|
-
delta: number;
|
|
105
|
-
inputs: Inputs;
|
|
106
|
-
globals: TGlobals;
|
|
107
|
-
camera: ICamera;
|
|
108
|
-
stage?: IStage;
|
|
109
|
-
game?: IGame<TGlobals>;
|
|
110
|
-
};
|
|
111
|
-
interface UpdateFunction<T, TGlobals extends GlobalRecord = any> {
|
|
112
|
-
(context: UpdateContext<T, TGlobals>): void;
|
|
113
|
-
}
|
|
114
|
-
/** Destroy */
|
|
115
|
-
interface DestroyContext<T, TGlobals extends GlobalRecord = any> {
|
|
116
|
-
me: T;
|
|
117
|
-
globals: TGlobals;
|
|
118
|
-
}
|
|
119
|
-
interface DestroyFunction<T, TGlobals extends GlobalRecord = any> {
|
|
120
|
-
(context: DestroyContext<T, TGlobals>): void;
|
|
121
|
-
}
|
|
122
|
-
/** Cleanup */
|
|
123
|
-
interface CleanupContext<T, TGlobals extends GlobalRecord = any> {
|
|
124
|
-
me: T;
|
|
125
|
-
globals: TGlobals;
|
|
126
|
-
}
|
|
127
|
-
interface CleanupFunction<T, TGlobals extends GlobalRecord = any> {
|
|
128
|
-
(context: CleanupContext<T, TGlobals>): void;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
interface NodeInterface {
|
|
132
|
-
uuid: string;
|
|
133
|
-
name: string;
|
|
134
|
-
markedForRemoval: boolean;
|
|
135
|
-
nodeSetup(params: SetupContext<any>): void;
|
|
136
|
-
nodeUpdate(params: UpdateContext<any>): void;
|
|
137
|
-
nodeDestroy(params: DestroyContext<any>): void;
|
|
138
|
-
setParent(parent: NodeInterface | null): void;
|
|
139
|
-
getParent(): NodeInterface | null;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
type BaseNodeOptions<T = any> = BaseNode | Partial<T>;
|
|
143
|
-
declare abstract class BaseNode<Options = any, T = any> implements NodeInterface {
|
|
144
|
-
protected parent: NodeInterface | null;
|
|
145
|
-
protected children: NodeInterface[];
|
|
146
|
-
options: Options;
|
|
147
|
-
eid: number;
|
|
148
|
-
uuid: string;
|
|
149
|
-
name: string;
|
|
150
|
-
markedForRemoval: boolean;
|
|
151
|
-
setup: SetupFunction<this>;
|
|
152
|
-
loaded: LoadedFunction<this>;
|
|
153
|
-
update: UpdateFunction<this>;
|
|
154
|
-
destroy: DestroyFunction<this>;
|
|
155
|
-
cleanup: CleanupFunction<this>;
|
|
156
|
-
constructor(args?: BaseNodeOptions[]);
|
|
157
|
-
setParent(parent: NodeInterface | null): void;
|
|
158
|
-
getParent(): NodeInterface | null;
|
|
159
|
-
add(baseNode: NodeInterface): void;
|
|
160
|
-
remove(baseNode: NodeInterface): void;
|
|
161
|
-
getChildren(): NodeInterface[];
|
|
162
|
-
isComposite(): boolean;
|
|
163
|
-
abstract create(): T;
|
|
164
|
-
protected abstract _setup(params: SetupContext<this>): void;
|
|
165
|
-
protected abstract _loaded(params: LoadedContext<this>): Promise<void>;
|
|
166
|
-
protected abstract _update(params: UpdateContext<this>): void;
|
|
167
|
-
protected abstract _destroy(params: DestroyContext<this>): void;
|
|
168
|
-
protected abstract _cleanup(params: CleanupContext<this>): Promise<void>;
|
|
169
|
-
nodeSetup(params: SetupContext<this>): void;
|
|
170
|
-
nodeUpdate(params: UpdateContext<this>): void;
|
|
171
|
-
nodeDestroy(params: DestroyContext<this>): void;
|
|
172
|
-
getOptions(): Options;
|
|
173
|
-
setOptions(options: Partial<Options>): void;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
type Vec3 = Vector3 | Vector3$1;
|
|
177
|
-
|
|
178
|
-
declare function shortHash(objString: string): string;
|
|
179
|
-
|
|
180
|
-
type ZylemShaderType = 'standard' | 'fire' | 'star' | 'debug';
|
|
181
|
-
|
|
182
|
-
interface MaterialOptions {
|
|
183
|
-
path?: string;
|
|
184
|
-
repeat?: Vector2;
|
|
185
|
-
shader?: ZylemShaderType;
|
|
186
|
-
color?: Color;
|
|
187
|
-
}
|
|
188
|
-
type BatchGeometryMap = Map<symbol, number>;
|
|
189
|
-
interface BatchMaterialMapObject {
|
|
190
|
-
geometryMap: BatchGeometryMap;
|
|
191
|
-
material: Material;
|
|
192
|
-
}
|
|
193
|
-
type BatchKey = ReturnType<typeof shortHash>;
|
|
194
|
-
type TexturePath = string | null;
|
|
195
|
-
declare class MaterialBuilder {
|
|
196
|
-
static batchMaterialMap: Map<BatchKey, BatchMaterialMapObject>;
|
|
197
|
-
materials: Material[];
|
|
198
|
-
batchMaterial(options: Partial<MaterialOptions>, entityType: symbol): void;
|
|
199
|
-
build(options: Partial<MaterialOptions>, entityType: symbol): Promise<void>;
|
|
200
|
-
withColor(color: Color): this;
|
|
201
|
-
withShader(shaderType: ZylemShaderType): this;
|
|
202
|
-
setTexture(texturePath?: TexturePath, repeat?: Vector2): Promise<void>;
|
|
203
|
-
setColor(color: Color): void;
|
|
204
|
-
setShader(customShader: ZylemShaderType): void;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
interface CollisionOptions {
|
|
208
|
-
static?: boolean;
|
|
209
|
-
sensor?: boolean;
|
|
210
|
-
size?: Vector3;
|
|
211
|
-
position?: Vector3;
|
|
212
|
-
collisionType?: string;
|
|
213
|
-
collisionFilter?: string[];
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
declare class CollisionBuilder {
|
|
217
|
-
static: boolean;
|
|
218
|
-
sensor: boolean;
|
|
219
|
-
gravity: Vec3;
|
|
220
|
-
build(options: Partial<CollisionOptions>): [RigidBodyDesc, ColliderDesc];
|
|
221
|
-
withCollision(collisionOptions: Partial<CollisionOptions>): this;
|
|
222
|
-
collider(options: CollisionOptions): ColliderDesc;
|
|
223
|
-
bodyDesc({ isDynamicBody }: {
|
|
224
|
-
isDynamicBody?: boolean | undefined;
|
|
225
|
-
}): RigidBodyDesc;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* TODO: allow for multiple materials requires geometry groups
|
|
230
|
-
* TODO: allow for instanced uniforms
|
|
231
|
-
* TODO: allow for geometry groups
|
|
232
|
-
* TODO: allow for batched meshes
|
|
233
|
-
* import { InstancedUniformsMesh } from 'three-instanced-uniforms-mesh';
|
|
234
|
-
* may not need geometry groups for shaders though
|
|
235
|
-
* setGeometry<T extends BufferGeometry>(geometry: T) {
|
|
236
|
-
* MeshBuilder.bachedMesh = new BatchedMesh(10, 5000, 10000, material);
|
|
237
|
-
* }
|
|
238
|
-
*/
|
|
239
|
-
type MeshBuilderOptions = Partial<Pick<GameEntityOptions, 'batched' | 'material'>>;
|
|
240
|
-
declare class MeshBuilder {
|
|
241
|
-
_build(meshOptions: MeshBuilderOptions, geometry: BufferGeometry, materials: Material[]): Mesh;
|
|
242
|
-
_postBuild(): void;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
declare abstract class EntityCollisionBuilder extends CollisionBuilder {
|
|
246
|
-
abstract collider(options: GameEntityOptions): ColliderDesc;
|
|
247
|
-
}
|
|
248
|
-
declare abstract class EntityMeshBuilder extends MeshBuilder {
|
|
249
|
-
build(options: GameEntityOptions): BufferGeometry;
|
|
250
|
-
postBuild(): void;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
interface Behavior {
|
|
254
|
-
component: IComponent;
|
|
255
|
-
values: any;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
interface LifeCycleDelegate<U> {
|
|
259
|
-
setup?: ((params: SetupContext<U>) => void)[];
|
|
260
|
-
update?: ((params: UpdateContext<U>) => void)[];
|
|
261
|
-
destroy?: ((params: DestroyContext<U>) => void)[];
|
|
262
|
-
}
|
|
263
|
-
interface CollisionContext<T, O extends GameEntityOptions, TGlobals extends Record<string, unknown> = any> {
|
|
264
|
-
entity: T;
|
|
265
|
-
other: GameEntity<O>;
|
|
266
|
-
globals: TGlobals;
|
|
267
|
-
}
|
|
268
|
-
type BehaviorContext<T, O extends GameEntityOptions> = SetupContext<T, O> | UpdateContext<T, O> | CollisionContext<T, O> | DestroyContext<T, O>;
|
|
269
|
-
type BehaviorCallback<T, O extends GameEntityOptions> = (params: BehaviorContext<T, O>) => void;
|
|
270
|
-
interface CollisionDelegate<T, O extends GameEntityOptions> {
|
|
271
|
-
collision?: ((params: CollisionContext<T, O>) => void)[];
|
|
272
|
-
}
|
|
273
|
-
type IBuilder<BuilderOptions = any> = {
|
|
274
|
-
preBuild: (options: BuilderOptions) => BuilderOptions;
|
|
275
|
-
build: (options: BuilderOptions) => BuilderOptions;
|
|
276
|
-
postBuild: (options: BuilderOptions) => BuilderOptions;
|
|
277
|
-
};
|
|
278
|
-
type GameEntityOptions = {
|
|
279
|
-
name?: string;
|
|
280
|
-
color?: Color;
|
|
281
|
-
size?: Vec3;
|
|
282
|
-
position?: Vec3;
|
|
283
|
-
batched?: boolean;
|
|
284
|
-
collision?: Partial<CollisionOptions>;
|
|
285
|
-
material?: Partial<MaterialOptions>;
|
|
286
|
-
custom?: {
|
|
287
|
-
[key: string]: any;
|
|
288
|
-
};
|
|
289
|
-
collisionType?: string;
|
|
290
|
-
collisionGroup?: string;
|
|
291
|
-
collisionFilter?: string[];
|
|
292
|
-
_builders?: {
|
|
293
|
-
meshBuilder?: IBuilder | EntityMeshBuilder | null;
|
|
294
|
-
collisionBuilder?: IBuilder | EntityCollisionBuilder | null;
|
|
295
|
-
materialBuilder?: MaterialBuilder | null;
|
|
296
|
-
};
|
|
297
|
-
};
|
|
298
|
-
declare abstract class GameEntityLifeCycle {
|
|
299
|
-
abstract _setup(params: SetupContext<this>): void;
|
|
300
|
-
abstract _update(params: UpdateContext<this>): void;
|
|
301
|
-
abstract _destroy(params: DestroyContext<this>): void;
|
|
302
|
-
}
|
|
303
|
-
interface EntityDebugInfo {
|
|
304
|
-
buildInfo: () => Record<string, string>;
|
|
305
|
-
}
|
|
306
|
-
type BehaviorCallbackType = 'setup' | 'update' | 'destroy' | 'collision';
|
|
307
|
-
declare class GameEntity<O extends GameEntityOptions> extends BaseNode<O> implements GameEntityLifeCycle, EntityDebugInfo {
|
|
308
|
-
behaviors: Behavior[];
|
|
309
|
-
group: Group | undefined;
|
|
310
|
-
mesh: Mesh | undefined;
|
|
311
|
-
materials: Material[] | undefined;
|
|
312
|
-
bodyDesc: RigidBodyDesc | null;
|
|
313
|
-
body: RigidBody | null;
|
|
314
|
-
colliderDesc: ColliderDesc | undefined;
|
|
315
|
-
collider: Collider | undefined;
|
|
316
|
-
custom: Record<string, any>;
|
|
317
|
-
debugInfo: Record<string, any>;
|
|
318
|
-
debugMaterial: ShaderMaterial | undefined;
|
|
319
|
-
lifeCycleDelegate: LifeCycleDelegate<O>;
|
|
320
|
-
collisionDelegate: CollisionDelegate<this, O>;
|
|
321
|
-
collisionType?: string;
|
|
322
|
-
behaviorCallbackMap: Record<BehaviorCallbackType, BehaviorCallback<this, O>[]>;
|
|
323
|
-
constructor();
|
|
324
|
-
create(): this;
|
|
325
|
-
onSetup(...callbacks: ((params: SetupContext<this>) => void)[]): this;
|
|
326
|
-
onUpdate(...callbacks: ((params: UpdateContext<this>) => void)[]): this;
|
|
327
|
-
onDestroy(...callbacks: ((params: DestroyContext<this>) => void)[]): this;
|
|
328
|
-
onCollision(...callbacks: ((params: CollisionContext<this, O>) => void)[]): this;
|
|
329
|
-
_setup(params: SetupContext<this>): void;
|
|
330
|
-
protected _loaded(_params: LoadedContext<this>): Promise<void>;
|
|
331
|
-
_update(params: UpdateContext<this>): void;
|
|
332
|
-
_destroy(params: DestroyContext<this>): void;
|
|
333
|
-
protected _cleanup(_params: CleanupContext<this>): Promise<void>;
|
|
334
|
-
_collision(other: GameEntity<O>, globals?: any): void;
|
|
335
|
-
addBehavior(behaviorCallback: ({
|
|
336
|
-
type: BehaviorCallbackType;
|
|
337
|
-
handler: any;
|
|
338
|
-
})): this;
|
|
339
|
-
addBehaviors(behaviorCallbacks: ({
|
|
340
|
-
type: BehaviorCallbackType;
|
|
341
|
-
handler: any;
|
|
342
|
-
})[]): this;
|
|
343
|
-
protected updateMaterials(params: any): void;
|
|
344
|
-
buildInfo(): Record<string, string>;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
export { type AnalogState as A, type BehaviorCallbackType as B, type CleanupContext as C, type DestroyFunction as D, GameEntity as G, type InputGamepad as I, type LoadingEvent as L, type MaterialOptions as M, type SetupFunction as S, type TexturePath as T, type UpdateContext as U, type Vec3 as V, type Behavior as a, type UpdateFunction as b, type SetupContext as c, type DestroyContext as d, BaseNode as e, type InputPlayerNumber as f, type Inputs as g, type ButtonState as h, GameEntityLifeCycle as i, type IGame as j, type LoadedContext as k, type GameEntityOptions as l, type CollisionContext as m };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Vector2 } from 'three';
|
|
2
|
-
import { G as GameEntity } from './entity-bQElAdpo.js';
|
|
3
|
-
import { a as Stage } from './stage-CrmY7V0i.js';
|
|
4
|
-
|
|
5
|
-
interface EntitySpawner {
|
|
6
|
-
spawn: (stage: Stage, x: number, y: number) => Promise<GameEntity<any>>;
|
|
7
|
-
spawnRelative: (source: any, stage: Stage, offset?: Vector2) => Promise<any | void>;
|
|
8
|
-
}
|
|
9
|
-
declare function entitySpawner(factory: (x: number, y: number) => Promise<any> | GameEntity<any>): EntitySpawner;
|
|
10
|
-
|
|
11
|
-
export { entitySpawner as e };
|