Implemented hotkeys

This commit is contained in:
thepaperpilot 2021-06-24 19:06:53 -05:00
parent 2bea76fc61
commit 9502430280
2 changed files with 30 additions and 4 deletions

View file

@ -391,9 +391,16 @@ export function addLayer(layer, player = null) {
} }
if (layer.hotkeys) { if (layer.hotkeys) {
for (let id in layer.hotkeys) { for (let id in layer.hotkeys) {
if (isPlainObject(layer.hotkeys[id])) {
if (layer.hotkeys[id].onPress) { if (layer.hotkeys[id].onPress) {
layer.hotkeys[id].onPress.forceCached = false; 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 // Register hotkeys
if (layer.hotkeys) { if (layer.hotkeys) {
for (let id in layer.hotkeys) { for (let id in layer.hotkeys) {
hotkeys[id] = layer.hotkeys[id]; hotkeys[layer.hotkeys[id].key] = layer.hotkeys[id];
} }
} }
} }

View file

@ -1,6 +1,6 @@
import Decimal from './bignum'; import Decimal from './bignum';
import { isPlainObject } from './common'; import { isPlainObject } from './common';
import { layers } from '../store/layers'; import { layers, hotkeys } from '../store/layers';
import { player } from '../store/proxies'; import { player } from '../store/proxies';
export function resetLayer(layer, force = false) { 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?.();
}
}
}