dino-ge 1.0.0
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/dist/Camera.d.ts +37 -0
- package/dist/Camera.js +44 -0
- package/dist/Camera.js.map +1 -0
- package/dist/Canvas.d.ts +12 -0
- package/dist/Canvas.js +21 -0
- package/dist/Canvas.js.map +1 -0
- package/dist/Circle.d.ts +39 -0
- package/dist/Circle.js +51 -0
- package/dist/Circle.js.map +1 -0
- package/dist/Engine.d.ts +114 -0
- package/dist/Engine.js +321 -0
- package/dist/Engine.js.map +1 -0
- package/dist/GameObject.d.ts +41 -0
- package/dist/GameObject.js +35 -0
- package/dist/GameObject.js.map +1 -0
- package/dist/Input.d.ts +27 -0
- package/dist/Input.js +99 -0
- package/dist/Input.js.map +1 -0
- package/dist/Line.d.ts +41 -0
- package/dist/Line.js +40 -0
- package/dist/Line.js.map +1 -0
- package/dist/Loader.d.ts +26 -0
- package/dist/Loader.js +76 -0
- package/dist/Loader.js.map +1 -0
- package/dist/Physics.d.ts +16 -0
- package/dist/Physics.js +77 -0
- package/dist/Physics.js.map +1 -0
- package/dist/Rectangle.d.ts +41 -0
- package/dist/Rectangle.js +44 -0
- package/dist/Rectangle.js.map +1 -0
- package/dist/Scene.d.ts +19 -0
- package/dist/Scene.js +27 -0
- package/dist/Scene.js.map +1 -0
- package/dist/Sprite.d.ts +76 -0
- package/dist/Sprite.js +129 -0
- package/dist/Sprite.js.map +1 -0
- package/dist/Text.d.ts +80 -0
- package/dist/Text.js +110 -0
- package/dist/Text.js.map +1 -0
- package/dist/Tilemap.d.ts +46 -0
- package/dist/Tilemap.js +48 -0
- package/dist/Tilemap.js.map +1 -0
- package/dist/Vector2.d.ts +26 -0
- package/dist/Vector2.js +21 -0
- package/dist/Vector2.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/package.json +18 -0
- package/src/Camera.ts +47 -0
- package/src/Canvas.ts +24 -0
- package/src/Circle.ts +88 -0
- package/src/Engine.ts +407 -0
- package/src/GameObject.ts +56 -0
- package/src/Input.ts +117 -0
- package/src/Line.ts +75 -0
- package/src/Loader.ts +66 -0
- package/src/Physics.ts +77 -0
- package/src/Rectangle.ts +83 -0
- package/src/Scene.ts +30 -0
- package/src/Sprite.ts +194 -0
- package/src/Text.ts +187 -0
- package/src/Tilemap.ts +95 -0
- package/src/Vector2.ts +36 -0
- package/src/index.ts +15 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Engine.js","sourceRoot":"","sources":["../src/Engine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,MAAM,MAAM,aAAa,CAAC;AA4BjC;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,GAAe;IAA9C;;QACE;;;WAGG;QACH,YAAO,GAAkC,GAAG,EAAE,CAAC,EAAE,CAAC;IACpD,CAAC;CAAA;AAED;;GAEG;AACH,MAAqB,MAAM;IA4BzB;;OAEG;IACI,MAAM,KAAK,YAAY;QAC5B,OAAO,IAAI,CAAC,aAAa,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,MAAM,KAAK,YAAY,CAAC,KAAY;QACzC,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,KAAK,CAAC,MAAM,EAAE,CAAC;IACjB,CAAC;IAiBD,+CAA+C;IAC/C,IAAI,MAAM;QACR,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;IAED,+CAA+C;IAC/C,IAAI,MAAM;QACR,OAAO,KAAK,CAAC,MAAM,CAAC;IACtB,CAAC;IASD,YAAY,SAA0B,EAAE,OAA4B,EAAE;;QAhCtE,iCAAgB;QAChB,8BAAgC;QAChC,i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KAAK,AAAR,CAAS;AAE7B;;GAEG;AACW,YAAK,GAAG,KAAK,AAAR,CAAS;AAE5B;;GAEG;AACW,qBAAc,GAAsB,IAAI,AAA1B,CAA2B;AAEvD;;GAEG;AACW,aAAM,GAAG,IAAI,MAAM,EAAE,AAAf,CAAgB;eAxBjB,MAAM"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Vector2 from './Vector2.js';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for all entities in the game world.
|
|
4
|
+
* Provides properties for physics, rendering, and lifecycle management.
|
|
5
|
+
*/
|
|
6
|
+
export default abstract class GameObject {
|
|
7
|
+
/** A unique identifier for the object type. */
|
|
8
|
+
tag: string;
|
|
9
|
+
/** Rendering order (lower is background, higher is foreground). */
|
|
10
|
+
zIndex: number;
|
|
11
|
+
/** Current velocity in pixels per second. */
|
|
12
|
+
velocity: Vector2;
|
|
13
|
+
/** Current acceleration in pixels per second squared. */
|
|
14
|
+
acceleration: Vector2;
|
|
15
|
+
/** Mass of the object (used for physics resolution). */
|
|
16
|
+
mass: number;
|
|
17
|
+
/** Whether the object is immovable (e.g., walls). */
|
|
18
|
+
isStatic: boolean;
|
|
19
|
+
/** Whether the object should be rendered. */
|
|
20
|
+
visible: boolean;
|
|
21
|
+
constructor(tag: string, zIndex: number);
|
|
22
|
+
/** The world-space position of the object. */
|
|
23
|
+
abstract get position(): Vector2;
|
|
24
|
+
/** The width of the object in pixels. */
|
|
25
|
+
abstract get width(): number;
|
|
26
|
+
/** The height of the object in pixels. */
|
|
27
|
+
abstract get height(): number;
|
|
28
|
+
/**
|
|
29
|
+
* Main rendering method for the object.
|
|
30
|
+
* @param ctx The canvas 2D rendering context.
|
|
31
|
+
*/
|
|
32
|
+
abstract draw(ctx: CanvasRenderingContext2D): void;
|
|
33
|
+
/**
|
|
34
|
+
* Registers the object with the active scene or global engine loop.
|
|
35
|
+
*/
|
|
36
|
+
registerSelf(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Removes the object from the active scene.
|
|
39
|
+
*/
|
|
40
|
+
destroySelf(): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Engine from './Engine.js';
|
|
2
|
+
import Vector2 from './Vector2.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base class for all entities in the game world.
|
|
5
|
+
* Provides properties for physics, rendering, and lifecycle management.
|
|
6
|
+
*/
|
|
7
|
+
export default class GameObject {
|
|
8
|
+
constructor(tag, zIndex) {
|
|
9
|
+
/** Current velocity in pixels per second. */
|
|
10
|
+
this.velocity = new Vector2(0, 0);
|
|
11
|
+
/** Current acceleration in pixels per second squared. */
|
|
12
|
+
this.acceleration = new Vector2(0, 0);
|
|
13
|
+
/** Mass of the object (used for physics resolution). */
|
|
14
|
+
this.mass = 1;
|
|
15
|
+
/** Whether the object is immovable (e.g., walls). */
|
|
16
|
+
this.isStatic = false;
|
|
17
|
+
/** Whether the object should be rendered. */
|
|
18
|
+
this.visible = true;
|
|
19
|
+
this.tag = tag;
|
|
20
|
+
this.zIndex = zIndex;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Registers the object with the active scene or global engine loop.
|
|
24
|
+
*/
|
|
25
|
+
registerSelf() {
|
|
26
|
+
Engine.registerObject(this);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Removes the object from the active scene.
|
|
30
|
+
*/
|
|
31
|
+
destroySelf() {
|
|
32
|
+
Engine.destroyObject(this);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=GameObject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GameObject.js","sourceRoot":"","sources":["../src/GameObject.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAgB,UAAU;IAiBtC,YAAY,GAAW,EAAE,MAAc;QAZvC,6CAA6C;QAC7C,aAAQ,GAAY,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACtC,yDAAyD;QACzD,iBAAY,GAAY,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1C,wDAAwD;QACxD,SAAI,GAAW,CAAC,CAAC;QACjB,qDAAqD;QACrD,aAAQ,GAAY,KAAK,CAAC;QAE1B,6CAA6C;QAC7C,YAAO,GAAY,IAAI,CAAC;QAGtB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAeD;;OAEG;IACH,YAAY;QACV,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,WAAW;QACT,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF"}
|
package/dist/Input.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Vector2 from './Vector2.js';
|
|
2
|
+
/**
|
|
3
|
+
* Handles mouse and keyboard input events.
|
|
4
|
+
*/
|
|
5
|
+
export default class Input {
|
|
6
|
+
private static mousePosition;
|
|
7
|
+
private static clickListeners;
|
|
8
|
+
private static keys;
|
|
9
|
+
private static isInitialized;
|
|
10
|
+
/**
|
|
11
|
+
* Initializes input event listeners.
|
|
12
|
+
*/
|
|
13
|
+
static init(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a specific key is currently held down.
|
|
16
|
+
* @param key The key to check (e.g., 'w', 'ArrowUp', ' ').
|
|
17
|
+
*/
|
|
18
|
+
static isKeyDown(key: string): boolean;
|
|
19
|
+
/** Current mouse x position in world space. */
|
|
20
|
+
static get mouseX(): number;
|
|
21
|
+
/** Current mouse y position in world space. */
|
|
22
|
+
static get mouseY(): number;
|
|
23
|
+
/** Adds a global click listener. */
|
|
24
|
+
static addClickListener(listener: (pos: Vector2) => void): void;
|
|
25
|
+
/** Removes a global click listener. */
|
|
26
|
+
static removeClickListener(listener: (pos: Vector2) => void): void;
|
|
27
|
+
}
|
package/dist/Input.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import Vector2 from './Vector2.js';
|
|
2
|
+
import Engine from './Engine.js';
|
|
3
|
+
/**
|
|
4
|
+
* Handles mouse and keyboard input events.
|
|
5
|
+
*/
|
|
6
|
+
class Input {
|
|
7
|
+
/**
|
|
8
|
+
* Initializes input event listeners.
|
|
9
|
+
*/
|
|
10
|
+
static init() {
|
|
11
|
+
if (this.isInitialized)
|
|
12
|
+
return;
|
|
13
|
+
this.isInitialized = true;
|
|
14
|
+
document.addEventListener('mousemove', (event) => {
|
|
15
|
+
this.mousePosition.x = event.clientX;
|
|
16
|
+
this.mousePosition.y = event.clientY;
|
|
17
|
+
});
|
|
18
|
+
document.addEventListener('click', (event) => {
|
|
19
|
+
if (event.target.tagName !== 'CANVAS')
|
|
20
|
+
return;
|
|
21
|
+
const pos = new Vector2(this.mouseX, this.mouseY);
|
|
22
|
+
// If debug mode is on, try to select an object
|
|
23
|
+
if (Engine.debug) {
|
|
24
|
+
const objects = Engine.currentScene ? Engine.currentScene.objects : Engine.objects;
|
|
25
|
+
let found = false;
|
|
26
|
+
// Check objects from top to bottom (zIndex)
|
|
27
|
+
const sorted = Array.from(objects).sort((a, b) => (b.zIndex > a.zIndex ? 1 : -1));
|
|
28
|
+
for (const obj of sorted) {
|
|
29
|
+
if (pos.x > obj.position.x &&
|
|
30
|
+
pos.x < obj.position.x + obj.width &&
|
|
31
|
+
pos.y > obj.position.y &&
|
|
32
|
+
pos.y < obj.position.y + obj.height) {
|
|
33
|
+
Engine.selectedObject = obj;
|
|
34
|
+
found = true;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (!found)
|
|
39
|
+
Engine.selectedObject = null;
|
|
40
|
+
}
|
|
41
|
+
if (!Engine.paused) {
|
|
42
|
+
this.clickListeners.forEach((listener) => listener(pos));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
document.addEventListener('mousedown', (event) => {
|
|
46
|
+
if (event.target.tagName !== 'CANVAS')
|
|
47
|
+
return;
|
|
48
|
+
this.keys.add(`mouse${event.button}`);
|
|
49
|
+
});
|
|
50
|
+
document.addEventListener('mouseup', (event) => {
|
|
51
|
+
this.keys.delete(`mouse${event.button}`);
|
|
52
|
+
});
|
|
53
|
+
document.addEventListener('keydown', (event) => {
|
|
54
|
+
this.keys.add(event.key.toLowerCase());
|
|
55
|
+
// Toggle Pause with P
|
|
56
|
+
if (event.key === 'p' || event.key === 'P') {
|
|
57
|
+
Engine.paused = !Engine.paused;
|
|
58
|
+
if (Engine.paused) {
|
|
59
|
+
document.getElementById('canvas').style.cursor = 'default';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
document.addEventListener('keyup', (event) => {
|
|
64
|
+
this.keys.delete(event.key.toLowerCase());
|
|
65
|
+
});
|
|
66
|
+
window.addEventListener('blur', () => {
|
|
67
|
+
this.keys.clear();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Checks if a specific key is currently held down.
|
|
72
|
+
* @param key The key to check (e.g., 'w', 'ArrowUp', ' ').
|
|
73
|
+
*/
|
|
74
|
+
static isKeyDown(key) {
|
|
75
|
+
return this.keys.has(key.toLowerCase());
|
|
76
|
+
}
|
|
77
|
+
/** Current mouse x position in world space. */
|
|
78
|
+
static get mouseX() {
|
|
79
|
+
return (this.mousePosition.x / Engine.camera.zoom) + Engine.camera.position.x;
|
|
80
|
+
}
|
|
81
|
+
/** Current mouse y position in world space. */
|
|
82
|
+
static get mouseY() {
|
|
83
|
+
return (this.mousePosition.y / Engine.camera.zoom) + Engine.camera.position.y;
|
|
84
|
+
}
|
|
85
|
+
/** Adds a global click listener. */
|
|
86
|
+
static addClickListener(listener) {
|
|
87
|
+
this.clickListeners.add(listener);
|
|
88
|
+
}
|
|
89
|
+
/** Removes a global click listener. */
|
|
90
|
+
static removeClickListener(listener) {
|
|
91
|
+
this.clickListeners.delete(listener);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
Input.mousePosition = new Vector2(0, 0);
|
|
95
|
+
Input.clickListeners = new Set();
|
|
96
|
+
Input.keys = new Set();
|
|
97
|
+
Input.isInitialized = false;
|
|
98
|
+
export default Input;
|
|
99
|
+
//# sourceMappingURL=Input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Input.js","sourceRoot":"","sources":["../src/Input.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC;;GAEG;AACH,MAAqB,KAAK;IAMxB;;OAEG;IACH,MAAM,CAAC,IAAI;QACT,IAAI,IAAI,CAAC,aAAa;YAAE,OAAO;QAC/B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAE1B,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC,KAAiB,EAAE,EAAE;YAC3D,IAAI,CAAC,aAAa,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;YACrC,IAAI,CAAC,aAAa,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;QACvC,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,KAAiB,EAAE,EAAE;YACvD,IAAK,KAAK,CAAC,MAAsB,CAAC,OAAO,KAAK,QAAQ;gBAAE,OAAO;YAE/D,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAElD,+CAA+C;YAC/C,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjB,MAAM,OAAO,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC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W,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,+CAA+C;IAC/C,MAAM,KAAK,MAAM;QACf,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChF,CAAC;IAED,+CAA+C;IAC/C,MAAM,KAAK,MAAM;QACf,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;IAChF,CAAC;IAED,oCAAoC;IACpC,MAAM,CAAC,gBAAgB,CAAC,QAAgC;QACtD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,uCAAuC;IACvC,MAAM,CAAC,mBAAmB,CAAC,QAAgC;QACzD,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;;AA5Gc,mBAAa,GAAY,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,oBAAc,GAAgC,IAAI,GAAG,EAAE,CAAC;AACxD,UAAI,GAAgB,IAAI,GAAG,EAAE,CAAC;AAC9B,mBAAa,GAAG,KAAK,CAAC;eAJlB,KAAK"}
|
package/dist/Line.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import GameObject from './GameObject.js';
|
|
2
|
+
import Vector2 from './Vector2.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for creating a Line object.
|
|
5
|
+
*/
|
|
6
|
+
export interface LineProperties {
|
|
7
|
+
/** Unique tag for identification. */
|
|
8
|
+
tag: string;
|
|
9
|
+
/** Stroke width of the line. */
|
|
10
|
+
width: number;
|
|
11
|
+
/** Start point of the line. */
|
|
12
|
+
p1: Vector2;
|
|
13
|
+
/** End point of the line. */
|
|
14
|
+
p2: Vector2;
|
|
15
|
+
/** Render order (lower is background). */
|
|
16
|
+
zIndex: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A basic line object that can be drawn between two points.
|
|
20
|
+
*/
|
|
21
|
+
export default class Line extends GameObject {
|
|
22
|
+
/** Stroke width of the line. */
|
|
23
|
+
strokeWidth: number;
|
|
24
|
+
/** Start x coordinate. */
|
|
25
|
+
x1: number;
|
|
26
|
+
/** Start y coordinate. */
|
|
27
|
+
y1: number;
|
|
28
|
+
/** End x coordinate. */
|
|
29
|
+
x2: number;
|
|
30
|
+
/** End y coordinate. */
|
|
31
|
+
y2: number;
|
|
32
|
+
/** Gets the starting position of the line. */
|
|
33
|
+
get position(): Vector2;
|
|
34
|
+
/** Gets the bounding box width of the line. */
|
|
35
|
+
get width(): number;
|
|
36
|
+
/** Gets the bounding box height of the line. */
|
|
37
|
+
get height(): number;
|
|
38
|
+
constructor(props: LineProperties);
|
|
39
|
+
/** Draws the line onto the provided rendering context. */
|
|
40
|
+
draw(ctx: CanvasRenderingContext2D): void;
|
|
41
|
+
}
|
package/dist/Line.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import GameObject from './GameObject.js';
|
|
2
|
+
import Vector2 from './Vector2.js';
|
|
3
|
+
const defaultProps = {
|
|
4
|
+
tag: 'line',
|
|
5
|
+
width: 1,
|
|
6
|
+
zIndex: 0,
|
|
7
|
+
p1: new Vector2(),
|
|
8
|
+
p2: new Vector2(),
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A basic line object that can be drawn between two points.
|
|
12
|
+
*/
|
|
13
|
+
export default class Line extends GameObject {
|
|
14
|
+
/** Gets the starting position of the line. */
|
|
15
|
+
get position() { return new Vector2(this.x1, this.y1); }
|
|
16
|
+
/** Gets the bounding box width of the line. */
|
|
17
|
+
get width() { return Math.abs(this.x2 - this.x1); }
|
|
18
|
+
/** Gets the bounding box height of the line. */
|
|
19
|
+
get height() { return Math.abs(this.y2 - this.y1); }
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(props.tag || defaultProps.tag, props.zIndex || defaultProps.zIndex);
|
|
22
|
+
const defaultedProps = Object.assign(Object.assign({}, defaultProps), props);
|
|
23
|
+
this.strokeWidth = defaultedProps.width;
|
|
24
|
+
this.x1 = defaultedProps.p1.x;
|
|
25
|
+
this.y1 = defaultedProps.p1.y;
|
|
26
|
+
this.x2 = defaultedProps.p2.x;
|
|
27
|
+
this.y2 = defaultedProps.p2.y;
|
|
28
|
+
this.registerSelf();
|
|
29
|
+
}
|
|
30
|
+
/** Draws the line onto the provided rendering context. */
|
|
31
|
+
draw(ctx) {
|
|
32
|
+
if (!this.visible)
|
|
33
|
+
return;
|
|
34
|
+
ctx.lineWidth = this.strokeWidth;
|
|
35
|
+
ctx.moveTo(this.x1, this.y1);
|
|
36
|
+
ctx.lineTo(this.x2, this.y2);
|
|
37
|
+
ctx.stroke();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=Line.js.map
|
package/dist/Line.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Line.js","sourceRoot":"","sources":["../src/Line.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,OAAO,MAAM,cAAc,CAAC;AAkBnC,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,MAAM;IACX,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,EAAE,EAAE,IAAI,OAAO,EAAE;IACjB,EAAE,EAAE,IAAI,OAAO,EAAE;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,UAAU;IAY1C,8CAA8C;IAC9C,IAAI,QAAQ,KAAK,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACxD,+CAA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 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles asynchronous loading of assets like images.
|
|
3
|
+
*/
|
|
4
|
+
export default class ResourceLoader {
|
|
5
|
+
private static assets;
|
|
6
|
+
private static loadingQueue;
|
|
7
|
+
private static totalToLoad;
|
|
8
|
+
private static loadedCount;
|
|
9
|
+
/**
|
|
10
|
+
* Queue an image for loading.
|
|
11
|
+
* @param tag Unique tag to reference the image later.
|
|
12
|
+
* @param src Path to the image file.
|
|
13
|
+
*/
|
|
14
|
+
static queueImage(tag: string, src: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Start loading all queued assets.
|
|
17
|
+
* @param onProgress Optional callback for loading progress updates.
|
|
18
|
+
*/
|
|
19
|
+
static loadAll(onProgress?: (percent: number) => void): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Get a loaded asset by its tag.
|
|
22
|
+
* @param tag The tag used when queuing the asset.
|
|
23
|
+
* @returns The loaded HTMLImageElement.
|
|
24
|
+
*/
|
|
25
|
+
static getImage(tag: string): HTMLImageElement;
|
|
26
|
+
}
|
package/dist/Loader.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Handles asynchronous loading of assets like images.
|
|
12
|
+
*/
|
|
13
|
+
class ResourceLoader {
|
|
14
|
+
/**
|
|
15
|
+
* Queue an image for loading.
|
|
16
|
+
* @param tag Unique tag to reference the image later.
|
|
17
|
+
* @param src Path to the image file.
|
|
18
|
+
*/
|
|
19
|
+
static queueImage(tag, src) {
|
|
20
|
+
if (this.assets.has(tag))
|
|
21
|
+
return;
|
|
22
|
+
this.loadingQueue.add(JSON.stringify({ tag, src }));
|
|
23
|
+
this.totalToLoad++;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Start loading all queued assets.
|
|
27
|
+
* @param onProgress Optional callback for loading progress updates.
|
|
28
|
+
*/
|
|
29
|
+
static loadAll(onProgress) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
if (this.loadingQueue.size === 0)
|
|
32
|
+
return Promise.resolve();
|
|
33
|
+
const promises = Array.from(this.loadingQueue).map(item => {
|
|
34
|
+
const { tag, src } = JSON.parse(item);
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const img = new Image();
|
|
37
|
+
img.src = src;
|
|
38
|
+
img.onload = () => {
|
|
39
|
+
this.assets.set(tag, img);
|
|
40
|
+
this.loadedCount++;
|
|
41
|
+
if (onProgress) {
|
|
42
|
+
onProgress((this.loadedCount / this.totalToLoad) * 100);
|
|
43
|
+
}
|
|
44
|
+
resolve();
|
|
45
|
+
};
|
|
46
|
+
img.onerror = () => {
|
|
47
|
+
console.error(`Failed to load asset: ${src}`);
|
|
48
|
+
reject();
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
yield Promise.all(promises);
|
|
53
|
+
this.loadingQueue.clear();
|
|
54
|
+
this.totalToLoad = 0;
|
|
55
|
+
this.loadedCount = 0;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get a loaded asset by its tag.
|
|
60
|
+
* @param tag The tag used when queuing the asset.
|
|
61
|
+
* @returns The loaded HTMLImageElement.
|
|
62
|
+
*/
|
|
63
|
+
static getImage(tag) {
|
|
64
|
+
const asset = this.assets.get(tag);
|
|
65
|
+
if (!asset) {
|
|
66
|
+
throw new Error(`Asset not found: ${tag}. Make sure it is queued and loaded.`);
|
|
67
|
+
}
|
|
68
|
+
return asset;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
ResourceLoader.assets = new Map();
|
|
72
|
+
ResourceLoader.loadingQueue = new Set();
|
|
73
|
+
ResourceLoader.totalToLoad = 0;
|
|
74
|
+
ResourceLoader.loadedCount = 0;
|
|
75
|
+
export default ResourceLoader;
|
|
76
|
+
//# sourceMappingURL=Loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Loader.js","sourceRoot":"","sources":["../src/Loader.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;GAEG;AACH,MAAqB,cAAc;IAMjC;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,GAAW,EAAE,GAAW;QACxC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO;QACjC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;QACpD,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAO,OAAO,CAAC,UAAsC;;YACzD,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,KAAK,CAAC;gBAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;YAE3D,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;gBACxD,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACtC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;oBAC3C,MAAM,GAAG,GAAG,IAAI,K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AC;eAJpB,cAAc"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import GameObject from './GameObject.js';
|
|
2
|
+
/**
|
|
3
|
+
* Utility class for collision detection between game objects.
|
|
4
|
+
*/
|
|
5
|
+
export default class Physics {
|
|
6
|
+
/**
|
|
7
|
+
* Checks if two game objects are colliding.
|
|
8
|
+
/**
|
|
9
|
+
* Checks if two game objects are colliding and resolves it if not static.
|
|
10
|
+
* @param obj1 First object.
|
|
11
|
+
* @param obj2 Second object.
|
|
12
|
+
* @returns True if the objects are colliding.
|
|
13
|
+
*/
|
|
14
|
+
static checkCollision(obj1: GameObject, obj2: GameObject): boolean;
|
|
15
|
+
private static resolveCollision;
|
|
16
|
+
}
|
package/dist/Physics.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import Vector2 from './Vector2.js';
|
|
2
|
+
import Circle from './Circle.js';
|
|
3
|
+
/**
|
|
4
|
+
* Utility class for collision detection between game objects.
|
|
5
|
+
*/
|
|
6
|
+
export default class Physics {
|
|
7
|
+
/**
|
|
8
|
+
* Checks if two game objects are colliding.
|
|
9
|
+
/**
|
|
10
|
+
* Checks if two game objects are colliding and resolves it if not static.
|
|
11
|
+
* @param obj1 First object.
|
|
12
|
+
* @param obj2 Second object.
|
|
13
|
+
* @returns True if the objects are colliding.
|
|
14
|
+
*/
|
|
15
|
+
static checkCollision(obj1, obj2) {
|
|
16
|
+
const isCircle1 = obj1 instanceof Circle;
|
|
17
|
+
const isCircle2 = obj2 instanceof Circle;
|
|
18
|
+
let isColliding = false;
|
|
19
|
+
if (isCircle1 && isCircle2) {
|
|
20
|
+
const c1 = obj1;
|
|
21
|
+
const c2 = obj2;
|
|
22
|
+
isColliding = Vector2.distance(c1.center, c2.center) < c1.radius + c2.radius;
|
|
23
|
+
}
|
|
24
|
+
else if (isCircle1 || isCircle2) {
|
|
25
|
+
const circle = (isCircle1 ? obj1 : obj2);
|
|
26
|
+
const rect = (isCircle1 ? obj2 : obj1);
|
|
27
|
+
const closestX = Math.max(rect.position.x, Math.min(circle.center.x, rect.position.x + rect.width));
|
|
28
|
+
const closestY = Math.max(rect.position.y, Math.min(circle.center.y, rect.position.y + rect.height));
|
|
29
|
+
isColliding = Vector2.distance(circle.center, new Vector2(closestX, closestY)) < circle.radius;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
isColliding = (obj1.position.x < obj2.position.x + obj2.width &&
|
|
33
|
+
obj1.position.x + obj1.width > obj2.position.x &&
|
|
34
|
+
obj1.position.y < obj2.position.y + obj2.height &&
|
|
35
|
+
obj1.position.y + obj1.height > obj2.position.y);
|
|
36
|
+
}
|
|
37
|
+
if (isColliding && (!obj1.isStatic || !obj2.isStatic)) {
|
|
38
|
+
this.resolveCollision(obj1, obj2);
|
|
39
|
+
}
|
|
40
|
+
return isColliding;
|
|
41
|
+
}
|
|
42
|
+
static resolveCollision(obj1, obj2) {
|
|
43
|
+
// Calculate overlap
|
|
44
|
+
const overlapX = Math.min(obj1.position.x + obj1.width - obj2.position.x, obj2.position.x + obj2.width - obj1.position.x);
|
|
45
|
+
const overlapY = Math.min(obj1.position.y + obj1.height - obj2.position.y, obj2.position.y + obj2.height - obj1.position.y);
|
|
46
|
+
// Push apart
|
|
47
|
+
if (overlapX < overlapY) {
|
|
48
|
+
if (obj1.position.x < obj2.position.x) {
|
|
49
|
+
if (!obj1.isStatic)
|
|
50
|
+
obj1.position.x -= overlapX / 2;
|
|
51
|
+
if (!obj2.isStatic)
|
|
52
|
+
obj2.position.x += overlapX / 2;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
if (!obj1.isStatic)
|
|
56
|
+
obj1.position.x += overlapX / 2;
|
|
57
|
+
if (!obj2.isStatic)
|
|
58
|
+
obj2.position.x -= overlapX / 2;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
if (obj1.position.y < obj2.position.y) {
|
|
63
|
+
if (!obj1.isStatic)
|
|
64
|
+
obj1.position.y -= overlapY / 2;
|
|
65
|
+
if (!obj2.isStatic)
|
|
66
|
+
obj2.position.y += overlapY / 2;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
if (!obj1.isStatic)
|
|
70
|
+
obj1.position.y += overlapY / 2;
|
|
71
|
+
if (!obj2.isStatic)
|
|
72
|
+
obj2.position.y -= overlapY / 2;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=Physics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Physics.js","sourceRoot":"","sources":["../src/Physics.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B;;;;;;;QAOI;IACH,MAAM,CAAC,cAAc,CAAC,IAAgB,EAAE,IAAgB;QACtD,MAAM,SAAS,GAAG,IAAI,YAAY,MAAM,CAAC;QACzC,MAAM,SAAS,GAAG,IAAI,YAAY,MAAM,CAAC;QACzC,IAAI,WAAW,GAAG,KAAK,CAAC;QAExB,IAAI,SAAS,IAAI,SAAS,EAAE,CAAC;YAC3B,MAAM,EAAE,GAAG,IAAc,CAAC;YAC1B,MAAM,EAAE,GAAG,IAAc,CAAC;YAC1B,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC;QAC/E,CAAC;aAAM,IAAI,SAAS,IAAI,SAAS,EAAE,CAAC;YAClC,MAAM,MAAM,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAW,CAAC;YACnD,MAAM,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,I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YACtD,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;gBACtC,IAAI,CAAC,IAAI,CAAC,QAAQ;oBAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC;gBACpD,IAAI,CAAC,IAAI,CAAC,QAAQ;oBAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC;YACtD,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,IAAI,CAAC,QAAQ;oBAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC;gBACpD,IAAI,CAAC,IAAI,CAAC,QAAQ;oBAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Vector2 from './Vector2.js';
|
|
2
|
+
import GameObject from './GameObject.js';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for creating a Rectangle object.
|
|
5
|
+
*/
|
|
6
|
+
export interface RectProps {
|
|
7
|
+
/** Unique tag for identification. */
|
|
8
|
+
tag: string;
|
|
9
|
+
/** Initial position of the top-left corner. */
|
|
10
|
+
position: Vector2;
|
|
11
|
+
/** Width of the rectangle. */
|
|
12
|
+
width: number;
|
|
13
|
+
/** Height of the rectangle. */
|
|
14
|
+
height: number;
|
|
15
|
+
/** Fill colour. */
|
|
16
|
+
colour: string;
|
|
17
|
+
/** Render order. */
|
|
18
|
+
zIndex: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* A basic rectangle shape that can be drawn to the screen.
|
|
22
|
+
*/
|
|
23
|
+
export default class Rectangle extends GameObject {
|
|
24
|
+
private _position;
|
|
25
|
+
private _width;
|
|
26
|
+
private _height;
|
|
27
|
+
/** Fill colour. */
|
|
28
|
+
colour: string;
|
|
29
|
+
/** Gets or sets the top-left position. */
|
|
30
|
+
get position(): Vector2;
|
|
31
|
+
set position(val: Vector2);
|
|
32
|
+
/** Gets or sets the width. */
|
|
33
|
+
get width(): number;
|
|
34
|
+
set width(val: number);
|
|
35
|
+
/** Gets or sets the height. */
|
|
36
|
+
get height(): number;
|
|
37
|
+
set height(val: number);
|
|
38
|
+
constructor(props: RectProps);
|
|
39
|
+
/** Draws the rectangle onto the provided rendering context. */
|
|
40
|
+
draw(ctx: CanvasRenderingContext2D): void;
|
|
41
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Vector2 from './Vector2.js';
|
|
2
|
+
import GameObject from './GameObject.js';
|
|
3
|
+
const defaultProps = {
|
|
4
|
+
tag: 'rect', colour: 'black', zIndex: 0,
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A basic rectangle shape that can be drawn to the screen.
|
|
8
|
+
*/
|
|
9
|
+
export default class Rectangle extends GameObject {
|
|
10
|
+
/** Gets or sets the top-left position. */
|
|
11
|
+
get position() { return this._position; }
|
|
12
|
+
set position(val) { this._position = val; }
|
|
13
|
+
/** Gets or sets the width. */
|
|
14
|
+
get width() { return this._width; }
|
|
15
|
+
set width(val) { this._width = val; }
|
|
16
|
+
/** Gets or sets the height. */
|
|
17
|
+
get height() { return this._height; }
|
|
18
|
+
set height(val) { this._height = val; }
|
|
19
|
+
constructor(props) {
|
|
20
|
+
super(props.tag || defaultProps.tag, props.zIndex || defaultProps.zIndex);
|
|
21
|
+
const defaultedProps = Object.assign(Object.assign({}, defaultProps), props);
|
|
22
|
+
if (!(defaultedProps.position instanceof Vector2)) {
|
|
23
|
+
throw new Error('"position" must be a Vector2!');
|
|
24
|
+
}
|
|
25
|
+
if (!defaultedProps.width || !defaultedProps.height) {
|
|
26
|
+
throw new Error('You must provide a width and height for Rectangle');
|
|
27
|
+
}
|
|
28
|
+
this.tag = defaultedProps.tag;
|
|
29
|
+
this._position = defaultedProps.position;
|
|
30
|
+
this._width = defaultedProps.width;
|
|
31
|
+
this._height = defaultedProps.height;
|
|
32
|
+
this.colour = defaultedProps.colour;
|
|
33
|
+
this.zIndex = defaultedProps.zIndex;
|
|
34
|
+
this.registerSelf();
|
|
35
|
+
}
|
|
36
|
+
/** Draws the rectangle onto the provided rendering context. */
|
|
37
|
+
draw(ctx) {
|
|
38
|
+
if (!this.visible)
|
|
39
|
+
return;
|
|
40
|
+
ctx.fillStyle = this.colour;
|
|
41
|
+
ctx.fillRect(this.position.x, this.position.y, this.width, this.height);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=Rectangle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rectangle.js","sourceRoot":"","sources":["../src/Rectangle.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAoBzC,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;CACxC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,UAAU;IAO/C,0CAA0C;IAC1C,IAAI,QAAQ,KAAK,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IACzC,IAAI,QAAQ,CAAC,GAAG,IAAI,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC;IAC3C,8BAA8B;IAC9B,IAAI,KAAK,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACnC,IAAI,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC;IACrC,+BAA+B;IAC/B,IAAI,MAAM,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACrC,I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