Fixed bug with CSV parsing where levels were calculated incorrectly.

This commit is contained in:
JustinOros
2025-10-29 09:20:05 -07:00
parent 1a4d47d97e
commit 97bcceaf75
+8 -11
View File
@@ -117,18 +117,15 @@
const response = await fetch('levels.csv');
const text = await response.text();
const lines = text.trim().split('\n');
xpThresholds = text
.trim()
.split('\n')
.map(line => {
const parts = line.split(',');
return parseInt(parts[1].replace(/,/g, ''), 10);
});
let cumulative = 0;
xpThresholds = lines.map((line, i) => {
const parts = line.split(',');
let xp = parseInt(parts[1].replace(/,/g, ''), 10);
if (i === 0) return 0; // Level 1 starts at 0 XP
cumulative += xp;
return cumulative;
});
console.log("Loaded cumulative XP thresholds:", xpThresholds);
console.log("Loaded XP thresholds (cumulative):", xpThresholds);
} catch (error) {
alert("Failed to load levels.csv. Please ensure it's in the same folder as index.html.");
console.error(error);