summaryrefslogtreecommitdiff
path: root/sw-ui-kt/src/main
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-04-04 19:11:01 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-04-04 19:11:49 +0200
commit134199b98baf70e4b014f92ff5c082b247aa407c (patch)
treed811dd41d91291be061751f8f59bb64db5a91d03 /sw-ui-kt/src/main
parentAdd blueprintjs Overlay component (diff)
downloadseven-wonders-134199b98baf70e4b014f92ff5c082b247aa407c.tar.gz
seven-wonders-134199b98baf70e4b014f92ff5c082b247aa407c.tar.bz2
seven-wonders-134199b98baf70e4b014f92ff5c082b247aa407c.zip
Add a way to "unprepare" a move
Diffstat (limited to 'sw-ui-kt/src/main')
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/ApiActions.kt2
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt13
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
bgstack15