@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
@@ -199,16 +199,16 @@ export class Text extends Image {
199
199
  tabs: source.tabs ?? 0,
200
200
  };
201
201
  const components = this.fontToComponents(resolved.font);
202
- if (resolved.fontStyle) {
202
+ if (resolved.fontStyle !== undefined && resolved.fontStyle !== '') {
203
203
  components.fontStyle = resolved.fontStyle;
204
204
  }
205
- if (resolved.fontVariant) {
205
+ if (resolved.fontVariant !== undefined && resolved.fontVariant !== '') {
206
206
  components.fontVariant = resolved.fontVariant;
207
207
  }
208
- if (resolved.fontWeight) {
208
+ if (resolved.fontWeight !== undefined && resolved.fontWeight !== '') {
209
209
  components.fontWeight = String(resolved.fontWeight);
210
210
  }
211
- if (resolved.fontSize) {
211
+ if (resolved.fontSize !== undefined && resolved.fontSize !== '') {
212
212
  const fontSize = typeof resolved.fontSize === 'number' ? `${resolved.fontSize}px` : resolved.fontSize;
213
213
  resolved.fontSize = fontSize;
214
214
  components.fontSize = fontSize;
@@ -302,7 +302,7 @@ export class Text extends Image {
302
302
  }
303
303
  this.canvas.height = height * this._res;
304
304
  this.context.scale(this._res, this._res);
305
- if (this.style.backgroundColor) {
305
+ if (this.style.backgroundColor !== null && this.style.backgroundColor !== '') {
306
306
  this.context.fillStyle = this.style.backgroundColor;
307
307
  this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
308
308
  }
@@ -384,16 +384,17 @@ export class Text extends Image {
384
384
  }
385
385
  }
386
386
  } else {
387
+ let cursor = x;
387
388
  for (const part of text) {
388
389
  const section = Math.ceil(this.context.measureText(part).width);
389
390
  // How far to the next tab?
390
- snap = snapToCeil(x, tabs);
391
+ snap = snapToCeil(cursor, tabs);
391
392
  if (fill) {
392
393
  this.context.fillText(part, snap, y);
393
394
  } else {
394
395
  this.context.strokeText(part, snap, y);
395
396
  }
396
- x = snap + section;
397
+ cursor = snap + section;
397
398
  }
398
399
  }
399
400
  }
@@ -441,24 +442,24 @@ export class Text extends Image {
441
442
  const components = this.fontToComponents(this.context.font);
442
443
  const charFontStyle = this.fontStyles[this._charCount];
443
444
  const charFontWeight = this.fontWeights[this._charCount];
444
- if (charFontStyle) {
445
+ if (charFontStyle !== undefined && charFontStyle !== null && charFontStyle !== '') {
445
446
  components.fontStyle = charFontStyle;
446
447
  }
447
- if (charFontWeight) {
448
+ if (charFontWeight !== undefined && charFontWeight !== null && charFontWeight !== '') {
448
449
  components.fontWeight = charFontWeight;
449
450
  }
450
451
  this.context.font = this.componentsToFont(components);
451
452
  }
452
453
  if (this.style.stroke && this.style.strokeThickness) {
453
454
  const charStrokeColor = this.strokeColors[this._charCount];
454
- if (charStrokeColor) {
455
+ if (charStrokeColor !== undefined && charStrokeColor !== null && charStrokeColor !== '') {
455
456
  this.context.strokeStyle = charStrokeColor;
456
457
  }
457
458
  this.updateShadow(this.style.shadowStroke ?? false);
458
459
  }
459
460
  if (this.style.fill) {
460
461
  const charFillColor = this.colors[this._charCount];
461
- if (charFillColor) {
462
+ if (charFillColor !== undefined && charFillColor !== null && charFillColor !== '') {
462
463
  this.context.fillStyle = charFillColor;
463
464
  }
464
465
  this.updateShadow(this.style.shadowFill ?? false);
@@ -476,36 +477,37 @@ export class Text extends Image {
476
477
  * @param {number} y - The y position to start updating from.
477
478
  */
478
479
  public updateLine(line: string, x: number, y: number): void {
480
+ let cursor = x;
479
481
  for (const letter of line) {
480
482
  if (this.fontWeights.length > 0 || this.fontStyles.length > 0) {
481
483
  const components = this.fontToComponents(this.context.font);
482
484
  const charFontStyle = this.fontStyles[this._charCount];
483
485
  const charFontWeight = this.fontWeights[this._charCount];
484
- if (charFontStyle) {
486
+ if (charFontStyle !== undefined && charFontStyle !== null && charFontStyle !== '') {
485
487
  components.fontStyle = charFontStyle;
486
488
  }
487
- if (charFontWeight) {
489
+ if (charFontWeight !== undefined && charFontWeight !== null && charFontWeight !== '') {
488
490
  components.fontWeight = charFontWeight;
489
491
  }
490
492
  this.context.font = this.componentsToFont(components);
491
493
  }
492
494
  if (this.style.stroke && this.style.strokeThickness) {
493
495
  const charStrokeColor = this.strokeColors[this._charCount];
494
- if (charStrokeColor) {
496
+ if (charStrokeColor !== undefined && charStrokeColor !== null && charStrokeColor !== '') {
495
497
  this.context.strokeStyle = charStrokeColor;
496
498
  }
497
499
  this.updateShadow(this.style.shadowStroke ?? false);
498
- this.context.strokeText(letter, x, y);
500
+ this.context.strokeText(letter, cursor, y);
499
501
  }
500
502
  if (this.style.fill) {
501
503
  const charFillColor = this.colors[this._charCount];
502
- if (charFillColor) {
504
+ if (charFillColor !== undefined && charFillColor !== null && charFillColor !== '') {
503
505
  this.context.fillStyle = charFillColor;
504
506
  }
505
507
  this.updateShadow(this.style.shadowFill ?? false);
506
- this.context.fillText(letter, x, y);
508
+ this.context.fillText(letter, cursor, y);
507
509
  }
508
- x += this.context.measureText(letter).width;
510
+ cursor += this.context.measureText(letter).width;
509
511
  this._charCount += 1;
510
512
  }
511
513
  }
@@ -778,31 +780,20 @@ export class Text extends Image {
778
780
  * @returns {string} The font string.
779
781
  */
780
782
  public componentsToFont(components: FontComponents): string {
781
- const parts = [];
782
- let v;
783
- v = components.fontStyle;
784
- if (v && v !== 'normal') {
785
- parts.push(v);
786
- }
787
- v = components.fontVariant;
788
- if (v && v !== 'normal') {
789
- parts.push(v);
790
- }
791
- v = components.fontWeight;
792
- if (v && v !== 'normal') {
793
- parts.push(v);
794
- }
795
- v = components.fontSize;
796
- if (v && v !== 'medium') {
797
- parts.push(v);
798
- }
799
- v = components.fontFamily;
800
- if (v) {
801
- parts.push(v);
802
- }
783
+ const parts: string[] = [];
784
+ const push = (value: string | number | undefined, skip: string): void => {
785
+ if (value !== undefined && value !== '' && value !== skip) {
786
+ parts.push(String(value));
787
+ }
788
+ };
789
+ push(components.fontStyle, 'normal');
790
+ push(components.fontVariant, 'normal');
791
+ push(components.fontWeight, 'normal');
792
+ push(components.fontSize, 'medium');
793
+ push(components.fontFamily, '');
803
794
  if (parts.length === 0) {
804
795
  // Fallback to whatever value the 'font' was
805
- parts.push(components.font);
796
+ parts.push(components.font ?? '');
806
797
  }
807
798
  return parts.join(' ');
808
799
  }
@@ -966,7 +957,7 @@ export class Text extends Image {
966
957
  * @returns {CanvasRenderingContext2D} The font properties canvas context.
967
958
  */
968
959
  public getFontPropertiesContext(): CanvasRenderingContext2D {
969
- if (!globalThis.PhaserRegistry.fontPropertiesContext) {
960
+ if (globalThis.PhaserRegistry.fontPropertiesContext === undefined) {
970
961
  const canvas = this.getFontPropertiesCanvas();
971
962
  const context = canvas.getContext('2d', { willReadFrequently: true });
972
963
  if (!context) {
@@ -1026,7 +1017,7 @@ export class Text extends Image {
1026
1017
  context.textBaseline = 'alphabetic';
1027
1018
  context.fillStyle = '#000';
1028
1019
  context.fillText('|MÉq', 0, baseline);
1029
- if (!context.getImageData(0, 0, width, height)) {
1020
+ if (context.getImageData(0, 0, width, height) === null) {
1030
1021
  const fallback: FontProperties = {
1031
1022
  ascent: baseline,
1032
1023
  descent: baseline + 6,
@@ -1169,7 +1160,7 @@ export class Text extends Image {
1169
1160
  if (typeof size === 'number') {
1170
1161
  return size;
1171
1162
  }
1172
- if (size && /(?:^0$|px$)/.exec(size)) {
1163
+ if (size !== undefined && size !== '' && /(?:^0$|px$)/.exec(size)) {
1173
1164
  // Number() cannot read the value here: the string carries a px suffix.
1174
1165
  // eslint-disable-next-line unicorn/prefer-number-coercion
1175
1166
  return Number.parseInt(size, 10);
@@ -27,7 +27,7 @@ export class AbstractFilter {
27
27
  this.dirty = true;
28
28
  this.padding = 0;
29
29
  this.uniforms = uniforms ?? {};
30
- this.fragmentSrc = fragmentSrc || [];
30
+ this.fragmentSrc = fragmentSrc;
31
31
  }
32
32
 
33
33
  /**
@@ -8,10 +8,11 @@ import { Node } from './earcut_node.js';
8
8
  export function sortLinked(list: Node | null): Node | null {
9
9
  let numMerges;
10
10
  let inSize = 1;
11
+ let sorted = list;
11
12
  do {
12
- let p: Node | null = list;
13
+ let p: Node | null = sorted;
13
14
  let tail: Node | null = null;
14
- list = null;
15
+ sorted = null;
15
16
  numMerges = 0;
16
17
  while (p) {
17
18
  numMerges += 1;
@@ -55,7 +56,7 @@ export function sortLinked(list: Node | null): Node | null {
55
56
  if (tail) {
56
57
  tail.nextZ = e;
57
58
  } else {
58
- list = e;
59
+ sorted = e;
59
60
  }
60
61
  e.prevZ = tail;
61
62
  tail = e;
@@ -67,7 +68,7 @@ export function sortLinked(list: Node | null): Node | null {
67
68
  }
68
69
  inSize *= 2;
69
70
  } while (numMerges > 1);
70
- return list;
71
+ return sorted;
71
72
  }
72
73
 
73
74
  /**
@@ -91,17 +92,17 @@ export function compareX(a: Node, b: Node): number {
91
92
  */
92
93
  export function zOrder(x: number, y: number, minX: number, minY: number, size: number): number {
93
94
  // coords are transformed into non-negative 15-bit integer range
94
- x = (32_767 * (x - minX)) / size;
95
- y = (32_767 * (y - minY)) / size;
96
- x = (x | (x << 8)) & 0x00ff00ff;
97
- x = (x | (x << 4)) & 0x0f0f0f0f;
98
- x = (x | (x << 2)) & 0x33333333;
99
- x = (x | (x << 1)) & 0x55555555;
100
- y = (y | (y << 8)) & 0x00ff00ff;
101
- y = (y | (y << 4)) & 0x0f0f0f0f;
102
- y = (y | (y << 2)) & 0x33333333;
103
- y = (y | (y << 1)) & 0x55555555;
104
- return x | (y << 1);
95
+ let ix = (32_767 * (x - minX)) / size;
96
+ let iy = (32_767 * (y - minY)) / size;
97
+ ix = (ix | (ix << 8)) & 0x00ff00ff;
98
+ ix = (ix | (ix << 4)) & 0x0f0f0f0f;
99
+ ix = (ix | (ix << 2)) & 0x33333333;
100
+ ix = (ix | (ix << 1)) & 0x55555555;
101
+ iy = (iy | (iy << 8)) & 0x00ff00ff;
102
+ iy = (iy | (iy << 4)) & 0x0f0f0f0f;
103
+ iy = (iy | (iy << 2)) & 0x33333333;
104
+ iy = (iy | (iy << 1)) & 0x55555555;
105
+ return ix | (iy << 1);
105
106
  }
106
107
 
107
108
  /**
@@ -446,7 +447,7 @@ export function filterPoints(start: Node | null, end?: Node | null): Node | null
446
447
  if (!start) {
447
448
  return start;
448
449
  }
449
- end ??= start;
450
+ let last = end ?? start;
450
451
  let p = start;
451
452
  let again;
452
453
  do {
@@ -454,7 +455,7 @@ export function filterPoints(start: Node | null, end?: Node | null): Node | null
454
455
  if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
455
456
  removeNode(p);
456
457
  p = p.prev;
457
- end = p;
458
+ last = p;
458
459
  if (p === p.next) {
459
460
  return null;
460
461
  }
@@ -462,8 +463,8 @@ export function filterPoints(start: Node | null, end?: Node | null): Node | null
462
463
  } else {
463
464
  p = p.next;
464
465
  }
465
- } while (again || p !== end);
466
- return end;
466
+ } while (again || p !== last);
467
+ return last;
467
468
  }
468
469
 
469
470
  /**
@@ -567,14 +568,15 @@ export function eliminateHoles(
567
568
  }
568
569
  queue.sort(compareX);
569
570
  // process holes from left to right
571
+ let outer = outerNode;
570
572
  for (i = 0; i < queue.length; i += 1) {
571
- if (!outerNode) {
572
- return outerNode;
573
+ if (!outer) {
574
+ return outer;
573
575
  }
574
- eliminateHole(queue[i]!, outerNode);
575
- outerNode = filterPoints(outerNode, outerNode.next);
576
+ eliminateHole(queue[i]!, outer);
577
+ outer = filterPoints(outer, outer.next);
576
578
  }
577
- return outerNode;
579
+ return outer;
578
580
  }
579
581
 
580
582
  /**
@@ -586,6 +588,7 @@ export function eliminateHoles(
586
588
  */
587
589
  export function cureLocalIntersections(start: Node, triangles: number[], dim: number): Node {
588
590
  let p = start;
591
+ let first = start;
589
592
  do {
590
593
  const a = p.prev;
591
594
  const b = p.next.next;
@@ -598,10 +601,10 @@ export function cureLocalIntersections(start: Node, triangles: number[], dim: nu
598
601
  removeNode(p);
599
602
  removeNode(p.next);
600
603
  p = b;
601
- start = p;
604
+ first = p;
602
605
  }
603
606
  p = p.next;
604
- } while (p !== start);
607
+ } while (p !== first);
605
608
  return p;
606
609
  }
607
610
 
@@ -659,40 +662,41 @@ export function earcutLinked(
659
662
  if (!ear) {
660
663
  return;
661
664
  }
665
+ let current = ear;
662
666
  // interlink polygon nodes in z-order
663
- if (!pass && size) {
664
- indexCurve(ear, minX, minY, size);
667
+ if (pass === undefined && size !== undefined) {
668
+ indexCurve(current, minX, minY, size);
665
669
  }
666
- let stop = ear;
670
+ let stop = current;
667
671
  let prev;
668
672
  let next;
669
673
  // iterate through ears, slicing them one by one
670
- while (ear.prev !== ear.next) {
671
- ({ prev, next } = ear);
672
- if (size ? isEarHashed(ear, minX, minY, size) : isEar(ear)) {
674
+ while (current.prev !== current.next) {
675
+ ({ prev, next } = current);
676
+ if (size === undefined ? isEar(current) : isEarHashed(current, minX, minY, size)) {
673
677
  // cut off the triangle
674
678
  triangles.push(prev.i / dim);
675
- triangles.push(ear.i / dim);
679
+ triangles.push(current.i / dim);
676
680
  triangles.push(next.i / dim);
677
- removeNode(ear);
681
+ removeNode(current);
678
682
  // skipping the next vertice leads to less sliver triangles
679
- ear = next.next;
683
+ current = next.next;
680
684
  stop = next.next;
681
685
  continue;
682
686
  }
683
- ear = next;
687
+ current = next;
684
688
  // if we looped through the whole remaining polygon and can't find any more ears
685
- if (ear === stop) {
689
+ if (current === stop) {
686
690
  // try filtering points and slicing again
687
- if (!pass) {
688
- earcutLinked(filterPoints(ear), triangles, dim, minX, minY, size, 1);
691
+ if (pass === undefined) {
692
+ earcutLinked(filterPoints(current), triangles, dim, minX, minY, size, 1);
689
693
  // if this didn't work, try curing all small self-intersections locally
690
694
  } else if (pass === 1) {
691
- ear = cureLocalIntersections(ear, triangles, dim);
692
- earcutLinked(ear, triangles, dim, minX, minY, size, 2);
695
+ current = cureLocalIntersections(current, triangles, dim);
696
+ earcutLinked(current, triangles, dim, minX, minY, size, 2);
693
697
  // as a last resort, try splitting the remaining polygon into two
694
698
  } else if (pass === 2) {
695
- splitEarcut(ear, triangles, dim, minX, minY, size);
699
+ splitEarcut(current, triangles, dim, minX, minY, size);
696
700
  }
697
701
  break;
698
702
  }
@@ -470,8 +470,8 @@ export const buildPoly = (graphicsData: DisplayGraphicsData, webGLData: Graphics
470
470
  const r = color[0] * alpha;
471
471
  const g = color[1] * alpha;
472
472
  const b = color[2] * alpha;
473
- const triangles = triangulate(points, null, 2);
474
- if (!triangles) {
473
+ const triangles: number[] | null = triangulate(points, null, 2);
474
+ if (!triangles?.length) {
475
475
  return false;
476
476
  }
477
477
  const vertPos = verts.length / 6;
@@ -75,7 +75,7 @@ export class WebGLRenderer {
75
75
  alpha: Boolean(game.config.transparent),
76
76
  depth: false,
77
77
  antialias: game.config.antialias,
78
- premultipliedAlpha: game.config.transparent && game.config.transparent !== 'notMultiplied',
78
+ premultipliedAlpha: game.config.transparent !== false && game.config.transparent !== 'notMultiplied',
79
79
  stencil: true,
80
80
  failIfMajorPerformanceCaveat: false,
81
81
  preserveDrawingBuffer: game.config.preserveDrawingBuffer,
@@ -111,7 +111,7 @@ export class WebGLRenderer {
111
111
  this.shaderManager.destroy();
112
112
  this.spriteBatch.destroy();
113
113
  this.filterManager.destroy();
114
- if (this.gl) {
114
+ if (this.gl as IdentifiedWebGLRenderingContext | undefined) {
115
115
  this.gl.canvas.width = 1;
116
116
  this.gl.canvas.height = 1;
117
117
  const loseContextExt = this.gl.getExtension('WEBGL_lose_context');
@@ -289,7 +289,7 @@ export class WebGLRenderer {
289
289
  * Maps blend modes to WebGL rendering operations.
290
290
  */
291
291
  public mapBlendModes(): void {
292
- if (globalThis.PhaserRegistry.blendModesWebGL) {
292
+ if (globalThis.PhaserRegistry.blendModesWebGL as number[][] | undefined) {
293
293
  return;
294
294
  }
295
295
  const { gl } = this;
@@ -197,7 +197,7 @@ export class NormalShader {
197
197
  */
198
198
  public initSampler2D(uniform: SamplerUniform): void {
199
199
  const texture = uniform.value;
200
- if (!texture?.baseTexture.hasLoaded) {
200
+ if (texture?.baseTexture.hasLoaded !== true) {
201
201
  return;
202
202
  }
203
203
  const { gl } = this;
@@ -218,13 +218,13 @@ export class NormalShader {
218
218
  const minFilter = data.minFilter ?? gl.LINEAR;
219
219
  let wrapS = data.wrapS ?? gl.CLAMP_TO_EDGE;
220
220
  let wrapT = data.wrapT ?? gl.CLAMP_TO_EDGE;
221
- const format = data.luminance ? gl.LUMINANCE : gl.RGBA;
222
- if (data.repeat) {
221
+ const format = data.luminance === true ? gl.LUMINANCE : gl.RGBA;
222
+ if (data.repeat === true) {
223
223
  wrapS = gl.REPEAT;
224
224
  wrapT = gl.REPEAT;
225
225
  }
226
226
  gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, Boolean(data.flipY));
227
- if (data.width) {
227
+ if (data.width !== undefined) {
228
228
  const width = data.width ?? 512;
229
229
  const height = data.height ?? 2;
230
230
  const border = data.border ?? 0;
@@ -268,10 +268,10 @@ export class NormalShader {
268
268
  } else if (uniform.glValueLength === 4) {
269
269
  callUniformSetter(uniform.glFunc, gl, uniform.uniformLocation, vector.x, vector.y, vector.z, vector.w);
270
270
  } else if (uniform.type === 'sampler2D') {
271
- if (uniform._init) {
271
+ if (uniform._init === true) {
272
272
  gl.activeTexture(glMember(gl, `TEXTURE${this.textureCount}`));
273
273
  const { baseTexture } = sampler.value!;
274
- if (baseTexture._dirty[gl.id]) {
274
+ if (baseTexture._dirty[gl.id] === true) {
275
275
  globalThis.PhaserRegistry.INSTANCES[gl.id]?.updateTexture(baseTexture);
276
276
  } else {
277
277
  // bind the current texture
@@ -71,7 +71,7 @@ export class WebGLShaderManager {
71
71
  for (i = 0; i < this.attribState.length; i += 1) {
72
72
  if (this.attribState[i] !== this.tempAttribState[i]) {
73
73
  this.attribState[i] = this.tempAttribState[i];
74
- if (this.tempAttribState[i]) {
74
+ if (this.tempAttribState[i] === true) {
75
75
  gl.enableVertexAttribArray(i);
76
76
  } else {
77
77
  gl.disableVertexAttribArray(i);
@@ -266,7 +266,7 @@ export class WebGLSpriteBatch {
266
266
  nextBlendMode = sprite.blendMode;
267
267
  nextShader = sprite.shader ?? this.defaultShader;
268
268
  blendSwap = currentBlendMode !== nextBlendMode;
269
- shaderSwap = !currentShader || !nextShader || currentShader._UID !== nextShader._UID;
269
+ shaderSwap = currentShader === null || currentShader._UID !== nextShader._UID;
270
270
  let skip = nextTexture.skipRender;
271
271
  if (skip && sprite.children.length > 0) {
272
272
  skip = false;
@@ -323,7 +323,7 @@ export class WebGLSpriteBatch {
323
323
  }
324
324
  const { gl } = this;
325
325
  // check if a texture is dirty..
326
- if (texture._dirty[gl.id]) {
326
+ if (texture._dirty[gl.id] === true) {
327
327
  if (!this.renderSession.renderer.updateTexture(texture)) {
328
328
  // If updateTexture returns false then we cannot render it, so bail out now
329
329
  return;
@@ -121,7 +121,8 @@ export class Texture {
121
121
  this.valid = false;
122
122
  return;
123
123
  }
124
- this.valid = Boolean(frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded);
124
+ this.valid =
125
+ frame.width !== 0 && frame.height !== 0 && this.baseTexture.source !== null && this.baseTexture.hasLoaded;
125
126
  if (this.trim) {
126
127
  this.width = this.trim.width;
127
128
  this.height = this.trim.height;
@@ -82,7 +82,7 @@ export const compileShader = (
82
82
  }
83
83
  gl.shaderSource(shader, src);
84
84
  gl.compileShader(shader);
85
- if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
85
+ if (gl.getShaderParameter(shader, gl.COMPILE_STATUS) !== true) {
86
86
  getRegistry();
87
87
  globalThis.PhaserRegistry.GL_SHADER_INFO_LOG = gl.getShaderInfoLog(shader);
88
88
  return null;
@@ -125,14 +125,14 @@ export const compileProgram = (
125
125
 
126
126
  const shaderProgram = gl.createProgram();
127
127
 
128
- if (!shaderProgram || !vertexShader || !fragmentShader) {
128
+ if (shaderProgram === null || vertexShader === null || fragmentShader === null) {
129
129
  return null;
130
130
  }
131
131
  gl.attachShader(shaderProgram, vertexShader);
132
132
  gl.attachShader(shaderProgram, fragmentShader);
133
133
  gl.linkProgram(shaderProgram);
134
134
 
135
- if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
135
+ if (gl.getProgramParameter(shaderProgram, gl.LINK_STATUS) !== true) {
136
136
  getRegistry();
137
137
  globalThis.PhaserRegistry.GL_PROGRAM_INFO_LOG = gl.getProgramInfoLog(shaderProgram);
138
138
  }
@@ -27,7 +27,7 @@ export class Polygon {
27
27
  this.flattened = false;
28
28
  /** @type {number} */
29
29
  this.type = GEOM_POLYGON;
30
- if (points) {
30
+ if (points !== null) {
31
31
  this.setTo(points);
32
32
  }
33
33
  }
@@ -111,7 +111,7 @@ export class Polygon {
111
111
  this.area = 0;
112
112
  const vertices: Point[] = [];
113
113
  this._points = vertices;
114
- if (points) {
114
+ if (points.length > 0) {
115
115
  // If points isn't an array, use arguments as the array
116
116
  if (!Array.isArray(points)) {
117
117
  console.error('[Polygon] setTo() error, input parameter is not an array', points);
@@ -95,9 +95,8 @@ export class Rectangle {
95
95
  * @returns {Rectangle} This rectangle instance for chaining.
96
96
  */
97
97
  public scale(x: number, y?: number): this {
98
- y ??= x;
99
98
  this.width *= x;
100
- this.height *= y;
99
+ this.height *= y ?? x;
101
100
  return this;
102
101
  }
103
102
 
@@ -59,11 +59,9 @@ export const intersects = (a: Circle, b: Circle): boolean => distance(a.x, a.y,
59
59
  */
60
60
  export const circumferencePoint = (a: Circle, angle: number, asDegrees = false, output: Point | null = null): Point => {
61
61
  const result = output ?? new Point();
62
- if (asDegrees) {
63
- angle = degToRad(angle);
64
- }
65
- result.x = a.x + a.radius * Math.cos(angle);
66
- result.y = a.y + a.radius * Math.sin(angle);
62
+ const radians = asDegrees ? degToRad(angle) : angle;
63
+ result.x = a.x + a.radius * Math.cos(radians);
64
+ result.y = a.y + a.radius * Math.sin(radians);
67
65
  return result;
68
66
  };
69
67
 
@@ -77,11 +75,9 @@ export const circumferencePoint = (a: Circle, angle: number, asDegrees = false,
77
75
  */
78
76
  export const intersectsPoint = (a: Circle, angle: number, asDegrees = false, output: Point | null = null): Point => {
79
77
  const result = output ?? new Point();
80
- if (asDegrees) {
81
- angle = degToRad(angle);
82
- }
83
- result.x = a.x + a.radius * Math.cos(angle);
84
- result.y = a.y + a.radius * Math.sin(angle);
78
+ const radians = asDegrees ? degToRad(angle) : angle;
79
+ result.x = a.x + a.radius * Math.cos(radians);
80
+ result.y = a.y + a.radius * Math.sin(radians);
85
81
  return result;
86
82
  };
87
83
 
@@ -221,13 +221,11 @@ export const rotate = (
221
221
  asDegrees: boolean,
222
222
  dist: number | null | undefined
223
223
  ): Point => {
224
- if (asDegrees) {
225
- ang *= Math.PI / 180;
226
- }
224
+ const radians = asDegrees ? ang * (Math.PI / 180) : ang;
227
225
  if (dist === undefined || dist === null) {
228
226
  a.subtract(x, y);
229
- const s = Math.sin(ang);
230
- const c = Math.cos(ang);
227
+ const s = Math.sin(radians);
228
+ const c = Math.cos(radians);
231
229
  const tx = c * a.x - s * a.y;
232
230
  const ty = s * a.x + c * a.y;
233
231
  a.x = tx + x;
@@ -273,10 +271,10 @@ export const centroid = (points: Point[], output: Point | null = null): Point =>
273
271
  */
274
272
  export const parse = (obj: Record<string, unknown>, xProp = 'x', yProp = 'y'): Point => {
275
273
  const point = new Point();
276
- if (obj[xProp]) {
274
+ if (obj[xProp] !== undefined) {
277
275
  point.x = Math.trunc(Number(obj[xProp]));
278
276
  }
279
- if (obj[yProp]) {
277
+ if (obj[yProp] !== undefined) {
280
278
  point.y = Math.trunc(Number(obj[yProp]));
281
279
  }
282
280
  return point;
@@ -63,9 +63,8 @@ export const snapToCeil = (input: number, gap = 0, start = 0): number => {
63
63
  if (gap === 0) {
64
64
  return input;
65
65
  }
66
- input -= start;
67
- input = gap * Math.ceil(input / gap);
68
- return start + input;
66
+ const offset = gap * Math.ceil((input - start) / gap);
67
+ return start + offset;
69
68
  };
70
69
 
71
70
  /** Wraps a value within a range. */