|
|
|
@ -11,78 +11,9 @@ struct RoundSettingsView: View { |
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
@Environment(\.editMode) private var editMode |
|
|
|
@Environment(\.editMode) private var editMode |
|
|
|
@Environment(Tournament.self) var tournament: Tournament |
|
|
|
@Environment(Tournament.self) var tournament: Tournament |
|
|
|
@State private var roundIndex: Int? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var round: Round? { |
|
|
|
|
|
|
|
guard let roundIndex else { return nil } |
|
|
|
|
|
|
|
return tournament.rounds()[roundIndex] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
var body: some View { |
|
|
|
List { |
|
|
|
List { |
|
|
|
if let availableSeedGroup = tournament.availableSeedGroup() { |
|
|
|
|
|
|
|
Section { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Picker(selection: $roundIndex) { |
|
|
|
|
|
|
|
Text("choisir de la manche").tag(nil as Int?) |
|
|
|
|
|
|
|
ForEach(tournament.rounds()) { round in |
|
|
|
|
|
|
|
Text(round.roundTitle()).tag(round.index as Int?) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} label: { |
|
|
|
|
|
|
|
Text(availableSeedGroup.localizedLabel()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let roundIndex { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RowButtonView("Valider") { |
|
|
|
|
|
|
|
if availableSeedGroup == SeedInterval(first: 1, last: 2) { |
|
|
|
|
|
|
|
let seeds = tournament.seeds() |
|
|
|
|
|
|
|
// let startIndex = RoundRule.matchIndex(fromRoundIndex: roundIndex) |
|
|
|
|
|
|
|
// let numberOfMatchInRound = RoundRule.numberOfMatches(forRoundIndex: roundIndex) |
|
|
|
|
|
|
|
// let lastIndex = startIndex + numberOfMatchInRound - 1 |
|
|
|
|
|
|
|
// seeds.prefix(1).first?.bracketPosition = lastIndex * 2 + 1 //TS 1 branche du bas du dernier match |
|
|
|
|
|
|
|
// seeds.prefix(2).dropFirst().first?.bracketPosition = startIndex * 2 //TS 2 branche du haut du premier match |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let matches = tournament.getRound(atRoundIndex: roundIndex)?.playedMatches() { |
|
|
|
|
|
|
|
if let lastMatch = matches.last { |
|
|
|
|
|
|
|
seeds.prefix(1).first?.setSeedPosition(inSpot: lastMatch, slot: .two, opposingSeeding: false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if let firstMatch = matches.first { |
|
|
|
|
|
|
|
seeds.prefix(2).dropFirst().first?.setSeedPosition(inSpot: firstMatch, slot: .one, opposingSeeding: false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
try? dataStore.teamRegistrations.addOrUpdate(contentOfs: seeds) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
tournament.setSeeds(inRoundIndex: roundIndex, inSeedGroup: availableSeedGroup) |
|
|
|
|
|
|
|
try? dataStore.teamRegistrations.addOrUpdate(contentOfs: tournament.seeds()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if tournament.availableSeeds().isEmpty { |
|
|
|
|
|
|
|
editMode?.wrappedValue = .inactive |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} header: { |
|
|
|
|
|
|
|
Text("Placement des têtes de série") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// Section { |
|
|
|
|
|
|
|
// RowButtonView("Effacer classement", role: .destructive) { |
|
|
|
|
|
|
|
// tournament.rounds().forEach { round in |
|
|
|
|
|
|
|
// try? dataStore.rounds.delete(contentOfs: round.loserRounds()) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
// Section { |
|
|
|
|
|
|
|
// RowButtonView("Match de classement") { |
|
|
|
|
|
|
|
// tournament.rounds().forEach { round in |
|
|
|
|
|
|
|
// round.buildLoserBracket() |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
Section { |
|
|
|
Section { |
|
|
|
RowButtonView("Retirer toutes les têtes de séries", role: .destructive) { |
|
|
|
RowButtonView("Retirer toutes les têtes de séries", role: .destructive) { |
|
|
|
tournament.unsortedTeams().forEach({ $0.bracketPosition = nil }) |
|
|
|
tournament.unsortedTeams().forEach({ $0.bracketPosition = nil }) |
|
|
|
@ -90,14 +21,7 @@ struct RoundSettingsView: View { |
|
|
|
tournament.allRounds().forEach({ round in |
|
|
|
tournament.allRounds().forEach({ round in |
|
|
|
round.enableRound() |
|
|
|
round.enableRound() |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
editMode?.wrappedValue = .active |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
|
|
|
if let lastRound = tournament.rounds().first { // first is final, last round |
|
|
|
|
|
|
|
RowButtonView("Supprimer " + lastRound.roundTitle(), role: .destructive) { |
|
|
|
|
|
|
|
try? dataStore.rounds.delete(instance: lastRound) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -116,6 +40,13 @@ struct RoundSettingsView: View { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
|
|
|
if let lastRound = tournament.rounds().first { // first is final, last round |
|
|
|
|
|
|
|
RowButtonView("Supprimer " + lastRound.roundTitle(), role: .destructive) { |
|
|
|
|
|
|
|
try? dataStore.rounds.delete(instance: lastRound) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|