summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt2
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt18
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt43
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt2
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt26
5 files changed, 62 insertions, 29 deletions
diff --git a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt
index 5476a890..6cccea8f 100644
--- a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt
+++ b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt
@@ -83,7 +83,7 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat
deserializer = LobbyDTO.serializer()
)
- suspend fun leaveGame() {
+ suspend fun leaveLobby() {
stompSession.sendEmptyMsg("/app/lobby/leave")
}
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt
index ee1c6271..403a4696 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt
@@ -33,8 +33,7 @@ class LobbyController @Autowired constructor(
/**
* Leaves the current lobby.
*
- * @param principal
- * the connected user's information
+ * @param principal the connected user's information
*/
@MessageMapping("/lobby/leave")
fun leave(principal: Principal) {
@@ -52,10 +51,8 @@ class LobbyController @Autowired constructor(
/**
* Reorders the players in the current lobby. This can only be done by the lobby's owner.
*
- * @param action
- * the action to reorder the players
- * @param principal
- * the connected user's information
+ * @param action the action to reorder the players
+ * @param principal the connected user's information
*/
@MessageMapping("/lobby/reorderPlayers")
fun reorderPlayers(@Validated action: ReorderPlayersAction, principal: Principal) {
@@ -69,10 +66,8 @@ class LobbyController @Autowired constructor(
/**
* Updates the game settings. This can only be done by the lobby's owner.
*
- * @param action
- * the action to update the settings
- * @param principal
- * the connected user's information
+ * @param action the action to update the settings
+ * @param principal the connected user's information
*/
@MessageMapping("/lobby/updateSettings")
fun updateSettings(@Validated action: UpdateSettingsAction, principal: Principal) {
@@ -93,8 +88,7 @@ class LobbyController @Autowired constructor(
/**
* Starts the game.
*
- * @param principal
- * the connected user's information
+ * @param principal the connected user's information
*/
@MessageMapping("/lobby/startGame")
fun startGame(principal: Principal) {
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 5b13d8b1..d015e2a2 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.RequestLeaveLobby
import org.luxons.sevenwonders.ui.redux.RequestStartGame
import org.luxons.sevenwonders.ui.redux.connectStateAndDispatch
import react.RBuilder
@@ -19,6 +20,7 @@ interface LobbyStateProps : RProps {
interface LobbyDispatchProps : RProps {
var startGame: () -> Unit
+ var leaveLobby: () -> Unit
}
interface LobbyProps : LobbyDispatchProps, LobbyStateProps
@@ -36,20 +38,38 @@ class LobbyPresenter(props: LobbyProps) : RComponent<LobbyProps, RState>(props)
h2 { +"${currentGame.name} — Lobby" }
radialPlayerList(currentGame.players, currentPlayer)
if (currentPlayer.isGameOwner) {
- val startability = currentGame.startability(currentPlayer.username)
- bpButton(
- large = true,
- intent = Intent.PRIMARY,
- icon = "play",
- title = startability.tooltip,
- disabled = !startability.canDo,
- onClick = { props.startGame() }
- ) {
- + "START"
- }
+ startButton(currentGame, currentPlayer)
+ } else {
+ leaveButton()
}
}
}
+
+ private fun RBuilder.startButton(currentGame: LobbyDTO, currentPlayer: PlayerDTO) {
+ val startability = currentGame.startability(currentPlayer.username)
+ bpButton(
+ large = true,
+ intent = Intent.PRIMARY,
+ icon = "play",
+ title = startability.tooltip,
+ disabled = !startability.canDo,
+ onClick = { props.startGame() }
+ ) {
+ +"START"
+ }
+ }
+
+ private fun RBuilder.leaveButton() {
+ bpButton(
+ large = true,
+ intent = Intent.DANGER,
+ icon = "arrow-left",
+ title = "Leave the lobby and go back to the game browser",
+ onClick = { props.leaveLobby() }
+ ) {
+ +"LEAVE"
+ }
+ }
}
fun RBuilder.lobby() = lobby {}
@@ -62,5 +82,6 @@ private val lobby = connectStateAndDispatch<LobbyStateProps, LobbyDispatchProps,
},
mapDispatchToProps = { dispatch, _ ->
startGame = { dispatch(RequestStartGame()) }
+ 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 9e2593d4..eef77585 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
@@ -16,6 +16,8 @@ data class RequestUpdateSettings(val settings: CustomizableSettings) : RAction
class RequestStartGame : RAction
+class RequestLeaveLobby : RAction
+
class RequestSayReady : RAction
data class RequestPrepareMove(val move: PlayerMove) : 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 678276dc..c3996af7 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
@@ -6,10 +6,12 @@ import org.hildan.krossbow.stomp.StompSubscription
import org.luxons.sevenwonders.client.SevenWondersSession
import org.luxons.sevenwonders.model.api.LobbyDTO
import org.luxons.sevenwonders.ui.redux.EnterGameAction
+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.router.Navigate
import org.luxons.sevenwonders.ui.router.Route
+import org.luxons.sevenwonders.ui.utils.awaitFirst
suspend fun SwSagaContext.lobbySaga(session: SevenWondersSession) {
val lobby = getState().currentLobby ?: error("Lobby saga run without a current lobby")
@@ -18,11 +20,20 @@ suspend fun SwSagaContext.lobbySaga(session: SevenWondersSession) {
launch { watchLobbyUpdates(lobbyUpdatesSubscription) }
val startGameJob = launch { awaitStartGame(session) }
- awaitGameStart(session, lobby.id)
-
- lobbyUpdatesSubscription.unsubscribe()
- startGameJob.cancel()
- dispatch(Navigate(Route.GAME))
+ awaitFirst(
+ {
+ awaitLeaveLobby(session)
+ lobbyUpdatesSubscription.unsubscribe()
+ startGameJob.cancel()
+ dispatch(Navigate(Route.GAME_BROWSER))
+ },
+ {
+ awaitGameStart(session, lobby.id)
+ lobbyUpdatesSubscription.unsubscribe()
+ startGameJob.cancel()
+ dispatch(Navigate(Route.GAME))
+ }
+ )
}
}
@@ -40,3 +51,8 @@ private suspend fun SwSagaContext.awaitStartGame(session: SevenWondersSession) {
next<RequestStartGame>()
session.startGame()
}
+
+private suspend fun SwSagaContext.awaitLeaveLobby(session: SevenWondersSession) {
+ next<RequestLeaveLobby>()
+ session.leaveLobby()
+}
bgstack15