From af11629e0370db37470e515e3c1234d312ffe39a Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Wed, 5 Jun 2024 13:48:00 +0200 Subject: [PATCH] b42 --- PadelClub.xcodeproj/project.pbxproj | 4 ++-- PadelClub/Data/Tournament.swift | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 876ac5f..f43fafb 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -1859,7 +1859,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 41; + CURRENT_PROJECT_VERSION = 42; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; @@ -1897,7 +1897,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 41; + CURRENT_PROJECT_VERSION = 42; 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 6cbc291..dba3201 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -531,9 +531,18 @@ class Tournament : ModelObject, Storable { selectedSortedTeams().filter({ $0.groupStagePosition != nil }) } + func groupStageSpots() -> Int { + let _groupStagesCount = groupStages().count + if groupStageCount != _groupStagesCount { + return groupStageCount * teamsPerGroupStage + } else { + return groupStages().map { $0.size }.reduce(0,+) + } + } + func seeds() -> [TeamRegistration] { let selectedSortedTeams = selectedSortedTeams() - let seeds = max(selectedSortedTeams.count - groupStageCount * teamsPerGroupStage, 0) + let seeds = max(selectedSortedTeams.count - groupStageSpots() , 0) return Array(selectedSortedTeams.prefix(seeds)) } @@ -761,8 +770,9 @@ class Tournament : ModelObject, Storable { let wcBracket = _teams.filter { $0.wildCardBracket }.sorted(using: _currentSelectionSorting, order: .ascending) - var bracketSeeds = min(teamCount, _completeTeams.count) - groupStageCount * teamsPerGroupStage - wcBracket.count - var groupStageTeamCount = groupStageCount * teamsPerGroupStage - wcGroupStage.count + let groupStageSpots = groupStageSpots() + var bracketSeeds = min(teamCount, _completeTeams.count) - groupStageSpots - wcBracket.count + var groupStageTeamCount = groupStageSpots - wcGroupStage.count if groupStageTeamCount < 0 { groupStageTeamCount = 0 } if bracketSeeds < 0 { bracketSeeds = 0 } @@ -792,7 +802,7 @@ class Tournament : ModelObject, Storable { } func groupStageCut() -> Int { - groupStageCount * teamsPerGroupStage + groupStageSpots() } func cutLabel(index: Int) -> String { @@ -1299,7 +1309,7 @@ class Tournament : ModelObject, Storable { func groupStageStatus() async -> String { let groupStageTeamsCount = groupStageTeams().count - if groupStageTeamsCount == 0 || groupStageTeamsCount != teamsPerGroupStage * groupStageCount { + if groupStageTeamsCount == 0 || groupStageTeamsCount != groupStageSpots() { return "à faire" } let runningGroupStages = groupStages().filter({ $0.isRunning() })