diff options
Diffstat (limited to 'sw-ui')
3 files changed, 29 insertions, 0 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 d015e2a2..2dc36ef9 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 @@ -4,6 +4,7 @@ import com.palantir.blueprintjs.Intent import com.palantir.blueprintjs.bpButton import org.luxons.sevenwonders.model.api.LobbyDTO import org.luxons.sevenwonders.model.api.PlayerDTO +import org.luxons.sevenwonders.ui.redux.RequestAddBot import org.luxons.sevenwonders.ui.redux.RequestLeaveLobby import org.luxons.sevenwonders.ui.redux.RequestStartGame import org.luxons.sevenwonders.ui.redux.connectStateAndDispatch @@ -20,6 +21,7 @@ interface LobbyStateProps : RProps { interface LobbyDispatchProps : RProps { var startGame: () -> Unit + var addBot: (displayName: String) -> Unit var leaveLobby: () -> Unit } @@ -39,6 +41,7 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) radialPlayerList(currentGame.players, currentPlayer) if (currentPlayer.isGameOwner) { startButton(currentGame, currentPlayer) + addBotButton() } else { leaveButton() } @@ -59,6 +62,25 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) } } + private fun RBuilder.addBotButton() { + bpButton( + large = true, + intent = Intent.NONE, + icon = "plus", + rightIcon = "desktop", + title = "Add a bot to this game", + onClick = { addBot() } + ) { + +"ADD BOT" + } + } + + private fun addBot() { + val name = listOf("Bob", "Jack", "John", "Boris", "HAL", "GLaDOS").random() +// val botName = "\uD83E\uDD16 $name" + props.addBot(name) + } + private fun RBuilder.leaveButton() { bpButton( large = true, @@ -82,6 +104,7 @@ private val lobby = connectStateAndDispatch<LobbyStateProps, LobbyDispatchProps, }, mapDispatchToProps = { dispatch, _ -> startGame = { dispatch(RequestStartGame()) } + addBot = { name -> dispatch(RequestAddBot(name)) } leaveLobby = { dispatch(RequestLeaveLobby()) } } ) diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt index eef77585..300693a3 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt @@ -10,6 +10,8 @@ data class RequestCreateGame(val gameName: String) : RAction data class RequestJoinGame(val gameId: Long) : RAction +data class RequestAddBot(val botDisplayName: String) : RAction + data class RequestReorderPlayers(val orderedPlayers: List<String>) : RAction data class RequestUpdateSettings(val settings: CustomizableSettings) : RAction diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt index e2bf82c5..d6d41881 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt @@ -5,6 +5,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import org.luxons.sevenwonders.client.SevenWondersSession import org.luxons.sevenwonders.ui.redux.EnterGameAction +import org.luxons.sevenwonders.ui.redux.RequestAddBot import org.luxons.sevenwonders.ui.redux.RequestLeaveLobby import org.luxons.sevenwonders.ui.redux.RequestStartGame import org.luxons.sevenwonders.ui.redux.UpdateLobbyAction @@ -19,6 +20,9 @@ suspend fun SwSagaContext.lobbySaga(session: SevenWondersSession) { .map { UpdateLobbyAction(it) } .dispatchAllIn(this) + launch { + onEach<RequestAddBot> { session.addBot(it.botDisplayName) } + } val startGameJob = launch { awaitStartGame(session) } awaitFirst( |