@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
@@ -1,25 +1,25 @@
1
- import { createWorld as l, addEntity as c, addComponent as u, removeEntity as f } from "bitecs";
2
- import { Vector3 as o, Vector2 as p } from "three";
3
- import { ZylemWorld as d } from "../collision/world.js";
4
- import { ZylemScene as m } from "../graphics/zylem-scene.js";
5
- import { setStageBackgroundColor as y, setStageBackgroundImage as g, setStageVariables as b, resetStageVariables as w } from "./stage-state.js";
6
- import { ZylemBlueColor as E } from "../core/utility.js";
1
+ import { createWorld as c, addEntity as f, addComponent as u, removeEntity as p } from "bitecs";
2
+ import { Vector3 as o, Color as d, Vector2 as m } from "three";
3
+ import { ZylemWorld as h } from "../collision/world.js";
4
+ import { ZylemScene as y } from "../graphics/zylem-scene.js";
5
+ import { setStageBackgroundColor as g, setStageBackgroundImage as E, setStageVariables as w, resetStageVariables as b } from "./stage-state.js";
6
+ import { ZylemBlueColor as S } from "../core/utility/vector.js";
7
7
  import { debugState as a } from "../debug/debug-state.js";
8
- import { getGlobalState as h } from "../game/game-state.js";
8
+ import { getGlobalState as l } from "../game/game-state.js";
9
9
  import { LifeCycleBase as v } from "../core/lifecycle-base.js";
10
- import S from "../systems/transformable.system.js";
11
- import { BaseNode as M } from "../core/base-node.js";
10
+ import M from "../systems/transformable.system.js";
11
+ import { BaseNode as _ } from "../core/base-node.js";
12
12
  import { nanoid as C } from "nanoid";
13
- import { ZylemCamera as _ } from "../camera/zylem-camera.js";
14
- import { Perspectives as k } from "../camera/perspective.js";
15
- import { CameraWrapper as B } from "../camera/camera.js";
16
- import { StageDebugDelegate as I } from "./stage-debug-delegate.js";
17
- import { GameEntity as O } from "../entities/entity.js";
18
- const P = "Stage";
19
- class K extends v {
20
- type = P;
13
+ import { ZylemCamera as B } from "../camera/zylem-camera.js";
14
+ import { Perspectives as O } from "../camera/perspective.js";
15
+ import { CameraWrapper as P } from "../camera/camera.js";
16
+ import { StageDebugDelegate as R } from "./stage-debug-delegate.js";
17
+ import { GameEntity as W } from "../entities/entity.js";
18
+ const k = "Stage";
19
+ class Y extends v {
20
+ type = k;
21
21
  state = {
22
- backgroundColor: E,
22
+ backgroundColor: S,
23
23
  backgroundImage: null,
24
24
  inputs: {
25
25
  p1: ["gamepad-1", "keyboard"],
@@ -40,7 +40,7 @@ class K extends v {
40
40
  isLoaded = !1;
41
41
  _debugMap = /* @__PURE__ */ new Map();
42
42
  entityAddedHandlers = [];
43
- ecs = l();
43
+ ecs = c();
44
44
  testSystem = null;
45
45
  transformSystem = null;
46
46
  debugDelegate = null;
@@ -55,18 +55,7 @@ class K extends v {
55
55
  constructor(e = []) {
56
56
  super(), this.world = null, this.scene = null, this.uuid = C();
57
57
  const { config: t, entities: i, asyncEntities: s, camera: r } = this.parseOptions(e);
58
- this.camera = r, this.children = i, this.pendingEntities = s, this.saveState({
59
- backgroundColor: t.backgroundColor ?? this.state.backgroundColor,
60
- backgroundImage: t.backgroundImage ?? this.state.backgroundImage,
61
- inputs: t.inputs ?? this.state.inputs,
62
- gravity: t.gravity ?? this.state.gravity,
63
- variables: t.variables ?? this.state.variables,
64
- entities: []
65
- }), this.gravity = t.gravity ?? new o(0, 0, 0);
66
- const n = this;
67
- window.onresize = function() {
68
- n.resize(window.innerWidth, window.innerHeight);
69
- };
58
+ this.camera = r, this.children = i, this.pendingEntities = s, this.saveState({ ...this.state, ...t, entities: [] }), this.gravity = t.gravity ?? new o(0, 0, 0);
70
59
  }
71
60
  parseOptions(e) {
72
61
  let t = {};
@@ -77,7 +66,7 @@ class K extends v {
77
66
  return { config: t, entities: i, asyncEntities: s, camera: r };
78
67
  }
79
68
  isZylemStageConfig(e) {
80
- return e && typeof e == "object" && !(e instanceof M) && !(e instanceof B);
69
+ return e && typeof e == "object" && !(e instanceof _) && !(e instanceof P);
81
70
  }
82
71
  isBaseNode(e) {
83
72
  return e && typeof e == "object" && typeof e.create == "function";
@@ -101,8 +90,8 @@ class K extends v {
101
90
  this.state = e;
102
91
  }
103
92
  setState() {
104
- const { backgroundColor: e, backgroundImage: t } = this.state;
105
- y(e), g(t), b(this.state.variables ?? {});
93
+ const { backgroundColor: e, backgroundImage: t } = this.state, i = e instanceof d ? e : new d(e);
94
+ g(i), E(t), w(this.state.variables ?? {});
106
95
  }
107
96
  /**
108
97
  * Load and initialize the stage's scene and world.
@@ -112,9 +101,9 @@ class K extends v {
112
101
  async load(e, t) {
113
102
  this.setState();
114
103
  const i = t || (this.camera ? this.camera.cameraRef : this.createDefaultCamera());
115
- this.cameraRef = i, this.scene = new m(e, i, this.state);
116
- const s = await d.loadPhysics(this.gravity ?? new o(0, 0, 0));
117
- this.world = new d(s), this.scene.setup();
104
+ this.cameraRef = i, this.scene = new y(e, i, this.state);
105
+ const s = await h.loadPhysics(this.gravity ?? new o(0, 0, 0));
106
+ this.world = new h(s), this.scene.setup();
118
107
  for (let r of this.children)
119
108
  this.spawnEntity(r);
120
109
  if (this.pendingEntities.length && (this.enqueue(...this.pendingEntities), this.pendingEntities = []), this.pendingPromises.length) {
@@ -122,18 +111,18 @@ class K extends v {
122
111
  r.then((n) => this.spawnEntity(n)).catch((n) => console.error("Failed to resolve pending stage entity", n));
123
112
  this.pendingPromises = [];
124
113
  }
125
- this.transformSystem = S(this), this.isLoaded = !0;
114
+ this.transformSystem = M(this), this.isLoaded = !0;
126
115
  }
127
116
  createDefaultCamera() {
128
- const e = window.innerWidth, t = window.innerHeight, i = new p(e, t);
129
- return new _(k.ThirdPerson, i);
117
+ const e = window.innerWidth, t = window.innerHeight, i = new m(e, t);
118
+ return new B(O.ThirdPerson, i);
130
119
  }
131
120
  _setup(e) {
132
121
  if (!this.scene || !this.world) {
133
122
  this.logMissingEntities();
134
123
  return;
135
124
  }
136
- a.on && (this.debugDelegate = new I(this));
125
+ a.on && (this.debugDelegate = new R(this));
137
126
  }
138
127
  _update(e) {
139
128
  const { delta: t } = e;
@@ -159,10 +148,10 @@ class K extends v {
159
148
  _destroy(e) {
160
149
  this._childrenMap.forEach((t) => {
161
150
  try {
162
- t.nodeDestroy({ me: t, globals: h() });
151
+ t.nodeDestroy({ me: t, globals: l() });
163
152
  } catch {
164
153
  }
165
- }), this._childrenMap.clear(), this._removalMap.clear(), this._debugMap.clear(), this.world?.destroy(), this.scene?.destroy(), this.debugDelegate?.dispose(), this.isLoaded = !1, this.world = null, this.scene = null, this.cameraRef = null, w();
154
+ }), this._childrenMap.clear(), this._removalMap.clear(), this._debugMap.clear(), this.world?.destroy(), this.scene?.destroy(), this.debugDelegate?.dispose(), this.isLoaded = !1, this.world = null, this.scene = null, this.cameraRef = null, b();
166
155
  }
167
156
  /**
168
157
  * Create, register, and add an entity to the scene/world.
@@ -171,7 +160,7 @@ class K extends v {
171
160
  async spawnEntity(e) {
172
161
  if (!this.scene || !this.world)
173
162
  return;
174
- const t = e.create(), i = c(this.ecs);
163
+ const t = e.create(), i = f(this.ecs);
175
164
  if (t.eid = i, this.scene.addEntity(t), e.behaviors)
176
165
  for (let s of e.behaviors) {
177
166
  u(this.ecs, s.component, t.eid);
@@ -181,12 +170,12 @@ class K extends v {
181
170
  }
182
171
  t.colliderDesc && this.world.addEntity(t), e.nodeSetup({
183
172
  me: e,
184
- globals: h(),
173
+ globals: l(),
185
174
  camera: this.scene.zylemCamera
186
175
  }), this.addEntityToStage(t);
187
176
  }
188
177
  buildEntityState(e) {
189
- return e instanceof O ? { ...e.buildInfo() } : {
178
+ return e instanceof W ? { ...e.buildInfo() } : {
190
179
  uuid: e.uuid,
191
180
  name: e.name,
192
181
  eid: e.eid
@@ -229,7 +218,7 @@ class K extends v {
229
218
  const i = this.world.collisionMap.get(e) ?? this._debugMap.get(e);
230
219
  if (!i)
231
220
  return !1;
232
- this.world.destroyEntity(i), i.group ? this.scene.scene.remove(i.group) : i.mesh && this.scene.scene.remove(i.mesh), f(this.ecs, i.eid);
221
+ this.world.destroyEntity(i), i.group ? this.scene.scene.remove(i.group) : i.mesh && this.scene.scene.remove(i.mesh), p(this.ecs, i.eid);
233
222
  let s = null;
234
223
  return this._childrenMap.forEach((r, n) => {
235
224
  r.uuid === e && (s = n);
@@ -274,6 +263,6 @@ class K extends v {
274
263
  }
275
264
  }
276
265
  export {
277
- P as STAGE_TYPE,
278
- K as ZylemStage
266
+ k as STAGE_TYPE,
267
+ Y as ZylemStage
279
268
  };
package/dist/main.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { game } from './lib/game/game';
2
2
  export type { ZylemGameConfig } from './lib/game/game-interfaces';
3
+ export { gameConfig } from './lib/game/game-config';
3
4
  export { stage } from './lib/stage/stage';
4
5
  export { entitySpawner } from './lib/stage/entity-spawner';
5
6
  export type { StageOptions } from './lib/stage/zylem-stage';
@@ -7,7 +8,7 @@ export { vessel } from './lib/core/vessel';
7
8
  export { camera } from './lib/camera/camera';
8
9
  export type { PerspectiveType } from './lib/camera/perspective';
9
10
  export { Perspectives } from './lib/camera/perspective';
10
- export type { Vect3 } from './lib/core/utility';
11
+ export type { Vect3 } from './lib/core/utility/vector';
11
12
  export { box } from './lib/entities/box';
12
13
  export { sphere } from './lib/entities/sphere';
13
14
  export { sprite } from './lib/entities/sprite';
package/dist/main.js CHANGED
@@ -1,56 +1,58 @@
1
1
  import { game as m } from "./lib/game/game.js";
2
- import { stage as a } from "./lib/stage/stage.js";
3
- import { entitySpawner as f } from "./lib/stage/entity-spawner.js";
4
- import { vessel as s } from "./lib/core/vessel.js";
5
- import { camera as i } from "./lib/camera/camera.js";
6
- import { Perspectives as c } from "./lib/camera/perspective.js";
7
- import { ZylemBox as h, box as v } from "./lib/entities/box.js";
8
- import { sphere as d } from "./lib/entities/sphere.js";
9
- import { sprite as R } from "./lib/entities/sprite.js";
10
- import { plane as E } from "./lib/entities/plane.js";
11
- import { zone as w } from "./lib/entities/zone.js";
12
- import { actor as D } from "./lib/entities/actor.js";
13
- import { text as I } from "./lib/entities/text.js";
14
- import { rect as T } from "./lib/entities/rect.js";
15
- import { makeMoveable as A } from "./lib/actions/capabilities/moveable.js";
16
- import { makeRotatable as S } from "./lib/actions/capabilities/rotatable.js";
17
- import { makeTransformable as j } from "./lib/actions/capabilities/transformable.js";
18
- import { ricochet2DInBounds as F } from "./lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.js";
19
- import { ricochet2DCollision as J } from "./lib/actions/behaviors/ricochet/ricochet-2d-collision.js";
20
- import { boundary2d as L } from "./lib/actions/behaviors/boundaries/boundary.js";
21
- import { destroy as O } from "./lib/entities/destroy.js";
22
- import { Howl as U } from "howler";
2
+ import { gameConfig as a } from "./lib/game/game-config.js";
3
+ import { stage as f } from "./lib/stage/stage.js";
4
+ import { entitySpawner as s } from "./lib/stage/entity-spawner.js";
5
+ import { vessel as i } from "./lib/core/vessel.js";
6
+ import { camera as b } from "./lib/camera/camera.js";
7
+ import { Perspectives as h } from "./lib/camera/perspective.js";
8
+ import { ZylemBox as v, box as d } from "./lib/entities/box.js";
9
+ import { sphere as R } from "./lib/entities/sphere.js";
10
+ import { sprite as E } from "./lib/entities/sprite.js";
11
+ import { plane as w } from "./lib/entities/plane.js";
12
+ import { zone as D } from "./lib/entities/zone.js";
13
+ import { actor as I } from "./lib/entities/actor.js";
14
+ import { text as T } from "./lib/entities/text.js";
15
+ import { rect as A } from "./lib/entities/rect.js";
16
+ import { makeMoveable as S } from "./lib/actions/capabilities/moveable.js";
17
+ import { makeRotatable as j } from "./lib/actions/capabilities/rotatable.js";
18
+ import { makeTransformable as F } from "./lib/actions/capabilities/transformable.js";
19
+ import { ricochet2DInBounds as J } from "./lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.js";
20
+ import { ricochet2DCollision as L } from "./lib/actions/behaviors/ricochet/ricochet-2d-collision.js";
21
+ import { boundary2d as O } from "./lib/actions/behaviors/boundaries/boundary.js";
22
+ import { destroy as U } from "./lib/entities/destroy.js";
23
+ import { Howl as W } from "howler";
23
24
  import * as o from "three";
24
25
  import * as r from "@dimforge/rapier3d-compat";
25
- import { globalChange as W, globalChanges as X, variableChange as Y, variableChanges as _ } from "./lib/actions/global-change.js";
26
+ import { globalChange as Y, globalChanges as _, variableChange as $, variableChanges as oo } from "./lib/actions/global-change.js";
26
27
  export {
27
- U as Howl,
28
- c as Perspectives,
28
+ W as Howl,
29
+ h as Perspectives,
29
30
  r as RAPIER,
30
31
  o as THREE,
31
- h as ZylemBox,
32
- D as actor,
33
- L as boundary2d,
34
- v as box,
35
- i as camera,
36
- O as destroy,
37
- f as entitySpawner,
32
+ v as ZylemBox,
33
+ I as actor,
34
+ O as boundary2d,
35
+ d as box,
36
+ b as camera,
37
+ U as destroy,
38
+ s as entitySpawner,
38
39
  m as game,
39
- W as globalChange,
40
- X as globalChanges,
41
- A as makeMoveable,
42
- S as makeRotatable,
43
- j as makeTransformable,
44
- E as plane,
45
- T as rect,
46
- J as ricochet2DCollision,
47
- F as ricochet2DInBounds,
48
- d as sphere,
49
- R as sprite,
50
- a as stage,
51
- I as text,
52
- Y as variableChange,
53
- _ as variableChanges,
54
- s as vessel,
55
- w as zone
40
+ a as gameConfig,
41
+ Y as globalChange,
42
+ _ as globalChanges,
43
+ S as makeMoveable,
44
+ j as makeRotatable,
45
+ F as makeTransformable,
46
+ w as plane,
47
+ A as rect,
48
+ L as ricochet2DCollision,
49
+ J as ricochet2DInBounds,
50
+ R as sphere,
51
+ E as sprite,
52
+ f as stage,
53
+ T as text,
54
+ $ as variableChange,
55
+ oo as variableChanges,
56
+ i as vessel,
57
+ D as zone
56
58
  };
package/dist/stage.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export { stage } from './lib/stage/stage';
2
2
  export { entitySpawner } from './lib/stage/entity-spawner';
3
3
  export type { StageOptions } from './lib/stage/zylem-stage';
4
+ export { stageBlueprintsState, createStageBlueprint, upsertStageBlueprint, removeStageBlueprint, getStageBlueprint, listStageBlueprints, setCurrentStageBlueprint, getCurrentStageBlueprint, buildStageFromBlueprint, resetStageBlueprints, } from './lib/stage/stage-blueprint';
5
+ export type { StageBlueprint } from './lib/stage/stage-blueprint';
6
+ export { stageDefaultsState, setStageDefaults, resetStageDefaults, getStageDefaultConfig, } from './lib/stage/stage-default';
package/dist/stage.js CHANGED
@@ -1,6 +1,22 @@
1
- import { stage as t } from "./lib/stage/stage.js";
2
- import { entitySpawner as p } from "./lib/stage/entity-spawner.js";
1
+ import { stage as r } from "./lib/stage/stage.js";
2
+ import { entitySpawner as g } from "./lib/stage/entity-spawner.js";
3
+ import { buildStageFromBlueprint as l, createStageBlueprint as p, getCurrentStageBlueprint as n, getStageBlueprint as s, listStageBlueprints as S, removeStageBlueprint as i, resetStageBlueprints as o, setCurrentStageBlueprint as B, stageBlueprintsState as f, upsertStageBlueprint as m } from "./lib/stage/stage-blueprint.js";
4
+ import { getStageDefaultConfig as D, resetStageDefaults as C, setStageDefaults as b, stageDefaultsState as c } from "./lib/stage/stage-default.js";
3
5
  export {
4
- p as entitySpawner,
5
- t as stage
6
+ l as buildStageFromBlueprint,
7
+ p as createStageBlueprint,
8
+ g as entitySpawner,
9
+ n as getCurrentStageBlueprint,
10
+ s as getStageBlueprint,
11
+ D as getStageDefaultConfig,
12
+ S as listStageBlueprints,
13
+ i as removeStageBlueprint,
14
+ o as resetStageBlueprints,
15
+ C as resetStageDefaults,
16
+ B as setCurrentStageBlueprint,
17
+ b as setStageDefaults,
18
+ r as stage,
19
+ f as stageBlueprintsState,
20
+ c as stageDefaultsState,
21
+ m as upsertStageBlueprint
6
22
  };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zylem/game-lib",
3
- "version": "0.3.16",
3
+ "version": "0.3.17",
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",
@@ -1,4 +0,0 @@
1
- export declare const GameCanvas: (targetRatio: number) => {
2
- targetRatio: number;
3
- canvasWrapper: null;
4
- };
@@ -1,20 +0,0 @@
1
- import { Color as i } from "three";
2
- import { Vector3 as n } from "@dimforge/rapier3d-compat";
3
- const u = new i("#0333EC");
4
- function f(r) {
5
- const e = Object.keys(r).sort().reduce((t, o) => (t[o] = r[o], t), {});
6
- return JSON.stringify(e);
7
- }
8
- function h(r) {
9
- let e = 0;
10
- for (let t = 0; t < r.length; t++)
11
- e = Math.imul(31, e) + r.charCodeAt(t) | 0;
12
- return e.toString(36);
13
- }
14
- new n(0, 0, 0);
15
- new n(1, 1, 1);
16
- export {
17
- u as ZylemBlueColor,
18
- h as shortHash,
19
- f as sortedStringify
20
- };