1
0
Fork 0
mirror of https://github.com/Acamaeda/The-Modding-Tree.git synced 2024-11-22 00:21:32 +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>
<div v-if="player.tab=='changelog'" class="col right"> <div v-if="player.tab=='changelog'" class="col right">
<button class="back" onclick="showTab('tree')"></button><br> <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> <h3>v1.1: Enhanced Edition</h3>
<ul> <ul>
<li>Added "Buyables", which can function like Space Buildings or Enhancers.</li> <li>Added "Buyables", which can function like Space Buildings or Enhancers.</li>
@ -78,7 +84,7 @@
<br><br> <br><br>
Time Played: {{ formatTime(player.timePlayed) }}<br><br> Time Played: {{ formatTime(player.timePlayed) }}<br><br>
<h3>Hotkeys</h3><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>
<div v-if="player.tab=='options'" class="col right"> <div v-if="player.tab=='options'" class="col right">
<button class="back" onclick="showTab('tree')"></button><br> <button class="back" onclick="showTab('tree')"></button><br>

View file

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

View file

@ -139,6 +139,10 @@ var layers = {
updateTemp() { updateTemp() {
}, // Do any necessary temp updating }, // Do any necessary temp updating
resetsNothing() {return false}, 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 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. // Optional, lets you format the tab yourself by listing components. You can create your own components in v.js.
@ -188,6 +192,10 @@ function layerShown(layer){
var LAYERS = Object.keys(layers); var LAYERS = Object.keys(layers);
var hotkeys = {};
var ROW_LAYERS = {} var ROW_LAYERS = {}
for (layer in layers){ for (layer in layers){
row = layers[layer].row 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; ROW_LAYERS[row][layer]=layer;
} }
updateHotkeys()
} }

View file

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