@woosh/meep-engine 2.46.6 → 2.46.7

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.6",
7
+ "version": "2.46.7",
8
8
  "main": "build/meep.module.js",
9
9
  "module": "build/meep.module.js",
10
10
  "scripts": {
@@ -0,0 +1,82 @@
1
+ import { NodeGraph } from "../NodeGraph.js";
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
+ }
39
+
40
+ /**
41
+ * Clone portion of a graph as a new graph, retaining connections amongst those nodes
42
+ * @param {NodeGraph} graph
43
+ * @param {NodeInstance[]} nodes
44
+ */
45
+ export function graph_clone_by_node_subset({ graph, nodes }) {
46
+
47
+ assert.defined(graph, 'graph');
48
+ assert.notNull(graph, 'graph');
49
+
50
+ assert.defined(nodes, 'nodes');
51
+ assert.notNull(nodes, 'nodes');
52
+ assert.isArray(nodes, 'nodes');
53
+
54
+ const result = new NodeGraph();
55
+
56
+ const cloned_nodes = {};
57
+
58
+ nodes.forEach(n => {
59
+ const id = result.createNode(n.description);
60
+
61
+ cloned_nodes[n.id] = id;
62
+ });
63
+
64
+ collectConnectionsAmongst({ graph, nodes })
65
+ .forEach(connection => {
66
+
67
+ const source_node_id = cloned_nodes[connection.source.instance.id];
68
+ const source_endpoint = result.getNode(source_node_id).getEndpoint(connection.source.port.id);
69
+
70
+ const target_node_id = cloned_nodes[connection.target.instance.id];
71
+ const target_endpoint = result.getNode(target_node_id).getEndpoint(connection.target.port.id);
72
+
73
+ result.createConnection(
74
+ source_node_id, source_endpoint.id,
75
+ target_node_id, target_endpoint.id
76
+ );
77
+
78
+ });
79
+
80
+ return result;
81
+
82
+ }