Skip to content

Working sound effects system - #7

Merged
MohamedSayed0573 merged 2 commits into
mainfrom
feat/sounds
Aug 8, 2026
Merged

Working sound effects system#7
MohamedSayed0573 merged 2 commits into
mainfrom
feat/sounds

Conversation

@MohamedSayed0573

@MohamedSayed0573 MohamedSayed0573 commented Aug 8, 2026

Copy link
Copy Markdown
Owner
  • Add sound effects for moves, captures, checks, checkmates, castling, promotions, defeats, and draws.
  • Trigger move sounds for server moves, Stockfish moves, and user piece drops.
  • Add playMoveSound(chess) to select the correct sound from the current game state.
  • Add the @services path alias to TypeScript and Vite configurations.
  • Fix the computer player side to white.

Note

Add context-aware sound effects system for chess moves and game events

  • Adds sfx service with preloaded Audio instances for move, capture, castle, check, promotion, checkmate, draw, and defeat events.
  • playMoveSound selects the appropriate sound by inspecting the last move's SAN notation and game-over state, then plays from the start.
  • Integrates playMoveSound into both useChessGame (online) and useComputerGame (vs engine) on each move.
  • Adds @services/* path alias to tsconfig.json and vite.config.ts.
  • Behavioral Change: the human player side in computer games is now always white instead of randomly assigned.

Macroscope summarized afcb7fd.

Copilot AI lite review requested due to automatic review settings August 8, 2026 22:55
@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chesslab Ready Ready Preview Aug 8, 2026 11:05pm

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The client adds chess move sound playback for ordinary moves, checks, captures, castling, promotions, checkmate, defeat, and draws. Online and computer game hooks invoke playMoveSound after moves update the game state. The computer side is fixed to white. TypeScript and Vite now resolve the @services alias.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main change: implementing a working sound effects system for chess gameplay.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread apps/client/src/hooks/game/useChessGame.ts Outdated
Comment thread apps/client/src/hooks/game/useComputerGame.ts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @services alias in Vite + TS config and introduce a new src/services/sfx module.
  • 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 like san and flags), not instances with methods like isCapture() / isPromotion() / castling helpers. As written, this will throw at runtime when trying to call those methods. Also remove the debug console.log calls.
		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.

Comment thread apps/client/src/services/sfx/index.ts
Comment thread apps/client/src/hooks/game/useChessGame.ts Outdated
Comment thread apps/client/src/hooks/game/useComputerGame.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7278907 and c2ecb01.

⛔ Files ignored due to path filters (7)
  • apps/client/public/sounds/standard/Capture.mp3 is excluded by !**/*.mp3
  • apps/client/public/sounds/standard/Castle.mp3 is excluded by !**/*.mp3
  • apps/client/public/sounds/standard/Check.mp3 is excluded by !**/*.mp3
  • apps/client/public/sounds/standard/Game-End.mp3 is excluded by !**/*.mp3
  • apps/client/public/sounds/standard/GenericNotify.mp3 is excluded by !**/*.mp3
  • apps/client/public/sounds/standard/Move.mp3 is excluded by !**/*.mp3
  • apps/client/public/sounds/standard/Promote.mp3 is excluded by !**/*.mp3
📒 Files selected for processing (5)
  • apps/client/src/hooks/game/useChessGame.ts
  • apps/client/src/hooks/game/useComputerGame.ts
  • apps/client/src/services/sfx/index.ts
  • apps/client/tsconfig.json
  • apps/client/vite.config.ts

Comment thread apps/client/src/hooks/game/useChessGame.ts Outdated
Comment thread apps/client/src/hooks/game/useComputerGame.ts
Comment thread apps/client/src/services/sfx/index.ts
Comment thread apps/client/src/services/sfx/index.ts
Comment thread apps/client/src/services/sfx/index.ts Outdated
@MohamedSayed0573
MohamedSayed0573 merged commit 039e0e9 into main Aug 8, 2026
4 checks passed
@MohamedSayed0573
MohamedSayed0573 deleted the feat/sounds branch August 9, 2026 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants