Browse Source

Add scientific/full number modes, plus a button to cycle them

tags/v0.0.6
Fen Dweller 5 years ago
parent
commit
013e5d4593
No known key found for this signature in database GPG Key ID: E80B35A6F11C3656
3 changed files with 52 additions and 2 deletions
  1. +1
    -0
      gorge.html
  2. +42
    -1
      gorge.js
  3. +9
    -1
      numbers.js

+ 1
- 0
gorge.html View File

@@ -26,6 +26,7 @@
<br> <br>
<button id="save">Save</button> <button id="save">Save</button>
<button id="reset">Reset saved data</button> <button id="reset">Reset saved data</button>
<button id="numbers">Number mode???</button>
</div> </div>
<div id="resources-area"> <div id="resources-area">
<div id="resources" class="title">Resources</div> <div id="resources" class="title">Resources</div>


+ 42
- 1
gorge.js View File

@@ -25,6 +25,28 @@ let shiftHeld = false;


let mouseTarget = undefined; let mouseTarget = undefined;


const numberModes = {
words: {
name: "Words",
render: numberText,
next: "scientific"
},
scientific: {
name: "Scientific",
render: numberScientific,
next: "full",
},
full: {
name: "Full",
render: numberFull,
next: "words"
}
}

deepFreeze(numberModes);

let numberMode = numberModes["words"];

const activePowerups = []; const activePowerups = [];


function tickPowerups(delta) { function tickPowerups(delta) {
@@ -177,7 +199,13 @@ function updateAll() {
updateProductivity(); updateProductivity();
updateClickBonus(); updateClickBonus();
updateClickVictim(); updateClickVictim();
updateOptions();
}

function updateOptions() {
cache.optionButtons.numbers.innerText = "Number mode: " + numberMode.name;
} }

// update stuff // update stuff


function updateDisplay() { function updateDisplay() {
@@ -489,6 +517,12 @@ function initializeCaches() {
}); });


cache.resourceLabels = resourceLabels; cache.resourceLabels = resourceLabels;

const optionButtons = {};

optionButtons.numbers = document.querySelector("#numbers");

cache.optionButtons = optionButtons;
} }


const states = {}; const states = {};
@@ -603,6 +637,8 @@ function registerListeners() {


document.querySelector("#reset").addEventListener("click", reset); document.querySelector("#reset").addEventListener("click", reset);


document.querySelector("#numbers").addEventListener("click", cycleNumbers);

document.querySelector("#upgrades").addEventListener("click", switchShowOwnedUpgrades); document.querySelector("#upgrades").addEventListener("click", switchShowOwnedUpgrades);


document.addEventListener("keydown", e => { document.addEventListener("keydown", e => {
@@ -1051,7 +1087,7 @@ function prodSummary(id) {
let list = []; let list = [];


list.push( list.push(
{ "text": "Each " + buildings[id].name + " produces " + render(belongings[id].count == 0 ? 0 : contributions[id].food / belongings[id].count, 3) + " food/sec" }
{ "text": "Each " + buildings[id].name + " produces " + render(belongings[id].count == 0 ? 0 : contributions[id].food / belongings[id].count, 3) + " food/sec" }
); );


list.push( list.push(
@@ -1178,3 +1214,8 @@ function load() {
function reset() { function reset() {
window.localStorage.clear(); window.localStorage.clear();
} }

function cycleNumbers() {
numberMode = numberModes[numberMode.next];
updateOptions();
}

+ 9
- 1
numbers.js View File

@@ -1,5 +1,5 @@
function render(val, places = 1, smallPlaces = 0) { function render(val, places = 1, smallPlaces = 0) {
return numberText(val, places, smallPlaces);
return numberMode.render(val, places, smallPlaces);
} }


function numberText(val, places = 1, smallPlaces = 0) { function numberText(val, places = 1, smallPlaces = 0) {
@@ -45,3 +45,11 @@ _numberWords = {
19: "novemdecillion", 19: "novemdecillion",
20: "vigintillion", 20: "vigintillion",
} }

function numberScientific(val, places = 1, smallPlaces) {
return val.toExponential(places)
}

function numberFull(val, places = 1, smallPlaces) {
return round(val, places);
}

Loading…
Cancel
Save