|
|
|
@ -345,6 +345,7 @@ defer { |
|
|
|
public func availableSeedOpponentSpot(inRoundIndex roundIndex: Int) -> [Match] { |
|
|
|
public func availableSeedOpponentSpot(inRoundIndex roundIndex: Int) -> [Match] { |
|
|
|
return getRound(atRoundIndex: roundIndex)?.playedMatches().filter { $0.hasSpaceLeft() } ?? [] |
|
|
|
return getRound(atRoundIndex: roundIndex)?.playedMatches().filter { $0.hasSpaceLeft() } ?? [] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public func availableSeedGroups(includeAll: Bool = false) -> [SeedInterval] { |
|
|
|
public func availableSeedGroups(includeAll: Bool = false) -> [SeedInterval] { |
|
|
|
let seeds = seeds() |
|
|
|
let seeds = seeds() |
|
|
|
var availableSeedGroup = Set<SeedInterval>() |
|
|
|
var availableSeedGroup = Set<SeedInterval>() |
|
|
|
@ -362,6 +363,24 @@ defer { |
|
|
|
return availableSeedGroup.sorted(by: <) |
|
|
|
return availableSeedGroup.sorted(by: <) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public func generateSeedGroups(base: Int, teamCount: Int) -> [SeedInterval] { |
|
|
|
|
|
|
|
let start = base + 1 |
|
|
|
|
|
|
|
let root = SeedInterval(first: start, last: start + teamCount - 1) |
|
|
|
|
|
|
|
var groups: [SeedInterval] = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func split(interval: SeedInterval) { |
|
|
|
|
|
|
|
groups.append(interval) |
|
|
|
|
|
|
|
if let chunks = interval.chunks() { |
|
|
|
|
|
|
|
for chunk in chunks { |
|
|
|
|
|
|
|
split(interval: chunk) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
split(interval: root) |
|
|
|
|
|
|
|
return groups.sorted(by: <) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public func chunksBy(in chunks: [SeedInterval], availableSeedGroup: inout Set<SeedInterval>) { |
|
|
|
public func chunksBy(in chunks: [SeedInterval], availableSeedGroup: inout Set<SeedInterval>) { |
|
|
|
chunks.forEach { chunk in |
|
|
|
chunks.forEach { chunk in |
|
|
|
availableSeedGroup.insert(chunk) |
|
|
|
availableSeedGroup.insert(chunk) |
|
|
|
@ -1663,12 +1682,14 @@ defer { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public func initSettings(templateTournament: Tournament?, overrideTeamCount: Bool = true) { |
|
|
|
public func initSettings(templateTournament: Tournament?, overrideTeamCount: Bool = true) { |
|
|
|
|
|
|
|
courtCount = eventObject()?.clubObject()?.courtCount ?? 2 |
|
|
|
setupDefaultPrivateSettings(templateTournament: templateTournament) |
|
|
|
setupDefaultPrivateSettings(templateTournament: templateTournament) |
|
|
|
setupUmpireSettings(defaultTournament: nil) //default is not template, default is for event sharing settings |
|
|
|
setupUmpireSettings(defaultTournament: nil) //default is not template, default is for event sharing settings |
|
|
|
if let templateTournament { |
|
|
|
if let templateTournament { |
|
|
|
setupRegistrationSettings(templateTournament: templateTournament, overrideTeamCount: overrideTeamCount) |
|
|
|
setupRegistrationSettings(templateTournament: templateTournament, overrideTeamCount: overrideTeamCount) |
|
|
|
} |
|
|
|
} |
|
|
|
setupFederalSettings() |
|
|
|
setupFederalSettings() |
|
|
|
|
|
|
|
customizeUsingPreferences() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public func setupFederalSettings() { |
|
|
|
public func setupFederalSettings() { |
|
|
|
@ -1684,6 +1705,23 @@ defer { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public func customizeUsingPreferences() { |
|
|
|
|
|
|
|
guard let lastTournamentWithSameBuild = DataStore.shared.tournaments.filter({ tournament in |
|
|
|
|
|
|
|
tournament.tournamentLevel == self.tournamentLevel |
|
|
|
|
|
|
|
&& tournament.tournamentCategory == self.tournamentCategory |
|
|
|
|
|
|
|
&& tournament.federalTournamentAge == self.federalTournamentAge |
|
|
|
|
|
|
|
&& tournament.hasEnded() == true |
|
|
|
|
|
|
|
&& tournament.isCanceled == false |
|
|
|
|
|
|
|
&& tournament.isDeleted == false |
|
|
|
|
|
|
|
}).sorted(by: \.endDate!, order: .descending).first else { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.entryFee = lastTournamentWithSameBuild.entryFee |
|
|
|
|
|
|
|
self.clubMemberFeeDeduction = lastTournamentWithSameBuild.clubMemberFeeDeduction |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public func deadline(for type: TournamentDeadlineType) -> Date? { |
|
|
|
public func deadline(for type: TournamentDeadlineType) -> Date? { |
|
|
|
guard [.p500, .p1000, .p1500, .p2000].contains(tournamentLevel) else { return nil } |
|
|
|
guard [.p500, .p1000, .p1500, .p2000].contains(tournamentLevel) else { return nil } |
|
|
|
|
|
|
|
|
|
|
|
|