@woosh/meep-engine 2.44.5 → 2.44.7
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.
|
@@ -127,6 +127,10 @@ export class Connection {
|
|
|
127
127
|
^ (target_hash)
|
|
128
128
|
;
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
toString() {
|
|
132
|
+
return `Connection{ id = ${this.id}, source=${this.source !== null ? this.source.id : 'null'}, target=${this.target !== null ? this.target.id : 'null'} }`
|
|
133
|
+
}
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
|
|
@@ -5,6 +5,7 @@ import { Connection } from "./Connection.js";
|
|
|
5
5
|
import { NodeInstance } from "./node/NodeInstance.js";
|
|
6
6
|
import { array_push_if_unique } from "../../collection/array/array_push_if_unique.js";
|
|
7
7
|
import { array_remove_first } from "../../collection/array/array_remove_first.js";
|
|
8
|
+
import { PortDirection } from "./node/PortDirection.js";
|
|
8
9
|
|
|
9
10
|
export class NodeGraph {
|
|
10
11
|
constructor() {
|
|
@@ -83,6 +84,8 @@ export class NodeGraph {
|
|
|
83
84
|
* @returns {NodeInstance|undefined}
|
|
84
85
|
*/
|
|
85
86
|
getNode(id) {
|
|
87
|
+
assert.isNonNegativeInteger(id, 'id');
|
|
88
|
+
|
|
86
89
|
const nodes = this.nodes;
|
|
87
90
|
const n = nodes.length;
|
|
88
91
|
|
|
@@ -98,6 +101,21 @@ export class NodeGraph {
|
|
|
98
101
|
return undefined;
|
|
99
102
|
}
|
|
100
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Same as getNode but throw exception when node doesn't exist
|
|
106
|
+
* @param {number} id
|
|
107
|
+
* @returns {NodeInstance}
|
|
108
|
+
*/
|
|
109
|
+
getNodeSafe(id) {
|
|
110
|
+
const result = this.getNode(id);
|
|
111
|
+
|
|
112
|
+
if (result === undefined) {
|
|
113
|
+
throw new Error(`Node ${id} not found`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
|
|
101
119
|
/**
|
|
102
120
|
*
|
|
103
121
|
* @param {number} id
|
|
@@ -209,6 +227,52 @@ export class NodeGraph {
|
|
|
209
227
|
return true;
|
|
210
228
|
}
|
|
211
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Utility method to help in creation of connections
|
|
232
|
+
* Same as {@link #createConnection}, but ports are identified by their named instead
|
|
233
|
+
* @param {number} sourceNode
|
|
234
|
+
* @param {string} sourcePort
|
|
235
|
+
* @param {number} targetNode
|
|
236
|
+
* @param {string} targetPort
|
|
237
|
+
* @returns {number} connection ID
|
|
238
|
+
*/
|
|
239
|
+
createConnectionByPortName(
|
|
240
|
+
sourceNode, sourcePort,
|
|
241
|
+
targetNode, targetPort
|
|
242
|
+
) {
|
|
243
|
+
const source_node_instance = this.getNodeSafe(sourceNode);
|
|
244
|
+
const target_node_instance = this.getNodeSafe(targetNode);
|
|
245
|
+
|
|
246
|
+
const source_ports = source_node_instance.description.getPortsByName(sourcePort).filter(p => p.direction === PortDirection.Out);
|
|
247
|
+
|
|
248
|
+
if (source_ports.length > 1) {
|
|
249
|
+
throw new Error(`Multiple source ports match name '${sourcePort}'`);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const source_port_object = source_ports[0];
|
|
253
|
+
|
|
254
|
+
const target_ports = target_node_instance.description.getPortsByName(targetPort).filter(p => p.direction === PortDirection.In);
|
|
255
|
+
|
|
256
|
+
if (target_ports.length > 1) {
|
|
257
|
+
throw new Error(`Multiple target ports match name '${targetPort}'`);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const target_port_object = target_ports[0];
|
|
261
|
+
|
|
262
|
+
if (source_port_object === undefined) {
|
|
263
|
+
throw new Error(`Source port '${sourcePort}' not found`);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (target_port_object === undefined) {
|
|
267
|
+
throw new Error(`Target port '${targetPort}' not found`);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return this.createConnection(
|
|
271
|
+
sourceNode, source_port_object.id,
|
|
272
|
+
targetNode, target_port_object.id,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
212
276
|
/**
|
|
213
277
|
*
|
|
214
278
|
* @param {number} sourceNode
|
|
@@ -177,20 +177,31 @@ export class NodeDescription {
|
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
179
|
*
|
|
180
|
-
* @param name
|
|
181
|
-
* @return {Port
|
|
180
|
+
* @param {string} name
|
|
181
|
+
* @return {Port[]}
|
|
182
182
|
*/
|
|
183
|
-
|
|
183
|
+
getPortsByName(name) {
|
|
184
184
|
assert.isString(name, 'name');
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
/**
|
|
187
|
+
*
|
|
188
|
+
* @type {Port[]}
|
|
189
|
+
*/
|
|
190
|
+
const result = [];
|
|
191
|
+
|
|
192
|
+
const ports = this.ports;
|
|
193
|
+
const port_count = ports.length;
|
|
194
|
+
|
|
195
|
+
for (let i = 0; i < port_count; i++) {
|
|
196
|
+
const port = ports[i];
|
|
197
|
+
|
|
187
198
|
if (port.name === name) {
|
|
188
|
-
|
|
199
|
+
result.push(port);
|
|
189
200
|
}
|
|
201
|
+
|
|
190
202
|
}
|
|
191
203
|
|
|
192
|
-
|
|
193
|
-
return undefined;
|
|
204
|
+
return result;
|
|
194
205
|
}
|
|
195
206
|
|
|
196
207
|
/**
|
|
@@ -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) {
|
|
@@ -203,6 +205,10 @@ export class NodeInstance {
|
|
|
203
205
|
&& isArrayEqual(this.parameters, other.parameters)
|
|
204
206
|
;
|
|
205
207
|
}
|
|
208
|
+
|
|
209
|
+
toString() {
|
|
210
|
+
return `NodeInstance{ id = ${this.id}, description = ${this.description.id} }`
|
|
211
|
+
}
|
|
206
212
|
}
|
|
207
213
|
|
|
208
214
|
|
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.
|
|
8
|
+
"version": "2.44.7",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|