@zylem/game-lib 0.3.16 → 0.3.17

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 (50) hide show
  1. package/README.md +38 -13
  2. package/dist/.vite/manifest.json +82 -12
  3. package/dist/core.d.ts +1 -1
  4. package/dist/lib/core/base-node-life-cycle.d.ts +14 -0
  5. package/dist/lib/core/base-node.d.ts +6 -2
  6. package/dist/lib/core/base-node.js +6 -2
  7. package/dist/lib/core/lazy-loader.d.ts +2 -2
  8. package/dist/lib/core/utility/nodes.d.ts +11 -0
  9. package/dist/lib/core/utility/nodes.js +27 -0
  10. package/dist/lib/core/utility/strings.d.ts +2 -0
  11. package/dist/lib/core/utility/strings.js +14 -0
  12. package/dist/lib/core/{utility.d.ts → utility/vector.d.ts} +0 -2
  13. package/dist/lib/core/utility/vector.js +8 -0
  14. package/dist/lib/core/vessel.d.ts +3 -1
  15. package/dist/lib/core/vessel.js +13 -9
  16. package/dist/lib/device/aspect-ratio.d.ts +37 -0
  17. package/dist/lib/device/aspect-ratio.js +44 -0
  18. package/dist/lib/entities/entity.d.ts +3 -1
  19. package/dist/lib/entities/entity.js +9 -5
  20. package/dist/lib/game/game-blueprint.d.ts +44 -0
  21. package/dist/lib/game/game-canvas.d.ts +34 -0
  22. package/dist/lib/game/game-canvas.js +57 -0
  23. package/dist/lib/game/game-config.d.ts +47 -0
  24. package/dist/lib/game/game-config.js +53 -0
  25. package/dist/lib/game/game-default.d.ts +18 -0
  26. package/dist/lib/game/game-default.js +24 -0
  27. package/dist/lib/game/game.d.ts +2 -5
  28. package/dist/lib/game/game.js +48 -72
  29. package/dist/lib/game/zylem-game.d.ts +12 -1
  30. package/dist/lib/game/zylem-game.js +55 -29
  31. package/dist/lib/graphics/material.d.ts +1 -1
  32. package/dist/lib/graphics/material.js +1 -1
  33. package/dist/lib/graphics/zylem-scene.d.ts +7 -7
  34. package/dist/lib/graphics/zylem-scene.js +26 -40
  35. package/dist/lib/stage/stage-blueprint.d.ts +44 -0
  36. package/dist/lib/stage/stage-blueprint.js +56 -0
  37. package/dist/lib/stage/stage-default.d.ts +9 -0
  38. package/dist/lib/stage/stage-default.js +42 -0
  39. package/dist/lib/stage/stage.d.ts +2 -2
  40. package/dist/lib/stage/stage.js +7 -5
  41. package/dist/lib/stage/zylem-stage.d.ts +4 -3
  42. package/dist/lib/stage/zylem-stage.js +38 -49
  43. package/dist/main.d.ts +2 -1
  44. package/dist/main.js +50 -48
  45. package/dist/stage.d.ts +3 -0
  46. package/dist/stage.js +20 -4
  47. package/dist/tests/stage/stage-blueprint.spec.d.ts +1 -0
  48. package/package.json +1 -1
  49. package/dist/lib/core/game-canvas.d.ts +0 -4
  50. package/dist/lib/core/utility.js +0 -20
package/README.md CHANGED
@@ -31,14 +31,9 @@ pnpm install
31
31
  npm run dev
32
32
  ```
33
33
 
34
- ## Examples
34
+ ## Getting started with a basic game
35
35
 
36
- >Note: The examples are not up to date with the latest version of Zylem.
37
- [Check out the examples repo here](https://github.com/tcool86/zylem-examples/tree/master)
38
-
39
- ## Basic Usage
40
-
41
- [Basic usage repo here](https://github.com/tcool86/zylem-basic)
36
+ [Basic example](https://github.com/zylem-game-lib/zylem-basic)
42
37
 
43
38
  ```html
44
39
  <!DOCTYPE html>
@@ -56,13 +51,43 @@ npm run dev
56
51
  ```
57
52
 
58
53
  ```typescript
59
- import { game, sphere, makeMoveable } from '@tcool86/zylem';
60
-
61
- const ball = await sphere();
62
- makeMoveable(ball).onUpdate(({ entity, inputs }) => {
63
- const { Horizontal, Vertical } = inputs.p1.axes;
64
- entity.moveXY(Horizontal.value * 5, -Vertical.value * 5);
54
+ /**
55
+ * @author: Tim Cool
56
+ *
57
+ * @description: basic ball movement
58
+ * the ball can be controlled with the arrow keys or gamepad
59
+ * the ball cannot go outside the boundaries
60
+ */
61
+ import { boundary2d, game, makeMoveable, sphere } from '@zylem/game-lib';
62
+
63
+ // Creates a moveable sphere
64
+ const ball = makeMoveable(await sphere());
65
+
66
+ // when the ball is updated, move it based on the inputs
67
+ ball.onUpdate(({ me, inputs, delta }) => {
68
+ // get the horizontal and vertical inputs from player one's controller
69
+ const { Horizontal, Vertical } = inputs.p1.axes;
70
+ // set the speed of the ball based on the delta time for smoother movement
71
+ const speed = 600 * delta;
72
+ // move the ball based on the inputs and the speed
73
+ me.moveXY(
74
+ Horizontal.value * speed,
75
+ -Vertical.value * speed
76
+ );
65
77
  });
66
78
 
79
+ // add a boundary behavior to the ball
80
+ ball.addBehavior(
81
+ boundary2d({
82
+ boundaries: {
83
+ top: 3,
84
+ bottom: -3,
85
+ left: -6,
86
+ right: 6,
87
+ },
88
+ })
89
+ );
90
+
91
+ // start the game with the ball
67
92
  game(ball).start();
68
93
  ```
@@ -210,10 +210,28 @@
210
210
  "name": "lib/core/three-addons/Timer",
211
211
  "src": "src/lib/core/three-addons/Timer.ts"
212
212
  },
213
- "src/lib/core/utility.ts": {
214
- "file": "lib/core/utility.js",
215
- "name": "lib/core/utility",
216
- "src": "src/lib/core/utility.ts"
213
+ "src/lib/core/utility/nodes.ts": {
214
+ "file": "lib/core/utility/nodes.js",
215
+ "name": "lib/core/utility/nodes",
216
+ "src": "src/lib/core/utility/nodes.ts",
217
+ "imports": [
218
+ "src/lib/core/base-node.ts",
219
+ "src/lib/stage/stage.ts",
220
+ "src/lib/entities/entity.ts"
221
+ ],
222
+ "dynamicImports": [
223
+ "src/lib/game/game-default.ts"
224
+ ]
225
+ },
226
+ "src/lib/core/utility/strings.ts": {
227
+ "file": "lib/core/utility/strings.js",
228
+ "name": "lib/core/utility/strings",
229
+ "src": "src/lib/core/utility/strings.ts"
230
+ },
231
+ "src/lib/core/utility/vector.ts": {
232
+ "file": "lib/core/utility/vector.js",
233
+ "name": "lib/core/utility/vector",
234
+ "src": "src/lib/core/utility/vector.ts"
217
235
  },
218
236
  "src/lib/core/vessel.ts": {
219
237
  "file": "lib/core/vessel.js",
@@ -236,6 +254,11 @@
236
254
  "src/lib/debug/console/console-state.ts"
237
255
  ]
238
256
  },
257
+ "src/lib/device/aspect-ratio.ts": {
258
+ "file": "lib/device/aspect-ratio.js",
259
+ "name": "lib/device/aspect-ratio",
260
+ "src": "src/lib/device/aspect-ratio.ts"
261
+ },
239
262
  "src/lib/entities/actor.ts": {
240
263
  "file": "lib/entities/actor.js",
241
264
  "name": "lib/entities/actor",
@@ -378,6 +401,31 @@
378
401
  "src/lib/game/game-state.ts"
379
402
  ]
380
403
  },
404
+ "src/lib/game/game-canvas.ts": {
405
+ "file": "lib/game/game-canvas.js",
406
+ "name": "lib/game/game-canvas",
407
+ "src": "src/lib/game/game-canvas.ts",
408
+ "imports": [
409
+ "src/lib/device/aspect-ratio.ts"
410
+ ]
411
+ },
412
+ "src/lib/game/game-config.ts": {
413
+ "file": "lib/game/game-config.js",
414
+ "name": "lib/game/game-config",
415
+ "src": "src/lib/game/game-config.ts",
416
+ "imports": [
417
+ "src/lib/device/aspect-ratio.ts"
418
+ ]
419
+ },
420
+ "src/lib/game/game-default.ts": {
421
+ "file": "lib/game/game-default.js",
422
+ "name": "lib/game/game-default",
423
+ "src": "src/lib/game/game-default.ts",
424
+ "isDynamicEntry": true,
425
+ "imports": [
426
+ "src/lib/stage/stage.ts"
427
+ ]
428
+ },
381
429
  "src/lib/game/game-state.ts": {
382
430
  "file": "lib/game/game-state.js",
383
431
  "name": "lib/game/game-state",
@@ -388,12 +436,12 @@
388
436
  "name": "lib/game/game",
389
437
  "src": "src/lib/game/game.ts",
390
438
  "imports": [
391
- "src/lib/core/base-node.ts",
392
439
  "src/lib/game/zylem-game.ts",
393
440
  "src/lib/stage/stage.ts",
394
441
  "src/lib/debug/debug-state.ts",
395
- "src/lib/entities/entity.ts",
396
- "src/lib/game/game-state.ts"
442
+ "src/lib/game/game-state.ts",
443
+ "src/lib/core/utility/nodes.ts",
444
+ "src/lib/game/game-config.ts"
397
445
  ]
398
446
  },
399
447
  "src/lib/game/zylem-game.ts": {
@@ -404,7 +452,9 @@
404
452
  "src/lib/game/game-state.ts",
405
453
  "src/lib/debug/debug-state.ts",
406
454
  "src/lib/input/input-manager.ts",
407
- "src/lib/core/three-addons/Timer.ts"
455
+ "src/lib/core/three-addons/Timer.ts",
456
+ "src/lib/game/game-config.ts",
457
+ "src/lib/game/game-canvas.ts"
408
458
  ]
409
459
  },
410
460
  "src/lib/graphics/geometries/XZPlaneGeometry.ts": {
@@ -417,7 +467,7 @@
417
467
  "name": "lib/graphics/material",
418
468
  "src": "src/lib/graphics/material.ts",
419
469
  "imports": [
420
- "src/lib/core/utility.ts",
470
+ "src/lib/core/utility/strings.ts",
421
471
  "src/lib/core/preset-shader.ts"
422
472
  ]
423
473
  },
@@ -508,6 +558,14 @@
508
558
  "name": "lib/stage/entity-spawner",
509
559
  "src": "src/lib/stage/entity-spawner.ts"
510
560
  },
561
+ "src/lib/stage/stage-blueprint.ts": {
562
+ "file": "lib/stage/stage-blueprint.js",
563
+ "name": "lib/stage/stage-blueprint",
564
+ "src": "src/lib/stage/stage-blueprint.ts",
565
+ "imports": [
566
+ "src/lib/stage/stage.ts"
567
+ ]
568
+ },
511
569
  "src/lib/stage/stage-debug-delegate.ts": {
512
570
  "file": "lib/stage/stage-debug-delegate.js",
513
571
  "name": "lib/stage/stage-debug-delegate",
@@ -517,6 +575,14 @@
517
575
  "src/lib/stage/debug-entity-cursor.ts"
518
576
  ]
519
577
  },
578
+ "src/lib/stage/stage-default.ts": {
579
+ "file": "lib/stage/stage-default.js",
580
+ "name": "lib/stage/stage-default",
581
+ "src": "src/lib/stage/stage-default.ts",
582
+ "imports": [
583
+ "src/lib/core/utility/vector.ts"
584
+ ]
585
+ },
520
586
  "src/lib/stage/stage-state.ts": {
521
587
  "file": "lib/stage/stage-state.js",
522
588
  "name": "lib/stage/stage-state",
@@ -529,7 +595,8 @@
529
595
  "imports": [
530
596
  "src/lib/stage/zylem-stage.ts",
531
597
  "src/lib/camera/camera.ts",
532
- "src/lib/stage/stage-state.ts"
598
+ "src/lib/stage/stage-state.ts",
599
+ "src/lib/stage/stage-default.ts"
533
600
  ]
534
601
  },
535
602
  "src/lib/stage/zylem-stage.ts": {
@@ -540,7 +607,7 @@
540
607
  "src/lib/collision/world.ts",
541
608
  "src/lib/graphics/zylem-scene.ts",
542
609
  "src/lib/stage/stage-state.ts",
543
- "src/lib/core/utility.ts",
610
+ "src/lib/core/utility/vector.ts",
544
611
  "src/lib/debug/debug-state.ts",
545
612
  "src/lib/game/game-state.ts",
546
613
  "src/lib/core/lifecycle-base.ts",
@@ -565,6 +632,7 @@
565
632
  "isEntry": true,
566
633
  "imports": [
567
634
  "src/lib/game/game.ts",
635
+ "src/lib/game/game-config.ts",
568
636
  "src/lib/stage/stage.ts",
569
637
  "src/lib/stage/entity-spawner.ts",
570
638
  "src/lib/core/vessel.ts",
@@ -595,7 +663,9 @@
595
663
  "isEntry": true,
596
664
  "imports": [
597
665
  "src/lib/stage/stage.ts",
598
- "src/lib/stage/entity-spawner.ts"
666
+ "src/lib/stage/entity-spawner.ts",
667
+ "src/lib/stage/stage-blueprint.ts",
668
+ "src/lib/stage/stage-default.ts"
599
669
  ]
600
670
  }
601
671
  }
package/dist/core.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { game } from './lib/game/game';
2
2
  export type { ZylemGameConfig } from './lib/game/game-interfaces';
3
3
  export { vessel } from './lib/core/vessel';
4
- export type { Vect3 } from './lib/core/utility';
4
+ export type { Vect3 } from './lib/core/utility/vector';
5
5
  export { globalChange, globalChanges, variableChange, variableChanges } from './lib/actions/global-change';
@@ -32,6 +32,13 @@ export interface SetupContext<T, TGlobals extends Record<string, unknown> = any>
32
32
  export interface SetupFunction<T, TGlobals extends Record<string, unknown> = any> {
33
33
  (context: SetupContext<T, TGlobals>): void;
34
34
  }
35
+ export interface LoadedFunction<T, TGlobals extends Record<string, unknown> = any> {
36
+ (context: LoadedContext<T, TGlobals>): void;
37
+ }
38
+ export interface LoadedContext<T, TGlobals extends Record<string, unknown> = any> {
39
+ me: T;
40
+ globals: TGlobals;
41
+ }
35
42
  export type UpdateContext<T, TGlobals extends Record<string, unknown> = any> = {
36
43
  me: T;
37
44
  delta: number;
@@ -51,3 +58,10 @@ export interface DestroyContext<T, TGlobals extends Record<string, unknown> = an
51
58
  export interface DestroyFunction<T, TGlobals extends Record<string, unknown> = any> {
52
59
  (context: DestroyContext<T, TGlobals>): void;
53
60
  }
61
+ export interface CleanupFunction<T, TGlobals extends Record<string, unknown> = any> {
62
+ (context: CleanupContext<T, TGlobals>): void;
63
+ }
64
+ export interface CleanupContext<T, TGlobals extends Record<string, unknown> = any> {
65
+ me: T;
66
+ globals: TGlobals;
67
+ }
@@ -1,5 +1,5 @@
1
1
  import { Behavior } from "~/lib/actions/behaviors/behavior";
2
- import { DestroyContext, DestroyFunction, SetupContext, SetupFunction, UpdateContext, UpdateFunction } from "./base-node-life-cycle";
2
+ import { CleanupContext, CleanupFunction, DestroyContext, DestroyFunction, LoadedContext, LoadedFunction, SetupContext, SetupFunction, UpdateContext, UpdateFunction } from "./base-node-life-cycle";
3
3
  export type BaseNodeOptions<T = any> = BaseNode | Partial<T>;
4
4
  export declare abstract class BaseNode<Options = any, T = any> {
5
5
  protected parent: BaseNode | null;
@@ -10,9 +10,11 @@ export declare abstract class BaseNode<Options = any, T = any> {
10
10
  uuid: string;
11
11
  name: string;
12
12
  markedForRemoval: boolean;
13
- update: UpdateFunction<this>;
14
13
  setup: SetupFunction<this>;
14
+ loaded: LoadedFunction<this>;
15
+ update: UpdateFunction<this>;
15
16
  destroy: DestroyFunction<this>;
17
+ cleanup: CleanupFunction<this>;
16
18
  constructor(args?: BaseNodeOptions[]);
17
19
  setParent(parent: BaseNode | null): void;
18
20
  getParent(): BaseNode | null;
@@ -22,8 +24,10 @@ export declare abstract class BaseNode<Options = any, T = any> {
22
24
  isComposite(): boolean;
23
25
  abstract create(): T;
24
26
  protected abstract _setup(params: SetupContext<this>): void;
27
+ protected abstract _loaded(params: LoadedContext<this>): Promise<void>;
25
28
  protected abstract _update(params: UpdateContext<this>): void;
26
29
  protected abstract _destroy(params: DestroyContext<this>): void;
30
+ protected abstract _cleanup(params: CleanupContext<this>): Promise<void>;
27
31
  nodeSetup(params: SetupContext<this>): void;
28
32
  nodeUpdate(params: UpdateContext<this>): void;
29
33
  nodeDestroy(params: DestroyContext<this>): void;
@@ -8,12 +8,16 @@ class s {
8
8
  uuid = "";
9
9
  name = "";
10
10
  markedForRemoval = !1;
11
- update = () => {
12
- };
13
11
  setup = () => {
14
12
  };
13
+ loaded = () => {
14
+ };
15
+ update = () => {
16
+ };
15
17
  destroy = () => {
16
18
  };
19
+ cleanup = () => {
20
+ };
17
21
  constructor(t = []) {
18
22
  const e = t.filter((i) => !(i instanceof s)).reduce((i, n) => ({ ...i, ...n }), {});
19
23
  this.options = e, this.uuid = o();
@@ -14,7 +14,7 @@
14
14
  export declare const loadFoundation: () => Promise<{
15
15
  baseNode: typeof import("./base-node");
16
16
  lifeCycle: typeof import("./base-node-life-cycle");
17
- utility: typeof import("./utility");
17
+ utility: typeof import("./utility/vector");
18
18
  vector: typeof import("./vector");
19
19
  }>;
20
20
  export declare const loadState: () => Promise<typeof import("../game/game-state")>;
@@ -48,7 +48,7 @@ export declare const loadFullGame: () => Promise<{
48
48
  foundation: {
49
49
  baseNode: typeof import("./base-node");
50
50
  lifeCycle: typeof import("./base-node-life-cycle");
51
- utility: typeof import("./utility");
51
+ utility: typeof import("./utility/vector");
52
52
  vector: typeof import("./vector");
53
53
  };
54
54
  state: typeof import("../game/game-state");
@@ -0,0 +1,11 @@
1
+ import { BaseNode } from '../base-node';
2
+ import { Stage } from '../../stage/stage';
3
+ import { GameEntityLifeCycle } from '../../entities/entity';
4
+ import { BasicTypes, GlobalVariablesType, ZylemGameConfig } from '../../game/game-interfaces';
5
+ import { GameConfigLike } from '~/lib/game/game-config';
6
+ export type GameOptions<TGlobals extends Record<string, BasicTypes> = GlobalVariablesType> = Array<ZylemGameConfig<Stage, any, TGlobals> | GameConfigLike | Stage | GameEntityLifeCycle | BaseNode>;
7
+ export declare function convertNodes<TGlobals extends Record<string, BasicTypes> = GlobalVariablesType>(_options: GameOptions<TGlobals>): Promise<{
8
+ id: string;
9
+ globals: TGlobals;
10
+ stages: Stage[];
11
+ }>;
@@ -0,0 +1,27 @@
1
+ import { BaseNode as f } from "../base-node.js";
2
+ import { Stage as r } from "../../stage/stage.js";
3
+ import { GameEntity as g } from "../../entities/entity.js";
4
+ async function h(c) {
5
+ const { getGameDefaultConfig: a } = await import("../../game/game-default.js");
6
+ let s = { ...a() };
7
+ const o = [], e = [], i = [];
8
+ return Object.values(c).forEach((t) => {
9
+ if (t instanceof r)
10
+ e.push(t);
11
+ else if (t instanceof g)
12
+ i.push(t);
13
+ else if (t instanceof f)
14
+ i.push(t);
15
+ else if (t?.constructor?.name === "Object" && typeof t == "object") {
16
+ const n = Object.assign({ ...a() }, { ...t });
17
+ o.push(n);
18
+ }
19
+ }), o.forEach((t) => {
20
+ s = Object.assign(s, { ...t });
21
+ }), e.forEach((t) => {
22
+ t.addEntities(i);
23
+ }), e.length ? s.stages = e : s.stages[0].addEntities(i), s;
24
+ }
25
+ export {
26
+ h as convertNodes
27
+ };
@@ -0,0 +1,2 @@
1
+ export declare function sortedStringify(obj: Record<string, any>): string;
2
+ export declare function shortHash(objString: string): string;
@@ -0,0 +1,14 @@
1
+ function o(r) {
2
+ const e = Object.keys(r).sort().reduce((t, n) => (t[n] = r[n], t), {});
3
+ return JSON.stringify(e);
4
+ }
5
+ function s(r) {
6
+ let e = 0;
7
+ for (let t = 0; t < r.length; t++)
8
+ e = Math.imul(31, e) + r.charCodeAt(t) | 0;
9
+ return e.toString(36);
10
+ }
11
+ export {
12
+ s as shortHash,
13
+ o as sortedStringify
14
+ };
@@ -9,7 +9,5 @@ export declare const ZylemBlue = "#0333EC";
9
9
  export declare const ZylemBlueTransparent = "#0333ECA0";
10
10
  export declare const ZylemGoldText = "#DAA420";
11
11
  export type SizeVector = Vect3 | null;
12
- export declare function sortedStringify(obj: Record<string, any>): string;
13
- export declare function shortHash(objString: string): string;
14
12
  export declare const Vec0: Vector3;
15
13
  export declare const Vec1: Vector3;
@@ -0,0 +1,8 @@
1
+ import { Color as r } from "three";
2
+ import { Vector3 as o } from "@dimforge/rapier3d-compat";
3
+ const t = new r("#0333EC");
4
+ new o(0, 0, 0);
5
+ new o(1, 1, 1);
6
+ export {
7
+ t as ZylemBlueColor
8
+ };
@@ -1,11 +1,13 @@
1
1
  import { BaseNode } from './base-node';
2
- import { SetupContext, UpdateContext, DestroyContext } from './base-node-life-cycle';
2
+ import { SetupContext, UpdateContext, DestroyContext, LoadedContext, CleanupContext } from './base-node-life-cycle';
3
3
  export declare const VESSEL_TYPE: unique symbol;
4
4
  export declare class Vessel extends BaseNode<{}, Vessel> {
5
5
  static type: symbol;
6
6
  protected _setup(_params: SetupContext<this>): void;
7
+ protected _loaded(_params: LoadedContext<this>): Promise<void>;
7
8
  protected _update(_params: UpdateContext<this>): void;
8
9
  protected _destroy(_params: DestroyContext<this>): void;
10
+ protected _cleanup(_params: CleanupContext<this>): Promise<void>;
9
11
  create(): this;
10
12
  }
11
13
  export declare function vessel(...args: Array<BaseNode>): BaseNode<{}, Vessel>;
@@ -1,23 +1,27 @@
1
- import { BaseNode as a } from "./base-node.js";
1
+ import { BaseNode as t } from "./base-node.js";
2
2
  const r = Symbol("vessel");
3
- class n extends a {
3
+ class n extends t {
4
4
  static type = r;
5
- _setup(e) {
5
+ _setup(s) {
6
6
  }
7
- _update(e) {
7
+ async _loaded(s) {
8
8
  }
9
- _destroy(e) {
9
+ _update(s) {
10
+ }
11
+ _destroy(s) {
12
+ }
13
+ async _cleanup(s) {
10
14
  }
11
15
  create() {
12
16
  return this;
13
17
  }
14
18
  }
15
- function c(...s) {
16
- const e = new n();
17
- return s.forEach((t) => e.add(t)), e;
19
+ function o(...e) {
20
+ const s = new n();
21
+ return e.forEach((a) => s.add(a)), s;
18
22
  }
19
23
  export {
20
24
  r as VESSEL_TYPE,
21
25
  n as Vessel,
22
- c as vessel
26
+ o as vessel
23
27
  };
@@ -0,0 +1,37 @@
1
+ export declare const AspectRatio: {
2
+ readonly FourByThree: number;
3
+ readonly SixteenByNine: number;
4
+ readonly TwentyOneByNine: number;
5
+ readonly OneByOne: number;
6
+ };
7
+ export type AspectRatioValue = (typeof AspectRatio)[keyof typeof AspectRatio] | number;
8
+ /**
9
+ * AspectRatioDelegate manages sizing a canvas to fit within a container
10
+ * while preserving a target aspect ratio. It notifies a consumer via
11
+ * onResize when the final width/height are applied so renderers/cameras
12
+ * can update their viewports.
13
+ */
14
+ export declare class AspectRatioDelegate {
15
+ container: HTMLElement;
16
+ canvas: HTMLCanvasElement;
17
+ aspectRatio: number;
18
+ onResize?: (width: number, height: number) => void;
19
+ private handleResizeBound;
20
+ constructor(params: {
21
+ container: HTMLElement;
22
+ canvas: HTMLCanvasElement;
23
+ aspectRatio: AspectRatioValue;
24
+ onResize?: (width: number, height: number) => void;
25
+ });
26
+ /** Attach window resize listener and apply once. */
27
+ attach(): void;
28
+ /** Detach window resize listener. */
29
+ detach(): void;
30
+ /** Compute the largest size that fits container while preserving aspect. */
31
+ measure(): {
32
+ width: number;
33
+ height: number;
34
+ };
35
+ /** Apply measured size to canvas and notify. */
36
+ apply(): void;
37
+ }
@@ -0,0 +1,44 @@
1
+ const h = {
2
+ FourByThree: 1.3333333333333333,
3
+ SixteenByNine: 1.7777777777777777,
4
+ TwentyOneByNine: 2.3333333333333335,
5
+ OneByOne: 1
6
+ };
7
+ class a {
8
+ container;
9
+ canvas;
10
+ aspectRatio;
11
+ onResize;
12
+ handleResizeBound;
13
+ constructor(t) {
14
+ this.container = t.container, this.canvas = t.canvas, this.aspectRatio = (typeof t.aspectRatio == "number", t.aspectRatio), this.onResize = t.onResize, this.handleResizeBound = this.apply.bind(this);
15
+ }
16
+ /** Attach window resize listener and apply once. */
17
+ attach() {
18
+ window.addEventListener("resize", this.handleResizeBound), this.apply();
19
+ }
20
+ /** Detach window resize listener. */
21
+ detach() {
22
+ window.removeEventListener("resize", this.handleResizeBound);
23
+ }
24
+ /** Compute the largest size that fits container while preserving aspect. */
25
+ measure() {
26
+ const t = this.container.clientWidth || window.innerWidth, e = this.container.clientHeight || window.innerHeight;
27
+ if (t / e > this.aspectRatio) {
28
+ const i = e;
29
+ return { width: Math.round(i * this.aspectRatio), height: i };
30
+ } else {
31
+ const i = t, n = Math.round(i / this.aspectRatio);
32
+ return { width: i, height: n };
33
+ }
34
+ }
35
+ /** Apply measured size to canvas and notify. */
36
+ apply() {
37
+ const { width: t, height: e } = this.measure();
38
+ this.canvas.style.width = `${t}px`, this.canvas.style.height = `${e}px`, this.onResize?.(t, e);
39
+ }
40
+ }
41
+ export {
42
+ h as AspectRatio,
43
+ a as AspectRatioDelegate
44
+ };
@@ -4,7 +4,7 @@ import { Vec3 } from "../core/vector";
4
4
  import { MaterialBuilder, MaterialOptions } from "../graphics/material";
5
5
  import { CollisionOptions } from "../collision/collision";
6
6
  import { BaseNode } from "../core/base-node";
7
- import { DestroyContext, SetupContext, UpdateContext } from "../core/base-node-life-cycle";
7
+ import { DestroyContext, SetupContext, UpdateContext, LoadedContext, CleanupContext } from "../core/base-node-life-cycle";
8
8
  import type { EntityMeshBuilder, EntityCollisionBuilder } from "./builder";
9
9
  export declare abstract class AbstractEntity {
10
10
  abstract uuid: string;
@@ -82,8 +82,10 @@ export declare class GameEntity<O extends GameEntityOptions> extends BaseNode<O>
82
82
  onDestroy(...callbacks: ((params: DestroyContext<this>) => void)[]): this;
83
83
  onCollision(...callbacks: ((params: CollisionContext<this, O>) => void)[]): this;
84
84
  _setup(params: SetupContext<this>): void;
85
+ protected _loaded(_params: LoadedContext<this>): Promise<void>;
85
86
  _update(params: UpdateContext<this>): void;
86
87
  _destroy(params: DestroyContext<this>): void;
88
+ protected _cleanup(_params: CleanupContext<this>): Promise<void>;
87
89
  _collision(other: GameEntity<O>, globals?: any): void;
88
90
  addBehavior(behaviorCallback: ({
89
91
  type: BehaviorCallbackType;
@@ -1,7 +1,7 @@
1
1
  import { ShaderMaterial as s } from "three";
2
- import { position as o, scale as a, rotation as n } from "../systems/transformable.system.js";
2
+ import { position as a, scale as o, rotation as n } from "../systems/transformable.system.js";
3
3
  import { BaseNode as c } from "../core/base-node.js";
4
- class d extends c {
4
+ class f extends c {
5
5
  group;
6
6
  mesh;
7
7
  materials;
@@ -33,8 +33,8 @@ class d extends c {
33
33
  create() {
34
34
  const { position: e } = this.options, { x: t, y: i, z: l } = e || { x: 0, y: 0, z: 0 };
35
35
  return this.behaviors = [
36
- { component: o, values: { x: t, y: i, z: l } },
37
- { component: a, values: { x: 0, y: 0, z: 0 } },
36
+ { component: a, values: { x: t, y: i, z: l } },
37
+ { component: o, values: { x: 0, y: 0, z: 0 } },
38
38
  { component: n, values: { x: 0, y: 0, z: 0, w: 0 } }
39
39
  ], this.name = this.options.name || "", this;
40
40
  }
@@ -70,6 +70,8 @@ class d extends c {
70
70
  i({ ...e, me: this });
71
71
  });
72
72
  }
73
+ async _loaded(e) {
74
+ }
73
75
  _update(e) {
74
76
  this.updateMaterials(e), this.lifeCycleDelegate.update?.length && this.lifeCycleDelegate.update.forEach((i) => {
75
77
  i({ ...e, me: this });
@@ -84,6 +86,8 @@ class d extends c {
84
86
  t({ ...e, me: this });
85
87
  });
86
88
  }
89
+ async _cleanup(e) {
90
+ }
87
91
  _collision(e, t) {
88
92
  this.collisionDelegate.collision?.length && this.collisionDelegate.collision.forEach((l) => {
89
93
  l({ entity: this, other: e, globals: t });
@@ -112,5 +116,5 @@ class d extends c {
112
116
  }
113
117
  }
114
118
  export {
115
- d as GameEntity
119
+ f as GameEntity
116
120
  };