Add keys to zoom in / out

This commit is contained in:
tobspr 2020-05-23 11:03:58 +02:00
parent 1561246dc4
commit 8678caf6c5
4 changed files with 16 additions and 7 deletions

View File

@ -83,7 +83,7 @@ export const globalConfig = {
debug: {
/* dev:start */
// fastGameEnter: true,
fastGameEnter: true,
noArtificialDelays: true,
// disableSavegameWrite: true,
// showEntityBounds: true,

View File

@ -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

View File

@ -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} */

View File

@ -502,6 +502,9 @@ keybindings:
centerMap: Center Map
mapZoomIn: Zoom in
mapZoomOut: Zoom out
menuOpenShop: Upgrades
menuOpenStats: Statistics