ChatCraft / frontend /src /lib /unitSounds.ts
gabraken's picture
feat: add game engine, voice commands, leaderboard, tutorial overlay, and stats tracking
29a88f8
/**
* Lecture des sons d'unités (mouvement, mort, tir) avec max 3 pistes simultanées.
* Si la limite est atteinte, le son est ignoré (pas de file d'attente).
*/
export const MAX_CONCURRENT_UNIT_SOUNDS = 5;
let activeCount = 0;
export function playUnitSound(baseUrl: string, unit: string, kind: 'move_ack' | 'death' | 'fire'): void {
if (typeof window === 'undefined') return;
if (activeCount >= MAX_CONCURRENT_UNIT_SOUNDS) return;
const url = `${baseUrl}/sounds/units/${unit}/${kind}.mp3`;
activeCount += 1;
const audio = new Audio(url);
audio.onended = () => { activeCount -= 1; };
audio.onerror = () => { activeCount -= 1; };
audio.play();
}