Skip to content

Commit 820ec13

Browse files
committed
Add winning team to team infos
1 parent 60fea42 commit 820ec13

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/controller/MatchController.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export class MatchController {
1616
private eventTimes: Record<string, number> = {};
1717

1818
private codeToTeamInfo: Record<string, { leftTeam: AuthTeam; rightTeam: AuthTeam }> = {};
19+
private finishedGamesTeamInfo: Record<
20+
string,
21+
{ leftTeam: AuthTeam; rightTeam: AuthTeam; higherScore: 0 | 1 }
22+
> = {};
1923
private teamInfoExpiry: Record<string, number> = {};
2024

2125
private constructor() {
@@ -24,7 +28,7 @@ export class MatchController {
2428
const now = Date.now();
2529
for (const groupCode in this.teamInfoExpiry) {
2630
if (now > this.teamInfoExpiry[groupCode]) {
27-
delete this.codeToTeamInfo[groupCode];
31+
delete this.finishedGamesTeamInfo[groupCode];
2832
delete this.teamInfoExpiry[groupCode];
2933
}
3034
}
@@ -59,7 +63,10 @@ export class MatchController {
5963
this.matches[data.groupCode] = newMatch;
6064
this.eventNumbers[data.groupCode] = 0;
6165

62-
this.codeToTeamInfo[data.groupCode] = { leftTeam: data.leftTeam, rightTeam: data.rightTeam };
66+
this.codeToTeamInfo[data.groupCode] = {
67+
leftTeam: data.leftTeam,
68+
rightTeam: data.rightTeam,
69+
};
6370
this.teamInfoExpiry[data.groupCode] = Date.now() + 1000 * 60 * 60; // 12 hour expiry for team info
6471

6572
Log.info(`New match "${newMatch.groupCode}" registered!`);
@@ -186,11 +193,19 @@ export class MatchController {
186193
}
187194

188195
public getTeamInfoForCode(groupCode: string) {
189-
const teamInfo = this.codeToTeamInfo[groupCode];
196+
const teamInfo = this.finishedGamesTeamInfo[groupCode];
190197
if (teamInfo) {
191198
return teamInfo;
192199
} else {
193200
return undefined;
194201
}
195202
}
203+
204+
public setWinningTeamInfo(groupCode: string, higherScoreTeam: 0 | 1) {
205+
this.finishedGamesTeamInfo[groupCode] = {
206+
leftTeam: this.codeToTeamInfo[groupCode].leftTeam,
207+
rightTeam: this.codeToTeamInfo[groupCode].rightTeam,
208+
higherScore: higherScoreTeam,
209+
};
210+
}
196211
}

src/model/Match.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ export class Match {
255255
this.timeoutEndTimeout = undefined;
256256
this.timeoutRemainingLoop = undefined;
257257

258+
MatchController.getInstance().setWinningTeamInfo(
259+
this.groupCode,
260+
this.teams[0].roundsWon > this.teams[1].roundsWon ? 0 : 1,
261+
);
262+
258263
this.eventNumber++;
259264
MatchController.getInstance().removeMatch(this.groupCode);
260265

0 commit comments

Comments
 (0)