diff --git a/renderer/index.html b/renderer/index.html index a85e100..459d124 100644 --- a/renderer/index.html +++ b/renderer/index.html @@ -748,19 +748,19 @@

Alertes de drop

-
- Volume - - 25% -
-
- +
+ +
+ Vol + + 10% +
-

Son joué à chaque fois que cet item drop. Volume global s'applique à toutes les alertes.

+

Chaque alerte a son propre son et volume.

@@ -2313,14 +2313,10 @@ return decoded; } - function getAlertVolume(){ - return parseInt(localStorage.getItem('alertGlobalVolume') || '25', 10) / 100; - } - async function playAlert(cfg){ try { const soundId = cfg ? (cfg.soundId || 'levelup') : 'levelup'; - const vol = getAlertVolume(); + const vol = Math.max(0, Math.min(1, ((cfg && cfg.volume != null) ? cfg.volume : 10) / 100)); const buf = await _getDecodedBuffer(soundId); if (!buf){ console.warn('Sound not cached:', soundId); return; } const ctx = getAudioCtx(); @@ -2329,23 +2325,20 @@ src.buffer = buf; src.connect(gain); gain.connect(ctx.destination); - gain.gain.value = Math.max(0, Math.min(1, vol)); + gain.gain.value = vol; src.start(); } catch(e){ console.warn('playAlert failed', e); } } - // migration ancien format (sans soundId) + // migration : ajoute soundId et volume si absents let alertConfigs = JSON.parse(localStorage.getItem('alertConfigs') || '[]').map(c => ({ - soundId: 'levelup', ...c + soundId: 'levelup', volume: 10, ...c })); function saveAlertConfigs(){ localStorage.setItem('alertConfigs', JSON.stringify(alertConfigs)); } - // Pre-cache levelup.ogg au démarrage (son par défaut) - _getDecodedBuffer('levelup').catch(() => {}); - // activeTimers : Map const activeTimers = new Map(); let timerClockId = null; @@ -2513,9 +2506,12 @@ const label = s.label + (notCached ? ' (⬇)' : ''); return ''; }).join(''); + const vol = cfg.volume != null ? cfg.volume : 10; return '
'+ ''+escHtml(cfg.itemName)+''+ ''+ + ''+ + ''+vol+'%'+ ''+ ''+ '
'; @@ -2550,16 +2546,21 @@ sel.innerHTML = buildSoundOptions('levelup'); } + // slider volume dans le formulaire d'ajout + $('alertVolumeInput').addEventListener('input', () => { + $('alertVolumeVal').textContent = $('alertVolumeInput').value + '%'; + }); + $('alertAddBtn').addEventListener('click', () => { const itemName = $('alertItemInput').value.trim(); if (!itemName) return; const soundId = $('alertSoundSelect').value || 'levelup'; - alertConfigs.push({ id: generateUUID(), itemName, nameLower: itemName.toLowerCase(), soundId }); + const volume = parseInt($('alertVolumeInput').value, 10); + alertConfigs.push({ id: generateUUID(), itemName, nameLower: itemName.toLowerCase(), soundId, volume }); saveAlertConfigs(); $('alertItemInput').value = ''; renderAlertConfigList(); populateAlertItemSuggestions(); - // auto-download si son pas encore en cache if (soundId !== 'levelup') isSoundCached(soundId).then(ok => { if (!ok) downloadSound(soundId).catch(()=>{}); }); }); @@ -2592,23 +2593,26 @@ }); $('alertConfigList').addEventListener('change', e => { - const id = e.target.dataset.alertSound; + const soundId = e.target.dataset.alertSound; + if (soundId){ + const cfg = alertConfigs.find(c => c.id === soundId); + if (!cfg) return; + cfg.soundId = e.target.value; + saveAlertConfigs(); + if (cfg.soundId !== 'levelup') isSoundCached(cfg.soundId).then(ok => { if (!ok) downloadSound(cfg.soundId).catch(()=>{}); }); + return; + } + }); + + $('alertConfigList').addEventListener('input', e => { + const id = e.target.dataset.alertVol; if (!id) return; const cfg = alertConfigs.find(c => c.id === id); if (!cfg) return; - cfg.soundId = e.target.value; + cfg.volume = parseInt(e.target.value, 10); saveAlertConfigs(); - if (cfg.soundId !== 'levelup') isSoundCached(cfg.soundId).then(ok => { if (!ok) downloadSound(cfg.soundId).catch(()=>{}); }); - }); - - // ---- Volume global ---- - const _volSlider = $('alertGlobalVolume'); - const _volLabel = $('alertGlobalVolumeVal'); - const _savedVol = localStorage.getItem('alertGlobalVolume') || '25'; - if (_volSlider){ _volSlider.value = _savedVol; _volLabel.textContent = _savedVol + '%'; } - _volSlider && _volSlider.addEventListener('input', () => { - localStorage.setItem('alertGlobalVolume', _volSlider.value); - _volLabel.textContent = _volSlider.value + '%'; + const label = document.querySelector('[data-alert-vol-label="'+id+'"]'); + if (label) label.textContent = cfg.volume + '%'; }); // ---- Sound library ----