- Updated the profile level component to be by itself;

- Made a rough experience and label calculator;
This commit is contained in:
Tiago Ribeiro
2023-03-07 19:14:37 +00:00
parent 84839c8bc9
commit aa869dd2ce
5 changed files with 81 additions and 24 deletions

20
src/resources/level.ts Normal file
View File

@@ -0,0 +1,20 @@
import JSON_LABELS from "@/constants/levelLabel.json";
const LABELS = JSON_LABELS as {[key: string]: string};
export const levelCalculator = (experience: number) => {
const sqrt = Math.sqrt(experience);
const labelLevel =
Object.keys(LABELS)
.reverse()
.filter((x) => parseInt(x) <= Math.floor(sqrt))
.shift() || Object.keys(LABELS).reverse().shift()!;
return {
currentLevel: Math.floor(sqrt),
nextLevel: Math.ceil(sqrt),
percentage: Math.floor((sqrt - Math.floor(sqrt)) * 100),
nextLevelExperience: Math.pow(Math.ceil(sqrt), 2),
label: LABELS[labelLevel],
};
};