2021-05-04 11:29:37 +02:00
|
|
|
import "jasmine";
|
|
|
|
import {HdpiManager} from "../../../src/Phaser/Services/HdpiManager";
|
|
|
|
|
|
|
|
describe("Test HdpiManager", () => {
|
|
|
|
it("should match screen size if size is too small.", () => {
|
2021-05-04 14:08:40 +02:00
|
|
|
const hdpiManager = new HdpiManager(640*480, 64*64);
|
2021-05-04 11:29:37 +02:00
|
|
|
|
|
|
|
const result = hdpiManager.getOptimalGameSize({ width: 320, height: 200 });
|
|
|
|
expect(result.game.width).toEqual(320);
|
|
|
|
expect(result.game.height).toEqual(200);
|
|
|
|
expect(result.real.width).toEqual(320);
|
|
|
|
expect(result.real.height).toEqual(200);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should match multiple just above.", () => {
|
2021-05-04 14:08:40 +02:00
|
|
|
const hdpiManager = new HdpiManager(640*480, 64*64);
|
2021-05-04 11:29:37 +02:00
|
|
|
|
|
|
|
let result = hdpiManager.getOptimalGameSize({ width: 960, height: 600 });
|
|
|
|
expect(result.game.width).toEqual(960);
|
|
|
|
expect(result.game.height).toEqual(600);
|
|
|
|
|
|
|
|
result = hdpiManager.getOptimalGameSize({ width: 640 * 2 + 50, height: 480 * 2 + 50 });
|
|
|
|
expect(result.game.width).toEqual(Math.ceil((640 * 2 + 50) / 2));
|
|
|
|
expect(result.game.height).toEqual((480 * 2 + 50) / 2);
|
|
|
|
|
|
|
|
result = hdpiManager.getOptimalGameSize({ width: 640 * 3 + 50, height: 480 * 3 + 50 });
|
|
|
|
expect(result.game.width).toEqual(Math.ceil((640 * 3 + 50) / 3));
|
|
|
|
expect(result.game.height).toEqual(Math.ceil((480 * 3 + 50) / 3));
|
|
|
|
expect(result.real.width).toEqual(result.game.width * 3);
|
|
|
|
expect(result.real.height).toEqual(result.game.height * 3);
|
|
|
|
});
|
2021-05-04 14:08:40 +02:00
|
|
|
|
|
|
|
it("should not zoom in too much.", () => {
|
|
|
|
const hdpiManager = new HdpiManager(640*480, 64*64);
|
|
|
|
|
|
|
|
hdpiManager.zoomModifier = 11;
|
|
|
|
|
2021-05-05 13:14:00 +02:00
|
|
|
const result = hdpiManager.getOptimalGameSize({ width: 640, height: 640 });
|
2021-05-04 14:08:40 +02:00
|
|
|
expect(result.game.width).toEqual(64);
|
|
|
|
expect(result.game.height).toEqual(64);
|
|
|
|
expect(hdpiManager.zoomModifier).toEqual(10);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not zoom out too much.", () => {
|
|
|
|
const hdpiManager = new HdpiManager(640*480, 64*64);
|
|
|
|
|
|
|
|
hdpiManager.zoomModifier = 1/10;
|
|
|
|
|
2021-05-05 13:14:00 +02:00
|
|
|
const result = hdpiManager.getOptimalGameSize({ width: 1280, height: 768 });
|
2021-05-04 14:08:40 +02:00
|
|
|
expect(result.game.width).toEqual(1280);
|
|
|
|
expect(result.game.height).toEqual(768);
|
2021-05-17 15:49:18 +02:00
|
|
|
expect(hdpiManager.zoomModifier).toEqual(2 / 3);
|
2021-05-04 14:08:40 +02:00
|
|
|
});
|
2021-05-04 11:29:37 +02:00
|
|
|
});
|