Replace magic numbers with named constants
Add POLL_RARES_MS, POLL_KILLS_MS, POLL_HEALTH_MS, NOTIFICATION_DURATION_MS, GLOW_DURATION_MS, MAX_HEATMAP_POINTS, and HEATMAP_HOURS constants to replace hardcoded values throughout script.js for better maintainability. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d025e2623f
commit
230f08fab8
1 changed files with 15 additions and 11 deletions
|
|
@ -302,6 +302,13 @@ const inventoryWindows = {};
|
||||||
const MAX_Z = 20;
|
const MAX_Z = 20;
|
||||||
const FOCUS_ZOOM = 3; // zoom level when you click a name
|
const FOCUS_ZOOM = 3; // zoom level when you click a name
|
||||||
const POLL_MS = 2000;
|
const POLL_MS = 2000;
|
||||||
|
const POLL_RARES_MS = 300000; // 5 minutes
|
||||||
|
const POLL_KILLS_MS = 300000; // 5 minutes
|
||||||
|
const POLL_HEALTH_MS = 30000; // 30 seconds
|
||||||
|
const NOTIFICATION_DURATION_MS = 6000; // Rare notification display time
|
||||||
|
const GLOW_DURATION_MS = 5000; // Player glow after rare find
|
||||||
|
const MAX_HEATMAP_POINTS = 50000;
|
||||||
|
const HEATMAP_HOURS = 24;
|
||||||
// UtilityBelt's more accurate coordinate bounds
|
// UtilityBelt's more accurate coordinate bounds
|
||||||
const MAP_BOUNDS = {
|
const MAP_BOUNDS = {
|
||||||
west: -102.1,
|
west: -102.1,
|
||||||
|
|
@ -557,7 +564,7 @@ function initHeatMap() {
|
||||||
|
|
||||||
async function fetchHeatmapData() {
|
async function fetchHeatmapData() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE}/spawns/heatmap?hours=24&limit=50000`);
|
const response = await fetch(`${API_BASE}/spawns/heatmap?hours=${HEATMAP_HOURS}&limit=${MAX_HEATMAP_POINTS}`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Heat map API error: ${response.status}`);
|
throw new Error(`Heat map API error: ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
@ -1448,12 +1455,9 @@ function startPolling() {
|
||||||
pollTotalKills(); // Initial fetch
|
pollTotalKills(); // Initial fetch
|
||||||
pollServerHealth(); // Initial server health check
|
pollServerHealth(); // Initial server health check
|
||||||
pollID = setInterval(pollLive, POLL_MS);
|
pollID = setInterval(pollLive, POLL_MS);
|
||||||
// Poll total rares every 5 minutes (300,000 ms)
|
setInterval(pollTotalRares, POLL_RARES_MS);
|
||||||
setInterval(pollTotalRares, 300000);
|
setInterval(pollTotalKills, POLL_KILLS_MS);
|
||||||
// Poll total kills every 5 minutes (300,000 ms)
|
setInterval(pollServerHealth, POLL_HEALTH_MS);
|
||||||
setInterval(pollTotalKills, 300000);
|
|
||||||
// Poll server health every 30 seconds (30,000 ms)
|
|
||||||
setInterval(pollServerHealth, 30000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
|
|
@ -2063,14 +2067,14 @@ function processNotificationQueue() {
|
||||||
|
|
||||||
container.appendChild(notifEl);
|
container.appendChild(notifEl);
|
||||||
|
|
||||||
// Remove notification after 6 seconds and process next
|
// Remove notification after display duration and process next
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
notifEl.style.animation = 'notification-slide-out 0.5s ease-in forwards';
|
notifEl.style.animation = 'notification-slide-out 0.5s ease-in forwards';
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
notifEl.remove();
|
notifEl.remove();
|
||||||
processNotificationQueue();
|
processNotificationQueue();
|
||||||
}, 500);
|
}, 500);
|
||||||
}, 6000);
|
}, NOTIFICATION_DURATION_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add slide out animation
|
// Add slide out animation
|
||||||
|
|
@ -2146,10 +2150,10 @@ function highlightRareFinder(characterName) {
|
||||||
const nameSpan = item.querySelector('.player-name');
|
const nameSpan = item.querySelector('.player-name');
|
||||||
if (nameSpan && nameSpan.textContent.includes(characterName)) {
|
if (nameSpan && nameSpan.textContent.includes(characterName)) {
|
||||||
item.classList.add('rare-finder-glow');
|
item.classList.add('rare-finder-glow');
|
||||||
// Remove glow after 5 seconds
|
// Remove glow after duration
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
item.classList.remove('rare-finder-glow');
|
item.classList.remove('rare-finder-glow');
|
||||||
}, 5000);
|
}, GLOW_DURATION_MS);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue