feat: Implement cumulative XP leveling system with new helper functions and update XP bar to show progress within the current level.

This commit is contained in:
syntaxbullet
2025-12-24 18:52:40 +01:00
parent 8c28fe60fc
commit eaaf569f4f
2 changed files with 47 additions and 20 deletions

View File

@@ -97,9 +97,12 @@ export async function generateStudentIdCard(data: StudentCardData): Promise<Buff
ctx.restore();
// Draw XP Bar
const xpForNextLevel = levelingService.getXpForLevel(data.level);
const xpForThisLevel = levelingService.getXpForNextLevel(data.level); // The total size of the current level bucket
const xpAtStartOfLevel = levelingService.getXpToReachLevel(data.level); // The accumulated XP when this level started
const currentLevelProgress = Number(data.xp) - xpAtStartOfLevel; // How much XP into this level
const xpBarMaxWidth = 382;
const xpBarWidth = xpBarMaxWidth * Number(data.xp) / Number(xpForNextLevel);
const xpBarWidth = Math.max(0, Math.min(xpBarMaxWidth, xpBarMaxWidth * currentLevelProgress / xpForThisLevel));
const xpBarHeight = 3;
ctx.save();
ctx.fillStyle = '#B3AD93';