@ -267,13 +267,13 @@ struct TableStructureView: View {
}
}
if groupStageCount > 0 {
LabeledContent {
Text ( tf . formatted ( ) )
} label : {
Text ( " Effectif " )
}
}
// i f g r o u p S t a g e C o u n t > 0 {
// L a b e l e d C o n t e n t {
// T e x t ( t f . f o r m a t t e d ( ) )
// } l a b e l : {
// T e x t ( " E f f e c t i f t a b l e a u " )
// }
// }
} else {
LabeledContent {
let mp1 = teamsPerGroupStage * ( teamsPerGroupStage - 1 ) / 2 * groupStageCount
@ -283,44 +283,37 @@ struct TableStructureView: View {
Text ( " Total de matchs " )
}
}
} footer : {
if tsPure > 0 && structurePreset != . doubleGroupStage , groupStageCount > 0 {
if tsPure > teamCount / 2 {
Text ( " Le nombre de têtes de série ne devrait pas être supérieur à la moitié de l'effectif. " ) . foregroundStyle ( . red )
} else if tsPure < teamCount / 8 {
Text ( " À partir du moment où vous avez des têtes de série, leur nombre ne devrait pas être inférieur à 1/8ème de l'effectif. " ) . foregroundStyle ( . red )
} else if tsPure < qualifiedFromGroupStage + groupStageAdditionalQualified {
Text ( " Le nombre de têtes de série ne devrait pas être inférieur au nombre de paires qualifiées sortantes. " ) . foregroundStyle ( . red )
LabeledContent {
FooterButtonView ( " configurer " ) {
showSeedRepartition = true
}
} label : {
if tournament . state ( ) = = . build {
Text ( " Répartition des équipes " )
} else if selectedTournament != nil {
Text ( " La configuration du tournoi séléctionné sera utilisée. " )
} else {
Text ( _seeds ( ) )
}
}
. onAppear {
if seedRepartition . isEmpty && tournament . state ( ) = = . initial && selectedTournament = = nil {
seedRepartition = HeadManagerView . place ( heads : tsPure , teamsInBracket : tf , initialSeedRound : nil )
}
}
if structurePreset . hasWildcards ( ) && tournament . level . wildcardArePossible ( ) {
Section {
Toggle ( " Avec wildcards " , isOn : $ buildWildcards )
} footer : {
Text ( " Padel Club réservera des places pour eux dans votre liste d'inscription. " )
if tsPure > 0 && structurePreset != . doubleGroupStage , groupStageCount > 0 , tsPure < qualifiedFromGroupStage + groupStageAdditionalQualified {
Text ( " Le nombre de têtes de série ne devrait pas être inférieur au nombre de paires qualifiées sortantes. " ) . foregroundStyle ( . red )
}
}
if tournament . state ( ) != . build {
if structurePreset . hasWildcards ( ) && tournament . level . wildcardArePossible ( ) {
Section {
LabeledContent {
Image ( systemName : seedRepartition . isEmpty ? " xmark " : " checkmark " )
} label : {
FooterButtonView ( " Configuration du tableau " ) {
showSeedRepartition = true
}
. disabled ( selectedTournament != nil )
}
Toggle ( " Avec wildcards " , isOn : $ buildWildcards )
} footer : {
if seedRepartition . isEmpty {
Text ( " Aucune répartition n'a été indiqué, vous devrez réserver ou placer les têtes de séries dans le tableau manuellement. " )
} else {
FooterButtonView ( " Supprimer la configuration " , role : . destructive ) {
seedRepartition = [ ]
}
}
Text ( " Padel Club réservera des places pour eux dans votre liste d'inscription. " )
}
}
@ -336,6 +329,12 @@ struct TableStructureView: View {
if tournament . state ( ) != . initial {
if seedRepartition . isEmpty = = false {
RowButtonView ( " Modifier la répartition des équipes en tableau " , role : . destructive , confirmationMessage : " Cette action va effacer le répartition actuelle des équipes dans le tableau. " ) {
await _handleSeedRepartition ( )
}
}
Section {
RowButtonView ( " Sauver sans reconstuire l'existant " ) {
_saveWithoutRebuild ( )
@ -370,13 +369,6 @@ struct TableStructureView: View {
}
}
. toolbarBackground ( . visible , for : . navigationBar )
. onChange ( of : teamCount ) {
if teamCount != tournament . teamCount {
updatedElements . insert ( . teamCount )
} else {
updatedElements . remove ( . teamCount )
}
}
. sheet ( isPresented : $ showSeedRepartition , content : {
NavigationStack {
HeadManagerView ( teamsInBracket : tf , heads : tsPure , initialSeedRepartition : seedRepartition ) { seedRepartition in
@ -384,6 +376,14 @@ struct TableStructureView: View {
}
}
} )
. onChange ( of : teamCount ) {
if teamCount != tournament . teamCount {
updatedElements . insert ( . teamCount )
} else {
updatedElements . remove ( . teamCount )
}
_verifyValueIntegrity ( )
}
. onChange ( of : groupStageCount ) {
if groupStageCount != tournament . groupStageCount {
updatedElements . insert ( . groupStageCount )
@ -394,25 +394,31 @@ struct TableStructureView: View {
if structurePreset . isFederalPreset ( ) , groupStageCount = = 0 {
teamCount = structurePreset . tableDimension ( )
}
_verifyValueIntegrity ( )
}
. onChange ( of : teamsPerGroupStage ) {
if teamsPerGroupStage != tournament . teamsPerGroupStage {
updatedElements . insert ( . teamsPerGroupStage )
} else {
updatedElements . remove ( . teamsPerGroupStage )
} }
}
_verifyValueIntegrity ( )
}
. onChange ( of : qualifiedPerGroupStage ) {
if qualifiedPerGroupStage != tournament . qualifiedPerGroupStage {
updatedElements . insert ( . qualifiedPerGroupStage )
} else {
updatedElements . remove ( . qualifiedPerGroupStage )
} }
}
_verifyValueIntegrity ( )
}
. onChange ( of : groupStageAdditionalQualified ) {
if groupStageAdditionalQualified != tournament . groupStageAdditionalQualified {
updatedElements . insert ( . groupStageAdditionalQualified )
} else {
updatedElements . remove ( . groupStageAdditionalQualified )
}
_verifyValueIntegrity ( )
}
. toolbar {
if tournament . state ( ) != . initial {
@ -485,6 +491,19 @@ struct TableStructureView: View {
}
private func _seeds ( ) -> String {
if seedRepartition . isEmpty || seedRepartition . reduce ( 0 , + ) = = 0 {
return " Aucune configuration "
}
return seedRepartition . enumerated ( ) . compactMap { ( index , count ) in
if count > 0 {
return RoundRule . roundName ( fromRoundIndex : index ) + " : \( count ) "
} else {
return nil
}
} . joined ( separator : " , " )
}
private func _reset ( ) {
tournament . removeWildCards ( )
tournament . deleteGroupStages ( )
@ -573,12 +592,6 @@ struct TableStructureView: View {
}
tournament . deleteAndBuildEverything ( preset : structurePreset )
if seedRepartition . count > 0 {
while tournament . rounds ( ) . count < seedRepartition . count {
await tournament . addNewRound ( tournament . rounds ( ) . count )
}
}
if let selectedTournament {
let oldTournamentStart = selectedTournament . startDate
let newTournamentStart = tournament . startDate
@ -614,7 +627,42 @@ struct TableStructureView: View {
}
tournament . tournamentStore ? . matches . addOrUpdate ( contentOfs : tournament . _allMatchesIncludingDisabled ( ) )
} else {
}
if seedRepartition . count > 0 {
await _handleSeedRepartition ( )
}
} else if ( rebuildEverything = = false && requirements . contains ( . groupStage ) ) {
tournament . deleteGroupStages ( )
tournament . buildGroupStages ( )
}
_checkGroupStagesTeams ( )
try dataStore . tournaments . addOrUpdate ( instance : tournament )
dismiss ( )
} catch {
// R e p l a c e t h i s i m p l e m e n t a t i o n w i t h c o d e t o h a n d l e t h e e r r o r a p p r o p r i a t e l y .
// f a t a l E r r o r ( ) c a u s e s t h e a p p l i c a t i o n t o g e n e r a t e a c r a s h l o g a n d t e r m i n a t e . Y o u s h o u l d n o t u s e t h i s f u n c t i o n i n a s h i p p i n g a p p l i c a t i o n , a l t h o u g h i t m a y b e u s e f u l d u r i n g d e v e l o p m e n t .
let nsError = error as NSError
fatalError ( " Unresolved error \( nsError ) , \( nsError . userInfo ) " )
}
}
private func _handleSeedRepartition ( ) async {
while tournament . rounds ( ) . count < seedRepartition . count {
await tournament . addNewRound ( tournament . rounds ( ) . count )
}
if seedRepartition . reduce ( 0 , + ) > 0 {
let rounds = tournament . rounds ( )
let roundsToDelete = rounds . suffix ( rounds . count - seedRepartition . count )
for round in roundsToDelete {
await tournament . removeRound ( round )
}
}
for ( index , seedCount ) in seedRepartition . enumerated ( ) {
if let round = tournament . rounds ( ) . first ( where : { $0 . index = = index } ) {
let baseIndex = RoundRule . baseIndex ( forRoundIndex : round . index )
@ -653,48 +701,12 @@ struct TableStructureView: View {
}
}
}
}
// i f i n i t i a l S e e d R o u n d > 0 {
// i f l e t r o u n d = t o u r n a m e n t . r o u n d s ( ) . f i r s t ( w h e r e : { $ 0 . i n d e x = = i n i t i a l S e e d R o u n d } ) {
// l e t s e e d S o r t e d = f r e n c h U m p i r e O r d e r ( f o r : R o u n d R u l e . n u m b e r O f M a t c h e s ( f o r R o u n d I n d e x : r o u n d . i n d e x ) )
// p r i n t ( s e e d S o r t e d )
// s e e d S o r t e d . p r e f i x ( i n i t i a l S e e d C o u n t ) . f o r E a c h { i n d e x i n
// i f l e t m a t c h = r o u n d . _ m a t c h e s ( ) [ s a f e : i n d e x ] {
// i f m a t c h . i n d e x I n R o u n d ( ) < R o u n d R u l e . n u m b e r O f M a t c h e s ( f o r R o u n d I n d e x : r o u n d . i n d e x ) / 2 {
// m a t c h . p r e v i o u s M a t c h ( . o n e ) ? . d i s a b l e M a t c h ( )
// } e l s e {
// m a t c h . p r e v i o u s M a t c h ( . t w o ) ? . d i s a b l e M a t c h ( )
// }
// }
// }
//
// i f i n i t i a l S e e d C o u n t > 0 {
// t o u r n a m e n t . t o u r n a m e n t S t o r e ? . m a t c h e s . a d d O r U p d a t e ( c o n t e n t O f s : t o u r n a m e n t . _ a l l M a t c h e s I n c l u d i n g D i s a b l e d ( ) )
// }
// }
// }
}
} else if ( rebuildEverything = = false && requirements . contains ( . groupStage ) ) {
tournament . deleteGroupStages ( )
tournament . buildGroupStages ( )
}
_checkGroupStagesTeams ( )
try dataStore . tournaments . addOrUpdate ( instance : tournament )
dismiss ( )
} catch {
// R e p l a c e t h i s i m p l e m e n t a t i o n w i t h c o d e t o h a n d l e t h e e r r o r a p p r o p r i a t e l y .
// f a t a l E r r o r ( ) c a u s e s t h e a p p l i c a t i o n t o g e n e r a t e a c r a s h l o g a n d t e r m i n a t e . Y o u s h o u l d n o t u s e t h i s f u n c t i o n i n a s h i p p i n g a p p l i c a t i o n , a l t h o u g h i t m a y b e u s e f u l d u r i n g d e v e l o p m e n t .
let nsError = error as NSError
fatalError ( " Unresolved error \( nsError ) , \( nsError . userInfo ) " )
}
}
private func _updatePreset ( ) {
if let selectedTournament {
seedRepartition = [ ]
teamCount = selectedTournament . teamCount
groupStageCount = selectedTournament . groupStageCount
teamsPerGroupStage = selectedTournament . teamsPerGroupStage
@ -709,6 +721,7 @@ struct TableStructureView: View {
groupStageAdditionalQualified = 0
buildWildcards = tournament . level . wildcardArePossible ( )
}
_verifyValueIntegrity ( )
}
private func _verifyValueIntegrity ( ) {
@ -754,6 +767,7 @@ struct TableStructureView: View {
}
}
seedRepartition = HeadManagerView . place ( heads : tsPure , teamsInBracket : tf , initialSeedRound : nil )
}
}