@vpmedia/phaser 1.123.0 → 1.124.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 +339 -323
- 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/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 +3 -1
- 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/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_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 +4 -4
- package/src/phaser/core/animation_manager.ts +10 -10
- package/src/phaser/core/animation_parser.ts +30 -24
- package/src/phaser/core/array_set.ts +27 -27
- package/src/phaser/core/cache.test.ts +33 -33
- package/src/phaser/core/cache.ts +3 -3
- package/src/phaser/core/callback.ts +1 -0
- package/src/phaser/core/callback_context.test.ts +8 -8
- package/src/phaser/core/dom.ts +15 -5
- package/src/phaser/core/factory.ts +9 -2
- package/src/phaser/core/frame_data.test.ts +23 -23
- package/src/phaser/core/input.ts +9 -8
- package/src/phaser/core/input_handler.test.ts +18 -18
- package/src/phaser/core/input_handler.ts +1 -1
- package/src/phaser/core/input_mouse.ts +9 -8
- package/src/phaser/core/input_pointer.test.ts +26 -26
- package/src/phaser/core/input_pointer.ts +3 -3
- package/src/phaser/core/input_touch.ts +8 -8
- package/src/phaser/core/loader.test.ts +26 -26
- package/src/phaser/core/loader.ts +25 -25
- 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 +2 -2
- package/src/phaser/core/scene_manager.test.ts +30 -30
- package/src/phaser/core/scene_manager.ts +1 -1
- package/src/phaser/core/signal.test.ts +8 -8
- package/src/phaser/core/signal.ts +1 -1
- package/src/phaser/core/signal_dispatch.test.ts +30 -30
- package/src/phaser/core/sound.ts +20 -8
- package/src/phaser/core/sound_manager.ts +6 -6
- package/src/phaser/core/stage.ts +19 -9
- package/src/phaser/core/time.ts +1 -1
- package/src/phaser/core/timer.test.ts +47 -47
- package/src/phaser/core/timer.ts +1 -1
- package/src/phaser/core/tween.ts +28 -25
- 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/button.ts +8 -6
- package/src/phaser/display/canvas/buffer.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 +3 -3
- package/src/phaser/display/canvas/renderer.ts +12 -11
- package/src/phaser/display/canvas/util.test.ts +25 -25
- package/src/phaser/display/display_object.ts +3 -1
- package/src/phaser/display/graphics.test.ts +70 -20
- package/src/phaser/display/graphics.ts +38 -32
- package/src/phaser/display/group.ts +4 -4
- package/src/phaser/display/image.ts +28 -25
- package/src/phaser/display/sprite_util.ts +3 -2
- package/src/phaser/display/text.test.ts +28 -25
- package/src/phaser/display/text.ts +21 -18
- package/src/phaser/display/webgl/abstract_filter.ts +20 -10
- 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/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 +2 -2
- 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 +7 -6
- package/src/phaser/display/webgl/shader/normal.ts +41 -31
- 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/sprite_batch.ts +8 -8
- package/src/phaser/display/webgl/stencil_manager.ts +4 -4
- package/src/phaser/display/webgl/texture_util.ts +2 -2
- package/src/phaser/display/webgl/util.ts +1 -1
- 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/rectangle.test.ts +87 -87
- package/src/phaser/geom/rectangle.ts +11 -11
- 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 +2 -1
- 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 +1 -1
- 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 +5 -2
|
@@ -38,6 +38,22 @@ export type GraphicsWebGLBucket = {
|
|
|
38
38
|
gl: IdentifiedWebGLRenderingContext;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Reports whether a triangle winds towards the viewer. In two dimensions the cross product is a
|
|
43
|
+
* scalar, so its sign alone says which way the face points.
|
|
44
|
+
* @param {Point[]} points - The three corners of the triangle, in order.
|
|
45
|
+
* @returns {boolean} True when the triangle faces the viewer.
|
|
46
|
+
*/
|
|
47
|
+
const isFrontFacing = (points: Point[]): boolean => {
|
|
48
|
+
const [a, b, c] = points;
|
|
49
|
+
if (!a || !b || !c) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
const ab = new Point(b.x - a.x, b.y - a.y);
|
|
53
|
+
const cb = new Point(b.x - c.x, b.y - c.y);
|
|
54
|
+
return cb.cross(ab) > 0;
|
|
55
|
+
};
|
|
56
|
+
|
|
41
57
|
export class Graphics extends DisplayObject {
|
|
42
58
|
declare public type: number;
|
|
43
59
|
declare public renderable: boolean;
|
|
@@ -887,18 +903,10 @@ export class Graphics extends DisplayObject {
|
|
|
887
903
|
*/
|
|
888
904
|
public drawTriangle(points: Point[], cull = false): void {
|
|
889
905
|
const triangle = new Polygon(points);
|
|
890
|
-
if (cull) {
|
|
891
|
-
|
|
892
|
-
const cameraToFace = new Point(0 - a.x, 0 - a.y);
|
|
893
|
-
const ab = new Point(b.x - a.x, b.y - a.y);
|
|
894
|
-
const cb = new Point(b.x - c.x, b.y - c.y);
|
|
895
|
-
const faceNormal = cb.cross(ab);
|
|
896
|
-
if (cameraToFace.dot(faceNormal as any) > 0) {
|
|
897
|
-
this.drawPolygon(triangle);
|
|
898
|
-
}
|
|
899
|
-
} else {
|
|
900
|
-
this.drawPolygon(triangle);
|
|
906
|
+
if (cull && !isFrontFacing(points)) {
|
|
907
|
+
return;
|
|
901
908
|
}
|
|
909
|
+
this.drawPolygon(triangle);
|
|
902
910
|
}
|
|
903
911
|
|
|
904
912
|
/**
|
|
@@ -907,43 +915,41 @@ export class Graphics extends DisplayObject {
|
|
|
907
915
|
* @param {number[]} indices - The indices of the vertices to use.
|
|
908
916
|
* @param {boolean} cull - Whether to perform backface culling.
|
|
909
917
|
*/
|
|
910
|
-
public drawTriangles(vertices:
|
|
911
|
-
|
|
912
|
-
const point2 = new Point();
|
|
913
|
-
const point3 = new Point();
|
|
914
|
-
let points = [];
|
|
918
|
+
public drawTriangles(vertices: Point[] | number[], indices: number[], cull = false): void {
|
|
919
|
+
let points: Point[] = [];
|
|
915
920
|
let i;
|
|
916
921
|
if (!indices) {
|
|
917
922
|
if (vertices[0] instanceof Point) {
|
|
918
|
-
|
|
919
|
-
|
|
923
|
+
const corners = vertices as Point[];
|
|
924
|
+
for (i = 0; i < corners.length / 3; i += 1) {
|
|
925
|
+
this.drawTriangle([corners[i * 3]!, corners[i * 3 + 1]!, corners[i * 3 + 2]!], cull);
|
|
920
926
|
}
|
|
921
927
|
} else {
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
928
|
+
const coordinates = vertices as number[];
|
|
929
|
+
for (i = 0; i < coordinates.length / 6; i += 1) {
|
|
930
|
+
this.drawTriangle(
|
|
931
|
+
[
|
|
932
|
+
new Point(coordinates[i * 6 + 0], coordinates[i * 6 + 1]),
|
|
933
|
+
new Point(coordinates[i * 6 + 2], coordinates[i * 6 + 3]),
|
|
934
|
+
new Point(coordinates[i * 6 + 4], coordinates[i * 6 + 5]),
|
|
935
|
+
],
|
|
936
|
+
cull
|
|
937
|
+
);
|
|
930
938
|
}
|
|
931
939
|
}
|
|
932
940
|
} else if (vertices[0] instanceof Point) {
|
|
941
|
+
const corners = vertices as Point[];
|
|
933
942
|
for (i = 0; i < indices.length / 3; i += 1) {
|
|
934
|
-
points.push(
|
|
935
|
-
points.push(vertices[indices[i * 3 + 1]!]);
|
|
936
|
-
points.push(vertices[indices[i * 3 + 2]!]);
|
|
943
|
+
points.push(corners[indices[i * 3]!]!, corners[indices[i * 3 + 1]!]!, corners[indices[i * 3 + 2]!]!);
|
|
937
944
|
if (points.length === 3) {
|
|
938
945
|
this.drawTriangle(points, cull);
|
|
939
946
|
points = [];
|
|
940
947
|
}
|
|
941
948
|
}
|
|
942
949
|
} else {
|
|
950
|
+
const coordinates = vertices as number[];
|
|
943
951
|
for (i = 0; i < indices.length; i += 1) {
|
|
944
|
-
|
|
945
|
-
point1.y = vertices[indices[i]! * 2 + 1]!;
|
|
946
|
-
points.push(point1.copyTo({} as any));
|
|
952
|
+
points.push(new Point(coordinates[indices[i]! * 2], coordinates[indices[i]! * 2 + 1]));
|
|
947
953
|
if (points.length === 3) {
|
|
948
954
|
this.drawTriangle(points, cull);
|
|
949
955
|
points = [];
|
|
@@ -288,11 +288,11 @@ export class Group extends DisplayObject {
|
|
|
288
288
|
* @param {boolean} silent - Whether to dispatch events.
|
|
289
289
|
* @returns {boolean} True if the child was removed, false otherwise.
|
|
290
290
|
*/
|
|
291
|
-
public remove(child:
|
|
291
|
+
public remove(child: DisplayObject, destroy = true, silent = false): boolean {
|
|
292
292
|
if (this.children.length === 0 || !this.children.includes(child)) {
|
|
293
293
|
return false;
|
|
294
294
|
}
|
|
295
|
-
if (!silent && child.events
|
|
295
|
+
if (!silent && child.events) {
|
|
296
296
|
child.events.onRemovedFromGroup$dispatch(child, this);
|
|
297
297
|
}
|
|
298
298
|
const removed = this.removeChild(child);
|
|
@@ -301,7 +301,7 @@ export class Group extends DisplayObject {
|
|
|
301
301
|
this.next();
|
|
302
302
|
}
|
|
303
303
|
if (destroy && removed) {
|
|
304
|
-
|
|
304
|
+
removed.destroy(true);
|
|
305
305
|
}
|
|
306
306
|
return true;
|
|
307
307
|
}
|
|
@@ -323,7 +323,7 @@ export class Group extends DisplayObject {
|
|
|
323
323
|
}
|
|
324
324
|
const removed = this.removeChild(first);
|
|
325
325
|
if (destroy && removed) {
|
|
326
|
-
|
|
326
|
+
removed.destroy(true, destroyTexture);
|
|
327
327
|
}
|
|
328
328
|
} while (this.children.length > 0);
|
|
329
329
|
this.cursor = null;
|
|
@@ -7,12 +7,13 @@ import { DisplayObject } from './display_object.js';
|
|
|
7
7
|
import { getBounds, getLocalBounds, renderCanvas, renderWebGL, setTexture } from './sprite_util.js';
|
|
8
8
|
import { Texture } from './webgl/texture.js';
|
|
9
9
|
import type { Game } from '../core/game.js';
|
|
10
|
-
import
|
|
10
|
+
import { Frame } from '../core/frame.js';
|
|
11
11
|
import type { Matrix } from '../geom/matrix.js';
|
|
12
12
|
import type { RenderSession } from './render_session.js';
|
|
13
|
+
import type { AbstractFilter } from './webgl/abstract_filter.js';
|
|
13
14
|
|
|
14
15
|
export class Image extends DisplayObject {
|
|
15
|
-
public key!:
|
|
16
|
+
public key!: string | number | Texture | null;
|
|
16
17
|
public texture!: Texture;
|
|
17
18
|
declare public _width: number;
|
|
18
19
|
declare public _height: number;
|
|
@@ -21,8 +22,8 @@ export class Image extends DisplayObject {
|
|
|
21
22
|
public tilingTexture!: Texture | null;
|
|
22
23
|
public tintedTexture!: HTMLCanvasElement | null;
|
|
23
24
|
public blendMode!: number;
|
|
24
|
-
public shader!:
|
|
25
|
-
public _frame!:
|
|
25
|
+
public shader!: AbstractFilter | null;
|
|
26
|
+
public _frame!: Frame | Rectangle | null;
|
|
26
27
|
public pendingDestroy!: boolean;
|
|
27
28
|
declare public events: EventManager;
|
|
28
29
|
public animations!: AnimationManager;
|
|
@@ -180,7 +181,7 @@ export class Image extends DisplayObject {
|
|
|
180
181
|
* Sets the current frame of this image.
|
|
181
182
|
* @param {Frame} frame - The frame to set.
|
|
182
183
|
*/
|
|
183
|
-
public setFrame(frame: Frame): void {
|
|
184
|
+
public setFrame(frame: Frame | Rectangle): void {
|
|
184
185
|
this._frame = frame;
|
|
185
186
|
this.texture.frame.x = frame.x;
|
|
186
187
|
this.texture.frame.y = frame.y;
|
|
@@ -190,25 +191,26 @@ export class Image extends DisplayObject {
|
|
|
190
191
|
this.texture.crop.y = frame.y;
|
|
191
192
|
this.texture.crop.width = frame.width;
|
|
192
193
|
this.texture.crop.height = frame.height;
|
|
193
|
-
|
|
194
|
+
const trimmed = frame instanceof Frame && frame.trimmed ? frame : null;
|
|
195
|
+
if (trimmed) {
|
|
194
196
|
if (this.texture.trim) {
|
|
195
|
-
this.texture.trim.x =
|
|
196
|
-
this.texture.trim.y =
|
|
197
|
-
this.texture.trim.width =
|
|
198
|
-
this.texture.trim.height =
|
|
197
|
+
this.texture.trim.x = trimmed.spriteSourceSizeX;
|
|
198
|
+
this.texture.trim.y = trimmed.spriteSourceSizeY;
|
|
199
|
+
this.texture.trim.width = trimmed.sourceSizeW;
|
|
200
|
+
this.texture.trim.height = trimmed.sourceSizeH;
|
|
199
201
|
} else {
|
|
200
202
|
this.texture.trim = new Rectangle(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
trimmed.spriteSourceSizeX,
|
|
204
|
+
trimmed.spriteSourceSizeY,
|
|
205
|
+
trimmed.sourceSizeW,
|
|
206
|
+
trimmed.sourceSizeH
|
|
205
207
|
);
|
|
206
208
|
}
|
|
207
|
-
this.texture.width =
|
|
208
|
-
this.texture.height =
|
|
209
|
-
this.texture.frame.width =
|
|
210
|
-
this.texture.frame.height =
|
|
211
|
-
} else if (
|
|
209
|
+
this.texture.width = trimmed.sourceSizeW;
|
|
210
|
+
this.texture.height = trimmed.sourceSizeH;
|
|
211
|
+
this.texture.frame.width = trimmed.sourceSizeW;
|
|
212
|
+
this.texture.frame.height = trimmed.sourceSizeH;
|
|
213
|
+
} else if (this.texture.trim) {
|
|
212
214
|
this.texture.trim = null;
|
|
213
215
|
}
|
|
214
216
|
if (this.cropRect) {
|
|
@@ -308,13 +310,14 @@ export class Image extends DisplayObject {
|
|
|
308
310
|
const oldY = this.texture.crop.y;
|
|
309
311
|
const oldW = this.texture.crop.width;
|
|
310
312
|
const oldH = this.texture.crop.height;
|
|
313
|
+
const frame = this._frame!;
|
|
311
314
|
this._crop = clone(this.cropRect, this._crop);
|
|
312
|
-
this._crop.x +=
|
|
313
|
-
this._crop.y +=
|
|
314
|
-
const cx = Math.max(
|
|
315
|
-
const cy = Math.max(
|
|
316
|
-
const cw = Math.min(
|
|
317
|
-
const ch = Math.min(
|
|
315
|
+
this._crop.x += frame.x;
|
|
316
|
+
this._crop.y += frame.y;
|
|
317
|
+
const cx = Math.max(frame.x, this._crop.x);
|
|
318
|
+
const cy = Math.max(frame.y, this._crop.y);
|
|
319
|
+
const cw = Math.min(frame.right, this._crop.right) - cx;
|
|
320
|
+
const ch = Math.min(frame.bottom, this._crop.bottom) - cy;
|
|
318
321
|
this.texture.crop.x = cx;
|
|
319
322
|
this.texture.crop.y = cy;
|
|
320
323
|
this.texture.crop.width = cw;
|
|
@@ -6,6 +6,7 @@ import type { Texture } from './webgl/texture.js';
|
|
|
6
6
|
import type { Matrix } from '../geom/matrix.js';
|
|
7
7
|
import type { RenderSession } from './render_session.js';
|
|
8
8
|
import { setSmoothing } from './canvas/util.js';
|
|
9
|
+
import type { Rectangle } from '../geom/rectangle.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Sets the texture of a sprite.
|
|
@@ -29,7 +30,7 @@ export const setTexture = (target: Image, texture: Texture, destroyBase = false)
|
|
|
29
30
|
* @param {object} matrix - The transformation matrix.
|
|
30
31
|
* @returns {Rectangle} The bounds rectangle.
|
|
31
32
|
*/
|
|
32
|
-
export const getBounds = (target: Image, matrix: Matrix | null = null) => {
|
|
33
|
+
export const getBounds = (target: Image, matrix: Matrix | null = null): Rectangle => {
|
|
33
34
|
if (target.currentBounds) {
|
|
34
35
|
return target.currentBounds;
|
|
35
36
|
}
|
|
@@ -110,7 +111,7 @@ export const getBounds = (target: Image, matrix: Matrix | null = null) => {
|
|
|
110
111
|
* @param {Image} target - The target image to get local bounds for.
|
|
111
112
|
* @returns {Rectangle} The local bounds rectangle.
|
|
112
113
|
*/
|
|
113
|
-
export const getLocalBounds = (target: Image) => {
|
|
114
|
+
export const getLocalBounds = (target: Image): Rectangle => {
|
|
114
115
|
const matrixCache = target.worldTransform;
|
|
115
116
|
target.worldTransform = getIdentityMatrix();
|
|
116
117
|
for (const child of target.children) {
|
|
@@ -36,99 +36,102 @@ const createContext2D = (): CanvasRenderingContext2D =>
|
|
|
36
36
|
const createGame = (): Game =>
|
|
37
37
|
({
|
|
38
38
|
renderer: { resolution: 1 },
|
|
39
|
-
cache: { getImage: () => null },
|
|
40
|
-
add: { existing: (child: unknown) => child },
|
|
39
|
+
cache: { getImage: (): null => null },
|
|
40
|
+
add: { existing: (child: unknown): unknown => child },
|
|
41
41
|
}) as unknown as Game;
|
|
42
42
|
|
|
43
43
|
const createText = (value: string | number): Text => new Text(createGame(), 0, 0, value);
|
|
44
44
|
|
|
45
|
-
describe('Text', () => {
|
|
45
|
+
describe('Text', (): void => {
|
|
46
46
|
const originalGetContext = HTMLCanvasElement.prototype.getContext;
|
|
47
47
|
|
|
48
|
-
beforeAll(() => {
|
|
49
|
-
HTMLCanvasElement.prototype.getContext = function getContext(
|
|
48
|
+
beforeAll((): void => {
|
|
49
|
+
HTMLCanvasElement.prototype.getContext = function getContext(
|
|
50
|
+
this: HTMLCanvasElement,
|
|
51
|
+
id: string
|
|
52
|
+
): CanvasRenderingContext2D | null {
|
|
50
53
|
return id === '2d' ? createContext2D() : null;
|
|
51
54
|
} as typeof HTMLCanvasElement.prototype.getContext;
|
|
52
55
|
});
|
|
53
56
|
|
|
54
|
-
beforeEach(() => {
|
|
57
|
+
beforeEach((): void => {
|
|
55
58
|
getRegistry().CACHE_MISSING_IMAGE = textureFromCanvas(document.createElement('canvas'));
|
|
56
59
|
});
|
|
57
60
|
|
|
58
|
-
afterAll(() => {
|
|
61
|
+
afterAll((): void => {
|
|
59
62
|
HTMLCanvasElement.prototype.getContext = originalGetContext;
|
|
60
63
|
});
|
|
61
64
|
|
|
62
|
-
describe('constructor', () => {
|
|
63
|
-
it('keeps a string as-is', () => {
|
|
65
|
+
describe('constructor', (): void => {
|
|
66
|
+
it('keeps a string as-is', (): void => {
|
|
64
67
|
expect(createText('hello').text).toBe('hello');
|
|
65
68
|
});
|
|
66
69
|
|
|
67
70
|
// Callers pass numbers straight into game.add.text(). The constructor must coerce:
|
|
68
71
|
// updateText() calls .split() on the value, which throws on a number.
|
|
69
|
-
it('coerces a number to its string form', () => {
|
|
72
|
+
it('coerces a number to its string form', (): void => {
|
|
70
73
|
expect(createText(42).text).toBe('42');
|
|
71
74
|
});
|
|
72
75
|
|
|
73
|
-
it('coerces zero rather than falling back to the empty string', () => {
|
|
76
|
+
it('coerces zero rather than falling back to the empty string', (): void => {
|
|
74
77
|
expect(createText(0).text).toBe('0');
|
|
75
78
|
});
|
|
76
79
|
|
|
77
|
-
it('coerces a negative number', () => {
|
|
80
|
+
it('coerces a negative number', (): void => {
|
|
78
81
|
expect(createText(-7).text).toBe('-7');
|
|
79
82
|
});
|
|
80
83
|
|
|
81
|
-
it('defaults to the empty string', () => {
|
|
84
|
+
it('defaults to the empty string', (): void => {
|
|
82
85
|
expect(new Text(createGame(), 0, 0).text).toBe('');
|
|
83
86
|
});
|
|
84
87
|
|
|
85
|
-
it('renders a numeric label without throwing', () => {
|
|
86
|
-
expect(() => createText(2026)).not.toThrow();
|
|
88
|
+
it('renders a numeric label without throwing', (): void => {
|
|
89
|
+
expect((): Text => createText(2026)).not.toThrow();
|
|
87
90
|
});
|
|
88
91
|
});
|
|
89
92
|
|
|
90
|
-
describe('text setter', () => {
|
|
91
|
-
it('coerces a number assigned after construction', () => {
|
|
93
|
+
describe('text setter', (): void => {
|
|
94
|
+
it('coerces a number assigned after construction', (): void => {
|
|
92
95
|
const text = createText('start');
|
|
93
96
|
text.text = 99;
|
|
94
97
|
expect(text.text).toBe('99');
|
|
95
98
|
});
|
|
96
99
|
});
|
|
97
100
|
|
|
98
|
-
describe('fontSize', () => {
|
|
101
|
+
describe('fontSize', (): void => {
|
|
99
102
|
// A px-suffixed size cannot be read with Number(); it yields NaN. An autofix made exactly that
|
|
100
103
|
// substitution once already.
|
|
101
|
-
it('reads a px size back as a number', () => {
|
|
104
|
+
it('reads a px size back as a number', (): void => {
|
|
102
105
|
const text = new Text(createGame(), 0, 0, 'hello', { font: '20px Arial' });
|
|
103
106
|
expect(text.fontSize).toBe(20);
|
|
104
107
|
});
|
|
105
108
|
|
|
106
|
-
it('round trips through the setter', () => {
|
|
109
|
+
it('round trips through the setter', (): void => {
|
|
107
110
|
const text = createText('hello');
|
|
108
111
|
text.fontSize = 32;
|
|
109
112
|
expect(text.fontSize).toBe(32);
|
|
110
113
|
});
|
|
111
114
|
|
|
112
|
-
it('reads zero back as zero', () => {
|
|
115
|
+
it('reads zero back as zero', (): void => {
|
|
113
116
|
const text = createText('hello');
|
|
114
117
|
text.fontSize = 0;
|
|
115
118
|
expect(text.fontSize).toBe(0);
|
|
116
119
|
});
|
|
117
120
|
|
|
118
|
-
it('never reports NaN for a styled font', () => {
|
|
121
|
+
it('never reports NaN for a styled font', (): void => {
|
|
119
122
|
const text = new Text(createGame(), 0, 0, 'hello', { font: 'bold 14px Arial' });
|
|
120
123
|
expect(Number.isNaN(text.fontSize)).toBe(false);
|
|
121
124
|
});
|
|
122
125
|
});
|
|
123
126
|
|
|
124
|
-
describe('setText', () => {
|
|
125
|
-
it('coerces a number', () => {
|
|
127
|
+
describe('setText', (): void => {
|
|
128
|
+
it('coerces a number', (): void => {
|
|
126
129
|
const text = createText('start');
|
|
127
130
|
text.setText(123);
|
|
128
131
|
expect(text.text).toBe('123');
|
|
129
132
|
});
|
|
130
133
|
|
|
131
|
-
it('returns itself for chaining', () => {
|
|
134
|
+
it('returns itself for chaining', (): void => {
|
|
132
135
|
const text = createText('start');
|
|
133
136
|
expect(text.setText('next')).toBe(text);
|
|
134
137
|
});
|
|
@@ -229,10 +229,7 @@ export class Text extends Image {
|
|
|
229
229
|
public updateText(): void {
|
|
230
230
|
this.texture.baseTexture.resolution = this._res;
|
|
231
231
|
this.context.font = this.style.font;
|
|
232
|
-
|
|
233
|
-
if (this.style.wordWrap) {
|
|
234
|
-
outputText = this.runWordWrap(this.text);
|
|
235
|
-
}
|
|
232
|
+
const outputText = this.style.wordWrap ? this.runWordWrap(this.text) : this.text;
|
|
236
233
|
// Split text into lines
|
|
237
234
|
const lines = outputText.split(/(?:\r\n|\r|\n)/);
|
|
238
235
|
// Calculate text width
|
|
@@ -250,24 +247,28 @@ export class Text extends Image {
|
|
|
250
247
|
}
|
|
251
248
|
this._charCount = 0;
|
|
252
249
|
for (let i = 0; i < drawnLines; i += 1) {
|
|
250
|
+
const currentLine = lines[i]!;
|
|
253
251
|
if (tabs === 0) {
|
|
254
252
|
// Simple layout (no tabs)
|
|
255
253
|
lineWidth = this.style.strokeThickness + this.padding.x;
|
|
256
|
-
lineWidth += this.hasCharacterStyles()
|
|
254
|
+
lineWidth += this.hasCharacterStyles()
|
|
255
|
+
? this.measureLine(currentLine)
|
|
256
|
+
: this.context.measureText(currentLine).width;
|
|
257
257
|
// Adjust for wrapped text
|
|
258
258
|
if (this.style.wordWrap) {
|
|
259
259
|
lineWidth -= this.context.measureText(' ').width;
|
|
260
260
|
}
|
|
261
261
|
} else {
|
|
262
262
|
// Complex layout (tabs)
|
|
263
|
-
const line =
|
|
263
|
+
const line = currentLine.split(/(?:\t)/);
|
|
264
264
|
lineWidth = this.padding.x + this.style.strokeThickness;
|
|
265
265
|
if (Array.isArray(tabs)) {
|
|
266
266
|
let tab = 0;
|
|
267
267
|
for (let c = 0; c < line.length; c += 1) {
|
|
268
|
+
const part = line[c]!;
|
|
268
269
|
const section = this.hasCharacterStyles()
|
|
269
|
-
? this.measureLine(
|
|
270
|
-
: Math.ceil(this.context.measureText(
|
|
270
|
+
? this.measureLine(part)
|
|
271
|
+
: Math.ceil(this.context.measureText(part).width);
|
|
271
272
|
if (c > 0) {
|
|
272
273
|
tab += tabs[c - 1]!;
|
|
273
274
|
}
|
|
@@ -317,6 +318,7 @@ export class Text extends Image {
|
|
|
317
318
|
this._charCount = 0;
|
|
318
319
|
// Draw text line by line
|
|
319
320
|
for (let i = 0; i < drawnLines; i += 1) {
|
|
321
|
+
const line = lines[i]!;
|
|
320
322
|
// Split the line by
|
|
321
323
|
linePositionX = this.style.strokeThickness / 2;
|
|
322
324
|
linePositionY = this.style.strokeThickness / 2 + i * lineHeight + fontProperties.ascent;
|
|
@@ -333,22 +335,22 @@ export class Text extends Image {
|
|
|
333
335
|
linePositionY = Math.round(linePositionY);
|
|
334
336
|
}
|
|
335
337
|
if (this.hasCharacterStyles()) {
|
|
336
|
-
this.updateLine(
|
|
338
|
+
this.updateLine(line, linePositionX, linePositionY);
|
|
337
339
|
} else {
|
|
338
340
|
if (this.style.stroke && this.style.strokeThickness) {
|
|
339
341
|
this.updateShadow(this.style.shadowStroke ?? false);
|
|
340
342
|
if (tabs === 0) {
|
|
341
|
-
this.context.strokeText(
|
|
343
|
+
this.context.strokeText(line, linePositionX, linePositionY);
|
|
342
344
|
} else {
|
|
343
|
-
this.renderTabLine(
|
|
345
|
+
this.renderTabLine(line, linePositionX, linePositionY, false);
|
|
344
346
|
}
|
|
345
347
|
}
|
|
346
348
|
if (this.style.fill) {
|
|
347
349
|
this.updateShadow(this.style.shadowFill ?? false);
|
|
348
350
|
if (tabs === 0) {
|
|
349
|
-
this.context.fillText(
|
|
351
|
+
this.context.fillText(line, linePositionX, linePositionY);
|
|
350
352
|
} else {
|
|
351
|
-
this.renderTabLine(
|
|
353
|
+
this.renderTabLine(line, linePositionX, linePositionY, true);
|
|
352
354
|
}
|
|
353
355
|
}
|
|
354
356
|
}
|
|
@@ -738,7 +740,7 @@ export class Text extends Image {
|
|
|
738
740
|
* @param {string} font - The font string to convert.
|
|
739
741
|
* @returns {{ font: string, fontStyle?: string, fontVariant?: string, fontWeight?: string, fontSize?: string, fontFamily?: string }} The font components.
|
|
740
742
|
*/
|
|
741
|
-
public fontToComponents(font: string) {
|
|
743
|
+
public fontToComponents(font: string): FontComponents {
|
|
742
744
|
// The format is specified in http://www.w3.org/TR/CSS2/fonts.html#font-shorthand:
|
|
743
745
|
// style - normal | italic | oblique | inherit
|
|
744
746
|
// variant - normal | small-caps | inherit
|
|
@@ -826,19 +828,20 @@ export class Text extends Image {
|
|
|
826
828
|
* @param {string[]|string[][]} list - The list of text to parse.
|
|
827
829
|
* @returns {Text} This Text object for chaining.
|
|
828
830
|
*/
|
|
829
|
-
public parseList(list:
|
|
831
|
+
public parseList(list: string[] | string[][]): this {
|
|
830
832
|
if (!Array.isArray(list)) {
|
|
831
833
|
return this;
|
|
832
834
|
}
|
|
833
835
|
let s = '';
|
|
834
836
|
for (let i = 0; i < list.length; i += 1) {
|
|
835
|
-
|
|
836
|
-
|
|
837
|
+
const row = list[i]!;
|
|
838
|
+
if (Array.isArray(row)) {
|
|
839
|
+
s += row.join('\t');
|
|
837
840
|
if (i < list.length - 1) {
|
|
838
841
|
s += '\n';
|
|
839
842
|
}
|
|
840
843
|
} else {
|
|
841
|
-
s +=
|
|
844
|
+
s += row;
|
|
842
845
|
if (i < list.length - 1) {
|
|
843
846
|
s += '\t';
|
|
844
847
|
}
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
import type { NormalShader } from './shader/normal.js';
|
|
3
|
+
|
|
4
|
+
/** A shader uniform: its GLSL type and the value bound to it. */
|
|
5
|
+
export type ShaderUniform = {
|
|
6
|
+
type: string;
|
|
7
|
+
value: unknown;
|
|
8
|
+
};
|
|
9
|
+
|
|
1
10
|
export class AbstractFilter {
|
|
2
|
-
|
|
3
|
-
public passes
|
|
4
|
-
public shaders
|
|
5
|
-
public dirty
|
|
6
|
-
public padding
|
|
7
|
-
public uniforms
|
|
8
|
-
public fragmentSrc
|
|
11
|
+
public _UID: string;
|
|
12
|
+
public passes: AbstractFilter[];
|
|
13
|
+
public shaders: NormalShader[];
|
|
14
|
+
public dirty: boolean;
|
|
15
|
+
public padding: number;
|
|
16
|
+
public uniforms: Record<string, ShaderUniform>;
|
|
17
|
+
public fragmentSrc: string[];
|
|
9
18
|
/**
|
|
10
19
|
* Creates a new AbstractFilter instance.
|
|
11
20
|
* @param {string[]} fragmentSrc - The fragment shader source.
|
|
12
21
|
* @param {object} uniforms - The uniform variables for the shader.
|
|
13
22
|
*/
|
|
14
|
-
public constructor(fragmentSrc: string[], uniforms?:
|
|
23
|
+
public constructor(fragmentSrc: string[], uniforms?: Record<string, ShaderUniform>) {
|
|
24
|
+
this._UID = uuidv4();
|
|
15
25
|
this.passes = [this];
|
|
16
26
|
this.shaders = [];
|
|
17
27
|
this.dirty = true;
|
|
@@ -24,8 +34,8 @@ export class AbstractFilter {
|
|
|
24
34
|
* Initializes the filter.
|
|
25
35
|
*/
|
|
26
36
|
public syncUniforms(): void {
|
|
27
|
-
for (
|
|
28
|
-
|
|
37
|
+
for (const shader of this.shaders) {
|
|
38
|
+
shader.dirty = true;
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
41
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export class WebGLBlendModeManager {
|
|
2
|
-
|
|
3
|
-
public
|
|
4
|
-
public currentBlendMode: any = 99_999;
|
|
2
|
+
public gl!: WebGLRenderingContext;
|
|
3
|
+
public currentBlendMode = 99_999;
|
|
5
4
|
/**
|
|
6
5
|
* Creates a new BlendModeManager instance.
|
|
7
6
|
*/
|
|
@@ -26,7 +25,7 @@ export class WebGLBlendModeManager {
|
|
|
26
25
|
this.currentBlendMode = blendMode;
|
|
27
26
|
const blendModeWebGL = globalThis.PhaserRegistry.blendModesWebGL[this.currentBlendMode];
|
|
28
27
|
if (blendModeWebGL) {
|
|
29
|
-
this.gl.blendFunc(blendModeWebGL[0]
|
|
28
|
+
this.gl.blendFunc(blendModeWebGL[0]!, blendModeWebGL[1]!);
|
|
30
29
|
}
|
|
31
30
|
return true;
|
|
32
31
|
}
|
|
@@ -35,6 +34,6 @@ export class WebGLBlendModeManager {
|
|
|
35
34
|
* Sets the blend mode for the WebGL context.
|
|
36
35
|
*/
|
|
37
36
|
public destroy(): void {
|
|
38
|
-
this.gl = null
|
|
37
|
+
this.gl = null!;
|
|
39
38
|
}
|
|
40
39
|
}
|