@woosh/meep-engine 2.46.15 → 2.46.17

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.15",
7
+ "version": "2.46.17",
8
8
  "main": "build/meep.module.js",
9
9
  "module": "build/meep.module.js",
10
10
  "scripts": {
@@ -103,15 +103,17 @@ export class NodeGraph {
103
103
  /**
104
104
  * Merge another graph into this one
105
105
  * Supplied graph does not change as a result
106
+ * @see {@link #mergeFragment}
106
107
  * @param {NodeGraph} other
108
+ * @returns {{connections:Connection[], nodes:NodeInstance[]}}
107
109
  */
108
110
  merge(other) {
109
111
  if (other === this) {
110
- // can't merge with self, operation is pointless
111
- return;
112
+ // can't merge with self, invalid operation
113
+ throw new Error("Can't merge with self, invalid operation");
112
114
  }
113
115
 
114
- this.mergeFragment({
116
+ return this.mergeFragment({
115
117
  nodes: other.nodes.asArray(),
116
118
  connections: other.connections.asArray()
117
119
  });
@@ -122,11 +124,14 @@ export class NodeGraph {
122
124
  * New node instances and connections will be created to reflect these inside this graph
123
125
  * @param {NodeInstance[]} nodes
124
126
  * @param {Connection[]} [connections]
127
+ * @returns {{connections:Connection[], nodes:NodeInstance[]}} local created instances
125
128
  */
126
129
  mergeFragment({ nodes, connections = [] }) {
127
130
 
128
- const other_nodes = nodes;
129
- const node_count = other_nodes.length;
131
+ const previous_node_count = this.nodes.length;
132
+ const previous_connection_count = this.connections.length;
133
+
134
+ const additional_node_count = nodes.length;
130
135
 
131
136
  /**
132
137
  * Mapping from original IDs to IDs in this graph
@@ -134,27 +139,26 @@ export class NodeGraph {
134
139
  */
135
140
  const this_nodes = {};
136
141
 
137
- for (let i = 0; i < node_count; i++) {
138
- const other_node = other_nodes[i];
142
+ for (let i = 0; i < additional_node_count; i++) {
143
+ const other_node = nodes[i];
139
144
  this_nodes[other_node.id] = this.createNode(other_node.description);
140
145
  }
141
146
 
142
147
  // create connections
143
- const other_connections = connections;
144
- const connection_count = other_connections.length;
148
+ const additional_connection_count = connections.length;
145
149
 
146
- for (let i = 0; i < connection_count; i++) {
147
- const other_connection = other_connections[i];
150
+ for (let i = 0; i < additional_connection_count; i++) {
151
+ const other_connection = connections[i];
148
152
 
149
153
  const other_source = other_connection.source;
150
154
 
151
155
  const this_source_node_id = this_nodes[other_source.instance.id];
152
- const this_source_port_id = this.getNode(this_source_node_id).getEndpoint(other_source.port.id).id;
156
+ const this_source_port_id = other_source.port.id;
153
157
 
154
158
  const other_target = other_connection.target;
155
159
 
156
160
  const this_target_node_id = this_nodes[other_target.instance.id];
157
- const this_target_port_id = this.getNode(this_target_node_id).getEndpoint(other_target.port.id).id;
161
+ const this_target_port_id = other_target.port.id;
158
162
 
159
163
  this.createConnection(
160
164
  this_source_node_id, this_source_port_id,
@@ -162,6 +166,10 @@ export class NodeGraph {
162
166
  );
163
167
  }
164
168
 
169
+ return {
170
+ connections: this.connections.asArray().slice(previous_connection_count, previous_connection_count + additional_connection_count),
171
+ nodes: this.nodes.asArray().slice(previous_node_count, previous_node_count + additional_node_count)
172
+ };
165
173
  }
166
174
 
167
175
  /**
@@ -562,6 +570,11 @@ export class NodeGraph {
562
570
  * @returns {number} number of found connections
563
571
  */
564
572
  getConnectionsAttachedToNode(id, result) {
573
+ assert.isNonNegativeInteger(id, 'id');
574
+
575
+ assert.defined(result, 'result');
576
+ assert.isArray(result, 'result');
577
+
565
578
  let count = 0;
566
579
 
567
580
  const connections = this.connections;