diff --git a/domain/monster/core/src/commonMain/kotlin/br/alexandregpereira/hunter/domain/model/Monster.kt b/domain/monster/core/src/commonMain/kotlin/br/alexandregpereira/hunter/domain/model/Monster.kt index 0f5de7eb..50d57677 100644 --- a/domain/monster/core/src/commonMain/kotlin/br/alexandregpereira/hunter/domain/model/Monster.kt +++ b/domain/monster/core/src/commonMain/kotlin/br/alexandregpereira/hunter/domain/model/Monster.kt @@ -21,6 +21,7 @@ import br.alexandregpereira.hunter.domain.monster.spell.model.SpellPreview import br.alexandregpereira.hunter.domain.monster.spell.model.SpellUsage import br.alexandregpereira.hunter.domain.monster.spell.model.Spellcasting import br.alexandregpereira.hunter.domain.monster.spell.model.SpellcastingType +import java.text.NumberFormat import kotlin.native.ObjCName @ObjCName(name = "Monster", exact = true) @@ -111,6 +112,20 @@ private fun Monster.challengeRatingToXp(): Int { } } +fun Monster.xpFormatted(): String { + val xpString = when { + xp < 1000 -> xp.toString() + else -> { + val xpFormatted = NumberFormat.getIntegerInstance().format(xp) + .dropLastWhile { it == '0' } + .let { if (it.last().isDigit().not()) it.dropLast(1) else it } + "${xpFormatted}k" + } + } + + return "$xpString XP" +} + fun getFakeMonster(): Monster { return Monster( index = "1", diff --git a/feature/monster-detail/android/src/main/kotlin/br/alexandregpereira/hunter/detail/MonsterDetailStateMapper.kt b/feature/monster-detail/android/src/main/kotlin/br/alexandregpereira/hunter/detail/MonsterDetailStateMapper.kt index c56dc6f9..7dc38a3d 100644 --- a/feature/monster-detail/android/src/main/kotlin/br/alexandregpereira/hunter/detail/MonsterDetailStateMapper.kt +++ b/feature/monster-detail/android/src/main/kotlin/br/alexandregpereira/hunter/detail/MonsterDetailStateMapper.kt @@ -50,6 +50,7 @@ import br.alexandregpereira.hunter.domain.model.MonsterType import br.alexandregpereira.hunter.domain.model.SavingThrow import br.alexandregpereira.hunter.domain.model.Skill import br.alexandregpereira.hunter.domain.model.SpeedValue +import br.alexandregpereira.hunter.domain.model.xpFormatted import br.alexandregpereira.hunter.domain.monster.spell.model.Spellcasting import br.alexandregpereira.hunter.ui.compose.SchoolOfMagicState import java.text.NumberFormat @@ -104,20 +105,6 @@ private fun Monster.asState(): MonsterState { ) } -private fun Monster.xpFormatted(): String { - val xpString = when { - xp < 1000 -> xp.toString() - else -> { - val xpFormatted = NumberFormat.getIntegerInstance().format(xp) - .replace("0", "") - .let { if (it.last().isDigit().not()) it.dropLast(1) else it } - "${xpFormatted}k" - } - } - - return "$xpString XP" -} - private fun MonsterImageData.asState( type: MonsterType, challengeRating: Float,