diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 9b1b10e..c8384c1 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -3222,7 +3222,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\""; @@ -3246,7 +3246,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.28; + MARKETING_VERSION = 1.0.29; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3267,7 +3267,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; @@ -3290,7 +3290,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.28; + MARKETING_VERSION = 1.0.29; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3383,7 +3383,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -3406,7 +3406,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.26; + MARKETING_VERSION = 1.0.29; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3427,7 +3427,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; @@ -3449,7 +3449,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.26; + MARKETING_VERSION = 1.0.29; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/PadelClub/Data/GroupStage.swift b/PadelClub/Data/GroupStage.swift index e89d98a..b8093f2 100644 --- a/PadelClub/Data/GroupStage.swift +++ b/PadelClub/Data/GroupStage.swift @@ -112,11 +112,17 @@ final class GroupStage: ModelObject, Storable { matchFormat: self.matchFormat, name: self.localizedMatchUpLabel(for: index)) match.store = self.store + print("_createMatch(index)", index) return match } - func removeReturnMatches() { - let returnMatches = _matches().filter({ $0.index >= matchCount }) + func removeReturnMatches(onlyLast: Bool = false) { + + var returnMatches = _matches().filter({ $0.index >= matchCount }) + if onlyLast { + let matchPhaseCount = matchPhaseCount - 1 + returnMatches = returnMatches.filter({ $0.index >= matchCount * matchPhaseCount }) + } do { try self.tournamentStore.matches.delete(contentOfs: returnMatches) } catch { @@ -124,12 +130,21 @@ final class GroupStage: ModelObject, Storable { } } + var matchPhaseCount: Int { + let count = _matches().count + if matchCount > 0 { + return count / matchCount + } else { + return 0 + } + } + func addReturnMatches() { var teamScores = [TeamScore]() var matches = [Match]() - + let matchPhaseCount = matchPhaseCount for i in 0..<_numberOfMatchesToBuild() { - let newMatch = self._createMatch(index: i + matchCount) + let newMatch = self._createMatch(index: i + matchCount * matchPhaseCount) // let newMatch = Match(groupStage: self.id, index: i, matchFormat: self.matchFormat, name: localizedMatchUpLabel(for: i)) teamScores.append(contentsOf: newMatch.createTeamScores()) matches.append(newMatch) @@ -174,10 +189,15 @@ final class GroupStage: ModelObject, Storable { func playedMatches() -> [Match] { let ordered = _matches() - if ordered.isEmpty == false && ordered.count == _matchOrder().count { - return _matchOrder().map { - ordered[$0] + let order = _matchOrder() + let matchCount = max(1, matchCount) + let count = ordered.count / matchCount + if ordered.isEmpty == false && ordered.count % order.count == 0 { + let repeatedArray = (0.. String { + if matchCount > 0 { + let count = _matches().count + if count > matchCount * 2 { + return " - vague \((matchIndex / matchCount) + 1)" + } + + if matchIndex >= matchCount { + return " - retour" + } + } + + return "" + } + func localizedMatchUpLabel(for matchIndex: Int) -> String { let matchUp = _matchUp(for: matchIndex) if let index = matchUp.first, let index2 = matchUp.last { - return "#\(index + 1) vs #\(index2 + 1)" + (matchIndex >= matchCount ? " - retour" : "") + return "#\(index + 1) vs #\(index2 + 1)" + returnMatchesSuffix(for: matchIndex) } else { return "--" } } var matchCount: Int { - (size * size - 1) / 2 + (size * (size - 1)) / 2 } func team(teamPosition team: TeamPosition, inMatchIndex matchIndex: Int) -> TeamRegistration? { diff --git a/PadelClub/Views/GroupStage/Components/GroupStageSettingsView.swift b/PadelClub/Views/GroupStage/Components/GroupStageSettingsView.swift index 6dcd8f9..521b328 100644 --- a/PadelClub/Views/GroupStage/Components/GroupStageSettingsView.swift +++ b/PadelClub/Views/GroupStage/Components/GroupStageSettingsView.swift @@ -154,14 +154,26 @@ struct GroupStageSettingsView: View { } Section { - if groupStage.isReturnMatchEnabled() { + if groupStage.matchPhaseCount > 2 { + RowButtonView("Effacer la dernière vague", role: .destructive) { + groupStage.removeReturnMatches(onlyLast: true) + } + } else if groupStage.isReturnMatchEnabled() { RowButtonView("Effacer les matchs retours", role: .destructive) { groupStage.removeReturnMatches() } - } else { + } + } + + Section { + if groupStage.isReturnMatchEnabled() == false { RowButtonView("Rajouter les matchs retours", role: .destructive) { groupStage.addReturnMatches() } + } else { + RowButtonView("Rajouter une vague de matchs", role: .destructive) { + groupStage.addReturnMatches() + } } } diff --git a/PadelClub/Views/GroupStage/GroupStagesSettingsView.swift b/PadelClub/Views/GroupStage/GroupStagesSettingsView.swift index bafec28..3bf6939 100644 --- a/PadelClub/Views/GroupStage/GroupStagesSettingsView.swift +++ b/PadelClub/Views/GroupStage/GroupStagesSettingsView.swift @@ -191,6 +191,14 @@ struct GroupStagesSettingsView: View { generationDoneMessage = "Matchs retours créés" } + } else if groupStages.allSatisfy({ $0.isReturnMatchEnabled() }) { + RowButtonView("Rajouter une vague de matchs", role: .destructive) { + groupStages.forEach { groupStage in + groupStage.addReturnMatches() + } + + generationDoneMessage = "Nouveaux matchs créés" + } } }