Working sound effects system - #7
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe client adds chess move sound playback for ordinary moves, checks, captures, castling, promotions, checkmate, defeat, and draws. Online and computer game hooks invoke Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a client-side sound effects (SFX) service and wires it into game hooks, supported by a new @services path alias for cleaner imports.
Changes:
- Add
@servicesalias in Vite + TS config and introduce a newsrc/services/sfxmodule. - Trigger move/game-end sound effects from the computer-game hook.
- Update multiplayer hook imports and attempt to trigger SFX on remote moves.
Reviewed changes
Copilot reviewed 5 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/client/vite.config.ts | Adds @services Vite alias to support new client services imports. |
| apps/client/tsconfig.json | Adds matching TS path mapping for @services/*. |
| apps/client/src/services/sfx/index.ts | New SFX service that selects and plays sounds based on game state / last move. |
| apps/client/src/hooks/game/useComputerGame.ts | Plays SFX on player + engine moves; changes side selection behavior. |
| apps/client/src/hooks/game/useChessGame.ts | Switches to aliased imports and calls SFX on move events. |
Suppressed comments (1)
apps/client/src/services/sfx/index.ts:36
chess.history({ verbose: true })returns plain move objects (with fields likesanandflags), not instances with methods likeisCapture()/isPromotion()/ castling helpers. As written, this will throw at runtime when trying to call those methods. Also remove the debugconsole.logcalls.
console.log(lastMove);
if (lastMove?.san.endsWith("+")) {
console.log(lastMove.san);
playSound("check");
} else if (lastMove?.isCapture()) {
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/client/src/hooks/game/useChessGame.ts`:
- Line 42: Update the networked move flow around handleMove and playMoveSound to
carry the move descriptor or SAN through MoveMadeEvent/GameMoveAck, rather than
deriving it from chessGame history after chessGame.load(fen). Pass that value
into playMoveSound and use it to classify normal moves, captures, checks,
castling, and promotions while preserving existing sound behavior.
In `@apps/client/src/hooks/game/useComputerGame.ts`:
- Around line 14-15: Update the fixed side initialization in useComputerGame so
it matches the requested computer side: set the human-controlled side to "b"
when Stockfish must play White, or revise the side/stockfishSide relationship so
stockfishSide resolves to "w". Preserve onPieceDrop’s interpretation of side as
the human-controlled side.
In `@apps/client/src/services/sfx/index.ts`:
- Around line 32-34: Remove the per-move and check debug logging from the
move-handling flow around lastMove, including both console.log calls; retain the
existing check detection behavior based on lastMove?.san.endsWith("+").
- Around line 14-19: Update playSound to handle the Promise returned by
HTMLMediaElement.play(), catching rejected playback attempts such as
NotAllowedError. Add an explicit audio-unlock entry point that callers can
invoke after a user gesture to enable blocked autoplay, while preserving the
existing sound reset and playback behavior.
- Around line 21-26: Update playMoveSound to accept the local side and use it
when selecting terminal sounds: preserve checkmate/draw handling, but play
defeat when the checkmated side is the local player. Update all callers in
useChessGame and useComputerGame to pass the local side into playMoveSound.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: e6c82a24-0a03-4ded-b772-74f2aef6acd1
⛔ Files ignored due to path filters (7)
apps/client/public/sounds/standard/Capture.mp3is excluded by!**/*.mp3apps/client/public/sounds/standard/Castle.mp3is excluded by!**/*.mp3apps/client/public/sounds/standard/Check.mp3is excluded by!**/*.mp3apps/client/public/sounds/standard/Game-End.mp3is excluded by!**/*.mp3apps/client/public/sounds/standard/GenericNotify.mp3is excluded by!**/*.mp3apps/client/public/sounds/standard/Move.mp3is excluded by!**/*.mp3apps/client/public/sounds/standard/Promote.mp3is excluded by!**/*.mp3
📒 Files selected for processing (5)
apps/client/src/hooks/game/useChessGame.tsapps/client/src/hooks/game/useComputerGame.tsapps/client/src/services/sfx/index.tsapps/client/tsconfig.jsonapps/client/vite.config.ts
playMoveSound(chess)to select the correct sound from the current game state.@servicespath alias to TypeScript and Vite configurations.Note
Add context-aware sound effects system for chess moves and game events
Audioinstances for move, capture, castle, check, promotion, checkmate, draw, and defeat events.playMoveSoundselects the appropriate sound by inspecting the last move's SAN notation and game-over state, then plays from the start.playMoveSoundinto bothuseChessGame(online) anduseComputerGame(vs engine) on each move.@services/*path alias totsconfig.jsonandvite.config.ts.Macroscope summarized afcb7fd.