From f03b14d07b60a09ef6ae8e391913b7e0a0e01076 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 25 Jun 2020 15:32:11 +0200 Subject: [PATCH] cache exponent values for number formats --- .../Localization/NumberFormat.de.json5 | 22 +++++++++---------- .../Content/Localization/NumberFormat.json5 | 22 +++++++++---------- TouchyTickets/Ui.cs | 3 ++- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/TouchyTickets/Content/Localization/NumberFormat.de.json5 b/TouchyTickets/Content/Localization/NumberFormat.de.json5 index b7286aa..6449a27 100644 --- a/TouchyTickets/Content/Localization/NumberFormat.de.json5 +++ b/TouchyTickets/Content/Localization/NumberFormat.de.json5 @@ -1,14 +1,14 @@ [ "0", // Hundert - "0,.##t", // Tausend - "0,,.##M", // Millionen - "0,,,.##Mr", // Milliarden - "0,,,,.##B", // Billionen - "0,,,,,.##Br", // Billiarden - "0,,,,,,.##T", // Trillionen - "0,,,,,,,.##Tr", // Trilliarden - "0,,,,,,,,.##Q", // Quadrillionen - "0,,,,,,,,,.##Qr", // Quadrilliarden - "0,,,,,,,,,,.##Qi", // Quintillionen - "0,,,,,,,,,,,.##Qir", // Quintilliarden + "0,.## t", // Tausend + "0,,.## M", // Millionen + "0,,,.## Mr", // Milliarden + "0,,,,.## B", // Billionen + "0,,,,,.## Br", // Billiarden + "0,,,,,,.## T", // Trillionen + "0,,,,,,,.## Tr", // Trilliarden + "0,,,,,,,,.## Q", // Quadrillionen + "0,,,,,,,,,.## Qr", // Quadrilliarden + "0,,,,,,,,,,.## Qi", // Quintillionen + "0,,,,,,,,,,,.## Qir", // Quintilliarden ] \ No newline at end of file diff --git a/TouchyTickets/Content/Localization/NumberFormat.json5 b/TouchyTickets/Content/Localization/NumberFormat.json5 index 91041da..7b1010f 100644 --- a/TouchyTickets/Content/Localization/NumberFormat.json5 +++ b/TouchyTickets/Content/Localization/NumberFormat.json5 @@ -1,14 +1,14 @@ [ "0", // hundreds - "0,.##K", // thousands - "0,,.##M", // millions - "0,,,.##B", // billions - "0,,,,.##T", // trillions - "0,,,,,.##Q", // quadrillions - "0,,,,,,.##Qi", // quintillions - "0,,,,,,,.##S", // sextillions - "0,,,,,,,,.##Sp", // septillions - "0,,,,,,,,,.##O", // octillions - "0,,,,,,,,,,.##N", // nonillions - "0,,,,,,,,,,,.##D", // decillions + "0,.## K", // thousands + "0,,.## M", // millions + "0,,,.## B", // billions + "0,,,,.## T", // trillions + "0,,,,,.## Q", // quadrillions + "0,,,,,,.## Qi", // quintillions + "0,,,,,,,.## S", // sextillions + "0,,,,,,,,.## Sp", // septillions + "0,,,,,,,,,.## O", // octillions + "0,,,,,,,,,,.## N", // nonillions + "0,,,,,,,,,,,.## D", // decillions ] \ No newline at end of file diff --git a/TouchyTickets/Ui.cs b/TouchyTickets/Ui.cs index 4e164c2..8393abe 100644 --- a/TouchyTickets/Ui.cs +++ b/TouchyTickets/Ui.cs @@ -23,6 +23,7 @@ namespace TouchyTickets { public class Ui { public static readonly UniformTextureAtlas Texture = new UniformTextureAtlas(MlemGame.LoadContent("Textures/Ui"), 16, 16); + private static readonly BigInteger[] ExpoNums = Enumerable.Range(0, Localization.NumberFormat.Count).Select(i => BigInteger.Pow(1000, i + 1)).ToArray(); private readonly UiSystem uiSystem; private readonly Element[] swipeRelations; private Element currentUi; @@ -602,7 +603,7 @@ namespace TouchyTickets { private static string PrettyPrintNumber(BigInteger number) { for (var i = 0; i < Localization.NumberFormat.Count; i++) { - if (number < BigInteger.Pow(1000, i + 1)) + if (number < ExpoNums[i]) return number.ToString(Localization.NumberFormat[i]); } // if the number is too large, just return the highest possible