Skip to content

Commit

Permalink
fix: inc points in the UI after scoring
Browse files Browse the repository at this point in the history
  • Loading branch information
djpiper28 committed Aug 30, 2024
1 parent d1ce708 commit 78409a9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backend/network/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -320,7 +321,7 @@ func (c *WsConnection) listenAndHandle() error {
}

wg.Wait()
return nil
return nil
},
})

Expand Down
1 change: 1 addition & 0 deletions backend/network/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
12 changes: 12 additions & 0 deletions cahfrontend/src/gameState/gameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 78409a9

Please sign in to comment.