This commit is contained in:
DBotThePony 2023-04-07 20:12:22 +07:00
parent 13bfa7f2b2
commit 85ed4802f4
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -147,30 +147,25 @@ fun Long.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2, formatAsRea
}
val prefix = SiPrefix.determine(this)
if (bias == 0) {
return TranslatableComponent(prefix.formatLocaleKey, "%.${decimalPlaces}f".format(this.toDouble() / prefix.long!!.toDouble()), suffix)
} else {
return TranslatableComponent(SiPrefix.determine(this, bias).formatLocaleKey, "%.${decimalPlaces}f".format(this.toDouble() / prefix.long!!.toDouble()), suffix)
}
return TranslatableComponent(prefix.neighbour(bias).formatLocaleKey, "%.${decimalPlaces}f".format(this.toDouble() / prefix.long!!.toDouble()), suffix)
}
fun Int.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never, bias: Int = 0): Component {
return toLong().formatSiComponent(suffix, decimalPlaces, formatAsReadable, bias)
}
fun Double.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never): Component {
fun Double.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never, bias: Int = 0): Component {
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
if (formatAsReadable.asBoolean) return concat(reformat("%.${decimalPlaces}f".format(this)), suffix)
val prefix = SiPrefix.determine(this)
return TranslatableComponent(prefix.formatLocaleKey, "%.${decimalPlaces}f".format(this / prefix.double), suffix)
return TranslatableComponent(prefix.neighbour(bias).formatLocaleKey, "%.${decimalPlaces}f".format(this / prefix.double), suffix)
}
fun Decimal.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never): Component {
fun Decimal.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never, bias: Int = 0): Component {
require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" }
if (formatAsReadable.asBoolean) return concat(reformat(toString(decimalPlaces)), suffix)
val prefix = SiPrefix.determine(this)
return TranslatableComponent(prefix.formatLocaleKey, (this / prefix.decimal).toString(decimalPlaces), suffix)
return TranslatableComponent(prefix.neighbour(bias).formatLocaleKey, (this / prefix.decimal).toString(decimalPlaces), suffix)
}
fun Int.formatPower(decimalPlaces: Int = 2, formatAsReadable: BooleanSupplier = never) = formatSiComponent(TranslatableComponent("otm.gui.power.name"), decimalPlaces, formatAsReadable = formatAsReadable)