summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-04-01 23:16:45 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-04-01 23:16:45 +0200
commit607466dd5e9940b4d73246c9bfcdeccec90d665c (patch)
treed4fa77275bfc97618eb19bc7733c24a6f5b263b4
parentRemove manual LinearDimension invocation (diff)
downloadseven-wonders-607466dd5e9940b4d73246c9bfcdeccec90d665c.tar.gz
seven-wonders-607466dd5e9940b4d73246c9bfcdeccec90d665c.tar.bz2
seven-wonders-607466dd5e9940b4d73246c9bfcdeccec90d665c.zip
Hide currently prepared card from hand
-rw-r--r--sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt11
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt8
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt11
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt10
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt3
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Reducers.kt12
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt8
7 files changed, 44 insertions, 19 deletions
diff --git a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt
index d72d353b..ea449a85 100644
--- a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt
+++ b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt
@@ -10,7 +10,6 @@ import org.hildan.krossbow.stomp.conversions.kxserialization.StompSessionWithKxS
import org.hildan.krossbow.stomp.conversions.kxserialization.convertAndSend
import org.hildan.krossbow.stomp.conversions.kxserialization.withJsonConversions
import org.hildan.krossbow.stomp.sendEmptyMsg
-import org.hildan.krossbow.stomp.subscribeEmptyMsg
import org.luxons.sevenwonders.model.CustomizableSettings
import org.luxons.sevenwonders.model.PlayerMove
import org.luxons.sevenwonders.model.PlayerTurnInfo
@@ -123,7 +122,11 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat
stompSession.sendEmptyMsg("/app/game/sayReady")
}
- suspend fun prepareMove(move: PlayerMove) {
- stompSession.convertAndSend("/app/game/prepareMove", PrepareMoveAction(move), PrepareMoveAction.serializer())
- }
+ suspend fun prepareMove(move: PlayerMove): PlayerMove = stompSession.request(
+ sendDestination = "/app/game/prepareMove",
+ receiveDestination = "/user/queue/game/preparedMove",
+ payload = PrepareMoveAction(move),
+ serializer = PrepareMoveAction.serializer(),
+ deserializer = PlayerMove.serializer()
+ )
}
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt
index 733259b9..5fd5f2e4 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt
@@ -2,8 +2,7 @@ package org.luxons.sevenwonders.server.controllers
import org.hildan.livedoc.core.annotations.Api
import org.luxons.sevenwonders.engine.Game
-import org.luxons.sevenwonders.model.Action
-import org.luxons.sevenwonders.model.PlayerTurnInfo
+import org.luxons.sevenwonders.model.PlayerMove
import org.luxons.sevenwonders.model.api.actions.PrepareMoveAction
import org.luxons.sevenwonders.model.cards.PreparedCard
import org.luxons.sevenwonders.model.hideHandsAndWaitForReadiness
@@ -14,6 +13,7 @@ import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.messaging.handler.annotation.MessageMapping
import org.springframework.messaging.simp.SimpMessagingTemplate
+import org.springframework.messaging.simp.annotation.SendToUser
import org.springframework.stereotype.Controller
import java.security.Principal
@@ -63,7 +63,8 @@ class GameController @Autowired constructor(
* the connected user's information
*/
@MessageMapping("/game/prepareMove")
- fun prepareMove(action: PrepareMoveAction, principal: Principal) {
+ @SendToUser("/queue/game/preparedMove")
+ fun prepareMove(action: PrepareMoveAction, principal: Principal): PlayerMove {
val player = principal.player
val game = player.game
val preparedCardBack = game.prepareMove(player.index, action.move)
@@ -76,6 +77,7 @@ class GameController @Autowired constructor(
game.playTurn()
sendTurnInfo(player.lobby.getPlayers(), game, true)
}
+ return action.move
}
private fun sendPlayerReady(gameId: Long, player: Player) =
diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt
index fecb8be2..48c993fc 100644
--- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt
+++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt
@@ -25,10 +25,10 @@ import org.luxons.sevenwonders.model.Action
import org.luxons.sevenwonders.model.PlayerMove
import org.luxons.sevenwonders.model.PlayerTurnInfo
import org.luxons.sevenwonders.model.api.PlayerDTO
+import org.luxons.sevenwonders.ui.redux.GameState
import org.luxons.sevenwonders.ui.redux.RequestPrepareMove
import org.luxons.sevenwonders.ui.redux.RequestSayReady
import org.luxons.sevenwonders.ui.redux.connectStateAndDispatch
-import org.luxons.sevenwonders.ui.utils.createElement
import react.RBuilder
import react.RClass
import react.RComponent
@@ -43,7 +43,8 @@ import styled.styledDiv
interface GameSceneStateProps: RProps {
var playerIsReady: Boolean
var players: List<PlayerDTO>
- var turnInfo: PlayerTurnInfo?
+ var gameState: GameState?
+ var preparedMove: PlayerMove?
}
interface GameSceneDispatchProps: RProps {
@@ -62,7 +63,7 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta
backgroundSize = "cover"
fullScreen()
}
- val turnInfo = props.turnInfo
+ val turnInfo = props.gameState?.turnInfo
if (turnInfo == null) {
p { +"Error: no turn info data"}
} else {
@@ -109,6 +110,7 @@ private class GameScene(props: GameSceneProps) : RComponent<GameSceneProps, RSta
handComponent(
cards = hand,
wonderUpgradable = turnInfo.wonderBuildability.isBuildable,
+ preparedMove = props.preparedMove,
prepareMove = props.prepareMove
)
}
@@ -139,7 +141,8 @@ private val gameScene: RClass<GameSceneProps> = connectStateAndDispatch<GameScen
mapStateToProps = { state, _ ->
playerIsReady = state.currentPlayer?.isReady == true
players = state.gameState?.players ?: emptyList()
- turnInfo = state.gameState?.turnInfo
+ gameState = state.gameState
+ preparedMove = state.gameState?.currentPreparedMove
}
)
diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt
index 9aac310a..985b3deb 100644
--- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt
+++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Hand.kt
@@ -38,6 +38,7 @@ import kotlinx.html.DIV
import org.luxons.sevenwonders.model.MoveType
import org.luxons.sevenwonders.model.PlayerMove
import org.luxons.sevenwonders.model.cards.HandCard
+import org.luxons.sevenwonders.model.cards.PreparedCard
import org.luxons.sevenwonders.ui.components.game.cardImage
import react.RBuilder
import styled.StyledDOMBuilder
@@ -47,14 +48,19 @@ import styled.styledDiv
fun RBuilder.handComponent(
cards: List<HandCard>,
wonderUpgradable: Boolean,
+ preparedMove: PlayerMove?,
prepareMove: (PlayerMove) -> Unit
) {
styledDiv {
css {
handStyle()
}
- cards.forEachIndexed { index, c ->
- handCard(card = c, wonderUpgradable = wonderUpgradable, prepareMove = prepareMove) {
+ cards.filter { it.name != preparedMove?.cardName }.forEachIndexed { index, c ->
+ handCard(
+ card = c,
+ wonderUpgradable = wonderUpgradable,
+ prepareMove = prepareMove
+ ) {
attrs {
key = index.toString()
}
diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt
index 85b48e61..3e3de561 100644
--- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt
+++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/Actions.kt
@@ -1,5 +1,6 @@
package org.luxons.sevenwonders.ui.redux
+import org.luxons.sevenwonders.model.PlayerMove
import org.luxons.sevenwonders.model.PlayerTurnInfo
import org.luxons.sevenwonders.model.api.ConnectedPlayer
import org.luxons.sevenwonders.model.api.LobbyDTO
@@ -18,6 +19,8 @@ data class EnterGameAction(val lobby: LobbyDTO, val turnInfo: PlayerTurnInfo): R
data class TurnInfoEvent(val turnInfo: PlayerTurnInfo): RAction
+data class PreparedMoveEvent(val move: PlayerMove): RAction
+
data class PreparedCardEvent(val card: PreparedCard): RAction
data class PlayerReadyEvent(val username: String): 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 f7c27eda..a9b595da 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
@@ -1,5 +1,6 @@
package org.luxons.sevenwonders.ui.redux
+import org.luxons.sevenwonders.model.PlayerMove
import org.luxons.sevenwonders.model.PlayerTurnInfo
import org.luxons.sevenwonders.model.api.ConnectedPlayer
import org.luxons.sevenwonders.model.api.LobbyDTO
@@ -24,15 +25,16 @@ data class SwState(
data class GameState(
val id: Long,
val players: List<PlayerDTO>,
- val preparedCardsByUsername: Map<String, PreparedCard>,
- val turnInfo: PlayerTurnInfo?
+ val turnInfo: PlayerTurnInfo?,
+ val preparedCardsByUsername: Map<String, PreparedCard> = emptyMap(),
+ val currentPreparedMove: PlayerMove? = null
)
fun rootReducer(state: SwState, action: RAction): SwState = state.copy(
gamesById = gamesReducer(state.gamesById, action),
connectedPlayer = currentPlayerReducer(state.connectedPlayer, action),
currentLobby = currentLobbyReducer(state.currentLobby, action),
- gameState = currentTurnInfoReducer(state.gameState, action)
+ gameState = gameStateReducer(state.gameState, action)
)
private fun gamesReducer(games: Map<Long, LobbyDTO>, action: RAction): Map<Long, LobbyDTO> = when (action) {
@@ -56,13 +58,13 @@ private fun currentLobbyReducer(currentLobby: LobbyDTO?, action: RAction): Lobby
else -> currentLobby
}
-private fun currentTurnInfoReducer(gameState: GameState?, action: RAction): GameState? = when (action) {
+private fun gameStateReducer(gameState: GameState?, action: RAction): GameState? = when (action) {
is EnterGameAction -> GameState(
id = action.lobby.id,
players = action.lobby.players,
- preparedCardsByUsername = emptyMap(),
turnInfo = action.turnInfo
)
+ is PreparedMoveEvent -> gameState?.copy(currentPreparedMove = action.move)
is PreparedCardEvent -> gameState?.copy(
preparedCardsByUsername = gameState.preparedCardsByUsername + (action.card.player.username to action.card)
)
diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt
index e2c2d4d1..c1788c98 100644
--- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt
+++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt
@@ -5,6 +5,7 @@ import kotlinx.coroutines.launch
import org.luxons.sevenwonders.client.SevenWondersSession
import org.luxons.sevenwonders.ui.redux.PlayerReadyEvent
import org.luxons.sevenwonders.ui.redux.PreparedCardEvent
+import org.luxons.sevenwonders.ui.redux.PreparedMoveEvent
import org.luxons.sevenwonders.ui.redux.RequestPrepareMove
import org.luxons.sevenwonders.ui.redux.RequestSayReady
import org.luxons.sevenwonders.ui.redux.TurnInfoEvent
@@ -16,7 +17,12 @@ suspend fun SwSagaContext.gameSaga(session: SevenWondersSession) {
val preparedCardsSub = session.watchPreparedCards(game.id)
val turnInfoSub = session.watchTurns()
val sayReadyJob = launch { onEach<RequestSayReady> { session.sayReady() } }
- val prepareMoveJob = launch { onEach<RequestPrepareMove> { session.prepareMove(it.move) } }
+ val prepareMoveJob = launch {
+ onEach<RequestPrepareMove> {
+ val move = session.prepareMove(it.move)
+ dispatch(PreparedMoveEvent(move))
+ }
+ }
launch { dispatchAll(playerReadySub.messages) { PlayerReadyEvent(it) } }
launch { dispatchAll(preparedCardsSub.messages) { PreparedCardEvent(it) } }
launch { dispatchAll(turnInfoSub.messages) { TurnInfoEvent(it) } }
bgstack15