@amodx/ncs 0.0.23 → 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.
@@ -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.
@@ -75,8 +75,15 @@ export class ComponentArray {
75
75
  const init = this.proto.init;
76
76
  if (!init)
77
77
  return false;
78
- this._componentCursor.setInstance(this._nodeCursor.setNode(this.graph, this._node[index]), this.numberTypeId, index);
79
- init(this._componentCursor);
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
  }
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.js CHANGED
@@ -17,12 +17,6 @@ function createNode(graph, data, parent) {
17
17
  nodeCursor.tags.add(data[3][i]);
18
18
  }
19
19
  }
20
- if (parent >= 0) {
21
- const parentCursor = NodeCursor.Get();
22
- parentCursor.setNode(graph, parent);
23
- parentCursor.addChild(nodeCursor);
24
- parentCursor.returnCursor();
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 {
package/Nodes/NodeId.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  export declare class NodeId {
2
2
  static Create(): bigint;
3
+ static GetHighPart(id: bigint): bigint;
4
+ static GetLowPart(id: bigint): bigint;
5
+ static GetCombined(lower: bigint, upper: bigint): bigint;
3
6
  static CreateString(): string;
4
7
  static FromString(id: string): bigint;
5
8
  static ToHexString(id: BigInt): string;
package/Nodes/NodeId.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const buffer = new ArrayBuffer(16);
2
2
  const randomArray = new Uint8Array(buffer);
3
3
  const view = new DataView(buffer);
4
+ const mask64 = 0xffffffffffffffffn;
4
5
  export class NodeId {
5
6
  static Create() {
6
7
  crypto.getRandomValues(randomArray);
@@ -11,6 +12,15 @@ export class NodeId {
11
12
  const bigIntId = high | midHigh | midLow | low;
12
13
  return bigIntId;
13
14
  }
15
+ static GetHighPart(id) {
16
+ return (id >> 64n) & mask64;
17
+ }
18
+ static GetLowPart(id) {
19
+ return id & mask64;
20
+ }
21
+ static GetCombined(lower, upper) {
22
+ return ((upper & mask64) << 64n) | (lower & mask64);
23
+ }
14
24
  static CreateString() {
15
25
  return this.ToHexString(this.Create());
16
26
  }
package/Schema/Schema.js CHANGED
@@ -11,7 +11,9 @@ const traverseCreate = (parent, properties, index) => {
11
11
  parent.children ??= [];
12
12
  for (let i = 0; i < properties.length; i++) {
13
13
  const data = properties[i];
14
- if (typeof data.value == "object" && !data.children?.length) {
14
+ if (typeof data.value == "object" &&
15
+ !data.children?.length &&
16
+ !Array.isArray(data.value)) {
15
17
  data.children ??= [];
16
18
  for (const key in data.value) {
17
19
  const value = data.value[key];
@@ -115,7 +117,11 @@ export class Schema {
115
117
  const data = [];
116
118
  for (const id in shape) {
117
119
  const value = shape[id];
118
- if (typeof value == "object") {
120
+ if (typeof value == "object" &&
121
+ value !== null &&
122
+ typeof value !== "undefined" &&
123
+ !Array.isArray(id) &&
124
+ !ArrayBuffer.isView(value)) {
119
125
  data.push(traverseCreateFromObject(value, {
120
126
  id,
121
127
  value: {},
package/package.json CHANGED
@@ -1 +1 @@
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"}}
1
+ {"name":"@amodx/ncs","version":"0.0.24","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"}}