diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 32f1a3e..9dd434e 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -1660,31 +1660,32 @@ defer { if groupStageCount != numberOfBracketsAsInt { deleteGroupStages() buildGroupStages() - } - - let max = groupStages.map { $0.size }.reduce(0,+) - var chunks = selectedSortedTeams().suffix(max).chunked(into: groupStageCount) - for (index, _) in chunks.enumerated() { - if randomize { - chunks[index].shuffle() - } else if index % 2 != 0 { - chunks[index].reverse() + } else { + + let max = groupStages.map { $0.size }.reduce(0,+) + var chunks = selectedSortedTeams().suffix(max).chunked(into: groupStageCount) + for (index, _) in chunks.enumerated() { + if randomize { + chunks[index].shuffle() + } else if index % 2 != 0 { + chunks[index].reverse() + } + + print("Equipes \(chunks[index].map { $0.weight })") + for (jIndex, _) in chunks[index].enumerated() { + print("Position \(index + 1) Poule \(groupStages[jIndex].index)") + chunks[index][jIndex].groupStage = groupStages[jIndex].id + chunks[index][jIndex].groupStagePosition = index + } } - print("Equipes \(chunks[index].map { $0.weight })") - for (jIndex, _) in chunks[index].enumerated() { - print("Position \(index + 1) Poule \(groupStages[jIndex].index)") - chunks[index][jIndex].groupStage = groupStages[jIndex].id - chunks[index][jIndex].groupStagePosition = index + do { + try self.tournamentStore.teamRegistrations.addOrUpdate(contentOfs: unsortedTeams()) + } catch { + Logger.error(error) } + groupStages.forEach { $0.buildMatches() } } - - do { - try self.tournamentStore.teamRegistrations.addOrUpdate(contentOfs: unsortedTeams()) - } catch { - Logger.error(error) - } - groupStages.forEach { $0.buildMatches() } }