fix issue with auto structure

main
Razmig Sarkissian 2 weeks ago
parent b287b67a0c
commit a5445e7280
  1. 29
      PadelClub/Views/Tournament/Screen/TableStructureView.swift

@ -238,6 +238,8 @@ struct TableStructureView: View {
} }
} }
if selectedTournament == nil {
Section { Section {
if groupStageCount > 0 { if groupStageCount > 0 {
if structurePreset != .doubleGroupStage { if structurePreset != .doubleGroupStage {
@ -267,13 +269,13 @@ struct TableStructureView: View {
} }
} }
// if groupStageCount > 0 { // if groupStageCount > 0 {
// LabeledContent { // LabeledContent {
// Text(tf.formatted()) // Text(tf.formatted())
// } label: { // } label: {
// Text("Effectif tableau") // Text("Effectif tableau")
// } // }
// } // }
} else { } else {
LabeledContent { LabeledContent {
let mp1 = teamsPerGroupStage * (teamsPerGroupStage - 1) / 2 * groupStageCount let mp1 = teamsPerGroupStage * (teamsPerGroupStage - 1) / 2 * groupStageCount
@ -326,7 +328,7 @@ struct TableStructureView: View {
Text("Vous pourrez ensuite modifier le nombre de tour dans l'écran de réglages du tableau.") 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 {
if seedRepartition.isEmpty == false { if seedRepartition.isEmpty == false {
@ -661,7 +663,7 @@ struct TableStructureView: View {
tournament.tournamentStore?.matches.addOrUpdate(contentOfs: tournament._allMatchesIncludingDisabled()) tournament.tournamentStore?.matches.addOrUpdate(contentOfs: tournament._allMatchesIncludingDisabled())
} }
if seedRepartition.count > 0 { if seedRepartition.count > 0, selectedTournament == nil {
await _handleSeedRepartition() await _handleSeedRepartition()
} }
} else if (rebuildEverything == false && requirements.contains(.groupStage)) { } else if (rebuildEverything == false && requirements.contains(.groupStage)) {
@ -683,13 +685,16 @@ struct TableStructureView: View {
} }
private func _handleSeedRepartition() async { private func _handleSeedRepartition() async {
while tournament.rounds().count < seedRepartition.count { let rounds = tournament.rounds()
await tournament.addNewRound(tournament.rounds().count) var roundsCount = rounds.count
while roundsCount < seedRepartition.count {
await tournament.addNewRound(roundsCount)
roundsCount += 1
} }
if seedRepartition.reduce(0, +) > 0 { if seedRepartition.reduce(0, +) > 0 {
let rounds = tournament.rounds() let rounds = tournament.rounds()
let roundsToDelete = rounds.suffix(rounds.count - seedRepartition.count) let roundsToDelete = rounds.prefix(rounds.count - seedRepartition.count)
for round in roundsToDelete { for round in roundsToDelete {
await tournament.removeRound(round) await tournament.removeRound(round)
} }

Loading…
Cancel
Save