diff options
author | Joffrey Bion <joffrey.bion@gmail.com> | 2021-02-23 00:01:00 +0100 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@gmail.com> | 2021-02-23 18:38:24 +0100 |
commit | e2957be6c0f2dea09d0633cd7ee7549311b9b923 (patch) | |
tree | 97b3dcbf09501ac2bd00d9ac8e0a1f1f280ecf0a /sw-ui/src | |
parent | Fix player re-order animation (diff) | |
download | seven-wonders-e2957be6c0f2dea09d0633cd7ee7549311b9b923.tar.gz seven-wonders-e2957be6c0f2dea09d0633cd7ee7549311b9b923.tar.bz2 seven-wonders-e2957be6c0f2dea09d0633cd7ee7549311b9b923.zip |
Funnel game events into a single client subscription
Diffstat (limited to 'sw-ui/src')
-rw-r--r-- | sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/RouteBasedSagas.kt | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/RouteBasedSagas.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/RouteBasedSagas.kt index 06b33e13..af2624ec 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/RouteBasedSagas.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/RouteBasedSagas.kt @@ -3,6 +3,7 @@ package org.luxons.sevenwonders.ui.redux.sagas import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.map import org.luxons.sevenwonders.client.SevenWondersSession +import org.luxons.sevenwonders.model.api.events.GameEvent import org.luxons.sevenwonders.ui.redux.* import org.luxons.sevenwonders.ui.router.Navigate import org.luxons.sevenwonders.ui.router.Route @@ -49,10 +50,14 @@ suspend fun SwSagaContext.lobbySaga(session: SevenWondersSession) { suspend fun SwSagaContext.gameSaga(session: SevenWondersSession) { val game = reduxState.gameState ?: error("Game saga run without a current game") coroutineScope { - session.watchPlayerReady(game.id).map { PlayerReadyEvent(it) }.dispatchAllIn(this) - session.watchPreparedCards(game.id).map { PreparedCardEvent(it) }.dispatchAllIn(this) - session.watchOwnMoves().map { PreparedMoveEvent(it) }.dispatchAllIn(this) - session.watchTurns().map { TurnInfoEvent(it) }.dispatchAllIn(this) + session.watchGameEvents(game.id).map { + when (it) { + is GameEvent.NewTurnStarted -> TurnInfoEvent(it.turnInfo) + is GameEvent.MovePrepared -> PreparedMoveEvent(it.move) + is GameEvent.CardPrepared -> PreparedCardEvent(it.preparedCard) + is GameEvent.PlayerIsReady -> PlayerReadyEvent(it.username) + } + }.dispatchAllIn(this) session.sayReady() } console.log("End of game saga") |