@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
package/dist/index.js
CHANGED
|
@@ -11692,7 +11692,7 @@ var WebGLRenderer = class {
|
|
|
11692
11692
|
this.height = game.height;
|
|
11693
11693
|
this.view = game.canvas;
|
|
11694
11694
|
this._contextOptions = {
|
|
11695
|
-
alpha: game.config.transparent,
|
|
11695
|
+
alpha: Boolean(game.config.transparent),
|
|
11696
11696
|
depth: false,
|
|
11697
11697
|
antialias: game.config.antialias,
|
|
11698
11698
|
premultipliedAlpha: game.config.transparent && game.config.transparent !== "notMultiplied",
|
|
@@ -16958,12 +16958,12 @@ var SceneManager = class {
|
|
|
16958
16958
|
* @returns {Scene|object} The created scene or state object.
|
|
16959
16959
|
*/
|
|
16960
16960
|
add(key, state, autoStart = false) {
|
|
16961
|
-
let newState
|
|
16962
|
-
if (state
|
|
16963
|
-
else
|
|
16961
|
+
let newState;
|
|
16962
|
+
if (typeof state === "function") newState = new state(this.game);
|
|
16963
|
+
else {
|
|
16964
16964
|
newState = state;
|
|
16965
|
-
newState.game = this.game;
|
|
16966
|
-
}
|
|
16965
|
+
if (!(state instanceof Scene)) newState.game = this.game;
|
|
16966
|
+
}
|
|
16967
16967
|
this.states[key] = newState;
|
|
16968
16968
|
if (autoStart) {
|
|
16969
16969
|
if (this.game.isBooted) this.start(key);
|
|
@@ -17019,7 +17019,7 @@ var SceneManager = class {
|
|
|
17019
17019
|
* This method is called before the game loop updates.
|
|
17020
17020
|
*/
|
|
17021
17021
|
preUpdate() {
|
|
17022
|
-
if (this._pendingState && this.game.isBooted) {
|
|
17022
|
+
if (typeof this._pendingState === "string" && this._pendingState && this.game.isBooted) {
|
|
17023
17023
|
this.clearCurrentState();
|
|
17024
17024
|
this.setCurrentState(this._pendingState);
|
|
17025
17025
|
this.game.world.x = 0;
|
|
@@ -17057,10 +17057,8 @@ var SceneManager = class {
|
|
|
17057
17057
|
* @returns {boolean} True if the scene exists, false otherwise.
|
|
17058
17058
|
*/
|
|
17059
17059
|
checkState(key) {
|
|
17060
|
-
|
|
17061
|
-
|
|
17062
|
-
return false;
|
|
17063
|
-
}
|
|
17060
|
+
const state = this.states[key];
|
|
17061
|
+
if (state) return Boolean(state.preload ?? state.create ?? state.update ?? state.render);
|
|
17064
17062
|
return false;
|
|
17065
17063
|
}
|
|
17066
17064
|
/**
|
|
@@ -17068,15 +17066,19 @@ var SceneManager = class {
|
|
|
17068
17066
|
* @param {string} key - The unique key for the state to link.
|
|
17069
17067
|
*/
|
|
17070
17068
|
link(key) {
|
|
17071
|
-
this.states[key]
|
|
17072
|
-
|
|
17069
|
+
const state = this.states[key];
|
|
17070
|
+
if (state) {
|
|
17071
|
+
state.game = this.game;
|
|
17072
|
+
state.key = key;
|
|
17073
|
+
}
|
|
17073
17074
|
}
|
|
17074
17075
|
/**
|
|
17075
17076
|
* Unlink a scene state from the manager.
|
|
17076
17077
|
* @param {string} key - The unique key for the state to unlink.
|
|
17077
17078
|
*/
|
|
17078
17079
|
unlink(key) {
|
|
17079
|
-
|
|
17080
|
+
const state = this.states[key];
|
|
17081
|
+
if (state) state.game = null;
|
|
17080
17082
|
}
|
|
17081
17083
|
/**
|
|
17082
17084
|
* Set the current scene state.
|
|
@@ -17111,7 +17113,7 @@ var SceneManager = class {
|
|
|
17111
17113
|
* This method is called when scene loading is complete.
|
|
17112
17114
|
*/
|
|
17113
17115
|
loadComplete() {
|
|
17114
|
-
if (this._created
|
|
17116
|
+
if (!this._created && this.onCreateCallback) {
|
|
17115
17117
|
this._created = true;
|
|
17116
17118
|
this.onCreateCallback.call(this.callbackContext, this.game);
|
|
17117
17119
|
} else this._created = true;
|
|
@@ -20009,7 +20011,6 @@ var Game = class {
|
|
|
20009
20011
|
*/
|
|
20010
20012
|
constructor(gameConfig = {}) {
|
|
20011
20013
|
getRegistry();
|
|
20012
|
-
this.config = {};
|
|
20013
20014
|
this.id = 0;
|
|
20014
20015
|
this.parent = "";
|
|
20015
20016
|
this.width = 800;
|
|
@@ -20072,7 +20073,7 @@ var Game = class {
|
|
|
20072
20073
|
if (this.config.canvas) this.canvas = this.config.canvas;
|
|
20073
20074
|
else this.canvas = create(this, this.width, this.height, this.config.canvasID, true);
|
|
20074
20075
|
if (this.config.canvasStyle) {
|
|
20075
|
-
const canvasStyle = this.config
|
|
20076
|
+
const { canvasStyle } = this.config;
|
|
20076
20077
|
for (const property of Object.keys(canvasStyle)) this.canvas.style.setProperty(property, canvasStyle[property] ?? null);
|
|
20077
20078
|
} else this.canvas.style.setProperty("-webkit-full-screen", "width: 100%; height: 100%");
|
|
20078
20079
|
}
|
|
@@ -20118,8 +20119,7 @@ var Game = class {
|
|
|
20118
20119
|
* @param {*} defaultValue - The default value if the key is not found in config.
|
|
20119
20120
|
*/
|
|
20120
20121
|
parseConfigElement(config, key, defaultValue) {
|
|
20121
|
-
|
|
20122
|
-
else this.config[key] = defaultValue;
|
|
20122
|
+
this.config[key] = config[key] ?? defaultValue;
|
|
20123
20123
|
}
|
|
20124
20124
|
/**
|
|
20125
20125
|
* Parses the configuration object and sets up game properties.
|
|
@@ -20128,6 +20128,7 @@ var Game = class {
|
|
|
20128
20128
|
parseConfig(config) {
|
|
20129
20129
|
this.logger = config.logger ?? getLogger(["phaser"]);
|
|
20130
20130
|
this.logger.info("parseConfig");
|
|
20131
|
+
this.config = {};
|
|
20131
20132
|
this.parseConfigElement(config, "width", 800);
|
|
20132
20133
|
this.parseConfigElement(config, "height", 600);
|
|
20133
20134
|
this.parseConfigElement(config, "backgroundColor", 0);
|
|
@@ -20143,16 +20144,14 @@ var Game = class {
|
|
|
20143
20144
|
this.parseConfigElement(config, "isForceDisabledAudio", false);
|
|
20144
20145
|
this.parseConfigElement(config, "maxParallelDownloads", 16);
|
|
20145
20146
|
if (config.parent) this.parent = config.parent;
|
|
20146
|
-
|
|
20147
|
-
if (config.state) ({state} = config);
|
|
20148
|
-
this.state = new SceneManager(this, state);
|
|
20147
|
+
this.state = new SceneManager(this, config.state ?? null);
|
|
20149
20148
|
}
|
|
20150
20149
|
/**
|
|
20151
20150
|
* Called when the WebGL context is lost.
|
|
20152
20151
|
* @param {WebGLContextEvent | Event} event - The WebGL context loss event.
|
|
20153
20152
|
*/
|
|
20154
20153
|
contextLost(event) {
|
|
20155
|
-
this.logger.info("contextLost", event);
|
|
20154
|
+
this.logger.info("contextLost", { type: event.type });
|
|
20156
20155
|
event.preventDefault();
|
|
20157
20156
|
if (this.renderer) this.renderer.contextLost = true;
|
|
20158
20157
|
}
|
|
@@ -20161,7 +20160,7 @@ var Game = class {
|
|
|
20161
20160
|
* @param {WebGLContextEvent | Event} event - The WebGL context restore event.
|
|
20162
20161
|
*/
|
|
20163
20162
|
contextRestored(event) {
|
|
20164
|
-
this.logger.info("contextRestored", event);
|
|
20163
|
+
this.logger.info("contextRestored", { type: event.type });
|
|
20165
20164
|
if (this.renderer) {
|
|
20166
20165
|
this.renderer.initContext(this);
|
|
20167
20166
|
this.renderer.contextLost = false;
|