@woosh/meep-engine 2.46.14 → 2.46.16
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.16",
|
|
8
8
|
"main": "build/meep.module.js",
|
|
9
9
|
"module": "build/meep.module.js",
|
|
10
10
|
"scripts": {
|
|
@@ -84,8 +84,55 @@ export class NodeGraph {
|
|
|
84
84
|
|
|
85
85
|
this.reset();
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
* @see {@link #mergeFragment}
|
|
107
|
+
* @param {NodeGraph} other
|
|
108
|
+
* @returns {{connections:Connection[], nodes:NodeInstance[]}}
|
|
109
|
+
*/
|
|
110
|
+
merge(other) {
|
|
111
|
+
if (other === this) {
|
|
112
|
+
// can't merge with self, invalid operation
|
|
113
|
+
throw new Error("Can't merge with self, invalid operation");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return this.mergeFragment({
|
|
117
|
+
nodes: other.nodes.asArray(),
|
|
118
|
+
connections: other.connections.asArray()
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Merge foreign nodes and associated connections into this graph
|
|
124
|
+
* New node instances and connections will be created to reflect these inside this graph
|
|
125
|
+
* @param {NodeInstance[]} nodes
|
|
126
|
+
* @param {Connection[]} [connections]
|
|
127
|
+
* @returns {{connections:Connection[], nodes:NodeInstance[]}} local created instances
|
|
128
|
+
*/
|
|
129
|
+
mergeFragment({ nodes, connections = [] }) {
|
|
130
|
+
|
|
131
|
+
const previous_node_count = this.nodes.length;
|
|
132
|
+
const previous_connection_count = this.connections.length;
|
|
133
|
+
|
|
134
|
+
const other_nodes = nodes;
|
|
135
|
+
const additional_node_count = other_nodes.length;
|
|
89
136
|
|
|
90
137
|
/**
|
|
91
138
|
* Mapping from original IDs to IDs in this graph
|
|
@@ -93,16 +140,16 @@ export class NodeGraph {
|
|
|
93
140
|
*/
|
|
94
141
|
const this_nodes = {};
|
|
95
142
|
|
|
96
|
-
for (let i = 0; i <
|
|
143
|
+
for (let i = 0; i < additional_node_count; i++) {
|
|
97
144
|
const other_node = other_nodes[i];
|
|
98
145
|
this_nodes[other_node.id] = this.createNode(other_node.description);
|
|
99
146
|
}
|
|
100
147
|
|
|
101
148
|
// create connections
|
|
102
|
-
const other_connections =
|
|
103
|
-
const
|
|
149
|
+
const other_connections = connections;
|
|
150
|
+
const additional_connection_count = other_connections.length;
|
|
104
151
|
|
|
105
|
-
for (let i = 0; i <
|
|
152
|
+
for (let i = 0; i < additional_connection_count; i++) {
|
|
106
153
|
const other_connection = other_connections[i];
|
|
107
154
|
|
|
108
155
|
const other_source = other_connection.source;
|
|
@@ -121,18 +168,10 @@ export class NodeGraph {
|
|
|
121
168
|
);
|
|
122
169
|
}
|
|
123
170
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* @returns {NodeGraph}
|
|
129
|
-
*/
|
|
130
|
-
clone() {
|
|
131
|
-
const r = new NodeGraph();
|
|
132
|
-
|
|
133
|
-
r.copy(this);
|
|
134
|
-
|
|
135
|
-
return r;
|
|
171
|
+
return {
|
|
172
|
+
connections: this.connections.asArray().slice(previous_connection_count, previous_connection_count + additional_connection_count),
|
|
173
|
+
nodes: this.nodes.asArray().slice(previous_node_count, previous_node_count + additional_node_count)
|
|
174
|
+
};
|
|
136
175
|
}
|
|
137
176
|
|
|
138
177
|
/**
|
|
@@ -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
|
}
|