@woosh/meep-engine 2.46.7 → 2.46.8

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.7",
7
+ "version": "2.46.8",
8
8
  "main": "build/meep.module.js",
9
9
  "module": "build/meep.module.js",
10
10
  "scripts": {
@@ -106,6 +106,26 @@ export class NodeGraph {
106
106
  return this.connections.data.slice();
107
107
  }
108
108
 
109
+ /**
110
+ *
111
+ * @param {NodeInstance} node
112
+ * @returns {boolean}
113
+ */
114
+ hasNode(node) {
115
+ const existing_node = this.getNode(node.id);
116
+
117
+ if (existing_node === undefined) {
118
+ return false;
119
+ }
120
+
121
+ if (existing_node !== node) {
122
+ // another node with this ID was found
123
+ return false;
124
+ }
125
+
126
+ return true;
127
+ }
128
+
109
129
  /**
110
130
  *
111
131
  * @param {number} id
@@ -119,6 +119,10 @@ export class NodeInstancePortReference {
119
119
  && this.port.equals(other.port)
120
120
  ;
121
121
  }
122
+
123
+ toString() {
124
+ return `NodeInstancePortReference{ id=${this.id}, instance=${this.instance}, port=${this.port}, connections.length=${this.connections.length} }`;
125
+ }
122
126
  }
123
127
 
124
128
  /**
@@ -1,41 +1,6 @@
1
1
  import { NodeGraph } from "../NodeGraph.js";
2
2
  import { assert } from "../../../assert.js";
3
-
4
- /**
5
- *
6
- * @param {NodeGraph} graph
7
- * @param {NodeInstance[]} nodes
8
- * @returns {Connection[]}
9
- */
10
- function collectConnectionsAmongst({
11
- graph,
12
- nodes
13
- }) {
14
-
15
- const r = new Set();
16
-
17
- const node_count = nodes.length;
18
- for (let i = 0; i < node_count; i++) {
19
- const node_0 = nodes[i];
20
-
21
- const connections = node_0.connections.asArray();
22
- const connection_count = connections.length;
23
-
24
- for (let j = 0; j < connection_count; j++) {
25
- const connection = connections[j];
26
-
27
- for (let k = i + 1; k < node_count; k++) {
28
- const node_1 = nodes[k];
29
-
30
- if (connection.isAttachedToNode(node_1.id)) {
31
- r.add(connection);
32
- }
33
- }
34
- }
35
- }
36
-
37
- return Array.from(r);
38
- }
3
+ import { graph_collect_connections_amongst_nodes } from "./graph_collect_connections_amongst_nodes.js";
39
4
 
40
5
  /**
41
6
  * Clone portion of a graph as a new graph, retaining connections amongst those nodes
@@ -53,15 +18,24 @@ export function graph_clone_by_node_subset({ graph, nodes }) {
53
18
 
54
19
  const result = new NodeGraph();
55
20
 
21
+ /**
22
+ * Maps from source node IDs to result node IDs
23
+ * @type {Object<number,number>}
24
+ */
56
25
  const cloned_nodes = {};
57
26
 
58
27
  nodes.forEach(n => {
28
+
29
+ if (!graph.hasNode(n)) {
30
+ throw new Error(`Referenced node ${n} is not a found in the graph`);
31
+ }
32
+
59
33
  const id = result.createNode(n.description);
60
34
 
61
35
  cloned_nodes[n.id] = id;
62
36
  });
63
37
 
64
- collectConnectionsAmongst({ graph, nodes })
38
+ graph_collect_connections_amongst_nodes({ graph, nodes })
65
39
  .forEach(connection => {
66
40
 
67
41
  const source_node_id = cloned_nodes[connection.source.instance.id];
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Given a graph and a set of nodes, get all connections that connect these nodes amongst themselves
3
+ * @param {NodeGraph} graph
4
+ * @param {NodeInstance[]} nodes
5
+ * @returns {Connection[]}
6
+ */
7
+ export function graph_collect_connections_amongst_nodes({
8
+ graph,
9
+ nodes
10
+ }) {
11
+
12
+ const r = new Set();
13
+
14
+ const node_count = nodes.length;
15
+
16
+ for (let i = 0; i < node_count; i++) {
17
+ const node_0 = nodes[i];
18
+
19
+ const connections = node_0.connections.asArray();
20
+ const connection_count = connections.length;
21
+
22
+ for (let j = 0; j < connection_count; j++) {
23
+ const connection = connections[j];
24
+
25
+ if (connection.source.instance === connection.target.instance) {
26
+ // Special case. Auto-connection, from node to itself
27
+ r.add(connection);
28
+ continue;
29
+ }
30
+
31
+ for (let k = i + 1; k < node_count; k++) {
32
+ const node_1 = nodes[k];
33
+
34
+ if (node_0 === node_1) {
35
+ // duplicate node found
36
+ continue;
37
+ }
38
+
39
+ if (connection.isAttachedToNode(node_1.id)) {
40
+ r.add(connection);
41
+
42
+ // connection can only exist between two ports, so we're done
43
+ break;
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ return Array.from(r);
50
+ }