From fee376b1136fa35d3804d63a7c5b276154eb5c6b Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Thu, 26 Mar 2020 15:12:32 +0100 Subject: Remove gameId parameter for the game scene route --- .../org/luxons/sevenwonders/ui/components/Application.kt | 4 ++-- .../org/luxons/sevenwonders/ui/components/game/GameScene.kt | 4 ++-- .../org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt | 12 +++++++----- .../org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt | 4 ++-- .../main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) (limited to 'sw-ui-kt/src/main') diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt index 5e602ae5..d692c256 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt @@ -19,8 +19,8 @@ interface IdProps : RProps { fun RBuilder.application() = hashRouter { switch { route("/games") { gameBrowser() } - route("/game/:id") { props -> gameScene(props.match.params.id) } - route("/lobby") { lobby() } + route("/game") { gameScene() } + route("/lobby") { lobby() } route("/", exact = true) { home() } redirect(from = "*", to = "/") } diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt index 44136993..d8b5ec7d 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt @@ -3,6 +3,6 @@ package org.luxons.sevenwonders.ui.components.game import react.RBuilder import react.dom.* -fun RBuilder.gameScene(gameId: Long) = div { - h1 { +"Game $gameId" } +fun RBuilder.gameScene() = div { + h1 { +"Game" } } diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt index 29242782..eb4e3c13 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt @@ -3,13 +3,15 @@ package org.luxons.sevenwonders.ui.redux.sagas import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import org.luxons.sevenwonders.client.SevenWondersSession -import org.luxons.sevenwonders.ui.redux.SwState -import redux.RAction -import redux.WrapperAction +import org.luxons.sevenwonders.model.api.State -suspend fun SwSagaContext.gameSaga(session: SevenWondersSession, gameId: Long) { +suspend fun SwSagaContext.gameSaga(session: SevenWondersSession) { + val lobby = getState().currentLobby ?: error("Game saga run without a current game") + if (lobby.state != State.PLAYING) { + error("Game saga run but the game hasn't started") + } coroutineScope { - launch { watchPlayerReady(session, gameId) } + launch { watchPlayerReady(session, lobby.id) } } } diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt index bf13c47e..b2d83416 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt @@ -29,8 +29,8 @@ private suspend fun SwSagaContext.handleGameStart(session: SevenWondersSession, dispatch(EnterGameAction(lobbyId)) coroutineScope { - launch { gameSaga(session, lobbyId) } - Router.game(lobbyId) + launch { gameSaga(session) } + Router.game() } } diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt index 25cb2ec1..09789ee1 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt @@ -8,8 +8,8 @@ object Router { push("/games") } - fun game(id: Long) { - push("/game/$id") + fun game() { + push("/game") } fun lobby() { -- cgit