@ -8,6 +8,37 @@
import SwiftUI
import LeStorage
struct ArrowView : View {
var direction : ArrowDirection // E n u m f o r l e f t o r r i g h t d i r e c t i o n
var isActive : Bool // W h e t h e r t h e a r r o w i s v i s i b l e
var color : Color
@ State private var isAnimating = false
enum ArrowDirection {
case left , right
}
var body : some View {
Image ( systemName : direction = = . left ? " arrow.left " : " arrow.right " )
. font ( . title )
. foregroundColor ( isActive ? color : . clear ) // A r r o w v i s i b l e o n l y w h e n a c t i v e
. opacity ( isAnimating ? 1.0 : 0.4 ) // A n i m a t e o p a c i t y b e t w e e n 1 . 0 a n d 0 . 4
. offset ( x : isAnimating ? ( direction = = . left ? - 5 : 5 ) : 0 ) // S l i g h t l e f t / r i g h t m o v e m e n t
. animation (
Animation . easeInOut ( duration : 0.7 ) . repeatForever ( autoreverses : true ) ,
value : isAnimating
)
. onAppear {
isAnimating = true
}
. onDisappear {
isAnimating = false
}
. padding ( )
}
}
struct EditScoreView : View {
@ EnvironmentObject var dataStore : DataStore
@ -15,20 +46,53 @@ struct EditScoreView: View {
@ ObservedObject var matchDescriptor : MatchDescriptor
@ Environment ( \ . dismiss ) private var dismiss
let colorTeamOne : Color = . mint
let colorTeamTwo : Color = . cyan
func walkout ( _ team : TeamPosition ) {
self . matchDescriptor . match ? . setWalkOut ( team )
save ( )
dismiss ( )
}
func pointRange ( winner : Bool ) -> Int ? {
guard let match = matchDescriptor . match else { return nil }
guard let tournament = match . currentTournament ( ) else {
return nil
}
let teamsCount = tournament . teamCount
guard let round = match . roundObject else { return nil }
guard let seedInterval = round . seedInterval ( ) , match . index = = 0 else {
return nil
}
return winner ? tournament . tournamentLevel . points ( for : seedInterval . first - 1 , count : teamsCount ) : tournament . tournamentLevel . points ( for : seedInterval . last - 1 , count : teamsCount )
}
var body : some View {
Form {
Section {
Text ( matchDescriptor . teamLabelOne )
VStack ( alignment : . leading ) {
Text ( matchDescriptor . teamLabelOne )
if matchDescriptor . hasEnded , let pointRange = pointRange ( winner : matchDescriptor . winner = = . one ) {
Text ( pointRange . formatted ( . number . sign ( strategy : . always ( ) ) ) + " pts " )
. bold ( )
}
}
. listRowView ( isActive : true , color : colorTeamOne , hideColorVariation : true )
HStack {
Spacer ( )
Text ( matchDescriptor . teamLabelTwo ) . multilineTextAlignment ( . trailing )
VStack ( alignment : . trailing ) {
Text ( matchDescriptor . teamLabelTwo ) . multilineTextAlignment ( . trailing )
if matchDescriptor . hasEnded , let pointRange = pointRange ( winner : matchDescriptor . winner = = . two ) {
Text ( pointRange . formatted ( . number . sign ( strategy : . always ( ) ) ) + " pts " )
. bold ( )
}
}
}
. listRowView ( isActive : true , color : colorTeamTwo , hideColorVariation : true , alignment : . trailing )
} footer : {
HStack {
Menu {
@ -67,6 +131,7 @@ struct EditScoreView: View {
matchDescriptor . setDescriptors = Array ( matchDescriptor . setDescriptors [ 0. . . index ] )
}
}
. tint ( getColor ( ) )
}
if matchDescriptor . hasEnded {
@ -112,4 +177,59 @@ struct EditScoreView: View {
}
}
}
var teamOneSetupIsActive : Bool {
guard let setDescriptor = matchDescriptor . setDescriptors . last else {
return false
}
if setDescriptor . valueTeamOne = = nil {
return true
} else if setDescriptor . valueTeamTwo = = nil {
return false
} else if setDescriptor . tieBreakValueTeamOne = = nil , setDescriptor . shouldTieBreak {
return true
} else if setDescriptor . tieBreakValueTeamTwo = = nil , setDescriptor . shouldTieBreak {
return false
}
return false
}
var teamTwoSetupIsActive : Bool {
guard let setDescriptor = matchDescriptor . setDescriptors . last else {
return false
}
if setDescriptor . valueTeamOne = = nil {
return false
} else if setDescriptor . valueTeamTwo = = nil {
return true
} else if setDescriptor . tieBreakValueTeamOne = = nil , setDescriptor . shouldTieBreak {
return false
} else if setDescriptor . tieBreakValueTeamTwo = = nil , setDescriptor . shouldTieBreak {
return true
}
return true
}
func getColor ( ) -> Color {
guard let setDescriptor = matchDescriptor . setDescriptors . last else {
return . master
}
if setDescriptor . valueTeamOne = = nil {
return colorTeamOne
} else if setDescriptor . valueTeamTwo = = nil {
return colorTeamTwo
} else if setDescriptor . tieBreakValueTeamOne = = nil , setDescriptor . shouldTieBreak {
return colorTeamOne
} else if setDescriptor . tieBreakValueTeamTwo = = nil , setDescriptor . shouldTieBreak {
return colorTeamTwo
}
return colorTeamTwo
}
}