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

@@ -58,4 +58,5 @@ public/piece/companion | David L. Brown | ["freeware"](http://www.enpassant.dk/c
public/piece/leipzig | Armando Hernandez Marroquin | ["freeware"](http://www.enpassant.dk/chess/fonteng.htm#LEIPZIG) public/piece/leipzig | Armando Hernandez Marroquin | ["freeware"](http://www.enpassant.dk/chess/fonteng.htm#LEIPZIG)
public/piece/reillycraig | [Reilly Craig](https://instagram.com/fader_) | public/piece/reillycraig | [Reilly Craig](https://instagram.com/fader_) |
public/piece/symmetric | [Arcticpenguins](https://github.com/lichess-org/lichobile/issues/215) | public/piece/symmetric | [Arcticpenguins](https://github.com/lichess-org/lichobile/issues/215) |
public/sounds | [Lichess](https://github.com/lichess-org/lila) | [GNU AGPL v3](https://github.com/lichess-org/lila?tab=License-2-ov-file)
public/piece/riohacha | | public/piece/riohacha | |

BIN
public/sounds/capture.mp3 Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
public/sounds/error.mp3 Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
public/sounds/move.mp3 Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,9 +1,5 @@
import { getGameFromPgn, setGameHeaders } from "@/lib/chess"; import { getGameFromPgn, setGameHeaders } from "@/lib/chess";
import { import { playIllegalMoveSound, playSoundFromMove } from "@/lib/sounds";
playGameEndSound,
playIllegalMoveSound,
playSoundFromMove,
} from "@/lib/sounds";
import { Player } from "@/types/game"; import { Player } from "@/types/game";
import { Chess, Move, DEFAULT_POSITION } from "chess.js"; import { Chess, Move, DEFAULT_POSITION } from "chess.js";
import { PrimitiveAtom, useAtom } from "jotai"; import { PrimitiveAtom, useAtom } from "jotai";
@@ -129,11 +125,7 @@ export const useChessActions = (chessAtom: PrimitiveAtom<Chess>) => {
} }
setGame(newGame); setGame(newGame);
if (lastMove) { playSoundFromMove(lastMove);
playSoundFromMove(lastMove);
} else {
playGameEndSound();
}
}, },
[setGame] [setGame]
); );

View File

@@ -1,5 +1,4 @@
import { Move } from "chess.js"; import { Move } from "chess.js";
import { getWhoIsCheckmated, isCheck } from "./chess";
let audioContext: AudioContext | null = null; let audioContext: AudioContext | null = null;
let audio: HTMLAudioElement | 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 playCaptureSound = () => playSound("/sounds/capture.mp3");
export const playCastleSound = () => playSound("/sounds/castle.webm"); export const playIllegalMoveSound = () => playSound("/sounds/error.mp3");
export const playGameEndSound = () => playSound("/sounds/game-end.webm"); export const playMoveSound = () => playSound("/sounds/move.mp3");
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 playSoundFromMove = async (move: Move | null) => { export const playSoundFromMove = async (move: Move | null) => {
if (!move) { if (!move) {
playIllegalMoveSound(); playIllegalMoveSound();
} else if (getWhoIsCheckmated(move.after)) {
playGameEndSound();
} else if (isCheck(move.after)) {
playMoveCheckSound();
} else if (move.promotion) {
playPromoteSound();
} else if (move.captured) { } else if (move.captured) {
playCaptureSound(); playCaptureSound();
} else if (move.isKingsideCastle() || move.isQueensideCastle()) {
playCastleSound();
} else { } else {
playMoveSound(); playMoveSound();
} }

View File

@@ -7,7 +7,6 @@ import {
import { useAtom, useAtomValue } from "jotai"; import { useAtom, useAtomValue } from "jotai";
import { gameAtom, isGameInProgressAtom } from "./states"; import { gameAtom, isGameInProgressAtom } from "./states";
import { useEffect } from "react"; import { useEffect } from "react";
import { playGameEndSound } from "@/lib/sounds";
import UndoMoveButton from "./undoMoveButton"; import UndoMoveButton from "./undoMoveButton";
export default function GameInProgress() { export default function GameInProgress() {
@@ -19,7 +18,6 @@ export default function GameInProgress() {
}, [game, setIsGameInProgress]); }, [game, setIsGameInProgress]);
const handleResign = () => { const handleResign = () => {
playGameEndSound();
setIsGameInProgress(false); setIsGameInProgress(false);
}; };

View File

@@ -28,7 +28,6 @@ import {
enginePlayNameAtom, enginePlayNameAtom,
} from "../states"; } from "../states";
import { useChessActions } from "@/hooks/useChessActions"; import { useChessActions } from "@/hooks/useChessActions";
import { playGameStartSound } from "@/lib/sounds";
import { logAnalyticsEvent } from "@/lib/firebase"; import { logAnalyticsEvent } from "@/lib/firebase";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { isEngineSupported } from "@/lib/engine/shared"; import { isEngineSupported } from "@/lib/engine/shared";
@@ -93,7 +92,6 @@ export default function GameSettingsDialog({ open, onClose }: Props) {
setIsGameInProgress(true); setIsGameInProgress(true);
handleClose(); handleClose();
playGameStartSound();
logAnalyticsEvent("play_game", { logAnalyticsEvent("play_game", {
engine: engineName, engine: engineName,