feat : new sounds
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user