multistore
Raz 1 year ago
parent c9c2b72b0f
commit 0b2542bc29
  1. 8
      PadelClub/Data/Tournament.swift
  2. 4
      PadelClub/Utils/FileImportManager.swift
  3. 88
      PadelClub/Utils/PadelRule.swift
  4. 4
      PadelClub/Views/GroupStage/GroupStageView.swift
  5. 8
      PadelClub/Views/Team/Components/TeamHeaderView.swift
  6. 5
      PadelClub/Views/Team/Components/TeamWeightView.swift
  7. 2
      PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift
  8. 12
      PadelClub/Views/Tournament/Screen/TournamentRankView.swift
  9. 8
      PadelClub/Views/Tournament/Shared/TournamentCellView.swift

@ -848,6 +848,8 @@ class Tournament : ModelObject, Storable {
func unrankValue(for malePlayer: Bool) -> Int? { func unrankValue(for malePlayer: Bool) -> Int? {
switch tournamentCategory { switch tournamentCategory {
case .unlisted:
return nil
case .men: case .men:
return maleUnrankedValue return maleUnrankedValue
case .women: case .women:
@ -1171,7 +1173,11 @@ class Tournament : ModelObject, Storable {
} }
func tournamentTitle(_ displayStyle: DisplayStyle = .wide) -> String { func tournamentTitle(_ displayStyle: DisplayStyle = .wide) -> String {
[tournamentLevel.localizedLabel(.wide) + " " + tournamentCategory.localizedLabel(.wide), displayStyle == .wide ? name : nil].compactMap({ $0 }).joined(separator: " - ") [tournamentLevel.localizedLabel(displayStyle) + " " + tournamentCategory.localizedLabel(displayStyle), displayStyle == .wide ? name : nil].compactMap({ $0 }).joined(separator: " - ")
}
func hideWeight() -> Bool {
tournamentLevel.hideWeight()
} }
func subtitle(_ displayStyle: DisplayStyle = .wide) -> String { func subtitle(_ displayStyle: DisplayStyle = .wide) -> String {

@ -253,6 +253,7 @@ class FileImportManager {
var sexPlayerOne : Int { var sexPlayerOne : Int {
switch tournamentCategory { switch tournamentCategory {
case .unlisted: return 1
case .men: return 1 case .men: return 1
case .women: return 0 case .women: return 0
case .mix: return 0 case .mix: return 0
@ -261,6 +262,7 @@ class FileImportManager {
var sexPlayerTwo : Int { var sexPlayerTwo : Int {
switch tournamentCategory { switch tournamentCategory {
case .unlisted: return 1
case .men: return 1 case .men: return 1
case .women: return 0 case .women: return 0
case .mix: return 1 case .mix: return 1
@ -299,6 +301,7 @@ class FileImportManager {
var sexPlayerOne : Int { var sexPlayerOne : Int {
switch tournamentCategory { switch tournamentCategory {
case .unlisted: return 1
case .men: return 1 case .men: return 1
case .women: return 0 case .women: return 0
case .mix: return 1 case .mix: return 1
@ -307,6 +310,7 @@ class FileImportManager {
var sexPlayerTwo : Int { var sexPlayerTwo : Int {
switch tournamentCategory { switch tournamentCategory {
case .unlisted: return 1
case .men: return 1 case .men: return 1
case .women: return 0 case .women: return 0
case .mix: return 0 case .mix: return 0

@ -156,6 +156,7 @@ enum TournamentDifficulty {
} }
enum FederalTournamentAge: Int, Hashable, Codable, CaseIterable, Identifiable { enum FederalTournamentAge: Int, Hashable, Codable, CaseIterable, Identifiable {
case unlisted = 0
case a11_12 = 120 case a11_12 = 120
case a13_14 = 140 case a13_14 = 140
case a15_16 = 160 case a15_16 = 160
@ -187,6 +188,8 @@ enum FederalTournamentAge: Int, Hashable, Codable, CaseIterable, Identifiable {
var order: Int { var order: Int {
switch self { switch self {
case .unlisted:
return 7
case .a11_12: case .a11_12:
return 6 return 6
case .a13_14: case .a13_14:
@ -206,6 +209,8 @@ enum FederalTournamentAge: Int, Hashable, Codable, CaseIterable, Identifiable {
func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String { func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String {
switch self { switch self {
case .unlisted:
return displayStyle == .wide ? "Aucune" : ""
case .a11_12: case .a11_12:
return "11/12 ans" return "11/12 ans"
case .a13_14: case .a13_14:
@ -236,6 +241,7 @@ enum FederalTournamentAge: Int, Hashable, Codable, CaseIterable, Identifiable {
} }
enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable { enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
case unlisted = 0
case p25 = 25 case p25 = 25
case p100 = 100 case p100 = 100
case p250 = 250 case p250 = 250
@ -249,6 +255,15 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
self.init(rawValue: value) self.init(rawValue: value)
} }
func hideWeight() -> Bool {
switch self {
case .unlisted:
return true
default:
return false
}
}
static func mostRecent(inTournaments tournaments: [Tournament]) -> Self { static func mostRecent(inTournaments tournaments: [Tournament]) -> Self {
return tournaments.first?.tournamentLevel ?? .p100 return tournaments.first?.tournamentLevel ?? .p100
} }
@ -265,15 +280,6 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
var id: Int { self.rawValue } var id: Int { self.rawValue }
func maximumDuration() -> Double {
switch self {
case .p25:
return 0.5
default:
return 3
}
}
func minimumPlayerRank(category: TournamentCategory, ageCategory: FederalTournamentAge) -> Int { func minimumPlayerRank(category: TournamentCategory, ageCategory: FederalTournamentAge) -> Int {
switch self { switch self {
case .p25: case .p25:
@ -376,6 +382,8 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
var order: Int { var order: Int {
switch self { switch self {
case .unlisted:
return 7
case .p25: case .p25:
return 6 return 6
case .p100: case .p100:
@ -394,6 +402,7 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
} }
func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String { func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String {
if self == .unlisted { return displayStyle == .wide ? "Animation" : "" }
return String(describing: self).capitalized return String(describing: self).capitalized
} }
@ -407,6 +416,7 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
} }
func points(for rank: Int, count: Int) -> Int { func points(for rank: Int, count: Int) -> Int {
if self == .unlisted { return 0 }
let points = points(for: count) let points = points(for: count)
if rank >= points.count { if rank >= points.count {
return points.last! return points.last!
@ -423,6 +433,8 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
func points(for count: Int) -> [Int] { func points(for count: Int) -> [Int] {
switch self { switch self {
case .unlisted:
return []
case .p25: case .p25:
switch count { switch count {
case 9...12: case 9...12:
@ -559,7 +571,7 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
// //
func minimumFormatFinalTableAndQualifier(roundIndex: Int) -> MatchFormat? { func minimumFormatFinalTableAndQualifier(roundIndex: Int) -> MatchFormat? {
switch self { switch self {
case .p25: case .p25, .unlisted:
return nil return nil
case .p100: case .p100:
return .nineGamesDecisivePoint return .nineGamesDecisivePoint
@ -588,7 +600,7 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
func minimumFormatLoserBracket(roundIndex: Int) -> MatchFormat? { func minimumFormatLoserBracket(roundIndex: Int) -> MatchFormat? {
switch self { switch self {
case .p25: case .p25, .unlisted:
return nil return nil
case .p100, .p250, .p500: case .p100, .p250, .p500:
return .nineGamesDecisivePoint return .nineGamesDecisivePoint
@ -632,6 +644,7 @@ enum TournamentCategory: Int, Hashable, Codable, CaseIterable, Identifiable {
case men case men
case women case women
case mix case mix
case unlisted
init?(rawValue: Int?) { init?(rawValue: Int?) {
guard let value = rawValue else { return nil } guard let value = rawValue else { return nil }
@ -640,6 +653,8 @@ enum TournamentCategory: Int, Hashable, Codable, CaseIterable, Identifiable {
func mandatoryPlayerType() -> [Int] { func mandatoryPlayerType() -> [Int] {
switch self { switch self {
case .unlisted:
return []
case .mix: case .mix:
return [0, 1] return [0, 1]
case .women: case .women:
@ -694,43 +709,25 @@ enum TournamentCategory: Int, Hashable, Codable, CaseIterable, Identifiable {
} }
} }
var next: TournamentCategory {
switch self {
case .men:
return .women
case .women:
return .mix
case .mix:
return .men
}
}
var id: Int { self.rawValue } var id: Int { self.rawValue }
var sexValue: Int {
switch self {
case .men:
return 1
case .women:
return 0
case .mix:
return -1
}
}
var order: Int { var order: Int {
switch self { switch self {
case .men: case .unlisted:
return 0 return 0
case .women: case .men:
return 1 return 1
case .mix: case .women:
return 2 return 2
case .mix:
return 3
} }
} }
var buildLabel: String { var buildLabel: String {
switch self { switch self {
case .unlisted:
return "-"
case .men: case .men:
return "H" return "H"
case .women: case .women:
@ -742,6 +739,8 @@ enum TournamentCategory: Int, Hashable, Codable, CaseIterable, Identifiable {
var requestLabel: String { var requestLabel: String {
switch self { switch self {
case .unlisted:
return "-"
case .men: case .men:
return "DM" return "DM"
case .women: case .women:
@ -753,6 +752,8 @@ enum TournamentCategory: Int, Hashable, Codable, CaseIterable, Identifiable {
var importingRawValue: String { var importingRawValue: String {
switch self { switch self {
case .unlisted:
return "-"
case .men: case .men:
return "messieurs" return "messieurs"
case .women: case .women:
@ -764,6 +765,8 @@ enum TournamentCategory: Int, Hashable, Codable, CaseIterable, Identifiable {
func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String { func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String {
switch self { switch self {
case .unlisted:
return displayStyle == .wide ? "Aucune" : ""
case .men: case .men:
return displayStyle == .wide ? "Hommes" : "H" return displayStyle == .wide ? "Hommes" : "H"
case .women: case .women:
@ -773,20 +776,9 @@ enum TournamentCategory: Int, Hashable, Codable, CaseIterable, Identifiable {
} }
} }
var rankingDataSourceMale: Bool {
switch self {
case .men:
return true
case .women:
return false
case .mix:
return false
}
}
var playerFilterOption: PlayerFilterOption { var playerFilterOption: PlayerFilterOption {
switch self { switch self {
case .men: case .men, .unlisted:
return .all return .all
case .women: case .women:
return .female return .female

@ -118,7 +118,9 @@ struct GroupStageView: View {
VStack(alignment: .leading, spacing: 4.0) { VStack(alignment: .leading, spacing: 4.0) {
HStack(spacing: 6.0) { HStack(spacing: 6.0) {
Text("#\(groupStagePosition + 1)") Text("#\(groupStagePosition + 1)")
Text("Poids \(team.weight)") if groupStage.tournamentObject()?.hideWeight() == false {
Text("Poids \(team.weight)")
}
Spacer() Spacer()
if team.qualified { if team.qualified {
Text("qualifié") Text("qualifié")

@ -22,9 +22,11 @@ struct TeamHeaderView: View {
} }
if team.unsortedPlayers().isEmpty == false { if team.unsortedPlayers().isEmpty == false {
VStack(alignment: .leading, spacing: 0) { if tournament?.hideWeight() == false {
Text("Poids").font(.caption) VStack(alignment: .leading, spacing: 0) {
Text(team.weight.formatted()) Text("Poids").font(.caption)
Text(team.weight.formatted())
}
} }
if let name = team.name { if let name = team.name {
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {

@ -8,6 +8,7 @@
import SwiftUI import SwiftUI
struct TeamWeightView: View { struct TeamWeightView: View {
@Environment(Tournament.self) var tournament: Tournament
var team: TeamRegistration var team: TeamRegistration
var teamPosition: TeamPosition? = nil var teamPosition: TeamPosition? = nil
var teamIndex: Int? var teamIndex: Int?
@ -20,7 +21,7 @@ struct TeamWeightView: View {
var body: some View { var body: some View {
VStack(alignment: .trailing, spacing: 0) { VStack(alignment: .trailing, spacing: 0) {
if teamPosition == .one || teamPosition == nil { if (teamPosition == .one || teamPosition == nil) && tournament.hideWeight() == false {
Text(team.weight.formatted()) Text(team.weight.formatted())
.monospacedDigit() .monospacedDigit()
.font(.caption) .font(.caption)
@ -29,7 +30,7 @@ struct TeamWeightView: View {
Text("#" + (teamIndex + 1).formatted(.number.precision(.integerLength(2...3)))) Text("#" + (teamIndex + 1).formatted(.number.precision(.integerLength(2...3))))
.monospacedDigit() .monospacedDigit()
} }
if teamPosition == .two { if teamPosition == .two && tournament.hideWeight() == false {
Text(team.weight.formatted()) Text(team.weight.formatted())
.monospacedDigit() .monospacedDigit()
.font(.caption) .font(.caption)

@ -631,7 +631,7 @@ struct InscriptionManagerView: View {
private func _addPlayerSex() -> Int { private func _addPlayerSex() -> Int {
switch tournament.tournamentCategory { switch tournament.tournamentCategory {
case .men: case .men, .unlisted:
return 1 return 1
case .women: case .women:
return 0 return 0

@ -119,11 +119,13 @@ struct TournamentRankView: View {
} }
} }
Spacer() if tournament.hideWeight() == false {
VStack(alignment: .trailing) { Spacer()
HStack(alignment: .lastTextBaseline, spacing: 0.0) { VStack(alignment: .trailing) {
Text(tournament.tournamentLevel.points(for: key - 1, count: tournament.teamCount).formatted(.number.sign(strategy: .always()))) HStack(alignment: .lastTextBaseline, spacing: 0.0) {
Text("pts").font(.caption) Text(tournament.tournamentLevel.points(for: key - 1, count: tournament.teamCount).formatted(.number.sign(strategy: .always())))
Text("pts").font(.caption)
}
} }
} }
} }

@ -79,8 +79,8 @@ struct TournamentCellView: View {
.fontWeight(.semibold) .fontWeight(.semibold)
if displayStyle == .wide { if displayStyle == .wide {
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
Text(build.category.localizedLabel()) Text(build.category.localizedLabel(.short))
Text(build.age.localizedLabel()) Text(build.age.localizedLabel(.short))
} }
.font(.caption) .font(.caption)
} }
@ -117,8 +117,8 @@ struct TournamentCellView: View {
} }
Text(tournament.subtitleLabel()).lineLimit(1) Text(tournament.subtitleLabel()).lineLimit(1)
} else { } else {
Text(build.category.localizedLabel()) Text(build.category.localizedLabel(.short))
Text(build.age.localizedLabel()) Text(build.age.localizedLabel(.short))
} }
} }
} }

Loading…
Cancel
Save