dino-ge 1.10.3 → 1.10.7
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/README.md +7 -3
- package/dist/Camera.d.ts +8 -4
- package/dist/Camera.js +8 -4
- package/dist/Camera.js.map +1 -1
- package/dist/Canvas.d.ts +6 -1
- package/dist/Canvas.js +13 -5
- package/dist/Canvas.js.map +1 -1
- package/dist/Circle.d.ts +12 -4
- package/dist/Circle.js +10 -2
- package/dist/Circle.js.map +1 -1
- package/dist/Engine.d.ts +42 -49
- package/dist/Engine.js +91 -68
- package/dist/Engine.js.map +1 -1
- package/dist/EngineState.d.ts +33 -0
- package/dist/EngineState.js +8 -0
- package/dist/EngineState.js.map +1 -0
- package/dist/GameObject.d.ts +50 -31
- package/dist/GameObject.js +70 -28
- package/dist/GameObject.js.map +1 -1
- package/dist/Group.d.ts +5 -0
- package/dist/Group.js +5 -0
- package/dist/Group.js.map +1 -1
- package/dist/Input.d.ts +14 -4
- package/dist/Input.js +14 -4
- package/dist/Input.js.map +1 -1
- package/dist/Line.d.ts +10 -6
- package/dist/Line.js +5 -1
- package/dist/Line.js.map +1 -1
- package/dist/ObjectSet.d.ts +11 -0
- package/dist/ObjectSet.js +15 -0
- package/dist/ObjectSet.js.map +1 -0
- package/dist/Physics.js +3 -0
- package/dist/Physics.js.map +1 -1
- package/dist/PhysicsSystem.d.ts +2 -2
- package/dist/PhysicsSystem.js +25 -8
- package/dist/PhysicsSystem.js.map +1 -1
- package/dist/Rectangle.d.ts +5 -1
- package/dist/Rectangle.js +4 -0
- package/dist/Rectangle.js.map +1 -1
- package/dist/Registry.d.ts +15 -0
- package/dist/Registry.js +41 -0
- package/dist/Registry.js.map +1 -0
- package/dist/RenderingSystem.js +9 -8
- package/dist/RenderingSystem.js.map +1 -1
- package/dist/Scene.d.ts +25 -5
- package/dist/Scene.js +18 -5
- package/dist/Scene.js.map +1 -1
- package/dist/Sprite.d.ts +18 -14
- package/dist/Sprite.js +36 -15
- package/dist/Sprite.js.map +1 -1
- package/dist/TagComponent.js +5 -2
- package/dist/TagComponent.js.map +1 -1
- package/dist/Text.d.ts +13 -6
- package/dist/Text.js +12 -5
- package/dist/Text.js.map +1 -1
- package/dist/Tilemap.d.ts +4 -0
- package/dist/Tilemap.js +4 -0
- package/dist/Tilemap.js.map +1 -1
- package/dist/Vector2.d.ts +20 -3
- package/dist/Vector2.js +20 -3
- package/dist/Vector2.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,14 +28,18 @@ class MyGame {
|
|
|
28
28
|
constructor() {
|
|
29
29
|
new Engine({
|
|
30
30
|
onLoad: () => this.onLoad(),
|
|
31
|
-
update: (
|
|
31
|
+
update: () => this.onUpdate()
|
|
32
|
+
}, {
|
|
33
|
+
title: 'My Game',
|
|
34
|
+
width: '100%',
|
|
35
|
+
height: '100%'
|
|
32
36
|
});
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
onLoad() {
|
|
36
40
|
const player = new Sprite({
|
|
37
41
|
tag: 'player',
|
|
38
|
-
img: 'player',
|
|
42
|
+
img: 'player', // Asset tag from ResourceLoader
|
|
39
43
|
rows: 1,
|
|
40
44
|
cols: 4,
|
|
41
45
|
position: new Vector2(400, 300),
|
|
@@ -45,7 +49,7 @@ class MyGame {
|
|
|
45
49
|
player.play();
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
onUpdate(
|
|
52
|
+
onUpdate() {
|
|
49
53
|
// Game logic here
|
|
50
54
|
}
|
|
51
55
|
}
|
package/dist/Camera.d.ts
CHANGED
|
@@ -8,9 +8,12 @@ export default class Camera {
|
|
|
8
8
|
position: Vector2;
|
|
9
9
|
/** Zoom level of the camera. */
|
|
10
10
|
zoom: number;
|
|
11
|
+
/**
|
|
12
|
+
* Initializes a new instance of Camera.
|
|
13
|
+
*/
|
|
11
14
|
constructor();
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
16
|
+
* Centers the camera on a target object.
|
|
14
17
|
* @param target The object to follow.
|
|
15
18
|
* @param viewportWidth Width of the viewport.
|
|
16
19
|
* @param viewportHeight Height of the viewport.
|
|
@@ -18,8 +21,9 @@ export default class Camera {
|
|
|
18
21
|
follow(target: GameObject, viewportWidth: number, viewportHeight: number): void;
|
|
19
22
|
/**
|
|
20
23
|
* Returns the current viewport bounds in world space.
|
|
21
|
-
* @param width Width of the viewport.
|
|
22
|
-
* @param height Height of the viewport.
|
|
24
|
+
* @param width Width of the viewport in pixels.
|
|
25
|
+
* @param height Height of the viewport in pixels.
|
|
26
|
+
* @returns An object representing the x, y, width, and height of the visible area.
|
|
23
27
|
*/
|
|
24
28
|
getViewportBounds(width: number, height: number): {
|
|
25
29
|
x: number;
|
|
@@ -28,7 +32,7 @@ export default class Camera {
|
|
|
28
32
|
height: number;
|
|
29
33
|
};
|
|
30
34
|
/**
|
|
31
|
-
*
|
|
35
|
+
* Resets the camera position to the origin (0, 0) and zoom to 1.
|
|
32
36
|
*/
|
|
33
37
|
reset(): void;
|
|
34
38
|
}
|
package/dist/Camera.js
CHANGED
|
@@ -3,6 +3,9 @@ import Vector2 from './Vector2.js';
|
|
|
3
3
|
* Manages the viewport and transformation of the game world.
|
|
4
4
|
*/
|
|
5
5
|
export default class Camera {
|
|
6
|
+
/**
|
|
7
|
+
* Initializes a new instance of Camera.
|
|
8
|
+
*/
|
|
6
9
|
constructor() {
|
|
7
10
|
/** Current camera position in world space. */
|
|
8
11
|
this.position = new Vector2(0, 0);
|
|
@@ -10,7 +13,7 @@ export default class Camera {
|
|
|
10
13
|
this.zoom = 1;
|
|
11
14
|
}
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
16
|
+
* Centers the camera on a target object.
|
|
14
17
|
* @param target The object to follow.
|
|
15
18
|
* @param viewportWidth Width of the viewport.
|
|
16
19
|
* @param viewportHeight Height of the viewport.
|
|
@@ -24,8 +27,9 @@ export default class Camera {
|
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
29
|
* Returns the current viewport bounds in world space.
|
|
27
|
-
* @param width Width of the viewport.
|
|
28
|
-
* @param height Height of the viewport.
|
|
30
|
+
* @param width Width of the viewport in pixels.
|
|
31
|
+
* @param height Height of the viewport in pixels.
|
|
32
|
+
* @returns An object representing the x, y, width, and height of the visible area.
|
|
29
33
|
*/
|
|
30
34
|
getViewportBounds(width, height) {
|
|
31
35
|
return {
|
|
@@ -36,7 +40,7 @@ export default class Camera {
|
|
|
36
40
|
};
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
|
-
*
|
|
43
|
+
* Resets the camera position to the origin (0, 0) and zoom to 1.
|
|
40
44
|
*/
|
|
41
45
|
reset() {
|
|
42
46
|
this.position.x = 0;
|
package/dist/Camera.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Camera.js","sourceRoot":"","sources":["../src/Camera.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AAGnC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IAMzB;
|
|
1
|
+
{"version":3,"file":"Camera.js","sourceRoot":"","sources":["../src/Camera.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AAGnC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IAMzB;;OAEG;IACH;QARA,8CAA8C;QACvC,aAAQ,GAAY,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7C,gCAAgC;QACzB,SAAI,GAAW,CAAC,CAAC;IAKT,CAAC;IAEhB;;;;;OAKG;IACI,MAAM,CAAC,MAAkB,EAAE,aAAqB,EAAE,cAAsB;;QAC7E,MAAM,KAAK,GAAG,MAAA,MAAA,MAAM,CAAC,MAAM,0CAAE,KAAK,mCAAI,CAAC,CAAC;QACxC,MAAM,MAAM,GAAG,MAAA,MAAA,MAAM,CAAC,MAAM,0CAAE,MAAM,mCAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,aAAa,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;QAC9F,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,cAAc,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;IAClG,CAAC;IAED;;;;;OAKG;IACI,iBAAiB,CAAC,KAAa,EAAE,MAAc;QACpD,OAAO;YACL,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAClB,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC,IAAI;YACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI;SAC3B,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,KAAK;QACV,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IAChB,CAAC;CACF"}
|
package/dist/Canvas.d.ts
CHANGED
|
@@ -8,14 +8,19 @@ export default class Canvas {
|
|
|
8
8
|
/** Optional callback fired when the canvas resizes. */
|
|
9
9
|
onResize?: () => void;
|
|
10
10
|
private _resizeObserver?;
|
|
11
|
+
/**
|
|
12
|
+
* Initializes a new instance of Canvas.
|
|
13
|
+
* @param parentElement Optional HTML element to inject the canvas into.
|
|
14
|
+
*/
|
|
11
15
|
constructor(parentElement?: HTMLElement);
|
|
12
16
|
/**
|
|
13
17
|
* Resizes the canvas to match its container or window dimensions.
|
|
14
18
|
* @param parent Optional parent element to match size with.
|
|
15
19
|
*/
|
|
16
20
|
resize(parent?: HTMLElement): void;
|
|
21
|
+
private _onResizeObserved;
|
|
17
22
|
/**
|
|
18
|
-
*
|
|
23
|
+
* Completely removes the canvas element and cleans up its observers.
|
|
19
24
|
*/
|
|
20
25
|
destroy(): void;
|
|
21
26
|
}
|
package/dist/Canvas.js
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* Supports full-screen or container-relative sizing.
|
|
4
4
|
*/
|
|
5
5
|
export default class Canvas {
|
|
6
|
+
/**
|
|
7
|
+
* Initializes a new instance of Canvas.
|
|
8
|
+
* @param parentElement Optional HTML element to inject the canvas into.
|
|
9
|
+
*/
|
|
6
10
|
constructor(parentElement) {
|
|
7
11
|
this.canvas = document.createElement('canvas');
|
|
8
12
|
this.canvas.id = 'canvas';
|
|
@@ -11,7 +15,7 @@ export default class Canvas {
|
|
|
11
15
|
this.canvas.style.width = '100%';
|
|
12
16
|
this.canvas.style.height = '100%';
|
|
13
17
|
// Use ResizeObserver to handle panel resizing in playground
|
|
14
|
-
this._resizeObserver = new ResizeObserver(
|
|
18
|
+
this._resizeObserver = new ResizeObserver(this._onResizeObserved.bind(this, parentElement));
|
|
15
19
|
this._resizeObserver.observe(parentElement);
|
|
16
20
|
this.resize(parentElement);
|
|
17
21
|
}
|
|
@@ -29,9 +33,10 @@ export default class Canvas {
|
|
|
29
33
|
* @param parent Optional parent element to match size with.
|
|
30
34
|
*/
|
|
31
35
|
resize(parent) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.canvas.
|
|
36
|
+
const target = parent || this.canvas.parentElement;
|
|
37
|
+
if (target && target.clientWidth > 0) {
|
|
38
|
+
this.canvas.width = target.clientWidth;
|
|
39
|
+
this.canvas.height = target.clientHeight;
|
|
35
40
|
}
|
|
36
41
|
else {
|
|
37
42
|
this.canvas.width = window.innerWidth;
|
|
@@ -41,8 +46,11 @@ export default class Canvas {
|
|
|
41
46
|
this.onResize();
|
|
42
47
|
}
|
|
43
48
|
}
|
|
49
|
+
_onResizeObserved(parentElement) {
|
|
50
|
+
this.resize(this.canvas.parentElement || parentElement);
|
|
51
|
+
}
|
|
44
52
|
/**
|
|
45
|
-
*
|
|
53
|
+
* Completely removes the canvas element and cleans up its observers.
|
|
46
54
|
*/
|
|
47
55
|
destroy() {
|
|
48
56
|
if (this._resizeObserver) {
|
package/dist/Canvas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canvas.js","sourceRoot":"","sources":["../src/Canvas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IAQzB,YAAY,aAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC;QAE1B,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;YACjC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;YAElC,4DAA4D;YAC5D,IAAI,CAAC,eAAe,GAAG,IAAI,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"Canvas.js","sourceRoot":"","sources":["../src/Canvas.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IAQzB;;;OAGG;IACH,YAAY,aAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC;QAE1B,IAAI,aAAa,EAAE,CAAC;YAClB,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,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C1C,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClB,CAAC;IACH,CAAC;IAEO,iBAAiB,CAAC,aAA0B;QAClD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,IAAI,aAAa,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACI,OAAO;QACZ,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC;QACpC,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF"}
|
package/dist/Circle.d.ts
CHANGED
|
@@ -19,13 +19,21 @@ export interface CircleProps {
|
|
|
19
19
|
* A basic circle shape that can be drawn to the screen.
|
|
20
20
|
*/
|
|
21
21
|
export default class Circle extends GameObject {
|
|
22
|
-
/** Radius of the circle. */
|
|
22
|
+
/** Radius of the circle in local space. */
|
|
23
23
|
radius: number;
|
|
24
|
-
/** Fill colour. */
|
|
24
|
+
/** Fill colour (CSS colour string). */
|
|
25
25
|
colour: string;
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* The center point of the circle in world space.
|
|
28
|
+
*/
|
|
27
29
|
get center(): Vector2;
|
|
28
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* The radius of the circle in world space (accounting for scale).
|
|
32
|
+
*/
|
|
29
33
|
get worldRadius(): number;
|
|
34
|
+
/**
|
|
35
|
+
* Initializes a new instance of a Circle.
|
|
36
|
+
* @param props Configuration properties for the circle.
|
|
37
|
+
*/
|
|
30
38
|
constructor(props: CircleProps);
|
|
31
39
|
}
|
package/dist/Circle.js
CHANGED
|
@@ -10,15 +10,23 @@ const defaultProps = {
|
|
|
10
10
|
* A basic circle shape that can be drawn to the screen.
|
|
11
11
|
*/
|
|
12
12
|
export default class Circle extends GameObject {
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* The center point of the circle in world space.
|
|
15
|
+
*/
|
|
14
16
|
get center() {
|
|
15
17
|
const r = this.radius * this.transform.worldScale.x;
|
|
16
18
|
return this.transform.worldPosition.add(new Vector2(r, r));
|
|
17
19
|
}
|
|
18
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* The radius of the circle in world space (accounting for scale).
|
|
22
|
+
*/
|
|
19
23
|
get worldRadius() {
|
|
20
24
|
return this.radius * this.transform.worldScale.x;
|
|
21
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Initializes a new instance of a Circle.
|
|
28
|
+
* @param props Configuration properties for the circle.
|
|
29
|
+
*/
|
|
22
30
|
constructor(props) {
|
|
23
31
|
super(props.tag || defaultProps.tag, props.zIndex || defaultProps.zIndex);
|
|
24
32
|
const defaultedProps = Object.assign(Object.assign({}, defaultProps), props);
|
package/dist/Circle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Circle.js","sourceRoot":"","sources":["../src/Circle.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,cAAc,MAAM,qBAAqB,CAAC;AAkBjD,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,QAAQ;IACb,MAAM,EAAE,OAAO;IACf,MAAM,EAAE,CAAC;CACV,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,UAAU;IAM5C
|
|
1
|
+
{"version":3,"file":"Circle.js","sourceRoot":"","sources":["../src/Circle.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,cAAc,MAAM,qBAAqB,CAAC;AAkBjD,MAAM,YAAY,GAAG;IACnB,GAAG,EAAE,QAAQ;IACb,MAAM,EAAE,OAAO;IACf,MAAM,EAAE,CAAC;CACV,C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IAAI,CAAC,YAAY,CAAC,IAAI,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QAEvF,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;CACF"}
|
package/dist/Engine.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import GameObject from './GameObject.js';
|
|
2
2
|
import Scene from './Scene.js';
|
|
3
3
|
import Camera from './Camera.js';
|
|
4
|
-
import System from './System.js';
|
|
5
4
|
import RenderingSystem from './RenderingSystem.js';
|
|
6
5
|
import type { CollisionManifold } from './Physics.js';
|
|
6
|
+
import { ObjectSet } from './ObjectSet.js';
|
|
7
7
|
/**
|
|
8
8
|
* Options for initializing the Engine.
|
|
9
9
|
*/
|
|
@@ -30,39 +30,6 @@ export interface EngineCallbacks {
|
|
|
30
30
|
/** Optional callback for physics or fixed-step logic. */
|
|
31
31
|
fixedUpdate?: () => void;
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Specialized Set for managing game objects with helper methods.
|
|
35
|
-
*/
|
|
36
|
-
export declare class ObjectSet extends Set<GameObject> {
|
|
37
|
-
/**
|
|
38
|
-
* Find all objects with a specific tag.
|
|
39
|
-
* @param tag The tag to search for.
|
|
40
|
-
*/
|
|
41
|
-
findAll: (tag?: string) => GameObject[];
|
|
42
|
-
constructor();
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Interface for the shared global state of the Engine.
|
|
46
|
-
*/
|
|
47
|
-
export interface EngineState {
|
|
48
|
-
objects: ObjectSet;
|
|
49
|
-
paused: boolean;
|
|
50
|
-
debug: boolean;
|
|
51
|
-
selectedObject: GameObject | null;
|
|
52
|
-
camera: Camera;
|
|
53
|
-
systems: System[];
|
|
54
|
-
renderingSystem?: RenderingSystem;
|
|
55
|
-
events: EventTarget;
|
|
56
|
-
currentScene: Scene | null;
|
|
57
|
-
debugCollisions: {
|
|
58
|
-
manifold: CollisionManifold;
|
|
59
|
-
timestamp: number;
|
|
60
|
-
}[];
|
|
61
|
-
showPhysicsVectors: boolean;
|
|
62
|
-
showCollisionLines: boolean;
|
|
63
|
-
zOrderDirty: boolean;
|
|
64
|
-
sortedObjects: GameObject[];
|
|
65
|
-
}
|
|
66
33
|
/**
|
|
67
34
|
* The core singleton class that manages the game loop, rendering, and scene state.
|
|
68
35
|
*/
|
|
@@ -171,6 +138,9 @@ export default class Engine {
|
|
|
171
138
|
private _ctx;
|
|
172
139
|
private _window;
|
|
173
140
|
private _title;
|
|
141
|
+
private _isWindowInternal;
|
|
142
|
+
private _destroyed;
|
|
143
|
+
private _resizeHandler;
|
|
174
144
|
/** Current background colour. */
|
|
175
145
|
backgroundColour: string;
|
|
176
146
|
/** Registered engine callbacks. */
|
|
@@ -179,9 +149,13 @@ export default class Engine {
|
|
|
179
149
|
width: number;
|
|
180
150
|
/** Pixel height of the canvas. */
|
|
181
151
|
height: number;
|
|
182
|
-
/**
|
|
152
|
+
/**
|
|
153
|
+
* Current mouse x position in world space.
|
|
154
|
+
*/
|
|
183
155
|
get mouseX(): number;
|
|
184
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* Current mouse y position in world space.
|
|
158
|
+
*/
|
|
185
159
|
get mouseY(): number;
|
|
186
160
|
/** Current frames per second (rolling average). */
|
|
187
161
|
fps: number;
|
|
@@ -192,39 +166,58 @@ export default class Engine {
|
|
|
192
166
|
private _accumulator;
|
|
193
167
|
private _fixedDelta;
|
|
194
168
|
private _fpsValues;
|
|
169
|
+
/**
|
|
170
|
+
* Initializes a new instance of the Engine.
|
|
171
|
+
* @param callbacks Lifecycle and update callbacks.
|
|
172
|
+
* @param opts Configuration options for the engine.
|
|
173
|
+
*/
|
|
195
174
|
constructor(callbacks: EngineCallbacks, opts?: Partial<EngineOpts>);
|
|
175
|
+
/**
|
|
176
|
+
* Completely stops the engine and cleans up all resources.
|
|
177
|
+
*/
|
|
178
|
+
terminate(): void;
|
|
196
179
|
private _onLoad;
|
|
197
180
|
private _update;
|
|
198
181
|
private _fixedUpdate;
|
|
199
182
|
private _setBackground;
|
|
200
183
|
private _draw;
|
|
184
|
+
/**
|
|
185
|
+
* Cleans up expired debug collisions.
|
|
186
|
+
* @param now Current timestamp.
|
|
187
|
+
*/
|
|
188
|
+
static cleanDebugCollisions(now?: number): void;
|
|
201
189
|
private _drawDebug;
|
|
202
|
-
private _findAllObjects;
|
|
203
190
|
/**
|
|
204
|
-
*
|
|
205
|
-
* @param
|
|
206
|
-
* @param
|
|
191
|
+
* Schedules a function to run after a delay.
|
|
192
|
+
* @param callback The function to run.
|
|
193
|
+
* @param delay The delay in milliseconds.
|
|
194
|
+
* @returns A timer ID.
|
|
207
195
|
*/
|
|
208
|
-
setTimeout(
|
|
196
|
+
setTimeout(callback: () => void, delay: number): number;
|
|
209
197
|
/**
|
|
210
|
-
*
|
|
211
|
-
* @param milliseconds
|
|
212
|
-
* @param fn
|
|
213
|
-
* @param onEnded
|
|
198
|
+
* Starts a countdown timer that runs a function every second and an ending function.
|
|
199
|
+
* @param milliseconds The total duration of the countdown.
|
|
200
|
+
* @param fn The function to run every second.
|
|
201
|
+
* @param onEnded The function to run when the countdown is finished.
|
|
214
202
|
*/
|
|
215
203
|
countdown(milliseconds: number, fn: () => void, onEnded: () => void): void;
|
|
216
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* Sets the CSS cursor style for the game canvas.
|
|
206
|
+
* @param value The CSS cursor value (e.g., 'pointer', 'crosshair').
|
|
207
|
+
*/
|
|
217
208
|
set cursor(value: string);
|
|
218
209
|
/**
|
|
219
|
-
*
|
|
210
|
+
* Registers a game object with the active scene or global engine loop.
|
|
220
211
|
* @param object The object to register.
|
|
221
212
|
*/
|
|
222
213
|
static registerObject(object: GameObject): void;
|
|
223
214
|
/**
|
|
224
|
-
*
|
|
215
|
+
* Removes a game object from the active scene or global engine loop.
|
|
225
216
|
* @param object The object to destroy.
|
|
226
217
|
*/
|
|
227
218
|
static destroyObject(object: GameObject): void;
|
|
228
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* Destroy all objects in the active scene or global engine.
|
|
221
|
+
*/
|
|
229
222
|
static destroyAll(): void;
|
|
230
223
|
}
|
package/dist/Engine.js
CHANGED
|
@@ -1,27 +1,11 @@
|
|
|
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
1
|
import Canvas from './Canvas.js';
|
|
11
2
|
import Input from './Input.js';
|
|
12
3
|
import Camera from './Camera.js';
|
|
13
4
|
import PhysicsSystem from './PhysicsSystem.js';
|
|
14
5
|
import RenderingSystem from './RenderingSystem.js';
|
|
6
|
+
import Registry from './Registry.js';
|
|
15
7
|
import PhysicsComponent from './PhysicsComponent.js';
|
|
16
|
-
|
|
17
|
-
* Specialized Set for managing game objects with helper methods.
|
|
18
|
-
*/
|
|
19
|
-
export class ObjectSet extends Set {
|
|
20
|
-
constructor() {
|
|
21
|
-
super();
|
|
22
|
-
this.findAll = () => [];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
8
|
+
import { ObjectSet } from './ObjectSet.js';
|
|
25
9
|
/**
|
|
26
10
|
* Shared state for the engine to ensure singletons work across different module loads.
|
|
27
11
|
*/
|
|
@@ -143,7 +127,12 @@ export default class Engine {
|
|
|
143
127
|
* The currently selected object in debug mode.
|
|
144
128
|
*/
|
|
145
129
|
static get selectedObject() { return this._state.selectedObject; }
|
|
146
|
-
static set selectedObject(val) {
|
|
130
|
+
static set selectedObject(val) {
|
|
131
|
+
if (this._state.selectedObject !== val) {
|
|
132
|
+
this._state.selectedObject = val;
|
|
133
|
+
this.emit('selectedObjectChanged', val);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
147
136
|
/**
|
|
148
137
|
* Whether the global object list needs to be re-sorted by z-index.
|
|
149
138
|
*/
|
|
@@ -175,15 +164,26 @@ export default class Engine {
|
|
|
175
164
|
scene.onLoad();
|
|
176
165
|
}
|
|
177
166
|
}
|
|
178
|
-
/**
|
|
167
|
+
/**
|
|
168
|
+
* Current mouse x position in world space.
|
|
169
|
+
*/
|
|
179
170
|
get mouseX() {
|
|
180
171
|
return Input.mouseX;
|
|
181
172
|
}
|
|
182
|
-
/**
|
|
173
|
+
/**
|
|
174
|
+
* Current mouse y position in world space.
|
|
175
|
+
*/
|
|
183
176
|
get mouseY() {
|
|
184
177
|
return Input.mouseY;
|
|
185
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Initializes a new instance of the Engine.
|
|
181
|
+
* @param callbacks Lifecycle and update callbacks.
|
|
182
|
+
* @param opts Configuration options for the engine.
|
|
183
|
+
*/
|
|
186
184
|
constructor(callbacks, opts = {}) {
|
|
185
|
+
this._isWindowInternal = false;
|
|
186
|
+
this._destroyed = false;
|
|
187
187
|
/** Current frames per second (rolling average). */
|
|
188
188
|
this.fps = 0;
|
|
189
189
|
/** Current frame time in milliseconds. */
|
|
@@ -193,8 +193,13 @@ export default class Engine {
|
|
|
193
193
|
this._accumulator = 0;
|
|
194
194
|
this._fixedDelta = 1 / 60;
|
|
195
195
|
this._fpsValues = [];
|
|
196
|
+
// Terminate existing engine if any
|
|
197
|
+
const global = globalThis;
|
|
198
|
+
if (global.__DINO_ENGINE_INSTANCE__) {
|
|
199
|
+
global.__DINO_ENGINE_INSTANCE__.terminate();
|
|
200
|
+
}
|
|
201
|
+
global.__DINO_ENGINE_INSTANCE__ = this;
|
|
196
202
|
const defaultedOpts = Object.assign({ width: '100%', height: '100%', title: 'Example', backgroundColour: 'white' }, opts);
|
|
197
|
-
Engine.objects.findAll = this._findAllObjects.bind(this);
|
|
198
203
|
this._title = document.createElement('title');
|
|
199
204
|
this._title.innerHTML = defaultedOpts.title;
|
|
200
205
|
const heads = document.getElementsByTagName('head');
|
|
@@ -226,6 +231,7 @@ export default class Engine {
|
|
|
226
231
|
Engine.renderingSystem = new RenderingSystem(this._ctx);
|
|
227
232
|
}
|
|
228
233
|
if (!container) {
|
|
234
|
+
this._isWindowInternal = true;
|
|
229
235
|
this._window = document.createElement('div');
|
|
230
236
|
this._window.id = 'canvas-container';
|
|
231
237
|
this._window.style.width = defaultedOpts.width;
|
|
@@ -240,18 +246,45 @@ export default class Engine {
|
|
|
240
246
|
this._window = container;
|
|
241
247
|
}
|
|
242
248
|
Input.init();
|
|
243
|
-
|
|
244
|
-
|
|
249
|
+
this._canvas.onResize = () => {
|
|
250
|
+
var _a;
|
|
245
251
|
this.width = this._canvas.canvas.width;
|
|
246
252
|
this.height = this._canvas.canvas.height;
|
|
247
|
-
|
|
253
|
+
if ((_a = Engine.currentScene) === null || _a === void 0 ? void 0 : _a.onResize) {
|
|
254
|
+
Engine.currentScene.onResize(this.width, this.height);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
this._resizeHandler = () => {
|
|
258
|
+
this._canvas.resize(container || undefined);
|
|
259
|
+
};
|
|
260
|
+
window.addEventListener('resize', this._resizeHandler);
|
|
248
261
|
setTimeout(() => { var _a, _b; return (_b = (_a = this.callbacks).onLoad) === null || _b === void 0 ? void 0 : _b.call(_a); }, 0);
|
|
249
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Completely stops the engine and cleans up all resources.
|
|
265
|
+
*/
|
|
266
|
+
terminate() {
|
|
267
|
+
this._destroyed = true;
|
|
268
|
+
window.removeEventListener('resize', this._resizeHandler);
|
|
269
|
+
this._canvas.destroy();
|
|
270
|
+
if (this._isWindowInternal && this._window) {
|
|
271
|
+
this._window.remove();
|
|
272
|
+
}
|
|
273
|
+
if (this._title) {
|
|
274
|
+
this._title.remove();
|
|
275
|
+
}
|
|
276
|
+
const global = globalThis;
|
|
277
|
+
if (global.__DINO_ENGINE_INSTANCE__ === this) {
|
|
278
|
+
global.__DINO_ENGINE_INSTANCE__ = null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
250
281
|
_onLoad() {
|
|
251
282
|
this._draw();
|
|
252
283
|
window.requestAnimationFrame(this._update.bind(this));
|
|
253
284
|
}
|
|
254
285
|
_update(timestamp) {
|
|
286
|
+
if (this._destroyed)
|
|
287
|
+
return;
|
|
255
288
|
if (this._oldTimestamp === 0)
|
|
256
289
|
this._oldTimestamp = timestamp;
|
|
257
290
|
if (!Engine.paused) {
|
|
@@ -312,6 +345,16 @@ export default class Engine {
|
|
|
312
345
|
this._drawDebug(objects);
|
|
313
346
|
}
|
|
314
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* Cleans up expired debug collisions.
|
|
350
|
+
* @param now Current timestamp.
|
|
351
|
+
*/
|
|
352
|
+
static cleanDebugCollisions(now = Date.now()) {
|
|
353
|
+
const TTL = 500; // 500ms
|
|
354
|
+
while (this.debugCollisions.length > 0 && now - this.debugCollisions[0].timestamp > TTL) {
|
|
355
|
+
this.debugCollisions.shift();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
315
358
|
_drawDebug(objects) {
|
|
316
359
|
var _a, _b, _c, _d;
|
|
317
360
|
// Draw Stats Overlay (Top Right)
|
|
@@ -365,75 +408,55 @@ export default class Engine {
|
|
|
365
408
|
}
|
|
366
409
|
this._ctx.restore();
|
|
367
410
|
}
|
|
368
|
-
_findAllObjects(tag = '') {
|
|
369
|
-
if (!tag) {
|
|
370
|
-
return Array.from(Engine.objects);
|
|
371
|
-
}
|
|
372
|
-
return Array.from(Engine.objects).filter((obj) => obj.metadata.tag === tag);
|
|
373
|
-
}
|
|
374
411
|
/**
|
|
375
|
-
*
|
|
376
|
-
* @param
|
|
377
|
-
* @param
|
|
412
|
+
* Schedules a function to run after a delay.
|
|
413
|
+
* @param callback The function to run.
|
|
414
|
+
* @param delay The delay in milliseconds.
|
|
415
|
+
* @returns A timer ID.
|
|
378
416
|
*/
|
|
379
|
-
setTimeout(
|
|
380
|
-
return
|
|
381
|
-
yield new Promise((resolve) => {
|
|
382
|
-
setTimeout(resolve, time);
|
|
383
|
-
});
|
|
384
|
-
timeoutFn();
|
|
385
|
-
});
|
|
417
|
+
setTimeout(callback, delay) {
|
|
418
|
+
return window.setTimeout(callback, delay);
|
|
386
419
|
}
|
|
387
420
|
/**
|
|
388
|
-
*
|
|
389
|
-
* @param milliseconds
|
|
390
|
-
* @param fn
|
|
391
|
-
* @param onEnded
|
|
421
|
+
* Starts a countdown timer that runs a function every second and an ending function.
|
|
422
|
+
* @param milliseconds The total duration of the countdown.
|
|
423
|
+
* @param fn The function to run every second.
|
|
424
|
+
* @param onEnded The function to run when the countdown is finished.
|
|
392
425
|
*/
|
|
393
426
|
countdown(milliseconds, fn, onEnded) {
|
|
394
|
-
setTimeout(onEnded, milliseconds);
|
|
427
|
+
this.setTimeout(onEnded, milliseconds);
|
|
395
428
|
for (let i = 1; i <= milliseconds; i += 1) {
|
|
396
429
|
if (i % 1000 === 0) {
|
|
397
|
-
setTimeout(fn, i);
|
|
430
|
+
this.setTimeout(fn, i);
|
|
398
431
|
}
|
|
399
432
|
}
|
|
400
433
|
}
|
|
401
|
-
/**
|
|
434
|
+
/**
|
|
435
|
+
* Sets the CSS cursor style for the game canvas.
|
|
436
|
+
* @param value The CSS cursor value (e.g., 'pointer', 'crosshair').
|
|
437
|
+
*/
|
|
402
438
|
set cursor(value) {
|
|
403
439
|
const canvas = document.getElementById('canvas');
|
|
404
440
|
if (canvas)
|
|
405
441
|
canvas.style.cursor = value;
|
|
406
442
|
}
|
|
407
443
|
/**
|
|
408
|
-
*
|
|
444
|
+
* Registers a game object with the active scene or global engine loop.
|
|
409
445
|
* @param object The object to register.
|
|
410
446
|
*/
|
|
411
447
|
static registerObject(object) {
|
|
412
|
-
|
|
413
|
-
if (Engine.currentScene) {
|
|
414
|
-
Engine.currentScene.add(object);
|
|
415
|
-
}
|
|
416
|
-
else {
|
|
417
|
-
this.objects.add(object);
|
|
418
|
-
}
|
|
448
|
+
Registry.registerObject(object);
|
|
419
449
|
}
|
|
420
450
|
/**
|
|
421
|
-
*
|
|
451
|
+
* Removes a game object from the active scene or global engine loop.
|
|
422
452
|
* @param object The object to destroy.
|
|
423
453
|
*/
|
|
424
454
|
static destroyObject(object) {
|
|
425
|
-
|
|
426
|
-
if (this.selectedObject === object) {
|
|
427
|
-
this.selectedObject = null;
|
|
428
|
-
}
|
|
429
|
-
if (Engine.currentScene) {
|
|
430
|
-
Engine.currentScene.remove(object);
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
this.objects.delete(object);
|
|
434
|
-
}
|
|
455
|
+
Registry.destroyObject(object);
|
|
435
456
|
}
|
|
436
|
-
/**
|
|
457
|
+
/**
|
|
458
|
+
* Destroy all objects in the active scene or global engine.
|
|
459
|
+
*/
|
|
437
460
|
static destroyAll() {
|
|
438
461
|
this.zOrderDirty = true;
|
|
439
462
|
if (Engine.currentScene) {
|