@woosh/meep-engine 2.47.37 → 2.47.39

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.
@@ -77596,28 +77596,31 @@ function planesEqual(a, b) {
77596
77596
  * @template T
77597
77597
  * @param {T[]} a
77598
77598
  * @param {T[]} b
77599
- * @param {function(T,T):boolean} elementsEqual
77599
+ * @param {function(T,T):boolean} elements_equal
77600
77600
  * @returns {boolean}
77601
77601
  */
77602
- function isArraysEqualWithComparator(a, b, elementsEqual) {
77602
+ function isArraysEqualWithComparator(a, b, elements_equal) {
77603
77603
  if (a === b) {
77604
+ // same object
77604
77605
  return true;
77605
77606
  }
77606
77607
 
77607
77608
  if (a === null || b === null || a === undefined || b === undefined) {
77609
+ // check if one of the arrays is missing
77608
77610
  return false
77609
77611
  }
77610
77612
 
77611
- const l = a.length;
77612
- if (l !== b.length) {
77613
+ const element_count = a.length;
77614
+
77615
+ if (element_count !== b.length) {
77613
77616
  return false;
77614
77617
  }
77615
77618
 
77616
- for (let i = 0; i < l; i++) {
77619
+ for (let i = 0; i < element_count; i++) {
77617
77620
  const aE = a[i];
77618
77621
  const bE = b[i];
77619
77622
 
77620
- if (!elementsEqual(aE, bE)) {
77623
+ if (!elements_equal(aE, bE)) {
77621
77624
  return false;
77622
77625
  }
77623
77626
  }
@@ -100733,16 +100736,29 @@ function objectDeepEquals(a, b) {
100733
100736
  }
100734
100737
 
100735
100738
  if (tA === "object") {
100736
- //one way
100737
- for (let pA in a) {
100738
- if (!objectDeepEquals(a[pA], b[pA])) {
100739
+ if (Array.isArray(a)) {
100740
+ // special fast path for arrays
100741
+ if (!Array.isArray(b)) {
100742
+ // one is an array, the other is not
100739
100743
  return false;
100740
100744
  }
100745
+ return isArraysEqualWithComparator(a, b, objectDeepEquals);
100741
100746
  }
100742
100747
 
100743
- //other way
100744
- for (let pB in b) {
100745
- if (!objectDeepEquals(a[pB], b[pB])) {
100748
+ const keys_a = Object.keys(a);
100749
+ const keys_b = Object.keys(b);
100750
+
100751
+ if (!isArrayEqualStrict(keys_a, keys_b)) {
100752
+ // different fields
100753
+ return false;
100754
+ }
100755
+
100756
+ const key_count = keys_a.length;
100757
+
100758
+ for (let i = 0; i < key_count; i++) {
100759
+ const key = keys_a[i];
100760
+
100761
+ if (!objectDeepEquals(a[key], b[key])) {
100746
100762
  return false;
100747
100763
  }
100748
100764
  }
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.37",
8
+ "version": "2.47.39",
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": [
@@ -2,28 +2,31 @@
2
2
  * @template T
3
3
  * @param {T[]} a
4
4
  * @param {T[]} b
5
- * @param {function(T,T):boolean} elementsEqual
5
+ * @param {function(T,T):boolean} elements_equal
6
6
  * @returns {boolean}
7
7
  */
8
- export function isArraysEqualWithComparator(a, b, elementsEqual) {
8
+ export function isArraysEqualWithComparator(a, b, elements_equal) {
9
9
  if (a === b) {
10
+ // same object
10
11
  return true;
11
12
  }
12
13
 
13
14
  if (a === null || b === null || a === undefined || b === undefined) {
15
+ // check if one of the arrays is missing
14
16
  return false
15
17
  }
16
18
 
17
- const l = a.length;
18
- if (l !== b.length) {
19
+ const element_count = a.length;
20
+
21
+ if (element_count !== b.length) {
19
22
  return false;
20
23
  }
21
24
 
22
- for (let i = 0; i < l; i++) {
25
+ for (let i = 0; i < element_count; i++) {
23
26
  const aE = a[i];
24
27
  const bE = b[i];
25
28
 
26
- if (!elementsEqual(aE, bE)) {
29
+ if (!elements_equal(aE, bE)) {
27
30
  return false;
28
31
  }
29
32
  }
@@ -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`);
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,18 @@ 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
+
329
342
  toJSON() {
330
343
  return {
331
344
  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
  }
@@ -1,3 +1,6 @@
1
+ import { isArraysEqualWithComparator } from "../../collection/array/isArraysEqualWithComparator.js";
2
+ import { isArrayEqualStrict } from "../../collection/array/isArrayEqualStrict.js";
3
+
1
4
  /**
2
5
  * @template A,B
3
6
  * @param {A} a
@@ -13,16 +16,29 @@ export function objectDeepEquals(a, b) {
13
16
  }
14
17
 
15
18
  if (tA === "object") {
16
- //one way
17
- for (let pA in a) {
18
- if (!objectDeepEquals(a[pA], b[pA])) {
19
+ if (Array.isArray(a)) {
20
+ // special fast path for arrays
21
+ if (!Array.isArray(b)) {
22
+ // one is an array, the other is not
19
23
  return false;
20
24
  }
25
+ return isArraysEqualWithComparator(a, b, objectDeepEquals);
26
+ }
27
+
28
+ const keys_a = Object.keys(a);
29
+ const keys_b = Object.keys(b);
30
+
31
+ if (!isArrayEqualStrict(keys_a, keys_b)) {
32
+ // different fields
33
+ return false;
21
34
  }
22
35
 
23
- //other way
24
- for (let pB in b) {
25
- if (!objectDeepEquals(a[pB], b[pB])) {
36
+ const key_count = keys_a.length;
37
+
38
+ for (let i = 0; i < key_count; i++) {
39
+ const key = keys_a[i];
40
+
41
+ if (!objectDeepEquals(a[key], b[key])) {
26
42
  return false;
27
43
  }
28
44
  }