1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2025-05-10 20:11:33 +00:00

Added the ability to define hotkeys from layer config (adds functionality and to the list on the info page)

This commit is contained in:
Acamaeda 2020-09-30 21:30:50 -04:00
parent 2933537307
commit 08daba7f4c
4 changed files with 41 additions and 18 deletions

View file

@ -5,7 +5,7 @@ var NaNalert = false;
var gameEnded = false;
let VERSION = {
num: 1.1,
num: "1.1.1",
name: "Enhanced Edition"
}
@ -694,28 +694,35 @@ function switchTheme() {
resizeCanvas()
}
function updateHotkeys()
{
hotkeys = {};
for (layer in layers){
hk = layers[layer].hotkeys
if (hk){
for (id in hk){
hotkeys[hk[id].key] = hk[id]
hotkeys[hk[id].key].layer = layer
}
}
}
}
updateHotkeys()
document.onkeydown = function(e) {
if (player===undefined) return;
if (gameEnded&&!player.keepGoing) return;
let shiftDown = e.shiftKey
let ctrlDown = e.ctrlKey
let key = e.key
if (ctrlDown) key = "ctrl+" + key
if (onFocused) return
if (ctrlDown && key != "-" && key != "_" && key != "+" && key != "=" && key != "r" && key != "R" && key != "F5") e.preventDefault()
if (false && key >= 0 && key <= 9) {
//if (key == 0) activateSpell(10)
//else activateSpell(key)
return
} else if ((!LAYERS.includes(key)) || ctrlDown || shiftDown) {
switch(key) {
case "???":
if (player.c.unl) doReset("c")
return
case "bbbbb":
if (ctrlDown && player.c.unl) doReset("c")
return
}
} else if (player[key].unl) doReset(key)
console.log(key)
if(hotkeys[key]){
if (player[hotkeys[key].layer].unl)
hotkeys[key].onPress()
}
}
var onFocused = false