@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
|
@@ -58,35 +58,35 @@ const createGame = (font: BitmapFontData | null = FONT): Game =>
|
|
|
58
58
|
|
|
59
59
|
const createText = (text: string, size = 10): BitmapText => new BitmapText(createGame(), 0, 0, 'test', text, size);
|
|
60
60
|
|
|
61
|
-
describe('BitmapText', () => {
|
|
62
|
-
beforeEach(() => {
|
|
61
|
+
describe('BitmapText', (): void => {
|
|
62
|
+
beforeEach((): void => {
|
|
63
63
|
getRegistry().CACHE_MISSING_IMAGE = new Texture(atlas, new Rectangle(0, 0, 1, 1));
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
describe('updateText', () => {
|
|
67
|
-
it('measures a single line from the glyph advances', () => {
|
|
66
|
+
describe('updateText', (): void => {
|
|
67
|
+
it('measures a single line from the glyph advances', (): void => {
|
|
68
68
|
const bitmapText = createText('AB');
|
|
69
69
|
expect(bitmapText.textWidth).toBe(20);
|
|
70
70
|
expect(bitmapText.textHeight).toBe(12);
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
it('scales the metrics with the font size', () => {
|
|
73
|
+
it('scales the metrics with the font size', (): void => {
|
|
74
74
|
const bitmapText = createText('AB', 20);
|
|
75
75
|
expect(bitmapText.textWidth).toBe(40);
|
|
76
76
|
expect(bitmapText.textHeight).toBe(24);
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
it('splits on a newline and takes the widest line as the width', () => {
|
|
79
|
+
it('splits on a newline and takes the widest line as the width', (): void => {
|
|
80
80
|
const bitmapText = createText('AB\nA');
|
|
81
81
|
expect(bitmapText.textWidth).toBe(20);
|
|
82
82
|
expect(bitmapText.textHeight).toBe(24);
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
it('creates one glyph sprite per character', () => {
|
|
85
|
+
it('creates one glyph sprite per character', (): void => {
|
|
86
86
|
expect(createText('AB')._glyphs).toHaveLength(2);
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
it('reuses the glyph pool when the text shrinks', () => {
|
|
89
|
+
it('reuses the glyph pool when the text shrinks', (): void => {
|
|
90
90
|
const bitmapText = createText('AB');
|
|
91
91
|
const pooled = bitmapText._glyphs;
|
|
92
92
|
bitmapText.text = 'A';
|
|
@@ -95,115 +95,115 @@ describe('BitmapText', () => {
|
|
|
95
95
|
expect(bitmapText.children).toHaveLength(1);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
it('drops the glyphs that left the display list when purged', () => {
|
|
98
|
+
it('drops the glyphs that left the display list when purged', (): void => {
|
|
99
99
|
const bitmapText = createText('AB');
|
|
100
100
|
bitmapText.text = 'A';
|
|
101
101
|
expect(bitmapText.purgeGlyphs()).toBe(1);
|
|
102
102
|
expect(bitmapText._glyphs).toHaveLength(1);
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
it('lays out an empty string as a single empty line', () => {
|
|
105
|
+
it('lays out an empty string as a single empty line', (): void => {
|
|
106
106
|
const bitmapText = createText('');
|
|
107
107
|
expect(bitmapText.textWidth).toBe(0);
|
|
108
108
|
expect(bitmapText.textHeight).toBe(12);
|
|
109
109
|
expect(bitmapText._glyphs).toHaveLength(0);
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
it('does nothing when the font is not in the cache', () => {
|
|
112
|
+
it('does nothing when the font is not in the cache', (): void => {
|
|
113
113
|
const bitmapText = new BitmapText(createGame(null), 0, 0, 'missing', 'AB');
|
|
114
114
|
expect(bitmapText.textWidth).toBe(0);
|
|
115
115
|
expect(bitmapText._glyphs).toHaveLength(0);
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
-
describe('scanLine', () => {
|
|
120
|
-
it('reports the whole text when nothing forces a wrap', () => {
|
|
119
|
+
describe('scanLine', (): void => {
|
|
120
|
+
it('reports the whole text when nothing forces a wrap', (): void => {
|
|
121
121
|
const line = createText('AB').scanLine(FONT, 1, 'AB');
|
|
122
122
|
expect(line).toMatchObject({ width: 20, text: 'AB', end: true, chars: [0, 10] });
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
-
it('stops at a newline and reports the line as unfinished', () => {
|
|
125
|
+
it('stops at a newline and reports the line as unfinished', (): void => {
|
|
126
126
|
const line = createText('AB').scanLine(FONT, 1, 'AB\nA');
|
|
127
127
|
expect(line.text).toBe('AB');
|
|
128
128
|
expect(line.end).toBe(false);
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
-
it('wraps at the last space once maxWidth is exceeded', () => {
|
|
131
|
+
it('wraps at the last space once maxWidth is exceeded', (): void => {
|
|
132
132
|
const bitmapText = createText('A A');
|
|
133
133
|
bitmapText.maxWidth = 20;
|
|
134
134
|
expect(bitmapText.scanLine(FONT, 1, 'A A').text).toBe('A');
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
-
it('substitutes a space for a character the font does not carry', () => {
|
|
137
|
+
it('substitutes a space for a character the font does not carry', (): void => {
|
|
138
138
|
const line = createText('A').scanLine(FONT, 1, 'Z');
|
|
139
139
|
expect(line.width).toBe(5);
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
-
it('skips a character the font cannot even substitute for', () => {
|
|
142
|
+
it('skips a character the font cannot even substitute for', (): void => {
|
|
143
143
|
const spaceless: BitmapFontData = { ...FONT, chars: Object.fromEntries([glyph(65, 10)]) };
|
|
144
144
|
expect(createText('A').scanLine(spaceless, 1, 'AZ').width).toBe(10);
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
describe('cleanText', () => {
|
|
149
|
-
it('drops characters the font does not carry', () => {
|
|
148
|
+
describe('cleanText', (): void => {
|
|
149
|
+
it('drops characters the font does not carry', (): void => {
|
|
150
150
|
expect(createText('A').cleanText('AZB')).toBe('AB');
|
|
151
151
|
});
|
|
152
152
|
|
|
153
|
-
it('replaces them with the given stand-in', () => {
|
|
153
|
+
it('replaces them with the given stand-in', (): void => {
|
|
154
154
|
expect(createText('A').cleanText('AZB', '?')).toBe('A?B');
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
-
it('keeps line breaks', () => {
|
|
157
|
+
it('keeps line breaks', (): void => {
|
|
158
158
|
expect(createText('A').cleanText('A\nB')).toBe('A\nB');
|
|
159
159
|
});
|
|
160
160
|
});
|
|
161
161
|
|
|
162
|
-
describe('properties', () => {
|
|
163
|
-
it('re-lays out when the alignment changes', () => {
|
|
162
|
+
describe('properties', (): void => {
|
|
163
|
+
it('re-lays out when the alignment changes', (): void => {
|
|
164
164
|
const bitmapText = createText('A\nAB');
|
|
165
165
|
bitmapText.align = 'right';
|
|
166
166
|
expect(bitmapText.align).toBe('right');
|
|
167
167
|
expect(bitmapText._glyphs[0]?.position.x).toBe(10);
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
-
it('ignores an alignment it does not know', () => {
|
|
170
|
+
it('ignores an alignment it does not know', (): void => {
|
|
171
171
|
const bitmapText = createText('A');
|
|
172
172
|
bitmapText.align = 'sideways';
|
|
173
173
|
expect(bitmapText.align).toBe('left');
|
|
174
174
|
});
|
|
175
175
|
|
|
176
|
-
it('coerces a string font size', () => {
|
|
176
|
+
it('coerces a string font size', (): void => {
|
|
177
177
|
const bitmapText = createText('A');
|
|
178
178
|
bitmapText.fontSize = '20';
|
|
179
179
|
expect(bitmapText.fontSize).toBe(20);
|
|
180
180
|
});
|
|
181
181
|
|
|
182
|
-
it('ignores a font size of zero or less', () => {
|
|
182
|
+
it('ignores a font size of zero or less', (): void => {
|
|
183
183
|
const bitmapText = createText('A');
|
|
184
184
|
bitmapText.fontSize = -5;
|
|
185
185
|
expect(bitmapText.fontSize).toBe(10);
|
|
186
186
|
});
|
|
187
187
|
|
|
188
|
-
it('renders the tint as a padded hex string', () => {
|
|
188
|
+
it('renders the tint as a padded hex string', (): void => {
|
|
189
189
|
const bitmapText = createText('A');
|
|
190
190
|
bitmapText.tint = 0x00ff00;
|
|
191
191
|
expect(bitmapText.fill).toBe('#00FF00');
|
|
192
192
|
});
|
|
193
193
|
|
|
194
|
-
it('reads a hex string back into the tint', () => {
|
|
194
|
+
it('reads a hex string back into the tint', (): void => {
|
|
195
195
|
const bitmapText = createText('A');
|
|
196
196
|
bitmapText.fill = '#FF0000';
|
|
197
197
|
expect(bitmapText.tint).toBe(0xff0000);
|
|
198
198
|
});
|
|
199
199
|
|
|
200
|
-
it('trims the font key before looking it up', () => {
|
|
200
|
+
it('trims the font key before looking it up', (): void => {
|
|
201
201
|
const bitmapText = createText('A');
|
|
202
202
|
bitmapText.font = ' other ';
|
|
203
203
|
expect(bitmapText.font).toBe('other');
|
|
204
204
|
});
|
|
205
205
|
|
|
206
|
-
it('stringifies whatever the text is set to', () => {
|
|
206
|
+
it('stringifies whatever the text is set to', (): void => {
|
|
207
207
|
const bitmapText = createText('A');
|
|
208
208
|
bitmapText.text = 65;
|
|
209
209
|
expect(bitmapText.text).toBe('65');
|
|
@@ -80,7 +80,7 @@ export class BitmapText extends DisplayObject {
|
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
if (!this.exists ||
|
|
83
|
+
if (!this.exists || this.parent?.exists !== true) {
|
|
84
84
|
this.renderOrderID = -1;
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
@@ -150,7 +150,7 @@ export class BitmapText extends DisplayObject {
|
|
|
150
150
|
// What will the line width be if we add this character to it?
|
|
151
151
|
c = (kerning + (charData.texture?.width ?? 0) + charData.xOffset) * scale;
|
|
152
152
|
// Do we need to line-wrap?
|
|
153
|
-
if (maxWidth && w + c >= maxWidth && lastSpace > -1) {
|
|
153
|
+
if (maxWidth !== null && w + c >= maxWidth && lastSpace > -1) {
|
|
154
154
|
// The last space was at "lastSpace" which was "i - lastSpace" characters ago
|
|
155
155
|
return {
|
|
156
156
|
width: wrappedWidth || w,
|
|
@@ -463,7 +463,7 @@ export class BitmapText extends DisplayObject {
|
|
|
463
463
|
* @returns {boolean} True if smoothing is enabled, false otherwise.
|
|
464
464
|
*/
|
|
465
465
|
public get smoothed(): boolean {
|
|
466
|
-
return
|
|
466
|
+
return this._data?.base.scaleMode === 0;
|
|
467
467
|
}
|
|
468
468
|
|
|
469
469
|
/**
|
|
@@ -4,6 +4,7 @@ import { Signal } from '../core/signal.js';
|
|
|
4
4
|
import { Image } from './image.js';
|
|
5
5
|
import type { Game } from '../core/game.js';
|
|
6
6
|
import type { SignalListener } from '../core/signal.js';
|
|
7
|
+
import type { Pointer } from '../core/input_pointer.js';
|
|
7
8
|
|
|
8
9
|
const STATE_OVER = 'Over';
|
|
9
10
|
const STATE_OUT = 'Out';
|
|
@@ -25,7 +26,7 @@ export class Button extends Image {
|
|
|
25
26
|
public onOverMouseOnly!: boolean;
|
|
26
27
|
public justReleasedPreventsOver!: number;
|
|
27
28
|
public freezeFrames!: boolean;
|
|
28
|
-
public forceOut!:
|
|
29
|
+
public forceOut!: boolean | number;
|
|
29
30
|
public input!: InputHandler;
|
|
30
31
|
/**
|
|
31
32
|
* Creates a new Button instance.
|
|
@@ -92,7 +93,7 @@ export class Button extends Image {
|
|
|
92
93
|
this._onDownFrame = null;
|
|
93
94
|
this._onUpFrame = null;
|
|
94
95
|
this._onDisabledFrame = null;
|
|
95
|
-
if (this.onInputOver) {
|
|
96
|
+
if (this.onInputOver !== null) {
|
|
96
97
|
this.onInputOver.dispose();
|
|
97
98
|
this.onInputOut.dispose();
|
|
98
99
|
this.onInputDown.dispose();
|
|
@@ -102,7 +103,7 @@ export class Button extends Image {
|
|
|
102
103
|
this.onInputOut = null!;
|
|
103
104
|
this.onInputDown = null!;
|
|
104
105
|
this.onInputUp = null!;
|
|
105
|
-
if (this.input) {
|
|
106
|
+
if (this.input !== null) {
|
|
106
107
|
this.input.destroy();
|
|
107
108
|
}
|
|
108
109
|
this.input = null!;
|
|
@@ -147,7 +148,7 @@ export class Button extends Image {
|
|
|
147
148
|
*/
|
|
148
149
|
public setStateFrame(state: string, frame: string | null, switchImmediately = false): void {
|
|
149
150
|
const frameKey: `_on${string}Frame` = `_on${state}Frame`;
|
|
150
|
-
if (frame) {
|
|
151
|
+
if (frame !== null) {
|
|
151
152
|
this[frameKey] = frame;
|
|
152
153
|
if (switchImmediately) {
|
|
153
154
|
this.changeStateFrame(state);
|
|
@@ -166,7 +167,7 @@ export class Button extends Image {
|
|
|
166
167
|
if (this.freezeFrames) {
|
|
167
168
|
return false;
|
|
168
169
|
}
|
|
169
|
-
const state = this.input.enabled ||
|
|
170
|
+
const state = this.input.enabled || this._onDisabledFrame === null ? newState : STATE_DISABLED;
|
|
170
171
|
const frameKey: `_on${string}Frame` = `_on${state}Frame`;
|
|
171
172
|
const frame = this[frameKey];
|
|
172
173
|
if (typeof frame === 'string') {
|
|
@@ -198,7 +199,7 @@ export class Button extends Image {
|
|
|
198
199
|
this.setStateFrame(STATE_OUT, outFrame, !this.input.pointerOver());
|
|
199
200
|
this.setStateFrame(STATE_DOWN, downFrame, this.input.pointerDown());
|
|
200
201
|
this.setStateFrame(STATE_UP, upFrame, this.input.pointerUp());
|
|
201
|
-
if (disabledFrame) {
|
|
202
|
+
if (disabledFrame !== null) {
|
|
202
203
|
this.setStateFrame(STATE_DISABLED, disabledFrame, !this.input.enabled);
|
|
203
204
|
}
|
|
204
205
|
}
|
|
@@ -208,7 +209,7 @@ export class Button extends Image {
|
|
|
208
209
|
* @param {object} _sprite - The sprite that triggered the event.
|
|
209
210
|
* @param {object} pointer - The pointer that triggered the event.
|
|
210
211
|
*/
|
|
211
|
-
public onInputOverHandler(_sprite:
|
|
212
|
+
public onInputOverHandler(_sprite: Image, pointer: Pointer): void {
|
|
212
213
|
if (pointer.justReleased() && (this.justReleasedPreventsOver & pointer.pointerMode) === pointer.pointerMode) {
|
|
213
214
|
// If the Pointer was only just released then we don't fire an over event
|
|
214
215
|
return;
|
|
@@ -217,7 +218,7 @@ export class Button extends Image {
|
|
|
217
218
|
if (this.onOverMouseOnly && !pointer.isMouse) {
|
|
218
219
|
return;
|
|
219
220
|
}
|
|
220
|
-
if (this.onInputOver) {
|
|
221
|
+
if (this.onInputOver !== null) {
|
|
221
222
|
this.onInputOver.dispatch(this, pointer);
|
|
222
223
|
}
|
|
223
224
|
}
|
|
@@ -227,9 +228,9 @@ export class Button extends Image {
|
|
|
227
228
|
* @param {object} _sprite - The sprite that triggered the event.
|
|
228
229
|
* @param {object} pointer - The pointer that triggered the event.
|
|
229
230
|
*/
|
|
230
|
-
public onInputOutHandler(_sprite:
|
|
231
|
+
public onInputOutHandler(_sprite: Image, pointer: Pointer): void {
|
|
231
232
|
this.changeStateFrame(STATE_OUT);
|
|
232
|
-
if (this.onInputOut) {
|
|
233
|
+
if (this.onInputOut !== null) {
|
|
233
234
|
this.onInputOut.dispatch(this, pointer);
|
|
234
235
|
}
|
|
235
236
|
}
|
|
@@ -239,9 +240,9 @@ export class Button extends Image {
|
|
|
239
240
|
* @param {object} _sprite - The sprite that triggered the event.
|
|
240
241
|
* @param {object} pointer - The pointer that triggered the event.
|
|
241
242
|
*/
|
|
242
|
-
public onInputDownHandler(_sprite:
|
|
243
|
+
public onInputDownHandler(_sprite: Image, pointer: Pointer): void {
|
|
243
244
|
this.changeStateFrame(STATE_DOWN);
|
|
244
|
-
if (this.onInputDown) {
|
|
245
|
+
if (this.onInputDown !== null) {
|
|
245
246
|
this.onInputDown.dispatch(this, pointer);
|
|
246
247
|
}
|
|
247
248
|
}
|
|
@@ -252,14 +253,15 @@ export class Button extends Image {
|
|
|
252
253
|
* @param {object} pointer - The pointer that triggered the event.
|
|
253
254
|
* @param {boolean} isOver - Whether the pointer is currently over the button (default: true).
|
|
254
255
|
*/
|
|
255
|
-
public onInputUpHandler(_sprite:
|
|
256
|
-
if (this.onInputUp) {
|
|
256
|
+
public onInputUpHandler(_sprite: Image, pointer: Pointer, isOver: boolean): void {
|
|
257
|
+
if (this.onInputUp !== null) {
|
|
257
258
|
this.onInputUp.dispatch(this, pointer, isOver);
|
|
258
259
|
}
|
|
259
260
|
if (this.freezeFrames) {
|
|
260
261
|
return;
|
|
261
262
|
}
|
|
262
|
-
|
|
263
|
+
const forcedOutMode = typeof this.forceOut === 'number' ? this.forceOut : 0;
|
|
264
|
+
if (this.forceOut === true || (forcedOutMode & pointer.pointerMode) === pointer.pointerMode) {
|
|
263
265
|
this.changeStateFrame(STATE_OUT);
|
|
264
266
|
} else {
|
|
265
267
|
const changedUp = this.changeStateFrame(STATE_UP);
|
|
@@ -279,7 +281,7 @@ export class Button extends Image {
|
|
|
279
281
|
* @returns {boolean} True if input is enabled, false otherwise.
|
|
280
282
|
*/
|
|
281
283
|
public get inputEnabled(): boolean {
|
|
282
|
-
return this.input && this.input.enabled;
|
|
284
|
+
return this.input !== null && this.input.enabled;
|
|
283
285
|
}
|
|
284
286
|
|
|
285
287
|
/**
|
|
@@ -291,10 +293,10 @@ export class Button extends Image {
|
|
|
291
293
|
if (this.input === null) {
|
|
292
294
|
this.input = new InputHandler(this);
|
|
293
295
|
this.input.start();
|
|
294
|
-
} else if (this.input && !this.input.enabled) {
|
|
296
|
+
} else if (this.input !== null && !this.input.enabled) {
|
|
295
297
|
this.input.start();
|
|
296
298
|
}
|
|
297
|
-
} else if (this.input && this.input.enabled) {
|
|
299
|
+
} else if (this.input !== null && this.input.enabled) {
|
|
298
300
|
this.input.stop();
|
|
299
301
|
}
|
|
300
302
|
}
|
|
@@ -3,7 +3,7 @@ import { create, removeByCanvas } from './pool.js';
|
|
|
3
3
|
export class CanvasBuffer {
|
|
4
4
|
public width!: number;
|
|
5
5
|
public height!: number;
|
|
6
|
-
public canvas!:
|
|
6
|
+
public canvas!: HTMLCanvasElement;
|
|
7
7
|
public context!: CanvasRenderingContext2D;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a new CanvasBuffer instance.
|
|
@@ -14,7 +14,7 @@ export class CanvasBuffer {
|
|
|
14
14
|
this.width = width;
|
|
15
15
|
this.height = height;
|
|
16
16
|
this.canvas = create(this, this.width, this.height);
|
|
17
|
-
this.context = this.canvas.getContext('2d', { willReadFrequently: false })
|
|
17
|
+
this.context = this.canvas.getContext('2d', { willReadFrequently: false })!;
|
|
18
18
|
this.canvas.width = width;
|
|
19
19
|
this.canvas.height = height;
|
|
20
20
|
}
|
|
@@ -71,7 +71,7 @@ export const renderGraphics = (graphics: Graphics, context: CanvasRenderingConte
|
|
|
71
71
|
context.stroke();
|
|
72
72
|
}
|
|
73
73
|
} else if (shape instanceof Rectangle) {
|
|
74
|
-
if (data.fillColor
|
|
74
|
+
if (data.fillColor !== null) {
|
|
75
75
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
76
76
|
context.fillStyle = `#${`00000${Math.trunc(fillColor ?? 0).toString(16)}`.slice(-6)}`;
|
|
77
77
|
context.fillRect(shape.x, shape.y, shape.width, shape.height);
|
|
@@ -144,7 +144,7 @@ export const renderGraphics = (graphics: Graphics, context: CanvasRenderingConte
|
|
|
144
144
|
context.lineTo(rx + radius, ry);
|
|
145
145
|
context.quadraticCurveTo(rx, ry, rx, ry + radius);
|
|
146
146
|
context.closePath();
|
|
147
|
-
if (data.fillColor
|
|
147
|
+
if (data.fillColor !== null) {
|
|
148
148
|
context.globalAlpha = data.fillAlpha * worldAlpha;
|
|
149
149
|
context.fillStyle = `#${`00000${Math.trunc(fillColor ?? 0).toString(16)}`.slice(-6)}`;
|
|
150
150
|
context.fill();
|
|
@@ -7,7 +7,7 @@ import type { Graphics } from '../graphics.js';
|
|
|
7
7
|
* @param {object} maskData - The mask data to apply.
|
|
8
8
|
* @param {object} renderSession - The rendering session object.
|
|
9
9
|
*/
|
|
10
|
-
export const pushMask = (maskData:
|
|
10
|
+
export const pushMask = (maskData: Graphics, renderSession: RenderSession): void => {
|
|
11
11
|
const { context } = renderSession;
|
|
12
12
|
context.save();
|
|
13
13
|
const cacheAlpha = maskData.alpha;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it } from 'vitest';
|
|
2
2
|
import { create, getFirst, getFree, getPool, getTotal, remove, removeByCanvas } from './pool.js';
|
|
3
3
|
|
|
4
|
-
describe('canvas pool', () => {
|
|
5
|
-
beforeEach(() => {
|
|
4
|
+
describe('canvas pool', (): void => {
|
|
5
|
+
beforeEach((): void => {
|
|
6
6
|
getPool().length = 0;
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
describe('getPool', () => {
|
|
10
|
-
it('lazily creates the backing array and returns the same one thereafter', () => {
|
|
9
|
+
describe('getPool', (): void => {
|
|
10
|
+
it('lazily creates the backing array and returns the same one thereafter', (): void => {
|
|
11
11
|
expect(getPool()).toBe(getPool());
|
|
12
12
|
expect(getPool()).toStrictEqual([]);
|
|
13
13
|
});
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
describe('create', () => {
|
|
17
|
-
it('adds a new entry when the pool is empty', () => {
|
|
16
|
+
describe('create', (): void => {
|
|
17
|
+
it('adds a new entry when the pool is empty', (): void => {
|
|
18
18
|
const parent = { name: 'owner' };
|
|
19
19
|
const canvas = create(parent);
|
|
20
20
|
expect(getPool()).toHaveLength(1);
|
|
@@ -22,7 +22,7 @@ describe('canvas pool', () => {
|
|
|
22
22
|
expect(getPool()[0]?.canvas).toBe(canvas);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
it('reuses a free entry instead of growing the pool', () => {
|
|
25
|
+
it('reuses a free entry instead of growing the pool', (): void => {
|
|
26
26
|
const first = { name: 'first' };
|
|
27
27
|
const canvas = create(first);
|
|
28
28
|
remove(first);
|
|
@@ -32,7 +32,7 @@ describe('canvas pool', () => {
|
|
|
32
32
|
expect(getPool()[0]?.parent).toBe(second);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
it('grows the pool when skipPool is set even if an entry is free', () => {
|
|
35
|
+
it('grows the pool when skipPool is set even if an entry is free', (): void => {
|
|
36
36
|
const first = { name: 'first' };
|
|
37
37
|
create(first);
|
|
38
38
|
remove(first);
|
|
@@ -40,20 +40,20 @@ describe('canvas pool', () => {
|
|
|
40
40
|
expect(getPool()).toHaveLength(2);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
it('applies the requested dimensions', () => {
|
|
43
|
+
it('applies the requested dimensions', (): void => {
|
|
44
44
|
const canvas = create({ name: 'sized' }, 64, 32);
|
|
45
45
|
expect(canvas.width).toBe(64);
|
|
46
46
|
expect(canvas.height).toBe(32);
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
describe('getFirst', () => {
|
|
51
|
-
it('reports -1 when every entry is claimed', () => {
|
|
50
|
+
describe('getFirst', (): void => {
|
|
51
|
+
it('reports -1 when every entry is claimed', (): void => {
|
|
52
52
|
create({ name: 'owner' });
|
|
53
53
|
expect(getFirst()).toBe(-1);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
it('reports the index of the first free entry', () => {
|
|
56
|
+
it('reports the index of the first free entry', (): void => {
|
|
57
57
|
create({ name: 'a' });
|
|
58
58
|
const b = { name: 'b' };
|
|
59
59
|
create(b);
|
|
@@ -63,8 +63,8 @@ describe('canvas pool', () => {
|
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
describe('remove', () => {
|
|
67
|
-
it('frees the entry and shrinks its canvas to 1x1', () => {
|
|
66
|
+
describe('remove', (): void => {
|
|
67
|
+
it('frees the entry and shrinks its canvas to 1x1', (): void => {
|
|
68
68
|
const parent = { name: 'owner' };
|
|
69
69
|
const canvas = create(parent, 100, 50);
|
|
70
70
|
remove(parent);
|
|
@@ -73,17 +73,17 @@ describe('canvas pool', () => {
|
|
|
73
73
|
expect(canvas.height).toBe(1);
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
it('ignores a parent that owns nothing', () => {
|
|
76
|
+
it('ignores a parent that owns nothing', (): void => {
|
|
77
77
|
create({ name: 'owner' });
|
|
78
|
-
expect(() => {
|
|
78
|
+
expect((): void => {
|
|
79
79
|
remove({ name: 'stranger' });
|
|
80
80
|
}).not.toThrow();
|
|
81
81
|
expect(getPool()[0]?.parent).not.toBeNull();
|
|
82
82
|
});
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
describe('removeByCanvas', () => {
|
|
86
|
-
it('frees the entry holding that canvas', () => {
|
|
85
|
+
describe('removeByCanvas', (): void => {
|
|
86
|
+
it('frees the entry holding that canvas', (): void => {
|
|
87
87
|
const canvas = create({ name: 'owner' }, 100, 50);
|
|
88
88
|
removeByCanvas(canvas);
|
|
89
89
|
expect(getPool()[0]?.parent).toBeNull();
|
|
@@ -91,8 +91,8 @@ describe('canvas pool', () => {
|
|
|
91
91
|
});
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
-
describe('getTotal and getFree', () => {
|
|
95
|
-
it('count claimed and unclaimed entries', () => {
|
|
94
|
+
describe('getTotal and getFree', (): void => {
|
|
95
|
+
it('count claimed and unclaimed entries', (): void => {
|
|
96
96
|
const a = { name: 'a' };
|
|
97
97
|
create(a);
|
|
98
98
|
create({ name: 'b' });
|
|
@@ -16,7 +16,7 @@ export const getPool = (): CanvasPoolEntry[] => {
|
|
|
16
16
|
export const getFirst = (): number => {
|
|
17
17
|
const pool = getPool();
|
|
18
18
|
for (let i = 0; i < pool.length; i += 1) {
|
|
19
|
-
if (
|
|
19
|
+
if (pool[i]!.parent === null) {
|
|
20
20
|
return i;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -27,7 +27,7 @@ export const getFirst = (): number => {
|
|
|
27
27
|
* Adds a canvas to the pool with the specified parent.
|
|
28
28
|
* @param {object} parent - The parent object for the canvas.
|
|
29
29
|
*/
|
|
30
|
-
export const remove = (parent:
|
|
30
|
+
export const remove = (parent: CanvasOwner): void => {
|
|
31
31
|
const pool = getPool();
|
|
32
32
|
for (const entry of pool) {
|
|
33
33
|
if (entry.parent === parent) {
|
|
@@ -61,7 +61,7 @@ export const getTotal = (): number => {
|
|
|
61
61
|
const pool = getPool();
|
|
62
62
|
let c = 0;
|
|
63
63
|
for (const entry of pool) {
|
|
64
|
-
if (entry.parent) {
|
|
64
|
+
if (entry.parent !== null) {
|
|
65
65
|
c += 1;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -76,7 +76,7 @@ export const getFree = (): number => {
|
|
|
76
76
|
const pool = getPool();
|
|
77
77
|
let c = 0;
|
|
78
78
|
for (const entry of pool) {
|
|
79
|
-
if (
|
|
79
|
+
if (entry.parent === null) {
|
|
80
80
|
c += 1;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -91,7 +91,7 @@ export const getFree = (): number => {
|
|
|
91
91
|
* @param {boolean} skipPool - True to skip using the pool and create a new canvas.
|
|
92
92
|
* @returns {HTMLCanvasElement} The canvas from the pool or a newly created one.
|
|
93
93
|
*/
|
|
94
|
-
export const create = (parent:
|
|
94
|
+
export const create = (parent: CanvasOwner, width?: number, height?: number, skipPool = false): HTMLCanvasElement => {
|
|
95
95
|
if (parent === undefined) {
|
|
96
96
|
console.warn('Created CanvasPool element with undefined parent.');
|
|
97
97
|
}
|
|
@@ -111,7 +111,7 @@ export const create = (parent: any, width?: any, height?: any, skipPool = false)
|
|
|
111
111
|
const { canvas } = entry;
|
|
112
112
|
if (width !== undefined) {
|
|
113
113
|
canvas.width = width;
|
|
114
|
-
canvas.height = height;
|
|
114
|
+
canvas.height = height ?? 0;
|
|
115
115
|
}
|
|
116
116
|
return canvas;
|
|
117
117
|
};
|
|
@@ -26,21 +26,23 @@ import { ENGINE_ERROR_CREATING_CANVAS_2D_CONTEXT } from '../../core/error_code.j
|
|
|
26
26
|
import * as CanvasMaskManager from './masker.js';
|
|
27
27
|
import { detectCapabilities } from './tinter.js';
|
|
28
28
|
import { getSmoothingPrefix, setSmoothing } from './util.js';
|
|
29
|
+
import type { DisplayObject } from '../display_object.js';
|
|
29
30
|
import type { RenderSession } from '../render_session.js';
|
|
31
|
+
import type { StageBackgroundColor } from '../../core/stage.js';
|
|
30
32
|
|
|
31
33
|
export class CanvasRenderer {
|
|
32
|
-
public type!:
|
|
34
|
+
public type!: number;
|
|
33
35
|
public resolution!: number;
|
|
34
|
-
public clearBeforeRender!:
|
|
35
|
-
public transparent!:
|
|
36
|
-
public autoResize!:
|
|
37
|
-
public contextLost!:
|
|
36
|
+
public clearBeforeRender!: boolean;
|
|
37
|
+
public transparent!: boolean;
|
|
38
|
+
public autoResize!: boolean;
|
|
39
|
+
public contextLost!: boolean;
|
|
38
40
|
public width!: number;
|
|
39
41
|
public height!: number;
|
|
40
42
|
public view!: HTMLCanvasElement;
|
|
41
43
|
public context!: CanvasRenderingContext2D;
|
|
42
|
-
public refresh!:
|
|
43
|
-
public count!:
|
|
44
|
+
public refresh!: boolean;
|
|
45
|
+
public count!: number;
|
|
44
46
|
public renderSession!: RenderSession;
|
|
45
47
|
/**
|
|
46
48
|
* Creates a new CanvasRenderer instance.
|
|
@@ -52,7 +54,7 @@ export class CanvasRenderer {
|
|
|
52
54
|
this.type = RENDER_CANVAS;
|
|
53
55
|
this.resolution = game.config.resolution;
|
|
54
56
|
this.clearBeforeRender = game.config.clearBeforeRender;
|
|
55
|
-
this.transparent = game.config.transparent;
|
|
57
|
+
this.transparent = Boolean(game.config.transparent);
|
|
56
58
|
this.autoResize = false;
|
|
57
59
|
this.contextLost = false;
|
|
58
60
|
this.width = game.width * this.resolution;
|
|
@@ -62,8 +64,8 @@ export class CanvasRenderer {
|
|
|
62
64
|
this.context = this.view.getContext('2d', {
|
|
63
65
|
willReadFrequently: false,
|
|
64
66
|
alpha: this.transparent,
|
|
65
|
-
})
|
|
66
|
-
if (!this.context) {
|
|
67
|
+
})!;
|
|
68
|
+
if (!(this.context as CanvasRenderingContext2D | undefined)) {
|
|
67
69
|
throw new Error(ENGINE_ERROR_CREATING_CANVAS_2D_CONTEXT);
|
|
68
70
|
}
|
|
69
71
|
this.refresh = true;
|
|
@@ -85,7 +87,7 @@ export class CanvasRenderer {
|
|
|
85
87
|
* @param {Stage} root - The root stage to render.
|
|
86
88
|
*/
|
|
87
89
|
public render(root: Stage): void {
|
|
88
|
-
if (!this.context) {
|
|
90
|
+
if (!(this.context as CanvasRenderingContext2D | undefined)) {
|
|
89
91
|
return;
|
|
90
92
|
}
|
|
91
93
|
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
|
@@ -97,7 +99,7 @@ export class CanvasRenderer {
|
|
|
97
99
|
if (this.clearBeforeRender) {
|
|
98
100
|
if (this.transparent) {
|
|
99
101
|
this.context.clearRect(0, 0, this.width, this.height);
|
|
100
|
-
} else if (root._bgColor) {
|
|
102
|
+
} else if (root._bgColor as StageBackgroundColor | undefined) {
|
|
101
103
|
this.context.fillStyle = root._bgColor.rgba;
|
|
102
104
|
this.context.fillRect(0, 0, this.width, this.height);
|
|
103
105
|
}
|
|
@@ -129,7 +131,7 @@ export class CanvasRenderer {
|
|
|
129
131
|
this.view.style.width = `${this.width / this.resolution}px`;
|
|
130
132
|
this.view.style.height = `${this.height / this.resolution}px`;
|
|
131
133
|
}
|
|
132
|
-
if (this.renderSession.smoothProperty) {
|
|
134
|
+
if (this.renderSession.smoothProperty !== null) {
|
|
133
135
|
setSmoothing(this.context, this.renderSession.smoothProperty, this.renderSession.scaleMode === SCALE_LINEAR);
|
|
134
136
|
}
|
|
135
137
|
}
|
|
@@ -140,17 +142,17 @@ export class CanvasRenderer {
|
|
|
140
142
|
* @param {CanvasRenderingContext2D} context - The canvas rendering context.
|
|
141
143
|
* @param {Matrix} matrix - The transformation matrix.
|
|
142
144
|
*/
|
|
143
|
-
public renderDisplayObject(displayObject:
|
|
145
|
+
public renderDisplayObject(displayObject: DisplayObject, context?: CanvasRenderingContext2D): void {
|
|
144
146
|
this.renderSession.context = context ?? this.context;
|
|
145
147
|
this.renderSession.resolution = this.resolution;
|
|
146
|
-
displayObject.renderCanvas(this.renderSession
|
|
148
|
+
displayObject.renderCanvas(this.renderSession);
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
/**
|
|
150
152
|
* Maps blend modes to canvas rendering operations.
|
|
151
153
|
*/
|
|
152
154
|
public mapBlendModes(): void {
|
|
153
|
-
if (globalThis.PhaserRegistry.blendModesCanvas) {
|
|
155
|
+
if (globalThis.PhaserRegistry.blendModesCanvas as GlobalCompositeOperation[] | undefined) {
|
|
154
156
|
return;
|
|
155
157
|
}
|
|
156
158
|
const b: GlobalCompositeOperation[] = [];
|
|
@@ -179,7 +179,7 @@ export const canUseNewCanvasBlendModes = (): boolean => {
|
|
|
179
179
|
context.globalCompositeOperation = 'multiply';
|
|
180
180
|
context.drawImage(magenta, 0, 0);
|
|
181
181
|
context.drawImage(yellow, 2, 0);
|
|
182
|
-
if (
|
|
182
|
+
if (context.getImageData(2, 0, 1, 1) === null) {
|
|
183
183
|
return false;
|
|
184
184
|
}
|
|
185
185
|
const { data } = context.getImageData(2, 0, 1, 1);
|