summaryrefslogtreecommitdiff
path: root/sw-client/src/commonMain/kotlin/org/luxons
diff options
context:
space:
mode:
authorjoffrey-bion <joffrey.bion@gmail.com>2020-12-10 23:06:00 +0100
committerjoffrey-bion <joffrey.bion@gmail.com>2020-12-11 02:16:49 +0100
commiteef32bd9307a3a9f1ee3b532db2fb1f7cf37927a (patch)
treef139487db3866a687e699a01f3ed4baa5e44faf2 /sw-client/src/commonMain/kotlin/org/luxons
parentDecouple some sagas from routes (diff)
downloadseven-wonders-eef32bd9307a3a9f1ee3b532db2fb1f7cf37927a.tar.gz
seven-wonders-eef32bd9307a3a9f1ee3b532db2fb1f7cf37927a.tar.bz2
seven-wonders-eef32bd9307a3a9f1ee3b532db2fb1f7cf37927a.zip
Allow owner to leave/disband the game
Resolves: https://github.com/joffrey-bion/seven-wonders/issues/51
Diffstat (limited to 'sw-client/src/commonMain/kotlin/org/luxons')
-rw-r--r--sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt18
1 files changed, 11 insertions, 7 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 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<List<LobbyDTO>> =
- stompSession.subscribe("/topic/games", ListSerializer(LobbyDTO.serializer()))
+ suspend fun watchGames(): Flow<GameListEvent> =
+ 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<Long> = 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
+}
bgstack15