@vpmedia/phaser 1.118.0 → 1.119.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/index.js +23 -24
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/game.d.ts +34 -8
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/scene.d.ts +3 -2
- package/dist/phaser/core/scene.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts +28 -17
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/game.ts +45 -22
- package/src/phaser/core/scene.ts +4 -2
- package/src/phaser/core/scene_manager.test.ts +193 -0
- package/src/phaser/core/scene_manager.ts +51 -36
- package/src/phaser/display/webgl/renderer.ts +1 -1
|
@@ -9,16 +9,42 @@ import { Loader } from './loader.js';
|
|
|
9
9
|
import { RequestAnimationFrame } from './raf.js';
|
|
10
10
|
import { ScaleManager } from './scale_manager.js';
|
|
11
11
|
import { SceneManager } from './scene_manager.js';
|
|
12
|
+
import type { SceneDefinition } from './scene_manager.js';
|
|
12
13
|
import { Signal } from './signal.js';
|
|
13
14
|
import { SoundManager } from './sound_manager.js';
|
|
14
15
|
import { Stage } from './stage.js';
|
|
15
16
|
import { Time } from './time.js';
|
|
16
17
|
import { TweenManager } from './tween_manager.js';
|
|
17
18
|
import { World } from './world.js';
|
|
19
|
+
/**
|
|
20
|
+
* The options a game is created with. Everything the constructor defaults is always present on
|
|
21
|
+
* `Game.config`; the rest is only there when the caller supplied it.
|
|
22
|
+
*/
|
|
23
|
+
export type GameConfig = {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
backgroundColor: number;
|
|
27
|
+
canvasID: string;
|
|
28
|
+
canvasStyle: Record<string, string> | undefined;
|
|
29
|
+
resolution: number;
|
|
30
|
+
transparent: boolean | 'notMultiplied';
|
|
31
|
+
antialias: boolean;
|
|
32
|
+
preserveDrawingBuffer: boolean;
|
|
33
|
+
clearBeforeRender: boolean;
|
|
34
|
+
roundPixels: boolean;
|
|
35
|
+
renderType: number;
|
|
36
|
+
isForceDisabledAudio: boolean;
|
|
37
|
+
maxParallelDownloads: number;
|
|
38
|
+
canvas?: HTMLCanvasElement;
|
|
39
|
+
isSkipTicker?: boolean;
|
|
40
|
+
parent?: string | HTMLElement;
|
|
41
|
+
state?: SceneDefinition | string;
|
|
42
|
+
logger?: Logger;
|
|
43
|
+
};
|
|
18
44
|
export declare class Game {
|
|
19
45
|
/** Set when the scene manager kick-starts the first scene. */
|
|
20
46
|
isKickStart: boolean;
|
|
21
|
-
config:
|
|
47
|
+
config: GameConfig;
|
|
22
48
|
id: number;
|
|
23
49
|
parent: string | HTMLElement;
|
|
24
50
|
width: number;
|
|
@@ -46,8 +72,8 @@ export declare class Game {
|
|
|
46
72
|
onResume: Signal;
|
|
47
73
|
onBoot: Signal;
|
|
48
74
|
isPaused: boolean;
|
|
49
|
-
contextLostBinded:
|
|
50
|
-
contextRestoredBinded:
|
|
75
|
+
contextLostBinded: EventListener | null;
|
|
76
|
+
contextRestoredBinded: EventListener | null;
|
|
51
77
|
/**
|
|
52
78
|
* Creates a new Game instance.
|
|
53
79
|
* @param {object} gameConfig - The configuration object for the game.
|
|
@@ -68,7 +94,7 @@ export declare class Game {
|
|
|
68
94
|
* @param {string|HTMLElement} gameConfig.parent - The parent element to append the canvas to.
|
|
69
95
|
* @param {object} gameConfig.state - The initial state object or class.
|
|
70
96
|
*/
|
|
71
|
-
constructor(gameConfig?:
|
|
97
|
+
constructor(gameConfig?: Partial<GameConfig>);
|
|
72
98
|
/**
|
|
73
99
|
* Boots the game and initializes all systems.
|
|
74
100
|
*/
|
|
@@ -87,22 +113,22 @@ export declare class Game {
|
|
|
87
113
|
* @param {string} key - The configuration key to parse.
|
|
88
114
|
* @param {*} defaultValue - The default value if the key is not found in config.
|
|
89
115
|
*/
|
|
90
|
-
parseConfigElement(config:
|
|
116
|
+
parseConfigElement<K extends keyof GameConfig>(config: Partial<GameConfig>, key: K, defaultValue?: GameConfig[K]): void;
|
|
91
117
|
/**
|
|
92
118
|
* Parses the configuration object and sets up game properties.
|
|
93
119
|
* @param {object} config - The configuration object to parse.
|
|
94
120
|
*/
|
|
95
|
-
parseConfig(config:
|
|
121
|
+
parseConfig(config: Partial<GameConfig>): void;
|
|
96
122
|
/**
|
|
97
123
|
* Called when the WebGL context is lost.
|
|
98
124
|
* @param {WebGLContextEvent | Event} event - The WebGL context loss event.
|
|
99
125
|
*/
|
|
100
|
-
contextLost(event:
|
|
126
|
+
contextLost(event: Event): void;
|
|
101
127
|
/**
|
|
102
128
|
* Called when the WebGL context is restored.
|
|
103
129
|
* @param {WebGLContextEvent | Event} event - The WebGL context restore event.
|
|
104
130
|
*/
|
|
105
|
-
contextRestored(event:
|
|
131
|
+
contextRestored(event: Event): void;
|
|
106
132
|
/**
|
|
107
133
|
* Updates the game state.
|
|
108
134
|
* @param {number} time - The current timestamp.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"game.d.ts","sourceRoot":"","sources":["../../../src/phaser/core/game.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EA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AC,GAAG,IAAI,CAsBpD;IAED;;;OAGG;IACI,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAMrC;IAED;;;OAGG;IACI,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAOzC;IAED;;;OAGG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAkBhC;IAED;;OAEG;IACI,OAAO,IAAI,IAAI,CAwCrB;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../../src/phaser/core/scene.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;IACT,IAAI,EAAE,GAAG,CAAQ;
|
|
1
|
+
{"version":3,"file":"scene.d.ts","sourceRoot":"","sources":["../../../src/phaser/core/scene.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,qBAAa,KAAK;IACT,IAAI,EAAE,IAAI,GAAG,IAAI,CAAQ;IACzB,GAAG,SAAM;IAChB;;OAEG;IAEH;;;OAGG;IACI,IAAI,IAAI,IAAI,CAElB;IAED;;;OAGG;IACI,OAAO,IAAI,IAAI,CAErB;IAED;;;OAGG;IACI,MAAM,IAAI,IAAI,CAEpB;IAED;;;OAGG;IACI,MAAM,IAAI,IAAI,CAEpB;IAED;;;;OAIG;IACI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAEnD;IAED;;;OAGG;IACI,WAAW,IAAI,IAAI,CAEzB;IAED;;;OAGG;IACI,QAAQ,IAAI,IAAI,CAEtB;CACF"}
|
|
@@ -6,33 +6,43 @@ export type SceneHooks = {
|
|
|
6
6
|
preload?: () => void;
|
|
7
7
|
create?: () => void;
|
|
8
8
|
update?: () => void;
|
|
9
|
+
render?: () => void;
|
|
9
10
|
resize?: (width: number, height: number) => void;
|
|
10
11
|
pauseUpdate?: () => void;
|
|
11
12
|
shutdown?: () => void;
|
|
12
13
|
};
|
|
14
|
+
/** A scene once the manager holds it: its hooks plus the wiring the manager adds. */
|
|
15
|
+
export type SceneState = SceneHooks & {
|
|
16
|
+
game?: Game | null;
|
|
17
|
+
key?: string;
|
|
18
|
+
};
|
|
19
|
+
/** What the manager accepts as a scene: an instance, a plain hook object, or a class to build one. */
|
|
20
|
+
export type SceneDefinition = SceneState | (new (game: Game) => SceneState);
|
|
21
|
+
/** A hook invoked with the scene as its receiver and the game as its argument. */
|
|
22
|
+
type SceneCallback = (game: Game) => void;
|
|
13
23
|
export declare class SceneManager {
|
|
14
24
|
game: Game;
|
|
15
|
-
states:
|
|
16
|
-
_pendingState:
|
|
17
|
-
_clearWorld:
|
|
18
|
-
_clearCache:
|
|
19
|
-
_created:
|
|
20
|
-
_args:
|
|
25
|
+
states: Record<string, SceneState>;
|
|
26
|
+
_pendingState: SceneDefinition | string | null;
|
|
27
|
+
_clearWorld: boolean;
|
|
28
|
+
_clearCache: boolean;
|
|
29
|
+
_created: boolean;
|
|
30
|
+
_args: unknown[];
|
|
21
31
|
current: string;
|
|
22
|
-
onInitCallback:
|
|
23
|
-
onPreloadCallback:
|
|
24
|
-
onCreateCallback:
|
|
25
|
-
onUpdateCallback:
|
|
26
|
-
onResizeCallback:
|
|
27
|
-
onPauseUpdateCallback:
|
|
28
|
-
onShutDownCallback:
|
|
29
|
-
callbackContext:
|
|
32
|
+
onInitCallback: ((...args: unknown[]) => void) | null;
|
|
33
|
+
onPreloadCallback: SceneCallback | null;
|
|
34
|
+
onCreateCallback: SceneCallback | null;
|
|
35
|
+
onUpdateCallback: SceneCallback | null;
|
|
36
|
+
onResizeCallback: ((width: number, height: number) => void) | null;
|
|
37
|
+
onPauseUpdateCallback: SceneCallback | null;
|
|
38
|
+
onShutDownCallback: SceneCallback | null;
|
|
39
|
+
callbackContext: SceneState;
|
|
30
40
|
/**
|
|
31
41
|
* Creates a new SceneManager instance.
|
|
32
42
|
* @param {Game} game - The game instance this manager belongs to.
|
|
33
43
|
* @param {string} pendingState - The state to load when the game boots.
|
|
34
44
|
*/
|
|
35
|
-
constructor(game: Game, pendingState: string);
|
|
45
|
+
constructor(game: Game, pendingState: SceneDefinition | string | null);
|
|
36
46
|
/**
|
|
37
47
|
* Initialize the scene manager.
|
|
38
48
|
* This method is called when the game boots and sets up the initial state.
|
|
@@ -45,7 +55,7 @@ export declare class SceneManager {
|
|
|
45
55
|
* @param {boolean} autoStart - Whether to start this state immediately.
|
|
46
56
|
* @returns {Scene|object} The created scene or state object.
|
|
47
57
|
*/
|
|
48
|
-
add(key: string, state:
|
|
58
|
+
add(key: string, state: SceneDefinition, autoStart?: boolean): SceneState;
|
|
49
59
|
/**
|
|
50
60
|
* Remove a scene state from the manager.
|
|
51
61
|
* @param {string} key - The unique key for the state to remove.
|
|
@@ -138,6 +148,7 @@ export declare class SceneManager {
|
|
|
138
148
|
* Get whether the scene has been created.
|
|
139
149
|
* @returns {boolean} True if the scene has been created, false otherwise.
|
|
140
150
|
*/
|
|
141
|
-
get created():
|
|
151
|
+
get created(): boolean;
|
|
142
152
|
}
|
|
153
|
+
export {};
|
|
143
154
|
//# sourceMappingURL=scene_manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scene_manager.d.ts","sourceRoot":"","sources":["../../../src/phaser/core/scene_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,0FAA0F;AAC1F,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,CAAC,EAAE,CAAC,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,EAAE,OAAO,EAAE,GAAG,IAAI,CAUzF;IAED;;;;;OAKG;IACI,OAAO,CAAC,UAAU,UAAO,EAAE,UAAU,UAAQ,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAO9E;IAED;;;OAGG;IACI,SAAS,IAAI,IAAI,CA6BvB;IAED;;;OAGG;IACI,iBAAiB,IAAI,IAAI,CAgB/B;IAED;;;;OAIG;IACI,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMtC;IAED;;;OAGG;IACI,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAM7B;IAED;;;OAGG;IACI,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAK/B;IAED;;;OAGG;IACI,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAkBxC;IAED;;;;OAIG;IACI,eAAe,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAE9C;IAED;;;OAGG;IACI,YAAY,IAAI,IAAI,CAO1B;IAED;;;OAGG;IACI,MAAM,IAAI,IAAI,CAIpB;IAED;;;OAGG;IACI,WAAW,IAAI,IAAI,CAIzB;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAIjD;IAED;;;OAGG;IACI,OAAO,IAAI,IAAI,CAarB;IAED;;;OAGG;IACI,KAAK,IAAI,IAAI,CAEnB;IAED;;;OAGG;IACH,IAAW,OAAO,YAEjB;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vpmedia/phaser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.119.0",
|
|
4
4
|
"description": "@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2",
|
|
5
5
|
"author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
|
|
6
6
|
"license": "MIT",
|
package/src/phaser/core/game.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { Loader } from './loader.js';
|
|
|
12
12
|
import { RequestAnimationFrame } from './raf.js';
|
|
13
13
|
import { ScaleManager } from './scale_manager.js';
|
|
14
14
|
import { SceneManager } from './scene_manager.js';
|
|
15
|
+
import type { SceneDefinition } from './scene_manager.js';
|
|
15
16
|
import { Signal } from './signal.js';
|
|
16
17
|
import { SoundManager } from './sound_manager.js';
|
|
17
18
|
import { Stage } from './stage.js';
|
|
@@ -20,10 +21,36 @@ import { TweenManager } from './tween_manager.js';
|
|
|
20
21
|
import { World } from './world.js';
|
|
21
22
|
import { getRegistry } from './registry.js';
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* The options a game is created with. Everything the constructor defaults is always present on
|
|
26
|
+
* `Game.config`; the rest is only there when the caller supplied it.
|
|
27
|
+
*/
|
|
28
|
+
export type GameConfig = {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
backgroundColor: number;
|
|
32
|
+
canvasID: string;
|
|
33
|
+
canvasStyle: Record<string, string> | undefined;
|
|
34
|
+
resolution: number;
|
|
35
|
+
transparent: boolean | 'notMultiplied';
|
|
36
|
+
antialias: boolean;
|
|
37
|
+
preserveDrawingBuffer: boolean;
|
|
38
|
+
clearBeforeRender: boolean;
|
|
39
|
+
roundPixels: boolean;
|
|
40
|
+
renderType: number;
|
|
41
|
+
isForceDisabledAudio: boolean;
|
|
42
|
+
maxParallelDownloads: number;
|
|
43
|
+
canvas?: HTMLCanvasElement;
|
|
44
|
+
isSkipTicker?: boolean;
|
|
45
|
+
parent?: string | HTMLElement;
|
|
46
|
+
state?: SceneDefinition | string;
|
|
47
|
+
logger?: Logger;
|
|
48
|
+
};
|
|
49
|
+
|
|
23
50
|
export class Game {
|
|
24
51
|
/** Set when the scene manager kick-starts the first scene. */
|
|
25
52
|
public isKickStart = false;
|
|
26
|
-
public config!:
|
|
53
|
+
public config!: GameConfig;
|
|
27
54
|
public id!: number;
|
|
28
55
|
public parent!: string | HTMLElement;
|
|
29
56
|
public width!: number;
|
|
@@ -56,8 +83,8 @@ export class Game {
|
|
|
56
83
|
public onResume!: Signal;
|
|
57
84
|
public onBoot!: Signal;
|
|
58
85
|
public isPaused!: boolean;
|
|
59
|
-
public contextLostBinded!:
|
|
60
|
-
public contextRestoredBinded!:
|
|
86
|
+
public contextLostBinded!: EventListener | null;
|
|
87
|
+
public contextRestoredBinded!: EventListener | null;
|
|
61
88
|
/**
|
|
62
89
|
* Creates a new Game instance.
|
|
63
90
|
* @param {object} gameConfig - The configuration object for the game.
|
|
@@ -78,9 +105,8 @@ export class Game {
|
|
|
78
105
|
* @param {string|HTMLElement} gameConfig.parent - The parent element to append the canvas to.
|
|
79
106
|
* @param {object} gameConfig.state - The initial state object or class.
|
|
80
107
|
*/
|
|
81
|
-
public constructor(gameConfig:
|
|
108
|
+
public constructor(gameConfig: Partial<GameConfig> = {}) {
|
|
82
109
|
getRegistry();
|
|
83
|
-
this.config = {};
|
|
84
110
|
this.id = 0;
|
|
85
111
|
this.parent = '';
|
|
86
112
|
this.width = 800;
|
|
@@ -160,7 +186,7 @@ export class Game {
|
|
|
160
186
|
this.canvas = create(this, this.width, this.height, this.config.canvasID, true);
|
|
161
187
|
}
|
|
162
188
|
if (this.config.canvasStyle) {
|
|
163
|
-
const canvasStyle = this.config
|
|
189
|
+
const { canvasStyle } = this.config;
|
|
164
190
|
for (const property of Object.keys(canvasStyle)) {
|
|
165
191
|
this.canvas.style.setProperty(property, canvasStyle[property] ?? null);
|
|
166
192
|
}
|
|
@@ -223,21 +249,22 @@ export class Game {
|
|
|
223
249
|
* @param {string} key - The configuration key to parse.
|
|
224
250
|
* @param {*} defaultValue - The default value if the key is not found in config.
|
|
225
251
|
*/
|
|
226
|
-
public parseConfigElement
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
252
|
+
public parseConfigElement<K extends keyof GameConfig>(
|
|
253
|
+
config: Partial<GameConfig>,
|
|
254
|
+
key: K,
|
|
255
|
+
defaultValue?: GameConfig[K]
|
|
256
|
+
): void {
|
|
257
|
+
this.config[key] = (config[key] ?? defaultValue)!;
|
|
232
258
|
}
|
|
233
259
|
|
|
234
260
|
/**
|
|
235
261
|
* Parses the configuration object and sets up game properties.
|
|
236
262
|
* @param {object} config - The configuration object to parse.
|
|
237
263
|
*/
|
|
238
|
-
public parseConfig(config:
|
|
264
|
+
public parseConfig(config: Partial<GameConfig>): void {
|
|
239
265
|
this.logger = config.logger ?? getLogger(['phaser']);
|
|
240
266
|
this.logger.info('parseConfig');
|
|
267
|
+
this.config = {} as GameConfig;
|
|
241
268
|
this.parseConfigElement(config, 'width', 800);
|
|
242
269
|
this.parseConfigElement(config, 'height', 600);
|
|
243
270
|
this.parseConfigElement(config, 'backgroundColor', 0x00_00_00);
|
|
@@ -255,19 +282,15 @@ export class Game {
|
|
|
255
282
|
if (config.parent) {
|
|
256
283
|
this.parent = config.parent;
|
|
257
284
|
}
|
|
258
|
-
|
|
259
|
-
if (config.state) {
|
|
260
|
-
({ state } = config);
|
|
261
|
-
}
|
|
262
|
-
this.state = new SceneManager(this, state);
|
|
285
|
+
this.state = new SceneManager(this, config.state ?? null);
|
|
263
286
|
}
|
|
264
287
|
|
|
265
288
|
/**
|
|
266
289
|
* Called when the WebGL context is lost.
|
|
267
290
|
* @param {WebGLContextEvent | Event} event - The WebGL context loss event.
|
|
268
291
|
*/
|
|
269
|
-
public contextLost(event:
|
|
270
|
-
this.logger.info('contextLost', event);
|
|
292
|
+
public contextLost(event: Event): void {
|
|
293
|
+
this.logger.info('contextLost', { type: event.type });
|
|
271
294
|
event.preventDefault();
|
|
272
295
|
if (this.renderer) {
|
|
273
296
|
this.renderer.contextLost = true;
|
|
@@ -278,8 +301,8 @@ export class Game {
|
|
|
278
301
|
* Called when the WebGL context is restored.
|
|
279
302
|
* @param {WebGLContextEvent | Event} event - The WebGL context restore event.
|
|
280
303
|
*/
|
|
281
|
-
public contextRestored(event:
|
|
282
|
-
this.logger.info('contextRestored', event);
|
|
304
|
+
public contextRestored(event: Event): void {
|
|
305
|
+
this.logger.info('contextRestored', { type: event.type });
|
|
283
306
|
if (this.renderer) {
|
|
284
307
|
this.renderer.initContext(this);
|
|
285
308
|
// This.cache.clearGLTextures();
|
package/src/phaser/core/scene.ts
CHANGED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { Scene } from './scene.js';
|
|
3
|
+
import { SceneManager } from './scene_manager.js';
|
|
4
|
+
import type { Game } from './game.js';
|
|
5
|
+
import type { SceneState } from './scene_manager.js';
|
|
6
|
+
|
|
7
|
+
const createGame = (isBooted = true): Game =>
|
|
8
|
+
({
|
|
9
|
+
isBooted,
|
|
10
|
+
isKickStart: false,
|
|
11
|
+
world: { x: 0, y: 0, destroy: vi.fn() },
|
|
12
|
+
tweens: { removeAll: vi.fn() },
|
|
13
|
+
input: { reset: vi.fn() },
|
|
14
|
+
time: { removeAll: vi.fn() },
|
|
15
|
+
scale: { reset: vi.fn() },
|
|
16
|
+
cache: { destroy: vi.fn() },
|
|
17
|
+
load: { reset: vi.fn(), start: vi.fn(), totalQueuedFiles: (): number => 0, totalQueuedPacks: (): number => 0 },
|
|
18
|
+
}) as unknown as Game;
|
|
19
|
+
|
|
20
|
+
const createManager = (pendingState: ConstructorParameters<typeof SceneManager>[1] = null): SceneManager =>
|
|
21
|
+
new SceneManager(createGame(), pendingState);
|
|
22
|
+
|
|
23
|
+
describe('SceneManager', () => {
|
|
24
|
+
describe('add', () => {
|
|
25
|
+
it('takes a plain hook object and links the game onto it', () => {
|
|
26
|
+
const manager = createManager();
|
|
27
|
+
const state: SceneState = { create: vi.fn<() => void>() };
|
|
28
|
+
expect(manager.add('menu', state)).toBe(state);
|
|
29
|
+
expect(state.game).toBeDefined();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('builds a state from a constructor', () => {
|
|
33
|
+
const manager = createManager();
|
|
34
|
+
class Menu extends Scene {}
|
|
35
|
+
expect(manager.add('menu', Menu)).toBeInstanceOf(Menu);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('takes a scene instance as-is', () => {
|
|
39
|
+
const manager = createManager();
|
|
40
|
+
const scene = new Scene();
|
|
41
|
+
expect(manager.add('menu', scene)).toBe(scene);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('queues the state when the game has not booted', () => {
|
|
45
|
+
const manager = new SceneManager(createGame(false), null);
|
|
46
|
+
manager.add('menu', { create: vi.fn<() => void>() }, true);
|
|
47
|
+
expect(manager._pendingState).toBe('menu');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('starts the state right away once the game has booted', () => {
|
|
51
|
+
const manager = createManager();
|
|
52
|
+
manager.add('menu', { create: vi.fn<() => void>() }, true);
|
|
53
|
+
expect(manager._pendingState).toBe('menu');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('boot', () => {
|
|
58
|
+
it('registers a state given as an object under the default key', () => {
|
|
59
|
+
const manager = createManager({ create: vi.fn<() => void>() });
|
|
60
|
+
manager.boot();
|
|
61
|
+
expect(manager.states['default']).toBeDefined();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('leaves a state given by key alone', () => {
|
|
65
|
+
const manager = createManager('menu');
|
|
66
|
+
manager.boot();
|
|
67
|
+
expect(manager.states['default']).toBeUndefined();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('checkState', () => {
|
|
72
|
+
it('accepts a state carrying any of the lifecycle hooks', () => {
|
|
73
|
+
const manager = createManager();
|
|
74
|
+
manager.add('menu', { update: vi.fn<() => void>() });
|
|
75
|
+
expect(manager.checkState('menu')).toBe(true);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('rejects a state with no hooks at all', () => {
|
|
79
|
+
const manager = createManager();
|
|
80
|
+
manager.add('menu', {});
|
|
81
|
+
expect(manager.checkState('menu')).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('rejects a key it does not hold', () => {
|
|
85
|
+
expect(createManager().checkState('nope')).toBe(false);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('setCurrentState', () => {
|
|
90
|
+
it('binds the hooks the state provides and leaves the rest null', () => {
|
|
91
|
+
const manager = createManager();
|
|
92
|
+
const create = vi.fn<() => void>();
|
|
93
|
+
manager.add('menu', { create });
|
|
94
|
+
manager.setCurrentState('menu');
|
|
95
|
+
expect(manager.current).toBe('menu');
|
|
96
|
+
expect(manager.onCreateCallback).toBe(create);
|
|
97
|
+
expect(manager.onUpdateCallback).toBeNull();
|
|
98
|
+
expect(manager.onPreloadCallback).toBeNull();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('falls back to a no-op for init and shutdown', () => {
|
|
102
|
+
const manager = createManager();
|
|
103
|
+
manager.add('menu', {});
|
|
104
|
+
manager.setCurrentState('menu');
|
|
105
|
+
expect(manager.onInitCallback).toBe(manager.dummy);
|
|
106
|
+
expect(manager.onShutDownCallback).toBe(manager.dummy);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('calls init with the arguments start was given', () => {
|
|
110
|
+
const manager = createManager();
|
|
111
|
+
const init = vi.fn<() => void>();
|
|
112
|
+
manager.add('menu', { init, update: vi.fn<() => void>() });
|
|
113
|
+
manager.start('menu', true, false, 'a', 1);
|
|
114
|
+
manager.setCurrentState('menu');
|
|
115
|
+
expect(init).toHaveBeenCalledWith('a', 1);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('stamps the key onto the state', () => {
|
|
119
|
+
const manager = createManager();
|
|
120
|
+
const state: SceneState = { create: vi.fn<() => void>() };
|
|
121
|
+
manager.add('menu', state);
|
|
122
|
+
manager.setCurrentState('menu');
|
|
123
|
+
expect(state.key).toBe('menu');
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('start', () => {
|
|
128
|
+
it('ignores a key with no lifecycle hooks', () => {
|
|
129
|
+
const manager = createManager();
|
|
130
|
+
manager.add('menu', {});
|
|
131
|
+
manager.start('menu');
|
|
132
|
+
expect(manager._pendingState).toBeNull();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('update', () => {
|
|
137
|
+
it('runs the update hook only once the scene has been created', () => {
|
|
138
|
+
const manager = createManager();
|
|
139
|
+
const update = vi.fn<() => void>();
|
|
140
|
+
manager.add('menu', { update });
|
|
141
|
+
manager.setCurrentState('menu');
|
|
142
|
+
manager.update();
|
|
143
|
+
expect(update).not.toHaveBeenCalled();
|
|
144
|
+
manager.loadComplete();
|
|
145
|
+
manager.update();
|
|
146
|
+
expect(update).toHaveBeenCalledTimes(1);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('runs the create hook exactly once', () => {
|
|
150
|
+
const manager = createManager();
|
|
151
|
+
const create = vi.fn<() => void>();
|
|
152
|
+
manager.add('menu', { create });
|
|
153
|
+
manager.setCurrentState('menu');
|
|
154
|
+
manager.loadComplete();
|
|
155
|
+
manager.loadComplete();
|
|
156
|
+
expect(create).toHaveBeenCalledTimes(1);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('resize', () => {
|
|
161
|
+
it('passes the new size to the scene', () => {
|
|
162
|
+
const manager = createManager();
|
|
163
|
+
const resize = vi.fn<(width: number, height: number) => void>();
|
|
164
|
+
manager.add('menu', { resize });
|
|
165
|
+
manager.setCurrentState('menu');
|
|
166
|
+
manager.resize(320, 240);
|
|
167
|
+
expect(resize).toHaveBeenCalledWith(320, 240);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('remove', () => {
|
|
172
|
+
it('drops the state and unbinds its hooks when it is current', () => {
|
|
173
|
+
const manager = createManager();
|
|
174
|
+
manager.add('menu', { create: vi.fn<() => void>() });
|
|
175
|
+
manager.setCurrentState('menu');
|
|
176
|
+
manager.remove('menu');
|
|
177
|
+
expect(manager.states['menu']).toBeUndefined();
|
|
178
|
+
expect(manager.onCreateCallback).toBeNull();
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
describe('destroy', () => {
|
|
183
|
+
it('empties the manager', () => {
|
|
184
|
+
const manager = createManager();
|
|
185
|
+
manager.add('menu', { create: vi.fn<() => void>(), shutdown: vi.fn<() => void>() });
|
|
186
|
+
manager.setCurrentState('menu');
|
|
187
|
+
manager.destroy();
|
|
188
|
+
expect(manager.states).toStrictEqual({});
|
|
189
|
+
expect(manager.current).toBe('');
|
|
190
|
+
expect(manager._pendingState).toBeNull();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
});
|