-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
385 lines (346 loc) · 13.1 KB
/
script.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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
$(document).ready(function(){
// Layout script, sets body to window size at start
var bwidth = ($(window).width());
var bheight = ($(window).height());
function isiPhone(){
return (
(navigator.platform.indexOf("iPhone") != -1) ||
(navigator.platform.indexOf("iPod") != -1)
);
}
// $('#tmrlap').html(navigator.platform);
$('#loaderWelcomePhone').hide();
$('#loaderPopPhone').hide();
$('#loaderbtnPhone').hide();
if(isiPhone()){
$('#loaderWelcomePad').hide();
$('#loaderWelcomePhone').show();
$('#loaderPopPad').hide();
$('#loaderPopPhone').show();
$('#loaderbtnPad').hide();
$('#loaderbtnPhone').show();
}
// $('#tmrlap').html(bwidth + ' ' + bheight);
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);
});
// No double tap zooming on buttons when double tapped
$('.updownbutton,.buttons').nodoubletapzoom();
// Breach box toggles
$('div#breach').click(function(){
$(this).toggleClass("redbtn");
});
// Health box toggles
var hideCrisis = function() {
$('#hthCrisisQP').hide();
$('#hthCrisisQN').hide();
$('#hthCrisisTP').hide();
$('#hthCrisisTN').hide();
};
hideCrisis();
$("#hthCrisisSel").change(function() {
var pickMe = $('option:selected', this).val();
hideCrisis();
if (pickMe !== 'hthCrisisDis') {
$('#'+pickMe).show();
}
});
$('div.health_container .healthBar:nth-child(2)').addClass('whiteText');
$('div.health_container .healthBar').click(function(){
$(this).siblings('.healthBar').removeClass('greybtn').removeClass('greyText').removeClass('whiteText');
$(this).removeClass('greybtn').removeClass('greyText').addClass('whiteText');
var boxNum = $(this).index();
var boxes = $(this).parents('.health_container').children('.healthBar');
var startBar = 0;
if (boxNum > 0) {
boxes.slice( startBar, boxNum -1 ).each(function(){
if (!$(this).hasClass('greybtn')){
$(this).addClass('greybtn').addClass('greyText');
}
});
} else {
$(this).removeClass('greybtn').removeClass('greyText').addClass('whiteText');
}
});
// Settings box toggles
$('#settings').hide();
$('#debugBox').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 module display
$('.checkEnabled').change(function() {
var selBox = $(this).attr('id').substring(0,2);
if ($('#' + selBox + 'Enabled').prop('checked')) {
$('#' + selBox + 'Display').show();
} else {
$('#' + selBox + 'Display').hide();
}
});
$('.checkCritical').change(function() {
var selBox = $(this).attr('id').substring(0,2);
if ($('#' + selBox + 'Critical').prop('checked')) {
$('#' + selBox + 'Out').addClass('redtext');
} else {
$('#' + selBox + 'Out').removeClass('redtext');
}
});
// System Status installed in switches
$(".dropSystem").change(function() {
var selBox = $(this).attr('id');
var selBoxId = '#' + selBox;
var selBoxSub = $(this).attr('id').substring(0,2);
var selSysName = $('option:selected', this).text();
$('#' + selBoxSub + 'System').html(selSysName);
var selSysVal = $('option:selected', this).val();
var selSysDefault = 50;
switch(selSysVal) {
case 'sysLifeSup':
selSysDefault = 80;
break;
case 'sysShields':
selSysDefault = 50;
break;
case 'sysHyper':
selSysDefault = 0;
break;
case 'sysTeleport':
selSysDefault = 50;
break;
case 'sysLasers':
selSysDefault = 50;
break;
case 'sysCargoBay':
selSysDefault = 60;
break;
case 'sysEnergy':
selSysDefault = 100;
break;
default:
selSysDefault = 50;
}
$('#' + selBoxSub + 'Out').html(selSysDefault);
$('#' + selBoxSub + 'Out').removeClass('sysLifeSup sysShields sysHyper sysTeleport sysLasers sysCargoBay sysEnergy');
$('#' + selBoxSub + 'Out').removeClass('css100 css90 css80 css70 css60 css50 css40 css30 css20 css10 css0');
$('#' + selBoxSub + 'Out').addClass(selSysVal);
var newCls = 'css' + $('#' + selBoxSub + 'Out').html();
$('#' + selBoxSub + 'Out').addClass(newCls);
});
// System Status buttons - THIS SUCKS AND NEEDS TO BE REDONE WITH REPEATABLE FUNCTION
$('#pcOut').addClass('css50');
$('#fgOut').addClass('css50');
$('#peOut').addClass('css50');
$('#trOut').addClass('css50');
$('#smOut').addClass('css50');
$('.updownbutton').click(function () {
var selBox = $(this).attr('id');
var selBoxSub = $(this).attr('id').substring(0, 2);
var selBoxType = $(this).attr('id').substring(2, 4);
var selBoxVal = parseInt($('#' + selBoxSub + 'Out').html(), 10);
var oldCls = 'css' + $('#' + selBoxSub + 'Out').html();
$('#' + selBoxSub + 'Out').removeClass(oldCls);
if (selBoxType === 'Up') {
if ($('#' + selBoxSub + 'Out').html() < 100) {
selBoxVal += 10;
}
}
if (selBoxType === 'Dn') {
if ($('#' + selBoxSub + 'Out').html() > 0) {
selBoxVal -= 10;
}
}
$('#' + selBoxSub + 'Out').html(selBoxVal);
var newCls = 'css' + $('#' + selBoxSub + 'Out').html();
$('#' + selBoxSub + 'Out').addClass(newCls);
});
$('#showDebug').click(function(){
$('#debugBox').show();
});
// 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();
$('#debugText').append(timer.msToTime(timer.lap()) + ' Interval ' + $('#tmrInterSet').val() + ' set ' + drdrawcard + ' of ' + drinitdeck + '<br />');
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');
}
$('#debugText').append(timer.msToTime(timer.lap()) + ' Interval ' + $('#tmrInterSet').val() + ' set ' + drdrawcard + ' of ' + drinitdeck + '<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');
});