diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-03-22 23:04:46 +0100 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-03-22 23:04:46 +0100 |
commit | 2c36a50874b0858de3c7320560618b0c7ddffb76 (patch) | |
tree | 364b387479f15fc26bc573de6544077109961ef9 /sw-ui-kt | |
parent | Fix radial math to account for reversed Y axis (diff) | |
download | seven-wonders-2c36a50874b0858de3c7320560618b0c7ddffb76.tar.gz seven-wonders-2c36a50874b0858de3c7320560618b0c7ddffb76.tar.bz2 seven-wonders-2c36a50874b0858de3c7320560618b0c7ddffb76.zip |
Fix player order by adding placeholders before shifting
Diffstat (limited to 'sw-ui-kt')
-rw-r--r-- | sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialPlayerList.kt | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialPlayerList.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialPlayerList.kt index 472f5811..f096c5db 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialPlayerList.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/RadialPlayerList.kt @@ -21,8 +21,8 @@ import styled.styledH5 fun RBuilder.radialPlayerList(players: List<PlayerDTO>): ReactElement { val playerItemBuilders = players - .withUserFirst() .growTo(targetSize = 3) + .withUserFirst() .map { p -> p.elementBuilder() } val tableImgBuilder: ElementBuilder = { roundTableImg() } @@ -48,12 +48,14 @@ private fun RBuilder.roundTableImg(): ReactElement = img { } } -private fun List<PlayerDTO>.withUserFirst(): List<PlayerDTO> { +private fun List<PlayerDTO?>.withUserFirst(): List<PlayerDTO?> { val nonUsersBeginning = takeWhile { !it.isUser } val userToEnd = subList(nonUsersBeginning.size, size) return userToEnd + nonUsersBeginning } +private val PlayerDTO?.isUser: Boolean get() = this?.isUser ?: false + private fun <T> List<T>.growTo(targetSize: Int): List<T?> { if (size >= targetSize) return this return this + List(targetSize - size) { null } |