@amodx/ncs 0.0.22 → 0.0.24
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/Components/Component.types.d.ts +6 -1
- package/Components/ComponentArray.d.ts +1 -1
- package/Components/ComponentArray.js +11 -4
- package/Components/ComponentCursor.d.ts +4 -1
- package/Components/ComponentCursor.js +7 -2
- package/Data/serializeComponent.js +1 -1
- package/Data/serializeNode.js +28 -2
- package/Functional.js +2 -0
- package/Graphs/Graph.d.ts +1 -0
- package/Graphs/Graph.js +25 -14
- package/NCS.d.ts +26 -19
- package/NCS.js +15 -0
- package/Nodes/NodeArray.d.ts +1 -0
- package/Nodes/NodeArray.js +14 -8
- package/Nodes/NodeComponents.js +34 -19
- package/Nodes/NodeCursor.d.ts +5 -5
- package/Nodes/NodeCursor.js +117 -55
- package/Nodes/NodeId.d.ts +3 -0
- package/Nodes/NodeId.js +10 -0
- package/Nodes/NodeTags.js +37 -13
- package/Register/NCSRegister.js +1 -1
- package/Register/registerComponent.js +3 -6
- package/Register/registerContext.js +1 -1
- package/Register/registerTag.js +28 -2
- package/Schema/Schema.js +9 -3
- package/Schema/SchemaView.js +1 -1
- package/Systems/System.types.d.ts +1 -1
- package/Systems/SystemInstance.d.ts +1 -1
- package/Systems/SystemInstance.js +2 -2
- package/Tags/TagCursor.d.ts +1 -0
- package/Tags/TagCursor.js +3 -0
- package/package.json +1 -27
package/Nodes/NodeCursor.js
CHANGED
|
@@ -15,17 +15,20 @@ export class NodeCursor {
|
|
|
15
15
|
return cursor;
|
|
16
16
|
}
|
|
17
17
|
static Retrun(cursor) {
|
|
18
|
-
|
|
18
|
+
if (cursor.index !== -1) {
|
|
19
|
+
cursor.clear(cursor.hasEvents, cursor.hasContexts, cursor.hasObservers, cursor.hasComponents, cursor.hasTags);
|
|
20
|
+
}
|
|
19
21
|
NCSPools.nodeCursor.addItem(cursor);
|
|
20
22
|
}
|
|
21
23
|
clear(events, context, observers, compoents, tags) {
|
|
24
|
+
this._index = -1;
|
|
22
25
|
if (events && this._events) {
|
|
23
26
|
NodeEvents.Retrun(this._events);
|
|
24
27
|
this._events = null;
|
|
25
28
|
}
|
|
26
|
-
if (context && this.
|
|
27
|
-
|
|
28
|
-
this.
|
|
29
|
+
if (context && this._context) {
|
|
30
|
+
NodeContext.Retrun(this._context);
|
|
31
|
+
this._context = null;
|
|
29
32
|
}
|
|
30
33
|
if (observers && this._observers) {
|
|
31
34
|
NodeObservers.Retrun(this._observers);
|
|
@@ -43,9 +46,6 @@ export class NodeCursor {
|
|
|
43
46
|
get index() {
|
|
44
47
|
return this._index;
|
|
45
48
|
}
|
|
46
|
-
get parentIndex() {
|
|
47
|
-
return this.arrays._parents[this._index];
|
|
48
|
-
}
|
|
49
49
|
get id() {
|
|
50
50
|
return this.graph._nodes._indexMap[this.index] || null;
|
|
51
51
|
}
|
|
@@ -132,7 +132,7 @@ export class NodeCursor {
|
|
|
132
132
|
get isDisposed() {
|
|
133
133
|
return this.arrays._disposed[this._index];
|
|
134
134
|
}
|
|
135
|
-
_index =
|
|
135
|
+
_index = -1;
|
|
136
136
|
constructor() { }
|
|
137
137
|
setNode(graph, index) {
|
|
138
138
|
this._index = index;
|
|
@@ -170,21 +170,39 @@ export class NodeCursor {
|
|
|
170
170
|
return cursor.setNode(this.graph, this.index);
|
|
171
171
|
}
|
|
172
172
|
/** Traverse the node's direct children */
|
|
173
|
-
*children(cursor
|
|
173
|
+
*children(cursor) {
|
|
174
174
|
const array = this.childrenArray;
|
|
175
175
|
if (!array)
|
|
176
176
|
return false;
|
|
177
|
+
const templChildArray = NCSPools.numberArray.get() || [];
|
|
177
178
|
for (let i = 0; i < array.length; i++) {
|
|
178
|
-
|
|
179
|
+
templChildArray[i] = array[i];
|
|
180
|
+
}
|
|
181
|
+
let usedTemp = false;
|
|
182
|
+
if (!cursor) {
|
|
183
|
+
usedTemp = true;
|
|
184
|
+
cursor = NodeCursor.Get();
|
|
185
|
+
}
|
|
186
|
+
for (let i = 0; i < templChildArray.length; i++) {
|
|
187
|
+
cursor.setNode(this.graph, templChildArray[i]);
|
|
179
188
|
yield cursor;
|
|
180
189
|
}
|
|
190
|
+
templChildArray.length = 0;
|
|
191
|
+
NCSPools.numberArray.addItem(templChildArray);
|
|
192
|
+
if (usedTemp)
|
|
193
|
+
cursor.returnCursor();
|
|
181
194
|
return true;
|
|
182
195
|
}
|
|
183
196
|
/** Traverse all the node's descendants */
|
|
184
|
-
*traverseChildren(cursor
|
|
197
|
+
*traverseChildren(cursor) {
|
|
185
198
|
if (!this.childrenArray)
|
|
186
199
|
return false;
|
|
187
200
|
const children = [this.childrenArray];
|
|
201
|
+
let usedTemp = false;
|
|
202
|
+
if (!cursor) {
|
|
203
|
+
usedTemp = true;
|
|
204
|
+
cursor = NodeCursor.Get();
|
|
205
|
+
}
|
|
188
206
|
while (children.length) {
|
|
189
207
|
const childrenArray = children.shift();
|
|
190
208
|
if (!childrenArray)
|
|
@@ -197,39 +215,63 @@ export class NodeCursor {
|
|
|
197
215
|
}
|
|
198
216
|
}
|
|
199
217
|
}
|
|
218
|
+
if (usedTemp)
|
|
219
|
+
cursor.returnCursor();
|
|
200
220
|
return true;
|
|
201
221
|
}
|
|
202
222
|
/** Traverse all the node's parents */
|
|
203
|
-
*traverseParents(cursor
|
|
223
|
+
*traverseParents(cursor) {
|
|
204
224
|
let parent = this.parent;
|
|
205
225
|
if (parent === undefined || parent < 0)
|
|
206
226
|
return false;
|
|
227
|
+
let usedTemp = false;
|
|
228
|
+
if (!cursor) {
|
|
229
|
+
usedTemp = true;
|
|
230
|
+
cursor = NodeCursor.Get();
|
|
231
|
+
}
|
|
207
232
|
while (true) {
|
|
208
233
|
cursor.setNode(this.graph, parent);
|
|
209
234
|
yield cursor;
|
|
210
235
|
parent = this.arrays._parents[cursor._index];
|
|
211
|
-
if (parent === undefined || parent < 0)
|
|
236
|
+
if (parent === undefined || parent < 0) {
|
|
237
|
+
if (usedTemp)
|
|
238
|
+
cursor.returnCursor();
|
|
212
239
|
return true;
|
|
240
|
+
}
|
|
213
241
|
}
|
|
214
242
|
}
|
|
215
243
|
/** Traverse all the node's components */
|
|
216
|
-
*traverseComponents(cursor
|
|
244
|
+
*traverseComponents(cursor) {
|
|
217
245
|
const components = this.components.components;
|
|
218
|
-
if (!components)
|
|
246
|
+
if (!components || !components.length)
|
|
219
247
|
return false;
|
|
248
|
+
let usedTemp = false;
|
|
249
|
+
if (!cursor) {
|
|
250
|
+
usedTemp = true;
|
|
251
|
+
cursor = ComponentCursor.Get();
|
|
252
|
+
}
|
|
220
253
|
for (let i = 0; i < components.length; i += 2) {
|
|
221
254
|
yield cursor.setInstance(this, components[i], components[i + 1]);
|
|
222
255
|
}
|
|
256
|
+
if (usedTemp)
|
|
257
|
+
cursor.returnCursor();
|
|
223
258
|
return true;
|
|
224
259
|
}
|
|
225
260
|
/** Traverse all the node's tags */
|
|
226
|
-
*traverseTags(cursor
|
|
261
|
+
*traverseTags(cursor) {
|
|
227
262
|
const tags = this.tags.tags;
|
|
228
263
|
if (!this.tags)
|
|
229
264
|
return false;
|
|
265
|
+
let usedTemp = false;
|
|
266
|
+
if (!cursor) {
|
|
267
|
+
usedTemp = true;
|
|
268
|
+
cursor = TagCursor.Get();
|
|
269
|
+
}
|
|
230
270
|
for (let i = 0; i < tags.length; i += 2) {
|
|
231
271
|
yield cursor.setTag(this, tags[i], tags[i + 1]);
|
|
232
272
|
}
|
|
273
|
+
if (usedTemp)
|
|
274
|
+
cursor.returnCursor();
|
|
233
275
|
return true;
|
|
234
276
|
}
|
|
235
277
|
dispose() {
|
|
@@ -238,10 +280,6 @@ export class NodeCursor {
|
|
|
238
280
|
this.hasObservers &&
|
|
239
281
|
this.observers.isDisposedSet &&
|
|
240
282
|
this.observers.disposed.notify(this);
|
|
241
|
-
if (this.parent !== undefined) {
|
|
242
|
-
nodeCursor.setNode(this.graph, this.parent);
|
|
243
|
-
nodeCursor.removeChild(this.index);
|
|
244
|
-
}
|
|
245
283
|
if (this.arrays._components[this._index]?.length) {
|
|
246
284
|
this.components.dispose();
|
|
247
285
|
}
|
|
@@ -249,10 +287,25 @@ export class NodeCursor {
|
|
|
249
287
|
this.tags.dispose();
|
|
250
288
|
}
|
|
251
289
|
if (this.childrenArray) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
290
|
+
const templChildArray = NCSPools.numberArray.get() || [];
|
|
291
|
+
const children = this.childrenArray;
|
|
292
|
+
for (let i = 0; i < children.length; i++) {
|
|
293
|
+
templChildArray[i] = children[i];
|
|
294
|
+
}
|
|
295
|
+
const tempCursor = NodeCursor.Get();
|
|
296
|
+
for (let i = 0; i < templChildArray.length; i++) {
|
|
297
|
+
tempCursor.setNode(this.graph, templChildArray[i]);
|
|
298
|
+
tempCursor.dispose();
|
|
255
299
|
}
|
|
300
|
+
tempCursor.returnCursor();
|
|
301
|
+
templChildArray.length = 0;
|
|
302
|
+
NCSPools.numberArray.addItem(templChildArray);
|
|
303
|
+
}
|
|
304
|
+
if (this.parent > -1) {
|
|
305
|
+
const tempCursor = NodeCursor.Get();
|
|
306
|
+
tempCursor.setNode(this.graph, this.parent);
|
|
307
|
+
tempCursor.removeChild(tempCursor.getChildIndex(this.index));
|
|
308
|
+
tempCursor.returnCursor();
|
|
256
309
|
}
|
|
257
310
|
this.graph.removeNode(this.index);
|
|
258
311
|
this.clear(this.hasEvents, this.hasContexts, this.hasObservers, this.hasComponents, this.hasTags);
|
|
@@ -267,17 +320,21 @@ export class NodeCursor {
|
|
|
267
320
|
return false;
|
|
268
321
|
}
|
|
269
322
|
parentTo(nodeToParentTo) {
|
|
323
|
+
if (this.index == nodeToParentTo.index)
|
|
324
|
+
throw new Error(`NCS: Tried to parent node ${this.index} ${this.name} to itself`);
|
|
270
325
|
if (nodeToParentTo.hasChild(this))
|
|
271
326
|
return;
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
327
|
+
const tempCursor = NodeCursor.Get();
|
|
328
|
+
if (this.parent > -1) {
|
|
329
|
+
tempCursor.setNode(this.graph, this.parent);
|
|
330
|
+
tempCursor.removeChild(tempCursor.getChildIndex(this.index));
|
|
275
331
|
}
|
|
276
332
|
nodeToParentTo.addChild(this);
|
|
277
333
|
this.parent = nodeToParentTo.index;
|
|
278
334
|
this.hasObservers &&
|
|
279
335
|
this.observers.isParentedSet &&
|
|
280
|
-
nodeToParentTo.observers.parented.notify(
|
|
336
|
+
nodeToParentTo.observers.parented.notify(tempCursor);
|
|
337
|
+
tempCursor.returnCursor();
|
|
281
338
|
}
|
|
282
339
|
getChild(index, cursor = NodeCursor.Get()) {
|
|
283
340
|
const childrenArray = this.childrenArray;
|
|
@@ -285,9 +342,18 @@ export class NodeCursor {
|
|
|
285
342
|
return null;
|
|
286
343
|
return cursor.setNode(this.graph, childrenArray[index]);
|
|
287
344
|
}
|
|
345
|
+
getChildIndex(node) {
|
|
346
|
+
let index = typeof node == "number" ? node : node.index;
|
|
347
|
+
for (let i = 0; i < this.childrenArray.length; i++) {
|
|
348
|
+
if (this.childrenArray[i] == index) {
|
|
349
|
+
return i;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return -1;
|
|
353
|
+
}
|
|
288
354
|
addChild(node) {
|
|
289
355
|
if (this.hasChild(node))
|
|
290
|
-
return;
|
|
356
|
+
return this.getChildIndex(node);
|
|
291
357
|
if (!this.childrenArray) {
|
|
292
358
|
this.arrays._children[this._index] = NCSPools.numberArray.get() || [];
|
|
293
359
|
}
|
|
@@ -297,40 +363,39 @@ export class NodeCursor {
|
|
|
297
363
|
this.observers.isChildAddedSet &&
|
|
298
364
|
this.observers.childAdded.notify(node);
|
|
299
365
|
this.observers.isChildrenUpdatedSet &&
|
|
300
|
-
this.observers.childrenUpdated.notify(
|
|
366
|
+
this.observers.childrenUpdated.notify(this);
|
|
301
367
|
}
|
|
302
368
|
if (node.hasObservers) {
|
|
303
369
|
node.observers.isParentedSet && node.observers.parented.notify(node);
|
|
304
370
|
}
|
|
371
|
+
return this.childrenArray.length - 1;
|
|
305
372
|
}
|
|
306
373
|
removeChild(index) {
|
|
307
|
-
if (!this.childrenArray)
|
|
374
|
+
if (!this.childrenArray || !this.childrenArray[index])
|
|
308
375
|
return;
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
nodeCursor.observers.removedFromParent.notify(nodeCursor);
|
|
324
|
-
}
|
|
325
|
-
return child;
|
|
326
|
-
}
|
|
376
|
+
const child = this.childrenArray.splice(index, 1)[0];
|
|
377
|
+
const tempCursor = NodeCursor.Get();
|
|
378
|
+
tempCursor.setNode(this.graph, child);
|
|
379
|
+
if (this.hasObservers) {
|
|
380
|
+
this.hasObservers &&
|
|
381
|
+
this.observers.isChildRemovedSet &&
|
|
382
|
+
this.observers.childRemoved.notify(tempCursor);
|
|
383
|
+
this.hasObservers &&
|
|
384
|
+
this.observers.isChildrenUpdatedSet &&
|
|
385
|
+
this.observers.childrenUpdated.notify(this);
|
|
386
|
+
}
|
|
387
|
+
if (tempCursor.hasObservers) {
|
|
388
|
+
tempCursor.observers.isRemovedFromParentSet &&
|
|
389
|
+
tempCursor.observers.removedFromParent.notify(tempCursor);
|
|
327
390
|
}
|
|
328
|
-
|
|
391
|
+
tempCursor.returnCursor();
|
|
392
|
+
return child;
|
|
329
393
|
}
|
|
330
|
-
|
|
394
|
+
uniqueId() {
|
|
331
395
|
let id = this.graph._nodes._indexMap[this.index];
|
|
332
|
-
if (
|
|
333
|
-
id
|
|
396
|
+
if (id)
|
|
397
|
+
return id;
|
|
398
|
+
id = NodeId.Create();
|
|
334
399
|
this.graph._nodes.addNodeId(this.index, id);
|
|
335
400
|
return id;
|
|
336
401
|
}
|
|
@@ -343,6 +408,3 @@ export class NodeCursor {
|
|
|
343
408
|
return newCursor;
|
|
344
409
|
}
|
|
345
410
|
}
|
|
346
|
-
const componentCursor = ComponentCursor.Get();
|
|
347
|
-
const tagCursor = TagCursor.Get();
|
|
348
|
-
const nodeCursor = NodeCursor.Get();
|
package/Nodes/NodeId.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export declare class NodeId {
|
|
2
2
|
static Create(): bigint;
|
|
3
|
+
static GetHighPart(id: bigint): bigint;
|
|
4
|
+
static GetLowPart(id: bigint): bigint;
|
|
5
|
+
static GetCombined(lower: bigint, upper: bigint): bigint;
|
|
3
6
|
static CreateString(): string;
|
|
4
7
|
static FromString(id: string): bigint;
|
|
5
8
|
static ToHexString(id: BigInt): string;
|
package/Nodes/NodeId.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const buffer = new ArrayBuffer(16);
|
|
2
2
|
const randomArray = new Uint8Array(buffer);
|
|
3
3
|
const view = new DataView(buffer);
|
|
4
|
+
const mask64 = 0xffffffffffffffffn;
|
|
4
5
|
export class NodeId {
|
|
5
6
|
static Create() {
|
|
6
7
|
crypto.getRandomValues(randomArray);
|
|
@@ -11,6 +12,15 @@ export class NodeId {
|
|
|
11
12
|
const bigIntId = high | midHigh | midLow | low;
|
|
12
13
|
return bigIntId;
|
|
13
14
|
}
|
|
15
|
+
static GetHighPart(id) {
|
|
16
|
+
return (id >> 64n) & mask64;
|
|
17
|
+
}
|
|
18
|
+
static GetLowPart(id) {
|
|
19
|
+
return id & mask64;
|
|
20
|
+
}
|
|
21
|
+
static GetCombined(lower, upper) {
|
|
22
|
+
return ((upper & mask64) << 64n) | (lower & mask64);
|
|
23
|
+
}
|
|
14
24
|
static CreateString() {
|
|
15
25
|
return this.ToHexString(this.Create());
|
|
16
26
|
}
|
package/Nodes/NodeTags.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { TagArray } from "../Tags/TagArray";
|
|
1
2
|
import { NCSPools } from "../Pools/NCSPools";
|
|
2
3
|
import { NCSRegister } from "../Register/NCSRegister";
|
|
3
4
|
import { TagCursor } from "../Tags/TagCursor";
|
|
4
|
-
const tagCursor = TagCursor.Get();
|
|
5
5
|
export class NodeTags {
|
|
6
6
|
node;
|
|
7
7
|
static Get() {
|
|
@@ -18,41 +18,63 @@ export class NodeTags {
|
|
|
18
18
|
}
|
|
19
19
|
constructor() { }
|
|
20
20
|
dispose() {
|
|
21
|
+
const tempCursor = TagCursor.Get();
|
|
21
22
|
for (let i = 0; i < this.tags.length; i += 2) {
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
tempCursor.setTag(this.node, this.tags[i], this.tags[i + 1]);
|
|
24
|
+
tempCursor.dispose();
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
|
-
add(id, cursor
|
|
27
|
-
|
|
27
|
+
add(id, cursor) {
|
|
28
|
+
let usedTemp = false;
|
|
29
|
+
if (!cursor) {
|
|
30
|
+
usedTemp = true;
|
|
31
|
+
cursor = TagCursor.Get();
|
|
32
|
+
}
|
|
33
|
+
let tagArray = this.node.graph._tags[id];
|
|
34
|
+
if (!tagArray) {
|
|
35
|
+
tagArray = new TagArray(NCSRegister.tags.get(id).id);
|
|
36
|
+
this.node.graph._tags[id] = tagArray;
|
|
37
|
+
}
|
|
38
|
+
const newTag = tagArray.addTag(this.node.index);
|
|
39
|
+
if (!this.node.arrays._tags[this.node.index]) {
|
|
40
|
+
this.node.arrays._tags[this.node.index] =
|
|
41
|
+
NCSPools.numberArray.get() || [];
|
|
42
|
+
}
|
|
28
43
|
this.tags.push(id, newTag);
|
|
29
44
|
cursor.setTag(this.node, id, newTag);
|
|
30
45
|
if (this.node.hasObservers) {
|
|
31
46
|
this.node.observers.isTagsAddedSet &&
|
|
32
47
|
this.node.observers.tagsAdded.notify(cursor);
|
|
33
48
|
}
|
|
49
|
+
if (usedTemp)
|
|
50
|
+
cursor.returnCursor();
|
|
34
51
|
return cursor;
|
|
35
52
|
}
|
|
36
53
|
remove(id) {
|
|
37
54
|
const tagId = NCSRegister.tags.idPalette.getNumberId(id);
|
|
38
55
|
const tags = this.tags;
|
|
56
|
+
const tempCursor = TagCursor.Get();
|
|
39
57
|
for (let i = 0; i < tags.length; i++) {
|
|
40
58
|
if (tags[i] == tagId) {
|
|
41
|
-
|
|
42
|
-
|
|
59
|
+
tempCursor.setTag(this.node, tagId, tags[i]);
|
|
60
|
+
tempCursor.dispose();
|
|
43
61
|
this.tags.splice(i, 2);
|
|
44
62
|
this.node.hasObservers &&
|
|
45
63
|
this.node.observers.isTagsRemovedSet &&
|
|
46
|
-
this.node.observers.tagsRemoved.notify(
|
|
64
|
+
this.node.observers.tagsRemoved.notify(tempCursor);
|
|
47
65
|
this.node.hasObservers &&
|
|
48
66
|
this.node.observers.isTagsUpdatedSet &&
|
|
49
67
|
this.node.observers.tagsUpdated.notify(0);
|
|
50
|
-
|
|
68
|
+
{
|
|
69
|
+
tempCursor.returnCursor();
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
51
72
|
}
|
|
52
73
|
}
|
|
74
|
+
tempCursor.returnCursor();
|
|
53
75
|
return false;
|
|
54
76
|
}
|
|
55
|
-
get(type, cursor =
|
|
77
|
+
get(type, cursor = TagCursor.Get()) {
|
|
56
78
|
const tagId = NCSRegister.tags.idPalette.getNumberId(type);
|
|
57
79
|
const tags = this.tags;
|
|
58
80
|
for (let i = 0; i < tags.length; i += 2) {
|
|
@@ -63,7 +85,7 @@ export class NodeTags {
|
|
|
63
85
|
}
|
|
64
86
|
return null;
|
|
65
87
|
}
|
|
66
|
-
getChild(type, cursor =
|
|
88
|
+
getChild(type, cursor = TagCursor.Get()) {
|
|
67
89
|
for (const child of this.node.traverseChildren()) {
|
|
68
90
|
const found = child.tags.get(type, cursor);
|
|
69
91
|
if (found)
|
|
@@ -81,7 +103,7 @@ export class NodeTags {
|
|
|
81
103
|
}
|
|
82
104
|
return tags;
|
|
83
105
|
}
|
|
84
|
-
getParent(type, cursor =
|
|
106
|
+
getParent(type, cursor = TagCursor.Get()) {
|
|
85
107
|
for (const parent of this.node.traverseParents()) {
|
|
86
108
|
const found = parent.tags.get(type, cursor);
|
|
87
109
|
if (found)
|
|
@@ -91,12 +113,14 @@ export class NodeTags {
|
|
|
91
113
|
}
|
|
92
114
|
getAllParents(type) {
|
|
93
115
|
const tags = [];
|
|
116
|
+
const temp = TagCursor.Get();
|
|
94
117
|
for (const child of this.node.traverseParents()) {
|
|
95
|
-
const found = child.tags.get(type,
|
|
118
|
+
const found = child.tags.get(type, temp);
|
|
96
119
|
if (found) {
|
|
97
120
|
tags.push(TagCursor.Get().setTag(this.node, found.typeId, found.index));
|
|
98
121
|
}
|
|
99
122
|
}
|
|
123
|
+
temp.returnCursor();
|
|
100
124
|
return tags;
|
|
101
125
|
}
|
|
102
126
|
}
|
package/Register/NCSRegister.js
CHANGED
|
@@ -11,7 +11,7 @@ class ItemRegister {
|
|
|
11
11
|
? this.items[this.idPalette.getNumberId(id)]
|
|
12
12
|
: this.items[id];
|
|
13
13
|
if (!item)
|
|
14
|
-
throw new Error(`[${this.itemtype}]: Entry with id ${id} does not exist`);
|
|
14
|
+
throw new Error(`NCS: [${this.itemtype}]: Entry with id ${id} does not exist`);
|
|
15
15
|
return item;
|
|
16
16
|
}
|
|
17
17
|
has(id) {
|
|
@@ -24,7 +24,6 @@ export const registerComponent = (data) => {
|
|
|
24
24
|
nodeCursor.setNode(graph, array._node[i]);
|
|
25
25
|
yield nodeCursor;
|
|
26
26
|
}
|
|
27
|
-
NodeCursor.Retrun(nodeCursor);
|
|
28
27
|
return true;
|
|
29
28
|
},
|
|
30
29
|
*getComponents(graph, cursor = ComponentCursor.Get(), nodeCursor = NodeCursor.Get()) {
|
|
@@ -36,8 +35,6 @@ export const registerComponent = (data) => {
|
|
|
36
35
|
cursor.setInstance(nodeCursor, typeId, i);
|
|
37
36
|
yield cursor;
|
|
38
37
|
}
|
|
39
|
-
ComponentCursor.Retrun(cursor);
|
|
40
|
-
NodeCursor.Retrun(nodeCursor);
|
|
41
38
|
return true;
|
|
42
39
|
},
|
|
43
40
|
set(node, schema, schemaView, cursor = ComponentCursor.Get()) {
|
|
@@ -55,7 +52,7 @@ export const registerComponent = (data) => {
|
|
|
55
52
|
getRequired(node, cursor, nodeCursor) {
|
|
56
53
|
const found = node.components.get(data.type, cursor, nodeCursor);
|
|
57
54
|
if (!found)
|
|
58
|
-
throw new Error(`Node [${node.name}] does not have required component [${data.type}].`);
|
|
55
|
+
throw new Error(`NCS: Node [${node.name}] does not have required component [${data.type}].`);
|
|
59
56
|
return found;
|
|
60
57
|
},
|
|
61
58
|
getChild(node, cursor, nodeCursor) {
|
|
@@ -64,7 +61,7 @@ export const registerComponent = (data) => {
|
|
|
64
61
|
getRequiredChild(node, cursor, nodeCursor) {
|
|
65
62
|
const comp = node.components.getChild(data.type, cursor, nodeCursor);
|
|
66
63
|
if (!comp)
|
|
67
|
-
throw new Error(`Node [${node.name}] does not have a child with required component [${data.type}].`);
|
|
64
|
+
throw new Error(`NCS: Node [${node.name}] does not have a child with required component [${data.type}].`);
|
|
68
65
|
return comp;
|
|
69
66
|
},
|
|
70
67
|
getParent(node, cursor, nodeCursor) {
|
|
@@ -73,7 +70,7 @@ export const registerComponent = (data) => {
|
|
|
73
70
|
getRequiredParent(node, cursor, nodeCursor) {
|
|
74
71
|
const comp = node.components.getParent(data.type, cursor, nodeCursor);
|
|
75
72
|
if (!comp)
|
|
76
|
-
throw new Error(`Node [${node.name}] does not have a parent with required component [${data.type}].`);
|
|
73
|
+
throw new Error(`NCS: Node [${node.name}] does not have a parent with required component [${data.type}].`);
|
|
77
74
|
return comp;
|
|
78
75
|
},
|
|
79
76
|
getAll(node) {
|
|
@@ -27,7 +27,7 @@ export function registerContext(data) {
|
|
|
27
27
|
getRequired: (parent) => {
|
|
28
28
|
const found = parent.context.get(data.type);
|
|
29
29
|
if (!found)
|
|
30
|
-
throw new Error(`Could not find required context type: ${data.type}`);
|
|
30
|
+
throw new Error(`NCS: Could not find required context type: ${data.type}`);
|
|
31
31
|
return found;
|
|
32
32
|
},
|
|
33
33
|
remove: (parent) => {
|
package/Register/registerTag.js
CHANGED
|
@@ -1,17 +1,43 @@
|
|
|
1
1
|
import { NCSRegister } from "./NCSRegister";
|
|
2
|
+
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
2
3
|
import { TagCursor } from "../Tags/TagCursor";
|
|
3
4
|
import { Tag } from "../Tags/Tag";
|
|
4
5
|
export function registerTag(data) {
|
|
5
6
|
const tag = new Tag(null, data);
|
|
6
7
|
const typeId = NCSRegister.tags.register(data.id, tag);
|
|
7
|
-
// const map = TagInstanceMap.registerTag(tag.id);
|
|
8
8
|
const createTag = () => {
|
|
9
9
|
return typeId;
|
|
10
10
|
};
|
|
11
11
|
return Object.assign(createTag, data, {
|
|
12
12
|
tag,
|
|
13
13
|
data,
|
|
14
|
-
|
|
14
|
+
*getNodes(graph, nodeCursor = NodeCursor.Get()) {
|
|
15
|
+
const array = graph._tags[typeId];
|
|
16
|
+
if (!array)
|
|
17
|
+
return false;
|
|
18
|
+
for (let i = 0; i < array._node.length; i++) {
|
|
19
|
+
const slot = array._node[i];
|
|
20
|
+
if (slot < 0)
|
|
21
|
+
continue;
|
|
22
|
+
nodeCursor.setNode(graph, array._node[i]);
|
|
23
|
+
yield nodeCursor;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
},
|
|
27
|
+
*getTags(graph, cursor = TagCursor.Get(), nodeCursor = NodeCursor.Get()) {
|
|
28
|
+
const array = graph._tags[typeId];
|
|
29
|
+
if (!array)
|
|
30
|
+
return false;
|
|
31
|
+
for (let i = 0; i < array._node.length; i++) {
|
|
32
|
+
const slot = array._node[i];
|
|
33
|
+
if (slot < 0)
|
|
34
|
+
continue;
|
|
35
|
+
nodeCursor.setNode(graph, slot);
|
|
36
|
+
cursor.setTag(nodeCursor, typeId, i);
|
|
37
|
+
yield cursor;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
},
|
|
15
41
|
// getTags: (graph: Graph) => map.getItems(graph),
|
|
16
42
|
getChild(parent, cursor) {
|
|
17
43
|
return parent.tags.getChild(data.id, cursor);
|
package/Schema/Schema.js
CHANGED
|
@@ -11,7 +11,9 @@ const traverseCreate = (parent, properties, index) => {
|
|
|
11
11
|
parent.children ??= [];
|
|
12
12
|
for (let i = 0; i < properties.length; i++) {
|
|
13
13
|
const data = properties[i];
|
|
14
|
-
if (typeof data.value == "object" &&
|
|
14
|
+
if (typeof data.value == "object" &&
|
|
15
|
+
!data.children?.length &&
|
|
16
|
+
!Array.isArray(data.value)) {
|
|
15
17
|
data.children ??= [];
|
|
16
18
|
for (const key in data.value) {
|
|
17
19
|
const value = data.value[key];
|
|
@@ -115,7 +117,11 @@ export class Schema {
|
|
|
115
117
|
const data = [];
|
|
116
118
|
for (const id in shape) {
|
|
117
119
|
const value = shape[id];
|
|
118
|
-
if (typeof value == "object"
|
|
120
|
+
if (typeof value == "object" &&
|
|
121
|
+
value !== null &&
|
|
122
|
+
typeof value !== "undefined" &&
|
|
123
|
+
!Array.isArray(id) &&
|
|
124
|
+
!ArrayBuffer.isView(value)) {
|
|
119
125
|
data.push(traverseCreateFromObject(value, {
|
|
120
126
|
id,
|
|
121
127
|
value: {},
|
|
@@ -191,7 +197,7 @@ export class Schema {
|
|
|
191
197
|
view = new SchemaView(this, data.id, meta, byteOffsets, byteSize, data, this._binaryObjectCursorClass);
|
|
192
198
|
}
|
|
193
199
|
if (!view)
|
|
194
|
-
throw new Error(`Invalid data`);
|
|
200
|
+
throw new Error(`NCS: Invalid data`);
|
|
195
201
|
const viewIndex = this.viewIdPalettew.register(data.id);
|
|
196
202
|
this.views[viewIndex] = view;
|
|
197
203
|
return view;
|
package/Schema/SchemaView.js
CHANGED
|
@@ -103,7 +103,7 @@ export class SchemaView {
|
|
|
103
103
|
}
|
|
104
104
|
return current;
|
|
105
105
|
}
|
|
106
|
-
throw new Error(`Invalid create data`);
|
|
106
|
+
throw new Error(`NCS: Invalid create data`);
|
|
107
107
|
}
|
|
108
108
|
createCursor() {
|
|
109
109
|
return new this._cursorClass(this, this.meta, this._createData, this.byteOffset);
|
package/Tags/TagCursor.d.ts
CHANGED