diff options
author | joffrey-bion <joffrey.bion@gmail.com> | 2020-12-10 01:30:51 +0100 |
---|---|---|
committer | joffrey-bion <joffrey.bion@gmail.com> | 2020-12-10 01:31:46 +0100 |
commit | 747911a542b5971de182e4491393a8f53eb8e9a8 (patch) | |
tree | 25fd2b515e3289c6c3e15c66cc066421881b3f89 /sw-client/src/commonMain | |
parent | Fix ready state for players (diff) | |
download | seven-wonders-747911a542b5971de182e4491393a8f53eb8e9a8.tar.gz seven-wonders-747911a542b5971de182e4491393a8f53eb8e9a8.tar.bz2 seven-wonders-747911a542b5971de182e4491393a8f53eb8e9a8.zip |
Decouple some sagas from routes
Resolves:
https://github.com/joffrey-bion/seven-wonders/issues/13
Diffstat (limited to 'sw-client/src/commonMain')
-rw-r--r-- | sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt | 39 |
1 files changed, 16 insertions, 23 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 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<List<LobbyDTO>> = 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<LobbyDTO> = + 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 |