@vpmedia/phaser 1.123.0 → 1.125.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 +635 -623
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts +3 -3
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +27 -2
- package/dist/phaser/core/animation_parser.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts +11 -11
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/callback.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts +125 -19
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +3 -2
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/frame_data.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +3 -2
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +5 -1
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +3 -3
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +8 -8
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +11 -2
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +14 -1
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts +1 -1
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +1 -1
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts +16 -6
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +1 -1
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +13 -5
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +9 -7
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +6 -5
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/masker.d.ts +1 -1
- package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts +2 -2
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +9 -8
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +5 -3
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +1 -1
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts +1 -1
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +6 -5
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts +3 -2
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +2 -16
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts +14 -8
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts +2 -3
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +11 -5
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +6 -4
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts +4 -4
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +2 -2
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/mask_manager.d.ts +3 -2
- package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +11 -8
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +8 -4
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +28 -3
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +6 -5
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +3 -3
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture_util.d.ts +2 -2
- package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/dist/phaser/display/webgl/util.d.ts +1 -1
- package/dist/phaser/display/webgl/util.d.ts.map +1 -1
- package/dist/phaser/geom/circle.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts +10 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/circle.d.ts +2 -1
- package/dist/phaser/geom/util/circle.d.ts.map +1 -1
- package/dist/phaser/geom/util/point.d.ts +1 -1
- package/dist/phaser/geom/util/point.d.ts.map +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/util/math.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/animation.ts +11 -11
- package/src/phaser/core/animation_manager.ts +12 -12
- package/src/phaser/core/animation_parser.ts +39 -37
- package/src/phaser/core/array_set.ts +28 -28
- package/src/phaser/core/cache.test.ts +33 -33
- package/src/phaser/core/cache.ts +7 -7
- package/src/phaser/core/callback.ts +1 -0
- package/src/phaser/core/callback_context.test.ts +8 -8
- package/src/phaser/core/device_util.ts +4 -4
- package/src/phaser/core/dom.ts +38 -24
- package/src/phaser/core/factory.ts +9 -2
- package/src/phaser/core/frame_data.test.ts +23 -23
- package/src/phaser/core/frame_data.ts +2 -5
- package/src/phaser/core/game.ts +12 -12
- package/src/phaser/core/input.ts +11 -10
- package/src/phaser/core/input_handler.test.ts +18 -18
- package/src/phaser/core/input_handler.ts +14 -14
- package/src/phaser/core/input_mouse.ts +13 -12
- package/src/phaser/core/input_pointer.test.ts +26 -26
- package/src/phaser/core/input_pointer.ts +4 -4
- package/src/phaser/core/input_touch.ts +8 -8
- package/src/phaser/core/loader.test.ts +26 -26
- package/src/phaser/core/loader.ts +63 -75
- package/src/phaser/core/loader_parser.test.ts +16 -16
- package/src/phaser/core/loader_parser.ts +16 -6
- package/src/phaser/core/raf.ts +1 -1
- package/src/phaser/core/registry.test.ts +6 -6
- package/src/phaser/core/scale_manager.ts +12 -11
- package/src/phaser/core/scene_manager.test.ts +30 -30
- package/src/phaser/core/scene_manager.ts +3 -3
- package/src/phaser/core/signal.test.ts +8 -8
- package/src/phaser/core/signal.ts +3 -3
- package/src/phaser/core/signal_dispatch.test.ts +30 -30
- package/src/phaser/core/sound.ts +45 -40
- package/src/phaser/core/sound_manager.ts +18 -22
- package/src/phaser/core/sound_sprite.ts +1 -1
- package/src/phaser/core/stage.ts +22 -12
- package/src/phaser/core/time.ts +1 -1
- package/src/phaser/core/timer.test.ts +47 -47
- package/src/phaser/core/timer.ts +2 -2
- package/src/phaser/core/tween.ts +34 -36
- package/src/phaser/core/tween_data.test.ts +119 -0
- package/src/phaser/core/tween_data.ts +54 -39
- package/src/phaser/core/tween_easing.test.ts +5 -5
- package/src/phaser/core/tween_manager.ts +2 -2
- package/src/phaser/display/bitmap_text.test.ts +30 -30
- package/src/phaser/display/bitmap_text.ts +3 -3
- package/src/phaser/display/button.ts +20 -18
- package/src/phaser/display/canvas/buffer.ts +2 -2
- package/src/phaser/display/canvas/graphics.ts +2 -2
- package/src/phaser/display/canvas/masker.ts +1 -1
- package/src/phaser/display/canvas/pool.test.ts +20 -20
- package/src/phaser/display/canvas/pool.ts +6 -6
- package/src/phaser/display/canvas/renderer.ts +18 -16
- package/src/phaser/display/canvas/tinter.ts +1 -1
- package/src/phaser/display/canvas/util.test.ts +25 -25
- package/src/phaser/display/canvas/util.ts +2 -2
- package/src/phaser/display/display_object.ts +16 -15
- package/src/phaser/display/graphics.test.ts +70 -20
- package/src/phaser/display/graphics.ts +46 -42
- package/src/phaser/display/group.ts +13 -12
- package/src/phaser/display/image.ts +35 -31
- package/src/phaser/display/sprite_util.ts +4 -3
- package/src/phaser/display/text.test.ts +28 -25
- package/src/phaser/display/text.ts +56 -62
- package/src/phaser/display/webgl/abstract_filter.ts +21 -11
- package/src/phaser/display/webgl/blend_manager.ts +4 -5
- package/src/phaser/display/webgl/earcut.test.ts +20 -20
- package/src/phaser/display/webgl/earcut.ts +46 -42
- package/src/phaser/display/webgl/fast_sprite_batch.ts +21 -16
- package/src/phaser/display/webgl/filter_manager.ts +7 -4
- package/src/phaser/display/webgl/filter_texture.ts +5 -5
- package/src/phaser/display/webgl/graphics.ts +3 -3
- package/src/phaser/display/webgl/mask_manager.ts +9 -14
- package/src/phaser/display/webgl/render_texture.ts +15 -14
- package/src/phaser/display/webgl/renderer.ts +10 -9
- package/src/phaser/display/webgl/shader/normal.ts +45 -35
- package/src/phaser/display/webgl/shader/shader.test.ts +24 -24
- package/src/phaser/display/webgl/shader_manager.test.ts +18 -18
- package/src/phaser/display/webgl/shader_manager.ts +1 -1
- package/src/phaser/display/webgl/sprite_batch.ts +10 -10
- package/src/phaser/display/webgl/stencil_manager.ts +4 -4
- package/src/phaser/display/webgl/texture.ts +2 -1
- package/src/phaser/display/webgl/texture_util.ts +2 -2
- package/src/phaser/display/webgl/util.ts +4 -4
- package/src/phaser/geom/circle.test.ts +38 -38
- package/src/phaser/geom/circle.ts +7 -7
- package/src/phaser/geom/ellipse.test.ts +12 -12
- package/src/phaser/geom/line.test.ts +15 -15
- package/src/phaser/geom/line.ts +5 -2
- package/src/phaser/geom/matrix.test.ts +31 -31
- package/src/phaser/geom/point.test.ts +31 -31
- package/src/phaser/geom/polygon.test.ts +27 -27
- package/src/phaser/geom/polygon.ts +2 -2
- package/src/phaser/geom/rectangle.test.ts +87 -87
- package/src/phaser/geom/rectangle.ts +12 -13
- package/src/phaser/geom/rounded_rectangle.test.ts +9 -9
- package/src/phaser/geom/util/circle.test.ts +5 -5
- package/src/phaser/geom/util/circle.ts +8 -11
- package/src/phaser/geom/util/ellipse.test.ts +2 -2
- package/src/phaser/geom/util/line.test.ts +2 -2
- package/src/phaser/geom/util/matrix.test.ts +4 -4
- package/src/phaser/geom/util/point.test.ts +2 -2
- package/src/phaser/geom/util/point.ts +6 -8
- package/src/phaser/geom/util/polygon.test.ts +2 -2
- package/src/phaser/geom/util/rectangle.test.ts +2 -2
- package/src/phaser/geom/util/rectangle.ts +1 -1
- package/src/phaser/geom/util/rounded_rectangle.test.ts +2 -2
- package/src/phaser/util/math.test.ts +41 -41
- package/src/phaser/util/math.ts +7 -5
|
@@ -138,7 +138,7 @@ export class InputHandler {
|
|
|
138
138
|
* @param {boolean} useHandCursor - TBD.
|
|
139
139
|
* @returns {DisplayObject} TBD.
|
|
140
140
|
*/
|
|
141
|
-
public start(priority = 0, useHandCursor = false) {
|
|
141
|
+
public start(priority = 0, useHandCursor = false): Image {
|
|
142
142
|
// Turning on
|
|
143
143
|
if (!this.enabled) {
|
|
144
144
|
// Register, etc
|
|
@@ -223,7 +223,7 @@ export class InputHandler {
|
|
|
223
223
|
* TBD.
|
|
224
224
|
*/
|
|
225
225
|
public destroy(): void {
|
|
226
|
-
if (this.sprite) {
|
|
226
|
+
if (this.sprite !== null) {
|
|
227
227
|
if (this._setHandCursor) {
|
|
228
228
|
this.game.canvas.style.cursor = 'default';
|
|
229
229
|
this._setHandCursor = false;
|
|
@@ -402,7 +402,7 @@ export class InputHandler {
|
|
|
402
402
|
if (
|
|
403
403
|
!pointer.isDown ||
|
|
404
404
|
!this.enabled ||
|
|
405
|
-
|
|
405
|
+
this.sprite === null ||
|
|
406
406
|
!this.sprite.parent ||
|
|
407
407
|
!this.sprite.visible ||
|
|
408
408
|
!this.sprite.parent.visible ||
|
|
@@ -430,7 +430,7 @@ export class InputHandler {
|
|
|
430
430
|
public checkPointerOver(pointer: Pointer, fastTest = false): boolean {
|
|
431
431
|
if (
|
|
432
432
|
!this.enabled ||
|
|
433
|
-
|
|
433
|
+
this.sprite === null ||
|
|
434
434
|
!this.sprite.parent ||
|
|
435
435
|
!this.sprite.visible ||
|
|
436
436
|
!this.sprite.parent.visible ||
|
|
@@ -511,7 +511,7 @@ export class InputHandler {
|
|
|
511
511
|
// Abort. We've been destroyed.
|
|
512
512
|
return false;
|
|
513
513
|
}
|
|
514
|
-
if (!this.enabled || !this.sprite.visible ||
|
|
514
|
+
if (!this.enabled || !this.sprite.visible || this.sprite.parent?.visible !== true) {
|
|
515
515
|
this._pointerOutHandler(pointer);
|
|
516
516
|
return false;
|
|
517
517
|
}
|
|
@@ -560,7 +560,7 @@ export class InputHandler {
|
|
|
560
560
|
this.game.canvas.style.cursor = 'pointer';
|
|
561
561
|
this._setHandCursor = true;
|
|
562
562
|
}
|
|
563
|
-
if (!silent && sendEvent && this.sprite
|
|
563
|
+
if (!silent && sendEvent && this.sprite !== null) {
|
|
564
564
|
this.sprite.events.onInputOver$dispatch(this.sprite, pointer);
|
|
565
565
|
}
|
|
566
566
|
if (this.sprite.parent && this.sprite.parent.type === GROUP) {
|
|
@@ -587,9 +587,9 @@ export class InputHandler {
|
|
|
587
587
|
this.game.canvas.style.cursor = 'default';
|
|
588
588
|
this._setHandCursor = false;
|
|
589
589
|
}
|
|
590
|
-
if (!silent && this.sprite
|
|
590
|
+
if (!silent && this.sprite !== null) {
|
|
591
591
|
this.sprite.events.onInputOut$dispatch(this.sprite, pointer);
|
|
592
|
-
if (this.sprite
|
|
592
|
+
if (this.sprite?.parent?.type === GROUP) {
|
|
593
593
|
(this.sprite.parent as Group).onChildInputOut.dispatch(this.sprite, pointer);
|
|
594
594
|
}
|
|
595
595
|
}
|
|
@@ -615,10 +615,10 @@ export class InputHandler {
|
|
|
615
615
|
this.downPoint.setTo(pointer.x, pointer.y);
|
|
616
616
|
// It's possible the onInputDown event creates a new Sprite that is on-top of this one, so we ought to force a Pointer update
|
|
617
617
|
pointer.dirty = true;
|
|
618
|
-
if (this.sprite
|
|
618
|
+
if (this.sprite !== null) {
|
|
619
619
|
this.sprite.events.onInputDown$dispatch(this.sprite, pointer);
|
|
620
620
|
// The event above might have destroyed this sprite.
|
|
621
|
-
if (this.sprite
|
|
621
|
+
if (this.sprite?.parent?.type === GROUP) {
|
|
622
622
|
(this.sprite.parent as Group).onChildInputDown.dispatch(this.sprite, pointer);
|
|
623
623
|
}
|
|
624
624
|
// The events might have destroyed this sprite.
|
|
@@ -650,7 +650,7 @@ export class InputHandler {
|
|
|
650
650
|
*/
|
|
651
651
|
public dragTimeElapsed(pointer: Pointer): void {
|
|
652
652
|
this._dragTimePass = true;
|
|
653
|
-
if (this._pendingDrag && this.sprite && this._dragDistancePass) {
|
|
653
|
+
if (this._pendingDrag && this.sprite !== null && this._dragDistancePass) {
|
|
654
654
|
this.startDrag(pointer);
|
|
655
655
|
}
|
|
656
656
|
}
|
|
@@ -673,14 +673,14 @@ export class InputHandler {
|
|
|
673
673
|
data.downDuration = data.timeUp - data.timeDown;
|
|
674
674
|
// Only release the InputUp signal if the pointer is still over this sprite
|
|
675
675
|
let isOver = this.checkPointerOver(pointer);
|
|
676
|
-
if (this.sprite
|
|
676
|
+
if (this.sprite !== null) {
|
|
677
677
|
if (
|
|
678
678
|
!this.dragStopBlocksInputUp ||
|
|
679
679
|
(this.dragStopBlocksInputUp && !(this.draggable && this.isDragged && this._draggedPointerID === pointer.id))
|
|
680
680
|
) {
|
|
681
681
|
this.sprite.events.onInputUp$dispatch(this.sprite, pointer, isOver);
|
|
682
682
|
}
|
|
683
|
-
if (this.sprite
|
|
683
|
+
if (this.sprite?.parent?.type === GROUP) {
|
|
684
684
|
(this.sprite.parent as Group).onChildInputUp.dispatch(this.sprite, pointer, isOver);
|
|
685
685
|
}
|
|
686
686
|
// The onInputUp event may have changed the sprite so that checkPointerOver is no longer true, so update it.
|
|
@@ -843,7 +843,7 @@ export class InputHandler {
|
|
|
843
843
|
* TBD.
|
|
844
844
|
*/
|
|
845
845
|
public disableDrag(): void {
|
|
846
|
-
if (this._pointerData) {
|
|
846
|
+
if (this._pointerData.length > 0) {
|
|
847
847
|
for (let i = 0; i < 10; i += 1) {
|
|
848
848
|
this.pointerData(i).isDragged = false;
|
|
849
849
|
}
|
|
@@ -2,6 +2,9 @@ import type { InputEvent } from './input_event.js';
|
|
|
2
2
|
import type { Input } from './input.js';
|
|
3
3
|
import type { Game } from './game.js';
|
|
4
4
|
|
|
5
|
+
/** The legacy wheel-event adapter Phaser 2 installed for old browsers; nothing sets it any more. */
|
|
6
|
+
export type WheelEventProxy = { bindEvent: (event: InputEvent) => InputEvent };
|
|
7
|
+
|
|
5
8
|
export class Mouse {
|
|
6
9
|
public game!: Game;
|
|
7
10
|
public input!: Input;
|
|
@@ -27,7 +30,7 @@ export class Mouse {
|
|
|
27
30
|
public _onMouseWheel: EventListener | null;
|
|
28
31
|
public _onMouseUpGlobal!: EventListener;
|
|
29
32
|
public _onMouseOutGlobal!: EventListener;
|
|
30
|
-
public _wheelEvent!:
|
|
33
|
+
public _wheelEvent!: WheelEventProxy | null;
|
|
31
34
|
/**
|
|
32
35
|
* TBD.
|
|
33
36
|
* @param {Game} game - TBD.
|
|
@@ -103,7 +106,7 @@ export class Mouse {
|
|
|
103
106
|
canvas.addEventListener('mouseover', this._onMouseOver, true);
|
|
104
107
|
canvas.addEventListener('mouseout', this._onMouseOut, true);
|
|
105
108
|
const { wheelEvent } = this.game.device;
|
|
106
|
-
if (wheelEvent) {
|
|
109
|
+
if (wheelEvent !== null) {
|
|
107
110
|
canvas.addEventListener(wheelEvent, this._onMouseWheel, true);
|
|
108
111
|
}
|
|
109
112
|
}
|
|
@@ -129,13 +132,13 @@ export class Mouse {
|
|
|
129
132
|
canvas.removeEventListener('mouseout', this._onMouseOut, true);
|
|
130
133
|
}
|
|
131
134
|
const { wheelEvent } = this.game.device;
|
|
132
|
-
if (wheelEvent && this._onMouseWheel) {
|
|
135
|
+
if (wheelEvent !== null && this._onMouseWheel) {
|
|
133
136
|
canvas.removeEventListener(wheelEvent, this._onMouseWheel, true);
|
|
134
137
|
}
|
|
135
|
-
if (this._onMouseUpGlobal) {
|
|
138
|
+
if (this._onMouseUpGlobal !== null) {
|
|
136
139
|
globalThis.removeEventListener('mouseup', this._onMouseUpGlobal, true);
|
|
137
140
|
}
|
|
138
|
-
if (this._onMouseOutGlobal) {
|
|
141
|
+
if (this._onMouseOutGlobal !== null) {
|
|
139
142
|
globalThis.removeEventListener('mouseout', this._onMouseOutGlobal, true);
|
|
140
143
|
}
|
|
141
144
|
}
|
|
@@ -262,15 +265,13 @@ export class Mouse {
|
|
|
262
265
|
* @param {WheelEvent} event - TBD.
|
|
263
266
|
*/
|
|
264
267
|
public onMouseWheel(event: InputEvent): void {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
this.event = event;
|
|
269
|
-
this.eventPreventDefault(event);
|
|
268
|
+
const wheelEvent = this._wheelEvent ? this._wheelEvent.bindEvent(event) : event;
|
|
269
|
+
this.event = wheelEvent;
|
|
270
|
+
this.eventPreventDefault(wheelEvent);
|
|
270
271
|
// reverse detail for firefox
|
|
271
|
-
this.wheelDelta = Math.max(-1, Math.min(1, -(
|
|
272
|
+
this.wheelDelta = Math.max(-1, Math.min(1, -(wheelEvent.deltaY ?? 0)));
|
|
272
273
|
if (this.mouseWheelCallback) {
|
|
273
|
-
this.mouseWheelCallback.call(this.callbackContext,
|
|
274
|
+
this.mouseWheelCallback.call(this.callbackContext, wheelEvent);
|
|
274
275
|
}
|
|
275
276
|
}
|
|
276
277
|
|
|
@@ -9,82 +9,82 @@ import { Pointer } from './input_pointer.js';
|
|
|
9
9
|
const createGame = (): Game =>
|
|
10
10
|
({
|
|
11
11
|
time: { time: 0 },
|
|
12
|
-
scale: { bounds: { contains: () => true }, offset: { x: 0, y: 0 } },
|
|
12
|
+
scale: { bounds: { contains: (): boolean => true }, offset: { x: 0, y: 0 } },
|
|
13
13
|
input: {
|
|
14
14
|
enabled: true,
|
|
15
15
|
multiInputOverride: 0,
|
|
16
16
|
moveCallbacks: [],
|
|
17
|
-
interactiveItems: { total: 0, callAll: () => undefined },
|
|
17
|
+
interactiveItems: { total: 0, callAll: (): undefined => undefined },
|
|
18
18
|
mouse: { locked: false },
|
|
19
19
|
scale: new Point(1, 1),
|
|
20
20
|
position: new Point(),
|
|
21
21
|
circle: new Circle(),
|
|
22
22
|
speed: new Point(),
|
|
23
23
|
activePointer: null,
|
|
24
|
-
onDown: { dispatch: () => undefined },
|
|
25
|
-
onUp: { dispatch: () => undefined },
|
|
26
|
-
onHold: { dispatch: () => undefined },
|
|
27
|
-
onTap: { dispatch: () => undefined },
|
|
24
|
+
onDown: { dispatch: (): undefined => undefined },
|
|
25
|
+
onUp: { dispatch: (): undefined => undefined },
|
|
26
|
+
onHold: { dispatch: (): undefined => undefined },
|
|
27
|
+
onTap: { dispatch: (): undefined => undefined },
|
|
28
28
|
x: 0,
|
|
29
29
|
y: 0,
|
|
30
|
-
resetSpeed: () => undefined,
|
|
30
|
+
resetSpeed: (): undefined => undefined,
|
|
31
31
|
},
|
|
32
32
|
}) as unknown as Game;
|
|
33
33
|
|
|
34
34
|
const createPointer = (id = 1): Pointer => new Pointer(createGame(), id, POINTER_CURSOR);
|
|
35
35
|
|
|
36
36
|
const event = (fields: Partial<InputEvent> = {}): InputEvent =>
|
|
37
|
-
({ type: 'pointerdown', target: null, preventDefault: () => undefined, ...fields }) as InputEvent;
|
|
37
|
+
({ type: 'pointerdown', target: null, preventDefault: (): undefined => undefined, ...fields }) as InputEvent;
|
|
38
38
|
|
|
39
|
-
describe('Pointer', () => {
|
|
40
|
-
describe('updateButtons', () => {
|
|
41
|
-
it('reads a down event as pressed', () => {
|
|
39
|
+
describe('Pointer', (): void => {
|
|
40
|
+
describe('updateButtons', (): void => {
|
|
41
|
+
it('reads a down event as pressed', (): void => {
|
|
42
42
|
const pointer = createPointer();
|
|
43
43
|
pointer.updateButtons(event({ type: 'pointerdown' }));
|
|
44
44
|
expect(pointer.isDown).toBe(true);
|
|
45
45
|
expect(pointer.isUp).toBe(false);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it('reads an up event as released', () => {
|
|
48
|
+
it('reads an up event as released', (): void => {
|
|
49
49
|
const pointer = createPointer();
|
|
50
50
|
pointer.updateButtons(event({ type: 'pointerup' }));
|
|
51
51
|
expect(pointer.isDown).toBe(false);
|
|
52
52
|
expect(pointer.isUp).toBe(true);
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
it('matches the suffix case insensitively, as the legacy events are capitalised', () => {
|
|
55
|
+
it('matches the suffix case insensitively, as the legacy events are capitalised', (): void => {
|
|
56
56
|
const pointer = createPointer();
|
|
57
57
|
pointer.updateButtons(event({ type: 'MSPointerDown' }));
|
|
58
58
|
expect(pointer.isDown).toBe(true);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
it('treats a move event as not pressed', () => {
|
|
61
|
+
it('treats a move event as not pressed', (): void => {
|
|
62
62
|
const pointer = createPointer();
|
|
63
63
|
pointer.updateButtons(event({ type: 'pointermove' }));
|
|
64
64
|
expect(pointer.isUp).toBe(true);
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
describe('start', () => {
|
|
69
|
-
it('records the identifier the event carries', () => {
|
|
68
|
+
describe('start', (): void => {
|
|
69
|
+
it('records the identifier the event carries', (): void => {
|
|
70
70
|
const pointer = createPointer();
|
|
71
71
|
pointer.start(event({ identifier: 7 }));
|
|
72
72
|
expect(pointer.identifier).toBe(7);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it('records a null identifier when the event has none', () => {
|
|
75
|
+
it('records a null identifier when the event has none', (): void => {
|
|
76
76
|
const pointer = createPointer();
|
|
77
77
|
pointer.start(event({}));
|
|
78
78
|
expect(pointer.identifier).toBeNull();
|
|
79
79
|
});
|
|
80
80
|
|
|
81
|
-
it('records the pointerId when the event carries one', () => {
|
|
81
|
+
it('records the pointerId when the event carries one', (): void => {
|
|
82
82
|
const pointer = createPointer();
|
|
83
83
|
pointer.start(event({ pointerId: 3 }));
|
|
84
84
|
expect(pointer.pointerId).toBe(3);
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
it('marks the pointer active and down', () => {
|
|
87
|
+
it('marks the pointer active and down', (): void => {
|
|
88
88
|
const pointer = createPointer();
|
|
89
89
|
pointer.start(event({ identifier: 1 }));
|
|
90
90
|
expect(pointer.active).toBe(true);
|
|
@@ -92,8 +92,8 @@ describe('Pointer', () => {
|
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
describe('move', () => {
|
|
96
|
-
it('copies the coordinate set off the event', () => {
|
|
95
|
+
describe('move', (): void => {
|
|
96
|
+
it('copies the coordinate set off the event', (): void => {
|
|
97
97
|
const pointer = createPointer();
|
|
98
98
|
pointer.start(event({ identifier: 1 }));
|
|
99
99
|
pointer.move(
|
|
@@ -115,7 +115,7 @@ describe('Pointer', () => {
|
|
|
115
115
|
expect(pointer.screenY).toBe(66);
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
it('falls back to zero for coordinates the event omits', () => {
|
|
118
|
+
it('falls back to zero for coordinates the event omits', (): void => {
|
|
119
119
|
const pointer = createPointer();
|
|
120
120
|
pointer.start(event({ identifier: 1 }));
|
|
121
121
|
pointer.move(event({ type: 'pointermove' }));
|
|
@@ -124,8 +124,8 @@ describe('Pointer', () => {
|
|
|
124
124
|
});
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
-
describe('stop', () => {
|
|
128
|
-
it('clears the identifiers it recorded', () => {
|
|
127
|
+
describe('stop', (): void => {
|
|
128
|
+
it('clears the identifiers it recorded', (): void => {
|
|
129
129
|
const pointer = createPointer();
|
|
130
130
|
pointer.start(event({ identifier: 5, pointerId: 5 }));
|
|
131
131
|
pointer.stop(event({ type: 'pointerup' }));
|
|
@@ -135,8 +135,8 @@ describe('Pointer', () => {
|
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
-
describe('reset', () => {
|
|
139
|
-
it('returns the pointer to its resting state', () => {
|
|
138
|
+
describe('reset', (): void => {
|
|
139
|
+
it('returns the pointer to its resting state', (): void => {
|
|
140
140
|
const pointer = createPointer();
|
|
141
141
|
pointer.start(event({ identifier: 5 }));
|
|
142
142
|
pointer.reset();
|
|
@@ -149,7 +149,7 @@ export class Pointer {
|
|
|
149
149
|
*/
|
|
150
150
|
public start(event: InputEvent): this {
|
|
151
151
|
const { input } = this.game;
|
|
152
|
-
if (event.pointerId) {
|
|
152
|
+
if (event.pointerId !== undefined) {
|
|
153
153
|
this.pointerId = event.pointerId;
|
|
154
154
|
}
|
|
155
155
|
this.identifier = event.identifier ?? null;
|
|
@@ -362,7 +362,7 @@ export class Pointer {
|
|
|
362
362
|
* @param {InputHandler} newTarget - TBD.
|
|
363
363
|
* @param {boolean} silent - TBD.
|
|
364
364
|
*/
|
|
365
|
-
public swapTarget(newTarget: InputHandler, silent = false): void {
|
|
365
|
+
public swapTarget(newTarget: InputHandler | null, silent = false): void {
|
|
366
366
|
// Now we know the top-most item (if any) we can process it
|
|
367
367
|
if (newTarget === null) {
|
|
368
368
|
// The pointer isn't currently over anything, check if we've got a lingering previous target
|
|
@@ -456,7 +456,7 @@ export class Pointer {
|
|
|
456
456
|
* @param {number} duration - TBD.
|
|
457
457
|
* @returns {boolean} TBD.
|
|
458
458
|
*/
|
|
459
|
-
public justPressed(duration
|
|
459
|
+
public justPressed(duration = 0): boolean {
|
|
460
460
|
const window = duration || this.game.input.justPressedRate;
|
|
461
461
|
return this.isDown && this.timeDown + window > this.game.time.time;
|
|
462
462
|
}
|
|
@@ -466,7 +466,7 @@ export class Pointer {
|
|
|
466
466
|
* @param {number} duration - TBD.
|
|
467
467
|
* @returns {boolean} TBD.
|
|
468
468
|
*/
|
|
469
|
-
public justReleased(duration
|
|
469
|
+
public justReleased(duration = 0): boolean {
|
|
470
470
|
const window = duration || this.game.input.justReleasedRate;
|
|
471
471
|
return this.isUp && this.timeUp + window > this.game.time.time;
|
|
472
472
|
}
|
|
@@ -2,15 +2,15 @@ import type { Game } from './game.js';
|
|
|
2
2
|
import type { InputEvent } from './input_event.js';
|
|
3
3
|
export class Touch {
|
|
4
4
|
public game!: Game;
|
|
5
|
-
public enabled!:
|
|
5
|
+
public enabled!: boolean;
|
|
6
6
|
public callbackContext!: unknown;
|
|
7
|
-
public touchStartCallback
|
|
8
|
-
public touchMoveCallback
|
|
9
|
-
public touchEndCallback
|
|
10
|
-
public touchEnterCallback
|
|
11
|
-
public touchLeaveCallback
|
|
12
|
-
public touchCancelCallback
|
|
13
|
-
public preventDefault!:
|
|
7
|
+
public touchStartCallback: EventListener | null;
|
|
8
|
+
public touchMoveCallback: EventListener | null;
|
|
9
|
+
public touchEndCallback: EventListener | null;
|
|
10
|
+
public touchEnterCallback: EventListener | null;
|
|
11
|
+
public touchLeaveCallback: EventListener | null;
|
|
12
|
+
public touchCancelCallback: EventListener | null;
|
|
13
|
+
public preventDefault!: boolean;
|
|
14
14
|
public event!: InputEvent | null;
|
|
15
15
|
public _onTouchStart: EventListener | null;
|
|
16
16
|
public _onTouchMove: EventListener | null;
|
|
@@ -4,7 +4,7 @@ import { Loader } from './loader.js';
|
|
|
4
4
|
|
|
5
5
|
const createGame = (formats: Record<string, boolean> = {}, noAudio = false): Game =>
|
|
6
6
|
({
|
|
7
|
-
logger: { warn: () => undefined, info: () => undefined, debug: () => undefined },
|
|
7
|
+
logger: { warn: (): undefined => undefined, info: (): undefined => undefined, debug: (): undefined => undefined },
|
|
8
8
|
config: { maxParallelDownloads: 4 },
|
|
9
9
|
cache: {},
|
|
10
10
|
sound: { noAudio },
|
|
@@ -14,35 +14,35 @@ const createGame = (formats: Record<string, boolean> = {}, noAudio = false): Gam
|
|
|
14
14
|
const createLoader = (formats: Record<string, boolean> = {}, noAudio = false): Loader =>
|
|
15
15
|
new Loader(createGame(formats, noAudio));
|
|
16
16
|
|
|
17
|
-
describe('Loader', () => {
|
|
18
|
-
describe('getAudioURL', () => {
|
|
19
|
-
it('returns null when the device has no audio', () => {
|
|
17
|
+
describe('Loader', (): void => {
|
|
18
|
+
describe('getAudioURL', (): void => {
|
|
19
|
+
it('returns null when the device has no audio', (): void => {
|
|
20
20
|
expect(createLoader({}, true).getAudioURL(['track.ogg'])).toBeNull();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
it('picks a plain url whose extension the device can play', () => {
|
|
23
|
+
it('picks a plain url whose extension the device can play', (): void => {
|
|
24
24
|
expect(createLoader({ ogg: true }).getAudioURL(['track.ogg'])).toBe('track.ogg');
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
it('skips an extension the device cannot play', () => {
|
|
27
|
+
it('skips an extension the device cannot play', (): void => {
|
|
28
28
|
expect(createLoader({ ogg: false, mp3: true }).getAudioURL(['track.ogg', 'track.mp3'])).toBe('track.mp3');
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
it('returns null when no candidate is playable', () => {
|
|
31
|
+
it('returns null when no candidate is playable', (): void => {
|
|
32
32
|
expect(createLoader({ ogg: false, mp3: false }).getAudioURL(['track.ogg', 'track.mp3'])).toBeNull();
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
it('accepts a bare string as a single candidate', () => {
|
|
35
|
+
it('accepts a bare string as a single candidate', (): void => {
|
|
36
36
|
expect(createLoader({ mp3: true }).getAudioURL('track.mp3')).toBe('track.mp3');
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
it('reads the format from a uri and type pair', () => {
|
|
39
|
+
it('reads the format from a uri and type pair', (): void => {
|
|
40
40
|
expect(createLoader({ ogg: true }).getAudioURL([{ uri: 'track-no-extension', type: 'ogg' }])).toBe(
|
|
41
41
|
'track-no-extension'
|
|
42
42
|
);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
it('skips a pair whose type the device cannot play', () => {
|
|
45
|
+
it('skips a pair whose type the device cannot play', (): void => {
|
|
46
46
|
const loader = createLoader({ ogg: false, mp3: true });
|
|
47
47
|
expect(
|
|
48
48
|
loader.getAudioURL([
|
|
@@ -52,55 +52,55 @@ describe('Loader', () => {
|
|
|
52
52
|
).toBe('b');
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
it('takes a blob url without checking the format', () => {
|
|
55
|
+
it('takes a blob url without checking the format', (): void => {
|
|
56
56
|
expect(createLoader().getAudioURL(['blob:https://example.test/abc'])).toBe('blob:https://example.test/abc');
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
it('takes a data uri without checking the format', () => {
|
|
59
|
+
it('takes a data uri without checking the format', (): void => {
|
|
60
60
|
expect(createLoader().getAudioURL(['data:audio/mp3;base64,AAAA'])).toBe('data:audio/mp3;base64,AAAA');
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
it('ignores a query string when reading the extension', () => {
|
|
63
|
+
it('ignores a query string when reading the extension', (): void => {
|
|
64
64
|
expect(createLoader({ mp3: true }).getAudioURL(['track.mp3?v=2'])).toBe('track.mp3?v=2');
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
it('returns null for an empty candidate list', () => {
|
|
67
|
+
it('returns null for an empty candidate list', (): void => {
|
|
68
68
|
expect(createLoader({ mp3: true }).getAudioURL([])).toBeNull();
|
|
69
69
|
});
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
describe('transformUrl', () => {
|
|
72
|
+
describe('transformUrl', (): void => {
|
|
73
73
|
const file = { path: 'assets/' } as Parameters<Loader['transformUrl']>[1];
|
|
74
74
|
|
|
75
|
-
it('returns false for a missing url', () => {
|
|
75
|
+
it('returns false for a missing url', (): void => {
|
|
76
76
|
expect(createLoader().transformUrl(null, file)).toBe(false);
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
it('returns false for an unresolved candidate list', () => {
|
|
79
|
+
it('returns false for an unresolved candidate list', (): void => {
|
|
80
80
|
expect(createLoader().transformUrl(['a.mp3'], file)).toBe(false);
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
it('passes an absolute url through', () => {
|
|
83
|
+
it('passes an absolute url through', (): void => {
|
|
84
84
|
expect(createLoader().transformUrl('https://example.test/a.png', file)).toBe('https://example.test/a.png');
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
it('passes a protocol relative url through', () => {
|
|
87
|
+
it('passes a protocol relative url through', (): void => {
|
|
88
88
|
expect(createLoader().transformUrl('//example.test/a.png', file)).toBe('//example.test/a.png');
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
it('passes a data uri through', () => {
|
|
91
|
+
it('passes a data uri through', (): void => {
|
|
92
92
|
expect(createLoader().transformUrl('data:image/png;base64,AAAA', file)).toBe('data:image/png;base64,AAAA');
|
|
93
93
|
});
|
|
94
94
|
|
|
95
|
-
it('prefixes a relative url with the base url and file path', () => {
|
|
95
|
+
it('prefixes a relative url with the base url and file path', (): void => {
|
|
96
96
|
const loader = createLoader();
|
|
97
97
|
loader.baseURL = 'https://cdn.test/';
|
|
98
98
|
expect(loader.transformUrl('a.png', file)).toBe('https://cdn.test/assets/a.png');
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
-
describe('addToFileList', () => {
|
|
103
|
-
it('records the core fields for a queued file', () => {
|
|
102
|
+
describe('addToFileList', (): void => {
|
|
103
|
+
it('records the core fields for a queued file', (): void => {
|
|
104
104
|
const loader = createLoader();
|
|
105
105
|
loader.image('logo', 'logo.png');
|
|
106
106
|
const asset = loader.getAsset('image', 'logo');
|
|
@@ -114,7 +114,7 @@ describe('Loader', () => {
|
|
|
114
114
|
});
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
-
it('folds the per-type extras onto the file', () => {
|
|
117
|
+
it('folds the per-type extras onto the file', (): void => {
|
|
118
118
|
const loader = createLoader();
|
|
119
119
|
loader.audio('theme', ['theme.mp3']);
|
|
120
120
|
expect(loader.getAsset('audio', 'theme')?.file).toMatchObject({
|
|
@@ -124,13 +124,13 @@ describe('Loader', () => {
|
|
|
124
124
|
});
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
-
it('skips a file with no key', () => {
|
|
127
|
+
it('skips a file with no key', (): void => {
|
|
128
128
|
const loader = createLoader();
|
|
129
129
|
loader.image('', 'logo.png');
|
|
130
130
|
expect(loader.getAsset('image', '')).toBeNull();
|
|
131
131
|
});
|
|
132
132
|
|
|
133
|
-
it('derives the url from the key and extension when none is given', () => {
|
|
133
|
+
it('derives the url from the key and extension when none is given', (): void => {
|
|
134
134
|
const loader = createLoader();
|
|
135
135
|
loader.image('logo');
|
|
136
136
|
expect(loader.getAsset('image', 'logo')?.file.url).toBe('logo.png');
|