@woosh/meep-engine 2.47.38 → 2.47.40

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
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.47.38",
8
+ "version": "2.47.40",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -52,6 +52,7 @@
52
52
  "@rollup/plugin-strip": "3.0.2",
53
53
  "@types/three": "^0.135.0",
54
54
  "babel-jest": "26.6.3",
55
+ "jest": "26.6.3",
55
56
  "rollup": "3.16.0"
56
57
  },
57
58
  "keywords": [
@@ -58,19 +58,35 @@ export function deserializeNodeGraphFromJSON({
58
58
  for (let i = 0; i < j_descriptions.length; i++) {
59
59
  const jDescription = j_descriptions[i];
60
60
 
61
- const nodeDescription = abstractJSONDeserializer(jDescription, deserializers);
61
+ const loaded_node = abstractJSONDeserializer(jDescription, deserializers);
62
62
 
63
63
  if (
64
- typeof nodeDescription !== "object"
65
- || nodeDescription.isNodeDescription !== true
64
+ typeof loaded_node !== "object"
65
+ || loaded_node.isNodeDescription !== true
66
66
  ) {
67
67
  throw new Error(`Deserialized object was expected to be a NodeDescription, instead got something else. Source JSON[${i}]: ${jDescription}`);
68
68
  }
69
69
 
70
- descriptions[i] = nodeDescription;
70
+ const existing_node = node_registry.getNode(loaded_node.id);
71
+
72
+ if (existing_node === undefined) {
73
+
74
+ descriptions[i] = loaded_node;
75
+
76
+ // make sure to register the node
77
+ node_registry.addNode(loaded_node);
78
+
79
+ } else {
80
+
81
+ if (!existing_node.equals(loaded_node)) {
82
+ throw new Error(`Loaded node does not match the one in the registry. Loaded: ${loaded_node}, Existing: ${existing_node}`);
83
+ }
84
+
85
+ // re-use node from registry
86
+ descriptions[i] = existing_node;
87
+
88
+ }
71
89
 
72
- // make sure to register the node
73
- node_registry.addNode(nodeDescription);
74
90
  }
75
91
 
76
92
  // parse nodes
@@ -5,6 +5,7 @@ import { Port } from "./Port.js";
5
5
  import { PortDirection } from "./PortDirection.js";
6
6
  import Signal from "../../../events/signal/Signal.js";
7
7
  import { invokeObjectToJSON } from "../../object/invokeObjectToJSON.js";
8
+ import { isArrayEqual } from "../../../collection/array/isArrayEqual.js";
8
9
 
9
10
 
10
11
  /**
@@ -88,7 +89,7 @@ export class NodeDescription {
88
89
  * This gives us an opportunity to add/change ports based on current state of a specific node instance
89
90
  * @param {NodeInstance} instance
90
91
  */
91
- configureNode(instance){
92
+ configureNode(instance) {
92
93
  // override in subclasses as necessary
93
94
  }
94
95
 
@@ -326,6 +327,22 @@ export class NodeDescription {
326
327
  return this.ports
327
328
  }
328
329
 
330
+ /**
331
+ *
332
+ * @param {NodeDescription} other
333
+ * @returns {boolean}
334
+ */
335
+ equals(other) {
336
+ return this.id === other.id
337
+ && this.name === other.name
338
+ && isArrayEqual(this.ports, other.ports)
339
+ ;
340
+ }
341
+
342
+ toString() {
343
+ return `NodeDescription[id=${this.id}, name='${this.name}']`;
344
+ }
345
+
329
346
  toJSON() {
330
347
  return {
331
348
  id: this.id,
@@ -49,7 +49,7 @@ export class NodeRegistry {
49
49
 
50
50
  if (existing_node !== undefined) {
51
51
 
52
- if (existing_node !== node) {
52
+ if (existing_node !== node && !existing_node.equals(node)) {
53
53
  // node with the same ID exists and is not the same node
54
54
  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`);
55
55
  }