diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-07-01 22:52:12 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-07-01 23:00:36 +0200 |
commit | 420a4c922101668578792c76493be2cb9eea19f3 (patch) | |
tree | df6a204c4bbd809a43b7f571fb223bed5a825583 /sw-common-model/src | |
parent | Use font from CDN instead of relying on "fantasy" (diff) | |
download | seven-wonders-420a4c922101668578792c76493be2cb9eea19f3.tar.gz seven-wonders-420a4c922101668578792c76493be2cb9eea19f3.tar.bz2 seven-wonders-420a4c922101668578792c76493be2cb9eea19f3.zip |
Add setup sidebar to choose wonder sides
Resolves:
https://github.com/joffrey-bion/seven-wonders/issues/35
Diffstat (limited to 'sw-common-model/src')
-rw-r--r-- | sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt | 4 | ||||
-rw-r--r-- | sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt | 8 |
2 files changed, 7 insertions, 5 deletions
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt index 1438600a..324482bb 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Lobby.kt @@ -20,6 +20,10 @@ data class LobbyDTO( val hasEnoughPlayers: Boolean, val maxPlayersReached: Boolean ) { + private val wondersByName = allWonders.associateBy { it.name } + + fun findWonder(name: String): PreGameWonder = wondersByName[name] ?: error("Unknown wonder '$name'") + fun joinability(userDisplayName: String): Actionability = when { state != State.LOBBY -> Actionability(false, "Cannot join: the game has already started") maxPlayersReached -> Actionability(false, "Cannot join: the game is full") diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt index 888e1c47..fcecd010 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/wonders/Wonders.kt @@ -32,11 +32,9 @@ enum class WonderSide { fun List<PreGameWonder>.deal(nbPlayers: Int, random: Random = Random): List<AssignedWonder> = shuffled(random).take(nbPlayers).map { it.withRandomSide(random) } -fun PreGameWonder.withRandomSide(random: Random = Random): AssignedWonder { - val side = WonderSide.values().random(random) - val sideImage = images.getValue(side) - return AssignedWonder(name, side, sideImage) -} +fun PreGameWonder.withRandomSide(random: Random = Random): AssignedWonder = withSide(WonderSide.values().random(random)) + +fun PreGameWonder.withSide(side: WonderSide): AssignedWonder = AssignedWonder(name, side, images.getValue(side)) @Serializable data class ApiWonder( |