From eef32bd9307a3a9f1ee3b532db2fb1f7cf37927a Mon Sep 17 00:00:00 2001 From: joffrey-bion Date: Thu, 10 Dec 2020 23:06:00 +0100 Subject: Allow owner to leave/disband the game Resolves: https://github.com/joffrey-bion/seven-wonders/issues/51 --- .../luxons/sevenwonders/client/SevenWondersClient.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'sw-client/src') 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 5dda0292..6cc50f44 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 @@ -3,10 +3,10 @@ package org.luxons.sevenwonders.client import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.map import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerializationStrategy -import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.builtins.serializer import org.hildan.krossbow.stomp.StompClient import org.hildan.krossbow.stomp.config.HeartBeat @@ -19,9 +19,7 @@ import org.hildan.krossbow.stomp.sendEmptyMsg import org.luxons.sevenwonders.model.PlayerMove import org.luxons.sevenwonders.model.PlayerTurnInfo 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.* import org.luxons.sevenwonders.model.api.actions.* import org.luxons.sevenwonders.model.api.errors.ErrorDTO import org.luxons.sevenwonders.model.cards.PreparedCard @@ -69,8 +67,8 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat deserializer = ConnectedPlayer.serializer(), ) - suspend fun watchGames(): Flow> = - stompSession.subscribe("/topic/games", ListSerializer(LobbyDTO.serializer())) + suspend fun watchGames(): Flow = + stompSession.subscribe("/topic/games", GameListEventWrapper.serializer()).map { it.event } suspend fun createGame(gameName: String) { stompSession.convertAndSend("/app/lobby/create", CreateGameAction(gameName), CreateGameAction.serializer()) @@ -87,6 +85,12 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat stompSession.sendEmptyMsg("/app/lobby/leave") } + suspend fun disbandLobby() { + stompSession.sendEmptyMsg("/app/lobby/disband") + } + + suspend fun watchLobbyLeft(): Flow = stompSession.subscribe("/user/queue/lobby/left", Long.serializer()) + suspend fun addBot(displayName: String) { stompSession.convertAndSend("/app/lobby/addBot", AddBotAction(displayName), AddBotAction.serializer()) } @@ -164,4 +168,4 @@ suspend fun SevenWondersSession.joinGameAndWaitLobby(gameId: Long): LobbyDTO { val joinedLobbies = watchLobbyJoined() joinGame(gameId) return joinedLobbies.first() -} \ No newline at end of file +} -- cgit