working with zoom modifier calculating per zone

This commit is contained in:
Hanusiak Piotr 2021-12-02 17:46:09 +01:00
parent ddaa81a7ac
commit 37949eda53
4 changed files with 20 additions and 14 deletions

View file

@ -24,10 +24,7 @@ export class WaScaleManager {
public applyNewSize() {
const { width, height } = coWebsiteManager.getGameSize();
let devicePixelRatio = 1;
if (window.devicePixelRatio) {
devicePixelRatio = window.devicePixelRatio;
}
const devicePixelRatio = window.devicePixelRatio ?? 1;
const { game: gameSize, real: realSize } = this.hdpiManager.getOptimalGameSize({
width: width * devicePixelRatio,
@ -59,6 +56,19 @@ export class WaScaleManager {
this.game.markDirty();
}
public getTargetZoomModifierFor(viewportWidth: number, viewportHeight: number) {
const { width: gameWidth, height: gameHeight } = coWebsiteManager.getGameSize();
const devicePixelRatio = window.devicePixelRatio ?? 1;
const { game: gameSize, real: realSize } = this.hdpiManager.getOptimalGameSize({
width: gameWidth * devicePixelRatio,
height: gameHeight * devicePixelRatio,
});
// P.H. Note: Dunno where this magic 2 comes from
// Always return lowest possible value. Need to add MAX ZOOM MODIFIER value into this.
return Math.min(realSize.width / viewportWidth / 2, realSize.height / viewportHeight / 2);
}
public get zoomModifier(): number {
return this.hdpiManager.zoomModifier;
}