From e2957be6c0f2dea09d0633cd7ee7549311b9b923 Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Tue, 23 Feb 2021 00:01:00 +0100 Subject: Funnel game events into a single client subscription --- .../sevenwonders/server/controllers/GameController.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'sw-server/src') 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, 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()) } } -- cgit