-
Notifications
You must be signed in to change notification settings - Fork 0
/
Objective.js
106 lines (87 loc) · 2.83 KB
/
Objective.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
class Objective
{
constructor(text, amount, checkBingo)
{
this.text = text;
this.amount = amount;
this.progress = 0;
this.progressElement = null;
this.element = this.createElement();
this.checkBingo = checkBingo;
this.highlighted = false;
}
createElement()
{
const div = document.createElement("div");
const pText = document.createElement("p");
div.classList.add("dvObjective");
div.classList.add("dvObjectiveNotCompleted");
div.addEventListener("mouseup", ((e)=> {
e.stopPropagation();
if (e.button === 0) this.addProgress();
else if (e.button === 2) this.toggleHighlight();
}).bind(this));
div.oncontextmenu = () => { return false; };
div.appendChild(pText);
pText.classList.add("pObjectiveText");
pText.textContent = this.text;
if (this.amount > 1)
{
const dvProgress = document.createElement("div");
const pProgress = document.createElement("p");
const btnUndoProgress = document.createElement("button");
pProgress.classList.add("pProgressText");
pProgress.textContent = this.progress + "/" + this.amount;
btnUndoProgress.classList.add("btnUndoProgress");
btnUndoProgress.textContent = "-";
btnUndoProgress.addEventListener("mouseup", ((e) => {
e.stopPropagation();
this.removeProgress();
}).bind(this));
this.progressElement = pProgress;
dvProgress.appendChild(btnUndoProgress);
dvProgress.appendChild(pProgress);
div.appendChild(dvProgress);
}
return div;
}
updateDisplay()
{
if (this.progressElement) this.progressElement.textContent = this.progress + "/" + this.amount;
this.element.className = "dvObjective";
if (this.progress === this.amount) this.element.classList.add("dvObjectiveCompleted");
else this.element.classList.add("dvObjectiveNotCompleted");
if (this.highlighted) this.element.classList.add("dvObjectiveHighlighted");
}
addProgress()
{
if (this.progress < this.amount)
{
this.progress++;
this.updateDisplay();
this.checkBingo();
}
else
{
if (this.amount === 1)
{
this.removeProgress();
this.checkBingo();
}
}
}
removeProgress()
{
if (this.progress > 0)
{
this.progress--;
this.updateDisplay();
this.checkBingo();
}
}
toggleHighlight()
{
this.highlighted = !this.highlighted;
this.updateDisplay();
}
}