From 36d5ef29e45a57e88d9d608d1becb5cb7de27cf5 Mon Sep 17 00:00:00 2001 From: nea Date: Thu, 31 Aug 2023 23:19:30 +0200 Subject: Add , seperatation to currency information --- src/main/kotlin/moe/nea/firmament/commands/rome.kt | 6 +++--- .../moe/nea/firmament/features/inventory/PriceData.kt | 6 +++--- .../kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt | 2 +- .../moe/nea/firmament/gui/profileviewer/SkillPage.kt | 2 +- .../kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt | 4 ++-- src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt | 14 +++++++++++--- 6 files changed, 21 insertions(+), 13 deletions(-) (limited to 'src/main/kotlin/moe') diff --git a/src/main/kotlin/moe/nea/firmament/commands/rome.kt b/src/main/kotlin/moe/nea/firmament/commands/rome.kt index 221c7c1..be2aefd 100644 --- a/src/main/kotlin/moe/nea/firmament/commands/rome.kt +++ b/src/main/kotlin/moe/nea/firmament/commands/rome.kt @@ -83,7 +83,7 @@ fun firmamentCommand() = literal("firmament") { source.sendFeedback( Text.translatable( "firmament.price.bazaar.buy.price", - FirmFormatters.toString(bazaarData.quickStatus.buyPrice, 1) + FirmFormatters.formatCurrency(bazaarData.quickStatus.buyPrice, 1) ) ) source.sendFeedback( @@ -95,7 +95,7 @@ fun firmamentCommand() = literal("firmament") { source.sendFeedback( Text.translatable( "firmament.price.bazaar.sell.price", - FirmFormatters.toString(bazaarData.quickStatus.sellPrice, 1) + FirmFormatters.formatCurrency(bazaarData.quickStatus.sellPrice, 1) ) ) source.sendFeedback( @@ -110,7 +110,7 @@ fun firmamentCommand() = literal("firmament") { source.sendFeedback( Text.translatable( "firmament.price.lowestbin", - FirmFormatters.toString(lowestBin, 1) + FirmFormatters.formatCurrency(lowestBin, 1) ) ) } diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt index 3ae7b00..8062357 100644 --- a/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt +++ b/src/main/kotlin/moe/nea/firmament/features/inventory/PriceData.kt @@ -38,13 +38,13 @@ object PriceData : FirmamentFeature { it.lines.add( Text.translatable( "firmament.tooltip.bazaar.sell-order", - FirmFormatters.toString(bazaarData.quickStatus.sellPrice, 1) + FirmFormatters.formatCurrency(bazaarData.quickStatus.sellPrice, 1) ) ) it.lines.add( Text.translatable( "firmament.tooltip.bazaar.buy-order", - FirmFormatters.toString(bazaarData.quickStatus.buyPrice, 1) + FirmFormatters.formatCurrency(bazaarData.quickStatus.buyPrice, 1) ) ) } else if (lowestBin != null) { @@ -52,7 +52,7 @@ object PriceData : FirmamentFeature { it.lines.add( Text.translatable( "firmament.tooltip.ah.lowestbin", - FirmFormatters.toString(lowestBin, 1) + FirmFormatters.formatCurrency(lowestBin, 1) ) ) } diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt index 82d2fef..6daeca4 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/PetsPage.kt @@ -73,7 +73,7 @@ object PetsPage : ProfilePage { Text.literal("Magic Find: ").styled { it.withColor(Formatting.AQUA) } .append( Text.literal( - FirmFormatters.toString( + FirmFormatters.formatCurrency( RepoManager.neuRepo.constants.bonuses.getPetRewards( petScore )["magic_find"] ?: 0.0F, 1 diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt index 74bf88c..197f560 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt @@ -49,7 +49,7 @@ object SkillPage : ProfilePage { ) { override fun addTooltip(tooltip: TooltipBuilder) { tooltip.add(Text.literal("$level/$maxLevel")) - tooltip.add(Text.translatable("firmament.pv.skills.total", FirmFormatters.toString(exp, 1))) + tooltip.add(Text.translatable("firmament.pv.skills.total", FirmFormatters.formatCurrency(exp, 1))) } } } diff --git a/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt b/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt index 8150f4c..fc0db3d 100644 --- a/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt +++ b/src/main/kotlin/moe/nea/firmament/rei/SBItemEntryDefinition.kt @@ -76,10 +76,10 @@ data class SBItemStack( ?.interpolatedStatsAtLevel(petData.levelData.currentLevel) if (stats != null) { stats.otherNumbers.forEachIndexed { index, it -> - replacementData[index.toString()] = FirmFormatters.toString(it, 1) + replacementData[index.toString()] = FirmFormatters.formatCurrency(it, 1) } stats.statNumbers.forEach { (t, u) -> - replacementData[t] = FirmFormatters.toString(u, 1) + replacementData[t] = FirmFormatters.formatCurrency(u, 1) } } replacementData["LVL"] = petData.levelData.currentLevel.toString() diff --git a/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt b/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt index b2c1f35..96a4389 100644 --- a/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt +++ b/src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt @@ -11,13 +11,21 @@ import kotlin.math.absoluteValue import kotlin.time.Duration object FirmFormatters { - fun toString(float: Float, fractionalDigits: Int): String = toString(float.toDouble(), fractionalDigits) - fun toString(double: Double, fractionalDigits: Int): String { + fun formatCurrency(long: Long, segments: Int = 3): String { + val α = long / 1000 + if (α != 0L) { + return formatCurrency(α, segments) + "," + (long - α * 1000).toString().padStart(3, '0') + } + return long.toString() + } + + fun formatCurrency(float: Float, fractionalDigits: Int): String = formatCurrency(float.toDouble(), fractionalDigits) + fun formatCurrency(double: Double, fractionalDigits: Int): String { val long = double.toLong() val δ = (double - long).absoluteValue val μ = pow(10, fractionalDigits) val digits = (μ * δ).toInt().toString().padStart(fractionalDigits, '0').trimEnd('0') - return long.toString() + (if (digits.isEmpty()) "" else ".$digits") + return formatCurrency(long) + (if (digits.isEmpty()) "" else ".$digits") } fun formatTimespan(duration: Duration): String { -- cgit