diff options
Diffstat (limited to 'sw-ui-kt/src')
5 files changed, 32 insertions, 12 deletions
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 fecb8be2..48c993fc 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 @@ -25,10 +25,10 @@ import org.luxons.sevenwonders.model.Action import org.luxons.sevenwonders.model.PlayerMove import org.luxons.sevenwonders.model.PlayerTurnInfo import org.luxons.sevenwonders.model.api.PlayerDTO +import org.luxons.sevenwonders.ui.redux.GameState import org.luxons.sevenwonders.ui.redux.RequestPrepareMove import org.luxons.sevenwonders.ui.redux.RequestSayReady import org.luxons.sevenwonders.ui.redux.connectStateAndDispatch -import org.luxons.sevenwonders.ui.utils.createElement import react.RBuilder import react.RClass import react.RComponent @@ -43,7 +43,8 @@ import styled.styledDiv interface GameSceneStateProps: RProps { var playerIsReady: Boolean var players: List<PlayerDTO> - var turnInfo: PlayerTurnInfo? + var gameState: GameState? + var preparedMove: PlayerMove? } interface GameSceneDispatchProps: RProps { @@ -62,7 +63,7 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta backgroundSize = "cover" fullScreen() } - val turnInfo = props.turnInfo + val turnInfo = props.gameState?.turnInfo if (turnInfo == null) { p { +"Error: no turn info data"} } else { @@ -109,6 +110,7 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta handComponent( cards = hand, wonderUpgradable = turnInfo.wonderBuildability.isBuildable, + preparedMove = props.preparedMove, prepareMove = props.prepareMove ) } @@ -139,7 +141,8 @@ private val gameScene: RClass<GameSceneProps> = connectStateAndDispatch<GameScen mapStateToProps = { state, _ -> playerIsReady = state.currentPlayer?.isReady == true players = state.gameState?.players ?: emptyList() - turnInfo = state.gameState?.turnInfo + gameState = state.gameState + preparedMove = state.gameState?.currentPreparedMove } ) diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt index 9aac310a..985b3deb 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt @@ -38,6 +38,7 @@ import kotlinx.html.DIV import org.luxons.sevenwonders.model.MoveType import org.luxons.sevenwonders.model.PlayerMove import org.luxons.sevenwonders.model.cards.HandCard +import org.luxons.sevenwonders.model.cards.PreparedCard import org.luxons.sevenwonders.ui.components.game.cardImage import react.RBuilder import styled.StyledDOMBuilder @@ -47,14 +48,19 @@ import styled.styledDiv fun RBuilder.handComponent( cards: List<HandCard>, wonderUpgradable: Boolean, + preparedMove: PlayerMove?, prepareMove: (PlayerMove) -> Unit ) { styledDiv { css { handStyle() } - cards.forEachIndexed { index, c -> - handCard(card = c, wonderUpgradable = wonderUpgradable, prepareMove = prepareMove) { + cards.filter { it.name != preparedMove?.cardName }.forEachIndexed { index, c -> + handCard( + card = c, + wonderUpgradable = wonderUpgradable, + prepareMove = prepareMove + ) { attrs { key = index.toString() } diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt index 85b48e61..3e3de561 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt @@ -1,5 +1,6 @@ package org.luxons.sevenwonders.ui.redux +import org.luxons.sevenwonders.model.PlayerMove import org.luxons.sevenwonders.model.PlayerTurnInfo import org.luxons.sevenwonders.model.api.ConnectedPlayer import org.luxons.sevenwonders.model.api.LobbyDTO @@ -18,6 +19,8 @@ data class EnterGameAction(val lobby: LobbyDTO, val turnInfo: PlayerTurnInfo): R data class TurnInfoEvent(val turnInfo: PlayerTurnInfo): RAction +data class PreparedMoveEvent(val move: PlayerMove): RAction + data class PreparedCardEvent(val card: PreparedCard): RAction data class PlayerReadyEvent(val username: String): RAction diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt index f7c27eda..a9b595da 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt @@ -1,5 +1,6 @@ package org.luxons.sevenwonders.ui.redux +import org.luxons.sevenwonders.model.PlayerMove import org.luxons.sevenwonders.model.PlayerTurnInfo import org.luxons.sevenwonders.model.api.ConnectedPlayer import org.luxons.sevenwonders.model.api.LobbyDTO @@ -24,15 +25,16 @@ data class SwState( data class GameState( val id: Long, val players: List<PlayerDTO>, - val preparedCardsByUsername: Map<String, PreparedCard>, - val turnInfo: PlayerTurnInfo? + val turnInfo: PlayerTurnInfo?, + val preparedCardsByUsername: Map<String, PreparedCard> = emptyMap(), + val currentPreparedMove: PlayerMove? = null ) fun rootReducer(state: SwState, action: RAction): SwState = state.copy( gamesById = gamesReducer(state.gamesById, action), connectedPlayer = currentPlayerReducer(state.connectedPlayer, action), currentLobby = currentLobbyReducer(state.currentLobby, action), - gameState = currentTurnInfoReducer(state.gameState, action) + gameState = gameStateReducer(state.gameState, action) ) private fun gamesReducer(games: Map<Long, LobbyDTO>, action: RAction): Map<Long, LobbyDTO> = when (action) { @@ -56,13 +58,13 @@ private fun currentLobbyReducer(currentLobby: LobbyDTO?, action: RAction): Lobby else -> currentLobby } -private fun currentTurnInfoReducer(gameState: GameState?, action: RAction): GameState? = when (action) { +private fun gameStateReducer(gameState: GameState?, action: RAction): GameState? = when (action) { is EnterGameAction -> GameState( id = action.lobby.id, players = action.lobby.players, - preparedCardsByUsername = emptyMap(), turnInfo = action.turnInfo ) + is PreparedMoveEvent -> gameState?.copy(currentPreparedMove = action.move) is PreparedCardEvent -> gameState?.copy( preparedCardsByUsername = gameState.preparedCardsByUsername + (action.card.player.username to action.card) ) 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 e2c2d4d1..c1788c98 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 @@ -5,6 +5,7 @@ import kotlinx.coroutines.launch import org.luxons.sevenwonders.client.SevenWondersSession import org.luxons.sevenwonders.ui.redux.PlayerReadyEvent import org.luxons.sevenwonders.ui.redux.PreparedCardEvent +import org.luxons.sevenwonders.ui.redux.PreparedMoveEvent import org.luxons.sevenwonders.ui.redux.RequestPrepareMove import org.luxons.sevenwonders.ui.redux.RequestSayReady import org.luxons.sevenwonders.ui.redux.TurnInfoEvent @@ -16,7 +17,12 @@ suspend fun SwSagaContext.gameSaga(session: SevenWondersSession) { val preparedCardsSub = session.watchPreparedCards(game.id) val turnInfoSub = session.watchTurns() val sayReadyJob = launch { onEach<RequestSayReady> { session.sayReady() } } - val prepareMoveJob = launch { onEach<RequestPrepareMove> { session.prepareMove(it.move) } } + val prepareMoveJob = launch { + onEach<RequestPrepareMove> { + val move = session.prepareMove(it.move) + dispatch(PreparedMoveEvent(move)) + } + } launch { dispatchAll(playerReadySub.messages) { PlayerReadyEvent(it) } } launch { dispatchAll(preparedCardsSub.messages) { PreparedCardEvent(it) } } launch { dispatchAll(turnInfoSub.messages) { TurnInfoEvent(it) } } |