@ -24,7 +24,8 @@ final class Round: ModelObject, Storable {
var startDate : Date ?
var groupStageLoserBracket : Bool = false
var loserBracketMode : LoserBracketMode = . automatic
var _cachedSeedInterval : SeedInterval ?
internal init ( tournament : String , index : Int , parent : String ? = nil , matchFormat : MatchFormat ? = nil , startDate : Date ? = nil , groupStageLoserBracket : Bool = false , loserBracketMode : LoserBracketMode = . automatic ) {
self . tournament = tournament
self . index = index
@ -451,6 +452,8 @@ defer {
func correspondingLoserRoundTitle ( _ displayStyle : DisplayStyle = . wide ) -> String {
if let _cachedSeedInterval { return _cachedSeedInterval . localizedLabel ( displayStyle ) }
#if _DEBUG_TIME // D E B U G I N G T I M E
let start = Date ( )
defer {
@ -469,8 +472,16 @@ defer {
// & & $ 0 . b r a c k e t P o s i t i o n ! = n i l
// & & ( $ 0 . b r a c k e t P o s i t i o n ! / 2 ) < i n i t i a l M a t c h I n d e x F r o m R o u n d I n d e x
// } )
var seedsCount = seedsAfterThisRound . count
if seedsAfterThisRound . isEmpty {
let nextRoundsDisableMatches = nextRoundsDisableMatches ( )
seedsCount = disabledMatches ( ) . count - nextRoundsDisableMatches
}
let playedMatches = playedMatches ( )
let seedInterval = SeedInterval ( first : playedMatches . count + seedsAfterThisRound . count + 1 , last : playedMatches . count * 2 + seedsAfterThisRound . count )
let seedInterval = SeedInterval ( first : playedMatches . count + seedsCount + 1 , last : playedMatches . count * 2 + seedsCount )
_cachedSeedInterval = seedInterval
return seedInterval . localizedLabel ( displayStyle )
}
@ -492,6 +503,8 @@ defer {
}
func seedInterval ( initialMode : Bool = false ) -> SeedInterval ? {
if initialMode = = false , let _cachedSeedInterval { return _cachedSeedInterval }
#if _DEBUG_TIME // D E B U G I N G T I M E
let start = Date ( )
defer {
@ -515,11 +528,17 @@ defer {
&& ( $0 . bracketPosition ! / 2 ) < initialMatchIndexFromRoundIndex
}
let playedMatches = playedMatches ( ) . count
let minimumMatches = playedMatches * 2
var seedsCount = seedsAfterThisRound . count
if seedsAfterThisRound . isEmpty {
let nextRoundsDisableMatches = nextRoundsDisableMatches ( )
seedsCount = disabledMatches ( ) . count - nextRoundsDisableMatches
}
let playedMatches = playedMatches ( )
// p r i n t ( " p l a y e d M a t c h e s \ ( p l a y e d M a t c h e s ) " , i n i t i a l M o d e , p a r e n t , p a r e n t R o u n d ? . r o u n d T i t l e ( ) , s e e d s A f t e r T h i s R o u n d . c o u n t )
let seedInterval = SeedInterval ( first : playedMatches + seedsAfterThisRound . count + 1 , last : minimumMatches + seedsAfterThisRound . count )
let seedInterval = SeedInterval ( first : playedMatches . count + seedsC ount + 1 , last : playedMatches . count * 2 + seedsC ount)
// p r i n t ( s e e d I n t e r v a l . l o c a l i z e d L a b e l ( ) )
_cachedSeedInterval = seedInterval
return seedInterval
}
@ -659,6 +678,14 @@ defer {
guard let parent = parent else { return nil }
return self . tournamentStore . rounds . findById ( parent )
}
func nextRoundsDisableMatches ( ) -> Int {
if parent = = nil , index > 0 {
return tournamentObject ( ) ? . rounds ( ) . suffix ( index ) . flatMap { $0 . disabledMatches ( ) } . count ? ? 0
} else {
return 0
}
}
func updateMatchFormat ( _ updatedMatchFormat : MatchFormat , checkIfPossible : Bool , andLoserBracket : Bool ) {
if updatedMatchFormat . weight < self . matchFormat . weight {