@amodx/ncs 0.0.1 → 0.0.2
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 +78 -0
- package/Components/ComponentArray.d.ts +30 -0
- package/Components/ComponentArray.js +82 -0
- package/Components/ComponentCursor.d.ts +27 -0
- package/Components/ComponentCursor.js +72 -0
- package/Contexts/Context.types.d.ts +76 -0
- package/Contexts/ContextArray.d.ts +14 -0
- package/Contexts/ContextArray.js +47 -0
- package/Contexts/ContextCursor.d.ts +20 -0
- package/Contexts/ContextCursor.js +39 -0
- package/Data/SerializedData.types.d.ts +44 -0
- package/Data/deserializeComponent.d.ts +3 -0
- package/Data/deserializeComponent.js +3 -0
- package/Data/deserializeNode.d.ts +3 -0
- package/Data/deserializeNode.js +34 -0
- package/Data/serializeComponent.d.ts +7 -0
- package/Data/serializeComponent.js +36 -0
- package/Data/serializeNode.d.ts +13 -0
- package/Data/serializeNode.js +83 -0
- package/Functional.d.ts +12 -0
- package/Functional.js +31 -0
- package/Graphs/Graph.d.ts +19 -21
- package/Graphs/Graph.js +85 -74
- package/NCS.d.ts +79 -48
- package/NCS.js +108 -32
- package/Nodes/Node.types.d.ts +39 -0
- package/Nodes/Node.types.js +16 -0
- package/Nodes/NodeArray.d.ts +25 -0
- package/Nodes/NodeArray.js +96 -0
- package/Nodes/NodeComponents.d.ts +19 -0
- package/Nodes/NodeComponents.js +180 -0
- package/Nodes/NodeContext.d.ts +14 -0
- package/Nodes/NodeContext.js +107 -0
- package/Nodes/NodeCursor.d.ts +65 -0
- package/Nodes/NodeCursor.js +348 -0
- package/Nodes/NodeEvents.d.ts +10 -13
- package/Nodes/NodeEvents.js +51 -26
- package/Nodes/NodeId.d.ts +4 -13
- package/Nodes/NodeId.js +16 -48
- package/Nodes/NodeObservers.d.ts +35 -20
- package/Nodes/NodeObservers.js +162 -37
- package/Nodes/NodeTags.d.ts +17 -0
- package/Nodes/NodeTags.js +102 -0
- package/Pools/NCSPools.d.ts +27 -4
- package/Pools/NCSPools.js +14 -2
- package/Queries/Query.types.d.ts +8 -0
- package/Queries/QueryInstance.d.ts +6 -4
- package/Queries/QueryInstance.js +89 -44
- package/Queries/QueryPrototype.d.ts +1 -1
- package/Register/NCSRegister.d.ts +17 -9
- package/Register/NCSRegister.js +25 -2
- package/Register/registerComponent.d.ts +31 -25
- package/Register/registerComponent.js +88 -36
- package/Register/registerContext.d.ts +10 -13
- package/Register/registerContext.js +13 -18
- package/Register/registerSystem.d.ts +1 -1
- package/Register/registerSystem.js +1 -1
- package/Register/registerTag.d.ts +15 -17
- package/Register/registerTag.js +20 -23
- package/Schema/Functions/createBaseSchemaCursor.d.ts +18 -0
- package/Schema/Functions/createBaseSchemaCursor.js +34 -0
- package/Schema/Functions/createSchemaBinaryObjectCursorClass.d.ts +22 -0
- package/Schema/Functions/createSchemaBinaryObjectCursorClass.js +134 -0
- package/Schema/Functions/createSchemaIndex.d.ts +3 -0
- package/Schema/Functions/createSchemaIndex.js +18 -0
- package/Schema/Functions/createSchemaObjectCursorClass.d.ts +18 -0
- package/Schema/Functions/createSchemaObjectCursorClass.js +66 -0
- package/Schema/Functions/createSchemaTypedArrayCursorClass.d.ts +17 -0
- package/Schema/Functions/createSchemaTypedArrayCursorClass.js +66 -0
- package/Schema/Property/Property.d.ts +11 -0
- package/Schema/Property/Property.js +16 -0
- package/Schema/Property/Property.types.d.ts +26 -0
- package/Schema/Property/Property.types.js +20 -0
- package/Schema/Schema.d.ts +28 -0
- package/Schema/Schema.js +223 -0
- package/Schema/Schema.types.d.ts +59 -0
- package/Schema/Schema.types.js +8 -0
- package/Schema/SchemaArray.d.ts +23 -0
- package/Schema/SchemaArray.js +87 -0
- package/Schema/SchemaArrayCursor.d.ts +19 -0
- package/Schema/SchemaArrayCursor.js +56 -0
- package/Schema/SchemaView.d.ts +24 -0
- package/Schema/SchemaView.js +141 -0
- package/Systems/{SystemData.d.ts → System.types.d.ts} +0 -4
- package/Systems/SystemInstance.d.ts +6 -4
- package/Systems/SystemInstance.js +14 -8
- package/Systems/SystemPrototype.d.ts +1 -1
- package/Systems/SystemPrototype.js +0 -1
- package/Tags/Tag.d.ts +1 -1
- package/Tags/Tag.js +1 -1
- package/Tags/{TagData.d.ts → Tag.types.d.ts} +0 -17
- package/Tags/TagArray.d.ts +18 -0
- package/Tags/TagArray.js +37 -0
- package/Tags/TagCursor.d.ts +20 -0
- package/Tags/TagCursor.js +45 -0
- package/Util/IdPalette.d.ts +13 -0
- package/Util/IdPalette.js +38 -0
- package/{Pools → Util}/ItemPool.d.ts +2 -3
- package/{Pools → Util}/ItemPool.js +2 -4
- package/Util/Observable.d.ts +28 -0
- package/Util/Observable.js +58 -0
- package/Util/Util.types.d.ts +4 -0
- package/index.d.ts +16 -6
- package/index.js +24 -6
- package/package.json +1 -1
- package/Components/ComponentData.d.ts +0 -112
- package/Components/ComponentInstance.d.ts +0 -36
- package/Components/ComponentInstance.js +0 -125
- package/Components/ComponentInstanceMap.d.ts +0 -7
- package/Components/ComponentInstanceMap.js +0 -15
- package/Components/ComponentObservers.d.ts +0 -8
- package/Components/ComponentObservers.js +0 -13
- package/Components/ComponentPipelines.d.ts +0 -16
- package/Components/ComponentPipelines.js +0 -33
- package/Components/ComponentPrototype.d.ts +0 -17
- package/Components/ComponentPrototype.js +0 -73
- package/Contexts/ContextData.d.ts +0 -59
- package/Contexts/ContextInstance.d.ts +0 -14
- package/Contexts/ContextInstance.js +0 -26
- package/Contexts/ContextInstanceAnchor.d.ts +0 -15
- package/Contexts/ContextInstanceAnchor.js +0 -33
- package/Contexts/ContextPrototype.d.ts +0 -9
- package/Contexts/ContextPrototype.js +0 -19
- package/Graphs/GraphEvents.d.ts +0 -9
- package/Graphs/GraphEvents.js +0 -35
- package/Graphs/GraphObservers.d.ts +0 -9
- package/Graphs/GraphObservers.js +0 -6
- package/Graphs/GraphUpdate.d.ts +0 -13
- package/Graphs/GraphUpdate.js +0 -38
- package/Maps/ItemGraphMap.d.ts +0 -11
- package/Maps/ItemGraphMap.js +0 -30
- package/Maps/ItemNodeMap.d.ts +0 -17
- package/Maps/ItemNodeMap.js +0 -41
- package/Nodes/Components/NodeComponentObservers.d.ts +0 -15
- package/Nodes/Components/NodeComponentObservers.js +0 -33
- package/Nodes/Components/NodeComponents.d.ts +0 -22
- package/Nodes/Components/NodeComponents.js +0 -107
- package/Nodes/Context/NodeContext.d.ts +0 -13
- package/Nodes/Context/NodeContext.js +0 -45
- package/Nodes/NodeData.d.ts +0 -40
- package/Nodes/NodeInstance.d.ts +0 -50
- package/Nodes/NodeInstance.js +0 -202
- package/Nodes/NodePipelines.d.ts +0 -16
- package/Nodes/NodePipelines.js +0 -33
- package/Nodes/Tags/NodeTagObservers.d.ts +0 -15
- package/Nodes/Tags/NodeTagObservers.js +0 -33
- package/Nodes/Tags/NodeTags.d.ts +0 -21
- package/Nodes/Tags/NodeTags.js +0 -95
- package/Queries/QueryData.d.ts +0 -8
- package/Register/ItemRegister.d.ts +0 -7
- package/Register/ItemRegister.js +0 -24
- package/Register/registerTrait.d.ts +0 -15
- package/Register/registerTrait.js +0 -39
- package/Tags/TagInstance.d.ts +0 -13
- package/Tags/TagInstance.js +0 -17
- package/Tags/TagInstanceMap.d.ts +0 -7
- package/Tags/TagInstanceMap.js +0 -15
- package/Tags/TagPrototype.d.ts +0 -16
- package/Tags/TagPrototype.js +0 -34
- package/Traits/TraitContaienrObservers.d.ts +0 -15
- package/Traits/TraitContaienrObservers.js +0 -33
- package/Traits/TraitContainer.d.ts +0 -22
- package/Traits/TraitContainer.js +0 -114
- package/Traits/TraitData.d.ts +0 -106
- package/Traits/TraitInstance.d.ts +0 -35
- package/Traits/TraitInstance.js +0 -115
- package/Traits/TraitInstanceMap.d.ts +0 -7
- package/Traits/TraitInstanceMap.js +0 -15
- package/Traits/TraitObservers.d.ts +0 -8
- package/Traits/TraitObservers.js +0 -13
- package/Traits/TraitPipelines.d.ts +0 -16
- package/Traits/TraitPipelines.js +0 -33
- package/Traits/TraitPrototype.d.ts +0 -16
- package/Traits/TraitPrototype.js +0 -74
- /package/Components/{ComponentData.js → Component.types.js} +0 -0
- /package/Contexts/{ContextData.js → Context.types.js} +0 -0
- /package/{Nodes/NodeData.js → Data/SerializedData.types.js} +0 -0
- /package/Queries/{QueryData.js → Query.types.js} +0 -0
- /package/Systems/{SystemData.js → System.types.js} +0 -0
- /package/Tags/{TagData.js → Tag.types.js} +0 -0
- /package/{Traits/TraitData.js → Util/Util.types.js} +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CreateComponentData } from "../Components/Component.types";
|
|
2
|
+
export type CreateNodeData = [
|
|
3
|
+
/**
|
|
4
|
+
* The unique 128 bit identifier of the node.
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
id: bigint | string | null,
|
|
8
|
+
/**
|
|
9
|
+
* The name of the node.
|
|
10
|
+
*/
|
|
11
|
+
name: string,
|
|
12
|
+
/**
|
|
13
|
+
* The components of the node.
|
|
14
|
+
*/
|
|
15
|
+
components: CreateComponentData[] | null,
|
|
16
|
+
/**
|
|
17
|
+
* The tags of the node.
|
|
18
|
+
*/
|
|
19
|
+
tags: number[] | null,
|
|
20
|
+
/**
|
|
21
|
+
* The children nodes of the node.
|
|
22
|
+
*/
|
|
23
|
+
children: CreateNodeData[] | null
|
|
24
|
+
];
|
|
25
|
+
export declare enum NodeObserverIds {
|
|
26
|
+
Disposed = 0,
|
|
27
|
+
Enabled = 1,
|
|
28
|
+
Parented = 2,
|
|
29
|
+
RemovedFromParent = 3,
|
|
30
|
+
ChildAdded = 4,
|
|
31
|
+
ChildRemoved = 5,
|
|
32
|
+
ChildrenUpdated = 6,
|
|
33
|
+
ComponentAdded = 7,
|
|
34
|
+
ComponentRemoved = 8,
|
|
35
|
+
ComponentsUpdated = 9,
|
|
36
|
+
TagAdded = 10,
|
|
37
|
+
TagRemoved = 11,
|
|
38
|
+
TagsUpdated = 12
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export var NodeObserverIds;
|
|
2
|
+
(function (NodeObserverIds) {
|
|
3
|
+
NodeObserverIds[NodeObserverIds["Disposed"] = 0] = "Disposed";
|
|
4
|
+
NodeObserverIds[NodeObserverIds["Enabled"] = 1] = "Enabled";
|
|
5
|
+
NodeObserverIds[NodeObserverIds["Parented"] = 2] = "Parented";
|
|
6
|
+
NodeObserverIds[NodeObserverIds["RemovedFromParent"] = 3] = "RemovedFromParent";
|
|
7
|
+
NodeObserverIds[NodeObserverIds["ChildAdded"] = 4] = "ChildAdded";
|
|
8
|
+
NodeObserverIds[NodeObserverIds["ChildRemoved"] = 5] = "ChildRemoved";
|
|
9
|
+
NodeObserverIds[NodeObserverIds["ChildrenUpdated"] = 6] = "ChildrenUpdated";
|
|
10
|
+
NodeObserverIds[NodeObserverIds["ComponentAdded"] = 7] = "ComponentAdded";
|
|
11
|
+
NodeObserverIds[NodeObserverIds["ComponentRemoved"] = 8] = "ComponentRemoved";
|
|
12
|
+
NodeObserverIds[NodeObserverIds["ComponentsUpdated"] = 9] = "ComponentsUpdated";
|
|
13
|
+
NodeObserverIds[NodeObserverIds["TagAdded"] = 10] = "TagAdded";
|
|
14
|
+
NodeObserverIds[NodeObserverIds["TagRemoved"] = 11] = "TagRemoved";
|
|
15
|
+
NodeObserverIds[NodeObserverIds["TagsUpdated"] = 12] = "TagsUpdated";
|
|
16
|
+
})(NodeObserverIds || (NodeObserverIds = {}));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IdPalette } from "../Util/IdPalette";
|
|
2
|
+
import { Observable } from "../Util/Observable";
|
|
3
|
+
export declare class NodeArray {
|
|
4
|
+
_freeSlots: number[];
|
|
5
|
+
_eventPalette: IdPalette;
|
|
6
|
+
/**A map of node ids to their index in the run time array */
|
|
7
|
+
_idMap: Map<bigint, number>;
|
|
8
|
+
/**A map of node run time indexes to their unique id */
|
|
9
|
+
_indexMap: bigint[];
|
|
10
|
+
_names: string[];
|
|
11
|
+
_events: Observable<any>[][];
|
|
12
|
+
_observers: Observable<any>[][];
|
|
13
|
+
_parents: number[];
|
|
14
|
+
_children: number[][];
|
|
15
|
+
_components: number[][];
|
|
16
|
+
_tags: number[][];
|
|
17
|
+
_context: number[][];
|
|
18
|
+
_disposed: boolean[];
|
|
19
|
+
_enabled: boolean[];
|
|
20
|
+
_hasObservers: boolean[];
|
|
21
|
+
addNode(id: bigint | null, parent: number, name: string): number;
|
|
22
|
+
removeNode(slot: number): boolean;
|
|
23
|
+
addNodeId(index: number, id: bigint): void;
|
|
24
|
+
removeNodeId(id: bigint): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { IdPalette } from "../Util/IdPalette";
|
|
2
|
+
import { NCSPools } from "../Pools/NCSPools";
|
|
3
|
+
import { NodeObserverIds } from "./Node.types";
|
|
4
|
+
const observerValues = Object.values(NodeObserverIds)
|
|
5
|
+
.map((_) => Number(_))
|
|
6
|
+
.filter((v) => !Number.isNaN(v));
|
|
7
|
+
const observersArrays = [];
|
|
8
|
+
for (let i = 0; i < observerValues.length; i++) {
|
|
9
|
+
observersArrays[observerValues[i]] = [];
|
|
10
|
+
}
|
|
11
|
+
export class NodeArray {
|
|
12
|
+
_freeSlots = [];
|
|
13
|
+
_eventPalette = new IdPalette();
|
|
14
|
+
/**A map of node ids to their index in the run time array */
|
|
15
|
+
_idMap = new Map();
|
|
16
|
+
/**A map of node run time indexes to their unique id */
|
|
17
|
+
_indexMap = [];
|
|
18
|
+
_names = [];
|
|
19
|
+
_events = [];
|
|
20
|
+
_observers = structuredClone(observersArrays);
|
|
21
|
+
_parents = [];
|
|
22
|
+
_children = [];
|
|
23
|
+
_components = [];
|
|
24
|
+
_tags = [];
|
|
25
|
+
_context = [];
|
|
26
|
+
_disposed = [];
|
|
27
|
+
_enabled = [];
|
|
28
|
+
_hasObservers = [];
|
|
29
|
+
addNode(id, parent, name) {
|
|
30
|
+
let slot = this._freeSlots.length
|
|
31
|
+
? this._freeSlots.shift()
|
|
32
|
+
: this._parents.length;
|
|
33
|
+
id && this.addNodeId(slot, id);
|
|
34
|
+
this._parents[slot] = parent;
|
|
35
|
+
this._names[slot] = name;
|
|
36
|
+
this._disposed[slot] = false;
|
|
37
|
+
this._enabled[slot] = true;
|
|
38
|
+
this._hasObservers[slot] = false;
|
|
39
|
+
return slot;
|
|
40
|
+
}
|
|
41
|
+
removeNode(slot) {
|
|
42
|
+
if (this._parents[slot] === undefined)
|
|
43
|
+
return false;
|
|
44
|
+
this._freeSlots.push(slot);
|
|
45
|
+
this._indexMap[slot] && this.removeNodeId(this._indexMap[slot]);
|
|
46
|
+
this._parents[slot] = -1;
|
|
47
|
+
this._names[slot] = "";
|
|
48
|
+
this._disposed[slot] = true;
|
|
49
|
+
this._enabled[slot] = false;
|
|
50
|
+
this._hasObservers[slot] = false;
|
|
51
|
+
for (let i = 0; i < observerValues.length; i++) {
|
|
52
|
+
const observer = this._observers[i][slot];
|
|
53
|
+
if (observer !== undefined) {
|
|
54
|
+
NCSPools.observers.addItem(observer);
|
|
55
|
+
this._events[i][slot] = undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (let i = 0; i < this._eventPalette.size; i++) {
|
|
59
|
+
const observer = this._events[i][slot];
|
|
60
|
+
if (observer !== undefined) {
|
|
61
|
+
NCSPools.observers.addItem(observer);
|
|
62
|
+
this._events[i][slot] = undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (this._children[slot] !== undefined) {
|
|
66
|
+
this._children[slot].length = 0;
|
|
67
|
+
NCSPools.numberArray.addItem(this._children[slot]);
|
|
68
|
+
this._children[slot] = undefined;
|
|
69
|
+
}
|
|
70
|
+
if (this._components[slot] !== undefined) {
|
|
71
|
+
this._components[slot].length = 0;
|
|
72
|
+
NCSPools.numberArray.addItem(this._components[slot]);
|
|
73
|
+
this._components[slot] = undefined;
|
|
74
|
+
}
|
|
75
|
+
if (this._tags[slot] !== undefined) {
|
|
76
|
+
this._tags[slot].length = 0;
|
|
77
|
+
NCSPools.numberArray.addItem(this._tags[slot]);
|
|
78
|
+
this._tags[slot] = undefined;
|
|
79
|
+
}
|
|
80
|
+
if (this._context[slot] !== undefined) {
|
|
81
|
+
this._context[slot].length = 0;
|
|
82
|
+
NCSPools.numberArray.addItem(this._context[slot]);
|
|
83
|
+
this._context[slot] = undefined;
|
|
84
|
+
}
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
addNodeId(index, id) {
|
|
88
|
+
this._idMap.set(id, index);
|
|
89
|
+
this._indexMap[index] = id;
|
|
90
|
+
}
|
|
91
|
+
removeNodeId(id) {
|
|
92
|
+
const index = this._idMap.get(id);
|
|
93
|
+
this._indexMap[index] = undefined;
|
|
94
|
+
this._idMap.delete(id);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CreateComponentData } from "../Components/Component.types";
|
|
2
|
+
import { ComponentCursor } from "../Components/ComponentCursor";
|
|
3
|
+
import { NodeCursor } from "./NodeCursor";
|
|
4
|
+
export declare class NodeComponents {
|
|
5
|
+
static Get(): NodeComponents;
|
|
6
|
+
static Retrun(cursor: NodeComponents): boolean;
|
|
7
|
+
get components(): number[];
|
|
8
|
+
node: NodeCursor;
|
|
9
|
+
private constructor();
|
|
10
|
+
dispose(): void;
|
|
11
|
+
add(comp: CreateComponentData): number;
|
|
12
|
+
remove(type: string): true | undefined;
|
|
13
|
+
has(type: string): boolean;
|
|
14
|
+
get(type: string, cursor?: ComponentCursor<{}, any, any>): ComponentCursor<any, any, any> | null;
|
|
15
|
+
getAll(type: string): ComponentCursor<any, any, any>[];
|
|
16
|
+
removeAll(type: string): boolean;
|
|
17
|
+
getChild(type: string, cursor?: ComponentCursor<{}, any, any>): ComponentCursor<any, any, any> | null;
|
|
18
|
+
getParent(type: string, cursor?: ComponentCursor<{}, any, any>): ComponentCursor<any, any, any> | null;
|
|
19
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { ComponentCursor } from "../Components/ComponentCursor";
|
|
2
|
+
import { NCSRegister } from "../Register/NCSRegister";
|
|
3
|
+
import { ComponentArray } from "../Components/ComponentArray";
|
|
4
|
+
import { NCSPools } from "../Pools/NCSPools";
|
|
5
|
+
const defaultCursor = ComponentCursor.Get();
|
|
6
|
+
export class NodeComponents {
|
|
7
|
+
static Get() {
|
|
8
|
+
const cursor = NCSPools.nodeComponents.get();
|
|
9
|
+
if (!cursor)
|
|
10
|
+
return new NodeComponents();
|
|
11
|
+
return cursor;
|
|
12
|
+
}
|
|
13
|
+
static Retrun(cursor) {
|
|
14
|
+
return NCSPools.nodeComponents.addItem(cursor);
|
|
15
|
+
}
|
|
16
|
+
get components() {
|
|
17
|
+
return this.node.arrays._components[this.node.index] || null;
|
|
18
|
+
}
|
|
19
|
+
node;
|
|
20
|
+
constructor() { }
|
|
21
|
+
dispose() {
|
|
22
|
+
if (!this.components)
|
|
23
|
+
return;
|
|
24
|
+
const components = this.components;
|
|
25
|
+
for (let i = 0; i < components.length; i += 2) {
|
|
26
|
+
defaultCursor.setInstance(this.node, components[i], components[i + 1]);
|
|
27
|
+
defaultCursor.dispose();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
add(comp) {
|
|
31
|
+
if (!this.components) {
|
|
32
|
+
this.node.arrays._components[this.node.index] =
|
|
33
|
+
NCSPools.numberArray.get() || [];
|
|
34
|
+
}
|
|
35
|
+
const compProto = NCSRegister.components.get(comp[0]);
|
|
36
|
+
const typeId = NCSRegister.components.idPalette.getNumberId(compProto.type);
|
|
37
|
+
let compArray = this.node.graph._components[typeId];
|
|
38
|
+
if (!compArray) {
|
|
39
|
+
compArray = new ComponentArray(this.node.graph, typeId);
|
|
40
|
+
if (compArray.proto.update) {
|
|
41
|
+
this.node.graph._updatingComponents.push(compArray);
|
|
42
|
+
}
|
|
43
|
+
this.node.graph._components[typeId] = compArray;
|
|
44
|
+
}
|
|
45
|
+
let compData = null;
|
|
46
|
+
if (comp[3]) {
|
|
47
|
+
compData = compArray.schemaArray.schema
|
|
48
|
+
.getView(comp[2] || "default")
|
|
49
|
+
.fromRemote(comp[1]);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
compData = compProto.schema
|
|
53
|
+
? compProto.schema.getView(comp[2] || "default")?.createData(comp[1]) ||
|
|
54
|
+
null
|
|
55
|
+
: null;
|
|
56
|
+
}
|
|
57
|
+
const componentIndex = compArray.addComponent(this.node.index, compData, comp[2] || "default");
|
|
58
|
+
comp[0] = "";
|
|
59
|
+
comp[1] = null;
|
|
60
|
+
comp[2] = null;
|
|
61
|
+
comp[3] = null;
|
|
62
|
+
NCSPools.createComponentData.addItem(comp);
|
|
63
|
+
this.components.push(typeId, componentIndex);
|
|
64
|
+
compArray.observers.nodeAdded.notify(this.node.index);
|
|
65
|
+
if (this.node.hasObservers) {
|
|
66
|
+
defaultCursor.setInstance(this.node, typeId, componentIndex);
|
|
67
|
+
this.node.observers.isComponentAddedSet &&
|
|
68
|
+
this.node.observers.componentAdded.notify(defaultCursor);
|
|
69
|
+
this.node.observers.isComponentsUpdatedSet &&
|
|
70
|
+
this.node.observers.componentsUpdated.notify(defaultCursor);
|
|
71
|
+
}
|
|
72
|
+
return componentIndex;
|
|
73
|
+
}
|
|
74
|
+
remove(type) {
|
|
75
|
+
const components = this.components;
|
|
76
|
+
if (!components)
|
|
77
|
+
return;
|
|
78
|
+
let removeIndex = -1;
|
|
79
|
+
let removeComponentIndex = -1;
|
|
80
|
+
const numberId = NCSRegister.components.idPalette.getNumberId(type);
|
|
81
|
+
for (let i = 0; i < components.length; i += 2) {
|
|
82
|
+
if (components[i] == numberId) {
|
|
83
|
+
removeIndex = i;
|
|
84
|
+
removeComponentIndex = components[i + 1];
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (removeIndex == -1)
|
|
89
|
+
return;
|
|
90
|
+
defaultCursor.setInstance(this.node, numberId, removeComponentIndex);
|
|
91
|
+
this.components.splice(removeIndex, 2);
|
|
92
|
+
if (this.node.hasObservers) {
|
|
93
|
+
this.node.observers.isComponentRemovedSet &&
|
|
94
|
+
this.node.observers.componentRemoved.notify(defaultCursor);
|
|
95
|
+
this.node.observers.isComponentsUpdatedSet &&
|
|
96
|
+
this.node.observers.componentsUpdated.notify(defaultCursor);
|
|
97
|
+
}
|
|
98
|
+
defaultCursor.dispose();
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
has(type) {
|
|
102
|
+
const components = this.components;
|
|
103
|
+
if (!components)
|
|
104
|
+
return false;
|
|
105
|
+
const numberId = NCSRegister.components.idPalette.getNumberId(type);
|
|
106
|
+
for (let i = 0; i < components.length; i += 2) {
|
|
107
|
+
if (components[i] == numberId) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
get(type, cursor = ComponentCursor.Get()) {
|
|
114
|
+
const components = this.components;
|
|
115
|
+
if (!components)
|
|
116
|
+
return null;
|
|
117
|
+
const numberId = NCSRegister.components.idPalette.getNumberId(type);
|
|
118
|
+
for (let i = 0; i < components.length; i += 2) {
|
|
119
|
+
if (components[i] == numberId) {
|
|
120
|
+
cursor.setInstance(this.node, numberId, components[i + 1]);
|
|
121
|
+
return cursor;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
getAll(type) {
|
|
127
|
+
const components = this.components;
|
|
128
|
+
if (!components)
|
|
129
|
+
return [];
|
|
130
|
+
const cursors = [];
|
|
131
|
+
const numberId = NCSRegister.components.idPalette.getNumberId(type);
|
|
132
|
+
for (let i = 0; i < components.length; i += 2) {
|
|
133
|
+
if (components[i] == numberId) {
|
|
134
|
+
const cursor = ComponentCursor.Get();
|
|
135
|
+
cursor.setInstance(this.node, components[i], components[i + 1]);
|
|
136
|
+
cursors.push(cursor);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return cursors;
|
|
140
|
+
}
|
|
141
|
+
removeAll(type) {
|
|
142
|
+
const components = this.components;
|
|
143
|
+
if (!components)
|
|
144
|
+
return false;
|
|
145
|
+
const numberId = NCSRegister.components.idPalette.getNumberId(type);
|
|
146
|
+
for (let i = components.length; i > 0; i -= 2) {
|
|
147
|
+
if (components[i] == numberId) {
|
|
148
|
+
defaultCursor.setInstance(this.node, components[i], components[i + 1]);
|
|
149
|
+
this.components.splice(i, 2);
|
|
150
|
+
if (this.node.hasObservers) {
|
|
151
|
+
this.node.observers.isComponentRemovedSet &&
|
|
152
|
+
this.node.observers.componentRemoved.notify(defaultCursor);
|
|
153
|
+
this.node.observers.isComponentsUpdatedSet &&
|
|
154
|
+
this.node.observers.componentsUpdated.notify(defaultCursor);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
getChild(type, cursor = ComponentCursor.Get()) {
|
|
161
|
+
for (const child of this.node.traverseChildren()) {
|
|
162
|
+
if (!child.components)
|
|
163
|
+
continue;
|
|
164
|
+
const found = child.components.get(type, cursor);
|
|
165
|
+
if (found)
|
|
166
|
+
return found;
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
getParent(type, cursor = ComponentCursor.Get()) {
|
|
171
|
+
for (const parent of this.node.traverseParents()) {
|
|
172
|
+
if (!parent.components)
|
|
173
|
+
continue;
|
|
174
|
+
const found = parent.components.get(type, cursor);
|
|
175
|
+
if (found)
|
|
176
|
+
return found;
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ContextCursor } from "../Contexts/ContextCursor";
|
|
2
|
+
import { CreateContextData } from "../Contexts/Context.types";
|
|
3
|
+
import { NodeCursor } from "./NodeCursor";
|
|
4
|
+
export declare class NodeContext {
|
|
5
|
+
node: NodeCursor;
|
|
6
|
+
static Get(): NodeContext;
|
|
7
|
+
static Retrun(cursor: NodeContext): boolean;
|
|
8
|
+
get context(): number[];
|
|
9
|
+
private constructor();
|
|
10
|
+
dispose(): void;
|
|
11
|
+
add(contextData: CreateContextData): number;
|
|
12
|
+
remove(type: string): boolean;
|
|
13
|
+
get(type: string): ContextCursor | null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ContextCursor } from "../Contexts/ContextCursor";
|
|
2
|
+
import { NCSRegister } from "../Register/NCSRegister";
|
|
3
|
+
import { NodeCursor } from "./NodeCursor";
|
|
4
|
+
import { NCSPools } from "../Pools/NCSPools";
|
|
5
|
+
export class NodeContext {
|
|
6
|
+
node;
|
|
7
|
+
static Get() {
|
|
8
|
+
const cursor = NCSPools.nodeContext.get();
|
|
9
|
+
if (!cursor)
|
|
10
|
+
return new NodeContext();
|
|
11
|
+
return cursor;
|
|
12
|
+
}
|
|
13
|
+
static Retrun(cursor) {
|
|
14
|
+
return NCSPools.nodeContext.addItem(cursor);
|
|
15
|
+
}
|
|
16
|
+
get context() {
|
|
17
|
+
return this.node.arrays._context[this.node.index];
|
|
18
|
+
}
|
|
19
|
+
constructor() { }
|
|
20
|
+
dispose() {
|
|
21
|
+
if (!this.context)
|
|
22
|
+
return;
|
|
23
|
+
const context = this.context;
|
|
24
|
+
const defaultCursor = ContextCursor.Get();
|
|
25
|
+
for (let i = 0; i < context.length; i += 2) {
|
|
26
|
+
defaultCursor.setContext(this.node, context[i]);
|
|
27
|
+
defaultCursor.dispose();
|
|
28
|
+
}
|
|
29
|
+
ContextCursor.Retrun(defaultCursor);
|
|
30
|
+
}
|
|
31
|
+
add(contextData) {
|
|
32
|
+
const cursor = ContextCursor.Get();
|
|
33
|
+
if (!this.context) {
|
|
34
|
+
this.node.arrays._context[this.node.index] =
|
|
35
|
+
NCSPools.numberArray.get() || [];
|
|
36
|
+
}
|
|
37
|
+
const context = this.context;
|
|
38
|
+
for (let i = 0; i < context.length; i++) {
|
|
39
|
+
cursor.setContext(this.node, context[i]);
|
|
40
|
+
if (cursor.type == contextData[0])
|
|
41
|
+
return cursor.index;
|
|
42
|
+
}
|
|
43
|
+
const contextType = NCSRegister.contexts.get(contextData[0]);
|
|
44
|
+
const typeId = NCSRegister.contexts.idPalette.getNumberId(contextData[0]);
|
|
45
|
+
const newContext = this.node.graph._contexts.addContext(typeId, [this.node.index], contextType, contextType.schema
|
|
46
|
+
? contextType.schema
|
|
47
|
+
.getView(contextData[2] || "default")
|
|
48
|
+
.createData(contextData[1])
|
|
49
|
+
: null, contextData[3]);
|
|
50
|
+
context.push(newContext);
|
|
51
|
+
cursor.setContext(this.node, newContext);
|
|
52
|
+
contextData[0] = "";
|
|
53
|
+
contextData[1] = null;
|
|
54
|
+
contextData[2] = null;
|
|
55
|
+
contextData[3] = null;
|
|
56
|
+
NCSPools.createContextData.addItem(contextData);
|
|
57
|
+
ContextCursor.Retrun(cursor);
|
|
58
|
+
return newContext;
|
|
59
|
+
}
|
|
60
|
+
remove(type) {
|
|
61
|
+
const cursor = ContextCursor.Get();
|
|
62
|
+
const context = this.context;
|
|
63
|
+
for (let i = 0; i < context.length; i++) {
|
|
64
|
+
cursor.setContext(this.node, context[i]);
|
|
65
|
+
if (cursor.type == type) {
|
|
66
|
+
context.splice(i, 1);
|
|
67
|
+
for (let n = 0; n < cursor.nodes.length; n++) {
|
|
68
|
+
if (cursor.nodes[n] == this.node.index) {
|
|
69
|
+
cursor.nodes.splice(n, 1);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
ContextCursor.Retrun(cursor);
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
ContextCursor.Retrun(cursor);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
get(type) {
|
|
81
|
+
const context = this.context;
|
|
82
|
+
const cursor = ContextCursor.Get();
|
|
83
|
+
if (context) {
|
|
84
|
+
for (let i = 0; i < context.length; i++) {
|
|
85
|
+
cursor.setContext(this.node, context[i]);
|
|
86
|
+
if (cursor.type == type)
|
|
87
|
+
return cursor;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const parentCursor = NodeCursor.Get();
|
|
91
|
+
for (const parent of this.node.traverseParents(parentCursor)) {
|
|
92
|
+
if (this.node.arrays._context[parent.index]) {
|
|
93
|
+
const context = this.node.arrays._context[parent.index];
|
|
94
|
+
for (let i = 0; i < context.length; i++) {
|
|
95
|
+
cursor.setContext(parent, context[i]);
|
|
96
|
+
if (cursor.type == type) {
|
|
97
|
+
//@todo add anchor
|
|
98
|
+
cursor.setContext(parent, context[i]);
|
|
99
|
+
return cursor;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
NodeCursor.Retrun(parentCursor);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Graph } from "../Graphs/Graph";
|
|
2
|
+
import { NodeEvents } from "./NodeEvents";
|
|
3
|
+
import { NodeObservers } from "./NodeObservers";
|
|
4
|
+
import { NodeContext } from "./NodeContext";
|
|
5
|
+
import { NodeComponents } from "./NodeComponents";
|
|
6
|
+
import { NodeTags } from "./NodeTags";
|
|
7
|
+
import { ComponentCursor } from "../Components/ComponentCursor";
|
|
8
|
+
import { TagCursor } from "../Tags/TagCursor";
|
|
9
|
+
export interface NodeCursor {
|
|
10
|
+
}
|
|
11
|
+
export declare class NodeCursor {
|
|
12
|
+
static Get(): NodeCursor;
|
|
13
|
+
static Retrun(cursor: NodeCursor): void;
|
|
14
|
+
clear(events: boolean, context: boolean, observers: boolean, compoents: boolean, tags: boolean): void;
|
|
15
|
+
get index(): number;
|
|
16
|
+
get parentIndex(): number;
|
|
17
|
+
get id(): bigint | null;
|
|
18
|
+
get name(): string;
|
|
19
|
+
private _events;
|
|
20
|
+
get events(): NodeEvents;
|
|
21
|
+
get hasEvents(): boolean;
|
|
22
|
+
private _context;
|
|
23
|
+
get context(): NodeContext;
|
|
24
|
+
get hasContexts(): boolean;
|
|
25
|
+
private _observers;
|
|
26
|
+
get observers(): NodeObservers;
|
|
27
|
+
get hasObservers(): boolean;
|
|
28
|
+
private _components;
|
|
29
|
+
get components(): NodeComponents;
|
|
30
|
+
get hasComponents(): boolean;
|
|
31
|
+
private _tags;
|
|
32
|
+
get tags(): NodeTags;
|
|
33
|
+
get hasTags(): boolean;
|
|
34
|
+
get childrenArray(): number[];
|
|
35
|
+
get parent(): number;
|
|
36
|
+
set parent(value: number);
|
|
37
|
+
graph: Graph;
|
|
38
|
+
get arrays(): import("./NodeArray").NodeArray;
|
|
39
|
+
get enabled(): boolean;
|
|
40
|
+
set enabled(enabled: boolean);
|
|
41
|
+
get isDisposed(): boolean;
|
|
42
|
+
private _index;
|
|
43
|
+
private constructor();
|
|
44
|
+
setNode(graph: Graph, index: number): this;
|
|
45
|
+
toRef(cursor?: NodeCursor): NodeCursor;
|
|
46
|
+
/** Traverse the node's direct children */
|
|
47
|
+
children(cursor?: NodeCursor): Generator<NodeCursor>;
|
|
48
|
+
/** Traverse all the node's descendants */
|
|
49
|
+
traverseChildren(cursor?: NodeCursor): Generator<NodeCursor>;
|
|
50
|
+
/** Traverse all the node's parents */
|
|
51
|
+
traverseParents(cursor?: NodeCursor): Generator<NodeCursor>;
|
|
52
|
+
/** Traverse all the node's components */
|
|
53
|
+
traverseComponents(cursor?: ComponentCursor<{}, any, any>): Generator<ComponentCursor>;
|
|
54
|
+
/** Traverse all the node's tags */
|
|
55
|
+
traverseTags(cursor?: TagCursor): Generator<TagCursor>;
|
|
56
|
+
dispose(): void;
|
|
57
|
+
hasChild(node: NodeCursor): boolean;
|
|
58
|
+
parentTo(nodeToParentTo: NodeCursor): void;
|
|
59
|
+
getChild(index: number, cursor?: NodeCursor): NodeCursor | null;
|
|
60
|
+
addChild(node: NodeCursor): void;
|
|
61
|
+
removeChild(index: number): number | null | undefined;
|
|
62
|
+
addUniqueId(): bigint;
|
|
63
|
+
returnCursor(): void;
|
|
64
|
+
cloneCursor(cursor?: NodeCursor): NodeCursor;
|
|
65
|
+
}
|