From 47c4bbcd23be71afad809d1cfc55ec41b86af188 Mon Sep 17 00:00:00 2001 From: Dimava Date: Wed, 27 May 2020 16:23:13 +0300 Subject: [PATCH] Round zoom to 2**(1/4) --- src/js/game/camera.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/js/game/camera.js b/src/js/game/camera.js index 7fb25b32..1492f5a0 100644 --- a/src/js/game/camera.js +++ b/src/js/game/camera.js @@ -343,8 +343,9 @@ export class Camera extends BasicSerializableObject { mapper.getBinding(KEYMAPPINGS.ingame.mapMoveRight).add(() => (this.keyboardForce.x = 1)); mapper.getBinding(KEYMAPPINGS.ingame.mapMoveLeft).add(() => (this.keyboardForce.x = -1)); - mapper.getBinding(KEYMAPPINGS.ingame.mapZoomIn).add(() => (this.desiredZoom = this.zoomLevel * 1.2)); - mapper.getBinding(KEYMAPPINGS.ingame.mapZoomOut).add(() => (this.desiredZoom = this.zoomLevel * 0.8)); + const roundToPow = (v, n)=> Math.pow(2, Math.round(Math.log2(v) * n) / n); + mapper.getBinding(KEYMAPPINGS.ingame.mapZoomIn).add(() => (this.desiredZoom = roundToPow(this.zoomLevel * 1.2, 4))); + mapper.getBinding(KEYMAPPINGS.ingame.mapZoomOut).add(() => (this.desiredZoom = roundToPow(this.zoomLevel * 0.8, 4))); mapper.getBinding(KEYMAPPINGS.ingame.centerMap).add(() => this.centerOnMap()); } @@ -499,7 +500,8 @@ export class Camera extends BasicSerializableObject { assert(Number.isFinite(this.zoomLevel), "Got invalid zoom level *after* wheel: " + this.zoomLevel); this.clampZoomLevel(); - this.desiredZoom = null; + const roundToPow = (v, n)=> Math.pow(2, Math.round(Math.log2(v) * n) / n); + this.desiredZoom = roundToPow(this.zoomLevel, 4); return false; }