@woosh/meep-engine 2.46.12 → 2.46.14
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.14",
|
|
8
8
|
"main": "build/meep.module.js",
|
|
9
9
|
"module": "build/meep.module.js",
|
|
10
10
|
"scripts": {
|
|
@@ -72,6 +72,69 @@ export class NodeGraph {
|
|
|
72
72
|
this.__idpConnections.reset();
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Perform a deep copy
|
|
77
|
+
* @param {NodeGraph} other
|
|
78
|
+
*/
|
|
79
|
+
copy(other) {
|
|
80
|
+
if (this === other) {
|
|
81
|
+
// pointless operation
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.reset();
|
|
86
|
+
|
|
87
|
+
const other_nodes = other.nodes.asArray();
|
|
88
|
+
const node_count = other_nodes.length;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Mapping from original IDs to IDs in this graph
|
|
92
|
+
* @type {Object<number,number>}
|
|
93
|
+
*/
|
|
94
|
+
const this_nodes = {};
|
|
95
|
+
|
|
96
|
+
for (let i = 0; i < node_count; i++) {
|
|
97
|
+
const other_node = other_nodes[i];
|
|
98
|
+
this_nodes[other_node.id] = this.createNode(other_node.description);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// create connections
|
|
102
|
+
const other_connections = other.connections.asArray();
|
|
103
|
+
const connection_count = other_connections.length;
|
|
104
|
+
|
|
105
|
+
for (let i = 0; i < connection_count; i++) {
|
|
106
|
+
const other_connection = other_connections[i];
|
|
107
|
+
|
|
108
|
+
const other_source = other_connection.source;
|
|
109
|
+
|
|
110
|
+
const this_source_node_id = this_nodes[other_source.instance.id];
|
|
111
|
+
const this_source_port_id = this.getNode(this_source_node_id).getEndpoint(other_source.port.id).id;
|
|
112
|
+
|
|
113
|
+
const other_target = other_connection.target;
|
|
114
|
+
|
|
115
|
+
const this_target_node_id = this_nodes[other_target.instance.id];
|
|
116
|
+
const this_target_port_id = this.getNode(this_target_node_id).getEndpoint(other_target.port.id).id;
|
|
117
|
+
|
|
118
|
+
this.createConnection(
|
|
119
|
+
this_source_node_id, this_source_port_id,
|
|
120
|
+
this_target_node_id, this_target_port_id
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
*
|
|
128
|
+
* @returns {NodeGraph}
|
|
129
|
+
*/
|
|
130
|
+
clone() {
|
|
131
|
+
const r = new NodeGraph();
|
|
132
|
+
|
|
133
|
+
r.copy(this);
|
|
134
|
+
|
|
135
|
+
return r;
|
|
136
|
+
}
|
|
137
|
+
|
|
75
138
|
/**
|
|
76
139
|
*
|
|
77
140
|
* @param {function(NodeInstance):*} visitor
|
|
@@ -152,6 +215,32 @@ export class NodeGraph {
|
|
|
152
215
|
return result;
|
|
153
216
|
}
|
|
154
217
|
|
|
218
|
+
/**
|
|
219
|
+
*
|
|
220
|
+
* @param {Type<NodeDescription>} Klass
|
|
221
|
+
* @returns {NodeInstance[]}
|
|
222
|
+
*/
|
|
223
|
+
getNodesByDescriptionClass(Klass) {
|
|
224
|
+
|
|
225
|
+
assert.defined(Klass, 'Klass');
|
|
226
|
+
assert.notNull(Klass, 'Klass');
|
|
227
|
+
|
|
228
|
+
const result = [];
|
|
229
|
+
|
|
230
|
+
const nodes = this.nodes;
|
|
231
|
+
const n = nodes.length;
|
|
232
|
+
|
|
233
|
+
for (let i = 0; i < n; i++) {
|
|
234
|
+
const node = nodes.get(i);
|
|
235
|
+
|
|
236
|
+
if (node.description.constructor === Klass) {
|
|
237
|
+
result.push(node);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
|
|
155
244
|
/**
|
|
156
245
|
*
|
|
157
246
|
* @param {number} id
|
|
@@ -66,3 +66,19 @@ test('getNode produces correct result', () => {
|
|
|
66
66
|
expect(node_instance).toBeDefined();
|
|
67
67
|
expect(node_instance.id).toBe(node_id);
|
|
68
68
|
});
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
test('.copy method with 1 node', () => {
|
|
72
|
+
const g0 = new NodeGraph();
|
|
73
|
+
|
|
74
|
+
const nodeDescription = new NodeDescription();
|
|
75
|
+
|
|
76
|
+
g0.createNode(nodeDescription);
|
|
77
|
+
|
|
78
|
+
const g1 = new NodeGraph();
|
|
79
|
+
|
|
80
|
+
g1.copy(g0);
|
|
81
|
+
|
|
82
|
+
expect(g1.nodes.length).toBe(1);
|
|
83
|
+
expect(g1.getNodesByDescription(nodeDescription).length).toBe(1);
|
|
84
|
+
});
|