@vpmedia/phaser 1.124.0 → 1.126.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.
Files changed (81) hide show
  1. package/dist/index.js +312 -309
  2. package/dist/index.js.map +1 -1
  3. package/dist/phaser/core/animation_parser.d.ts.map +1 -1
  4. package/dist/phaser/core/device_util.d.ts.map +1 -1
  5. package/dist/phaser/core/dom.d.ts.map +1 -1
  6. package/dist/phaser/core/frame_data.d.ts.map +1 -1
  7. package/dist/phaser/core/game.d.ts.map +1 -1
  8. package/dist/phaser/core/input.d.ts.map +1 -1
  9. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  10. package/dist/phaser/core/loader.d.ts.map +1 -1
  11. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  12. package/dist/phaser/core/sound.d.ts.map +1 -1
  13. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  14. package/dist/phaser/core/tween.d.ts.map +1 -1
  15. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  16. package/dist/phaser/display/display_object.d.ts +2 -2
  17. package/dist/phaser/display/display_object.d.ts.map +1 -1
  18. package/dist/phaser/display/graphics.d.ts +1 -1
  19. package/dist/phaser/display/graphics.d.ts.map +1 -1
  20. package/dist/phaser/display/group.d.ts.map +1 -1
  21. package/dist/phaser/display/image.d.ts.map +1 -1
  22. package/dist/phaser/display/text.d.ts.map +1 -1
  23. package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
  24. package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
  25. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  26. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  27. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  28. package/dist/phaser/util/math.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/src/phaser/core/animation.ts +7 -7
  31. package/src/phaser/core/animation_manager.ts +2 -2
  32. package/src/phaser/core/animation_parser.ts +11 -15
  33. package/src/phaser/core/array_set.ts +2 -2
  34. package/src/phaser/core/cache.ts +4 -4
  35. package/src/phaser/core/device_util.ts +7 -4
  36. package/src/phaser/core/dom.ts +24 -19
  37. package/src/phaser/core/frame_data.ts +2 -5
  38. package/src/phaser/core/game.test.ts +131 -0
  39. package/src/phaser/core/game.ts +17 -12
  40. package/src/phaser/core/input.ts +4 -3
  41. package/src/phaser/core/input_handler.ts +14 -13
  42. package/src/phaser/core/input_mouse.ts +4 -4
  43. package/src/phaser/core/input_pointer.ts +1 -1
  44. package/src/phaser/core/loader.ts +38 -50
  45. package/src/phaser/core/scale_manager.ts +10 -9
  46. package/src/phaser/core/scene_manager.ts +2 -2
  47. package/src/phaser/core/signal.ts +2 -2
  48. package/src/phaser/core/sound.ts +25 -32
  49. package/src/phaser/core/sound_manager.ts +12 -16
  50. package/src/phaser/core/sound_sprite.ts +1 -1
  51. package/src/phaser/core/stage.ts +3 -3
  52. package/src/phaser/core/timer.ts +1 -1
  53. package/src/phaser/core/tween.ts +6 -11
  54. package/src/phaser/display/bitmap_text.ts +3 -3
  55. package/src/phaser/display/button.ts +12 -12
  56. package/src/phaser/display/canvas/graphics.ts +2 -2
  57. package/src/phaser/display/canvas/pool.ts +3 -3
  58. package/src/phaser/display/canvas/renderer.ts +6 -5
  59. package/src/phaser/display/canvas/tinter.ts +1 -1
  60. package/src/phaser/display/canvas/util.ts +2 -2
  61. package/src/phaser/display/display_object.ts +13 -14
  62. package/src/phaser/display/graphics.test.ts +2 -2
  63. package/src/phaser/display/graphics.ts +9 -11
  64. package/src/phaser/display/group.ts +10 -9
  65. package/src/phaser/display/image.ts +7 -6
  66. package/src/phaser/display/sprite_util.ts +1 -1
  67. package/src/phaser/display/text.ts +35 -44
  68. package/src/phaser/display/webgl/abstract_filter.ts +1 -1
  69. package/src/phaser/display/webgl/earcut.ts +46 -42
  70. package/src/phaser/display/webgl/graphics.ts +2 -2
  71. package/src/phaser/display/webgl/renderer.ts +3 -3
  72. package/src/phaser/display/webgl/shader/normal.ts +6 -6
  73. package/src/phaser/display/webgl/shader_manager.ts +1 -1
  74. package/src/phaser/display/webgl/sprite_batch.ts +2 -2
  75. package/src/phaser/display/webgl/texture.ts +2 -1
  76. package/src/phaser/display/webgl/util.ts +3 -3
  77. package/src/phaser/geom/polygon.ts +2 -2
  78. package/src/phaser/geom/rectangle.ts +1 -2
  79. package/src/phaser/geom/util/circle.ts +6 -10
  80. package/src/phaser/geom/util/point.ts +5 -7
  81. package/src/phaser/util/math.ts +2 -3
@@ -282,19 +282,19 @@ export class Loader {
282
282
  this.game.logger.warn(`Loader: Invalid or no key given of type ${type}`);
283
283
  return this;
284
284
  }
285
- if (url === undefined || url === null) {
286
- if (extension) {
287
- url = key + extension;
288
- } else {
285
+ let resolvedUrl = url;
286
+ if (resolvedUrl === undefined || resolvedUrl === null) {
287
+ if (extension === null) {
289
288
  this.game.logger.warn(`Loader: No URL given for file type: ${type} key: ${key}`);
290
289
  return this;
291
290
  }
291
+ resolvedUrl = key + extension;
292
292
  }
293
293
  const file: LoaderFile = {
294
294
  type,
295
295
  key,
296
296
  path: this.path,
297
- url,
297
+ url: resolvedUrl,
298
298
  syncPoint: this._withSyncPointDepth > 0,
299
299
  data: null,
300
300
  loading: false,
@@ -351,11 +351,9 @@ export class Loader {
351
351
  error: false,
352
352
  callbackContext,
353
353
  };
354
- if (data) {
355
- if (typeof data === 'string') {
356
- data = JSON.parse(data);
357
- }
358
- pack.data = (data ?? {}) as LoaderFileData;
354
+ if (data !== null) {
355
+ const parsed: unknown = typeof data === 'string' ? JSON.parse(data) : data;
356
+ pack.data = (parsed ?? {}) as LoaderFileData;
359
357
  pack.loaded = true;
360
358
  }
361
359
  for (let i = 0; i < this._fileList.length + 1; i += 1) {
@@ -473,10 +471,8 @@ export class Loader {
473
471
  if (this.game.sound.noAudio || this.game.device.noAudioFormat) {
474
472
  return this;
475
473
  }
476
- if (typeof urls === 'string') {
477
- urls = [urls];
478
- }
479
- return this.addToFileList('audio', key, urls, { buffer: null, autoDecode });
474
+ const sources = typeof urls === 'string' ? [urls] : urls;
475
+ return this.addToFileList('audio', key, sources, { buffer: null, autoDecode });
480
476
  }
481
477
 
482
478
  /**
@@ -495,11 +491,9 @@ export class Loader {
495
491
  this.audio(key, urls, autoDecode);
496
492
  if (jsonURL) {
497
493
  this.json(`${key}-audioatlas`, jsonURL);
498
- } else if (jsonData) {
499
- if (typeof jsonData === 'string') {
500
- jsonData = JSON.parse(jsonData);
501
- }
502
- this.cache.addJSON(`${key}-audioatlas`, '', jsonData);
494
+ } else if (jsonData !== null) {
495
+ const parsed: unknown = typeof jsonData === 'string' ? JSON.parse(jsonData) : jsonData;
496
+ this.cache.addJSON(`${key}-audioatlas`, '', parsed);
503
497
  }
504
498
  return this;
505
499
  }
@@ -523,13 +517,11 @@ export class Loader {
523
517
  xSpacing = 0,
524
518
  ySpacing = 0
525
519
  ): this {
526
- textureURL ??= `${key}.png`;
527
- if (atlasURL === null && atlasData === null) {
528
- atlasURL = `${key}.xml`;
529
- }
520
+ const texture = textureURL ?? `${key}.png`;
521
+ const atlas = atlasURL === null && atlasData === null ? `${key}.xml` : atlasURL;
530
522
  // A URL to a json/xml atlas has been given
531
- if (atlasURL) {
532
- this.addToFileList('bitmapfont', key, textureURL, { atlasURL, xSpacing, ySpacing });
523
+ if (atlas !== null) {
524
+ this.addToFileList('bitmapfont', key, texture, { atlasURL: atlas, xSpacing, ySpacing });
533
525
  } else if (typeof atlasData === 'string') {
534
526
  // A stringified xml/json atlas has been given
535
527
  let json: unknown = null;
@@ -539,13 +531,13 @@ export class Loader {
539
531
  } catch {
540
532
  xml = this.parseXml(atlasData);
541
533
  }
542
- if (!xml && !json) {
534
+ if (xml === null && json === null) {
543
535
  throw new Error(ENGINE_ERROR_INVALID_BITMAP_FONT_ATLAS);
544
536
  }
545
- this.addToFileList('bitmapfont', key, textureURL, {
537
+ this.addToFileList('bitmapfont', key, texture, {
546
538
  atlasURL: null,
547
539
  atlasData: json ?? xml,
548
- atlasType: json ? 'json' : 'xml',
540
+ atlasType: json === null ? 'xml' : 'json',
549
541
  xSpacing,
550
542
  ySpacing,
551
543
  });
@@ -569,15 +561,13 @@ export class Loader {
569
561
  atlasData: unknown = null,
570
562
  format: number = TEXTURE_ATLAS_JSON_HASH
571
563
  ): this {
572
- textureURL ??= `${key}.png`;
573
- if (!atlasURL && !atlasData) {
574
- atlasURL = `${key}.json`;
575
- }
564
+ const texture = textureURL ?? `${key}.png`;
565
+ const atlas = atlasURL === null && atlasData === null ? `${key}.json` : atlasURL;
576
566
  // A URL to a json/xml file has been given
577
- if (atlasURL) {
578
- this.addToFileList('textureatlas', key, textureURL, { atlasURL, format });
567
+ if (atlas !== null) {
568
+ this.addToFileList('textureatlas', key, texture, { atlasURL: atlas, format });
579
569
  } else {
580
- this.addToFileList('textureatlas', key, textureURL, { atlasURL: null, atlasData, format });
570
+ this.addToFileList('textureatlas', key, texture, { atlasURL: null, atlasData, format });
581
571
  }
582
572
  return this;
583
573
  }
@@ -701,7 +691,7 @@ export class Loader {
701
691
  }
702
692
  } else if (!file.loading && this._flightQueue.length < inflightLimit) {
703
693
  // -> not loaded/failed, not loading
704
- if (file.type === 'packfile' && !file.data) {
694
+ if (file.type === 'packfile' && file.data === null) {
705
695
  // Fetches the pack data: the pack is processed above as it reaches queue-start.
706
696
  // (Packs do not trigger onLoadStart or onFileStart.)
707
697
  this._flightQueue.push(file);
@@ -892,7 +882,7 @@ export class Loader {
892
882
  }
893
883
  case 'audio': {
894
884
  const resolved = this.getAudioURL(file.url);
895
- if (resolved) {
885
+ if (resolved !== null) {
896
886
  file.url = resolved;
897
887
  this.xhrLoad(file, this.transformUrl(resolved, file), 'arraybuffer', this.fileComplete);
898
888
  } else if (this.game.sound.noAudio) {
@@ -947,9 +937,9 @@ export class Loader {
947
937
  { once: true }
948
938
  );
949
939
  image.addEventListener('error', (): void => {
950
- if (this.isUseRetry && (!file.numRetry || file.numRetry < this.maxRetry)) {
940
+ if (this.isUseRetry && (file.numRetry === undefined || file.numRetry < this.maxRetry)) {
951
941
  setTimeout((): void => {
952
- file.numRetry = file.numRetry ? file.numRetry + 1 : 1;
942
+ file.numRetry = file.numRetry === undefined ? 1 : file.numRetry + 1;
953
943
  this.loadImageTag(file);
954
944
  }, 1000);
955
945
  } else if (!settled) {
@@ -993,16 +983,16 @@ export class Loader {
993
983
  xhr.setRequestHeader('X-Requested-With', requestedWith);
994
984
  }
995
985
  const acceptHeader = this.headers[file.type];
996
- if (acceptHeader) {
986
+ if (acceptHeader !== undefined && acceptHeader !== false) {
997
987
  xhr.setRequestHeader('Accept', acceptHeader);
998
988
  }
999
989
  const handleError = onerror ?? this.fileError;
1000
990
  const retry = (): boolean => {
1001
- if (!this.isUseRetry || (file.numRetry && file.numRetry >= this.maxRetry)) {
991
+ if (!this.isUseRetry || (file.numRetry !== undefined && file.numRetry >= this.maxRetry)) {
1002
992
  return false;
1003
993
  }
1004
994
  setTimeout((): void => {
1005
- file.numRetry = file.numRetry ? file.numRetry + 1 : 1;
995
+ file.numRetry = file.numRetry === undefined ? 1 : file.numRetry + 1;
1006
996
  this.xhrLoad(file, url, type, onload, handleError);
1007
997
  }, 1000);
1008
998
  return true;
@@ -1101,10 +1091,8 @@ export class Loader {
1101
1091
  */
1102
1092
  public fileError(file: LoaderFile, xhr: XMLHttpRequest | null = null, reason: unknown = 0): void {
1103
1093
  // const url = file.requestUrl || this.transformUrl(file.url, file);
1104
- if (!reason && xhr) {
1105
- reason = xhr.status;
1106
- }
1107
- const message = `Error loading asset (${String(reason)})`;
1094
+ const cause = reason === 0 && xhr !== null ? xhr.status : reason;
1095
+ const message = `Error loading asset (${String(cause)})`;
1108
1096
  this.asyncComplete(file, message);
1109
1097
  }
1110
1098
 
@@ -1156,7 +1144,7 @@ export class Loader {
1156
1144
  break;
1157
1145
  }
1158
1146
  case 'bitmapfont': {
1159
- if (!file.atlasURL) {
1147
+ if (file.atlasURL === null || file.atlasURL === undefined) {
1160
1148
  this.cache.addBitmapFont(
1161
1149
  file.key,
1162
1150
  url,
@@ -1181,7 +1169,7 @@ export class Loader {
1181
1169
  } catch {
1182
1170
  // pass
1183
1171
  }
1184
- if (json) {
1172
+ if (json !== undefined) {
1185
1173
  bitmapFontFile.atlasType = 'json';
1186
1174
  this.jsonLoadComplete(bitmapFontFile, bitmapFontXhr);
1187
1175
  } else {
@@ -1197,7 +1185,7 @@ export class Loader {
1197
1185
  const audio = response.response as ArrayBuffer;
1198
1186
  file.data = audio;
1199
1187
  this.cache.addSound(file.key, url, audio);
1200
- if (file.autoDecode) {
1188
+ if (file.autoDecode === true) {
1201
1189
  void this.game.sound.decode(file.key);
1202
1190
  }
1203
1191
  break;
@@ -1314,7 +1302,7 @@ export class Loader {
1314
1302
  } else {
1315
1303
  this.preloadSprite.rect.height = Math.floor((this.preloadSprite.height / 100) * this.progress);
1316
1304
  }
1317
- if (this.preloadSprite.sprite) {
1305
+ if (this.preloadSprite.sprite !== null) {
1318
1306
  this.preloadSprite.sprite.updateCrop();
1319
1307
  } else {
1320
1308
  // We seem to have lost our sprite - maybe it was destroyed?
@@ -5,6 +5,7 @@ import type { Game, GameConfig } from './game.js';
5
5
  import { DOM } from './dom.js';
6
6
  import { Signal } from './signal.js';
7
7
  import type { AppliedCallback, Callback } from './callback.js';
8
+ import type { Input } from './input.js';
8
9
 
9
10
  /** The gap the canvas leaves around itself inside its parent. */
10
11
  export type ScaleMargin = { left: number; top: number; right: number; bottom: number; x: number; y: number };
@@ -159,7 +160,7 @@ export class ScaleManager {
159
160
  this._lastReportedCanvasSize = new Rectangle();
160
161
  this._lastReportedGameSize = new Rectangle();
161
162
  this._booted = false;
162
- if (game.config) {
163
+ if (game.config as GameConfig | undefined) {
163
164
  this.parseConfig(game.config);
164
165
  }
165
166
  this.setupScale(width, height);
@@ -249,7 +250,7 @@ export class ScaleManager {
249
250
  if (typeof this.game.parent === 'string') {
250
251
  // hopefully an element ID
251
252
  target = document.querySelector<HTMLElement>(`#${CSS.escape(this.game.parent)}`);
252
- } else if (this.game.parent && this.game.parent.nodeType === 1) {
253
+ } else if (typeof this.game.parent === 'object' && this.game.parent.nodeType === 1) {
253
254
  // quick test for a HTMLelement
254
255
  target = this.game.parent;
255
256
  }
@@ -447,12 +448,12 @@ export class ScaleManager {
447
448
  this.scaleFactorInversed.y = this.height / this.game.height;
448
449
  this.aspectRatio = this.width / this.height;
449
450
  // This can be invoked in boot pre-canvas
450
- if (this.game.canvas) {
451
+ if (this.game.canvas as HTMLCanvasElement | undefined) {
451
452
  this.dom.getOffset(this.game.canvas, this.offset);
452
453
  }
453
454
  this.bounds.setTo(this.offset.x, this.offset.y, this.width, this.height);
454
455
  // Can be invoked in boot pre-input
455
- if (this.game.input && this.game.input.scale) {
456
+ if ((this.game.input as Input | undefined)?.scale) {
456
457
  this.game.input.scale.setTo(this.scaleFactor.x, this.scaleFactor.y);
457
458
  }
458
459
  }
@@ -579,7 +580,7 @@ export class ScaleManager {
579
580
  * @returns {Rectangle} TBD.
580
581
  */
581
582
  public getParentBounds(target: Rectangle): Rectangle {
582
- const bounds = target || new Rectangle();
583
+ const bounds = target ?? new Rectangle();
583
584
  const parentNode = this.boundingParent;
584
585
  const { visualBounds } = this.dom;
585
586
  const { layoutBounds } = this.dom;
@@ -757,10 +758,10 @@ export class ScaleManager {
757
758
  // Max/min not honored fullscreen
758
759
  return;
759
760
  }
760
- if (this.maxWidth) {
761
+ if (this.maxWidth !== null) {
761
762
  this.width = Math.min(this.width, this.maxWidth);
762
763
  }
763
- if (this.maxHeight) {
764
+ if (this.maxHeight !== null) {
764
765
  this.height = Math.min(this.height, this.maxHeight);
765
766
  }
766
767
  }
@@ -796,7 +797,7 @@ export class ScaleManager {
796
797
  }
797
798
  if (this.compatibility.clickTrampoline === 'when-not-mouse') {
798
799
  const { input } = this.game;
799
- if (input.activePointer && input.activePointer !== input.mousePointer && allowTrampoline) {
800
+ if (input.activePointer !== null && input.activePointer !== input.mousePointer && allowTrampoline) {
800
801
  input.activePointer.addClickTrampoline('startFullScreen', this.startFullScreen, this, [antialias, false]);
801
802
  return false;
802
803
  }
@@ -953,7 +954,7 @@ export class ScaleManager {
953
954
  if (this.parentIsWindow || (this.isFullScreen && this.hasPhaserSetFullScreen && !this._createdFullScreenTarget)) {
954
955
  return null;
955
956
  }
956
- const parentNode = this.game.canvas ? (this.game.canvas.parentNode as HTMLElement | null) : null;
957
+ const parentNode = (this.game.canvas.parentNode as HTMLElement | null) ?? null;
957
958
  return parentNode ?? null;
958
959
  }
959
960
 
@@ -137,7 +137,7 @@ export class SceneManager {
137
137
  this._pendingState = key;
138
138
  this._clearWorld = clearWorld;
139
139
  this._clearCache = clearCache;
140
- if (args && args.length > 0) {
140
+ if (args.length > 0) {
141
141
  this._args = [...args];
142
142
  }
143
143
  }
@@ -153,7 +153,7 @@ export class SceneManager {
153
153
  this._pendingState = this.current;
154
154
  this._clearWorld = clearWorld;
155
155
  this._clearCache = clearCache;
156
- if (args && args.length > 0) {
156
+ if (args.length > 0) {
157
157
  this._args = [...args];
158
158
  }
159
159
  }
@@ -185,7 +185,7 @@ export class Signal {
185
185
  let n = this._bindings.length;
186
186
  while (n) {
187
187
  n -= 1;
188
- if (context) {
188
+ if (context !== null) {
189
189
  if (this._bindings[n]!.context === context) {
190
190
  this._bindings[n]!._destroy();
191
191
  this._bindings.splice(n, 1);
@@ -194,7 +194,7 @@ export class Signal {
194
194
  this._bindings[n]!._destroy();
195
195
  }
196
196
  }
197
- if (!context) {
197
+ if (context === null) {
198
198
  this._bindings.length = 0;
199
199
  }
200
200
  }
@@ -81,7 +81,7 @@ export class Sound {
81
81
  */
82
82
  public constructor(game: Game, key: string, volume = 1, loop = false, connect: boolean | null = null) {
83
83
  // https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Migrating_from_webkitAudioContext
84
- connect ??= game.sound.connectToMaster;
84
+ const connectToMaster = connect ?? game.sound.connectToMaster;
85
85
  this.game = game;
86
86
  this.name = key;
87
87
  this.key = key;
@@ -116,7 +116,7 @@ export class Sound {
116
116
  : this.context!.createGain();
117
117
  this.gainNode = gainNode;
118
118
  gainNode.gain.value = volume * this.game.sound.volume;
119
- if (connect && this.masterGainNode) {
119
+ if (connectToMaster && this.masterGainNode !== null) {
120
120
  gainNode.connect(this.masterGainNode);
121
121
  }
122
122
  this.onPlay = new Signal();
@@ -193,7 +193,7 @@ export class Sound {
193
193
  }
194
194
  if (this.externalNode) {
195
195
  this._sound.disconnect(this.externalNode);
196
- } else if (this.gainNode) {
196
+ } else if (this.gainNode as GainNode | undefined) {
197
197
  this._sound.disconnect(this.gainNode);
198
198
  }
199
199
  if (this._removeFromSoundManager) {
@@ -270,16 +270,14 @@ export class Sound {
270
270
  * @returns {Sound} This Sound instance for chaining.
271
271
  */
272
272
  public play(marker: string | false | null = '', position = 0, volume = 1, loop = false, forceRestart = true): this {
273
- if (marker === undefined || marker === false || marker === null) {
274
- marker = '';
275
- }
276
- forceRestart ??= true;
273
+ const markerName = marker === undefined || marker === false || marker === null ? '' : marker;
277
274
 
278
275
  if (this.isPlaying && !this.allowMultiple && !forceRestart && !this.override) {
279
276
  // Use Restart instead
280
277
  return this;
281
278
  }
282
- if (this._sound && this.isPlaying && !this.allowMultiple && (this.override || forceRestart)) {
279
+ const source = this._sound as AudioBufferSourceNode | undefined;
280
+ if (source && this.isPlaying && !this.allowMultiple && (this.override || forceRestart)) {
283
281
  if (this._sound.stop === undefined) {
284
282
  (this._sound as unknown as LegacyBufferSource).noteOff(0);
285
283
  } else {
@@ -287,20 +285,20 @@ export class Sound {
287
285
  }
288
286
  if (this.externalNode) {
289
287
  this._sound.disconnect(this.externalNode);
290
- } else if (this.gainNode) {
288
+ } else if (this.gainNode as GainNode | undefined) {
291
289
  this._sound.disconnect(this.gainNode);
292
290
  }
293
291
  this.isPlaying = false;
294
292
  }
295
- if (marker === '' && Object.keys(this.markers).length > 0) {
293
+ if (markerName === '' && Object.keys(this.markers).length > 0) {
296
294
  // If they didn't specify a marker but this is an audio sprite,
297
295
  // We should never play the entire thing
298
296
  return this;
299
297
  }
300
- const markerData = marker === '' ? undefined : this.markers[marker];
301
- if (marker !== '') {
298
+ const markerData = markerName === '' ? undefined : this.markers[markerName];
299
+ if (markerName !== '') {
302
300
  if (markerData) {
303
- this.currentMarker = marker;
301
+ this.currentMarker = markerName;
304
302
  // Playing a marker? Then we default to the marker values
305
303
  this.position = markerData.start;
306
304
  this.volume = markerData.volume;
@@ -313,32 +311,27 @@ export class Sound {
313
311
  if (loop !== undefined) {
314
312
  this.loop = loop;
315
313
  }
316
- this._tempMarker = marker;
314
+ this._tempMarker = markerName;
317
315
  this._tempPosition = this.position;
318
316
  this._tempVolume = this.volume;
319
317
  this._tempLoop = this.loop;
320
318
  } else {
321
- this.game.logger.warn(`Sound.play: audio marker ${marker} does not exist`);
319
+ this.game.logger.warn(`Sound.play: audio marker ${markerName} does not exist`);
322
320
  return this;
323
321
  }
324
322
  } else {
325
- position ??= 0;
326
- volume ??= this._volume;
327
- if (loop === undefined) {
328
- ({ loop } = this);
329
- }
330
- this.position = Math.max(0, position);
331
- this.volume = volume;
332
- this.loop = loop;
323
+ this.position = Math.max(0, position ?? 0);
324
+ this.volume = volume ?? this._volume;
325
+ this.loop = loop ?? this.loop;
333
326
  this.duration = 0;
334
327
  this.durationMS = 0;
335
- this._tempMarker = marker;
328
+ this._tempMarker = markerName;
336
329
  this._tempPosition = position;
337
330
  this._tempVolume = volume;
338
331
  this._tempLoop = loop;
339
332
  }
340
333
  // Does the sound need decoding?
341
- if (this.game.cache.isSoundDecoded(this.key)) {
334
+ if (this.game.cache.isSoundDecoded(this.key) === true) {
342
335
  this._sound = this.context!.createBufferSource();
343
336
  if (this.externalNode) {
344
337
  this._sound.connect(this.externalNode);
@@ -347,10 +340,10 @@ export class Sound {
347
340
  }
348
341
  this._buffer = this.game.cache.getSoundData(this.key) as AudioBuffer | null;
349
342
  this._sound.buffer = this._buffer;
350
- if (this.loop && marker === '') {
343
+ if (this.loop && markerName === '') {
351
344
  this._sound.loop = true;
352
345
  }
353
- if (!this.loop && marker === '') {
346
+ if (!this.loop && markerName === '') {
354
347
  this._sound.addEventListener('ended', this.onEndedHandler, { once: true });
355
348
  }
356
349
  this.totalDuration = this._sound.buffer?.duration ?? 0;
@@ -361,7 +354,7 @@ export class Sound {
361
354
  // Useful to cache this somewhere perhaps?
362
355
  if (this._sound.start === undefined) {
363
356
  (this._sound as unknown as LegacyBufferSource).noteGrainOn(0, this.position, this.duration);
364
- } else if (this.loop && marker === '') {
357
+ } else if (this.loop && markerName === '') {
365
358
  this._sound.start(0, 0);
366
359
  } else {
367
360
  this._sound.start(0, this.position, this.duration);
@@ -395,7 +388,7 @@ export class Sound {
395
388
  * Pauses the sound.
396
389
  */
397
390
  public pause(): void {
398
- if (this.isPlaying && this._sound) {
391
+ if (this.isPlaying && (this._sound as AudioBufferSourceNode | undefined)) {
399
392
  this.paused = true;
400
393
  this.pausedPosition = this.currentTime;
401
394
  this.pausedTime = this.game.time.time;
@@ -409,7 +402,7 @@ export class Sound {
409
402
  * Resumes the sound.
410
403
  */
411
404
  public resume(): void {
412
- if (this.paused && this._sound) {
405
+ if (this.paused && (this._sound as AudioBufferSourceNode | undefined)) {
413
406
  const p = Math.max(0, this.position + this.pausedPosition / 1000);
414
407
  this._sound = this.context!.createBufferSource();
415
408
  this._sound.buffer = this._buffer;
@@ -441,7 +434,7 @@ export class Sound {
441
434
  * Stops the sound.
442
435
  */
443
436
  public stop(): void {
444
- if (this.isPlaying && this._sound) {
437
+ if (this.isPlaying && (this._sound as AudioBufferSourceNode | undefined)) {
445
438
  if (this._sound.stop === undefined) {
446
439
  (this._sound as unknown as LegacyBufferSource).noteOff(0);
447
440
  } else {
@@ -449,7 +442,7 @@ export class Sound {
449
442
  }
450
443
  if (this.externalNode) {
451
444
  this._sound.disconnect(this.externalNode);
452
- } else if (this.gainNode) {
445
+ } else if (this.gainNode as GainNode | undefined) {
453
446
  this._sound.disconnect(this.gainNode);
454
447
  }
455
448
  }
@@ -73,7 +73,7 @@ export class SoundManager {
73
73
  setAudioDisabledState();
74
74
  return;
75
75
  }
76
- if (globalThis.AudioContext) {
76
+ if (globalThis.AudioContext as typeof AudioContext | undefined) {
77
77
  try {
78
78
  this.game.logger.info('initAudioContext');
79
79
  this.context = new globalThis.AudioContext();
@@ -240,7 +240,7 @@ export class SoundManager {
240
240
  return;
241
241
  }
242
242
  for (const sound of this._sounds) {
243
- if (sound) {
243
+ if (sound !== null) {
244
244
  sound.stop();
245
245
  }
246
246
  }
@@ -254,7 +254,7 @@ export class SoundManager {
254
254
  return;
255
255
  }
256
256
  for (const sound of this._sounds) {
257
- if (sound) {
257
+ if (sound !== null) {
258
258
  sound.pause();
259
259
  }
260
260
  }
@@ -268,7 +268,7 @@ export class SoundManager {
268
268
  return;
269
269
  }
270
270
  for (const sound of this._sounds) {
271
- if (sound) {
271
+ if (sound !== null) {
272
272
  sound.resume();
273
273
  }
274
274
  }
@@ -317,7 +317,7 @@ export class SoundManager {
317
317
  this._watchList.reset();
318
318
  for (const file of candidates) {
319
319
  const key = file instanceof Sound ? file.key : file;
320
- if (!this.game.cache.isSoundDecoded(key)) {
320
+ if (this.game.cache.isSoundDecoded(key) !== true) {
321
321
  this._watchList.add(key);
322
322
  }
323
323
  }
@@ -344,8 +344,8 @@ export class SoundManager {
344
344
  }
345
345
  if (this._watching) {
346
346
  let key = this._watchList.first;
347
- while (key) {
348
- if (this.game.cache.isSoundDecoded(key)) {
347
+ while (key !== null) {
348
+ if (this.game.cache.isSoundDecoded(key) === true) {
349
349
  this._watchList.remove(key);
350
350
  }
351
351
  key = this._watchList.next;
@@ -469,7 +469,7 @@ export class SoundManager {
469
469
  public destroy(): void {
470
470
  this.stopAll();
471
471
  for (const sound of this._sounds) {
472
- if (sound) {
472
+ if (sound !== null) {
473
473
  sound.destroy();
474
474
  }
475
475
  }
@@ -519,15 +519,11 @@ export class SoundManager {
519
519
  * Sets the volume level of the sound manager.
520
520
  */
521
521
  public set volume(value: number) {
522
- if (value < 0) {
523
- value = 0;
524
- } else if (value > 1) {
525
- value = 1;
526
- }
527
- if (this._volume !== value) {
528
- this._volume = value;
522
+ const level = Math.min(1, Math.max(0, value));
523
+ if (this._volume !== level) {
524
+ this._volume = level;
529
525
  if (!this.noAudio) {
530
- this.masterGain.gain.value = value;
526
+ this.masterGain.gain.value = level;
531
527
  }
532
528
  }
533
529
  }
@@ -38,7 +38,7 @@ export class SoundSprite {
38
38
  sound.addMarker(markerKey, marker.start, marker.end - marker.start, undefined, marker.loop);
39
39
  this.sounds[markerKey] = sound;
40
40
  }
41
- if (this.config.autoplay) {
41
+ if (this.config.autoplay !== undefined) {
42
42
  this.autoplayKey = this.config.autoplay;
43
43
  this.play(this.autoplayKey);
44
44
  this.autoplay = this.sounds[this.autoplayKey]!;
@@ -37,11 +37,11 @@ export class Stage extends DisplayObject {
37
37
  color: 0,
38
38
  rgba: '#000000',
39
39
  };
40
- if (!game.config.transparent) {
40
+ if (game.config.transparent === false) {
41
41
  // transparent = 0,0,0,0 - otherwise r,g,b,1
42
42
  this._bgColor.a = 1;
43
43
  }
44
- if (game.config.backgroundColor && !this.game.config.transparent) {
44
+ if (game.config.backgroundColor !== 0 && this.game.config.transparent === false) {
45
45
  this.setBackgroundColor(game.config.backgroundColor);
46
46
  }
47
47
  }
@@ -51,7 +51,7 @@ export class Stage extends DisplayObject {
51
51
  * @param {number} color - The color to set as the background.
52
52
  */
53
53
  public setBackgroundColor(color: number): void {
54
- if (this.game.config.transparent) {
54
+ if (this.game.config.transparent !== false) {
55
55
  return;
56
56
  }
57
57
  valueToColor(color, this._bgColor);
@@ -215,7 +215,7 @@ export class Timer {
215
215
  this._i = this.events.length;
216
216
  while (this._i) {
217
217
  this._i -= 1;
218
- if (this.events[this._i]?.pendingDelete) {
218
+ if (this.events[this._i]?.pendingDelete === true) {
219
219
  this.events.splice(this._i, 1);
220
220
  }
221
221
  }
@@ -167,10 +167,7 @@ export class Tween {
167
167
  }
168
168
  this.manager.add(this);
169
169
  this.isRunning = true;
170
- if (index < 0 || index > this.timeline.length - 1) {
171
- index = 0;
172
- }
173
- this.current = index;
170
+ this.current = index < 0 || index > this.timeline.length - 1 ? 0 : index;
174
171
  this.timeline[this.current]!.start();
175
172
  return this;
176
173
  }
@@ -290,10 +287,7 @@ export class Tween {
290
287
  * @returns {Tween} This Tween object for chaining.
291
288
  */
292
289
  public easing(ease: string | EasingFunction, index: number): this {
293
- if (typeof ease === 'string' && this.manager.easeMap[ease]) {
294
- ease = this.manager.easeMap[ease]!;
295
- }
296
- return this.updateTweenData('easingFunction', ease, index);
290
+ return this.updateTweenData('easingFunction', this.resolveEasing(ease), index);
297
291
  }
298
292
 
299
293
  /**
@@ -407,7 +401,7 @@ export class Tween {
407
401
  * @returns {boolean} True if the tween should continue running, false if it's complete.
408
402
  */
409
403
  public update(time: number): boolean {
410
- if (this.pendingDelete || !this.target) {
404
+ if (this.pendingDelete || !(this.target as TweenTarget | undefined)) {
411
405
  return false;
412
406
  }
413
407
  if (this.isPaused) {
@@ -507,10 +501,11 @@ export class Tween {
507
501
  for (const tweenData of this.timeline) {
508
502
  tweenData.loadValues();
509
503
  }
504
+ const frames = [...data];
510
505
  for (const tweenData of this.timeline) {
511
- data = [...data, ...tweenData.generateData(frameRate)];
506
+ frames.push(...tweenData.generateData(frameRate));
512
507
  }
513
- return data;
508
+ return frames;
514
509
  }
515
510
 
516
511
  /**