@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,10 +1,12 @@
1
- import { state as i, getGlobalState as r, setGlobalState as n } from "./game-state.js";
2
- import { setDebugFlag as u, isPaused as h } from "../debug/debug-state.js";
3
- import { InputManager as g } from "../input/input-manager.js";
4
- import { Timer as c } from "../core/three-addons/Timer.js";
5
- import { subscribe as m } from "valtio/vanilla";
6
- import f from "stats.js";
7
- class l {
1
+ import { state as o, getGlobalState as n, setGlobalState as l } from "./game-state.js";
2
+ import { setDebugFlag as u, isPaused as m } from "../debug/debug-state.js";
3
+ import { InputManager as c } from "../input/input-manager.js";
4
+ import { Timer as h } from "../core/three-addons/Timer.js";
5
+ import { resolveGameConfig as d } from "./game-config.js";
6
+ import { GameCanvas as g } from "./game-canvas.js";
7
+ import { subscribe as f } from "valtio/vanilla";
8
+ import p from "stats.js";
9
+ class r {
8
10
  id;
9
11
  initialGlobals = {};
10
12
  customSetup = null;
@@ -20,16 +22,40 @@ class l {
20
22
  wrapperRef;
21
23
  statsRef = null;
22
24
  defaultCamera = null;
25
+ container = null;
26
+ canvas = null;
27
+ aspectRatioDelegate = null;
28
+ resolvedConfig = null;
29
+ gameCanvas = null;
23
30
  static FRAME_LIMIT = 120;
24
- static FRAME_DURATION = 1e3 / l.FRAME_LIMIT;
31
+ static FRAME_DURATION = 1e3 / r.FRAME_LIMIT;
25
32
  static MAX_DELTA_SECONDS = 1 / 30;
26
33
  constructor(t, e) {
27
- this.wrapperRef = e, this.inputManager = new g(t.input), this.timer = new c(), this.timer.connect(document), this.id = t.id, this.stages = t.stages || [], this.setGlobals(t), t.debug && (this.statsRef = new f(), this.statsRef.showPanel(0), this.statsRef.dom.style.position = "absolute", this.statsRef.dom.style.bottom = "0", this.statsRef.dom.style.right = "0", this.statsRef.dom.style.top = "auto", this.statsRef.dom.style.left = "auto", document.body.appendChild(this.statsRef.dom));
34
+ this.wrapperRef = e, this.inputManager = new c(t.input), this.timer = new h(), this.timer.connect(document);
35
+ const a = d(t);
36
+ this.id = a.id, this.stages = a.stages || [], this.container = a.container, this.canvas = a.canvas ?? null, this.resolvedConfig = a, this.loadGameCanvas(a), this.loadDebugOptions(t), this.setGlobals(t);
37
+ }
38
+ loadGameCanvas(t) {
39
+ this.gameCanvas = new g({
40
+ id: t.id,
41
+ container: t.container,
42
+ containerId: t.containerId,
43
+ canvas: this.canvas ?? void 0,
44
+ bodyBackground: t.bodyBackground,
45
+ fullscreen: t.fullscreen,
46
+ aspectRatio: t.aspectRatio
47
+ }), this.gameCanvas.applyBodyBackground(), this.gameCanvas.mountCanvas(), this.gameCanvas.centerIfFullscreen();
48
+ }
49
+ loadDebugOptions(t) {
50
+ u(!!t.debug), t.debug && (this.statsRef = new p(), this.statsRef.showPanel(0), this.statsRef.dom.style.position = "absolute", this.statsRef.dom.style.bottom = "0", this.statsRef.dom.style.right = "0", this.statsRef.dom.style.top = "auto", this.statsRef.dom.style.left = "auto", document.body.appendChild(this.statsRef.dom));
28
51
  }
29
52
  async loadStage(t) {
30
53
  this.unloadCurrentStage();
31
54
  const e = t.options[0];
32
- await t.load(this.id, e?.camera), this.stageMap.set(t.stageRef.uuid, t), this.currentStageId = t.stageRef.uuid, this.defaultCamera = t.stageRef.cameraRef;
55
+ if (await t.load(this.id, e?.camera), this.stageMap.set(t.stageRef.uuid, t), this.currentStageId = t.stageRef.uuid, this.defaultCamera = t.stageRef.cameraRef, this.container && this.defaultCamera) {
56
+ const a = this.defaultCamera.getDomElement();
57
+ this.gameCanvas?.mountRenderer(a, (s, i) => this.defaultCamera?.resize(s, i));
58
+ }
33
59
  }
34
60
  unloadCurrentStage() {
35
61
  if (!this.currentStageId)
@@ -40,7 +66,7 @@ class l {
40
66
  try {
41
67
  t.stageRef.nodeDestroy({
42
68
  me: t.stageRef,
43
- globals: i.globals
69
+ globals: o.globals
44
70
  });
45
71
  } catch (e) {
46
72
  console.error("Failed to destroy previous stage", e);
@@ -49,20 +75,20 @@ class l {
49
75
  }
50
76
  }
51
77
  setGlobals(t) {
52
- u(t.debug), this.initialGlobals = { ...t.globals };
78
+ this.initialGlobals = { ...t.globals };
53
79
  for (const e in this.initialGlobals) {
54
- const s = this.initialGlobals[e];
55
- s === void 0 && console.error(`global ${e} is undefined`), this.setGlobal(e, s);
80
+ const a = this.initialGlobals[e];
81
+ a === void 0 && console.error(`global ${e} is undefined`), this.setGlobal(e, a);
56
82
  }
57
83
  }
58
84
  params() {
59
- const t = this.currentStage(), e = this.timer.getDelta(), s = this.inputManager.getInputs(e), a = t?.stageRef?.cameraRef || this.defaultCamera;
85
+ const t = this.currentStage(), e = this.timer.getDelta(), a = this.inputManager.getInputs(e), s = t?.stageRef?.cameraRef || this.defaultCamera;
60
86
  return {
61
87
  delta: e,
62
- inputs: s,
63
- globals: i.globals,
88
+ inputs: a,
89
+ globals: o.globals,
64
90
  me: this,
65
- camera: a
91
+ camera: s
66
92
  };
67
93
  }
68
94
  start() {
@@ -70,10 +96,10 @@ class l {
70
96
  t.start({ ...e, me: t.stageRef }), this.customSetup && this.customSetup(e), this.loop(0);
71
97
  }
72
98
  loop(t) {
73
- if (this.statsRef && this.statsRef.begin(), !h()) {
99
+ if (this.statsRef && this.statsRef.begin(), !m()) {
74
100
  this.timer.update(t);
75
- const e = this.currentStage(), s = this.params(), a = Math.min(s.delta, l.MAX_DELTA_SECONDS), o = { ...s, delta: a };
76
- this.customUpdate && this.customUpdate(o), e && e.stageRef.nodeUpdate({ ...o, me: e.stageRef }), this.totalTime += o.delta, i.time = this.totalTime, this.previousTimeStamp = t;
101
+ const e = this.currentStage(), a = this.params(), s = Math.min(a.delta, r.MAX_DELTA_SECONDS), i = { ...a, delta: s };
102
+ this.customUpdate && this.customUpdate(i), e && e.stageRef.nodeUpdate({ ...i, me: e.stageRef }), this.totalTime += i.delta, o.time = this.totalTime, this.previousTimeStamp = t;
77
103
  }
78
104
  this.statsRef && this.statsRef.end(), this.outOfLoop(), requestAnimationFrame(this.loop.bind(this));
79
105
  }
@@ -88,20 +114,20 @@ class l {
88
114
  return this.getStage(this.currentStageId);
89
115
  }
90
116
  getGlobal(t) {
91
- return r(t);
117
+ return n(t);
92
118
  }
93
119
  setGlobal(t, e) {
94
- n(t, e);
120
+ l(t, e);
95
121
  }
96
122
  onGlobalChange(t, e) {
97
- let s = r(t);
98
- m(i, () => {
99
- const a = r(t);
100
- a !== s && (s = a, e(a));
123
+ let a = n(t);
124
+ f(o, () => {
125
+ const s = n(t);
126
+ s !== a && (a = s, e(s));
101
127
  });
102
128
  }
103
129
  }
104
130
  export {
105
- l as ZylemGame,
106
- l as default
131
+ r as ZylemGame,
132
+ r as default
107
133
  };
@@ -1,5 +1,5 @@
1
1
  import { Color, Material, Vector2 } from 'three';
2
- import { shortHash } from '../core/utility';
2
+ import { shortHash } from '../core/utility/strings';
3
3
  import { ZylemShaderType } from '../core/preset-shader';
4
4
  export interface MaterialOptions {
5
5
  path?: string;
@@ -1,5 +1,5 @@
1
1
  import { Color as n, Vector2 as m, TextureLoader as c, RepeatWrapping as o, MeshPhongMaterial as p, MeshStandardMaterial as u, ShaderMaterial as f, Vector3 as d } from "three";
2
- import { shortHash as M, sortedStringify as w } from "../core/utility.js";
2
+ import { shortHash as M, sortedStringify as w } from "../core/utility/strings.js";
3
3
  import h from "../core/preset-shader.js";
4
4
  class i {
5
5
  static batchMaterialMap = /* @__PURE__ */ new Map();
@@ -1,10 +1,10 @@
1
1
  import { Scene, Color, Object3D, Vector3 } from 'three';
2
- import { Entity } from '../interfaces/entity';
2
+ import { Entity, LifecycleFunction } from '../interfaces/entity';
3
3
  import { GameEntity } from '../entities/entity';
4
4
  import { ZylemCamera } from '../camera/zylem-camera';
5
5
  import { SetupFunction } from '../core/base-node-life-cycle';
6
6
  interface SceneState {
7
- backgroundColor: Color;
7
+ backgroundColor: Color | string;
8
8
  backgroundImage: string | null;
9
9
  }
10
10
  export declare class ZylemScene implements Entity<ZylemScene> {
@@ -13,14 +13,14 @@ export declare class ZylemScene implements Entity<ZylemScene> {
13
13
  scene: Scene;
14
14
  zylemCamera: ZylemCamera;
15
15
  containerElement: HTMLElement | null;
16
+ update: LifecycleFunction<ZylemScene>;
17
+ _collision?: ((entity: any, other: any, globals?: any) => void) | undefined;
18
+ _destroy?: ((globals?: any) => void) | undefined;
19
+ name?: string | undefined;
20
+ tag?: Set<string> | undefined;
16
21
  constructor(id: string, camera: ZylemCamera, state: SceneState);
17
- /**
18
- * Setup the container element and append camera's renderer
19
- */
20
- private setupContainer;
21
22
  setup(): void;
22
23
  destroy(): void;
23
- update({ delta }: Partial<any>): void;
24
24
  /**
25
25
  * Setup camera with the scene
26
26
  */
@@ -1,74 +1,60 @@
1
- import { Scene as r, Color as n, TextureLoader as o, AmbientLight as m, DirectionalLight as d, Vector3 as h, GridHelper as l } from "three";
2
- import { debugState as c } from "../debug/debug-state.js";
1
+ import { Scene as d, Color as i, TextureLoader as n, AmbientLight as m, DirectionalLight as c, Vector3 as h, GridHelper as l } from "three";
2
+ import { debugState as g } from "../debug/debug-state.js";
3
3
  import { getGlobalState as p } from "../game/game-state.js";
4
- class y {
4
+ class b {
5
5
  type = "Scene";
6
6
  _setup;
7
7
  scene;
8
8
  zylemCamera;
9
9
  containerElement = null;
10
- constructor(e, t, a) {
11
- const i = new r();
12
- if (i.background = new n(a.backgroundColor), a.backgroundImage) {
13
- const s = new o().load(a.backgroundImage);
14
- i.background = s;
10
+ update = () => {
11
+ };
12
+ _collision;
13
+ _destroy;
14
+ name;
15
+ tag;
16
+ constructor(e, s, a) {
17
+ const o = new d(), t = a.backgroundColor instanceof i ? a.backgroundColor : new i(a.backgroundColor);
18
+ if (o.background = t, a.backgroundImage) {
19
+ const r = new n().load(a.backgroundImage);
20
+ o.background = r;
15
21
  }
16
- this.scene = i, this.zylemCamera = t, this.setupContainer(e), this.setupLighting(i), this.setupCamera(i, t), c.on && this.debugScene();
17
- }
18
- /**
19
- * Setup the container element and append camera's renderer
20
- */
21
- setupContainer(e) {
22
- let t = document.getElementById(e);
23
- if (!t) {
24
- console.warn(`Could not find element with id: ${e}`);
25
- const a = document.createElement("main");
26
- a.setAttribute("id", e), document.body.appendChild(a), t = a;
27
- }
28
- t?.firstChild && t.removeChild(t.firstChild), this.containerElement = t, t?.appendChild(this.zylemCamera.getDomElement());
22
+ this.scene = o, this.zylemCamera = s, this.setupLighting(o), this.setupCamera(o, s), g.on && this.debugScene();
29
23
  }
30
24
  setup() {
31
25
  this._setup && this._setup({ me: this, camera: this.zylemCamera, globals: p() });
32
26
  }
33
27
  destroy() {
34
- if (this.containerElement && this.zylemCamera)
35
- try {
36
- const e = this.zylemCamera.getDomElement();
37
- e && e.parentElement === this.containerElement && this.containerElement.removeChild(e);
38
- } catch {
39
- }
40
28
  this.zylemCamera && this.zylemCamera.destroy && this.zylemCamera.destroy(), this.scene && this.scene.traverse((e) => {
41
- e.geometry && e.geometry.dispose?.(), e.material && (Array.isArray(e.material) ? e.material.forEach((t) => t.dispose?.()) : e.material.dispose?.());
29
+ e.geometry && e.geometry.dispose?.(), e.material && (Array.isArray(e.material) ? e.material.forEach((s) => s.dispose?.()) : e.material.dispose?.());
42
30
  });
43
31
  }
44
- update({ delta: e }) {
45
- }
46
32
  /**
47
33
  * Setup camera with the scene
48
34
  */
49
- setupCamera(e, t) {
50
- e.add(t.cameraRig), t.setup(e);
35
+ setupCamera(e, s) {
36
+ e.add(s.cameraRig), s.setup(e);
51
37
  }
52
38
  /**
53
39
  * Setup scene lighting
54
40
  */
55
41
  setupLighting(e) {
56
- const t = new m(16777215, 2);
57
- e.add(t);
58
- const a = new d(16777215, 2);
42
+ const s = new m(16777215, 2);
43
+ e.add(s);
44
+ const a = new c(16777215, 2);
59
45
  a.name = "Light", a.position.set(0, 100, 0), a.castShadow = !0, a.shadow.camera.near = 0.1, a.shadow.camera.far = 2e3, a.shadow.camera.left = -100, a.shadow.camera.right = 100, a.shadow.camera.top = 100, a.shadow.camera.bottom = -100, a.shadow.mapSize.width = 2048, a.shadow.mapSize.height = 2048, e.add(a);
60
46
  }
61
47
  /**
62
48
  * Update renderer size - delegates to camera
63
49
  */
64
- updateRenderer(e, t) {
65
- this.zylemCamera.resize(e, t);
50
+ updateRenderer(e, s) {
51
+ this.zylemCamera.resize(e, s);
66
52
  }
67
53
  /**
68
54
  * Add object to scene
69
55
  */
70
- add(e, t = new h(0, 0, 0)) {
71
- e.position.set(t.x, t.y, t.z), this.scene.add(e);
56
+ add(e, s = new h(0, 0, 0)) {
57
+ e.position.set(s.x, s.y, s.z), this.scene.add(e);
72
58
  }
73
59
  /**
74
60
  * Add game entity to scene
@@ -85,5 +71,5 @@ class y {
85
71
  }
86
72
  }
87
73
  export {
88
- y as ZylemScene
74
+ b as ZylemScene
89
75
  };
@@ -0,0 +1,44 @@
1
+ import type { Stage } from './stage';
2
+ import type { StageOptions, ZylemStageConfig } from './zylem-stage';
3
+ /**
4
+ * A lightweight, serializable blueprint representing the initial configuration
5
+ * of a `ZylemStage`. It is intentionally minimal and should not include
6
+ * entities, functions, or runtime references. Use blueprints only to build
7
+ * stages.
8
+ */
9
+ export interface StageBlueprint {
10
+ id: string;
11
+ name?: string;
12
+ config: Partial<ZylemStageConfig>;
13
+ }
14
+ export declare const stageBlueprintsState: {
15
+ byId: Record<string, StageBlueprint>;
16
+ order: string[];
17
+ currentId: string | null;
18
+ };
19
+ /** Reset the blueprints store back to its initial empty state. */
20
+ export declare function resetStageBlueprints(): void;
21
+ /** Create and register a new `StageBlueprint`. */
22
+ export declare function createStageBlueprint(config: Partial<ZylemStageConfig>, options?: {
23
+ id?: string;
24
+ name?: string;
25
+ setCurrent?: boolean;
26
+ }): StageBlueprint;
27
+ /** Upsert a blueprint into the store. */
28
+ export declare function upsertStageBlueprint(blueprint: StageBlueprint): void;
29
+ /** Remove a blueprint by id. */
30
+ export declare function removeStageBlueprint(id: string): void;
31
+ /** Get a blueprint by id. */
32
+ export declare function getStageBlueprint(id: string): StageBlueprint | undefined;
33
+ /** List all blueprints in insertion order. */
34
+ export declare function listStageBlueprints(): StageBlueprint[];
35
+ /** Set the current blueprint id (or clear by passing null). */
36
+ export declare function setCurrentStageBlueprint(id: string | null): void;
37
+ /** Get the current blueprint object, if any. */
38
+ export declare function getCurrentStageBlueprint(): StageBlueprint | null;
39
+ /**
40
+ * Build a `Stage` instance from a blueprint and optional extra `StageOptions`
41
+ * (e.g., entities or a camera wrapper). This does not load the stage; callers
42
+ * should pass the returned `Stage` to the game and call `load` as usual.
43
+ */
44
+ export declare function buildStageFromBlueprint(input: string | StageBlueprint, ...extras: StageOptions): Stage;
@@ -0,0 +1,56 @@
1
+ import { proxy as d } from "valtio/vanilla";
2
+ import { deepClone as i } from "valtio/utils";
3
+ import { nanoid as c } from "nanoid";
4
+ import { stage as l } from "./stage.js";
5
+ const u = {
6
+ byId: {},
7
+ order: [],
8
+ currentId: null
9
+ }, e = d(i(u));
10
+ function m() {
11
+ const r = i(u);
12
+ Object.keys(r).forEach((t) => {
13
+ e[t] = r[t];
14
+ });
15
+ }
16
+ function I(r, t) {
17
+ const n = t?.id ?? c(), o = { id: n, name: t?.name, config: { ...r } };
18
+ return e.byId[n] = o, e.order.includes(n) || (e.order = [...e.order, n]), t?.setCurrent && (e.currentId = n), o;
19
+ }
20
+ function S(r) {
21
+ e.byId[r.id] = { ...r, config: { ...r.config } }, e.order.includes(r.id) || (e.order = [...e.order, r.id]);
22
+ }
23
+ function B(r) {
24
+ delete e.byId[r], e.order = e.order.filter((t) => t !== r), e.currentId === r && (e.currentId = null);
25
+ }
26
+ function f(r) {
27
+ return e.byId[r];
28
+ }
29
+ function b() {
30
+ return e.order.map((r) => e.byId[r]).filter((r) => !!r);
31
+ }
32
+ function y(r) {
33
+ e.currentId = r;
34
+ }
35
+ function C() {
36
+ const r = e.currentId;
37
+ return r ? e.byId[r] ?? null : null;
38
+ }
39
+ function h(r, ...t) {
40
+ const n = typeof r == "string" ? f(r) : r;
41
+ if (!n)
42
+ throw new Error("Stage blueprint not found");
43
+ return l(n.config, ...t);
44
+ }
45
+ export {
46
+ h as buildStageFromBlueprint,
47
+ I as createStageBlueprint,
48
+ C as getCurrentStageBlueprint,
49
+ f as getStageBlueprint,
50
+ b as listStageBlueprints,
51
+ B as removeStageBlueprint,
52
+ m as resetStageBlueprints,
53
+ y as setCurrentStageBlueprint,
54
+ e as stageBlueprintsState,
55
+ S as upsertStageBlueprint
56
+ };
@@ -0,0 +1,9 @@
1
+ import type { StageOptions, ZylemStageConfig } from './zylem-stage';
2
+ export declare const stageDefaultsState: Partial<ZylemStageConfig>;
3
+ /** Replace multiple defaults at once (shallow merge). */
4
+ export declare function setStageDefaults(partial: Partial<ZylemStageConfig>): void;
5
+ /** Reset defaults back to library defaults. */
6
+ export declare function resetStageDefaults(): void;
7
+ export declare function getStageOptions(options: StageOptions): StageOptions;
8
+ /** Get a plain object copy of the current defaults. */
9
+ export declare function getStageDefaultConfig(): Partial<ZylemStageConfig>;
@@ -0,0 +1,42 @@
1
+ import { proxy as i } from "valtio/vanilla";
2
+ import { Vector3 as r } from "three";
3
+ import { ZylemBlueColor as g } from "../core/utility/vector.js";
4
+ const o = {
5
+ backgroundColor: g,
6
+ backgroundImage: null,
7
+ inputs: {
8
+ p1: ["gamepad-1", "keyboard"],
9
+ p2: ["gamepad-2", "keyboard"]
10
+ },
11
+ gravity: new r(0, 0, 0),
12
+ variables: {}
13
+ }, t = i({
14
+ ...o
15
+ });
16
+ function b(a) {
17
+ Object.assign(t, a);
18
+ }
19
+ function d() {
20
+ Object.assign(t, o);
21
+ }
22
+ function m(a) {
23
+ const n = u();
24
+ let e = {};
25
+ return typeof a[0] == "object" && (e = a.shift() ?? {}), [{ ...n, ...e }, ...a];
26
+ }
27
+ function u() {
28
+ return {
29
+ backgroundColor: t.backgroundColor,
30
+ backgroundImage: t.backgroundImage ?? null,
31
+ inputs: t.inputs ? { ...t.inputs } : void 0,
32
+ gravity: t.gravity,
33
+ variables: t.variables ? { ...t.variables } : void 0
34
+ };
35
+ }
36
+ export {
37
+ u as getStageDefaultConfig,
38
+ m as getStageOptions,
39
+ d as resetStageDefaults,
40
+ b as setStageDefaults,
41
+ t as stageDefaultsState
42
+ };
@@ -1,6 +1,6 @@
1
1
  import { BaseNode } from '../core/base-node';
2
2
  import { DestroyFunction, SetupContext, SetupFunction, UpdateFunction } from '../core/base-node-life-cycle';
3
- import { StageOptions, ZylemStage } from './zylem-stage';
3
+ import { StageOptionItem, StageOptions, ZylemStage } from './zylem-stage';
4
4
  import { ZylemCamera } from '../camera/zylem-camera';
5
5
  import { CameraWrapper } from '../camera/camera';
6
6
  type NodeLike = {
@@ -10,7 +10,7 @@ type AnyNode = NodeLike | Promise<NodeLike>;
10
10
  type EntityInput = AnyNode | (() => AnyNode) | (() => Promise<any>);
11
11
  export declare class Stage {
12
12
  stageRef: ZylemStage;
13
- options: StageOptions;
13
+ options: StageOptionItem[];
14
14
  update: UpdateFunction<ZylemStage>;
15
15
  setup: SetupFunction<ZylemStage>;
16
16
  destroy: DestroyFunction<ZylemStage>;
@@ -1,7 +1,8 @@
1
1
  import { ZylemStage as n } from "./zylem-stage.js";
2
2
  import { CameraWrapper as r } from "../camera/camera.js";
3
3
  import { stageState as i, setStageVariable as g, getStageVariable as p } from "./stage-state.js";
4
- class f {
4
+ import { getStageOptions as f } from "./stage-default.js";
5
+ class d {
5
6
  stageRef;
6
7
  options = [];
7
8
  update = () => {
@@ -49,10 +50,11 @@ class f {
49
50
  return p(t);
50
51
  }
51
52
  }
52
- function R(...a) {
53
- return new f(a);
53
+ function l(...a) {
54
+ const t = f(a);
55
+ return new d([...t]);
54
56
  }
55
57
  export {
56
- f as Stage,
57
- R as stage
58
+ d as Stage,
59
+ l as stage
58
60
  };
@@ -12,7 +12,7 @@ import { StageDebugDelegate } from './stage-debug-delegate';
12
12
  import { BaseEntityInterface } from '../types/entity-types';
13
13
  export interface ZylemStageConfig {
14
14
  inputs: Record<string, string[]>;
15
- backgroundColor: Color;
15
+ backgroundColor: Color | string;
16
16
  backgroundImage: string | null;
17
17
  gravity: Vector3;
18
18
  variables: Record<string, any>;
@@ -21,8 +21,9 @@ export interface ZylemStageConfig {
21
21
  type NodeLike = {
22
22
  create: Function;
23
23
  };
24
- type StageEntityInput = NodeLike | Promise<any> | (() => NodeLike | Promise<any>);
25
- export type StageOptions = Array<Partial<ZylemStageConfig> | CameraWrapper | StageEntityInput>;
24
+ export type StageEntityInput = NodeLike | Promise<any> | (() => NodeLike | Promise<any>);
25
+ export type StageOptionItem = Partial<ZylemStageConfig> | CameraWrapper | StageEntityInput;
26
+ export type StageOptions = [] | [Partial<ZylemStageConfig>, ...StageOptionItem[]];
26
27
  export type StageState = ZylemStageConfig & {
27
28
  entities: GameEntityInterface[];
28
29
  };