Add DEBUG flag and gate console.log behind debugLog helper

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
erik 2026-02-26 09:05:41 +00:00
parent 3d0a0b33a3
commit d025e2623f

View file

@ -22,6 +22,10 @@
* 6. Rendering functions for list and map
* 7. Event listeners for map interactions and WebSocket messages
*/
/* ---------- Debug configuration ---------------------------------- */
const DEBUG = false;
function debugLog(...args) { if (DEBUG) console.log(...args); }
/* ---------- DOM references --------------------------------------- */
const wrap = document.getElementById('mapContainer');
const group = document.getElementById('mapGroup');
@ -97,16 +101,16 @@ function createNewListItem() {
chatBtn.className = 'chat-btn';
chatBtn.textContent = 'Chat';
chatBtn.addEventListener('click', (e) => {
console.log('🔥 CHAT BUTTON CLICKED!', e.target, e.currentTarget);
debugLog('🔥 CHAT BUTTON CLICKED!', e.target, e.currentTarget);
e.stopPropagation();
// Try button's own playerData first, fallback to DOM traversal
const playerData = e.currentTarget.playerData || e.target.closest('li.player-item')?.playerData;
console.log('🔥 Player data found:', playerData);
debugLog('🔥 Player data found:', playerData);
if (playerData) {
console.log('🔥 Opening chat for:', playerData.character_name);
debugLog('🔥 Opening chat for:', playerData.character_name);
showChatWindow(playerData.character_name);
} else {
console.log('🔥 No player data found!');
debugLog('🔥 No player data found!');
}
});
@ -114,16 +118,16 @@ function createNewListItem() {
statsBtn.className = 'stats-btn';
statsBtn.textContent = 'Stats';
statsBtn.addEventListener('click', (e) => {
console.log('📊 STATS BUTTON CLICKED!', e.target, e.currentTarget);
debugLog('📊 STATS BUTTON CLICKED!', e.target, e.currentTarget);
e.stopPropagation();
// Try button's own playerData first, fallback to DOM traversal
const playerData = e.currentTarget.playerData || e.target.closest('li.player-item')?.playerData;
console.log('📊 Player data found:', playerData);
debugLog('📊 Player data found:', playerData);
if (playerData) {
console.log('📊 Opening stats for:', playerData.character_name);
debugLog('📊 Opening stats for:', playerData.character_name);
showStatsWindow(playerData.character_name);
} else {
console.log('📊 No player data found!');
debugLog('📊 No player data found!');
}
});
@ -131,16 +135,16 @@ function createNewListItem() {
inventoryBtn.className = 'inventory-btn';
inventoryBtn.textContent = 'Inventory';
inventoryBtn.addEventListener('click', (e) => {
console.log('🎒 INVENTORY BUTTON CLICKED!', e.target, e.currentTarget);
debugLog('🎒 INVENTORY BUTTON CLICKED!', e.target, e.currentTarget);
e.stopPropagation();
// Try button's own playerData first, fallback to DOM traversal
const playerData = e.currentTarget.playerData || e.target.closest('li.player-item')?.playerData;
console.log('🎒 Player data found:', playerData);
debugLog('🎒 Player data found:', playerData);
if (playerData) {
console.log('🎒 Opening inventory for:', playerData.character_name);
debugLog('🎒 Opening inventory for:', playerData.character_name);
showInventoryWindow(playerData.character_name);
} else {
console.log('🎒 No player data found!');
debugLog('🎒 No player data found!');
}
});
@ -560,7 +564,7 @@ async function fetchHeatmapData() {
const data = await response.json();
heatmapData = data.spawn_points; // [{ew, ns, intensity}]
console.log(`Loaded ${heatmapData.length} heat map points from last ${data.hours_window} hours`);
debugLog(`Loaded ${heatmapData.length} heat map points from last ${data.hours_window} hours`);
renderHeatmap();
} catch (err) {
console.error('Failed to fetch heat map data:', err);
@ -645,7 +649,7 @@ async function fetchPortalData() {
const data = await response.json();
portalData = data.portals; // [{portal_name, coordinates: {ns, ew, z}, discovered_by, discovered_at}]
console.log(`Loaded ${portalData.length} portals from last hour`);
debugLog(`Loaded ${portalData.length} portals from last hour`);
renderPortals();
} catch (err) {
console.error('Failed to fetch portal data:', err);
@ -707,7 +711,7 @@ function renderPortals() {
portalContainer.appendChild(icon);
}
console.log(`Rendered ${portalData.length} portal icons`);
debugLog(`Rendered ${portalData.length} portal icons`);
}
function clearPortals() {
@ -726,20 +730,20 @@ function debounce(fn, ms) {
// Show or create a stats window for a character
function showStatsWindow(name) {
console.log('📊 showStatsWindow called for:', name);
debugLog('📊 showStatsWindow called for:', name);
if (statsWindows[name]) {
const existing = statsWindows[name];
console.log('📊 Existing stats window found, showing it:', existing);
debugLog('📊 Existing stats window found, showing it:', existing);
// Always show the window (no toggle)
existing.style.display = 'flex';
// Bring to front when opening
if (!window.__chatZ) window.__chatZ = 10000;
window.__chatZ += 1;
existing.style.zIndex = window.__chatZ;
console.log('📊 Stats window shown with zIndex:', window.__chatZ);
debugLog('📊 Stats window shown with zIndex:', window.__chatZ);
return;
}
console.log('📊 Creating new stats window for:', name);
debugLog('📊 Creating new stats window for:', name);
const win = document.createElement('div');
win.className = 'stats-window';
win.dataset.character = name;
@ -783,10 +787,10 @@ function showStatsWindow(name) {
content.className = 'chat-messages';
content.textContent = 'Loading stats...';
win.appendChild(content);
console.log('📊 Appending stats window to DOM:', win);
debugLog('📊 Appending stats window to DOM:', win);
document.body.appendChild(win);
statsWindows[name] = win;
console.log('📊 Stats window added to DOM, total children:', document.body.children.length);
debugLog('📊 Stats window added to DOM, total children:', document.body.children.length);
// Load initial stats with default 24h range
updateStatsTimeRange(content, name, 'now-24h');
// Enable dragging using the global drag system
@ -821,20 +825,20 @@ function updateStatsTimeRange(content, name, timeRange) {
// Show or create an inventory window for a character
function showInventoryWindow(name) {
console.log('🎒 showInventoryWindow called for:', name);
debugLog('🎒 showInventoryWindow called for:', name);
if (inventoryWindows[name]) {
const existing = inventoryWindows[name];
console.log('🎒 Existing inventory window found, showing it:', existing);
debugLog('🎒 Existing inventory window found, showing it:', existing);
// Always show the window (no toggle)
existing.style.display = 'flex';
// Bring to front when opening
if (!window.__chatZ) window.__chatZ = 10000;
window.__chatZ += 1;
existing.style.zIndex = window.__chatZ;
console.log('🎒 Inventory window shown with zIndex:', window.__chatZ);
debugLog('🎒 Inventory window shown with zIndex:', window.__chatZ);
return;
}
console.log('🎒 Creating new inventory window for:', name);
debugLog('🎒 Creating new inventory window for:', name);
const win = document.createElement('div');
win.className = 'inventory-window';
win.dataset.character = name;
@ -1026,10 +1030,10 @@ function showInventoryWindow(name) {
console.error('Inventory fetch failed:', err);
});
console.log('🎒 Appending inventory window to DOM:', win);
debugLog('🎒 Appending inventory window to DOM:', win);
document.body.appendChild(win);
inventoryWindows[name] = win;
console.log('🎒 Inventory window added to DOM, total children:', document.body.children.length);
debugLog('🎒 Inventory window added to DOM, total children:', document.body.children.length);
// Enable dragging using the global drag system
makeDraggable(win, header);
@ -1430,7 +1434,7 @@ function handleServerStatusUpdate(msg) {
// Handle real-time server status updates via WebSocket
if (msg.status === 'up' && msg.message) {
// Show notification for server coming back online
console.log(`Server Status: ${msg.message}`);
debugLog(`Server Status: ${msg.message}`);
}
// Trigger an immediate server health poll to refresh the display
@ -1508,11 +1512,11 @@ document.addEventListener('mouseup', () => {
function render(players) {
const startTime = performance.now();
console.log('🔄 RENDER STARTING:', new Date().toISOString());
debugLog('🔄 RENDER STARTING:', new Date().toISOString());
// If user is actively clicking, defer this render briefly
if (userInteracting) {
console.log('🔄 RENDER DEFERRED: User interaction detected');
debugLog('🔄 RENDER DEFERRED: User interaction detected');
setTimeout(() => render(players), 100);
return;
}
@ -1730,7 +1734,7 @@ function render(players) {
// Optimization is achieving 100% element reuse consistently
const renderTime = performance.now() - startTime;
console.log('🔄 RENDER COMPLETED:', renderTime.toFixed(2) + 'ms');
debugLog('🔄 RENDER COMPLETED:', renderTime.toFixed(2) + 'ms');
}
/* ---------- rendering trails ------------------------------- */
@ -1798,20 +1802,20 @@ function initWebSocket() {
// Display or create a chat window for a character
function showChatWindow(name) {
console.log('💬 showChatWindow called for:', name);
debugLog('💬 showChatWindow called for:', name);
if (chatWindows[name]) {
const existing = chatWindows[name];
console.log('💬 Existing chat window found, showing it:', existing);
debugLog('💬 Existing chat window found, showing it:', existing);
// Always show the window (no toggle)
existing.style.display = 'flex';
// Bring to front when opening
if (!window.__chatZ) window.__chatZ = 10000;
window.__chatZ += 1;
existing.style.zIndex = window.__chatZ;
console.log('💬 Chat window shown with zIndex:', window.__chatZ);
debugLog('💬 Chat window shown with zIndex:', window.__chatZ);
return;
}
console.log('💬 Creating new chat window for:', name);
debugLog('💬 Creating new chat window for:', name);
const win = document.createElement('div');
win.className = 'chat-window';
win.dataset.character = name;
@ -1848,10 +1852,10 @@ function showChatWindow(name) {
input.value = '';
});
win.appendChild(form);
console.log('💬 Appending chat window to DOM:', win);
debugLog('💬 Appending chat window to DOM:', win);
document.body.appendChild(win);
chatWindows[name] = win;
console.log('💬 Chat window added to DOM, total children:', document.body.children.length);
debugLog('💬 Chat window added to DOM, total children:', document.body.children.length);
// Enable dragging using the global drag system
makeDraggable(win, header);
@ -2170,7 +2174,7 @@ updateTotalRaresDisplay = function(data) {
}
function triggerMilestoneCelebration(rareNumber) {
console.log(`🏆 MILESTONE: Rare #${rareNumber}! 🏆`);
debugLog(`🏆 MILESTONE: Rare #${rareNumber}! 🏆`);
// Create full-screen milestone overlay
const overlay = document.createElement('div');