add shared game types for predictions, dishes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 11:10:24 +01:00
parent e619a5f1a9
commit 4ee2252dde
2 changed files with 76 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
import { z } from "zod"
// ─── Country Lineup ─────────────────────────────────────────────────
export const countrySchema = z.object({
code: z.string(),
name: z.string(),
})
export type Country = z.infer<typeof countrySchema>
export const lineupSchema = z.object({
year: z.number(),
countries: z.array(countrySchema),
})
export type Lineup = z.infer<typeof lineupSchema>
// ─── Predictions ────────────────────────────────────────────────────
export const predictionSchema = z.object({
playerId: z.string().uuid(),
predictedWinner: z.string(),
top3: z.array(z.string()).length(3),
nulPointsPick: z.string(),
})
export type Prediction = z.infer<typeof predictionSchema>
// ─── Dishes ─────────────────────────────────────────────────────────
export const dishSchema = z.object({
id: z.string().uuid(),
name: z.string(),
correctCountry: z.string(),
revealed: z.boolean(),
})
export type Dish = z.infer<typeof dishSchema>
export const dishGuessSchema = z.object({
dishId: z.string().uuid(),
playerId: z.string().uuid(),
guessedCountry: z.string(),
})
export type DishGuess = z.infer<typeof dishGuessSchema>
// ─── Game State (sent to clients) ───────────────────────────────────
/** State slice sent to each player — they only see their own prediction */
export const gameStateSchema = z.object({
lineup: lineupSchema,
myPrediction: predictionSchema.nullable(),
predictionsLocked: z.boolean(),
dishes: z.array(dishSchema),
myDishGuesses: z.array(dishGuessSchema),
dishResults: z
.array(
z.object({
dish: dishSchema,
guesses: z.array(
z.object({
playerId: z.string().uuid(),
displayName: z.string(),
guessedCountry: z.string(),
correct: z.boolean(),
}),
),
}),
)
.nullable(),
})
export type GameState = z.infer<typeof gameStateSchema>

View File

@@ -1,3 +1,4 @@
export * from "./constants"
export * from "./game-types"
export * from "./room-types"
export * from "./ws-messages"