summaryrefslogtreecommitdiff
path: root/sw-ui/src/main/kotlin
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@gmail.com>2021-02-23 18:31:20 +0100
committerJoffrey Bion <joffrey.bion@gmail.com>2021-02-23 18:45:04 +0100
commitb9108dd5f848f13db157cdbe04a2b403e2d8ee7d (patch)
tree1708b619ed0687d638b6e1846770d9a2e5ef6e84 /sw-ui/src/main/kotlin
parentCleanup self board summary (diff)
downloadseven-wonders-b9108dd5f848f13db157cdbe04a2b403e2d8ee7d.tar.gz
seven-wonders-b9108dd5f848f13db157cdbe04a2b403e2d8ee7d.tar.bz2
seven-wonders-b9108dd5f848f13db157cdbe04a2b403e2d8ee7d.zip
Use proper sealed class for TurnActions
Diffstat (limited to 'sw-ui/src/main/kotlin')
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt7
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt24
-rw-r--r--sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt7
3 files changed, 24 insertions, 14 deletions
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt
index ccbb2958..ed1c14d1 100644
--- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt
+++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt
@@ -61,8 +61,9 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta
+GameStyles.pulsatingRed
}
}
- turnInfo.scoreBoard?.let {
- scoreTableOverlay(it, props.players, props.leaveGame)
+ val action = turnInfo.action
+ if (action is TurnAction.WatchScore) {
+ scoreTableOverlay(action.scoreBoard, props.players, props.leaveGame)
}
actionInfo(turnInfo.message)
boardComponent(board = board) {
@@ -86,7 +87,7 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta
if (card != null && move != null) {
preparedMove(card, move)
}
- if (turnInfo.action == Action.SAY_READY) {
+ if (turnInfo.action is TurnAction.SayReady) {
sayReadyButton()
}
}
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt
index 8800c92e..9eab3553 100644
--- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt
+++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt
@@ -37,7 +37,7 @@ interface HandProps : RProps {
class HandComponent(props: HandProps) : RComponent<HandProps, RState>(props) {
override fun RBuilder.render() {
- val hand = props.turnInfo.cardsToPlay() ?: return
+ val hand = props.turnInfo.action.cardsToPlay() ?: return
styledDiv {
css {
handStyle()
@@ -52,11 +52,13 @@ class HandComponent(props: HandProps) : RComponent<HandProps, RState>(props) {
}
}
- private fun PlayerTurnInfo.cardsToPlay(): List<HandCard>? = when (action) {
- Action.PLAY, Action.PLAY_2, Action.PLAY_LAST -> hand
- Action.PLAY_FREE_DISCARDED -> discardedCards
- Action.PICK_NEIGHBOR_GUILD -> neighbourGuildCards
- Action.WAIT, Action.WATCH_SCORE, Action.SAY_READY -> null
+ private fun TurnAction.cardsToPlay(): List<HandCard>? = when (this) {
+ is TurnAction.PlayFromHand -> hand
+ is TurnAction.PlayFromDiscarded -> discardedCards
+ is TurnAction.PickNeighbourGuild -> neighbourGuildCards
+ is TurnAction.SayReady,
+ is TurnAction.Wait,
+ is TurnAction.WatchScore -> null
}
private fun RBuilder.handCard(
@@ -94,15 +96,17 @@ class HandComponent(props: HandProps) : RComponent<HandProps, RState>(props) {
bpButtonGroup {
val action = props.turnInfo.action
when (action) {
- Action.PLAY, Action.PLAY_2, Action.PLAY_LAST -> {
+ is TurnAction.PlayFromHand -> {
playCardButton(card, HandAction.PLAY)
if (props.turnInfo.getOwnBoard().canPlayAnyCardForFree) {
playCardButton(card.copy(playability = CardPlayability.SPECIAL_FREE), HandAction.PLAY_FREE)
}
}
- Action.PLAY_FREE_DISCARDED -> playCardButton(card, HandAction.PLAY_FREE_DISCARDED)
- Action.PICK_NEIGHBOR_GUILD -> playCardButton(card, HandAction.COPY_GUILD)
- else -> error("unsupported action in hand card: $action")
+ is TurnAction.PlayFromDiscarded -> playCardButton(card, HandAction.PLAY_FREE_DISCARDED)
+ is TurnAction.PickNeighbourGuild -> playCardButton(card, HandAction.COPY_GUILD)
+ is TurnAction.SayReady,
+ is TurnAction.Wait,
+ is TurnAction.WatchScore -> error("unsupported action in hand card: $action")
}
if (action.allowsBuildingWonder()) {
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt
index 91dbf61f..5d345136 100644
--- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt
+++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt
@@ -3,6 +3,7 @@ package org.luxons.sevenwonders.ui.redux
import org.luxons.sevenwonders.model.MoveType
import org.luxons.sevenwonders.model.PlayerMove
import org.luxons.sevenwonders.model.PlayerTurnInfo
+import org.luxons.sevenwonders.model.TurnAction
import org.luxons.sevenwonders.model.api.ConnectedPlayer
import org.luxons.sevenwonders.model.api.GameListEvent
import org.luxons.sevenwonders.model.api.LobbyDTO
@@ -32,10 +33,14 @@ data class GameState(
val turnInfo: PlayerTurnInfo?,
val preparedCardsByUsername: Map<String, CardBack?> = emptyMap(),
val currentPreparedMove: PlayerMove? = null,
+ // UI
val transactionSelector: TransactionSelectorState? = null,
) {
val currentPreparedCard: HandCard?
- get() = turnInfo?.hand?.firstOrNull { it.name == currentPreparedMove?.cardName }
+ get() {
+ val hand = (turnInfo?.action as? TurnAction.PlayFromHand)?.hand
+ return hand?.firstOrNull { it.name == currentPreparedMove?.cardName }
+ }
}
data class TransactionSelectorState(
bgstack15