/** Фоновый звук горения при наличии огня на сцене (`public/fire-ambient.mp3`). */ import { getEffectsSfxGain } from './effectsSfxGain'; const FIRE_AMBIENT_BASE_VOLUME = 0.72; export function fireAmbientSoundUrl(): string { return new URL('fire-ambient.mp3', window.location.href).href; } let ambientEl: HTMLAudioElement | null = null; function ensureAmbientEl(): HTMLAudioElement { if (ambientEl) return ambientEl; const el = new Audio(fireAmbientSoundUrl()); el.loop = true; el.preload = 'auto'; ambientEl = el; return el; } function applyVolume(el: HTMLAudioElement): void { el.volume = Math.max(0, Math.min(1, FIRE_AMBIENT_BASE_VOLUME * getEffectsSfxGain())); } /** Включить/выключить loop горения. */ export function setFireAmbientActive(active: boolean): void { try { const el = ensureAmbientEl(); applyVolume(el); if (active) { if (el.paused) void el.play().catch(() => undefined); } else if (!el.paused) { el.pause(); el.currentTime = 0; } } catch { /* ignore */ } } /** Обновить громкость, если ambient уже играет. */ export function syncFireAmbientVolume(): void { if (!ambientEl) return; try { applyVolume(ambientEl); } catch { /* ignore */ } }