Improve floating point number formatting
This commit is contained in:
@@ -21,25 +21,16 @@ package moe.nea.firmament.commands
|
|||||||
import com.mojang.brigadier.CommandDispatcher
|
import com.mojang.brigadier.CommandDispatcher
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType.getString
|
import com.mojang.brigadier.arguments.StringArgumentType.getString
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType.string
|
import com.mojang.brigadier.arguments.StringArgumentType.string
|
||||||
import io.github.cottonmc.cotton.gui.client.CottonClientScreen
|
|
||||||
import io.ktor.client.call.body
|
|
||||||
import io.ktor.client.request.get
|
|
||||||
import io.ktor.client.request.parameter
|
|
||||||
import io.ktor.http.URLProtocol
|
|
||||||
import io.ktor.http.path
|
|
||||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
|
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import net.minecraft.text.Text
|
import net.minecraft.text.Text
|
||||||
import moe.nea.firmament.Firmament
|
|
||||||
import moe.nea.firmament.apis.Profiles
|
|
||||||
import moe.nea.firmament.features.world.FairySouls
|
import moe.nea.firmament.features.world.FairySouls
|
||||||
import moe.nea.firmament.gui.config.AllConfigsGui
|
import moe.nea.firmament.gui.config.AllConfigsGui
|
||||||
import moe.nea.firmament.gui.profileviewer.ProfileViewer
|
import moe.nea.firmament.gui.profileviewer.ProfileViewer
|
||||||
import moe.nea.firmament.repo.ItemCostData
|
import moe.nea.firmament.repo.ItemCostData
|
||||||
import moe.nea.firmament.repo.RepoManager
|
import moe.nea.firmament.repo.RepoManager
|
||||||
|
import moe.nea.firmament.util.FirmFormatters
|
||||||
import moe.nea.firmament.util.MC
|
import moe.nea.firmament.util.MC
|
||||||
import moe.nea.firmament.util.SBData
|
import moe.nea.firmament.util.SBData
|
||||||
import moe.nea.firmament.util.ScreenUtil
|
|
||||||
import moe.nea.firmament.util.SkyblockId
|
import moe.nea.firmament.util.SkyblockId
|
||||||
import moe.nea.firmament.util.unformattedString
|
import moe.nea.firmament.util.unformattedString
|
||||||
|
|
||||||
@@ -87,7 +78,7 @@ fun firmamentCommand() = literal("firmament") {
|
|||||||
source.sendFeedback(
|
source.sendFeedback(
|
||||||
Text.translatable(
|
Text.translatable(
|
||||||
"firmament.price.bazaar.buy.price",
|
"firmament.price.bazaar.buy.price",
|
||||||
bazaarData.quickStatus.buyPrice
|
FirmFormatters.toString(bazaarData.quickStatus.buyPrice, 1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
source.sendFeedback(
|
source.sendFeedback(
|
||||||
@@ -99,7 +90,7 @@ fun firmamentCommand() = literal("firmament") {
|
|||||||
source.sendFeedback(
|
source.sendFeedback(
|
||||||
Text.translatable(
|
Text.translatable(
|
||||||
"firmament.price.bazaar.sell.price",
|
"firmament.price.bazaar.sell.price",
|
||||||
bazaarData.quickStatus.sellPrice
|
FirmFormatters.toString(bazaarData.quickStatus.sellPrice, 1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
source.sendFeedback(
|
source.sendFeedback(
|
||||||
@@ -111,7 +102,12 @@ fun firmamentCommand() = literal("firmament") {
|
|||||||
}
|
}
|
||||||
val lowestBin = ItemCostData.lowestBin[itemName]
|
val lowestBin = ItemCostData.lowestBin[itemName]
|
||||||
if (lowestBin != null) {
|
if (lowestBin != null) {
|
||||||
source.sendFeedback(Text.translatable("firmament.price.lowestbin", lowestBin))
|
source.sendFeedback(
|
||||||
|
Text.translatable(
|
||||||
|
"firmament.price.lowestbin",
|
||||||
|
FirmFormatters.toString(lowestBin, 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import net.minecraft.util.Formatting
|
|||||||
import moe.nea.firmament.apis.Skill
|
import moe.nea.firmament.apis.Skill
|
||||||
import moe.nea.firmament.gui.WBar
|
import moe.nea.firmament.gui.WBar
|
||||||
import moe.nea.firmament.repo.RepoManager
|
import moe.nea.firmament.repo.RepoManager
|
||||||
|
import moe.nea.firmament.util.FirmFormatters
|
||||||
import moe.nea.firmament.util.toShedaniel
|
import moe.nea.firmament.util.toShedaniel
|
||||||
|
|
||||||
object SkillPage : ProfilePage {
|
object SkillPage : ProfilePage {
|
||||||
@@ -45,7 +46,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", exp))
|
tooltip.add(Text.translatable("firmament.pv.skills.total", FirmFormatters.toString(exp, 1)))
|
||||||
}
|
}
|
||||||
}, 4, i + 1, 4, 1)
|
}, 4, i + 1, 4, 1)
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt
Normal file
15
src/main/kotlin/moe/nea/firmament/util/FirmFormatters.kt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package moe.nea.firmament.util
|
||||||
|
|
||||||
|
import com.google.common.math.IntMath.pow
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
|
object FirmFormatters {
|
||||||
|
fun toString(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")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,11 +6,11 @@
|
|||||||
"firmament.price": "Checking price for %s",
|
"firmament.price": "Checking price for %s",
|
||||||
"firmament.price.bazaar": "Bazaar stats:",
|
"firmament.price.bazaar": "Bazaar stats:",
|
||||||
"firmament.price.bazaar.productid": "Stock id: %s",
|
"firmament.price.bazaar.productid": "Stock id: %s",
|
||||||
"firmament.price.bazaar.buy.price": "Buy Price: %.1f",
|
"firmament.price.bazaar.buy.price": "Buy Price: %s",
|
||||||
"firmament.price.bazaar.buy.order": "Buy orders: %d",
|
"firmament.price.bazaar.buy.order": "Buy orders: %d",
|
||||||
"firmament.price.bazaar.sell.price": "Sell Price: %.1f",
|
"firmament.price.bazaar.sell.price": "Sell Price: %s",
|
||||||
"firmament.price.bazaar.sell.order": "Sell orders: %d",
|
"firmament.price.bazaar.sell.order": "Sell orders: %d",
|
||||||
"firmament.price.lowestbin": "Lowest BIN: %.1f",
|
"firmament.price.lowestbin": "Lowest BIN: %s",
|
||||||
"firmament.repo.reload.network": "Trying to redownload the repository",
|
"firmament.repo.reload.network": "Trying to redownload the repository",
|
||||||
"firmament.repo.reload.disk": "Reloading repository from disk. This may lag a bit.",
|
"firmament.repo.reload.disk": "Reloading repository from disk. This may lag a bit.",
|
||||||
"firmament.repo.cache": "Recaching items",
|
"firmament.repo.cache": "Recaching items",
|
||||||
@@ -53,6 +53,6 @@
|
|||||||
"firmament.pv.skills.combat": "Combat",
|
"firmament.pv.skills.combat": "Combat",
|
||||||
"firmament.pv.skills.social": "Social",
|
"firmament.pv.skills.social": "Social",
|
||||||
"firmament.pv.skills.enchanting": "Enchanting",
|
"firmament.pv.skills.enchanting": "Enchanting",
|
||||||
"firmament.pv.skills.total": "Total Exp: %.1f",
|
"firmament.pv.skills.total": "Total Exp: %s",
|
||||||
"firmament.pv.lookingup": "Looking up %s"
|
"firmament.pv.lookingup": "Looking up %s"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user