mage-engine 3.24.0 → 3.24.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/mage.js +170 -9
  2. package/package.json +1 -1
package/dist/mage.js CHANGED
@@ -55052,14 +55052,36 @@ var Config$1 = new Config();let Universe = /*#__PURE__*/function () {
55052
55052
  }, {
55053
55053
  key: "find",
55054
55054
  value: function find(element) {
55055
- if (!element) return;
55056
- let found;
55055
+ if (!element) return; // Traverse up the THREE.js parent chain to find the closest Mage entity.
55056
+ // This ensures that when clicking on a child mesh that's nested inside
55057
+ // a parent entity's body, we find the child entity (not the parent).
55058
+
55059
+ let current = element;
55060
+
55061
+ while (current) {
55062
+ // Check if any entity's body IS this object directly
55063
+ let found;
55064
+ this.forEach(el => {
55065
+ if (!found && el.hasBody() && el.getBody() === current) {
55066
+ found = el;
55067
+ }
55068
+ });
55069
+
55070
+ if (found) {
55071
+ return found;
55072
+ }
55073
+
55074
+ current = current.parent;
55075
+ } // Fallback: use the original has() check for edge cases
55076
+
55077
+
55078
+ let fallback;
55057
55079
  this.forEach(el => {
55058
- if (el.has(element) && !found) {
55059
- found = el;
55080
+ if (el.has(element) && !fallback) {
55081
+ fallback = el;
55060
55082
  }
55061
55083
  });
55062
- return found;
55084
+ return fallback;
55063
55085
  }
55064
55086
  }, {
55065
55087
  key: "getByTag",
@@ -56880,7 +56902,13 @@ var Physics$1 = new Physics();let Scene = /*#__PURE__*/function () {
56880
56902
  key: "remove",
56881
56903
  value: function remove(body) {
56882
56904
  this.scene.remove(body);
56883
- Universe$1.remove(body.uuid);
56905
+ Universe$1.remove(body.uuid); // Remove the element from the elements array
56906
+
56907
+ const index = this.elements.findIndex(e => e.hasBody() && e.getBody().uuid === body.uuid);
56908
+
56909
+ if (index !== -1) {
56910
+ this.elements.splice(index, 1);
56911
+ }
56884
56912
  }
56885
56913
  }, {
56886
56914
  key: "setClearColor",
@@ -58213,7 +58241,7 @@ function applyMiddleware() {
58213
58241
 
58214
58242
  var thunk = createThunkMiddleware();
58215
58243
  thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
58216
- var version$1 = "3.24.0";
58244
+ var version$1 = "3.24.2";
58217
58245
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
58218
58246
  var main = "dist/mage.js";
58219
58247
  var author$1 = {
@@ -61079,6 +61107,67 @@ const tweenTo = function (origin, target) {
61079
61107
  value: function hasChildren() {
61080
61108
  return this.children.length > 0;
61081
61109
  }
61110
+ /**
61111
+ * Checks if the given ancestor is in this entity's parent chain.
61112
+ * Used to prevent circular references when reparenting.
61113
+ * @param {Entity} ancestor - The potential ancestor entity
61114
+ * @returns {boolean} True if ancestor is in the parent chain
61115
+ */
61116
+
61117
+ }, {
61118
+ key: "isDescendantOf",
61119
+ value: function isDescendantOf(ancestor) {
61120
+ if (!ancestor) return false;
61121
+ let current = this.getParent();
61122
+
61123
+ while (current) {
61124
+ if (current === ancestor || current.uuid && ancestor.uuid && current.uuid() === ancestor.uuid()) {
61125
+ return true;
61126
+ }
61127
+
61128
+ current = current.getParent ? current.getParent() : null;
61129
+ }
61130
+
61131
+ return false;
61132
+ }
61133
+ /**
61134
+ * Reparents this entity to a new parent while preserving world position.
61135
+ * Uses THREE.js attach() to maintain the entity's world transform.
61136
+ * @param {Entity|null} newParent - The new parent entity, or null to move to scene root
61137
+ * @returns {Entity} This entity for chaining
61138
+ */
61139
+
61140
+ }, {
61141
+ key: "reparent",
61142
+ value: function reparent(newParent) {
61143
+ if (!this.hasBody()) return this;
61144
+ const oldParent = this.getParent(); // Detach from old parent's Entity children array
61145
+
61146
+ if (oldParent && oldParent.children) {
61147
+ const index = oldParent.children.findIndex(c => c === this || c.uuid && this.uuid && c.uuid() === this.uuid());
61148
+ if (index !== -1) oldParent.children.splice(index, 1);
61149
+ } // Detach from old THREE.js parent
61150
+
61151
+
61152
+ const body = this.getBody();
61153
+
61154
+ if (body.parent) {
61155
+ body.parent.remove(body);
61156
+ }
61157
+
61158
+ if (newParent && newParent.hasBody()) {
61159
+ // Attach to new parent (preserves world position)
61160
+ newParent.children.push(this);
61161
+ this.setParent(newParent);
61162
+ newParent.getBody().attach(body);
61163
+ } else {
61164
+ // Move to scene root
61165
+ this.setParent(false);
61166
+ Scene$1.getScene().attach(body);
61167
+ }
61168
+
61169
+ return this;
61170
+ }
61082
61171
  }, {
61083
61172
  key: "getHierarchy",
61084
61173
  value: function getHierarchy() {
@@ -87421,6 +87510,11 @@ var Proton = three_proton_min.exports;const PARTICLE_EMITTER_TYPES = {
87421
87510
  }, {
87422
87511
  key: "dispose",
87423
87512
  value: function dispose() {
87513
+ if (this.holder) {
87514
+ this.holder.dispose();
87515
+ this.holder = undefined;
87516
+ }
87517
+
87424
87518
  _get(_getPrototypeOf(ParticleEmitter.prototype), "dispose", this).call(this);
87425
87519
  }
87426
87520
  }, {
@@ -88123,6 +88217,11 @@ let Fountain = /*#__PURE__*/function (_ProtonParticleEmitte) {
88123
88217
  }, {
88124
88218
  key: "dispose",
88125
88219
  value: function dispose() {
88220
+ if (this.holder) {
88221
+ this.holder.dispose();
88222
+ this.holder = undefined;
88223
+ }
88224
+
88126
88225
  _get(_getPrototypeOf(ParticleEmitterGroup.prototype), "dispose", this).call(this);
88127
88226
 
88128
88227
  this.system.forEach(emitter => emitter.dispose());
@@ -95418,7 +95517,7 @@ let Sky = /*#__PURE__*/function (_Element) {
95418
95517
  } catch (error) {
95419
95518
  console.error(IMPORTER_ERROR_ELEMENT_CREATION, elementData.name, elementData.entitySubType, error);
95420
95519
  }
95421
- } // adding children to elements
95520
+ } // adding children to elements (legacy children array format)
95422
95521
 
95423
95522
 
95424
95523
  for (const elementData of elements) {
@@ -95436,6 +95535,21 @@ let Sky = /*#__PURE__*/function (_Element) {
95436
95535
  }
95437
95536
  }
95438
95537
  }
95538
+ } // Handle parentUUID relationships (new format from database parentId)
95539
+ // Use parent.add(child) instead of child.reparent(parent) to preserve
95540
+ // the saved local position. reparent() uses attach() which preserves
95541
+ // world position, but for import we want to keep the saved local position.
95542
+
95543
+
95544
+ for (const elementData of elements) {
95545
+ if (elementData.parentUUID) {
95546
+ const child = Universe$1.getByUUID(elementData.uuid);
95547
+ const parent = Universe$1.getByUUID(elementData.parentUUID);
95548
+
95549
+ if (child && parent && parent.add) {
95550
+ await parent.add(child);
95551
+ }
95552
+ }
95439
95553
  }
95440
95554
 
95441
95555
  lights.forEach(data => {
@@ -95514,7 +95628,54 @@ let Sky = /*#__PURE__*/function (_Element) {
95514
95628
  } catch (error) {
95515
95629
  console.error(IMPORTER_ERROR_PARTICLE_CREATION, data.name, data.preset, error.stack);
95516
95630
  }
95517
- });
95631
+ }); // Handle parentUUID for lights
95632
+
95633
+ for (const lightData of lights) {
95634
+ if (lightData.parentUUID) {
95635
+ const child = Universe$1.getByUUID(lightData.uuid);
95636
+ const parent = Universe$1.getByUUID(lightData.parentUUID);
95637
+
95638
+ if (child && parent && parent.add) {
95639
+ await parent.add(child);
95640
+ }
95641
+ }
95642
+ } // Handle parentUUID for sounds
95643
+
95644
+
95645
+ for (const soundData of allSounds) {
95646
+ if (soundData.parentUUID) {
95647
+ const child = Universe$1.getByUUID(soundData.uuid);
95648
+ const parent = Universe$1.getByUUID(soundData.parentUUID);
95649
+
95650
+ if (child && parent && parent.add) {
95651
+ await parent.add(child);
95652
+ }
95653
+ }
95654
+ } // Handle parentUUID for particles
95655
+
95656
+
95657
+ for (const particleData of particles) {
95658
+ if (particleData.parentUUID) {
95659
+ const child = Universe$1.getByUUID(particleData.uuid);
95660
+ const parent = Universe$1.getByUUID(particleData.parentUUID);
95661
+
95662
+ if (child && parent && parent.add) {
95663
+ await parent.add(child);
95664
+ }
95665
+ }
95666
+ } // Handle parentUUID for cameras
95667
+
95668
+
95669
+ for (const cameraData of cameras) {
95670
+ if (cameraData.parentUUID) {
95671
+ const child = Universe$1.getByUUID(cameraData.uuid);
95672
+ const parent = Universe$1.getByUUID(cameraData.parentUUID);
95673
+
95674
+ if (child && parent && parent.add) {
95675
+ await parent.add(child);
95676
+ }
95677
+ }
95678
+ }
95518
95679
  }
95519
95680
  }]);
95520
95681
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-engine",
3
- "version": "3.24.0",
3
+ "version": "3.24.2",
4
4
  "description": "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.",
5
5
  "main": "dist/mage.js",
6
6
  "author": {