Skip to content

Commit

Permalink
only play move sound when position changes forward by 1 ply
Browse files Browse the repository at this point in the history
  • Loading branch information
0Xero7 committed Nov 27, 2024
1 parent 3249028 commit 49adad4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions frontend/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ export class App implements WebsocketObserver {
public onPositionReceived(position: WsPositionData[]): void {
const filteredPositions = position.filter(p => p.gameId == this.curGameId);
this.moveList.updatePositions(filteredPositions);
if (filteredPositions.length > 0) {
this.audioPlayer.playMoveAudio();
}
}
public onEvaluationReceived(evaluation: WsEvaluationData[]): void {
let evals = evaluation.filter(
Expand Down Expand Up @@ -117,6 +114,7 @@ export class App implements WebsocketObserver {
public onMoveSelected(
position: WsPositionData, pos_changed: boolean,
isOngoling: boolean): void {
const currentPly = this.curPly ?? -1;
this.curPly = position.ply;
const nextMove = this.moveList.getMoveAtPly(position.ply + 1)?.moveUci;
this.boardArea.changePosition(
Expand All @@ -125,7 +123,11 @@ export class App implements WebsocketObserver {
this.multiPvView.setPosition(position);
this.websocketFeed.setPosition(position.ply);
this.boardArea.resetSideBoardVisualization();
this.audioPlayer.playMoveAudio();

// Only play move sound when the next move is 1 ply ahead of the current position
if (position.ply === currentPly + 1) {
this.audioPlayer.playMoveAudio();
}
}
this.boardArea.updatePosition(position);
}
Expand Down

0 comments on commit 49adad4

Please sign in to comment.