diff --git a/src/app/components/tournament-manage/tournament-manage.component.html b/src/app/components/tournament-manage/tournament-manage.component.html index a1b0708..6213d4c 100644 --- a/src/app/components/tournament-manage/tournament-manage.component.html +++ b/src/app/components/tournament-manage/tournament-manage.component.html @@ -130,9 +130,21 @@
Baan {{ activeMatch.match.court }}
-
{{ activeMatch.match.team1 | teamText }}
+
+ + +
-
-
{{ activeMatch.match.team2 | teamText }}
+
+ + +
{{ activeMatch.group.name }} {{ activeMatch.round.name }}
diff --git a/src/app/components/tournament-manage/tournament-manage.component.ts b/src/app/components/tournament-manage/tournament-manage.component.ts index b522343..a43288a 100644 --- a/src/app/components/tournament-manage/tournament-manage.component.ts +++ b/src/app/components/tournament-manage/tournament-manage.component.ts @@ -64,7 +64,6 @@ import {TeamDisplayComponent} from "../team-display/team-display.component"; TournamentValidateComponent, TournamentPlayersComponent, MatExpansionPanelActionRow, - MatTooltip, TeamDisplayComponent, ], providers: [ @@ -224,36 +223,43 @@ export class TournamentManageComponent implements OnInit, OnDestroy { } matchContainsPlayersThatArePlaying(match: Match): boolean { - let activePlayers: number[] = []; - for (let activeMatch of this.activeMatches()) { - activePlayers.push(activeMatch.match.team1.player1.id); - if (activeMatch.match.team1.player2) activePlayers.push(activeMatch.match.team1.player2.id); - activePlayers.push(activeMatch.match.team2.player1.id); - if (activeMatch.match.team2.player2) activePlayers.push(activeMatch.match.team2.player2.id); - } let matchPlayers: number[] = []; - matchPlayers.push(match.team1.player1.id); - if (match.team1.player2) matchPlayers.push(match.team1.player2.id); - matchPlayers.push(match.team2.player1.id); - if (match.team2.player2) matchPlayers.push(match.team2.player2.id); - let playersThatArePlaying = activePlayers.filter(Set.prototype.has, new Set(matchPlayers)); - return playersThatArePlaying.length > 0; + matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team1.player1).id); + if (match.team1.player2) matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team1.player2).id); + matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team2.player1).id); + if (match.team2.player2) matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team2.player2).id); + + let matchPlayersThatArePlaying = this.tournament.playersPlaying.filter(Set.prototype.has, new Set(matchPlayers)); + return matchPlayersThatArePlaying.length > 0; } matchContainsPlayersThatAreCounting(match: Match): boolean { - let currentCounters: number[] = []; - for (let activeMatch of this.activeMatches()) { - currentCounters.push(activeMatch.match.counter.id); - } - let matchPlayers: number[] = []; - matchPlayers.push(match.team1.player1.id); - if (match.team1.player2) matchPlayers.push(match.team1.player2.id); - matchPlayers.push(match.team2.player1.id); - if (match.team2.player2) matchPlayers.push(match.team2.player2.id); + matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team1.player1).id); + if (match.team1.player2) matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team1.player2).id); + matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team2.player1).id); + if (match.team2.player2) matchPlayers.push(this.getTournamentPlayerFromPlayer(match.team2.player2).id); - let playersThatAreCounting = currentCounters.filter(Set.prototype.has, new Set(matchPlayers)); - return playersThatAreCounting.length > 0; + let matchPlayersThatAreCounting = this.tournament.playersCounting.filter(Set.prototype.has, new Set(matchPlayers)); + return matchPlayersThatAreCounting.length > 0; + } + + getTournamentPlayerFromPlayer(player: Player): TournamentPlayer { + for (let tournamentPlayer of this.tournament.tournamentPlayers) { + if (tournamentPlayer.playerId == player.id) { + return tournamentPlayer; + } + } + return null!; + } + + getTournamentPlayerFromId(tournamentPlayerId: number): TournamentPlayer { + for (let tournamentPlayer of this.tournament.tournamentPlayers) { + if (tournamentPlayer.id == tournamentPlayerId) { + return tournamentPlayer; + } + } + return null!; } getAvailableCourts(): number[] { @@ -267,28 +273,33 @@ export class TournamentManageComponent implements OnInit, OnDestroy { } getAvailableCounters(match: Match): TournamentPlayer[] { - const activePlayerIds = new Set( - this.activeMatches().flatMap(activeMatch => [ - activeMatch.match.team1.player1.id, - activeMatch.match.team1.player2?.id, - activeMatch.match.team2.player1.id, - activeMatch.match.team2.player2?.id - ].filter(id => id !== undefined)) - ); + const matchPlayers: number[] = []; + matchPlayers.push(this.getPlayerOrSubstitute(match.team1.player1, match.type).id); + if (match.team1.player2) matchPlayers.push(this.getPlayerOrSubstitute(match.team1.player2, match.type).id); + matchPlayers.push(this.getPlayerOrSubstitute(match.team2.player1, match.type).id); + if (match.team2.player2) matchPlayers.push(this.getPlayerOrSubstitute(match.team2.player2, match.type).id); - const playerIdsInMatchToBeStarted = new Set([ - match.team1.player1.id, - match.team1.player2?.id, - match.team2.player1.id, - match.team2.player2?.id - ].filter(id => id !== undefined)); + const counterIds = this.tournament.playersAvailable.filter(player => !matchPlayers.includes(player)); - return this.tournament.tournamentPlayers.filter( - player => - !player.counting - && !activePlayerIds.has(player.playerId) - && !playerIdsInMatchToBeStarted.has(player.playerId) + return counterIds.map(id => this.getTournamentPlayerFromId(id)); + } + + getPlayerOrSubstitute(player: Player, type: String): TournamentPlayer { + return this.getSubstituteForEvent(player, type) || this.getTournamentPlayerFromPlayer(player); + } + + getSubstituteForEvent(player: Player, type: String): TournamentPlayer | undefined { + const tournamentPlayer = this.tournament.tournamentPlayers.find( + tp => tp.playerId === player.id ); + if (!tournamentPlayer) return undefined; + + const substitution = tournamentPlayer.substitutions.find( + s => s.event === type + ); + if (!substitution) return undefined; + + return this.getTournamentPlayerFromId(substitution.substitute); } stopMatch(match: Match) { @@ -326,7 +337,7 @@ export class TournamentManageComponent implements OnInit, OnDestroy { for (const round of group.rounds) { for (const match of round.matches) { if (match.status == 'IN_PROGRESS') { - matches.push(new ActiveMatch(match, round, group)); + matches.push(new ActiveMatch(match, round, group, event)); } } } @@ -420,13 +431,15 @@ export class TournamentManageComponent implements OnInit, OnDestroy { } class ActiveMatch { - constructor(match: Match, round: Round, group: Group) { + constructor(match: Match, round: Round, group: Group, event: Event) { this.match = match; this.round = round; this.group = group; + this.event = event; } match: Match; round: Round; group: Group; + event: Event; } diff --git a/src/app/model/tournament.ts b/src/app/model/tournament.ts index 7d8d9b0..d3db37b 100644 --- a/src/app/model/tournament.ts +++ b/src/app/model/tournament.ts @@ -12,6 +12,9 @@ export class Tournament { costsPerEvent: number[] = [10, 20, 0]; courts: number; active: boolean; + playersPlaying: number[]; + playersCounting: number[]; + playersAvailable: number[]; static getStatus(tournament: Tournament): string { if (tournament.status == "CLOSED") return "Afgerond";