|
|
|
|
@ -112,11 +112,17 @@ final class GroupStage: ModelObject, Storable { |
|
|
|
|
matchFormat: self.matchFormat, |
|
|
|
|
name: self.localizedMatchUpLabel(for: index)) |
|
|
|
|
match.store = self.store |
|
|
|
|
print("_createMatch(index)", index) |
|
|
|
|
return match |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func removeReturnMatches() { |
|
|
|
|
let returnMatches = _matches().filter({ $0.index >= matchCount }) |
|
|
|
|
func removeReturnMatches(onlyLast: Bool = false) { |
|
|
|
|
|
|
|
|
|
var returnMatches = _matches().filter({ $0.index >= matchCount }) |
|
|
|
|
if onlyLast { |
|
|
|
|
let matchPhaseCount = matchPhaseCount - 1 |
|
|
|
|
returnMatches = returnMatches.filter({ $0.index >= matchCount * matchPhaseCount }) |
|
|
|
|
} |
|
|
|
|
do { |
|
|
|
|
try self.tournamentStore.matches.delete(contentOfs: returnMatches) |
|
|
|
|
} catch { |
|
|
|
|
@ -124,12 +130,21 @@ final class GroupStage: ModelObject, Storable { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var matchPhaseCount: Int { |
|
|
|
|
let count = _matches().count |
|
|
|
|
if matchCount > 0 { |
|
|
|
|
return count / matchCount |
|
|
|
|
} else { |
|
|
|
|
return 0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func addReturnMatches() { |
|
|
|
|
var teamScores = [TeamScore]() |
|
|
|
|
var matches = [Match]() |
|
|
|
|
|
|
|
|
|
let matchPhaseCount = matchPhaseCount |
|
|
|
|
for i in 0..<_numberOfMatchesToBuild() { |
|
|
|
|
let newMatch = self._createMatch(index: i + matchCount) |
|
|
|
|
let newMatch = self._createMatch(index: i + matchCount * matchPhaseCount) |
|
|
|
|
// let newMatch = Match(groupStage: self.id, index: i, matchFormat: self.matchFormat, name: localizedMatchUpLabel(for: i)) |
|
|
|
|
teamScores.append(contentsOf: newMatch.createTeamScores()) |
|
|
|
|
matches.append(newMatch) |
|
|
|
|
@ -174,10 +189,15 @@ final class GroupStage: ModelObject, Storable { |
|
|
|
|
|
|
|
|
|
func playedMatches() -> [Match] { |
|
|
|
|
let ordered = _matches() |
|
|
|
|
if ordered.isEmpty == false && ordered.count == _matchOrder().count { |
|
|
|
|
return _matchOrder().map { |
|
|
|
|
ordered[$0] |
|
|
|
|
let order = _matchOrder() |
|
|
|
|
let matchCount = max(1, matchCount) |
|
|
|
|
let count = ordered.count / matchCount |
|
|
|
|
if ordered.isEmpty == false && ordered.count % order.count == 0 { |
|
|
|
|
let repeatedArray = (0..<count).flatMap { i in |
|
|
|
|
order.map { $0 + i * order.count } |
|
|
|
|
} |
|
|
|
|
let result = repeatedArray.map { ordered[$0] } |
|
|
|
|
return result |
|
|
|
|
} else { |
|
|
|
|
return ordered |
|
|
|
|
} |
|
|
|
|
@ -340,12 +360,6 @@ final class GroupStage: ModelObject, Storable { |
|
|
|
|
order = [] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if isReturnMatchEnabled() { |
|
|
|
|
let arraySize = order.count |
|
|
|
|
// Duplicate and increment each value by the array size |
|
|
|
|
order += order.map { $0 + arraySize } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return order |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -359,17 +373,32 @@ final class GroupStage: ModelObject, Storable { |
|
|
|
|
return combinations[safe: matchIndex%matchCount] ?? [] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func returnMatchesSuffix(for matchIndex: Int) -> String { |
|
|
|
|
if matchCount > 0 { |
|
|
|
|
let count = _matches().count |
|
|
|
|
if count > matchCount * 2 { |
|
|
|
|
return " - vague \((matchIndex / matchCount) + 1)" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if matchIndex >= matchCount { |
|
|
|
|
return " - retour" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return "" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func localizedMatchUpLabel(for matchIndex: Int) -> String { |
|
|
|
|
let matchUp = _matchUp(for: matchIndex) |
|
|
|
|
if let index = matchUp.first, let index2 = matchUp.last { |
|
|
|
|
return "#\(index + 1) vs #\(index2 + 1)" + (matchIndex >= matchCount ? " - retour" : "") |
|
|
|
|
return "#\(index + 1) vs #\(index2 + 1)" + returnMatchesSuffix(for: matchIndex) |
|
|
|
|
} else { |
|
|
|
|
return "--" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var matchCount: Int { |
|
|
|
|
(size * size - 1) / 2 |
|
|
|
|
(size * (size - 1)) / 2 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func team(teamPosition team: TeamPosition, inMatchIndex matchIndex: Int) -> TeamRegistration? { |
|
|
|
|
|