summaryrefslogtreecommitdiff
path: root/sw-client
diff options
context:
space:
mode:
Diffstat (limited to 'sw-client')
-rw-r--r--sw-client/build.gradle.kts1
-rw-r--r--sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt30
2 files changed, 28 insertions, 3 deletions
diff --git a/sw-client/build.gradle.kts b/sw-client/build.gradle.kts
index 421b58dd..68953bc4 100644
--- a/sw-client/build.gradle.kts
+++ b/sw-client/build.gradle.kts
@@ -13,6 +13,7 @@ kotlin {
api(project(":sw-common-model"))
api("org.hildan.krossbow:krossbow-stomp-kxserialization:1.1.5")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")
+ implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
}
}
val commonTest by getting {
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 68026888..fc097d86 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
@@ -1,5 +1,7 @@
package org.luxons.sevenwonders.client
+import kotlinx.coroutines.async
+import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
@@ -148,8 +150,30 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat
}
}
-suspend fun SevenWondersSession.joinGameAndWaitLobby(gameId: Long): LobbyDTO {
- val joinedLobbies = watchLobbyJoined()
+suspend fun SevenWondersSession.createGameAndWaitLobby(gameName: String): LobbyDTO = coroutineScope {
+ val lobbies = watchLobbyJoined()
+ val joinedLobby = async { lobbies.first() }
+ createGame(gameName)
+ joinedLobby.await()
+}
+
+suspend fun SevenWondersSession.joinGameAndWaitLobby(gameId: Long): LobbyDTO = coroutineScope {
+ val lobbies = watchLobbyJoined()
+ val joinedLobby = async { lobbies.first() }
+ joinGame(gameId)
+ joinedLobby.await()
+}
+
+suspend fun SevenWondersSession.startGameAndAwaitFirstTurn(): PlayerTurnInfo = coroutineScope {
+ val gameStartedEvents = watchGameStarted()
+ val deferredFirstTurn = async { gameStartedEvents.first() }
+ startGame()
+ deferredFirstTurn.await()
+}
+
+suspend fun SevenWondersSession.joinGameAndWaitFirstTurn(gameId: Long): PlayerTurnInfo = coroutineScope {
+ val gameStartedEvents = watchGameStarted()
+ val deferredFirstTurn = async { gameStartedEvents.first() }
joinGame(gameId)
- return joinedLobbies.first()
+ deferredFirstTurn.await()
}
bgstack15