From 08daba7f4c52e98455dfb0db70fa2a4289649dff Mon Sep 17 00:00:00 2001 From: Acamaeda Date: Wed, 30 Sep 2020 21:30:50 -0400 Subject: [PATCH] Added the ability to define hotkeys from layer config (adds functionality and to the list on the info page) --- index.html | 8 +++++++- js/game.js | 37 ++++++++++++++++++++++--------------- js/layers.js | 11 ++++++++++- js/v.js | 3 ++- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index 694f8f9..296c90f 100644 --- a/index.html +++ b/index.html @@ -42,6 +42,12 @@

+ + +

v1.1.1

+

v1.1: Enhanced Edition


diff --git a/js/game.js b/js/game.js index 40e8ecd..e170ac4 100644 --- a/js/game.js +++ b/js/game.js @@ -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 diff --git a/js/layers.js b/js/layers.js index 6825bb4..916e509 100644 --- a/js/layers.js +++ b/js/layers.js @@ -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() } \ No newline at end of file diff --git a/js/v.js b/js/v.js index 36e3b61..489a039 100644 --- a/js/v.js +++ b/js/v.js @@ -179,7 +179,8 @@ function loadVue() { keepGoing, VERSION, ENDGAME, - LAYERS + LAYERS, + hotkeys }, }) } \ No newline at end of file