Add keys to zoom in / out
This commit is contained in:
parent
1561246dc4
commit
8678caf6c5
|
@ -83,7 +83,7 @@ export const globalConfig = {
|
||||||
|
|
||||||
debug: {
|
debug: {
|
||||||
/* dev:start */
|
/* dev:start */
|
||||||
// fastGameEnter: true,
|
fastGameEnter: true,
|
||||||
noArtificialDelays: true,
|
noArtificialDelays: true,
|
||||||
// disableSavegameWrite: true,
|
// disableSavegameWrite: true,
|
||||||
// showEntityBounds: true,
|
// showEntityBounds: true,
|
||||||
|
|
|
@ -343,6 +343,9 @@ export class Camera extends BasicSerializableObject {
|
||||||
mapper.getBinding(KEYMAPPINGS.ingame.mapMoveRight).add(() => (this.keyboardForce.x = 1));
|
mapper.getBinding(KEYMAPPINGS.ingame.mapMoveRight).add(() => (this.keyboardForce.x = 1));
|
||||||
mapper.getBinding(KEYMAPPINGS.ingame.mapMoveLeft).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());
|
mapper.getBinding(KEYMAPPINGS.ingame.centerMap).add(() => this.centerOnMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -823,7 +826,7 @@ export class Camera extends BasicSerializableObject {
|
||||||
internalUpdateZooming(now, dt) {
|
internalUpdateZooming(now, dt) {
|
||||||
if (!this.currentlyPinching && this.desiredZoom !== null) {
|
if (!this.currentlyPinching && this.desiredZoom !== null) {
|
||||||
const diff = this.zoomLevel - this.desiredZoom;
|
const diff = this.zoomLevel - this.desiredZoom;
|
||||||
if (Math_abs(diff) > 0.05) {
|
if (Math_abs(diff) > 0.0001) {
|
||||||
let fade = 0.94;
|
let fade = 0.94;
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
// Zoom out faster than in
|
// Zoom out faster than in
|
||||||
|
|
|
@ -32,6 +32,9 @@ export const KEYMAPPINGS = {
|
||||||
|
|
||||||
toggleHud: { keyCode: 113 }, // F2
|
toggleHud: { keyCode: 113 }, // F2
|
||||||
toggleFPSInfo: { keyCode: 115 }, // F1
|
toggleFPSInfo: { keyCode: 115 }, // F1
|
||||||
|
|
||||||
|
mapZoomIn: { keyCode: 187, repeated: true }, // "+"
|
||||||
|
mapZoomOut: { keyCode: 189, repeated: true }, // "-"
|
||||||
},
|
},
|
||||||
|
|
||||||
buildings: {
|
buildings: {
|
||||||
|
@ -193,13 +196,11 @@ export function getStringForKeyCode(code) {
|
||||||
case 186:
|
case 186:
|
||||||
return ";";
|
return ";";
|
||||||
case 187:
|
case 187:
|
||||||
return "=";
|
return "+";
|
||||||
case 188:
|
case 188:
|
||||||
return ",";
|
return ",";
|
||||||
case 189:
|
case 189:
|
||||||
return "-";
|
return "-";
|
||||||
case 189:
|
|
||||||
return ".";
|
|
||||||
case 191:
|
case 191:
|
||||||
return "/";
|
return "/";
|
||||||
case 219:
|
case 219:
|
||||||
|
@ -223,12 +224,14 @@ export class Keybinding {
|
||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {number} param0.keyCode
|
* @param {number} param0.keyCode
|
||||||
* @param {boolean=} param0.builtin
|
* @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);
|
assert(keyCode && Number.isInteger(keyCode), "Invalid key code: " + keyCode);
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.keyCode = keyCode;
|
this.keyCode = keyCode;
|
||||||
this.builtin = builtin;
|
this.builtin = builtin;
|
||||||
|
this.repeated = repeated;
|
||||||
|
|
||||||
this.currentlyDown = false;
|
this.currentlyDown = false;
|
||||||
|
|
||||||
|
@ -363,7 +366,7 @@ export class KeyActionMapper {
|
||||||
for (const key in this.keybindings) {
|
for (const key in this.keybindings) {
|
||||||
/** @type {Keybinding} */
|
/** @type {Keybinding} */
|
||||||
const binding = this.keybindings[key];
|
const binding = this.keybindings[key];
|
||||||
if (binding.keyCode === keyCode && !binding.currentlyDown) {
|
if (binding.keyCode === keyCode && (!binding.currentlyDown || binding.repeated)) {
|
||||||
binding.currentlyDown = true;
|
binding.currentlyDown = true;
|
||||||
|
|
||||||
/** @type {Signal} */
|
/** @type {Signal} */
|
||||||
|
|
|
@ -502,6 +502,9 @@ keybindings:
|
||||||
|
|
||||||
centerMap: Center Map
|
centerMap: Center Map
|
||||||
|
|
||||||
|
mapZoomIn: Zoom in
|
||||||
|
mapZoomOut: Zoom out
|
||||||
|
|
||||||
menuOpenShop: Upgrades
|
menuOpenShop: Upgrades
|
||||||
menuOpenStats: Statistics
|
menuOpenStats: Statistics
|
||||||
|
|
||||||
|
|
Reference in New Issue