@woosh/meep-engine 2.46.8 → 2.46.10

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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "productName": "Meep",
5
5
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
6
6
  "author": "Alexander Goldring",
7
- "version": "2.46.8",
7
+ "version": "2.46.10",
8
8
  "main": "build/meep.module.js",
9
9
  "module": "build/meep.module.js",
10
10
  "scripts": {
@@ -29,6 +29,12 @@ function pickNewSetId(things) {
29
29
  return r;
30
30
  }
31
31
 
32
+ /**
33
+ *
34
+ * @type {number}
35
+ */
36
+ let node_id_counter = 0;
37
+
32
38
  export class NodeDescription {
33
39
  constructor() {
34
40
  /**
@@ -38,10 +44,13 @@ export class NodeDescription {
38
44
  this.name = "";
39
45
 
40
46
  /**
41
- *
47
+ * A unique identifier in the scope of a single registry
48
+ * If two nodes belong to the same registry - they must have different IDs
49
+ * By default an auto-incrementing ID is assigned, as this ID is assigned at the time of object construction - it may be subject to race conditions
50
+ * In case nodes are loaded or constructed in async manner - consider using your own ID assignment scheme
42
51
  * @type {number}
43
52
  */
44
- this.id = 0;
53
+ this.id = node_id_counter++;
45
54
 
46
55
  /**
47
56
  * @protected
@@ -38,12 +38,21 @@ export class NodeRegistry {
38
38
  /**
39
39
  *
40
40
  * @param {NodeDescription} node
41
+ * @returns {boolean} true if node was added, false if node already exists
41
42
  */
42
43
  addNode(node) {
43
44
  assert.defined(node, "node");
44
45
  assert.notNull(node, "node");
45
46
 
46
- if (this.nodes.has(node.id)) {
47
+ const existing_node = this.nodes.get(node.id);
48
+
49
+ if (existing_node !== undefined) {
50
+
51
+ if (existing_node !== node) {
52
+ // node with the same ID exists and is not the same node
53
+ throw new Error(`A different node with the same ID ${node.id} is already registered. IDs of all nodes in the registry must be unique`);
54
+ }
55
+
47
56
  // console.warn(`Node with id ${node.id} already exists`);
48
57
 
49
58
  return false;