diff --git a/.gitignore b/.gitignore index 3e66a7e..53ba16a 100644 --- a/.gitignore +++ b/.gitignore @@ -22,5 +22,8 @@ Thumbs.db .vscode/ .idea/ +# Token local (jamais commité) +.gitea-token + # Claude Code .claude/ diff --git a/lib/dropstats.js b/lib/dropstats.js index 7a87d20..24959a7 100644 --- a/lib/dropstats.js +++ b/lib/dropstats.js @@ -21,12 +21,14 @@ function mergeDropStatsInto(target, source) { for (const [mobName, mobData] of Object.entries(sourceMobs)) { if (!mobName) continue; - if (!target.mobs[mobName]) target.mobs[mobName] = { kills: 0, items: {} }; + if (!target.mobs[mobName]) target.mobs[mobName] = { kills: 0, totalExp: 0, totalCols: 0, items: {} }; const t = target.mobs[mobName]; const kills = Number(mobData.kills) || 0; t.kills += kills; addedKills += kills; + t.totalExp = (t.totalExp || 0) + (Number(mobData.totalExp) || 0); + t.totalCols = (t.totalCols || 0) + (Number(mobData.totalCols) || 0); const items = mobData.items || {}; for (const [key, item] of Object.entries(items)) { diff --git a/package.json b/package.json index de28289..60c3377 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "farm-tracker", - "version": "1.0.7", + "version": "1.0.8", "description": "Suivi de loot Minecraft en direct, avec sauvegarde automatique des stats et des chances de drop.", "main": "main.js", "scripts": { diff --git a/renderer/index.html b/renderer/index.html index 4f9659f..6ce4b5b 100644 --- a/renderer/index.html +++ b/renderer/index.html @@ -290,6 +290,7 @@ .sessions-table td.hl{font-family:var(--font-mono);color:var(--text);} .sessions-table td.dim{font-size:12px;color:var(--text-dim);} .hist-empty{padding:40px 0;text-align:center;color:var(--text-dim);font-size:14px;line-height:1.8;} + .sessions-table tbody tr:hover td{background:rgba(255,255,255,.03);} @media(max-width:760px){.charts-2col{grid-template-columns:1fr;}} /* ---------- Graphes en direct ---------- */ @@ -325,6 +326,9 @@ .timer-card-bar{height:3px;background:var(--border);margin-top:10px;overflow:hidden;} .timer-card-bar-fill{height:100%;transition:width .9s linear;} .timer-empty-msg{color:var(--text-dim);font-size:13px;padding:20px 0;} + #chartTip{position:fixed;z-index:1001;background:var(--bg-panel);border:1px solid var(--border); + padding:4px 10px;font-family:var(--font-mono);font-size:11px;color:var(--text); + pointer-events:none;display:none;white-space:nowrap;box-shadow:0 2px 8px rgba(0,0,0,.5);} @@ -640,6 +644,47 @@ + + + @@ -731,6 +790,8 @@ +
+
Qui drop cet item ?
@@ -799,6 +860,28 @@ const $ = (id) => document.getElementById(id); + // ---------- Tooltip pour les graphes ---------- + const chartTip = $('chartTip'); + function showChartTip(text, cx, cy){ + chartTip.textContent = text; + chartTip.style.display = 'block'; + chartTip.style.left = Math.min(cx + 14, window.innerWidth - 170) + 'px'; + chartTip.style.top = Math.min(cy - 30, window.innerHeight - 44) + 'px'; + } + function hideChartTip(){ chartTip.style.display = 'none'; } + function attachChartTip(svg){ + if (!svg) return; + svg.addEventListener('mouseover', e => { if (e.target.dataset.tip) showChartTip(e.target.dataset.tip, e.clientX, e.clientY); }); + svg.addEventListener('mouseout', e => { if (e.target.dataset.tip) hideChartTip(); }); + svg.addEventListener('mousemove', e => { + if (e.target.dataset.tip){ + chartTip.style.left = Math.min(e.clientX + 14, window.innerWidth - 170) + 'px'; + chartTip.style.top = Math.min(e.clientY - 30, window.innerHeight - 44) + 'px'; + } + }); + svg.addEventListener('mouseleave', hideChartTip); + } + // ====================================================================== // SHELL : navigation entre écrans (dossier -> accueil -> outils) // ====================================================================== @@ -809,7 +892,8 @@ farmTracker: $('appFarmTracker'), dropBoard: $('appDropBoard'), history: $('appHistory'), - timers: $('appTimers') + timers: $('appTimers'), + sessionDetail: $('appSessionDetail') }; const homeBtn = $('homeBtn'); const changeFolderBtn = $('changeFolderBtn'); @@ -895,7 +979,7 @@ for (const [key, it] of entry.items.entries()){ items[key] = {name: mcPlain(it.rawName) || it.name || '', rawName: it.rawName, occurrences: it.occurrences, totalQty: it.totalQty}; } - mobs[mobName] = {kills: entry.kills, items}; + mobs[mobName] = {kills: entry.kills, totalExp: entry.totalExp || 0, totalCols: entry.totalCols || 0, items}; } return {type: 'farm-tracker-dropstats', version: 1, updatedAt: new Date().toISOString(), mobs}; } @@ -906,7 +990,7 @@ for (const [key, it] of Object.entries(mobData.items || {})){ items.set(key, {rawName: it.rawName || it.name || '', occurrences: it.occurrences || 0, totalQty: it.totalQty || 0}); } - map.set(mobName, {kills: mobData.kills || 0, items}); + map.set(mobName, {kills: mobData.kills || 0, totalExp: mobData.totalExp || 0, totalCols: mobData.totalCols || 0, items}); } return map; } @@ -1280,9 +1364,11 @@ state.killCols += col; triggerTimer(mobPlain); - if (!state.dropStats.has(mobPlain)) state.dropStats.set(mobPlain, {kills: 0, items: new Map()}); + if (!state.dropStats.has(mobPlain)) state.dropStats.set(mobPlain, {kills: 0, totalExp: 0, totalCols: 0, items: new Map()}); const dropEntry = state.dropStats.get(mobPlain); dropEntry.kills += 1; + dropEntry.totalExp = (dropEntry.totalExp || 0) + exp; + dropEntry.totalCols = (dropEntry.totalCols || 0) + col; const items = Array.isArray(data.items) ? data.items : []; const feedItems = []; @@ -1303,6 +1389,12 @@ dropEntry.items.set(key, dropItem); feedItems.push({rawName: it.name || '', qty: amt, key}); + if (alertConfigs.length){ + const pn = mcPlain(it.name || '').toLowerCase(); + for (const alert of alertConfigs){ + if (pn && alert.nameLower && pn.includes(alert.nameLower)){ playAlertPing(); break; } + } + } } state.feedEntries.unshift({time: Date.now(), mobRaw, mobPlain, exp, col, items: feedItems}); @@ -1370,7 +1462,7 @@ if (state.timelineTimer){ clearInterval(state.timelineTimer); state.timelineTimer = null; } } - function drawLiveChart(container, rates, colorHex){ + function drawLiveChart(container, rates, colorHex, unit){ if (rates.length < 2){ container.innerHTML = '

En attente…

'; return; @@ -1386,12 +1478,19 @@ const y=(padT+plotH*(1-pct)).toFixed(1); return ''; }).join(''); + const dots=xs.map((x,i)=>{ + const label=fmt(rates[i],1)+(unit?' '+unit:''); + return '' + +''; + }).join(''); container.innerHTML= '' +grid +'' +'' + +dots +''; + attachChartTip(container.querySelector('svg')); } function fmtHHMM(ts){ const d=new Date(ts); return pad(d.getHours())+':'+pad(d.getMinutes()); } @@ -1411,9 +1510,9 @@ colRates.push((snap[i].cols-snap[i-1].cols)/dt); } - drawLiveChart($('liveChartKills'), killRates, '#6B8F5C'); - drawLiveChart($('liveChartExp'), expRates, '#F2C94C'); - drawLiveChart($('liveChartCols'), colRates, '#C97B4A'); + drawLiveChart($('liveChartKills'), killRates, '#6B8F5C', 'kills/min'); + drawLiveChart($('liveChartExp'), expRates, '#F2C94C', 'xp/min'); + drawLiveChart($('liveChartCols'), colRates, '#C97B4A', 'cols/min'); const last = arr => arr.length ? arr[arr.length-1] : 0; $('liveChartKillsVal').textContent = fmt(last(killRates),1)+'/min'; @@ -1652,6 +1751,19 @@ body.innerHTML = '

Pas encore de drop enregistré pour ce mob.

'; return; } + const totalExp = entry.totalExp || 0; + const totalCols = entry.totalCols || 0; + const statDiv = document.createElement('div'); + statDiv.style.cssText = 'font-family:var(--font-mono);font-size:11px;color:var(--text-dim);margin-bottom:10px;padding-bottom:8px;border-bottom:1px solid var(--border);display:flex;gap:18px;flex-wrap:wrap;'; + if (totalExp > 0){ + statDiv.innerHTML += 'XP ~'+fmt(totalExp/kills,1)+' / kill · '+fmt(Math.round(totalExp))+' total'; + } else { + statDiv.innerHTML += 'XP — non disponible'; + } + if (totalCols > 0){ + statDiv.innerHTML += 'Cols ~'+fmt(totalCols/kills,2)+' / kill · '+fmt(Math.round(totalCols))+' total'; + } + body.appendChild(statDiv); const itemEntries = Array.from(entry.items.entries()).sort((a,b) => (b[1].occurrences/kills) - (a[1].occurrences/kills)); for (const [key, it] of itemEntries){ const pct = kills > 0 ? (it.occurrences/kills*100) : 0; @@ -1794,9 +1906,12 @@ const header = document.createElement('div'); header.className = 'drop-board-mob-header'; + const xpPerKill = entry.kills > 0 && (entry.totalExp || 0) > 0 ? fmt((entry.totalExp||0)/entry.kills,1)+' xp/kill' : null; + const colPerKill = entry.kills > 0 && (entry.totalCols || 0) > 0 ? fmt((entry.totalCols||0)/entry.kills,2)+' col/kill' : null; + const xpColParts = [xpPerKill, colPerKill].filter(Boolean).join(' · '); header.innerHTML = ''+escHtml(mobName)+''+ - ''+fmt(entry.kills)+' kills'; + ''+fmt(entry.kills)+' kills'+(xpColParts ? ' · '+xpColParts : '')+''; section.appendChild(header); const cardsGrid = document.createElement('div'); @@ -1874,8 +1989,9 @@ const d=new Date(sessions[i].startedAt); const dateStr=d.toLocaleDateString('fr-FR',{day:'2-digit',month:'2-digit'}); const valStr=labelFn?labelFn(val):Math.round(val).toLocaleString('fr-FR'); - const title=escHtml('Session '+(i+1)+' ('+dateStr+') : '+valStr); - return ''+title+''; + const tip=escAttr('Session '+(i+1)+' ('+dateStr+') : '+valStr); + return '' + +''; }).join(''); container.innerHTML= '' @@ -1884,6 +2000,7 @@ +'' +dots +''; + attachChartTip(container.querySelector('svg')); if (labelContainer&&sessions.length>=2){ const d1=new Date(sessions[0].startedAt); const d2=new Date(sessions[sessions.length-1].startedAt); @@ -1957,6 +2074,9 @@ const colsPerMin=minElapsed>0?Math.round((s.killCols||0)/minElapsed*10)/10:0; const topItemName=s.topItems&&s.topItems.length?s.topItems[0].name+' ×'+s.topItems[0].qty:'—'; const tr=document.createElement('tr'); + tr.style.cursor='pointer'; + tr.title='Clic pour voir le détail'; + tr.dataset.sessionId=s.id; tr.innerHTML= ''+escHtml(dateStr)+''+ ''+escHtml(durStr)+''+ @@ -1967,11 +2087,83 @@ ''+(s.sellTotal?fmtShort(Math.round(s.sellTotal)):'—')+''+ ''+fmt(colsPerMin,1)+'/min'+ ''+escHtml(s.topMob||'—')+''+ - ''+escHtml(topItemName.length>22?topItemName.slice(0,20)+'…':topItemName)+''; + ''+escHtml(topItemName.length>22?topItemName.slice(0,20)+'…':topItemName)+''+ + '→'; tbody.appendChild(tr); } } + function renderSessionDetail(s){ + const d = new Date(s.startedAt); + const dateStr = d.toLocaleDateString('fr-FR',{weekday:'long',day:'2-digit',month:'long',year:'numeric'}) + + ' à ' + d.toLocaleTimeString('fr-FR',{hour:'2-digit',minute:'2-digit'}); + $('sessionDetailTitle').textContent = dateStr; + + const minElapsed = s.durationMs / 60000; + const dH = Math.floor(s.durationMs/3600000), dM = Math.floor((s.durationMs%3600000)/60000), dS = Math.floor((s.durationMs%60000)/1000); + $('sdDur').textContent = dH > 0 ? dH+'h'+String(dM).padStart(2,'0')+'m' : dM+'min '+String(dS).padStart(2,'0')+'s'; + $('sdKills').textContent = fmt(s.totalKills); + $('sdKillsRate').textContent = minElapsed > 0 ? fmt(s.totalKills/minElapsed,1)+' kills/min' : '—'; + $('sdExp').textContent = fmtShort(s.totalExp||0); + $('sdExpRate').textContent = minElapsed > 0 ? fmtShort(Math.round((s.totalExp||0)/minElapsed))+'/min' : '—'; + $('sdKamas').textContent = s.sellTotal ? fmtShort(Math.round(s.sellTotal)) : '—'; + $('sdCols').textContent = minElapsed > 0 ? fmt((s.killCols||0)/minElapsed,1)+' cols/min' : '—'; + + // Mobs + const mobEl = $('sdMobList'); + const mobEntries = Object.entries(s.mobCounts||{}).sort((a,b)=>b[1]-a[1]); + if (!mobEntries.length){ + mobEl.innerHTML = '

Aucun mob enregistré.

'; + } else { + const maxCount = mobEntries[0][1]; + const colors = ['#9B5DE5','#5DB7E5','#F2C94C','#E05563','#5DE5A0','#E5955D']; + mobEl.innerHTML = mobEntries.map(([name, count], i) => { + const pct = (count / maxCount * 100).toFixed(1); + const color = colors[i % colors.length]; + const perMin = minElapsed > 0 ? (count/minElapsed).toFixed(1) : '—'; + return '
' + + '
'+escHtml(name)+'' + + ''+fmt(count)+' ('+perMin+'/min)
' + + '
' + + '
'; + }).join(''); + } + + // Items + const itemEl = $('sdItemList'); + const items = s.topItems||[]; + if (!items.length){ + itemEl.innerHTML = '

Aucun item enregistré.

'; + } else { + const maxQty = items[0].qty; + const colors = ['#F2C94C','#9B5DE5','#5DB7E5','#E05563','#5DE5A0']; + itemEl.innerHTML = items.map(({name, qty}, i) => { + const pct = (qty / maxQty * 100).toFixed(1); + const color = colors[i % colors.length]; + const perMin = minElapsed > 0 ? (qty/minElapsed).toFixed(2) : '—'; + return '
' + + '
'+escHtml(name)+'' + + '×'+fmt(qty)+' ('+perMin+'/min)
' + + '
' + + '
'; + }).join(''); + } + } + + $('sessionDetailBackBtn').addEventListener('click', () => { + showScreen('history'); + renderHistoryScreen(); + }); + + $('histSessionsBody').addEventListener('click', e => { + const tr = e.target.closest('tr[data-session-id]'); + if (!tr) return; + const session = sessionHistory.sessions.find(s => s.id === tr.dataset.sessionId); + if (!session) return; + renderSessionDetail(session); + showScreen('sessionDetail'); + }); + $('clearHistoryBtn').addEventListener('click', async () => { if (!sessionHistory.sessions.length) return; if (!window.confirm('Effacer tout l\'historique des sessions ? Cette action est irréversible.')) return; @@ -1985,6 +2177,21 @@ // ====================================================================== let timerConfigs = JSON.parse(localStorage.getItem('timerConfigs') || '[]'); + let alertConfigs = JSON.parse(localStorage.getItem('alertConfigs') || '[]'); + + function saveAlertConfigs(){ + localStorage.setItem('alertConfigs', JSON.stringify(alertConfigs)); + } + + let _alertAudio = null; + function playAlertPing(){ + try { + if (!_alertAudio) _alertAudio = new Audio('levelup.ogg'); + _alertAudio.currentTime = 0; + _alertAudio.play().catch(e => console.warn('Alert ping failed', e)); + } catch(e){ console.warn('Alert ping failed', e); } + } + // activeTimers : Map const activeTimers = new Map(); let timerClockId = null; @@ -2073,9 +2280,33 @@ }).join(''); } + function populateTimerMobSuggestions(){ + const dl = $('timerMobSuggestions'); + if (!dl) return; + const seen = new Set(); + // mobs de la session courante + if (ft && ft.state && ft.state.mobCounts){ + for (const name of ft.state.mobCounts.keys()) seen.add(name); + } + // mobs de l'historique + for (const sess of sessionHistory.sessions){ + if (sess.mobCounts) for (const name of Object.keys(sess.mobCounts)) seen.add(name); + } + // exclure ceux déjà configurés + const configured = new Set(timerConfigs.map(c => c.mobName.toLowerCase())); + dl.innerHTML = Array.from(seen) + .filter(n => !configured.has(n.toLowerCase())) + .sort((a,b) => a.localeCompare(b)) + .map(n => '') + .join(''); + } + function renderTimerScreen(){ renderTimerConfigList(); renderTimerActiveGrid(); + populateTimerMobSuggestions(); + renderAlertConfigList(); + populateAlertItemSuggestions(); startTimerClock(); } @@ -2088,6 +2319,7 @@ $('timerMobInput').value = ''; $('timerDurInput').value = ''; renderTimerConfigList(); + populateTimerMobSuggestions(); }); $('timerMobInput').addEventListener('keydown', e => { if (e.key === 'Enter') $('timerAddBtn').click(); }); @@ -2101,6 +2333,62 @@ saveTimerConfigs(); renderTimerConfigList(); renderTimerActiveGrid(); + populateTimerMobSuggestions(); + }); + + function renderAlertConfigList(){ + const list = $('alertConfigList'); + if (!list) return; + if (!alertConfigs.length){ list.innerHTML = ''; return; } + list.innerHTML = alertConfigs.map(cfg => + '
'+ + ''+escHtml(cfg.itemName)+''+ + ''+ + '
' + ).join(''); + } + + function populateAlertItemSuggestions(){ + const dl = $('alertItemSuggestions'); + if (!dl) return; + const seen = new Set(); + if (ft && ft.state && ft.state.itemCounts){ + for (const it of ft.state.itemCounts.values()){ + const n = mcPlain(it.rawName); if (n) seen.add(n); + } + } + if (ft && ft.state && ft.state.dropStats){ + for (const [, entry] of ft.state.dropStats){ + for (const [, it] of entry.items){ const n = mcPlain(it.rawName); if (n) seen.add(n); } + } + } + const configured = new Set(alertConfigs.map(c => c.itemName.toLowerCase())); + dl.innerHTML = Array.from(seen) + .filter(n => !configured.has(n.toLowerCase())) + .sort((a,b) => a.localeCompare(b)) + .map(n => '') + .join(''); + } + + $('alertAddBtn').addEventListener('click', () => { + const itemName = $('alertItemInput').value.trim(); + if (!itemName) return; + alertConfigs.push({ id: generateUUID(), itemName, nameLower: itemName.toLowerCase() }); + saveAlertConfigs(); + $('alertItemInput').value = ''; + renderAlertConfigList(); + populateAlertItemSuggestions(); + }); + + $('alertItemInput').addEventListener('keydown', e => { if (e.key === 'Enter') $('alertAddBtn').click(); }); + + $('alertConfigList').addEventListener('click', e => { + const id = e.target.dataset.delAlert; + if (!id) return; + alertConfigs = alertConfigs.filter(c => c.id !== id); + saveAlertConfigs(); + renderAlertConfigList(); + populateAlertItemSuggestions(); }); updateTimerTileStatus(); diff --git a/renderer/levelup.ogg b/renderer/levelup.ogg new file mode 100644 index 0000000..f097959 Binary files /dev/null and b/renderer/levelup.ogg differ