feat : new sounds

This commit is contained in:
GuillaumeSD
2025-05-30 00:30:19 +02:00
parent 2f38aca7b5
commit 134cc714de
16 changed files with 6 additions and 32 deletions

View File

@@ -1,5 +1,4 @@
import { Move } from "chess.js";
import { getWhoIsCheckmated, isCheck } from "./chess";
let audioContext: AudioContext | null = null;
let audio: HTMLAudioElement | null = null;
@@ -20,29 +19,15 @@ const playSound = async (url: string) => {
}
};
export const playCaptureSound = () => playSound("/sounds/capture.webm");
export const playCastleSound = () => playSound("/sounds/castle.webm");
export const playGameEndSound = () => playSound("/sounds/game-end.webm");
export const playGameStartSound = () => playSound("/sounds/game-start.webm");
export const playIllegalMoveSound = () =>
playSound("/sounds/illegal-move.webm");
export const playMoveCheckSound = () => playSound("/sounds/move-check.webm");
export const playMoveSound = () => playSound("/sounds/move.webm");
export const playPromoteSound = () => playSound("/sounds/promote.webm");
export const playCaptureSound = () => playSound("/sounds/capture.mp3");
export const playIllegalMoveSound = () => playSound("/sounds/error.mp3");
export const playMoveSound = () => playSound("/sounds/move.mp3");
export const playSoundFromMove = async (move: Move | null) => {
if (!move) {
playIllegalMoveSound();
} else if (getWhoIsCheckmated(move.after)) {
playGameEndSound();
} else if (isCheck(move.after)) {
playMoveCheckSound();
} else if (move.promotion) {
playPromoteSound();
} else if (move.captured) {
playCaptureSound();
} else if (move.isKingsideCastle() || move.isQueensideCastle()) {
playCastleSound();
} else {
playMoveSound();
}