From 6684f2524a1993ec9c6f07dccfd6e3250fec437e Mon Sep 17 00:00:00 2001 From: Subham Sangwan Date: Thu, 29 Jan 2026 12:47:18 +0530 Subject: [PATCH 1/3] feat: define XP constants for all events and secrets - Add XP constants section at top of script.js - Replace all magic numbers with descriptive constants - Improves maintainability and readability Fixes #285 --- src/assets/js/script.js | 49 +++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/assets/js/script.js b/src/assets/js/script.js index 2815b4b..5f3891e 100644 --- a/src/assets/js/script.js +++ b/src/assets/js/script.js @@ -1,4 +1,17 @@ const XP_PER_LEVEL = 45; + +// XP rewards for events and secrets +const XP_MOUSE_HOVER = 1; // Base XP for mouse interactions +const XP_FORCE_SURGE_TICK = 10; // XP per tick during Force Surge +const XP_FORCE_SURGE_TOTAL = 1000; // Total XP from Force Surge event +const XP_MAGIC_BONUS = 50; // Magic XP bonus +const XP_MATRIX_SECRET = 75; // Matrix easter egg unlock +const XP_PULSE_SECRET = 180; // Pulse dot easter egg +const XP_GRAVITY_SECRET = 250; // Gravity effect easter egg +const XP_KONAMI_SECRET = 500; // Konami code easter egg +const XP_FOOTER_SURGE = 1000; // Footer surge secret +const XP_BADGE_CLICK = 45; // Badge click reward + const NUM_LEVELS = LEVELS.length; // Load saved level or start at 0 let currentLevel = Number(localStorage.getItem("userLevel")) || 0; @@ -236,7 +249,7 @@ window.createFloatingXP = function (e) { // 2. Styling (Tailwind classes + Inline for positioning) popup.className = "fixed pointer-events-none z-[999] font-black text-sm tracking-tighter animate-xp-float"; - popup.innerText = "+1 XP"; + popup.innerText = `+${XP_MOUSE_HOVER} XP`; // 3. Get current Rank color for the "Pop" const rank = getRank(currentLevel); @@ -250,7 +263,7 @@ window.createFloatingXP = function (e) { // 5. Award XP and update that "Newbie" header if (typeof addExperience === "function") { - addExperience(1); + addExperience(XP_MOUSE_HOVER); } // 6. Cleanup @@ -433,9 +446,9 @@ function triggerForceSurge() { // 4. XP Logic let currentXPAdded = 0; const xpInt = setInterval(() => { - addExperience(10); - currentXPAdded += 10; - if (currentXPAdded >= 1000) clearInterval(xpInt); + addExperience(XP_FORCE_SURGE_TICK); + currentXPAdded += XP_FORCE_SURGE_TICK; + if (currentXPAdded >= XP_FORCE_SURGE_TOTAL) clearInterval(xpInt); }, 50); // 5. Cleanup @@ -449,7 +462,7 @@ function triggerForceSurge() { function triggerMagicXP() { initAudio(); - addExperience(50); + addExperience(XP_MAGIC_BONUS); } function triggerSecretUnlock(type) { @@ -476,18 +489,18 @@ function triggerSecretUnlock(type) { // Assign XP based on difficulty if (type === "konami") { - addExperience(500); // Massive bonus for the long code + addExperience(XP_KONAMI_SECRET); } else if (type === "gravity") { - addExperience(250); // 1 full level + addExperience(XP_GRAVITY_SECRET); } else if (type === "pulse") { - addExperience(180); // 4 levels + addExperience(XP_PULSE_SECRET); } else if (type === "footer_surge") { - addExperience(1000); // 4 levels + addExperience(XP_FOOTER_SURGE); } else if (type === "badge_click") { - addExperience(45); // 4 levels + addExperience(XP_BADGE_CLICK); } else { // matrix - addExperience(75); // 2 full levels + addExperience(XP_MATRIX_SECRET); } console.log(`✨ Secret Unlocked: ${eggId}`); @@ -612,12 +625,10 @@ function activateGravityEffect() { ); targets.forEach((el) => { const dist = window.innerHeight + 1000; - el.style.transition = `transform ${ - 1 + Math.random() - }s ease-in, opacity 1s`; - el.style.transform = `translateY(${dist}px) rotate(${ - Math.random() * 60 - 30 - }deg)`; + el.style.transition = `transform ${1 + Math.random() + }s ease-in, opacity 1s`; + el.style.transform = `translateY(${dist}px) rotate(${Math.random() * 60 - 30 + }deg)`; el.style.opacity = "0"; el.style.pointerEvents = "none"; }); @@ -726,7 +737,7 @@ function triggerBadgeLevelUp() { playSound("secret"); // Force a level up for the "first time" experience - addExperience(45); // Assuming 45 XP = 1 Level + addExperience(XP_PER_LEVEL); hasTriggeredFirstLevel = true; From 8a7c400953eab940695cafa0225bbd45ed8d66fa Mon Sep 17 00:00:00 2001 From: Subham Sangwan Date: Thu, 29 Jan 2026 12:48:21 +0530 Subject: [PATCH 2/3] fix: replace remaining magic number in initSkillXP --- src/assets/js/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assets/js/script.js b/src/assets/js/script.js index 5f3891e..12354b7 100644 --- a/src/assets/js/script.js +++ b/src/assets/js/script.js @@ -1214,7 +1214,7 @@ function initSkillXP() { .getElementById("dev-tools") ?.hasAttribute("data-lock"); if (!isLocked) { - addExperience(1); + addExperience(XP_MOUSE_HOVER); createFloatingXP(e); // Fancy scale-up on hover From 0dc3e89dcfc14aba6592a10569852301299df260 Mon Sep 17 00:00:00 2001 From: Subham Sangwan Date: Thu, 29 Jan 2026 12:57:36 +0530 Subject: [PATCH 3/3] style: apply prettier formatting --- src/assets/js/script.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/assets/js/script.js b/src/assets/js/script.js index 12354b7..a6d41a9 100644 --- a/src/assets/js/script.js +++ b/src/assets/js/script.js @@ -1,16 +1,16 @@ const XP_PER_LEVEL = 45; // XP rewards for events and secrets -const XP_MOUSE_HOVER = 1; // Base XP for mouse interactions -const XP_FORCE_SURGE_TICK = 10; // XP per tick during Force Surge -const XP_FORCE_SURGE_TOTAL = 1000; // Total XP from Force Surge event -const XP_MAGIC_BONUS = 50; // Magic XP bonus -const XP_MATRIX_SECRET = 75; // Matrix easter egg unlock -const XP_PULSE_SECRET = 180; // Pulse dot easter egg -const XP_GRAVITY_SECRET = 250; // Gravity effect easter egg -const XP_KONAMI_SECRET = 500; // Konami code easter egg -const XP_FOOTER_SURGE = 1000; // Footer surge secret -const XP_BADGE_CLICK = 45; // Badge click reward +const XP_MOUSE_HOVER = 1; // Base XP for mouse interactions +const XP_FORCE_SURGE_TICK = 10; // XP per tick during Force Surge +const XP_FORCE_SURGE_TOTAL = 1000; // Total XP from Force Surge event +const XP_MAGIC_BONUS = 50; // Magic XP bonus +const XP_MATRIX_SECRET = 75; // Matrix easter egg unlock +const XP_PULSE_SECRET = 180; // Pulse dot easter egg +const XP_GRAVITY_SECRET = 250; // Gravity effect easter egg +const XP_KONAMI_SECRET = 500; // Konami code easter egg +const XP_FOOTER_SURGE = 1000; // Footer surge secret +const XP_BADGE_CLICK = 45; // Badge click reward const NUM_LEVELS = LEVELS.length; // Load saved level or start at 0 @@ -625,10 +625,12 @@ function activateGravityEffect() { ); targets.forEach((el) => { const dist = window.innerHeight + 1000; - el.style.transition = `transform ${1 + Math.random() - }s ease-in, opacity 1s`; - el.style.transform = `translateY(${dist}px) rotate(${Math.random() * 60 - 30 - }deg)`; + el.style.transition = `transform ${ + 1 + Math.random() + }s ease-in, opacity 1s`; + el.style.transform = `translateY(${dist}px) rotate(${ + Math.random() * 60 - 30 + }deg)`; el.style.opacity = "0"; el.style.pointerEvents = "none"; });