Add , seperatation to currency information

This commit is contained in:
nea
2023-08-31 23:19:30 +02:00
parent ece429c361
commit 36d5ef29e4
6 changed files with 21 additions and 13 deletions

View File

@@ -83,7 +83,7 @@ fun firmamentCommand() = literal("firmament") {
source.sendFeedback( source.sendFeedback(
Text.translatable( Text.translatable(
"firmament.price.bazaar.buy.price", "firmament.price.bazaar.buy.price",
FirmFormatters.toString(bazaarData.quickStatus.buyPrice, 1) FirmFormatters.formatCurrency(bazaarData.quickStatus.buyPrice, 1)
) )
) )
source.sendFeedback( source.sendFeedback(
@@ -95,7 +95,7 @@ fun firmamentCommand() = literal("firmament") {
source.sendFeedback( source.sendFeedback(
Text.translatable( Text.translatable(
"firmament.price.bazaar.sell.price", "firmament.price.bazaar.sell.price",
FirmFormatters.toString(bazaarData.quickStatus.sellPrice, 1) FirmFormatters.formatCurrency(bazaarData.quickStatus.sellPrice, 1)
) )
) )
source.sendFeedback( source.sendFeedback(
@@ -110,7 +110,7 @@ fun firmamentCommand() = literal("firmament") {
source.sendFeedback( source.sendFeedback(
Text.translatable( Text.translatable(
"firmament.price.lowestbin", "firmament.price.lowestbin",
FirmFormatters.toString(lowestBin, 1) FirmFormatters.formatCurrency(lowestBin, 1)
) )
) )
} }

View File

@@ -38,13 +38,13 @@ object PriceData : FirmamentFeature {
it.lines.add( it.lines.add(
Text.translatable( Text.translatable(
"firmament.tooltip.bazaar.sell-order", "firmament.tooltip.bazaar.sell-order",
FirmFormatters.toString(bazaarData.quickStatus.sellPrice, 1) FirmFormatters.formatCurrency(bazaarData.quickStatus.sellPrice, 1)
) )
) )
it.lines.add( it.lines.add(
Text.translatable( Text.translatable(
"firmament.tooltip.bazaar.buy-order", "firmament.tooltip.bazaar.buy-order",
FirmFormatters.toString(bazaarData.quickStatus.buyPrice, 1) FirmFormatters.formatCurrency(bazaarData.quickStatus.buyPrice, 1)
) )
) )
} else if (lowestBin != null) { } else if (lowestBin != null) {
@@ -52,7 +52,7 @@ object PriceData : FirmamentFeature {
it.lines.add( it.lines.add(
Text.translatable( Text.translatable(
"firmament.tooltip.ah.lowestbin", "firmament.tooltip.ah.lowestbin",
FirmFormatters.toString(lowestBin, 1) FirmFormatters.formatCurrency(lowestBin, 1)
) )
) )
} }

View File

@@ -73,7 +73,7 @@ object PetsPage : ProfilePage {
Text.literal("Magic Find: ").styled { it.withColor(Formatting.AQUA) } Text.literal("Magic Find: ").styled { it.withColor(Formatting.AQUA) }
.append( .append(
Text.literal( Text.literal(
FirmFormatters.toString( FirmFormatters.formatCurrency(
RepoManager.neuRepo.constants.bonuses.getPetRewards( RepoManager.neuRepo.constants.bonuses.getPetRewards(
petScore petScore
)["magic_find"] ?: 0.0F, 1 )["magic_find"] ?: 0.0F, 1

View File

@@ -49,7 +49,7 @@ object SkillPage : ProfilePage {
) { ) {
override fun addTooltip(tooltip: TooltipBuilder) { override fun addTooltip(tooltip: TooltipBuilder) {
tooltip.add(Text.literal("$level/$maxLevel")) 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)))
} }
} }
} }

View File

@@ -76,10 +76,10 @@ data class SBItemStack(
?.interpolatedStatsAtLevel(petData.levelData.currentLevel) ?.interpolatedStatsAtLevel(petData.levelData.currentLevel)
if (stats != null) { if (stats != null) {
stats.otherNumbers.forEachIndexed { index, it -> stats.otherNumbers.forEachIndexed { index, it ->
replacementData[index.toString()] = FirmFormatters.toString(it, 1) replacementData[index.toString()] = FirmFormatters.formatCurrency(it, 1)
} }
stats.statNumbers.forEach { (t, u) -> stats.statNumbers.forEach { (t, u) ->
replacementData[t] = FirmFormatters.toString(u, 1) replacementData[t] = FirmFormatters.formatCurrency(u, 1)
} }
} }
replacementData["LVL"] = petData.levelData.currentLevel.toString() replacementData["LVL"] = petData.levelData.currentLevel.toString()

View File

@@ -11,13 +11,21 @@ import kotlin.math.absoluteValue
import kotlin.time.Duration import kotlin.time.Duration
object FirmFormatters { object FirmFormatters {
fun toString(float: Float, fractionalDigits: Int): String = toString(float.toDouble(), fractionalDigits) fun formatCurrency(long: Long, segments: Int = 3): String {
fun toString(double: Double, fractionalDigits: Int): 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 long = double.toLong()
val δ = (double - long).absoluteValue val δ = (double - long).absoluteValue
val μ = pow(10, fractionalDigits) val μ = pow(10, fractionalDigits)
val digits = (μ * δ).toInt().toString().padStart(fractionalDigits, '0').trimEnd('0') 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 { fun formatTimespan(duration: Duration): String {