|
|
@@ -4,9 +4,7 @@ let belongings = {}; |
|
|
|
|
|
|
|
|
let ownedUpgrades = {}; |
|
|
let ownedUpgrades = {}; |
|
|
|
|
|
|
|
|
let resources = { |
|
|
|
|
|
"food": 0 |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
let resources = {}; |
|
|
|
|
|
|
|
|
let updateRate = 60; |
|
|
let updateRate = 60; |
|
|
|
|
|
|
|
|
@@ -23,6 +21,17 @@ function calculateProductivity() { |
|
|
function productivityOf(type) { |
|
|
function productivityOf(type) { |
|
|
let baseProd = buildings[type].prod; |
|
|
let baseProd = buildings[type].prod; |
|
|
|
|
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(upgrades)) { |
|
|
|
|
|
if (!ownedUpgrades[key]) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
console.log(value); |
|
|
|
|
|
if (value.effect.type == "prod-2x") { |
|
|
|
|
|
if (value.effect.target == key) { |
|
|
|
|
|
baseProd *= 2; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
return baseProd * belongings[type].count; |
|
|
return baseProd * belongings[type].count; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -66,19 +75,20 @@ function displayResources() { |
|
|
|
|
|
|
|
|
function displayBuildings() { |
|
|
function displayBuildings() { |
|
|
for (const [key, value] of Object.entries(belongings)) { |
|
|
for (const [key, value] of Object.entries(belongings)) { |
|
|
|
|
|
let button = document.querySelector("#building-" + key); |
|
|
|
|
|
|
|
|
document.querySelector("#building-" + key + " > .building-button-name").innerText = value.count + " " + (value.count == 1 ? buildings[key].name : buildings[key].plural); |
|
|
document.querySelector("#building-" + key + " > .building-button-name").innerText = value.count + " " + (value.count == 1 ? buildings[key].name : buildings[key].plural); |
|
|
document.querySelector("#building-" + key + " > .building-button-cost").innerText = costOfBuilding(key) + " food"; |
|
|
document.querySelector("#building-" + key + " > .building-button-cost").innerText = costOfBuilding(key) + " food"; |
|
|
|
|
|
|
|
|
if (costOfBuilding(key) > resources.food) { |
|
|
if (costOfBuilding(key) > resources.food) { |
|
|
document.querySelector("#building-" + key).classList.add("building-button-disabled"); |
|
|
|
|
|
|
|
|
button.classList.add("building-button-disabled"); |
|
|
} else { |
|
|
} else { |
|
|
document.querySelector("#building-" + key).classList.remove("building-button-disabled"); |
|
|
|
|
|
|
|
|
button.classList.remove("building-button-disabled"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function canAfford(cost) { |
|
|
function canAfford(cost) { |
|
|
console.log(cost) |
|
|
|
|
|
for (const [resource, amount] of Object.entries(cost)) { |
|
|
for (const [resource, amount] of Object.entries(cost)) { |
|
|
if (resources[resource] < amount) { |
|
|
if (resources[resource] < amount) { |
|
|
return false; |
|
|
return false; |
|
|
@@ -136,6 +146,7 @@ function eatMicro() { |
|
|
function setup() { |
|
|
function setup() { |
|
|
initializeData(); |
|
|
initializeData(); |
|
|
createButtons(); |
|
|
createButtons(); |
|
|
|
|
|
createDisplays(); |
|
|
registerListeners(); |
|
|
registerListeners(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
@@ -184,6 +195,39 @@ function createBuildings() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function createUpgrades() { |
|
|
|
|
|
let container = document.querySelector("#upgrades-list"); |
|
|
|
|
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(upgrades)) { |
|
|
|
|
|
let button = document.createElement("div"); |
|
|
|
|
|
button.classList.add("upgrade-button"); |
|
|
|
|
|
button.id = "upgrade-" + key; |
|
|
|
|
|
let buttonName = document.createElement("div"); |
|
|
|
|
|
buttonName.classList.add("upgrade-button-name"); |
|
|
|
|
|
buttonName.innerText = value.name; |
|
|
|
|
|
button.appendChild(buttonName); |
|
|
|
|
|
|
|
|
|
|
|
button.addEventListener("mousemove", function(e) { upgradeTooltip(key, e); }); |
|
|
|
|
|
button.addEventListener("mouseleave", function() { upgradeTooltipRemove(); }); |
|
|
|
|
|
button.addEventListener("click", function() { buyUpgrade(key); }); |
|
|
|
|
|
|
|
|
|
|
|
container.appendChild(button); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function createDisplays() { |
|
|
|
|
|
let resourceList = document.querySelector("#resource-list"); |
|
|
|
|
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(resourceTypes)) { |
|
|
|
|
|
resources[key] = 0; |
|
|
|
|
|
|
|
|
|
|
|
let line = document.createElement("div"); |
|
|
|
|
|
|
|
|
|
|
|
line.id = "resource-" + key; |
|
|
|
|
|
|
|
|
|
|
|
resourceList.appendChild(line); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
function renderCost(cost) { |
|
|
function renderCost(cost) { |
|
|
let list = []; |
|
|
let list = []; |
|
|
|
|
|
|
|
|
@@ -225,26 +269,6 @@ function upgradeTooltipRemove() { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function createUpgrades() { |
|
|
|
|
|
let container = document.querySelector("#upgrades-list"); |
|
|
|
|
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(upgrades)) { |
|
|
|
|
|
let button = document.createElement("div"); |
|
|
|
|
|
button.classList.add("upgrade-button"); |
|
|
|
|
|
button.id = "upgrade-" + key; |
|
|
|
|
|
let buttonName = document.createElement("div"); |
|
|
|
|
|
buttonName.classList.add("upgrade-button-name"); |
|
|
|
|
|
buttonName.innerText = value.name; |
|
|
|
|
|
button.appendChild(buttonName); |
|
|
|
|
|
|
|
|
|
|
|
button.addEventListener("mousemove", function(e) { upgradeTooltip(key, e); }); |
|
|
|
|
|
button.addEventListener("mouseleave", function() { upgradeTooltipRemove(); }); |
|
|
|
|
|
button.addEventListener("click", function() { buyUpgrade(key); }); |
|
|
|
|
|
|
|
|
|
|
|
container.appendChild(button); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window.onload = function() { |
|
|
window.onload = function() { |
|
|
setup(); |
|
|
setup(); |
|
|
|
|
|
|
|
|
|