Skip to content

Commit

Permalink
Improved test coverage, improved type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
vpmedia committed Dec 3, 2024
1 parent 29a209c commit a76d6de
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/phaser/core/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ export class DOM {
*/
getScreenOrientation(primaryFallback) {
const screen = window.screen;
// @ts-ignore
const orientation = screen.orientation || screen.mozOrientation || screen.msOrientation;
if (orientation && typeof orientation.type === 'string') {
// Screen Orientation API specification
Expand Down
2 changes: 1 addition & 1 deletion src/phaser/core/signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Signal {
this.memorize = false;
this._shouldPropagate = true;
this.active = true;
this._boundDispatch = false;
this._boundDispatch = null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/phaser/core/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class Timer {
* TBD.
* @param {number} delay - TBD.
*/
start(delay) {
start(delay = 0) {
if (this.running) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/phaser/display/display_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class DisplayObject {
this.cachedBounds = new Rectangle(0, 0, 0, 0);
this.currentBounds = null;
this._mask = null;
this._filters = null;
this._filterBlock = null;
this.children = [];
this.ignoreChildInput = false;
}
Expand Down
9 changes: 5 additions & 4 deletions src/phaser/display/webgl/render_texture.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Rectangle } from '../../geom/rectangle.js';
import { RENDER_WEBGL } from '../../core/const.js';
import { Point } from '../../geom/point.js';
import { Texture } from './texture.js';
import { Rectangle } from '../../geom/rectangle.js';
import { CanvasBuffer } from '../canvas/buffer.js';
import { BaseTexture } from './base_texture.js';
import { FilterTexture } from './filter_texture.js';
import { CanvasBuffer } from '../canvas/buffer.js';
import { RENDER_WEBGL } from '../../core/const.js';
import { Texture } from './texture.js';

export class RenderTexture extends Texture {
/**
Expand Down Expand Up @@ -34,6 +34,7 @@ export class RenderTexture extends Texture {
this.crop = new Rectangle(0, 0, this.width * this.resolution, this.height * this.resolution);
this.renderer = renderer;
if (this.renderer.type === RENDER_WEBGL) {
// @ts-ignore
const gl = this.renderer.gl;
this.baseTexture._dirty[gl.id] = false;
this.textureBuffer = new FilterTexture(gl, this.width, this.height, this.baseTexture.scaleMode);
Expand Down
29 changes: 29 additions & 0 deletions src/phaser/geom/util/circle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Circle } from '../circle.js';
import { clone, contains, equals, intersects } from './circle.js';

it('should clone a circle', () => {
const circle1 = new Circle(0, 0, 10);
const circle2 = clone(circle1);
expect(circle1.x).toBe(circle2.x);
expect(circle1.y).toBe(circle2.y);
expect(circle1.radius).toBe(circle2.radius);
});

it('should contain a point in a circle', () => {
const circle = new Circle(5, 5, 10);
expect(contains(circle, 5, 5)).toBe(true);
});

it('should match two circles', () => {
const circle1 = new Circle(5, 5, 10);
const circle2 = new Circle(5, 5, 10);
expect(equals(circle1, circle2)).toBe(true);
circle2.x = 0;
expect(equals(circle1, circle2)).toBe(false);
});

it('should intersects two circles', () => {
const circle1 = new Circle(5, 5, 10);
const circle2 = new Circle(5, 5, 5);
expect(intersects(circle1, circle2)).toBe(true);
});
8 changes: 8 additions & 0 deletions src/phaser/geom/util/ellipse.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Ellipse } from '../ellipse.js';
import { contains } from './ellipse.js';

it('should contain an ellipse the given coordinates', () => {
const ellipse = new Ellipse(0, 0, 10, 10);
expect(contains(ellipse, 5, 5)).toBe(true);
expect(contains(ellipse, 15, 15)).toBe(false);
});
2 changes: 1 addition & 1 deletion src/phaser/geom/util/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const intersects = (a, b, asSegment, result) => {
*/
export const intersectsRectangle = (line, rect) => {
// Quick bail out of the Line and Rect bounds don't intersect
if (intersectsRect(line, rect)) {
if (!intersectsRect(line, rect)) {
return false;
}
const x1 = line.start.x;
Expand Down
11 changes: 11 additions & 0 deletions src/phaser/geom/util/line.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Line } from '../line.js';
import { clone } from './line.js';

it('should clone a line', () => {
const line1 = new Line(0, 0, 10, 0);
const line2 = clone(line1);
expect(line1.start.x).toBe(line2.start.x);
expect(line1.start.y).toBe(line2.start.y);
expect(line1.end.x).toBe(line2.end.x);
expect(line1.end.y).toBe(line2.end.y);
});
23 changes: 23 additions & 0 deletions src/phaser/geom/util/matrix.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Matrix } from '../matrix.js';
import { clone, getIdentityMatrix, getTempMatrix } from './matrix.js';

it('should clone a matrix', () => {
const matrix1 = new Matrix(2, 0, 0, 2, 0, 0);
const matrix2 = clone(matrix1);
expect(matrix1.a).toBe(matrix2.a);
expect(matrix1.b).toBe(matrix2.b);
expect(matrix1.c).toBe(matrix2.c);
expect(matrix1.d).toBe(matrix2.d);
expect(matrix1.tx).toBe(matrix2.tx);
expect(matrix1.ty).toBe(matrix2.ty);
});

it('should create an identity matrix', () => {
const matrix = getIdentityMatrix();
expect(matrix.a).toBe(1);
});

it('should create a temporary matrix', () => {
const matrix = getTempMatrix();
expect(matrix.a).toBe(1);
});
9 changes: 9 additions & 0 deletions src/phaser/geom/util/point.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Point } from '../point.js';
import { clone } from './point.js';

it('should clone a point', () => {
const point1 = new Point(1, 2);
const point2 = clone(point1);
expect(point1.x).toBe(point2.x);
expect(point1.y).toBe(point2.y);
});
13 changes: 13 additions & 0 deletions src/phaser/geom/util/polygon.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Polygon } from '../polygon.js';
import { clone } from './polygon.js';

it('should clone a polygon', () => {
const polygon = new Polygon([0, 0, 1, 0, 1, 1]);
const points = clone(polygon).toNumberArray();
expect(points[0]).toBe(0);
expect(points[1]).toBe(0);
expect(points[2]).toBe(1);
expect(points[3]).toBe(0);
expect(points[4]).toBe(1);
expect(points[5]).toBe(1);
});
11 changes: 11 additions & 0 deletions src/phaser/geom/util/rectangle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Rectangle } from '../rectangle.js';
import { clone } from './rectangle.js';

it('should clone a rectangle', () => {
const rectangle1 = new Rectangle(0, 0, 10, 10);
const rectangle2 = clone(rectangle1);
expect(rectangle1.x).toBe(rectangle2.x);
expect(rectangle1.y).toBe(rectangle2.y);
expect(rectangle1.width).toBe(rectangle2.width);
expect(rectangle1.height).toBe(rectangle2.height);
});
12 changes: 12 additions & 0 deletions src/phaser/geom/util/rounded_rectangle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { RoundedRectangle } from '../rounded_rectangle.js';
import { clone } from './rounded_rectangle.js';

it('should clone a rounded rectangle', () => {
const rectangle1 = new RoundedRectangle(0, 0, 10, 10, 2);
const rectangle2 = clone(rectangle1);
expect(rectangle1.x).toBe(rectangle2.x);
expect(rectangle1.y).toBe(rectangle2.y);
expect(rectangle1.width).toBe(rectangle2.width);
expect(rectangle1.height).toBe(rectangle2.height);
expect(rectangle1.radius).toBe(rectangle2.radius);
});
2 changes: 1 addition & 1 deletion types/phaser/core/dom.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/phaser/core/signal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export class Signal {
memorize: boolean;
_shouldPropagate: boolean;
active: boolean;
_boundDispatch: boolean;
_boundDispatch: (...rest: any[]) => void;
/**
* TBD.
* @param {Function} listener - TBD.
Expand Down
2 changes: 1 addition & 1 deletion types/phaser/core/signal.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/phaser/core/timer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class Timer {
* TBD.
* @param {number} delay - TBD.
*/
start(delay: number): void;
start(delay?: number): void;
/**
* TBD.
* @param {boolean} clearEvents - TBD.
Expand Down
2 changes: 1 addition & 1 deletion types/phaser/core/timer.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions types/phaser/display/display_object.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class DisplayObject {
cachedBounds: Rectangle;
currentBounds: any;
_mask: import("./graphics.js").Graphics;
_filters: any;
_filterBlock: any;
children: any[];
ignoreChildInput: boolean;
/**
Expand Down
2 changes: 1 addition & 1 deletion types/phaser/display/display_object.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a76d6de

Please sign in to comment.