diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-03-23 21:41:44 +0100 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-03-23 21:41:44 +0100 |
commit | 2b62a334d6e8951d6b0f6bb5d32ac0df3c9e7e70 (patch) | |
tree | 874f7f4c418f9b5d0f805ff2fca52e30985f41d2 | |
parent | Insignificant cleanup (diff) | |
download | seven-wonders-2b62a334d6e8951d6b0f6bb5d32ac0df3c9e7e70.tar.gz seven-wonders-2b62a334d6e8951d6b0f6bb5d32ac0df3c9e7e70.tar.bz2 seven-wonders-2b62a334d6e8951d6b0f6bb5d32ac0df3c9e7e70.zip |
Add whether game can be started in LobbyDTO
3 files changed, 5 insertions, 2 deletions
diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt index c691a89d..503141c4 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/api/Api.kt @@ -14,7 +14,8 @@ data class LobbyDTO( val name: String, val owner: String, val players: List<PlayerDTO>, - val state: State + val state: State, + val canBeStarted: Boolean ) @Serializable diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt index 6f0fc180..390dc839 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt @@ -7,7 +7,7 @@ import org.luxons.sevenwonders.server.lobby.Player fun Lobby.toDTO(currentUser: String): LobbyDTO { val players = getPlayers().map { it.toDTO(currentUser) } - return LobbyDTO(id, name, owner.username, players, state) + return LobbyDTO(id, name, owner.username, players, state, canBeStarted()) } fun Player.toDTO(currentUser: String) = diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt index 7158a417..599d889f 100644 --- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt +++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt @@ -57,6 +57,8 @@ class Lobby( return game } + fun canBeStarted(): Boolean = hasEnoughPlayers() + private fun hasEnoughPlayers(): Boolean = players.size >= gameDefinition.minPlayers @Synchronized |