@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
|
@@ -41,6 +41,10 @@ export type ComponentRegisterData<ComponentSchema extends object = any, Data ext
|
|
|
41
41
|
* The type of the component.
|
|
42
42
|
*/
|
|
43
43
|
type: string;
|
|
44
|
+
performance?: {
|
|
45
|
+
/**If set to true component init will use a re-usable cursor that will be used for other components. */
|
|
46
|
+
useReusableCursor: boolean;
|
|
47
|
+
};
|
|
44
48
|
/**
|
|
45
49
|
* The schema used to create an editable version of the component.
|
|
46
50
|
* For the actual ComponentInstance the schema is created into an object.
|
|
@@ -67,8 +71,9 @@ export type ComponentRegisterData<ComponentSchema extends object = any, Data ext
|
|
|
67
71
|
* It is up to the graph though when it gets called.
|
|
68
72
|
*
|
|
69
73
|
* @param component - The instance of the component being updated.
|
|
74
|
+
* @param delta - The time since the last update
|
|
70
75
|
*/
|
|
71
|
-
update?(component: ComponentCursor<ComponentSchema, Data, Shared
|
|
76
|
+
update?(component: ComponentCursor<ComponentSchema, Data, Shared>, delta: number): void;
|
|
72
77
|
/**
|
|
73
78
|
* Optional disposal function for the component.
|
|
74
79
|
*
|
|
@@ -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,15 +68,22 @@ 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) {
|
|
75
75
|
const init = this.proto.init;
|
|
76
76
|
if (!init)
|
|
77
77
|
return false;
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const cursor = !this.proto.performance?.useReusableCursor
|
|
79
|
+
? ComponentCursor.Get()
|
|
80
|
+
: this._componentCursor;
|
|
81
|
+
const nodeCursor = !this.proto.performance?.useReusableCursor
|
|
82
|
+
? NodeCursor.Get()
|
|
83
|
+
: this._nodeCursor;
|
|
84
|
+
cursor.setInstance(nodeCursor
|
|
85
|
+
.setNode(this.graph, this._node[index]), this.numberTypeId, index);
|
|
86
|
+
init(cursor);
|
|
80
87
|
return false;
|
|
81
88
|
}
|
|
82
89
|
}
|
|
@@ -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/Functional.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NCS } from "./NCS";
|
|
2
2
|
export function Node(dataOrComponents, maybeComponentsOrChildren, ...restChildren) {
|
|
3
|
+
if (typeof dataOrComponents == "string" && dataOrComponents == "")
|
|
4
|
+
dataOrComponents = "New Node";
|
|
3
5
|
if (!dataOrComponents) {
|
|
4
6
|
return NCS.createNode(null, "New Node", null, undefined, restChildren);
|
|
5
7
|
}
|
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++) {
|
|
@@ -19,10 +17,6 @@ function createNode(graph, data, parent) {
|
|
|
19
17
|
nodeCursor.tags.add(data[3][i]);
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
|
-
if (parent >= 0) {
|
|
23
|
-
parentCursor.setNode(graph, parent);
|
|
24
|
-
parentCursor.addChild(nodeCursor);
|
|
25
|
-
}
|
|
26
20
|
if (data[4]?.length) {
|
|
27
21
|
for (let i = 0; i < data[4].length; i++) {
|
|
28
22
|
createNode(graph, data[4][i], newNode);
|
|
@@ -35,6 +29,12 @@ function createNode(graph, data, parent) {
|
|
|
35
29
|
data[3] = null;
|
|
36
30
|
data[4] = null;
|
|
37
31
|
NCSPools.createNodeData.addItem(data);
|
|
32
|
+
if (parent >= 0) {
|
|
33
|
+
const parentCursor = NodeCursor.Get();
|
|
34
|
+
parentCursor.setNode(graph, parent);
|
|
35
|
+
parentCursor.addChild(nodeCursor);
|
|
36
|
+
parentCursor.returnCursor();
|
|
37
|
+
}
|
|
38
38
|
return nodeCursor;
|
|
39
39
|
}
|
|
40
40
|
export class Graph {
|
|
@@ -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
|
}
|