diff options
Diffstat (limited to 'sw-ui/src/main/kotlin')
5 files changed, 34 insertions, 28 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 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<GameSceneProps, RState>(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<GameSceneProps, GameSceneState>(props) { + + override fun GameSceneState.init() { + transactionSelector = null + } override fun RBuilder.render() { styledDiv { @@ -74,14 +88,14 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta } } transactionsSelectorDialog( - state = props.gameState?.transactionSelector, + state = state.transactionSelector, neighbours = playerNeighbours(), - prepareMove = props.prepareMove, - cancelTransactionSelection = props.cancelTransactionsSelection, + prepareMove = ::prepareMove, + cancelTransactionSelection = ::resetTransactionSelector, ) boardSummaries(turnInfo) handRotationIndicator(turnInfo.table.handRotationDirection) - handCards(turnInfo, props.preparedMove, props.prepareMove, props.startTransactionsSelection) + handCards(turnInfo, props.preparedMove, props.prepareMove, ::startTransactionSelection) val card = props.preparedCard val move = props.preparedMove if (card != null && move != null) { @@ -93,6 +107,19 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta } } + private fun prepareMove(move: PlayerMove) { + props.prepareMove(move) + setState { transactionSelector = null } + } + + private fun startTransactionSelection(selectorState: TransactionSelectorState) { + setState { transactionSelector = selectorState } + } + + private fun resetTransactionSelector() { + setState { transactionSelector = null } + } + private fun everyoneIsWaitingForMe(): Boolean { val onlyMeInTheGame = props.players.count { it.isHuman } == 1 if (onlyMeInTheGame || props.preparedMove != null) { @@ -264,8 +291,6 @@ private val gameScene: RClass<GameSceneProps> = 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<String, CardBack?> = 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 } |