fix(card-sorting): add missing gameMode support after hard reset

After reverting cursor tracking commits, the gameMode type system remained
but implementation was incomplete, causing TypeScript errors. This adds the
missing gameMode handling throughout the codebase.

Changes:
- Add gameMode to createInitialState (Provider and Validator)
- Add gameMode to setConfig type signature and implementation
- Add gameMode validation case in validateSetConfig
- Include gameMode in originalConfig for pause/resume
- Initialize activePlayers, allPlayerMetadata, cursorPositions as empty

Fixes TypeScript errors:
- "Property 'gameMode' is missing" in Provider and Validator
- "Argument of type 'gameMode' not assignable" in SetupPhase

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Thomas Hallock 2025-10-23 17:13:45 -05:00
parent d25b888ffb
commit a832325deb
2 changed files with 34 additions and 2 deletions

View File

@ -28,7 +28,7 @@ interface CardSortingContextValue {
revealNumbers: () => void
goToSetup: () => void
resumeGame: () => void
setConfig: (field: 'cardCount' | 'showNumbers' | 'timeLimit', value: unknown) => void
setConfig: (field: 'cardCount' | 'showNumbers' | 'timeLimit' | 'gameMode', value: unknown) => void
updateCardPositions: (positions: CardPosition[]) => void
exitSession: () => void
// Computed
@ -55,6 +55,7 @@ const createInitialState = (config: Partial<CardSortingConfig>): CardSortingStat
cardCount: config.cardCount ?? 8,
showNumbers: config.showNumbers ?? true,
timeLimit: config.timeLimit ?? null,
gameMode: config.gameMode ?? 'solo',
gamePhase: 'setup',
playerId: '',
playerMetadata: {
@ -63,6 +64,8 @@ const createInitialState = (config: Partial<CardSortingConfig>): CardSortingStat
emoji: '',
userId: '',
},
activePlayers: [],
allPlayerMetadata: new Map(),
gameStartTime: null,
gameEndTime: null,
selectedCards: [],
@ -70,6 +73,7 @@ const createInitialState = (config: Partial<CardSortingConfig>): CardSortingStat
availableCards: [],
placedCards: new Array(config.cardCount ?? 8).fill(null),
cardPositions: [],
cursorPositions: new Map(),
selectedCardId: null,
numbersRevealed: false,
scoreBreakdown: null,
@ -91,6 +95,8 @@ function applyMoveOptimistically(state: CardSortingState, move: GameMove): CardS
gamePhase: 'playing',
playerId: typedMove.playerId,
playerMetadata: typedMove.data.playerMetadata,
activePlayers: [typedMove.playerId],
allPlayerMetadata: new Map([[typedMove.playerId, typedMove.data.playerMetadata]]),
gameStartTime: Date.now(),
selectedCards,
correctOrder,
@ -103,6 +109,7 @@ function applyMoveOptimistically(state: CardSortingState, move: GameMove): CardS
cardCount: state.cardCount,
showNumbers: state.showNumbers,
timeLimit: state.timeLimit,
gameMode: state.gameMode,
},
pausedGamePhase: undefined,
pausedGameState: undefined,
@ -535,7 +542,7 @@ export function CardSortingProvider({ children }: { children: ReactNode }) {
}, [localPlayerId, canResumeGame, sendMove, viewerId])
const setConfig = useCallback(
(field: 'cardCount' | 'showNumbers' | 'timeLimit', value: unknown) => {
(field: 'cardCount' | 'showNumbers' | 'timeLimit' | 'gameMode', value: unknown) => {
if (!localPlayerId) return
sendMove({

View File

@ -323,11 +323,13 @@ export class CardSortingValidator implements GameValidator<CardSortingState, Car
cardCount: state.cardCount,
showNumbers: state.showNumbers,
timeLimit: state.timeLimit,
gameMode: state.gameMode,
}),
originalConfig: {
cardCount: state.cardCount,
showNumbers: state.showNumbers,
timeLimit: state.timeLimit,
gameMode: state.gameMode,
},
pausedGamePhase: 'playing',
pausedGameState: {
@ -349,6 +351,7 @@ export class CardSortingValidator implements GameValidator<CardSortingState, Car
cardCount: state.cardCount,
showNumbers: state.showNumbers,
timeLimit: state.timeLimit,
gameMode: state.gameMode,
}),
}
}
@ -414,6 +417,24 @@ export class CardSortingValidator implements GameValidator<CardSortingState, Car
},
}
case 'gameMode':
if (!['solo', 'collaborative', 'competitive', 'relay'].includes(value as string)) {
return {
valid: false,
error: 'gameMode must be solo, collaborative, competitive, or relay',
}
}
return {
valid: true,
newState: {
...state,
gameMode: value as 'solo' | 'collaborative' | 'competitive' | 'relay',
// Clear pause state if config changed
pausedGamePhase: undefined,
pausedGameState: undefined,
},
}
default:
return { valid: false, error: `Unknown config field: ${field}` }
}
@ -500,6 +521,7 @@ export class CardSortingValidator implements GameValidator<CardSortingState, Car
cardCount: config.cardCount,
showNumbers: config.showNumbers,
timeLimit: config.timeLimit,
gameMode: config.gameMode,
gamePhase: 'setup',
playerId: '',
playerMetadata: {
@ -508,6 +530,8 @@ export class CardSortingValidator implements GameValidator<CardSortingState, Car
emoji: '',
userId: '',
},
activePlayers: [],
allPlayerMetadata: new Map(),
gameStartTime: null,
gameEndTime: null,
selectedCards: [],
@ -515,6 +539,7 @@ export class CardSortingValidator implements GameValidator<CardSortingState, Car
availableCards: [],
placedCards: new Array(config.cardCount).fill(null),
cardPositions: [],
cursorPositions: new Map(),
selectedCardId: null,
numbersRevealed: false,
scoreBreakdown: null,