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:
@@ -28,7 +28,7 @@ interface CardSortingContextValue {
|
|||||||
revealNumbers: () => void
|
revealNumbers: () => void
|
||||||
goToSetup: () => void
|
goToSetup: () => void
|
||||||
resumeGame: () => void
|
resumeGame: () => void
|
||||||
setConfig: (field: 'cardCount' | 'showNumbers' | 'timeLimit', value: unknown) => void
|
setConfig: (field: 'cardCount' | 'showNumbers' | 'timeLimit' | 'gameMode', value: unknown) => void
|
||||||
updateCardPositions: (positions: CardPosition[]) => void
|
updateCardPositions: (positions: CardPosition[]) => void
|
||||||
exitSession: () => void
|
exitSession: () => void
|
||||||
// Computed
|
// Computed
|
||||||
@@ -55,6 +55,7 @@ const createInitialState = (config: Partial<CardSortingConfig>): CardSortingStat
|
|||||||
cardCount: config.cardCount ?? 8,
|
cardCount: config.cardCount ?? 8,
|
||||||
showNumbers: config.showNumbers ?? true,
|
showNumbers: config.showNumbers ?? true,
|
||||||
timeLimit: config.timeLimit ?? null,
|
timeLimit: config.timeLimit ?? null,
|
||||||
|
gameMode: config.gameMode ?? 'solo',
|
||||||
gamePhase: 'setup',
|
gamePhase: 'setup',
|
||||||
playerId: '',
|
playerId: '',
|
||||||
playerMetadata: {
|
playerMetadata: {
|
||||||
@@ -63,6 +64,8 @@ const createInitialState = (config: Partial<CardSortingConfig>): CardSortingStat
|
|||||||
emoji: '',
|
emoji: '',
|
||||||
userId: '',
|
userId: '',
|
||||||
},
|
},
|
||||||
|
activePlayers: [],
|
||||||
|
allPlayerMetadata: new Map(),
|
||||||
gameStartTime: null,
|
gameStartTime: null,
|
||||||
gameEndTime: null,
|
gameEndTime: null,
|
||||||
selectedCards: [],
|
selectedCards: [],
|
||||||
@@ -70,6 +73,7 @@ const createInitialState = (config: Partial<CardSortingConfig>): CardSortingStat
|
|||||||
availableCards: [],
|
availableCards: [],
|
||||||
placedCards: new Array(config.cardCount ?? 8).fill(null),
|
placedCards: new Array(config.cardCount ?? 8).fill(null),
|
||||||
cardPositions: [],
|
cardPositions: [],
|
||||||
|
cursorPositions: new Map(),
|
||||||
selectedCardId: null,
|
selectedCardId: null,
|
||||||
numbersRevealed: false,
|
numbersRevealed: false,
|
||||||
scoreBreakdown: null,
|
scoreBreakdown: null,
|
||||||
@@ -91,6 +95,8 @@ function applyMoveOptimistically(state: CardSortingState, move: GameMove): CardS
|
|||||||
gamePhase: 'playing',
|
gamePhase: 'playing',
|
||||||
playerId: typedMove.playerId,
|
playerId: typedMove.playerId,
|
||||||
playerMetadata: typedMove.data.playerMetadata,
|
playerMetadata: typedMove.data.playerMetadata,
|
||||||
|
activePlayers: [typedMove.playerId],
|
||||||
|
allPlayerMetadata: new Map([[typedMove.playerId, typedMove.data.playerMetadata]]),
|
||||||
gameStartTime: Date.now(),
|
gameStartTime: Date.now(),
|
||||||
selectedCards,
|
selectedCards,
|
||||||
correctOrder,
|
correctOrder,
|
||||||
@@ -103,6 +109,7 @@ function applyMoveOptimistically(state: CardSortingState, move: GameMove): CardS
|
|||||||
cardCount: state.cardCount,
|
cardCount: state.cardCount,
|
||||||
showNumbers: state.showNumbers,
|
showNumbers: state.showNumbers,
|
||||||
timeLimit: state.timeLimit,
|
timeLimit: state.timeLimit,
|
||||||
|
gameMode: state.gameMode,
|
||||||
},
|
},
|
||||||
pausedGamePhase: undefined,
|
pausedGamePhase: undefined,
|
||||||
pausedGameState: undefined,
|
pausedGameState: undefined,
|
||||||
@@ -535,7 +542,7 @@ export function CardSortingProvider({ children }: { children: ReactNode }) {
|
|||||||
}, [localPlayerId, canResumeGame, sendMove, viewerId])
|
}, [localPlayerId, canResumeGame, sendMove, viewerId])
|
||||||
|
|
||||||
const setConfig = useCallback(
|
const setConfig = useCallback(
|
||||||
(field: 'cardCount' | 'showNumbers' | 'timeLimit', value: unknown) => {
|
(field: 'cardCount' | 'showNumbers' | 'timeLimit' | 'gameMode', value: unknown) => {
|
||||||
if (!localPlayerId) return
|
if (!localPlayerId) return
|
||||||
|
|
||||||
sendMove({
|
sendMove({
|
||||||
|
|||||||
@@ -323,11 +323,13 @@ export class CardSortingValidator implements GameValidator<CardSortingState, Car
|
|||||||
cardCount: state.cardCount,
|
cardCount: state.cardCount,
|
||||||
showNumbers: state.showNumbers,
|
showNumbers: state.showNumbers,
|
||||||
timeLimit: state.timeLimit,
|
timeLimit: state.timeLimit,
|
||||||
|
gameMode: state.gameMode,
|
||||||
}),
|
}),
|
||||||
originalConfig: {
|
originalConfig: {
|
||||||
cardCount: state.cardCount,
|
cardCount: state.cardCount,
|
||||||
showNumbers: state.showNumbers,
|
showNumbers: state.showNumbers,
|
||||||
timeLimit: state.timeLimit,
|
timeLimit: state.timeLimit,
|
||||||
|
gameMode: state.gameMode,
|
||||||
},
|
},
|
||||||
pausedGamePhase: 'playing',
|
pausedGamePhase: 'playing',
|
||||||
pausedGameState: {
|
pausedGameState: {
|
||||||
@@ -349,6 +351,7 @@ export class CardSortingValidator implements GameValidator<CardSortingState, Car
|
|||||||
cardCount: state.cardCount,
|
cardCount: state.cardCount,
|
||||||
showNumbers: state.showNumbers,
|
showNumbers: state.showNumbers,
|
||||||
timeLimit: state.timeLimit,
|
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:
|
default:
|
||||||
return { valid: false, error: `Unknown config field: ${field}` }
|
return { valid: false, error: `Unknown config field: ${field}` }
|
||||||
}
|
}
|
||||||
@@ -500,6 +521,7 @@ export class CardSortingValidator implements GameValidator<CardSortingState, Car
|
|||||||
cardCount: config.cardCount,
|
cardCount: config.cardCount,
|
||||||
showNumbers: config.showNumbers,
|
showNumbers: config.showNumbers,
|
||||||
timeLimit: config.timeLimit,
|
timeLimit: config.timeLimit,
|
||||||
|
gameMode: config.gameMode,
|
||||||
gamePhase: 'setup',
|
gamePhase: 'setup',
|
||||||
playerId: '',
|
playerId: '',
|
||||||
playerMetadata: {
|
playerMetadata: {
|
||||||
@@ -508,6 +530,8 @@ export class CardSortingValidator implements GameValidator<CardSortingState, Car
|
|||||||
emoji: '',
|
emoji: '',
|
||||||
userId: '',
|
userId: '',
|
||||||
},
|
},
|
||||||
|
activePlayers: [],
|
||||||
|
allPlayerMetadata: new Map(),
|
||||||
gameStartTime: null,
|
gameStartTime: null,
|
||||||
gameEndTime: null,
|
gameEndTime: null,
|
||||||
selectedCards: [],
|
selectedCards: [],
|
||||||
@@ -515,6 +539,7 @@ export class CardSortingValidator implements GameValidator<CardSortingState, Car
|
|||||||
availableCards: [],
|
availableCards: [],
|
||||||
placedCards: new Array(config.cardCount).fill(null),
|
placedCards: new Array(config.cardCount).fill(null),
|
||||||
cardPositions: [],
|
cardPositions: [],
|
||||||
|
cursorPositions: new Map(),
|
||||||
selectedCardId: null,
|
selectedCardId: null,
|
||||||
numbersRevealed: false,
|
numbersRevealed: false,
|
||||||
scoreBreakdown: null,
|
scoreBreakdown: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user