|
|
|
|
@ -52,8 +52,30 @@ struct RoundSettingsView: View { |
|
|
|
|
let round = Round(tournament: tournament.id, index: roundIndex, matchFormat: tournament.matchFormat) |
|
|
|
|
let matchCount = RoundRule.numberOfMatches(forRoundIndex: roundIndex) |
|
|
|
|
let matchStartIndex = RoundRule.matchIndex(fromRoundIndex: roundIndex) |
|
|
|
|
let matches = (0..<matchCount).map { //0 is final match |
|
|
|
|
return Match(round: round.id, index: $0 + matchStartIndex, matchFormat: round.matchFormat, name: Match.setServerTitle(upperRound: round, matchIndex: $0)) |
|
|
|
|
let nextRound = round.nextRound() |
|
|
|
|
var currentIndex = 0 |
|
|
|
|
let matches = (0..<matchCount).map { index in //0 is final match |
|
|
|
|
let match = Match(round: round.id, index: index + matchStartIndex, matchFormat: round.matchFormat) |
|
|
|
|
|
|
|
|
|
if let nextRound, let followingMatch = match.getFollowingMatch(fromNextRoundId: nextRound.id) { |
|
|
|
|
if followingMatch.disabled { |
|
|
|
|
match.disabled = true |
|
|
|
|
} else if index%2 == 1 && followingMatch.team(.one) != nil { |
|
|
|
|
//index du match courant impair = position haut du prochain match |
|
|
|
|
match.disabled = true |
|
|
|
|
} else if index%2 == 0 && followingMatch.team(.two) != nil { |
|
|
|
|
//index du match courant pair = position basse du prochain match |
|
|
|
|
match.disabled = true |
|
|
|
|
} else { |
|
|
|
|
match.name = Match.setServerTitle(upperRound: round, matchIndex: currentIndex) |
|
|
|
|
currentIndex += 1 |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
match.name = Match.setServerTitle(upperRound: round, matchIndex: currentIndex) |
|
|
|
|
currentIndex += 1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return match |
|
|
|
|
} |
|
|
|
|
do { |
|
|
|
|
try dataStore.rounds.addOrUpdate(instance: round) |
|
|
|
|
@ -66,6 +88,8 @@ struct RoundSettingsView: View { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
round.buildLoserBracket() |
|
|
|
|
matches.filter { $0.disabled }.forEach { $0._toggleLoserMatchDisableState(true) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|