@woosh/meep-engine 2.46.13 → 2.46.15
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
|
+
"version": "2.46.15",
|
|
8
8
|
"main": "build/meep.module.js",
|
|
9
9
|
"module": "build/meep.module.js",
|
|
10
10
|
"scripts": {
|
|
@@ -84,7 +84,48 @@ export class NodeGraph {
|
|
|
84
84
|
|
|
85
85
|
this.reset();
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
this.merge(other);
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
* @returns {NodeGraph}
|
|
94
|
+
*/
|
|
95
|
+
clone() {
|
|
96
|
+
const r = new NodeGraph();
|
|
97
|
+
|
|
98
|
+
r.copy(this);
|
|
99
|
+
|
|
100
|
+
return r;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Merge another graph into this one
|
|
105
|
+
* Supplied graph does not change as a result
|
|
106
|
+
* @param {NodeGraph} other
|
|
107
|
+
*/
|
|
108
|
+
merge(other) {
|
|
109
|
+
if (other === this) {
|
|
110
|
+
// can't merge with self, operation is pointless
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.mergeFragment({
|
|
115
|
+
nodes: other.nodes.asArray(),
|
|
116
|
+
connections: other.connections.asArray()
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Merge foreign nodes and associated connections into this graph
|
|
122
|
+
* New node instances and connections will be created to reflect these inside this graph
|
|
123
|
+
* @param {NodeInstance[]} nodes
|
|
124
|
+
* @param {Connection[]} [connections]
|
|
125
|
+
*/
|
|
126
|
+
mergeFragment({ nodes, connections = [] }) {
|
|
127
|
+
|
|
128
|
+
const other_nodes = nodes;
|
|
88
129
|
const node_count = other_nodes.length;
|
|
89
130
|
|
|
90
131
|
/**
|
|
@@ -99,7 +140,7 @@ export class NodeGraph {
|
|
|
99
140
|
}
|
|
100
141
|
|
|
101
142
|
// create connections
|
|
102
|
-
const other_connections =
|
|
143
|
+
const other_connections = connections;
|
|
103
144
|
const connection_count = other_connections.length;
|
|
104
145
|
|
|
105
146
|
for (let i = 0; i < connection_count; i++) {
|
|
@@ -203,6 +244,32 @@ export class NodeGraph {
|
|
|
203
244
|
return result;
|
|
204
245
|
}
|
|
205
246
|
|
|
247
|
+
/**
|
|
248
|
+
*
|
|
249
|
+
* @param {Type<NodeDescription>} Klass
|
|
250
|
+
* @returns {NodeInstance[]}
|
|
251
|
+
*/
|
|
252
|
+
getNodesByDescriptionClass(Klass) {
|
|
253
|
+
|
|
254
|
+
assert.defined(Klass, 'Klass');
|
|
255
|
+
assert.notNull(Klass, 'Klass');
|
|
256
|
+
|
|
257
|
+
const result = [];
|
|
258
|
+
|
|
259
|
+
const nodes = this.nodes;
|
|
260
|
+
const n = nodes.length;
|
|
261
|
+
|
|
262
|
+
for (let i = 0; i < n; i++) {
|
|
263
|
+
const node = nodes.get(i);
|
|
264
|
+
|
|
265
|
+
if (node.description.constructor === Klass) {
|
|
266
|
+
result.push(node);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
|
|
206
273
|
/**
|
|
207
274
|
*
|
|
208
275
|
* @param {number} id
|
|
@@ -18,39 +18,13 @@ export function graph_clone_by_node_subset({ graph, nodes }) {
|
|
|
18
18
|
|
|
19
19
|
const result = new NodeGraph();
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
* Maps from source node IDs to result node IDs
|
|
23
|
-
* @type {Object<number,number>}
|
|
24
|
-
*/
|
|
25
|
-
const cloned_nodes = {};
|
|
21
|
+
const connections = graph_collect_connections_amongst_nodes({ graph, nodes });
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
throw new Error(`Referenced node ${n} is not a found in the graph`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const id = result.createNode(n.description);
|
|
34
|
-
|
|
35
|
-
cloned_nodes[n.id] = id;
|
|
23
|
+
result.mergeFragment({
|
|
24
|
+
nodes,
|
|
25
|
+
connections
|
|
36
26
|
});
|
|
37
27
|
|
|
38
|
-
graph_collect_connections_amongst_nodes({ graph, nodes })
|
|
39
|
-
.forEach(connection => {
|
|
40
|
-
|
|
41
|
-
const source_node_id = cloned_nodes[connection.source.instance.id];
|
|
42
|
-
const source_endpoint = result.getNode(source_node_id).getEndpoint(connection.source.port.id);
|
|
43
|
-
|
|
44
|
-
const target_node_id = cloned_nodes[connection.target.instance.id];
|
|
45
|
-
const target_endpoint = result.getNode(target_node_id).getEndpoint(connection.target.port.id);
|
|
46
|
-
|
|
47
|
-
result.createConnection(
|
|
48
|
-
source_node_id, source_endpoint.id,
|
|
49
|
-
target_node_id, target_endpoint.id
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
|
|
54
28
|
return result;
|
|
55
29
|
|
|
56
30
|
}
|