paca_championship
Raz 1 year ago
parent 7b2989d29b
commit b5041db0db
  1. 6
      PadelClub/Data/GroupStage.swift
  2. 2
      PadelClub/Data/Match.swift
  3. 3
      PadelClub/Data/Tournament.swift
  4. 74
      PadelClub/ViewModel/MatchDescriptor.swift
  5. 4
      PadelClub/ViewModel/SetDescriptor.swift
  6. 5
      PadelClub/Views/Navigation/Toolbox/MatchFormatStorageView.swift
  7. 106
      PadelClub/Views/Score/EditScoreView.swift
  8. 10
      PadelClub/Views/Score/SetInputView.swift

@ -163,11 +163,13 @@ final class GroupStage: ModelObject, Storable {
for (index, team) in teams.enumerated() { for (index, team) in teams.enumerated() {
team.qualified = index < tournament.qualifiedPerGroupStage team.qualified = index < tournament.qualifiedPerGroupStage
if team.bracketPosition != nil && team.qualified == false { if team.bracketPosition != nil && team.qualified == false {
tournamentObject()?.resetTeamScores(in: team.bracketPosition) tournamentObject()?.shouldVerifyBracket = true
team.bracketPosition = nil
} }
} }
try self.tournamentStore.teamRegistrations.addOrUpdate(contentOfs: teams) try self.tournamentStore.teamRegistrations.addOrUpdate(contentOfs: teams)
if let tournamentObject = tournamentObject() {
try DataStore.shared.tournaments.addOrUpdate(instance: tournamentObject)
}
} catch { } catch {
Logger.error(error) Logger.error(error)
} }

@ -128,7 +128,7 @@ defer {
} }
func matchWarningMessage() -> String { func matchWarningMessage() -> String {
[roundTitle(), matchTitle(.short), startDate?.localizedDate(), courtName()].compacted().joined(separator: "\n") [roundAndMatchTitle(), startDate?.localizedDate(), courtName(), matchFormat.computedLongLabel].compacted().joined(separator: "\n")
} }
func matchTitle(_ displayStyle: DisplayStyle = .wide, inMatches matches: [Match]? = nil) -> String { func matchTitle(_ displayStyle: DisplayStyle = .wide, inMatches matches: [Match]? = nil) -> String {

@ -2189,7 +2189,8 @@ defer {
let newGroup = selected.prefix(seedCount) + selected.filter({ $0.qualified }) let newGroup = selected.prefix(seedCount) + selected.filter({ $0.qualified })
let currentGroup = allTeams.filter({ $0.bracketPosition != nil }) let currentGroup = allTeams.filter({ $0.bracketPosition != nil })
let selectedIds = newGroup.map { $0.id } let selectedIds = newGroup.map { $0.id }
let groupIds = currentGroup.map { $0.id } let groupStageTeamsInBracket = selected.filter({ $0.qualified == false && $0.inGroupStage() && $0.inRound() })
let groupIds = currentGroup.map { $0.id } + groupStageTeamsInBracket.map { $0.id }
let shouldBeInIt = Set(selectedIds).subtracting(groupIds) let shouldBeInIt = Set(selectedIds).subtracting(groupIds)
let shouldNotBeInIt = Set(groupIds).subtracting(selectedIds) let shouldNotBeInIt = Set(groupIds).subtracting(selectedIds)
return (Array(shouldBeInIt), Array(shouldNotBeInIt)) return (Array(shouldBeInIt), Array(shouldNotBeInIt))

@ -1,11 +1,12 @@
// //
// MatchDescriptor.swift // swift
// PadelClub // PadelClub
// //
// Created by Razmig Sarkissian on 02/04/2024. // Created by Razmig Sarkissian on 02/04/2024.
// //
import Foundation import Foundation
import SwiftUI
class MatchDescriptor: ObservableObject { class MatchDescriptor: ObservableObject {
@Published var matchFormat: MatchFormat @Published var matchFormat: MatchFormat
@ -16,6 +17,77 @@ class MatchDescriptor: ObservableObject {
var teamLabelTwo: String = "" var teamLabelTwo: String = ""
var startDate: Date = Date() var startDate: Date = Date()
var match: Match? var match: Match?
let colorTeamOne: Color = .teal
let colorTeamTwo: Color = .indigo
var teamOneSetupIsActive: Bool {
if hasEnded && showSetInputView == false && showTieBreakInputView == false {
return false
}
guard let setDescriptor = 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 {
if hasEnded && showSetInputView == false && showTieBreakInputView == false {
return false
}
guard let setDescriptor = 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 = 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
}
var showSetInputView: Bool {
return setDescriptors.anySatisfy({ $0.showSetInputView })
}
var showTieBreakInputView: Bool {
return setDescriptors.anySatisfy({ $0.showTieBreakInputView })
}
init(match: Match? = nil) { init(match: Match? = nil) {
self.match = match self.match = match

@ -14,7 +14,9 @@ struct SetDescriptor: Identifiable, Equatable {
var tieBreakValueTeamOne: Int? var tieBreakValueTeamOne: Int?
var tieBreakValueTeamTwo: Int? var tieBreakValueTeamTwo: Int?
var setFormat: SetFormat var setFormat: SetFormat
var showSetInputView: Bool = true
var showTieBreakInputView: Bool = false
var hasEnded: Bool { var hasEnded: Bool {
if let valueTeamTwo, let valueTeamOne { if let valueTeamTwo, let valueTeamOne {
return setFormat.hasEnded(teamOne: valueTeamOne, teamTwo: valueTeamTwo) return setFormat.hasEnded(teamOne: valueTeamOne, teamTwo: valueTeamTwo)

@ -24,8 +24,9 @@ struct MatchFormatStorageView: View {
LabeledContent { LabeledContent {
StepperView(title: "minutes", count: $estimatedDuration, step: 5) StepperView(title: "minutes", count: $estimatedDuration, step: 5)
} label: { } label: {
Text("Durée \(matchFormat.format)") Text("Durée \(matchFormat.format)" + matchFormat.suffix)
Text(matchFormat.computedShortLabelWithoutPrefix) Text(matchFormat.longLabel)
Text(matchFormat.formattedEstimatedBreakDuration() + " de pause").foregroundStyle(.secondary).font(.subheadline)
} }
} footer: { } footer: {
if estimatedDuration != matchFormat.defaultEstimatedDuration { if estimatedDuration != matchFormat.defaultEstimatedDuration {

@ -8,37 +8,6 @@
import SwiftUI import SwiftUI
import LeStorage import LeStorage
struct ArrowView: View {
var direction: ArrowDirection // Enum for left or right direction
var isActive: Bool // Whether the arrow is visible
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) // Arrow visible only when active
.opacity(isAnimating ? 1.0 : 0.4) // Animate opacity between 1.0 and 0.4
.offset(x: isAnimating ? (direction == .left ? -5 : 5) : 0) // Slight left/right movement
.animation(
Animation.easeInOut(duration: 0.7).repeatForever(autoreverses: true),
value: isAnimating
)
.onAppear {
isAnimating = true
}
.onDisappear {
isAnimating = false
}
.padding()
}
}
struct EditScoreView: View { struct EditScoreView: View {
@EnvironmentObject var dataStore: DataStore @EnvironmentObject var dataStore: DataStore
@ -46,11 +15,6 @@ struct EditScoreView: View {
@StateObject var matchDescriptor: MatchDescriptor @StateObject var matchDescriptor: MatchDescriptor
@Binding var confirmScoreEdition: Bool @Binding var confirmScoreEdition: Bool
@Environment(\.dismiss) private var dismiss @Environment(\.dismiss) private var dismiss
@State private var showSetInputView: Bool = true
@State private var showTieBreakInputView: Bool = false
let colorTeamOne: Color = .teal
let colorTeamTwo: Color = .indigo
init(match: Match, confirmScoreEdition: Binding<Bool>) { init(match: Match, confirmScoreEdition: Binding<Bool>) {
let matchDescriptor = MatchDescriptor(match: match) let matchDescriptor = MatchDescriptor(match: match)
@ -90,7 +54,7 @@ struct EditScoreView: View {
.bold() .bold()
} }
} }
.listRowView(isActive: teamOneSetupIsActive, color: colorTeamOne, hideColorVariation: false) .listRowView(isActive: matchDescriptor.teamOneSetupIsActive, color: matchDescriptor.colorTeamOne, hideColorVariation: false)
HStack { HStack {
Spacer() Spacer()
VStack(alignment: .trailing) { VStack(alignment: .trailing) {
@ -101,7 +65,7 @@ struct EditScoreView: View {
} }
} }
} }
.listRowView(isActive: teamTwoSetupIsActive, color: colorTeamTwo, hideColorVariation: false, alignment: .trailing) .listRowView(isActive: matchDescriptor.teamTwoSetupIsActive, color: matchDescriptor.colorTeamTwo, hideColorVariation: false, alignment: .trailing)
} header: { } header: {
if let roundTitle = matchDescriptor.match?.roundAndMatchTitle() { if let roundTitle = matchDescriptor.match?.roundAndMatchTitle() {
Text(roundTitle) Text(roundTitle)
@ -133,7 +97,7 @@ struct EditScoreView: View {
} }
} }
ForEach($matchDescriptor.setDescriptors) { $setDescriptor in ForEach($matchDescriptor.setDescriptors) { $setDescriptor in
SetInputView(setDescriptor: $setDescriptor, showSetInputView: $showSetInputView, showTieBreakInputView: $showTieBreakInputView) SetInputView(setDescriptor: $setDescriptor)
.onChange(of: setDescriptor.hasEnded) { .onChange(of: setDescriptor.hasEnded) {
if setDescriptor.hasEnded { if setDescriptor.hasEnded {
if matchDescriptor.hasEnded == false { if matchDescriptor.hasEnded == false {
@ -144,7 +108,7 @@ struct EditScoreView: View {
matchDescriptor.setDescriptors = Array(matchDescriptor.setDescriptors[0...index]) matchDescriptor.setDescriptors = Array(matchDescriptor.setDescriptors[0...index])
} }
} }
.tint(getColor()) .tint(matchDescriptor.getColor())
} }
if matchDescriptor.hasEnded { if matchDescriptor.hasEnded {
@ -191,66 +155,4 @@ struct EditScoreView: View {
} }
} }
} }
var teamOneSetupIsActive: Bool {
if matchDescriptor.hasEnded && showSetInputView == false && showTieBreakInputView == false {
return false
}
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 {
if matchDescriptor.hasEnded && showSetInputView == false && showTieBreakInputView == false {
return false
}
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
}
} }

@ -9,8 +9,8 @@ import SwiftUI
struct SetInputView: View { struct SetInputView: View {
@Binding var setDescriptor: SetDescriptor @Binding var setDescriptor: SetDescriptor
@Binding var showSetInputView: Bool @State private var showSetInputView: Bool = true
@Binding var showTieBreakInputView: Bool @State private var showTieBreakInputView: Bool = false
var setFormat: SetFormat { setDescriptor.setFormat } var setFormat: SetFormat { setDescriptor.setFormat }
@ -137,6 +137,12 @@ struct SetInputView: View {
} }
} }
} }
.onChange(of: showSetInputView) {
setDescriptor.showSetInputView = showSetInputView
}
.onChange(of: showTieBreakInputView) {
setDescriptor.showTieBreakInputView = showTieBreakInputView
}
.onChange(of: setDescriptor.valueTeamOne) { .onChange(of: setDescriptor.valueTeamOne) {
if let newValue = setDescriptor.valueTeamOne { if let newValue = setDescriptor.valueTeamOne {
if newValue == setFormat.scoreToWin - 1 && setFormat.tieBreak == 8 { if newValue == setFormat.scoreToWin - 1 && setFormat.tieBreak == 8 {

Loading…
Cancel
Save