dino-ge 1.10.2 → 1.10.6
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 +5 -1
- package/dist/Canvas.js +5 -1
- 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 +37 -49
- package/dist/Engine.js +76 -71
- 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 +8 -4
- package/dist/RenderingSystem.js.map +1 -1
- package/dist/Scene.d.ts +18 -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/TransformComponent.d.ts +19 -1
- package/dist/TransformComponent.js +37 -13
- package/dist/TransformComponent.js.map +1 -1
- package/dist/Vector2.d.ts +54 -9
- package/dist/Vector2.js +70 -9
- 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,6 +8,10 @@ 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.
|
|
@@ -15,7 +19,7 @@ export default class Canvas {
|
|
|
15
19
|
*/
|
|
16
20
|
resize(parent?: HTMLElement): void;
|
|
17
21
|
/**
|
|
18
|
-
*
|
|
22
|
+
* Completely removes the canvas element and cleans up its observers.
|
|
19
23
|
*/
|
|
20
24
|
destroy(): void;
|
|
21
25
|
}
|
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';
|
|
@@ -42,7 +46,7 @@ export default class Canvas {
|
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
/**
|
|
45
|
-
*
|
|
49
|
+
* Completely removes the canvas element and cleans up its observers.
|
|
46
50
|
*/
|
|
47
51
|
destroy() {
|
|
48
52
|
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,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AAe,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,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,UAAU;IAM5C;;OAEG;IACH,IAAW,MAAM;QACf,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;QACpD,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;IA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'./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,53 @@ 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;
|
|
201
184
|
private _drawDebug;
|
|
202
|
-
private _findAllObjects;
|
|
203
185
|
/**
|
|
204
|
-
*
|
|
205
|
-
* @param
|
|
206
|
-
* @param
|
|
186
|
+
* Schedules a function to run after a delay.
|
|
187
|
+
* @param callback The function to run.
|
|
188
|
+
* @param delay The delay in milliseconds.
|
|
189
|
+
* @returns A timer ID.
|
|
207
190
|
*/
|
|
208
|
-
setTimeout(
|
|
191
|
+
setTimeout(callback: () => void, delay: number): number;
|
|
209
192
|
/**
|
|
210
|
-
*
|
|
211
|
-
* @param milliseconds
|
|
212
|
-
* @param fn
|
|
213
|
-
* @param onEnded
|
|
193
|
+
* Starts a countdown timer that runs a function every second and an ending function.
|
|
194
|
+
* @param milliseconds The total duration of the countdown.
|
|
195
|
+
* @param fn The function to run every second.
|
|
196
|
+
* @param onEnded The function to run when the countdown is finished.
|
|
214
197
|
*/
|
|
215
198
|
countdown(milliseconds: number, fn: () => void, onEnded: () => void): void;
|
|
216
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* Sets the CSS cursor style for the game canvas.
|
|
201
|
+
* @param value The CSS cursor value (e.g., 'pointer', 'crosshair').
|
|
202
|
+
*/
|
|
217
203
|
set cursor(value: string);
|
|
218
204
|
/**
|
|
219
|
-
*
|
|
205
|
+
* Registers a game object with the active scene or global engine loop.
|
|
220
206
|
* @param object The object to register.
|
|
221
207
|
*/
|
|
222
208
|
static registerObject(object: GameObject): void;
|
|
223
209
|
/**
|
|
224
|
-
*
|
|
210
|
+
* Removes a game object from the active scene or global engine loop.
|
|
225
211
|
* @param object The object to destroy.
|
|
226
212
|
*/
|
|
227
213
|
static destroyObject(object: GameObject): void;
|
|
228
|
-
/**
|
|
214
|
+
/**
|
|
215
|
+
* Destroy all objects in the active scene or global engine.
|
|
216
|
+
*/
|
|
229
217
|
static destroyAll(): void;
|
|
230
218
|
}
|
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,39 @@ export default class Engine {
|
|
|
240
246
|
this._window = container;
|
|
241
247
|
}
|
|
242
248
|
Input.init();
|
|
243
|
-
|
|
249
|
+
this._resizeHandler = () => {
|
|
244
250
|
this._canvas.resize(container || undefined);
|
|
245
251
|
this.width = this._canvas.canvas.width;
|
|
246
252
|
this.height = this._canvas.canvas.height;
|
|
247
|
-
}
|
|
253
|
+
};
|
|
254
|
+
window.addEventListener('resize', this._resizeHandler);
|
|
248
255
|
setTimeout(() => { var _a, _b; return (_b = (_a = this.callbacks).onLoad) === null || _b === void 0 ? void 0 : _b.call(_a); }, 0);
|
|
249
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Completely stops the engine and cleans up all resources.
|
|
259
|
+
*/
|
|
260
|
+
terminate() {
|
|
261
|
+
this._destroyed = true;
|
|
262
|
+
window.removeEventListener('resize', this._resizeHandler);
|
|
263
|
+
this._canvas.destroy();
|
|
264
|
+
if (this._isWindowInternal && this._window) {
|
|
265
|
+
this._window.remove();
|
|
266
|
+
}
|
|
267
|
+
if (this._title) {
|
|
268
|
+
this._title.remove();
|
|
269
|
+
}
|
|
270
|
+
const global = globalThis;
|
|
271
|
+
if (global.__DINO_ENGINE_INSTANCE__ === this) {
|
|
272
|
+
global.__DINO_ENGINE_INSTANCE__ = null;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
250
275
|
_onLoad() {
|
|
251
276
|
this._draw();
|
|
252
277
|
window.requestAnimationFrame(this._update.bind(this));
|
|
253
278
|
}
|
|
254
279
|
_update(timestamp) {
|
|
280
|
+
if (this._destroyed)
|
|
281
|
+
return;
|
|
255
282
|
if (this._oldTimestamp === 0)
|
|
256
283
|
this._oldTimestamp = timestamp;
|
|
257
284
|
if (!Engine.paused) {
|
|
@@ -342,10 +369,8 @@ export default class Engine {
|
|
|
342
369
|
['Size', `${Math.round((_b = (_a = obj.bounds) === null || _a === void 0 ? void 0 : _a.width) !== null && _b !== void 0 ? _b : 0)}x${Math.round((_d = (_c = obj.bounds) === null || _c === void 0 ? void 0 : _c.height) !== null && _d !== void 0 ? _d : 0)}`]
|
|
343
370
|
];
|
|
344
371
|
const tagComp = obj.metadata;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
properties.push(['Z-Index', tagComp.zIndex]);
|
|
348
|
-
}
|
|
372
|
+
properties.unshift(['Tag', tagComp.tag]);
|
|
373
|
+
properties.push(['Z-Index', tagComp.zIndex]);
|
|
349
374
|
const physComp = obj.getComponent(PhysicsComponent);
|
|
350
375
|
if (physComp) {
|
|
351
376
|
properties.push(['Vel', `${Math.round(physComp.velocity.x)}, ${Math.round(physComp.velocity.y)}`]);
|
|
@@ -365,75 +390,55 @@ export default class Engine {
|
|
|
365
390
|
}
|
|
366
391
|
this._ctx.restore();
|
|
367
392
|
}
|
|
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
393
|
/**
|
|
375
|
-
*
|
|
376
|
-
* @param
|
|
377
|
-
* @param
|
|
394
|
+
* Schedules a function to run after a delay.
|
|
395
|
+
* @param callback The function to run.
|
|
396
|
+
* @param delay The delay in milliseconds.
|
|
397
|
+
* @returns A timer ID.
|
|
378
398
|
*/
|
|
379
|
-
setTimeout(
|
|
380
|
-
return
|
|
381
|
-
yield new Promise((resolve) => {
|
|
382
|
-
setTimeout(resolve, time);
|
|
383
|
-
});
|
|
384
|
-
timeoutFn();
|
|
385
|
-
});
|
|
399
|
+
setTimeout(callback, delay) {
|
|
400
|
+
return window.setTimeout(callback, delay);
|
|
386
401
|
}
|
|
387
402
|
/**
|
|
388
|
-
*
|
|
389
|
-
* @param milliseconds
|
|
390
|
-
* @param fn
|
|
391
|
-
* @param onEnded
|
|
403
|
+
* Starts a countdown timer that runs a function every second and an ending function.
|
|
404
|
+
* @param milliseconds The total duration of the countdown.
|
|
405
|
+
* @param fn The function to run every second.
|
|
406
|
+
* @param onEnded The function to run when the countdown is finished.
|
|
392
407
|
*/
|
|
393
408
|
countdown(milliseconds, fn, onEnded) {
|
|
394
|
-
setTimeout(onEnded, milliseconds);
|
|
409
|
+
this.setTimeout(onEnded, milliseconds);
|
|
395
410
|
for (let i = 1; i <= milliseconds; i += 1) {
|
|
396
411
|
if (i % 1000 === 0) {
|
|
397
|
-
setTimeout(fn, i);
|
|
412
|
+
this.setTimeout(fn, i);
|
|
398
413
|
}
|
|
399
414
|
}
|
|
400
415
|
}
|
|
401
|
-
/**
|
|
416
|
+
/**
|
|
417
|
+
* Sets the CSS cursor style for the game canvas.
|
|
418
|
+
* @param value The CSS cursor value (e.g., 'pointer', 'crosshair').
|
|
419
|
+
*/
|
|
402
420
|
set cursor(value) {
|
|
403
421
|
const canvas = document.getElementById('canvas');
|
|
404
422
|
if (canvas)
|
|
405
423
|
canvas.style.cursor = value;
|
|
406
424
|
}
|
|
407
425
|
/**
|
|
408
|
-
*
|
|
426
|
+
* Registers a game object with the active scene or global engine loop.
|
|
409
427
|
* @param object The object to register.
|
|
410
428
|
*/
|
|
411
429
|
static registerObject(object) {
|
|
412
|
-
|
|
413
|
-
if (Engine.currentScene) {
|
|
414
|
-
Engine.currentScene.add(object);
|
|
415
|
-
}
|
|
416
|
-
else {
|
|
417
|
-
this.objects.add(object);
|
|
418
|
-
}
|
|
430
|
+
Registry.registerObject(object);
|
|
419
431
|
}
|
|
420
432
|
/**
|
|
421
|
-
*
|
|
433
|
+
* Removes a game object from the active scene or global engine loop.
|
|
422
434
|
* @param object The object to destroy.
|
|
423
435
|
*/
|
|
424
436
|
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
|
-
}
|
|
437
|
+
Registry.destroyObject(object);
|
|
435
438
|
}
|
|
436
|
-
/**
|
|
439
|
+
/**
|
|
440
|
+
* Destroy all objects in the active scene or global engine.
|
|
441
|
+
*/
|
|
437
442
|
static destroyAll() {
|
|
438
443
|
this.zOrderDirty = true;
|
|
439
444
|
if (Engine.currentScene) {
|