@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,191 @@
1
+ "use strict";
2
+ import Canvas from "../Canvas";
3
+ import InputDebug from "./debugs/InputDebug";
4
+ import { System } from "./System";
5
+ export default class Input extends System {
6
+ static id = "input";
7
+ static debug = new InputDebug();
8
+ static pointer = {
9
+ x: 0,
10
+ y: 0,
11
+ overCanvas: false,
12
+ current: void 0
13
+ };
14
+ static wheel = {
15
+ delta: {
16
+ x: 0,
17
+ y: 0,
18
+ z: 0
19
+ },
20
+ deltaMode: void 0
21
+ };
22
+ static dontPreventDefault = /* @__PURE__ */ new Set();
23
+ static pressedList = /* @__PURE__ */ new Map();
24
+ static justPressedList = /* @__PURE__ */ new Set();
25
+ static showDebug = false;
26
+ static pressed(key) {
27
+ if (!this.pressedList.has(key)) {
28
+ this.pressedList.set(key, false);
29
+ }
30
+ return this.pressedList.get(key);
31
+ }
32
+ static justPressed(key) {
33
+ return this.justPressedList.has(key);
34
+ }
35
+ static handlePreventDefault(event) {
36
+ if (this.dontPreventDefault.has(event.type)) {
37
+ event.preventDefault();
38
+ }
39
+ }
40
+ static setupCanvasEventListeners(canvasID) {
41
+ const canvas = Canvas.get(canvasID);
42
+ if (!canvas) {
43
+ return;
44
+ }
45
+ canvas.element.addEventListener("mousemove", (event) => {
46
+ this.handlePreventDefault(event);
47
+ this.dontPreventDefault.has("mousemove");
48
+ const rect = canvas.element.getBoundingClientRect();
49
+ const x = event.clientX - rect.left;
50
+ const y = event.clientY - rect.top;
51
+ Input.pointer.x = x;
52
+ Input.pointer.y = y;
53
+ Input.pointer.overCanvas = true;
54
+ });
55
+ canvas.element.addEventListener("mousedown", (event) => {
56
+ this.handlePreventDefault(event);
57
+ const button = MouseButtonsMap[event.button];
58
+ this.pressedList.set(MouseButton[button], true);
59
+ this.justPressedList.add(MouseButton[button]);
60
+ });
61
+ canvas.element.addEventListener("mouseup", (event) => {
62
+ this.handlePreventDefault(event);
63
+ const button = MouseButtonsMap[event.button];
64
+ Input.pressedList.set(MouseButton[button], false);
65
+ });
66
+ canvas.element.addEventListener("mouseenter", (event) => {
67
+ this.handlePreventDefault(event);
68
+ Input.pointer.overCanvas = true;
69
+ Input.pointer.current = canvasID;
70
+ });
71
+ canvas.element.addEventListener("mouseleave", (event) => {
72
+ this.handlePreventDefault(event);
73
+ Input.pointer.overCanvas = false;
74
+ Input.pointer.current = void 0;
75
+ });
76
+ canvas.element.addEventListener("wheel", (event) => {
77
+ this.handlePreventDefault(event);
78
+ this.wheel.delta.x = Math.sign(event.deltaX);
79
+ this.wheel.delta.y = Math.sign(event.deltaY);
80
+ this.wheel.delta.z = Math.sign(event.deltaZ);
81
+ this.wheel.deltaMode = event.deltaMode;
82
+ });
83
+ }
84
+ static tick() {
85
+ if (this.debug) {
86
+ this.debug.tick();
87
+ }
88
+ this.justPressedList.clear();
89
+ this.wheel.delta.x = 0;
90
+ this.wheel.delta.y = 0;
91
+ this.wheel.delta.z = 0;
92
+ }
93
+ }
94
+ export var MouseButton = /* @__PURE__ */ ((MouseButton2) => {
95
+ MouseButton2["MAIN"] = "main-mouse-btn";
96
+ MouseButton2["AUXILIARY"] = "auxiliary-mouse-btn";
97
+ MouseButton2["SECONDARY"] = "secondary-mouse-btn";
98
+ MouseButton2["FOURTH"] = "fourth-mouse-btn";
99
+ MouseButton2["FIFTH"] = "fifth-mouse-btn";
100
+ return MouseButton2;
101
+ })(MouseButton || {});
102
+ const MouseButtonsMap = Object.keys(
103
+ MouseButton
104
+ );
105
+ export var Keys = /* @__PURE__ */ ((Keys2) => {
106
+ Keys2["a"] = "a";
107
+ Keys2["b"] = "b";
108
+ Keys2["c"] = "c";
109
+ Keys2["d"] = "d";
110
+ Keys2["e"] = "e";
111
+ Keys2["f"] = "f";
112
+ Keys2["g"] = "g";
113
+ Keys2["h"] = "h";
114
+ Keys2["i"] = "i";
115
+ Keys2["j"] = "j";
116
+ Keys2["k"] = "k";
117
+ Keys2["l"] = "l";
118
+ Keys2["m"] = "m";
119
+ Keys2["n"] = "n";
120
+ Keys2["o"] = "o";
121
+ Keys2["p"] = "p";
122
+ Keys2["q"] = "q";
123
+ Keys2["r"] = "r";
124
+ Keys2["s"] = "s";
125
+ Keys2["t"] = "t";
126
+ Keys2["u"] = "u";
127
+ Keys2["v"] = "v";
128
+ Keys2["w"] = "w";
129
+ Keys2["x"] = "x";
130
+ Keys2["y"] = "y";
131
+ Keys2["z"] = "z";
132
+ Keys2["A"] = "A";
133
+ Keys2["B"] = "B";
134
+ Keys2["C"] = "C";
135
+ Keys2["D"] = "D";
136
+ Keys2["E"] = "E";
137
+ Keys2["F"] = "F";
138
+ Keys2["G"] = "G";
139
+ Keys2["H"] = "H";
140
+ Keys2["I"] = "I";
141
+ Keys2["J"] = "J";
142
+ Keys2["K"] = "K";
143
+ Keys2["L"] = "L";
144
+ Keys2["M"] = "M";
145
+ Keys2["N"] = "N";
146
+ Keys2["O"] = "O";
147
+ Keys2["P"] = "P";
148
+ Keys2["Q"] = "Q";
149
+ Keys2["R"] = "R";
150
+ Keys2["S"] = "S";
151
+ Keys2["T"] = "T";
152
+ Keys2["U"] = "U";
153
+ Keys2["V"] = "V";
154
+ Keys2["W"] = "W";
155
+ Keys2["X"] = "X";
156
+ Keys2["Y"] = "Y";
157
+ Keys2["Z"] = "Z";
158
+ Keys2["Space"] = " ";
159
+ Keys2["ArrowDown"] = "ArrowDown";
160
+ Keys2["ArrowLeft"] = "ArrowLeft";
161
+ Keys2["ArrowRight"] = "ArrowRight";
162
+ Keys2["ArrowUp"] = "ArrowUp";
163
+ Keys2["End"] = "End";
164
+ Keys2["Home"] = "Home";
165
+ Keys2["PageDown"] = "PageDown";
166
+ Keys2["PageUp"] = "PageUp";
167
+ Keys2["Enter"] = "Enter";
168
+ Keys2["Tab"] = "Tab";
169
+ Keys2["Control"] = "Control";
170
+ Keys2["Fn"] = "Fn";
171
+ Keys2["CapsLock"] = "CapsLock";
172
+ Keys2["Alt"] = "Alt";
173
+ Keys2["AltGraph"] = "AltGraph";
174
+ Keys2["Shift"] = "Shift";
175
+ Keys2["Backspace"] = "Backspace";
176
+ Keys2["Delete"] = "Delete";
177
+ Keys2["Insert"] = "Insert";
178
+ Keys2["F1"] = "F1";
179
+ Keys2["F2"] = "F2";
180
+ Keys2["F3"] = "F3";
181
+ Keys2["F4"] = "F4";
182
+ Keys2["F5"] = "F5";
183
+ Keys2["F6"] = "F6";
184
+ Keys2["F7"] = "F7";
185
+ Keys2["F8"] = "F8";
186
+ Keys2["F9"] = "F9";
187
+ Keys2["F10"] = "F10";
188
+ Keys2["F11"] = "F11";
189
+ Keys2["F12"] = "F12";
190
+ return Keys2;
191
+ })(Keys || {});
@@ -0,0 +1,29 @@
1
+ import { IDebugSystem } from "./debugs/Debug";
2
+ import { System } from "./System";
3
+ export interface ILoopConfig {
4
+ dt: number;
5
+ last: number;
6
+ now: number;
7
+ elapsed: number;
8
+ autoDestory: boolean;
9
+ beforeTickTime: number;
10
+ afterTickTime: number;
11
+ id?: string;
12
+ tick: (dt: number) => void;
13
+ }
14
+ type IGeneralLoop = Omit<ILoopConfig, "tick"> & {
15
+ running: boolean;
16
+ };
17
+ export default class Loop extends System {
18
+ static id: string;
19
+ static loops: Map<string, ILoopConfig>;
20
+ static requestAnimationFrameID: number;
21
+ static debug: IDebugSystem;
22
+ static general: IGeneralLoop;
23
+ static get(id: string): ILoopConfig | undefined;
24
+ static create(id: string, tick: (dt: number) => void): string;
25
+ static tick(now: number): Promise<void>;
26
+ static clear(): void;
27
+ }
28
+ export {};
29
+ //# sourceMappingURL=Loop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Loop.d.ts","sourceRoot":"","sources":["../../src/systems/Loop.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,MAAM,WAAW,WAAW;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3B;AAED,KAAK,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAErE,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,MAAM;IACvC,OAAc,EAAE,SAAU;IAC1B,OAAc,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAa;IAC1D,OAAc,uBAAuB,EAAE,MAAM,CAAC;IAC9C,OAAc,KAAK,EAAE,YAAY,CAAmB;IAEpD,OAAc,OAAO,EAAE,YAAY,CASjC;WAEY,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;WAIxC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM;WAqBhD,IAAI,CAAC,GAAG,EAAE,MAAM;WAmDtB,KAAK;CAYnB"}
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ import LoopDebug from "./debugs/LoopDebug";
3
+ import { System } from "./System";
4
+ import Input from "./Input";
5
+ export default class Loop extends System {
6
+ static id = "loop";
7
+ static loops = /* @__PURE__ */ new Map();
8
+ static requestAnimationFrameID;
9
+ static debug = new LoopDebug();
10
+ static general = {
11
+ running: false,
12
+ dt: 0,
13
+ last: 0,
14
+ now: 0,
15
+ autoDestory: true,
16
+ beforeTickTime: 0,
17
+ afterTickTime: 0,
18
+ elapsed: 0
19
+ };
20
+ static get(id) {
21
+ return this.loops.get(id);
22
+ }
23
+ static create(id, tick) {
24
+ Loop.loops.set(id, {
25
+ dt: 0,
26
+ last: 0,
27
+ now: 0,
28
+ elapsed: 0,
29
+ autoDestory: true,
30
+ beforeTickTime: 0,
31
+ afterTickTime: 0,
32
+ tick,
33
+ id
34
+ });
35
+ if (!Loop.general.running) {
36
+ Loop.general.running = true;
37
+ Loop.tick(0);
38
+ }
39
+ return id;
40
+ }
41
+ static async tick(now) {
42
+ Loop.general.dt = (now - Loop.general.last) / 1e3;
43
+ Loop.general.last = now;
44
+ Loop.general.now = now;
45
+ Loop.general.elapsed += Loop.general.dt;
46
+ const main = Loop.loops.get("main");
47
+ if (main) {
48
+ main.dt = (now - main.last) / 1e3;
49
+ main.last = now;
50
+ main.now = now;
51
+ main.elapsed += main.dt;
52
+ main.beforeTickTime = performance.now();
53
+ main?.tick(Loop.general.dt);
54
+ main.afterTickTime = performance.now();
55
+ }
56
+ Loop.loops.forEach((loop) => {
57
+ if (loop.id !== "main" || loop.id !== "vue-debug") {
58
+ loop.dt = (now - loop.last) / 1e3;
59
+ loop.last = now;
60
+ loop.elapsed += loop.dt;
61
+ loop.now = now;
62
+ loop.beforeTickTime = performance.now();
63
+ loop.tick(Loop.general.dt);
64
+ loop.afterTickTime = performance.now();
65
+ }
66
+ });
67
+ Input.tick();
68
+ const debug = Loop.loops.get("vue-debug");
69
+ if (debug) {
70
+ debug.dt = (now - debug.last) / 1e3;
71
+ debug.last = now;
72
+ debug.now = now;
73
+ debug.elapsed += debug.dt;
74
+ debug.beforeTickTime = performance.now();
75
+ debug?.tick(Loop.general.dt);
76
+ debug.afterTickTime = performance.now();
77
+ }
78
+ if (typeof window !== "undefined") {
79
+ Loop.requestAnimationFrameID = window.requestAnimationFrame(Loop.tick);
80
+ }
81
+ }
82
+ static clear() {
83
+ Loop.loops.forEach((loop, key) => {
84
+ if (loop.autoDestory) {
85
+ Loop.loops.delete(key);
86
+ }
87
+ });
88
+ Loop.general.running = false;
89
+ if (typeof window !== "undefined") {
90
+ window.cancelAnimationFrame(Loop.requestAnimationFrameID);
91
+ }
92
+ }
93
+ }
@@ -0,0 +1,21 @@
1
+ import { ICircle, IPolygon, IRectangle } from "./Shape";
2
+ import { System } from "./System";
3
+ interface RenderConfig {
4
+ canvasID: string;
5
+ }
6
+ export default class Render extends System {
7
+ static id: string;
8
+ static list: Map<string, RenderConfig>;
9
+ static create(entity: string, canvasID: string): void;
10
+ static drawCircle(ctx: CanvasRenderingContext2D, shape: ICircle, x: number, y: number): void;
11
+ static drawRectangle(ctx: CanvasRenderingContext2D, shape: IRectangle, x: number, y: number): void;
12
+ static drawPolygon(ctx: CanvasRenderingContext2D, shape: IPolygon, x: number, y: number): void;
13
+ static tick(_dt: number, entity: string): void;
14
+ static set(entity: string, canvasID?: string): void;
15
+ static setCanvas(entity: string, canvasID?: string): void;
16
+ static get(entity: string): RenderConfig | undefined;
17
+ static destroy(entity: string): void;
18
+ static clear(): void;
19
+ }
20
+ export {};
21
+ //# sourceMappingURL=Render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Render.d.ts","sourceRoot":"","sources":["../../src/systems/Render.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG/D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,UAAU,YAAY;IACrB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAID,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,MAAM;IACzC,MAAM,CAAC,EAAE,SAAY;IAErB,OAAc,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAa;WAE5C,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;WAM9C,UAAU,CACvB,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,OAAO,EACd,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM;WAiBI,aAAa,CAC1B,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,UAAU,EACjB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM;WAgBI,WAAW,CACxB,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,QAAQ,EACf,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM;WA6BI,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;WA4BvC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;WAY5C,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI;WAYlD,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;WAI7C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;WAI7B,KAAK,IAAI,IAAI;CAG3B"}
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ import Shape from "./Shape";
3
+ import Canvas from "../Canvas";
4
+ import Vector3 from "../Vector3";
5
+ import { System } from "./System";
6
+ const DEFAULT_VECTOR = { x: 0, y: 0, z: 0 };
7
+ export default class Render extends System {
8
+ static id = "render";
9
+ static list = /* @__PURE__ */ new Map();
10
+ static create(entity, canvasID) {
11
+ Render.list.set(entity, {
12
+ canvasID
13
+ });
14
+ }
15
+ static drawCircle(ctx, shape, x, y) {
16
+ ctx.beginPath();
17
+ ctx.arc(x, y, shape.radius, 0, 2 * Math.PI);
18
+ ctx.closePath();
19
+ if (shape.fillColor) {
20
+ ctx.fillStyle = shape.fillColor;
21
+ ctx.fill();
22
+ }
23
+ ctx.lineWidth = shape.strokeWidth ?? ctx.lineWidth;
24
+ if (shape.strokeColor) {
25
+ ctx.strokeStyle = shape.strokeColor;
26
+ ctx.stroke();
27
+ }
28
+ }
29
+ static drawRectangle(ctx, shape, x, y) {
30
+ ctx.beginPath();
31
+ ctx.rect(x, y, shape.width, shape.height);
32
+ ctx.closePath();
33
+ if (shape.fillColor) {
34
+ ctx.fillStyle = shape.fillColor;
35
+ ctx.fill();
36
+ }
37
+ ctx.lineWidth = shape.strokeWidth ?? ctx.lineWidth;
38
+ if (shape.strokeColor) {
39
+ ctx.strokeStyle = shape.strokeColor;
40
+ ctx.stroke();
41
+ }
42
+ }
43
+ static drawPolygon(ctx, shape, x, y) {
44
+ ctx.beginPath();
45
+ const vertices = shape.vertices;
46
+ ctx.moveTo(Math.floor(vertices[0][0] + x), Math.floor(vertices[0][1] + y));
47
+ for (let j = 1; j < vertices.length; j += 1) {
48
+ const vertice = vertices[j];
49
+ ctx.lineTo(Math.floor(vertice[0] + x), Math.floor(vertice[1] + y));
50
+ }
51
+ ctx.lineTo(Math.floor(vertices[0][0] + x), Math.floor(vertices[0][1] + y));
52
+ ctx.closePath();
53
+ if (shape.fillColor) {
54
+ ctx.fillStyle = shape.fillColor;
55
+ ctx.fill();
56
+ }
57
+ ctx.lineWidth = shape.strokeWidth ?? ctx.lineWidth;
58
+ if (shape.strokeColor) {
59
+ ctx.strokeStyle = shape.strokeColor;
60
+ ctx.stroke();
61
+ }
62
+ }
63
+ static tick(_dt, entity) {
64
+ const shapes = Shape.get(entity);
65
+ const renderConfig = Render.list.get(entity);
66
+ if (!(shapes && renderConfig)) {
67
+ return;
68
+ }
69
+ shapes.forEach((shape) => {
70
+ const ctx = Canvas.get(renderConfig.canvasID)?.ctx;
71
+ const vector = Vector3.get(entity) ?? DEFAULT_VECTOR;
72
+ if (ctx) {
73
+ if (Shape.isCircle(shape)) {
74
+ this.drawCircle(ctx, shape, vector.x, vector.y);
75
+ }
76
+ if (Shape.isRectangle(shape)) {
77
+ this.drawRectangle(ctx, shape, vector.x, vector.y);
78
+ }
79
+ if (Shape.isPolygon(shape)) {
80
+ this.drawPolygon(ctx, shape, vector.x, vector.y);
81
+ }
82
+ }
83
+ });
84
+ }
85
+ static set(entity, canvasID) {
86
+ const config = Render.list.get(entity);
87
+ if (!config) {
88
+ return;
89
+ }
90
+ if (canvasID) {
91
+ config.canvasID = canvasID;
92
+ }
93
+ }
94
+ static setCanvas(entity, canvasID) {
95
+ const config = Render.list.get(entity);
96
+ if (!config) {
97
+ return;
98
+ }
99
+ if (canvasID) {
100
+ config.canvasID = canvasID;
101
+ }
102
+ }
103
+ static get(entity) {
104
+ return Render.list.get(entity);
105
+ }
106
+ static destroy(entity) {
107
+ Render.list.delete(entity);
108
+ }
109
+ static clear() {
110
+ Render.list.clear();
111
+ }
112
+ }
@@ -0,0 +1,48 @@
1
+ export interface IShape {
2
+ type: "circle" | "rectangle" | "polygon";
3
+ entity: string;
4
+ id: string;
5
+ strokeColor?: string;
6
+ strokeWidth?: number;
7
+ fillColor?: string;
8
+ }
9
+ export interface ICircle extends IShape {
10
+ radius: number;
11
+ }
12
+ export interface IRectangle extends IShape {
13
+ width: number;
14
+ height: number;
15
+ }
16
+ export type PolygonVector = [number, number];
17
+ export interface IPolygon extends IShape {
18
+ vertices: PolygonVector[];
19
+ }
20
+ export type IShapes = ICircle | IRectangle | IPolygon;
21
+ export default class Shape {
22
+ static id: string;
23
+ private static list;
24
+ static allList: Map<string, IShapes>;
25
+ static circle: {
26
+ create(entity: string, radius: number): string;
27
+ setRadius(entity: string, shape: string, radius: number): void;
28
+ };
29
+ static rectangle: {
30
+ create(entity: string, width: number, height: number): string;
31
+ setSize(entity: string, shape: string, width: number, height: number): void;
32
+ };
33
+ static polygon: {
34
+ create(entity: string, vertices: PolygonVector[]): string;
35
+ };
36
+ static setFillColor(entity: string, shape: string, color?: string): void;
37
+ static setAllFillColor(entity: string, color?: string): void;
38
+ static setStrokeColor(entity: string, shape: string, color?: string): void;
39
+ static setAllStrokeColor(entity: string, color?: string): void;
40
+ static setStrokeWidth(entity: string, shape: string, width?: number): void;
41
+ static get(entity: string): Map<string, IShapes> | undefined;
42
+ static isCircle(shape: IShapes): shape is ICircle;
43
+ static isRectangle(shape: IShapes): shape is IRectangle;
44
+ static isPolygon(shape: IShapes): shape is IPolygon;
45
+ static destroy(entity: string, id?: string): void;
46
+ static clear(): void;
47
+ }
48
+ //# sourceMappingURL=Shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Shape.d.ts","sourceRoot":"","sources":["../../src/systems/Shape.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,OAAQ,SAAQ,MAAM;IACrC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,UAAW,SAAQ,MAAM;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE7C,MAAM,WAAW,QAAS,SAAQ,MAAM;IACtC,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAC;AAEtD,MAAM,CAAC,OAAO,OAAO,KAAK;IACxB,MAAM,CAAC,EAAE,SAAW;IAEpB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAgD;IACnE,OAAc,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAa;IAExD,OAAc,MAAM;uBACH,MAAM,UAAU,MAAM,GAAG,MAAM;0BAwB5B,MAAM,SAAS,MAAM,UAAU,MAAM;MAOvD;IAEF,OAAc,SAAS;uBACN,MAAM,SAAS,MAAM,UAAU,MAAM,GAAG,MAAM;wBAyB7C,MAAM,SAAS,MAAM,SAAS,MAAM,UAAU,MAAM;MAQpE;IAEF,OAAc,OAAO;uBACJ,MAAM,YAAY,aAAa,EAAE,GAAG,MAAM;MAwBzD;WAEY,YAAY,CACxB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,GACb,IAAI;WAUO,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;WAUrD,cAAc,CAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,GACb,IAAI;WAUO,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;WAUvD,cAAc,CAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,GACb,IAAI;WAUO,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;WAIrD,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO;WAI1C,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU;WAIhD,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ;WAI5C,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;WAe1C,KAAK,IAAI,IAAI;CAI5B"}
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ import { v4 as uuidv4 } from "uuid";
3
+ export default class Shape {
4
+ static id = "shape";
5
+ static list = /* @__PURE__ */ new Map();
6
+ static allList = /* @__PURE__ */ new Map();
7
+ static circle = {
8
+ create(entity, radius) {
9
+ const id = uuidv4();
10
+ let shapes = Shape.list.get(entity);
11
+ if (!shapes) {
12
+ Shape.list.set(entity, /* @__PURE__ */ new Map());
13
+ }
14
+ shapes = Shape.list.get(entity);
15
+ const shape = {
16
+ radius,
17
+ entity,
18
+ type: "circle",
19
+ id
20
+ };
21
+ shapes.set(id, shape);
22
+ Shape.allList.set(id, shape);
23
+ return id;
24
+ },
25
+ setRadius(entity, shape, radius) {
26
+ const s = Shape.get(entity)?.get(shape);
27
+ if (s && Shape.isCircle(s)) {
28
+ s.radius = radius;
29
+ }
30
+ }
31
+ };
32
+ static rectangle = {
33
+ create(entity, width, height) {
34
+ const id = uuidv4();
35
+ let shapes = Shape.list.get(entity);
36
+ if (!shapes) {
37
+ Shape.list.set(entity, /* @__PURE__ */ new Map());
38
+ }
39
+ shapes = Shape.list.get(entity);
40
+ const shape = {
41
+ width,
42
+ height,
43
+ entity,
44
+ type: "rectangle",
45
+ id
46
+ };
47
+ shapes.set(id, shape);
48
+ Shape.allList.set(id, shape);
49
+ return id;
50
+ },
51
+ setSize(entity, shape, width, height) {
52
+ const s = Shape.get(entity)?.get(shape);
53
+ if (s && Shape.isRectangle(s)) {
54
+ s.width = width;
55
+ s.height = height;
56
+ }
57
+ }
58
+ };
59
+ static polygon = {
60
+ create(entity, vertices) {
61
+ const id = uuidv4();
62
+ let shapes = Shape.list.get(entity);
63
+ if (!shapes) {
64
+ Shape.list.set(entity, /* @__PURE__ */ new Map());
65
+ }
66
+ shapes = Shape.list.get(entity);
67
+ const shape = {
68
+ vertices,
69
+ entity,
70
+ type: "polygon",
71
+ id
72
+ };
73
+ shapes.set(id, shape);
74
+ Shape.allList.set(id, shape);
75
+ return id;
76
+ }
77
+ };
78
+ static setFillColor(entity, shape, color) {
79
+ const s = Shape.get(entity)?.get(shape);
80
+ if (s) {
81
+ if (color) {
82
+ s.fillColor = color;
83
+ }
84
+ }
85
+ }
86
+ static setAllFillColor(entity, color) {
87
+ const shapes = Shape.get(entity);
88
+ if (shapes) {
89
+ shapes.forEach((shape) => {
90
+ shape.fillColor = color;
91
+ });
92
+ }
93
+ }
94
+ static setStrokeColor(entity, shape, color) {
95
+ const s = Shape.get(entity)?.get(shape);
96
+ if (s) {
97
+ if (color) {
98
+ s.strokeColor = color;
99
+ }
100
+ }
101
+ }
102
+ static setAllStrokeColor(entity, color) {
103
+ const shapes = Shape.get(entity);
104
+ if (shapes) {
105
+ shapes.forEach((shape) => {
106
+ shape.strokeColor = color;
107
+ });
108
+ }
109
+ }
110
+ static setStrokeWidth(entity, shape, width) {
111
+ const s = Shape.get(entity)?.get(shape);
112
+ if (s) {
113
+ if (width) {
114
+ s.strokeWidth = width;
115
+ }
116
+ }
117
+ }
118
+ static get(entity) {
119
+ return Shape.list.get(entity);
120
+ }
121
+ static isCircle(shape) {
122
+ return shape.type === "circle";
123
+ }
124
+ static isRectangle(shape) {
125
+ return shape.type === "rectangle";
126
+ }
127
+ static isPolygon(shape) {
128
+ return shape.type === "polygon";
129
+ }
130
+ static destroy(entity, id) {
131
+ const shape = Shape.list.get(entity);
132
+ if (!shape) {
133
+ return;
134
+ }
135
+ if (!id) {
136
+ shape.clear();
137
+ }
138
+ if (id) {
139
+ shape.delete(id);
140
+ }
141
+ }
142
+ static clear() {
143
+ Shape.list.clear();
144
+ Shape.allList.clear();
145
+ }
146
+ }
@@ -0,0 +1,22 @@
1
+ import { IDebugSystem } from "./debugs/Debug";
2
+ import { EntityID } from "./Entity";
3
+ type TickArgs = [dt: number] | [dt: number, entity: EntityID];
4
+ export interface ISystem {
5
+ id: string;
6
+ loopType: "single" | "entity";
7
+ tick(...args: TickArgs): void;
8
+ clear(): void;
9
+ has(entity: EntityID): boolean;
10
+ debug?: IDebugSystem;
11
+ }
12
+ export declare abstract class System {
13
+ static id: string;
14
+ static debug?: IDebugSystem;
15
+ static list?: Map<EntityID, unknown>;
16
+ static loopType: "entity" | "single";
17
+ static has(entity: EntityID): boolean;
18
+ static tick(..._args: TickArgs): void;
19
+ static clear(): void;
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=System.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"System.d.ts","sourceRoot":"","sources":["../../src/systems/System.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,KAAK,QAAQ,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAE9D,MAAM,WAAW,OAAO;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC9B,IAAI,CAAC,GAAG,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC9B,KAAK,IAAI,IAAI,CAAC;IACd,GAAG,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC/B,KAAK,CAAC,EAAE,YAAY,CAAC;CACrB;AAED,8BAAsB,MAAM;IAC3B,OAAc,EAAE,EAAE,MAAM,CAAY;IACpC,OAAc,KAAK,CAAC,EAAE,YAAY,CAAC;IACnC,OAAc,IAAI,CAAC,EAAE,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAa;IACxD,OAAc,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAY;WAEzC,GAAG,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO;WAQ9B,IAAI,CAAC,GAAG,KAAK,EAAE,QAAQ,GAAG,IAAI;WAG9B,KAAK,IAAI,IAAI;CAG3B"}