fix : audio play

This commit is contained in:
GuillaumeSD
2025-05-26 01:39:10 +02:00
parent 3d2b41acf5
commit f5283b6f6c
2 changed files with 8 additions and 3 deletions

View File

@@ -317,11 +317,10 @@ export const getCapturedPieces = (
new RegExp(piece, "g") new RegExp(piece, "g")
)?.length; )?.length;
const newPiece = pieceFenToSymbol[piece] ?? piece; const newPiece = pieceFenToSymbol[piece] ?? piece;
if (!count) return { piece: newPiece, count };
return { return {
piece: newPiece, piece: newPiece,
count: count - (piecesLeftCount ?? 0), count: Math.max(0, count - (piecesLeftCount ?? 0)),
}; };
}); });
}; };

View File

@@ -1,10 +1,16 @@
import { Move } from "chess.js"; import { Move } from "chess.js";
import { getWhoIsCheckmated, isCheck } from "./chess"; import { getWhoIsCheckmated, isCheck } from "./chess";
let audioContext: AudioContext | null = null;
let audio: HTMLAudioElement | null = null; let audio: HTMLAudioElement | null = null;
const playSound = async (url: string) => { const playSound = async (url: string) => {
if (!audio) audio = new Audio(); if (!audio) {
audioContext = new AudioContext();
audio = new Audio();
const source = audioContext.createMediaElementSource(audio);
source.connect(audioContext.destination);
}
audio.src = url; audio.src = url;
try { try {