|
|
@@ -29,7 +29,7 @@ function tickPowerups(delta) { |
|
|
const powerupList = document.querySelector("#powerup-list"); |
|
|
const powerupList = document.querySelector("#powerup-list"); |
|
|
let changed = false; |
|
|
let changed = false; |
|
|
// I love mutating arrays as I traverse them. |
|
|
// I love mutating arrays as I traverse them. |
|
|
for (let i = activePowerups.length-1; i >= 0; i--) { |
|
|
|
|
|
|
|
|
for (let i = activePowerups.length - 1; i >= 0; i--) { |
|
|
activePowerups[i].lifetime -= delta; |
|
|
activePowerups[i].lifetime -= delta; |
|
|
if (activePowerups[i].lifetime <= 0) { |
|
|
if (activePowerups[i].lifetime <= 0) { |
|
|
const entry = activePowerups[i]; |
|
|
const entry = activePowerups[i]; |
|
|
@@ -56,12 +56,12 @@ function addPowerup(powerup) { |
|
|
|
|
|
|
|
|
const powerupEntry = document.createElement("div"); |
|
|
const powerupEntry = document.createElement("div"); |
|
|
powerupEntry.classList.add("powerup-entry"); |
|
|
powerupEntry.classList.add("powerup-entry"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
powerupEntry.innerText = powerup.name; |
|
|
powerupEntry.innerText = powerup.name; |
|
|
|
|
|
|
|
|
powerupList.appendChild(powerupEntry); |
|
|
powerupList.appendChild(powerupEntry); |
|
|
|
|
|
|
|
|
activePowerups.push({powerup: powerup, lifetime: powerup.duration, element: powerupEntry}); |
|
|
|
|
|
|
|
|
activePowerups.push({ powerup: powerup, lifetime: powerup.duration, element: powerupEntry }); |
|
|
|
|
|
|
|
|
updateAll(); |
|
|
updateAll(); |
|
|
} |
|
|
} |
|
|
@@ -81,7 +81,7 @@ function calculateProductivity() { |
|
|
let productivity = 0; |
|
|
let productivity = 0; |
|
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(belongings)) { |
|
|
for (const [key, value] of Object.entries(belongings)) { |
|
|
productivity += productivityOf(key); |
|
|
|
|
|
|
|
|
productivity += productivityOf(key); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return productivity; |
|
|
return productivity; |
|
|
@@ -128,7 +128,7 @@ function costOfBuilding(type, count = 1) { |
|
|
total += countCost; |
|
|
total += countCost; |
|
|
count--; |
|
|
count--; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Math.round(total); |
|
|
return Math.round(total); |
|
|
} |
|
|
} |
|
|
@@ -143,7 +143,7 @@ function buildingCount() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
function buyBuilding(type, e) { |
|
|
function buyBuilding(type, e) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const count = buildingCount(); |
|
|
const count = buildingCount(); |
|
|
|
|
|
|
|
|
let cost = costOfBuilding(type, count); |
|
|
let cost = costOfBuilding(type, count); |
|
|
@@ -177,7 +177,7 @@ function updateDisplay() { |
|
|
displayUpgrades(showOwnedUpgrades); |
|
|
displayUpgrades(showOwnedUpgrades); |
|
|
tickPowerups(delta); |
|
|
tickPowerups(delta); |
|
|
|
|
|
|
|
|
setTimeout(updateDisplay, 1000/updateRate); |
|
|
|
|
|
|
|
|
setTimeout(updateDisplay, 1000 / updateRate); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function updateProductivity() { |
|
|
function updateProductivity() { |
|
|
@@ -185,7 +185,7 @@ function updateProductivity() { |
|
|
|
|
|
|
|
|
activePowerups.forEach(entry => { |
|
|
activePowerups.forEach(entry => { |
|
|
const powerup = entry.powerup; |
|
|
const powerup = entry.powerup; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const state = { |
|
|
const state = { |
|
|
ownedUpgrades: ownedUpgrades, |
|
|
ownedUpgrades: ownedUpgrades, |
|
|
resources: resources, |
|
|
resources: resources, |
|
|
@@ -196,7 +196,7 @@ function updateProductivity() { |
|
|
console.log(currentProductivity); |
|
|
console.log(currentProductivity); |
|
|
|
|
|
|
|
|
powerup.effect(state); |
|
|
powerup.effect(state); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(currentProductivity); |
|
|
console.log(currentProductivity); |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
@@ -221,8 +221,8 @@ function renderResources() { |
|
|
let line1 = render(value, 3, 0) + " " + resourceTypes[key].name; |
|
|
let line1 = render(value, 3, 0) + " " + resourceTypes[key].name; |
|
|
let line2 = render(currentProductivity[key], 1, 1) + " " + resourceTypes[key].name + "/sec"; |
|
|
let line2 = render(currentProductivity[key], 1, 1) + " " + resourceTypes[key].name + "/sec"; |
|
|
|
|
|
|
|
|
list.push({"text": line1, "class": "resource-quantity"}); |
|
|
|
|
|
list.push({"text": line2, "class": "resource-rate"}); |
|
|
|
|
|
|
|
|
list.push({ "text": line1, "class": "resource-quantity" }); |
|
|
|
|
|
list.push({ "text": line2, "class": "resource-rate" }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return renderLines(list); |
|
|
return renderLines(list); |
|
|
@@ -238,8 +238,8 @@ function displayBuildings() { |
|
|
} else { |
|
|
} else { |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
belongings[key].visible = true; |
|
|
|
|
|
document.querySelector("#building-" + key).classList.remove("hidden"); |
|
|
|
|
|
|
|
|
belongings[key].visible = true; |
|
|
|
|
|
document.querySelector("#building-" + key).classList.remove("hidden"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
let button = document.querySelector("#building-" + key); |
|
|
let button = document.querySelector("#building-" + key); |
|
|
@@ -249,7 +249,7 @@ function displayBuildings() { |
|
|
|
|
|
|
|
|
name.innerText = value.count + " " + (value.count == 1 ? buildings[key].name : buildings[key].plural); |
|
|
name.innerText = value.count + " " + (value.count == 1 ? buildings[key].name : buildings[key].plural); |
|
|
cost.innerText = render(costOfBuilding(key, count)) + " food"; |
|
|
cost.innerText = render(costOfBuilding(key, count)) + " food"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (costOfBuilding(key, count) > resources.food) { |
|
|
if (costOfBuilding(key, count) > resources.food) { |
|
|
button.classList.add("building-button-disabled"); |
|
|
button.classList.add("building-button-disabled"); |
|
|
cost.classList.add("building-button-cost-invalid"); |
|
|
cost.classList.add("building-button-cost-invalid"); |
|
|
@@ -300,7 +300,7 @@ function displayUpgrades(owned) { |
|
|
else { |
|
|
else { |
|
|
for (let id of remainingUpgrades) { |
|
|
for (let id of remainingUpgrades) { |
|
|
let button = document.querySelector("#upgrade-" + id); |
|
|
let button = document.querySelector("#upgrade-" + id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ownedUpgrades[id]) { |
|
|
if (ownedUpgrades[id]) { |
|
|
button.classList.add("hidden"); |
|
|
button.classList.add("hidden"); |
|
|
continue; |
|
|
continue; |
|
|
@@ -316,7 +316,7 @@ function displayUpgrades(owned) { |
|
|
button.classList.add("upgrade-button-inactive"); |
|
|
button.classList.add("upgrade-button-inactive"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// we aren't trimming the list of upgrades now |
|
|
// we aren't trimming the list of upgrades now |
|
|
// because we need to switch between owned and unowned upgrades |
|
|
// because we need to switch between owned and unowned upgrades |
|
|
// - thus we need to be able to show or hide anything |
|
|
// - thus we need to be able to show or hide anything |
|
|
@@ -451,7 +451,7 @@ function initializeData() { |
|
|
// I'm using apply() to pass on any number of arguments to the |
|
|
// I'm using apply() to pass on any number of arguments to the |
|
|
// apply() function of the effect type |
|
|
// apply() function of the effect type |
|
|
|
|
|
|
|
|
newEffect.apply = function(...args) { return effect_types[effect.type].apply.apply(null, [effect].concat(args)); } |
|
|
|
|
|
|
|
|
newEffect.apply = function (...args) { return effect_types[effect.type].apply.apply(null, [effect].concat(args)); } |
|
|
|
|
|
|
|
|
effects[effect.type].push(newEffect); |
|
|
effects[effect.type].push(newEffect); |
|
|
} |
|
|
} |
|
|
@@ -516,10 +516,10 @@ function createBuildings() { |
|
|
button.appendChild(buttonName); |
|
|
button.appendChild(buttonName); |
|
|
button.appendChild(buttonCost); |
|
|
button.appendChild(buttonCost); |
|
|
button.appendChild(buildingIcon); |
|
|
button.appendChild(buildingIcon); |
|
|
button.addEventListener("mousemove", function(e) { mouseTarget = button; buildingTooltip(key, e); }); |
|
|
|
|
|
button.addEventListener("mouseleave", function() { mouseTarget = undefined; buildingTooltipRemove(); }); |
|
|
|
|
|
button.addEventListener("click", function(e) { buyBuilding(key, e); }); |
|
|
|
|
|
button.addEventListener("click", function(e) { buildingTooltip(key, e); }); |
|
|
|
|
|
|
|
|
button.addEventListener("mousemove", function (e) { mouseTarget = button; buildingTooltip(key, e); }); |
|
|
|
|
|
button.addEventListener("mouseleave", function () { mouseTarget = undefined; buildingTooltipRemove(); }); |
|
|
|
|
|
button.addEventListener("click", function (e) { buyBuilding(key, e); }); |
|
|
|
|
|
button.addEventListener("click", function (e) { buildingTooltip(key, e); }); |
|
|
|
|
|
|
|
|
container.appendChild(button); |
|
|
container.appendChild(button); |
|
|
} |
|
|
} |
|
|
@@ -533,7 +533,7 @@ function upgradeReachable(id) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (upgrades[id].prereqs !== undefined ){ |
|
|
|
|
|
|
|
|
if (upgrades[id].prereqs !== undefined) { |
|
|
for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) { |
|
|
for (const [type, reqs] of Object.entries(upgrades[id].prereqs)) { |
|
|
if (type == "buildings") { |
|
|
if (type == "buildings") { |
|
|
for (const [building, amount] of Object.entries(reqs)) { |
|
|
for (const [building, amount] of Object.entries(reqs)) { |
|
|
@@ -604,14 +604,14 @@ function createUpgrades() { |
|
|
let upgradeIcon = document.createElement("i"); |
|
|
let upgradeIcon = document.createElement("i"); |
|
|
upgradeIcon.classList.add("fas"); |
|
|
upgradeIcon.classList.add("fas"); |
|
|
upgradeIcon.classList.add(value.icon); |
|
|
upgradeIcon.classList.add(value.icon); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
button.appendChild(buttonName); |
|
|
button.appendChild(buttonName); |
|
|
button.appendChild(upgradeIcon); |
|
|
button.appendChild(upgradeIcon); |
|
|
|
|
|
|
|
|
button.addEventListener("mouseenter", function(e) { mouseTarget = button; upgradeTooltip(key, e); }); |
|
|
|
|
|
button.addEventListener("mousemove", function(e) { mouseTarget = button; upgradeTooltip(key, e); }); |
|
|
|
|
|
button.addEventListener("mouseleave", function() { mouseTarget = undefined; upgradeTooltipRemove(); }); |
|
|
|
|
|
button.addEventListener("click", function(e) { buyUpgrade(key, e); }); |
|
|
|
|
|
|
|
|
button.addEventListener("mouseenter", function (e) { mouseTarget = button; upgradeTooltip(key, e); }); |
|
|
|
|
|
button.addEventListener("mousemove", function (e) { mouseTarget = button; upgradeTooltip(key, e); }); |
|
|
|
|
|
button.addEventListener("mouseleave", function () { mouseTarget = undefined; upgradeTooltipRemove(); }); |
|
|
|
|
|
button.addEventListener("click", function (e) { buyUpgrade(key, e); }); |
|
|
|
|
|
|
|
|
container.appendChild(button); |
|
|
container.appendChild(button); |
|
|
} |
|
|
} |
|
|
@@ -661,7 +661,7 @@ function renderCost(cost) { |
|
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(cost)) { |
|
|
for (const [key, value] of Object.entries(cost)) { |
|
|
list.push({ |
|
|
list.push({ |
|
|
"text": render(value,0) + " " + resourceTypes[key].name, |
|
|
|
|
|
|
|
|
"text": render(value, 0) + " " + resourceTypes[key].name, |
|
|
"valid": resources[key] >= value |
|
|
"valid": resources[key] >= value |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@@ -684,14 +684,14 @@ function renderPrereqs(prereqs) { |
|
|
if (key == "buildings") { |
|
|
if (key == "buildings") { |
|
|
for (const [id, amount] of Object.entries(prereqs.buildings)) { |
|
|
for (const [id, amount] of Object.entries(prereqs.buildings)) { |
|
|
list.push({ |
|
|
list.push({ |
|
|
"text": buildings[id].name + " x" + render(amount,0), |
|
|
|
|
|
|
|
|
"text": buildings[id].name + " x" + render(amount, 0), |
|
|
"valid": belongings[id].count >= amount |
|
|
"valid": belongings[id].count >= amount |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} else if (key == "productivity") { |
|
|
} else if (key == "productivity") { |
|
|
for (const [id, amount] of Object.entries(prereqs.productivity)) { |
|
|
for (const [id, amount] of Object.entries(prereqs.productivity)) { |
|
|
list.push({ |
|
|
list.push({ |
|
|
"text": render(amount,0) + " " + resourceTypes[id].name + "/s", |
|
|
|
|
|
|
|
|
"text": render(amount, 0) + " " + resourceTypes[id].name + "/s", |
|
|
"valid": currentProductivity[id] >= amount |
|
|
"valid": currentProductivity[id] >= amount |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@@ -705,7 +705,7 @@ function renderEffects(effectList) { |
|
|
let list = []; |
|
|
let list = []; |
|
|
|
|
|
|
|
|
for (let effect of effectList) { |
|
|
for (let effect of effectList) { |
|
|
list.push({"text": effect_types[effect.type].desc(effect)}); |
|
|
|
|
|
|
|
|
list.push({ "text": effect_types[effect.type].desc(effect) }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return renderLines(list); |
|
|
return renderLines(list); |
|
|
@@ -796,7 +796,7 @@ function doPowerup() { |
|
|
|
|
|
|
|
|
button.classList.add("powerup"); |
|
|
button.classList.add("powerup"); |
|
|
|
|
|
|
|
|
button.style.setProperty("--lifetime", lifetime/1000 + "s"); |
|
|
|
|
|
|
|
|
button.style.setProperty("--lifetime", lifetime / 1000 + "s"); |
|
|
button.style.setProperty("--leftpos", left); |
|
|
button.style.setProperty("--leftpos", left); |
|
|
button.style.setProperty("--toppos", top); |
|
|
button.style.setProperty("--toppos", top); |
|
|
|
|
|
|
|
|
@@ -813,7 +813,7 @@ function doPowerup() { |
|
|
const choice = Math.floor(Math.random() * choices.length); |
|
|
const choice = Math.floor(Math.random() * choices.length); |
|
|
|
|
|
|
|
|
const powerup = powerups[choices[choice]]; |
|
|
const powerup = powerups[choices[choice]]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const icon = document.createElement("div"); |
|
|
const icon = document.createElement("div"); |
|
|
|
|
|
|
|
|
icon.classList.add("fas"); |
|
|
icon.classList.add("fas"); |
|
|
@@ -850,12 +850,12 @@ function doPowerup() { |
|
|
} else { |
|
|
} else { |
|
|
powerup.effect(state); |
|
|
powerup.effect(state); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
powerup.popup(powerup, e); |
|
|
powerup.popup(powerup, e); |
|
|
button.classList.add("powerup-clicked"); |
|
|
button.classList.add("powerup-clicked"); |
|
|
resources.food += 1000; |
|
|
resources.food += 1000; |
|
|
clearTimeout(remove); |
|
|
clearTimeout(remove); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
body.removeChild(button); |
|
|
body.removeChild(button); |
|
|
}, 500); |
|
|
}, 500); |
|
|
@@ -867,7 +867,7 @@ function doPowerup() { |
|
|
|
|
|
|
|
|
function fillTooltip(type, field, content) { |
|
|
function fillTooltip(type, field, content) { |
|
|
let item = document.querySelector("#" + type + "-tooltip-" + field); |
|
|
let item = document.querySelector("#" + type + "-tooltip-" + field); |
|
|
if (typeof(content) === "string") { |
|
|
|
|
|
|
|
|
if (typeof (content) === "string") { |
|
|
item.innerText = content; |
|
|
item.innerText = content; |
|
|
} else { |
|
|
} else { |
|
|
replaceChildren(item, content); |
|
|
replaceChildren(item, content); |
|
|
@@ -910,11 +910,11 @@ function prodSummary(id) { |
|
|
let list = []; |
|
|
let list = []; |
|
|
|
|
|
|
|
|
list.push( |
|
|
list.push( |
|
|
{"text": "Each " + buildings[id].name + " produces " + round(productivityMultiplierOf(id) * buildings[id].prod,1) + " food/sec"} |
|
|
|
|
|
|
|
|
{ "text": "Each " + buildings[id].name + " produces " + round(productivityMultiplierOf(id) * buildings[id].prod, 1) + " food/sec" } |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
list.push( |
|
|
list.push( |
|
|
{"text": "Your " + render(belongings[id].count) + " " + (belongings[id].count == 1 ? buildings[id].name + " is": buildings[id].plural + " are") + " producing " + round(productivityOf(id),1) + " food/sec"} |
|
|
|
|
|
|
|
|
{ "text": "Your " + render(belongings[id].count) + " " + (belongings[id].count == 1 ? buildings[id].name + " is" : buildings[id].plural + " are") + " producing " + round(productivityOf(id), 1) + " food/sec" } |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
let percentage = round(100 * productivityOf(id) / currentProductivity["food"], 2); |
|
|
let percentage = round(100 * productivityOf(id) / currentProductivity["food"], 2); |
|
|
@@ -923,7 +923,7 @@ function prodSummary(id) { |
|
|
percentage = 0; |
|
|
percentage = 0; |
|
|
} |
|
|
} |
|
|
list.push( |
|
|
list.push( |
|
|
{"text": "(" + percentage + "% of all food)"} |
|
|
|
|
|
|
|
|
{ "text": "(" + percentage + "% of all food)" } |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
return renderLines(list); |
|
|
return renderLines(list); |
|
|
@@ -933,26 +933,26 @@ function buildingTooltip(id, event) { |
|
|
|
|
|
|
|
|
let tooltip = document.querySelector("#building-tooltip"); |
|
|
let tooltip = document.querySelector("#building-tooltip"); |
|
|
tooltip.style.setProperty("display", "inline-block"); |
|
|
tooltip.style.setProperty("display", "inline-block"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const count = buildingCount(); |
|
|
const count = buildingCount(); |
|
|
|
|
|
|
|
|
fillTooltip("building", "name", (count != 1 ? count +"x " : "") + buildings[id].name); |
|
|
|
|
|
|
|
|
fillTooltip("building", "name", (count != 1 ? count + "x " : "") + buildings[id].name); |
|
|
fillTooltip("building", "desc", buildings[id].desc); |
|
|
fillTooltip("building", "desc", buildings[id].desc); |
|
|
fillTooltip("building", "cost", render(costOfBuilding(id, count)) + " food"); |
|
|
fillTooltip("building", "cost", render(costOfBuilding(id, count)) + " food"); |
|
|
fillTooltip("building", "prod", prodSummary(id)); |
|
|
fillTooltip("building", "prod", prodSummary(id)); |
|
|
|
|
|
|
|
|
let xPos = tooltip.parentElement.getBoundingClientRect().x - 450; |
|
|
let xPos = tooltip.parentElement.getBoundingClientRect().x - 450; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// wow browsers are bad |
|
|
// wow browsers are bad |
|
|
|
|
|
|
|
|
var body = document.body, |
|
|
var body = document.body, |
|
|
html = document.documentElement; |
|
|
html = document.documentElement; |
|
|
|
|
|
|
|
|
var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); |
|
|
|
|
|
|
|
|
var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight); |
|
|
|
|
|
|
|
|
let yPos = Math.min(event.clientY, height - 200); |
|
|
let yPos = Math.min(event.clientY, height - 200); |
|
|
|
|
|
|
|
|
tooltip.style.setProperty("transform", "translate(" + xPos + "px, " + yPos + "px)") |
|
|
|
|
|
|
|
|
tooltip.style.setProperty("transform", "translate(" + xPos + "px, " + yPos + "px)") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function buildingTooltipRemove() { |
|
|
function buildingTooltipRemove() { |
|
|
@@ -961,7 +961,7 @@ function buildingTooltipRemove() { |
|
|
tooltip.style.setProperty("display", "none"); |
|
|
tooltip.style.setProperty("display", "none"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
window.onload = function() { |
|
|
|
|
|
|
|
|
window.onload = function () { |
|
|
setup(); |
|
|
setup(); |
|
|
|
|
|
|
|
|
lastTime = performance.now(); |
|
|
lastTime = performance.now(); |
|
|
@@ -969,7 +969,7 @@ window.onload = function() { |
|
|
doNews(); |
|
|
doNews(); |
|
|
doPowerup(); |
|
|
doPowerup(); |
|
|
|
|
|
|
|
|
setTimeout(updateDisplay, 1000/updateRate); |
|
|
|
|
|
|
|
|
setTimeout(updateDisplay, 1000 / updateRate); |
|
|
|
|
|
|
|
|
setTimeout(autosave, 60000); |
|
|
setTimeout(autosave, 60000); |
|
|
} |
|
|
} |
|
|
@@ -998,8 +998,8 @@ function saveGame() { |
|
|
storage.setItem("resources", JSON.stringify(resources)); |
|
|
storage.setItem("resources", JSON.stringify(resources)); |
|
|
|
|
|
|
|
|
storage.setItem("belongings", JSON.stringify(belongings)); |
|
|
storage.setItem("belongings", JSON.stringify(belongings)); |
|
|
} catch(e) { |
|
|
|
|
|
clickPopup("Can't save - no access to local storage.", "info", [window.innerWidth/2, window.innerHeight/5]); |
|
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
clickPopup("Can't save - no access to local storage.", "info", [window.innerWidth / 2, window.innerHeight / 5]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -1010,28 +1010,28 @@ function load() { |
|
|
if (!storage.getItem("save-version")) { |
|
|
if (!storage.getItem("save-version")) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let newOwnedUpgrades = JSON.parse(storage.getItem("ownedUpgrades")); |
|
|
let newOwnedUpgrades = JSON.parse(storage.getItem("ownedUpgrades")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(newOwnedUpgrades)) { |
|
|
for (const [key, value] of Object.entries(newOwnedUpgrades)) { |
|
|
ownedUpgrades[key] = value; |
|
|
ownedUpgrades[key] = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let newResources = JSON.parse(storage.getItem("resources")); |
|
|
let newResources = JSON.parse(storage.getItem("resources")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(newResources)) { |
|
|
for (const [key, value] of Object.entries(newResources)) { |
|
|
resources[key] = value; |
|
|
resources[key] = value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let newBelongings = JSON.parse(storage.getItem("belongings")); |
|
|
let newBelongings = JSON.parse(storage.getItem("belongings")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(newBelongings)) { |
|
|
for (const [key, value] of Object.entries(newBelongings)) { |
|
|
belongings[key] = value; |
|
|
belongings[key] = value; |
|
|
} |
|
|
} |
|
|
} catch(e) { |
|
|
|
|
|
clickPopup("Can't load - no access to local storage.", "info", [window.innerWidth/2, window.innerHeight/5]); |
|
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
clickPopup("Can't load - no access to local storage.", "info", [window.innerWidth / 2, window.innerHeight / 5]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function reset() { |
|
|
function reset() { |
|
|
|