forked from challenge-project/challenge-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime.Script.txt
More file actions
134 lines (111 loc) · 3.07 KB
/
Copy pathTime.Script.txt
File metadata and controls
134 lines (111 loc) · 3.07 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
// Time.Script.txt
// by BigBang1112
// part of Universe Library Set
// Various time related functions.
// This library does not depend on any other library from the Universe Library Set.
// You can use this library independently, although it's recommended to use the whole set.
*/
/*
// Compatible contexts:
// - CManiaApp
// - CMode
// - CServerPlugin
*/
/*
// Void Watch_Create(Text _WatchName)
// Void Watch_Remove(Text _WatchName)
// Boolean Watch_Start(Text _WatchName)
// Integer Watch_Track(Text _WatchName)
// Integer Watch_Stop(Text _WatchName)
// Boolean Watch_Pause(Text _WatchName)
// Boolean Watch_Unpause(Text _WatchName)
// Void Stamp_Create(Text _StampName, Integer _Offset)
// Void Stamp_Create(Text _StampName)
// Boolean Stamp_CreateOnce(Text _StampName, Integer _Offset)
// Boolean Stamp_CreateOnce(Text _StampName)
// Void Stamp_Remove(Text _StampName)
// Boolean Stamp_Reached(Text _StampName)
*/
#Struct SPause {
Integer Start;
Integer Time;
}
#Struct SWatch {
Integer StartTime;
SPause[] Pauses;
}
#Struct SStamp {
Integer Time;
}
declare SWatch[Text] Watches;
declare SStamp[Text] Stamps;
Void Watch_Create(Text _WatchName) {
declare SWatch Watch;
Watch.StartTime = -1;
Watches[_WatchName] = Watch;
}
Void Watch_Remove(Text _WatchName) {
declare Removed = Watches.removekey(_WatchName);
}
Boolean Watch_Start(Text _WatchName) {
if(Watches[_WatchName].StartTime == -1)
Watches[_WatchName].StartTime = Now;
else return False;
return True;
}
Integer Watch_Track(Text _WatchName) {
declare Time = Now - Watches[_WatchName].StartTime;
foreach(Pause, Watches[_WatchName].Pauses) Time -= Pause.Time;
return Time;
}
Integer Watch_Stop(Text _WatchName) {
declare EndTime = Watch_Track(_WatchName);
Watch_Create(_WatchName);
return EndTime;
}
Boolean Watch_Pause(Text _WatchName) {
if(Watches[_WatchName].Pauses.count > 0 && Watches[_WatchName].Pauses[Watches[_WatchName].Pauses.count-1].Time != -1) {
declare SPause Pause;
Pause.Start = Now;
Pause.Time = -1;
Watches[_WatchName].Pauses.add(Pause);
return True;
}
return False;
}
Boolean Watch_Unpause(Text _WatchName) {
if(Watches[_WatchName].Pauses.count > 0 && Watches[_WatchName].Pauses[Watches[_WatchName].Pauses.count-1].Time == -1) {
declare LastPause = Watches[_WatchName].Pauses[Watches[_WatchName].Pauses.count-1];
LastPause.Time = Now - LastPause.Start;
return True;
}
return False;
}
Void Stamp_Create(Text _StampName, Integer _Offset) {
declare SStamp Stamp;
Stamp.Time = Now + _Offset;
Stamps[_StampName] = Stamp;
}
Void Stamp_Create(Text _StampName) {
Stamp_Create(_StampName, 0);
}
Boolean Stamp_CreateOnce(Text _StampName, Integer _Offset) {
if(Stamps.existskey(_StampName)) return False;
Stamp_Create(_StampName, _Offset);
return True;
}
Boolean Stamp_CreateOnce(Text _StampName) {
return Stamp_CreateOnce(_StampName, 0);
}
Void Stamp_Remove(Text _StampName) {
declare Removed = Stamps.removekey(_StampName);
}
Boolean Stamp_Reached(Text _StampName) {
if(Stamps.existskey(_StampName))
if(Now >= Stamps[_StampName].Time) {
Stamp_Remove(_StampName);
return True;
}
return False;
}