Skip to content

Commit

Permalink
feat: added all plays to initial load
Browse files Browse the repository at this point in the history
  • Loading branch information
djpiper28 committed Aug 30, 2024
1 parent c2e3b7a commit d854845
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 8 additions & 0 deletions backend/gameLogic/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -264,6 +271,7 @@ func (g *Game) StateInfo(pid uuid.UUID) GameStateInfo {
Players: players,
GameOwnerId: g.GameOwnerId,
RoundInfo: initialRoundInfo,
AllPlays: allPlays,
}
}

Expand Down
1 change: 1 addition & 0 deletions backend/network/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions cahfrontend/src/gameState/gameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?? {
Expand All @@ -240,6 +240,7 @@ class GameState {
this.handleOnPlayerPlay({ playerId: pid });
});
this.onPlayerListChange?.(this.playerList());
this.onAllPlaysChanged?.(state.allPlays as WhiteCard[][]);
}

public playerList(): GamePlayerList {
Expand Down Expand Up @@ -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)),
Expand Down

0 comments on commit d854845

Please sign in to comment.