-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer.js
95 lines (91 loc) · 3.04 KB
/
timer.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
let TimerValues = {
StartTime: 0,
CurrentTime: 0,
PauseStartTime: 0,
OverallPauseTime: 0,
OverallTime: 0,
InheritedSaveTime: 0
}
function timerStart() {
TimerValues.StartTime = Date.now();
}
function timerPause() {
TimerValues.PauseStartTime = Date.now();
}
function timerUnpause() {
TimerValues.CurrentTime = Date.now();
TimerValues.OverallPauseTime += Math.abs(Number(TimerValues.CurrentTime) - Number(TimerValues.PauseStartTime));
TimerValues.PauseStartTime = 0;
}
function timerEnd() {
TimerValues.CurrentTime = Date.now();
TimerValues.OverallTime = Math.floor((Math.abs(Number(TimerValues.CurrentTime) - Number(TimerValues.StartTime)) - Number(TimerValues.OverallPauseTime)) / 1000) + TimerValues.InheritedSaveTime;
}
function timerToString() {
return String(Math.floor(TimerValues.OverallTime / 60) + ":" + String("00" + Number(TimerValues.OverallTime % 60) ).slice(-2) + " ([M]M:SS)");
}
function timerToNumber() {
timerEnd(); //doesnt really end it
return Number(Math.floor(TimerValues.OverallTime));
}
function timerReset() {
TimerValues.StartTime = 0;
TimerValues.CurrentTime = 0;
TimerValues.PauseStartTime = 0;
TimerValues.OverallPauseTime = 0;
TimerValues.OverallTime = 0;
TimerValues.InheritedSaveTime = 0;
}
let TimerlimitValues = {
TimeLimit: 0,
StartTime: 0,
CurrentTime: 0,
OverallTime: 0
}
function timelimitStart(minutes, seconds) {
TimerlimitValues.StartTime = Date.now();
TimerlimitValues.TimeLimit = (minutes * 60) + seconds;
}
function timelimitStart(seconds) {
TimerlimitValues.StartTime = Date.now();
TimerlimitValues.TimeLimit = seconds;
}
function timelimitUpdate() {
TimerlimitValues.CurrentTime = Date.now();
TimerlimitValues.OverallTime = Math.floor(Math.abs(Number(TimerlimitValues.CurrentTime) - Number(TimerlimitValues.StartTime)) / 1000);
}
function timelimitToString() {
timelimitUpdate();
return String(
Number(Math.floor((TimerlimitValues.TimeLimit - TimerlimitValues.OverallTime) / 60))
+ ":" + String("00" +
Number((TimerlimitValues.TimeLimit - TimerlimitValues.OverallTime) % 60)
).slice(-2));
}
function timelimitToNumber() {
timelimitUpdate();
return Number(
Math.floor(TimerlimitValues.TimeLimit - TimerlimitValues.OverallTime)
);
}
function timelimitRender(canvasobj) {
timelimitUpdate();
canvasobj.setnewcolor("#ffffff");
canvasobj.setnewfont("Arial, FreeSans", "32");
let text = TranslatedText[SettingsValues.Language][94]+": "+timelimitToString()+" ";
let metrics = canvasobj.context.measureText(text);
canvasobj.box(1000 - metrics.width - 20, 0, metrics.width + 20, 50);
if(TimerlimitValues.TimeLimit - TimerlimitValues.OverallTime <= 10) { canvasobj.setnewcolor("#800000"); }
else { canvasobj.setnewcolor("#333399"); }
canvasobj.text(text, 1000 - metrics.width - 10, 40);
}
function timelimitInfo() {
TranslatedText[SettingsValues.Language][93] + String(
Number(Math.floor((TimerlimitValues.TimeLimit) / 60))
+ ":" + String("00" +
Number((TimerlimitValues.TimeLimit) % 60)
).slice(-2));
}
function timelimitIsDone() {
return (TimerlimitValues.OverallTime >= TimerlimitValues.TimeLimit);
}