From 78409a91999395456aa83b65d1f86906328bb84f Mon Sep 17 00:00:00 2001 From: Danny Piper Date: Fri, 30 Aug 2024 20:32:53 +0200 Subject: [PATCH] fix: inc points in the UI after scoring --- backend/network/connection.go | 5 +++-- backend/network/rpc.go | 1 + cahfrontend/src/gameState/gameState.ts | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/network/connection.go b/backend/network/connection.go index 11dffb0..173fc30 100644 --- a/backend/network/connection.go +++ b/backend/network/connection.go @@ -309,7 +309,8 @@ func (c *WsConnection) listenAndHandle() error { defer wg.Done() msg := RpcOnWhiteCardPlayPhase{YourHand: hand, BlackCard: res.NewBlackCard, - CardCzarId: res.NewCzarId} + CardCzarId: res.NewCzarId, + WinnerId: res.WinnerId} encodedMsg, err := EncodeRpcMessage(msg) if err != nil { logger.Logger.Error("Cannot encode message to send to player") @@ -320,7 +321,7 @@ func (c *WsConnection) listenAndHandle() error { } wg.Wait() - return nil + return nil }, }) diff --git a/backend/network/rpc.go b/backend/network/rpc.go index c4e8392..e967987 100644 --- a/backend/network/rpc.go +++ b/backend/network/rpc.go @@ -268,6 +268,7 @@ func (msg RpcCzarSelectCardMsg) Type() RpcMessageType { type RpcOnWhiteCardPlayPhase struct { BlackCard *gameLogic.BlackCard `json:"blackCard"` YourHand []*gameLogic.WhiteCard `json:"yourHand"` + WinnerId uuid.UUID `json:"winnerId"` CardCzarId uuid.UUID `json:"cardCzarId"` } diff --git a/cahfrontend/src/gameState/gameState.ts b/cahfrontend/src/gameState/gameState.ts index 0911cd0..3556fde 100644 --- a/cahfrontend/src/gameState/gameState.ts +++ b/cahfrontend/src/gameState/gameState.ts @@ -359,6 +359,18 @@ class GameState { this.roundState.yourHand = msg.yourHand as WhiteCard[]; this.roundState.currentCardCzarId = msg.cardCzarId; this.onRoundStateChange?.(structuredClone(this.roundState)); + + this.players = this.players.map((player) => { + if (player.id === msg.winnerId) { + return { + ...player, + points: player.points + 1, + }; + } + + return player; + }); + this.onPlayerListChange?.(this.players); } /**