diff --git a/PadelClubData/Data/Match.swift b/PadelClubData/Data/Match.swift index c8c9798..77182fd 100644 --- a/PadelClubData/Data/Match.swift +++ b/PadelClubData/Data/Match.swift @@ -891,7 +891,7 @@ defer { let endedSetsTwo = teamScoreOtherTeam.score?.components(separatedBy: ",").compactMap({ $0.components(separatedBy: "-").first }).compactMap({ Int($0) }) ?? matchFormat.defaultWalkOutScore(teamScoreOtherTeam.isWalkOut()) var setDifference : Int = 0 let zip = zip(endedSetsOne, endedSetsTwo) - if matchFormat.setsToWin == 1 { + if matchFormat.setsToWin == 1, endedSetsOne.count > 0, endedSetsTwo.count > 0 { setDifference = endedSetsOne[0] - endedSetsTwo[0] } else { setDifference = zip.filter { $0 > $1 }.count - zip.filter { $1 > $0 }.count diff --git a/PadelClubData/Data/TeamRegistration.swift b/PadelClubData/Data/TeamRegistration.swift index 75a13dd..e3964e4 100644 --- a/PadelClubData/Data/TeamRegistration.swift +++ b/PadelClubData/Data/TeamRegistration.swift @@ -250,7 +250,7 @@ final public class TeamRegistration: BaseTeamRegistration, SideStorable { public func teamLabel( _ displayStyle: DisplayStyle = .wide, twoLines: Bool = false, separator: String = "&" ) -> String { - if let name { return name } + if let name, name.isEmpty == false { return name } return players().map { $0.playerLabel(displayStyle) }.joined( separator: twoLines ? "\n" : " \(separator) ") } diff --git a/PadelClubData/Data/Tournament.swift b/PadelClubData/Data/Tournament.swift index a9a2442..12d26e4 100644 --- a/PadelClubData/Data/Tournament.swift +++ b/PadelClubData/Data/Tournament.swift @@ -361,6 +361,7 @@ defer { public func availableSeedOpponentSpot(inRoundIndex roundIndex: Int) -> [Match] { return getRound(atRoundIndex: roundIndex)?.playedMatches().filter { $0.hasSpaceLeft() } ?? [] } + public func availableSeedGroups(includeAll: Bool = false) -> [SeedInterval] { let seeds = seeds() var availableSeedGroup = Set() @@ -378,6 +379,24 @@ defer { 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) { chunks.forEach { chunk in availableSeedGroup.insert(chunk) @@ -1678,11 +1697,11 @@ defer { } } - public func initSettings(templateTournament: Tournament?) { + public func initSettings(templateTournament: Tournament?, overrideTeamCount: Bool = true) { setupDefaultPrivateSettings(templateTournament: templateTournament) setupUmpireSettings(defaultTournament: nil) //default is not template, default is for event sharing settings if let templateTournament { - setupRegistrationSettings(templateTournament: templateTournament) + setupRegistrationSettings(templateTournament: templateTournament, overrideTeamCount: overrideTeamCount) } setupFederalSettings() } @@ -1755,7 +1774,7 @@ defer { } } - public func setupRegistrationSettings(templateTournament: Tournament) { + public func setupRegistrationSettings(templateTournament: Tournament, overrideTeamCount: Bool = true) { self.enableOnlineRegistration = templateTournament.enableOnlineRegistration self.unregisterDeltaInHours = templateTournament.unregisterDeltaInHours self.accountIsRequired = templateTournament.accountIsRequired @@ -1764,7 +1783,9 @@ defer { self.maximumPlayerPerTeam = templateTournament.maximumPlayerPerTeam self.waitingListLimit = templateTournament.waitingListLimit self.teamCountLimit = templateTournament.teamCountLimit - self.teamCount = templateTournament.teamCount + if overrideTeamCount { + self.teamCount = templateTournament.teamCount + } self.enableOnlinePayment = templateTournament.enableOnlinePayment self.onlinePaymentIsMandatory = templateTournament.onlinePaymentIsMandatory self.enableOnlinePaymentRefund = templateTournament.enableOnlinePaymentRefund diff --git a/PadelClubData/ViewModel/PadelRule.swift b/PadelClubData/ViewModel/PadelRule.swift index 2c8a0cb..2c954c8 100644 --- a/PadelClubData/ViewModel/PadelRule.swift +++ b/PadelClubData/ViewModel/PadelRule.swift @@ -2178,7 +2178,7 @@ public enum TournamentDeadlineType: String, CaseIterable { case definitiveBroadcastList = "Publication définitive" public func daysOffset(level: TournamentLevel) -> Int { - if level == .p500 { + if level == .p500 || level == .p1000 { switch self { case .inscription: return -6