|
|
|
@ -81,7 +81,7 @@ class Round: ModelObject, Storable { |
|
|
|
} else if let previousMatch = topPreviousRoundMatch(ofMatch: match) { |
|
|
|
} else if let previousMatch = topPreviousRoundMatch(ofMatch: match) { |
|
|
|
if let teamId = previousMatch.winningTeamId { |
|
|
|
if let teamId = previousMatch.winningTeamId { |
|
|
|
return Store.main.findById(teamId) |
|
|
|
return Store.main.findById(teamId) |
|
|
|
} else if previousMatch.isBye() { |
|
|
|
} else if previousMatch.disabled { |
|
|
|
return previousMatch.teams().first |
|
|
|
return previousMatch.teams().first |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -91,7 +91,7 @@ class Round: ModelObject, Storable { |
|
|
|
} else if let previousMatch = bottomPreviousRoundMatch(ofMatch: match) { |
|
|
|
} else if let previousMatch = bottomPreviousRoundMatch(ofMatch: match) { |
|
|
|
if let teamId = previousMatch.winningTeamId { |
|
|
|
if let teamId = previousMatch.winningTeamId { |
|
|
|
return Store.main.findById(teamId) |
|
|
|
return Store.main.findById(teamId) |
|
|
|
} else if previousMatch.isBye() { |
|
|
|
} else if previousMatch.disabled { |
|
|
|
return previousMatch.teams().first |
|
|
|
return previousMatch.teams().first |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -143,7 +143,11 @@ class Round: ModelObject, Storable { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func playedMatches() -> [Match] { |
|
|
|
func playedMatches() -> [Match] { |
|
|
|
|
|
|
|
if loser == nil { |
|
|
|
Store.main.filter { $0.round == self.id && $0.disabled == false } |
|
|
|
Store.main.filter { $0.round == self.id && $0.disabled == false } |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
Store.main.filter { $0.round == self.id } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func previousRound() -> Round? { |
|
|
|
func previousRound() -> Round? { |
|
|
|
@ -159,7 +163,7 @@ class Round: ModelObject, Storable { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func isDisabled() -> Bool { |
|
|
|
func isDisabled() -> Bool { |
|
|
|
playedMatches().allSatisfy({ $0.disabled || $0.isBye() }) |
|
|
|
_matches().allSatisfy({ $0.disabled }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getActiveLoserRound() -> Round? { |
|
|
|
func getActiveLoserRound() -> Round? { |
|
|
|
@ -167,6 +171,32 @@ class Round: ModelObject, Storable { |
|
|
|
return rounds.filter({ $0.hasStarted() && $0.hasEnded() == false && $0.isDisabled() == false }).sorted(by: \.index).reversed().first ?? rounds.first(where: { $0.isDisabled() == false }) |
|
|
|
return rounds.filter({ $0.hasStarted() && $0.hasEnded() == false && $0.isDisabled() == false }).sorted(by: \.index).reversed().first ?? rounds.first(where: { $0.isDisabled() == false }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func enableRound() { |
|
|
|
|
|
|
|
let _matches = _matches() |
|
|
|
|
|
|
|
_matches.forEach { match in |
|
|
|
|
|
|
|
match.disabled = false |
|
|
|
|
|
|
|
match.losingTeamId = nil |
|
|
|
|
|
|
|
match.winningTeamId = nil |
|
|
|
|
|
|
|
match.endDate = nil |
|
|
|
|
|
|
|
match.court = nil |
|
|
|
|
|
|
|
match.servingTeamId = nil |
|
|
|
|
|
|
|
try? DataStore.shared.teamScores.delete(contentOfs: match.teamScores) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try? DataStore.shared.matches.addOrUpdate(contentOfs: _matches) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func disableLoserRound(_ disable: Bool) { |
|
|
|
|
|
|
|
let _matches = _matches() |
|
|
|
|
|
|
|
_matches.forEach { match in |
|
|
|
|
|
|
|
match.disabled = match.topPreviousRoundMatch()?.disabled == disable || match.bottomPreviousRoundMatch()?.disabled == disable |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try? DataStore.shared.matches.addOrUpdate(contentOfs: _matches) |
|
|
|
|
|
|
|
loserRounds().forEach { round in |
|
|
|
|
|
|
|
round.disableLoserRound(disable) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var cumulativeMatchCount: Int { |
|
|
|
var cumulativeMatchCount: Int { |
|
|
|
var totalMatches = playedMatches().count |
|
|
|
var totalMatches = playedMatches().count |
|
|
|
if let parent = parentRound { |
|
|
|
if let parent = parentRound { |
|
|
|
@ -188,7 +218,7 @@ class Round: ModelObject, Storable { |
|
|
|
let parentMatchCount = parentRound.cumulativeMatchCount - initialRound.playedMatches().count |
|
|
|
let parentMatchCount = parentRound.cumulativeMatchCount - initialRound.playedMatches().count |
|
|
|
print("initialRound", initialRound.roundTitle()) |
|
|
|
print("initialRound", initialRound.roundTitle()) |
|
|
|
if let initialRoundNextRound = initialRound.nextRound()?.playedMatches() { |
|
|
|
if let initialRoundNextRound = initialRound.nextRound()?.playedMatches() { |
|
|
|
return SeedInterval(first: parentMatchCount + initialRoundNextRound.count * 2 + 1, last: parentMatchCount + initialRoundNextRound.count * 2 + playedMatches().count * 2).localizedLabel(displayStyle) |
|
|
|
return SeedInterval(first: parentMatchCount + initialRoundNextRound.count * 2 + 1, last: parentMatchCount + initialRoundNextRound.count * 2 + (previousRound() ?? parentRound).playedMatches().count).localizedLabel(displayStyle) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return RoundRule.roundName(fromRoundIndex: index) |
|
|
|
return RoundRule.roundName(fromRoundIndex: index) |
|
|
|
|