blob: 7be54b386c0774e1a98db816ff8fe11be2f8c2b6 [file] [log] [blame]
Philipp Schrader817cce32022-03-26 15:00:00 -07001import {
2 Component,
3 ElementRef,
4 EventEmitter,
5 Input,
6 OnInit,
7 Output,
8 ViewChild,
9} from '@angular/core';
Ravago Jones2813c032022-03-16 23:44:11 -070010import {FormsModule} from '@angular/forms';
James Kuszmauldac091f2022-03-22 09:35:06 -070011import {Builder, ByteBuffer} from 'flatbuffers';
Philipp Schraderd7efa2b2023-02-17 21:15:13 -080012import {ErrorResponse} from '../../webserver/requests/messages/error_response_generated';
Philipp Schrader817cce32022-03-26 15:00:00 -070013import {
Filip Kujawa0ef334c2023-02-20 19:42:45 -080014 StartMatchAction,
Emily Markovadcadcb62024-02-03 13:07:17 -080015 ScoreType,
16 StageType,
17 Submit2024Actions,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -070018 MobilityAction,
Emily Markovadcadcb62024-02-03 13:07:17 -080019 PenaltyAction,
20 PickupNoteAction,
21 PlaceNoteAction,
Filip Kujawa0ef334c2023-02-20 19:42:45 -080022 RobotDeathAction,
23 EndMatchAction,
24 ActionType,
25 Action,
Emily Markovadcadcb62024-02-03 13:07:17 -080026} from '../../webserver/requests/messages/submit_2024_actions_generated';
Philipp Schrader8702b782023-04-15 17:33:37 -070027import {Match} from '../../webserver/requests/messages/request_all_matches_response_generated';
Philipp Schraderba072d92024-02-21 17:00:37 -080028import {MatchListRequestor} from '../rpc';
Philipp Schrader8b8ed672022-03-05 18:08:50 -080029
Philipp Schrader817cce32022-03-26 15:00:00 -070030type Section =
31 | 'Team Selection'
Filip Kujawa0ef334c2023-02-20 19:42:45 -080032 | 'Init'
33 | 'Pickup'
34 | 'Place'
35 | 'Endgame'
36 | 'Dead'
Philipp Schrader817cce32022-03-26 15:00:00 -070037 | 'Review and Submit'
38 | 'Success';
Philipp Schrader80587432022-03-05 15:41:22 -080039
Philipp Schrader8aeb14f2022-04-08 21:23:18 -070040// TODO(phil): Deduplicate with match_list.component.ts.
41const COMP_LEVELS = ['qm', 'ef', 'qf', 'sf', 'f'] as const;
42type CompLevel = typeof COMP_LEVELS[number];
43
44// TODO(phil): Deduplicate with match_list.component.ts.
45const COMP_LEVEL_LABELS: Record<CompLevel, string> = {
46 qm: 'Qualifications',
47 ef: 'Eighth Finals',
48 qf: 'Quarter Finals',
49 sf: 'Semi Finals',
50 f: 'Finals',
51};
52
Filip Kujawa0ef334c2023-02-20 19:42:45 -080053type ActionT =
54 | {
55 type: 'startMatchAction';
56 timestamp?: number;
57 position: number;
58 }
59 | {
Filip Kujawa0b4b1e52023-04-15 14:05:40 -070060 type: 'mobilityAction';
61 timestamp?: number;
62 mobility: boolean;
63 }
64 | {
Emily Markovadcadcb62024-02-03 13:07:17 -080065 type: 'pickupNoteAction';
Filip Kujawa4413a592023-03-01 10:54:34 -080066 timestamp?: number;
Filip Kujawa0ef334c2023-02-20 19:42:45 -080067 auto?: boolean;
68 }
69 | {
Emily Markovadcadcb62024-02-03 13:07:17 -080070 type: 'placeNoteAction';
Filip Kujawa0ef334c2023-02-20 19:42:45 -080071 timestamp?: number;
Emily Markovadcadcb62024-02-03 13:07:17 -080072 scoreType: ScoreType;
Filip Kujawa0ef334c2023-02-20 19:42:45 -080073 auto?: boolean;
74 }
75 | {
76 type: 'robotDeathAction';
77 timestamp?: number;
Emily Markova040123c2024-02-27 09:48:37 -080078 robotDead: boolean;
Filip Kujawa0ef334c2023-02-20 19:42:45 -080079 }
80 | {
Emily Markovadcadcb62024-02-03 13:07:17 -080081 type: 'penaltyAction';
82 timestamp?: number;
83 penalties: number;
84 }
85 | {
Filip Kujawa0ef334c2023-02-20 19:42:45 -080086 type: 'endMatchAction';
Emily Markovadcadcb62024-02-03 13:07:17 -080087 stageType: StageType;
88 trapNote: boolean;
Emily Markova6079e2f2024-02-17 13:17:24 -080089 spotlight: boolean;
Filip Kujawa0ef334c2023-02-20 19:42:45 -080090 timestamp?: number;
91 }
92 | {
93 // This is not a action that is submitted,
94 // It is used for undoing purposes.
95 type: 'endAutoPhase';
96 timestamp?: number;
Emily Markovadcadcb62024-02-03 13:07:17 -080097 }
98 | {
99 // This is not a action that is submitted,
100 // It is used for undoing purposes.
101 type: 'endTeleopPhase';
102 timestamp?: number;
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800103 };
emilym38d08ba2022-10-22 15:25:01 -0700104
Philipp Schrader23993e82022-03-18 18:54:00 -0700105@Component({
106 selector: 'app-entry',
107 templateUrl: './entry.ng.html',
Philipp Schrader175a93c2023-02-19 13:13:40 -0800108 styleUrls: ['../app/common.css', './entry.component.css'],
Philipp Schrader23993e82022-03-18 18:54:00 -0700109})
Philipp Schrader75021f52023-04-09 21:14:13 -0700110export class EntryComponent implements OnInit {
Philipp Schrader36df73a2022-03-17 23:27:24 -0700111 // Re-export the type here so that we can use it in the `[value]` attribute
112 // of radio buttons.
Philipp Schrader8aeb14f2022-04-08 21:23:18 -0700113 readonly COMP_LEVELS = COMP_LEVELS;
114 readonly COMP_LEVEL_LABELS = COMP_LEVEL_LABELS;
Emily Markovadcadcb62024-02-03 13:07:17 -0800115 readonly ScoreType = ScoreType;
Emily Markova6079e2f2024-02-17 13:17:24 -0800116 readonly StageType = StageType;
Philipp Schrader36df73a2022-03-17 23:27:24 -0700117
Ravago Jones2813c032022-03-16 23:44:11 -0700118 section: Section = 'Team Selection';
Ravago Jones2813c032022-03-16 23:44:11 -0700119 @Input() matchNumber: number = 1;
Emily Markovae68b7632023-12-30 14:17:55 -0800120 @Input() teamNumber: string = '1';
Philipp Schrader30b4a682022-04-16 14:36:17 -0700121 @Input() setNumber: number = 1;
Philipp Schrader8aeb14f2022-04-08 21:23:18 -0700122 @Input() compLevel: CompLevel = 'qm';
Philipp Schrader75021f52023-04-09 21:14:13 -0700123 @Input() skipTeamSelection = false;
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800124
Philipp Schrader8702b782023-04-15 17:33:37 -0700125 matchList: Match[] = [];
126
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800127 actionList: ActionT[] = [];
Philipp Schrader8702b782023-04-15 17:33:37 -0700128 progressMessage: string = '';
Ravago Jones2813c032022-03-16 23:44:11 -0700129 errorMessage: string = '';
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800130 autoPhase: boolean = true;
Filip Kujawab73e94c2023-04-19 09:33:14 -0700131 mobilityCompleted: boolean = false;
Evelyn Yangc8036b12023-10-11 21:14:46 -0700132 selectedValue = 0;
133 nextTeamNumber = '';
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800134
Philipp Schradere1498852023-04-15 18:06:45 -0700135 preScouting: boolean = false;
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800136 matchStartTimestamp: number = 0;
Emily Markovadcadcb62024-02-03 13:07:17 -0800137 penalties: number = 0;
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800138
Philipp Schrader8702b782023-04-15 17:33:37 -0700139 teamSelectionIsValid = false;
140
141 constructor(private readonly matchListRequestor: MatchListRequestor) {}
142
Philipp Schrader75021f52023-04-09 21:14:13 -0700143 ngOnInit() {
144 // When the user navigated from the match list, we can skip the team
145 // selection. I.e. we trust that the user clicked the correct button.
146 this.section = this.skipTeamSelection ? 'Init' : 'Team Selection';
Evelyn Yangc8036b12023-10-11 21:14:46 -0700147 this.fetchMatchList();
148 }
Philipp Schrader8702b782023-04-15 17:33:37 -0700149
Evelyn Yangc8036b12023-10-11 21:14:46 -0700150 goToNextTeam() {
151 this.ngOnInit();
152 this.teamNumber = this.nextTeamNumber;
153 this.nextTeamNumber = '';
Philipp Schrader8702b782023-04-15 17:33:37 -0700154 }
155
156 async fetchMatchList() {
157 this.progressMessage = 'Fetching match list. Please be patient.';
158 this.errorMessage = '';
159
160 try {
161 this.matchList = await this.matchListRequestor.fetchMatchList();
162 this.progressMessage = 'Successfully fetched match list.';
163 } catch (e) {
164 this.errorMessage = e;
165 this.progressMessage = '';
166 }
167 }
168
169 // This gets called when the user changes something on the Init screen.
170 // It makes sure that the user can't click "Next" until the information is
Philipp Schradere1498852023-04-15 18:06:45 -0700171 // valid, or this is for pre-scouting.
Philipp Schrader8702b782023-04-15 17:33:37 -0700172 updateTeamSelectionValidity(): void {
Philipp Schradere1498852023-04-15 18:06:45 -0700173 this.teamSelectionIsValid = this.preScouting || this.matchIsInMatchList();
Philipp Schrader8702b782023-04-15 17:33:37 -0700174 }
175
176 matchIsInMatchList(): boolean {
177 // If the user deletes the content of the teamNumber field, the value here
178 // is undefined. Guard against that.
179 if (this.teamNumber == null) {
180 return false;
181 }
Philipp Schrader8702b782023-04-15 17:33:37 -0700182
183 for (const match of this.matchList) {
184 if (
185 this.matchNumber == match.matchNumber() &&
186 this.setNumber == match.setNumber() &&
187 this.compLevel == match.compLevel() &&
Evelyn Yangc8036b12023-10-11 21:14:46 -0700188 (this.teamNumber === match.r1() ||
189 this.teamNumber === match.r2() ||
190 this.teamNumber === match.r3() ||
191 this.teamNumber === match.b1() ||
192 this.teamNumber === match.b2() ||
193 this.teamNumber === match.b3())
Philipp Schrader8702b782023-04-15 17:33:37 -0700194 ) {
195 return true;
196 }
197 }
198 return false;
Philipp Schrader75021f52023-04-09 21:14:13 -0700199 }
200
Emily Markovadcadcb62024-02-03 13:07:17 -0800201 addPenalty(): void {
202 this.penalties += 1;
203 }
204
205 removePenalty(): void {
206 if (this.penalties > 0) {
207 this.penalties -= 1;
208 }
209 }
210
211 addPenalties(): void {
212 this.addAction({type: 'penaltyAction', penalties: this.penalties});
213 }
214
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800215 addAction(action: ActionT): void {
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800216 if (action.type == 'startMatchAction') {
217 // Unix nanosecond timestamp.
218 this.matchStartTimestamp = Date.now() * 1e6;
219 action.timestamp = 0;
220 } else {
221 // Unix nanosecond timestamp relative to match start.
222 action.timestamp = Date.now() * 1e6 - this.matchStartTimestamp;
223 }
224
Emily Markovadcadcb62024-02-03 13:07:17 -0800225 if (action.type == 'endMatchAction') {
226 // endMatchAction occurs at the same time as penaltyAction so add to its timestamp to make it unique.
227 action.timestamp += 1;
228 }
229
Filip Kujawab73e94c2023-04-19 09:33:14 -0700230 if (action.type == 'mobilityAction') {
231 this.mobilityCompleted = true;
232 }
233
Emily Markovadcadcb62024-02-03 13:07:17 -0800234 if (action.type == 'pickupNoteAction' || action.type == 'placeNoteAction') {
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800235 action.auto = this.autoPhase;
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800236 }
237 this.actionList.push(action);
238 }
239
240 undoLastAction() {
241 if (this.actionList.length > 0) {
242 let lastAction = this.actionList.pop();
243 switch (lastAction?.type) {
244 case 'endAutoPhase':
245 this.autoPhase = true;
Emily Markovadcadcb62024-02-03 13:07:17 -0800246 this.section = 'Pickup';
247 case 'pickupNoteAction':
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800248 this.section = 'Pickup';
249 break;
Emily Markovadcadcb62024-02-03 13:07:17 -0800250 case 'endTeleopPhase':
251 this.section = 'Pickup';
252 break;
253 case 'placeNoteAction':
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800254 this.section = 'Place';
255 break;
256 case 'endMatchAction':
Emily Markovadcadcb62024-02-03 13:07:17 -0800257 this.section = 'Endgame';
258 case 'mobilityAction':
259 this.mobilityCompleted = false;
260 break;
261 case 'startMatchAction':
262 this.section = 'Init';
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800263 break;
Filip Kujawa9f56d0e2023-03-03 19:44:43 -0800264 case 'robotDeathAction':
265 // TODO(FILIP): Return user to the screen they
266 // clicked dead robot on. Pickup is fine for now but
267 // might cause confusion.
268 this.section = 'Pickup';
269 break;
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800270 default:
271 break;
272 }
273 }
274 }
275
Emily Markovadcadcb62024-02-03 13:07:17 -0800276 stringifyScoreType(scoreType: ScoreType): String {
277 return ScoreType[scoreType];
Emily Markovaf4b06a22023-05-10 17:44:09 -0700278 }
279
Emily Markovadcadcb62024-02-03 13:07:17 -0800280 stringifyStageType(stageType: StageType): String {
281 return StageType[stageType];
Emily Markovaf4b06a22023-05-10 17:44:09 -0700282 }
283
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800284 changeSectionTo(target: Section) {
Philipp Schrader8702b782023-04-15 17:33:37 -0700285 // Clear the messages since they won't be relevant in the next section.
286 this.errorMessage = '';
287 this.progressMessage = '';
288
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800289 this.section = target;
290 }
Philipp Schrader80587432022-03-05 15:41:22 -0800291
Ravago Jones2813c032022-03-16 23:44:11 -0700292 @ViewChild('header') header: ElementRef;
Philipp Schrader6b2e9502022-03-15 23:42:56 -0700293
Ravago Jones2813c032022-03-16 23:44:11 -0700294 private scrollToTop() {
295 this.header.nativeElement.scrollIntoView();
296 }
297
Emily Markovadcadcb62024-02-03 13:07:17 -0800298 async submit2024Actions() {
James Kuszmauldac091f2022-03-22 09:35:06 -0700299 const builder = new Builder();
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800300 const actionOffsets: number[] = [];
301
302 for (const action of this.actionList) {
303 let actionOffset: number | undefined;
304 console.log(action.type);
305
306 switch (action.type) {
307 case 'startMatchAction':
308 const startMatchActionOffset =
309 StartMatchAction.createStartMatchAction(builder, action.position);
310 actionOffset = Action.createAction(
311 builder,
Philipp Schrader8c878a22023-03-20 22:36:38 -0700312 BigInt(action.timestamp || 0),
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800313 ActionType.StartMatchAction,
314 startMatchActionOffset
315 );
316 break;
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700317 case 'mobilityAction':
318 const mobilityActionOffset = MobilityAction.createMobilityAction(
319 builder,
320 action.mobility
321 );
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800322 actionOffset = Action.createAction(
323 builder,
Philipp Schrader8c878a22023-03-20 22:36:38 -0700324 BigInt(action.timestamp || 0),
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700325 ActionType.MobilityAction,
326 mobilityActionOffset
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800327 );
328 break;
Emily Markovadcadcb62024-02-03 13:07:17 -0800329 case 'penaltyAction':
330 const penaltyActionOffset = PenaltyAction.createPenaltyAction(
331 builder,
332 action.penalties
333 );
Filip Kujawa4c286442023-03-03 10:41:22 -0800334 actionOffset = Action.createAction(
335 builder,
Philipp Schrader8c878a22023-03-20 22:36:38 -0700336 BigInt(action.timestamp || 0),
Emily Markovadcadcb62024-02-03 13:07:17 -0800337 ActionType.PenaltyAction,
338 penaltyActionOffset
Filip Kujawa4c286442023-03-03 10:41:22 -0800339 );
340 break;
Emily Markovadcadcb62024-02-03 13:07:17 -0800341 case 'pickupNoteAction':
342 const pickupNoteActionOffset =
343 PickupNoteAction.createPickupNoteAction(
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700344 builder,
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700345 action.auto || false
346 );
347 actionOffset = Action.createAction(
348 builder,
349 BigInt(action.timestamp || 0),
Emily Markovadcadcb62024-02-03 13:07:17 -0800350 ActionType.PickupNoteAction,
351 pickupNoteActionOffset
Filip Kujawa0b4b1e52023-04-15 14:05:40 -0700352 );
353 break;
Emily Markovadcadcb62024-02-03 13:07:17 -0800354 case 'placeNoteAction':
355 const placeNoteActionOffset = PlaceNoteAction.createPlaceNoteAction(
356 builder,
357 action.scoreType,
358 action.auto || false
359 );
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800360 actionOffset = Action.createAction(
361 builder,
Philipp Schrader8c878a22023-03-20 22:36:38 -0700362 BigInt(action.timestamp || 0),
Emily Markovadcadcb62024-02-03 13:07:17 -0800363 ActionType.PlaceNoteAction,
364 placeNoteActionOffset
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800365 );
366 break;
367
368 case 'robotDeathAction':
369 const robotDeathActionOffset =
Emily Markova040123c2024-02-27 09:48:37 -0800370 RobotDeathAction.createRobotDeathAction(builder, action.robotDead);
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800371 actionOffset = Action.createAction(
372 builder,
Philipp Schrader8c878a22023-03-20 22:36:38 -0700373 BigInt(action.timestamp || 0),
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800374 ActionType.RobotDeathAction,
375 robotDeathActionOffset
376 );
377 break;
378
379 case 'endMatchAction':
380 const endMatchActionOffset = EndMatchAction.createEndMatchAction(
381 builder,
Emily Markovadcadcb62024-02-03 13:07:17 -0800382 action.stageType,
Emily Markova6079e2f2024-02-17 13:17:24 -0800383 action.trapNote,
384 action.spotlight
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800385 );
386 actionOffset = Action.createAction(
387 builder,
Philipp Schrader8c878a22023-03-20 22:36:38 -0700388 BigInt(action.timestamp || 0),
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800389 ActionType.EndMatchAction,
390 endMatchActionOffset
391 );
392 break;
393
394 case 'endAutoPhase':
395 // Not important action.
396 break;
397
Emily Markovadcadcb62024-02-03 13:07:17 -0800398 case 'endTeleopPhase':
399 // Not important action.
400 break;
401
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800402 default:
403 throw new Error(`Unknown action type`);
404 }
405
406 if (actionOffset !== undefined) {
407 actionOffsets.push(actionOffset);
408 }
409 }
Emily Markovae68b7632023-12-30 14:17:55 -0800410 const teamNumberFb = builder.createString(this.teamNumber);
Philipp Schradere859e6e2023-03-22 19:59:51 -0700411 const compLevelFb = builder.createString(this.compLevel);
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800412
Emily Markovadcadcb62024-02-03 13:07:17 -0800413 const actionsVector = Submit2024Actions.createActionsListVector(
Philipp Schrader817cce32022-03-26 15:00:00 -0700414 builder,
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800415 actionOffsets
Philipp Schrader817cce32022-03-26 15:00:00 -0700416 );
Emily Markovadcadcb62024-02-03 13:07:17 -0800417 Submit2024Actions.startSubmit2024Actions(builder);
418 Submit2024Actions.addTeamNumber(builder, teamNumberFb);
419 Submit2024Actions.addMatchNumber(builder, this.matchNumber);
420 Submit2024Actions.addSetNumber(builder, this.setNumber);
421 Submit2024Actions.addCompLevel(builder, compLevelFb);
422 Submit2024Actions.addActionsList(builder, actionsVector);
423 Submit2024Actions.addPreScouting(builder, this.preScouting);
424 builder.finish(Submit2024Actions.endSubmit2024Actions(builder));
Ravago Jones2813c032022-03-16 23:44:11 -0700425
426 const buffer = builder.asUint8Array();
Emily Markovadcadcb62024-02-03 13:07:17 -0800427 const res = await fetch('/requests/submit/submit_2024_actions', {
Philipp Schrader817cce32022-03-26 15:00:00 -0700428 method: 'POST',
429 body: buffer,
430 });
Ravago Jones2813c032022-03-16 23:44:11 -0700431
432 if (res.ok) {
433 // We successfully submitted the data. Report success.
434 this.section = 'Success';
Filip Kujawa0ef334c2023-02-20 19:42:45 -0800435 this.actionList = [];
Evelyn Yangc8036b12023-10-11 21:14:46 -0700436
437 // Keep track of the position of the last robot, use to figure out what the next robot in the same position is.
438
439 let lastTeamPos = '0';
440 for (const match of this.matchList) {
441 if (
442 this.matchNumber === match.matchNumber() &&
443 this.setNumber === match.setNumber() &&
444 this.compLevel === match.compLevel()
445 ) {
446 this.teamNumber = this.teamNumber;
447 if (this.teamNumber == match.r1()) {
448 lastTeamPos = 'r1';
449 } else if (this.teamNumber == match.r2()) {
450 lastTeamPos = 'r2';
451 } else if (this.teamNumber == match.r3()) {
452 lastTeamPos = 'r3';
453 } else if (this.teamNumber == match.b1()) {
454 lastTeamPos = 'b1';
455 } else if (this.teamNumber == match.b2()) {
456 lastTeamPos = 'b2';
457 } else if (this.teamNumber == match.b3()) {
458 lastTeamPos = 'b3';
459 } else {
460 console.log('Position of scouted team not found.');
461 }
462 break;
463 }
464 }
465 if (lastTeamPos != '0') {
466 this.matchNumber += 1;
467 for (const match of this.matchList) {
468 if (
469 this.matchNumber == match.matchNumber() &&
470 this.setNumber == match.setNumber() &&
471 this.compLevel == match.compLevel()
472 ) {
473 if (lastTeamPos == 'r1') {
474 this.nextTeamNumber = match.r1();
475 } else if (lastTeamPos == 'r2') {
476 this.nextTeamNumber = match.r2();
477 } else if (lastTeamPos == 'r3') {
478 this.nextTeamNumber = match.r3();
479 } else if (lastTeamPos == 'b1') {
480 this.nextTeamNumber = match.b1();
481 } else if (lastTeamPos == 'b2') {
482 this.nextTeamNumber = match.b2();
483 } else if (lastTeamPos == 'b3') {
484 this.nextTeamNumber = match.b3();
485 } else {
486 console.log('Position of last team not found.');
487 }
488 break;
489 }
490 }
491 } else {
492 console.log('Last team position not found.');
493 }
494 this.matchList = [];
495 this.progressMessage = '';
496 this.errorMessage = '';
497 this.autoPhase = true;
498 this.actionList = [];
499 this.mobilityCompleted = false;
500 this.preScouting = false;
501 this.matchStartTimestamp = 0;
502 this.selectedValue = 0;
Ravago Jones2813c032022-03-16 23:44:11 -0700503 } else {
504 const resBuffer = await res.arrayBuffer();
505 const fbBuffer = new ByteBuffer(new Uint8Array(resBuffer));
James Kuszmauldac091f2022-03-22 09:35:06 -0700506 const parsedResponse = ErrorResponse.getRootAsErrorResponse(fbBuffer);
Ravago Jones2813c032022-03-16 23:44:11 -0700507
508 const errorMessage = parsedResponse.errorMessage();
Philipp Schrader817cce32022-03-26 15:00:00 -0700509 this.errorMessage = `Received ${res.status} ${res.statusText}: "${errorMessage}"`;
Alex Perrybb3d2062022-03-05 18:14:33 -0800510 }
Ravago Jones2813c032022-03-16 23:44:11 -0700511 }
Philipp Schrader80587432022-03-05 15:41:22 -0800512}