diff options
author | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-03 02:37:38 +0100 |
---|---|---|
committer | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-03 23:29:16 +0100 |
commit | 7c2371766b940742f3986d7904d4c20a4127ea70 (patch) | |
tree | 294d0c80b2590b69d032a37bcc78b3ce15be012a /sw-client | |
parent | Cleanup (diff) | |
download | seven-wonders-7c2371766b940742f3986d7904d4c20a4127ea70.tar.gz seven-wonders-7c2371766b940742f3986d7904d4c20a4127ea70.tar.bz2 seven-wonders-7c2371766b940742f3986d7904d4c20a4127ea70.zip |
Add auto-game with bots only
Resolves:
https://github.com/joffrey-bion/seven-wonders/issues/82
Diffstat (limited to 'sw-client')
-rw-r--r-- | sw-client/build.gradle.kts | 1 | ||||
-rw-r--r-- | sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt | 30 |
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() } |