Frontend alignment with backend WebSocket protocol: **Type System Fixes**: - types/game.ts: Changed DecisionPhase to use 'awaiting_*' convention matching backend - types/game.ts: Fixed PlayOutcome enum values to match backend string values (e.g., 'strikeout' not 'STRIKEOUT') - types/game.ts: Added comprehensive play outcome types (groundball_a/b/c, flyout variants, x_check) **Decision Detection**: - store/game.ts: Updated decision detection to check both decision prompt AND gameState.decision_phase - components: Updated all decision phase checks to use 'awaiting_defensive', 'awaiting_offensive', 'awaiting_stolen_base' **WebSocket Enhancements**: - useWebSocket.ts: Added game_joined event handler with success toast - useWebSocket.ts: Fixed dice roll data - now receives d6_two_a and d6_two_b from server - useWebSocket.ts: Request fresh game state after decision submissions to sync decision_phase **New Constants**: - constants/outcomes.ts: Created centralized PlayOutcome enum with display labels and descriptions **Testing**: - Updated test expectations for new decision phase naming - All component tests passing **Why**: Eliminates confusion from dual naming conventions. Frontend now uses same vocabulary as backend. Fixes runtime type errors from enum value mismatches. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
93 lines
1.9 KiB
TypeScript
93 lines
1.9 KiB
TypeScript
/**
|
|
* Outcome Constants
|
|
*
|
|
* Centralized definitions for play outcomes used across the UI.
|
|
* These match the backend PlayOutcome enum values.
|
|
*/
|
|
|
|
import type { PlayOutcome } from '~/types/game'
|
|
|
|
/**
|
|
* Outcome categories for UI display and selection
|
|
* Grouped by common baseball categories for user-friendly selection
|
|
*/
|
|
export const OUTCOME_CATEGORIES = [
|
|
{
|
|
name: 'Outs',
|
|
outcomes: [
|
|
'strikeout',
|
|
'groundball_a',
|
|
'groundball_b',
|
|
'groundball_c',
|
|
'flyout_a',
|
|
'flyout_b',
|
|
'flyout_c',
|
|
'lineout',
|
|
'popout',
|
|
] as const satisfies readonly PlayOutcome[],
|
|
},
|
|
{
|
|
name: 'Hits',
|
|
outcomes: [
|
|
'single_1',
|
|
'single_2',
|
|
'single_uncapped',
|
|
'double_2',
|
|
'double_3',
|
|
'double_uncapped',
|
|
'triple',
|
|
'homerun',
|
|
] as const satisfies readonly PlayOutcome[],
|
|
},
|
|
{
|
|
name: 'Walks / HBP',
|
|
outcomes: [
|
|
'walk',
|
|
'intentional_walk',
|
|
'hbp',
|
|
] as const satisfies readonly PlayOutcome[],
|
|
},
|
|
{
|
|
name: 'Special',
|
|
outcomes: [
|
|
'error',
|
|
'x_check',
|
|
] as const satisfies readonly PlayOutcome[],
|
|
},
|
|
{
|
|
name: 'Interrupts',
|
|
outcomes: [
|
|
'stolen_base',
|
|
'caught_stealing',
|
|
'wild_pitch',
|
|
'passed_ball',
|
|
'balk',
|
|
'pick_off',
|
|
] as const satisfies readonly PlayOutcome[],
|
|
},
|
|
] as const
|
|
|
|
/**
|
|
* Outcomes that require a hit location to be specified
|
|
* These outcomes involve defensive plays where location matters
|
|
*/
|
|
export const OUTCOMES_REQUIRING_HIT_LOCATION = [
|
|
'groundball_a',
|
|
'groundball_b',
|
|
'groundball_c',
|
|
'flyout_a',
|
|
'flyout_b',
|
|
'flyout_c',
|
|
'lineout',
|
|
'single_uncapped',
|
|
'double_uncapped',
|
|
'error',
|
|
] as const satisfies readonly PlayOutcome[]
|
|
|
|
/**
|
|
* Hit location options
|
|
*/
|
|
export const HIT_LOCATIONS = {
|
|
infield: ['P', 'C', '1B', '2B', '3B', 'SS'] as const,
|
|
outfield: ['LF', 'CF', 'RF'] as const,
|
|
} as const |