diff options
-rw-r--r-- | sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/score/Score.kt | 16 | ||||
-rw-r--r-- | sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/ScoreTable.kt | 2 |
2 files changed, 16 insertions, 2 deletions
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/score/Score.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/score/Score.kt index c1f5e4d3..34dc0d99 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/score/Score.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/score/Score.kt @@ -3,7 +3,21 @@ package org.luxons.sevenwonders.model.score import kotlinx.serialization.Serializable @Serializable -class ScoreBoard(val scores: Collection<PlayerScore>) +class ScoreBoard(val scores: List<PlayerScore>) { + + @OptIn(ExperimentalStdlibApi::class) + val ranks = buildList { + var r = 1 + add(1) + for (i in 1..scores.lastIndex) { + if (scores[i] < scores[i - 1]) { + add(++r) + } else { + add(r) + } + } + } +} @Serializable data class PlayerScore( 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 16c83c78..23fd6d8e 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 @@ -77,7 +77,7 @@ private fun RBuilder.scoreTable(scoreBoard: ScoreBoard, players: List<PlayerDTO> scoreBoard.scores.forEachIndexed { index, score -> val player = players[score.playerIndex] tr { - centeredTd { +"${index + 1}" } + centeredTd { +"${scoreBoard.ranks[index]}" } centeredTd { bpIcon(player.icon?.name ?: "user", size = 25) } styledTd { inlineStyles { |