diff --git a/src/store/layers.js b/src/store/layers.js index 3758181..fa268d6 100644 --- a/src/store/layers.js +++ b/src/store/layers.js @@ -391,8 +391,15 @@ export function addLayer(layer, player = null) { } if (layer.hotkeys) { for (let id in layer.hotkeys) { - if (layer.hotkeys[id].onPress) { - layer.hotkeys[id].onPress.forceCached = false; + if (isPlainObject(layer.hotkeys[id])) { + if (layer.hotkeys[id].onPress) { + layer.hotkeys[id].onPress.forceCached = false; + } + if (layer.hotkeys[id].unlocked == undefined) { + layer.hotkeys[id].unlocked = function() { + return layer.unlocked; + } + } } } } @@ -407,7 +414,7 @@ export function addLayer(layer, player = null) { // Register hotkeys if (layer.hotkeys) { for (let id in layer.hotkeys) { - hotkeys[id] = layer.hotkeys[id]; + hotkeys[layer.hotkeys[id].key] = layer.hotkeys[id]; } } } diff --git a/src/util/layers.js b/src/util/layers.js index c5c1c09..f94fca2 100644 --- a/src/util/layers.js +++ b/src/util/layers.js @@ -1,6 +1,6 @@ import Decimal from './bignum'; import { isPlainObject } from './common'; -import { layers } from '../store/layers'; +import { layers, hotkeys } from '../store/layers'; import { player } from '../store/proxies'; export function resetLayer(layer, force = false) { @@ -292,3 +292,22 @@ export const defaultLayerProperties = { } } }; + +document.onkeydown = function(e) { + if (player.hasWon && !player.keepGoing) { + return; + } + let key = e.key; + if (e.shiftKey) { + key = "shift+" + key; + } + if (e.ctrlKey) { + key = "ctrl+" + key; + } + if (hotkeys[key]) { + e.preventDefault(); + if (hotkeys[key].unlocked) { + hotkeys[key].onPress?.(); + } + } +}