@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.
@@ -0,0 +1,306 @@
1
+ import { G as GameEntity, g as GameEntityOptions, b as UpdateContext, c as DestroyContext, B as BaseNode, T as TexturePath, A as CollisionHandlerDelegate, V as Vec3, M as MaterialOptions } from './world-C8tQ7Plj.js';
2
+ import { Vector3, Sprite, Color, Vector2, Object3D } from 'three';
3
+
4
+ type SpriteImage = {
5
+ name: string;
6
+ file: string;
7
+ };
8
+ type SpriteAnimation = {
9
+ name: string;
10
+ frames: string[];
11
+ speed: number | number[];
12
+ loop: boolean;
13
+ };
14
+ type ZylemSpriteOptions = GameEntityOptions & {
15
+ images?: SpriteImage[];
16
+ animations?: SpriteAnimation[];
17
+ size?: Vector3;
18
+ collisionSize?: Vector3;
19
+ };
20
+ declare const SPRITE_TYPE: unique symbol;
21
+ declare class ZylemSprite extends GameEntity<ZylemSpriteOptions> {
22
+ static type: symbol;
23
+ protected sprites: Sprite[];
24
+ protected spriteMap: Map<string, number>;
25
+ protected currentSpriteIndex: number;
26
+ protected animations: Map<string, any>;
27
+ protected currentAnimation: any;
28
+ protected currentAnimationFrame: string;
29
+ protected currentAnimationIndex: number;
30
+ protected currentAnimationTime: number;
31
+ constructor(options?: ZylemSpriteOptions);
32
+ create(): this;
33
+ protected createSpritesFromImages(images: SpriteImage[]): void;
34
+ protected createAnimations(animations: SpriteAnimation[]): void;
35
+ setSprite(key: string): void;
36
+ setAnimation(name: string, delta: number): void;
37
+ spriteUpdate(params: UpdateContext<ZylemSpriteOptions>): void;
38
+ spriteDestroy(params: DestroyContext<ZylemSpriteOptions>): void;
39
+ buildInfo(): Record<string, any>;
40
+ }
41
+ type SpriteOptions = BaseNode | Partial<ZylemSpriteOptions>;
42
+ declare function createSprite(...args: Array<SpriteOptions>): ZylemSprite;
43
+
44
+ type ZylemSphereOptions = GameEntityOptions & {
45
+ radius?: number;
46
+ };
47
+ declare const SPHERE_TYPE: unique symbol;
48
+ declare class ZylemSphere extends GameEntity<ZylemSphereOptions> {
49
+ static type: symbol;
50
+ constructor(options?: ZylemSphereOptions);
51
+ buildInfo(): Record<string, any>;
52
+ }
53
+ type SphereOptions = BaseNode | Partial<ZylemSphereOptions>;
54
+ declare function createSphere(...args: Array<SphereOptions>): ZylemSphere;
55
+
56
+ type ZylemRectOptions = GameEntityOptions & {
57
+ width?: number;
58
+ height?: number;
59
+ fillColor?: Color | string | null;
60
+ strokeColor?: Color | string | null;
61
+ strokeWidth?: number;
62
+ radius?: number;
63
+ padding?: number;
64
+ stickToViewport?: boolean;
65
+ screenPosition?: Vector2;
66
+ zDistance?: number;
67
+ anchor?: Vector2;
68
+ bounds?: {
69
+ screen?: {
70
+ x: number;
71
+ y: number;
72
+ width: number;
73
+ height: number;
74
+ };
75
+ world?: {
76
+ left: number;
77
+ right: number;
78
+ top: number;
79
+ bottom: number;
80
+ z?: number;
81
+ };
82
+ };
83
+ };
84
+ declare const RECT_TYPE: unique symbol;
85
+ declare class ZylemRect extends GameEntity<ZylemRectOptions> {
86
+ static type: symbol;
87
+ private _sprite;
88
+ private _mesh;
89
+ private _texture;
90
+ private _canvas;
91
+ private _ctx;
92
+ private _cameraRef;
93
+ private _lastCanvasW;
94
+ private _lastCanvasH;
95
+ constructor(options?: ZylemRectOptions);
96
+ private createSprite;
97
+ private redrawRect;
98
+ getWidth(): number;
99
+ getHeight(): number;
100
+ private roundedRectPath;
101
+ private toCssColor;
102
+ private rectSetup;
103
+ private rectUpdate;
104
+ private updateStickyTransform;
105
+ private worldToScreen;
106
+ private computeScreenBoundsFromOptions;
107
+ updateRect(options?: Partial<Pick<ZylemRectOptions, 'width' | 'height' | 'fillColor' | 'strokeColor' | 'strokeWidth' | 'radius'>>): void;
108
+ buildInfo(): Record<string, any>;
109
+ }
110
+ type RectOptions = BaseNode | Partial<ZylemRectOptions>;
111
+ declare function createRect(...args: Array<RectOptions>): ZylemRect;
112
+
113
+ type ZylemTextOptions = GameEntityOptions & {
114
+ text?: string;
115
+ fontFamily?: string;
116
+ fontSize?: number;
117
+ fontColor?: Color | string;
118
+ backgroundColor?: Color | string | null;
119
+ padding?: number;
120
+ stickToViewport?: boolean;
121
+ screenPosition?: Vector2;
122
+ zDistance?: number;
123
+ };
124
+ declare const TEXT_TYPE: unique symbol;
125
+ declare class ZylemText extends GameEntity<ZylemTextOptions> {
126
+ static type: symbol;
127
+ private _sprite;
128
+ private _texture;
129
+ private _canvas;
130
+ private _ctx;
131
+ private _cameraRef;
132
+ private _lastCanvasW;
133
+ private _lastCanvasH;
134
+ constructor(options?: ZylemTextOptions);
135
+ create(): this;
136
+ private createSprite;
137
+ private measureAndResizeCanvas;
138
+ private drawCenteredText;
139
+ private updateTexture;
140
+ private redrawText;
141
+ private toCssColor;
142
+ private textSetup;
143
+ private textUpdate;
144
+ private getResolution;
145
+ private getScreenPixels;
146
+ private computeWorldExtents;
147
+ private updateSpriteScale;
148
+ private updateStickyTransform;
149
+ updateText(_text: string): void;
150
+ buildInfo(): Record<string, any>;
151
+ /**
152
+ * Dispose of Three.js resources when the entity is destroyed.
153
+ */
154
+ private textDestroy;
155
+ }
156
+ type TextOptions = BaseNode | Partial<ZylemTextOptions>;
157
+ declare function createText(...args: Array<TextOptions>): ZylemText;
158
+
159
+ type ZylemBoxOptions = GameEntityOptions;
160
+ declare const BOX_TYPE: unique symbol;
161
+ declare class ZylemBox extends GameEntity<ZylemBoxOptions> {
162
+ static type: symbol;
163
+ constructor(options?: ZylemBoxOptions);
164
+ buildInfo(): Record<string, any>;
165
+ }
166
+ type BoxOptions = BaseNode | ZylemBoxOptions;
167
+ declare function createBox(...args: Array<BoxOptions>): ZylemBox;
168
+
169
+ type ZylemPlaneOptions = GameEntityOptions & {
170
+ tile?: Vector2;
171
+ repeat?: Vector2;
172
+ texture?: TexturePath;
173
+ subdivisions?: number;
174
+ randomizeHeight?: boolean;
175
+ heightMap?: number[];
176
+ heightScale?: number;
177
+ };
178
+ declare const PLANE_TYPE: unique symbol;
179
+ declare class ZylemPlane extends GameEntity<ZylemPlaneOptions> {
180
+ static type: symbol;
181
+ constructor(options?: ZylemPlaneOptions);
182
+ }
183
+ type PlaneOptions = BaseNode | Partial<ZylemPlaneOptions>;
184
+ declare function createPlane(...args: Array<PlaneOptions>): ZylemPlane;
185
+
186
+ type OnHeldParams = {
187
+ delta: number;
188
+ self: ZylemZone;
189
+ visitor: GameEntity<any>;
190
+ heldTime: number;
191
+ globals: any;
192
+ };
193
+ type OnEnterParams = Pick<OnHeldParams, 'self' | 'visitor' | 'globals'>;
194
+ type OnExitParams = Pick<OnHeldParams, 'self' | 'visitor' | 'globals'>;
195
+ type ZylemZoneOptions = GameEntityOptions & {
196
+ size?: Vector3;
197
+ static?: boolean;
198
+ onEnter?: (params: OnEnterParams) => void;
199
+ onHeld?: (params: OnHeldParams) => void;
200
+ onExit?: (params: OnExitParams) => void;
201
+ };
202
+ declare const ZONE_TYPE: unique symbol;
203
+ declare class ZylemZone extends GameEntity<ZylemZoneOptions> implements CollisionHandlerDelegate {
204
+ static type: symbol;
205
+ private _enteredZone;
206
+ private _exitedZone;
207
+ private _zoneEntities;
208
+ constructor(options?: ZylemZoneOptions);
209
+ handlePostCollision({ delta }: {
210
+ delta: number;
211
+ }): boolean;
212
+ handleIntersectionEvent({ other, delta }: {
213
+ other: any;
214
+ delta: number;
215
+ }): void;
216
+ onEnter(callback: (params: OnEnterParams) => void): this;
217
+ onHeld(callback: (params: OnHeldParams) => void): this;
218
+ onExit(callback: (params: OnExitParams) => void): this;
219
+ entered(other: any): void;
220
+ exited(delta: number, key: string): void;
221
+ held(delta: number, other: any): void;
222
+ }
223
+ type ZoneOptions = BaseNode | Partial<ZylemZoneOptions>;
224
+ declare function createZone(...args: Array<ZoneOptions>): ZylemZone;
225
+
226
+ interface EntityLoaderDelegate {
227
+ /** Initiates loading (may be async internally, but call returns immediately) */
228
+ load(): void;
229
+ /** Returns data synchronously (may be null if still loading) */
230
+ data(): any;
231
+ }
232
+
233
+ type AnimationOptions = {
234
+ key: string;
235
+ pauseAtEnd?: boolean;
236
+ pauseAtPercentage?: number;
237
+ fadeToKey?: string;
238
+ fadeDuration?: number;
239
+ };
240
+
241
+ /**
242
+ * Interface for entities that provide custom debug information
243
+ */
244
+ interface DebugInfoProvider {
245
+ getDebugInfo(): Record<string, any>;
246
+ }
247
+
248
+ type AnimationObject = {
249
+ key?: string;
250
+ path: string;
251
+ };
252
+ type CollisionShapeType = 'capsule' | 'model';
253
+ type ZylemActorOptions = GameEntityOptions & {
254
+ static?: boolean;
255
+ animations?: AnimationObject[];
256
+ models?: string[];
257
+ scale?: Vec3;
258
+ material?: MaterialOptions;
259
+ collisionShape?: CollisionShapeType;
260
+ };
261
+ declare const ACTOR_TYPE: unique symbol;
262
+ declare class ZylemActor extends GameEntity<ZylemActorOptions> implements EntityLoaderDelegate, DebugInfoProvider {
263
+ static type: symbol;
264
+ private _object;
265
+ private _animationDelegate;
266
+ private _modelFileNames;
267
+ private _assetLoader;
268
+ controlledRotation: boolean;
269
+ constructor(options?: ZylemActorOptions);
270
+ /**
271
+ * Initiates model and animation loading in background (deferred).
272
+ * Call returns immediately; assets will be ready on subsequent updates.
273
+ */
274
+ load(): void;
275
+ /**
276
+ * Returns current data synchronously.
277
+ * May return null values if loading is still in progress.
278
+ */
279
+ data(): any;
280
+ actorUpdate(params: UpdateContext<ZylemActorOptions>): void;
281
+ /**
282
+ * Clean up actor resources including animations, models, and groups
283
+ */
284
+ actorDestroy(): void;
285
+ /**
286
+ * Deferred loading - starts async load and updates entity when complete.
287
+ * Called by synchronous load() method.
288
+ */
289
+ private loadModelsDeferred;
290
+ playAnimation(animationOptions: AnimationOptions): void;
291
+ /**
292
+ * Apply material overrides from options to all meshes in the loaded model.
293
+ * Only applies if material options are explicitly specified (not just defaults).
294
+ */
295
+ private applyMaterialOverrides;
296
+ get object(): Object3D | null;
297
+ /**
298
+ * Provide custom debug information for the actor
299
+ * This will be merged with the default debug information
300
+ */
301
+ getDebugInfo(): Record<string, any>;
302
+ }
303
+ type ActorOptions = BaseNode | ZylemActorOptions;
304
+ declare function createActor(...args: Array<ActorOptions>): ZylemActor;
305
+
306
+ export { ACTOR_TYPE as A, BOX_TYPE as B, PLANE_TYPE as P, RECT_TYPE as R, SPRITE_TYPE as S, TEXT_TYPE as T, ZylemSprite as Z, SPHERE_TYPE as a, ZylemSphere as b, ZylemRect as c, ZylemText as d, ZylemBox as e, ZylemPlane as f, ZONE_TYPE as g, ZylemZone as h, ZylemActor as i, createBox as j, createSphere as k, createSprite as l, createPlane as m, createZone as n, createActor as o, createText as p, createRect as q };
@@ -1,269 +1,7 @@
1
- import { e as BaseNode, l as GameEntityOptions, V as Vec3, M as MaterialOptions, G as GameEntity, U as UpdateContext, T as TexturePath, d as DestroyContext } from './entity-bQElAdpo.js';
2
- import { Object3D, Vector2, Vector3, Sprite, Color } from 'three';
1
+ export { e as ZylemBox, o as createActor, j as createBox, m as createPlane, q as createRect, k as createSphere, l as createSprite, p as createText, n as createZone } from './entities-DvByhMGU.js';
2
+ import './world-C8tQ7Plj.js';
3
+ import 'three';
3
4
  import '@dimforge/rapier3d-compat';
5
+ import './entity-Bq_eNEDI.js';
4
6
  import 'bitecs';
5
-
6
- interface EntityLoaderDelegate {
7
- load(): Promise<void>;
8
- data(): any;
9
- }
10
-
11
- type AnimationOptions = {
12
- key: string;
13
- pauseAtEnd?: boolean;
14
- pauseAtPercentage?: number;
15
- fadeToKey?: string;
16
- fadeDuration?: number;
17
- };
18
-
19
- /**
20
- * Interface for entities that provide custom debug information
21
- */
22
- interface DebugInfoProvider {
23
- getDebugInfo(): Record<string, any>;
24
- }
25
-
26
- type AnimationObject = {
27
- key?: string;
28
- path: string;
29
- };
30
- type ZylemActorOptions = GameEntityOptions & {
31
- static?: boolean;
32
- animations?: AnimationObject[];
33
- models?: string[];
34
- scale?: Vec3;
35
- material?: MaterialOptions;
36
- };
37
- declare class ZylemActor extends GameEntity<ZylemActorOptions> implements EntityLoaderDelegate, DebugInfoProvider {
38
- static type: symbol;
39
- private _object;
40
- private _animationDelegate;
41
- private _modelFileNames;
42
- private _assetLoader;
43
- controlledRotation: boolean;
44
- constructor(options?: ZylemActorOptions);
45
- load(): Promise<void>;
46
- data(): Promise<any>;
47
- actorUpdate(params: UpdateContext<ZylemActorOptions>): Promise<void>;
48
- private loadModels;
49
- playAnimation(animationOptions: AnimationOptions): void;
50
- get object(): Object3D | null;
51
- /**
52
- * Provide custom debug information for the actor
53
- * This will be merged with the default debug information
54
- */
55
- getDebugInfo(): Record<string, any>;
56
- }
57
- type ActorOptions = BaseNode | ZylemActorOptions;
58
- declare function actor(...args: Array<ActorOptions>): Promise<ZylemActor>;
59
-
60
- type ZylemBoxOptions = GameEntityOptions;
61
- declare class ZylemBox extends GameEntity<ZylemBoxOptions> {
62
- static type: symbol;
63
- constructor(options?: ZylemBoxOptions);
64
- buildInfo(): Record<string, any>;
65
- }
66
- type BoxOptions = BaseNode | ZylemBoxOptions;
67
- declare function box(...args: Array<BoxOptions>): Promise<ZylemBox>;
68
-
69
- type ZylemPlaneOptions = GameEntityOptions & {
70
- tile?: Vector2;
71
- repeat?: Vector2;
72
- texture?: TexturePath;
73
- subdivisions?: number;
74
- };
75
- declare class ZylemPlane extends GameEntity<ZylemPlaneOptions> {
76
- static type: symbol;
77
- constructor(options?: ZylemPlaneOptions);
78
- }
79
- type PlaneOptions = BaseNode | Partial<ZylemPlaneOptions>;
80
- declare function plane(...args: Array<PlaneOptions>): Promise<ZylemPlane>;
81
-
82
- type ZylemSphereOptions = GameEntityOptions & {
83
- radius?: number;
84
- };
85
- declare class ZylemSphere extends GameEntity<ZylemSphereOptions> {
86
- static type: symbol;
87
- constructor(options?: ZylemSphereOptions);
88
- buildInfo(): Record<string, any>;
89
- }
90
- type SphereOptions = BaseNode | Partial<ZylemSphereOptions>;
91
- declare function sphere(...args: Array<SphereOptions>): Promise<ZylemSphere>;
92
-
93
- type SpriteImage = {
94
- name: string;
95
- file: string;
96
- };
97
- type SpriteAnimation = {
98
- name: string;
99
- frames: string[];
100
- speed: number | number[];
101
- loop: boolean;
102
- };
103
- type ZylemSpriteOptions = GameEntityOptions & {
104
- images?: SpriteImage[];
105
- animations?: SpriteAnimation[];
106
- size?: Vector3;
107
- collisionSize?: Vector3;
108
- };
109
- declare class ZylemSprite extends GameEntity<ZylemSpriteOptions> {
110
- static type: symbol;
111
- protected sprites: Sprite[];
112
- protected spriteMap: Map<string, number>;
113
- protected currentSpriteIndex: number;
114
- protected animations: Map<string, any>;
115
- protected currentAnimation: any;
116
- protected currentAnimationFrame: string;
117
- protected currentAnimationIndex: number;
118
- protected currentAnimationTime: number;
119
- constructor(options?: ZylemSpriteOptions);
120
- protected createSpritesFromImages(images: SpriteImage[]): void;
121
- protected createAnimations(animations: SpriteAnimation[]): void;
122
- setSprite(key: string): void;
123
- setAnimation(name: string, delta: number): void;
124
- spriteUpdate(params: UpdateContext<ZylemSpriteOptions>): Promise<void>;
125
- spriteDestroy(params: DestroyContext<ZylemSpriteOptions>): Promise<void>;
126
- buildInfo(): Record<string, any>;
127
- }
128
- type SpriteOptions = BaseNode | Partial<ZylemSpriteOptions>;
129
- declare function sprite(...args: Array<SpriteOptions>): Promise<ZylemSprite>;
130
-
131
- interface CollisionHandlerDelegate {
132
- handlePostCollision(params: any): boolean;
133
- handleIntersectionEvent(params: any): void;
134
- }
135
-
136
- type OnHeldParams = {
137
- delta: number;
138
- self: ZylemZone;
139
- visitor: GameEntity<any>;
140
- heldTime: number;
141
- globals: any;
142
- };
143
- type OnEnterParams = Pick<OnHeldParams, 'self' | 'visitor' | 'globals'>;
144
- type OnExitParams = Pick<OnHeldParams, 'self' | 'visitor' | 'globals'>;
145
- type ZylemZoneOptions = GameEntityOptions & {
146
- size?: Vector3;
147
- static?: boolean;
148
- onEnter?: (params: OnEnterParams) => void;
149
- onHeld?: (params: OnHeldParams) => void;
150
- onExit?: (params: OnExitParams) => void;
151
- };
152
- declare class ZylemZone extends GameEntity<ZylemZoneOptions> implements CollisionHandlerDelegate {
153
- static type: symbol;
154
- private _enteredZone;
155
- private _exitedZone;
156
- private _zoneEntities;
157
- constructor(options?: ZylemZoneOptions);
158
- handlePostCollision({ delta }: {
159
- delta: number;
160
- }): boolean;
161
- handleIntersectionEvent({ other, delta }: {
162
- other: any;
163
- delta: number;
164
- }): void;
165
- onEnter(callback: (params: OnEnterParams) => void): this;
166
- onHeld(callback: (params: OnHeldParams) => void): this;
167
- onExit(callback: (params: OnExitParams) => void): this;
168
- entered(other: any): void;
169
- exited(delta: number, key: string): void;
170
- held(delta: number, other: any): void;
171
- }
172
- type ZoneOptions = BaseNode | Partial<ZylemZoneOptions>;
173
- declare function zone(...args: Array<ZoneOptions>): Promise<ZylemZone>;
174
-
175
- type ZylemTextOptions = GameEntityOptions & {
176
- text?: string;
177
- fontFamily?: string;
178
- fontSize?: number;
179
- fontColor?: Color | string;
180
- backgroundColor?: Color | string | null;
181
- padding?: number;
182
- stickToViewport?: boolean;
183
- screenPosition?: Vector2;
184
- zDistance?: number;
185
- };
186
- declare class ZylemText extends GameEntity<ZylemTextOptions> {
187
- static type: symbol;
188
- private _sprite;
189
- private _texture;
190
- private _canvas;
191
- private _ctx;
192
- private _cameraRef;
193
- private _lastCanvasW;
194
- private _lastCanvasH;
195
- constructor(options?: ZylemTextOptions);
196
- private createSprite;
197
- private measureAndResizeCanvas;
198
- private drawCenteredText;
199
- private updateTexture;
200
- private redrawText;
201
- private toCssColor;
202
- private textSetup;
203
- private textUpdate;
204
- private getResolution;
205
- private getScreenPixels;
206
- private computeWorldExtents;
207
- private updateSpriteScale;
208
- private updateStickyTransform;
209
- updateText(_text: string): void;
210
- buildInfo(): Record<string, any>;
211
- }
212
- type TextOptions = BaseNode | Partial<ZylemTextOptions>;
213
- declare function text(...args: Array<TextOptions>): Promise<ZylemText>;
214
-
215
- type ZylemRectOptions = GameEntityOptions & {
216
- width?: number;
217
- height?: number;
218
- fillColor?: Color | string | null;
219
- strokeColor?: Color | string | null;
220
- strokeWidth?: number;
221
- radius?: number;
222
- padding?: number;
223
- stickToViewport?: boolean;
224
- screenPosition?: Vector2;
225
- zDistance?: number;
226
- anchor?: Vector2;
227
- bounds?: {
228
- screen?: {
229
- x: number;
230
- y: number;
231
- width: number;
232
- height: number;
233
- };
234
- world?: {
235
- left: number;
236
- right: number;
237
- top: number;
238
- bottom: number;
239
- z?: number;
240
- };
241
- };
242
- };
243
- declare class ZylemRect extends GameEntity<ZylemRectOptions> {
244
- static type: symbol;
245
- private _sprite;
246
- private _mesh;
247
- private _texture;
248
- private _canvas;
249
- private _ctx;
250
- private _cameraRef;
251
- private _lastCanvasW;
252
- private _lastCanvasH;
253
- constructor(options?: ZylemRectOptions);
254
- private createSprite;
255
- private redrawRect;
256
- private roundedRectPath;
257
- private toCssColor;
258
- private rectSetup;
259
- private rectUpdate;
260
- private updateStickyTransform;
261
- private worldToScreen;
262
- private computeScreenBoundsFromOptions;
263
- updateRect(options?: Partial<Pick<ZylemRectOptions, 'width' | 'height' | 'fillColor' | 'strokeColor' | 'strokeWidth' | 'radius'>>): void;
264
- buildInfo(): Record<string, any>;
265
- }
266
- type RectOptions = BaseNode | Partial<ZylemRectOptions>;
267
- declare function rect(...args: Array<RectOptions>): Promise<ZylemRect>;
268
-
269
- export { ZylemBox, actor, box, plane, rect, sphere, sprite, text, zone };
7
+ import 'mitt';