From 8678caf6c5801357641a69b61bc47bf44165ef66 Mon Sep 17 00:00:00 2001 From: tobspr Date: Sat, 23 May 2020 11:03:58 +0200 Subject: [PATCH] Add keys to zoom in / out --- src/js/core/config.js | 2 +- src/js/game/camera.js | 5 ++++- src/js/game/key_action_mapper.js | 13 ++++++++----- translations/base-en.yaml | 3 +++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/js/core/config.js b/src/js/core/config.js index 973c5f26..a758cf48 100644 --- a/src/js/core/config.js +++ b/src/js/core/config.js @@ -83,7 +83,7 @@ export const globalConfig = { debug: { /* dev:start */ - // fastGameEnter: true, + fastGameEnter: true, noArtificialDelays: true, // disableSavegameWrite: true, // showEntityBounds: true, diff --git a/src/js/game/camera.js b/src/js/game/camera.js index d7608ce9..c95970c1 100644 --- a/src/js/game/camera.js +++ b/src/js/game/camera.js @@ -343,6 +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)); + mapper.getBinding(KEYMAPPINGS.ingame.centerMap).add(() => this.centerOnMap()); } @@ -823,7 +826,7 @@ export class Camera extends BasicSerializableObject { internalUpdateZooming(now, dt) { if (!this.currentlyPinching && this.desiredZoom !== null) { const diff = this.zoomLevel - this.desiredZoom; - if (Math_abs(diff) > 0.05) { + if (Math_abs(diff) > 0.0001) { let fade = 0.94; if (diff > 0) { // Zoom out faster than in diff --git a/src/js/game/key_action_mapper.js b/src/js/game/key_action_mapper.js index 40774933..9ab089c3 100644 --- a/src/js/game/key_action_mapper.js +++ b/src/js/game/key_action_mapper.js @@ -32,6 +32,9 @@ export const KEYMAPPINGS = { toggleHud: { keyCode: 113 }, // F2 toggleFPSInfo: { keyCode: 115 }, // F1 + + mapZoomIn: { keyCode: 187, repeated: true }, // "+" + mapZoomOut: { keyCode: 189, repeated: true }, // "-" }, buildings: { @@ -193,13 +196,11 @@ export function getStringForKeyCode(code) { case 186: return ";"; case 187: - return "="; + return "+"; case 188: return ","; case 189: return "-"; - case 189: - return "."; case 191: return "/"; case 219: @@ -223,12 +224,14 @@ export class Keybinding { * @param {object} param0 * @param {number} param0.keyCode * @param {boolean=} param0.builtin + * @param {boolean=} param0.repeated */ - constructor(app, { keyCode, builtin = false }) { + constructor(app, { keyCode, builtin = false, repeated = false }) { assert(keyCode && Number.isInteger(keyCode), "Invalid key code: " + keyCode); this.app = app; this.keyCode = keyCode; this.builtin = builtin; + this.repeated = repeated; this.currentlyDown = false; @@ -363,7 +366,7 @@ export class KeyActionMapper { for (const key in this.keybindings) { /** @type {Keybinding} */ const binding = this.keybindings[key]; - if (binding.keyCode === keyCode && !binding.currentlyDown) { + if (binding.keyCode === keyCode && (!binding.currentlyDown || binding.repeated)) { binding.currentlyDown = true; /** @type {Signal} */ diff --git a/translations/base-en.yaml b/translations/base-en.yaml index 7af068b9..c3095aa9 100644 --- a/translations/base-en.yaml +++ b/translations/base-en.yaml @@ -502,6 +502,9 @@ keybindings: centerMap: Center Map + mapZoomIn: Zoom in + mapZoomOut: Zoom out + menuOpenShop: Upgrades menuOpenStats: Statistics