diff options
Diffstat (limited to 'sw-ui/src/main')
3 files changed, 50 insertions, 9 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 9043537c..910fd71d 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 @@ -8,10 +8,9 @@ import kotlinx.css.properties.* import kotlinx.html.DIV 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 +import org.luxons.sevenwonders.model.wonders.AssignedWonder +import org.luxons.sevenwonders.model.wonders.deal +import org.luxons.sevenwonders.ui.redux.* import react.RBuilder import react.RComponent import react.RProps @@ -31,6 +30,8 @@ interface LobbyDispatchProps : RProps { var startGame: () -> Unit var addBot: (displayName: String) -> Unit var leaveLobby: () -> Unit + var reorderPlayers: (orderedPlayers: List<String>) -> Unit + var reassignWonders: (wonders: List<AssignedWonder>) -> Unit } interface LobbyProps : LobbyDispatchProps, LobbyStateProps @@ -65,6 +66,8 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) if (currentPlayer.isGameOwner) { startButton(currentGame, currentPlayer) addBotButton(currentGame) + reorderPlayersButton(currentGame) + randomizeWondersButton(currentGame) } else { leaveButton() } @@ -104,6 +107,37 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props) props.addBot(availableBotNames.random()) } + private fun RBuilder.reorderPlayersButton(currentGame: LobbyDTO) { + bpButton( + large = true, + intent = Intent.NONE, + icon = "random", + rightIcon = "people", + title = "Re-order players randomly", + onClick = { reorderPlayers(currentGame) } + ) + } + + private fun reorderPlayers(currentGame: LobbyDTO) { + props.reorderPlayers(currentGame.players.map { it.username }.shuffled()) + } + + private fun RBuilder.randomizeWondersButton(currentGame: LobbyDTO) { + bpButton( + large = true, + intent = Intent.NONE, + icon = "random", + title = "Re-assign wonders to players randomly", + onClick = { randomizeWonders(currentGame) } + ) { + +"W" + } + } + + private fun randomizeWonders(currentGame: LobbyDTO) { + props.reassignWonders(currentGame.allWonders.deal(currentGame.players.size)) + } + private fun RBuilder.leaveButton() { bpButton( large = true, @@ -129,5 +163,7 @@ private val lobby = connectStateAndDispatch<LobbyStateProps, LobbyDispatchProps, startGame = { dispatch(RequestStartGame()) } addBot = { name -> dispatch(RequestAddBot(name)) } leaveLobby = { dispatch(RequestLeaveLobby()) } + reorderPlayers = { orderedPlayers -> dispatch(RequestReorderPlayers(orderedPlayers)) } + reassignWonders = { wonders -> dispatch(RequestReassignWonders(wonders)) } } ) 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 7badb11c..53cdeaf4 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 @@ -2,6 +2,7 @@ package org.luxons.sevenwonders.ui.redux import org.luxons.sevenwonders.model.Settings import org.luxons.sevenwonders.model.PlayerMove +import org.luxons.sevenwonders.model.wonders.AssignedWonder import redux.RAction data class RequestChooseName(val playerName: String) : RAction @@ -14,6 +15,8 @@ data class RequestAddBot(val botDisplayName: String) : RAction data class RequestReorderPlayers(val orderedPlayers: List<String>) : RAction +data class RequestReassignWonders(val wonders: List<AssignedWonder>) : RAction + data class RequestUpdateSettings(val settings: Settings) : RAction class RequestStartGame : 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 d6d41881..044f8e78 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 @@ -4,11 +4,7 @@ import kotlinx.coroutines.coroutineScope 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 +import org.luxons.sevenwonders.ui.redux.* import org.luxons.sevenwonders.ui.router.Navigate import org.luxons.sevenwonders.ui.router.Route import org.luxons.sevenwonders.ui.utils.awaitFirst @@ -23,6 +19,12 @@ suspend fun SwSagaContext.lobbySaga(session: SevenWondersSession) { launch { onEach<RequestAddBot> { session.addBot(it.botDisplayName) } } + launch { + onEach<RequestReorderPlayers> { session.reorderPlayers(it.orderedPlayers) } + } + launch { + onEach<RequestReassignWonders> { session.reassignWonders(it.wonders) } + } val startGameJob = launch { awaitStartGame(session) } awaitFirst( |