Skip to content

Commit 1de4c32

Browse files
feat: add move sound effects to hand & brain games
1 parent cb49c9c commit 1de4c32

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/components/Board/AnalysisGameBoard.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,12 @@ export const AnalysisGameBoard: React.FC<Props> = ({
5454

5555
const chess = new Chess(currentNode.fen)
5656

57-
// Check if there's a piece at the destination before making the move
5857
const pieceAtDestination = chess.get(to)
5958
const isCapture = !!pieceAtDestination
6059

6160
const moveAttempt = chess.move({ from: from, to: to })
6261

6362
if (moveAttempt) {
64-
// Play the appropriate sound
6563
playSound(isCapture)
6664

6765
const newFen = chess.fen()

src/pages/play/hb.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from 'src/components'
2020
import { ModalContext } from 'src/contexts'
2121
import { useStats } from 'src/hooks/useStats'
22+
import { useChessSound } from 'src/hooks/useChessSound'
2223
import { Color, PlayGameConfig, TimeControl } from 'src/types'
2324
import { usePlayController } from 'src/hooks/usePlayController'
2425
import { PlayControllerContext } from 'src/contexts/PlayControllerContext/PlayControllerContext'
@@ -46,6 +47,7 @@ const useHandBrainPlayController = (
4647
playGameConfig: PlayGameConfig,
4748
) => {
4849
const controller = usePlayController(id, playGameConfig)
50+
const { playSound } = useChessSound()
4951
const isBrain = playGameConfig.isBrain
5052

5153
const [selectedPiece, setSelectedPiece] = useState<PieceSymbol | undefined>(
@@ -170,6 +172,7 @@ const useHandBrainPlayController = (
170172
const moveTime = controller.updateClock()
171173
controller.setMoves([...controller.moves, nextMove])
172174
controller.setMoveTimes([...controller.moveTimes, moveTime])
175+
playSound(false)
173176
},
174177
playGameConfig.simulateMaiaTime ? moveDelay * 1000 : 0,
175178
)
@@ -213,6 +216,7 @@ const useHandBrainPlayController = (
213216
)
214217
const nextMove = maiaMoves['top_move']
215218
makeMove(nextMove)
219+
playSound(false)
216220
}
217221
},
218222
[
@@ -247,7 +251,6 @@ const useHandBrainPlayController = (
247251
controller.reset()
248252
}
249253

250-
// Logging
251254
useEffect(() => {
252255
const gameOverState = controller.game.termination?.type || 'not_over'
253256

0 commit comments

Comments
 (0)