-
Notifications
You must be signed in to change notification settings - Fork 1
/
BackgroundImage.js
54 lines (52 loc) · 1.47 KB
/
BackgroundImage.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
class BackgroundImage {
achievements = '';
time = '';
background;
foreground;
constructor(background, foreground) {
this.background = background;
this.foreground = foreground;
}
updateBackground() {
let timeApplied = false;
//Background
if (this.achievements != '') {
this.background.src = 'assets/generic/' + this.achievements + '.png';
} else if (this.time != '') {
this.background.src = 'assets/generic/' + this.time + '.png';
timeApplied = true;
} else {
this.background.src = 'assets/generic/default.png';
}
//Foreground
!timeApplied && this.time
? (this.foreground.src = 'assets/generic/part_' + this.time + '.png')
: (this.foreground.src = '');
}
setAchievements(percentage) {
if (percentage < 33) {
this.achievements = '';
} else if (percentage >= 33 && percentage < 66) {
this.achievements = 'bronze';
} else if (percentage >= 66 && percentage < 99) {
this.achievements = 'silver';
} else if (percentage >= 99) {
this.achievements = 'gold';
}
this.updateBackground();
}
setTime(hours) {
if (hours < 10) {
this.time = '';
} else if (hours >= 10 && hours < 20) {
this.time = 'ruby';
} else if (hours >= 20 && hours < 40) {
this.time = 'emerald';
} else if (hours >= 40 && hours < 80) {
this.time = 'diamond';
} else if (hours >= 80) {
this.time = 'obsidian';
}
this.updateBackground();
}
}