From 50a0f8a6aeb935c392281605ab32092f4bd53b96 Mon Sep 17 00:00:00 2001 From: Raz Date: Mon, 14 Oct 2024 18:37:35 +0200 Subject: [PATCH] fix single group stage final ranking stuff --- PadelClub.xcodeproj/project.pbxproj | 4 +-- PadelClub/Data/Tournament.swift | 4 +++ PadelClub/Utils/PadelRule.swift | 3 +- .../Components/GroupStageTeamView.swift | 34 +++++++++++-------- .../Screen/TableStructureView.swift | 6 ++-- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 7b1f59c..ce71154 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -3150,7 +3150,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 5; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -3195,7 +3195,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 5; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 1bf494d..a7d71c3 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -1778,6 +1778,10 @@ defer { return Round(tournament: id, index: $0, matchFormat: roundSmartMatchFormat($0), loserBracketMode: loserBracketMode) } + if rounds.isEmpty { + return + } + do { try self.tournamentStore.rounds.addOrUpdate(contentOfs: rounds) } catch { diff --git a/PadelClub/Utils/PadelRule.swift b/PadelClub/Utils/PadelRule.swift index bc7aee6..72abedc 100644 --- a/PadelClub/Utils/PadelRule.swift +++ b/PadelClub/Utils/PadelRule.swift @@ -1592,7 +1592,8 @@ enum RoundRule { } static func numberOfRounds(forTeams teams: Int) -> Int { - Int(log2(Double(teamsInFirstRound(forTeams: teams)))) + if teams == 0 { return 0 } + return Int(log2(Double(teamsInFirstRound(forTeams: teams)))) } static func matchIndex(fromRoundIndex roundIndex: Int) -> Int { diff --git a/PadelClub/Views/GroupStage/Components/GroupStageTeamView.swift b/PadelClub/Views/GroupStage/Components/GroupStageTeamView.swift index b8794db..1d4b467 100644 --- a/PadelClub/Views/GroupStage/Components/GroupStageTeamView.swift +++ b/PadelClub/Views/GroupStage/Components/GroupStageTeamView.swift @@ -66,24 +66,28 @@ struct GroupStageTeamView: View { } } } - - Section { - if team.qualified == false { - RowButtonView("Qualifier l'équipe", role: .destructive) { - team.qualified = true - //team.bracketPosition = nil - _save() - } - } else { - RowButtonView("Annuler la qualification", role: .destructive) { - team.qualified = false - groupStage.tournamentObject()?.resetTeamScores(in: team.bracketPosition) - team.bracketPosition = nil - _save() - } + } + + + Section { + if team.qualified == false { + RowButtonView("Qualifier l'équipe", role: .destructive) { + team.qualified = true + //team.bracketPosition = nil + _save() + } + } else { + RowButtonView("Annuler la qualification", role: .destructive) { + team.qualified = false + groupStage.tournamentObject()?.resetTeamScores(in: team.bracketPosition) + team.bracketPosition = nil + _save() } } + } + + if groupStage.tournamentObject()?.hasEnded() == false { if team.qualified == false { Section { RowButtonView("Retirer de la poule", role: .destructive) { diff --git a/PadelClub/Views/Tournament/Screen/TableStructureView.swift b/PadelClub/Views/Tournament/Screen/TableStructureView.swift index 317bf6a..ff126af 100644 --- a/PadelClub/Views/Tournament/Screen/TableStructureView.swift +++ b/PadelClub/Views/Tournament/Screen/TableStructureView.swift @@ -106,7 +106,7 @@ struct TableStructureView: View { if structurePreset != .doubleGroupStage { LabeledContent { - StepperView(count: $qualifiedPerGroupStage, minimum: 1, maximum: (teamsPerGroupStage-1)) + StepperView(count: $qualifiedPerGroupStage, minimum: 0, maximum: (teamsPerGroupStage-1)) } label: { Text("Qualifié\(qualifiedPerGroupStage.pluralSuffix) par poule") } @@ -445,8 +445,8 @@ struct TableStructureView: View { teamsPerGroupStage = 2 } - if qualifiedPerGroupStage < 1 { - qualifiedPerGroupStage = 1 + if qualifiedPerGroupStage < 0 { + qualifiedPerGroupStage = 0 } if groupStageAdditionalQualified < 0 {