add multi waves of group stage matchs management

paca_championship
Raz 1 year ago
parent 619702bcff
commit 884f1d9186
  1. 16
      PadelClub.xcodeproj/project.pbxproj
  2. 61
      PadelClub/Data/GroupStage.swift
  3. 16
      PadelClub/Views/GroupStage/Components/GroupStageSettingsView.swift
  4. 8
      PadelClub/Views/GroupStage/GroupStagesSettingsView.swift

@ -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 = "";

@ -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..<count).flatMap { i in
order.map { $0 + i * order.count }
}
let result = repeatedArray.map { ordered[$0] }
return result
} else {
return ordered
}
@ -340,12 +360,6 @@ final class GroupStage: ModelObject, Storable {
order = []
}
if isReturnMatchEnabled() {
let arraySize = order.count
// Duplicate and increment each value by the array size
order += order.map { $0 + arraySize }
}
return order
}
@ -359,17 +373,32 @@ final class GroupStage: ModelObject, Storable {
return combinations[safe: matchIndex%matchCount] ?? []
}
func returnMatchesSuffix(for matchIndex: Int) -> 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? {

@ -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()
}
}
}

@ -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"
}
}
}

Loading…
Cancel
Save