| @@ -1,5 +1,10 @@ | |||||
| "use strict"; | "use strict"; | ||||
| const resourceTypes = { | |||||
| "food": { | |||||
| name: "Food" | |||||
| } | |||||
| } | |||||
| const buildings = { | const buildings = { | ||||
| "micro": { | "micro": { | ||||
| "name": "Micro", | "name": "Micro", | ||||
| @@ -48,6 +53,9 @@ const upgrades = { | |||||
| "micro-prod-1": { | "micro-prod-1": { | ||||
| "name": "Bigger Micros", | "name": "Bigger Micros", | ||||
| "desc": "A macro micro? Certainly more filling.", | "desc": "A macro micro? Certainly more filling.", | ||||
| "cost": { | |||||
| "food": 100 | |||||
| }, | |||||
| "effect": { | "effect": { | ||||
| "type": "prod-2x", | "type": "prod-2x", | ||||
| "target": "micro" | "target": "micro" | ||||
| @@ -56,6 +64,12 @@ const upgrades = { | |||||
| "micro-prod-2": { | "micro-prod-2": { | ||||
| "name": "Beefy Micros", | "name": "Beefy Micros", | ||||
| "desc": "25% more protein, 10% fewer carbs.", | "desc": "25% more protein, 10% fewer carbs.", | ||||
| "effect": "prod-2x" | |||||
| "cost": { | |||||
| "food": 500 | |||||
| }, | |||||
| "effect": { | |||||
| "type": "prod-2x", | |||||
| "target": "micro" | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -91,6 +91,13 @@ body.dark { | |||||
| position: absolute; | position: absolute; | ||||
| top: 50px; | top: 50px; | ||||
| } | } | ||||
| #upgrade-tooltip-cost { | |||||
| position: absolute; | |||||
| right: 0px; | |||||
| bottom: 0px; | |||||
| } | |||||
| .upgrade-button { | .upgrade-button { | ||||
| width: 75px; | width: 75px; | ||||
| height: 75px; | height: 75px; | ||||
| @@ -31,6 +31,7 @@ | |||||
| <div id="upgrade-tooltip"> | <div id="upgrade-tooltip"> | ||||
| <div id="upgrade-tooltip-desc"></div> | <div id="upgrade-tooltip-desc"></div> | ||||
| <div id="upgrade-tooltip-effect"></div> | <div id="upgrade-tooltip-effect"></div> | ||||
| <div id="upgrade-tooltip-cost"></div> | |||||
| </div> | </div> | ||||
| <div id="upgrades-list"></div> | <div id="upgrades-list"></div> | ||||
| </div> | </div> | ||||
| @@ -123,6 +123,16 @@ function createBuildings() { | |||||
| } | } | ||||
| } | } | ||||
| function renderCost(cost) { | |||||
| let list = []; | |||||
| for (const [key, value] of Object.entries(cost)) { | |||||
| list.push(value + " " + resourceTypes[key].name); | |||||
| } | |||||
| return list.join(", "); | |||||
| } | |||||
| function upgradeTooltip(id, event) { | function upgradeTooltip(id, event) { | ||||
| console.log(upgrades[id].desc); | console.log(upgrades[id].desc); | ||||
| console.log(event.clientX, event.clientY); | console.log(event.clientX, event.clientY); | ||||
| @@ -138,6 +148,11 @@ function upgradeTooltip(id, event) { | |||||
| let tooltipEffect = document.querySelector("#upgrade-tooltip-effect"); | let tooltipEffect = document.querySelector("#upgrade-tooltip-effect"); | ||||
| tooltipEffect.innerText = upgrade_types[upgrades[id].effect.type].desc(buildings[upgrades[id].effect.target].name); | tooltipEffect.innerText = upgrade_types[upgrades[id].effect.type].desc(buildings[upgrades[id].effect.target].name); | ||||
| let tooltipCost = document.querySelector("#upgrade-tooltip-cost"); | |||||
| tooltipCost.innerText = renderCost(upgrades[id].cost); | |||||
| let yOffset = tooltip.parentElement.getBoundingClientRect().y; | let yOffset = tooltip.parentElement.getBoundingClientRect().y; | ||||
| let yTrans = Math.round(event.clientY - yOffset); | let yTrans = Math.round(event.clientY - yOffset); | ||||