diff options
author | Joffrey Bion <joffrey.bion@gmail.com> | 2021-02-23 00:01:00 +0100 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@gmail.com> | 2021-02-23 18:38:24 +0100 |
commit | e2957be6c0f2dea09d0633cd7ee7549311b9b923 (patch) | |
tree | 97b3dcbf09501ac2bd00d9ac8e0a1f1f280ecf0a /sw-server/src | |
parent | Fix player re-order animation (diff) | |
download | seven-wonders-e2957be6c0f2dea09d0633cd7ee7549311b9b923.tar.gz seven-wonders-e2957be6c0f2dea09d0633cd7ee7549311b9b923.tar.bz2 seven-wonders-e2957be6c0f2dea09d0633cd7ee7549311b9b923.zip |
Funnel game events into a single client subscription
Diffstat (limited to 'sw-server/src')
-rw-r--r-- | sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt | 16 |
1 files changed, 10 insertions, 6 deletions
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 e4c1b39a..70fb3220 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 @@ -4,6 +4,8 @@ import io.micrometer.core.instrument.MeterRegistry import org.luxons.sevenwonders.engine.Game import org.luxons.sevenwonders.model.api.GameListEvent import org.luxons.sevenwonders.model.api.actions.PrepareMoveAction +import org.luxons.sevenwonders.model.api.events.GameEvent +import org.luxons.sevenwonders.model.api.events.wrap import org.luxons.sevenwonders.model.api.wrap import org.luxons.sevenwonders.model.cards.PreparedCard import org.luxons.sevenwonders.model.hideHandsAndWaitForReadiness @@ -102,7 +104,7 @@ class GameController( handleEndOfGame(game, player, lobby) } } else { - template.convertAndSendToUser(player.username, "/queue/game/preparedMove", action.move) + template.convertAndSendToUser(player.username, "/queue/game/events", GameEvent.MovePrepared(action.move).wrap()) } } } @@ -130,18 +132,20 @@ class GameController( } } - private fun sendPlayerReady(gameId: Long, player: Player) = - template.convertAndSend("/topic/game/$gameId/playerReady", player.username) + private fun sendPlayerReady(gameId: Long, player: Player) { + template.convertAndSend("/topic/game/$gameId/events", GameEvent.PlayerIsReady(player.username).wrap()) + } - private fun sendPreparedCard(gameId: Long, preparedCard: PreparedCard) = - template.convertAndSend("/topic/game/$gameId/prepared", preparedCard) + private fun sendPreparedCard(gameId: Long, preparedCard: PreparedCard) { + template.convertAndSend("/topic/game/$gameId/events", GameEvent.CardPrepared(preparedCard).wrap()) + } private fun sendTurnInfo(players: List<Player>, game: Game, hideHands: Boolean) { val turns = game.getCurrentTurnInfo() val turnsToSend = if (hideHands) turns.hideHandsAndWaitForReadiness() else turns for (turnInfo in turnsToSend) { val player = players[turnInfo.playerIndex] - template.convertAndSendToUser(player.username, "/queue/game/turn", turnInfo) + template.convertAndSendToUser(player.username, "/queue/game/events", GameEvent.NewTurnStarted(turnInfo).wrap()) } } |