@woosh/meep-engine 2.46.8 → 2.46.11
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.11",
|
|
8
8
|
"main": "build/meep.module.js",
|
|
9
9
|
"module": "build/meep.module.js",
|
|
10
10
|
"scripts": {
|
|
@@ -126,6 +126,32 @@ export class NodeGraph {
|
|
|
126
126
|
return true;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
/**
|
|
130
|
+
*
|
|
131
|
+
* @param {NodeDescription} description
|
|
132
|
+
* @returns {NodeInstance[]}
|
|
133
|
+
*/
|
|
134
|
+
getNodesByDescription(description) {
|
|
135
|
+
assert.defined(description, 'description');
|
|
136
|
+
assert.notNull(description, 'description');
|
|
137
|
+
assert.equal(description.isNodeDescription, true, 'description.isNodeDescription !== true');
|
|
138
|
+
|
|
139
|
+
const result = [];
|
|
140
|
+
|
|
141
|
+
const nodes = this.nodes;
|
|
142
|
+
const n = nodes.length;
|
|
143
|
+
|
|
144
|
+
for (let i = 0; i < n; i++) {
|
|
145
|
+
const node = nodes.get(i);
|
|
146
|
+
|
|
147
|
+
if (node.description === description) {
|
|
148
|
+
result.push(node);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
|
|
129
155
|
/**
|
|
130
156
|
*
|
|
131
157
|
* @param {number} id
|
|
@@ -29,6 +29,12 @@ function pickNewSetId(things) {
|
|
|
29
29
|
return r;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @type {number}
|
|
35
|
+
*/
|
|
36
|
+
let node_id_counter = 0;
|
|
37
|
+
|
|
32
38
|
export class NodeDescription {
|
|
33
39
|
constructor() {
|
|
34
40
|
/**
|
|
@@ -38,10 +44,13 @@ export class NodeDescription {
|
|
|
38
44
|
this.name = "";
|
|
39
45
|
|
|
40
46
|
/**
|
|
41
|
-
*
|
|
47
|
+
* A unique identifier in the scope of a single registry
|
|
48
|
+
* If two nodes belong to the same registry - they must have different IDs
|
|
49
|
+
* By default an auto-incrementing ID is assigned, as this ID is assigned at the time of object construction - it may be subject to race conditions
|
|
50
|
+
* In case nodes are loaded or constructed in async manner - consider using your own ID assignment scheme
|
|
42
51
|
* @type {number}
|
|
43
52
|
*/
|
|
44
|
-
this.id =
|
|
53
|
+
this.id = node_id_counter++;
|
|
45
54
|
|
|
46
55
|
/**
|
|
47
56
|
* @protected
|
|
@@ -38,12 +38,22 @@ export class NodeRegistry {
|
|
|
38
38
|
/**
|
|
39
39
|
*
|
|
40
40
|
* @param {NodeDescription} node
|
|
41
|
+
* @returns {boolean} true if node was added, false if node already exists
|
|
41
42
|
*/
|
|
42
43
|
addNode(node) {
|
|
43
44
|
assert.defined(node, "node");
|
|
44
45
|
assert.notNull(node, "node");
|
|
46
|
+
assert.equal(node.isNodeDescription, true, 'node.isNodeDescription !== true');
|
|
47
|
+
|
|
48
|
+
const existing_node = this.nodes.get(node.id);
|
|
49
|
+
|
|
50
|
+
if (existing_node !== undefined) {
|
|
51
|
+
|
|
52
|
+
if (existing_node !== node) {
|
|
53
|
+
// node with the same ID exists and is not the same node
|
|
54
|
+
throw new Error(`A different node with the same ID ${node.id} is already registered. IDs of all nodes in the registry must be unique`);
|
|
55
|
+
}
|
|
45
56
|
|
|
46
|
-
if (this.nodes.has(node.id)) {
|
|
47
57
|
// console.warn(`Node with id ${node.id} already exists`);
|
|
48
58
|
|
|
49
59
|
return false;
|
|
@@ -57,6 +67,66 @@ export class NodeRegistry {
|
|
|
57
67
|
return true;
|
|
58
68
|
}
|
|
59
69
|
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
* @param {NodeDescription} node
|
|
73
|
+
* @returns {boolean}
|
|
74
|
+
*/
|
|
75
|
+
hasNode(node) {
|
|
76
|
+
assert.defined(node, "node");
|
|
77
|
+
assert.notNull(node, "node");
|
|
78
|
+
assert.equal(node.isNodeDescription, true, 'node.isNodeDescription !== true');
|
|
79
|
+
|
|
80
|
+
const existing = this.nodes.get(node.id);
|
|
81
|
+
|
|
82
|
+
if (existing === undefined) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (existing !== node) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
* @param {NodeDescription} node
|
|
96
|
+
* @returns {boolean}
|
|
97
|
+
*/
|
|
98
|
+
removeNode(node) {
|
|
99
|
+
assert.defined(node, "node");
|
|
100
|
+
assert.notNull(node, "node");
|
|
101
|
+
assert.equal(node.isNodeDescription, true, 'node.isNodeDescription !== true');
|
|
102
|
+
|
|
103
|
+
if (!this.hasNode(node)) {
|
|
104
|
+
// not found
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.nodes.delete(node.id);
|
|
109
|
+
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Given a class inheriting from NodeDescription, get all registered instances
|
|
115
|
+
* @param {Type<NodeDescription>} Klass
|
|
116
|
+
* @returns {NodeDescription[]}
|
|
117
|
+
*/
|
|
118
|
+
getNodesByClass(Klass) {
|
|
119
|
+
const result = [];
|
|
120
|
+
|
|
121
|
+
for (const [id, node] of this.nodes) {
|
|
122
|
+
if (Object.getPrototypeOf(node) === Klass) {
|
|
123
|
+
result.push(node);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
|
|
60
130
|
/**
|
|
61
131
|
*
|
|
62
132
|
* @param {DataType} type
|