From 747911a542b5971de182e4491393a8f53eb8e9a8 Mon Sep 17 00:00:00 2001 From: joffrey-bion Date: Thu, 10 Dec 2020 01:30:51 +0100 Subject: Decouple some sagas from routes Resolves: https://github.com/joffrey-bion/seven-wonders/issues/13 --- .../sevenwonders/client/SevenWondersClient.kt | 39 +++++++++------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'sw-client') 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 9a9fe356..5dda0292 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 @@ -22,15 +22,7 @@ import org.luxons.sevenwonders.model.Settings import org.luxons.sevenwonders.model.api.ConnectedPlayer import org.luxons.sevenwonders.model.api.LobbyDTO import org.luxons.sevenwonders.model.api.SEVEN_WONDERS_WS_ENDPOINT -import org.luxons.sevenwonders.model.api.actions.AddBotAction -import org.luxons.sevenwonders.model.api.actions.ChooseNameAction -import org.luxons.sevenwonders.model.api.actions.CreateGameAction -import org.luxons.sevenwonders.model.api.actions.Icon -import org.luxons.sevenwonders.model.api.actions.JoinGameAction -import org.luxons.sevenwonders.model.api.actions.PrepareMoveAction -import org.luxons.sevenwonders.model.api.actions.ReassignWondersAction -import org.luxons.sevenwonders.model.api.actions.ReorderPlayersAction -import org.luxons.sevenwonders.model.api.actions.UpdateSettingsAction +import org.luxons.sevenwonders.model.api.actions.* import org.luxons.sevenwonders.model.api.errors.ErrorDTO import org.luxons.sevenwonders.model.cards.PreparedCard import org.luxons.sevenwonders.model.wonders.AssignedWonder @@ -80,21 +72,16 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat suspend fun watchGames(): Flow> = stompSession.subscribe("/topic/games", ListSerializer(LobbyDTO.serializer())) - suspend fun createGame(gameName: String): LobbyDTO = stompSession.request( - sendDestination = "/app/lobby/create", - receiveDestination = "/user/queue/lobby/joined", - payload = CreateGameAction(gameName), - serializer = CreateGameAction.serializer(), - deserializer = LobbyDTO.serializer(), - ) + suspend fun createGame(gameName: String) { + stompSession.convertAndSend("/app/lobby/create", CreateGameAction(gameName), CreateGameAction.serializer()) + } - suspend fun joinGame(gameId: Long): LobbyDTO = stompSession.request( - sendDestination = "/app/lobby/join", - receiveDestination = "/user/queue/lobby/joined", - payload = JoinGameAction(gameId), - serializer = JoinGameAction.serializer(), - deserializer = LobbyDTO.serializer(), - ) + suspend fun joinGame(gameId: Long) { + stompSession.convertAndSend("/app/lobby/join", JoinGameAction(gameId), JoinGameAction.serializer()) + } + + suspend fun watchLobbyJoined(): Flow = + stompSession.subscribe("/user/queue/lobby/joined", LobbyDTO.serializer()) suspend fun leaveLobby() { stompSession.sendEmptyMsg("/app/lobby/leave") @@ -172,3 +159,9 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat stompSession.sendEmptyMsg("/app/game/leave") } } + +suspend fun SevenWondersSession.joinGameAndWaitLobby(gameId: Long): LobbyDTO { + val joinedLobbies = watchLobbyJoined() + joinGame(gameId) + return joinedLobbies.first() +} \ No newline at end of file -- cgit