@woosh/meep-engine 2.47.16 → 2.47.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 +1 -1
- package/src/core/model/node-graph/DataType.js +13 -0
- package/src/core/model/node-graph/node/NodeDescription.js +19 -3
- package/src/core/model/node-graph/node/NodeRegistry.js +8 -0
- package/src/core/model/node-graph/node/Port.js +64 -0
- package/src/core/model/object/invokeObjectToJSON.js +3 -0
package/package.json
CHANGED
|
@@ -48,6 +48,19 @@ export class DataType {
|
|
|
48
48
|
this.name = name;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {*} j
|
|
54
|
+
* @returns {DataType}
|
|
55
|
+
*/
|
|
56
|
+
static fromJSON(j){
|
|
57
|
+
const r = new DataType();
|
|
58
|
+
|
|
59
|
+
r.fromJSON(j);
|
|
60
|
+
|
|
61
|
+
return r;
|
|
62
|
+
}
|
|
63
|
+
|
|
51
64
|
/**
|
|
52
65
|
*
|
|
53
66
|
* @param {number} id
|
|
@@ -4,6 +4,7 @@ import { NodeParameterDescription } from "./parameter/NodeParameterDescription.j
|
|
|
4
4
|
import { Port } from "./Port.js";
|
|
5
5
|
import { PortDirection } from "./PortDirection.js";
|
|
6
6
|
import Signal from "../../../events/signal/Signal.js";
|
|
7
|
+
import { invokeObjectToJSON } from "../../object/invokeObjectToJSON.js";
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -317,14 +318,29 @@ export class NodeDescription {
|
|
|
317
318
|
}
|
|
318
319
|
|
|
319
320
|
toJSON() {
|
|
320
|
-
|
|
321
|
+
return {
|
|
322
|
+
id: this.id,
|
|
323
|
+
name: this.name,
|
|
324
|
+
ports: this.ports.map(invokeObjectToJSON),
|
|
325
|
+
}
|
|
321
326
|
}
|
|
322
327
|
|
|
323
|
-
|
|
324
|
-
|
|
328
|
+
/**
|
|
329
|
+
*
|
|
330
|
+
* @param ports
|
|
331
|
+
* @param id
|
|
332
|
+
* @param name
|
|
333
|
+
* @param {NodeRegistry} registry
|
|
334
|
+
*/
|
|
335
|
+
fromJSON({ ports, id, name }, registry) {
|
|
336
|
+
this.id = id;
|
|
337
|
+
this.name = name;
|
|
338
|
+
this.ports = ports.map(p => Port.fromJSON(p, registry));
|
|
325
339
|
}
|
|
326
340
|
}
|
|
327
341
|
|
|
342
|
+
NodeDescription.typeName = "NodeDescription";
|
|
343
|
+
|
|
328
344
|
/**
|
|
329
345
|
* @readonly
|
|
330
346
|
* @type {boolean}
|
|
@@ -154,6 +154,14 @@ export class NodeRegistry {
|
|
|
154
154
|
return this.types.has(type.id);
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
/**
|
|
158
|
+
* @param {number} id
|
|
159
|
+
* @returns {DataType|undefined}
|
|
160
|
+
*/
|
|
161
|
+
getTypeById(id) {
|
|
162
|
+
return this.types.get(id);
|
|
163
|
+
}
|
|
164
|
+
|
|
157
165
|
/**
|
|
158
166
|
*
|
|
159
167
|
* @returns {number}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { computeStringHash } from "../../../primitives/strings/computeStringHash.js";
|
|
2
2
|
import { PortDirection } from "./PortDirection.js";
|
|
3
3
|
import { computeHashIntegerArray } from "../../../collection/array/computeHashIntegerArray.js";
|
|
4
|
+
import { objectKeyByValue } from "../../object/objectKeyByValue.js";
|
|
5
|
+
import { DataType } from "../DataType.js";
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* @type {number}
|
|
@@ -65,6 +67,68 @@ export class Port {
|
|
|
65
67
|
toString() {
|
|
66
68
|
return `Port{ id=${this.id}, direction=${this.direction}, name=${this.name}, type=${this.dataType} }`;
|
|
67
69
|
}
|
|
70
|
+
|
|
71
|
+
toJSON() {
|
|
72
|
+
return {
|
|
73
|
+
id: this.id,
|
|
74
|
+
name: this.name,
|
|
75
|
+
direction: objectKeyByValue(PortDirection, this.direction),
|
|
76
|
+
dataType: this.dataType !== null ? this.dataType.toJSON() : null
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @param {number} id
|
|
83
|
+
* @param {string} name
|
|
84
|
+
* @param {string} direction
|
|
85
|
+
* @param {*} dataType
|
|
86
|
+
* @param {NodeRegistry} [registry] to avoid creating copies of data types
|
|
87
|
+
*/
|
|
88
|
+
fromJSON({
|
|
89
|
+
id, name, direction, dataType
|
|
90
|
+
}, registry) {
|
|
91
|
+
|
|
92
|
+
this.id = id;
|
|
93
|
+
this.name = name;
|
|
94
|
+
this.direction = PortDirection[direction];
|
|
95
|
+
|
|
96
|
+
let _type = dataType !== null ? DataType.fromJSON(dataType) : null;
|
|
97
|
+
|
|
98
|
+
if (registry !== undefined && _type !== null) {
|
|
99
|
+
// attempt to re-write data type with one from the registry
|
|
100
|
+
const match = registry.getTypeById(_type.id);
|
|
101
|
+
|
|
102
|
+
if (match !== undefined) {
|
|
103
|
+
|
|
104
|
+
if (match.equals(_type)) {
|
|
105
|
+
throw new Error(`Loaded type ${_type} does not match one in the registry ${match}`)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// re-write type
|
|
109
|
+
_type = match;
|
|
110
|
+
} else {
|
|
111
|
+
throw new Error(`Loaded type ${_type} was not found in the registry`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.dataType = _type;
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
*
|
|
121
|
+
* @param j
|
|
122
|
+
* @param {NodeRegistry} registry
|
|
123
|
+
* @returns {Port}
|
|
124
|
+
*/
|
|
125
|
+
static fromJSON(j, registry) {
|
|
126
|
+
const r = new Port();
|
|
127
|
+
|
|
128
|
+
r.fromJSON(j, registry);
|
|
129
|
+
|
|
130
|
+
return r;
|
|
131
|
+
}
|
|
68
132
|
}
|
|
69
133
|
|
|
70
134
|
/**
|