Kaynağa Gözat

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

tags/v0.0.6
Fen Dweller 5 yıl önce
ebeveyn
işleme
013e5d4593
Veri tabanında bu imza için bilinen anahtar bulunamadı GPG Anahtar Kimliği: E80B35A6F11C3656
3 değiştirilmiş dosya ile 52 ekleme ve 2 silme
  1. +1
    -0
      gorge.html
  2. +42
    -1
      gorge.js
  3. +9
    -1
      numbers.js

+ 1
- 0
gorge.html Dosyayı Görüntüle

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


+ 42
- 1
gorge.js Dosyayı Görüntüle

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

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 = [];

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

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

// update stuff

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

cache.resourceLabels = resourceLabels;

const optionButtons = {};

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

cache.optionButtons = optionButtons;
}

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

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

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

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

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

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(
@@ -1178,3 +1214,8 @@ function load() {
function reset() {
window.localStorage.clear();
}

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

+ 9
- 1
numbers.js Dosyayı Görüntüle

@@ -1,5 +1,5 @@
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) {
@@ -45,3 +45,11 @@ _numberWords = {
19: "novemdecillion",
20: "vigintillion",
}

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

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

Yükleniyor…
İptal
Kaydet