-
Notifications
You must be signed in to change notification settings - Fork 1
/
global.js
61 lines (50 loc) · 1.81 KB
/
global.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, { useState } from 'react';
import { firebaseApp } from "./firebase.config";
import { doc, setDoc, getDoc, updateDoc } from "firebase/firestore";
import { getFirestore } from "firebase/firestore";
import { UpdateLevel } from './Firebasebackend/UpdateLevel';
import { refresh } from './screens/Leaderboard';
//initialising database
const db = getFirestore(firebaseApp);
global.XP = 0;
global.username = "";
global.email = "hello"; //used to access the respective collection
global.leaderboard = [];
global.friends = []; //contains information about friends
global.friendemails = []; //used for querying for friends
global.level = 1;
global.activities = [] //used for showing recent activities of user
global.calendar = null //used to keep track of events
{/*Give exp to user*/}
global.updateCoins = (amount) => {
const docref = doc(db, "Users", global.email);
let levelledUp = false;
global.XP = amount + global.XP;
console.log(global.XP);
let fullexp = (Math.floor(global.level / 10) + 1) * 50;
while (global.XP >= fullexp) {
global.XP -= fullexp;
global.level++;
fullexp = (Math.floor(global.level / 10) + 1) * 50;
levelledUp = true;
}
if (levelledUp) {
refresh();
UpdateLevel();
}
updateDoc(docref, {
coins: global.XP,
level: global.level,
})
}
global.signOut = () => {
global.XP = 0;
global.username = "";
global.email = "hello"; //used to access the respective collection
global.leaderboard = [];
global.friends = []; //contains information about friends
global.friendemails = []; //used for querying for friends
global.level = 1;
global.activities = [] //used for showing recent activities of user
}
export default global;