fix host dish visibility, show correct countries to host

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 11:18:58 +01:00
parent a587cd66c4
commit 2114084234
3 changed files with 14 additions and 6 deletions

View File

@@ -155,7 +155,7 @@ export class GameManager {
// ─── State for client ───────────────────────────────────────────
getGameStateForPlayer(playerId: string, playerLookup: Map<string, string>): GameState {
getGameStateForPlayer(playerId: string, playerLookup: Map<string, string>, isHost: boolean): GameState {
return {
lineup,
myPrediction: this.getPrediction(playerId),
@@ -163,7 +163,7 @@ export class GameManager {
dishes: this.dishes.map((d) => ({
id: d.id,
name: d.name,
correctCountry: d.revealed ? d.correctCountry : "",
correctCountry: d.revealed || isHost ? d.correctCountry : "",
revealed: d.revealed,
})),
myDishGuesses: this.getDishGuesses(playerId),

View File

@@ -47,7 +47,8 @@ function sendGameState(ws: WSContext, roomCode: string, sessionId: string) {
if (!gm || !playerId) return
const playerLookup = roomManager.getPlayerLookup(roomCode)
const gameState = gm.getGameStateForPlayer(playerId, playerLookup)
const isHost = roomManager.isHost(roomCode, sessionId)
const gameState = gm.getGameStateForPlayer(playerId, playerLookup, isHost)
sendTo(ws, { type: "game_state", gameState })
}

View File

@@ -136,7 +136,7 @@ describe("GameManager", () => {
it("hides correct country for unrevealed dishes", () => {
gm.addDish("Köttbullar", "SE")
const lookup = new Map<string, string>()
const state = gm.getGameStateForPlayer("p1", lookup)
const state = gm.getGameStateForPlayer("p1", lookup, false)
expect(state.dishes[0]?.correctCountry).toBe("")
})
@@ -144,7 +144,14 @@ describe("GameManager", () => {
gm.addDish("Köttbullar", "SE")
gm.revealDishes()
const lookup = new Map<string, string>()
const state = gm.getGameStateForPlayer("p1", lookup)
const state = gm.getGameStateForPlayer("p1", lookup, false)
expect(state.dishes[0]?.correctCountry).toBe("SE")
})
it("shows correct country to host for unrevealed dishes", () => {
gm.addDish("Köttbullar", "SE")
const lookup = new Map<string, string>()
const state = gm.getGameStateForPlayer("p1", lookup, true)
expect(state.dishes[0]?.correctCountry).toBe("SE")
})
@@ -152,7 +159,7 @@ describe("GameManager", () => {
gm.submitPrediction("p1", "SE", ["DE", "IT", "FR"], "GB")
gm.submitPrediction("p2", "NO", ["DE", "IT", "FR"], "GB")
const lookup = new Map<string, string>()
const state = gm.getGameStateForPlayer("p1", lookup)
const state = gm.getGameStateForPlayer("p1", lookup, false)
expect(state.myPrediction?.predictedWinner).toBe("SE")
})
})