From 83d334698c2cdaee0b67df1c8318844da0c081f6 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Tue, 23 Feb 2021 23:49:48 +0100 Subject: Move transaction selector state from redux to component state --- .../sevenwonders/ui/components/game/GameScene.kt | 43 +++++++++++++++++----- .../luxons/sevenwonders/ui/components/game/Hand.kt | 1 - .../ui/components/game/TransactionsSelector.kt | 1 - .../org/luxons/sevenwonders/ui/redux/Actions.kt | 4 -- .../org/luxons/sevenwonders/ui/redux/Reducers.kt | 13 ------- 5 files changed, 34 insertions(+), 28 deletions(-) (limited to 'sw-ui') 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 ed1c14d1..f61182bf 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 @@ -9,8 +9,10 @@ import org.luxons.sevenwonders.model.api.PlayerDTO import org.luxons.sevenwonders.model.boards.Board import org.luxons.sevenwonders.model.boards.RelativeBoardPosition import org.luxons.sevenwonders.model.cards.HandCard +import org.luxons.sevenwonders.model.resources.ResourceTransactionOptions import org.luxons.sevenwonders.ui.components.GlobalStyles import org.luxons.sevenwonders.ui.redux.* +import org.luxons.sevenwonders.ui.redux.GameState import react.* import styled.css import styled.getClassName @@ -28,14 +30,26 @@ interface GameSceneDispatchProps : RProps { var sayReady: () -> Unit var prepareMove: (move: PlayerMove) -> Unit var unprepareMove: () -> Unit - var startTransactionsSelection: (TransactionSelectorState) -> Unit - var cancelTransactionsSelection: () -> Unit var leaveGame: () -> Unit } interface GameSceneProps : GameSceneStateProps, GameSceneDispatchProps -private class GameScene(props: GameSceneProps) : RComponent(props) { +data class GameSceneState( + var transactionSelector: TransactionSelectorState? +) : RState + +data class TransactionSelectorState( + val moveType: MoveType, + val card: HandCard, + val transactionsOptions: ResourceTransactionOptions, +) + +private class GameScene(props: GameSceneProps) : RComponent(props) { + + override fun GameSceneState.init() { + transactionSelector = null + } override fun RBuilder.render() { styledDiv { @@ -74,14 +88,14 @@ private class GameScene(props: GameSceneProps) : RComponent = mapDispatchToProps = { dispatch, _ -> prepareMove = { move -> dispatch(RequestPrepareMove(move)) } unprepareMove = { dispatch(RequestUnprepareMove()) } - startTransactionsSelection = { selector -> dispatch(StartTransactionSelection(selector)) } - cancelTransactionsSelection = { dispatch(CancelTransactionSelection) } sayReady = { dispatch(RequestSayReady()) } leaveGame = { dispatch(RequestLeaveGame()) } }, 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 9eab3553..08983228 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 @@ -9,7 +9,6 @@ import org.luxons.sevenwonders.model.cards.CardPlayability import org.luxons.sevenwonders.model.cards.HandCard import org.luxons.sevenwonders.model.resources.ResourceTransactionOptions import org.luxons.sevenwonders.model.wonders.WonderBuildability -import org.luxons.sevenwonders.ui.redux.TransactionSelectorState import react.* import styled.StyledDOMBuilder import styled.css diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/TransactionsSelector.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/TransactionsSelector.kt index 77cc97f8..24b94748 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/TransactionsSelector.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/TransactionsSelector.kt @@ -11,7 +11,6 @@ import org.luxons.sevenwonders.model.PlayerMove import org.luxons.sevenwonders.model.api.PlayerDTO import org.luxons.sevenwonders.model.resources.* import org.luxons.sevenwonders.ui.components.gameBrowser.playerInfo -import org.luxons.sevenwonders.ui.redux.TransactionSelectorState import react.* import react.dom.* import styled.* diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt index c5ffafa0..81ac14b8 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt @@ -24,10 +24,6 @@ data class EnterGameAction(val lobby: LobbyDTO, val turnInfo: PlayerTurnInfo) : data class TurnInfoEvent(val turnInfo: PlayerTurnInfo) : RAction -data class StartTransactionSelection(val transactionSelector: TransactionSelectorState) : RAction - -object CancelTransactionSelection : RAction - data class PreparedMoveEvent(val move: PlayerMove) : RAction data class PreparedCardEvent(val card: PreparedCard) : RAction 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 5d345136..bf6aaf2e 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 @@ -1,6 +1,5 @@ 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 @@ -10,7 +9,6 @@ import org.luxons.sevenwonders.model.api.LobbyDTO import org.luxons.sevenwonders.model.api.PlayerDTO import org.luxons.sevenwonders.model.cards.CardBack import org.luxons.sevenwonders.model.cards.HandCard -import org.luxons.sevenwonders.model.resources.ResourceTransactionOptions import redux.RAction data class SwState( @@ -33,8 +31,6 @@ data class GameState( val turnInfo: PlayerTurnInfo?, val preparedCardsByUsername: Map = emptyMap(), val currentPreparedMove: PlayerMove? = null, - // UI - val transactionSelector: TransactionSelectorState? = null, ) { val currentPreparedCard: HandCard? get() { @@ -43,12 +39,6 @@ data class GameState( } } -data class TransactionSelectorState( - val moveType: MoveType, - val card: HandCard, - val transactionsOptions: ResourceTransactionOptions, -) - fun rootReducer(state: SwState, action: RAction): SwState = state.copy( gamesById = gamesReducer(state.gamesById, action), connectedPlayer = currentPlayerReducer(state.connectedPlayer, action), @@ -103,9 +93,6 @@ private fun gameStateReducer(gameState: GameState?, action: RAction): GameState? preparedCardsByUsername = emptyMap(), currentPreparedMove = null, ) - is StartTransactionSelection -> gameState?.copy(transactionSelector = action.transactionSelector) - is CancelTransactionSelection -> gameState?.copy(transactionSelector = null) - is RequestPrepareMove -> gameState?.copy(transactionSelector = null) is LeaveLobbyAction -> null else -> gameState } -- cgit