- Updated the profile level component to be by itself;
- Made a rough experience and label calculator;
This commit is contained in:
20
src/resources/level.ts
Normal file
20
src/resources/level.ts
Normal 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],
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user