@vpmedia/phaser 1.119.0 → 1.121.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +499 -607
- package/dist/index.js.map +1 -1
- 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 +1 -1
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/callback.d.ts +12 -0
- package/dist/phaser/core/callback.d.ts.map +1 -0
- package/dist/phaser/core/device.d.ts +1 -5
- package/dist/phaser/core/device.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +2 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts +3 -0
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +11 -9
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_event.d.ts +1 -1
- package/dist/phaser/core/input_event.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +3 -2
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +5 -4
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/scale_manager.d.ts +5 -4
- 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 +14 -7
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts +10 -10
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +3 -3
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +9 -3
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts +19 -7
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +5 -4
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/timer_event.d.ts +3 -2
- package/dist/phaser/core/timer_event.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +7 -6
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +2 -1
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_easing.d.ts +31 -31
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +2 -1
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/dist/phaser/display/canvas/util.d.ts +2 -2
- package/dist/phaser/display/canvas/util.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +8 -6
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +7 -3
- 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.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +5 -0
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.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.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/geom/polygon.d.ts +11 -5
- package/dist/phaser/geom/polygon.d.ts.map +1 -1
- package/dist/phaser/geom/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
- package/dist/phaser/util/math.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/phaser/core/animation.ts +1 -2
- package/src/phaser/core/animation_manager.ts +3 -11
- package/src/phaser/core/animation_parser.ts +2 -2
- package/src/phaser/core/array_set.ts +8 -10
- package/src/phaser/core/cache.ts +2 -2
- package/src/phaser/core/callback.ts +14 -0
- package/src/phaser/core/device.ts +24 -53
- package/src/phaser/core/device_util.ts +6 -6
- package/src/phaser/core/dom.ts +10 -7
- package/src/phaser/core/factory.ts +3 -2
- package/src/phaser/core/game.ts +4 -5
- package/src/phaser/core/input.ts +16 -12
- package/src/phaser/core/input_event.ts +1 -1
- package/src/phaser/core/input_handler.ts +21 -22
- package/src/phaser/core/input_mouse.ts +12 -17
- package/src/phaser/core/input_mspointer.ts +8 -11
- package/src/phaser/core/input_pointer.ts +22 -21
- package/src/phaser/core/input_touch.ts +16 -19
- package/src/phaser/core/loader.ts +75 -86
- package/src/phaser/core/loader_parser.ts +6 -6
- package/src/phaser/core/scale_manager.ts +34 -42
- package/src/phaser/core/scene_manager.ts +2 -1
- package/src/phaser/core/signal.ts +21 -13
- package/src/phaser/core/signal_binding.ts +20 -21
- package/src/phaser/core/sound.ts +9 -11
- package/src/phaser/core/sound_manager.ts +53 -47
- package/src/phaser/core/sound_sprite.ts +34 -21
- package/src/phaser/core/stage.ts +4 -4
- package/src/phaser/core/timer.ts +13 -30
- package/src/phaser/core/timer_event.ts +3 -2
- package/src/phaser/core/tween.ts +9 -8
- package/src/phaser/core/tween_data.ts +15 -41
- package/src/phaser/core/tween_easing.test.ts +35 -35
- package/src/phaser/core/tween_easing.ts +33 -33
- package/src/phaser/core/tween_manager.ts +77 -75
- package/src/phaser/display/bitmap_text.ts +7 -11
- package/src/phaser/display/button.ts +3 -2
- package/src/phaser/display/canvas/graphics.ts +7 -7
- package/src/phaser/display/canvas/pool.ts +5 -6
- package/src/phaser/display/canvas/renderer.ts +7 -4
- package/src/phaser/display/canvas/tinter.ts +9 -11
- package/src/phaser/display/canvas/util.test.ts +122 -0
- package/src/phaser/display/canvas/util.ts +34 -35
- package/src/phaser/display/display_object.ts +30 -43
- package/src/phaser/display/graphics.ts +30 -45
- package/src/phaser/display/group.ts +1 -1
- package/src/phaser/display/image.ts +9 -16
- package/src/phaser/display/sprite_util.ts +0 -1
- package/src/phaser/display/text.ts +27 -43
- package/src/phaser/display/webgl/base_texture.ts +3 -3
- package/src/phaser/display/webgl/earcut.ts +2 -3
- package/src/phaser/display/webgl/fast_sprite_batch.ts +1 -2
- package/src/phaser/display/webgl/filter_manager.ts +6 -18
- package/src/phaser/display/webgl/filter_texture.ts +3 -3
- package/src/phaser/display/webgl/graphics.ts +28 -38
- package/src/phaser/display/webgl/graphics_data.ts +0 -1
- package/src/phaser/display/webgl/render_texture.ts +4 -13
- package/src/phaser/display/webgl/renderer.ts +0 -1
- package/src/phaser/display/webgl/sprite_batch.ts +2 -9
- package/src/phaser/display/webgl/texture.ts +12 -15
- package/src/phaser/geom/point.ts +1 -1
- package/src/phaser/geom/polygon.test.ts +59 -0
- package/src/phaser/geom/polygon.ts +43 -45
- package/src/phaser/geom/rectangle.ts +3 -15
- package/src/phaser/geom/rounded_rectangle.ts +2 -4
- package/src/phaser/geom/util/point.ts +1 -1
- package/src/phaser/geom/util/rectangle.ts +2 -2
- package/src/phaser/util/math.ts +1 -5
|
@@ -118,15 +118,9 @@ export class AnimationManager {
|
|
|
118
118
|
): Animation {
|
|
119
119
|
const frames = frameList ?? [];
|
|
120
120
|
// If they didn't set the useNumericIndex then let's at least try and guess it
|
|
121
|
-
|
|
122
|
-
if (frames && typeof frames[0] === 'number') {
|
|
123
|
-
useNumericIndex = true;
|
|
124
|
-
} else {
|
|
125
|
-
useNumericIndex = false;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
121
|
+
const numericIndex = useNumericIndex ?? typeof frames[0] === 'number';
|
|
128
122
|
this._outputFrames = [];
|
|
129
|
-
this._frameData!.getFrameIndexes(frames,
|
|
123
|
+
this._frameData!.getFrameIndexes(frames, numericIndex, this._outputFrames);
|
|
130
124
|
this._anims[name] = new Animation(
|
|
131
125
|
this.game,
|
|
132
126
|
this.sprite,
|
|
@@ -150,8 +144,7 @@ export class AnimationManager {
|
|
|
150
144
|
* @returns {boolean} True if all frames are valid, false otherwise.
|
|
151
145
|
*/
|
|
152
146
|
public validateFrames(frames: string[] | number[], useNumericIndex = false): boolean {
|
|
153
|
-
for (
|
|
154
|
-
const frame = frames[i]!;
|
|
147
|
+
for (const frame of frames) {
|
|
155
148
|
if (useNumericIndex) {
|
|
156
149
|
if (Number(frame) > this._frameData!.total) {
|
|
157
150
|
return false;
|
|
@@ -254,7 +247,6 @@ export class AnimationManager {
|
|
|
254
247
|
* Refreshes the current frame texture (not implemented).
|
|
255
248
|
*/
|
|
256
249
|
public refreshFrame(): void {
|
|
257
|
-
// TODO
|
|
258
250
|
this.game.logger.warn('animation_manager.refreshFrame() is not implemented');
|
|
259
251
|
// this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
|
|
260
252
|
}
|
|
@@ -71,9 +71,9 @@ export const spriteSheet = (
|
|
|
71
71
|
* @param {object} json - TBD.
|
|
72
72
|
* @returns {FrameData} TBD.
|
|
73
73
|
*/
|
|
74
|
-
export const
|
|
74
|
+
export const jsonDataHash = (game: Game, json: any, _key?: any): FrameData | null => {
|
|
75
75
|
if (!json.frames) {
|
|
76
|
-
game.logger.warn('
|
|
76
|
+
game.logger.warn('jsonDataHash: Invalid Texture Atlas JSON given, missing frames object', json);
|
|
77
77
|
return null;
|
|
78
78
|
}
|
|
79
79
|
// Let's create some frames then
|
|
@@ -84,11 +84,9 @@ export class ArraySet {
|
|
|
84
84
|
* @param {object} value - TBD.
|
|
85
85
|
*/
|
|
86
86
|
public setAll(key: string, value: any): void {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (this.list[i]) {
|
|
91
|
-
this.list[i][key] = value;
|
|
87
|
+
for (const item of this.list) {
|
|
88
|
+
if (item) {
|
|
89
|
+
item[key] = value;
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
}
|
|
@@ -99,11 +97,11 @@ export class ArraySet {
|
|
|
99
97
|
* @param {...any} args - TBD.
|
|
100
98
|
*/
|
|
101
99
|
public callAll(key: string, ...args: unknown[]): void {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (
|
|
106
|
-
|
|
100
|
+
// walked backwards so a callback that removes its own entry does not skip the next one
|
|
101
|
+
for (let i = this.list.length - 1; i >= 0; i -= 1) {
|
|
102
|
+
const item = this.list[i];
|
|
103
|
+
if (item && item[key]) {
|
|
104
|
+
item[key](...args);
|
|
107
105
|
}
|
|
108
106
|
}
|
|
109
107
|
}
|
package/src/phaser/core/cache.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TextureSource } from '../display/webgl/base_texture.js';
|
|
2
2
|
import { BaseTexture } from '../display/webgl/base_texture.js';
|
|
3
3
|
import { Texture } from '../display/webgl/texture.js';
|
|
4
|
-
import {
|
|
4
|
+
import { jsonDataHash, spriteSheet } from './animation_parser.js';
|
|
5
5
|
import { Frame } from './frame.js';
|
|
6
6
|
import { FrameData } from './frame_data.js';
|
|
7
7
|
import { jsonBitmapFont, xmlBitmapFont } from './loader_parser.js';
|
|
@@ -215,7 +215,7 @@ export class Cache {
|
|
|
215
215
|
url,
|
|
216
216
|
data,
|
|
217
217
|
base: new BaseTexture(data),
|
|
218
|
-
frameData:
|
|
218
|
+
frameData: jsonDataHash(this.game, atlasData, key),
|
|
219
219
|
};
|
|
220
220
|
this._cache.image[key] = obj;
|
|
221
221
|
this._resolveURL(url, obj);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A callback the engine invokes with a receiver the caller chose. The rest parameter is `never[]`
|
|
3
|
+
* so a handler declared with concrete parameters is still assignable.
|
|
4
|
+
*/
|
|
5
|
+
export type Callback = (...args: never[]) => unknown;
|
|
6
|
+
|
|
7
|
+
/** The same callback once its concrete parameter types are behind us, ready to be applied. */
|
|
8
|
+
export type AppliedCallback = (...args: unknown[]) => unknown;
|
|
9
|
+
|
|
10
|
+
/** An easing curve: it maps a normalised time to a normalised progress. */
|
|
11
|
+
export type EasingFunction = (k: number) => number;
|
|
12
|
+
|
|
13
|
+
/** An interpolation curve: it reads a value out of a list of stops at a normalised position. */
|
|
14
|
+
export type InterpolationFunction = (v: number[], k: number) => number;
|
|
@@ -1,55 +1,26 @@
|
|
|
1
|
+
/** What the current device and browser can do, as probed at boot. */
|
|
1
2
|
export class Device {
|
|
2
|
-
public desktop
|
|
3
|
-
public iOS
|
|
4
|
-
public android
|
|
5
|
-
public chromeOS
|
|
6
|
-
public linux
|
|
7
|
-
public macOS
|
|
8
|
-
public windows
|
|
9
|
-
public windowsPhone
|
|
10
|
-
public canvas
|
|
11
|
-
public touch
|
|
12
|
-
public mspointer
|
|
13
|
-
public wheelEvent
|
|
14
|
-
public chrome
|
|
15
|
-
public firefox
|
|
16
|
-
public edge
|
|
17
|
-
public safari
|
|
18
|
-
public fullscreen
|
|
19
|
-
public requestFullscreen
|
|
20
|
-
public cancelFullscreen
|
|
21
|
-
public fullscreenKeyboard
|
|
22
|
-
public noAudioFormat
|
|
23
|
-
public supportedAudioFormats
|
|
24
|
-
public supportedImageFormats
|
|
25
|
-
/**
|
|
26
|
-
* Creates a new Device instance.
|
|
27
|
-
* This class provides information about the current device and browser capabilities.
|
|
28
|
-
*/
|
|
29
|
-
public constructor() {
|
|
30
|
-
this.macOS = false;
|
|
31
|
-
this.windows = false;
|
|
32
|
-
this.windowsPhone = false;
|
|
33
|
-
this.canvas = false;
|
|
34
|
-
this.touch = false;
|
|
35
|
-
this.mspointer = false;
|
|
36
|
-
this.wheelEvent = null;
|
|
37
|
-
this.chrome = false;
|
|
38
|
-
this.firefox = false;
|
|
39
|
-
this.edge = false;
|
|
40
|
-
this.safari = false;
|
|
41
|
-
this.fullscreen = false;
|
|
42
|
-
this.requestFullscreen = '';
|
|
43
|
-
this.cancelFullscreen = '';
|
|
44
|
-
this.fullscreenKeyboard = false;
|
|
45
|
-
this.noAudioFormat = false;
|
|
46
|
-
/**
|
|
47
|
-
* @type {{[key: string]: boolean}}
|
|
48
|
-
*/
|
|
49
|
-
this.supportedAudioFormats = {};
|
|
50
|
-
/**
|
|
51
|
-
* @type {{[key: string]: boolean}}
|
|
52
|
-
*/
|
|
53
|
-
this.supportedImageFormats = {};
|
|
54
|
-
}
|
|
3
|
+
public desktop = false;
|
|
4
|
+
public iOS = false;
|
|
5
|
+
public android = false;
|
|
6
|
+
public chromeOS = false;
|
|
7
|
+
public linux = false;
|
|
8
|
+
public macOS = false;
|
|
9
|
+
public windows = false;
|
|
10
|
+
public windowsPhone = false;
|
|
11
|
+
public canvas = false;
|
|
12
|
+
public touch = false;
|
|
13
|
+
public mspointer = false;
|
|
14
|
+
public wheelEvent: string | null = null;
|
|
15
|
+
public chrome = false;
|
|
16
|
+
public firefox = false;
|
|
17
|
+
public edge = false;
|
|
18
|
+
public safari = false;
|
|
19
|
+
public fullscreen = false;
|
|
20
|
+
public requestFullscreen = '';
|
|
21
|
+
public cancelFullscreen = '';
|
|
22
|
+
public fullscreenKeyboard = false;
|
|
23
|
+
public noAudioFormat = false;
|
|
24
|
+
public supportedAudioFormats: Record<string, boolean> = {};
|
|
25
|
+
public supportedImageFormats: Record<string, boolean> = {};
|
|
55
26
|
}
|
|
@@ -110,8 +110,8 @@ export const checkFullScreenSupport = (device: Device): void => {
|
|
|
110
110
|
break;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
//
|
|
114
|
-
if (globalThis.Element && Element.ALLOW_KEYBOARD_INPUT) {
|
|
113
|
+
// ALLOW_KEYBOARD_INPUT is a legacy webkit fullscreen flag, absent from lib.dom
|
|
114
|
+
if (globalThis.Element && (Element as unknown as { ALLOW_KEYBOARD_INPUT?: number }).ALLOW_KEYBOARD_INPUT) {
|
|
115
115
|
device.fullscreenKeyboard = true;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -213,9 +213,9 @@ export const checkImage = (device: Device): void => {
|
|
|
213
213
|
const avif = new Image();
|
|
214
214
|
avif.src =
|
|
215
215
|
'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=';
|
|
216
|
-
avif.
|
|
216
|
+
avif.addEventListener('load', (): void => {
|
|
217
217
|
device.supportedImageFormats['avif'] = true;
|
|
218
|
-
};
|
|
218
|
+
});
|
|
219
219
|
} catch (error) {
|
|
220
220
|
const typedError = error instanceof Error ? error : new Error(String(error));
|
|
221
221
|
logger.fatal('checkImage error with avif', { error: typedError });
|
|
@@ -223,9 +223,9 @@ export const checkImage = (device: Device): void => {
|
|
|
223
223
|
try {
|
|
224
224
|
const webp = new Image();
|
|
225
225
|
webp.src = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=';
|
|
226
|
-
webp.
|
|
226
|
+
webp.addEventListener('load', (): void => {
|
|
227
227
|
device.supportedImageFormats['webp'] = true;
|
|
228
|
-
};
|
|
228
|
+
});
|
|
229
229
|
} catch (error) {
|
|
230
230
|
const typedError = error instanceof Error ? error : new Error(String(error));
|
|
231
231
|
logger.fatal('checkImage error with webp', { error: typedError });
|
package/src/phaser/core/dom.ts
CHANGED
|
@@ -205,15 +205,15 @@ export class DOM {
|
|
|
205
205
|
* @returns {Point} The offset position of the element.
|
|
206
206
|
*/
|
|
207
207
|
public getOffset(element: HTMLCanvasElement, point: Point | null = null): Point {
|
|
208
|
-
|
|
208
|
+
const offset = point ?? new Point();
|
|
209
209
|
const box = element.getBoundingClientRect();
|
|
210
210
|
const scrollTop = this.scrollY;
|
|
211
211
|
const scrollLeft = this.scrollX;
|
|
212
212
|
const { clientTop } = document.documentElement;
|
|
213
213
|
const { clientLeft } = document.documentElement;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
return
|
|
214
|
+
offset.x = box.left + scrollLeft - clientLeft;
|
|
215
|
+
offset.y = box.top + scrollTop - clientTop;
|
|
216
|
+
return offset;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
/**
|
|
@@ -257,7 +257,7 @@ export class DOM {
|
|
|
257
257
|
*/
|
|
258
258
|
public getScreenOrientation(primaryFallback: string | null = null): OrientationType {
|
|
259
259
|
const { screen } = globalThis;
|
|
260
|
-
// @ts-expect-error
|
|
260
|
+
// @ts-expect-error the prefixed orientation properties predate the standard one and are absent from lib.dom
|
|
261
261
|
const orientation = screen.orientation || screen.mozOrientation || screen.msOrientation;
|
|
262
262
|
if (orientation && typeof orientation.type === 'string') {
|
|
263
263
|
// Screen Orientation API specification
|
|
@@ -272,9 +272,12 @@ export class DOM {
|
|
|
272
272
|
return screen.height > screen.width ? PORTRAIT : LANDSCAPE;
|
|
273
273
|
} else if (primaryFallback === 'viewport') {
|
|
274
274
|
return this.visualBounds.height > this.visualBounds.width ? PORTRAIT : LANDSCAPE;
|
|
275
|
-
}
|
|
275
|
+
}
|
|
276
|
+
// the legacy angle, kept behind its own fallback because the standard API does not report it
|
|
277
|
+
const { orientation: legacyOrientation } = globalThis as { orientation?: number };
|
|
278
|
+
if (primaryFallback === 'window.orientation' && typeof legacyOrientation === 'number') {
|
|
276
279
|
// This may change by device based on "natural" orientation.
|
|
277
|
-
return
|
|
280
|
+
return legacyOrientation === 0 || legacyOrientation === 180 ? PORTRAIT : LANDSCAPE;
|
|
278
281
|
} else if (globalThis.matchMedia) {
|
|
279
282
|
if (globalThis.matchMedia('(orientation: portrait)').matches) {
|
|
280
283
|
return PORTRAIT;
|
|
@@ -5,6 +5,7 @@ import { Group } from '../display/group.js';
|
|
|
5
5
|
import { Image } from '../display/image.js';
|
|
6
6
|
import { Text } from '../display/text.js';
|
|
7
7
|
import type { Game } from './game.js';
|
|
8
|
+
import type { SignalListener } from './signal.js';
|
|
8
9
|
|
|
9
10
|
export class GameObjectFactory {
|
|
10
11
|
public game!: Game;
|
|
@@ -73,8 +74,8 @@ export class GameObjectFactory {
|
|
|
73
74
|
x: number,
|
|
74
75
|
y: number,
|
|
75
76
|
key: string,
|
|
76
|
-
callback:
|
|
77
|
-
callbackContext: unknown
|
|
77
|
+
callback: SignalListener | null = null,
|
|
78
|
+
callbackContext: unknown = null,
|
|
78
79
|
overFrame: string | null = null,
|
|
79
80
|
outFrame: string | null = null,
|
|
80
81
|
downFrame: string | null = null,
|
package/src/phaser/core/game.ts
CHANGED
|
@@ -42,6 +42,9 @@ export type GameConfig = {
|
|
|
42
42
|
maxParallelDownloads: number;
|
|
43
43
|
canvas?: HTMLCanvasElement;
|
|
44
44
|
isSkipTicker?: boolean;
|
|
45
|
+
scaleMode?: number;
|
|
46
|
+
fullScreenScaleMode?: number;
|
|
47
|
+
fullScreenTarget?: HTMLElement;
|
|
45
48
|
parent?: string | HTMLElement;
|
|
46
49
|
state?: SceneDefinition | string;
|
|
47
50
|
logger?: Logger;
|
|
@@ -180,11 +183,7 @@ export class Game {
|
|
|
180
183
|
if (this.canvas) {
|
|
181
184
|
removeFromDOM(this.canvas);
|
|
182
185
|
}
|
|
183
|
-
|
|
184
|
-
this.canvas = this.config.canvas;
|
|
185
|
-
} else {
|
|
186
|
-
this.canvas = create(this, this.width, this.height, this.config.canvasID, true);
|
|
187
|
-
}
|
|
186
|
+
this.canvas = this.config.canvas ?? create(this, this.width, this.height, this.config.canvasID, true);
|
|
188
187
|
if (this.config.canvasStyle) {
|
|
189
188
|
const { canvasStyle } = this.config;
|
|
190
189
|
for (const property of Object.keys(canvasStyle)) {
|
package/src/phaser/core/input.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { Signal } from './signal.js';
|
|
|
13
13
|
import type { Game } from './game.js';
|
|
14
14
|
import type { DisplayObject } from '../display/display_object.js';
|
|
15
15
|
import type { InputEvent } from './input_event.js';
|
|
16
|
+
import type { Callback } from './callback.js';
|
|
16
17
|
|
|
17
18
|
const MAX_POINTERS = 10;
|
|
18
19
|
|
|
@@ -20,9 +21,9 @@ export class Input {
|
|
|
20
21
|
public game!: Game;
|
|
21
22
|
public hitCanvas!: HTMLCanvasElement;
|
|
22
23
|
public hitContext!: CanvasRenderingContext2D | null;
|
|
23
|
-
public moveCallbacks!: { callback:
|
|
24
|
+
public moveCallbacks!: { callback: Callback; context: unknown }[];
|
|
24
25
|
public lockCallbacks!: unknown[];
|
|
25
|
-
public customCandidateHandler!:
|
|
26
|
+
public customCandidateHandler!: Callback | null;
|
|
26
27
|
public customCandidateHandlerContext!: unknown;
|
|
27
28
|
public pollRate!: number;
|
|
28
29
|
public enabled!: boolean;
|
|
@@ -66,7 +67,7 @@ export class Input {
|
|
|
66
67
|
public _localPoint!: Point;
|
|
67
68
|
public _pollCounter!: number;
|
|
68
69
|
public _oldPosition!: Point;
|
|
69
|
-
public _onClickTrampoline!:
|
|
70
|
+
public _onClickTrampoline!: EventListener | null;
|
|
70
71
|
public _x!: number;
|
|
71
72
|
public _y!: number;
|
|
72
73
|
/**
|
|
@@ -154,8 +155,9 @@ export class Input {
|
|
|
154
155
|
this.touch.start();
|
|
155
156
|
}
|
|
156
157
|
this.mousePointer.active = true;
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
this._onClickTrampoline = (): void => {
|
|
159
|
+
this.onClickTrampoline();
|
|
160
|
+
};
|
|
159
161
|
this.game.canvas.addEventListener('click', this._onClickTrampoline, false);
|
|
160
162
|
}
|
|
161
163
|
|
|
@@ -171,7 +173,9 @@ export class Input {
|
|
|
171
173
|
}
|
|
172
174
|
this.moveCallbacks = [];
|
|
173
175
|
remove(this);
|
|
174
|
-
|
|
176
|
+
if (this._onClickTrampoline) {
|
|
177
|
+
this.game.canvas.removeEventListener('click', this._onClickTrampoline);
|
|
178
|
+
}
|
|
175
179
|
}
|
|
176
180
|
|
|
177
181
|
/**
|
|
@@ -179,7 +183,7 @@ export class Input {
|
|
|
179
183
|
* @param {Function} callback - TBD.
|
|
180
184
|
* @param {object} context - TBD.
|
|
181
185
|
*/
|
|
182
|
-
public setInteractiveCandidateHandler(callback:
|
|
186
|
+
public setInteractiveCandidateHandler(callback: Callback, context: unknown): void {
|
|
183
187
|
this.customCandidateHandler = callback;
|
|
184
188
|
this.customCandidateHandlerContext = context;
|
|
185
189
|
}
|
|
@@ -189,7 +193,7 @@ export class Input {
|
|
|
189
193
|
* @param {Function} callback - TBD.
|
|
190
194
|
* @param {object} context - TBD.
|
|
191
195
|
*/
|
|
192
|
-
public addMoveCallback(callback:
|
|
196
|
+
public addMoveCallback(callback: Callback, context: unknown): void {
|
|
193
197
|
this.moveCallbacks.push({ callback, context });
|
|
194
198
|
}
|
|
195
199
|
|
|
@@ -198,7 +202,7 @@ export class Input {
|
|
|
198
202
|
* @param {Function} callback - TBD.
|
|
199
203
|
* @param {object} context - TBD.
|
|
200
204
|
*/
|
|
201
|
-
public deleteMoveCallback(callback:
|
|
205
|
+
public deleteMoveCallback(callback: Callback, context: unknown): void {
|
|
202
206
|
let i = this.moveCallbacks.length;
|
|
203
207
|
while (i) {
|
|
204
208
|
i -= 1;
|
|
@@ -287,7 +291,7 @@ export class Input {
|
|
|
287
291
|
* @param {MouseEvent|TouchEvent|PointerEvent} event - TBD.
|
|
288
292
|
* @returns {Pointer} TBD.
|
|
289
293
|
*/
|
|
290
|
-
public startPointer(event:
|
|
294
|
+
public startPointer(event: InputEvent) {
|
|
291
295
|
if (this.maxPointers >= 0 && this.countActivePointers(this.maxPointers) >= this.maxPointers) {
|
|
292
296
|
return null;
|
|
293
297
|
}
|
|
@@ -311,7 +315,7 @@ export class Input {
|
|
|
311
315
|
* @param {MouseEvent|TouchEvent|PointerEvent} event - TBD.
|
|
312
316
|
* @returns {Pointer} TBD.
|
|
313
317
|
*/
|
|
314
|
-
public updatePointer(event:
|
|
318
|
+
public updatePointer(event: InputEvent) {
|
|
315
319
|
if (this.pointer1.active && this.pointer1.identifier === event.identifier) {
|
|
316
320
|
return this.pointer1.move(event);
|
|
317
321
|
}
|
|
@@ -332,7 +336,7 @@ export class Input {
|
|
|
332
336
|
* @param {MouseEvent|TouchEvent|PointerEvent} event - TBD.
|
|
333
337
|
* @returns {Pointer} TBD.
|
|
334
338
|
*/
|
|
335
|
-
public stopPointer(event:
|
|
339
|
+
public stopPointer(event: InputEvent) {
|
|
336
340
|
if (this.pointer1.active && this.pointer1.identifier === event.identifier) {
|
|
337
341
|
return this.pointer1.stop(event);
|
|
338
342
|
}
|
|
@@ -26,7 +26,7 @@ export type InputEvent = Event & {
|
|
|
26
26
|
mozMovementY?: number;
|
|
27
27
|
webkitMovementX?: number;
|
|
28
28
|
webkitMovementY?: number;
|
|
29
|
-
changedTouches?: ArrayLike<InputEvent>;
|
|
29
|
+
changedTouches?: ArrayLike<InputEvent> & Iterable<InputEvent>;
|
|
30
30
|
targetTouches?: ArrayLike<InputEvent>;
|
|
31
31
|
touches?: ArrayLike<InputEvent>;
|
|
32
32
|
buttons?: number;
|
|
@@ -459,39 +459,40 @@ export class InputHandler {
|
|
|
459
459
|
public checkPixel(x: number | null, y: number | null, pointer?: Pointer): boolean {
|
|
460
460
|
// Grab a pixel from our image into the hitCanvas and then test it
|
|
461
461
|
if (this.sprite.texture.baseTexture.source) {
|
|
462
|
-
|
|
462
|
+
let localX = x;
|
|
463
|
+
let localY = y;
|
|
464
|
+
if (localX === null || localY === null) {
|
|
463
465
|
// Use the pointer parameter
|
|
464
466
|
this.game.input.getLocalPosition(this.sprite, pointer!, this._tempPoint);
|
|
465
|
-
x = this._tempPoint
|
|
466
|
-
y = this._tempPoint.y;
|
|
467
|
+
({ x: localX, y: localY } = this._tempPoint);
|
|
467
468
|
}
|
|
468
469
|
if (this.sprite.anchor.x !== 0) {
|
|
469
|
-
|
|
470
|
+
localX -= -this.sprite.texture.frame.width * this.sprite.anchor.x;
|
|
470
471
|
}
|
|
471
472
|
if (this.sprite.anchor.y !== 0) {
|
|
472
|
-
|
|
473
|
+
localY -= -this.sprite.texture.frame.height * this.sprite.anchor.y;
|
|
473
474
|
}
|
|
474
|
-
|
|
475
|
-
|
|
475
|
+
localX += this.sprite.texture.frame.x;
|
|
476
|
+
localY += this.sprite.texture.frame.y;
|
|
476
477
|
if (this.sprite.texture.trim) {
|
|
477
|
-
|
|
478
|
-
|
|
478
|
+
localX -= this.sprite.texture.trim.x;
|
|
479
|
+
localY -= this.sprite.texture.trim.y;
|
|
479
480
|
// If the coordinates are outside the trim area we return false immediately, to save doing a draw call
|
|
480
481
|
if (
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
482
|
+
localX < this.sprite.texture.crop.x ||
|
|
483
|
+
localX > this.sprite.texture.crop.right ||
|
|
484
|
+
localY < this.sprite.texture.crop.y ||
|
|
485
|
+
localY > this.sprite.texture.crop.bottom
|
|
485
486
|
) {
|
|
486
|
-
this._dx =
|
|
487
|
-
this._dy =
|
|
487
|
+
this._dx = localX;
|
|
488
|
+
this._dy = localY;
|
|
488
489
|
return false;
|
|
489
490
|
}
|
|
490
491
|
}
|
|
491
|
-
this._dx =
|
|
492
|
-
this._dy =
|
|
492
|
+
this._dx = localX;
|
|
493
|
+
this._dy = localY;
|
|
493
494
|
this.game.input.hitContext!.clearRect(0, 0, 1, 1);
|
|
494
|
-
this.game.input.hitContext!.drawImage(this.sprite.texture.baseTexture.source,
|
|
495
|
+
this.game.input.hitContext!.drawImage(this.sprite.texture.baseTexture.source, localX, localY, 1, 1, 0, 0, 1, 1);
|
|
495
496
|
const rgb = this.game.input.hitContext!.getImageData(0, 0, 1, 1);
|
|
496
497
|
if (rgb.data[3]! >= this.pixelPerfectAlpha) {
|
|
497
498
|
return true;
|
|
@@ -649,10 +650,8 @@ export class InputHandler {
|
|
|
649
650
|
*/
|
|
650
651
|
public dragTimeElapsed(pointer: Pointer): void {
|
|
651
652
|
this._dragTimePass = true;
|
|
652
|
-
if (this._pendingDrag && this.sprite) {
|
|
653
|
-
|
|
654
|
-
this.startDrag(pointer);
|
|
655
|
-
}
|
|
653
|
+
if (this._pendingDrag && this.sprite && this._dragDistancePass) {
|
|
654
|
+
this.startDrag(pointer);
|
|
656
655
|
}
|
|
657
656
|
}
|
|
658
657
|
|
|
@@ -70,30 +70,29 @@ export class Mouse {
|
|
|
70
70
|
// Avoid setting multiple listeners
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
|
-
const scope = this;
|
|
74
73
|
this._onMouseDown = (event): void => {
|
|
75
|
-
|
|
74
|
+
this.onMouseDown(event);
|
|
76
75
|
};
|
|
77
76
|
this._onMouseMove = (event): void => {
|
|
78
|
-
|
|
77
|
+
this.onMouseMove(event);
|
|
79
78
|
};
|
|
80
79
|
this._onMouseUp = (event): void => {
|
|
81
|
-
|
|
80
|
+
this.onMouseUp(event);
|
|
82
81
|
};
|
|
83
82
|
this._onMouseUpGlobal = (event): void => {
|
|
84
|
-
|
|
83
|
+
this.onMouseUpGlobal(event);
|
|
85
84
|
};
|
|
86
85
|
this._onMouseOutGlobal = (event): void => {
|
|
87
|
-
|
|
86
|
+
this.onMouseOutGlobal(event);
|
|
88
87
|
};
|
|
89
88
|
this._onMouseOut = (event): void => {
|
|
90
|
-
|
|
89
|
+
this.onMouseOut(event);
|
|
91
90
|
};
|
|
92
91
|
this._onMouseOver = (event): void => {
|
|
93
|
-
|
|
92
|
+
this.onMouseOver(event);
|
|
94
93
|
};
|
|
95
94
|
this._onMouseWheel = (event): void => {
|
|
96
|
-
|
|
95
|
+
this.onMouseWheel(event);
|
|
97
96
|
};
|
|
98
97
|
const { canvas } = this.game;
|
|
99
98
|
canvas.addEventListener('mousedown', this._onMouseDown, true);
|
|
@@ -130,10 +129,8 @@ export class Mouse {
|
|
|
130
129
|
canvas.removeEventListener('mouseout', this._onMouseOut, true);
|
|
131
130
|
}
|
|
132
131
|
const { wheelEvent } = this.game.device;
|
|
133
|
-
if (wheelEvent) {
|
|
134
|
-
|
|
135
|
-
canvas.removeEventListener(wheelEvent, this._onMouseWheel, true);
|
|
136
|
-
}
|
|
132
|
+
if (wheelEvent && this._onMouseWheel) {
|
|
133
|
+
canvas.removeEventListener(wheelEvent, this._onMouseWheel, true);
|
|
137
134
|
}
|
|
138
135
|
if (this._onMouseUpGlobal) {
|
|
139
136
|
globalThis.removeEventListener('mouseup', this._onMouseUpGlobal, true);
|
|
@@ -282,10 +279,8 @@ export class Mouse {
|
|
|
282
279
|
* @param {MouseEvent} event - TBD.
|
|
283
280
|
*/
|
|
284
281
|
public eventPreventDefault(event: Event): void {
|
|
285
|
-
if (this.capture) {
|
|
286
|
-
|
|
287
|
-
event.preventDefault();
|
|
288
|
-
}
|
|
282
|
+
if (this.capture && (typeof event.cancelable !== 'boolean' || event.cancelable)) {
|
|
283
|
+
event.preventDefault();
|
|
289
284
|
}
|
|
290
285
|
}
|
|
291
286
|
}
|
|
@@ -48,24 +48,23 @@ export class MSPointer {
|
|
|
48
48
|
if (!this.game.device.mspointer || this._onMSPointerDown !== null) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
const scope = this;
|
|
52
51
|
this._onMSPointerDown = (event): void => {
|
|
53
|
-
|
|
52
|
+
this.onPointerDown(event);
|
|
54
53
|
};
|
|
55
54
|
this._onMSPointerMove = (event): void => {
|
|
56
|
-
|
|
55
|
+
this.onPointerMove(event);
|
|
57
56
|
};
|
|
58
57
|
this._onMSPointerUp = (event): void => {
|
|
59
|
-
|
|
58
|
+
this.onPointerUp(event);
|
|
60
59
|
};
|
|
61
60
|
this._onMSPointerUpGlobal = (event): void => {
|
|
62
|
-
|
|
61
|
+
this.onPointerUpGlobal(event);
|
|
63
62
|
};
|
|
64
63
|
this._onMSPointerOut = (event): void => {
|
|
65
|
-
|
|
64
|
+
this.onPointerOut(event);
|
|
66
65
|
};
|
|
67
66
|
this._onMSPointerOver = (event): void => {
|
|
68
|
-
|
|
67
|
+
this.onPointerOver(event);
|
|
69
68
|
};
|
|
70
69
|
const { canvas } = this.game;
|
|
71
70
|
canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false);
|
|
@@ -269,10 +268,8 @@ export class MSPointer {
|
|
|
269
268
|
* @param {Event} event - TBD.
|
|
270
269
|
*/
|
|
271
270
|
public eventPreventDefault(event: Event): void {
|
|
272
|
-
if (this.capture) {
|
|
273
|
-
|
|
274
|
-
event.preventDefault();
|
|
275
|
-
}
|
|
271
|
+
if (this.capture && (typeof event.cancelable !== 'boolean' || event.cancelable)) {
|
|
272
|
+
event.preventDefault();
|
|
276
273
|
}
|
|
277
274
|
}
|
|
278
275
|
}
|