-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.js
316 lines (285 loc) · 9.92 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
$(document).ready(function(){
// Layout script, sets body to window size at start
var bwidth = ($(window).width());
var bheight = ($(window).height());
/* if (bheight < 768 || bwidth < 768) {
alert('The full version is the Damage Report Manager is intended for iPad use only. Detected phone resolution. Redirecting to Timer only edition.');
window.location.replace('timer.html');
} */
bwidth -= 50;
bheight -= 50;
$('body').css('width', bwidth + 'px');
$('body').css('height', bheight + 'px');
$('#loaderready').hide();
$('#loaderbtn').click(function(){
var gameOver = document.getElementsByTagName("audio")[1];
gameOver.play();
$('#loaderbox').fadeOut(1000);
});
/* $('body').css('width', '960px');
$('body').css('height', '640px'); */
// Breach box toggles
$('div#breach').click(function(){
$(this).toggleClass("redbtn");
});
// Settings box toggles
$('#settings').hide();
$('#credits').hide();
$('#redAlert').hide();
$('#gameOver').hide();
$('#setbtn').click(function(){
$('#timer').hide();
$('#settings').show();
});
$('#mainbtn').click(function(){
$('#settings').hide();
$('#timer').show();
});
$('#crsetbtn').click(function(){
$('#credits').hide();
$('#settings').show();
});
$('#crmainbtn').click(function(){
$('#credits').hide();
$('#timer').show();
});
$('#credbtn').click(function(){
$('#settings').hide();
$('#credits').show();
});
// System Status buttons - THIS SUCKS AND NEEDS TO BE REDONE WITH REPEATABLE FUNCTION
// Plasma Capacitor
$('#pcUp').click(function () {
if ($('#pcOut').html() < 100) {
$('#pcOut').html(function (i, val) {
return val * 1 + 10;
});
}
});
$('#pcDown').click(function () {
if ($('#pcOut').html() > 0) {
$('#pcOut').html(function (i, val) {
return val * 1 - 10;
});
}
});
// Flux Generator
$('#fgUp').click(function () {
if ($('#fgOut').html() < 100) {
$('#fgOut').html(function (i, val) {
return val * 1 + 10;
});
}
});
$('#fgDown').click(function () {
if ($('#fgOut').html() > 0) {
$('#fgOut').html(function (i, val) {
return val * 1 - 10;
});
}
});
// Photonic Emitter
$('#peUp').click(function () {
if ($('#peOut').html() < 100) {
$('#peOut').html(function (i, val) {
return val * 1 + 10;
});
}
});
$('#peDown').click(function () {
if ($('#peOut').html() > 0) {
$('#peOut').html(function (i, val) {
return val * 1 - 10;
});
}
});
// Torque Relay
$('#trUp').click(function () {
if ($('#trOut').html() < 100) {
$('#trOut').html(function (i, val) {
return val * 1 + 10;
});
}
});
$('#trDown').click(function () {
if ($('#trOut').html() > 0) {
$('#trOut').html(function (i, val) {
return val * 1 - 10;
});
}
});
// Sonic Modulator
$('#smUp').click(function () {
if ($('#smOut').html() < 100) {
$('#smOut').html(function (i, val) {
return val * 1 + 10;
});
}
});
$('#smDown').click(function () {
if ($('#smOut').html() > 0) {
$('#smOut').html(function (i, val) {
return val * 1 - 10;
});
}
});
// Timer script
// Initialise timer buttons
$('#tmrpause').hide();
$('#tmrresume').hide();
$('#tmrreset').hide();
$('#gameoverdisp').hide();
// Timer display
var timer = Tock({
callback: function () {
$('#tmrdisp').html(function() {
var ms = timer.lap();
// Initialise timer
if (ms <= 0) {
return "0:00.00";
}
// Calculate from raw milliseconds to m:ss.cs
var milliseconds = Math.floor((ms / 10) % 100).toString(),
seconds = Math.floor((ms / 1000) % 60).toString(),
minutes = Math.floor((ms / (60 * 1000)) % 60).toString();
// Add leading 0 to ss.cs
if (milliseconds.length === 1) {
milliseconds = '0' + milliseconds;
}
if (seconds.length === 1) {
seconds = '0' + seconds;
}
// Send result to display
return minutes + ":" + seconds + "." + milliseconds;
});
}
});
// Grab initial countdown interval and deck size from Settings page
var setInterSet = $('#tmrInterSet').val();
var tmrInterval = timer.timeToMS(setInterSet);
var setDRDeck = $('#tmrDRDeck').val();
var setDREvent = $('#tmrDREvent').val();
var drinitdeck = parseInt(setDRDeck, 10); // + parseInt(setDREvent, 10);
var setTotalTmr = tmrInterval * drinitdeck;
$('#setTotTime').html(timer.msToTime(setTotalTmr));
// var tmrInterval = 10000;
// var drinitdeck = 3;
var drnowdeck = drinitdeck;
// $('#tmrlap').html(tmrInterval + ' ' + drinitdeck + ' ' + setInterSet + ' ' + setTotalTmr + ' ' + setDREvent + ' ' + setDRDeck + ' ' + timer.msToTime(setTotalTmr));
// Grab updates to countdown interval and deck size from Settings page
$('#tmrInterSet').change(function() {
setInterSet = $('#tmrInterSet').val();
tmrInterval = timer.timeToMS(setInterSet);
setTotalTmr = tmrInterval * drinitdeck;
$('#setTotTime').html(timer.msToTime(setTotalTmr));
});
$('#tmrDRDeck').change(function() {
setDRDeck = $('#tmrDRDeck').val();
drinitdeck = parseInt(setDRDeck, 10); // + parseInt(setDREvent, 10);
drnowdeck = drinitdeck;
setTotalTmr = tmrInterval * drinitdeck;
$('#setTotTime').html(timer.msToTime(setTotalTmr));
});
$('#tmrDREvent').change(function() {
setDREvent = $('#tmrDREvent').val();
drinitdeck = parseInt(setDRDeck, 10); // + parseInt(setDREvent, 10);
drnowdeck = drinitdeck;
setTotalTmr = tmrInterval * drinitdeck;
$('#setTotTime').html(timer.msToTime(setTotalTmr));
});
// Timer button controls
// Start button - shown on load, hides itself, shows pause
$('#tmrstart').on('click', function () {
timer.start();
countdown.start(tmrInterval);
$('#tmrpause').show();
$('#tmrstart').hide();
$('#setbtn').hide();
$('#tmrreset').hide();
var redAlert = document.getElementsByTagName("audio")[0];
redAlert.play();
});
// Pause button - hidden until start, unhides reset, toggles between self and resume
$('#tmrpause').on('click', function () {
timer.pause();
countdown.pause();
$('#tmrpause').hide();
$('#tmrresume').show();
$('#tmrreset').show();
});
// Resume button - hidden until pause, hides reset toggles between self and pause
$('#tmrresume').on('click', function () {
timer.pause();
countdown.pause();
$('#tmrresume').hide();
$('#tmrpause').show();
$('#tmrreset').hide();
});
// Reset button - resets timer to 0, hidden until pause, shows start and hides self+resume
$('#tmrreset').on('click', function () {
timer.reset();
countdown.stop();
$('#tmrdisp').html('0:00.00');
$('#tmrlap').removeClass('redtext');
$('#tmrdisp').removeClass('redtext');
$('#tmrcount').html('3:00:00');
$('#tmrlap').html('');
$('#gameoverdisp').hide();
$('#tmrresume').hide();
$('#tmrpause').hide();
$('#tmrreset').hide();
$('#tmrdisp').show();
$('#tmrstart').show();
$('#setbtn').show();
drnowdeck = drinitdeck;
});
var countdown = Tock({
countdown : true,
interval : 10,
callback : function () {
$('#tmrcount').html(timer.msToTime(countdown.lap()));
},
complete : function () {
drnowdeck -= 1;
var drdrawcard = drinitdeck - drnowdeck;
countdown.stop();
$('#tmrcount').html('3:00:00');
if (drnowdeck <= 0) {
timer.stop();
$('#tmrpause').hide();
$('#tmrreset').show();
$('#tmrlap').html('');
$('#gameoverdisp').show();
$('#tmrdisp').hide();
var gameOver = document.getElementsByTagName("audio")[1];
gameOver.play();
} else {
if (drnowdeck === 1) {
$('#tmrlap').html('DAMAGE REPORT - Draw Card #' + drdrawcard + '! ' + drnowdeck + ' card remains');
$('#tmrlap').addClass('redtext');
$('#tmrdisp').addClass('redtext');
} else {
$('#tmrlap').html('DAMAGE REPORT - Draw Card #' + drdrawcard + '! ' + drnowdeck + ' cards remain');
}
// $('#tmrlap').html(timer.msToTime(timer.lap()) + ' - DAMAGE REPORT - Draw Card #' + drdrawcard + '! ' + drnowdeck + ' cards remain<br>');
var redAlert = document.getElementsByTagName("audio")[0];
redAlert.play();
countdown.start(tmrInterval);
}
}
});
});
$(window).load(function(){
$('#loaderPop').hide();
$('#loaderready').show();
// $('#loaderbox').fadeOut(500);
});
$(window).resize(function () {
// Layout script, sets body to window size on resize
var bwidth = ($(window).width());
var bheight = ($(window).height());
bwidth -= 50;
bheight -= 50;
$('body').css('width', bwidth + 'px');
$('body').css('height', bheight + 'px');
});