diff options
Diffstat (limited to 'sw-ui-kt/src/main')
-rw-r--r-- | sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt | 2 | ||||
-rw-r--r-- | sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt | 13 |
2 files changed, 11 insertions, 4 deletions
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<PlayerDTO>, val turnInfo: PlayerTurnInfo?, - val preparedCardsByUsername: Map<String, PreparedCard> = emptyMap(), + val preparedCardsByUsername: Map<String, CardBack?> = 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 |