From e2957be6c0f2dea09d0633cd7ee7549311b9b923 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Tue, 23 Feb 2021 00:01:00 +0100 Subject: Funnel game events into a single client subscription --- .../luxons/sevenwonders/ui/redux/sagas/RouteBasedSagas.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'sw-ui/src/main/kotlin') 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") -- cgit