fix stuff loser bracket / spin drawing

club_update
Razmig Sarkissian 1 year ago
parent 9f32bf3dbd
commit 610e69f0d4
  1. 2
      PadelClub/Data/Round.swift
  2. 12
      PadelClub/Views/Components/FortuneWheelView.swift
  3. 6
      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. 15
      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,12 +173,18 @@ struct SpinDrawView: View {
ToolbarItem(placement: .topBarTrailing) { ToolbarItem(placement: .topBarTrailing) {
Button { Button {
validating = true validating = true
completion(draws) Task {
await completion(draws)
dismiss() dismiss()
}
} label: { } label: {
if validating {
ProgressView()
} else {
Text("Tout valider") Text("Tout valider")
} }
} }
}
ToolbarItem(placement: .status) { ToolbarItem(placement: .status) {
Text("Tous les tirages sont terminés") Text("Tous les tirages sont terminés")

@ -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 {
if value > 1 {
Text("\(value.formatted()) poules commenceront en parallèle") 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,6 +130,7 @@ 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" : "")) {
Task {
tournament.setSeeds(inRoundIndex: upperRound.round.index, inSeedGroup: availableSeedGroup) tournament.setSeeds(inRoundIndex: upperRound.round.index, inSeedGroup: availableSeedGroup)
_save() _save()
if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty { if tournament.availableSeeds().isEmpty && tournament.availableQualifiedTeams().isEmpty {
@ -136,6 +138,7 @@ struct RoundView: View {
} }
_prepareRound() _prepareRound()
} }
}
} footer: { } footer: {
if availableSeedGroup.isFixed() == false { if availableSeedGroup.isFixed() == false {
Text("Le tirage au sort ne sera pas visuel. Toutes les équipes de ce chapeau seront tirées.") Text("Le tirage au sort ne sera pas visuel. Toutes les équipes de ce chapeau seront tirées.")
@ -160,6 +163,7 @@ 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
Task {
results.forEach { drawResult in results.forEach { drawResult in
team.setSeedPosition(inSpot: spaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: true) team.setSeedPosition(inSpot: spaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: true)
} }
@ -169,6 +173,7 @@ struct RoundView: View {
} }
_prepareRound() _prepareRound()
} }
}
} label: { } label: {
TeamRowView(team: team, displayCallDate: false) TeamRowView(team: team, displayCallDate: false)
} }
@ -189,6 +194,7 @@ 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
Task {
results.forEach { drawResult in results.forEach { drawResult in
team.setSeedPosition(inSpot: seedSpaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: false) team.setSeedPosition(inSpot: seedSpaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: false)
} }
@ -198,6 +204,7 @@ struct RoundView: View {
} }
_prepareRound() _prepareRound()
} }
}
} label: { } label: {
TeamRowView(team: team, displayCallDate: false) TeamRowView(team: team, displayCallDate: false)
} }
@ -214,6 +221,7 @@ 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
Task {
results.forEach { drawResult in results.forEach { drawResult in
team.setSeedPosition(inSpot: spaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: true) team.setSeedPosition(inSpot: spaceLeft[drawResult.drawIndex], slot: nil, opposingSeeding: true)
} }
@ -223,6 +231,7 @@ struct RoundView: View {
} }
_prepareRound() _prepareRound()
} }
}
} label: { } label: {
TeamRowView(team: team, displayCallDate: false) TeamRowView(team: team, displayCallDate: false)
} }
@ -286,6 +295,7 @@ 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
Task {
draws.forEach { drawResult in draws.forEach { drawResult in
seeds[drawResult.drawee].setSeedPosition(inSpot: availableSeedSpot[drawResult.drawIndex], slot: nil, opposingSeeding: opposingSeeding) seeds[drawResult.drawee].setSeedPosition(inSpot: availableSeedSpot[drawResult.drawIndex], slot: nil, opposingSeeding: opposingSeeding)
} }
@ -300,6 +310,7 @@ struct RoundView: View {
} }
} }
} }
}
.headerProminence(.increased) .headerProminence(.increased)
.toolbar { .toolbar {
ToolbarItem(placement: .topBarTrailing) { ToolbarItem(placement: .topBarTrailing) {

Loading…
Cancel
Save