1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-21 16:13:55 +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

@ -42,6 +42,12 @@
</div>
<div v-if="player.tab=='changelog'" class="col right">
<button class="back" onclick="showTab('tree')"></button><br>
<h3>v1.1.1</h3>
<ul>
<li>You can define hotkeys in layer config.</li>
</ul><br>
<h3>v1.1: Enhanced Edition</h3>
<ul>
<li>Added "Buyables", which can function like Space Buildings or Enhancers.</li>
@ -78,7 +84,7 @@
<br><br>
Time Played: {{ formatTime(player.timePlayed) }}<br><br>
<h3>Hotkeys</h3><br>
<span v-if="player.c.unl"><br>C: Reset candies for lollipops.</span>
<span v-for="key in hotkeys" v-if="player[key.layer].unl"><br>{{key.desc}}</span>
</div>
<div v-if="player.tab=='options'" class="col right">
<button class="back" onclick="showTab('tree')"></button><br>

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

View file

@ -139,8 +139,12 @@ var layers = {
updateTemp() {
}, // Do any necessary temp updating
resetsNothing() {return false},
hotkeys: [
{key: "c", desc: "C: reset for lollipops or whatever", onPress(){if (player.c.unl) doReset("c")}},
{key: "ctrl+c", desc: "Ctrl+c: respec things", onPress(){if (player.c.unl) respecBuyables("c")}},
],
incr_order: [], // Array of layer names to have their order increased when this one is first unlocked
// Optional, lets you format the tab yourself by listing components. You can create your own components in v.js.
tabFormat: ["main-display",
["prestige-button", function(){return "Melt your points into "}],
@ -188,6 +192,10 @@ function layerShown(layer){
var LAYERS = Object.keys(layers);
var hotkeys = {};
var ROW_LAYERS = {}
for (layer in layers){
row = layers[layer].row
@ -206,4 +214,5 @@ function addLayer(layerName, layerData){ // Call this to add layers from a diffe
ROW_LAYERS[row][layer]=layer;
}
updateHotkeys()
}

View file

@ -179,7 +179,8 @@ function loadVue() {
keepGoing,
VERSION,
ENDGAME,
LAYERS
LAYERS,
hotkeys
},
})
}