@argila/core 0.0.0-alpha-20250607064138

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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Argila.d.ts +24 -0
  3. package/dist/Argila.d.ts.map +1 -0
  4. package/dist/Argila.js +62 -0
  5. package/dist/Argila.test.d.ts +2 -0
  6. package/dist/Argila.test.d.ts.map +1 -0
  7. package/dist/Argila.test.js +150 -0
  8. package/dist/Canvas.d.ts +117 -0
  9. package/dist/Canvas.d.ts.map +1 -0
  10. package/dist/Canvas.js +311 -0
  11. package/dist/Canvas.test.d.ts +2 -0
  12. package/dist/Canvas.test.d.ts.map +1 -0
  13. package/dist/Canvas.test.js +311 -0
  14. package/dist/Common.d.ts +11 -0
  15. package/dist/Common.d.ts.map +1 -0
  16. package/dist/Common.js +64 -0
  17. package/dist/Common.test.js +118 -0
  18. package/dist/Event.d.ts +10 -0
  19. package/dist/Event.d.ts.map +1 -0
  20. package/dist/Event.js +23 -0
  21. package/dist/Event.test.js +72 -0
  22. package/dist/LinkedList.d.ts +44 -0
  23. package/dist/LinkedList.d.ts.map +1 -0
  24. package/dist/LinkedList.js +95 -0
  25. package/dist/LinkedList.test.d.ts +2 -0
  26. package/dist/LinkedList.test.d.ts.map +1 -0
  27. package/dist/LinkedList.test.js +197 -0
  28. package/dist/Vector3.d.ts +104 -0
  29. package/dist/Vector3.d.ts.map +1 -0
  30. package/dist/Vector3.js +185 -0
  31. package/dist/Vector3.test.d.ts +2 -0
  32. package/dist/Vector3.test.d.ts.map +1 -0
  33. package/dist/Vector3.test.js +127 -0
  34. package/dist/common.test.d.ts +2 -0
  35. package/dist/common.test.d.ts.map +1 -0
  36. package/dist/event.test.d.ts +2 -0
  37. package/dist/event.test.d.ts.map +1 -0
  38. package/dist/index.d.ts +29 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +41 -0
  41. package/dist/systems/Draw.d.ts +8 -0
  42. package/dist/systems/Draw.d.ts.map +1 -0
  43. package/dist/systems/Draw.js +15 -0
  44. package/dist/systems/Entity.d.ts +18 -0
  45. package/dist/systems/Entity.d.ts.map +1 -0
  46. package/dist/systems/Entity.js +44 -0
  47. package/dist/systems/Input.d.ts +127 -0
  48. package/dist/systems/Input.d.ts.map +1 -0
  49. package/dist/systems/Input.js +191 -0
  50. package/dist/systems/Loop.d.ts +29 -0
  51. package/dist/systems/Loop.d.ts.map +1 -0
  52. package/dist/systems/Loop.js +93 -0
  53. package/dist/systems/Render.d.ts +21 -0
  54. package/dist/systems/Render.d.ts.map +1 -0
  55. package/dist/systems/Render.js +112 -0
  56. package/dist/systems/Shape.d.ts +48 -0
  57. package/dist/systems/Shape.d.ts.map +1 -0
  58. package/dist/systems/Shape.js +146 -0
  59. package/dist/systems/System.d.ts +22 -0
  60. package/dist/systems/System.d.ts.map +1 -0
  61. package/dist/systems/System.js +20 -0
  62. package/dist/systems/World.d.ts +24 -0
  63. package/dist/systems/World.d.ts.map +1 -0
  64. package/dist/systems/World.js +84 -0
  65. package/dist/systems/debugs/Debug.d.ts +9 -0
  66. package/dist/systems/debugs/Debug.d.ts.map +1 -0
  67. package/dist/systems/debugs/Debug.js +12 -0
  68. package/dist/systems/debugs/InputDebug.d.ts +7 -0
  69. package/dist/systems/debugs/InputDebug.d.ts.map +1 -0
  70. package/dist/systems/debugs/InputDebug.js +11 -0
  71. package/dist/systems/debugs/LoopDebug.d.ts +7 -0
  72. package/dist/systems/debugs/LoopDebug.d.ts.map +1 -0
  73. package/dist/systems/debugs/LoopDebug.js +11 -0
  74. package/package.json +79 -0
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ import { v4 as uuidv4 } from "uuid";
3
+ import LinkedList, { LinkedNode } from "./LinkedList";
4
+ export default class Vector3 {
5
+ // Static map to store vectors by entity
6
+ static vectors = /* @__PURE__ */ new Map();
7
+ // Linked list to manage vector objects
8
+ static vectorPool = new LinkedList();
9
+ /**
10
+ * Creates a new vector and stores it in the map.
11
+ * @param entity - The entity identifier.
12
+ * @param x - The x component of the vector.
13
+ * @param y - The y component of the vector.
14
+ * @param z - The z component of the vector.
15
+ * @returns The unique ID of the created vector.
16
+ */
17
+ static create(entity, x, y, z) {
18
+ const id = uuidv4();
19
+ let vectorNode;
20
+ if (Vector3.vectorPool.length > 0) {
21
+ vectorNode = Vector3.vectorPool.pop();
22
+ vectorNode.x = x;
23
+ vectorNode.y = y;
24
+ vectorNode.z = z;
25
+ } else {
26
+ vectorNode = { x, y, z };
27
+ }
28
+ Vector3.vectors.set(entity, new LinkedNode(vectorNode));
29
+ return id;
30
+ }
31
+ /**
32
+ * Retrieves a vector by its entity identifier.
33
+ * @param entity - The entity identifier.
34
+ * @returns The vector associated with the entity, or undefined if not found.
35
+ */
36
+ static get(entity) {
37
+ const vectorNode = Vector3.vectors.get(entity);
38
+ return vectorNode ? vectorNode.data : void 0;
39
+ }
40
+ /**
41
+ * Validates if a vector exists.
42
+ * @param vector - The vector to validate.
43
+ * @throws Will throw an error if the vector is not found.
44
+ */
45
+ static validateVector(vector) {
46
+ if (!vector) {
47
+ throw new Error("Vector not found");
48
+ }
49
+ }
50
+ /**
51
+ * Sets the components of a vector.
52
+ * @param entity - The entity identifier.
53
+ * @param x - The new x component.
54
+ * @param y - The new y component.
55
+ * @param z - The new z component.
56
+ */
57
+ static set(entity, x, y, z) {
58
+ const vectorNode = Vector3.vectors.get(entity);
59
+ Vector3.validateVector(vectorNode?.data);
60
+ vectorNode.data.x = x;
61
+ vectorNode.data.y = y;
62
+ vectorNode.data.z = z;
63
+ }
64
+ /**
65
+ * Adds values to the components of a vector.
66
+ * @param entity - The entity identifier.
67
+ * @param x - The value to add to the x component.
68
+ * @param y - The value to add to the y component.
69
+ * @param z - The value to add to the z component.
70
+ */
71
+ static add(entity, x, y, z) {
72
+ const vectorNode = Vector3.vectors.get(entity);
73
+ Vector3.validateVector(vectorNode?.data);
74
+ vectorNode.data.x += x;
75
+ vectorNode.data.y += y;
76
+ vectorNode.data.z += z;
77
+ }
78
+ /**
79
+ * Subtracts values from the components of a vector.
80
+ * @param entity - The entity identifier.
81
+ * @param x - The value to subtract from the x component.
82
+ * @param y - The value to subtract from the y component.
83
+ * @param z - The value to subtract from the z component.
84
+ */
85
+ static subtract(entity, x, y, z) {
86
+ const vectorNode = Vector3.vectors.get(entity);
87
+ Vector3.validateVector(vectorNode?.data);
88
+ vectorNode.data.x -= x;
89
+ vectorNode.data.y -= y;
90
+ vectorNode.data.z -= z;
91
+ }
92
+ /**
93
+ * Multiplies the components of a vector by given values.
94
+ * @param entity - The entity identifier.
95
+ * @param x - The value to multiply the x component by.
96
+ * @param y - The value to multiply the y component by.
97
+ * @param z - The value to multiply the z component by.
98
+ */
99
+ static multiply(entity, x, y, z) {
100
+ const vectorNode = Vector3.vectors.get(entity);
101
+ Vector3.validateVector(vectorNode?.data);
102
+ vectorNode.data.x *= x;
103
+ vectorNode.data.y *= y;
104
+ vectorNode.data.z *= z;
105
+ }
106
+ /**
107
+ * Divides the components of a vector by given values.
108
+ * @param entity - The entity identifier.
109
+ * @param x - The value to divide the x component by.
110
+ * @param y - The value to divide the y component by.
111
+ * @param z - The value to divide the z component by.
112
+ * @throws Will throw an error if any of the values are zero.
113
+ */
114
+ static divide(entity, x, y, z) {
115
+ const vectorNode = Vector3.vectors.get(entity);
116
+ Vector3.validateVector(vectorNode?.data);
117
+ if (x === 0 || y === 0 || z === 0) {
118
+ throw new Error("Division by zero");
119
+ }
120
+ vectorNode.data.x /= x;
121
+ vectorNode.data.y /= y;
122
+ vectorNode.data.z /= z;
123
+ }
124
+ /**
125
+ * Calculates the magnitude (length) of a vector.
126
+ * @param entity - The entity identifier.
127
+ * @returns The magnitude of the vector.
128
+ */
129
+ static magnitude(entity) {
130
+ const vectorNode = Vector3.vectors.get(entity);
131
+ Vector3.validateVector(vectorNode?.data);
132
+ return Math.sqrt(
133
+ vectorNode.data.x ** 2 + vectorNode.data.y ** 2 + vectorNode.data.z ** 2
134
+ );
135
+ }
136
+ /**
137
+ * Normalizes the vector to have a magnitude of 1.
138
+ * @param entity - The entity identifier.
139
+ * @throws Will throw an error if the vector is a zero vector.
140
+ */
141
+ static normalize(entity) {
142
+ const vectorNode = Vector3.vectors.get(entity);
143
+ Vector3.validateVector(vectorNode?.data);
144
+ const magnitude = Vector3.magnitude(entity);
145
+ if (magnitude === 0) {
146
+ throw new Error("Cannot normalize a zero vector");
147
+ }
148
+ vectorNode.data.x /= magnitude;
149
+ vectorNode.data.y /= magnitude;
150
+ vectorNode.data.z /= magnitude;
151
+ }
152
+ /**
153
+ * Calculates the dot product of two vectors.
154
+ * @param entity1 - The first entity identifier.
155
+ * @param entity2 - The second entity identifier.
156
+ * @returns The dot product of the two vectors.
157
+ */
158
+ static dotProduct(entity1, entity2) {
159
+ const vector1 = Vector3.vectors.get(entity1);
160
+ const vector2 = Vector3.vectors.get(entity2);
161
+ Vector3.validateVector(vector1?.data);
162
+ Vector3.validateVector(vector2?.data);
163
+ return vector1.data.x * vector2.data.x + vector1.data.y * vector2.data.y + vector1.data.z * vector2.data.z;
164
+ }
165
+ /**
166
+ * Removes a vector from the map and returns it to the pool.
167
+ * @param entity - The entity identifier.
168
+ */
169
+ static destroy(entity) {
170
+ const vectorNode = Vector3.vectors.get(entity);
171
+ if (vectorNode) {
172
+ Vector3.vectorPool.push(vectorNode.data);
173
+ Vector3.vectors.delete(entity);
174
+ }
175
+ }
176
+ /**
177
+ * Clears all vectors from the map and returns them to the pool.
178
+ */
179
+ static clear() {
180
+ Vector3.vectors.forEach((vectorNode) => {
181
+ Vector3.vectorPool.push(vectorNode.data);
182
+ });
183
+ Vector3.vectors.clear();
184
+ }
185
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Vector3.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Vector3.test.d.ts","sourceRoot":"","sources":["../src/Vector3.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ import Vector3 from "./Vector3";
3
+ describe("Vector3", () => {
4
+ beforeEach(() => {
5
+ Vector3.clear();
6
+ });
7
+ it("should create and retrieve a vector", () => {
8
+ const entity = "entity1";
9
+ Vector3.create(entity, 1, 2, 3);
10
+ const vector = Vector3.get(entity);
11
+ expect(vector).toEqual({ x: 1, y: 2, z: 3 });
12
+ });
13
+ it("should update a vector", () => {
14
+ const entity = "entity2";
15
+ Vector3.create(entity, 1, 2, 3);
16
+ Vector3.set(entity, 4, 5, 6);
17
+ const vector = Vector3.get(entity);
18
+ expect(vector).toEqual({ x: 4, y: 5, z: 6 });
19
+ });
20
+ it("should add values to a vector", () => {
21
+ const entity = "entity3";
22
+ Vector3.create(entity, 1, 2, 3);
23
+ Vector3.add(entity, 1, 1, 1);
24
+ const vector = Vector3.get(entity);
25
+ expect(vector).toEqual({ x: 2, y: 3, z: 4 });
26
+ });
27
+ it("should subtract values from a vector", () => {
28
+ const entity = "entity4";
29
+ Vector3.create(entity, 5, 5, 5);
30
+ Vector3.subtract(entity, 2, 2, 2);
31
+ const vector = Vector3.get(entity);
32
+ expect(vector).toEqual({ x: 3, y: 3, z: 3 });
33
+ });
34
+ it("should multiply values of a vector", () => {
35
+ const entity = "entity5";
36
+ Vector3.create(entity, 2, 3, 4);
37
+ Vector3.multiply(entity, 2, 2, 2);
38
+ const vector = Vector3.get(entity);
39
+ expect(vector).toEqual({ x: 4, y: 6, z: 8 });
40
+ });
41
+ it("should divide values of a vector", () => {
42
+ const entity = "entity6";
43
+ Vector3.create(entity, 8, 6, 4);
44
+ Vector3.divide(entity, 2, 2, 2);
45
+ const vector = Vector3.get(entity);
46
+ expect(vector).toEqual({ x: 4, y: 3, z: 2 });
47
+ });
48
+ it("should throw an error if vector not found", () => {
49
+ expect(() => Vector3.set("nonexistent", 1, 1, 1)).toThrow(
50
+ "Vector not found"
51
+ );
52
+ expect(() => Vector3.add("nonexistent", 1, 1, 1)).toThrow(
53
+ "Vector not found"
54
+ );
55
+ expect(() => Vector3.subtract("nonexistent", 1, 1, 1)).toThrow(
56
+ "Vector not found"
57
+ );
58
+ expect(() => Vector3.multiply("nonexistent", 1, 1, 1)).toThrow(
59
+ "Vector not found"
60
+ );
61
+ expect(() => Vector3.divide("nonexistent", 1, 1, 1)).toThrow(
62
+ "Vector not found"
63
+ );
64
+ });
65
+ it("should throw an error on division by zero", () => {
66
+ const entity = "entity7";
67
+ Vector3.create(entity, 1, 1, 1);
68
+ expect(() => Vector3.divide(entity, 0, 1, 1)).toThrow("Division by zero");
69
+ expect(() => Vector3.divide(entity, 1, 0, 1)).toThrow("Division by zero");
70
+ expect(() => Vector3.divide(entity, 1, 1, 0)).toThrow("Division by zero");
71
+ });
72
+ it("should calculate the magnitude of a vector", () => {
73
+ const entity = "entity8";
74
+ Vector3.create(entity, 3, 4, 0);
75
+ const magnitude = Vector3.magnitude(entity);
76
+ expect(magnitude).toBe(5);
77
+ });
78
+ it("should normalize a vector", () => {
79
+ const entity = "entity9";
80
+ Vector3.create(entity, 3, 4, 0);
81
+ Vector3.normalize(entity);
82
+ const vector = Vector3.get(entity);
83
+ expect(vector).toEqual({ x: 0.6, y: 0.8, z: 0 });
84
+ });
85
+ it("should throw an error when normalizing a zero vector", () => {
86
+ const entity = "entity10";
87
+ Vector3.create(entity, 0, 0, 0);
88
+ expect(() => Vector3.normalize(entity)).toThrow(
89
+ "Cannot normalize a zero vector"
90
+ );
91
+ });
92
+ it("should calculate the dot product of two vectors", () => {
93
+ const entity1 = "entity11";
94
+ const entity2 = "entity12";
95
+ Vector3.create(entity1, 1, 2, 3);
96
+ Vector3.create(entity2, 4, 5, 6);
97
+ const dotProduct = Vector3.dotProduct(entity1, entity2);
98
+ expect(dotProduct).toBe(32);
99
+ });
100
+ });
101
+ describe("Vector3 Pool", () => {
102
+ beforeEach(() => {
103
+ Vector3.clear();
104
+ });
105
+ it("should reuse vectors from the pool", () => {
106
+ const entity1 = "entity1";
107
+ const entity2 = "entity2";
108
+ Vector3.create(entity1, 1, 2, 3);
109
+ Vector3.destroy(entity1);
110
+ Vector3.create(entity2, 4, 5, 6);
111
+ const vector = Vector3.get(entity2);
112
+ expect(vector).toEqual({ x: 4, y: 5, z: 6 });
113
+ });
114
+ it("should clear all vectors and return them to the pool", () => {
115
+ const entity1 = "entity1";
116
+ const entity2 = "entity2";
117
+ Vector3.create(entity1, 1, 2, 3);
118
+ Vector3.create(entity2, 4, 5, 6);
119
+ Vector3.clear();
120
+ Vector3.create(entity1, 7, 8, 9);
121
+ Vector3.create(entity2, 10, 11, 12);
122
+ const vector1 = Vector3.get(entity1);
123
+ const vector2 = Vector3.get(entity2);
124
+ expect(vector1).toEqual({ x: 7, y: 8, z: 9 });
125
+ expect(vector2).toEqual({ x: 10, y: 11, z: 12 });
126
+ });
127
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=common.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Common.test.d.ts","sourceRoot":"","sources":["../src/Common.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=event.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Event.test.d.ts","sourceRoot":"","sources":["../src/Event.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ export * from "./Argila";
2
+ export * from "./systems/Draw";
3
+ export * from "./systems/World";
4
+ export * from "./systems/Entity";
5
+ export * from "./systems/Shape";
6
+ export * from "./Vector3";
7
+ export * from "./systems/Input";
8
+ export * from "./Canvas";
9
+ export * from "./systems/Loop";
10
+ export * from "./systems/debugs/Debug";
11
+ export * from "./Common";
12
+ export * from "./systems/Render";
13
+ export * from "./systems/System";
14
+ import Argila from "./Argila";
15
+ import Draw from "./systems/Draw";
16
+ import World from "./systems/World";
17
+ import Entity from "./systems/Entity";
18
+ import Shape from "./systems/Shape";
19
+ import Vector3 from "./Vector3";
20
+ import Input from "./systems/Input";
21
+ import Canvas from "./Canvas";
22
+ import Loop from "./systems/Loop";
23
+ import { IDebugSystem } from "./systems/debugs/Debug";
24
+ export * from "./Common";
25
+ import Render from "./systems/Render";
26
+ import { System } from "./systems/System";
27
+ export default Argila;
28
+ export { Draw, World, Entity, Shape, Vector3, System, Input, Canvas, Render, Loop, IDebugSystem, };
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AAEjC,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,IAAI,MAAM,gBAAgB,CAAC;AAClC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,IAAI,MAAM,gBAAgB,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,cAAc,UAAU,CAAC;AACzB,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,eAAe,MAAM,CAAC;AAEtB,OAAO,EACN,IAAI,EACJ,KAAK,EACL,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,EACN,KAAK,EACL,MAAM,EACN,MAAM,EACN,IAAI,EACJ,YAAY,GACZ,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ export * from "./Argila";
3
+ export * from "./systems/Draw";
4
+ export * from "./systems/World";
5
+ export * from "./systems/Entity";
6
+ export * from "./systems/Shape";
7
+ export * from "./Vector3";
8
+ export * from "./systems/Input";
9
+ export * from "./Canvas";
10
+ export * from "./systems/Loop";
11
+ export * from "./systems/debugs/Debug";
12
+ export * from "./Common";
13
+ export * from "./systems/Render";
14
+ export * from "./systems/System";
15
+ import Argila from "./Argila";
16
+ import Draw from "./systems/Draw";
17
+ import World from "./systems/World";
18
+ import Entity from "./systems/Entity";
19
+ import Shape from "./systems/Shape";
20
+ import Vector3 from "./Vector3";
21
+ import Input from "./systems/Input";
22
+ import Canvas from "./Canvas";
23
+ import Loop from "./systems/Loop";
24
+ import { IDebugSystem } from "./systems/debugs/Debug";
25
+ export * from "./Common";
26
+ import Render from "./systems/Render";
27
+ import { System } from "./systems/System";
28
+ export default Argila;
29
+ export {
30
+ Draw,
31
+ World,
32
+ Entity,
33
+ Shape,
34
+ Vector3,
35
+ System,
36
+ Input,
37
+ Canvas,
38
+ Render,
39
+ Loop,
40
+ IDebugSystem
41
+ };
@@ -0,0 +1,8 @@
1
+ import { System } from "./System";
2
+ export default class Draw extends System {
3
+ static id: string;
4
+ static create(_world: string, _entity: string): string;
5
+ static tick(_dt: number): void;
6
+ static clear(): void;
7
+ }
8
+ //# sourceMappingURL=Draw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Draw.d.ts","sourceRoot":"","sources":["../../src/systems/Draw.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,MAAM;IACvC,OAAc,EAAE,SAAU;WAEZ,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;WAM/C,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;WAKvB,KAAK,IAAI,IAAI;CAC3B"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ import { v4 as uuidv4 } from "uuid";
3
+ import { System } from "./System";
4
+ export default class Draw extends System {
5
+ static id = "draw";
6
+ static create(_world, _entity) {
7
+ const id = uuidv4();
8
+ return id;
9
+ }
10
+ static tick(_dt) {
11
+ }
12
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
13
+ static clear() {
14
+ }
15
+ }
@@ -0,0 +1,18 @@
1
+ export type EntityID = string;
2
+ export type EntityName = string;
3
+ export interface EntityConfig {
4
+ name: EntityName;
5
+ id: EntityID;
6
+ world: string;
7
+ }
8
+ export default class Entity {
9
+ static id: string;
10
+ private static list;
11
+ static create(world: string): EntityID;
12
+ static setName(entity: EntityID, name: EntityName): void;
13
+ static getName(entity: EntityID): EntityName;
14
+ static get(entity: EntityID): EntityConfig | undefined;
15
+ static destroy(entity: EntityID): void;
16
+ static clear(): void;
17
+ }
18
+ //# sourceMappingURL=Entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Entity.d.ts","sourceRoot":"","sources":["../../src/systems/Entity.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC9B,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,QAAQ,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd;AAED,MAAM,CAAC,OAAO,OAAO,MAAM;IAC1B,OAAc,EAAE,SAAY;IAE5B,OAAO,CAAC,MAAM,CAAC,IAAI,CAA0C;WAE/C,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ;WAc/B,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI;WASjD,OAAO,CAAC,MAAM,EAAE,QAAQ,GAAG,UAAU;WAUrC,GAAG,CAAC,MAAM,EAAE,QAAQ,GAAG,YAAY,GAAG,SAAS;WAI/C,OAAO,CAAC,MAAM,EAAE,QAAQ,GAAG,IAAI;WAQ/B,KAAK,IAAI,IAAI;CAG3B"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ import { v4 as uuidv4 } from "uuid";
3
+ import World from "./World";
4
+ export default class Entity {
5
+ static id = "entity";
6
+ static list = /* @__PURE__ */ new Map();
7
+ static create(world) {
8
+ const id = uuidv4();
9
+ Entity.list.set(id, {
10
+ id,
11
+ name: id,
12
+ world
13
+ });
14
+ World.addEntity(world, id);
15
+ return id;
16
+ }
17
+ static setName(entity, name) {
18
+ const e = this.get(entity);
19
+ if (!e) {
20
+ throw Error(`Entity ${entity} does not exist`);
21
+ }
22
+ e.name = name;
23
+ }
24
+ static getName(entity) {
25
+ const e = this.get(entity);
26
+ if (!e) {
27
+ throw Error(`Entity ${entity} does not exist`);
28
+ }
29
+ return e.name;
30
+ }
31
+ static get(entity) {
32
+ return Entity.list.get(entity);
33
+ }
34
+ static destroy(entity) {
35
+ const e = Entity.list.get(entity);
36
+ if (e) {
37
+ World.removeEntity(e.world, entity);
38
+ Entity.list.delete(entity);
39
+ }
40
+ }
41
+ static clear() {
42
+ Entity.list.clear();
43
+ }
44
+ }
@@ -0,0 +1,127 @@
1
+ import InputDebug from "./debugs/InputDebug";
2
+ import { System } from "./System";
3
+ interface Pointer {
4
+ x: number;
5
+ y: number;
6
+ overCanvas: boolean;
7
+ current?: string;
8
+ }
9
+ interface Wheel {
10
+ delta: {
11
+ x: number;
12
+ y: number;
13
+ z: number;
14
+ };
15
+ deltaMode: typeof WheelEvent.DOM_DELTA_PIXEL | typeof WheelEvent.DOM_DELTA_LINE | typeof WheelEvent.DOM_DELTA_PAGE | undefined;
16
+ }
17
+ type InputEventType = "mousemove" | "mousedown" | "mouseup" | "mouseenter" | "mouseleave" | "wheel";
18
+ export default class Input extends System {
19
+ static id: string;
20
+ static debug: InputDebug;
21
+ static pointer: Pointer;
22
+ static wheel: Wheel;
23
+ static dontPreventDefault: Set<InputEventType>;
24
+ static pressedList: Map<MouseButton | Keys, boolean>;
25
+ static justPressedList: Set<MouseButton | Keys>;
26
+ static showDebug: boolean;
27
+ static pressed(key: MouseButton | Keys): boolean | undefined;
28
+ static justPressed(key: MouseButton | Keys): boolean;
29
+ static handlePreventDefault(event: MouseEvent | WheelEvent): void;
30
+ static setupCanvasEventListeners(canvasID: string): void;
31
+ static tick(): void;
32
+ }
33
+ export declare enum MouseButton {
34
+ MAIN = "main-mouse-btn",// Main button pressed, usually the left button or the un-initialized state
35
+ AUXILIARY = "auxiliary-mouse-btn",// Auxiliary button pressed, usually the wheel button or the middle button (if present)
36
+ SECONDARY = "secondary-mouse-btn",// Secondary button pressed, usually the right button
37
+ FOURTH = "fourth-mouse-btn",// Fourth button, typically the Browser Back button
38
+ FIFTH = "fifth-mouse-btn"
39
+ }
40
+ export declare enum Keys {
41
+ a = "a",
42
+ b = "b",
43
+ c = "c",
44
+ d = "d",
45
+ e = "e",
46
+ f = "f",
47
+ g = "g",
48
+ h = "h",
49
+ i = "i",
50
+ j = "j",
51
+ k = "k",
52
+ l = "l",
53
+ m = "m",
54
+ n = "n",
55
+ o = "o",
56
+ p = "p",
57
+ q = "q",
58
+ r = "r",
59
+ s = "s",
60
+ t = "t",
61
+ u = "u",
62
+ v = "v",
63
+ w = "w",
64
+ x = "x",
65
+ y = "y",
66
+ z = "z",
67
+ A = "A",
68
+ B = "B",
69
+ C = "C",
70
+ D = "D",
71
+ E = "E",
72
+ F = "F",
73
+ G = "G",
74
+ H = "H",
75
+ I = "I",
76
+ J = "J",
77
+ K = "K",
78
+ L = "L",
79
+ M = "M",
80
+ N = "N",
81
+ O = "O",
82
+ P = "P",
83
+ Q = "Q",
84
+ R = "R",
85
+ S = "S",
86
+ T = "T",
87
+ U = "U",
88
+ V = "V",
89
+ W = "W",
90
+ X = "X",
91
+ Y = "Y",
92
+ Z = "Z",
93
+ Space = " ",
94
+ ArrowDown = "ArrowDown",
95
+ ArrowLeft = "ArrowLeft",
96
+ ArrowRight = "ArrowRight",
97
+ ArrowUp = "ArrowUp",
98
+ End = "End",
99
+ Home = "Home",
100
+ PageDown = "PageDown",
101
+ PageUp = "PageUp",
102
+ Enter = "Enter",
103
+ Tab = "Tab",
104
+ Control = "Control",
105
+ Fn = "Fn",
106
+ CapsLock = "CapsLock",
107
+ Alt = "Alt",
108
+ AltGraph = "AltGraph",
109
+ Shift = "Shift",
110
+ Backspace = "Backspace",
111
+ Delete = "Delete",
112
+ Insert = "Insert",
113
+ F1 = "F1",
114
+ F2 = "F2",
115
+ F3 = "F3",
116
+ F4 = "F4",
117
+ F5 = "F5",
118
+ F6 = "F6",
119
+ F7 = "F7",
120
+ F8 = "F8",
121
+ F9 = "F9",
122
+ F10 = "F10",
123
+ F11 = "F11",
124
+ F12 = "F12"
125
+ }
126
+ export {};
127
+ //# sourceMappingURL=Input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Input.d.ts","sourceRoot":"","sources":["../../src/systems/Input.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,UAAU,OAAO;IACf,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,KAAK;IACb,KAAK,EAAE;QACL,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;IACF,SAAS,EACL,OAAO,UAAU,CAAC,eAAe,GACjC,OAAO,UAAU,CAAC,cAAc,GAChC,OAAO,UAAU,CAAC,cAAc,GAChC,SAA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