Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /**
* Know Your World - Type Definitions
*
* This module uses Zod schemas as the single source of truth for types.
* TypeScript types are inferred from Zod schemas using z.infer<>.
*
* This enables:
* - Compile-time type checking (TypeScript)
* - Runtime validation (Zod) for client-server state sync
* - Automatic detection of schema mismatches when loading from database
*/
import { z } from 'zod'
// =============================================================================
// Shared Enums (Zod schemas that can be reused)
// =============================================================================
/**
* Assistance level - controls gameplay features (hints, hot/cold, etc.)
* Separate from region filtering
*/
export const AssistanceLevelSchema = z.enum(['learning', 'guided', 'helpful', 'standard', 'none'])
export type AssistanceLevel = z.infer<typeof AssistanceLevelSchema>
/**
* Region size categories for filtering
*/
export const RegionSizeSchema = z.enum(['huge', 'large', 'medium', 'small', 'tiny'])
export type RegionSize = z.infer<typeof RegionSizeSchema>
/**
* Continent identifiers for world map filtering
*/
export const ContinentIdSchema = z.enum([
'africa',
'asia',
'europe',
'north-america',
'south-america',
'oceania',
'antarctica',
])
export type ContinentId = z.infer<typeof ContinentIdSchema>
/**
* Map selection
*/
export const MapSelectionSchema = z.enum(['world', 'usa'])
export type MapSelection = z.infer<typeof MapSelectionSchema>
/**
* Game mode
*/
export const GameModeSchema = z.enum(['cooperative', 'race', 'turn-based'])
export type GameMode = z.infer<typeof GameModeSchema>
/**
* Game phase
*/
export const GamePhaseSchema = z.enum(['setup', 'playing', 'results'])
export type GamePhase = z.infer<typeof GamePhaseSchema>
// =============================================================================
// Game Configuration Schema
// =============================================================================
export const KnowYourWorldConfigSchema = z.object({
selectedMap: MapSelectionSchema,
gameMode: GameModeSchema,
includeSizes: z.array(RegionSizeSchema),
assistanceLevel: AssistanceLevelSchema,
difficulty: z.string().optional(), // @deprecated - kept for backwards compatibility
selectedContinent: z.union([ContinentIdSchema, z.literal('all')]),
studyDuration: z.number().optional(), // Duration in seconds for study mode
})
/**
* Game configuration type - inferred from Zod schema
* Compatible with GameConfig (Record<string, unknown>)
*/
export type KnowYourWorldConfig = z.infer<typeof KnowYourWorldConfigSchema>
// =============================================================================
// Map Data Structures
// =============================================================================
/**
* Basic region data from map
*/
export const MapRegionSchema = z.object({
id: z.string(),
name: z.string(),
path: z.string(),
center: z.tuple([z.number(), z.number()]), // SVG coordinates of region centroid
})
export type MapRegion = z.infer<typeof MapRegionSchema>
/**
* Hints mode for difficulty levels
*/
export const HintsModeSchema = z.enum(['onRequest', 'limited', 'none'])
export type HintsMode = z.infer<typeof HintsModeSchema>
/**
* Give up behavior mode
*/
export const GiveUpModeSchema = z.enum(['reaskSoon', 'reaskEnd', 'countsAgainst', 'skipEntirely'])
export type GiveUpMode = z.infer<typeof GiveUpModeSchema>
/**
* Difficulty level configuration
*/
export const DifficultyLevelSchema = z.object({
id: z.string(),
label: z.string(),
emoji: z.string().optional(),
description: z.string().optional(),
detailedDescription: z.string().optional(),
includeSizes: z.array(RegionSizeSchema).optional(),
excludeRegions: z.array(z.string()).optional(),
keepPercentile: z.number().optional(),
hotColdEnabled: z.boolean().optional(),
hintsMode: HintsModeSchema.optional(),
hintLimit: z.number().optional(),
autoHintDefault: z.boolean().optional(),
struggleHintEnabled: z.boolean().optional(),
giveUpMode: GiveUpModeSchema.optional(),
wrongClickShowsName: z.boolean().optional(),
})
export type DifficultyLevel = z.infer<typeof DifficultyLevelSchema>
/**
* Per-map difficulty configuration
*/
export const MapDifficultyConfigSchema = z.object({
levels: z.array(DifficultyLevelSchema),
defaultLevel: z.string(),
})
export type MapDifficultyConfig = z.infer<typeof MapDifficultyConfigSchema>
/**
* Map data structure containing all information about a map
*/
export const MapDataSchema = z.object({
id: z.string(),
name: z.string(),
viewBox: z.string(),
originalViewBox: z.string(),
customCrop: z.string().nullable(),
regions: z.array(MapRegionSchema),
difficultyConfig: MapDifficultyConfigSchema.optional(),
})
export type MapData = z.infer<typeof MapDataSchema>
// =============================================================================
// Game State Schema (synchronized across clients - NEEDS runtime validation)
// =============================================================================
/**
* Individual guess record
*/
export const GuessRecordSchema = z.object({
playerId: z.string(),
regionId: z.string(),
regionName: z.string(),
correct: z.boolean(),
attempts: z.number(),
timestamp: z.number(),
})
export type GuessRecord = z.infer<typeof GuessRecordSchema>
/**
* Give up reveal state (for animation)
*/
export const GiveUpRevealSchema = z
.object({
regionId: z.string(),
regionName: z.string(),
timestamp: z.number(),
})
.nullable()
/**
* Hint active state
*/
export const HintActiveSchema = z
.object({
regionId: z.string(),
timestamp: z.number(),
})
.nullable()
/**
* Player metadata schema - flexible record for player info
*/
export const PlayerMetadataSchema = z.record(z.string(), z.any())
/**
* Game state schema - the main synchronized state
* This is the single source of truth for what KnowYourWorldState contains
*/
export const KnowYourWorldStateSchema = z.object({
// Game phase
gamePhase: GamePhaseSchema,
// Setup configuration
selectedMap: MapSelectionSchema,
gameMode: GameModeSchema,
includeSizes: z.array(RegionSizeSchema),
assistanceLevel: AssistanceLevelSchema,
difficulty: z.string().optional(), // @deprecated
selectedContinent: z.union([ContinentIdSchema, z.literal('all')]),
// Game progression
currentPrompt: z.string().nullable(),
regionsToFind: z.array(z.string()),
regionsFound: z.array(z.string()),
regionsGivenUp: z.array(z.string()),
currentPlayer: z.string(),
// Scoring
scores: z.record(z.string(), z.number()),
attempts: z.record(z.string(), z.number()),
guessHistory: z.array(GuessRecordSchema),
// Timing
startTime: z.number(),
endTime: z.number().optional(),
// Multiplayer
activePlayers: z.array(z.string()),
activeUserIds: z.array(z.string()),
playerMetadata: PlayerMetadataSchema,
// Give up reveal state
giveUpReveal: GiveUpRevealSchema,
// Unanimous give-up voting
giveUpVotes: z.array(z.string()),
// Hint system
hintsUsed: z.number(),
hintActive: HintActiveSchema,
// Name confirmation progress (learning mode)
nameConfirmationProgress: z.number(),
})
/**
* Game state type - inferred from schema
* Use this type for compile-time checking
*/
export type KnowYourWorldState = z.infer<typeof KnowYourWorldStateSchema>
// =============================================================================
// Move Types (could also be validated, but less critical than state)
// =============================================================================
// For now, keep moves as TypeScript types. They could be converted to Zod later
// if we want to validate incoming moves on the server.
export type KnowYourWorldMove =
| {
type: 'START_GAME'
playerId: string
userId: string
timestamp: number
data: {
activePlayers: string[]
playerMetadata: Record<string, any>
selectedMap: 'world' | 'usa'
gameMode: 'cooperative' | 'race' | 'turn-based'
includeSizes: RegionSize[]
assistanceLevel: AssistanceLevel
}
}
| {
type: 'CLICK_REGION'
playerId: string
userId: string
timestamp: number
data: {
regionId: string
regionName: string
}
}
| {
type: 'NEXT_ROUND'
playerId: string
userId: string
timestamp: number
data: {}
}
| {
type: 'END_GAME'
playerId: string
userId: string
timestamp: number
data: {}
}
| {
type: 'SET_MAP'
playerId: string
userId: string
timestamp: number
data: {
selectedMap: 'world' | 'usa'
}
}
| {
type: 'SET_MODE'
playerId: string
userId: string
timestamp: number
data: {
gameMode: 'cooperative' | 'race' | 'turn-based'
}
}
| {
type: 'SET_REGION_SIZES'
playerId: string
userId: string
timestamp: number
data: {
includeSizes: RegionSize[]
}
}
| {
type: 'SET_ASSISTANCE_LEVEL'
playerId: string
userId: string
timestamp: number
data: {
assistanceLevel: AssistanceLevel
}
}
| {
type: 'RETURN_TO_SETUP'
playerId: string
userId: string
timestamp: number
data: {}
}
| {
type: 'SET_CONTINENT'
playerId: string
userId: string
timestamp: number
data: {
selectedContinent: ContinentId | 'all'
}
}
| {
type: 'GIVE_UP'
playerId: string
userId: string
timestamp: number
data: {}
}
| {
type: 'REQUEST_HINT'
playerId: string
userId: string
timestamp: number
data: {}
}
| {
type: 'CONFIRM_LETTER'
playerId: string
userId: string
timestamp: number
data: {
letter: string
letterIndex: number
}
}
| {
type: 'JOIN_GAME'
playerId: string
userId: string
timestamp: number
data: {
playerId: string
playerName: string
emoji: string
color: string
userId: string
}
}
|