sync2
Raz 8 months ago
parent f7c393fc07
commit fdfe9b92ee
  1. 7
      PadelClub/Data/Tournament.swift
  2. 2
      PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift
  3. 12
      PadelClub/Views/Tournament/Screen/TableStructureView.swift

@ -1941,9 +1941,11 @@ defer {
return bracketTeamCount return bracketTeamCount
} }
func buildBracket() { func buildBracket(minimalBracketTeamCount: Int? = nil) {
guard rounds().isEmpty else { return } guard rounds().isEmpty else { return }
let roundCount = RoundRule.numberOfRounds(forTeams: bracketTeamCount()) let roundCount = RoundRule.numberOfRounds(forTeams: minimalBracketTeamCount ?? bracketTeamCount())
let matchCount = RoundRule.numberOfMatches(forTeams: minimalBracketTeamCount ?? bracketTeamCount())
let rounds = (0..<roundCount).map { //index 0 is the final let rounds = (0..<roundCount).map { //index 0 is the final
return Round(tournament: id, index: $0, matchFormat: roundSmartMatchFormat($0), loserBracketMode: loserBracketMode) return Round(tournament: id, index: $0, matchFormat: roundSmartMatchFormat($0), loserBracketMode: loserBracketMode)
@ -1958,7 +1960,6 @@ defer {
} catch { } catch {
Logger.error(error) Logger.error(error)
} }
let matchCount = RoundRule.numberOfMatches(forTeams: bracketTeamCount())
let matches = (0..<matchCount).map { //0 is final match let matches = (0..<matchCount).map { //0 is final match
let roundIndex = RoundRule.roundIndex(fromMatchIndex: $0) let roundIndex = RoundRule.roundIndex(fromMatchIndex: $0)

@ -255,7 +255,7 @@ struct RegistrationSetupView: View {
} }
.onChange(of: targetTeamCount) { .onChange(of: targetTeamCount) {
displayWarning = true displayWarning = targetTeamCount != tournament.teamCount
_hasChanged() _hasChanged()
} }

@ -98,7 +98,7 @@ struct TableStructureView: View {
Text("Nombre d'équipes") Text("Nombre d'équipes")
} }
.onChange(of: teamCount) { .onChange(of: teamCount) {
displayWarning = true displayWarning = teamCount != tournament.teamCount
} }
LabeledContent { LabeledContent {
StepperView(count: $groupStageCount, minimum: 0, maximum: maxGroupStages) { StepperView(count: $groupStageCount, minimum: 0, maximum: maxGroupStages) {
@ -261,6 +261,16 @@ struct TableStructureView: View {
} }
} }
if tournament.rounds().isEmpty {
Section {
RowButtonView("Ajouter un tableau", role: .destructive) {
tournament.buildBracket(minimalBracketTeamCount: 4)
}
} footer: {
Text("Vous pourrez ensuite modifier le nombre de tour dans l'écran de réglages du tableau.")
}
}
if tournament.state() != .initial { if tournament.state() != .initial {
Section { Section {

Loading…
Cancel
Save