|
|
|
@ -58,7 +58,7 @@ class Match: ModelObject, Storable { |
|
|
|
func indexInRound() -> Int { |
|
|
|
func indexInRound() -> Int { |
|
|
|
if groupStage != nil { |
|
|
|
if groupStage != nil { |
|
|
|
return index |
|
|
|
return index |
|
|
|
} else if let index = roundObject?.playedMatches().firstIndex(where: { $0.id == id }) { |
|
|
|
} else if let index = roundObject?.playedMatches().sorted(by: \.index).firstIndex(where: { $0.id == id }) { |
|
|
|
return index |
|
|
|
return index |
|
|
|
} |
|
|
|
} |
|
|
|
return RoundRule.matchIndexWithinRound(fromMatchIndex: index) |
|
|
|
return RoundRule.matchIndexWithinRound(fromMatchIndex: index) |
|
|
|
@ -400,6 +400,7 @@ class Match: ModelObject, Storable { |
|
|
|
losingTeamId = teamScoreWalkout.teamRegistration |
|
|
|
losingTeamId = teamScoreWalkout.teamRegistration |
|
|
|
groupStageObject?.updateGroupStageState() |
|
|
|
groupStageObject?.updateGroupStageState() |
|
|
|
roundObject?.updateTournamentState() |
|
|
|
roundObject?.updateTournamentState() |
|
|
|
|
|
|
|
updateFollowingMatchTeamScore() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setScore(fromMatchDescriptor matchDescriptor: MatchDescriptor) { |
|
|
|
func setScore(fromMatchDescriptor matchDescriptor: MatchDescriptor) { |
|
|
|
@ -411,6 +412,7 @@ class Match: ModelObject, Storable { |
|
|
|
losingTeamId = team(matchDescriptor.winner.otherTeam)?.id |
|
|
|
losingTeamId = team(matchDescriptor.winner.otherTeam)?.id |
|
|
|
groupStageObject?.updateGroupStageState() |
|
|
|
groupStageObject?.updateGroupStageState() |
|
|
|
roundObject?.updateTournamentState() |
|
|
|
roundObject?.updateTournamentState() |
|
|
|
|
|
|
|
updateFollowingMatchTeamScore() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func updateScore(fromMatchDescriptor matchDescriptor: MatchDescriptor) { |
|
|
|
func updateScore(fromMatchDescriptor matchDescriptor: MatchDescriptor) { |
|
|
|
@ -422,6 +424,39 @@ class Match: ModelObject, Storable { |
|
|
|
matchFormat = matchDescriptor.matchFormat |
|
|
|
matchFormat = matchDescriptor.matchFormat |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func updateFollowingMatchTeamScore() { |
|
|
|
|
|
|
|
followingMatch()?.updateTeamScores() |
|
|
|
|
|
|
|
_loserMatch()?.updateTeamScores() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func resetTeamScores() { |
|
|
|
|
|
|
|
let teamScores = teamScores |
|
|
|
|
|
|
|
if teamScores.isEmpty == false { |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
try DataStore.shared.teamScores.delete(contentOfs: teamScores) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
followingMatch()?.resetTeamScores() |
|
|
|
|
|
|
|
_loserMatch()?.resetTeamScores() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func updateTeamScores() { |
|
|
|
|
|
|
|
resetTeamScores() |
|
|
|
|
|
|
|
let teamOne = team(.one) |
|
|
|
|
|
|
|
let teamTwo = team(.two) |
|
|
|
|
|
|
|
let teams = [teamOne, teamTwo].compactMap({ $0 }).map { TeamScore(match: id, team: $0) } |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
try DataStore.shared.teamScores.addOrUpdate(contentOfs: teams) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if teams.isEmpty == false { |
|
|
|
|
|
|
|
updateFollowingMatchTeamScore() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func validateMatch(fromStartDate: Date, toEndDate: Date, fieldSetup: MatchFieldSetup) { |
|
|
|
func validateMatch(fromStartDate: Date, toEndDate: Date, fieldSetup: MatchFieldSetup) { |
|
|
|
if hasEnded() == false { |
|
|
|
if hasEnded() == false { |
|
|
|
startDate = fromStartDate |
|
|
|
startDate = fromStartDate |
|
|
|
|