Skip to content

Commit 5db378f

Browse files
committed
Set minimum level to 1
1 parent 5c1c6d5 commit 5db378f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/store/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default createStore({
55
state: {
66
todos: [] as any[],
77
user: {
8-
level: 0 as number,
8+
level: 1 as number, //set level to 1 as total xp is 0 when state is created
99
xp: 0 as number,
1010
progress: 0 as number,
1111
},
@@ -75,11 +75,16 @@ export default createStore({
7575
1
7676
); //get at least 1 xp when the task is completed
7777
state.user.xp += xp; //get amount of xp earned based on task difficulty, task priority, task due date and task repetition
78-
state.user.level = Math.floor(Math.pow(state.user.xp, 1 / 3 + 5e-16)); //calculate level based on how many xp
78+
state.user.level = Math.max(
79+
1,
80+
Math.floor(Math.pow(state.user.xp, 1 / 3 + 5e-16))
81+
); //calculate level based on how many xp and set level to 1 if total xp is 0
7982
state.user.progress =
80-
((state.user.xp - Math.pow(state.user.level, 3)) /
81-
(Math.pow(state.user.level + 1, 3) - Math.pow(state.user.level, 3))) *
82-
100; //calculate level progress
83+
((state.user.xp -
84+
Math.pow(state.user.level == 1 ? 0 : state.user.level, 3)) /
85+
(Math.pow(state.user.level + 1, 3) -
86+
Math.pow(state.user.level == 1 ? 0 : state.user.level, 3))) *
87+
100; //calculate level progress and if level is 1 set total xp at the start of level 1 to 0 xp
8388
},
8489
create_Todo: (state, payload) => {
8590
const createTask = {

0 commit comments

Comments
 (0)