mage-engine 3.23.40 → 3.23.41

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 +89 -29
  2. package/package.json +1 -1
package/dist/mage.js CHANGED
@@ -54995,7 +54995,7 @@ var Config$1 = new Config();let Universe = /*#__PURE__*/function () {
54995
54995
 
54996
54996
  _defineProperty$1(this, "reset", () => {
54997
54997
  this.reality = {};
54998
- this.realityUUID = {};
54998
+ this.nameIndex = {};
54999
54999
  });
55000
55000
 
55001
55001
  _defineProperty$1(this, "forEach", callback => {
@@ -55016,15 +55016,37 @@ var Config$1 = new Config();let Universe = /*#__PURE__*/function () {
55016
55016
  this.reset();
55017
55017
  });
55018
55018
 
55019
- this.reality = {};
55020
- this.realityUUID = {};
55019
+ this.reality = {}; // uuid -> element (primary storage)
55020
+
55021
+ this.nameIndex = {}; // name -> uuid[] (reverse index for name lookups)
55022
+
55021
55023
  this.worker = undefined;
55022
55024
  }
55023
55025
 
55024
55026
  _createClass(Universe, [{
55025
55027
  key: "get",
55026
55028
  value: function get(id) {
55027
- return this.reality[id];
55029
+ // Primary: lookup by UUID
55030
+ if (this.reality[id]) {
55031
+ return this.reality[id];
55032
+ } // Fallback: lookup by name (backward compat for user scripts)
55033
+
55034
+
55035
+ return this.getByName(id);
55036
+ }
55037
+ }, {
55038
+ key: "getByName",
55039
+ value: function getByName(name) {
55040
+ const uuids = this.nameIndex[name];
55041
+
55042
+ if (uuids && uuids.length > 0) {
55043
+ return this.reality[uuids[0]];
55044
+ }
55045
+ }
55046
+ }, {
55047
+ key: "getByUUID",
55048
+ value: function getByUUID(uuid) {
55049
+ return this.reality[uuid];
55028
55050
  }
55029
55051
  }, {
55030
55052
  key: "find",
@@ -55038,15 +55060,6 @@ var Config$1 = new Config();let Universe = /*#__PURE__*/function () {
55038
55060
  });
55039
55061
  return found;
55040
55062
  }
55041
- }, {
55042
- key: "getByUUID",
55043
- value: function getByUUID(uuid) {
55044
- const id = this.realityUUID[uuid.toString()];
55045
-
55046
- if (id) {
55047
- return this.get(id);
55048
- }
55049
- }
55050
55063
  }, {
55051
55064
  key: "getByTag",
55052
55065
  value: function getByTag(tagName) {
@@ -55060,24 +55073,72 @@ var Config$1 = new Config();let Universe = /*#__PURE__*/function () {
55060
55073
  }
55061
55074
  }, {
55062
55075
  key: "set",
55063
- value: function set(id, value) {
55064
- this.reality[id] = value;
55076
+ value: function set(uuid, element) {
55077
+ this.reality[uuid] = element; // Maintain name index
55078
+
55079
+ const name = element.getName ? element.getName() : undefined;
55080
+
55081
+ if (name) {
55082
+ if (!this.nameIndex[name]) {
55083
+ this.nameIndex[name] = [];
55084
+ }
55085
+
55086
+ if (!this.nameIndex[name].includes(uuid)) {
55087
+ this.nameIndex[name].push(uuid);
55088
+ }
55089
+ }
55065
55090
  }
55091
+ }, {
55092
+ key: "updateNameIndex",
55093
+ value: function updateNameIndex(uuid, oldName, newName) {
55094
+ // Remove from old name's list
55095
+ if (oldName && this.nameIndex[oldName]) {
55096
+ this.nameIndex[oldName] = this.nameIndex[oldName].filter(u => u !== uuid);
55097
+
55098
+ if (this.nameIndex[oldName].length === 0) {
55099
+ delete this.nameIndex[oldName];
55100
+ }
55101
+ } // Add to new name's list
55102
+
55103
+
55104
+ if (newName) {
55105
+ if (!this.nameIndex[newName]) {
55106
+ this.nameIndex[newName] = [];
55107
+ }
55108
+
55109
+ if (!this.nameIndex[newName].includes(uuid)) {
55110
+ this.nameIndex[newName].push(uuid);
55111
+ }
55112
+ }
55113
+ } // @deprecated - indexing is now handled inside set()
55114
+
55066
55115
  }, {
55067
55116
  key: "storeUUIDToElementNameReference",
55068
- value: function storeUUIDToElementNameReference(uuid, name) {
55069
- this.realityUUID[uuid] = name;
55070
- }
55117
+ value: function storeUUIDToElementNameReference(uuid, name) {// no-op: set() handles name indexing
55118
+ } // @deprecated - use updateNameIndex() instead
55119
+
55071
55120
  }, {
55072
55121
  key: "replaceUUIDToElementNameReference",
55073
- value: function replaceUUIDToElementNameReference(uuid, newName) {
55074
- delete this.realityUUID[uuid];
55075
- this.realityUUID[uuid] = newName;
55122
+ value: function replaceUUIDToElementNameReference(uuid, newName) {// no-op: use updateNameIndex() instead
55076
55123
  }
55077
55124
  }, {
55078
55125
  key: "remove",
55079
- value: function remove(id) {
55080
- delete this.reality[id];
55126
+ value: function remove(uuid) {
55127
+ const element = this.reality[uuid];
55128
+
55129
+ if (element) {
55130
+ const name = element.getName ? element.getName() : undefined;
55131
+
55132
+ if (name && this.nameIndex[name]) {
55133
+ this.nameIndex[name] = this.nameIndex[name].filter(u => u !== uuid);
55134
+
55135
+ if (this.nameIndex[name].length === 0) {
55136
+ delete this.nameIndex[name];
55137
+ }
55138
+ }
55139
+ }
55140
+
55141
+ delete this.reality[uuid];
55081
55142
  }
55082
55143
  }, {
55083
55144
  key: "update",
@@ -56791,9 +56852,7 @@ var Physics$1 = new Physics();let Scene = /*#__PURE__*/function () {
56791
56852
  }
56792
56853
 
56793
56854
  if (addUniverse) {
56794
- const name = element.getName();
56795
- Universe$1.set(name, element);
56796
- Universe$1.storeUUIDToElementNameReference(body.uuid, name);
56855
+ Universe$1.set(body.uuid, element);
56797
56856
  }
56798
56857
  }
56799
56858
  }, {
@@ -56812,7 +56871,7 @@ var Physics$1 = new Physics();let Scene = /*#__PURE__*/function () {
56812
56871
  key: "remove",
56813
56872
  value: function remove(body) {
56814
56873
  this.scene.remove(body);
56815
- Universe$1.remove(body.name);
56874
+ Universe$1.remove(body.uuid);
56816
56875
  }
56817
56876
  }, {
56818
56877
  key: "setClearColor",
@@ -58145,7 +58204,7 @@ function applyMiddleware() {
58145
58204
 
58146
58205
  var thunk = createThunkMiddleware();
58147
58206
  thunk.withExtraArgument = createThunkMiddleware;var name = "mage-engine";
58148
- var version$1 = "3.23.40";
58207
+ var version$1 = "3.23.41";
58149
58208
  var description = "A WebGL Javascript Game Engine, built on top of THREE.js and many other libraries.";
58150
58209
  var main = "dist/mage.js";
58151
58210
  var author$1 = {
@@ -62125,13 +62184,14 @@ let Element$1 = /*#__PURE__*/function (_Entity) {
62125
62184
  let {
62126
62185
  replace = false
62127
62186
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
62187
+ const oldName = this.name;
62128
62188
 
62129
62189
  _get(_getPrototypeOf(Element.prototype), "setName", this).call(this, name);
62130
62190
 
62131
62191
  if (this.hasBody()) {
62132
62192
  if (replace) this.dispose();
62133
62193
  this.body.name = name;
62134
- Universe$1.replaceUUIDToElementNameReference(this.uuid(), name);
62194
+ Universe$1.updateNameIndex(this.uuid(), oldName, name);
62135
62195
  if (replace) this.addToScene();
62136
62196
  }
62137
62197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mage-engine",
3
- "version": "3.23.40",
3
+ "version": "3.23.41",
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": {