|
|
|
@ -54,31 +54,10 @@ struct LoserBracketFromGroupStageView: View { |
|
|
|
} |
|
|
|
} |
|
|
|
} footer: { |
|
|
|
} footer: { |
|
|
|
if isEditingLoserBracketGroupStage == true { |
|
|
|
if isEditingLoserBracketGroupStage == true { |
|
|
|
HStack { |
|
|
|
GroupStageLoserBracketMatchFooterView(match: match, samePlaceThanAboveOption: displayableMatches.count > 1) |
|
|
|
if match.index > tournament.groupStageLoserBracketsInitialPlace() { |
|
|
|
|
|
|
|
FooterButtonView("même place qu'au-dessus") { |
|
|
|
|
|
|
|
match.index -= 2 |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
try tournamentStore.matches.addOrUpdate(instance: match) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Spacer() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
FooterButtonView("effacer", role: .destructive) { |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
try match.deleteDependencies() |
|
|
|
|
|
|
|
try tournamentStore.matches.delete(instance: match) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
Section { |
|
|
|
if displayableMatches.count > 1 && isEditingLoserBracketGroupStage == true { |
|
|
|
if displayableMatches.count > 1 && isEditingLoserBracketGroupStage == true { |
|
|
|
Section { |
|
|
|
Section { |
|
|
|
@ -124,7 +103,8 @@ struct LoserBracketFromGroupStageView: View { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func _addNewMatch() { |
|
|
|
private func _addNewMatch() { |
|
|
|
let placeCount = tournament.groupStageLoserBracketsInitialPlace() + displayableMatches.count * 2 |
|
|
|
let currentGroupStageLoserBracketsInitialPlace = tournament.groupStageLoserBracketsInitialPlace() |
|
|
|
|
|
|
|
let placeCount = displayableMatches.isEmpty ? currentGroupStageLoserBracketsInitialPlace : max(currentGroupStageLoserBracketsInitialPlace, displayableMatches.map({ $0.index }).max()! + 2) |
|
|
|
let match = Match(round: loserBracket.id, index: placeCount, matchFormat: loserBracket.matchFormat) |
|
|
|
let match = Match(round: loserBracket.id, index: placeCount, matchFormat: loserBracket.matchFormat) |
|
|
|
match.name = "\(placeCount)\(placeCount.ordinalFormattedSuffix()) place" |
|
|
|
match.name = "\(placeCount)\(placeCount.ordinalFormattedSuffix()) place" |
|
|
|
do { |
|
|
|
do { |
|
|
|
@ -148,3 +128,79 @@ struct LoserBracketFromGroupStageView: View { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct GroupStageLoserBracketMatchFooterView: View { |
|
|
|
|
|
|
|
@Environment(Tournament.self) var tournament: Tournament |
|
|
|
|
|
|
|
@Bindable var match: Match |
|
|
|
|
|
|
|
let samePlaceThanAboveOption: Bool |
|
|
|
|
|
|
|
@State private var selectPlacePlayed: Bool = false |
|
|
|
|
|
|
|
@State private var index: Int = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
|
|
|
HStack { |
|
|
|
|
|
|
|
Menu { |
|
|
|
|
|
|
|
if samePlaceThanAboveOption { |
|
|
|
|
|
|
|
Button("Même place qu'au-dessus") { |
|
|
|
|
|
|
|
_updateIndex(match.index-2) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Button("Choisir la place") { |
|
|
|
|
|
|
|
index = match.index |
|
|
|
|
|
|
|
selectPlacePlayed = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} label: { |
|
|
|
|
|
|
|
Text("Éditer la place jouée") |
|
|
|
|
|
|
|
.underline() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Spacer() |
|
|
|
|
|
|
|
FooterButtonView("Effacer", role: .destructive) { |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
try match.deleteDependencies() |
|
|
|
|
|
|
|
try match.tournamentStore.matches.delete(instance: match) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.alert("Place jouée", isPresented: $selectPlacePlayed) { |
|
|
|
|
|
|
|
TextField("Place jouée", value: $index, format: .number) |
|
|
|
|
|
|
|
.keyboardType(.numberPad) |
|
|
|
|
|
|
|
.multilineTextAlignment(.trailing) |
|
|
|
|
|
|
|
.onSubmit { |
|
|
|
|
|
|
|
_updateIndex(index) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Button("Confirmer") { |
|
|
|
|
|
|
|
_updateIndex(index) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Button("Annuler", role: .cancel) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func _updateIndex(_ newIndex: Int) { |
|
|
|
|
|
|
|
let newIndexValidated = max(1,abs(newIndex)) |
|
|
|
|
|
|
|
let teamScores = match.teamScores |
|
|
|
|
|
|
|
teamScores.forEach { ts in |
|
|
|
|
|
|
|
if let luckyLoser = ts.luckyLoser { |
|
|
|
|
|
|
|
ts.luckyLoser = (luckyLoser - match.index * 2) % 2 + newIndexValidated * 2 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match.index = newIndexValidated |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match.name = "\(newIndexValidated)\(newIndexValidated.ordinalFormattedSuffix()) place" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
try match.tournamentStore.teamScores.addOrUpdate(contentOfs: teamScores) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
try match.tournamentStore.matches.addOrUpdate(instance: match) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|