Made notation cutoff configurable

This commit is contained in:
Daniel van Noord
2020-12-19 10:49:17 +01:00
parent 30c4617bde
commit d3a4eb936a
4 changed files with 80 additions and 24 deletions

View File

@@ -8,7 +8,7 @@
/**
* This function saves the config of CookieMonster to localStorage
* It is called by CM.Config.LoadConfig(), CM.Config.RestoreDefault(), CM.Config.ToggleConfig(),
* CM.ToggleConfigVolume() and changes in options with type "url" or "color"
* CM.ToggleConfigVolume() and changes in options with type "url", "color" or "numscale"
* @param {object} config The Config to be saved (normally CM.Options)
*/
CM.Config.SaveConfig = function(config) {

View File

@@ -38,9 +38,9 @@ CM.Data.PlantDrops = ['Elderwort biscuits', 'Bakeberry cookies', 'Duketater cook
/********
* Section: Data for the various scales used by CookieMonster */
CM.Data.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
CM.Data.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint'];
CM.Data.shortScaleAbbreviated = ['K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'De',
CM.Data.metric = ['', '', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
CM.Data.shortScale = ['', '', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint'];
CM.Data.shortScaleAbbreviated = ['', 'K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'De',
'UDe', 'DDe', 'TDe', 'QaDe', 'QiDe', 'SxDe', 'SpDe', 'ODe', 'NDe', 'Vi',
'UVi', 'DVi', 'TVi', 'QaVi', 'QiVi', 'SxVi', 'SpVi', 'OVi', 'NVi', 'Tr',
'UTr', 'DTr', 'TTr', 'QaTr', 'QiTr', 'SxTr', 'SpTr', 'OTr', 'NTr', 'Qaa',
@@ -193,6 +193,7 @@ CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoir
CM.ConfigData.Scale = {type: 'bool', group: 'Notation', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Short Scale (Abbreviated)', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}};
CM.ConfigData.ScaleDecimals = {type: 'bool', group: 'Notation', label: ['1 decimals', '2 decimals', '3 decimals'], desc: 'Set the number of decimals used when applicable', toggle: false, func: function() {CM.Disp.RefreshScale();}};
CM.ConfigData.ScaleSeparator = {type: 'bool', group: 'Notation', label: ['. for decimals (Standard)', '. for thousands'], desc: 'Set the separator used for decimals and thousands', toggle: false, func: function() {CM.Disp.RefreshScale();}};
CM.ConfigData.ScaleCutoff = {type: 'numscale', group: 'Notation', label: 'Notation Cut-off Point', desc: 'The number from which CookieMonster will start formatting numbers based on chosen scale. Standard is 999,999. Setting this above 999,999,999 might break certain notations.', min: 1, max: 999999999};
/**
* This array describes all default settings
@@ -268,6 +269,7 @@ CM.Data.ConfigDefault = {
Scale: 2,
ScaleDecimals: 2,
ScaleSeparator: 0,
ScaleCutoff: 999999,
Colors: {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'},
SortBuildings: 0,
SortUpgrades: 0,

View File

@@ -174,13 +174,13 @@ CM.Disp.Beautify = function(num, floats, forced) {
}
else if (isFinite(num)) {
var answer = '';
var timesTenToPowerThree = Math.trunc(Math.log10(num) / 3)
if (num == 0) {
return num.toString()
}
else if (-1 < timesTenToPowerThree && timesTenToPowerThree < 2) {
// TODO: Add changing separators of thousands and making this cut-off user configurable
answer = Math.round(num * 100) / 100;
else if (0.001 < num && num < CM.Options.ScaleCutoff) {
answer = num.toFixed(0);
if (CM.Options.ScaleSeparator) answer = answer.toLocaleString('nl');
return answer;
}
else if (CM.Options.Scale == 4 && !forced || forced == 4) { // Scientific notation, 123456789 => 1.235E+8
answer = num.toExponential(decimals).toString().replace("e", "E");
@@ -192,21 +192,21 @@ CM.Disp.Beautify = function(num, floats, forced) {
// answer is now "xxx.xx" (e.g., 123456789 would be 123.46)
if (CM.Options.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M
if (num >= 0.01 && num < Number("1e" + CM.Data.metric.length * 3)) {
answer += ' ' + CM.Data.metric[AmountOfTenPowerThree - 1]
answer += ' ' + CM.Data.metric[AmountOfTenPowerThree]
}
// If number is too large or little, revert to scientific notation
else answer = CM.Disp.Beautify(num, 0, 4);
}
else if (CM.Options.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M
if (num >= 0.01 && num < Number("1e" + CM.Data.shortScale.length * 3)) {
answer += ' ' + CM.Data.shortScale[AmountOfTenPowerThree - 1];
answer += ' ' + CM.Data.shortScale[AmountOfTenPowerThree];
}
// If number is too large or little, revert to scientific notation
else answer = CM.Disp.Beautify(num, 0, 4);
}
else if (CM.Options.Scale == 3 && !forced || forced == 3) { // Short scale, 123456789 => 123.457 M
if (num >= 0.01 && num < Number("1e" + CM.Data.shortScaleAbbreviated.length * 3)) {
answer += ' ' + CM.Data.shortScaleAbbreviated[AmountOfTenPowerThree - 1];
answer += ' ' + CM.Data.shortScaleAbbreviated[AmountOfTenPowerThree];
}
// If number is too large or little, revert to scientific notation
else answer = CM.Disp.Beautify(num, 0, 4);
@@ -2005,6 +2005,32 @@ CM.Disp.CreatePrefOption = function(config) {
return div;
}
}
else if (CM.ConfigData[config].type == "numscale") {
var div = document.createElement('div');
div.className = 'listing';
var span = document.createElement('span');
span.className = 'option';
span.textContent = CM.ConfigData[config].label + ' ';
div.appendChild(span);
var input = document.createElement('input');
input.id = CM.ConfigPrefix + config;
input.className = 'option';
input.type = 'number';
input.value = (CM.Options[config]);
input.min = CM.ConfigData[config].min;
input.max = CM.ConfigData[config].max;
input.oninput = function() {if (this.value > this.max) console.log("TEST");
CM.Options[config] = this.value;
CM.Config.SaveConfig(CM.Options);
CM.Disp.RefreshScale()
}
div.appendChild(input);
div.appendChild(document.createTextNode(' '));
var label = document.createElement('label');
label.textContent = CM.ConfigData[config].desc;
div.appendChild(label);
return div;
}
}
/**
@@ -2018,7 +2044,7 @@ CM.Disp.ToggleDetailedTime = function() {
/**
* This function refreshes all numbers after a change in scale-setting
* It is therefore called by a change in CM.Options.Scale and CM.Options.ScaleDecimals
* It is therefore called by a changes in CM.Options.Scale, CM.Options.ScaleDecimals, CM.Options.ScaleSeparator and CM.Options.ScaleCutoff
*/
CM.Disp.RefreshScale = function() {
BeautifyAll();