@amodx/ncs 0.0.22 → 0.0.23
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 +2 -1
- package/Components/ComponentArray.d.ts +1 -1
- package/Components/ComponentArray.js +2 -2
- 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/Graphs/Graph.d.ts +1 -0
- package/Graphs/Graph.js +21 -10
- 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/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 +1 -1
- 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
|
@@ -67,8 +67,9 @@ export type ComponentRegisterData<ComponentSchema extends object = any, Data ext
|
|
|
67
67
|
* It is up to the graph though when it gets called.
|
|
68
68
|
*
|
|
69
69
|
* @param component - The instance of the component being updated.
|
|
70
|
+
* @param delta - The time since the last update
|
|
70
71
|
*/
|
|
71
|
-
update?(component: ComponentCursor<ComponentSchema, Data, Shared
|
|
72
|
+
update?(component: ComponentCursor<ComponentSchema, Data, Shared>, delta: number): void;
|
|
72
73
|
/**
|
|
73
74
|
* Optional disposal function for the component.
|
|
74
75
|
*
|
|
@@ -24,7 +24,7 @@ export declare class ComponentArray {
|
|
|
24
24
|
constructor(graph: Graph, numberTypeId: number);
|
|
25
25
|
addComponent(node: number, schema: any | null, schemaView: string | null): number;
|
|
26
26
|
removeComponent(index: number): number | null;
|
|
27
|
-
update(): void;
|
|
27
|
+
update(delta: number): void;
|
|
28
28
|
init(index: number): boolean;
|
|
29
29
|
}
|
|
30
30
|
export {};
|
|
@@ -60,7 +60,7 @@ export class ComponentArray {
|
|
|
60
60
|
this.schemaArray.removeData(index);
|
|
61
61
|
return nodeIndex;
|
|
62
62
|
}
|
|
63
|
-
update() {
|
|
63
|
+
update(delta) {
|
|
64
64
|
const update = this.proto.update;
|
|
65
65
|
if (!update)
|
|
66
66
|
return;
|
|
@@ -68,7 +68,7 @@ export class ComponentArray {
|
|
|
68
68
|
if (this._disposed[i])
|
|
69
69
|
continue;
|
|
70
70
|
this._componentCursor.setInstance(this._nodeCursor.setNode(this.graph, this._node[i]), this.numberTypeId, i);
|
|
71
|
-
update(this._componentCursor);
|
|
71
|
+
update(this._componentCursor, delta);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
init(index) {
|
|
@@ -5,6 +5,9 @@ import { ComponentArray } from "./ComponentArray";
|
|
|
5
5
|
export declare class ComponentCursor<ComponentSchema extends object = {}, Data extends any = any, Shared extends any = any> {
|
|
6
6
|
static Get(): ComponentCursor<{}, any, any>;
|
|
7
7
|
static Retrun(cursor: ComponentCursor): boolean;
|
|
8
|
+
/**The index of the parent node in the node array */
|
|
9
|
+
get nodeIndex(): number;
|
|
10
|
+
/**The index in the component array */
|
|
8
11
|
get index(): number;
|
|
9
12
|
get type(): string;
|
|
10
13
|
get shared(): Shared;
|
|
@@ -23,5 +26,5 @@ export declare class ComponentCursor<ComponentSchema extends object = {}, Data e
|
|
|
23
26
|
dispose(): void;
|
|
24
27
|
returnCursor(): boolean;
|
|
25
28
|
cloneCursor(cursor?: ComponentCursor, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>;
|
|
26
|
-
update(): void;
|
|
29
|
+
update(delta: number): void;
|
|
27
30
|
}
|
|
@@ -11,6 +11,11 @@ export class ComponentCursor {
|
|
|
11
11
|
static Retrun(cursor) {
|
|
12
12
|
return NCSPools.componentCursor.addItem(cursor);
|
|
13
13
|
}
|
|
14
|
+
/**The index of the parent node in the node array */
|
|
15
|
+
get nodeIndex() {
|
|
16
|
+
return this.node.index;
|
|
17
|
+
}
|
|
18
|
+
/**The index in the component array */
|
|
14
19
|
get index() {
|
|
15
20
|
return this._index;
|
|
16
21
|
}
|
|
@@ -66,7 +71,7 @@ export class ComponentCursor {
|
|
|
66
71
|
newCursor.setInstance(newNodeCursor, this.typeId, this._index);
|
|
67
72
|
return newCursor;
|
|
68
73
|
}
|
|
69
|
-
update() {
|
|
70
|
-
this.__proto.update && this.__proto.update(this);
|
|
74
|
+
update(delta) {
|
|
75
|
+
this.__proto.update && this.__proto.update(this, delta);
|
|
71
76
|
}
|
|
72
77
|
}
|
|
@@ -10,7 +10,7 @@ export function serializeComponentData(data) {
|
|
|
10
10
|
export function serializeComponent(component) {
|
|
11
11
|
return {
|
|
12
12
|
type: component.type,
|
|
13
|
-
...(component.schema ? { schema: component.schema.toJSON() } : {}),
|
|
13
|
+
...(component.schema?.__cursor?.data ? { schema: component.schema.toJSON() } : {}),
|
|
14
14
|
...(component.schema?.__view && component.schema?.__view.id !== "default"
|
|
15
15
|
? { schemaViewId: component.schema.__view.id }
|
|
16
16
|
: {}),
|
package/Data/serializeNode.js
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
import { NodeId } from "../Nodes/NodeId";
|
|
2
|
-
import { createRemoteComponent, serializeComponent, } from "./serializeComponent";
|
|
2
|
+
import { createRemoteComponent, serializeComponent, serializeComponentData, } from "./serializeComponent";
|
|
3
|
+
import { NCSRegister } from "../Register/NCSRegister";
|
|
3
4
|
export function serializeNodeData(data) {
|
|
4
|
-
|
|
5
|
+
const nodeData = {
|
|
5
6
|
name: data[1],
|
|
6
7
|
};
|
|
8
|
+
if (typeof data[0] == "string") {
|
|
9
|
+
nodeData.id = data[0];
|
|
10
|
+
}
|
|
11
|
+
if (typeof data[0] == "bigint") {
|
|
12
|
+
nodeData.id = NodeId.ToHexString(data[0]);
|
|
13
|
+
}
|
|
14
|
+
if (data[2]) {
|
|
15
|
+
nodeData.components = [];
|
|
16
|
+
for (const comp of data[2]) {
|
|
17
|
+
nodeData.components.push(serializeComponentData(comp));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (data[3]) {
|
|
21
|
+
nodeData.tags = [];
|
|
22
|
+
for (const tag of data[3]) {
|
|
23
|
+
nodeData.tags.push(NCSRegister.tags.get(tag).id);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (data[4]) {
|
|
27
|
+
nodeData.children = [];
|
|
28
|
+
for (const child of data[4]) {
|
|
29
|
+
nodeData.children.push(serializeNodeData(child));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return nodeData;
|
|
7
33
|
}
|
|
8
34
|
/** Serialize the node data as is for storage*/
|
|
9
35
|
export function serializeNode(node) {
|
package/Graphs/Graph.d.ts
CHANGED
|
@@ -18,5 +18,6 @@ export declare class Graph {
|
|
|
18
18
|
getNodeFromId(id: bigint | string, cursor?: NodeCursor): NodeCursor;
|
|
19
19
|
addNode(data: CreateNodeData, parent?: number, cursor?: NodeCursor): NodeCursor;
|
|
20
20
|
removeNode(index: number): boolean;
|
|
21
|
+
private _lastTime;
|
|
21
22
|
update(): void;
|
|
22
23
|
}
|
package/Graphs/Graph.js
CHANGED
|
@@ -3,11 +3,9 @@ import { NodeArray } from "../Nodes/NodeArray";
|
|
|
3
3
|
import { NodeCursor } from "../Nodes/NodeCursor";
|
|
4
4
|
import { ContextArray } from "../Contexts/ContextArray";
|
|
5
5
|
import { NCSPools } from "../Pools/NCSPools";
|
|
6
|
-
const parentCursor = NodeCursor.Get();
|
|
7
|
-
const nodeCursor = NodeCursor.Get();
|
|
8
6
|
function createNode(graph, data, parent) {
|
|
9
7
|
const newNode = graph._nodes.addNode(typeof data[0] == "string" ? NodeId.FromString(data[0]) : data[0], parent, data[1]);
|
|
10
|
-
nodeCursor
|
|
8
|
+
const nodeCursor = NodeCursor.Get();
|
|
11
9
|
nodeCursor.setNode(graph, newNode);
|
|
12
10
|
if (data[2]?.length) {
|
|
13
11
|
for (let i = 0; i < data[2].length; i++) {
|
|
@@ -20,8 +18,10 @@ function createNode(graph, data, parent) {
|
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
if (parent >= 0) {
|
|
21
|
+
const parentCursor = NodeCursor.Get();
|
|
23
22
|
parentCursor.setNode(graph, parent);
|
|
24
23
|
parentCursor.addChild(nodeCursor);
|
|
24
|
+
parentCursor.returnCursor();
|
|
25
25
|
}
|
|
26
26
|
if (data[4]?.length) {
|
|
27
27
|
for (let i = 0; i < data[4].length; i++) {
|
|
@@ -49,23 +49,25 @@ export class Graph {
|
|
|
49
49
|
const rootIndex = this._nodes.addNode(null, -1, "root");
|
|
50
50
|
this.root.setNode(this, rootIndex);
|
|
51
51
|
}
|
|
52
|
-
getNode(index, cursor =
|
|
52
|
+
getNode(index, cursor = NodeCursor.Get()) {
|
|
53
53
|
const parentIndex = this._nodes._parents[index];
|
|
54
54
|
if (typeof parentIndex === "undefined")
|
|
55
|
-
throw new Error(`Node with index ${index} does not exist`);
|
|
55
|
+
throw new Error(`NCS: Node with index ${index} does not exist`);
|
|
56
56
|
cursor.setNode(this, index);
|
|
57
57
|
return cursor;
|
|
58
58
|
}
|
|
59
|
-
getNodeFromId(id, cursor =
|
|
59
|
+
getNodeFromId(id, cursor = NodeCursor.Get()) {
|
|
60
60
|
if (typeof id == "string")
|
|
61
61
|
id = NodeId.FromString(id);
|
|
62
62
|
const nodeIndex = this._nodes._idMap.get(id);
|
|
63
63
|
if (typeof nodeIndex === "undefined")
|
|
64
|
-
throw new Error(`Node with id ${id} does not exist`);
|
|
64
|
+
throw new Error(`NCS: Node with id ${id} does not exist`);
|
|
65
65
|
cursor.setNode(this, nodeIndex);
|
|
66
66
|
return cursor;
|
|
67
67
|
}
|
|
68
|
-
addNode(data, parent = this.root.index, cursor =
|
|
68
|
+
addNode(data, parent = this.root.index, cursor = NodeCursor.Get()) {
|
|
69
|
+
if (typeof parent !== "number")
|
|
70
|
+
throw new Error(`NCS: Passed in invalid parent ${parent} in graph.addNode`);
|
|
69
71
|
const newNode = createNode(this, data, parent);
|
|
70
72
|
if (newNode.hasComponents) {
|
|
71
73
|
const components = newNode.components.components;
|
|
@@ -82,6 +84,7 @@ export class Graph {
|
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
newNode.toRef(cursor);
|
|
87
|
+
newNode.returnCursor();
|
|
85
88
|
return cursor;
|
|
86
89
|
}
|
|
87
90
|
removeNode(index) {
|
|
@@ -90,12 +93,20 @@ export class Graph {
|
|
|
90
93
|
return false;
|
|
91
94
|
return true;
|
|
92
95
|
}
|
|
96
|
+
_lastTime = 0;
|
|
93
97
|
update() {
|
|
98
|
+
if (this._lastTime == 0) {
|
|
99
|
+
this._lastTime = performance.now();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const current = performance.now();
|
|
103
|
+
const delta = current - this._lastTime;
|
|
104
|
+
this._lastTime = current;
|
|
94
105
|
for (let i = 0; i < this._updatingComponents.length; i++) {
|
|
95
|
-
this._updatingComponents[i].update();
|
|
106
|
+
this._updatingComponents[i].update(delta);
|
|
96
107
|
}
|
|
97
108
|
for (let i = 0; i < this._systems.length; i++) {
|
|
98
|
-
this._systems[i].update();
|
|
109
|
+
this._systems[i].update(delta);
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
}
|
package/NCS.d.ts
CHANGED
|
@@ -12,7 +12,14 @@ import { deserializeComponentData } from "./Data/deserializeComponent";
|
|
|
12
12
|
import { cloneNode, copyNode, createRemoteNode, serializeNode, serializeNodeData } from "./Data/serializeNode";
|
|
13
13
|
import { deserializeNodeData } from "./Data/deserializeNode";
|
|
14
14
|
import { ExtractSchemaClass, SchemaCreateData, SchemaProperty } from "./Schema/Schema.types";
|
|
15
|
+
import { NodeCursor } from "./Nodes/NodeCursor";
|
|
16
|
+
import { ComponentCursor } from "./Components/ComponentCursor";
|
|
17
|
+
import { SerializedNodeData } from "./Data/SerializedData.types";
|
|
15
18
|
export declare const NCS: {
|
|
19
|
+
Debug: {
|
|
20
|
+
logNode(node: NodeCursor): void;
|
|
21
|
+
output(node: NodeCursor): [index: number, data: SerializedNodeData];
|
|
22
|
+
};
|
|
16
23
|
/** Create a graph. */
|
|
17
24
|
createGraph(): Graph;
|
|
18
25
|
/** Create node data to add a node to a graph. */
|
|
@@ -31,30 +38,30 @@ export declare const NCS: {
|
|
|
31
38
|
registerSystem: typeof registerSystem;
|
|
32
39
|
/** Register a component for use with NCS. */
|
|
33
40
|
registerComponent: <Data extends unknown = any, Shared extends unknown = any, ComponentSchema extends object = any>(data: import("./Components/Component.types").ComponentRegisterData<ComponentSchema, Data, Shared>) => import("./Components/Component.types").ComponentRegisterData<ComponentSchema, Data, Shared> & {
|
|
34
|
-
getNodes(grpah: Graph): Generator<
|
|
35
|
-
getComponents(grpah: Graph): Generator<
|
|
36
|
-
set(node:
|
|
37
|
-
has(node:
|
|
38
|
-
get(node:
|
|
39
|
-
getRequired(node:
|
|
40
|
-
getChild(node:
|
|
41
|
-
getRequiredChild(node:
|
|
42
|
-
getParent(node:
|
|
43
|
-
getRequiredParent(node:
|
|
44
|
-
getAll(node:
|
|
45
|
-
remove(node:
|
|
46
|
-
removeAll(node:
|
|
41
|
+
getNodes(grpah: Graph): Generator<NodeCursor>;
|
|
42
|
+
getComponents(grpah: Graph): Generator<ComponentCursor<ComponentSchema, Data, Shared>, any, any>;
|
|
43
|
+
set(node: NodeCursor, componentSchema?: import("./Util/Util.types").Nullable<Partial<ComponentSchema>> | undefined, schemaCursor?: import("./Util/Util.types").Nullable<import("./Schema/Schema.types").SchemaCursor<ComponentSchema>> | undefined, cursor?: ComponentCursor<ComponentSchema, Data, Shared> | undefined): ComponentCursor<ComponentSchema, Data, Shared>;
|
|
44
|
+
has(node: NodeCursor): boolean;
|
|
45
|
+
get(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared> | undefined, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared> | null;
|
|
46
|
+
getRequired(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared> | undefined, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>;
|
|
47
|
+
getChild(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared> | undefined, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared> | null;
|
|
48
|
+
getRequiredChild(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared> | undefined, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>;
|
|
49
|
+
getParent(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared> | undefined, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared> | null;
|
|
50
|
+
getRequiredParent(node: NodeCursor, cursor?: ComponentCursor<ComponentSchema, Data, Shared> | undefined, nodeCursor?: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>;
|
|
51
|
+
getAll(node: NodeCursor): ComponentCursor<ComponentSchema, Data, Shared>[] | null;
|
|
52
|
+
remove(node: NodeCursor): boolean;
|
|
53
|
+
removeAll(node: NodeCursor): boolean;
|
|
47
54
|
nodeData: {
|
|
48
|
-
get(node:
|
|
49
|
-
set(node:
|
|
50
|
-
getAll(node:
|
|
51
|
-
remove(node:
|
|
52
|
-
removeAll(node:
|
|
55
|
+
get(node: SerializedNodeData): import("./Data/SerializedData.types").SerializedComponentData<ComponentSchema> | null;
|
|
56
|
+
set(node: SerializedNodeData, componentSchema?: Partial<ComponentSchema> | undefined): void;
|
|
57
|
+
getAll(node: SerializedNodeData): import("./Data/SerializedData.types").SerializedComponentData<ComponentSchema>[] | null;
|
|
58
|
+
remove(node: SerializedNodeData): import("./Data/SerializedData.types").SerializedComponentData<ComponentSchema> | null;
|
|
59
|
+
removeAll(node: SerializedNodeData): import("./Data/SerializedData.types").SerializedComponentData<ComponentSchema>[] | null;
|
|
53
60
|
};
|
|
54
61
|
type: string;
|
|
55
62
|
typeId: number;
|
|
56
63
|
data: import("./Components/Component.types").ComponentRegisterData<ComponentSchema, Data, Shared>;
|
|
57
|
-
default:
|
|
64
|
+
default: ComponentCursor<ComponentSchema, Data, Shared>;
|
|
58
65
|
} & ((schema?: Partial<ComponentSchema> | null | undefined, schemaView?: string | null) => CreateComponentData<ComponentSchema>);
|
|
59
66
|
/** Register a context for use with NCS. */
|
|
60
67
|
registerContext: typeof registerContext;
|
package/NCS.js
CHANGED
|
@@ -12,6 +12,7 @@ import { deserializeComponentData } from "./Data/deserializeComponent";
|
|
|
12
12
|
import { cloneNode, copyNode, createRemoteNode, serializeNode, serializeNodeData, } from "./Data/serializeNode";
|
|
13
13
|
import { deserializeNodeData } from "./Data/deserializeNode";
|
|
14
14
|
import { SchemaProperty, } from "./Schema/Schema.types";
|
|
15
|
+
import { ComponentCursor } from "./Components/ComponentCursor";
|
|
15
16
|
function traverseCreateSchema(obj, parent) {
|
|
16
17
|
parent.children ??= [];
|
|
17
18
|
for (const key in obj) {
|
|
@@ -45,7 +46,21 @@ function traverseCreateSchema(obj, parent) {
|
|
|
45
46
|
}
|
|
46
47
|
return parent;
|
|
47
48
|
}
|
|
49
|
+
const Debug = {
|
|
50
|
+
logNode(node) {
|
|
51
|
+
console.log("log node", node.index);
|
|
52
|
+
const temp = ComponentCursor.Get();
|
|
53
|
+
for (const comp of node.traverseComponents(temp)) {
|
|
54
|
+
console.log(comp.type, comp.schema && comp.schema.toJSON());
|
|
55
|
+
}
|
|
56
|
+
temp.returnCursor();
|
|
57
|
+
},
|
|
58
|
+
output(node) {
|
|
59
|
+
return [node.index, serializeNode(node)];
|
|
60
|
+
},
|
|
61
|
+
};
|
|
48
62
|
export const NCS = {
|
|
63
|
+
Debug,
|
|
49
64
|
/** Create a graph. */
|
|
50
65
|
createGraph() {
|
|
51
66
|
return new Graph();
|
package/Nodes/NodeArray.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare class NodeArray {
|
|
|
18
18
|
_disposed: boolean[];
|
|
19
19
|
_enabled: boolean[];
|
|
20
20
|
_hasObservers: boolean[];
|
|
21
|
+
private _count;
|
|
21
22
|
addNode(id: bigint | null, parent: number, name: string): number;
|
|
22
23
|
removeNode(slot: number): boolean;
|
|
23
24
|
addNodeId(index: number, id: bigint): void;
|
package/Nodes/NodeArray.js
CHANGED
|
@@ -26,10 +26,13 @@ export class NodeArray {
|
|
|
26
26
|
_disposed = [];
|
|
27
27
|
_enabled = [];
|
|
28
28
|
_hasObservers = [];
|
|
29
|
+
_count = 0;
|
|
29
30
|
addNode(id, parent, name) {
|
|
30
|
-
let slot = this._freeSlots.
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
let slot = this._freeSlots.shift();
|
|
32
|
+
if (slot === undefined) {
|
|
33
|
+
slot = this._count;
|
|
34
|
+
this._count++;
|
|
35
|
+
}
|
|
33
36
|
id && this.addNodeId(slot, id);
|
|
34
37
|
this._parents[slot] = parent;
|
|
35
38
|
this._names[slot] = name;
|
|
@@ -39,25 +42,28 @@ export class NodeArray {
|
|
|
39
42
|
return slot;
|
|
40
43
|
}
|
|
41
44
|
removeNode(slot) {
|
|
42
|
-
if (this._parents[slot] ===
|
|
45
|
+
if (this._parents[slot] === -1)
|
|
43
46
|
return false;
|
|
44
47
|
this._freeSlots.push(slot);
|
|
45
48
|
this._indexMap[slot] && this.removeNodeId(this._indexMap[slot]);
|
|
46
|
-
this._parents[slot] =
|
|
49
|
+
this._parents[slot] = 0;
|
|
47
50
|
this._names[slot] = "";
|
|
48
51
|
this._disposed[slot] = true;
|
|
49
52
|
this._enabled[slot] = false;
|
|
50
53
|
this._hasObservers[slot] = false;
|
|
51
|
-
for (let
|
|
52
|
-
const
|
|
54
|
+
for (let j = 0; j < observerValues.length; j++) {
|
|
55
|
+
const key = observerValues[j];
|
|
56
|
+
const observer = this._observers[key]?.[slot];
|
|
53
57
|
if (observer !== undefined) {
|
|
58
|
+
observer.clear();
|
|
54
59
|
NCSPools.observers.addItem(observer);
|
|
55
|
-
this.
|
|
60
|
+
this._observers[key][slot] = undefined;
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
for (let i = 0; i < this._eventPalette.size; i++) {
|
|
59
64
|
const observer = this._events[i][slot];
|
|
60
65
|
if (observer !== undefined) {
|
|
66
|
+
observer.clear();
|
|
61
67
|
NCSPools.observers.addItem(observer);
|
|
62
68
|
this._events[i][slot] = undefined;
|
|
63
69
|
}
|
package/Nodes/NodeComponents.js
CHANGED
|
@@ -3,7 +3,6 @@ import { NodeCursor } from "./NodeCursor";
|
|
|
3
3
|
import { NCSRegister } from "../Register/NCSRegister";
|
|
4
4
|
import { ComponentArray } from "../Components/ComponentArray";
|
|
5
5
|
import { NCSPools } from "../Pools/NCSPools";
|
|
6
|
-
const defaultCursor = ComponentCursor.Get();
|
|
7
6
|
export class NodeComponents {
|
|
8
7
|
static Get() {
|
|
9
8
|
const cursor = NCSPools.nodeComponents.get();
|
|
@@ -23,10 +22,12 @@ export class NodeComponents {
|
|
|
23
22
|
if (!this.components)
|
|
24
23
|
return;
|
|
25
24
|
const components = this.components;
|
|
25
|
+
const tempCursor = ComponentCursor.Get();
|
|
26
26
|
for (let i = 0; i < components.length; i += 2) {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
tempCursor.setInstance(this.node, components[i], components[i + 1]);
|
|
28
|
+
tempCursor.dispose();
|
|
29
29
|
}
|
|
30
|
+
tempCursor.returnCursor();
|
|
30
31
|
}
|
|
31
32
|
add(comp) {
|
|
32
33
|
if (!this.components) {
|
|
@@ -63,13 +64,15 @@ export class NodeComponents {
|
|
|
63
64
|
NCSPools.createComponentData.addItem(comp);
|
|
64
65
|
this.components.push(typeId, componentIndex);
|
|
65
66
|
compArray.observers.nodeAdded.notify(this.node.index);
|
|
67
|
+
const temp = ComponentCursor.Get();
|
|
66
68
|
if (this.node.hasObservers) {
|
|
67
|
-
|
|
69
|
+
temp.setInstance(this.node, typeId, componentIndex);
|
|
68
70
|
this.node.observers.isComponentAddedSet &&
|
|
69
|
-
this.node.observers.componentAdded.notify(
|
|
71
|
+
this.node.observers.componentAdded.notify(temp);
|
|
70
72
|
this.node.observers.isComponentsUpdatedSet &&
|
|
71
|
-
this.node.observers.componentsUpdated.notify(
|
|
73
|
+
this.node.observers.componentsUpdated.notify(temp);
|
|
72
74
|
}
|
|
75
|
+
temp.returnCursor();
|
|
73
76
|
return componentIndex;
|
|
74
77
|
}
|
|
75
78
|
remove(type) {
|
|
@@ -88,15 +91,17 @@ export class NodeComponents {
|
|
|
88
91
|
}
|
|
89
92
|
if (removeIndex == -1)
|
|
90
93
|
return;
|
|
91
|
-
|
|
94
|
+
const temp = ComponentCursor.Get();
|
|
95
|
+
temp.setInstance(this.node, numberId, removeComponentIndex);
|
|
92
96
|
this.components.splice(removeIndex, 2);
|
|
93
97
|
if (this.node.hasObservers) {
|
|
94
98
|
this.node.observers.isComponentRemovedSet &&
|
|
95
|
-
this.node.observers.componentRemoved.notify(
|
|
99
|
+
this.node.observers.componentRemoved.notify(temp);
|
|
96
100
|
this.node.observers.isComponentsUpdatedSet &&
|
|
97
|
-
this.node.observers.componentsUpdated.notify(
|
|
101
|
+
this.node.observers.componentsUpdated.notify(temp);
|
|
98
102
|
}
|
|
99
|
-
|
|
103
|
+
temp.dispose();
|
|
104
|
+
temp.returnCursor();
|
|
100
105
|
return true;
|
|
101
106
|
}
|
|
102
107
|
has(type) {
|
|
@@ -118,8 +123,7 @@ export class NodeComponents {
|
|
|
118
123
|
const numberId = NCSRegister.components.idPalette.getNumberId(type);
|
|
119
124
|
for (let i = 0; i < components.length; i += 2) {
|
|
120
125
|
if (components[i] == numberId) {
|
|
121
|
-
|
|
122
|
-
this.node.cloneCursor(nodeCursor);
|
|
126
|
+
nodeCursor.setNode(this.node.graph, this.node.index);
|
|
123
127
|
cursor.setInstance(nodeCursor, numberId, components[i + 1]);
|
|
124
128
|
return cursor;
|
|
125
129
|
}
|
|
@@ -146,38 +150,49 @@ export class NodeComponents {
|
|
|
146
150
|
if (!components)
|
|
147
151
|
return false;
|
|
148
152
|
const numberId = NCSRegister.components.idPalette.getNumberId(type);
|
|
153
|
+
const tempCursor = ComponentCursor.Get();
|
|
149
154
|
for (let i = components.length; i > 0; i -= 2) {
|
|
150
155
|
if (components[i] == numberId) {
|
|
151
|
-
|
|
156
|
+
tempCursor.setInstance(this.node, components[i], components[i + 1]);
|
|
152
157
|
this.components.splice(i, 2);
|
|
153
158
|
if (this.node.hasObservers) {
|
|
154
159
|
this.node.observers.isComponentRemovedSet &&
|
|
155
|
-
this.node.observers.componentRemoved.notify(
|
|
160
|
+
this.node.observers.componentRemoved.notify(tempCursor);
|
|
156
161
|
this.node.observers.isComponentsUpdatedSet &&
|
|
157
|
-
this.node.observers.componentsUpdated.notify(
|
|
162
|
+
this.node.observers.componentsUpdated.notify(tempCursor);
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
165
|
}
|
|
166
|
+
tempCursor.returnCursor();
|
|
161
167
|
return true;
|
|
162
168
|
}
|
|
163
169
|
getChild(type, cursor = ComponentCursor.Get(), nodeCursor = NodeCursor.Get()) {
|
|
164
|
-
|
|
170
|
+
const tempCursor = NodeCursor.Get();
|
|
171
|
+
for (const child of this.node.traverseChildren(tempCursor)) {
|
|
165
172
|
if (!child.components)
|
|
166
173
|
continue;
|
|
174
|
+
nodeCursor.setNode(this.node.graph, child.index);
|
|
167
175
|
const found = child.components.get(type, cursor, nodeCursor);
|
|
168
|
-
if (found)
|
|
176
|
+
if (found) {
|
|
177
|
+
tempCursor.returnCursor();
|
|
169
178
|
return found;
|
|
179
|
+
}
|
|
170
180
|
}
|
|
181
|
+
tempCursor.returnCursor();
|
|
171
182
|
return null;
|
|
172
183
|
}
|
|
173
184
|
getParent(type, cursor = ComponentCursor.Get(), nodeCursor = NodeCursor.Get()) {
|
|
174
|
-
|
|
185
|
+
const tempCursor = NodeCursor.Get();
|
|
186
|
+
for (const parent of this.node.traverseParents(tempCursor)) {
|
|
175
187
|
if (!parent.components)
|
|
176
188
|
continue;
|
|
177
189
|
const found = parent.components.get(type, cursor, nodeCursor);
|
|
178
|
-
if (found)
|
|
190
|
+
if (found) {
|
|
191
|
+
tempCursor.returnCursor();
|
|
179
192
|
return found;
|
|
193
|
+
}
|
|
180
194
|
}
|
|
195
|
+
tempCursor.returnCursor();
|
|
181
196
|
return null;
|
|
182
197
|
}
|
|
183
198
|
}
|
package/Nodes/NodeCursor.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ export declare class NodeCursor {
|
|
|
13
13
|
static Retrun(cursor: NodeCursor): void;
|
|
14
14
|
clear(events: boolean, context: boolean, observers: boolean, compoents: boolean, tags: boolean): void;
|
|
15
15
|
get index(): number;
|
|
16
|
-
get parentIndex(): number;
|
|
17
16
|
get id(): bigint | null;
|
|
18
17
|
get name(): string;
|
|
19
18
|
private _events;
|
|
@@ -50,16 +49,17 @@ export declare class NodeCursor {
|
|
|
50
49
|
/** Traverse all the node's parents */
|
|
51
50
|
traverseParents(cursor?: NodeCursor): Generator<NodeCursor>;
|
|
52
51
|
/** Traverse all the node's components */
|
|
53
|
-
traverseComponents(cursor?: ComponentCursor
|
|
52
|
+
traverseComponents(cursor?: ComponentCursor): Generator<ComponentCursor>;
|
|
54
53
|
/** Traverse all the node's tags */
|
|
55
54
|
traverseTags(cursor?: TagCursor): Generator<TagCursor>;
|
|
56
55
|
dispose(): void;
|
|
57
56
|
hasChild(node: NodeCursor): boolean;
|
|
58
57
|
parentTo(nodeToParentTo: NodeCursor): void;
|
|
59
58
|
getChild(index: number, cursor?: NodeCursor): NodeCursor | null;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
getChildIndex(node: NodeCursor | number): number;
|
|
60
|
+
addChild(node: NodeCursor): number;
|
|
61
|
+
removeChild(index: number): number | undefined;
|
|
62
|
+
uniqueId(): bigint;
|
|
63
63
|
returnCursor(): void;
|
|
64
64
|
cloneCursor(cursor?: NodeCursor): NodeCursor;
|
|
65
65
|
}
|
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/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
|
@@ -191,7 +191,7 @@ export class Schema {
|
|
|
191
191
|
view = new SchemaView(this, data.id, meta, byteOffsets, byteSize, data, this._binaryObjectCursorClass);
|
|
192
192
|
}
|
|
193
193
|
if (!view)
|
|
194
|
-
throw new Error(`Invalid data`);
|
|
194
|
+
throw new Error(`NCS: Invalid data`);
|
|
195
195
|
const viewIndex = this.viewIdPalettew.register(data.id);
|
|
196
196
|
this.views[viewIndex] = view;
|
|
197
197
|
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
package/Tags/TagCursor.js
CHANGED
package/package.json
CHANGED
|
@@ -1,27 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@amodx/ncs",
|
|
3
|
-
"version": "0.0.22",
|
|
4
|
-
"module": "index.js",
|
|
5
|
-
"types": "index.d.ts",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"description": "NCS (Node Component System) is a library for the base of any NCS/ECS system.",
|
|
8
|
-
"keywords": [],
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "mkdir -p dist && rm -rf dist/* && cp package.json dist/package.json && cd ./src && npx tsc",
|
|
11
|
-
"compile": "cd ./src && npx tsc --watch"
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"url": "git+https://github.com/Amodx/Libraries.git"
|
|
15
|
-
},
|
|
16
|
-
"bugs": {
|
|
17
|
-
"url": "https://github.com/Amodx/Libraries/issues"
|
|
18
|
-
},
|
|
19
|
-
"homepage": "https://github.com/Amodx/Libraries",
|
|
20
|
-
"author": "Amodx",
|
|
21
|
-
"license": "MIT",
|
|
22
|
-
"devDependencies": {},
|
|
23
|
-
"main": "index.js",
|
|
24
|
-
"publishConfig": {
|
|
25
|
-
"access": "public"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
{"name":"@amodx/ncs","version":"0.0.23","module":"index.js","types":"index.d.ts","type":"module","description":"NCS (Node Component System) is a library for the base of any NCS/ECS system.","keywords":[],"scripts":{"build":"mkdir -p dist && rm -rf dist/* && cp package.json dist/package.json && cd ./src && npx tsc","compile":"cd ./src && npx tsc --watch"},"repository":{"url":"git+https://github.com/Amodx/Libraries.git"},"bugs":{"url":"https://github.com/Amodx/Libraries/issues"},"homepage":"https://github.com/Amodx/Libraries","author":"Amodx","license":"MIT","devDependencies":{},"main":"index.js","publishConfig":{"access":"public"}}
|