diff options
6 files changed, 30 insertions, 5 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 ea449a85..5476a890 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 @@ -129,4 +129,8 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat serializer = PrepareMoveAction.serializer(), deserializer = PlayerMove.serializer() ) + + suspend fun unprepareMove() { + stompSession.sendEmptyMsg("/app/game/unprepareMove") + } } diff --git a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt index 24c640b2..6b7e1fe0 100644 --- a/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt +++ b/sw-common-model/src/commonMain/kotlin/org/luxons/sevenwonders/model/cards/Cards.kt @@ -46,7 +46,7 @@ data class HandCard( @Serializable data class PreparedCard( val player: PlayerDTO, - val cardBack: CardBack + val cardBack: CardBack? ) @Serializable diff --git a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt index 5a75516c..25f1de6d 100644 --- a/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt +++ b/sw-engine/src/main/kotlin/org/luxons/sevenwonders/engine/Game.kt @@ -93,6 +93,10 @@ class Game internal constructor( return card.back } + fun unprepareMove(playerIndex: Int) { + preparedMoves.remove(playerIndex) + } + /** * Returns true if all players that had to do something have [prepared their move][prepareMove]. This means we are * ready to [play the current turn][playTurn]. 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 5fd5f2e4..32359d58 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 @@ -80,6 +80,16 @@ class GameController @Autowired constructor( return action.move } + @MessageMapping("/game/unprepareMove") + fun unprepareMove(principal: Principal) { + val player = principal.player + val game = player.game + game.unprepareMove(player.index) + val preparedCard = PreparedCard(player.toDTO(), null) + logger.info("Game {}: player {} unprepared his move", game.id, principal.name) + sendPreparedCard(game.id, preparedCard) + } + private fun sendPlayerReady(gameId: Long, player: Player) = template.convertAndSend("/topic/game/$gameId/playerReady", "\"${player.username}\"") 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 |