From 8fba3c3fa4d0bf0dcfc3ef39b8767adbe610986e Mon Sep 17 00:00:00 2001 From: Tesseract1234567890 Date: Wed, 2 Jun 2021 16:07:52 -0400 Subject: [PATCH 1/7] Modified numeralFormat.ts to prevent NaNt from appearing --- src/ui/numeralFormat.ts | 105 +++++++++++++++++++++++++++++++++++----- 1 file changed, 93 insertions(+), 12 deletions(-) diff --git a/src/ui/numeralFormat.ts b/src/ui/numeralFormat.ts index c729a6377..fd66961d2 100644 --- a/src/ui/numeralFormat.ts +++ b/src/ui/numeralFormat.ts @@ -16,6 +16,9 @@ import 'numeral/locales/ru'; /* eslint-disable class-methods-use-this */ +const extraFormats = [1e15, 1e18, 1e21, 1e24, 1e27, 1e30]; +const extraNotations = ['q', 'Q', 's', 'S', 'o', 'n']; + class NumeralFormatter { // Default Locale defaultLocale = "en"; @@ -54,8 +57,6 @@ class NumeralFormatter { formatMoney(n: number): string { if(numeral.options.currentLocale === "en") { - const extraFormats = [1e15, 1e18, 1e21, 1e24, 1e27, 1e30]; - const extraNotations = ['q', 'Q', 's', 'S', 'o', 'n']; for(let i = 0; i < extraFormats.length; i++) { if(extraFormats[i] < n && n <= extraFormats[i]*1000) { return '$'+this.format(n/extraFormats[i], '0.000')+extraNotations[i]; @@ -75,15 +76,51 @@ class NumeralFormatter { } formatExp(n: number): string { - return this.format(n, "0.000a"); + if(numeral.options.currentLocale === "en") { + for(let i = 0; i < extraFormats.length; i++) { + if(extraFormats[i] < n && n <= extraFormats[i]*1000) { + return this.format(n/extraFormats[i], '0.000')+extraNotations[i]; + } + } + } + if(Math.abs(n) < 1000) { + return this.format(n, "0.000"); + } + const str = this.format(n, "0.000a"); + if(str === "NaNt") return this.format(n, '0.000e+0'); + return str; } formatHashes(n: number): string { - return this.format(n, "0.000a"); + if(numeral.options.currentLocale === "en") { + for(let i = 0; i < extraFormats.length; i++) { + if(extraFormats[i] < n && n <= extraFormats[i]*1000) { + return this.format(n/extraFormats[i], '0.000')+extraNotations[i]; + } + } + } + if(Math.abs(n) < 1000) { + return this.format(n, "0.000"); + } + const str = this.format(n, "0.000a"); + if(str === "NaNt") return this.format(n, '0.000e+0'); + return str; } formatReputation(n: number): string { - return this.format(n, "0.000a"); + if(numeral.options.currentLocale === "en") { + for(let i = 0; i < extraFormats.length; i++) { + if(extraFormats[i] < n && n <= extraFormats[i]*1000) { + return this.format(n/extraFormats[i], '0.000')+extraNotations[i]; + } + } + } + if(Math.abs(n) < 1000) { + return this.format(n, "0.000"); + } + const str = this.format(n, "0.000a"); + if(str === "NaNt") return this.format(n, '0.000e+0'); + return str; } formatFavor(n: number): string { @@ -104,11 +141,35 @@ class NumeralFormatter { } formatRespect(n: number): string { - return this.format(n, "0.00000a"); + if(numeral.options.currentLocale === "en") { + for(let i = 0; i < extraFormats.length; i++) { + if(extraFormats[i] < n && n <= extraFormats[i]*1000) { + return this.format(n/extraFormats[i], '0.00000')+extraNotations[i]; + } + } + } + if(Math.abs(n) < 1000) { + return this.format(n, "0.00000"); + } + const str = this.format(n, "0.00000a"); + if(str === "NaNt") return this.format(n, '0.00000e+0'); + return str; } formatWanted(n: number): string { - return this.format(n, "0.00000a"); + if(numeral.options.currentLocale === "en") { + for(let i = 0; i < extraFormats.length; i++) { + if(extraFormats[i] < n && n <= extraFormats[i]*1000) { + return this.format(n/extraFormats[i], '0.00000')+extraNotations[i]; + } + } + } + if(Math.abs(n) < 1000) { + return this.format(n, "0.00000"); + } + const str = this.format(n, "0.00000a"); + if(str === "NaNt") return this.format(n, '0.00000e+0'); + return str; } formatMultiplier(n: number): string { @@ -136,14 +197,34 @@ class NumeralFormatter { } formatShares(n: number): string { - if (n < 1000) { - return this.format(n, "0"); + if(numeral.options.currentLocale === "en") { + for(let i = 0; i < extraFormats.length; i++) { + if(extraFormats[i] < n && n <= extraFormats[i]*1000) { + return this.format(n/extraFormats[i], '0.000')+extraNotations[i]; + } + } } - return this.format(n, "0.000a"); - } + if(Math.abs(n) < 1000) { + return this.format(n, "0.000"); + } + const str = this.format(n, "0.000a"); + if(str === "NaNt") return this.format(n, '0.000e+0'); + return str; } formatInfiltrationSecurity(n: number): string { - return this.format(n, "0.000a"); + if(numeral.options.currentLocale === "en") { + for(let i = 0; i < extraFormats.length; i++) { + if(extraFormats[i] < n && n <= extraFormats[i]*1000) { + return this.format(n/extraFormats[i], '0.000')+extraNotations[i]; + } + } + } + if(Math.abs(n) < 1000) { + return this.format(n, "0.000"); + } + const str = this.format(n, "0.000a"); + if(str === "NaNt") return this.format(n, '0.000e+0'); + return str; } formatThreads(n: number): string { From 75227233f32dcace789dd1b0e09bdd81a115ddaa Mon Sep 17 00:00:00 2001 From: Tesseract1234567890 Date: Wed, 2 Jun 2021 21:33:27 -0400 Subject: [PATCH 2/7] Added class method formatAbsurdNumber --- src/ui/numeralFormat.ts | 128 ++++++++-------------------------------- 1 file changed, 24 insertions(+), 104 deletions(-) diff --git a/src/ui/numeralFormat.ts b/src/ui/numeralFormat.ts index fd66961d2..c5935793f 100644 --- a/src/ui/numeralFormat.ts +++ b/src/ui/numeralFormat.ts @@ -19,6 +19,7 @@ import 'numeral/locales/ru'; const extraFormats = [1e15, 1e18, 1e21, 1e24, 1e27, 1e30]; const extraNotations = ['q', 'Q', 's', 'S', 'o', 'n']; + class NumeralFormatter { // Default Locale defaultLocale = "en"; @@ -51,24 +52,26 @@ class NumeralFormatter { return this.format(n, "0.000a"); } + formatAbsurdNumber(n: number, decimalPlaces: string): string { + for(let i = 0; i < extraFormats.length; i++) { + if(extraFormats[i] < n && n <= extraFormats[i]*1000) { + return this.format(n/extraFormats[i], '0.'+'0'.repeat(decimalPlaces))+extraNotations[i]; + } + } + if(Math.abs(n) < 1000) { + return this.format(n, '0.'+'0'.repeat(decimalPlaces)); + } + const str = this.format(n, '0.'+'0'.repeat(decimalPlaces) + 'a'); + if(str === "NaNt") return this.format(n, '0.' + ' '.repeat(decimalPlaces) + 'e+0'); + return str; + } + formatHp(n: number): string { return this.format(n, "0"); } formatMoney(n: number): string { - if(numeral.options.currentLocale === "en") { - for(let i = 0; i < extraFormats.length; i++) { - if(extraFormats[i] < n && n <= extraFormats[i]*1000) { - return '$'+this.format(n/extraFormats[i], '0.000')+extraNotations[i]; - } - } - } - if(Math.abs(n) < 1000) { - return this.format(n, "$0.00"); - } - const str = this.format(n, "$0.000a"); - if(str === "$NaNt") return '$'+this.format(n, '0.000e+0'); - return str; + return "$" + this.formatAbsurdNumber } formatSkill(n: number): string { @@ -76,51 +79,15 @@ class NumeralFormatter { } formatExp(n: number): string { - if(numeral.options.currentLocale === "en") { - for(let i = 0; i < extraFormats.length; i++) { - if(extraFormats[i] < n && n <= extraFormats[i]*1000) { - return this.format(n/extraFormats[i], '0.000')+extraNotations[i]; - } - } - } - if(Math.abs(n) < 1000) { - return this.format(n, "0.000"); - } - const str = this.format(n, "0.000a"); - if(str === "NaNt") return this.format(n, '0.000e+0'); - return str; + return this.formatAbsurdNumber(n, 3); } formatHashes(n: number): string { - if(numeral.options.currentLocale === "en") { - for(let i = 0; i < extraFormats.length; i++) { - if(extraFormats[i] < n && n <= extraFormats[i]*1000) { - return this.format(n/extraFormats[i], '0.000')+extraNotations[i]; - } - } - } - if(Math.abs(n) < 1000) { - return this.format(n, "0.000"); - } - const str = this.format(n, "0.000a"); - if(str === "NaNt") return this.format(n, '0.000e+0'); - return str; + return this.formatAbsurdNumber(n, 3); } formatReputation(n: number): string { - if(numeral.options.currentLocale === "en") { - for(let i = 0; i < extraFormats.length; i++) { - if(extraFormats[i] < n && n <= extraFormats[i]*1000) { - return this.format(n/extraFormats[i], '0.000')+extraNotations[i]; - } - } - } - if(Math.abs(n) < 1000) { - return this.format(n, "0.000"); - } - const str = this.format(n, "0.000a"); - if(str === "NaNt") return this.format(n, '0.000e+0'); - return str; + return this.formatAbsurdNumber(n, 3); } formatFavor(n: number): string { @@ -141,35 +108,11 @@ class NumeralFormatter { } formatRespect(n: number): string { - if(numeral.options.currentLocale === "en") { - for(let i = 0; i < extraFormats.length; i++) { - if(extraFormats[i] < n && n <= extraFormats[i]*1000) { - return this.format(n/extraFormats[i], '0.00000')+extraNotations[i]; - } - } - } - if(Math.abs(n) < 1000) { - return this.format(n, "0.00000"); - } - const str = this.format(n, "0.00000a"); - if(str === "NaNt") return this.format(n, '0.00000e+0'); - return str; + return this.formatAbsurdNumber(n, 5); } formatWanted(n: number): string { - if(numeral.options.currentLocale === "en") { - for(let i = 0; i < extraFormats.length; i++) { - if(extraFormats[i] < n && n <= extraFormats[i]*1000) { - return this.format(n/extraFormats[i], '0.00000')+extraNotations[i]; - } - } - } - if(Math.abs(n) < 1000) { - return this.format(n, "0.00000"); - } - const str = this.format(n, "0.00000a"); - if(str === "NaNt") return this.format(n, '0.00000e+0'); - return str; + return this.formatAbsurdNumber(n, 5); } formatMultiplier(n: number): string { @@ -197,34 +140,11 @@ class NumeralFormatter { } formatShares(n: number): string { - if(numeral.options.currentLocale === "en") { - for(let i = 0; i < extraFormats.length; i++) { - if(extraFormats[i] < n && n <= extraFormats[i]*1000) { - return this.format(n/extraFormats[i], '0.000')+extraNotations[i]; - } - } - } - if(Math.abs(n) < 1000) { - return this.format(n, "0.000"); - } - const str = this.format(n, "0.000a"); - if(str === "NaNt") return this.format(n, '0.000e+0'); - return str; } + return this.formatAbsurdNumber(n, 3); + } formatInfiltrationSecurity(n: number): string { - if(numeral.options.currentLocale === "en") { - for(let i = 0; i < extraFormats.length; i++) { - if(extraFormats[i] < n && n <= extraFormats[i]*1000) { - return this.format(n/extraFormats[i], '0.000')+extraNotations[i]; - } - } - } - if(Math.abs(n) < 1000) { - return this.format(n, "0.000"); - } - const str = this.format(n, "0.000a"); - if(str === "NaNt") return this.format(n, '0.000e+0'); - return str; + return this.formatAbsurdNumber(n, 3); } formatThreads(n: number): string { From 1b6058dd0ae3beac1f286f83b83c8b8921e88523 Mon Sep 17 00:00:00 2001 From: Tesseract1234567890 Date: Wed, 2 Jun 2021 21:33:27 -0400 Subject: [PATCH 3/7] Fixed formatAbsurdNumber --- src/ui/numeralFormat.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/numeralFormat.ts b/src/ui/numeralFormat.ts index c5935793f..ecd59b914 100644 --- a/src/ui/numeralFormat.ts +++ b/src/ui/numeralFormat.ts @@ -52,7 +52,7 @@ class NumeralFormatter { return this.format(n, "0.000a"); } - formatAbsurdNumber(n: number, decimalPlaces: string): string { + formatAbsurdNumber(n: number, decimalPlaces: number): string { for(let i = 0; i < extraFormats.length; i++) { if(extraFormats[i] < n && n <= extraFormats[i]*1000) { return this.format(n/extraFormats[i], '0.'+'0'.repeat(decimalPlaces))+extraNotations[i]; From 54114dc6d0c03cbb1caa36a64afed5b07b26138f Mon Sep 17 00:00:00 2001 From: Tesseract1234567890 Date: Wed, 2 Jun 2021 21:41:58 -0400 Subject: [PATCH 4/7] Edited formatAbsurdNumber; reinstated parts of formatShares --- src/ui/numeralFormat.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/numeralFormat.ts b/src/ui/numeralFormat.ts index ecd59b914..5029bdaa9 100644 --- a/src/ui/numeralFormat.ts +++ b/src/ui/numeralFormat.ts @@ -52,7 +52,7 @@ class NumeralFormatter { return this.format(n, "0.000a"); } - formatAbsurdNumber(n: number, decimalPlaces: number): string { + formatAbsurdNumber(n: number, decimalPlaces = 3): string { for(let i = 0; i < extraFormats.length; i++) { if(extraFormats[i] < n && n <= extraFormats[i]*1000) { return this.format(n/extraFormats[i], '0.'+'0'.repeat(decimalPlaces))+extraNotations[i]; @@ -140,6 +140,9 @@ class NumeralFormatter { } formatShares(n: number): string { + if (n < 1000) { + return this.format(n, "0"); + } return this.formatAbsurdNumber(n, 3); } From a05335d6e289cdfa088c4bc99598f1472b059a2d Mon Sep 17 00:00:00 2001 From: Tesseract1234567890 Date: Wed, 2 Jun 2021 21:47:32 -0400 Subject: [PATCH 5/7] fixed a stupid mistake --- src/ui/numeralFormat.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/numeralFormat.ts b/src/ui/numeralFormat.ts index 5029bdaa9..3c8c38d57 100644 --- a/src/ui/numeralFormat.ts +++ b/src/ui/numeralFormat.ts @@ -71,7 +71,7 @@ class NumeralFormatter { } formatMoney(n: number): string { - return "$" + this.formatAbsurdNumber + return "$" + this.formatAbsurdNumber(n, 3); } formatSkill(n: number): string { From 6314000bd06e6b9b40c63fb2c4302639e320366a Mon Sep 17 00:00:00 2001 From: Tesseract1234567890 Date: Wed, 2 Jun 2021 21:54:11 -0400 Subject: [PATCH 6/7] Fixed absurdly high skill counter on UI --- src/ui/numeralFormat.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/numeralFormat.ts b/src/ui/numeralFormat.ts index 3c8c38d57..37cdcae71 100644 --- a/src/ui/numeralFormat.ts +++ b/src/ui/numeralFormat.ts @@ -75,7 +75,10 @@ class NumeralFormatter { } formatSkill(n: number): string { - return this.format(n, "0,0"); + if(n < 1e15){ + return this.format(n, "0,0"); + } + return this.formatAbsurdNumber(n, 3); } formatExp(n: number): string { From 0535a0c49b3fb17444cffac812df04e21fa60074 Mon Sep 17 00:00:00 2001 From: Tesseract1234567890 Date: Wed, 2 Jun 2021 21:57:31 -0400 Subject: [PATCH 7/7] Fixed high HP values --- src/ui/numeralFormat.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/numeralFormat.ts b/src/ui/numeralFormat.ts index 37cdcae71..e30568faa 100644 --- a/src/ui/numeralFormat.ts +++ b/src/ui/numeralFormat.ts @@ -67,7 +67,10 @@ class NumeralFormatter { } formatHp(n: number): string { - return this.format(n, "0"); + if(n < 1e6){ + return this.format(n, "0,0"); + } + return this.formatAbsurdNumber(n, 3) } formatMoney(n: number): string {