fix stuff loser bracket / spin drawing

club_update
Razmig Sarkissian 1 year ago
parent 9f32bf3dbd
commit 610e69f0d4
  1. 2
      PadelClub/Data/Round.swift
  2. 16
      PadelClub/Views/Components/FortuneWheelView.swift
  3. 8
      PadelClub/Views/Planning/PlanningSettingsView.swift
  4. 14
      PadelClub/Views/Round/LoserRoundView.swift
  5. 2
      PadelClub/Views/Round/LoserRoundsView.swift
  6. 9
      PadelClub/Views/Round/RoundSettingsView.swift
  7. 81
      PadelClub/Views/Round/RoundView.swift

@ -480,7 +480,7 @@ defer {
if (previousRound.enabledMatches().isEmpty == false || initialMode) { if (previousRound.enabledMatches().isEmpty == false || initialMode) {
return previousRound.seedInterval(initialMode: initialMode)?.chunks()?.first return previousRound.seedInterval(initialMode: initialMode)?.chunks()?.first
} else { } else {
return previousRound.previousRound()?.seedInterval(initialMode: initialMode) return previousRound.seedInterval(initialMode: initialMode)
} }
} else if let parentRound { } else if let parentRound {
if parentRound.parent == nil { if parentRound.parent == nil {

@ -62,7 +62,7 @@ struct SpinDrawView: View {
let drawees: [any SpinDrawable] let drawees: [any SpinDrawable]
@State var segments: [any SpinDrawable] @State var segments: [any SpinDrawable]
var autoMode: Bool = false var autoMode: Bool = false
let completion: ([DrawResult]) -> Void // Completion closure let completion: ([DrawResult]) async -> Void // Completion closure
@State private var drawCount: Int = 0 @State private var drawCount: Int = 0
@State private var draws: [DrawResult] = [DrawResult]() @State private var draws: [DrawResult] = [DrawResult]()
@ -82,7 +82,7 @@ struct SpinDrawView: View {
_validationLabelView(drawee: drawCount, result: segments[draws.last!.drawIndex]) _validationLabelView(drawee: drawCount, result: segments[draws.last!.drawIndex])
if autoMode == false || drawCount == drawees.count { if autoMode == false || drawCount == drawees.count {
RowButtonView("Valider le tirage") { RowButtonView("Valider le tirage") {
completion(draws) await completion(draws)
dismiss() dismiss()
} }
} }
@ -173,10 +173,16 @@ struct SpinDrawView: View {
ToolbarItem(placement: .topBarTrailing) { ToolbarItem(placement: .topBarTrailing) {
Button { Button {
validating = true validating = true
completion(draws) Task {
dismiss() await completion(draws)
dismiss()
}
} label: { } label: {
Text("Tout valider") if validating {
ProgressView()
} else {
Text("Tout valider")
}
} }
} }

@ -220,8 +220,12 @@ struct PlanningSettingsView: View {
} label: { } label: {
Text("Poules en parallèle") Text("Poules en parallèle")
let value = tournament.getGroupStageChunkValue() let value = tournament.getGroupStageChunkValue()
if parallelType == false, value > 1 { if parallelType == false {
Text("\(value.formatted()) poules commenceront en parallèle") if value > 1 {
Text("\(value.formatted()) poules commenceront en parallèle")
} else {
Text("une poule sera jouer à la fois")
}
} }
} }
.onChange(of: parallelType) { .onChange(of: parallelType) {

@ -65,6 +65,20 @@ struct LoserRoundView: View {
Spacer() Spacer()
Text(seedIntervalPointRange) Text(seedIntervalPointRange)
.font(.caption) .font(.caption)
} else {
if let previousRound = loserRound.previousRound() {
if let seedInterval = previousRound.seedInterval() {
Text(seedInterval.localizedLabel())
} else {
Text("no previous round")
}
} else if let parentRound = loserRound.parentRound {
if let seedInterval = parentRound.seedInterval() {
Text(seedInterval.localizedLabel())
} else {
Text("no parent round")
}
}
} }
} }
} }

@ -15,13 +15,11 @@ class UpperRound: Identifiable, Selectable {
}() }()
let title: String let title: String
let playedMatches: [Match] let playedMatches: [Match]
let correspondingLoserRoundTitle: String
init(round: Round) { init(round: Round) {
self.round = round self.round = round
self.title = round.roundTitle(.short) self.title = round.roundTitle(.short)
self.playedMatches = round.playedMatches() self.playedMatches = round.playedMatches()
self.correspondingLoserRoundTitle = round.correspondingLoserRoundTitle()
} }
func loserMatches() -> [Match] { func loserMatches() -> [Match] {

@ -99,14 +99,15 @@ struct RoundSettingsView: View {
let nextRound = round.nextRound() let nextRound = round.nextRound()
var currentIndex = 0 var currentIndex = 0
let matches = (0..<matchCount).map { index in //0 is final match let matches = (0..<matchCount).map { index in //0 is final match
let match = Match(round: round.id, index: index + matchStartIndex, matchFormat: round.matchFormat) let computedIndex = index + matchStartIndex
if let nextRound, let followingMatch = self.tournament.tournamentStore.matches.first(where: { $0.round == nextRound.id && $0.index == (index - 1) / 2 }) { let match = Match(round: round.id, index: computedIndex, matchFormat: round.matchFormat)
if let nextRound, let followingMatch = self.tournament.tournamentStore.matches.first(where: { $0.round == nextRound.id && $0.index == (computedIndex - 1) / 2 }) {
if followingMatch.disabled { if followingMatch.disabled {
match.disabled = true match.disabled = true
} else if index%2 == 1 && followingMatch.team(.one) != nil { } else if computedIndex%2 == 1 && followingMatch.team(.one) != nil {
//index du match courant impair = position haut du prochain match //index du match courant impair = position haut du prochain match
match.disabled = true match.disabled = true
} else if index%2 == 0 && followingMatch.team(.two) != nil { } else if computedIndex%2 == 0 && followingMatch.team(.two) != nil {
//index du match courant pair = position basse du prochain match //index du match courant pair = position basse du prochain match
match.disabled = true match.disabled = true
} else { } else {

@ -87,11 +87,12 @@ struct RoundView: View {
.tipStyle(tint: .master, asSection: true) .tipStyle(tint: .master, asSection: true)
if upperRound.loserRounds.isEmpty == false { if upperRound.loserRounds.isEmpty == false {
let correspondingLoserRoundTitle = upperRound.round.correspondingLoserRoundTitle()
Section { Section {
NavigationLink { NavigationLink {
LoserRoundsView(upperBracketRound: upperRound) LoserRoundsView(upperBracketRound: upperRound)
.environment(tournament) .environment(tournament)
.navigationTitle(upperRound.correspondingLoserRoundTitle) .navigationTitle(correspondingLoserRoundTitle)
} label: { } label: {
LabeledContent { LabeledContent {
let status = upperRound.status() let status = upperRound.status()
@ -101,7 +102,7 @@ struct RoundView: View {
Text("\(status.0) terminé\(status.0.pluralSuffix) sur \(status.1)") Text("\(status.0) terminé\(status.0.pluralSuffix) sur \(status.1)")
} }
} label: { } label: {
Text(upperRound.correspondingLoserRoundTitle) Text(correspondingLoserRoundTitle)
} }
} }
} }
@ -129,12 +130,14 @@ struct RoundView: View {
if availableSeeds.isEmpty == false, let availableSeedGroup { if availableSeeds.isEmpty == false, let availableSeedGroup {
Section { Section {
RowButtonView("Placer \(availableSeedGroup.localizedLabel())" + ((availableSeedGroup.isFixed() == false) ? " au hasard" : "")) { RowButtonView("Placer \(availableSeedGroup.localizedLabel())" + ((availableSeedGroup.isFixed() == false) ? " au hasard" : "")) {
tournament.setSeeds(inRoundIndex: upperRound.round.index, inSeedGroup: availableSeedGroup) Task {
_save() tournament.setSeeds(inRoundIndex: upperRound.round.index, inSeedGroup: availableSeedGroup)
if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty { _save()
self.isEditingTournamentSeed.wrappedValue = false if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty {
self.isEditingTournamentSeed.wrappedValue = false
}
_prepareRound()
} }
_prepareRound()
} }
} footer: { } footer: {
if availableSeedGroup.isFixed() == false { if availableSeedGroup.isFixed() == false {
@ -160,14 +163,16 @@ struct RoundView: View {
ForEach(availableQualifiedTeams) { team in ForEach(availableQualifiedTeams) { team in
NavigationLink { NavigationLink {
SpinDrawView(drawees: [team], segments: spaceLeft) { results in SpinDrawView(drawees: [team], segments: spaceLeft) { results in
results.forEach { drawResult in Task {
team.setSeedPosition(inSpot: spaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: true) results.forEach { drawResult in
} team.setSeedPosition(inSpot: spaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: true)
_save() }
if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty { _save()
self.isEditingTournamentSeed.wrappedValue = false if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty {
self.isEditingTournamentSeed.wrappedValue = false
}
_prepareRound()
} }
_prepareRound()
} }
} label: { } label: {
TeamRowView(team: team, displayCallDate: false) TeamRowView(team: team, displayCallDate: false)
@ -189,14 +194,16 @@ struct RoundView: View {
ForEach(availableSeeds) { team in ForEach(availableSeeds) { team in
NavigationLink { NavigationLink {
SpinDrawView(drawees: [team], segments: seedSpaceLeft) { results in SpinDrawView(drawees: [team], segments: seedSpaceLeft) { results in
results.forEach { drawResult in Task {
team.setSeedPosition(inSpot: seedSpaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: false) results.forEach { drawResult in
team.setSeedPosition(inSpot: seedSpaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: false)
}
_save()
if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty {
self.isEditingTournamentSeed.wrappedValue = false
}
_prepareRound()
} }
_save()
if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty {
self.isEditingTournamentSeed.wrappedValue = false
}
_prepareRound()
} }
} label: { } label: {
TeamRowView(team: team, displayCallDate: false) TeamRowView(team: team, displayCallDate: false)
@ -214,14 +221,16 @@ struct RoundView: View {
ForEach(availableSeeds) { team in ForEach(availableSeeds) { team in
NavigationLink { NavigationLink {
SpinDrawView(drawees: [team], segments: spaceLeft) { results in SpinDrawView(drawees: [team], segments: spaceLeft) { results in
results.forEach { drawResult in Task {
team.setSeedPosition(inSpot: spaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: true) results.forEach { drawResult in
} team.setSeedPosition(inSpot: spaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: true)
_save() }
if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty { _save()
self.isEditingTournamentSeed.wrappedValue = false if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty {
self.isEditingTournamentSeed.wrappedValue = false
}
_prepareRound()
} }
_prepareRound()
} }
} label: { } label: {
TeamRowView(team: team, displayCallDate: false) TeamRowView(team: team, displayCallDate: false)
@ -286,15 +295,17 @@ struct RoundView: View {
let availableSeedSpot = opposingSeeding ? spaceLeft : seedSpaceLeft let availableSeedSpot = opposingSeeding ? spaceLeft : seedSpaceLeft
NavigationStack { NavigationStack {
SpinDrawView(drawees: seeds, segments: availableSeedSpot, autoMode: true) { draws in SpinDrawView(drawees: seeds, segments: availableSeedSpot, autoMode: true) { draws in
draws.forEach { drawResult in Task {
seeds[drawResult.drawee].setSeedPosition(inSpot: availableSeedSpot[drawResult.drawIndex], slot: nil, opposingSeeding: opposingSeeding) draws.forEach { drawResult in
} seeds[drawResult.drawee].setSeedPosition(inSpot: availableSeedSpot[drawResult.drawIndex], slot: nil, opposingSeeding: opposingSeeding)
}
_save() _save()
_prepareRound() _prepareRound()
if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty { if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty {
self.isEditingTournamentSeed.wrappedValue = false self.isEditingTournamentSeed.wrappedValue = false
}
} }
} }
} }

Loading…
Cancel
Save