From d85484516c4efcf89d21c74e4c87612c4bf079ad Mon Sep 17 00:00:00 2001 From: Danny Piper Date: Fri, 30 Aug 2024 14:27:13 +0200 Subject: [PATCH] feat: added all plays to initial load --- backend/gameLogic/game.go | 8 ++++++++ backend/network/connection.go | 1 + cahfrontend/src/gameState/gameState.ts | 9 +++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/gameLogic/game.go b/backend/gameLogic/game.go index fcdbf7a..e8d40f7 100644 --- a/backend/gameLogic/game.go +++ b/backend/gameLogic/game.go @@ -214,6 +214,8 @@ type GameStateInfo struct { Players []Player `json:"players"` GameOwnerId uuid.UUID `json:"gameOwnerId"` RoundInfo InitialRoundInfo `json:"roundInfo"` + // Only used when there it is in the judging round + AllPlays [][]*WhiteCard `json:"allPlays"` } // The state of a game for player who has just joined a game @@ -241,6 +243,7 @@ func (g *Game) StateInfo(pid uuid.UUID) GameStateInfo { YourPlays: make([]int, 0), } + allPlays := make([][]*WhiteCard, 0) for playerId, player := range g.PlayersMap { if pid == playerId { for _, card := range player.Hand { @@ -255,6 +258,10 @@ func (g *Game) StateInfo(pid uuid.UUID) GameStateInfo { if len(player.CurrentPlay) > 0 { initialRoundInfo.PlayersWhoHavePlayed = append(initialRoundInfo.PlayersWhoHavePlayed, playerId) } + + if g.GameState == GameStateCzarJudgingCards { + allPlays = append(allPlays, player.CurrentPlay) + } } return GameStateInfo{Id: g.Id, @@ -264,6 +271,7 @@ func (g *Game) StateInfo(pid uuid.UUID) GameStateInfo { Players: players, GameOwnerId: g.GameOwnerId, RoundInfo: initialRoundInfo, + AllPlays: allPlays, } } diff --git a/backend/network/connection.go b/backend/network/connection.go index e7571e4..1346520 100644 --- a/backend/network/connection.go +++ b/backend/network/connection.go @@ -156,6 +156,7 @@ func (c *WsConnection) listenAndHandle() error { logger.Logger.Error("Cannot encode the messages", "err", err) } + // TODO: do not block on this call - this will cause bugs GlobalConnectionManager.Broadcast(gid, message) // Send the initial state diff --git a/cahfrontend/src/gameState/gameState.ts b/cahfrontend/src/gameState/gameState.ts index a9c70c7..8e7e047 100644 --- a/cahfrontend/src/gameState/gameState.ts +++ b/cahfrontend/src/gameState/gameState.ts @@ -220,7 +220,7 @@ class GameState { this.onLobbyStateChange?.(this.lobbyState); - const roundState = { + const roundState: RpcRoundInformationMsg = { yourPlays: state.roundInfo.yourPlays.map( (x) => state.roundInfo.yourHand.find((y) => y?.id === x) ?? { @@ -240,6 +240,7 @@ class GameState { this.handleOnPlayerPlay({ playerId: pid }); }); this.onPlayerListChange?.(this.playerList()); + this.onAllPlaysChanged?.(state.allPlays as WhiteCard[][]); } public playerList(): GamePlayerList { @@ -465,14 +466,14 @@ class GameState { } public czarSelectCards(cards: number[]) { - console.log("Czar is selecting cards: ", cards) + console.log("Czar is selecting cards: ", cards); if (!this.wsClient) { throw new Error("Cannot play cards as websocket is not connected"); } const msg: RpcCzarSelectCardMsg = { - cards: cards - } + cards: cards, + }; this.wsClient.sendMessage( JSON.stringify(this.encodeMessage(MsgCzarSelectCard, msg)),