From 134199b98baf70e4b014f92ff5c082b247aa407c Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Sat, 4 Apr 2020 19:11:01 +0200 Subject: Add a way to "unprepare" a move --- .../kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt | 2 ++ .../kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'sw-ui-kt/src') diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt index e10dcf4d..836f5b4e 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt @@ -19,3 +19,5 @@ class RequestStartGame: RAction class RequestSayReady: RAction data class RequestPrepareMove(val move: PlayerMove): RAction + +class RequestUnprepareMove: 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 a9b595da..c21f6deb 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 @@ -6,7 +6,8 @@ import org.luxons.sevenwonders.model.api.ConnectedPlayer import org.luxons.sevenwonders.model.api.LobbyDTO import org.luxons.sevenwonders.model.api.PlayerDTO import org.luxons.sevenwonders.model.api.State -import org.luxons.sevenwonders.model.cards.PreparedCard +import org.luxons.sevenwonders.model.cards.CardBack +import org.luxons.sevenwonders.model.cards.HandCard import redux.RAction data class SwState( @@ -26,9 +27,12 @@ data class GameState( val id: Long, val players: List, val turnInfo: PlayerTurnInfo?, - val preparedCardsByUsername: Map = emptyMap(), + val preparedCardsByUsername: Map = emptyMap(), val currentPreparedMove: PlayerMove? = null -) +) { + val currentPreparedCard: HandCard? + get() = turnInfo?.hand?.firstOrNull { it.name == currentPreparedMove?.cardName } +} fun rootReducer(state: SwState, action: RAction): SwState = state.copy( gamesById = gamesReducer(state.gamesById, action), @@ -65,8 +69,9 @@ private fun gameStateReducer(gameState: GameState?, action: RAction): GameState? turnInfo = action.turnInfo ) is PreparedMoveEvent -> gameState?.copy(currentPreparedMove = action.move) + is RequestUnprepareMove -> gameState?.copy(currentPreparedMove = null) is PreparedCardEvent -> gameState?.copy( - preparedCardsByUsername = gameState.preparedCardsByUsername + (action.card.player.username to action.card) + preparedCardsByUsername = gameState.preparedCardsByUsername + (action.card.player.username to action.card.cardBack) ) is PlayerReadyEvent -> gameState?.copy(players = gameState.players.map { p -> if (p.username == action.username) p.copy(isReady = true) else p -- cgit