@vpmedia/phaser 1.118.0 → 1.120.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.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * as Const from './phaser/core/const.js';
2
2
  export { GameObjectFactory } from './phaser/core/factory.js';
3
3
  export { Game } from './phaser/core/game.js';
4
+ export type { GameConfig } from './phaser/core/game.js';
4
5
  export { Signal } from './phaser/core/signal.js';
5
6
  export * as MathUtils from './phaser/util/math.js';
6
7
  export { Cache } from './phaser/core/cache.js';
@@ -11,6 +12,7 @@ export type { LoaderFile } from './phaser/core/loader.js';
11
12
  export { ScaleManager } from './phaser/core/scale_manager.js';
12
13
  export { Scene } from './phaser/core/scene.js';
13
14
  export { SceneManager } from './phaser/core/scene_manager.js';
15
+ export type { SceneDefinition, SceneHooks, SceneState } from './phaser/core/scene_manager.js';
14
16
  export { Sound } from './phaser/core/sound.js';
15
17
  export { SoundManager } from './phaser/core/sound_manager.js';
16
18
  export { SoundSprite } from './phaser/core/sound_sprite.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAEzD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,YAAY,EAAE,UAAU,EA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AoC,CAAC;AAEtE,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAEhD,OAAO,EACL,6BAA6B,EAC7B,kCAAkC,EAClC,mCAAmC,EACnC,uCAAuC,EACvC,mCAAmC,EACnC,6BAA6B,EAC7B,sCAAsC,EACtC,+BAA+B,GAChC,MAAM,6BAA6B,CAAC"}
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 = null;
16962
- if (state instanceof Scene) newState = state;
16963
- else if (typeof state === "object") {
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
- } else if (typeof state === "function") newState = new state(this.game);
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
- if (this.states[key]) {
17061
- if (this.states[key].preload || this.states[key].create || this.states[key].update || this.states[key].render) return true;
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].game = this.game;
17072
- this.states[key].key = key;
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
- if (this.states[key]) this.states[key].game = null;
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 === false && this.onCreateCallback) {
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.canvasStyle;
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
- if (config[key] !== void 0) this.config[key] = config[key];
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
- let state = null;
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;