diff options
Diffstat (limited to 'sw-common-model/src/commonMain/kotlin/org/luxons')
-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( |