diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-21 13:11:24 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-05-21 13:46:58 +0200 |
commit | afa890418b61a942b0fd6107125d5a2beac36560 (patch) | |
tree | 45431aad5f5e4a5db99215099d47033c94101076 | |
parent | Fix game background image path (diff) | |
download | seven-wonders-afa890418b61a942b0fd6107125d5a2beac36560.tar.gz seven-wonders-afa890418b61a942b0fd6107125d5a2beac36560.tar.bz2 seven-wonders-afa890418b61a942b0fd6107125d5a2beac36560.zip |
Prevent bots with already used names
-rw-r--r-- | sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt index 2dc36ef9..da799e3c 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt @@ -14,6 +14,8 @@ import react.RProps import react.RState import react.dom.* +private val BOT_NAMES = listOf("Wall-E", "B-Max", "Sonny", "T-800", "HAL", "GLaDOS") + interface LobbyStateProps : RProps { var currentGame: LobbyDTO? var currentPlayer: PlayerDTO? @@ -41,7 +43,7 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) radialPlayerList(currentGame.players, currentPlayer) if (currentPlayer.isGameOwner) { startButton(currentGame, currentPlayer) - addBotButton() + addBotButton(currentGame) } else { leaveButton() } @@ -62,23 +64,23 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) } } - private fun RBuilder.addBotButton() { + private fun RBuilder.addBotButton(currentGame: LobbyDTO) { bpButton( large = true, intent = Intent.NONE, icon = "plus", rightIcon = "desktop", - title = "Add a bot to this game", - onClick = { addBot() } - ) { - +"ADD BOT" - } + title = if (currentGame.maxPlayersReached) "Max players reached" else "Add a bot to this game", + disabled = currentGame.maxPlayersReached, + onClick = { addBot(currentGame) } + ) } - private fun addBot() { - val name = listOf("Bob", "Jack", "John", "Boris", "HAL", "GLaDOS").random() -// val botName = "\uD83E\uDD16 $name" - props.addBot(name) + private fun addBot(currentGame: LobbyDTO) { + val availableBotNames = BOT_NAMES.filter { name -> + currentGame.players.all { it.displayName != name } + } + props.addBot(availableBotNames.random()) } private fun RBuilder.leaveButton() { |