summaryrefslogtreecommitdiff
path: root/sw-ui/src/main/kotlin
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@gmail.com>2021-06-19 15:51:54 +0200
committerJoffrey Bion <joffrey.bion@gmail.com>2021-06-19 19:06:30 +0200
commit5d4eda165a4d01ba78d6f49e7ba3b84b4bdabba9 (patch)
treefde9f6b310011b00e1f94a4bd80159dd2f3c26ba /sw-ui/src/main/kotlin
parentFix ex-aequo ranks (diff)
downloadseven-wonders-5d4eda165a4d01ba78d6f49e7ba3b84b4bdabba9.tar.gz
seven-wonders-5d4eda165a4d01ba78d6f49e7ba3b84b4bdabba9.tar.bz2
seven-wonders-5d4eda165a4d01ba78d6f49e7ba3b84b4bdabba9.zip
Use ordinals for score ranks
Diffstat (limited to 'sw-ui/src/main/kotlin')
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/ScoreTable.kt14
1 files changed, 13 insertions, 1 deletions
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/ScoreTable.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/ScoreTable.kt
index a92857ae..b89a02a8 100644
--- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/ScoreTable.kt
+++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/ScoreTable.kt
@@ -66,7 +66,7 @@ private fun RBuilder.scoreTable(scoreBoard: ScoreBoard, players: List<PlayerDTO>
scoreBoard.scores.forEachIndexed { index, score ->
val player = players[score.playerIndex]
tr {
- centeredTd { +"${scoreBoard.ranks[index]}" }
+ centeredTd { ordinal(scoreBoard.ranks[index]) }
centeredTd { bpIcon(player.icon?.name ?: "user", size = 25) }
styledTd {
inlineStyles {
@@ -98,6 +98,18 @@ private fun RBuilder.scoreTable(scoreBoard: ScoreBoard, players: List<PlayerDTO>
}
}
+private fun RBuilder.ordinal(value: Int) {
+ +"$value"
+ sup { +value.ordinalIndicator() }
+}
+
+private fun Int.ordinalIndicator() = when {
+ this % 10 == 1 && this != 11 -> "st"
+ this % 10 == 2 && this != 12 -> "nd"
+ this % 10 == 3 && this != 13 -> "rd"
+ else -> "th"
+}
+
private fun RBuilder.centeredTh(block: RDOMBuilder<TH>.() -> Unit) {
th {
// inline styles necessary to overcome blueprintJS overrides
bgstack15