Refactor game logic and improve state management, add some tests

- Added `handleHit` function to handle hit types (single, double, triple, home run).
- Enhanced `handleBall` and `handlePitch` to track `scoredRunners` and update scores dynamically.
- Updated history to include both `gameState` and `lineupState`.
- Refactored UI components (`GameStateDisplay`) to use unified score structure and display detailed base states.
- Styled active lineup tab with visual emphasis.
- Introduced utility functions `encodeInning` and `decodeInning` for inning state management.
This commit is contained in:
2024-12-06 17:57:55 -06:00
parent 9cc3793a17
commit 7203ac4c2d
3 changed files with 394 additions and 171 deletions

View File

@@ -13,7 +13,7 @@ function Inning({inning, isTopHalf}){
)
}
function GameStateDisplay({inning, bases, isTopHalf, outs, balls, strikes, awayScore, homeScore, isFinal }){
function GameStateDisplay({inning, bases, isTopHalf, outs, count, awayScore, homeScore, isFinal }){
return (
<div className="gameState">
<header>Scoreboard</header>
@@ -21,7 +21,7 @@ function GameStateDisplay({inning, bases, isTopHalf, outs, balls, strikes, away
<div>
<Row>
<Col><Inning inning={inning} isTopHalf={isTopHalf}></Inning></Col>
<Col>{balls}-{strikes}</Col>
<Col>{count.balls}-{count.strikes}</Col>
<Col>{outs} outs</Col>
<Col>
<FontAwesomeIcon icon={fa1} className={`base ${bases[0] ? "occupied" : ""}`}></FontAwesomeIcon>