fix stuff for setuping heads

sync^2
Raz 8 months ago
parent ebb4d9a367
commit 8372030d83
  1. 13
      PadelClub/Data/Tournament.swift
  2. 2
      PadelClub/PadelClubApp.swift
  3. 11
      PadelClub/Views/Round/RoundView.swift
  4. 10
      PadelClub/Views/Tournament/TournamentBuildView.swift

@ -783,7 +783,7 @@ defer {
let availableSeeds = seeds(inSeedGroup: availableSeedGroup) let availableSeeds = seeds(inSeedGroup: availableSeedGroup)
let availableSeedSpot = availableSeedSpot(inRoundIndex: roundIndex) let availableSeedSpot = availableSeedSpot(inRoundIndex: roundIndex)
let availableSeedOpponentSpot = availableSeedOpponentSpot(inRoundIndex: roundIndex) let availableSeedOpponentSpot = availableSeedOpponentSpot(inRoundIndex: roundIndex)
let maxSpots = max(availableSeedSpot.count, availableSeedOpponentSpot.count) let targetSpots = availableSeedSpot.isEmpty ? availableSeedOpponentSpot.count : availableSeedSpot.count
if availableSeedGroup == SeedInterval(first: 3, last: 4), availableSeedSpot.count == 6 { if availableSeedGroup == SeedInterval(first: 3, last: 4), availableSeedSpot.count == 6 {
return availableSeedGroup return availableSeedGroup
} }
@ -796,18 +796,13 @@ defer {
if let chunk = chunks.first(where: { seedInterval in if let chunk = chunks.first(where: { seedInterval in
return seedInterval.first == seededTeamsCount return seedInterval.first == seededTeamsCount
}) { }) {
return seedGroupAvailable(atRoundIndex: roundIndex + 1, availableSeedGroup: chunk) return seedGroupAvailable(atRoundIndex: roundIndex, availableSeedGroup: chunk)
} else { } else if fullLeftSeeds.count > 1, targetSpots > 1, fullLeftSeeds.count >= targetSpots {
let seeds = seeds() let seeds = seeds()
if let firstIndex = seeds.firstIndex(where: { $0.isSeedable() }) { if let firstIndex = seeds.firstIndex(where: { $0.isSeedable() }) {
return SeedInterval(first: firstIndex + 1, last: firstIndex + maxSpots) return seedGroupAvailable(atRoundIndex: roundIndex, availableSeedGroup: SeedInterval(first: firstIndex + 1, last: firstIndex + targetSpots))
} }
} }
} else if fullLeftSeeds.count % maxSpots == 0 || fullLeftSeeds.count >= maxSpots {
let seeds = seeds()
if let firstIndex = seeds.firstIndex(where: { $0.isSeedable() }) {
return SeedInterval(first: firstIndex + 1, last: firstIndex + maxSpots)
}
} }
} }

@ -106,7 +106,7 @@ struct PadelClubApp: App {
} }
.task { .task {
try? Tips.resetDatastore() // try? Tips.resetDatastore()
try? Tips.configure([ try? Tips.configure([
.displayFrequency(.immediate), .displayFrequency(.immediate),

@ -285,6 +285,12 @@ struct RoundView: View {
seedSpaceLeft.isEmpty ? true : false seedSpaceLeft.isEmpty ? true : false
} }
private func _warnGroupWillCloseRound(availableSeedGroup: SeedInterval) -> Bool {
opposingSeeding
&& seedSpaceLeft.count <= availableSeedGroup.count
&& tournament.rounds().count - 1 > upperRound.round.index
}
private func _availableSeedSpot(availableSeedGroup: SeedInterval) -> [Match] { private func _availableSeedSpot(availableSeedGroup: SeedInterval) -> [Match] {
let spots = opposingSeeding ? spaceLeft : seedSpaceLeft let spots = opposingSeeding ? spaceLeft : seedSpaceLeft
if availableSeedGroup == SeedInterval(first: 3, last: 4), spots.count == 6 { if availableSeedGroup == SeedInterval(first: 3, last: 4), spots.count == 6 {
@ -379,8 +385,9 @@ struct RoundView: View {
private func _seedGroupSection(availableSeeds: [TeamRegistration], availableSeedGroup: SeedInterval) -> some View { private func _seedGroupSection(availableSeeds: [TeamRegistration], availableSeedGroup: SeedInterval) -> some View {
Group { Group {
let warnGroupWillCloseRound = _warnGroupWillCloseRound(availableSeedGroup: availableSeedGroup)
Section { Section {
RowButtonView("Placer \(availableSeedGroup.localizedInterval())" + ((availableSeedGroup.isFixed() == false) ? " au hasard" : "")) { RowButtonView("Placer \(availableSeedGroup.localizedInterval())" + ((availableSeedGroup.isFixed() == false) ? " au hasard" : ""), role: warnGroupWillCloseRound ? .destructive : nil, confirmationMessage: warnGroupWillCloseRound ? "Attention, tous vos matchs du tour précédent seront désactivés" : nil) {
Task { Task {
tournament.setSeeds(inRoundIndex: upperRound.round.index, inSeedGroup: availableSeedGroup) tournament.setSeeds(inRoundIndex: upperRound.round.index, inSeedGroup: availableSeedGroup)
_save(seeds: availableSeeds) _save(seeds: availableSeeds)
@ -408,7 +415,7 @@ struct RoundView: View {
Text("Réalise un tirage des positions.") Text("Réalise un tirage des positions.")
} }
} }
RowButtonView("Tirage au sort \(availableSeedGroup.localizedInterval()) visuel") { RowButtonView("Tirage au sort \(availableSeedGroup.localizedInterval()) visuel", role: warnGroupWillCloseRound ? .destructive : nil, confirmationMessage: warnGroupWillCloseRound ? "Attention, tous vos matchs du tour précédent seront désactivés" : nil) {
self.selectedSeedGroup = availableSeedGroup self.selectedSeedGroup = availableSeedGroup
} }
// if upperRound.round.index == 3, availableSeedGroup.first == 5, availableSeedGroup.last == 8, availableSeeds.count > 1, let half = availableSeedGroup.chunks()?.first { // if upperRound.round.index == 3, availableSeedGroup.first == 5, availableSeedGroup.last == 8, availableSeeds.count > 1, let half = availableSeedGroup.chunks()?.first {

@ -130,10 +130,6 @@ struct TournamentBuildView: View {
} }
} }
} }
} else {
NavigationLink(value: Screen.restingTime) {
Text("Temps de repos")
}
} }
if state == .running || state == .finished { if state == .running || state == .finished {
TournamentInscriptionView(tournament: tournament) TournamentInscriptionView(tournament: tournament)
@ -203,6 +199,12 @@ struct TournamentBuildView: View {
cashierStatus = await tournament.cashierStatus() cashierStatus = await tournament.cashierStatus()
} }
} }
if state == .running {
NavigationLink(value: Screen.restingTime) {
Text("Temps de repos")
}
}
} }
} }

Loading…
Cancel
Save