@@ -309,6 +309,7 @@ function switchShowOwnedUpgrades() {
function displayUpgrades(owned) {
function displayUpgrades(owned) {
if (owned) {
if (owned) {
Object.entries(ownedUpgrades).forEach(([key, val]) => {
Object.entries(ownedUpgrades).forEach(([key, val]) => {
let button = cache.upgradeButtons[key];
let button = cache.upgradeButtons[key];
if (val) {
if (val) {
button.classList.remove("hidden");
button.classList.remove("hidden");
@@ -320,20 +321,29 @@ function displayUpgrades(owned) {
else {
else {
for (let id of remainingUpgrades) {
for (let id of remainingUpgrades) {
let button = cache.upgradeButtons[id];
let button = cache.upgradeButtons[id];
let visible = states.upgrades[id].visible;
let available = states.upgrades[id].available;
if (ownedUpgrades[id]) {
if (ownedUpgrades[id] && visible !== false ) {
button.classList.add("hidden");
button.classList.add("hidden");
states.upgrades[id].visible = false;
continue;
continue;
}
}
if (upgradeReachable(id)) {
if (upgradeReachable(id) && visible !== true) {
button.classList.remove("hidden");
button.classList.remove("hidden");
} else {
states.upgrades[id].visible = true;
} else if (!upgradeReachable(id) && visible !== false) {
button.classList.add("hidden");
button.classList.add("hidden");
states.upgrades[id].visible = false;
}
}
if (upgradeAvailable(id)) {
if (upgradeAvailable(id) && available !== true) {
button.classList.remove("upgrade-button-inactive");
button.classList.remove("upgrade-button-inactive");
} else {
states.upgrades[id].available = true;
} else if (!upgradeAvailable(id) && available !== false) {
button.classList.add("upgrade-button-inactive");
button.classList.add("upgrade-button-inactive");
states.upgrades[id].available = false;
}
}
}
}
@@ -419,6 +429,7 @@ function setup() {
load();
load();
unlockAtStart();
unlockAtStart();
initializeCaches();
initializeCaches();
initializeStates();
updateAll();
updateAll();
}
}
@@ -453,6 +464,25 @@ function initializeCaches() {
cache.upgradeButtons = upgradeButtons;
cache.upgradeButtons = upgradeButtons;
}
}
const states = {};
// we can keep track of some things, like whether
// specific upgrades are currently visible. this
// way, we don't have to set them visible every tick;
// we can just check if they've been handled already
function initializeStates() {
const upgradeStates = {};
Object.keys(upgrades).forEach(key => {
upgradeStates[key] = {
visible: undefined,
available: undefined
}
});
states.upgrades = upgradeStates;
}
function unlockAtStart() {
function unlockAtStart() {
unlockBuilding("micro");
unlockBuilding("micro");