@vpmedia/phaser 1.116.0 → 1.117.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 +56 -96
- 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 +15 -14
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- 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 +10 -9
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/device_util.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +16 -16
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts +11 -13
- 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 +19 -8
- 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.map +1 -1
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/scale_manager.d.ts +37 -12
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene.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/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +2 -2
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +24 -22
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +26 -26
- 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/core/world.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/phaser/display/image.d.ts +2 -2
- 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.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.d.ts +12 -10
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- 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 +13 -12
- 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/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +9 -7
- 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/mask_manager.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 +12 -10
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +18 -33
- 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.map +1 -1
- package/dist/phaser/geom/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/matrix.d.ts +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.map +1 -1
- package/dist/phaser/geom/util/line.d.ts +5 -4
- package/dist/phaser/geom/util/line.d.ts.map +1 -1
- 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/polygon.d.ts.map +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts +10 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/animation.ts +20 -20
- package/src/phaser/core/animation_manager.ts +27 -24
- package/src/phaser/core/animation_parser.ts +2 -2
- package/src/phaser/core/array_set.ts +7 -7
- package/src/phaser/core/cache.ts +55 -51
- package/src/phaser/core/device_util.ts +13 -13
- package/src/phaser/core/dom.ts +26 -22
- package/src/phaser/core/factory.ts +6 -6
- package/src/phaser/core/game.ts +10 -10
- package/src/phaser/core/input.ts +36 -38
- package/src/phaser/core/input_handler.ts +90 -93
- package/src/phaser/core/input_mouse.ts +19 -19
- package/src/phaser/core/input_mspointer.ts +15 -15
- package/src/phaser/core/input_pointer.ts +37 -28
- package/src/phaser/core/input_touch.ts +17 -17
- package/src/phaser/core/loader.ts +52 -52
- package/src/phaser/core/loader_parser.ts +3 -3
- package/src/phaser/core/raf.ts +3 -3
- package/src/phaser/core/scale_manager.ts +86 -67
- package/src/phaser/core/scene.ts +7 -7
- package/src/phaser/core/scene_manager.ts +16 -16
- package/src/phaser/core/signal.ts +29 -19
- package/src/phaser/core/signal_binding.ts +4 -4
- package/src/phaser/core/sound.ts +17 -17
- package/src/phaser/core/sound_manager.ts +71 -72
- package/src/phaser/core/sound_sprite.ts +1 -1
- package/src/phaser/core/stage.ts +7 -7
- package/src/phaser/core/time.ts +16 -16
- package/src/phaser/core/timer.ts +36 -26
- package/src/phaser/core/tween.ts +23 -23
- package/src/phaser/core/tween_data.ts +41 -37
- package/src/phaser/core/tween_manager.ts +11 -11
- package/src/phaser/core/world.ts +1 -1
- package/src/phaser/display/bitmap_text.ts +13 -13
- package/src/phaser/display/button.ts +13 -13
- package/src/phaser/display/canvas/buffer.ts +3 -3
- package/src/phaser/display/canvas/graphics.ts +3 -3
- package/src/phaser/display/canvas/masker.ts +2 -2
- package/src/phaser/display/canvas/pool.ts +6 -6
- package/src/phaser/display/canvas/renderer.ts +6 -6
- package/src/phaser/display/canvas/tinter.ts +39 -8
- package/src/phaser/display/canvas/util.ts +15 -9
- package/src/phaser/display/display_object.ts +38 -38
- package/src/phaser/display/graphics.ts +30 -30
- package/src/phaser/display/graphics_data.ts +1 -1
- package/src/phaser/display/graphics_data_util.ts +1 -1
- package/src/phaser/display/group.ts +16 -16
- package/src/phaser/display/image.ts +30 -26
- package/src/phaser/display/sprite_util.ts +12 -4
- package/src/phaser/display/text.ts +55 -55
- package/src/phaser/display/webgl/abstract_filter.ts +1 -1
- package/src/phaser/display/webgl/base_texture.ts +22 -18
- package/src/phaser/display/webgl/blend_manager.ts +3 -3
- package/src/phaser/display/webgl/earcut.ts +3 -3
- package/src/phaser/display/webgl/fast_sprite_batch.ts +26 -24
- package/src/phaser/display/webgl/filter_manager.ts +7 -7
- package/src/phaser/display/webgl/filter_texture.ts +3 -3
- package/src/phaser/display/webgl/graphics.ts +43 -41
- package/src/phaser/display/webgl/graphics_data.ts +2 -2
- package/src/phaser/display/webgl/mask_manager.ts +2 -2
- package/src/phaser/display/webgl/render_texture.ts +6 -6
- package/src/phaser/display/webgl/renderer.ts +20 -25
- package/src/phaser/display/webgl/shader/normal.ts +3 -3
- package/src/phaser/display/webgl/shader_manager.ts +2 -2
- package/src/phaser/display/webgl/sprite_batch.ts +9 -9
- package/src/phaser/display/webgl/stencil_manager.ts +4 -4
- package/src/phaser/display/webgl/texture.ts +23 -42
- package/src/phaser/display/webgl/texture_util.ts +2 -2
- package/src/phaser/display/webgl/util.ts +11 -7
- package/src/phaser/geom/circle.ts +21 -21
- package/src/phaser/geom/ellipse.ts +7 -7
- package/src/phaser/geom/line.ts +29 -29
- package/src/phaser/geom/matrix.ts +13 -13
- package/src/phaser/geom/point.ts +36 -30
- package/src/phaser/geom/polygon.ts +6 -6
- package/src/phaser/geom/rectangle.ts +42 -42
- package/src/phaser/geom/rounded_rectangle.ts +2 -2
- package/src/phaser/geom/util/circle.ts +7 -7
- package/src/phaser/geom/util/ellipse.ts +1 -1
- package/src/phaser/geom/util/line.ts +13 -5
- package/src/phaser/geom/util/matrix.ts +3 -3
- package/src/phaser/geom/util/point.ts +20 -20
- package/src/phaser/geom/util/polygon.ts +1 -1
- package/src/phaser/geom/util/rectangle.ts +34 -17
- package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
|
@@ -133,7 +133,7 @@ export class NormalShader {
|
|
|
133
133
|
/**
|
|
134
134
|
* Binds this shader to the WebGL context.
|
|
135
135
|
*/
|
|
136
|
-
public initUniforms() {
|
|
136
|
+
public initUniforms(): void {
|
|
137
137
|
this.textureCount = 1;
|
|
138
138
|
const { gl } = this;
|
|
139
139
|
for (const uniform of Object.values(this.uniforms)) {
|
|
@@ -174,7 +174,7 @@ export class NormalShader {
|
|
|
174
174
|
* Sets a uniform value for this shader.
|
|
175
175
|
* @param {object} uniform - The uniform to set.
|
|
176
176
|
*/
|
|
177
|
-
public initSampler2D(uniform: any) {
|
|
177
|
+
public initSampler2D(uniform: any): void {
|
|
178
178
|
if (!uniform.value || !uniform.value.baseTexture || !uniform.value.baseTexture.hasLoaded) {
|
|
179
179
|
return;
|
|
180
180
|
}
|
|
@@ -226,7 +226,7 @@ export class NormalShader {
|
|
|
226
226
|
/**
|
|
227
227
|
* Sets the shader to use for rendering.
|
|
228
228
|
*/
|
|
229
|
-
public syncUniforms() {
|
|
229
|
+
public syncUniforms(): void {
|
|
230
230
|
this.textureCount = 1;
|
|
231
231
|
const { gl } = this;
|
|
232
232
|
// This would probably be faster in an array and it would guarantee key order
|
|
@@ -41,7 +41,7 @@ export class WebGLShaderManager {
|
|
|
41
41
|
* Initializes the shader manager with a WebGL context.
|
|
42
42
|
* @param {WebGLRenderingContext & { id: number }} gl - The WebGL rendering context.
|
|
43
43
|
*/
|
|
44
|
-
public setContext(gl: IdentifiedWebGLRenderingContext) {
|
|
44
|
+
public setContext(gl: IdentifiedWebGLRenderingContext): void {
|
|
45
45
|
this.gl = gl;
|
|
46
46
|
this.primitiveShader = new PrimitiveShader(gl);
|
|
47
47
|
this.complexPrimitiveShader = new ComplexPrimitiveShader(gl);
|
|
@@ -55,7 +55,7 @@ export class WebGLShaderManager {
|
|
|
55
55
|
* Sets up the shader manager for WebGL rendering.
|
|
56
56
|
* @param {number[]} attribs - The attribute locations to set up.
|
|
57
57
|
*/
|
|
58
|
-
public setAttribs(attribs: (number | undefined)[]) {
|
|
58
|
+
public setAttribs(attribs: (number | undefined)[]): void {
|
|
59
59
|
// reset temp state
|
|
60
60
|
let i;
|
|
61
61
|
for (i = 0; i < this.tempAttribState.length; i += 1) {
|
|
@@ -74,7 +74,7 @@ export class WebGLSpriteBatch {
|
|
|
74
74
|
* Renders a sprite using WebGL.
|
|
75
75
|
* @param {WebGLRenderingContext & { id: number }} gl - The WebGL rendering context.
|
|
76
76
|
*/
|
|
77
|
-
public setContext(gl: IdentifiedWebGLRenderingContext) {
|
|
77
|
+
public setContext(gl: IdentifiedWebGLRenderingContext): void {
|
|
78
78
|
this.gl = gl;
|
|
79
79
|
// create a couple of buffers
|
|
80
80
|
this.vertexBuffer = gl.createBuffer();
|
|
@@ -97,7 +97,7 @@ export class WebGLSpriteBatch {
|
|
|
97
97
|
* Renders the sprite batch using WebGL.
|
|
98
98
|
* @param {object} renderSession - The render session to use.
|
|
99
99
|
*/
|
|
100
|
-
public begin(renderSession: RenderSession) {
|
|
100
|
+
public begin(renderSession: RenderSession): void {
|
|
101
101
|
this.renderSession = renderSession;
|
|
102
102
|
this.shader = this.renderSession.shaderManager.defaultShader;
|
|
103
103
|
this.start();
|
|
@@ -106,7 +106,7 @@ export class WebGLSpriteBatch {
|
|
|
106
106
|
/**
|
|
107
107
|
* Updates the sprite batch.
|
|
108
108
|
*/
|
|
109
|
-
public end() {
|
|
109
|
+
public end(): void {
|
|
110
110
|
this.flush();
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -115,7 +115,7 @@ export class WebGLSpriteBatch {
|
|
|
115
115
|
* @param {Image} sprite - The sprite to render.
|
|
116
116
|
* @param {Matrix} matrix - The transformation matrix.
|
|
117
117
|
*/
|
|
118
|
-
public render(sprite: Image, matrix: Matrix | null = null) {
|
|
118
|
+
public render(sprite: Image, matrix: Matrix | null = null): void {
|
|
119
119
|
const { texture } = sprite;
|
|
120
120
|
// They provided an alternative rendering matrix, so use it
|
|
121
121
|
let wt = sprite.worldTransform;
|
|
@@ -215,14 +215,14 @@ export class WebGLSpriteBatch {
|
|
|
215
215
|
/**
|
|
216
216
|
* Binds the sprite batch to the WebGL context.
|
|
217
217
|
*/
|
|
218
|
-
public renderTilingSprite() {
|
|
218
|
+
public renderTilingSprite(): void {
|
|
219
219
|
// TODO
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
/**
|
|
223
223
|
* Updates the sprite batch.
|
|
224
224
|
*/
|
|
225
|
-
public flush() {
|
|
225
|
+
public flush(): void {
|
|
226
226
|
// If the batch is length 0 then return as there is nothing to draw
|
|
227
227
|
if (this.currentBatchSize === 0) {
|
|
228
228
|
return;
|
|
@@ -324,7 +324,7 @@ export class WebGLSpriteBatch {
|
|
|
324
324
|
* @param {number} size - The size of the batch.
|
|
325
325
|
* @param {number} startIndex - The start index in the batch.
|
|
326
326
|
*/
|
|
327
|
-
public renderBatch(texture: BaseTexture, size: number, startIndex: number) {
|
|
327
|
+
public renderBatch(texture: BaseTexture, size: number, startIndex: number): void {
|
|
328
328
|
if (size === 0) {
|
|
329
329
|
return;
|
|
330
330
|
}
|
|
@@ -337,7 +337,7 @@ export class WebGLSpriteBatch {
|
|
|
337
337
|
}
|
|
338
338
|
} else {
|
|
339
339
|
// bind the current texture
|
|
340
|
-
gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
|
|
340
|
+
gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id] ?? null);
|
|
341
341
|
}
|
|
342
342
|
// now draw those suckas!
|
|
343
343
|
gl.drawElements(gl.TRIANGLES, size * 6, gl.UNSIGNED_SHORT, startIndex * 6 * 2);
|
|
@@ -348,7 +348,7 @@ export class WebGLSpriteBatch {
|
|
|
348
348
|
/**
|
|
349
349
|
* Destroys this sprite batch and cleans up resources.
|
|
350
350
|
*/
|
|
351
|
-
public stop() {
|
|
351
|
+
public stop(): void {
|
|
352
352
|
this.flush();
|
|
353
353
|
this.dirty = true;
|
|
354
354
|
}
|
|
@@ -21,7 +21,7 @@ export class WebGLStencilManager {
|
|
|
21
21
|
* Binds the stencil buffer for rendering.
|
|
22
22
|
* @param {WebGLRenderingContext} gl - The WebGL rendering context.
|
|
23
23
|
*/
|
|
24
|
-
public setContext(gl: WebGLRenderingContext) {
|
|
24
|
+
public setContext(gl: WebGLRenderingContext): void {
|
|
25
25
|
this.gl = gl;
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -38,7 +38,7 @@ export class WebGLStencilManager {
|
|
|
38
38
|
* @param {GraphicsData} webGLData - The WebGL graphics data.
|
|
39
39
|
* @param {object} renderSession - The rendering session.
|
|
40
40
|
*/
|
|
41
|
-
public pushStencil(graphics: Graphics, webGLData: GraphicsData, renderSession: RenderSession) {
|
|
41
|
+
public pushStencil(graphics: Graphics, webGLData: GraphicsData, renderSession: RenderSession): void {
|
|
42
42
|
const { gl } = renderSession;
|
|
43
43
|
this.bindGraphics(graphics, webGLData, renderSession);
|
|
44
44
|
if (this.stencilStack.length === 0) {
|
|
@@ -96,7 +96,7 @@ export class WebGLStencilManager {
|
|
|
96
96
|
* @param {GraphicsData} webGLData - The WebGL graphics data.
|
|
97
97
|
* @param {object} renderSession - The rendering session.
|
|
98
98
|
*/
|
|
99
|
-
public bindGraphics(graphics: Graphics, webGLData: GraphicsData, renderSession: RenderSession) {
|
|
99
|
+
public bindGraphics(graphics: Graphics, webGLData: GraphicsData, renderSession: RenderSession): void {
|
|
100
100
|
// if(this._currentGraphics === graphics)return;
|
|
101
101
|
// this._currentGraphics = graphics;
|
|
102
102
|
const { gl } = renderSession;
|
|
@@ -149,7 +149,7 @@ export class WebGLStencilManager {
|
|
|
149
149
|
* @param {GraphicsData} webGLData - The WebGL graphics data.
|
|
150
150
|
* @param {object} renderSession - The rendering session.
|
|
151
151
|
*/
|
|
152
|
-
public popStencil(graphics: Graphics, webGLData: GraphicsData, renderSession: RenderSession) {
|
|
152
|
+
public popStencil(graphics: Graphics, webGLData: GraphicsData, renderSession: RenderSession): void {
|
|
153
153
|
const { gl } = renderSession;
|
|
154
154
|
this.stencilStack.pop();
|
|
155
155
|
this.count -= 1;
|
|
@@ -1,50 +1,31 @@
|
|
|
1
1
|
import { Rectangle } from '../../geom/rectangle.js';
|
|
2
2
|
import type { BaseTexture } from './base_texture.js';
|
|
3
3
|
|
|
4
|
+
/** The four corners of a texture frame in normalised texture space. */
|
|
4
5
|
export class TextureUvs {
|
|
5
|
-
public
|
|
6
|
-
public
|
|
7
|
-
public
|
|
8
|
-
public
|
|
9
|
-
public
|
|
10
|
-
public
|
|
11
|
-
public
|
|
12
|
-
public
|
|
13
|
-
public _uvs!: any;
|
|
14
|
-
public width!: number;
|
|
15
|
-
public height!: number;
|
|
16
|
-
public crop!: any;
|
|
17
|
-
public x0: any = 0;
|
|
18
|
-
public y0: any = 0;
|
|
19
|
-
public x1: any = 0;
|
|
20
|
-
public y1: any = 0;
|
|
21
|
-
public x2: any = 0;
|
|
22
|
-
public y2!: any;
|
|
23
|
-
public x3!: any;
|
|
24
|
-
public y3!: any;
|
|
25
|
-
/**
|
|
26
|
-
* Creates a new Texture instance.
|
|
27
|
-
*/
|
|
28
|
-
public constructor() {
|
|
29
|
-
this.y2 = 0;
|
|
30
|
-
this.x3 = 0;
|
|
31
|
-
this.y3 = 0;
|
|
32
|
-
}
|
|
6
|
+
public x0 = 0;
|
|
7
|
+
public y0 = 0;
|
|
8
|
+
public x1 = 0;
|
|
9
|
+
public y1 = 0;
|
|
10
|
+
public x2 = 0;
|
|
11
|
+
public y2 = 0;
|
|
12
|
+
public x3 = 0;
|
|
13
|
+
public y3 = 0;
|
|
33
14
|
}
|
|
34
15
|
|
|
35
16
|
export class Texture {
|
|
36
|
-
public noFrame
|
|
37
|
-
public baseTexture!:
|
|
38
|
-
public frame!:
|
|
39
|
-
public trim!:
|
|
17
|
+
public noFrame = false;
|
|
18
|
+
public baseTexture!: BaseTexture;
|
|
19
|
+
public frame!: Rectangle;
|
|
20
|
+
public trim!: Rectangle | null;
|
|
40
21
|
public valid!: boolean;
|
|
41
|
-
public isTiling!:
|
|
42
|
-
public requiresUpdate!:
|
|
43
|
-
public requiresReTint!:
|
|
44
|
-
public _uvs!:
|
|
22
|
+
public isTiling!: boolean;
|
|
23
|
+
public requiresUpdate!: boolean;
|
|
24
|
+
public requiresReTint!: boolean;
|
|
25
|
+
public _uvs!: TextureUvs | null;
|
|
45
26
|
public width!: number;
|
|
46
27
|
public height!: number;
|
|
47
|
-
public crop!:
|
|
28
|
+
public crop!: Rectangle;
|
|
48
29
|
/**
|
|
49
30
|
* Creates a new Texture instance.
|
|
50
31
|
* @param {BaseTexture} baseTexture - The base texture to use.
|
|
@@ -97,7 +78,7 @@ export class Texture {
|
|
|
97
78
|
/**
|
|
98
79
|
* Destroys this texture and cleans up resources.
|
|
99
80
|
*/
|
|
100
|
-
public onBaseTextureLoaded() {
|
|
81
|
+
public onBaseTextureLoaded(): void {
|
|
101
82
|
if (this.noFrame) {
|
|
102
83
|
this.frame = new Rectangle(0, 0, this.baseTexture.width, this.baseTexture.height);
|
|
103
84
|
}
|
|
@@ -108,7 +89,7 @@ export class Texture {
|
|
|
108
89
|
* Destroys this texture and cleans up resources.
|
|
109
90
|
* @param {boolean} destroyBase - Whether to destroy the base texture as well.
|
|
110
91
|
*/
|
|
111
|
-
public destroy(destroyBase: boolean = false) {
|
|
92
|
+
public destroy(destroyBase: boolean = false): void {
|
|
112
93
|
if (destroyBase) {
|
|
113
94
|
this.baseTexture.destroy();
|
|
114
95
|
}
|
|
@@ -120,7 +101,7 @@ export class Texture {
|
|
|
120
101
|
* @param {Rectangle} frame - The new frame rectangle.
|
|
121
102
|
* @throws {Error} If the operation fails.
|
|
122
103
|
*/
|
|
123
|
-
public setFrame(frame: Rectangle) {
|
|
104
|
+
public setFrame(frame: Rectangle): void {
|
|
124
105
|
this.noFrame = false;
|
|
125
106
|
this.frame = frame;
|
|
126
107
|
this.width = frame.width;
|
|
@@ -143,7 +124,7 @@ export class Texture {
|
|
|
143
124
|
this.valid = false;
|
|
144
125
|
return;
|
|
145
126
|
}
|
|
146
|
-
this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded;
|
|
127
|
+
this.valid = Boolean(frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded);
|
|
147
128
|
if (this.trim) {
|
|
148
129
|
this.width = this.trim.width;
|
|
149
130
|
this.height = this.trim.height;
|
|
@@ -158,7 +139,7 @@ export class Texture {
|
|
|
158
139
|
/**
|
|
159
140
|
* Updates the texture UVs based on the crop frame.
|
|
160
141
|
*/
|
|
161
|
-
public _updateUvs() {
|
|
142
|
+
public _updateUvs(): void {
|
|
162
143
|
this._uvs ??= new TextureUvs();
|
|
163
144
|
const frame = this.crop;
|
|
164
145
|
const tw = this.baseTexture.width;
|
|
@@ -7,7 +7,7 @@ import { Texture } from './texture.js';
|
|
|
7
7
|
* @param {number} [scaleMode] - The scale mode to use for the texture.
|
|
8
8
|
* @returns {BaseTexture} The newly created BaseTexture instance.
|
|
9
9
|
*/
|
|
10
|
-
export const baseTextureFromCanvas = (canvas: HTMLCanvasElement, scaleMode: number) => {
|
|
10
|
+
export const baseTextureFromCanvas = (canvas: HTMLCanvasElement, scaleMode: number): BaseTexture => {
|
|
11
11
|
if (canvas.width === 0) {
|
|
12
12
|
canvas.width = 1;
|
|
13
13
|
}
|
|
@@ -23,5 +23,5 @@ export const baseTextureFromCanvas = (canvas: HTMLCanvasElement, scaleMode: numb
|
|
|
23
23
|
* @param {number} [scaleMode] - The scale mode to use for the texture.
|
|
24
24
|
* @returns {Texture} The newly created Texture instance.
|
|
25
25
|
*/
|
|
26
|
-
export const textureFromCanvas = (canvas: HTMLCanvasElement, scaleMode?: any) =>
|
|
26
|
+
export const textureFromCanvas = (canvas: HTMLCanvasElement, scaleMode?: any): Texture =>
|
|
27
27
|
new Texture(baseTextureFromCanvas(canvas, scaleMode));
|
|
@@ -22,14 +22,14 @@ export const CONTEXT_LOST_WEBGL = 0x9242;
|
|
|
22
22
|
* @param {WebGLRenderingContext} gl - The WebGL rendering context.
|
|
23
23
|
* @returns {number} The error code from the WebGL context.
|
|
24
24
|
*/
|
|
25
|
-
export const getWebGLContextErrorCode = (gl: WebGLRenderingContext) => gl?.getError() ?? 0;
|
|
25
|
+
export const getWebGLContextErrorCode = (gl: WebGLRenderingContext): number => gl?.getError() ?? 0;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Gets the WebGL context error name from an error code.
|
|
29
29
|
* @param {number} errorCode - The error code to look up.
|
|
30
30
|
* @returns {string} The name of the WebGL error.
|
|
31
31
|
*/
|
|
32
|
-
export const getWebGLContextErrorName = (errorCode: number) => {
|
|
32
|
+
export const getWebGLContextErrorName = (errorCode: number): string => {
|
|
33
33
|
switch (errorCode) {
|
|
34
34
|
case NO_ERROR: {
|
|
35
35
|
return 'NO_ERROR';
|
|
@@ -61,7 +61,7 @@ export const getWebGLContextErrorName = (errorCode: number) => {
|
|
|
61
61
|
/**
|
|
62
62
|
* Initializes default shaders.
|
|
63
63
|
*/
|
|
64
|
-
export const initDefaultShaders = () => {};
|
|
64
|
+
export const initDefaultShaders = (): void => {};
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Compiles a WebGL shader.
|
|
@@ -70,7 +70,11 @@ export const initDefaultShaders = () => {};
|
|
|
70
70
|
* @param {object} shaderType - The type of shader to compile.
|
|
71
71
|
* @returns {WebGLShader} The compiled WebGL shader or null if compilation failed.
|
|
72
72
|
*/
|
|
73
|
-
export const compileShader = (
|
|
73
|
+
export const compileShader = (
|
|
74
|
+
gl: WebGLRenderingContext,
|
|
75
|
+
shaderSrc: string[] | string,
|
|
76
|
+
shaderType: any
|
|
77
|
+
): WebGLShader | null => {
|
|
74
78
|
const src = Array.isArray(shaderSrc) ? shaderSrc.join('\n') : shaderSrc;
|
|
75
79
|
const shader = gl.createShader(shaderType);
|
|
76
80
|
if (!shader) {
|
|
@@ -92,7 +96,7 @@ export const compileShader = (gl: WebGLRenderingContext, shaderSrc: string[] | s
|
|
|
92
96
|
* @param {string[]|string} shaderSrc - The vertex shader source code.
|
|
93
97
|
* @returns {WebGLShader} The compiled WebGL vertex shader or null if compilation failed.
|
|
94
98
|
*/
|
|
95
|
-
export const compileVertexShader = (gl: WebGLRenderingContext, shaderSrc: string[] | string) =>
|
|
99
|
+
export const compileVertexShader = (gl: WebGLRenderingContext, shaderSrc: string[] | string): WebGLShader | null =>
|
|
96
100
|
compileShader(gl, shaderSrc, gl.VERTEX_SHADER);
|
|
97
101
|
|
|
98
102
|
/**
|
|
@@ -101,7 +105,7 @@ export const compileVertexShader = (gl: WebGLRenderingContext, shaderSrc: string
|
|
|
101
105
|
* @param {string[]|string} shaderSrc - The fragment shader source code.
|
|
102
106
|
* @returns {WebGLShader} The compiled WebGL fragment shader or null if compilation failed.
|
|
103
107
|
*/
|
|
104
|
-
export const compileFragmentShader = (gl: WebGLRenderingContext, shaderSrc: string[] | string) =>
|
|
108
|
+
export const compileFragmentShader = (gl: WebGLRenderingContext, shaderSrc: string[] | string): WebGLShader | null =>
|
|
105
109
|
compileShader(gl, shaderSrc, gl.FRAGMENT_SHADER);
|
|
106
110
|
|
|
107
111
|
/**
|
|
@@ -115,7 +119,7 @@ export const compileProgram = (
|
|
|
115
119
|
gl: WebGLRenderingContext,
|
|
116
120
|
vertexSrc: string[] | string,
|
|
117
121
|
fragmentSrc: string[] | string
|
|
118
|
-
) => {
|
|
122
|
+
): WebGLProgram | null => {
|
|
119
123
|
const fragmentShader = compileFragmentShader(gl, fragmentSrc);
|
|
120
124
|
const vertexShader = compileVertexShader(gl, vertexSrc);
|
|
121
125
|
|
|
@@ -37,7 +37,7 @@ export class Circle {
|
|
|
37
37
|
* Calculates the circumference of this circle.
|
|
38
38
|
* @returns {number} The circumference of this circle.
|
|
39
39
|
*/
|
|
40
|
-
public circumference() {
|
|
40
|
+
public circumference(): number {
|
|
41
41
|
return 2 * (Math.PI * this._radius);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -46,7 +46,7 @@ export class Circle {
|
|
|
46
46
|
* @param {Point} output - The point to store the result in (optional).
|
|
47
47
|
* @returns {Point} A random point within this circle.
|
|
48
48
|
*/
|
|
49
|
-
public random(output: Point | null = null) {
|
|
49
|
+
public random(output: Point | null = null): Point {
|
|
50
50
|
const result = output ?? new Point();
|
|
51
51
|
const t = 2 * Math.PI * Math.random();
|
|
52
52
|
const u = Math.random() + Math.random();
|
|
@@ -62,7 +62,7 @@ export class Circle {
|
|
|
62
62
|
* Gets the bounding rectangle of this circle.
|
|
63
63
|
* @returns {Rectangle} The bounding rectangle of this circle.
|
|
64
64
|
*/
|
|
65
|
-
public getBounds() {
|
|
65
|
+
public getBounds(): Rectangle {
|
|
66
66
|
return new Rectangle(this.x - this.radius, this.y - this.radius, this.diameter, this.diameter);
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -73,7 +73,7 @@ export class Circle {
|
|
|
73
73
|
* @param {number} diameter - The new diameter of the circle.
|
|
74
74
|
* @returns {Circle} This circle instance for chaining.
|
|
75
75
|
*/
|
|
76
|
-
public setTo(x: number, y: number, diameter: number) {
|
|
76
|
+
public setTo(x: number, y: number, diameter: number): this {
|
|
77
77
|
this.x = x;
|
|
78
78
|
this.y = y;
|
|
79
79
|
this._diameter = diameter;
|
|
@@ -86,7 +86,7 @@ export class Circle {
|
|
|
86
86
|
* @param {Circle} source - The circle to copy values from.
|
|
87
87
|
* @returns {Circle} This circle instance for chaining.
|
|
88
88
|
*/
|
|
89
|
-
public copyFrom(source: Circle) {
|
|
89
|
+
public copyFrom(source: Circle): this {
|
|
90
90
|
return this.setTo(source.x, source.y, source.diameter);
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -95,7 +95,7 @@ export class Circle {
|
|
|
95
95
|
* @param {Circle} dest - The circle to copy values to.
|
|
96
96
|
* @returns {Circle} The destination circle.
|
|
97
97
|
*/
|
|
98
|
-
public copyTo(dest: Circle) {
|
|
98
|
+
public copyTo(dest: Circle): Circle {
|
|
99
99
|
dest.x = this.x;
|
|
100
100
|
dest.y = this.y;
|
|
101
101
|
dest.diameter = this._diameter;
|
|
@@ -108,7 +108,7 @@ export class Circle {
|
|
|
108
108
|
* @param {boolean} round - Whether to round the result (default: false).
|
|
109
109
|
* @returns {number} The distance between the circles.
|
|
110
110
|
*/
|
|
111
|
-
public distance(dest: { x: number; y: number }, round = false) {
|
|
111
|
+
public distance(dest: { x: number; y: number }, round = false): number {
|
|
112
112
|
const d = distance(this.x, this.y, dest.x, dest.y);
|
|
113
113
|
return round ? Math.round(d) : d;
|
|
114
114
|
}
|
|
@@ -117,7 +117,7 @@ export class Circle {
|
|
|
117
117
|
* Creates a clone of this circle.
|
|
118
118
|
* @returns {Circle} A new circle with the same values as this one.
|
|
119
119
|
*/
|
|
120
|
-
public clone() {
|
|
120
|
+
public clone(): Circle {
|
|
121
121
|
return clone(this);
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -127,7 +127,7 @@ export class Circle {
|
|
|
127
127
|
* @param {number} y - The y coordinate of the point to check.
|
|
128
128
|
* @returns {boolean} True if the point is contained within this circle, false otherwise.
|
|
129
129
|
*/
|
|
130
|
-
public contains(x: number, y: number) {
|
|
130
|
+
public contains(x: number, y: number): boolean {
|
|
131
131
|
return contains(this, x, y);
|
|
132
132
|
}
|
|
133
133
|
|
|
@@ -138,7 +138,7 @@ export class Circle {
|
|
|
138
138
|
* @param {Point} out - The point to store the result in (optional).
|
|
139
139
|
* @returns {Point} A point at the specified angle on the circumference of this circle.
|
|
140
140
|
*/
|
|
141
|
-
public circumferencePoint(angle: number, asDegrees?: boolean, out?: Point) {
|
|
141
|
+
public circumferencePoint(angle: number, asDegrees?: boolean, out?: Point): Point {
|
|
142
142
|
return circumferencePoint(this, angle, asDegrees, out);
|
|
143
143
|
}
|
|
144
144
|
|
|
@@ -148,7 +148,7 @@ export class Circle {
|
|
|
148
148
|
* @param {number} dy - The amount to offset the y coordinate by.
|
|
149
149
|
* @returns {Circle} This circle instance for chaining.
|
|
150
150
|
*/
|
|
151
|
-
public offset(dx: number, dy: number) {
|
|
151
|
+
public offset(dx: number, dy: number): this {
|
|
152
152
|
this.x += dx;
|
|
153
153
|
this.y += dy;
|
|
154
154
|
return this;
|
|
@@ -159,7 +159,7 @@ export class Circle {
|
|
|
159
159
|
* @param {Point} point - The point to offset the circle by.
|
|
160
160
|
* @returns {Circle} This circle instance for chaining.
|
|
161
161
|
*/
|
|
162
|
-
public offsetPoint(point: Point) {
|
|
162
|
+
public offsetPoint(point: Point): this {
|
|
163
163
|
return this.offset(point.x, point.y);
|
|
164
164
|
}
|
|
165
165
|
|
|
@@ -167,7 +167,7 @@ export class Circle {
|
|
|
167
167
|
* Returns a string representation of this circle.
|
|
168
168
|
* @returns {string} A string representation of the circle.
|
|
169
169
|
*/
|
|
170
|
-
public toString() {
|
|
170
|
+
public toString(): string {
|
|
171
171
|
return `[{Circle (x=${this.x} y=${this.y} diameter=${this.diameter} radius=${this.radius})}]`;
|
|
172
172
|
}
|
|
173
173
|
|
|
@@ -175,7 +175,7 @@ export class Circle {
|
|
|
175
175
|
* Gets the diameter of this circle.
|
|
176
176
|
* @returns {number} The diameter of this circle.
|
|
177
177
|
*/
|
|
178
|
-
public get diameter() {
|
|
178
|
+
public get diameter(): number {
|
|
179
179
|
return this._diameter;
|
|
180
180
|
}
|
|
181
181
|
|
|
@@ -193,7 +193,7 @@ export class Circle {
|
|
|
193
193
|
* Gets the radius of this circle.
|
|
194
194
|
* @returns {number} The radius of this circle.
|
|
195
195
|
*/
|
|
196
|
-
public get radius() {
|
|
196
|
+
public get radius(): number {
|
|
197
197
|
return this._radius;
|
|
198
198
|
}
|
|
199
199
|
|
|
@@ -211,7 +211,7 @@ export class Circle {
|
|
|
211
211
|
* Gets the left coordinate of this circle.
|
|
212
212
|
* @returns {number} The left coordinate of this circle.
|
|
213
213
|
*/
|
|
214
|
-
public get left() {
|
|
214
|
+
public get left(): number {
|
|
215
215
|
return this.x - this._radius;
|
|
216
216
|
}
|
|
217
217
|
|
|
@@ -231,7 +231,7 @@ export class Circle {
|
|
|
231
231
|
* Gets the right coordinate of this circle.
|
|
232
232
|
* @returns {number} The right coordinate of this circle.
|
|
233
233
|
*/
|
|
234
|
-
public get right() {
|
|
234
|
+
public get right(): number {
|
|
235
235
|
return this.x + this._radius;
|
|
236
236
|
}
|
|
237
237
|
|
|
@@ -251,7 +251,7 @@ export class Circle {
|
|
|
251
251
|
* Gets the top coordinate of this circle.
|
|
252
252
|
* @returns {number} The top coordinate of this circle.
|
|
253
253
|
*/
|
|
254
|
-
public get top() {
|
|
254
|
+
public get top(): number {
|
|
255
255
|
return this.y - this._radius;
|
|
256
256
|
}
|
|
257
257
|
|
|
@@ -271,7 +271,7 @@ export class Circle {
|
|
|
271
271
|
* Gets the bottom coordinate of this circle.
|
|
272
272
|
* @returns {number} The bottom coordinate of this circle.
|
|
273
273
|
*/
|
|
274
|
-
public get bottom() {
|
|
274
|
+
public get bottom(): number {
|
|
275
275
|
return this.y + this._radius;
|
|
276
276
|
}
|
|
277
277
|
|
|
@@ -291,7 +291,7 @@ export class Circle {
|
|
|
291
291
|
* Gets the area of this circle.
|
|
292
292
|
* @returns {number} The area of this circle.
|
|
293
293
|
*/
|
|
294
|
-
public get area() {
|
|
294
|
+
public get area(): number {
|
|
295
295
|
if (this._radius > 0) {
|
|
296
296
|
return Math.PI * this._radius * this._radius;
|
|
297
297
|
}
|
|
@@ -302,7 +302,7 @@ export class Circle {
|
|
|
302
302
|
* Checks if this circle is empty (has zero diameter).
|
|
303
303
|
* @returns {boolean} True if the circle is empty, false otherwise.
|
|
304
304
|
*/
|
|
305
|
-
public get empty() {
|
|
305
|
+
public get empty(): boolean {
|
|
306
306
|
return this._diameter === 0;
|
|
307
307
|
}
|
|
308
308
|
|
|
@@ -38,7 +38,7 @@ export class Ellipse {
|
|
|
38
38
|
* @param {number} height - The new height of the ellipse.
|
|
39
39
|
* @returns {Ellipse} This ellipse instance for chaining.
|
|
40
40
|
*/
|
|
41
|
-
public setTo(x: number, y: number, width: number, height: number) {
|
|
41
|
+
public setTo(x: number, y: number, width: number, height: number): this {
|
|
42
42
|
this.x = x;
|
|
43
43
|
this.y = y;
|
|
44
44
|
this.width = width;
|
|
@@ -50,7 +50,7 @@ export class Ellipse {
|
|
|
50
50
|
* Gets the bounding rectangle of this ellipse.
|
|
51
51
|
* @returns {Rectangle} The bounding rectangle of this ellipse.
|
|
52
52
|
*/
|
|
53
|
-
public getBounds() {
|
|
53
|
+
public getBounds(): Rectangle {
|
|
54
54
|
return new Rectangle(this.x - this.width, this.y - this.height, this.width, this.height);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -59,7 +59,7 @@ export class Ellipse {
|
|
|
59
59
|
* @param {Ellipse} source - The ellipse to copy values from.
|
|
60
60
|
* @returns {Ellipse} This ellipse instance for chaining.
|
|
61
61
|
*/
|
|
62
|
-
public copyFrom(source: Ellipse) {
|
|
62
|
+
public copyFrom(source: Ellipse): this {
|
|
63
63
|
return this.setTo(source.x, source.y, source.width, source.height);
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -68,7 +68,7 @@ export class Ellipse {
|
|
|
68
68
|
* @param {Ellipse} dest - The ellipse to copy values to.
|
|
69
69
|
* @returns {Ellipse} The destination ellipse.
|
|
70
70
|
*/
|
|
71
|
-
public copyTo(dest: Ellipse) {
|
|
71
|
+
public copyTo(dest: Ellipse): Ellipse {
|
|
72
72
|
dest.x = this.x;
|
|
73
73
|
dest.y = this.y;
|
|
74
74
|
dest.width = this.width;
|
|
@@ -82,7 +82,7 @@ export class Ellipse {
|
|
|
82
82
|
* @param {number} y - The y coordinate of the point to check.
|
|
83
83
|
* @returns {boolean} True if the point is contained within this ellipse, false otherwise.
|
|
84
84
|
*/
|
|
85
|
-
public contains(x: number, y: number) {
|
|
85
|
+
public contains(x: number, y: number): boolean {
|
|
86
86
|
return contains(this, x, y);
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -91,7 +91,7 @@ export class Ellipse {
|
|
|
91
91
|
* @param {Point} output - The point to store the result in (optional).
|
|
92
92
|
* @returns {Point} A random point within this ellipse.
|
|
93
93
|
*/
|
|
94
|
-
public random(output: Point | null = null) {
|
|
94
|
+
public random(output: Point | null = null): Point {
|
|
95
95
|
const result = output ?? new Point();
|
|
96
96
|
const p = Math.random() * Math.PI * 2;
|
|
97
97
|
const r = Math.random();
|
|
@@ -106,7 +106,7 @@ export class Ellipse {
|
|
|
106
106
|
* Returns a string representation of this ellipse.
|
|
107
107
|
* @returns {string} A string representation of the ellipse.
|
|
108
108
|
*/
|
|
109
|
-
public toString() {
|
|
109
|
+
public toString(): string {
|
|
110
110
|
return `[{Ellipse (x=${this.x} y=${this.y} width=${this.width} height=${this.height})}]`;
|
|
111
111
|
}
|
|
112
112
|
}
|