From af4d3c4a84727df2f21e6f1df9318946fa0398ae Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Fri, 13 Apr 2018 19:04:49 -0400 Subject: [PATCH] Previews have working units now. Turned off autocomplete --- game.js | 41 +++++++++- stroll.html | 212 ++++++++++++++++++++++++++-------------------------- units.js | 36 +++++++++ 3 files changed, 182 insertions(+), 107 deletions(-) diff --git a/game.js b/game.js index 32e5f05..1dabe5b 100644 --- a/game.js +++ b/game.js @@ -1428,6 +1428,18 @@ function toggle_units() update(); } +function toggle_units_options() +{ + switch(unit) { + case "metric": unit = "customary"; break; + case "customary": unit = "metric"; break; + } + + document.getElementById("button-units-options").innerHTML = "Units: " + unit.charAt(0).toUpperCase() + unit.slice(1); + + updateAllPreviews(); +} + function toggle_numbers() { switch(numbers) { case "full": numbers="prefix"; break; @@ -3397,11 +3409,30 @@ function updateAllPreviews() { } function updatePreview(name) { + let scale = document.getElementById("scale").value; + if (scale == "") + scale = document.getElementById("scale").placeholder; + let value = document.getElementById(name).value; + let unitType = document.getElementById(name).dataset.unit; + if (value == "") value = document.getElementById(name).placeholder; - document.getElementById(name + "Preview").innerHTML = value; + + let result = ""; + + if (unitType == "length") + result = length(value * scale, unit); + else if (unitType == "area") + result = area(value * scale * scale, unit); + else if (unitType == "volume") + result = volume(value * scale * scale * scale, unit); + else if (unitType == "mass") + result = mass(value * scale * scale * scale, unit); + + document.getElementById(name + "Preview").innerHTML = result; } + function debugLog() { console.log("Your character settings:"); console.log(JSON.stringify(generateSettings())); @@ -3426,7 +3457,11 @@ window.addEventListener('load', function(event) { document.querySelectorAll("input[type='number']").forEach(function(x) { x.addEventListener("input", function() { updatePreview(x.id); }); }); - + + updateAllPreviews(); + + document.querySelector("#scale").addEventListener("input", updateAllPreviews); + presets.sort(function(x,y) {return x.name.localeCompare(y.name); } ); let list = document.getElementById("character-presets"); @@ -3455,6 +3490,8 @@ window.addEventListener('load', function(event) { document.getElementById("button-dark-mode-options").addEventListener("click",toggleDarkMode); document.getElementById("button-dark-mode-game").addEventListener("click",toggleDarkMode); + document.getElementById("button-units-options").addEventListener("click",toggle_units_options); + document.getElementById("button-stats").addEventListener("click",showStats); document.getElementById("button-debug-log").addEventListener("click",debugLog); diff --git a/stroll.html b/stroll.html index 3e00209..608d697 100644 --- a/stroll.html +++ b/stroll.html @@ -46,32 +46,32 @@
Growth
- - - - - - @@ -217,7 +217,7 @@
- +
@@ -244,7 +244,7 @@ -

+

@@ -255,40 +255,40 @@
  • - +
  • - +
  • - +
  • - +
  • - +
  • - +
  • - +
  • - +
  • @@ -299,19 +299,19 @@
    @@ -323,19 +323,19 @@
  • - +
  • - +
  • - +
  • - +
  • @@ -345,11 +345,11 @@
  • - +
  • - +
  • @@ -371,13 +371,13 @@
  • - +
    • - +
    • @@ -391,7 +391,7 @@
      • - +
      • @@ -411,65 +411,67 @@
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - + +
      • - + +
        • - +
        • - +
        @@ -479,7 +481,7 @@
        - +
      • @@ -489,91 +491,91 @@
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
        • - +
        • - +
        • - +
        • - +
        • @@ -583,21 +585,21 @@
          • - +
          • - +
          • - +
          • - +
          @@ -607,126 +609,126 @@
          - +
        • - +
        • - +
        • - +
        • - +
        • - +
        • - +
        • - +
        • - +
      • - +
      • - +
      • - - + +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
      • - +
        • - +
        • - +
        • - +
        • - +
        • - +
        @@ -735,42 +737,42 @@
      • - +
      • - +
      • - +
        • - +
        • - +
        • - +
        • - +
        • - +
        @@ -779,7 +781,7 @@
        - +
      • @@ -787,28 +789,28 @@
      • - +
      • - +
      • - +
      • - +
      • - +
      diff --git a/units.js b/units.js index 85ea806..ab5ac04 100644 --- a/units.js +++ b/units.js @@ -121,6 +121,14 @@ function length(m, type="metric", singular=false) { } } +function area(m2, type="metric", singular=false) { + switch(type) { + case "metric": return metricArea(m2, singular); + case "customary": return customaryArea(m2, singular); + case "approx": return approxArea(m2, singular); + } +} + function volume(m3, type="metric", singular=false) { switch(type) { case "metric": return metricVolume(m3, singular); @@ -248,6 +256,34 @@ function approxLength(m, singular=false) { } } +function metricArea(m2, singular=false) { + if (m2 < 1/1000) { + let area = round(m2 * 10000,2); + return area + (singular || area == 1 ? " square centimeter" : " square centimeters"); + } else if (m2 < 100000) { + let area = round(m2 * 100,0); + return area + (singular || area == 1 ? " square meter" : " square centimeters"); + } else { + let area = round(m2 / 1e6,2); + return area + (singular || area == 1 ? " kilometer" : " square kilometers"); + } +} + +function customaryArea(m2, singular=false) { + let ft2 = m2 * 3.28084 * 3.28084; + + if (ft2 < 1) { + let area = round(ft2 * 144,0); + return area + (singular || area == 1 ? " square inch" : " square inches"); + } else if (ft2 < 5280 * 5280 / 10) { + let area = round(ft2,1); + return area + (singular || area == 1 ? " square foot" : " square feet"); + } else { + let length = round(ft2 /5280 / 5280,1); + return area + (singular || area == 1 ? " square mile" : " square miles"); + } +} + function metricVolume(m3, singular=false) { if (m3 < 1/1000) { let volume = round(m3*1e6, 0);
  • +
    +
    +
    +
    +
    +