From 176df45214019bc2785833227d74ffb8b9b86614 Mon Sep 17 00:00:00 2001 From: Raz Date: Wed, 9 Oct 2024 11:46:41 +0200 Subject: [PATCH] fix preset management when no group stage --- PadelClub.xcodeproj/project.pbxproj | 4 ++-- PadelClub/Utils/PadelRule.swift | 12 ++++++++++++ .../Views/Tournament/Screen/TableStructureView.swift | 8 ++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 5b4ff6d..d860ba4 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -3134,7 +3134,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -3179,7 +3179,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 2; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/Utils/PadelRule.swift b/PadelClub/Utils/PadelRule.swift index c5c0d1a..8caae56 100644 --- a/PadelClub/Utils/PadelRule.swift +++ b/PadelClub/Utils/PadelRule.swift @@ -1884,9 +1884,21 @@ enum PadelTournamentStructurePreset: Int, Identifiable, CaseIterable { 1 } } + func hasWildcards() -> Bool { wildcardBrackets() > 0 || wildcardQualifiers() > 0 } + + func isFederalPreset() -> Bool { + switch self { + case .manual: + return false + case .doubleGroupStage: + return false + case .federalStructure_8, .federalStructure_12, .federalStructure_16, .federalStructure_20, .federalStructure_24, .federalStructure_32, .federalStructure_48, .federalStructure_64: + return true + } + } } enum TournamentDeadlineType: String, CaseIterable { diff --git a/PadelClub/Views/Tournament/Screen/TableStructureView.swift b/PadelClub/Views/Tournament/Screen/TableStructureView.swift index 76cd345..10e660a 100644 --- a/PadelClub/Views/Tournament/Screen/TableStructureView.swift +++ b/PadelClub/Views/Tournament/Screen/TableStructureView.swift @@ -193,7 +193,7 @@ struct TableStructureView: View { } label: { Text("Nombre de têtes de série") - if tsPure > 0 && (tsPure > teamCount / 2 || tsPure < teamCount / 8 || tsPure < qualifiedFromGroupStage + groupStageAdditionalQualified) { + if groupStageCount > 0 && tsPure > 0 && (tsPure > teamCount / 2 || tsPure < teamCount / 8 || tsPure < qualifiedFromGroupStage + groupStageAdditionalQualified) { Text("Attention !").foregroundStyle(.red) } } @@ -212,7 +212,7 @@ struct TableStructureView: View { } } } footer: { - if tsPure > 0 && structurePreset != .doubleGroupStage { + if tsPure > 0 && structurePreset != .doubleGroupStage, groupStageCount > 0 { if tsPure > teamCount / 2 { Text("Le nombre de têtes de série ne devrait pas être supérieur à la moitié de l'effectif.").foregroundStyle(.red) } else if tsPure < teamCount / 8 { @@ -288,6 +288,10 @@ struct TableStructureView: View { } else { updatedElements.remove(.groupStageCount) } + + if structurePreset.isFederalPreset(), groupStageCount == 0 { + teamCount = structurePreset.tableDimension() + } } .onChange(of: teamsPerGroupStage) { if teamsPerGroupStage != tournament.teamsPerGroupStage {