@skewedaspect/sage 0.9.0-beta.8 → 0.9.0-beta.9
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 +697 -690
- package/dist/sage.es.js.map +1 -1
- package/dist/sage.umd.js +1 -1
- package/dist/sage.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/sage.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CreateAudioEngineAsync as le } from "@babylonjs/core/AudioV2/webAudio/webAudioEngine";
|
|
2
|
-
import { Scene as he, Vector3 as p, HavokPlugin as Y, FreeCamera as B, HemisphericLight as J, DirectionalLight as X, PointLight as Q, SpotLight as ee, MeshBuilder as y, PhysicsAggregate as te, LoadAssetContainerAsync as ce, ImportMeshAsync as de, ImageProcessingConfiguration as v, DefaultRenderingPipeline as ue, Color4 as ge, SSAO2RenderingPipeline as _e, StandardMaterial as R, Texture as fe, CubeTexture as pe, HDRCubeTexture as ye, UniversalCamera as me, ArcRotateCamera as O, Color3 as ve, TransformNode as be, PBRMaterial as we, SoundState as
|
|
2
|
+
import { Scene as he, Vector3 as p, HavokPlugin as Y, FreeCamera as B, HemisphericLight as J, DirectionalLight as X, PointLight as Q, SpotLight as ee, MeshBuilder as y, PhysicsAggregate as te, LoadAssetContainerAsync as ce, ImportMeshAsync as de, ImageProcessingConfiguration as v, DefaultRenderingPipeline as ue, Color4 as ge, SSAO2RenderingPipeline as _e, StandardMaterial as R, Texture as fe, CubeTexture as pe, HDRCubeTexture as ye, UniversalCamera as me, ArcRotateCamera as O, Color3 as ve, TransformNode as be, PBRMaterial as we, SoundState as ie, NullEngine as $e, WebGPUEngine as Se, Engine as Ee, Mesh as w, PhysicsShapeType as S, AbstractMesh as se, ActionManager as L, ExecuteCodeAction as Ce } from "@babylonjs/core";
|
|
3
3
|
import "@babylonjs/loaders/glTF";
|
|
4
4
|
import xe from "@babylonjs/havok";
|
|
5
|
-
const E = "0.9.0-beta.
|
|
5
|
+
const E = "0.9.0-beta.9";
|
|
6
6
|
class Me {
|
|
7
7
|
canvas;
|
|
8
8
|
renderEngine;
|
|
@@ -29,8 +29,8 @@ class Me {
|
|
|
29
29
|
* @param engines
|
|
30
30
|
* @param managers
|
|
31
31
|
*/
|
|
32
|
-
constructor(e, t,
|
|
33
|
-
this.canvas = e, this.renderEngine = t, this.physics =
|
|
32
|
+
constructor(e, t, i, s, n, o, a, l, h) {
|
|
33
|
+
this.canvas = e, this.renderEngine = t, this.physics = i, this.eventBus = s, this.logger = n, this.raycast = o, this.timer = a, this.engines = l, this.managers = h, this._log = n.getLogger("GameEngine");
|
|
34
34
|
}
|
|
35
35
|
//------------------------------------------------------------------------------------------------------------------
|
|
36
36
|
// Public API
|
|
@@ -146,21 +146,21 @@ class Me {
|
|
|
146
146
|
this._log.error(`Error in onTeardown hook: ${t}`), e = e || t;
|
|
147
147
|
}
|
|
148
148
|
for (const t of Object.keys(this.managers)) {
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
149
|
+
const i = this.managers[t];
|
|
150
|
+
if (i)
|
|
151
151
|
try {
|
|
152
|
-
this._log.debug(`Tearing down manager: ${t}`), await
|
|
153
|
-
} catch (
|
|
154
|
-
this._log.error(`Error tearing down manager ${t}: ${
|
|
152
|
+
this._log.debug(`Tearing down manager: ${t}`), await i.$teardown();
|
|
153
|
+
} catch (s) {
|
|
154
|
+
this._log.error(`Error tearing down manager ${t}: ${s}`), e = e || s;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
for (const t of Object.keys(this.engines)) {
|
|
158
|
-
const
|
|
159
|
-
if (
|
|
158
|
+
const i = this.engines[t];
|
|
159
|
+
if (i)
|
|
160
160
|
try {
|
|
161
|
-
this._log.debug(`Tearing down engine: ${t}`), await
|
|
162
|
-
} catch (
|
|
163
|
-
this._log.error(`Error tearing down engine ${t}: ${
|
|
161
|
+
this._log.debug(`Tearing down engine: ${t}`), await i.$teardown();
|
|
162
|
+
} catch (s) {
|
|
163
|
+
this._log.error(`Error tearing down engine ${t}: ${s}`), e = e || s;
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
if (this.started = !1, this._log.info("Game engine stopped successfully"), e)
|
|
@@ -200,7 +200,7 @@ class ke {
|
|
|
200
200
|
* Format a log message with category, timestamp and log level
|
|
201
201
|
*/
|
|
202
202
|
formatMessage(e, t) {
|
|
203
|
-
const
|
|
203
|
+
const i = /* @__PURE__ */ new Date(), s = i.getHours() % 12 || 12, n = i.getMinutes().toString().padStart(2, "0"), o = i.getSeconds().toString().padStart(2, "0"), a = i.getHours() >= 12 ? "PM" : "AM", l = `[${s}:${n}:${o} ${a}]`, h = t.toUpperCase();
|
|
204
204
|
return [
|
|
205
205
|
`${l} %c${h}%c (${e}): `,
|
|
206
206
|
// Format string with placeholders
|
|
@@ -212,41 +212,41 @@ class ke {
|
|
|
212
212
|
// Reset style
|
|
213
213
|
];
|
|
214
214
|
}
|
|
215
|
-
trace(e, t, ...
|
|
216
|
-
const [
|
|
217
|
-
console.debug(
|
|
215
|
+
trace(e, t, ...i) {
|
|
216
|
+
const [s, n, o, a] = this.formatMessage(e, "trace");
|
|
217
|
+
console.debug(s, n, o, a, t, ...i);
|
|
218
218
|
}
|
|
219
|
-
debug(e, t, ...
|
|
220
|
-
const [
|
|
221
|
-
console.debug(
|
|
219
|
+
debug(e, t, ...i) {
|
|
220
|
+
const [s, n, o, a] = this.formatMessage(e, "debug");
|
|
221
|
+
console.debug(s, n, o, a, t, ...i);
|
|
222
222
|
}
|
|
223
|
-
info(e, t, ...
|
|
224
|
-
const [
|
|
225
|
-
console.info(
|
|
223
|
+
info(e, t, ...i) {
|
|
224
|
+
const [s, n, o, a] = this.formatMessage(e, "info");
|
|
225
|
+
console.info(s, n, o, a, t, ...i);
|
|
226
226
|
}
|
|
227
|
-
warn(e, t, ...
|
|
228
|
-
const [
|
|
229
|
-
console.warn(
|
|
227
|
+
warn(e, t, ...i) {
|
|
228
|
+
const [s, n, o, a] = this.formatMessage(e, "warn");
|
|
229
|
+
console.warn(s, n, o, a, t, ...i);
|
|
230
230
|
}
|
|
231
|
-
error(e, t, ...
|
|
232
|
-
const [
|
|
233
|
-
console.error(
|
|
231
|
+
error(e, t, ...i) {
|
|
232
|
+
const [s, n, o, a] = this.formatMessage(e, "error");
|
|
233
|
+
console.error(s, n, o, a, t, ...i);
|
|
234
234
|
}
|
|
235
235
|
/**
|
|
236
236
|
* Start a timer with the specified label.
|
|
237
237
|
*/
|
|
238
238
|
time(e, t) {
|
|
239
|
-
const
|
|
240
|
-
this.timers.set(
|
|
239
|
+
const i = `${e}:${t}`;
|
|
240
|
+
this.timers.set(i, performance.now());
|
|
241
241
|
}
|
|
242
242
|
/**
|
|
243
243
|
* End a timer and log the elapsed time.
|
|
244
244
|
*/
|
|
245
245
|
timeEnd(e, t) {
|
|
246
|
-
const
|
|
247
|
-
if (
|
|
248
|
-
const n = performance.now() -
|
|
249
|
-
this.timers.delete(
|
|
246
|
+
const i = `${e}:${t}`, s = this.timers.get(i);
|
|
247
|
+
if (s !== void 0) {
|
|
248
|
+
const n = performance.now() - s;
|
|
249
|
+
this.timers.delete(i);
|
|
250
250
|
const [o, a, l, h] = this.formatMessage(e, "timer");
|
|
251
251
|
console.info(
|
|
252
252
|
`${o} Timer '${t}' completed in ${n.toFixed(2)}ms`,
|
|
@@ -259,15 +259,15 @@ class ke {
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
class De {
|
|
262
|
-
trace(e, t, ...
|
|
262
|
+
trace(e, t, ...i) {
|
|
263
263
|
}
|
|
264
|
-
debug(e, t, ...
|
|
264
|
+
debug(e, t, ...i) {
|
|
265
265
|
}
|
|
266
|
-
info(e, t, ...
|
|
266
|
+
info(e, t, ...i) {
|
|
267
267
|
}
|
|
268
|
-
warn(e, t, ...
|
|
268
|
+
warn(e, t, ...i) {
|
|
269
269
|
}
|
|
270
|
-
error(e, t, ...
|
|
270
|
+
error(e, t, ...i) {
|
|
271
271
|
}
|
|
272
272
|
time(e, t) {
|
|
273
273
|
}
|
|
@@ -278,8 +278,8 @@ class u {
|
|
|
278
278
|
category;
|
|
279
279
|
backend;
|
|
280
280
|
minLevel;
|
|
281
|
-
constructor(e, t = "none",
|
|
282
|
-
this.category = e, this.backend =
|
|
281
|
+
constructor(e, t = "none", i = new De()) {
|
|
282
|
+
this.category = e, this.backend = i, this.minLevel = t;
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
285
285
|
* Update the logger's backend and minimum level
|
|
@@ -431,13 +431,13 @@ class Be {
|
|
|
431
431
|
*/
|
|
432
432
|
subscribeExact(e, t) {
|
|
433
433
|
this._log.debug(`Adding exact subscription for: ${e}`);
|
|
434
|
-
let
|
|
435
|
-
|
|
436
|
-
const
|
|
434
|
+
let i = this.directMap.get(e);
|
|
435
|
+
i || (i = /* @__PURE__ */ new Set(), this.directMap.set(e, i));
|
|
436
|
+
const s = {
|
|
437
437
|
callback: (n) => t(n)
|
|
438
438
|
};
|
|
439
|
-
return
|
|
440
|
-
this._log.debug(`Removing exact subscription for: ${e}`),
|
|
439
|
+
return i.add(s), () => {
|
|
440
|
+
this._log.debug(`Removing exact subscription for: ${e}`), i.delete(s), i.size === 0 && this.directMap.delete(e);
|
|
441
441
|
};
|
|
442
442
|
}
|
|
443
443
|
/**
|
|
@@ -452,20 +452,20 @@ class Be {
|
|
|
452
452
|
* @returns A function that removes this subscription when called
|
|
453
453
|
*/
|
|
454
454
|
subscribePattern(e, t) {
|
|
455
|
-
let
|
|
455
|
+
let i;
|
|
456
456
|
if (typeof e == "string") {
|
|
457
457
|
const n = e.replace(/[-/\\^$+?.()|[\]{}]/g, "\\$&").replace(/\*/g, ".*");
|
|
458
|
-
|
|
459
|
-
`Adding pattern subscription for string: ${e}, regex: ${
|
|
458
|
+
i = new RegExp(`^${n}$`), this._log.debug(
|
|
459
|
+
`Adding pattern subscription for string: ${e}, regex: ${i.toString()}`
|
|
460
460
|
);
|
|
461
461
|
} else
|
|
462
|
-
|
|
463
|
-
const
|
|
464
|
-
pattern:
|
|
462
|
+
i = e, this._log.debug(`Adding pattern subscription for regex: ${i.toString()}`);
|
|
463
|
+
const s = {
|
|
464
|
+
pattern: i,
|
|
465
465
|
callback: (n) => t(n)
|
|
466
466
|
};
|
|
467
|
-
return this.patternSubs.add(
|
|
468
|
-
this._log.debug(`Removing pattern subscription: ${
|
|
467
|
+
return this.patternSubs.add(s), () => {
|
|
468
|
+
this._log.debug(`Removing pattern subscription: ${i.toString()}`), this.patternSubs.delete(s);
|
|
469
469
|
};
|
|
470
470
|
}
|
|
471
471
|
//------------------------------------------------------------------------------------------------------------------
|
|
@@ -490,16 +490,16 @@ class Be {
|
|
|
490
490
|
publish(e) {
|
|
491
491
|
this._log.trace(`Publishing event: ${e.type}`, e);
|
|
492
492
|
let t = 0;
|
|
493
|
-
const
|
|
494
|
-
if (
|
|
495
|
-
t +=
|
|
496
|
-
for (const
|
|
497
|
-
Promise.resolve().then(() =>
|
|
493
|
+
const i = this.directMap.get(e.type);
|
|
494
|
+
if (i) {
|
|
495
|
+
t += i.size;
|
|
496
|
+
for (const s of i)
|
|
497
|
+
Promise.resolve().then(() => s.callback(e)).catch((n) => {
|
|
498
498
|
this._log.error(`Error in event handler for '${e.type}':`, n);
|
|
499
499
|
});
|
|
500
500
|
}
|
|
501
|
-
for (const
|
|
502
|
-
|
|
501
|
+
for (const s of this.patternSubs)
|
|
502
|
+
s.pattern && s.pattern.test(e.type) && (t++, Promise.resolve().then(() => s.callback(e)).catch((n) => {
|
|
503
503
|
this._log.error(`Error in pattern event handler for '${e.type}':`, n);
|
|
504
504
|
}));
|
|
505
505
|
t === 0 ? this._log.debug(`No subscribers found for event: ${e.type}`) : this._log.trace(`Event ${e.type} dispatched to ${t} subscribers`);
|
|
@@ -548,11 +548,11 @@ class Le {
|
|
|
548
548
|
//------------------------------------------------------------------------------------------------------------------
|
|
549
549
|
// Sound Creation
|
|
550
550
|
//------------------------------------------------------------------------------------------------------------------
|
|
551
|
-
async createSound(e, t,
|
|
551
|
+
async createSound(e, t, i, s) {
|
|
552
552
|
if (!this._engine)
|
|
553
553
|
throw new Error("AudioEngine not initialized");
|
|
554
|
-
const n =
|
|
555
|
-
...
|
|
554
|
+
const n = i ?? this._mainBus ?? void 0, o = {
|
|
555
|
+
...s,
|
|
556
556
|
...n ? { outBus: n } : {}
|
|
557
557
|
};
|
|
558
558
|
return this._engine.createSoundAsync(e, t, o);
|
|
@@ -577,8 +577,8 @@ class Te {
|
|
|
577
577
|
_engine;
|
|
578
578
|
_havok;
|
|
579
579
|
_log;
|
|
580
|
-
constructor(e, t,
|
|
581
|
-
this._canvas = e, this._engine = t, this._havok =
|
|
580
|
+
constructor(e, t, i, s) {
|
|
581
|
+
this._canvas = e, this._engine = t, this._havok = i, this._log = s.getLogger("SceneEngine");
|
|
582
582
|
}
|
|
583
583
|
/**
|
|
584
584
|
* Creates a new scene with physics enabled
|
|
@@ -590,8 +590,8 @@ class Te {
|
|
|
590
590
|
this._log.debug(
|
|
591
591
|
`Enabling physics with gravity (${t.x}, ${t.y}, ${t.z})...`
|
|
592
592
|
);
|
|
593
|
-
const
|
|
594
|
-
e.enablePhysics(t,
|
|
593
|
+
const i = new Y(!0, this._havok);
|
|
594
|
+
e.enablePhysics(t, i);
|
|
595
595
|
}
|
|
596
596
|
// Camera Utilities
|
|
597
597
|
/**
|
|
@@ -602,9 +602,9 @@ class Te {
|
|
|
602
602
|
* @param scene
|
|
603
603
|
* @param canvas - Overrides the default canvas for input controls
|
|
604
604
|
*/
|
|
605
|
-
createFreeCamera(e, t,
|
|
606
|
-
const n = new B(e, t,
|
|
607
|
-
return n.setTarget(p.Zero()),
|
|
605
|
+
createFreeCamera(e, t, i, s) {
|
|
606
|
+
const n = new B(e, t, i);
|
|
607
|
+
return n.setTarget(p.Zero()), s = s ?? this._canvas, s && n.attachControl(s, !0), n;
|
|
608
608
|
}
|
|
609
609
|
// Lighting Utilities
|
|
610
610
|
/**
|
|
@@ -614,9 +614,9 @@ class Te {
|
|
|
614
614
|
* @param scene
|
|
615
615
|
* @param intensity - Default: 0.7
|
|
616
616
|
*/
|
|
617
|
-
createHemisphericLight(e, t,
|
|
618
|
-
const n = new J(e, t,
|
|
619
|
-
return n.intensity =
|
|
617
|
+
createHemisphericLight(e, t, i, s = 0.7) {
|
|
618
|
+
const n = new J(e, t, i);
|
|
619
|
+
return n.intensity = s, n;
|
|
620
620
|
}
|
|
621
621
|
/**
|
|
622
622
|
* Creates a directional light (sun-like lighting)
|
|
@@ -625,9 +625,9 @@ class Te {
|
|
|
625
625
|
* @param scene
|
|
626
626
|
* @param intensity - Default: 1.0
|
|
627
627
|
*/
|
|
628
|
-
createDirectionalLight(e, t,
|
|
629
|
-
const n = new X(e, t,
|
|
630
|
-
return n.intensity =
|
|
628
|
+
createDirectionalLight(e, t, i, s = 1) {
|
|
629
|
+
const n = new X(e, t, i);
|
|
630
|
+
return n.intensity = s, n;
|
|
631
631
|
}
|
|
632
632
|
/**
|
|
633
633
|
* Creates a point light (bulb-like lighting)
|
|
@@ -636,9 +636,9 @@ class Te {
|
|
|
636
636
|
* @param scene
|
|
637
637
|
* @param intensity - Default: 1.0
|
|
638
638
|
*/
|
|
639
|
-
createPointLight(e, t,
|
|
640
|
-
const n = new Q(e, t,
|
|
641
|
-
return n.intensity =
|
|
639
|
+
createPointLight(e, t, i, s = 1) {
|
|
640
|
+
const n = new Q(e, t, i);
|
|
641
|
+
return n.intensity = s, n;
|
|
642
642
|
}
|
|
643
643
|
/**
|
|
644
644
|
* Creates a spotlight (flashlight-like lighting)
|
|
@@ -650,8 +650,8 @@ class Te {
|
|
|
650
650
|
* @param scene
|
|
651
651
|
* @param intensity - Default: 1.0
|
|
652
652
|
*/
|
|
653
|
-
createSpotLight(e, t,
|
|
654
|
-
const l = new ee(e, t,
|
|
653
|
+
createSpotLight(e, t, i, s, n, o, a = 1) {
|
|
654
|
+
const l = new ee(e, t, i, s, n, o);
|
|
655
655
|
return l.intensity = a, l;
|
|
656
656
|
}
|
|
657
657
|
// Mesh Creation Utilities
|
|
@@ -661,9 +661,9 @@ class Te {
|
|
|
661
661
|
* @param options
|
|
662
662
|
* @param scene
|
|
663
663
|
*/
|
|
664
|
-
createSphere(e, t = {},
|
|
665
|
-
const
|
|
666
|
-
return y.CreateSphere(e, { ...
|
|
664
|
+
createSphere(e, t = {}, i) {
|
|
665
|
+
const s = { diameter: 1, segments: 32 };
|
|
666
|
+
return y.CreateSphere(e, { ...s, ...t }, i);
|
|
667
667
|
}
|
|
668
668
|
/**
|
|
669
669
|
* Creates a box mesh. Default size: 1.
|
|
@@ -671,9 +671,9 @@ class Te {
|
|
|
671
671
|
* @param options
|
|
672
672
|
* @param scene
|
|
673
673
|
*/
|
|
674
|
-
createBox(e, t = {},
|
|
675
|
-
const
|
|
676
|
-
return y.CreateBox(e, { ...
|
|
674
|
+
createBox(e, t = {}, i) {
|
|
675
|
+
const s = { size: 1 };
|
|
676
|
+
return y.CreateBox(e, { ...s, ...t }, i);
|
|
677
677
|
}
|
|
678
678
|
/**
|
|
679
679
|
* Creates a ground mesh. Defaults: 6x6 with 2 subdivisions.
|
|
@@ -681,9 +681,9 @@ class Te {
|
|
|
681
681
|
* @param options
|
|
682
682
|
* @param scene
|
|
683
683
|
*/
|
|
684
|
-
createGround(e, t = {},
|
|
685
|
-
const
|
|
686
|
-
return y.CreateGround(e, { ...
|
|
684
|
+
createGround(e, t = {}, i) {
|
|
685
|
+
const s = { width: 6, height: 6, subdivisions: 2 };
|
|
686
|
+
return y.CreateGround(e, { ...s, ...t }, i);
|
|
687
687
|
}
|
|
688
688
|
/**
|
|
689
689
|
* Creates a cylinder mesh. Defaults: height 2, diameter 1 (top and bottom).
|
|
@@ -691,9 +691,9 @@ class Te {
|
|
|
691
691
|
* @param options
|
|
692
692
|
* @param scene
|
|
693
693
|
*/
|
|
694
|
-
createCylinder(e, t = {},
|
|
695
|
-
const
|
|
696
|
-
return y.CreateCylinder(e, { ...
|
|
694
|
+
createCylinder(e, t = {}, i) {
|
|
695
|
+
const s = { height: 2, diameterTop: 1, diameterBottom: 1 };
|
|
696
|
+
return y.CreateCylinder(e, { ...s, ...t }, i);
|
|
697
697
|
}
|
|
698
698
|
// Physics Utilities
|
|
699
699
|
/**
|
|
@@ -703,9 +703,9 @@ class Te {
|
|
|
703
703
|
* @param physicsProps
|
|
704
704
|
* @param scene
|
|
705
705
|
*/
|
|
706
|
-
addPhysics(e, t,
|
|
706
|
+
addPhysics(e, t, i = {}, s) {
|
|
707
707
|
const n = { mass: 1, restitution: 0.75, friction: 0.5 };
|
|
708
|
-
return new te(e, t, { ...n, ...
|
|
708
|
+
return new te(e, t, { ...n, ...i }, s);
|
|
709
709
|
}
|
|
710
710
|
// Model Loading Utilities
|
|
711
711
|
/**
|
|
@@ -716,10 +716,10 @@ class Te {
|
|
|
716
716
|
async loadModel(e, t) {
|
|
717
717
|
this._log.debug(`Loading model: ${e}`);
|
|
718
718
|
try {
|
|
719
|
-
const
|
|
720
|
-
return this._log.debug(`Model loaded successfully: ${e}`),
|
|
721
|
-
} catch (
|
|
722
|
-
throw this._log.error(`Failed to load model: ${e}`,
|
|
719
|
+
const i = await ce(`${e}`, t);
|
|
720
|
+
return this._log.debug(`Model loaded successfully: ${e}`), i;
|
|
721
|
+
} catch (i) {
|
|
722
|
+
throw this._log.error(`Failed to load model: ${e}`, i), i;
|
|
723
723
|
}
|
|
724
724
|
}
|
|
725
725
|
/**
|
|
@@ -728,13 +728,13 @@ class Te {
|
|
|
728
728
|
* @param sceneFilename
|
|
729
729
|
* @param scene
|
|
730
730
|
*/
|
|
731
|
-
async importMeshes(e, t,
|
|
731
|
+
async importMeshes(e, t, i) {
|
|
732
732
|
this._log.debug(`Importing meshes from: ${t}`);
|
|
733
733
|
try {
|
|
734
|
-
const
|
|
734
|
+
const s = e.length > 0 ? { meshNames: e } : void 0, n = await de(`${t}`, i, s);
|
|
735
735
|
return this._log.debug(`Meshes imported successfully: ${e.length > 0 ? e.join(", ") : "all"}`), n;
|
|
736
|
-
} catch (
|
|
737
|
-
throw this._log.error(`Failed to import meshes from: ${t}`,
|
|
736
|
+
} catch (s) {
|
|
737
|
+
throw this._log.error(`Failed to import meshes from: ${t}`, s), s;
|
|
738
738
|
}
|
|
739
739
|
}
|
|
740
740
|
/**
|
|
@@ -753,8 +753,8 @@ class Ie {
|
|
|
753
753
|
/** Extracted fragment meshes (source meshes for instancing), keyed by full fragment path */
|
|
754
754
|
_sourceMeshes = /* @__PURE__ */ new Map();
|
|
755
755
|
//------------------------------------------------------------------------------------------------------------------
|
|
756
|
-
constructor(e, t,
|
|
757
|
-
this._eventBus = e, this._sceneEngine = t, this._log =
|
|
756
|
+
constructor(e, t, i) {
|
|
757
|
+
this._eventBus = e, this._sceneEngine = t, this._log = i?.getLogger("AssetManager") ?? new u("AssetManager");
|
|
758
758
|
}
|
|
759
759
|
//------------------------------------------------------------------------------------------------------------------
|
|
760
760
|
// Private Helpers
|
|
@@ -778,26 +778,26 @@ class Ie {
|
|
|
778
778
|
if (t)
|
|
779
779
|
return t.refCount++, t.container;
|
|
780
780
|
this._log.debug(`Loading asset container: ${e}`);
|
|
781
|
-
const
|
|
781
|
+
const i = this._sceneEngine.createScene();
|
|
782
782
|
try {
|
|
783
|
-
const
|
|
784
|
-
return this._containers.set(e, { container:
|
|
783
|
+
const s = await this._sceneEngine.loadModel(e, i);
|
|
784
|
+
return this._containers.set(e, { container: s, refCount: 1 }), this._log.debug(`Cached asset container: ${e}`), s;
|
|
785
785
|
} finally {
|
|
786
|
-
|
|
786
|
+
i.dispose();
|
|
787
787
|
}
|
|
788
788
|
}
|
|
789
789
|
/**
|
|
790
790
|
* Find a mesh by name inside a container. Throws if not found.
|
|
791
791
|
*/
|
|
792
|
-
_findMeshInContainer(e, t,
|
|
793
|
-
const
|
|
794
|
-
if (!
|
|
792
|
+
_findMeshInContainer(e, t, i) {
|
|
793
|
+
const s = e.meshes.find((n) => n.name === t);
|
|
794
|
+
if (!s) {
|
|
795
795
|
const n = e.meshes.map((o) => o.name).join(", ");
|
|
796
796
|
throw new Error(
|
|
797
|
-
`Mesh '${t}' not found in container for '${
|
|
797
|
+
`Mesh '${t}' not found in container for '${i}'. Available meshes: ${n}`
|
|
798
798
|
);
|
|
799
799
|
}
|
|
800
|
-
return
|
|
800
|
+
return s;
|
|
801
801
|
}
|
|
802
802
|
//------------------------------------------------------------------------------------------------------------------
|
|
803
803
|
// Public API
|
|
@@ -811,14 +811,14 @@ class Ie {
|
|
|
811
811
|
* Increments refCount on the underlying container each time.
|
|
812
812
|
*/
|
|
813
813
|
async load(e) {
|
|
814
|
-
const { basePath: t, fragment:
|
|
815
|
-
if (
|
|
816
|
-
const
|
|
817
|
-
if (
|
|
814
|
+
const { basePath: t, fragment: i } = this._parsePath(e);
|
|
815
|
+
if (i) {
|
|
816
|
+
const s = this._sourceMeshes.get(e);
|
|
817
|
+
if (s) {
|
|
818
818
|
const a = this._containers.get(t);
|
|
819
|
-
return a && a.refCount++,
|
|
819
|
+
return a && a.refCount++, s;
|
|
820
820
|
}
|
|
821
|
-
const n = await this._loadContainer(t), o = this._findMeshInContainer(n,
|
|
821
|
+
const n = await this._loadContainer(t), o = this._findMeshInContainer(n, i, e);
|
|
822
822
|
return this._sourceMeshes.set(e, o), o;
|
|
823
823
|
}
|
|
824
824
|
return this._loadContainer(t);
|
|
@@ -846,12 +846,12 @@ class Ie {
|
|
|
846
846
|
*/
|
|
847
847
|
async preload(e) {
|
|
848
848
|
const t = e.length;
|
|
849
|
-
for (let
|
|
850
|
-
await this.load(e[
|
|
849
|
+
for (let i = 0; i < e.length; i++)
|
|
850
|
+
await this.load(e[i]), this._eventBus.publish({
|
|
851
851
|
type: "asset:progress",
|
|
852
852
|
payload: {
|
|
853
|
-
path: e[
|
|
854
|
-
loaded:
|
|
853
|
+
path: e[i],
|
|
854
|
+
loaded: i + 1,
|
|
855
855
|
total: t
|
|
856
856
|
}
|
|
857
857
|
});
|
|
@@ -865,12 +865,12 @@ class Ie {
|
|
|
865
865
|
* When refCount hits 0, dispose the container and clean up all fragment meshes from it.
|
|
866
866
|
*/
|
|
867
867
|
dispose(e) {
|
|
868
|
-
const { basePath: t } = this._parsePath(e),
|
|
869
|
-
if (
|
|
868
|
+
const { basePath: t } = this._parsePath(e), i = this._containers.get(t);
|
|
869
|
+
if (i && (i.refCount--, i.refCount <= 0)) {
|
|
870
870
|
this._log.debug(`Disposing asset container: ${t} (refCount reached 0)`);
|
|
871
|
-
for (const [
|
|
872
|
-
|
|
873
|
-
|
|
871
|
+
for (const [s, n] of this._sourceMeshes)
|
|
872
|
+
s.startsWith(`${t}#`) && (n.dispose(), this._sourceMeshes.delete(s));
|
|
873
|
+
i.container.dispose(), this._containers.delete(t);
|
|
874
874
|
}
|
|
875
875
|
}
|
|
876
876
|
/**
|
|
@@ -938,8 +938,8 @@ class Ne {
|
|
|
938
938
|
* @param reader
|
|
939
939
|
* @param options
|
|
940
940
|
*/
|
|
941
|
-
constructor(e, t,
|
|
942
|
-
this.action = e, this.deviceID = t, this.deviceType =
|
|
941
|
+
constructor(e, t, i, s, n = {}) {
|
|
942
|
+
this.action = e, this.deviceID = t, this.deviceType = i, this.reader = s, this.context = n.context, this._edgeMode = n.edgeMode ?? "rising", this._threshold = n.threshold ?? 0.5;
|
|
943
943
|
}
|
|
944
944
|
//------------------------------------------------------------------------------------------------------------------
|
|
945
945
|
// Public Methods
|
|
@@ -951,23 +951,23 @@ class Ne {
|
|
|
951
951
|
* @param eventBus
|
|
952
952
|
*/
|
|
953
953
|
process(e, t) {
|
|
954
|
-
const
|
|
954
|
+
const i = this.reader.getValue(e) ?? !1, s = typeof i == "boolean" ? i : i >= this._threshold;
|
|
955
955
|
let n = !1;
|
|
956
956
|
switch (this._edgeMode) {
|
|
957
957
|
case "rising":
|
|
958
|
-
n =
|
|
958
|
+
n = s && !this._lastDigitalState;
|
|
959
959
|
break;
|
|
960
960
|
case "falling":
|
|
961
|
-
n = !
|
|
961
|
+
n = !s && this._lastDigitalState;
|
|
962
962
|
break;
|
|
963
963
|
case "both":
|
|
964
|
-
n =
|
|
964
|
+
n = s !== this._lastDigitalState;
|
|
965
965
|
break;
|
|
966
966
|
}
|
|
967
|
-
if (this._lastDigitalState =
|
|
967
|
+
if (this._lastDigitalState = s, n) {
|
|
968
968
|
let o;
|
|
969
969
|
if (this.action.type === "analog") {
|
|
970
|
-
let l = typeof
|
|
970
|
+
let l = typeof i == "number" ? i : i ? 1 : 0;
|
|
971
971
|
if (this.action.minValue !== void 0 || this.action.maxValue !== void 0) {
|
|
972
972
|
const h = this.action.minValue ?? 0, c = this.action.maxValue ?? 1;
|
|
973
973
|
l = h + l * (c - h);
|
|
@@ -1080,8 +1080,8 @@ class Ve {
|
|
|
1080
1080
|
* @param reader
|
|
1081
1081
|
* @param options
|
|
1082
1082
|
*/
|
|
1083
|
-
constructor(e, t,
|
|
1084
|
-
this.action = e, this.deviceID = t, this.deviceType =
|
|
1083
|
+
constructor(e, t, i, s, n = {}) {
|
|
1084
|
+
this.action = e, this.deviceID = t, this.deviceType = i, this.reader = s, this.context = n.context, this._invert = n.invert ?? !1, this._threshold = n.threshold ?? 0.5, this._initialState = n.initialState ?? !1, this._toggleState = this._initialState, this._onValue = n.onValue ?? !0, this._offValue = n.offValue ?? !1;
|
|
1085
1085
|
}
|
|
1086
1086
|
//------------------------------------------------------------------------------------------------------------------
|
|
1087
1087
|
// Public Methods
|
|
@@ -1093,8 +1093,8 @@ class Ve {
|
|
|
1093
1093
|
* @param eventBus
|
|
1094
1094
|
*/
|
|
1095
1095
|
process(e, t) {
|
|
1096
|
-
const
|
|
1097
|
-
this._lastDigitalState =
|
|
1096
|
+
const i = this.reader.getValue(e) ?? !1, s = typeof i == "boolean" ? i : i >= this._threshold, n = this._invert ? !s && this._lastDigitalState : s && !this._lastDigitalState;
|
|
1097
|
+
this._lastDigitalState = s, n && (this._toggleState = !this._toggleState, t.publish({
|
|
1098
1098
|
type: `action:${this.action.name}`,
|
|
1099
1099
|
payload: {
|
|
1100
1100
|
value: this.value,
|
|
@@ -1177,8 +1177,8 @@ class Ge {
|
|
|
1177
1177
|
* @param reader
|
|
1178
1178
|
* @param options
|
|
1179
1179
|
*/
|
|
1180
|
-
constructor(e, t,
|
|
1181
|
-
this.action = e, this.deviceID = t, this.deviceType =
|
|
1180
|
+
constructor(e, t, i, s, n = {}) {
|
|
1181
|
+
this.action = e, this.deviceID = t, this.deviceType = i, this.reader = s, this.context = n.context, this._scale = n.scale ?? 1, this._offset = n.offset ?? 0, this._invert = n.invert ?? !1, this._emitOnChange = n.emitOnChange ?? !0, this._deadzone = n.deadzone ?? 0, this._onValue = n.onValue ?? !0, this._offValue = n.offValue ?? !1;
|
|
1182
1182
|
const o = this.action.type === "analog" ? this.action.minValue ?? Number.NEGATIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
1183
1183
|
this._min = n.min ?? o;
|
|
1184
1184
|
const a = this.action.type === "analog" ? this.action.maxValue ?? Number.POSITIVE_INFINITY : Number.POSITIVE_INFINITY;
|
|
@@ -1194,11 +1194,11 @@ class Ge {
|
|
|
1194
1194
|
* @param eventBus
|
|
1195
1195
|
*/
|
|
1196
1196
|
process(e, t) {
|
|
1197
|
-
const
|
|
1198
|
-
if (
|
|
1197
|
+
const i = this.reader.getValue(e);
|
|
1198
|
+
if (i === void 0)
|
|
1199
1199
|
return;
|
|
1200
|
-
const
|
|
1201
|
-
let n = this._deadzone > 0 && Math.abs(
|
|
1200
|
+
const s = typeof i == "boolean" ? i ? 1 : 0 : i;
|
|
1201
|
+
let n = this._deadzone > 0 && Math.abs(s) < this._deadzone ? 0 : s;
|
|
1202
1202
|
n = (this._invert ? -n : n) * this._scale + this._offset, n = Math.max(this._min, Math.min(this._max, n)), !(this._emitOnChange && this._lastValue === n) && (this._lastValue = n, t.publish({
|
|
1203
1203
|
type: `action:${this.action.name}`,
|
|
1204
1204
|
payload: {
|
|
@@ -1316,8 +1316,8 @@ class z {
|
|
|
1316
1316
|
return t ? t.pressed : void 0;
|
|
1317
1317
|
}
|
|
1318
1318
|
case "position": {
|
|
1319
|
-
const [t,
|
|
1320
|
-
return !t || !
|
|
1319
|
+
const [t, i] = this.sourceKey.split(":");
|
|
1320
|
+
return !t || !i || t !== "absolute" && t !== "relative" || i !== "x" && i !== "y" ? void 0 : e.position[t][i];
|
|
1321
1321
|
}
|
|
1322
1322
|
case "wheel": {
|
|
1323
1323
|
const t = this.sourceKey === "deltaX" || this.sourceKey === "deltaY" || this.sourceKey === "deltaZ";
|
|
@@ -1333,12 +1333,12 @@ class z {
|
|
|
1333
1333
|
* @param sourceTypeString
|
|
1334
1334
|
*/
|
|
1335
1335
|
static fromString(e) {
|
|
1336
|
-
const [t, ...
|
|
1337
|
-
if (!t || !
|
|
1336
|
+
const [t, ...i] = e.split(":"), s = i.join(":");
|
|
1337
|
+
if (!t || !s)
|
|
1338
1338
|
throw new Error(`Invalid mouse source format: ${e}`);
|
|
1339
1339
|
return new z(
|
|
1340
1340
|
t,
|
|
1341
|
-
|
|
1341
|
+
s
|
|
1342
1342
|
);
|
|
1343
1343
|
}
|
|
1344
1344
|
/**
|
|
@@ -1380,8 +1380,8 @@ class N {
|
|
|
1380
1380
|
* @param sourceKey - e.g. "button-0", "axis-1"
|
|
1381
1381
|
* @param options
|
|
1382
1382
|
*/
|
|
1383
|
-
constructor(e, t,
|
|
1384
|
-
this.sourceType = e, this.sourceKey = t, this.useAnalogValue =
|
|
1383
|
+
constructor(e, t, i = {}) {
|
|
1384
|
+
this.sourceType = e, this.sourceKey = t, this.useAnalogValue = i.useAnalogValue || !1, this.deadzone = i.deadzone || 0.1, this.invert = i.invert || !1;
|
|
1385
1385
|
}
|
|
1386
1386
|
/**
|
|
1387
1387
|
* Gets the value of the input source. Returns undefined for non-gamepad input states.
|
|
@@ -1410,12 +1410,12 @@ class N {
|
|
|
1410
1410
|
* @param options
|
|
1411
1411
|
*/
|
|
1412
1412
|
static fromString(e, t = {}) {
|
|
1413
|
-
const [
|
|
1414
|
-
if (!
|
|
1413
|
+
const [i, s] = e.split(":");
|
|
1414
|
+
if (!i || !s)
|
|
1415
1415
|
throw new Error(`Invalid gamepad source format: ${e}`);
|
|
1416
1416
|
return new N(
|
|
1417
|
-
s,
|
|
1418
1417
|
i,
|
|
1418
|
+
s,
|
|
1419
1419
|
t
|
|
1420
1420
|
);
|
|
1421
1421
|
}
|
|
@@ -1467,9 +1467,9 @@ class He {
|
|
|
1467
1467
|
constructor(e, t) {
|
|
1468
1468
|
this._eventBus = e, this._inputUnsubscribe = this._eventBus.subscribe(
|
|
1469
1469
|
"input:changed",
|
|
1470
|
-
(
|
|
1471
|
-
const
|
|
1472
|
-
|
|
1470
|
+
(i) => {
|
|
1471
|
+
const s = i.payload;
|
|
1472
|
+
s && this.$handleInput(s.device, s.state);
|
|
1473
1473
|
}
|
|
1474
1474
|
), this._log = t?.getLogger("BindingManager") || new u("BindingManager"), this._log.debug("BindingManager initialized");
|
|
1475
1475
|
}
|
|
@@ -1492,11 +1492,11 @@ class He {
|
|
|
1492
1492
|
* @param exclusive - Only used when creating a new context
|
|
1493
1493
|
*/
|
|
1494
1494
|
_getOrCreateContext(e, t = !0) {
|
|
1495
|
-
let
|
|
1496
|
-
return
|
|
1495
|
+
let i = this._contexts.get(e);
|
|
1496
|
+
return i || (i = {
|
|
1497
1497
|
name: e,
|
|
1498
1498
|
exclusive: t
|
|
1499
|
-
}, this._contexts.set(e,
|
|
1499
|
+
}, this._contexts.set(e, i), this._log.debug(`Auto-created context "${e}" (exclusive: ${t})`)), i;
|
|
1500
1500
|
}
|
|
1501
1501
|
/**
|
|
1502
1502
|
* Deactivate all exclusive contexts except the specified one.
|
|
@@ -1506,10 +1506,10 @@ class He {
|
|
|
1506
1506
|
*/
|
|
1507
1507
|
_deactivateExclusiveContexts(e) {
|
|
1508
1508
|
const t = [];
|
|
1509
|
-
for (const
|
|
1510
|
-
if (
|
|
1509
|
+
for (const i of this._activeContexts) {
|
|
1510
|
+
if (i === e)
|
|
1511
1511
|
continue;
|
|
1512
|
-
this._contexts.get(
|
|
1512
|
+
this._contexts.get(i)?.exclusive && (this._activeContexts.delete(i), t.push(i));
|
|
1513
1513
|
}
|
|
1514
1514
|
return t;
|
|
1515
1515
|
}
|
|
@@ -1532,14 +1532,14 @@ class He {
|
|
|
1532
1532
|
const t = this._actions.get(e.action);
|
|
1533
1533
|
if (!t)
|
|
1534
1534
|
return this._log.warn(`Cannot create binding: Action "${e.action}" not found.`), null;
|
|
1535
|
-
const { deviceID:
|
|
1535
|
+
const { deviceID: i, ...s } = e.input;
|
|
1536
1536
|
switch (e.type) {
|
|
1537
1537
|
case "trigger":
|
|
1538
1538
|
return new Ne(
|
|
1539
1539
|
t,
|
|
1540
|
-
|
|
1540
|
+
i,
|
|
1541
1541
|
e.input.type,
|
|
1542
|
-
this._createInputSourceFromDefinition(
|
|
1542
|
+
this._createInputSourceFromDefinition(s),
|
|
1543
1543
|
{
|
|
1544
1544
|
...e.options || {},
|
|
1545
1545
|
context: e.context
|
|
@@ -1548,9 +1548,9 @@ class He {
|
|
|
1548
1548
|
case "toggle":
|
|
1549
1549
|
return new Ve(
|
|
1550
1550
|
t,
|
|
1551
|
-
|
|
1551
|
+
i,
|
|
1552
1552
|
e.input.type,
|
|
1553
|
-
this._createInputSourceFromDefinition(
|
|
1553
|
+
this._createInputSourceFromDefinition(s),
|
|
1554
1554
|
{
|
|
1555
1555
|
...e.options || {},
|
|
1556
1556
|
context: e.context
|
|
@@ -1559,9 +1559,9 @@ class He {
|
|
|
1559
1559
|
case "value":
|
|
1560
1560
|
return new Ge(
|
|
1561
1561
|
t,
|
|
1562
|
-
|
|
1562
|
+
i,
|
|
1563
1563
|
e.input.type,
|
|
1564
|
-
this._createInputSourceFromDefinition(
|
|
1564
|
+
this._createInputSourceFromDefinition(s),
|
|
1565
1565
|
{
|
|
1566
1566
|
...e.options || {},
|
|
1567
1567
|
context: e.context
|
|
@@ -1615,11 +1615,11 @@ class He {
|
|
|
1615
1615
|
* @param state
|
|
1616
1616
|
*/
|
|
1617
1617
|
_processCaptureInput(e, t) {
|
|
1618
|
-
const
|
|
1619
|
-
if (!
|
|
1618
|
+
const i = this._captureState;
|
|
1619
|
+
if (!i)
|
|
1620
1620
|
return;
|
|
1621
|
-
const { options:
|
|
1622
|
-
if (!
|
|
1621
|
+
const { options: s } = i;
|
|
1622
|
+
if (!s.deviceTypes.includes(e.type))
|
|
1623
1623
|
return;
|
|
1624
1624
|
let n = null;
|
|
1625
1625
|
if (ze(t)) {
|
|
@@ -1650,9 +1650,9 @@ class He {
|
|
|
1650
1650
|
}
|
|
1651
1651
|
}
|
|
1652
1652
|
}
|
|
1653
|
-
if (!n ||
|
|
1653
|
+
if (!n || s.sourceTypes && !s.sourceTypes.includes(n.sourceType))
|
|
1654
1654
|
return;
|
|
1655
|
-
const { resolve: o } =
|
|
1655
|
+
const { resolve: o } = i;
|
|
1656
1656
|
this._cleanupCapture(), o(n);
|
|
1657
1657
|
}
|
|
1658
1658
|
/**
|
|
@@ -1666,8 +1666,8 @@ class He {
|
|
|
1666
1666
|
e.abortCleanup && e.abortCleanup();
|
|
1667
1667
|
const { snapshot: t } = e;
|
|
1668
1668
|
this._captureState = null, this.deactivateContext("__sage_capture__"), this._contexts.delete("__sage_capture__");
|
|
1669
|
-
for (const
|
|
1670
|
-
this.activateContext(
|
|
1669
|
+
for (const i of t)
|
|
1670
|
+
this.activateContext(i);
|
|
1671
1671
|
}
|
|
1672
1672
|
//------------------------------------------------------------------------------------------------------------------
|
|
1673
1673
|
// Internal API
|
|
@@ -1686,20 +1686,20 @@ class He {
|
|
|
1686
1686
|
*/
|
|
1687
1687
|
$handleInput(e, t) {
|
|
1688
1688
|
if (this._shouldUpdateActiveDevice(t) && e.type !== this._lastActiveDeviceType) {
|
|
1689
|
-
const
|
|
1689
|
+
const s = this._lastActiveDeviceType;
|
|
1690
1690
|
this._lastActiveDeviceType = e.type, this._eventBus.publish({
|
|
1691
1691
|
type: "input:device-type:changed",
|
|
1692
|
-
payload: { deviceType: e.type, previousDeviceType:
|
|
1692
|
+
payload: { deviceType: e.type, previousDeviceType: s }
|
|
1693
1693
|
});
|
|
1694
1694
|
}
|
|
1695
1695
|
if (this._captureState) {
|
|
1696
1696
|
this._processCaptureInput(e, t);
|
|
1697
1697
|
return;
|
|
1698
1698
|
}
|
|
1699
|
-
const
|
|
1700
|
-
if (!(!
|
|
1701
|
-
for (const
|
|
1702
|
-
this._isBindingContextActive(
|
|
1699
|
+
const i = this._bindings.get(e.id);
|
|
1700
|
+
if (!(!i || i.length === 0) && !(this._activeContexts.size === 0 && i.some((s) => s.context)))
|
|
1701
|
+
for (const s of i)
|
|
1702
|
+
this._isBindingContextActive(s) && s.process(t, this._eventBus);
|
|
1703
1703
|
}
|
|
1704
1704
|
//------------------------------------------------------------------------------------------------------------------
|
|
1705
1705
|
// Action Management API
|
|
@@ -1752,16 +1752,16 @@ class He {
|
|
|
1752
1752
|
if (this._captureState)
|
|
1753
1753
|
throw new Error("captureInput() already in progress");
|
|
1754
1754
|
const t = [...this._activeContexts];
|
|
1755
|
-
return this.registerContext("__sage_capture__", !0), this.activateContext("__sage_capture__"), new Promise((
|
|
1756
|
-
const n = { resolve:
|
|
1755
|
+
return this.registerContext("__sage_capture__", !0), this.activateContext("__sage_capture__"), new Promise((i, s) => {
|
|
1756
|
+
const n = { resolve: i, reject: s, options: e, snapshot: t };
|
|
1757
1757
|
if (this._captureState = n, e.signal) {
|
|
1758
1758
|
if (e.signal.aborted) {
|
|
1759
|
-
this._cleanupCapture(),
|
|
1759
|
+
this._cleanupCapture(), s(e.signal.reason ?? new Error("captureInput() aborted"));
|
|
1760
1760
|
return;
|
|
1761
1761
|
}
|
|
1762
1762
|
const o = () => {
|
|
1763
1763
|
const a = e.signal?.reason ?? new Error("captureInput() aborted");
|
|
1764
|
-
this._cleanupCapture(),
|
|
1764
|
+
this._cleanupCapture(), s(a);
|
|
1765
1765
|
};
|
|
1766
1766
|
e.signal.addEventListener("abort", o, { once: !0 }), n.abortCleanup = () => {
|
|
1767
1767
|
e.signal?.removeEventListener("abort", o);
|
|
@@ -1780,8 +1780,8 @@ class He {
|
|
|
1780
1780
|
* @param exclusive
|
|
1781
1781
|
*/
|
|
1782
1782
|
registerContext(e, t = !0) {
|
|
1783
|
-
const
|
|
1784
|
-
return
|
|
1783
|
+
const i = this._getOrCreateContext(e, t);
|
|
1784
|
+
return i.exclusive !== t && (i.exclusive = t, this._log.info(`Updated context "${e}" exclusivity: ${t}`)), i;
|
|
1785
1785
|
}
|
|
1786
1786
|
/**
|
|
1787
1787
|
* Activates a context, enabling all bindings associated with it.
|
|
@@ -1790,19 +1790,19 @@ class He {
|
|
|
1790
1790
|
* @param contextName
|
|
1791
1791
|
*/
|
|
1792
1792
|
activateContext(e) {
|
|
1793
|
-
const
|
|
1794
|
-
this._log.debug(`Activating context "${e}" (exclusive: ${
|
|
1795
|
-
const
|
|
1796
|
-
if (
|
|
1793
|
+
const i = this._getOrCreateContext(e).exclusive;
|
|
1794
|
+
this._log.debug(`Activating context "${e}" (exclusive: ${i})`);
|
|
1795
|
+
const s = this._activeContexts.has(e);
|
|
1796
|
+
if (i) {
|
|
1797
1797
|
const n = this._deactivateExclusiveContexts(e);
|
|
1798
1798
|
n.length > 0 && this._log.info(`Deactivated exclusive contexts: ${n.join(", ")}`);
|
|
1799
1799
|
}
|
|
1800
|
-
if (!
|
|
1800
|
+
if (!s) {
|
|
1801
1801
|
this._activeContexts.add(e);
|
|
1802
1802
|
for (const n of this._bindings.values())
|
|
1803
1803
|
for (const o of n)
|
|
1804
1804
|
o.context === e && o.resetEdgeState();
|
|
1805
|
-
this._log.info(`Context "${e}" activated${
|
|
1805
|
+
this._log.info(`Context "${e}" activated${i ? " as exclusive" : ""}`);
|
|
1806
1806
|
}
|
|
1807
1807
|
}
|
|
1808
1808
|
/**
|
|
@@ -1868,15 +1868,15 @@ class He {
|
|
|
1868
1868
|
*/
|
|
1869
1869
|
unregisterBindings(e, t = null) {
|
|
1870
1870
|
this._log.debug(`Unregistering all bindings for action "${e}" in context "${t}"`);
|
|
1871
|
-
let
|
|
1872
|
-
for (const [
|
|
1871
|
+
let i = 0;
|
|
1872
|
+
for (const [s, n] of this._bindings.entries()) {
|
|
1873
1873
|
const o = n.filter((a) => {
|
|
1874
1874
|
const l = a.context || null, h = a.action.name !== e || l !== t;
|
|
1875
|
-
return h ||
|
|
1875
|
+
return h || i++, h;
|
|
1876
1876
|
});
|
|
1877
|
-
o.length !== n.length && this._bindings.set(
|
|
1877
|
+
o.length !== n.length && this._bindings.set(s, o);
|
|
1878
1878
|
}
|
|
1879
|
-
this._log.info(`Removed ${
|
|
1879
|
+
this._log.info(`Removed ${i} bindings for action "${e}" in context "${t}"`);
|
|
1880
1880
|
}
|
|
1881
1881
|
/**
|
|
1882
1882
|
* Gets all bindings for a specific action, optionally filtered by device type and/or context.
|
|
@@ -1885,16 +1885,16 @@ class He {
|
|
|
1885
1885
|
* @param deviceType - If provided, filters to only bindings for that device type
|
|
1886
1886
|
* @param context - If provided, filters to only bindings in that context
|
|
1887
1887
|
*/
|
|
1888
|
-
getBindingsForAction(e, t,
|
|
1889
|
-
const
|
|
1888
|
+
getBindingsForAction(e, t, i) {
|
|
1889
|
+
const s = [];
|
|
1890
1890
|
for (const n of this._bindings.values())
|
|
1891
1891
|
for (const o of n) {
|
|
1892
1892
|
if (o.action.name !== e || t !== void 0 && o.deviceType !== t)
|
|
1893
1893
|
continue;
|
|
1894
1894
|
const a = o.context || null;
|
|
1895
|
-
|
|
1895
|
+
i !== void 0 && a !== i || s.push(o);
|
|
1896
1896
|
}
|
|
1897
|
-
return
|
|
1897
|
+
return s;
|
|
1898
1898
|
}
|
|
1899
1899
|
//------------------------------------------------------------------------------------------------------------------
|
|
1900
1900
|
// Configuration Management API
|
|
@@ -1905,25 +1905,25 @@ class He {
|
|
|
1905
1905
|
*/
|
|
1906
1906
|
exportConfiguration() {
|
|
1907
1907
|
this._log.debug("Exporting binding configuration");
|
|
1908
|
-
const e = [...this._actions.values()].map((
|
|
1909
|
-
name:
|
|
1910
|
-
type:
|
|
1911
|
-
label:
|
|
1912
|
-
minValue:
|
|
1913
|
-
maxValue:
|
|
1914
|
-
} :
|
|
1915
|
-
for (const
|
|
1916
|
-
for (const n of
|
|
1908
|
+
const e = [...this._actions.values()].map((s) => s.type === "analog" ? {
|
|
1909
|
+
name: s.name,
|
|
1910
|
+
type: s.type,
|
|
1911
|
+
label: s.label,
|
|
1912
|
+
minValue: s.minValue ?? 0,
|
|
1913
|
+
maxValue: s.maxValue ?? 1
|
|
1914
|
+
} : s), t = [];
|
|
1915
|
+
for (const s of this._bindings.values())
|
|
1916
|
+
for (const n of s)
|
|
1917
1917
|
t.push(n.toJSON());
|
|
1918
|
-
const
|
|
1919
|
-
name:
|
|
1920
|
-
exclusive:
|
|
1921
|
-
active: this._activeContexts.has(
|
|
1918
|
+
const i = [...this._contexts.values()].map((s) => ({
|
|
1919
|
+
name: s.name,
|
|
1920
|
+
exclusive: s.exclusive,
|
|
1921
|
+
active: this._activeContexts.has(s.name)
|
|
1922
1922
|
}));
|
|
1923
|
-
return this._log.info(`Configuration exported: ${e.length} actions, ${t.length} bindings, ${
|
|
1923
|
+
return this._log.info(`Configuration exported: ${e.length} actions, ${t.length} bindings, ${i.length} contexts`), {
|
|
1924
1924
|
actions: e,
|
|
1925
1925
|
bindings: t,
|
|
1926
|
-
contexts:
|
|
1926
|
+
contexts: i
|
|
1927
1927
|
};
|
|
1928
1928
|
}
|
|
1929
1929
|
/**
|
|
@@ -1940,8 +1940,8 @@ class He {
|
|
|
1940
1940
|
for (const t of e.bindings)
|
|
1941
1941
|
try {
|
|
1942
1942
|
this.registerBinding(t);
|
|
1943
|
-
} catch (
|
|
1944
|
-
|
|
1943
|
+
} catch (i) {
|
|
1944
|
+
i instanceof Error && this._log.error(`Failed to import binding for action "${t.action}": ${i.message}`);
|
|
1945
1945
|
}
|
|
1946
1946
|
this._log.info(`Configuration imported: ${e.actions.length} actions, ${e.bindings.length} bindings, ${e.contexts.length} contexts`);
|
|
1947
1947
|
}
|
|
@@ -1979,8 +1979,8 @@ class Ue {
|
|
|
1979
1979
|
_paused = !1;
|
|
1980
1980
|
started = !1;
|
|
1981
1981
|
//------------------------------------------------------------------------------------------------------------------
|
|
1982
|
-
constructor(e, t,
|
|
1983
|
-
this._engine = e, this._eventBus = t, this._entityManager =
|
|
1982
|
+
constructor(e, t, i, s, n, o) {
|
|
1983
|
+
this._engine = e, this._eventBus = t, this._entityManager = i, this._inputManager = s, this._levelManager = n, this._log = o?.getLogger("GameManager") || new u("GameManager"), this._boundRenderLoop = this._renderLoop.bind(this), this._boundResizeHandler = this._resizeHandler.bind(this), T() && window.addEventListener("resize", this._boundResizeHandler);
|
|
1984
1984
|
}
|
|
1985
1985
|
get currentScene() {
|
|
1986
1986
|
return this._levelManager.currentLevel?.scene ?? null;
|
|
@@ -2020,8 +2020,8 @@ class Ue {
|
|
|
2020
2020
|
registerFrameCallback(e) {
|
|
2021
2021
|
const t = this._nextCallbackId++;
|
|
2022
2022
|
return this._frameCallbacks.push({ id: t, callback: e }), this._log.debug(`Registered frame callback (id: ${t})`), () => {
|
|
2023
|
-
const
|
|
2024
|
-
|
|
2023
|
+
const i = this._frameCallbacks.findIndex((s) => s.id === t);
|
|
2024
|
+
i !== -1 && (this._frameCallbacks.splice(i, 1), this._log.debug(`Unregistered frame callback (id: ${t})`));
|
|
2025
2025
|
};
|
|
2026
2026
|
}
|
|
2027
2027
|
//------------------------------------------------------------------------------------------------------------------
|
|
@@ -2029,11 +2029,11 @@ class Ue {
|
|
|
2029
2029
|
const t = this._engine.getDeltaTime() / 1e3;
|
|
2030
2030
|
if (this._inputManager.pollGamepads(), !this._paused) {
|
|
2031
2031
|
this._entityManager.$frameUpdate(t);
|
|
2032
|
-
for (const { callback:
|
|
2032
|
+
for (const { callback: i } of this._frameCallbacks)
|
|
2033
2033
|
try {
|
|
2034
|
-
|
|
2035
|
-
} catch (
|
|
2036
|
-
this._log.error("Error in frame callback:",
|
|
2034
|
+
i(t);
|
|
2035
|
+
} catch (s) {
|
|
2036
|
+
this._log.error("Error in frame callback:", s);
|
|
2037
2037
|
}
|
|
2038
2038
|
}
|
|
2039
2039
|
this.currentScene && this.currentScene.render();
|
|
@@ -2178,9 +2178,9 @@ class We {
|
|
|
2178
2178
|
* @param behaviors - Attached in order; order determines event processing priority.
|
|
2179
2179
|
* @param name
|
|
2180
2180
|
*/
|
|
2181
|
-
constructor(e, t,
|
|
2182
|
-
this.id = Fe(), this.type = e, this.name = n, this.state =
|
|
2183
|
-
for (const o of
|
|
2181
|
+
constructor(e, t, i, s, n) {
|
|
2182
|
+
this.id = Fe(), this.type = e, this.name = n, this.state = i, this.eventBus = t;
|
|
2183
|
+
for (const o of s)
|
|
2184
2184
|
this.attachBehavior(new o());
|
|
2185
2185
|
}
|
|
2186
2186
|
//------------------------------------------------------------------------------------------------------------------
|
|
@@ -2235,9 +2235,9 @@ class We {
|
|
|
2235
2235
|
if (!this.node)
|
|
2236
2236
|
return;
|
|
2237
2237
|
let t = this.node;
|
|
2238
|
-
for (const
|
|
2238
|
+
for (const i of e.split("/"))
|
|
2239
2239
|
t = t?.getChildren(
|
|
2240
|
-
(
|
|
2240
|
+
(s) => s.name === i,
|
|
2241
2241
|
!1
|
|
2242
2242
|
)[0];
|
|
2243
2243
|
return t;
|
|
@@ -2251,10 +2251,10 @@ class We {
|
|
|
2251
2251
|
*/
|
|
2252
2252
|
$attachToNode(e, t) {
|
|
2253
2253
|
this.node = e, this._gameEngine = t;
|
|
2254
|
-
for (const
|
|
2255
|
-
|
|
2256
|
-
for (const
|
|
2257
|
-
|
|
2254
|
+
for (const i of this.behaviors)
|
|
2255
|
+
i.onNodeAttached?.(e, t);
|
|
2256
|
+
for (const i of this.children)
|
|
2257
|
+
i.node && (i.node.parent = e);
|
|
2258
2258
|
}
|
|
2259
2259
|
/**
|
|
2260
2260
|
* Internal method for EntityManager to detach entity from its node.
|
|
@@ -2308,12 +2308,12 @@ class We {
|
|
|
2308
2308
|
* @param type - Event type string
|
|
2309
2309
|
* @param payload - Optional event payload
|
|
2310
2310
|
*/
|
|
2311
|
-
async send(e, t,
|
|
2311
|
+
async send(e, t, i) {
|
|
2312
2312
|
if (e === this.id)
|
|
2313
|
-
return this.$send(t,
|
|
2313
|
+
return this.$send(t, i, this.id);
|
|
2314
2314
|
if (!this._entityManager)
|
|
2315
2315
|
throw new Error("Entity is not registered with an EntityManager.");
|
|
2316
|
-
return this._entityManager.send(e, t,
|
|
2316
|
+
return this._entityManager.send(e, t, i, this.id);
|
|
2317
2317
|
}
|
|
2318
2318
|
/**
|
|
2319
2319
|
* Sends a request to a specific entity's behaviors and returns the first response.
|
|
@@ -2323,12 +2323,12 @@ class We {
|
|
|
2323
2323
|
* @param type - Request type string
|
|
2324
2324
|
* @param payload - Optional request payload
|
|
2325
2325
|
*/
|
|
2326
|
-
async request(e, t,
|
|
2326
|
+
async request(e, t, i) {
|
|
2327
2327
|
if (e === this.id)
|
|
2328
|
-
return this.$request(t,
|
|
2328
|
+
return this.$request(t, i, this.id);
|
|
2329
2329
|
if (!this._entityManager)
|
|
2330
2330
|
throw new Error("Entity is not registered with an EntityManager.");
|
|
2331
|
-
return this._entityManager.request(e, t,
|
|
2331
|
+
return this._entityManager.request(e, t, i, this.id);
|
|
2332
2332
|
}
|
|
2333
2333
|
/**
|
|
2334
2334
|
* Sends a fire-and-forget event directly to this entity's own behaviors.
|
|
@@ -2337,8 +2337,8 @@ class We {
|
|
|
2337
2337
|
* @param payload - Optional event payload
|
|
2338
2338
|
* @internal
|
|
2339
2339
|
*/
|
|
2340
|
-
async $send(e, t,
|
|
2341
|
-
await this.$processEvent({ type: e, targetID: this.id, senderID:
|
|
2340
|
+
async $send(e, t, i) {
|
|
2341
|
+
await this.$processEvent({ type: e, targetID: this.id, senderID: i, payload: t });
|
|
2342
2342
|
}
|
|
2343
2343
|
/**
|
|
2344
2344
|
* Sends a request to this entity's own behaviors and returns the first response.
|
|
@@ -2347,12 +2347,12 @@ class We {
|
|
|
2347
2347
|
* @param payload - Optional request payload
|
|
2348
2348
|
* @internal
|
|
2349
2349
|
*/
|
|
2350
|
-
async $request(e, t,
|
|
2351
|
-
const
|
|
2350
|
+
async $request(e, t, i) {
|
|
2351
|
+
const s = { type: e, targetID: this.id, senderID: i, payload: t };
|
|
2352
2352
|
let n;
|
|
2353
2353
|
for (const o of this.behaviors)
|
|
2354
2354
|
try {
|
|
2355
|
-
const a = await o.processRequest?.(
|
|
2355
|
+
const a = await o.processRequest?.(s, this.state);
|
|
2356
2356
|
if (a !== void 0)
|
|
2357
2357
|
return { success: !0, value: a };
|
|
2358
2358
|
} catch (a) {
|
|
@@ -2374,13 +2374,13 @@ class We {
|
|
|
2374
2374
|
*/
|
|
2375
2375
|
$reset(e, t) {
|
|
2376
2376
|
this.state = { ...e }, this._tags.clear();
|
|
2377
|
-
for (const
|
|
2378
|
-
this._tags.add(
|
|
2377
|
+
for (const i of t)
|
|
2378
|
+
this._tags.add(i);
|
|
2379
2379
|
this.node && this.$detachFromNode();
|
|
2380
|
-
for (const
|
|
2381
|
-
|
|
2382
|
-
for (const
|
|
2383
|
-
|
|
2380
|
+
for (const i of this.behaviors)
|
|
2381
|
+
i.onReset?.(this.state);
|
|
2382
|
+
for (const i of this.children)
|
|
2383
|
+
i.$reset({}, []);
|
|
2384
2384
|
this.parent = null;
|
|
2385
2385
|
}
|
|
2386
2386
|
/**
|
|
@@ -2453,33 +2453,33 @@ class We {
|
|
|
2453
2453
|
attachBehavior(e, t) {
|
|
2454
2454
|
if (this.hasBehavior(e.constructor))
|
|
2455
2455
|
throw new Error(`Behavior ${e.constructor.name} is already attached to this entity.`);
|
|
2456
|
-
for (const
|
|
2457
|
-
const
|
|
2458
|
-
if (
|
|
2459
|
-
|
|
2456
|
+
for (const i of e.eventSubscriptions) {
|
|
2457
|
+
const s = this.subscriptions.get(i);
|
|
2458
|
+
if (s)
|
|
2459
|
+
s.count++;
|
|
2460
2460
|
else {
|
|
2461
|
-
const o = this.eventBus.subscribe(
|
|
2462
|
-
this.subscriptions.set(
|
|
2461
|
+
const o = this.eventBus.subscribe(i, this.$processEvent.bind(this));
|
|
2462
|
+
this.subscriptions.set(i, { count: 1, unsubscribe: o });
|
|
2463
2463
|
}
|
|
2464
2464
|
}
|
|
2465
2465
|
if (!t)
|
|
2466
2466
|
this.behaviors.push(e);
|
|
2467
2467
|
else {
|
|
2468
|
-
if ([t.before, t.after, t.at].filter((
|
|
2468
|
+
if ([t.before, t.after, t.at].filter((s) => s !== void 0).length > 1)
|
|
2469
2469
|
throw new Error("attachBehavior: specify only one of before, after, or at");
|
|
2470
2470
|
if (t.before) {
|
|
2471
|
-
const
|
|
2472
|
-
if (
|
|
2471
|
+
const s = this.findBehaviorIndex(t.before);
|
|
2472
|
+
if (s === -1)
|
|
2473
2473
|
throw new Error(`attachBehavior: no behavior of type ${t.before.name} found`);
|
|
2474
|
-
this.behaviors.splice(
|
|
2474
|
+
this.behaviors.splice(s, 0, e);
|
|
2475
2475
|
} else if (t.after) {
|
|
2476
|
-
const
|
|
2477
|
-
if (
|
|
2476
|
+
const s = this.findBehaviorIndex(t.after);
|
|
2477
|
+
if (s === -1)
|
|
2478
2478
|
throw new Error(`attachBehavior: no behavior of type ${t.after.name} found`);
|
|
2479
|
-
this.behaviors.splice(
|
|
2479
|
+
this.behaviors.splice(s + 1, 0, e);
|
|
2480
2480
|
} else if (t.at !== void 0) {
|
|
2481
|
-
const
|
|
2482
|
-
this.behaviors.splice(
|
|
2481
|
+
const s = Math.max(0, Math.min(t.at, this.behaviors.length));
|
|
2482
|
+
this.behaviors.splice(s, 0, e);
|
|
2483
2483
|
} else
|
|
2484
2484
|
this.behaviors.push(e);
|
|
2485
2485
|
}
|
|
@@ -2493,13 +2493,13 @@ class We {
|
|
|
2493
2493
|
const t = this.findBehaviorIndex(e);
|
|
2494
2494
|
if (t === -1)
|
|
2495
2495
|
return !1;
|
|
2496
|
-
const
|
|
2497
|
-
this.node &&
|
|
2498
|
-
for (const
|
|
2499
|
-
const n = this.subscriptions.get(
|
|
2500
|
-
n && (n.count--, n.count <= 0 && (n.unsubscribe(), this.subscriptions.delete(
|
|
2496
|
+
const i = this.behaviors[t];
|
|
2497
|
+
this.node && i.onNodeDetached?.();
|
|
2498
|
+
for (const s of i.eventSubscriptions) {
|
|
2499
|
+
const n = this.subscriptions.get(s);
|
|
2500
|
+
n && (n.count--, n.count <= 0 && (n.unsubscribe(), this.subscriptions.delete(s)));
|
|
2501
2501
|
}
|
|
2502
|
-
return this.behaviors.splice(t, 1),
|
|
2502
|
+
return this.behaviors.splice(t, 1), i.$setEntity(null), !0;
|
|
2503
2503
|
}
|
|
2504
2504
|
}
|
|
2505
2505
|
class je {
|
|
@@ -2534,8 +2534,8 @@ class je {
|
|
|
2534
2534
|
* @param logger
|
|
2535
2535
|
* @param bindingManager
|
|
2536
2536
|
*/
|
|
2537
|
-
constructor(e, t,
|
|
2538
|
-
this.eventBus = e, this.bindingManager =
|
|
2537
|
+
constructor(e, t, i) {
|
|
2538
|
+
this.eventBus = e, this.bindingManager = i, this._log = t?.getLogger("EntityManager") || new u("EntityManager"), this._log.info("EntityManager initialized");
|
|
2539
2539
|
}
|
|
2540
2540
|
//------------------------------------------------------------------------------------------------------------------
|
|
2541
2541
|
// Internal API
|
|
@@ -2559,8 +2559,8 @@ class je {
|
|
|
2559
2559
|
* Gets or creates a Set in a Map, returning the Set.
|
|
2560
2560
|
*/
|
|
2561
2561
|
_getOrCreateSet(e, t) {
|
|
2562
|
-
let
|
|
2563
|
-
return
|
|
2562
|
+
let i = e.get(t);
|
|
2563
|
+
return i || (i = /* @__PURE__ */ new Set(), e.set(t, i)), i;
|
|
2564
2564
|
}
|
|
2565
2565
|
/**
|
|
2566
2566
|
* Adds an entity to all relevant indices.
|
|
@@ -2577,12 +2577,12 @@ class je {
|
|
|
2577
2577
|
_unindexEntity(e) {
|
|
2578
2578
|
const t = this._entitiesByType.get(e.type);
|
|
2579
2579
|
if (t && (t.delete(e), t.size === 0 && this._entitiesByType.delete(e.type)), e.name) {
|
|
2580
|
-
const
|
|
2581
|
-
|
|
2580
|
+
const i = this._entitiesByName.get(e.name);
|
|
2581
|
+
i && (i.delete(e), i.size === 0 && this._entitiesByName.delete(e.name));
|
|
2582
2582
|
}
|
|
2583
|
-
for (const
|
|
2584
|
-
const
|
|
2585
|
-
|
|
2583
|
+
for (const i of e.tags) {
|
|
2584
|
+
const s = this._entitiesByTag.get(i);
|
|
2585
|
+
s && (s.delete(e), s.size === 0 && this._entitiesByTag.delete(i));
|
|
2586
2586
|
}
|
|
2587
2587
|
e.node && this._entitiesByNode.delete(e.node);
|
|
2588
2588
|
}
|
|
@@ -2597,34 +2597,34 @@ class je {
|
|
|
2597
2597
|
const t = e.extends;
|
|
2598
2598
|
if (!t)
|
|
2599
2599
|
return e;
|
|
2600
|
-
const
|
|
2601
|
-
if (!
|
|
2600
|
+
const i = this.entityDefinitions.get(t);
|
|
2601
|
+
if (!i) {
|
|
2602
2602
|
const o = `Cannot extend "${t}": base entity definition is not registered.`;
|
|
2603
2603
|
throw this._log.error(o), new Error(o);
|
|
2604
2604
|
}
|
|
2605
|
-
let
|
|
2606
|
-
return (
|
|
2605
|
+
let s;
|
|
2606
|
+
return (i.tags || e.tags) && (s = [.../* @__PURE__ */ new Set([...i.tags ?? [], ...e.tags ?? []])]), {
|
|
2607
2607
|
// Scalar fields: child overrides if provided, else inherit
|
|
2608
2608
|
type: e.type,
|
|
2609
|
-
name: e.name ??
|
|
2610
|
-
mesh: e.mesh ??
|
|
2609
|
+
name: e.name ?? i.name,
|
|
2610
|
+
mesh: e.mesh ?? i.mesh,
|
|
2611
2611
|
// Shallow-merged state
|
|
2612
|
-
defaultState: { ...
|
|
2612
|
+
defaultState: { ...i.defaultState, ...e.defaultState },
|
|
2613
2613
|
// Replace-entirely fields: child overrides if provided, else inherit
|
|
2614
|
-
behaviors: e.behaviors ??
|
|
2615
|
-
actions: e.actions ??
|
|
2614
|
+
behaviors: e.behaviors ?? i.behaviors,
|
|
2615
|
+
actions: e.actions ?? i.actions,
|
|
2616
2616
|
// Concatenated tags
|
|
2617
|
-
tags:
|
|
2617
|
+
tags: s,
|
|
2618
2618
|
// Pooling: child overrides if provided, else inherit
|
|
2619
|
-
poolable: e.poolable ??
|
|
2620
|
-
poolSize: e.poolSize ??
|
|
2619
|
+
poolable: e.poolable ?? i.poolable,
|
|
2620
|
+
poolSize: e.poolSize ?? i.poolSize,
|
|
2621
2621
|
// Children: child overrides if provided, else inherit
|
|
2622
|
-
children: e.children ??
|
|
2622
|
+
children: e.children ?? i.children,
|
|
2623
2623
|
// Lifecycle hooks: child overrides if provided, else inherit
|
|
2624
|
-
onBeforeCreate: e.onBeforeCreate ??
|
|
2625
|
-
onCreate: e.onCreate ??
|
|
2626
|
-
onBeforeDestroy: e.onBeforeDestroy ??
|
|
2627
|
-
onDestroy: e.onDestroy ??
|
|
2624
|
+
onBeforeCreate: e.onBeforeCreate ?? i.onBeforeCreate,
|
|
2625
|
+
onCreate: e.onCreate ?? i.onCreate,
|
|
2626
|
+
onBeforeDestroy: e.onBeforeDestroy ?? i.onBeforeDestroy,
|
|
2627
|
+
onDestroy: e.onDestroy ?? i.onDestroy
|
|
2628
2628
|
};
|
|
2629
2629
|
}
|
|
2630
2630
|
//------------------------------------------------------------------------------------------------------------------
|
|
@@ -2647,14 +2647,14 @@ class je {
|
|
|
2647
2647
|
if (e.actions)
|
|
2648
2648
|
for (const t of e.actions)
|
|
2649
2649
|
try {
|
|
2650
|
-
const
|
|
2651
|
-
|
|
2650
|
+
const i = this.bindingManager.getAction(t.name);
|
|
2651
|
+
i ? this._areActionsCompatible(i, t) ? this._log.trace(
|
|
2652
2652
|
`Action "${t.name}" already registered with compatible options, skipping registration`
|
|
2653
2653
|
) : this._log.warn(
|
|
2654
|
-
`Action "${t.name}" already registered with different options. Entity "${e.type}" requires: ${JSON.stringify(t)}, but found: ${JSON.stringify(
|
|
2654
|
+
`Action "${t.name}" already registered with different options. Entity "${e.type}" requires: ${JSON.stringify(t)}, but found: ${JSON.stringify(i)}`
|
|
2655
2655
|
) : (this._log.debug(`Registering action "${t.name}" from entity type "${e.type}"`), this.bindingManager.registerAction(t));
|
|
2656
|
-
} catch (
|
|
2657
|
-
this._log.debug(`Failed to register action "${t.name}": ${
|
|
2656
|
+
} catch (i) {
|
|
2657
|
+
this._log.debug(`Failed to register action "${t.name}": ${i instanceof Error ? i.message : String(i)}`);
|
|
2658
2658
|
}
|
|
2659
2659
|
}
|
|
2660
2660
|
$frameUpdate(e) {
|
|
@@ -2690,52 +2690,52 @@ class je {
|
|
|
2690
2690
|
*/
|
|
2691
2691
|
async createEntity(e, t = {}) {
|
|
2692
2692
|
this._log.debug(`Creating entity of type: ${e}`);
|
|
2693
|
-
const
|
|
2694
|
-
if (!
|
|
2693
|
+
const i = this.entityDefinitions.get(e);
|
|
2694
|
+
if (!i) {
|
|
2695
2695
|
const a = `Entity type ${e} is not registered.`;
|
|
2696
2696
|
throw this._log.error(a), new Error(a);
|
|
2697
2697
|
}
|
|
2698
|
-
if (
|
|
2698
|
+
if (i.poolable) {
|
|
2699
2699
|
const a = this._pools.get(e);
|
|
2700
2700
|
if (a && a.length > 0) {
|
|
2701
2701
|
this._log.trace(`Recycling entity from pool for type: ${e}`);
|
|
2702
2702
|
const l = a.pop();
|
|
2703
2703
|
if (l.$reset(
|
|
2704
|
-
|
|
2705
|
-
|
|
2704
|
+
i.defaultState,
|
|
2705
|
+
i.tags ?? []
|
|
2706
2706
|
), l.$setEntityManager(this), t.initialState && (l.state = { ...l.state, ...t.initialState }), t.tags)
|
|
2707
2707
|
for (const h of t.tags)
|
|
2708
2708
|
l.$addTag(h);
|
|
2709
2709
|
return t.node && l.$attachToNode(t.node, this._engine), this.entities.set(l.id, l), this._indexEntity(l), this._log.debug(`Recycled entity ${l.id} from pool`), l;
|
|
2710
2710
|
}
|
|
2711
2711
|
}
|
|
2712
|
-
this._log.trace(`Using entity definition with ${
|
|
2713
|
-
let
|
|
2714
|
-
if (
|
|
2712
|
+
this._log.trace(`Using entity definition with ${i.behaviors?.length || 0} behaviors`);
|
|
2713
|
+
let s = { ...i.defaultState, ...t.initialState };
|
|
2714
|
+
if (i.onBeforeCreate) {
|
|
2715
2715
|
this._log.trace(`Calling onBeforeCreate hook for entity type: ${e}`);
|
|
2716
|
-
const a = await
|
|
2717
|
-
a !== void 0 && (
|
|
2716
|
+
const a = await i.onBeforeCreate(s);
|
|
2717
|
+
a !== void 0 && (s = a);
|
|
2718
2718
|
}
|
|
2719
|
-
const n = t.name ??
|
|
2720
|
-
|
|
2719
|
+
const n = t.name ?? i.name, o = new We(
|
|
2720
|
+
i.type,
|
|
2721
2721
|
this.eventBus,
|
|
2722
|
-
|
|
2723
|
-
|
|
2722
|
+
s,
|
|
2723
|
+
i.behaviors,
|
|
2724
2724
|
n
|
|
2725
2725
|
);
|
|
2726
|
-
if (o.$setEntityManager(this), t.node && o.$attachToNode(t.node, this._engine),
|
|
2727
|
-
for (const a of
|
|
2726
|
+
if (o.$setEntityManager(this), t.node && o.$attachToNode(t.node, this._engine), i.tags)
|
|
2727
|
+
for (const a of i.tags)
|
|
2728
2728
|
o.$addTag(a);
|
|
2729
2729
|
if (t.tags)
|
|
2730
2730
|
for (const a of t.tags)
|
|
2731
2731
|
o.$addTag(a);
|
|
2732
|
-
if (this.entities.set(o.id, o), this._indexEntity(o), this._log.debug(`Entity created with ID: ${o.id}${n ? ` (name: ${n})` : ""}`),
|
|
2732
|
+
if (this.entities.set(o.id, o), this._indexEntity(o), this._log.debug(`Entity created with ID: ${o.id}${n ? ` (name: ${n})` : ""}`), i.onCreate) {
|
|
2733
2733
|
this._log.trace(`Calling onCreate hook for entity type: ${e}`);
|
|
2734
|
-
const a = await
|
|
2734
|
+
const a = await i.onCreate(o.state);
|
|
2735
2735
|
a !== void 0 && (o.state = a);
|
|
2736
2736
|
}
|
|
2737
|
-
if (
|
|
2738
|
-
for (const a of
|
|
2737
|
+
if (i.children)
|
|
2738
|
+
for (const a of i.children) {
|
|
2739
2739
|
const l = { ...a.initialState };
|
|
2740
2740
|
a.position && (l._position = a.position), a.rotation && (l._rotation = a.rotation);
|
|
2741
2741
|
const h = await this.createEntity(a.type, {
|
|
@@ -2755,24 +2755,24 @@ class je {
|
|
|
2755
2755
|
this._log.debug(`Destroying entity: ${e}`);
|
|
2756
2756
|
const t = this.entities.get(e);
|
|
2757
2757
|
if (t) {
|
|
2758
|
-
const
|
|
2759
|
-
if (
|
|
2758
|
+
const i = this.entityDefinitions.get(t.type);
|
|
2759
|
+
if (i?.poolable) {
|
|
2760
2760
|
this._log.trace(`Pooling entity ${e} instead of destroying`);
|
|
2761
2761
|
for (const n of [...t.children])
|
|
2762
2762
|
await this.destroyEntity(n.id);
|
|
2763
|
-
t.parent && t.parent.$removeChild(t), this._unindexEntity(t), t.$reset(
|
|
2764
|
-
let
|
|
2765
|
-
|
|
2763
|
+
t.parent && t.parent.$removeChild(t), this._unindexEntity(t), t.$reset(i.defaultState, i.tags ?? []);
|
|
2764
|
+
let s = this._pools.get(t.type);
|
|
2765
|
+
s || (s = [], this._pools.set(t.type, s)), s.push(t), this.entities.delete(e), this._log.debug(`Entity ${e} pooled`);
|
|
2766
2766
|
return;
|
|
2767
2767
|
}
|
|
2768
|
-
for (const
|
|
2769
|
-
await this.destroyEntity(
|
|
2770
|
-
if (t.parent && t.parent.$removeChild(t),
|
|
2768
|
+
for (const s of [...t.children])
|
|
2769
|
+
await this.destroyEntity(s.id);
|
|
2770
|
+
if (t.parent && t.parent.$removeChild(t), i?.onBeforeDestroy) {
|
|
2771
2771
|
this._log.trace(`Calling onBeforeDestroy hook for entity: ${e}`);
|
|
2772
|
-
const
|
|
2773
|
-
|
|
2772
|
+
const s = await i.onBeforeDestroy(t.state);
|
|
2773
|
+
s !== void 0 && (t.state = s);
|
|
2774
2774
|
}
|
|
2775
|
-
this._unindexEntity(t), await t.$destroy(),
|
|
2775
|
+
this._unindexEntity(t), await t.$destroy(), i?.onDestroy && (this._log.trace(`Calling onDestroy hook for entity: ${e}`), await i.onDestroy(t.state)), this.entities.delete(e), this._log.debug(`Entity ${e} destroyed`);
|
|
2776
2776
|
} else
|
|
2777
2777
|
this._log.warn(`Attempted to destroy non-existent entity: ${e}`);
|
|
2778
2778
|
}
|
|
@@ -2809,8 +2809,8 @@ class je {
|
|
|
2809
2809
|
* @returns False if either entity is not found
|
|
2810
2810
|
*/
|
|
2811
2811
|
addChild(e, t) {
|
|
2812
|
-
const
|
|
2813
|
-
return
|
|
2812
|
+
const i = this.entities.get(e), s = this.entities.get(t);
|
|
2813
|
+
return i ? s ? (i.$addChild(s), this._log.trace(`Added child ${t} to parent ${e}`), !0) : (this._log.warn(`addChild: child entity "${t}" not found`), !1) : (this._log.warn(`addChild: parent entity "${e}" not found`), !1);
|
|
2814
2814
|
}
|
|
2815
2815
|
/**
|
|
2816
2816
|
* Removes a child entity from a parent entity.
|
|
@@ -2819,8 +2819,8 @@ class je {
|
|
|
2819
2819
|
* @returns False if either entity is not found
|
|
2820
2820
|
*/
|
|
2821
2821
|
removeChild(e, t) {
|
|
2822
|
-
const
|
|
2823
|
-
return
|
|
2822
|
+
const i = this.entities.get(e), s = this.entities.get(t);
|
|
2823
|
+
return i ? s ? (i.$removeChild(s), this._log.trace(`Removed child ${t} from parent ${e}`), !0) : (this._log.warn(`removeChild: child entity "${t}" not found`), !1) : (this._log.warn(`removeChild: parent entity "${e}" not found`), !1);
|
|
2824
2824
|
}
|
|
2825
2825
|
//------------------------------------------------------------------------------------------------------------------
|
|
2826
2826
|
// Query Methods
|
|
@@ -2868,21 +2868,21 @@ class je {
|
|
|
2868
2868
|
if (e.length === 0)
|
|
2869
2869
|
return [];
|
|
2870
2870
|
if (t === "any") {
|
|
2871
|
-
const
|
|
2872
|
-
for (const
|
|
2873
|
-
const n = this._entitiesByTag.get(
|
|
2871
|
+
const i = /* @__PURE__ */ new Set();
|
|
2872
|
+
for (const s of e) {
|
|
2873
|
+
const n = this._entitiesByTag.get(s);
|
|
2874
2874
|
if (n)
|
|
2875
2875
|
for (const o of n)
|
|
2876
|
-
|
|
2876
|
+
i.add(o);
|
|
2877
2877
|
}
|
|
2878
|
-
return Array.from(
|
|
2878
|
+
return Array.from(i);
|
|
2879
2879
|
} else {
|
|
2880
|
-
const
|
|
2881
|
-
if (
|
|
2880
|
+
const i = e.map((o) => this._entitiesByTag.get(o)).filter((o) => o !== void 0);
|
|
2881
|
+
if (i.length !== e.length)
|
|
2882
2882
|
return [];
|
|
2883
|
-
|
|
2884
|
-
const [
|
|
2885
|
-
return Array.from(
|
|
2883
|
+
i.sort((o, a) => o.size - a.size);
|
|
2884
|
+
const [s, ...n] = i;
|
|
2885
|
+
return Array.from(s).filter((o) => n.every((a) => a.has(o)));
|
|
2886
2886
|
}
|
|
2887
2887
|
}
|
|
2888
2888
|
/**
|
|
@@ -2909,13 +2909,13 @@ class je {
|
|
|
2909
2909
|
* @param type - Event type string
|
|
2910
2910
|
* @param payload - Optional event payload
|
|
2911
2911
|
*/
|
|
2912
|
-
async send(e, t,
|
|
2912
|
+
async send(e, t, i, s) {
|
|
2913
2913
|
const n = this.entities.get(e) ?? this.getByName(e);
|
|
2914
2914
|
if (!n) {
|
|
2915
2915
|
this._log.warn(`send: entity "${e}" not found`);
|
|
2916
2916
|
return;
|
|
2917
2917
|
}
|
|
2918
|
-
await n.$send(t,
|
|
2918
|
+
await n.$send(t, i, s);
|
|
2919
2919
|
}
|
|
2920
2920
|
/**
|
|
2921
2921
|
* Sends a request to a specific entity's behaviors and returns the first response.
|
|
@@ -2926,9 +2926,9 @@ class je {
|
|
|
2926
2926
|
* @param payload - Optional request payload
|
|
2927
2927
|
* @param senderID - Optional sender entity ID (stamped on the event)
|
|
2928
2928
|
*/
|
|
2929
|
-
async request(e, t,
|
|
2929
|
+
async request(e, t, i, s) {
|
|
2930
2930
|
const n = this.entities.get(e) ?? this.getByName(e);
|
|
2931
|
-
return n ? n.$request(t,
|
|
2931
|
+
return n ? n.$request(t, i, s) : { success: !1, error: `Entity "${e}" not found` };
|
|
2932
2932
|
}
|
|
2933
2933
|
//------------------------------------------------------------------------------------------------------------------
|
|
2934
2934
|
// Tag Manipulation
|
|
@@ -2940,8 +2940,8 @@ class je {
|
|
|
2940
2940
|
* @returns False if already present or entity not found
|
|
2941
2941
|
*/
|
|
2942
2942
|
addTag(e, t) {
|
|
2943
|
-
const
|
|
2944
|
-
return
|
|
2943
|
+
const i = typeof e == "string" ? this.entities.get(e) : e;
|
|
2944
|
+
return i ? i.hasTag(t) ? !1 : (i.$addTag(t), this._getOrCreateSet(this._entitiesByTag, t).add(i), this._log.trace(`Added tag "${t}" to entity ${i.id}`), !0) : (this._log.warn("addTag: entity not found"), !1);
|
|
2945
2945
|
}
|
|
2946
2946
|
/**
|
|
2947
2947
|
* Removes a tag from an entity and updates the tag index.
|
|
@@ -2950,13 +2950,13 @@ class je {
|
|
|
2950
2950
|
* @returns False if not present or entity not found
|
|
2951
2951
|
*/
|
|
2952
2952
|
removeTag(e, t) {
|
|
2953
|
-
const
|
|
2954
|
-
if (!
|
|
2953
|
+
const i = typeof e == "string" ? this.entities.get(e) : e;
|
|
2954
|
+
if (!i)
|
|
2955
2955
|
return this._log.warn("removeTag: entity not found"), !1;
|
|
2956
|
-
if (!
|
|
2956
|
+
if (!i.$removeTag(t))
|
|
2957
2957
|
return !1;
|
|
2958
|
-
const
|
|
2959
|
-
return
|
|
2958
|
+
const s = this._entitiesByTag.get(t);
|
|
2959
|
+
return s && (s.delete(i), s.size === 0 && this._entitiesByTag.delete(t)), this._log.trace(`Removed tag "${t}" from entity ${i.id}`), !0;
|
|
2960
2960
|
}
|
|
2961
2961
|
//------------------------------------------------------------------------------------------------------------------
|
|
2962
2962
|
// Node Attachment
|
|
@@ -2977,8 +2977,8 @@ class je {
|
|
|
2977
2977
|
* @returns False if entity not found or node already has an entity
|
|
2978
2978
|
*/
|
|
2979
2979
|
attachToNode(e, t) {
|
|
2980
|
-
const
|
|
2981
|
-
return
|
|
2980
|
+
const i = typeof e == "string" ? this.entities.get(e) : e;
|
|
2981
|
+
return i ? this._entitiesByNode.has(t) ? (this._log.warn("attachToNode: node already has an attached entity"), !1) : (i.node && this._entitiesByNode.delete(i.node), i.$attachToNode(t, this._engine), this._entitiesByNode.set(t, i), this._log.trace(`Attached entity ${i.id} to node "${t.name}"`), !0) : (this._log.warn("attachToNode: entity not found"), !1);
|
|
2982
2982
|
}
|
|
2983
2983
|
/**
|
|
2984
2984
|
* Detaches an entity from its scene node.
|
|
@@ -2993,8 +2993,8 @@ class je {
|
|
|
2993
2993
|
if (!t.node)
|
|
2994
2994
|
return !1;
|
|
2995
2995
|
this._entitiesByNode.delete(t.node);
|
|
2996
|
-
const
|
|
2997
|
-
return t.$detachFromNode(), this._log.trace(`Detached entity ${t.id} from node "${
|
|
2996
|
+
const i = t.node.name;
|
|
2997
|
+
return t.$detachFromNode(), this._log.trace(`Detached entity ${t.id} from node "${i}"`), !0;
|
|
2998
2998
|
}
|
|
2999
2999
|
//------------------------------------------------------------------------------------------------------------------
|
|
3000
3000
|
// Object Pooling
|
|
@@ -3006,9 +3006,9 @@ class je {
|
|
|
3006
3006
|
*/
|
|
3007
3007
|
async prewarm(e, t) {
|
|
3008
3008
|
this._log.debug(`Prewarming pool for "${e}" with ${t} entities`);
|
|
3009
|
-
for (let
|
|
3010
|
-
const
|
|
3011
|
-
await this.destroyEntity(
|
|
3009
|
+
for (let i = 0; i < t; i++) {
|
|
3010
|
+
const s = await this.createEntity(e);
|
|
3011
|
+
await this.destroyEntity(s.id);
|
|
3012
3012
|
}
|
|
3013
3013
|
}
|
|
3014
3014
|
/**
|
|
@@ -3019,8 +3019,8 @@ class je {
|
|
|
3019
3019
|
const t = this._pools.get(e);
|
|
3020
3020
|
if (t) {
|
|
3021
3021
|
this._log.debug(`Draining pool for "${e}" (${t.length} entities)`);
|
|
3022
|
-
for (const
|
|
3023
|
-
await
|
|
3022
|
+
for (const i of t)
|
|
3023
|
+
await i.$destroy();
|
|
3024
3024
|
t.length = 0, this._pools.delete(e);
|
|
3025
3025
|
}
|
|
3026
3026
|
}
|
|
@@ -3037,14 +3037,14 @@ class je {
|
|
|
3037
3037
|
for (const t of e)
|
|
3038
3038
|
try {
|
|
3039
3039
|
await this.destroyEntity(t);
|
|
3040
|
-
} catch (
|
|
3041
|
-
this._log.error(`Error destroying entity ${t}: ${
|
|
3040
|
+
} catch (i) {
|
|
3041
|
+
this._log.error(`Error destroying entity ${t}: ${i}`);
|
|
3042
3042
|
}
|
|
3043
3043
|
for (const t of [...this._pools.keys()])
|
|
3044
3044
|
try {
|
|
3045
3045
|
await this.drainPool(t);
|
|
3046
|
-
} catch (
|
|
3047
|
-
this._log.error(`Error draining pool for "${t}": ${
|
|
3046
|
+
} catch (i) {
|
|
3047
|
+
this._log.error(`Error draining pool for "${t}": ${i}`);
|
|
3048
3048
|
}
|
|
3049
3049
|
this.entityDefinitions.clear(), this._entitiesByName.clear(), this._entitiesByType.clear(), this._entitiesByTag.clear(), this._entitiesByNode.clear(), this._log.info("EntityManager torn down successfully");
|
|
3050
3050
|
}
|
|
@@ -3066,8 +3066,8 @@ function qe(r, e) {
|
|
|
3066
3066
|
e.vignette.color.b,
|
|
3067
3067
|
1
|
|
3068
3068
|
))), e.sharpen && (t.sharpenEnabled = !0, e.sharpen.edge !== void 0 && (t.sharpen.edgeAmount = e.sharpen.edge), e.sharpen.color !== void 0 && (t.sharpen.colorAmount = e.sharpen.color)), e.chromaticAberration && (t.chromaticAberrationEnabled = !0, e.chromaticAberration.amount !== void 0 && (t.chromaticAberration.aberrationAmount = e.chromaticAberration.amount)), e.ssao) {
|
|
3069
|
-
const
|
|
3070
|
-
e.ssao.radius !== void 0 && (
|
|
3069
|
+
const i = new _e("sage-ssao", r, { ssaoRatio: 0.5, blurRatio: 1 });
|
|
3070
|
+
e.ssao.radius !== void 0 && (i.radius = e.ssao.radius), e.ssao.samples !== void 0 && (i.samples = e.ssao.samples), e.ssao.totalStrength !== void 0 && (i.totalStrength = e.ssao.totalStrength);
|
|
3071
3071
|
}
|
|
3072
3072
|
}
|
|
3073
3073
|
class Ye {
|
|
@@ -3159,7 +3159,14 @@ class Ye {
|
|
|
3159
3159
|
* other engine lifecycle methods like `$teardown()`.
|
|
3160
3160
|
*/
|
|
3161
3161
|
async $dispose() {
|
|
3162
|
-
|
|
3162
|
+
if (this._scene) {
|
|
3163
|
+
this._log.info(`Disposing level: ${this.name}`);
|
|
3164
|
+
const e = this._context.gameEngine?.managers?.entityManager;
|
|
3165
|
+
if (e?.getAllEntities)
|
|
3166
|
+
for (const t of e.getAllEntities())
|
|
3167
|
+
t.node && t.node.getScene() === this._scene && e.detachFromNode(t);
|
|
3168
|
+
this._scene.dispose(), this._scene = null;
|
|
3169
|
+
}
|
|
3163
3170
|
}
|
|
3164
3171
|
}
|
|
3165
3172
|
class Je extends Ye {
|
|
@@ -3205,8 +3212,8 @@ class Je extends Ye {
|
|
|
3205
3212
|
async buildScene() {
|
|
3206
3213
|
const { sceneEngine: e } = this.gameEngine.engines, { assetManager: t } = this.gameEngine.managers;
|
|
3207
3214
|
this._config.preload && this._config.preload.length > 0 && (this.$emitProgress(2, "Preloading assets..."), await t.preload(this._config.preload));
|
|
3208
|
-
const
|
|
3209
|
-
return this._scene =
|
|
3215
|
+
const i = e.createScene();
|
|
3216
|
+
return this._scene = i, this._config.physics && (this.$emitProgress(5, "Initializing physics..."), await this._enablePhysics(i)), this._config.scene && (this.$emitProgress(10, "Loading scene file..."), await this._loadSceneFile(i)), this._config.environment && (this.$emitProgress(15, "Setting up environment..."), this._processEnvironment(i)), this._processCameras(i), this._processLights(i), this._config.postProcessing && qe(i, this._config.postProcessing), this.$emitProgress(50, "Processing scene properties..."), await this._processNodeProperties(i), this.$emitProgress(70, "Spawning entities..."), await this._processSpawnPoints(), this.$emitProgress(85, "Configuring entities..."), await this._processEntityNodes(), this._config.sounds && (this.$emitProgress(95, "Loading sounds..."), await this._processLevelSounds()), i;
|
|
3210
3217
|
}
|
|
3211
3218
|
/**
|
|
3212
3219
|
* Import all meshes from the configured scene file (GLB/GLTF/Babylon) into the scene.
|
|
@@ -3228,15 +3235,15 @@ class Je extends Ye {
|
|
|
3228
3235
|
const t = this._config.environment;
|
|
3229
3236
|
if (t) {
|
|
3230
3237
|
if (t.ibl && (e.environmentTexture = this._createEnvironmentTexture(t.ibl, t.iblResolution ?? 256, e), this._log.debug(`IBL set from: ${t.ibl}`)), t.skybox) {
|
|
3231
|
-
const
|
|
3232
|
-
if (
|
|
3238
|
+
const i = this._getFileExtension(t.skybox);
|
|
3239
|
+
if (i === ".hdr" || i === ".env") {
|
|
3233
3240
|
if (!t.ibl) {
|
|
3234
|
-
const
|
|
3235
|
-
e.environmentTexture = this._createEnvironmentTexture(t.skybox,
|
|
3241
|
+
const s = t.iblResolution ?? 256;
|
|
3242
|
+
e.environmentTexture = this._createEnvironmentTexture(t.skybox, s, e);
|
|
3236
3243
|
}
|
|
3237
3244
|
e.environmentTexture && e.createDefaultSkybox(e.environmentTexture, !0, t.skyboxSize ?? 1e3, 0, !1);
|
|
3238
3245
|
} else {
|
|
3239
|
-
const
|
|
3246
|
+
const s = t.skyboxSize ?? 1e3, n = y.CreateSphere("skybox", { diameter: s, segments: 32 }, e), o = new R("skybox-mat", e);
|
|
3240
3247
|
o.backFaceCulling = !1, o.disableLighting = !0, o.emissiveTexture = new fe(t.skybox, e), n.material = o, n.infiniteDistance = !0;
|
|
3241
3248
|
}
|
|
3242
3249
|
this._log.debug(`Skybox set from: ${t.skybox}`);
|
|
@@ -3247,8 +3254,8 @@ class Je extends Ye {
|
|
|
3247
3254
|
/**
|
|
3248
3255
|
* Create an environment texture from an HDR or env file.
|
|
3249
3256
|
*/
|
|
3250
|
-
_createEnvironmentTexture(e, t,
|
|
3251
|
-
return this._getFileExtension(e) === ".env" ? pe.CreateFromPrefilteredData(e,
|
|
3257
|
+
_createEnvironmentTexture(e, t, i) {
|
|
3258
|
+
return this._getFileExtension(e) === ".env" ? pe.CreateFromPrefilteredData(e, i) : new ye(e, i, t);
|
|
3252
3259
|
}
|
|
3253
3260
|
_getFileExtension(e) {
|
|
3254
3261
|
const t = e.lastIndexOf(".");
|
|
@@ -3260,35 +3267,35 @@ class Je extends Ye {
|
|
|
3260
3267
|
* If no YAML cameras config exists, the first imported camera (if any) is activated.
|
|
3261
3268
|
*/
|
|
3262
3269
|
_processCameras(e) {
|
|
3263
|
-
const t = this._config.cameras,
|
|
3270
|
+
const t = this._config.cameras, i = this.gameEngine.canvas;
|
|
3264
3271
|
if (!t) {
|
|
3265
|
-
e.cameras.length > 0 && (e.activeCamera = e.cameras[0],
|
|
3272
|
+
e.cameras.length > 0 && (e.activeCamera = e.cameras[0], i && e.activeCamera.attachControl(i, !0), this._log.debug(`Activated imported camera: "${e.activeCamera.name}"`));
|
|
3266
3273
|
return;
|
|
3267
3274
|
}
|
|
3268
|
-
let
|
|
3275
|
+
let s = null;
|
|
3269
3276
|
for (const [n, o] of Object.entries(t)) {
|
|
3270
3277
|
const a = e.getCameraByName(n);
|
|
3271
3278
|
if (a)
|
|
3272
|
-
this._applyCameraConfig(a, o), this._log.debug(`Applied overrides to camera: "${n}"`), (!
|
|
3279
|
+
this._applyCameraConfig(a, o), this._log.debug(`Applied overrides to camera: "${n}"`), (!s || o.active) && (s = a);
|
|
3273
3280
|
else if (o.type) {
|
|
3274
3281
|
const l = this._createCamera(n, o, e);
|
|
3275
|
-
this._log.debug(`Created ${o.type} camera: "${n}"`), (!
|
|
3282
|
+
this._log.debug(`Created ${o.type} camera: "${n}"`), (!s || o.active) && (s = l);
|
|
3276
3283
|
} else
|
|
3277
3284
|
this._log.warn(
|
|
3278
3285
|
`Camera "${n}" not found in scene and no type specified — skipping`
|
|
3279
3286
|
);
|
|
3280
3287
|
}
|
|
3281
|
-
if (
|
|
3282
|
-
e.activeCamera =
|
|
3283
|
-
const n = t[
|
|
3284
|
-
|
|
3288
|
+
if (s) {
|
|
3289
|
+
e.activeCamera = s;
|
|
3290
|
+
const n = t[s.name];
|
|
3291
|
+
i && n?.attachControl !== !1 && s.attachControl(i, !0);
|
|
3285
3292
|
}
|
|
3286
3293
|
}
|
|
3287
3294
|
/**
|
|
3288
3295
|
* Create a new camera from a YAML definition.
|
|
3289
3296
|
*/
|
|
3290
|
-
_createCamera(e, t,
|
|
3291
|
-
const
|
|
3297
|
+
_createCamera(e, t, i) {
|
|
3298
|
+
const s = t.position ? this._toVector3(t.position) : p.Zero();
|
|
3292
3299
|
let n;
|
|
3293
3300
|
switch (t.type) {
|
|
3294
3301
|
case "arcRotate": {
|
|
@@ -3299,16 +3306,16 @@ class Je extends Ye {
|
|
|
3299
3306
|
t.beta ?? Math.PI / 3,
|
|
3300
3307
|
t.radius ?? 10,
|
|
3301
3308
|
o,
|
|
3302
|
-
|
|
3309
|
+
i
|
|
3303
3310
|
);
|
|
3304
3311
|
break;
|
|
3305
3312
|
}
|
|
3306
3313
|
case "universal": {
|
|
3307
|
-
n = new me(e,
|
|
3314
|
+
n = new me(e, s, i);
|
|
3308
3315
|
break;
|
|
3309
3316
|
}
|
|
3310
3317
|
default: {
|
|
3311
|
-
n = new B(e,
|
|
3318
|
+
n = new B(e, s, i);
|
|
3312
3319
|
break;
|
|
3313
3320
|
}
|
|
3314
3321
|
}
|
|
@@ -3328,31 +3335,31 @@ class Je extends Ye {
|
|
|
3328
3335
|
_processLights(e) {
|
|
3329
3336
|
const t = this._config.lights;
|
|
3330
3337
|
if (t)
|
|
3331
|
-
for (const [
|
|
3332
|
-
const n = e.getLightByName(
|
|
3333
|
-
n ? (this._applyLightConfig(n,
|
|
3334
|
-
`Light "${
|
|
3338
|
+
for (const [i, s] of Object.entries(t)) {
|
|
3339
|
+
const n = e.getLightByName(i);
|
|
3340
|
+
n ? (this._applyLightConfig(n, s), this._log.debug(`Applied overrides to light: "${i}"`)) : s.type ? (this._createLight(i, s, e), this._log.debug(`Created ${s.type} light: "${i}"`)) : this._log.warn(
|
|
3341
|
+
`Light "${i}" not found in scene and no type specified — skipping`
|
|
3335
3342
|
);
|
|
3336
3343
|
}
|
|
3337
3344
|
}
|
|
3338
3345
|
/**
|
|
3339
3346
|
* Create a new light from a YAML definition.
|
|
3340
3347
|
*/
|
|
3341
|
-
_createLight(e, t,
|
|
3342
|
-
const
|
|
3348
|
+
_createLight(e, t, i) {
|
|
3349
|
+
const s = t.direction ? this._toVector3(t.direction) : new p(0, -1, 0), n = t.position ? this._toVector3(t.position) : p.Zero();
|
|
3343
3350
|
switch (t.type) {
|
|
3344
3351
|
case "hemispheric": {
|
|
3345
|
-
const o = new J(e,
|
|
3352
|
+
const o = new J(e, s, i);
|
|
3346
3353
|
t.groundColor && (o.groundColor = this._toColor3(t.groundColor)), this._applyLightConfig(o, t);
|
|
3347
3354
|
break;
|
|
3348
3355
|
}
|
|
3349
3356
|
case "directional": {
|
|
3350
|
-
const o = new X(e,
|
|
3357
|
+
const o = new X(e, s, i);
|
|
3351
3358
|
this._applyLightConfig(o, t);
|
|
3352
3359
|
break;
|
|
3353
3360
|
}
|
|
3354
3361
|
case "point": {
|
|
3355
|
-
const o = new Q(e, n,
|
|
3362
|
+
const o = new Q(e, n, i);
|
|
3356
3363
|
this._applyLightConfig(o, t);
|
|
3357
3364
|
break;
|
|
3358
3365
|
}
|
|
@@ -3360,10 +3367,10 @@ class Je extends Ye {
|
|
|
3360
3367
|
const o = new ee(
|
|
3361
3368
|
e,
|
|
3362
3369
|
n,
|
|
3363
|
-
|
|
3370
|
+
s,
|
|
3364
3371
|
t.angle ?? Math.PI / 3,
|
|
3365
3372
|
t.exponent ?? 2,
|
|
3366
|
-
|
|
3373
|
+
i
|
|
3367
3374
|
);
|
|
3368
3375
|
this._applyLightConfig(o, t);
|
|
3369
3376
|
break;
|
|
@@ -3388,21 +3395,21 @@ class Je extends Ye {
|
|
|
3388
3395
|
*/
|
|
3389
3396
|
async _enablePhysics(e) {
|
|
3390
3397
|
const t = this._config.physics;
|
|
3391
|
-
let
|
|
3392
|
-
typeof t == "object" && t.gravity && (
|
|
3398
|
+
let i = new p(0, -9.81, 0);
|
|
3399
|
+
typeof t == "object" && t.gravity && (i = new p(
|
|
3393
3400
|
t.gravity.x,
|
|
3394
3401
|
t.gravity.y,
|
|
3395
3402
|
t.gravity.z
|
|
3396
|
-
)), this._log.debug(`Enabling physics with gravity: ${
|
|
3403
|
+
)), this._log.debug(`Enabling physics with gravity: ${i.toString()}`), await this.gameEngine.engines.sceneEngine.enablePhysics(e, i);
|
|
3397
3404
|
}
|
|
3398
3405
|
/**
|
|
3399
3406
|
* Walk all transform nodes and meshes, normalizing glTF metadata and dispatching to property handlers.
|
|
3400
3407
|
*/
|
|
3401
3408
|
async _processNodeProperties(e) {
|
|
3402
3409
|
const t = e.transformNodes.concat(e.meshes);
|
|
3403
|
-
for (const
|
|
3404
|
-
const
|
|
3405
|
-
|
|
3410
|
+
for (const i of t) {
|
|
3411
|
+
const s = this._getNormalizedMetadata(i);
|
|
3412
|
+
s && Object.keys(s).length > 0 && (i.metadata = { ...i.metadata, ...s }, await this._processNodeMetadata(i));
|
|
3406
3413
|
}
|
|
3407
3414
|
this._log.debug(
|
|
3408
3415
|
`Processed ${t.length} nodes, found ${this._spawnPoints.length} spawn points and ${this._entityNodes.length} entity nodes`
|
|
@@ -3434,14 +3441,14 @@ class Je extends Ye {
|
|
|
3434
3441
|
type: e.metadata.entity,
|
|
3435
3442
|
node: e
|
|
3436
3443
|
});
|
|
3437
|
-
for (const [t,
|
|
3444
|
+
for (const [t, i] of this.propertyHandlers)
|
|
3438
3445
|
if (t in e.metadata)
|
|
3439
3446
|
try {
|
|
3440
|
-
await
|
|
3441
|
-
} catch (
|
|
3447
|
+
await i(e, e.metadata[t], this, this.gameEngine);
|
|
3448
|
+
} catch (s) {
|
|
3442
3449
|
this._log.error(
|
|
3443
3450
|
`Error in property handler '${t}' for node '${e.name}':`,
|
|
3444
|
-
|
|
3451
|
+
s
|
|
3445
3452
|
);
|
|
3446
3453
|
}
|
|
3447
3454
|
}
|
|
@@ -3459,23 +3466,23 @@ class Je extends Ye {
|
|
|
3459
3466
|
*/
|
|
3460
3467
|
async _processSpawnPoint(e, t) {
|
|
3461
3468
|
try {
|
|
3462
|
-
const
|
|
3463
|
-
this._spawnedEntities.push(
|
|
3464
|
-
} catch (
|
|
3465
|
-
this._log.error(`Failed to spawn entity at spawn point '${e.name}':`,
|
|
3469
|
+
const i = await this._spawnEntity(t, e);
|
|
3470
|
+
this._spawnedEntities.push(i), e.node.dispose(), this._log.debug(`Spawned entity '${t.entity}' at spawn point '${e.name}'`);
|
|
3471
|
+
} catch (i) {
|
|
3472
|
+
this._log.error(`Failed to spawn entity at spawn point '${e.name}':`, i);
|
|
3466
3473
|
}
|
|
3467
3474
|
}
|
|
3468
3475
|
/**
|
|
3469
3476
|
* Create an entity from a spawn definition, inheriting position/rotation/scaling from the spawn point.
|
|
3470
3477
|
*/
|
|
3471
3478
|
async _spawnEntity(e, t) {
|
|
3472
|
-
const
|
|
3479
|
+
const i = {
|
|
3473
3480
|
...e.config,
|
|
3474
3481
|
position: this._vectorToObject(t.position),
|
|
3475
3482
|
rotation: this._vectorToObject(t.rotation),
|
|
3476
3483
|
scaling: this._vectorToObject(t.scaling)
|
|
3477
|
-
},
|
|
3478
|
-
return await this._createEntityMesh(
|
|
3484
|
+
}, s = await this.gameEngine.managers.entityManager.createEntity(e.entity, { initialState: i });
|
|
3485
|
+
return await this._createEntityMesh(s, t), s;
|
|
3479
3486
|
}
|
|
3480
3487
|
/**
|
|
3481
3488
|
* Converts a Vector3 to a plain `{ x, y, z }` object for serialization into entity state.
|
|
@@ -3490,43 +3497,43 @@ class Je extends Ye {
|
|
|
3490
3497
|
async _createEntityMesh(e, t) {
|
|
3491
3498
|
if (!this._scene)
|
|
3492
3499
|
return;
|
|
3493
|
-
const
|
|
3494
|
-
if (!
|
|
3500
|
+
const i = this.gameEngine.managers.entityManager.getDefinition(e.type);
|
|
3501
|
+
if (!i?.mesh)
|
|
3495
3502
|
return;
|
|
3496
|
-
const
|
|
3503
|
+
const s = i.mesh, n = this._scene, o = new be(`entity-${e.id}`, n);
|
|
3497
3504
|
o.position.copyFrom(t.position), o.rotation.copyFrom(t.rotation);
|
|
3498
3505
|
let a;
|
|
3499
|
-
switch (
|
|
3506
|
+
switch (s.source) {
|
|
3500
3507
|
case "box":
|
|
3501
3508
|
a = [y.CreateBox(`${e.type}-mesh`, {
|
|
3502
|
-
size:
|
|
3503
|
-
width:
|
|
3504
|
-
height:
|
|
3505
|
-
depth:
|
|
3509
|
+
size: s.params?.size ?? 1,
|
|
3510
|
+
width: s.params?.width,
|
|
3511
|
+
height: s.params?.height,
|
|
3512
|
+
depth: s.params?.depth
|
|
3506
3513
|
}, n)];
|
|
3507
3514
|
break;
|
|
3508
3515
|
case "sphere":
|
|
3509
3516
|
a = [y.CreateSphere(`${e.type}-mesh`, {
|
|
3510
|
-
diameter:
|
|
3511
|
-
segments:
|
|
3517
|
+
diameter: s.params?.diameter ?? 1,
|
|
3518
|
+
segments: s.params?.segments ?? 16
|
|
3512
3519
|
}, n)];
|
|
3513
3520
|
break;
|
|
3514
3521
|
case "capsule":
|
|
3515
3522
|
a = [y.CreateCapsule(`${e.type}-mesh`, {
|
|
3516
|
-
height:
|
|
3517
|
-
radius:
|
|
3523
|
+
height: s.params?.height ?? 1.8,
|
|
3524
|
+
radius: s.params?.radius ?? 0.4
|
|
3518
3525
|
}, n)];
|
|
3519
3526
|
break;
|
|
3520
3527
|
case "cylinder":
|
|
3521
3528
|
a = [y.CreateCylinder(`${e.type}-mesh`, {
|
|
3522
|
-
height:
|
|
3523
|
-
diameter:
|
|
3529
|
+
height: s.params?.height ?? 1,
|
|
3530
|
+
diameter: s.params?.diameter ?? 1
|
|
3524
3531
|
}, n)];
|
|
3525
3532
|
break;
|
|
3526
3533
|
default: {
|
|
3527
|
-
const h = await this.gameEngine.engines.sceneEngine.importMeshes([],
|
|
3534
|
+
const h = await this.gameEngine.engines.sceneEngine.importMeshes([], s.source, n);
|
|
3528
3535
|
if (h.meshes.length === 0) {
|
|
3529
|
-
this._log.warn(`No meshes loaded from: ${
|
|
3536
|
+
this._log.warn(`No meshes loaded from: ${s.source}`), o.dispose();
|
|
3530
3537
|
return;
|
|
3531
3538
|
}
|
|
3532
3539
|
a = h.meshes;
|
|
@@ -3537,8 +3544,8 @@ class Je extends Ye {
|
|
|
3537
3544
|
}
|
|
3538
3545
|
for (const h of a)
|
|
3539
3546
|
h.parent || (h.parent = o);
|
|
3540
|
-
|
|
3541
|
-
const l =
|
|
3547
|
+
s.scale && (typeof s.scale == "number" ? o.scaling.setAll(s.scale) : o.scaling.set(s.scale.x, s.scale.y, s.scale.z));
|
|
3548
|
+
const l = s.material;
|
|
3542
3549
|
if (l?.color) {
|
|
3543
3550
|
const h = l.color;
|
|
3544
3551
|
if (l.type === "pbr") {
|
|
@@ -3568,17 +3575,17 @@ class Je extends Ye {
|
|
|
3568
3575
|
async _processEntityNode(e) {
|
|
3569
3576
|
const t = this._config.entities?.[e.type];
|
|
3570
3577
|
try {
|
|
3571
|
-
const
|
|
3578
|
+
const i = {
|
|
3572
3579
|
...t?.config,
|
|
3573
3580
|
position: this._vectorToObject(e.node.position)
|
|
3574
|
-
},
|
|
3581
|
+
}, s = await this.gameEngine.managers.entityManager.createEntity(e.type, {
|
|
3575
3582
|
name: e.node.name,
|
|
3576
|
-
initialState:
|
|
3583
|
+
initialState: i,
|
|
3577
3584
|
node: e.node
|
|
3578
3585
|
});
|
|
3579
|
-
this._spawnedEntities.push(
|
|
3580
|
-
} catch (
|
|
3581
|
-
this._log.error(`Failed to create entity for node '${e.node.name}':`,
|
|
3586
|
+
this._spawnedEntities.push(s), this._log.debug(`Created entity '${e.type}' for node '${e.node.name}'`);
|
|
3587
|
+
} catch (i) {
|
|
3588
|
+
this._log.error(`Failed to create entity for node '${e.node.name}':`, i);
|
|
3582
3589
|
}
|
|
3583
3590
|
}
|
|
3584
3591
|
//------------------------------------------------------------------------------------------------------------------
|
|
@@ -3597,15 +3604,15 @@ class Je extends Ye {
|
|
|
3597
3604
|
this._log.warn("No AudioManager configured. Level sounds will not be created.");
|
|
3598
3605
|
return;
|
|
3599
3606
|
}
|
|
3600
|
-
for (const [
|
|
3607
|
+
for (const [i, s] of Object.entries(e))
|
|
3601
3608
|
try {
|
|
3602
|
-
const n = await t.createSound(
|
|
3603
|
-
loop:
|
|
3604
|
-
volume:
|
|
3609
|
+
const n = await t.createSound(i, s.url, s.channel, {
|
|
3610
|
+
loop: s.loop ?? !1,
|
|
3611
|
+
volume: s.volume ?? 1
|
|
3605
3612
|
});
|
|
3606
|
-
this._levelSounds.set(
|
|
3613
|
+
this._levelSounds.set(i, n), s.autoplay && n.play(), this._log.debug(`Created level sound: "${i}"`);
|
|
3607
3614
|
} catch (n) {
|
|
3608
|
-
this._log.error(`Failed to create level sound "${
|
|
3615
|
+
this._log.error(`Failed to create level sound "${i}":`, n);
|
|
3609
3616
|
}
|
|
3610
3617
|
}
|
|
3611
3618
|
//------------------------------------------------------------------------------------------------------------------
|
|
@@ -3617,7 +3624,7 @@ class Je extends Ye {
|
|
|
3617
3624
|
*/
|
|
3618
3625
|
async onDeactivate() {
|
|
3619
3626
|
for (const [e, t] of this._levelSounds)
|
|
3620
|
-
t.state ===
|
|
3627
|
+
t.state === ie.Started && (this._playingSoundsBeforeDeactivate.add(e), t.pause());
|
|
3621
3628
|
}
|
|
3622
3629
|
/**
|
|
3623
3630
|
* Resume previously playing level sounds when the level is reactivated.
|
|
@@ -3637,16 +3644,16 @@ class Je extends Ye {
|
|
|
3637
3644
|
* Dispose of this level's resources
|
|
3638
3645
|
*/
|
|
3639
3646
|
async $dispose() {
|
|
3640
|
-
const { entityManager: e } = this.gameEngine.managers, t = this._spawnedEntities.map(async (
|
|
3647
|
+
const { entityManager: e } = this.gameEngine.managers, t = this._spawnedEntities.map(async (i) => {
|
|
3641
3648
|
try {
|
|
3642
|
-
await e.destroyEntity(
|
|
3643
|
-
} catch (
|
|
3644
|
-
this._log.error(`Failed to destroy entity ${
|
|
3649
|
+
await e.destroyEntity(i.id);
|
|
3650
|
+
} catch (s) {
|
|
3651
|
+
this._log.error(`Failed to destroy entity ${i.id}:`, s);
|
|
3645
3652
|
}
|
|
3646
3653
|
});
|
|
3647
3654
|
await Promise.all(t), this._spawnedEntities = [], this._spawnPoints = [], this._entityNodes = [];
|
|
3648
|
-
for (const
|
|
3649
|
-
|
|
3655
|
+
for (const i of this._levelSounds.values())
|
|
3656
|
+
i.dispose();
|
|
3650
3657
|
this._levelSounds.clear(), this._playingSoundsBeforeDeactivate.clear(), await super.$dispose();
|
|
3651
3658
|
}
|
|
3652
3659
|
}
|
|
@@ -3683,16 +3690,16 @@ class Xe {
|
|
|
3683
3690
|
//------------------------------------------------------------------------------------------------------------------
|
|
3684
3691
|
constructor(e, t) {
|
|
3685
3692
|
this._eventBus = e, this._logger = t, this._log = t?.getLogger("LevelManager") || new u("LevelManager"), this._eventUnsubscribers.push(
|
|
3686
|
-
this._eventBus.subscribe("level:progress", (
|
|
3687
|
-
this._handleProgress(
|
|
3693
|
+
this._eventBus.subscribe("level:progress", (i) => {
|
|
3694
|
+
this._handleProgress(i.payload);
|
|
3688
3695
|
})
|
|
3689
3696
|
), this._eventUnsubscribers.push(
|
|
3690
|
-
this._eventBus.subscribe("level:complete", (
|
|
3691
|
-
this._handleComplete(
|
|
3697
|
+
this._eventBus.subscribe("level:complete", (i) => {
|
|
3698
|
+
this._handleComplete(i.payload);
|
|
3692
3699
|
})
|
|
3693
3700
|
), this._eventUnsubscribers.push(
|
|
3694
|
-
this._eventBus.subscribe("level:error", (
|
|
3695
|
-
this._handleError(
|
|
3701
|
+
this._eventBus.subscribe("level:error", (i) => {
|
|
3702
|
+
this._handleError(i.payload);
|
|
3696
3703
|
})
|
|
3697
3704
|
), this._log.info("LevelManager initialized");
|
|
3698
3705
|
}
|
|
@@ -3736,10 +3743,10 @@ class Xe {
|
|
|
3736
3743
|
_createLevelInstance(e) {
|
|
3737
3744
|
const t = this._createContext();
|
|
3738
3745
|
if (e.class) {
|
|
3739
|
-
const
|
|
3740
|
-
if (!
|
|
3746
|
+
const i = this._levelClasses.get(e.class);
|
|
3747
|
+
if (!i)
|
|
3741
3748
|
throw new Error(`Level class '${e.class}' is not registered.`);
|
|
3742
|
-
return this._log.debug(`Creating level '${e.name}' using class '${e.class}'`), new
|
|
3749
|
+
return this._log.debug(`Creating level '${e.name}' using class '${e.class}'`), new i(e, t);
|
|
3743
3750
|
}
|
|
3744
3751
|
return this._log.debug(`Creating level '${e.name}' using GameLevel`), new Je(e, t);
|
|
3745
3752
|
}
|
|
@@ -3829,12 +3836,12 @@ class Xe {
|
|
|
3829
3836
|
t = n;
|
|
3830
3837
|
} else
|
|
3831
3838
|
t = e, this.registerLevelConfig(t);
|
|
3832
|
-
const
|
|
3833
|
-
if (
|
|
3834
|
-
return this._log.warn(`Level '${t.name}' is already loaded`),
|
|
3839
|
+
const i = this._loadedLevels.get(t.name);
|
|
3840
|
+
if (i)
|
|
3841
|
+
return this._log.warn(`Level '${t.name}' is already loaded`), i;
|
|
3835
3842
|
this._log.debug(`Loading level: ${t.name}`);
|
|
3836
|
-
const
|
|
3837
|
-
return await
|
|
3843
|
+
const s = this._createLevelInstance(t);
|
|
3844
|
+
return await s.load(), this._loadedLevels.set(t.name, s), s;
|
|
3838
3845
|
}
|
|
3839
3846
|
/**
|
|
3840
3847
|
* Activates a level, loading it if necessary.
|
|
@@ -3875,37 +3882,37 @@ class Xe {
|
|
|
3875
3882
|
* @param options
|
|
3876
3883
|
*/
|
|
3877
3884
|
async transition(e, t) {
|
|
3878
|
-
const
|
|
3885
|
+
const i = this._currentLevel;
|
|
3879
3886
|
try {
|
|
3880
3887
|
this._eventBus.publish({
|
|
3881
3888
|
type: "level:transition:start",
|
|
3882
3889
|
payload: {
|
|
3883
|
-
from:
|
|
3890
|
+
from: i?.name,
|
|
3884
3891
|
to: e
|
|
3885
3892
|
}
|
|
3886
|
-
}),
|
|
3893
|
+
}), i?.onDeactivate && await i.onDeactivate(), this._eventBus.publish({
|
|
3887
3894
|
type: "level:transition:progress",
|
|
3888
3895
|
payload: {
|
|
3889
3896
|
stage: "loading",
|
|
3890
3897
|
levelName: e
|
|
3891
3898
|
}
|
|
3892
3899
|
});
|
|
3893
|
-
const
|
|
3900
|
+
const s = await this.loadLevel(e);
|
|
3894
3901
|
if (t?.preloadOnly)
|
|
3895
3902
|
return;
|
|
3896
|
-
|
|
3903
|
+
i && !t?.keepAlive && await this.unloadLevel(i.name), this._currentLevel = s, s.onActivate && await s.onActivate(), this._eventBus.publish({
|
|
3897
3904
|
type: "level:transition:complete",
|
|
3898
3905
|
payload: { levelName: e }
|
|
3899
3906
|
});
|
|
3900
|
-
} catch (
|
|
3907
|
+
} catch (s) {
|
|
3901
3908
|
throw this._eventBus.publish({
|
|
3902
3909
|
type: "level:transition:error",
|
|
3903
3910
|
payload: {
|
|
3904
|
-
from:
|
|
3911
|
+
from: i?.name,
|
|
3905
3912
|
to: e,
|
|
3906
|
-
error:
|
|
3913
|
+
error: s
|
|
3907
3914
|
}
|
|
3908
|
-
}),
|
|
3915
|
+
}), s;
|
|
3909
3916
|
}
|
|
3910
3917
|
}
|
|
3911
3918
|
//------------------------------------------------------------------------------------------------------------------
|
|
@@ -3938,8 +3945,8 @@ class Qe {
|
|
|
3938
3945
|
async initialize(e) {
|
|
3939
3946
|
this._log.info(`Initializing audio channels: ${e.join(", ")}`);
|
|
3940
3947
|
for (const t of e) {
|
|
3941
|
-
const
|
|
3942
|
-
this._channels.set(t, { bus:
|
|
3948
|
+
const i = await this._audioEngine.createBus(t);
|
|
3949
|
+
this._channels.set(t, { bus: i, volume: 1, muted: !1 });
|
|
3943
3950
|
}
|
|
3944
3951
|
this._log.info("Audio channels initialized.");
|
|
3945
3952
|
}
|
|
@@ -3952,13 +3959,13 @@ class Qe {
|
|
|
3952
3959
|
//------------------------------------------------------------------------------------------------------------------
|
|
3953
3960
|
// Sound Creation
|
|
3954
3961
|
//------------------------------------------------------------------------------------------------------------------
|
|
3955
|
-
async createSound(e, t,
|
|
3962
|
+
async createSound(e, t, i, s) {
|
|
3956
3963
|
let n;
|
|
3957
|
-
if (
|
|
3958
|
-
const o = this._channels.get(
|
|
3959
|
-
o ? n = o.bus : this._log.warn(`Unknown audio channel "${
|
|
3964
|
+
if (i) {
|
|
3965
|
+
const o = this._channels.get(i);
|
|
3966
|
+
o ? n = o.bus : this._log.warn(`Unknown audio channel "${i}", sound "${e}" will use default bus.`);
|
|
3960
3967
|
}
|
|
3961
|
-
return this._audioEngine.createSound(e, t, n,
|
|
3968
|
+
return this._audioEngine.createSound(e, t, n, s);
|
|
3962
3969
|
}
|
|
3963
3970
|
//------------------------------------------------------------------------------------------------------------------
|
|
3964
3971
|
// Master Volume
|
|
@@ -3979,23 +3986,23 @@ class Qe {
|
|
|
3979
3986
|
// Channel Volume
|
|
3980
3987
|
//------------------------------------------------------------------------------------------------------------------
|
|
3981
3988
|
setChannelVolume(e, t) {
|
|
3982
|
-
const
|
|
3983
|
-
if (!
|
|
3989
|
+
const i = this._channels.get(e);
|
|
3990
|
+
if (!i) {
|
|
3984
3991
|
this._log.warn(`Unknown audio channel: ${e}`);
|
|
3985
3992
|
return;
|
|
3986
3993
|
}
|
|
3987
|
-
|
|
3994
|
+
i.volume = t, i.muted || this._audioEngine.setBusVolume(i.bus, t);
|
|
3988
3995
|
}
|
|
3989
3996
|
getChannelVolume(e) {
|
|
3990
3997
|
return this._channels.get(e)?.volume ?? 1;
|
|
3991
3998
|
}
|
|
3992
3999
|
setChannelMuted(e, t) {
|
|
3993
|
-
const
|
|
3994
|
-
if (!
|
|
4000
|
+
const i = this._channels.get(e);
|
|
4001
|
+
if (!i) {
|
|
3995
4002
|
this._log.warn(`Unknown audio channel: ${e}`);
|
|
3996
4003
|
return;
|
|
3997
4004
|
}
|
|
3998
|
-
t !==
|
|
4005
|
+
t !== i.muted && (i.muted = t, this._audioEngine.setBusVolume(i.bus, t ? 0 : i.volume));
|
|
3999
4006
|
}
|
|
4000
4007
|
isChannelMuted(e) {
|
|
4001
4008
|
return this._channels.get(e)?.muted ?? !1;
|
|
@@ -4010,8 +4017,8 @@ class et {
|
|
|
4010
4017
|
_log;
|
|
4011
4018
|
_beforeSerializeHooks = [];
|
|
4012
4019
|
_afterDeserializeHooks = [];
|
|
4013
|
-
constructor(e, t,
|
|
4014
|
-
this._entityManager = e, this._levelManager = t, this._log =
|
|
4020
|
+
constructor(e, t, i) {
|
|
4021
|
+
this._entityManager = e, this._levelManager = t, this._log = i?.getLogger("SaveManager") || new u("SaveManager"), this._log.info("SaveManager initialized");
|
|
4015
4022
|
}
|
|
4016
4023
|
//------------------------------------------------------------------------------------------------------------------
|
|
4017
4024
|
// Hook Registration
|
|
@@ -4058,18 +4065,18 @@ class et {
|
|
|
4058
4065
|
}
|
|
4059
4066
|
t.push(o);
|
|
4060
4067
|
}
|
|
4061
|
-
let
|
|
4068
|
+
let i = {};
|
|
4062
4069
|
for (const n of this._beforeSerializeHooks) {
|
|
4063
4070
|
const o = n();
|
|
4064
|
-
|
|
4071
|
+
i = { ...i, ...o };
|
|
4065
4072
|
}
|
|
4066
|
-
const
|
|
4073
|
+
const s = {
|
|
4067
4074
|
version: 1,
|
|
4068
4075
|
levelName: e,
|
|
4069
4076
|
entities: t,
|
|
4070
|
-
custom:
|
|
4077
|
+
custom: i
|
|
4071
4078
|
};
|
|
4072
|
-
return this._log.info(`Serialized ${t.length} entities from level "${e}"`),
|
|
4079
|
+
return this._log.info(`Serialized ${t.length} entities from level "${e}"`), s;
|
|
4073
4080
|
}
|
|
4074
4081
|
//------------------------------------------------------------------------------------------------------------------
|
|
4075
4082
|
// Deserialize
|
|
@@ -4088,31 +4095,31 @@ class et {
|
|
|
4088
4095
|
async deserialize(e) {
|
|
4089
4096
|
this._log.debug(`Deserializing save data (version ${e.version}, level "${e.levelName}")...`), await this._levelManager.transition(e.levelName);
|
|
4090
4097
|
const t = [];
|
|
4091
|
-
for (const
|
|
4092
|
-
t.push(
|
|
4093
|
-
for (const
|
|
4094
|
-
await this._entityManager.destroyEntity(
|
|
4095
|
-
const
|
|
4096
|
-
for (const
|
|
4097
|
-
const n = await this._entityManager.createEntity(
|
|
4098
|
-
name:
|
|
4099
|
-
initialState:
|
|
4100
|
-
tags:
|
|
4098
|
+
for (const s of this._entityManager.getAllEntities())
|
|
4099
|
+
t.push(s.id);
|
|
4100
|
+
for (const s of t)
|
|
4101
|
+
await this._entityManager.destroyEntity(s);
|
|
4102
|
+
const i = /* @__PURE__ */ new Map();
|
|
4103
|
+
for (const s of e.entities) {
|
|
4104
|
+
const n = await this._entityManager.createEntity(s.type, {
|
|
4105
|
+
name: s.name,
|
|
4106
|
+
initialState: s.state,
|
|
4107
|
+
tags: s.tags
|
|
4101
4108
|
});
|
|
4102
|
-
if (
|
|
4103
|
-
const { position: o, rotation: a, scaling: l } =
|
|
4109
|
+
if (i.set(s.id, n.id), s.transform && n.node) {
|
|
4110
|
+
const { position: o, rotation: a, scaling: l } = s.transform;
|
|
4104
4111
|
n.node.position.x = o.x, n.node.position.y = o.y, n.node.position.z = o.z, n.node.rotation.x = a.x, n.node.rotation.y = a.y, n.node.rotation.z = a.z, n.node.scaling.x = l.x, n.node.scaling.y = l.y, n.node.scaling.z = l.z;
|
|
4105
4112
|
}
|
|
4106
4113
|
}
|
|
4107
|
-
for (const
|
|
4108
|
-
if (
|
|
4109
|
-
const n =
|
|
4114
|
+
for (const s of e.entities)
|
|
4115
|
+
if (s.parentId) {
|
|
4116
|
+
const n = i.get(s.parentId), o = i.get(s.id);
|
|
4110
4117
|
n && o ? this._entityManager.addChild(n, o) : this._log.warn(
|
|
4111
|
-
`Could not restore parent-child: ${
|
|
4118
|
+
`Could not restore parent-child: ${s.id} -> ${s.parentId} (mapped: ${o} -> ${n})`
|
|
4112
4119
|
);
|
|
4113
4120
|
}
|
|
4114
|
-
for (const
|
|
4115
|
-
|
|
4121
|
+
for (const s of this._afterDeserializeHooks)
|
|
4122
|
+
s(e.custom);
|
|
4116
4123
|
this._log.info(`Deserialized ${e.entities.length} entities for level "${e.levelName}"`);
|
|
4117
4124
|
}
|
|
4118
4125
|
//------------------------------------------------------------------------------------------------------------------
|
|
@@ -4197,13 +4204,13 @@ class tt {
|
|
|
4197
4204
|
this._keysState[e.code] = !0;
|
|
4198
4205
|
const t = {};
|
|
4199
4206
|
t[e.code] = !0;
|
|
4200
|
-
const
|
|
4207
|
+
const i = {
|
|
4201
4208
|
type: "keyboard",
|
|
4202
4209
|
keys: { ...this._keysState },
|
|
4203
4210
|
delta: t,
|
|
4204
4211
|
event: e
|
|
4205
4212
|
};
|
|
4206
|
-
this._notifyInputChanged(
|
|
4213
|
+
this._notifyInputChanged(i);
|
|
4207
4214
|
}
|
|
4208
4215
|
/**
|
|
4209
4216
|
* Handle keyboard key up events
|
|
@@ -4212,13 +4219,13 @@ class tt {
|
|
|
4212
4219
|
this._keysState[e.code] = !1;
|
|
4213
4220
|
const t = {};
|
|
4214
4221
|
t[e.code] = !1;
|
|
4215
|
-
const
|
|
4222
|
+
const i = {
|
|
4216
4223
|
type: "keyboard",
|
|
4217
4224
|
keys: { ...this._keysState },
|
|
4218
4225
|
delta: t,
|
|
4219
4226
|
event: e
|
|
4220
4227
|
};
|
|
4221
|
-
this._notifyInputChanged(
|
|
4228
|
+
this._notifyInputChanged(i);
|
|
4222
4229
|
}
|
|
4223
4230
|
/**
|
|
4224
4231
|
* Notify subscribers of device connected event
|
|
@@ -4233,7 +4240,7 @@ class tt {
|
|
|
4233
4240
|
this._onInputChanged && this._onInputChanged(this._keyboardDevice, e);
|
|
4234
4241
|
}
|
|
4235
4242
|
}
|
|
4236
|
-
class
|
|
4243
|
+
class it {
|
|
4237
4244
|
_targetElement;
|
|
4238
4245
|
_mouseDevice;
|
|
4239
4246
|
_buttonState = {};
|
|
@@ -4324,10 +4331,10 @@ class st {
|
|
|
4324
4331
|
* Handle mouse button down events
|
|
4325
4332
|
*/
|
|
4326
4333
|
_handleMouseDown(e) {
|
|
4327
|
-
const t = `button-${e.button}`,
|
|
4334
|
+
const t = `button-${e.button}`, i = {
|
|
4328
4335
|
pressed: !0
|
|
4329
4336
|
};
|
|
4330
|
-
this._buttonState[t] =
|
|
4337
|
+
this._buttonState[t] = i, this._notifyInputChanged({
|
|
4331
4338
|
type: "mouse",
|
|
4332
4339
|
event: e,
|
|
4333
4340
|
buttons: { ...this._buttonState },
|
|
@@ -4339,10 +4346,10 @@ class st {
|
|
|
4339
4346
|
* Handle mouse button up events
|
|
4340
4347
|
*/
|
|
4341
4348
|
_handleMouseUp(e) {
|
|
4342
|
-
const t = `button-${e.button}`,
|
|
4349
|
+
const t = `button-${e.button}`, i = {
|
|
4343
4350
|
pressed: !1
|
|
4344
4351
|
};
|
|
4345
|
-
this._buttonState[t] =
|
|
4352
|
+
this._buttonState[t] = i, this._notifyInputChanged({
|
|
4346
4353
|
type: "mouse",
|
|
4347
4354
|
event: e,
|
|
4348
4355
|
buttons: { ...this._buttonState },
|
|
@@ -4402,7 +4409,7 @@ class st {
|
|
|
4402
4409
|
this._onInputChanged && this._onInputChanged(this._mouseDevice, e);
|
|
4403
4410
|
}
|
|
4404
4411
|
}
|
|
4405
|
-
class
|
|
4412
|
+
class st {
|
|
4406
4413
|
_gamepadDevices = {};
|
|
4407
4414
|
_buttonStates = {};
|
|
4408
4415
|
_axesStates = {};
|
|
@@ -4456,10 +4463,10 @@ class it {
|
|
|
4456
4463
|
getStates() {
|
|
4457
4464
|
const e = {};
|
|
4458
4465
|
return Object.keys(this._buttonStates).forEach((t) => {
|
|
4459
|
-
const
|
|
4460
|
-
e[
|
|
4466
|
+
const i = Number(t), s = this._buttonStates[i] || {}, n = this._axesStates[i] || {};
|
|
4467
|
+
e[i] = {
|
|
4461
4468
|
type: "gamepad",
|
|
4462
|
-
buttons: { ...
|
|
4469
|
+
buttons: { ...s },
|
|
4463
4470
|
axes: { ...n }
|
|
4464
4471
|
};
|
|
4465
4472
|
}), e;
|
|
@@ -4479,11 +4486,11 @@ class it {
|
|
|
4479
4486
|
* @param index
|
|
4480
4487
|
*/
|
|
4481
4488
|
getState(e) {
|
|
4482
|
-
const t = this._buttonStates[e],
|
|
4483
|
-
return !t && !
|
|
4489
|
+
const t = this._buttonStates[e], i = this._axesStates[e];
|
|
4490
|
+
return !t && !i ? null : {
|
|
4484
4491
|
type: "gamepad",
|
|
4485
4492
|
buttons: t ? { ...t } : {},
|
|
4486
|
-
axes:
|
|
4493
|
+
axes: i ? { ...i } : {}
|
|
4487
4494
|
};
|
|
4488
4495
|
}
|
|
4489
4496
|
/**
|
|
@@ -4496,15 +4503,15 @@ class it {
|
|
|
4496
4503
|
for (const t of e) {
|
|
4497
4504
|
if (!t)
|
|
4498
4505
|
continue;
|
|
4499
|
-
const
|
|
4500
|
-
if (!this._gamepadDevices[
|
|
4506
|
+
const i = t.index;
|
|
4507
|
+
if (!this._gamepadDevices[i]) {
|
|
4501
4508
|
this._handleGamepadConnected(t);
|
|
4502
4509
|
continue;
|
|
4503
4510
|
}
|
|
4504
|
-
const
|
|
4505
|
-
if (!
|
|
4511
|
+
const s = this._gamepadDevices[i];
|
|
4512
|
+
if (!s)
|
|
4506
4513
|
continue;
|
|
4507
|
-
const n = this._buttonStates[
|
|
4514
|
+
const n = this._buttonStates[i] || {}, o = this._axesStates[i] || {}, a = {};
|
|
4508
4515
|
let l = !1;
|
|
4509
4516
|
t.buttons.forEach((d, m) => {
|
|
4510
4517
|
const f = `button-${m}`, g = {
|
|
@@ -4521,13 +4528,13 @@ class it {
|
|
|
4521
4528
|
if (t.axes.forEach((d, m) => {
|
|
4522
4529
|
const f = `axis-${m}`;
|
|
4523
4530
|
h[f] = d, o[f] !== d && (c = !0);
|
|
4524
|
-
}), this._buttonStates[
|
|
4531
|
+
}), this._buttonStates[i] = a, this._axesStates[i] = h, l || c) {
|
|
4525
4532
|
const d = {
|
|
4526
4533
|
type: "gamepad",
|
|
4527
4534
|
buttons: { ...a },
|
|
4528
4535
|
axes: { ...h }
|
|
4529
4536
|
};
|
|
4530
|
-
this._notifyInputChanged(
|
|
4537
|
+
this._notifyInputChanged(s, d);
|
|
4531
4538
|
}
|
|
4532
4539
|
}
|
|
4533
4540
|
}
|
|
@@ -4554,17 +4561,17 @@ class it {
|
|
|
4554
4561
|
* Handle gamepad connected event
|
|
4555
4562
|
*/
|
|
4556
4563
|
_handleGamepadConnected(e) {
|
|
4557
|
-
const t = e instanceof GamepadEvent ? e.gamepad : e,
|
|
4558
|
-
id: `gamepad-${
|
|
4564
|
+
const t = e instanceof GamepadEvent ? e.gamepad : e, i = t.index, s = {
|
|
4565
|
+
id: `gamepad-${i}`,
|
|
4559
4566
|
name: t.id,
|
|
4560
4567
|
type: "gamepad",
|
|
4561
4568
|
connected: !0,
|
|
4562
|
-
index:
|
|
4569
|
+
index: i,
|
|
4563
4570
|
mapping: t.mapping,
|
|
4564
4571
|
axes: Array.from(t.axes),
|
|
4565
4572
|
buttons: Array.from(t.buttons)
|
|
4566
4573
|
};
|
|
4567
|
-
this._gamepadDevices[
|
|
4574
|
+
this._gamepadDevices[i] = s;
|
|
4568
4575
|
const n = {};
|
|
4569
4576
|
Array.from(t.buttons).forEach((a, l) => {
|
|
4570
4577
|
n[`button-${l}`] = {
|
|
@@ -4572,11 +4579,11 @@ class it {
|
|
|
4572
4579
|
touched: a.touched,
|
|
4573
4580
|
value: a.value
|
|
4574
4581
|
};
|
|
4575
|
-
}), this._buttonStates[
|
|
4582
|
+
}), this._buttonStates[i] = n;
|
|
4576
4583
|
const o = {};
|
|
4577
4584
|
Array.from(t.axes).forEach((a, l) => {
|
|
4578
4585
|
o[`axis-${l}`] = a;
|
|
4579
|
-
}), this._axesStates[
|
|
4586
|
+
}), this._axesStates[i] = o, this._notifyDeviceConnected(s), this._notifyInputChanged(s, {
|
|
4580
4587
|
type: "gamepad",
|
|
4581
4588
|
buttons: { ...n },
|
|
4582
4589
|
axes: { ...o },
|
|
@@ -4587,8 +4594,8 @@ class it {
|
|
|
4587
4594
|
* Handle gamepad disconnected event
|
|
4588
4595
|
*/
|
|
4589
4596
|
_handleGamepadDisconnected(e) {
|
|
4590
|
-
const
|
|
4591
|
-
|
|
4597
|
+
const i = e.gamepad.index, s = this._gamepadDevices[i];
|
|
4598
|
+
s && (s.connected = !1, this._notifyDeviceDisconnected(s), this._gamepadDevices[i] = void 0, this._buttonStates[i] = void 0, this._axesStates[i] = void 0);
|
|
4592
4599
|
}
|
|
4593
4600
|
/**
|
|
4594
4601
|
* Notify subscribers of device connected event
|
|
@@ -4624,8 +4631,8 @@ class nt {
|
|
|
4624
4631
|
* @param canvas - The DOM element to attach input listeners to (used by mouse input)
|
|
4625
4632
|
* @param logger
|
|
4626
4633
|
*/
|
|
4627
|
-
constructor(e, t,
|
|
4628
|
-
this._eventBus = e, this._log =
|
|
4634
|
+
constructor(e, t, i) {
|
|
4635
|
+
this._eventBus = e, this._log = i?.getLogger("UserInputManager") || new u("UserInputManager"), this._log.info("Initializing UserInputManager"), this._log.debug("Initializing input resource access classes"), this._keyboardRA = new tt(), this._mouseRA = new it(t), this._gamepadRA = new st(), 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");
|
|
4629
4636
|
}
|
|
4630
4637
|
//------------------------------------------------------------------------------------------------------------------
|
|
4631
4638
|
// Private methods
|
|
@@ -4693,10 +4700,10 @@ class nt {
|
|
|
4693
4700
|
if (e.startsWith("mouse-"))
|
|
4694
4701
|
return this._mouseRA.getDevice();
|
|
4695
4702
|
if (e.startsWith("gamepad-")) {
|
|
4696
|
-
const
|
|
4697
|
-
return this._gamepadRA.getDevice(
|
|
4703
|
+
const i = parseInt(e.split("-")[1], 10);
|
|
4704
|
+
return this._gamepadRA.getDevice(i);
|
|
4698
4705
|
}
|
|
4699
|
-
const t = this.listDevices().find((
|
|
4706
|
+
const t = this.listDevices().find((i) => i.id === e);
|
|
4700
4707
|
return t || (this._log.warn(`Device not found: ${e}`), null);
|
|
4701
4708
|
}
|
|
4702
4709
|
/**
|
|
@@ -4724,8 +4731,8 @@ async function at(r, e) {
|
|
|
4724
4731
|
if (K())
|
|
4725
4732
|
try {
|
|
4726
4733
|
return console.debug("Using forced WebGPU engine"), await F(r, e);
|
|
4727
|
-
} catch (
|
|
4728
|
-
throw console.error("Forced WebGPU initialization failed:",
|
|
4734
|
+
} catch (i) {
|
|
4735
|
+
throw console.error("Forced WebGPU initialization failed:", i), new Error(
|
|
4729
4736
|
"Forced WebGPU failed to initialize. If WebGPU is required, check browser compatibility."
|
|
4730
4737
|
);
|
|
4731
4738
|
}
|
|
@@ -4735,9 +4742,9 @@ async function at(r, e) {
|
|
|
4735
4742
|
return console.debug("Using forced WebGL engine"), D(r, e);
|
|
4736
4743
|
if (K())
|
|
4737
4744
|
try {
|
|
4738
|
-
return console.debug("Using WebGPU"), F(r, e).catch((
|
|
4739
|
-
} catch (
|
|
4740
|
-
console.warn("WebGPU initialization failed, falling back to WebGL:",
|
|
4745
|
+
return console.debug("Using WebGPU"), F(r, e).catch((i) => (console.warn("WebGPU initialization failed, falling back to WebGL:", i), D(r, e)));
|
|
4746
|
+
} catch (i) {
|
|
4747
|
+
console.warn("WebGPU initialization failed, falling back to WebGL:", i);
|
|
4741
4748
|
}
|
|
4742
4749
|
else
|
|
4743
4750
|
console.warn("WebGPU not supported, falling back to WebGL.");
|
|
@@ -4757,39 +4764,39 @@ class ht {
|
|
|
4757
4764
|
//------------------------------------------------------------------------------------------------------------------
|
|
4758
4765
|
// Public API
|
|
4759
4766
|
//------------------------------------------------------------------------------------------------------------------
|
|
4760
|
-
pickEntity(e, t,
|
|
4761
|
-
const n = e.pick(t,
|
|
4762
|
-
return this._toEntityResult(n,
|
|
4767
|
+
pickEntity(e, t, i, s) {
|
|
4768
|
+
const n = e.pick(t, i);
|
|
4769
|
+
return this._toEntityResult(n, s);
|
|
4763
4770
|
}
|
|
4764
|
-
pickEntities(e, t,
|
|
4765
|
-
const n = e.multiPick(t,
|
|
4771
|
+
pickEntities(e, t, i, s) {
|
|
4772
|
+
const n = e.multiPick(t, i);
|
|
4766
4773
|
if (!n)
|
|
4767
4774
|
return [];
|
|
4768
4775
|
const o = [];
|
|
4769
4776
|
for (const a of n) {
|
|
4770
|
-
const l = this._toEntityResult(a,
|
|
4777
|
+
const l = this._toEntityResult(a, s);
|
|
4771
4778
|
l && o.push(l);
|
|
4772
4779
|
}
|
|
4773
4780
|
return o;
|
|
4774
4781
|
}
|
|
4775
|
-
pickEntityWithRay(e, t,
|
|
4776
|
-
const
|
|
4777
|
-
return
|
|
4782
|
+
pickEntityWithRay(e, t, i) {
|
|
4783
|
+
const s = e.pickWithRay(t);
|
|
4784
|
+
return s ? this._toEntityResult(s, i) : null;
|
|
4778
4785
|
}
|
|
4779
|
-
pickEntitiesWithRay(e, t,
|
|
4780
|
-
const
|
|
4781
|
-
if (!
|
|
4786
|
+
pickEntitiesWithRay(e, t, i) {
|
|
4787
|
+
const s = e.multiPickWithRay(t);
|
|
4788
|
+
if (!s)
|
|
4782
4789
|
return [];
|
|
4783
4790
|
const n = [];
|
|
4784
|
-
for (const o of
|
|
4785
|
-
const a = this._toEntityResult(o,
|
|
4791
|
+
for (const o of s) {
|
|
4792
|
+
const a = this._toEntityResult(o, i);
|
|
4786
4793
|
a && n.push(a);
|
|
4787
4794
|
}
|
|
4788
4795
|
return n;
|
|
4789
4796
|
}
|
|
4790
|
-
pickEntityForward(e, t,
|
|
4791
|
-
const n = t.getForwardRay(
|
|
4792
|
-
return this.pickEntityWithRay(e, n,
|
|
4797
|
+
pickEntityForward(e, t, i = 1e3, s) {
|
|
4798
|
+
const n = t.getForwardRay(i);
|
|
4799
|
+
return this.pickEntityWithRay(e, n, s);
|
|
4793
4800
|
}
|
|
4794
4801
|
//------------------------------------------------------------------------------------------------------------------
|
|
4795
4802
|
// Private
|
|
@@ -4797,33 +4804,33 @@ class ht {
|
|
|
4797
4804
|
_toEntityResult(e, t) {
|
|
4798
4805
|
if (!e.hit || !e.pickedMesh || !e.pickedPoint)
|
|
4799
4806
|
return null;
|
|
4800
|
-
const
|
|
4801
|
-
let
|
|
4802
|
-
if (!
|
|
4803
|
-
let o =
|
|
4804
|
-
for (; o && (
|
|
4807
|
+
const i = e.pickedMesh;
|
|
4808
|
+
let s = this._entityManager.getByNode(i);
|
|
4809
|
+
if (!s) {
|
|
4810
|
+
let o = i.parent;
|
|
4811
|
+
for (; o && (s = this._entityManager.getByNode(o), !s); )
|
|
4805
4812
|
o = o.parent;
|
|
4806
4813
|
}
|
|
4807
|
-
if (!
|
|
4814
|
+
if (!s)
|
|
4808
4815
|
return null;
|
|
4809
4816
|
if (t) {
|
|
4810
|
-
if (t.type &&
|
|
4817
|
+
if (t.type && s.type !== t.type)
|
|
4811
4818
|
return null;
|
|
4812
4819
|
if (t.tags) {
|
|
4813
4820
|
for (const o of t.tags)
|
|
4814
|
-
if (!
|
|
4821
|
+
if (!s.hasTag(o))
|
|
4815
4822
|
return null;
|
|
4816
4823
|
}
|
|
4817
|
-
if (t.predicate && !t.predicate(
|
|
4824
|
+
if (t.predicate && !t.predicate(s))
|
|
4818
4825
|
return null;
|
|
4819
4826
|
}
|
|
4820
4827
|
const n = e.getNormal(!0, !0);
|
|
4821
4828
|
return {
|
|
4822
|
-
entity:
|
|
4829
|
+
entity: s,
|
|
4823
4830
|
point: e.pickedPoint,
|
|
4824
4831
|
distance: e.distance,
|
|
4825
4832
|
normal: n ?? { x: 0, y: 0, z: 0 },
|
|
4826
|
-
mesh:
|
|
4833
|
+
mesh: i,
|
|
4827
4834
|
pickingInfo: e
|
|
4828
4835
|
};
|
|
4829
4836
|
}
|
|
@@ -4844,9 +4851,9 @@ class ct {
|
|
|
4844
4851
|
delay(e, t) {
|
|
4845
4852
|
if (e < 0)
|
|
4846
4853
|
throw new RangeError(`delay() requires ms >= 0, got ${e}`);
|
|
4847
|
-
const
|
|
4848
|
-
return this._delays.push({ id:
|
|
4849
|
-
this._delays = this._delays.filter((
|
|
4854
|
+
const i = this._nextId++;
|
|
4855
|
+
return this._delays.push({ id: i, remaining: e, callback: t }), () => {
|
|
4856
|
+
this._delays = this._delays.filter((s) => s.id !== i);
|
|
4850
4857
|
};
|
|
4851
4858
|
}
|
|
4852
4859
|
/**
|
|
@@ -4857,22 +4864,22 @@ class ct {
|
|
|
4857
4864
|
interval(e, t) {
|
|
4858
4865
|
if (e <= 0)
|
|
4859
4866
|
throw new RangeError(`interval() requires ms > 0, got ${e}`);
|
|
4860
|
-
const
|
|
4861
|
-
return this._intervals.push({ id:
|
|
4862
|
-
this._intervals = this._intervals.filter((
|
|
4867
|
+
const i = this._nextId++;
|
|
4868
|
+
return this._intervals.push({ id: i, periodMs: e, elapsed: 0, callback: t }), () => {
|
|
4869
|
+
this._intervals = this._intervals.filter((s) => s.id !== i);
|
|
4863
4870
|
};
|
|
4864
4871
|
}
|
|
4865
4872
|
/**
|
|
4866
4873
|
* Pollable cooldown. Starts ready; after calling `reset()`, becomes not-ready until `ms` elapses.
|
|
4867
4874
|
*/
|
|
4868
4875
|
cooldown(e) {
|
|
4869
|
-
const
|
|
4870
|
-
return this._cooldowns.push(
|
|
4876
|
+
const i = { id: this._nextId++, periodMs: e, remaining: 0 };
|
|
4877
|
+
return this._cooldowns.push(i), {
|
|
4871
4878
|
get ready() {
|
|
4872
|
-
return
|
|
4879
|
+
return i.remaining <= 0;
|
|
4873
4880
|
},
|
|
4874
4881
|
reset() {
|
|
4875
|
-
|
|
4882
|
+
i.remaining = i.periodMs;
|
|
4876
4883
|
}
|
|
4877
4884
|
};
|
|
4878
4885
|
}
|
|
@@ -4890,14 +4897,14 @@ class ct {
|
|
|
4890
4897
|
*/
|
|
4891
4898
|
tick(e) {
|
|
4892
4899
|
const t = [];
|
|
4893
|
-
for (const
|
|
4894
|
-
|
|
4895
|
-
t.length > 0 && (this._delays = this._delays.filter((
|
|
4896
|
-
for (const
|
|
4897
|
-
for (
|
|
4898
|
-
|
|
4899
|
-
for (const
|
|
4900
|
-
|
|
4900
|
+
for (const i of this._delays)
|
|
4901
|
+
i.remaining -= e, i.remaining <= 0 && (i.callback(), t.push(i.id));
|
|
4902
|
+
t.length > 0 && (this._delays = this._delays.filter((i) => !t.includes(i.id)));
|
|
4903
|
+
for (const i of this._intervals)
|
|
4904
|
+
for (i.elapsed += e; i.elapsed >= i.periodMs; )
|
|
4905
|
+
i.callback(), i.elapsed -= i.periodMs;
|
|
4906
|
+
for (const i of this._cooldowns)
|
|
4907
|
+
i.remaining > 0 && (i.remaining = Math.max(0, i.remaining - e));
|
|
4901
4908
|
}
|
|
4902
4909
|
}
|
|
4903
4910
|
const xt = [
|
|
@@ -4934,9 +4941,9 @@ class Mt extends ne {
|
|
|
4934
4941
|
}
|
|
4935
4942
|
if (!this.entity)
|
|
4936
4943
|
return;
|
|
4937
|
-
const
|
|
4938
|
-
if (
|
|
4939
|
-
for (const [n, o] of Object.entries(
|
|
4944
|
+
const s = this.entity.state.sounds;
|
|
4945
|
+
if (s)
|
|
4946
|
+
for (const [n, o] of Object.entries(s))
|
|
4940
4947
|
this._createSound(n, o);
|
|
4941
4948
|
}
|
|
4942
4949
|
processEvent(e, t) {
|
|
@@ -4954,9 +4961,9 @@ class Mt extends ne {
|
|
|
4954
4961
|
_createSound(e, t) {
|
|
4955
4962
|
if (!this._audioManager || !this.entity)
|
|
4956
4963
|
return;
|
|
4957
|
-
const
|
|
4964
|
+
const i = this.entity.id, s = this._node;
|
|
4958
4965
|
this._audioManager.createSound(
|
|
4959
|
-
`${
|
|
4966
|
+
`${i}_${e}`,
|
|
4960
4967
|
t.url,
|
|
4961
4968
|
t.channel,
|
|
4962
4969
|
{
|
|
@@ -4968,7 +4975,7 @@ class Mt extends ne {
|
|
|
4968
4975
|
spatialDistanceModel: "linear"
|
|
4969
4976
|
}
|
|
4970
4977
|
).then((n) => {
|
|
4971
|
-
this._sounds.set(e, n), (t.spatial ?? !1) &&
|
|
4978
|
+
this._sounds.set(e, n), (t.spatial ?? !1) && s && n.spatial.attach(s);
|
|
4972
4979
|
}).catch((n) => {
|
|
4973
4980
|
this._log.error(`Failed to create sound "${e}": ${n}`);
|
|
4974
4981
|
});
|
|
@@ -4988,8 +4995,8 @@ class Mt extends ne {
|
|
|
4988
4995
|
* @param time - Optional time offset in seconds to start playing from
|
|
4989
4996
|
*/
|
|
4990
4997
|
play(e, t) {
|
|
4991
|
-
const
|
|
4992
|
-
|
|
4998
|
+
const i = this._getSound(e);
|
|
4999
|
+
i && (t !== void 0 ? i.play({ startOffset: t }) : i.play());
|
|
4993
5000
|
}
|
|
4994
5001
|
/**
|
|
4995
5002
|
* Stop a sound by name.
|
|
@@ -5021,11 +5028,11 @@ class Mt extends ne {
|
|
|
5021
5028
|
*/
|
|
5022
5029
|
setVolume(e, t) {
|
|
5023
5030
|
if (t) {
|
|
5024
|
-
const
|
|
5025
|
-
|
|
5031
|
+
const i = this._sounds.get(t);
|
|
5032
|
+
i && (i.volume = e);
|
|
5026
5033
|
} else
|
|
5027
|
-
for (const
|
|
5028
|
-
|
|
5034
|
+
for (const i of this._sounds.values())
|
|
5035
|
+
i.volume = e;
|
|
5029
5036
|
}
|
|
5030
5037
|
/**
|
|
5031
5038
|
* Check if a sound is currently playing.
|
|
@@ -5033,7 +5040,7 @@ class Mt extends ne {
|
|
|
5033
5040
|
* @param name - The name of the sound. If omitted and only one sound exists, checks that sound.
|
|
5034
5041
|
*/
|
|
5035
5042
|
isPlaying(e) {
|
|
5036
|
-
return this._getSound(e)?.state ===
|
|
5043
|
+
return this._getSound(e)?.state === ie.Started;
|
|
5037
5044
|
}
|
|
5038
5045
|
/**
|
|
5039
5046
|
* Get all registered sound names.
|
|
@@ -5058,8 +5065,8 @@ class Mt extends ne {
|
|
|
5058
5065
|
registerSound(e, t) {
|
|
5059
5066
|
if (!this._initialized || !this._audioManager)
|
|
5060
5067
|
throw new Error("SoundBehavior must be initialized before registering sounds");
|
|
5061
|
-
const
|
|
5062
|
-
|
|
5068
|
+
const i = this._sounds.get(e);
|
|
5069
|
+
i && i.dispose(), this._createSound(e, t);
|
|
5063
5070
|
}
|
|
5064
5071
|
/**
|
|
5065
5072
|
* Unregister and dispose a sound.
|
|
@@ -5105,9 +5112,9 @@ class W {
|
|
|
5105
5112
|
/**
|
|
5106
5113
|
* Register a valid transition from one state to another, with an optional guard function.
|
|
5107
5114
|
*/
|
|
5108
|
-
addTransition(e, t,
|
|
5109
|
-
const
|
|
5110
|
-
this.transitions.set(
|
|
5115
|
+
addTransition(e, t, i) {
|
|
5116
|
+
const s = `${e}->${t}`;
|
|
5117
|
+
this.transitions.set(s, { guard: i });
|
|
5111
5118
|
}
|
|
5112
5119
|
/**
|
|
5113
5120
|
* Register a wildcard transition: allows transitioning to the given state from any state.
|
|
@@ -5119,15 +5126,15 @@ class W {
|
|
|
5119
5126
|
* Register a callback to run when entering a state.
|
|
5120
5127
|
*/
|
|
5121
5128
|
onEnter(e, t) {
|
|
5122
|
-
const
|
|
5123
|
-
|
|
5129
|
+
const i = this.enterCallbacks.get(e) ?? [];
|
|
5130
|
+
i.push(t), this.enterCallbacks.set(e, i);
|
|
5124
5131
|
}
|
|
5125
5132
|
/**
|
|
5126
5133
|
* Register a callback to run when exiting a state.
|
|
5127
5134
|
*/
|
|
5128
5135
|
onExit(e, t) {
|
|
5129
|
-
const
|
|
5130
|
-
|
|
5136
|
+
const i = this.exitCallbacks.get(e) ?? [];
|
|
5137
|
+
i.push(t), this.exitCallbacks.set(e, i);
|
|
5131
5138
|
}
|
|
5132
5139
|
//------------------------------------------------------------------------------------------------------------------
|
|
5133
5140
|
// Queries
|
|
@@ -5150,22 +5157,22 @@ class W {
|
|
|
5150
5157
|
*/
|
|
5151
5158
|
transition(e) {
|
|
5152
5159
|
const t = `${this._currentState}->${e}`;
|
|
5153
|
-
let
|
|
5154
|
-
if (
|
|
5160
|
+
let i = this.transitions.get(t);
|
|
5161
|
+
if (i || (i = this.wildcardTransitions.get(e)), !i)
|
|
5155
5162
|
throw new Error(
|
|
5156
5163
|
`No transition defined from '${this._currentState}' to '${e}'.`
|
|
5157
5164
|
);
|
|
5158
|
-
if (
|
|
5165
|
+
if (i.guard && !i.guard())
|
|
5159
5166
|
throw new Error(
|
|
5160
5167
|
`Guard rejected transition from '${this._currentState}' to '${e}'.`
|
|
5161
5168
|
);
|
|
5162
|
-
const
|
|
5169
|
+
const s = this._currentState, n = this.exitCallbacks.get(s);
|
|
5163
5170
|
if (n)
|
|
5164
5171
|
for (const a of n)
|
|
5165
5172
|
a();
|
|
5166
5173
|
this.eventBus && this.eventBus.publish({
|
|
5167
|
-
type: `state:exit:${
|
|
5168
|
-
payload: { from:
|
|
5174
|
+
type: `state:exit:${s}`,
|
|
5175
|
+
payload: { from: s, to: e }
|
|
5169
5176
|
}), this._currentState = e;
|
|
5170
5177
|
const o = this.enterCallbacks.get(e);
|
|
5171
5178
|
if (o)
|
|
@@ -5173,7 +5180,7 @@ class W {
|
|
|
5173
5180
|
a();
|
|
5174
5181
|
this.eventBus && this.eventBus.publish({
|
|
5175
5182
|
type: `state:enter:${e}`,
|
|
5176
|
-
payload: { from:
|
|
5183
|
+
payload: { from: s, to: e }
|
|
5177
5184
|
});
|
|
5178
5185
|
}
|
|
5179
5186
|
}
|
|
@@ -5216,11 +5223,11 @@ class oe extends ne {
|
|
|
5216
5223
|
* The returned class can be used directly as a behavior constructor.
|
|
5217
5224
|
*/
|
|
5218
5225
|
static create(e) {
|
|
5219
|
-
const { initialState: t, stateKey:
|
|
5226
|
+
const { initialState: t, stateKey: i, transitions: s, wildcardTransitions: n } = e;
|
|
5220
5227
|
class o extends oe {
|
|
5221
5228
|
constructor() {
|
|
5222
|
-
super(), this.stateKey =
|
|
5223
|
-
for (const l of
|
|
5229
|
+
super(), this.stateKey = i, this.stateMachine = new W(t);
|
|
5230
|
+
for (const l of s)
|
|
5224
5231
|
this.stateMachine.addTransition(l.from, l.to, l.guard);
|
|
5225
5232
|
if (n)
|
|
5226
5233
|
for (const l of n)
|
|
@@ -5242,9 +5249,9 @@ function dt(r) {
|
|
|
5242
5249
|
e instanceof w ? (e.isVisible = !1, C(e, S.MESH)) : C(r, S.MESH);
|
|
5243
5250
|
}
|
|
5244
5251
|
function ut(r) {
|
|
5245
|
-
r.registerPropertyHandler("collider", (e, t,
|
|
5252
|
+
r.registerPropertyHandler("collider", (e, t, i, s) => {
|
|
5246
5253
|
const n = t;
|
|
5247
|
-
if (A.debug(`Processing collider: ${e.name} -> ${n} (isMesh: ${e instanceof w})`), !
|
|
5254
|
+
if (A.debug(`Processing collider: ${e.name} -> ${n} (isMesh: ${e instanceof w})`), !i.scene)
|
|
5248
5255
|
throw new Error("Scene not available for collider handler");
|
|
5249
5256
|
if (!(e instanceof w)) {
|
|
5250
5257
|
A.warn(`Skipping collider for ${e.name}: not a Mesh instance`);
|
|
@@ -5273,7 +5280,7 @@ function _t(r) {
|
|
|
5273
5280
|
return r.split(",").map((e) => parseFloat(e.trim())).filter((e) => !isNaN(e));
|
|
5274
5281
|
}
|
|
5275
5282
|
function ft(r) {
|
|
5276
|
-
r.registerPropertyHandler("lod_distances", (e, t,
|
|
5283
|
+
r.registerPropertyHandler("lod_distances", (e, t, i, s) => {
|
|
5277
5284
|
const n = t;
|
|
5278
5285
|
if (!(e instanceof w))
|
|
5279
5286
|
return;
|
|
@@ -5290,29 +5297,29 @@ function ft(r) {
|
|
|
5290
5297
|
});
|
|
5291
5298
|
}
|
|
5292
5299
|
function pt(r) {
|
|
5293
|
-
r.registerPropertyHandler("occluder", (e, t,
|
|
5300
|
+
r.registerPropertyHandler("occluder", (e, t, i, s) => {
|
|
5294
5301
|
t && e instanceof w && (e.isOccluder = !0, e.isVisible = !1);
|
|
5295
5302
|
});
|
|
5296
5303
|
}
|
|
5297
5304
|
function yt(r, e) {
|
|
5298
|
-
const t = {},
|
|
5299
|
-
for (const [
|
|
5300
|
-
if (
|
|
5301
|
-
const o =
|
|
5305
|
+
const t = {}, i = `${e}_`;
|
|
5306
|
+
for (const [s, n] of Object.entries(r))
|
|
5307
|
+
if (s.startsWith(i)) {
|
|
5308
|
+
const o = s.slice(i.length);
|
|
5302
5309
|
t[o] = n;
|
|
5303
5310
|
}
|
|
5304
5311
|
return t;
|
|
5305
5312
|
}
|
|
5306
5313
|
const j = new u("SoundHandler");
|
|
5307
5314
|
function mt(r) {
|
|
5308
|
-
r.registerPropertyHandler("sound", (e, t,
|
|
5315
|
+
r.registerPropertyHandler("sound", (e, t, i, s) => {
|
|
5309
5316
|
const n = t;
|
|
5310
|
-
if (!
|
|
5317
|
+
if (!i.scene)
|
|
5311
5318
|
throw new Error("Scene not available for sound handler");
|
|
5312
5319
|
const a = yt(
|
|
5313
5320
|
e.metadata,
|
|
5314
5321
|
"sound"
|
|
5315
|
-
), l = a.volume ?? 1, h = a.loop ?? !0, c = a.spatial ?? !0, d = a.distance ?? 100, m = a.autoplay ?? !0, f = a.channel ?? "ambient", g =
|
|
5322
|
+
), l = a.volume ?? 1, h = a.loop ?? !0, c = a.spatial ?? !0, d = a.distance ?? 100, m = a.autoplay ?? !0, f = a.channel ?? "ambient", g = s.managers.audioManager;
|
|
5316
5323
|
if (!g) {
|
|
5317
5324
|
j.warn(`No AudioManager available. Sound for "${e.name}" skipped.`);
|
|
5318
5325
|
return;
|
|
@@ -5336,13 +5343,13 @@ function mt(r) {
|
|
|
5336
5343
|
});
|
|
5337
5344
|
});
|
|
5338
5345
|
}
|
|
5339
|
-
function Z(r, e, t,
|
|
5340
|
-
const n =
|
|
5346
|
+
function Z(r, e, t, i, s) {
|
|
5347
|
+
const n = s === "enter" ? L.OnIntersectionEnterTrigger : L.OnIntersectionExitTrigger, o = `trigger:${s}`;
|
|
5341
5348
|
r.registerAction(
|
|
5342
5349
|
new Ce(
|
|
5343
5350
|
{
|
|
5344
5351
|
trigger: n,
|
|
5345
|
-
parameter: { mesh:
|
|
5352
|
+
parameter: { mesh: i }
|
|
5346
5353
|
},
|
|
5347
5354
|
(a) => {
|
|
5348
5355
|
t.publish({
|
|
@@ -5356,17 +5363,17 @@ function Z(r, e, t, s, i) {
|
|
|
5356
5363
|
)
|
|
5357
5364
|
);
|
|
5358
5365
|
}
|
|
5359
|
-
function q(r, e, t,
|
|
5360
|
-
Z(r, e, t,
|
|
5366
|
+
function q(r, e, t, i) {
|
|
5367
|
+
Z(r, e, t, i, "enter"), Z(r, e, t, i, "exit");
|
|
5361
5368
|
}
|
|
5362
5369
|
function vt(r) {
|
|
5363
|
-
r.registerPropertyHandler("trigger", (e, t,
|
|
5364
|
-
const n = t, o =
|
|
5370
|
+
r.registerPropertyHandler("trigger", (e, t, i, s) => {
|
|
5371
|
+
const n = t, o = i.scene;
|
|
5365
5372
|
if (!o)
|
|
5366
5373
|
throw new Error("Scene not available for trigger handler");
|
|
5367
|
-
if (!(e instanceof
|
|
5374
|
+
if (!(e instanceof se))
|
|
5368
5375
|
return;
|
|
5369
|
-
const a =
|
|
5376
|
+
const a = s.eventBus;
|
|
5370
5377
|
e.isVisible = !1, e.checkCollisions = !0;
|
|
5371
5378
|
const l = e.actionManager ?? new L(o);
|
|
5372
5379
|
e.actionManager = l;
|
|
@@ -5381,8 +5388,8 @@ function vt(r) {
|
|
|
5381
5388
|
});
|
|
5382
5389
|
}
|
|
5383
5390
|
function bt(r) {
|
|
5384
|
-
r.registerPropertyHandler("visible", (e, t,
|
|
5385
|
-
if (!(e instanceof
|
|
5391
|
+
r.registerPropertyHandler("visible", (e, t, i, s) => {
|
|
5392
|
+
if (!(e instanceof se))
|
|
5386
5393
|
return;
|
|
5387
5394
|
let n = !0;
|
|
5388
5395
|
typeof t == "boolean" ? n = t : typeof t == "string" ? n = t.toLowerCase() === "true" || t === "1" : typeof t == "number" && (n = t !== 0), e.isVisible = n;
|
|
@@ -5392,31 +5399,31 @@ function kt(r) {
|
|
|
5392
5399
|
ut(r), ft(r), pt(r), mt(r), vt(r), bt(r);
|
|
5393
5400
|
}
|
|
5394
5401
|
async function Dt(r, e, t = {}) {
|
|
5395
|
-
const
|
|
5396
|
-
|
|
5402
|
+
const i = new Ae(t.logLevel || "debug"), s = i.getLogger("SAGE");
|
|
5403
|
+
s.info(`Initializing SAGE Game Engine v${E}...`), s.debug("Creating rendering engine...");
|
|
5397
5404
|
const n = {
|
|
5398
5405
|
antialias: !0,
|
|
5399
5406
|
adaptToDeviceRatio: !0,
|
|
5400
5407
|
...t.renderOptions
|
|
5401
5408
|
}, o = await at(r, n);
|
|
5402
|
-
|
|
5409
|
+
s.debug("Creating physics engine...");
|
|
5403
5410
|
const a = await rt(), l = lt(a);
|
|
5404
|
-
|
|
5405
|
-
const h = new Be(
|
|
5406
|
-
|
|
5407
|
-
const c = new Te(r, o, a,
|
|
5408
|
-
|
|
5409
|
-
const d = new Ie(h, c,
|
|
5410
|
-
|
|
5411
|
+
s.debug("Creating event bus...");
|
|
5412
|
+
const h = new Be(i);
|
|
5413
|
+
s.debug("Creating scene engine...");
|
|
5414
|
+
const c = new Te(r, o, a, i);
|
|
5415
|
+
s.debug("Creating managers...");
|
|
5416
|
+
const d = new Ie(h, c, i), m = new nt(h, r, i), f = new He(h, i), g = new je(h, i, f), _ = new Xe(h, i), ae = new et(g, _, i), V = new Ue(o, h, g, m, _, i);
|
|
5417
|
+
s.debug("Creating raycast helper...");
|
|
5411
5418
|
const re = new ht(g);
|
|
5412
|
-
|
|
5419
|
+
s.debug("Creating game timer...");
|
|
5413
5420
|
const G = new ct();
|
|
5414
5421
|
V.registerFrameCallback((b) => G.tick(b * 1e3));
|
|
5415
5422
|
let $, x;
|
|
5416
|
-
t.audioChannels && t.audioChannels.length > 0 && (
|
|
5423
|
+
t.audioChannels && t.audioChannels.length > 0 && (s.debug("Creating audio engine..."), $ = new Le(i), await $.initialize(), s.debug("Creating audio manager..."), x = new Qe($, i), await x.initialize(t.audioChannels)), s.info(`SAGE Game Engine v${E} initialized successfully.`), s.debug("Loading entities...");
|
|
5417
5424
|
for (const b of e)
|
|
5418
5425
|
g.registerEntityDefinition(b);
|
|
5419
|
-
if (
|
|
5426
|
+
if (s.debug("Registering default input bindings..."), t.bindings)
|
|
5420
5427
|
for (const b of t.bindings)
|
|
5421
5428
|
f.registerBinding(b);
|
|
5422
5429
|
const M = new Me(
|
|
@@ -5424,7 +5431,7 @@ async function Dt(r, e, t = {}) {
|
|
|
5424
5431
|
o,
|
|
5425
5432
|
l,
|
|
5426
5433
|
h,
|
|
5427
|
-
|
|
5434
|
+
i,
|
|
5428
5435
|
re,
|
|
5429
5436
|
G,
|
|
5430
5437
|
// Engines
|