Browse Source

Upgrades have a cost. Added cost to tooltip (so much for using the "right tense" in commit messages lul)

tags/v0.0.1
Fen Dweller 7 years ago
parent
commit
f051dcbc30
No known key found for this signature in database GPG Key ID: E80B35A6F11C3656
4 changed files with 38 additions and 1 deletions
  1. +15
    -1
      constants.js
  2. +7
    -0
      gorge.css
  3. +1
    -0
      gorge.html
  4. +15
    -0
      gorge.js

+ 15
- 1
constants.js View File

@@ -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"
}
} }
} }

+ 7
- 0
gorge.css View File

@@ -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;


+ 1
- 0
gorge.html View File

@@ -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>


+ 15
- 0
gorge.js View File

@@ -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);


Loading…
Cancel
Save