From 87a76f2aeb4da2ef966d743b2df73b8c83ec76ef Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sat, 21 Jul 2018 22:22:56 -0500 Subject: [PATCH] Prod-all upgrades, fixed application of prod upgrades, fixed polyfill whoops --- constants.js | 90 +++++++++++++++++++++++++++++++++++++++++++++------- gorge.css | 12 ++++--- gorge.js | 47 +++++++++++++++++++++++---- polyfill.js | 3 +- 4 files changed, 127 insertions(+), 25 deletions(-) diff --git a/constants.js b/constants.js index a59e54b..d558257 100644 --- a/constants.js +++ b/constants.js @@ -114,12 +114,20 @@ const buildings = { } const upgrade_types = { - "prod-2x": { - "apply": function(productivity) { + "prod": { + "apply": function(effect, productivity) { return productivity * 2; }, - "desc": function(name) { - return "2x food production from " + name; + "desc": function(effect) { + return "2x food production from " + effect.target; + } + }, + "prod-all": { + "apply": function(effect, productivity) { + return productivity * effect.amount; + }, + "desc": function(effect) { + return Math.round((effect.amount - 1) * 100) + "% increase to food production"; } } } @@ -132,8 +140,9 @@ const upgrades = { "food": buildings.micro.cost * 5 }, "effect": { - "type": "prod-2x", - "target": "micro" + "type": "prod", + "target": "micro", + "amount": 2, }, "prereqs": { "buildings": { @@ -148,8 +157,9 @@ const upgrades = { "food": buildings.micro.cost * 50 }, "effect": { - "type": "prod-2x", - "target": "micro" + "type": "prod", + "target": "micro", + "amount": 2, }, "prereqs": { "buildings": { @@ -167,8 +177,9 @@ const upgrades = { "food": buildings.anthro.cost * 5 }, "effect": { - "type": "prod-2x", - "target": "anthro" + "type": "prod", + "target": "anthro", + "amount": 2, }, "prereqs": { "buildings": { @@ -183,8 +194,9 @@ const upgrades = { "food": buildings.anthro.cost * 50 }, "effect": { - "type": "prod-2x", - "target": "anthro" + "type": "prod", + "target": "anthro", + "amount": 2, }, "prereqs": { "buildings": { @@ -194,5 +206,59 @@ const upgrades = { "anthro-prod-1" ] } + }, + "prod-1": { + "name": "Sloth Metabolism", + "desc": "Burn those calories. Eventually.", + "cost": { + "food": 5e2 + }, + "effect": { + "type": "prod-all", + "amount": 1.05 + }, + "prereqs": { + "productivity": { + "food": 1e1 + } + }, + }, + "prod-2": { + "name": "Decent Metabolism", + "desc": "Picking up the pace.", + "cost": { + "food": 5e3 + }, + "effect": { + "type": "prod-all", + "amount": 1.05 + }, + "prereqs": { + "productivity": { + "food": 1e2 + }, + "upgrades": [ + "prod-1" + ] + }, + }, + "prod-3": { + "name": "Perky Metabolism", + "desc": "Sweat a little.", + "cost": { + "food": 5e4 + }, + "effect": { + "type": "prod-all", + "amount": 1.05 + }, + "prereqs": { + "productivity": { + "food": 1e3 + }, + "upgrades": [ + "prod-2" + ] + }, } } diff --git a/gorge.css b/gorge.css index 2576c3a..a738f11 100644 --- a/gorge.css +++ b/gorge.css @@ -213,8 +213,8 @@ body.dark { } .upgrade-button { - width: 75px; - height: 75px; + width: 100px; + height: 100px; display: block; background-color: #444; user-select: none; @@ -229,9 +229,11 @@ body.dark { .upgrade-button-name { position: relative; text-align: center; - width: 75px; - height: 75px + width: 100px; + height: 100px; top: 50%; + bottom: 50%; + right: 50%; left: 50%; - margin: 18.75px -37.5px; + margin: -25px -50px; } diff --git a/gorge.js b/gorge.js index 83ba667..ac42f58 100644 --- a/gorge.js +++ b/gorge.js @@ -10,11 +10,24 @@ let resources = {}; let updateRate = 60; +let currentProductivity = {}; + function calculateProductivity() { let productivity = 0; for (const [key, value] of Object.entries(belongings)) { productivity += productivityOf(key); } + + for (const [key, value] of Object.entries(upgrades)) { + if (!ownedUpgrades[key]) { + continue; + } + + if (value.effect.type == "prod-all") { + productivity *= value.effect.amount; + } + } + return productivity; } @@ -29,9 +42,9 @@ function productivityMultiplierOf(type) { } - if (value.effect.type == "prod-2x") { + if (value.effect.type == "prod") { if (value.effect.target == type) { - base *= 2; + base *= value.effect.amount; } } } @@ -67,6 +80,7 @@ function buyBuilding(type) { // update stuff function updateDisplay() { + updateProductivity(); addResources(); displayResources(); displayBuildings(); @@ -75,8 +89,12 @@ function updateDisplay() { setTimeout(updateDisplay, 1000/updateRate); } +function updateProductivity() { + currentProductivity["food"] = calculateProductivity(); +} + function addResources() { - resources.food += calculateProductivity() * 1 / updateRate; + resources.food += currentProductivity["food"] * 1 / updateRate; } function displayResources() { @@ -163,7 +181,7 @@ function buyUpgrade(id) { let upgrade = upgrades[id]; - if (!canAfford(upgrade.cost)) { + if (!upgradeAvailable(id)) { return; } @@ -204,6 +222,10 @@ function initializeData() { belongings[key].visible = false; } + for (const [key, value] of Object.entries(resourceTypes)) { + currentProductivity[key] = 0; + } + for (const [key, value] of Object.entries(upgrades)) { ownedUpgrades[key] = false; } @@ -263,7 +285,7 @@ function upgradeReachable(id) { for (let upgrade of reqs) { if (!ownedUpgrades[upgrade]) { return false; - } + }currentProductivity["food"] = 0; } } } @@ -271,7 +293,6 @@ function upgradeReachable(id) { return true; } function upgradeAvailable(id) { - if (!upgradeReachable(id)) { return false; } @@ -287,6 +308,11 @@ function upgradeAvailable(id) { return false; } } + } else if (type == "productivity") { + console.log(type, reqs); + if (currentProductivity < reqs) { + return false; + } } } @@ -388,6 +414,13 @@ function renderPrereqs(prereqs) { "valid": belongings[id].count >= amount }); } + } else if (key == "productivity") { + for (const [id, amount] of Object.entries(prereqs.productivity)) { + list.push({ + "text": amount + " " + resourceTypes[id].name + "/s", + "valid": currentProductivity[id].count >= amount + }); + } } } @@ -410,7 +443,7 @@ function upgradeTooltip(id, event) { fillTooltip("upgrade", "name", upgrades[id].name); fillTooltip("upgrade", "desc", upgrades[id].desc); - fillTooltip("upgrade", "effect", upgrade_types[upgrades[id].effect.type].desc(buildings[upgrades[id].effect.target].name)); + fillTooltip("upgrade", "effect", upgrade_types[upgrades[id].effect.type].desc(upgrades[id].effect)); fillTooltip("upgrade", "cost", renderCost(upgrades[id].cost)); fillTooltip("upgrade", "prereqs", renderPrereqs(upgrades[id].prereqs)); diff --git a/polyfill.js b/polyfill.js index 207a036..8460c6c 100644 --- a/polyfill.js +++ b/polyfill.js @@ -1,4 +1,4 @@ -if (!Object.entries) +if (!Object.entries) { console.log("Your browser doesn't support Object.entries()") Object.entries = function( obj ){ var ownProps = Object.keys( obj ), @@ -9,3 +9,4 @@ if (!Object.entries) return resArray; }; +}