mirror of
https://github.com/thepaperpilot/Planar-Pioneers.git
synced 2024-11-25 09:51:50 +00:00
Implemented hotkeys
This commit is contained in:
parent
2bea76fc61
commit
9502430280
2 changed files with 30 additions and 4 deletions
|
@ -391,9 +391,16 @@ export function addLayer(layer, player = null) {
|
|||
}
|
||||
if (layer.hotkeys) {
|
||||
for (let id in layer.hotkeys) {
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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?.();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue