@skewedaspect/sage 0.7.0 → 0.7.1

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/sage.es.js CHANGED
@@ -1,10 +1,10 @@
1
- var k = Object.defineProperty;
2
- var L = (r, e, t) => e in r ? k(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var n = (r, e, t) => L(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { Scene as A, Vector3 as C, FreeCamera as I, HemisphericLight as B, DirectionalLight as G, PointLight as V, SpotLight as K, MeshBuilder as v, PhysicsAggregate as T, Sound as U, SceneLoader as E, NullEngine as R, WebGPUEngine as z, Engine as P, HavokPlugin as O } from "@babylonjs/core";
5
- import H from "@babylonjs/havok";
6
- const b = "0.6.2";
7
- class W {
1
+ var M = Object.defineProperty;
2
+ var k = (r, e, t) => e in r ? M(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var n = (r, e, t) => k(r, typeof e != "symbol" ? e + "" : e, t);
4
+ import { Scene as L, Vector3 as C, FreeCamera as A, HemisphericLight as I, DirectionalLight as B, PointLight as G, SpotLight as V, MeshBuilder as v, PhysicsAggregate as K, Sound as T, LoadAssetContainerAsync as U, ImportMeshAsync as R, NullEngine as z, WebGPUEngine as P, Engine as O, HavokPlugin as H } from "@babylonjs/core";
5
+ import W from "@babylonjs/havok";
6
+ const b = "0.7.0";
7
+ class F {
8
8
  /**
9
9
  * Creates an instance of SkewedAspectGameEngine.
10
10
  * @param canvas - The game canvas.
@@ -112,7 +112,7 @@ class W {
112
112
  this._log.warn("Game engine is not started. Skipping stop.");
113
113
  }
114
114
  }
115
- class F {
115
+ class N {
116
116
  constructor() {
117
117
  n(this, "timers");
118
118
  this.timers = /* @__PURE__ */ new Map();
@@ -201,7 +201,7 @@ class F {
201
201
  console.warn(`[${e}]: Timer '${t}' does not exist`);
202
202
  }
203
203
  }
204
- class N {
204
+ class J {
205
205
  trace(e, t, ...s) {
206
206
  }
207
207
  debug(e, t, ...s) {
@@ -218,7 +218,7 @@ class N {
218
218
  }
219
219
  }
220
220
  class u {
221
- constructor(e, t = "none", s = new N()) {
221
+ constructor(e, t = "none", s = new J()) {
222
222
  n(this, "category");
223
223
  n(this, "backend");
224
224
  n(this, "minLevel");
@@ -273,14 +273,14 @@ class u {
273
273
  }
274
274
  }
275
275
  }
276
- class J {
276
+ class Y {
277
277
  /**
278
278
  * Create a new LoggingUtility.
279
279
  *
280
280
  * @param level - The minimum logging level (defaults to INFO)
281
281
  * @param backend - The logging backend to use (defaults to ConsoleBackend)
282
282
  */
283
- constructor(e = "debug", t = new F()) {
283
+ constructor(e = "debug", t = new N()) {
284
284
  n(this, "backend");
285
285
  n(this, "level");
286
286
  n(this, "loggers");
@@ -326,7 +326,7 @@ class J {
326
326
  return t;
327
327
  }
328
328
  }
329
- class Y {
329
+ class j {
330
330
  /**
331
331
  * Creates a new GameEventBus instance
332
332
  *
@@ -430,7 +430,7 @@ class Y {
430
430
  t === 0 ? this._log.debug(`No subscribers found for event: ${e.type}`) : this._log.trace(`Event ${e.type} dispatched to ${t} subscribers`);
431
431
  }
432
432
  }
433
- class j {
433
+ class X {
434
434
  constructor(e, t, s, i) {
435
435
  n(this, "_canvas");
436
436
  n(this, "_engine");
@@ -443,7 +443,7 @@ class j {
443
443
  * @returns A new Scene instance with physics enabled
444
444
  */
445
445
  createScene() {
446
- return this._log.debug("Creating new scene..."), new A(this._engine);
446
+ return this._log.debug("Creating new scene..."), new L(this._engine);
447
447
  }
448
448
  enablePhysics(e, t = new C(0, -9.8, 0)) {
449
449
  this._log.debug(
@@ -461,7 +461,7 @@ class j {
461
461
  */
462
462
  createFreeCamera(e, t, s, i) {
463
463
  this._log.debug(`Creating free camera: ${e}`);
464
- const o = new I(e, t, s);
464
+ const o = new A(e, t, s);
465
465
  return o.setTarget(C.Zero()), i = i ?? this._canvas, i && o.attachControl(i, !0), o;
466
466
  }
467
467
  // Lighting Utilities
@@ -475,7 +475,7 @@ class j {
475
475
  */
476
476
  createHemisphericLight(e, t, s, i = 0.7) {
477
477
  this._log.debug(`Creating hemispheric light: ${e}`);
478
- const o = new B(e, t, s);
478
+ const o = new I(e, t, s);
479
479
  return o.intensity = i, o;
480
480
  }
481
481
  /**
@@ -488,7 +488,7 @@ class j {
488
488
  */
489
489
  createDirectionalLight(e, t, s, i = 1) {
490
490
  this._log.debug(`Creating directional light: ${e}`);
491
- const o = new G(e, t, s);
491
+ const o = new B(e, t, s);
492
492
  return o.intensity = i, o;
493
493
  }
494
494
  /**
@@ -501,7 +501,7 @@ class j {
501
501
  */
502
502
  createPointLight(e, t, s, i = 1) {
503
503
  this._log.debug(`Creating point light: ${e}`);
504
- const o = new V(e, t, s);
504
+ const o = new G(e, t, s);
505
505
  return o.intensity = i, o;
506
506
  }
507
507
  /**
@@ -517,7 +517,7 @@ class j {
517
517
  */
518
518
  createSpotLight(e, t, s, i, o, c, a = 1) {
519
519
  this._log.debug(`Creating spot light: ${e}`);
520
- const h = new K(e, t, s, i, o, c);
520
+ const h = new V(e, t, s, i, o, c);
521
521
  return h.intensity = a, h;
522
522
  }
523
523
  // Mesh Creation Utilities
@@ -581,7 +581,7 @@ class j {
581
581
  addPhysics(e, t, s = {}, i) {
582
582
  this._log.debug(`Adding physics to mesh: ${e.name}`);
583
583
  const o = { mass: 1, restitution: 0.75, friction: 0.5 };
584
- return new T(e, t, { ...o, ...s }, i);
584
+ return new K(e, t, { ...o, ...s }, i);
585
585
  }
586
586
  // Audio Utilities
587
587
  /**
@@ -595,7 +595,7 @@ class j {
595
595
  createSound(e, t, s, i = {}) {
596
596
  this._log.debug(`Creating sound: ${e}`);
597
597
  const c = { ...{ loop: !1, autoplay: !1, volume: 1, playbackRate: 1 }, ...i };
598
- return new U(
598
+ return new T(
599
599
  e,
600
600
  t,
601
601
  s,
@@ -615,7 +615,7 @@ class j {
615
615
  async loadModel(e, t, s) {
616
616
  this._log.debug(`Loading model: ${e}${t}`);
617
617
  try {
618
- const i = await E.LoadAssetContainerAsync(e, t, s);
618
+ const i = await U(`${e}${t}`, s);
619
619
  return this._log.debug(`Model loaded successfully: ${t}`), i;
620
620
  } catch (i) {
621
621
  throw this._log.error(`Failed to load model: ${t}`, i), i;
@@ -632,7 +632,7 @@ class j {
632
632
  async importMeshes(e, t, s, i) {
633
633
  this._log.debug(`Importing meshes from: ${t}${s}`);
634
634
  try {
635
- const o = await E.ImportMeshAsync(e, t, s, i);
635
+ const o = await R(`${t}${s}`, i, { meshNames: e });
636
636
  return this._log.debug(`Meshes imported successfully: ${e.length > 0 ? e.join(", ") : "all"}`), o;
637
637
  } catch (o) {
638
638
  throw this._log.error(`Failed to import meshes from: ${s}`, o), o;
@@ -645,12 +645,12 @@ class j {
645
645
  return this._log.info("Tearing down SceneEngine"), this._log.info("SceneEngine torn down successfully"), Promise.resolve();
646
646
  }
647
647
  }
648
- const X = [
648
+ const Z = [
649
649
  "trigger",
650
650
  "toggle",
651
651
  "value"
652
652
  ];
653
- class Z {
653
+ class q {
654
654
  //------------------------------------------------------------------------------------------------------------------
655
655
  /**
656
656
  * Create a new trigger binding
@@ -751,7 +751,7 @@ class Z {
751
751
  };
752
752
  }
753
753
  }
754
- class q {
754
+ class Q {
755
755
  //------------------------------------------------------------------------------------------------------------------
756
756
  /**
757
757
  * Create a new toggle binding
@@ -880,7 +880,7 @@ class q {
880
880
  };
881
881
  }
882
882
  }
883
- class Q {
883
+ class ee {
884
884
  //------------------------------------------------------------------------------------------------------------------
885
885
  /**
886
886
  * Create a new value binding
@@ -1196,7 +1196,7 @@ class x {
1196
1196
  };
1197
1197
  }
1198
1198
  }
1199
- class ee {
1199
+ class te {
1200
1200
  /**
1201
1201
  * Creates an instance of BindingManager.
1202
1202
  *
@@ -1277,7 +1277,7 @@ class ee {
1277
1277
  const { deviceID: s, ...i } = e.input;
1278
1278
  switch (e.type) {
1279
1279
  case "trigger":
1280
- return new Z(
1280
+ return new q(
1281
1281
  t,
1282
1282
  s,
1283
1283
  this._createInputSourceFromDefinition(i),
@@ -1287,7 +1287,7 @@ class ee {
1287
1287
  }
1288
1288
  );
1289
1289
  case "toggle":
1290
- return new q(
1290
+ return new Q(
1291
1291
  t,
1292
1292
  s,
1293
1293
  this._createInputSourceFromDefinition(i),
@@ -1297,7 +1297,7 @@ class ee {
1297
1297
  }
1298
1298
  );
1299
1299
  case "value":
1300
- return new Q(
1300
+ return new ee(
1301
1301
  t,
1302
1302
  s,
1303
1303
  this._createInputSourceFromDefinition(i),
@@ -1464,7 +1464,7 @@ class ee {
1464
1464
  */
1465
1465
  $registerBinding(e) {
1466
1466
  var t;
1467
- if (!X.includes(e.type))
1467
+ if (!Z.includes(e.type))
1468
1468
  throw new Error(`Invalid binding type: ${e.type}`);
1469
1469
  e.context && !this._contexts.has(e.context) && this.registerContext(e.context), this._bindings.has(e.deviceID) || this._bindings.set(e.deviceID, []), (t = this._bindings.get(e.deviceID)) == null || t.push(e), this._log.debug(`Registered ${e.type} binding for "${e.action.name}" in context "${e.context || null}"`);
1470
1470
  }
@@ -1570,10 +1570,10 @@ class ee {
1570
1570
  function w() {
1571
1571
  return typeof window < "u" && typeof window.document < "u";
1572
1572
  }
1573
- function D() {
1573
+ function E() {
1574
1574
  return w() && !!window.navigator.gpu;
1575
1575
  }
1576
- class te {
1576
+ class se {
1577
1577
  //------------------------------------------------------------------------------------------------------------------
1578
1578
  constructor(e, t, s, i, o) {
1579
1579
  n(this, "_engine");
@@ -1613,7 +1613,7 @@ class te {
1613
1613
  this._log.info("Tearing down GameManager"), this.started && await this.stop(), w() && window.removeEventListener("resize", this._boundResizeHandler), this._log.info("GameManager torn down successfully");
1614
1614
  }
1615
1615
  }
1616
- class pe {
1616
+ class fe {
1617
1617
  constructor() {
1618
1618
  n(this, "entity", null);
1619
1619
  }
@@ -1633,7 +1633,7 @@ class pe {
1633
1633
  this.entity = e;
1634
1634
  }
1635
1635
  }
1636
- class se {
1636
+ class ie {
1637
1637
  /**
1638
1638
  * Creates an instance of GameEntityBase.
1639
1639
  * @param type - The type of the entity.
@@ -1729,7 +1729,7 @@ class se {
1729
1729
  }
1730
1730
  }
1731
1731
  }
1732
- class ie {
1732
+ class ne {
1733
1733
  /**
1734
1734
  * Creates an instance of EntityManager.
1735
1735
  * @param eventBus - The event bus for the entity manager.
@@ -1815,7 +1815,7 @@ class ie {
1815
1815
  const a = await s.onBeforeCreate(i);
1816
1816
  a !== void 0 && (i = a);
1817
1817
  }
1818
- const o = new se(
1818
+ const o = new ie(
1819
1819
  s.type,
1820
1820
  this.eventBus,
1821
1821
  i,
@@ -1884,7 +1884,7 @@ class ie {
1884
1884
  this.entityDefinitions.clear(), this._log.info("EntityManager torn down successfully");
1885
1885
  }
1886
1886
  }
1887
- class ne {
1887
+ class oe {
1888
1888
  constructor(e, t, s) {
1889
1889
  n(this, "_eventBus");
1890
1890
  n(this, "_sceneEngine");
@@ -1967,7 +1967,7 @@ class ne {
1967
1967
  return this._registeredLevels.clear(), this._currentLevel = null, Promise.resolve();
1968
1968
  }
1969
1969
  }
1970
- class oe {
1970
+ class ae {
1971
1971
  //------------------------------------------------------------------------------------------------------------------
1972
1972
  /**
1973
1973
  * Create a new KeyboardResourceAccess
@@ -2078,7 +2078,7 @@ class oe {
2078
2078
  this._onInputChanged && this._onInputChanged(this._keyboardDevice, e);
2079
2079
  }
2080
2080
  }
2081
- class ae {
2081
+ class re {
2082
2082
  //------------------------------------------------------------------------------------------------------------------
2083
2083
  /**
2084
2084
  * Create a new MouseResourceAccess
@@ -2247,7 +2247,7 @@ class ae {
2247
2247
  this._onInputChanged && this._onInputChanged(this._mouseDevice, e);
2248
2248
  }
2249
2249
  }
2250
- class re {
2250
+ class ce {
2251
2251
  //------------------------------------------------------------------------------------------------------------------
2252
2252
  /**
2253
2253
  * Create a new GamepadResourceAccess
@@ -2454,7 +2454,7 @@ class re {
2454
2454
  this._onInputChanged && this._onInputChanged(e, t);
2455
2455
  }
2456
2456
  }
2457
- class ce {
2457
+ class he {
2458
2458
  //------------------------------------------------------------------------------------------------------------------
2459
2459
  /**
2460
2460
  * Create a new UserInputManager
@@ -2470,7 +2470,7 @@ class ce {
2470
2470
  n(this, "_gamepadRA");
2471
2471
  /** Logger instance */
2472
2472
  n(this, "_log");
2473
- this._eventBus = e, this._log = (s == null ? void 0 : s.getLogger("UserInputManager")) || new u("UserInputManager"), this._log.info("Initializing UserInputManager"), this._log.debug("Initializing input resource access classes"), this._keyboardRA = new oe(), this._mouseRA = new ae(t), this._gamepadRA = new re(), this._log.debug("Registering input event callbacks"), this._keyboardRA.onDeviceConnected(this._publishDeviceConnected.bind(this)), this._keyboardRA.onInputChanged(this._publishInputChanged.bind(this)), this._mouseRA.onDeviceConnected(this._publishDeviceConnected.bind(this)), this._mouseRA.onInputChanged(this._publishInputChanged.bind(this)), this._gamepadRA.onDeviceConnected(this._publishDeviceConnected.bind(this)), this._gamepadRA.onDeviceDisconnected(this._publishDeviceDisconnected.bind(this)), this._gamepadRA.onInputChanged(this._publishInputChanged.bind(this)), this._log.info("UserInputManager initialized successfully");
2473
+ this._eventBus = e, this._log = (s == null ? void 0 : s.getLogger("UserInputManager")) || new u("UserInputManager"), this._log.info("Initializing UserInputManager"), this._log.debug("Initializing input resource access classes"), this._keyboardRA = new ae(), this._mouseRA = new re(t), this._gamepadRA = new ce(), this._log.debug("Registering input event callbacks"), this._keyboardRA.onDeviceConnected(this._publishDeviceConnected.bind(this)), this._keyboardRA.onInputChanged(this._publishInputChanged.bind(this)), this._mouseRA.onDeviceConnected(this._publishDeviceConnected.bind(this)), this._mouseRA.onInputChanged(this._publishInputChanged.bind(this)), this._gamepadRA.onDeviceConnected(this._publishDeviceConnected.bind(this)), this._gamepadRA.onDeviceDisconnected(this._publishDeviceDisconnected.bind(this)), this._gamepadRA.onInputChanged(this._publishInputChanged.bind(this)), this._log.info("UserInputManager initialized successfully");
2474
2474
  }
2475
2475
  //------------------------------------------------------------------------------------------------------------------
2476
2476
  // Private methods
@@ -2570,24 +2570,24 @@ class ce {
2570
2570
  this._gamepadRA.pollGamepads();
2571
2571
  }
2572
2572
  }
2573
- async function M(r, e) {
2574
- const t = new z(r, e);
2573
+ async function D(r, e) {
2574
+ const t = new P(r, e);
2575
2575
  return await t.initAsync(), t;
2576
2576
  }
2577
2577
  function m(r, e) {
2578
- return new P(r, e.antialias, e.options, e.adaptToDeviceRatio);
2578
+ return new O(r, e.antialias, e.options, e.adaptToDeviceRatio);
2579
2579
  }
2580
- function he(r) {
2581
- return new R(r);
2580
+ function le(r) {
2581
+ return new z(r);
2582
2582
  }
2583
- async function le(r, e) {
2583
+ async function de(r, e) {
2584
2584
  if (r === null)
2585
- return console.debug("Using Null Engine"), he(e);
2585
+ return console.debug("Using Null Engine"), le(e);
2586
2586
  const t = e.engine || "auto";
2587
2587
  if (t === "webgpu")
2588
- if (D())
2588
+ if (E())
2589
2589
  try {
2590
- return console.debug("Using forced WebGPU engine"), await M(r, e);
2590
+ return console.debug("Using forced WebGPU engine"), await D(r, e);
2591
2591
  } catch (s) {
2592
2592
  throw console.error("Forced WebGPU initialization failed:", s), new Error(
2593
2593
  "Forced WebGPU failed to initialize. If WebGPU is required, check browser compatibility."
@@ -2597,9 +2597,9 @@ async function le(r, e) {
2597
2597
  throw new Error("WebGPU was forced but is not available in this browser.");
2598
2598
  if (t === "webgl")
2599
2599
  return console.debug("Using forced WebGL engine"), m(r, e);
2600
- if (D())
2600
+ if (E())
2601
2601
  try {
2602
- return console.debug("Using WebGPU"), M(r, e).catch((s) => (console.warn("WebGPU initialization failed, falling back to WebGL:", s), m(r, e)));
2602
+ return console.debug("Using WebGPU"), D(r, e).catch((s) => (console.warn("WebGPU initialization failed, falling back to WebGL:", s), m(r, e)));
2603
2603
  } catch (s) {
2604
2604
  console.warn("WebGPU initialization failed, falling back to WebGL:", s);
2605
2605
  }
@@ -2607,11 +2607,11 @@ async function le(r, e) {
2607
2607
  console.warn("WebGPU not supported, falling back to WebGL.");
2608
2608
  return console.debug("Using WebGL"), m(r, e);
2609
2609
  }
2610
- async function de() {
2611
- const r = await H();
2612
- return new O(!0, r);
2610
+ async function ue() {
2611
+ const r = await W();
2612
+ return new H(!0, r);
2613
2613
  }
2614
- const fe = ["keyboard", "mouse", "gamepad"], ye = [
2614
+ const ye = ["keyboard", "mouse", "gamepad"], ve = [
2615
2615
  "trace",
2616
2616
  "debug",
2617
2617
  "info",
@@ -2619,7 +2619,7 @@ const fe = ["keyboard", "mouse", "gamepad"], ye = [
2619
2619
  "error",
2620
2620
  "none"
2621
2621
  ];
2622
- class ve {
2622
+ class be {
2623
2623
  //------------------------------------------------------------------------------------------------------------------
2624
2624
  constructor(e) {
2625
2625
  n(this, "_name");
@@ -2698,25 +2698,25 @@ class ve {
2698
2698
  this._scene && (this._log.info(`Disposing level: ${this._name}`), this._scene.dispose(), this._scene = null);
2699
2699
  }
2700
2700
  }
2701
- async function be(r, e, t = {}) {
2702
- const s = new J(t.logLevel || "debug"), i = s.getLogger("SAGE");
2701
+ async function me(r, e, t = {}) {
2702
+ const s = new Y(t.logLevel || "debug"), i = s.getLogger("SAGE");
2703
2703
  i.info(`Initializing SAGE Game Engine v${b}...`), i.debug("Creating rendering engine...");
2704
- const o = await le(r, t.renderOptions || {});
2704
+ const o = await de(r, t.renderOptions || {});
2705
2705
  i.debug("Creating physics engine...");
2706
- const c = await de();
2706
+ const c = await ue();
2707
2707
  i.debug("Creating event bus...");
2708
- const a = new Y(s);
2708
+ const a = new j(s);
2709
2709
  i.debug("Creating scene engine...");
2710
- const h = new j(r, o, c, s);
2710
+ const h = new X(r, o, c, s);
2711
2711
  i.debug("Creating managers...");
2712
- const l = new ce(a, r, s), _ = new ee(a, s), d = new ie(a, s, _), f = new ne(a, h, s), p = new te(o, d, l, f, s);
2712
+ const l = new he(a, r, s), _ = new te(a, s), d = new ne(a, s, _), f = new oe(a, h, s), p = new se(o, d, l, f, s);
2713
2713
  i.info(`SAGE Game Engine v${b} initialized successfully.`), i.debug("Loading entities...");
2714
2714
  for (const g of e)
2715
2715
  d.registerEntityDefinition(g);
2716
2716
  if (i.debug("Registering default input bindings..."), t.bindings)
2717
2717
  for (const g of t.bindings)
2718
2718
  _.registerBinding(g);
2719
- return new W(
2719
+ return new F(
2720
2720
  r,
2721
2721
  o,
2722
2722
  c,
@@ -2737,19 +2737,19 @@ async function be(r, e, t = {}) {
2737
2737
  );
2738
2738
  }
2739
2739
  export {
2740
- F as ConsoleBackend,
2741
- se as GameEntity,
2742
- pe as GameEntityBehavior,
2743
- Y as GameEventBus,
2744
- ve as Level,
2745
- ye as LogLevels,
2746
- J as LoggingUtility,
2747
- N as NullBackend,
2740
+ N as ConsoleBackend,
2741
+ ie as GameEntity,
2742
+ fe as GameEntityBehavior,
2743
+ j as GameEventBus,
2744
+ be as Level,
2745
+ ve as LogLevels,
2746
+ Y as LoggingUtility,
2747
+ J as NullBackend,
2748
2748
  u as SAGELogger,
2749
- W as SkewedAspectGameEngine,
2749
+ F as SkewedAspectGameEngine,
2750
2750
  b as VERSION,
2751
- X as bindingTypes,
2752
- be as createGameEngine,
2753
- fe as validDeviceTypes
2751
+ Z as bindingTypes,
2752
+ me as createGameEngine,
2753
+ ye as validDeviceTypes
2754
2754
  };
2755
2755
  //# sourceMappingURL=sage.es.js.map