Skip to content

Commit eb30e3d

Browse files
authored
feat: define XP constants for all events and secrets (NextCommunity#321)
* 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 NextCommunity#285 * fix: replace remaining magic number in initSkillXP * style: apply prettier formatting
1 parent 0daaeab commit eb30e3d

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

src/assets/js/script.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
const XP_PER_LEVEL = 45;
2+
3+
// XP rewards for events and secrets
4+
const XP_MOUSE_HOVER = 1; // Base XP for mouse interactions
5+
const XP_FORCE_SURGE_TICK = 10; // XP per tick during Force Surge
6+
const XP_FORCE_SURGE_TOTAL = 1000; // Total XP from Force Surge event
7+
const XP_MAGIC_BONUS = 50; // Magic XP bonus
8+
const XP_MATRIX_SECRET = 75; // Matrix easter egg unlock
9+
const XP_PULSE_SECRET = 180; // Pulse dot easter egg
10+
const XP_GRAVITY_SECRET = 250; // Gravity effect easter egg
11+
const XP_KONAMI_SECRET = 500; // Konami code easter egg
12+
const XP_FOOTER_SURGE = 1000; // Footer surge secret
13+
const XP_BADGE_CLICK = 45; // Badge click reward
14+
215
const NUM_LEVELS = LEVELS.length;
316
// Load saved level or start at 0
417
let currentLevel = Number(localStorage.getItem("userLevel")) || 0;
@@ -236,7 +249,7 @@ window.createFloatingXP = function (e) {
236249
// 2. Styling (Tailwind classes + Inline for positioning)
237250
popup.className =
238251
"fixed pointer-events-none z-[999] font-black text-sm tracking-tighter animate-xp-float";
239-
popup.innerText = "+1 XP";
252+
popup.innerText = `+${XP_MOUSE_HOVER} XP`;
240253

241254
// 3. Get current Rank color for the "Pop"
242255
const rank = getRank(currentLevel);
@@ -250,7 +263,7 @@ window.createFloatingXP = function (e) {
250263

251264
// 5. Award XP and update that "Newbie" header
252265
if (typeof addExperience === "function") {
253-
addExperience(1);
266+
addExperience(XP_MOUSE_HOVER);
254267
}
255268

256269
// 6. Cleanup
@@ -433,9 +446,9 @@ function triggerForceSurge() {
433446
// 4. XP Logic
434447
let currentXPAdded = 0;
435448
const xpInt = setInterval(() => {
436-
addExperience(10);
437-
currentXPAdded += 10;
438-
if (currentXPAdded >= 1000) clearInterval(xpInt);
449+
addExperience(XP_FORCE_SURGE_TICK);
450+
currentXPAdded += XP_FORCE_SURGE_TICK;
451+
if (currentXPAdded >= XP_FORCE_SURGE_TOTAL) clearInterval(xpInt);
439452
}, 50);
440453

441454
// 5. Cleanup
@@ -449,7 +462,7 @@ function triggerForceSurge() {
449462

450463
function triggerMagicXP() {
451464
initAudio();
452-
addExperience(50);
465+
addExperience(XP_MAGIC_BONUS);
453466
}
454467

455468
function triggerSecretUnlock(type) {
@@ -476,18 +489,18 @@ function triggerSecretUnlock(type) {
476489

477490
// Assign XP based on difficulty
478491
if (type === "konami") {
479-
addExperience(500); // Massive bonus for the long code
492+
addExperience(XP_KONAMI_SECRET);
480493
} else if (type === "gravity") {
481-
addExperience(250); // 1 full level
494+
addExperience(XP_GRAVITY_SECRET);
482495
} else if (type === "pulse") {
483-
addExperience(180); // 4 levels
496+
addExperience(XP_PULSE_SECRET);
484497
} else if (type === "footer_surge") {
485-
addExperience(1000); // 4 levels
498+
addExperience(XP_FOOTER_SURGE);
486499
} else if (type === "badge_click") {
487-
addExperience(45); // 4 levels
500+
addExperience(XP_BADGE_CLICK);
488501
} else {
489502
// matrix
490-
addExperience(75); // 2 full levels
503+
addExperience(XP_MATRIX_SECRET);
491504
}
492505

493506
console.log(`✨ Secret Unlocked: ${eggId}`);
@@ -726,7 +739,7 @@ function triggerBadgeLevelUp() {
726739
playSound("secret");
727740

728741
// Force a level up for the "first time" experience
729-
addExperience(45); // Assuming 45 XP = 1 Level
742+
addExperience(XP_PER_LEVEL);
730743

731744
hasTriggeredFirstLevel = true;
732745

@@ -1203,7 +1216,7 @@ function initSkillXP() {
12031216
.getElementById("dev-tools")
12041217
?.hasAttribute("data-lock");
12051218
if (!isLocked) {
1206-
addExperience(1);
1219+
addExperience(XP_MOUSE_HOVER);
12071220
createFloatingXP(e);
12081221

12091222
// Fancy scale-up on hover

0 commit comments

Comments
 (0)