@vpmedia/phaser 1.112.0 → 1.114.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 +1261 -1314
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts +14 -10
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts +10 -8
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +5 -4
- package/dist/phaser/core/animation_parser.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts +4 -3
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/const.d.ts.map +1 -1
- package/dist/phaser/core/device.d.ts.map +1 -1
- package/dist/phaser/core/device_util.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts +3 -2
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/event_manager.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/frame.d.ts.map +1 -1
- package/dist/phaser/core/frame_data.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +8 -6
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts +40 -30
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +3 -2
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts +3 -2
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +6 -4
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +3 -2
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +4 -3
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +9 -8
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts +3 -2
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/registry.d.ts +7 -0
- package/dist/phaser/core/registry.d.ts.map +1 -0
- package/dist/phaser/core/scale_manager.d.ts +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene.d.ts +0 -1
- package/dist/phaser/core/scene.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts +0 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts +4 -3
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +6 -4
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +3 -2
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts +5 -4
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts +3 -2
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts +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/timer_event.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +10 -7
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +3 -2
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_easing.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts +3 -2
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/core/world.d.ts +3 -2
- package/dist/phaser/core/world.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts +3 -2
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +3 -2
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/graphics.d.ts +7 -6
- package/dist/phaser/display/canvas/graphics.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 +10 -8
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/tinter.d.ts +3 -2
- 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 +14 -12
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +8 -5
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts +4 -3
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +13 -10
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_batch.d.ts +3 -2
- package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts +18 -15
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +12 -10
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts +0 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +4 -3
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +7 -6
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts +2 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +4 -2
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +16 -11
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/complex.d.ts +16 -6
- package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/fast.d.ts +19 -7
- package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +33 -12
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/primitive.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/strip.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts +16 -11
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +29 -20
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +12 -10
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +3 -2
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/dist/phaser/display/webgl/util.d.ts.map +1 -1
- package/dist/phaser/geom/circle.d.ts +4 -1
- package/dist/phaser/geom/circle.d.ts.map +1 -1
- package/dist/phaser/geom/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts +1 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/matrix.d.ts.map +1 -1
- package/dist/phaser/geom/point.d.ts.map +1 -1
- 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/geom/util/circle.d.ts.map +1 -1
- package/dist/phaser/geom/util/ellipse.d.ts +3 -2
- package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/util/line.d.ts.map +1 -1
- package/dist/phaser/geom/util/matrix.d.ts +2 -2
- package/dist/phaser/geom/util/matrix.d.ts.map +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 +5 -5
- package/src/phaser/core/animation.ts +64 -60
- package/src/phaser/core/animation_manager.ts +50 -53
- package/src/phaser/core/animation_parser.ts +9 -9
- package/src/phaser/core/array_set.ts +16 -17
- package/src/phaser/core/cache.ts +92 -93
- package/src/phaser/core/const.ts +1 -1
- package/src/phaser/core/device.ts +24 -29
- package/src/phaser/core/device_util.ts +22 -26
- package/src/phaser/core/dom.ts +54 -65
- package/src/phaser/core/event_manager.ts +64 -94
- package/src/phaser/core/factory.ts +14 -14
- package/src/phaser/core/frame.ts +28 -28
- package/src/phaser/core/frame_data.test.ts +100 -0
- package/src/phaser/core/frame_data.ts +24 -24
- package/src/phaser/core/frame_util.ts +2 -2
- package/src/phaser/core/game.ts +47 -48
- package/src/phaser/core/input.ts +104 -110
- package/src/phaser/core/input_handler.test.ts +113 -0
- package/src/phaser/core/input_handler.ts +199 -218
- package/src/phaser/core/input_mouse.ts +71 -54
- package/src/phaser/core/input_mspointer.ts +52 -39
- package/src/phaser/core/input_pointer.ts +81 -80
- package/src/phaser/core/input_touch.ts +49 -36
- package/src/phaser/core/loader.ts +173 -152
- package/src/phaser/core/loader_parser.ts +39 -57
- package/src/phaser/core/raf.ts +8 -7
- package/src/phaser/core/registry.test.ts +31 -0
- package/src/phaser/core/registry.ts +9 -0
- package/src/phaser/core/scale_manager.ts +156 -152
- package/src/phaser/core/scene.ts +9 -13
- package/src/phaser/core/scene_manager.ts +47 -47
- package/src/phaser/core/signal.test.ts +4 -4
- package/src/phaser/core/signal.ts +41 -52
- package/src/phaser/core/signal_binding.ts +26 -25
- package/src/phaser/core/signal_dispatch.test.ts +180 -0
- package/src/phaser/core/sound.ts +75 -83
- package/src/phaser/core/sound_manager.ts +52 -51
- package/src/phaser/core/sound_sprite.ts +17 -16
- package/src/phaser/core/stage.ts +25 -24
- package/src/phaser/core/time.ts +52 -52
- package/src/phaser/core/timer.test.ts +187 -0
- package/src/phaser/core/timer.ts +82 -69
- package/src/phaser/core/timer_event.ts +10 -10
- package/src/phaser/core/tween.ts +90 -93
- package/src/phaser/core/tween_data.ts +45 -51
- package/src/phaser/core/tween_easing.test.ts +106 -0
- package/src/phaser/core/tween_easing.ts +151 -123
- package/src/phaser/core/tween_manager.ts +19 -18
- package/src/phaser/core/world.ts +4 -3
- package/src/phaser/display/bitmap_text.ts +56 -64
- package/src/phaser/display/button.ts +33 -32
- package/src/phaser/display/canvas/buffer.ts +8 -8
- package/src/phaser/display/canvas/graphics.ts +36 -37
- package/src/phaser/display/canvas/masker.ts +2 -2
- package/src/phaser/display/canvas/pool.test.ts +106 -0
- package/src/phaser/display/canvas/pool.ts +25 -27
- package/src/phaser/display/canvas/renderer.ts +32 -31
- package/src/phaser/display/canvas/tinter.ts +25 -25
- package/src/phaser/display/canvas/util.ts +7 -10
- package/src/phaser/display/display_object.ts +114 -118
- package/src/phaser/display/graphics.ts +121 -119
- package/src/phaser/display/graphics_data.ts +12 -12
- package/src/phaser/display/graphics_data_util.ts +2 -3
- package/src/phaser/display/group.ts +50 -57
- package/src/phaser/display/image.ts +55 -52
- package/src/phaser/display/sprite_batch.ts +3 -2
- package/src/phaser/display/sprite_util.ts +48 -54
- package/src/phaser/display/text.test.ts +110 -0
- package/src/phaser/display/text.ts +199 -204
- package/src/phaser/display/webgl/abstract_filter.ts +9 -9
- package/src/phaser/display/webgl/base_texture.ts +21 -24
- package/src/phaser/display/webgl/blend_manager.ts +6 -10
- package/src/phaser/display/webgl/earcut.ts +73 -37
- package/src/phaser/display/webgl/earcut_node.ts +10 -10
- package/src/phaser/display/webgl/fast_sprite_batch.ts +34 -34
- package/src/phaser/display/webgl/filter_manager.ts +13 -12
- package/src/phaser/display/webgl/filter_texture.ts +14 -13
- package/src/phaser/display/webgl/graphics.ts +51 -57
- package/src/phaser/display/webgl/graphics_data.ts +15 -14
- package/src/phaser/display/webgl/mask_manager.ts +2 -2
- package/src/phaser/display/webgl/render_texture.ts +26 -25
- package/src/phaser/display/webgl/renderer.ts +57 -62
- package/src/phaser/display/webgl/shader/complex.ts +28 -12
- package/src/phaser/display/webgl/shader/fast.ts +30 -12
- package/src/phaser/display/webgl/shader/normal.ts +70 -57
- package/src/phaser/display/webgl/shader/primitive.ts +26 -11
- package/src/phaser/display/webgl/shader/shader.test.ts +148 -0
- package/src/phaser/display/webgl/shader/strip.ts +27 -12
- package/src/phaser/display/webgl/shader_manager.test.ts +124 -0
- package/src/phaser/display/webgl/shader_manager.ts +26 -34
- package/src/phaser/display/webgl/sprite_batch.ts +67 -61
- package/src/phaser/display/webgl/stencil_manager.ts +23 -34
- package/src/phaser/display/webgl/texture.ts +43 -50
- package/src/phaser/display/webgl/texture_util.ts +2 -3
- package/src/phaser/display/webgl/util.ts +26 -25
- package/src/phaser/geom/circle.test.ts +2 -3
- package/src/phaser/geom/circle.ts +36 -36
- package/src/phaser/geom/ellipse.test.ts +73 -71
- package/src/phaser/geom/ellipse.ts +14 -14
- package/src/phaser/geom/line.test.ts +5 -5
- package/src/phaser/geom/line.ts +35 -35
- package/src/phaser/geom/matrix.test.ts +1 -1
- package/src/phaser/geom/matrix.ts +27 -27
- package/src/phaser/geom/point.test.ts +1 -2
- package/src/phaser/geom/point.ts +35 -35
- package/src/phaser/geom/polygon.test.ts +82 -0
- package/src/phaser/geom/polygon.ts +16 -16
- package/src/phaser/geom/rectangle.test.ts +14 -14
- package/src/phaser/geom/rectangle.ts +83 -75
- package/src/phaser/geom/rounded_rectangle.test.ts +1 -7
- package/src/phaser/geom/rounded_rectangle.ts +9 -9
- package/src/phaser/geom/util/circle.test.ts +25 -23
- package/src/phaser/geom/util/circle.ts +9 -18
- package/src/phaser/geom/util/ellipse.test.ts +7 -5
- package/src/phaser/geom/util/ellipse.ts +3 -2
- package/src/phaser/geom/util/line.test.ts +10 -8
- package/src/phaser/geom/util/line.ts +6 -16
- package/src/phaser/geom/util/matrix.test.ts +20 -18
- package/src/phaser/geom/util/matrix.ts +8 -15
- package/src/phaser/geom/util/point.test.ts +8 -6
- package/src/phaser/geom/util/point.ts +24 -28
- package/src/phaser/geom/util/polygon.test.ts +12 -10
- package/src/phaser/geom/util/polygon.ts +2 -2
- package/src/phaser/geom/util/rectangle.test.ts +10 -8
- package/src/phaser/geom/util/rectangle.ts +18 -37
- package/src/phaser/geom/util/rounded_rectangle.test.ts +11 -9
- package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
- package/src/phaser/util/math.test.ts +11 -11
- package/src/phaser/util/math.ts +29 -46
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { create, removeByCanvas } from './pool.js';
|
|
2
2
|
|
|
3
3
|
export class CanvasBuffer {
|
|
4
|
-
width!: any;
|
|
5
|
-
height!: any;
|
|
6
|
-
canvas!: any;
|
|
7
|
-
context!: any;
|
|
4
|
+
public width!: any;
|
|
5
|
+
public height!: any;
|
|
6
|
+
public canvas!: any;
|
|
7
|
+
public context!: any;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a new CanvasBuffer instance.
|
|
10
10
|
* @param {number} width - The width of the canvas buffer.
|
|
11
11
|
* @param {number} height - The height of the canvas buffer.
|
|
12
12
|
*/
|
|
13
|
-
constructor(width: number, height: number) {
|
|
13
|
+
public constructor(width: number, height: number) {
|
|
14
14
|
this.width = width;
|
|
15
15
|
this.height = height;
|
|
16
16
|
this.canvas = create(this, this.width, this.height);
|
|
@@ -22,7 +22,7 @@ export class CanvasBuffer {
|
|
|
22
22
|
/**
|
|
23
23
|
* Clears the canvas buffer.
|
|
24
24
|
*/
|
|
25
|
-
clear() {
|
|
25
|
+
public clear() {
|
|
26
26
|
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
|
27
27
|
this.context.clearRect(0, 0, this.width, this.height);
|
|
28
28
|
}
|
|
@@ -32,7 +32,7 @@ export class CanvasBuffer {
|
|
|
32
32
|
* @param {number} width - The new width of the canvas buffer.
|
|
33
33
|
* @param {number} height - The new height of the canvas buffer.
|
|
34
34
|
*/
|
|
35
|
-
resize(width: number, height: number) {
|
|
35
|
+
public resize(width: number, height: number) {
|
|
36
36
|
this.width = width;
|
|
37
37
|
this.height = height;
|
|
38
38
|
this.canvas.width = width;
|
|
@@ -42,7 +42,7 @@ export class CanvasBuffer {
|
|
|
42
42
|
/**
|
|
43
43
|
* Destroys the canvas buffer and cleans up resources.
|
|
44
44
|
*/
|
|
45
|
-
destroy() {
|
|
45
|
+
public destroy() {
|
|
46
46
|
try {
|
|
47
47
|
this.context?.reset();
|
|
48
48
|
} catch {
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { GEOM_CIRCLE, GEOM_ELLIPSE, GEOM_POLYGON, GEOM_RECTANGLE, GEOM_ROUNDED_RECTANGLE } from '../../core/const.js';
|
|
2
|
+
import type { Graphics } from '../graphics.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Renders a graphics object to canvas.
|
|
5
|
-
* @param {
|
|
6
|
+
* @param {Graphics} graphics - The graphics object to render.
|
|
6
7
|
*/
|
|
7
|
-
export const updateGraphicsTint = (graphics:
|
|
8
|
+
export const updateGraphicsTint = (graphics: Graphics) => {
|
|
8
9
|
if (graphics.tint === 0xffffff) {
|
|
9
10
|
return;
|
|
10
11
|
}
|
|
11
12
|
const tintR = ((graphics.tint >> 16) & 0xff) / 255;
|
|
12
13
|
const tintG = ((graphics.tint >> 8) & 0xff) / 255;
|
|
13
14
|
const tintB = (graphics.tint & 0xff) / 255;
|
|
14
|
-
for (
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const lineColor = data.lineColor | 0;
|
|
15
|
+
for (const data of graphics.graphicsData) {
|
|
16
|
+
const fillColor = Math.trunc(data.fillColor);
|
|
17
|
+
const lineColor = Math.trunc(data.lineColor);
|
|
18
18
|
data._fillTint =
|
|
19
19
|
(((((fillColor >> 16) & 0xff) / 255) * tintR * 255) << 16) +
|
|
20
20
|
(((((fillColor >> 8) & 0xff) / 255) * tintG * 255) << 8) +
|
|
@@ -28,24 +28,23 @@ export const updateGraphicsTint = (graphics: import('../graphics.js').Graphics)
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Renders a graphics object to canvas.
|
|
31
|
-
* @param {
|
|
31
|
+
* @param {Graphics} graphics - The graphics object to render.
|
|
32
32
|
* @param {object} context - The canvas rendering context.
|
|
33
33
|
*/
|
|
34
|
-
export const renderGraphics = (graphics:
|
|
35
|
-
const worldAlpha = graphics
|
|
34
|
+
export const renderGraphics = (graphics: Graphics, context: any) => {
|
|
35
|
+
const { worldAlpha } = graphics;
|
|
36
36
|
if (graphics.dirty) {
|
|
37
37
|
updateGraphicsTint(graphics);
|
|
38
38
|
graphics.dirty = false;
|
|
39
39
|
}
|
|
40
|
-
for (
|
|
41
|
-
const
|
|
42
|
-
const shape = data.shape;
|
|
40
|
+
for (const data of graphics.graphicsData) {
|
|
41
|
+
const { shape } = data;
|
|
43
42
|
const fillColor = data._fillTint;
|
|
44
43
|
const lineColor = data._lineTint;
|
|
45
44
|
context.lineWidth = data.lineWidth;
|
|
46
45
|
if (data.type === GEOM_POLYGON) {
|
|
47
46
|
context.beginPath();
|
|
48
|
-
const points = shape
|
|
47
|
+
const { points } = shape;
|
|
49
48
|
context.moveTo(points[0], points[1]);
|
|
50
49
|
for (let j = 1; j < points.length / 2; j += 1) {
|
|
51
50
|
context.lineTo(points[j * 2], points[j * 2 + 1]);
|
|
@@ -54,28 +53,28 @@ export const renderGraphics = (graphics: import('../graphics.js').Graphics, cont
|
|
|
54
53
|
context.lineTo(points[0], points[1]);
|
|
55
54
|
}
|
|
56
55
|
// if the first and last point are the same close the path - much neater :)
|
|
57
|
-
if (points[0] === points
|
|
56
|
+
if (points[0] === points.at(-2) && points[1] === points.at(-1)) {
|
|
58
57
|
context.closePath();
|
|
59
58
|
}
|
|
60
59
|
if (data.fill) {
|
|
61
60
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
62
|
-
context.fillStyle = `#${`00000${(fillColor
|
|
61
|
+
context.fillStyle = `#${`00000${Math.trunc(fillColor).toString(16)}`.slice(-6)}`;
|
|
63
62
|
context.fill();
|
|
64
63
|
}
|
|
65
64
|
if (data.lineWidth) {
|
|
66
65
|
context.globalAlpha = data.lineAlpha * worldAlpha;
|
|
67
|
-
context.strokeStyle = `#${`00000${(lineColor
|
|
66
|
+
context.strokeStyle = `#${`00000${Math.trunc(lineColor).toString(16)}`.slice(-6)}`;
|
|
68
67
|
context.stroke();
|
|
69
68
|
}
|
|
70
69
|
} else if (data.type === GEOM_RECTANGLE) {
|
|
71
70
|
if (data.fillColor || data.fillColor === 0) {
|
|
72
71
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
73
|
-
context.fillStyle = `#${`00000${(fillColor
|
|
72
|
+
context.fillStyle = `#${`00000${Math.trunc(fillColor).toString(16)}`.slice(-6)}`;
|
|
74
73
|
context.fillRect(shape.x, shape.y, shape.width, shape.height);
|
|
75
74
|
}
|
|
76
75
|
if (data.lineWidth) {
|
|
77
76
|
context.globalAlpha = data.lineAlpha * worldAlpha;
|
|
78
|
-
context.strokeStyle = `#${`00000${(lineColor
|
|
77
|
+
context.strokeStyle = `#${`00000${Math.trunc(lineColor).toString(16)}`.slice(-6)}`;
|
|
79
78
|
context.strokeRect(shape.x, shape.y, shape.width, shape.height);
|
|
80
79
|
}
|
|
81
80
|
} else if (data.type === GEOM_CIRCLE) {
|
|
@@ -84,12 +83,12 @@ export const renderGraphics = (graphics: import('../graphics.js').Graphics, cont
|
|
|
84
83
|
context.closePath();
|
|
85
84
|
if (data.fill) {
|
|
86
85
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
87
|
-
context.fillStyle = `#${`00000${(fillColor
|
|
86
|
+
context.fillStyle = `#${`00000${Math.trunc(fillColor).toString(16)}`.slice(-6)}`;
|
|
88
87
|
context.fill();
|
|
89
88
|
}
|
|
90
89
|
if (data.lineWidth) {
|
|
91
90
|
context.globalAlpha = data.lineAlpha * worldAlpha;
|
|
92
|
-
context.strokeStyle = `#${`00000${(lineColor
|
|
91
|
+
context.strokeStyle = `#${`00000${Math.trunc(lineColor).toString(16)}`.slice(-6)}`;
|
|
93
92
|
context.stroke();
|
|
94
93
|
}
|
|
95
94
|
} else if (data.type === GEOM_ELLIPSE) {
|
|
@@ -114,21 +113,21 @@ export const renderGraphics = (graphics: import('../graphics.js').Graphics, cont
|
|
|
114
113
|
context.closePath();
|
|
115
114
|
if (data.fill) {
|
|
116
115
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
117
|
-
context.fillStyle = `#${`00000${(fillColor
|
|
116
|
+
context.fillStyle = `#${`00000${Math.trunc(fillColor).toString(16)}`.slice(-6)}`;
|
|
118
117
|
context.fill();
|
|
119
118
|
}
|
|
120
119
|
if (data.lineWidth) {
|
|
121
120
|
context.globalAlpha = data.lineAlpha * worldAlpha;
|
|
122
|
-
context.strokeStyle = `#${`00000${(lineColor
|
|
121
|
+
context.strokeStyle = `#${`00000${Math.trunc(lineColor).toString(16)}`.slice(-6)}`;
|
|
123
122
|
context.stroke();
|
|
124
123
|
}
|
|
125
124
|
} else if (data.type === GEOM_ROUNDED_RECTANGLE) {
|
|
126
125
|
const rx = shape.x;
|
|
127
126
|
const ry = shape.y;
|
|
128
|
-
const width = shape
|
|
129
|
-
const height = shape
|
|
130
|
-
let radius = shape
|
|
131
|
-
const maxRadius = (Math.min(width, height) / 2)
|
|
127
|
+
const { width } = shape;
|
|
128
|
+
const { height } = shape;
|
|
129
|
+
let { radius } = shape;
|
|
130
|
+
const maxRadius = Math.trunc(Math.min(width, height) / 2);
|
|
132
131
|
radius = radius > maxRadius ? maxRadius : radius;
|
|
133
132
|
context.beginPath();
|
|
134
133
|
context.moveTo(rx, ry + radius);
|
|
@@ -143,12 +142,12 @@ export const renderGraphics = (graphics: import('../graphics.js').Graphics, cont
|
|
|
143
142
|
context.closePath();
|
|
144
143
|
if (data.fillColor || data.fillColor === 0) {
|
|
145
144
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
146
|
-
context.fillStyle = `#${`00000${(fillColor
|
|
145
|
+
context.fillStyle = `#${`00000${Math.trunc(fillColor).toString(16)}`.slice(-6)}`;
|
|
147
146
|
context.fill();
|
|
148
147
|
}
|
|
149
148
|
if (data.lineWidth) {
|
|
150
149
|
context.globalAlpha = data.lineAlpha * worldAlpha;
|
|
151
|
-
context.strokeStyle = `#${`00000${(lineColor
|
|
150
|
+
context.strokeStyle = `#${`00000${Math.trunc(lineColor).toString(16)}`.slice(-6)}`;
|
|
152
151
|
context.stroke();
|
|
153
152
|
}
|
|
154
153
|
}
|
|
@@ -157,10 +156,10 @@ export const renderGraphics = (graphics: import('../graphics.js').Graphics, cont
|
|
|
157
156
|
|
|
158
157
|
/**
|
|
159
158
|
* Renders a graphics object to canvas.
|
|
160
|
-
* @param {
|
|
159
|
+
* @param {Graphics} graphics - The graphics object to render.
|
|
161
160
|
* @param {object} context - The canvas rendering context.
|
|
162
161
|
*/
|
|
163
|
-
export const renderGraphicsMask = (graphics:
|
|
162
|
+
export const renderGraphicsMask = (graphics: Graphics, context: any) => {
|
|
164
163
|
const len = graphics.graphicsData.length;
|
|
165
164
|
if (len === 0) {
|
|
166
165
|
return;
|
|
@@ -168,15 +167,15 @@ export const renderGraphicsMask = (graphics: import('../graphics.js').Graphics,
|
|
|
168
167
|
context.beginPath();
|
|
169
168
|
for (let i = 0; i < len; i += 1) {
|
|
170
169
|
const data = graphics.graphicsData[i];
|
|
171
|
-
const shape = data
|
|
170
|
+
const { shape } = data;
|
|
172
171
|
if (data.type === GEOM_POLYGON) {
|
|
173
|
-
const points = shape
|
|
172
|
+
const { points } = shape;
|
|
174
173
|
context.moveTo(points[0], points[1]);
|
|
175
174
|
for (let j = 1; j < points.length / 2; j += 1) {
|
|
176
175
|
context.lineTo(points[j * 2], points[j * 2 + 1]);
|
|
177
176
|
}
|
|
178
177
|
// if the first and last point are the same close the path - much neater :)
|
|
179
|
-
if (points[0] === points
|
|
178
|
+
if (points[0] === points.at(-2) && points[1] === points.at(-1)) {
|
|
180
179
|
context.closePath();
|
|
181
180
|
}
|
|
182
181
|
} else if (data.type === GEOM_RECTANGLE) {
|
|
@@ -207,10 +206,10 @@ export const renderGraphicsMask = (graphics: import('../graphics.js').Graphics,
|
|
|
207
206
|
} else if (data.type === GEOM_ROUNDED_RECTANGLE) {
|
|
208
207
|
const rx = shape.x;
|
|
209
208
|
const ry = shape.y;
|
|
210
|
-
const width = shape
|
|
211
|
-
const height = shape
|
|
212
|
-
let radius = shape
|
|
213
|
-
const maxRadius = (Math.min(width, height) / 2)
|
|
209
|
+
const { width } = shape;
|
|
210
|
+
const { height } = shape;
|
|
211
|
+
let { radius } = shape;
|
|
212
|
+
const maxRadius = Math.trunc(Math.min(width, height) / 2);
|
|
214
213
|
radius = radius > maxRadius ? maxRadius : radius;
|
|
215
214
|
context.moveTo(rx, ry + radius);
|
|
216
215
|
context.lineTo(rx, ry + height - radius);
|
|
@@ -6,11 +6,11 @@ import { renderGraphicsMask } from './graphics.js';
|
|
|
6
6
|
* @param {object} renderSession - The rendering session object.
|
|
7
7
|
*/
|
|
8
8
|
export const pushMask = (maskData: any, renderSession: any) => {
|
|
9
|
-
const context = renderSession
|
|
9
|
+
const { context } = renderSession;
|
|
10
10
|
context.save();
|
|
11
11
|
const cacheAlpha = maskData.alpha;
|
|
12
12
|
const transform = maskData.worldTransform;
|
|
13
|
-
const resolution = renderSession
|
|
13
|
+
const { resolution } = renderSession;
|
|
14
14
|
context.setTransform(
|
|
15
15
|
transform.a * resolution,
|
|
16
16
|
transform.b * resolution,
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { create, getFirst, getFree, getPool, getTotal, remove, removeByCanvas } from './pool.js';
|
|
3
|
+
|
|
4
|
+
describe('canvas pool', () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
getPool().length = 0;
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
describe('getPool', () => {
|
|
10
|
+
it('lazily creates the backing array and returns the same one thereafter', () => {
|
|
11
|
+
expect(getPool()).toBe(getPool());
|
|
12
|
+
expect(getPool()).toStrictEqual([]);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('create', () => {
|
|
17
|
+
it('adds a new entry when the pool is empty', () => {
|
|
18
|
+
const parent = { name: 'owner' };
|
|
19
|
+
const canvas = create(parent);
|
|
20
|
+
expect(getPool()).toHaveLength(1);
|
|
21
|
+
expect(getPool()[0]?.parent).toBe(parent);
|
|
22
|
+
expect(getPool()[0]?.canvas).toBe(canvas);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('reuses a free entry instead of growing the pool', () => {
|
|
26
|
+
const first = { name: 'first' };
|
|
27
|
+
const canvas = create(first);
|
|
28
|
+
remove(first);
|
|
29
|
+
const second = { name: 'second' };
|
|
30
|
+
expect(create(second)).toBe(canvas);
|
|
31
|
+
expect(getPool()).toHaveLength(1);
|
|
32
|
+
expect(getPool()[0]?.parent).toBe(second);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('grows the pool when skipPool is set even if an entry is free', () => {
|
|
36
|
+
const first = { name: 'first' };
|
|
37
|
+
create(first);
|
|
38
|
+
remove(first);
|
|
39
|
+
create({ name: 'second' }, undefined, undefined, true);
|
|
40
|
+
expect(getPool()).toHaveLength(2);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('applies the requested dimensions', () => {
|
|
44
|
+
const canvas = create({ name: 'sized' }, 64, 32);
|
|
45
|
+
expect(canvas.width).toBe(64);
|
|
46
|
+
expect(canvas.height).toBe(32);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('getFirst', () => {
|
|
51
|
+
it('reports -1 when every entry is claimed', () => {
|
|
52
|
+
create({ name: 'owner' });
|
|
53
|
+
expect(getFirst()).toBe(-1);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('reports the index of the first free entry', () => {
|
|
57
|
+
create({ name: 'a' });
|
|
58
|
+
const b = { name: 'b' };
|
|
59
|
+
create(b);
|
|
60
|
+
create({ name: 'c' });
|
|
61
|
+
remove(b);
|
|
62
|
+
expect(getFirst()).toBe(1);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('remove', () => {
|
|
67
|
+
it('frees the entry and shrinks its canvas to 1x1', () => {
|
|
68
|
+
const parent = { name: 'owner' };
|
|
69
|
+
const canvas = create(parent, 100, 50);
|
|
70
|
+
remove(parent);
|
|
71
|
+
expect(getPool()[0]?.parent).toBeNull();
|
|
72
|
+
expect(canvas.width).toBe(1);
|
|
73
|
+
expect(canvas.height).toBe(1);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('ignores a parent that owns nothing', () => {
|
|
77
|
+
create({ name: 'owner' });
|
|
78
|
+
expect(() => {
|
|
79
|
+
remove({ name: 'stranger' });
|
|
80
|
+
}).not.toThrow();
|
|
81
|
+
expect(getPool()[0]?.parent).not.toBeNull();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('removeByCanvas', () => {
|
|
86
|
+
it('frees the entry holding that canvas', () => {
|
|
87
|
+
const canvas = create({ name: 'owner' }, 100, 50);
|
|
88
|
+
removeByCanvas(canvas);
|
|
89
|
+
expect(getPool()[0]?.parent).toBeNull();
|
|
90
|
+
expect(canvas.width).toBe(1);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('getTotal and getFree', () => {
|
|
95
|
+
it('count claimed and unclaimed entries', () => {
|
|
96
|
+
const a = { name: 'a' };
|
|
97
|
+
create(a);
|
|
98
|
+
create({ name: 'b' });
|
|
99
|
+
expect(getTotal()).toBe(2);
|
|
100
|
+
expect(getFree()).toBe(0);
|
|
101
|
+
remove(a);
|
|
102
|
+
expect(getTotal()).toBe(1);
|
|
103
|
+
expect(getFree()).toBe(1);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
+
import { getRegistry } from '../../core/registry.js';
|
|
1
2
|
/**
|
|
2
3
|
* Gets the canvas pool array.
|
|
3
4
|
* @returns {{canvas: HTMLCanvasElement, parent: object}[]} The canvas pool array.
|
|
4
5
|
*/
|
|
5
|
-
export const getPool = () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (!window.PhaserRegistry.CANVAS_POOL) {
|
|
10
|
-
window.PhaserRegistry.CANVAS_POOL = [];
|
|
11
|
-
}
|
|
12
|
-
return window.PhaserRegistry.CANVAS_POOL;
|
|
6
|
+
export const getPool = (): CanvasPoolEntry[] => {
|
|
7
|
+
const registry = getRegistry();
|
|
8
|
+
registry.CANVAS_POOL ??= [];
|
|
9
|
+
return registry.CANVAS_POOL;
|
|
13
10
|
};
|
|
14
11
|
|
|
15
12
|
/**
|
|
@@ -19,7 +16,7 @@ export const getPool = () => {
|
|
|
19
16
|
export const getFirst = () => {
|
|
20
17
|
const pool = getPool();
|
|
21
18
|
for (let i = 0; i < pool.length; i += 1) {
|
|
22
|
-
if (!pool[i]
|
|
19
|
+
if (!pool[i]!.parent) {
|
|
23
20
|
return i;
|
|
24
21
|
}
|
|
25
22
|
}
|
|
@@ -32,11 +29,11 @@ export const getFirst = () => {
|
|
|
32
29
|
*/
|
|
33
30
|
export const remove = (parent: any) => {
|
|
34
31
|
const pool = getPool();
|
|
35
|
-
for (
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
for (const entry of pool) {
|
|
33
|
+
if (entry.parent === parent) {
|
|
34
|
+
entry.parent = null;
|
|
35
|
+
entry.canvas.width = 1;
|
|
36
|
+
entry.canvas.height = 1;
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
};
|
|
@@ -47,11 +44,11 @@ export const remove = (parent: any) => {
|
|
|
47
44
|
*/
|
|
48
45
|
export const removeByCanvas = (canvas: HTMLCanvasElement) => {
|
|
49
46
|
const pool = getPool();
|
|
50
|
-
for (
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
for (const entry of pool) {
|
|
48
|
+
if (entry.canvas === canvas) {
|
|
49
|
+
entry.parent = null;
|
|
50
|
+
entry.canvas.width = 1;
|
|
51
|
+
entry.canvas.height = 1;
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
};
|
|
@@ -63,8 +60,8 @@ export const removeByCanvas = (canvas: HTMLCanvasElement) => {
|
|
|
63
60
|
export const getTotal = () => {
|
|
64
61
|
const pool = getPool();
|
|
65
62
|
let c = 0;
|
|
66
|
-
for (
|
|
67
|
-
if (
|
|
63
|
+
for (const entry of pool) {
|
|
64
|
+
if (entry.parent) {
|
|
68
65
|
c += 1;
|
|
69
66
|
}
|
|
70
67
|
}
|
|
@@ -78,8 +75,8 @@ export const getTotal = () => {
|
|
|
78
75
|
export const getFree = () => {
|
|
79
76
|
const pool = getPool();
|
|
80
77
|
let c = 0;
|
|
81
|
-
for (
|
|
82
|
-
if (!
|
|
78
|
+
for (const entry of pool) {
|
|
79
|
+
if (!entry.parent) {
|
|
83
80
|
c += 1;
|
|
84
81
|
}
|
|
85
82
|
}
|
|
@@ -94,14 +91,14 @@ export const getFree = () => {
|
|
|
94
91
|
* @param {boolean} skipPool - True to skip using the pool and create a new canvas.
|
|
95
92
|
* @returns {HTMLCanvasElement} The canvas from the pool or a newly created one.
|
|
96
93
|
*/
|
|
97
|
-
export const create = (parent: any, width?: any, height?: any, skipPool
|
|
94
|
+
export const create = (parent: any, width?: any, height?: any, skipPool = false) => {
|
|
98
95
|
if (parent === undefined) {
|
|
99
96
|
console.warn('Created CanvasPool element with undefined parent.');
|
|
100
97
|
}
|
|
101
98
|
const idx = getFirst();
|
|
102
99
|
const pool = getPool();
|
|
103
100
|
let canvas;
|
|
104
|
-
if (idx === -1 || skipPool
|
|
101
|
+
if (idx === -1 || skipPool) {
|
|
105
102
|
const container = {
|
|
106
103
|
parent,
|
|
107
104
|
canvas: document.createElement('canvas'),
|
|
@@ -109,8 +106,9 @@ export const create = (parent: any, width?: any, height?: any, skipPool: boolean
|
|
|
109
106
|
pool.push(container);
|
|
110
107
|
canvas = container.canvas;
|
|
111
108
|
} else {
|
|
112
|
-
pool[idx]
|
|
113
|
-
|
|
109
|
+
const entry = pool[idx]!;
|
|
110
|
+
entry.parent = parent;
|
|
111
|
+
canvas = entry.canvas;
|
|
114
112
|
}
|
|
115
113
|
if (width !== undefined) {
|
|
116
114
|
canvas.width = width;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { Game } from '../../core/game.js';
|
|
2
|
+
import type { Stage } from '../../core/stage.js';
|
|
1
3
|
import {
|
|
2
4
|
BLEND_ADD,
|
|
3
5
|
BLEND_COLOR,
|
|
@@ -26,24 +28,24 @@ import { detectCapabilities } from './tinter.js';
|
|
|
26
28
|
import { getSmoothingPrefix } from './util.js';
|
|
27
29
|
|
|
28
30
|
export class CanvasRenderer {
|
|
29
|
-
type!: any;
|
|
30
|
-
resolution!: any;
|
|
31
|
-
clearBeforeRender!: any;
|
|
32
|
-
transparent!: any;
|
|
33
|
-
autoResize!: any;
|
|
34
|
-
contextLost!: any;
|
|
35
|
-
width!: any;
|
|
36
|
-
height!: any;
|
|
37
|
-
view!: any;
|
|
38
|
-
context!: any;
|
|
39
|
-
refresh!: any;
|
|
40
|
-
count!: any;
|
|
41
|
-
renderSession!: any;
|
|
31
|
+
public type!: any;
|
|
32
|
+
public resolution!: any;
|
|
33
|
+
public clearBeforeRender!: any;
|
|
34
|
+
public transparent!: any;
|
|
35
|
+
public autoResize!: any;
|
|
36
|
+
public contextLost!: any;
|
|
37
|
+
public width!: any;
|
|
38
|
+
public height!: any;
|
|
39
|
+
public view!: any;
|
|
40
|
+
public context!: any;
|
|
41
|
+
public refresh!: any;
|
|
42
|
+
public count!: any;
|
|
43
|
+
public renderSession!: any;
|
|
42
44
|
/**
|
|
43
45
|
* Creates a new CanvasRenderer instance.
|
|
44
|
-
* @param {
|
|
46
|
+
* @param {Game} _game - The game instance.
|
|
45
47
|
*/
|
|
46
|
-
constructor(game:
|
|
48
|
+
public constructor(game: Game) {
|
|
47
49
|
detectCapabilities(game);
|
|
48
50
|
/** @type {number} */
|
|
49
51
|
this.type = RENDER_CANVAS;
|
|
@@ -56,7 +58,6 @@ export class CanvasRenderer {
|
|
|
56
58
|
this.height = game.height * this.resolution;
|
|
57
59
|
this.view = game.canvas;
|
|
58
60
|
/** @type {CanvasRenderingContext2D} */
|
|
59
|
-
// @ts-ignore
|
|
60
61
|
this.context = this.view.getContext('2d', { willReadFrequently: false, alpha: this.transparent });
|
|
61
62
|
if (!this.context) {
|
|
62
63
|
throw new Error(ENGINE_ERROR_CREATING_CANVAS_2D_CONTEXT);
|
|
@@ -76,9 +77,9 @@ export class CanvasRenderer {
|
|
|
76
77
|
|
|
77
78
|
/**
|
|
78
79
|
* Renders the stage to canvas.
|
|
79
|
-
* @param {
|
|
80
|
+
* @param {Stage} root - The root stage to render.
|
|
80
81
|
*/
|
|
81
|
-
render(root:
|
|
82
|
+
public render(root: Stage) {
|
|
82
83
|
if (!this.context) {
|
|
83
84
|
return;
|
|
84
85
|
}
|
|
@@ -103,7 +104,7 @@ export class CanvasRenderer {
|
|
|
103
104
|
* Destroys this renderer and cleans up resources.
|
|
104
105
|
* @param {boolean} removeView - Whether to remove the view from the DOM.
|
|
105
106
|
*/
|
|
106
|
-
destroy(removeView
|
|
107
|
+
public destroy(removeView = true) {
|
|
107
108
|
if (removeView && this.view.parent) {
|
|
108
109
|
this.view.parent.removeChild(this.view);
|
|
109
110
|
}
|
|
@@ -117,7 +118,7 @@ export class CanvasRenderer {
|
|
|
117
118
|
* @param {number} width - The new width of the canvas.
|
|
118
119
|
* @param {number} height - The new height of the canvas.
|
|
119
120
|
*/
|
|
120
|
-
resize(width: number, height: number) {
|
|
121
|
+
public resize(width: number, height: number) {
|
|
121
122
|
this.width = width * this.resolution;
|
|
122
123
|
this.height = height * this.resolution;
|
|
123
124
|
this.view.width = this.width;
|
|
@@ -133,12 +134,12 @@ export class CanvasRenderer {
|
|
|
133
134
|
|
|
134
135
|
/**
|
|
135
136
|
* Renders a display object to canvas.
|
|
136
|
-
* @param {
|
|
137
|
+
* @param {Image} displayObject - The display object to render.
|
|
137
138
|
* @param {CanvasRenderingContext2D} context - The canvas rendering context.
|
|
138
|
-
* @param {
|
|
139
|
+
* @param {Matrix} matrix - The transformation matrix.
|
|
139
140
|
*/
|
|
140
|
-
renderDisplayObject(displayObject: any, context?: any, matrix?: any) {
|
|
141
|
-
this.renderSession.context = context
|
|
141
|
+
public renderDisplayObject(displayObject: any, context?: any, matrix?: any) {
|
|
142
|
+
this.renderSession.context = context ?? this.context;
|
|
142
143
|
this.renderSession.resolution = this.resolution;
|
|
143
144
|
displayObject.renderCanvas(this.renderSession, matrix);
|
|
144
145
|
}
|
|
@@ -146,12 +147,12 @@ export class CanvasRenderer {
|
|
|
146
147
|
/**
|
|
147
148
|
* Maps blend modes to canvas rendering operations.
|
|
148
149
|
*/
|
|
149
|
-
mapBlendModes() {
|
|
150
|
-
if (
|
|
150
|
+
public mapBlendModes() {
|
|
151
|
+
if (globalThis.PhaserRegistry.blendModesCanvas) {
|
|
151
152
|
return;
|
|
152
153
|
}
|
|
153
|
-
const b = [];
|
|
154
|
-
const useNew =
|
|
154
|
+
const b: GlobalCompositeOperation[] = [];
|
|
155
|
+
const useNew = globalThis.PhaserRegistry.CAN_CANVAS_USE_MULTIPLY;
|
|
155
156
|
b[BLEND_NORMAL] = 'source-over';
|
|
156
157
|
b[BLEND_ADD] = 'lighter';
|
|
157
158
|
b[BLEND_MULTIPLY] = useNew ? 'multiply' : 'source-over';
|
|
@@ -169,14 +170,14 @@ export class CanvasRenderer {
|
|
|
169
170
|
b[BLEND_SATURATION] = useNew ? 'saturation' : 'source-over';
|
|
170
171
|
b[BLEND_COLOR] = useNew ? 'color' : 'source-over';
|
|
171
172
|
b[BLEND_LUMINOSITY] = useNew ? 'luminosity' : 'source-over';
|
|
172
|
-
|
|
173
|
+
globalThis.PhaserRegistry.blendModesCanvas = b;
|
|
173
174
|
}
|
|
174
175
|
|
|
175
176
|
/**
|
|
176
177
|
* Initializes the WebGL context for rendering.
|
|
177
|
-
* @param {
|
|
178
|
+
* @param {Game} game - The game instance.
|
|
178
179
|
*/
|
|
179
|
-
initContext(_game:
|
|
180
|
+
public initContext(_game: Game) {
|
|
180
181
|
// stub
|
|
181
182
|
}
|
|
182
183
|
}
|