From 54a35571b1b341a301a0afc7bdae6d485e6e0be6 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Mon, 13 Oct 2025 14:55:14 +0200 Subject: [PATCH] add heads config system --- PadelClubData/Data/Tournament.swift | 3 +++ PadelClubData/ViewModel/PadelRule.swift | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/PadelClubData/Data/Tournament.swift b/PadelClubData/Data/Tournament.swift index 8ff9037..3c3514d 100644 --- a/PadelClubData/Data/Tournament.swift +++ b/PadelClubData/Data/Tournament.swift @@ -1547,6 +1547,9 @@ defer { public func deleteGroupStages() { self.tournamentStore?.groupStages.delete(contentOfs: allGroupStages()) + if let gs = self.groupStageLoserBracket() { + self.tournamentStore?.rounds.delete(instance: gs) + } } public func refreshGroupStages(keepExistingMatches: Bool = false) { diff --git a/PadelClubData/ViewModel/PadelRule.swift b/PadelClubData/ViewModel/PadelRule.swift index 5c9b033..f73e759 100644 --- a/PadelClubData/ViewModel/PadelRule.swift +++ b/PadelClubData/ViewModel/PadelRule.swift @@ -1882,12 +1882,16 @@ public enum RoundRule { } public static func numberOfMatches(forRoundIndex roundIndex: Int) -> Int { - Int(pow(2.0, Double(roundIndex))) + (1 << roundIndex) + } + + public static func baseIndex(forRoundIndex roundIndex: Int) -> Int { + numberOfMatches(forRoundIndex: roundIndex) - 1 } static func matchIndexWithinRound(fromMatchIndex matchIndex: Int) -> Int { let roundIndex = roundIndex(fromMatchIndex: matchIndex) - let matchIndexWithinRound = matchIndex - (Int(pow(2.0, Double(roundIndex))) - 1) + let matchIndexWithinRound = matchIndex - baseIndex(forRoundIndex: roundIndex) return matchIndexWithinRound } @@ -1911,7 +1915,7 @@ public enum RoundRule { } return "Quart de finale" default: - return "\(Int(pow(2.0, Double(roundIndex))))ème" + return "\((1 << roundIndex))ème" } } }