-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
453 lines (394 loc) · 11.9 KB
/
index.html
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<html lang="en">
<head>
<meta charSet="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>FTC Match Counter</title>
</head>
<body>
<red-side>
<current-teams>
<team>?</team>
<team>?</team>
</current-teams>
<next-teams>
<team>?</team>
<team>?</team>
</next-teams>
<queue-teams>
<team>?</team>
<team>?</team>
</queue-teams>
</red-side>
<blue-side>
<current-teams>
<team>?</team>
<team>?</team>
</current-teams>
<next-teams>
<team>?</team>
<team>?</team>
</next-teams>
<queue-teams>
<team>?</team>
<team>?</team>
</queue-teams>
</blue-side>
<round-container>
<round-counter>
<span>Current Match</span>
<round>
?
</round>
</round-counter>
<rankings>
</rankings>
<welcome>
<banner>Robostorm 6.1</banner>
<subtitle>Welcome and Good Luck!</subtitle>
<time></time>
</welcome>
</round-container>
<style>
body {
background-color: #222222;
}
round-container {
display: flex;
align-items: center;
justify-content: center;
margin: 2rem;
}
round-counter {
display: flex;
flex-direction: column;
align-items: center;
font-size: 4vw;
font-family: sans-serif;
color: white;
}
round {
font-size: 17vw;
font-family: monospace;
line-height: 80%;
}
red-side {
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 20vw;
}
blue-side {
position: absolute;
right: 0;
top: 0;
bottom: 0;
width: 20vw;
}
current-teams,
next-teams,
queue-teams {
display: flex;
flex-direction: column;
justify-content: space-between;
left: 0;
right: 0;
position: relative;
margin: 5px;
padding: 20px;
color: white;
font-family: 'Segoe UI', sans-serif;
}
red-side team,
blue-side team {
font-size: 6vw;
line-height: 100%;
font-family: monospace;
}
red-side team {
text-align: right;
}
blue-side team {
text-align: left;
}
red-side > * {
background-color: red;
}
blue-side > * {
background-color: blue;
}
queue-teams::before {
content: "IN QUEUE";
}
next-teams::before {
content: "UP NEXT";
}
current-teams::before {
content: "ON FIELD";
}
blue-side > *::before {
text-align: left;
}
red-side > *::before {
text-align: right;
}
queue-teams::before,
next-teams::before,
current-teams::before {
color: #ddd;
padding-bottom: 2px;
font-size: 2.3vw;
font-weight: bold;
}
rankings {
display: flex;
flex-direction: row;
flex-wrap: wrap;
background: rgba(0, 0, 0, 0.5);
padding: 5px;
position: absolute;
bottom: 0;
left: 20vw;
right: 20vw;
margin: 0 auto;
max-height: 60vh;
justify-content: center;
}
ranking {
background: purple;
display: flex;
flex-direction: column;
margin: 6px;
color: white;
font: 2.5em monospace;
}
ranking team {
padding: 10px;
text-align: center;
box-sizing: border-box;
background: brown;
}
ranking table {
padding: 5px 10px;
width: 100%;
font-size: 2rem;
box-sizing: border-box;
color: white;
}
ranking table td:nth-child(2) {
text-align: right;
}
welcome {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 10;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
background-color: #333;
}
welcome banner {
font: 10vh sans-serif;
color: white;
}
welcome subtitle {
font: 8vh sans-serif;
font-style: italic;
color: #ddd;
}
welcome time {
font: 7vh monospace;
color: white;
margin-top: 30vh;
}
</style>
<script>
const currentRedTeams = document.querySelector('red-side current-teams').children;
const currentBlueTeams = document.querySelector('blue-side current-teams').children;
const queueingRedTeams = document.querySelector('red-side queue-teams').children;
const queueingBlueTeams = document.querySelector('blue-side queue-teams').children;
const nextRedTeams = document.querySelector('red-side next-teams').children;
const nextBlueTeams = document.querySelector('blue-side next-teams').children;
const roundCounter = document.querySelector('round');
const roundCaption = document.querySelector('round-container span');
let ranking = [];
let schedule = null;
let roundEndTask = null;
function populateSchedule(host, event) {
const request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState === XMLHttpRequest.DONE && request.status === 200) {
schedule = JSON.parse(request.responseText).matches;
console.info('Schedule populated');
}
}
request.open('GET', `http://localhost:3000/fetch/http://${host}/api/v1/events/${event}/matches/`);
request.send();
}
function updateRanking(host, event, half) {
const request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState === XMLHttpRequest.DONE && request.status === 200) {
ranking = JSON.parse(request.responseText).rankingList;
ranking.sort((a, b) => a.ranking - b.ranking);
console.info('Rankings rendered');
}
}
request.open('GET', `http://localhost:3000/fetch/http://${host}/api/v1/events/${event}/rankings/`);
request.send();
renderRankings(half);
}
function renderRankings(half) {
const teamCount = half == 0 ? Math.ceil(ranking.length / 2) : Math.floor(ranking.length / 2);
const rankings = document.querySelector('rankings');
rankings.innerHTML = '';
while (rankings.children.length < teamCount)
appendEmptyRanking();
for (let i = 0; i < teamCount; i++)
populateRanking(i, ranking[(Math.ceil(ranking.length / 2) * half) + i]);
}
function appendEmptyRanking() {
document.querySelector('rankings').innerHTML += "<ranking><team></team><table><tbody><tr><td>PLAYED</td><td plays>0</td></tr><tr><td>RP</td><td rp>0</td></tr><tr><td>TBP1</td><td tbp1>0</td></tr><tr><td>TBP2</td><td tbp2>0</td></tr></tbody></table></ranking>";
}
function populateRanking(index, rank) {
const ranking = document.querySelector('rankings').children[index];
const rankExpr = rank.ranking < 1 ? "NP" : `#${rank.ranking}`;
let team = rank.team.toString();
while (team.length < 6)
team += ' ';
ranking.querySelector('team').innerHTML = team.replace(/\s/g, ' ') + rankExpr;
ranking.querySelector('td[plays]').innerText = rank.matchesPlayed;
ranking.querySelector('td[rp]').innerText = rank.rankingPoints;
ranking.querySelector('td[tbp1]').innerText = `${rank.tbp1}`;
ranking.querySelector('td[tbp2]').innerText = `${rank.tbp2}`;
}
function alliancesOfRound(roundNumber) {
if (roundNumber > schedule.length) {
return {red: ['-', ''], blue: ['-', '']};
}
const round = schedule[roundNumber - 1];
return {red: [round.red.team1, round.red.team2], blue: [round.blue.team1, round.blue.team2]};
}
function populateTeams(teamChildren, teams) {
if (teams === undefined)
return;
for (let i = 0; i < teamChildren.length; i++) {
teamChildren[i].innerText = teams[i];
}
}
function showPrep(roundNum) {
const current = alliancesOfRound(roundNum);
const next = alliancesOfRound(roundNum + 1);
const queue = alliancesOfRound(roundNum + 2);
populateTeams(currentRedTeams, current.red);
populateTeams(currentBlueTeams, current.blue);
populateTeams(nextRedTeams, next.red);
populateTeams(nextBlueTeams, next.blue);
populateTeams(queueingRedTeams, queue.red);
populateTeams(queueingBlueTeams, queue.blue);
roundCounter.innerHTML = schedule[roundNum - 1].matchNumber;
roundCaption.innerText = "Preparing Match";
console.info(`Preparing Match ${roundNum}. Teams populated`);
}
function showStart() {
roundCaption.innerText = "Match In Progress";
}
function showAbort() {
roundCaption.innerText = "Match ABORTED";
}
function handleShowPreview(response) {
startBackgroundFlash();
showPrep(response.params.number);
}
function handleStart(response) {
startBackgroundFlash();
showStart();
startRound();
}
function pollBlocking(host, event) {
const request = new WebSocket(`ws://${host}/stream/display/command/?code=${event}`);
request.onopen = () => {
request.send("GET");
}
request.onmessage = (event) => {
const response = JSON.parse(event.data);
if (response.type === "START_MATCH")
handleStart(response);
else if (response.type === "SHOW_PREVIEW")
handleShowPreview(response);
else if (response.type === "ABORT_MATCH") {
startBackgroundFlash();
showAbort();
abortRound();
}
}
}
function startBackgroundFlash() {
function show(color) {
return () => document.body.style.background = color;
}
const schedule = [
[show('#333333'), 500],
[show(''), 500],
[show('#333333'), 500],
[show(''), 500],
[show('#333333'), 500],
[show(''), 500]
];
let index = 0;
function advanceSchedule() {
const i = index++;
if (i < schedule.length) {
schedule[i][0]();
setTimeout(advanceSchedule, schedule[i][1]);
}
}
advanceSchedule();
}
function setupRecurringRankingUpdate(host, event, frequency) {
let half = 0;
return setInterval(() => {
updateRanking(host, event, half);
half = (half + 1) % 2;
}, frequency);
}
function setupTimerUpdate() {
timerUpdate = setInterval(() => {
const timeExpression = new Date().toLocaleTimeString();
document.querySelectorAll('time').forEach(it => it.innerText = timeExpression);
}, 1000);
}
function startRound() {
roundEndTask = setTimeout(() => {
startBackgroundFlash();
roundCaption.innerText = "Match Complete";
}, (120 + 38) * 1000);
}
function abortRound() {
clearTimeout(roundEndTask);
}
const control = {
hideWelcome: function () {
document.querySelector('welcome').style.display = 'none';
},
showWelcome: function (message) {
document.querySelector('welcome').style.display = '';
if (message !== undefined)
document.querySelector('subtitle').innerText = message;
},
initialize: function (host, event) {
populateSchedule(host, event);
pollBlocking(host, event);
setupRecurringRankingUpdate(host, event, 7000);
},
flash: startBackgroundFlash
};
setupTimerUpdate();
</script>
</body>
</html>