fix bugs double groupstage mode

sync2
Raz 1 year ago
parent 8dec31dd14
commit a01dfcea59
  1. 4
      PadelClub.xcodeproj/project.pbxproj
  2. 12
      PadelClub/Data/GroupStage.swift
  3. 9
      PadelClub/Data/Tournament.swift
  4. 14
      PadelClub/Views/GroupStage/GroupStageView.swift
  5. 13
      PadelClub/Views/Tournament/TournamentBuildView.swift

@ -3134,7 +3134,7 @@
CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements;
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 3;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\"";
@ -3179,7 +3179,7 @@
CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements;
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2; CURRENT_PROJECT_VERSION = 3;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\"";
DEVELOPMENT_TEAM = BQ3Y44M3Q6; DEVELOPMENT_TEAM = BQ3Y44M3Q6;

@ -163,7 +163,11 @@ final class GroupStage: ModelObject, Storable {
Logger.error(error) Logger.error(error)
} }
if tournament.groupStagesAreOver(), tournament.groupStageLoserBracketAreOver(), tournament.rounds().isEmpty { let groupStagesAreOverAtFirstStep = tournament.groupStagesAreOver(atStep: 0)
let nextStepGroupStages = tournament.groupStages(atStep: 1)
let groupStagesAreOverAtSecondStep = tournament.groupStagesAreOver(atStep: 1)
if groupStagesAreOverAtFirstStep, nextStepGroupStages.isEmpty || groupStagesAreOverAtSecondStep == true, tournament.groupStageLoserBracketAreOver(), tournament.rounds().isEmpty {
tournament.endDate = Date() tournament.endDate = Date()
do { do {
try DataStore.shared.tournaments.addOrUpdate(instance: tournament) try DataStore.shared.tournaments.addOrUpdate(instance: tournament)
@ -365,17 +369,17 @@ final class GroupStage: ModelObject, Storable {
func teams(_ sortedByScore: Bool = false, scores: [TeamGroupStageScore]? = nil) -> [TeamRegistration] { func teams(_ sortedByScore: Bool = false, scores: [TeamGroupStageScore]? = nil) -> [TeamRegistration] {
if sortedByScore { if sortedByScore {
return unsortedTeams().compactMap({ team in return unsortedTeams().compactMap({ team in
scores?.first(where: { $0.team.id == team.id }) ?? _score(forGroupStagePosition: team.groupStagePosition!) scores?.first(where: { $0.team.id == team.id }) ?? _score(forGroupStagePosition: team.groupStagePositionAtStep(step)!)
}).sorted { (lhs, rhs) in }).sorted { (lhs, rhs) in
let predicates: [TeamScoreAreInIncreasingOrder] = [ let predicates: [TeamScoreAreInIncreasingOrder] = [
{ $0.wins < $1.wins }, { $0.wins < $1.wins },
{ $0.setDifference < $1.setDifference }, { $0.setDifference < $1.setDifference },
{ $0.gameDifference < $1.gameDifference}, { $0.gameDifference < $1.gameDifference},
{ self._headToHead($0.team, $1.team) }, { self._headToHead($0.team, $1.team) },
{ $0.team.groupStagePosition! > $1.team.groupStagePosition! } { [self] in $0.team.groupStagePositionAtStep(self.step)! > $1.team.groupStagePositionAtStep(self.step)! }
] ]
for predicate in predicates { for predicate in predicates {
if !predicate(lhs, rhs) && !predicate(rhs, lhs) { if !predicate(lhs, rhs) && !predicate(rhs, lhs) {
continue continue
} }

@ -1225,8 +1225,9 @@ defer {
let groupStages = groupStages(atStep: lastStep) let groupStages = groupStages(atStep: lastStep)
for groupStage in groupStages { for groupStage in groupStages {
for (teamIndex, team) in groupStage.teams(true).enumerated() { let groupStageTeams = groupStage.teams(true)
teams[groupStage.index + 1 + teamIndex] = [team.id] for teamIndex in 0..<groupStageTeams.count {
teams[groupStage.index * groupStage.size + 1 + teamIndex] = [groupStageTeams[teamIndex].id]
} }
} }
@ -1512,8 +1513,8 @@ defer {
} }
} }
func groupStagesAreOver() -> Bool { func groupStagesAreOver(atStep: Int = 0) -> Bool {
let groupStages = groupStages() let groupStages = groupStages(atStep: atStep)
guard groupStages.isEmpty == false else { guard groupStages.isEmpty == false else {
return true return true
} }

@ -57,12 +57,24 @@ struct GroupStageView: View {
MatchListView(section: "prêt à démarrer", matches: availableToStart, hideWhenEmpty: true) MatchListView(section: "prêt à démarrer", matches: availableToStart, hideWhenEmpty: true)
.listRowView(isActive: availableToStart.isEmpty == false, color: .green, hideColorVariation: true) .listRowView(isActive: availableToStart.isEmpty == false, color: .green, hideColorVariation: true)
MatchListView(section: "à lancer", matches: groupStage.readyMatches(playedMatches: playedMatches), hideWhenEmpty: true) MatchListView(section: "à lancer", matches: groupStage.readyMatches(playedMatches: playedMatches), hideWhenEmpty: true)
MatchListView(section: "terminés", matches: groupStage.finishedMatches(playedMatches: playedMatches), isExpanded: false) MatchListView(section: "terminés", matches: groupStage.finishedMatches(playedMatches: playedMatches), hideWhenEmpty: playedMatches.isEmpty || playedMatches.flatMap({ $0.teamScores }).isEmpty, isExpanded: false)
if playedMatches.isEmpty { if playedMatches.isEmpty {
RowButtonView("Créer les matchs de poules") { RowButtonView("Créer les matchs de poules") {
groupStage.buildMatches() groupStage.buildMatches()
} }
} else if groupStage.step > 0, playedMatches.flatMap({ $0.teamScores }).isEmpty {
Section {
RowButtonView("Préparer les matchs") {
playedMatches.forEach { match in
match.updateTeamScores()
}
}
.disabled(tournament.groupStagesAreOver(atStep: 0) == false)
} footer: {
Text("La première phase doit être terminée avant de pouvoir préparer les matchs de la deuxième phase de poule.")
}
} }
} }
.toolbar { .toolbar {

@ -60,8 +60,19 @@ struct TournamentBuildView: View {
} }
if tournament.groupStages(atStep: 1).isEmpty == false { if tournament.groupStages(atStep: 1).isEmpty == false {
NavigationLink("2ème phase de poules") { NavigationLink {
GroupStagesView(tournament: tournament, step: 1) GroupStagesView(tournament: tournament, step: 1)
} label: {
LabeledContent {
if tournament.groupStagesAreOver(atStep: 1) {
Text("terminées")
} else {
Text("")
}
} label: {
Text("2ème phase de poules")
}
} }
} }

Loading…
Cancel
Save