-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
361 lines (309 loc) · 12.8 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
function hideEverything() {
document.getElementById('note-page').style.display = 'none';
document.getElementById('game-page').style.display = 'none';
document.getElementById('endgame-page').style.display = 'none';
}
/*start button to switch to game page*/
function toGamePage() {
document.getElementById('first-page').style.display = 'none';
document.getElementById('game-page').style.display = 'inline-block';
document.getElementById('start-time').value = Date.now();
document.getElementById('off-line').style.display = 'none';
document.getElementById('scoring').style.display = 'none';
document.getElementById('fouls').style.display = 'none';
}
//rotates the slider to be upside down from already rotated position
function flipInitiationLine() {
var initiationLine = document.getElementById('start-slide');
var sector = document.getElementById('sp-sector');
if (sector.innerHTML == ("Shield <br> Generator")) {
initiationLine.style.transform = 'rotate(270deg)';
} else if (sector.innerHTML == ("Sector")) {
initiationLine.style.transform = 'rotate(90deg)';
}
}
//changes the text from "sector" to "shield generator"
function flipSectorGenerator() {
var sector = document.getElementById('sp-sector');
if (sector.innerHTML == ("Sector")) {
sector.innerHTML = "Shield <br> Generator";
} else {
sector.innerHTML = "Sector";
}
}
//changes the text from "shield generator" to "sector"
function flipGeneratorSector() {
var generator = document.getElementById('sp-generator');
if (generator.innerHTML == ("Shield <br> Generator")) {
generator.innerHTML = "Sector";
} else {
generator.innerHTML = "Shield <br> Generator";
}
}
//calls all the functions relating to switching the initiation line orientation
function flip() {
flipGeneratorSector();
flipSectorGenerator();
flipInitiationLine();
console.log("It worked!");
}
function toStartPage() {
document.getElementById('first-page').style.display = 'inline-block';
document.getElementById('game-page').style.display = 'none';
}
/*if this function is called and blue is on the right, something, else, something else*/
function flipField() {
var flipped = document.getElementById('flip-button');
var field = document.getElementById('field-image');
if (field.style.transform == 'rotate(180deg)') {
field.style.transform = null;
} else {
field.style.transform = 'rotate(180deg)';
}
}
function movedOffLine() {
if (document.getElementById('off-line').style.display === 'none') {
document.getElementById('off-line').style.display = 'block';
} else {
document.getElementById('off-line').style.display = 'none';
}
}
function closeOffLine() {
document.getElementById('off-line').style.display = 'none';
}
function coordinates() {
$(document).ready(function () {
$("img").on("click", function (event) {
const x = event.pageX - this.offsetLeft;
const y = event.pageY - this.offsetTop;
document.getElementById('x').value = (x);
document.getElementById('y').value = (y);
});
});
document.getElementById("time").value = Date.now();
}
function showPoints() {
if (document.getElementById('scoring').style.display === 'none') {
document.getElementById('scoring').style.display = 'block';
} else {
document.getElementById('scoring').style.display = 'none';
}
}
function saveShot() {
let i;
document.getElementById("scoring").style.display = 'none';
const x = document.getElementById("x").value;
const y = document.getElementById("y").value;
const inner = document.getElementById("inner").value;
const outer = document.getElementById("outer").value;
const lower = document.getElementById("lower").value;
const miss = document.getElementById("miss").value;
const time = document.getElementById("time").value;
const imgHeight = document.getElementById("field-image").clientHeight;
const imgWidth = document.getElementById("field-image").clientWidth;
const currentWord = document.getElementById("shots").value;
let assembledWord = "";
for (i = 0; i < inner; i++) {
assembledWord = assembledWord + "{(" + x + "," + y + ");INNER;" + time + "};";
}
for (i = 0; i < outer; i++) {
assembledWord = assembledWord + "{(" + x + "," + y + ");OUTER;" + time + "};";
}
for (i = 0; i < lower; i++) {
assembledWord = assembledWord + "{(" + x + "," + y + ");LOWER;" + time + "};";
}
for (i = 0; i < miss; i++) {
assembledWord = assembledWord + "{(" + x + "," + y + ");MISS;" + time + "};";
}
document.getElementById("x").value = 0;
document.getElementById("y").value = 0;
document.getElementById("inner").value = 0;
document.getElementById("outer").value = 0;
document.getElementById("lower").value = 0;
document.getElementById("miss").value = 0;
document.getElementById("time").value = 0;
document.getElementById("shots").value = currentWord + assembledWord;
document.getElementById("img-size").value = "{"+imgWidth+","+imgHeight+"}";
document.getElementById("scoring").style.display = 'none';
}
function showFouls() {
if (document.getElementById('fouls').style.display === 'none') {
document.getElementById('fouls').style.display = 'block';
} else {
document.getElementById('fouls').style.display = 'none';
}
}
function hideFouls() {
document.getElementById('fouls').style.display = 'none';
}
function rotationTime() {
document.getElementById('rotTime').value = Date.now();
document.getElementById("rotation").innerHTML = "ROTATED";
}
function positionTime() {
document.getElementById('posTime').value = Date.now();
document.getElementById('position').innerHTML = "POSITIONED";
}
function showControl() {
document.getElementById('control-panel').style.display = 'block';
}
function hideControl() {
document.getElementById('control-panel').style.display = 'none';
}
/*function to go forward one page*/
function toEndgame() {
document.getElementById('endgame-page').style.display = "inline-block";
document.getElementById('game-page').style.display = "none";
}
function stageOneTime() {
document.getElementById('cap1Time').value = Date.now();
document.getElementById('stage-one').value = "FULL";
}
function stageTwoTime() {
document.getElementById('cap2Time').value = Date.now();
document.getElementById('stage-two').value = "FULL";
}
function stageThreeTime() {
document.getElementById('cap3Time').value = Date.now();
document.getElementById('stage-three').value = "FULL";
}
function showStages() {
document.getElementById('stages').style.display = 'block';
}
function hideStages() {
document.getElementById('stages').style.display = 'none';
}
function backToGamePage() {
document.getElementById('game-page').style.display = 'inline-block';
document.getElementById('endgame-page').style.display = 'none';
}
function toNotesPage() {
document.getElementById('note-page').style.display = 'inline-block';
document.getElementById('endgame-page').style.display = 'none';
}
function backToEnd() {
document.getElementById('endgame-page').style.display = 'inline-block';
document.getElementById('note-page').style.display = 'none';
}
var driverSlider = document.getElementById("driver-rank");
var outputDrive = document.getElementById("display-drive");
var infoBoxDrive = document.getElementById("info-drive");
var hpSlider = document.getElementById("player-rank");
var outputHP = document.getElementById("display-hp");
var infoBoxHP = document.getElementById("info-hp");
var defSlider = document.getElementById("defense-rank");
var outputDef = document.getElementById("display-def");
var infoBoxDef = document.getElementById("info-def");
var defAvoidSlider = document.getElementById("defense-avoid-rank");
var outputDefAvoid = document.getElementById("display-defavoid");
var infoBoxDefAvoid = document.getElementById("info-defavoid");
function setup(){
outputDrive.innerHTML = getName(driverSlider.value);
infoBoxDrive.innerHTML = getTextDrive(driverSlider.value);
outputHP.innerHTML = getName(hpSlider.value);
infoBoxHP.innerHTML = getTextDrive(hpSlider.value);
outputDef.innerHTML = getName(defSlider.value);
infoBoxDef.innerHTML = getTextDrive(defSlider.value);
outputDefAvoid.innerHTML = getName(defAvoidSlider.value);
infoBoxDefAvoid.innerHTML = getTextDrive(defAvoidSlider.value);
}
function getName(slideVal) {
if (slideVal === "1") {
var toReturn = "1 Does Not Meet Standards ";
} else if (slideVal === "2") {
var toReturn = "2 Below average ";
} else if (slideVal === "3") {
var toReturn = "3 Average ";
} else if (slideVal === "4") {
var toReturn = "4 Above Average ";
} else if (slideVal === "5") {
var toReturn = "5 Excellent ";
} else {
var toReturn = "0 N/A ";
}
return toReturn;
}
function getTextDrive(slideVal) {
if (slideVal === "1") {
var toReturn = "Drove poorly, hindered allies, looks lost, can't achieve objectives, start-and-stop motion, looses control.";
} else if (slideVal === "2") {
var toReturn = "Occasionally hinders allies, not efficient at all, trouble lining up.";
} else if (slideVal === "3") {
var toReturn = "Doesn't hinder allies, recovers from mistakes, mostly goes fast enough, may have trouble with defense.";
} else if (slideVal === "4") {
var toReturn = "Doesn't hinder allies, has clear objectives, recovers quickly, few mistakes, aware of other events on the field.";
} else if (slideVal === "5") {
var toReturn = "Doesn't hinder allies at all, very few mistakes, very aware of other robots, seamless recovery, moves to avoid defense, smooth motion.";
}
return toReturn;
}
function getTextHP(slideVal) {
if (slideVal === "1") {
var toReturn = "Got a ton of fouls. Doesn't supply cells to alliance robots.";
} else if (slideVal === "2") {
var toReturn = "No fouls, but ignores alliance robots.";
} else if (slideVal === "3") {
var toReturn = "Unnoticeable, neither good nor bad.";
} else if (slideVal === "4") {
var toReturn = "Robot uses the human player heavily, still no errors.";
} else if (slideVal === "5") {
var toReturn = "Strategically dumps cargo to minimize opponent usage.";
}
return toReturn;
}
function getTextDef(slideVal) {
if (slideVal === "1") {
var toReturn = "Hinders own alliance. Completely inefficient.";
} else if (slideVal === "2") {
var toReturn = "Fairly inefficient, but at least inconveniences opposing alliance.";
} else if (slideVal === "3") {
var toReturn = "Average defense, generally gets in the way and slows down opposition.";
} else if (slideVal === "4") {
var toReturn = "Pretty good, blocks a couple shots and gets in the way.";
} else if (slideVal === "5") {
var toReturn = "Amazing, completely shuts down at least one opposing robot.";
}
return toReturn;
}
function getTextDefAvoid(slideVal) {
if (slideVal === "1") {
var toReturn = "Completely shut down by a not-very-good defender.";
} else if (slideVal === "2") {
var toReturn = "Seems lost on what to do when defended, but manages to score a few.";
} else if (slideVal === "3") {
var toReturn = "Slight trouble getting around defenders, but does ok.";
} else if (slideVal === "4") {
var toReturn = "Has a few struggles getting around, but then manages to avoid defenders well.";
} else if (slideVal === "5") {
var toReturn = "Defense doesn't break their stride; little-to-no impact on scoring.";
}
return toReturn;
}
// Update the current slider value (each time you drag the slider handle)
driverSlider.onchange = function () {
outputDrive.innerHTML = getName(driverSlider.value);
infoBoxDrive.innerHTML = getTextDrive(driverSlider.value);
};
hpSlider.onchange = function () {
outputHP.innerHTML = getName(hpSlider.value);
infoBoxHP.innerHTML = getTextHP(hpSlider.value);
};
defSlider.onchange = function () {
outputDef.innerHTML = getName(defSlider.value);
infoBoxDef.innerHTML = getTextDef(defSlider.value);
};
defAvoidSlider.onchange = function () {
outputDefAvoid.innerHTML = getName(defAvoidSlider.value);
infoBoxDefAvoid.innerHTML = getTextDefAvoid(defAvoidSlider.value);
};
function startClimb() {
document.getElementById('climb-start').value = Date.now();
document.getElementById('begin-climb').innerHTML = "BEGUN";
}
function endClimb() {
document.getElementById('climb-end').value = Date.now();
document.getElementById('stop-climb').innerHTML = "COMPLETED";
}
function inc(elementID){
document.getElementById(elementID).value = Number(document.getElementById(elementID).value) +Number(1);
}