@woosh/meep-engine 2.46.11 → 2.46.13
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.13",
|
|
8
8
|
"main": "build/meep.module.js",
|
|
9
9
|
"module": "build/meep.module.js",
|
|
10
10
|
"scripts": {
|
|
@@ -72,6 +72,57 @@ 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
|
+
|
|
75
126
|
/**
|
|
76
127
|
*
|
|
77
128
|
* @param {function(NodeInstance):*} visitor
|
|
@@ -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
|
+
});
|
|
@@ -112,6 +112,7 @@ export class NodeRegistry {
|
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
114
|
* Given a class inheriting from NodeDescription, get all registered instances
|
|
115
|
+
* Matching is strict, instances of subclasses are not matched
|
|
115
116
|
* @param {Type<NodeDescription>} Klass
|
|
116
117
|
* @returns {NodeDescription[]}
|
|
117
118
|
*/
|
|
@@ -119,7 +120,7 @@ export class NodeRegistry {
|
|
|
119
120
|
const result = [];
|
|
120
121
|
|
|
121
122
|
for (const [id, node] of this.nodes) {
|
|
122
|
-
if (
|
|
123
|
+
if (node.constructor === Klass) {
|
|
123
124
|
result.push(node);
|
|
124
125
|
}
|
|
125
126
|
}
|