@woosh/meep-engine 2.44.5 → 2.44.6

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.
@@ -5,4 +5,8 @@ export class Connection {
5
5
 
6
6
  readonly source: NodeInstancePortReference
7
7
  readonly target: NodeInstancePortReference
8
+
9
+ setSource(endpoint: NodeInstancePortReference): void
10
+
11
+ setTarget(endpoint: NodeInstancePortReference): void
8
12
  }
@@ -83,6 +83,8 @@ export class NodeGraph {
83
83
  * @returns {NodeInstance|undefined}
84
84
  */
85
85
  getNode(id) {
86
+ assert.isNonNegativeInteger(id, 'id');
87
+
86
88
  const nodes = this.nodes;
87
89
  const n = nodes.length;
88
90
 
@@ -98,6 +100,21 @@ export class NodeGraph {
98
100
  return undefined;
99
101
  }
100
102
 
103
+ /**
104
+ * Same as getNode but throw exception when node doesn't exist
105
+ * @param {number} id
106
+ * @returns {NodeInstance}
107
+ */
108
+ getNodeSafe(id) {
109
+ const result = this.getNode(id);
110
+
111
+ if (result === undefined) {
112
+ throw new Error(`Node ${id} not found`);
113
+ }
114
+
115
+ return result;
116
+ }
117
+
101
118
  /**
102
119
  *
103
120
  * @param {number} id
@@ -209,6 +226,37 @@ export class NodeGraph {
209
226
  return true;
210
227
  }
211
228
 
229
+ /**
230
+ * Same as {@link #createConnection}, but ports are identified by their named instead
231
+ * @param {number} sourceNode
232
+ * @param {string} sourcePort
233
+ * @param {number} targetNode
234
+ * @param {string} targetPort
235
+ * @returns {number} connection ID
236
+ */
237
+ createConnectionByPortName(
238
+ sourceNode, sourcePort,
239
+ targetNode, targetPort) {
240
+ const source_node_instance = this.getNodeSafe(sourceNode);
241
+ const target_node_instance = this.getNodeSafe(targetNode);
242
+
243
+ const source_port_object = source_node_instance.description.getPortByName(sourcePort);
244
+ const target_port_object = target_node_instance.description.getPortByName(targetPort);
245
+
246
+ if (source_port_object === undefined) {
247
+ throw new Error(`Source port '${sourcePort}' not found`);
248
+ }
249
+
250
+ if (target_port_object === undefined) {
251
+ throw new Error(`Target port '${targetPort}' not found`);
252
+ }
253
+
254
+ return this.createConnection(
255
+ sourceNode, source_port_object.id,
256
+ targetNode, target_port_object.id,
257
+ );
258
+ }
259
+
212
260
  /**
213
261
  *
214
262
  * @param {number} sourceNode
@@ -175,6 +175,8 @@ export class NodeInstance {
175
175
  * @returns {NodeInstancePortReference|undefined}
176
176
  */
177
177
  getEndpoint(port) {
178
+ assert.isNonNegativeInteger(port, 'port');
179
+
178
180
  const endpoints = this.endpoints;
179
181
 
180
182
  for (const endpoint of endpoints) {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "productName": "Meep",
6
6
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.44.5",
8
+ "version": "2.44.6",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",