update enum management to handle codable

multistore
Razmig Sarkissian 2 years ago
parent c0eb74bb43
commit 32d66cc7c4
  1. 8
      PadelClub.xcodeproj/project.pbxproj
  2. 9
      PadelClub/Data/AppSettings.swift
  3. 97
      PadelClub/Data/Coredata/ImportedPlayer+Extensions.swift
  4. 126
      PadelClub/Data/Federal/FederalPlayer.swift
  5. 32
      PadelClub/Data/Federal/PlayerHolder.swift
  6. 12
      PadelClub/Data/GroupStage.swift
  7. 8
      PadelClub/Data/Match.swift
  8. 8
      PadelClub/Data/Round.swift
  9. 8
      PadelClub/Data/TeamRegistration.swift
  10. 59
      PadelClub/Data/Tournament.swift
  11. 45
      PadelClub/Manager/PadelRule.swift
  12. 6
      PadelClub/Views/Event/TournamentConfiguratorView.swift
  13. 12
      PadelClub/Views/Navigation/Toolbox/GlobalSettingsView.swift
  14. 16
      PadelClub/Views/Tournament/Screen/Components/TournamentGeneralSettingsView.swift

@ -142,6 +142,8 @@
FF5D0D872BB48AFD005CB568 /* NumberFormatter+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5D0D862BB48AFD005CB568 /* NumberFormatter+Extensions.swift */; };
FF5D0D892BB4935C005CB568 /* ClubRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5D0D882BB4935C005CB568 /* ClubRowView.swift */; };
FF5D0D8B2BB4D1E3005CB568 /* CalendarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5D0D8A2BB4D1E3005CB568 /* CalendarView.swift */; };
FF5D30512BD94E1000F2B93D /* ImportedPlayer+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5D30502BD94E1000F2B93D /* ImportedPlayer+Extensions.swift */; };
FF5D30532BD94E2E00F2B93D /* PlayerHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5D30522BD94E2E00F2B93D /* PlayerHolder.swift */; };
FF5DA18F2BB9268800A33061 /* GroupStageSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5DA18E2BB9268800A33061 /* GroupStageSettingsView.swift */; };
FF5DA1932BB9279B00A33061 /* RoundSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5DA1922BB9279B00A33061 /* RoundSettingsView.swift */; };
FF5DA1952BB927E800A33061 /* GenericDestinationPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF5DA1942BB927E800A33061 /* GenericDestinationPickerView.swift */; };
@ -438,6 +440,8 @@
FF5D0D862BB48AFD005CB568 /* NumberFormatter+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NumberFormatter+Extensions.swift"; sourceTree = "<group>"; };
FF5D0D882BB4935C005CB568 /* ClubRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClubRowView.swift; sourceTree = "<group>"; };
FF5D0D8A2BB4D1E3005CB568 /* CalendarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarView.swift; sourceTree = "<group>"; };
FF5D30502BD94E1000F2B93D /* ImportedPlayer+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ImportedPlayer+Extensions.swift"; sourceTree = "<group>"; };
FF5D30522BD94E2E00F2B93D /* PlayerHolder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerHolder.swift; sourceTree = "<group>"; };
FF5DA18E2BB9268800A33061 /* GroupStageSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupStageSettingsView.swift; sourceTree = "<group>"; };
FF5DA1922BB9279B00A33061 /* RoundSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundSettingsView.swift; sourceTree = "<group>"; };
FF5DA1942BB927E800A33061 /* GenericDestinationPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenericDestinationPickerView.swift; sourceTree = "<group>"; };
@ -1005,6 +1009,7 @@
children = (
FF3795602B9396D0004EA093 /* PadelClubApp.xcdatamodeld */,
FF3795652B9399AA004EA093 /* Persistence.swift */,
FF5D30502BD94E1000F2B93D /* ImportedPlayer+Extensions.swift */,
);
path = Coredata;
sourceTree = "<group>";
@ -1015,6 +1020,7 @@
FFF8ACCC2B92367B008466FA /* FederalPlayer.swift */,
FF1CBC182BB53D1F0036DAAB /* FederalTournament.swift */,
FF1CBC202BB53E590036DAAB /* ClubHolder.swift */,
FF5D30522BD94E2E00F2B93D /* PlayerHolder.swift */,
FF1CBC212BB53E590036DAAB /* FederalTournamentHolder.swift */,
);
path = Federal;
@ -1410,6 +1416,7 @@
FF7091662B90F0B000AB08DA /* TabDestination.swift in Sources */,
FF9267F82BCE78C70080F940 /* CashierView.swift in Sources */,
FF8F263F2BAD7D5C00650388 /* Event.swift in Sources */,
FF5D30532BD94E2E00F2B93D /* PlayerHolder.swift in Sources */,
FF11628C2BD05267000C4809 /* LoserRoundStepScheduleEditorView.swift in Sources */,
FF089EBF2BB0B14600F0AEC7 /* FileImportView.swift in Sources */,
C4A47D9F2B7D0BCE00ADC637 /* StepperView.swift in Sources */,
@ -1524,6 +1531,7 @@
FFF8ACCD2B92367B008466FA /* FederalPlayer.swift in Sources */,
FFBF06602BBD9F6D009D6715 /* NavigationViewModel.swift in Sources */,
FF6EC9092B947A5300EA7F5A /* FixedWidthInteger+Extensions.swift in Sources */,
FF5D30512BD94E1000F2B93D /* ImportedPlayer+Extensions.swift in Sources */,
FFC1E1042BAC28C6008D6F59 /* ClubSearchView.swift in Sources */,
FF089EBB2BB0120700F0AEC7 /* PlayerPopoverView.swift in Sources */,
FF70916E2B9108C600AB08DA /* InscriptionManagerView.swift in Sources */,

@ -21,10 +21,11 @@ class AppSettings: MicroStorable {
var callDisplayEntryFee: Bool = false
var callUseFullCustomMessage: Bool = false
var matchFormatsDefaultDuration: [MatchFormat: Int]? = nil
var bracketMatchFormatPreference: Int?
var groupStageMatchFormatPreference: Int?
var loserBracketMatchFormatPreference: Int?
var bracketMatchFormatPreference: MatchFormat?
var groupStageMatchFormatPreference: MatchFormat?
var loserBracketMatchFormatPreference: MatchFormat?
//bracket naming preference (index or alphabetical)
required init() {
}

@ -0,0 +1,97 @@
//
// ImportedPlayer+Extensions.swift
// PadelClub
//
// Created by Razmig Sarkissian on 24/04/2024.
//
import Foundation
extension ImportedPlayer: PlayerHolder {
func getAssimilatedAsMaleRank() -> Int? {
guard male == false else { return nil }
return getRank()?.femaleInMaleAssimilation
}
var computedAge: Int? { nil }
var tournamentPlayed: Int? {
Int(tournamentCount)
}
func getPoints() -> Double? {
self.points
}
func getFirstName() -> String {
self.firstName ?? "prénom inconnu"
}
func getLastName() -> String {
self.lastName ?? "nom inconnu"
}
func formattedLicense() -> String {
if let license { return license.computedLicense }
return "aucune licence"
}
func getRank() -> Int? {
Int(rank)
}
func isUnranked() -> Bool {
false
}
func formattedRank() -> String {
rank.formatted()
}
func isMalePlayer() -> Bool {
male
}
func hitForSearch(_ searchText: String) -> Int {
var trimmedSearchText = searchText.lowercased().trimmingCharacters(in: .whitespaces).folding(options: .diacriticInsensitive, locale: .current)
trimmedSearchText = trimmedSearchText.replaceCharactersFromSet(characterSet: .punctuationCharacters, replacementString: " ")
trimmedSearchText = trimmedSearchText.replaceCharactersFromSet(characterSet: .symbols, replacementString: " ")
if trimmedSearchText.isEmpty { return 0 }
let tokens = trimmedSearchText.components(separatedBy: .whitespacesAndNewlines).filter { $0.isEmpty == false }
if let license, trimmedSearchText.contains(license) {
return 100
}
let label = canonicalFullName!
if tokens.count > 1 {
var wordFound = 0
if trimmedSearchText.lowercased().components(separatedBy: .whitespacesAndNewlines).count > 1 {
let searchFields: Set = Set([firstName!.canonicalVersion.components(separatedBy: .whitespacesAndNewlines), lastName!.canonicalVersion.components(separatedBy: .whitespacesAndNewlines)].flatMap { $0 })
let tokens: Set = Set(trimmedSearchText.components(separatedBy: .whitespacesAndNewlines))
wordFound = searchFields.intersection(tokens).count
}
if wordFound == 2 {
if let first = tokens.pairs().first(where: { a,b in
label.contains(a) && label.contains(b)
}) {
return 2 + first.0.count + first.1.count
}
} else {
return wordFound * 10
}
} else if let first = tokens.first {
if label.contains(first) {
return 1
}
}
return 0
}
}
fileprivate extension Int {
var femaleInMaleAssimilation: Int {
self + TournamentCatgory.femaleInMaleAssimilationAddition(self)
}
}

@ -7,132 +7,6 @@
import Foundation
protocol PlayerHolder {
func getFirstName() -> String
func getLastName() -> String
func formattedRank() -> String
func formattedLicense() -> String
func getPoints() -> Double?
func getRank() -> Int?
func isUnranked() -> Bool
var male: Bool { get }
var tournamentPlayed: Int? { get }
var clubName: String? { get }
var ligueName: String? { get }
var assimilation: String? { get }
var computedAge: Int? { get }
func getAssimilatedAsMaleRank() -> Int?
}
extension PlayerHolder {
var isAssimilated: Bool {
assimilation == "Oui"
}
}
fileprivate extension Int {
var femaleInMaleAssimilation: Int {
self + femaleInMaleAssimilationAddition
}
var femaleInMaleAssimilationAddition: Int {
switch self {
case 1...10: return 400
case 11...30: return 1000
case 31...60: return 2000
case 61...100: return 3000
case 101...200: return 8000
case 201...500: return 12000
default:
return 15000
}
}
}
extension ImportedPlayer: PlayerHolder {
func getAssimilatedAsMaleRank() -> Int? {
guard male == false else { return nil }
return getRank()?.femaleInMaleAssimilation
}
var computedAge: Int? { nil }
var tournamentPlayed: Int? {
Int(tournamentCount)
}
func getPoints() -> Double? {
self.points
}
func getFirstName() -> String {
self.firstName ?? "prénom inconnu"
}
func getLastName() -> String {
self.lastName ?? "nom inconnu"
}
func formattedLicense() -> String {
if let license { return license.computedLicense }
return "aucune licence"
}
func getRank() -> Int? {
Int(rank)
}
func isUnranked() -> Bool {
false
}
func formattedRank() -> String {
rank.formatted()
}
func isMalePlayer() -> Bool {
male
}
func hitForSearch(_ searchText: String) -> Int {
var trimmedSearchText = searchText.lowercased().trimmingCharacters(in: .whitespaces).folding(options: .diacriticInsensitive, locale: .current)
trimmedSearchText = trimmedSearchText.replaceCharactersFromSet(characterSet: .punctuationCharacters, replacementString: " ")
trimmedSearchText = trimmedSearchText.replaceCharactersFromSet(characterSet: .symbols, replacementString: " ")
if trimmedSearchText.isEmpty { return 0 }
let tokens = trimmedSearchText.components(separatedBy: .whitespacesAndNewlines).filter { $0.isEmpty == false }
if let license, trimmedSearchText.contains(license) {
return 100
}
let label = canonicalFullName!
if tokens.count > 1 {
var wordFound = 0
if trimmedSearchText.lowercased().components(separatedBy: .whitespacesAndNewlines).count > 1 {
let searchFields: Set = Set([firstName!.canonicalVersion.components(separatedBy: .whitespacesAndNewlines), lastName!.canonicalVersion.components(separatedBy: .whitespacesAndNewlines)].flatMap { $0 })
let tokens: Set = Set(trimmedSearchText.components(separatedBy: .whitespacesAndNewlines))
wordFound = searchFields.intersection(tokens).count
}
if wordFound == 2 {
if let first = tokens.pairs().first(where: { a,b in
label.contains(a) && label.contains(b)
}) {
return 2 + first.0.count + first.1.count
}
} else {
return wordFound * 10
}
} else if let first = tokens.first {
if label.contains(first) {
return 1
}
}
return 0
}
}
struct FederalPlayer {
var rank: Int
var lastName: String

@ -0,0 +1,32 @@
//
// PlayerHolder.swift
// PadelClub
//
// Created by Razmig Sarkissian on 24/04/2024.
//
import Foundation
protocol PlayerHolder {
func getFirstName() -> String
func getLastName() -> String
func formattedRank() -> String
func formattedLicense() -> String
func getPoints() -> Double?
func getRank() -> Int?
func isUnranked() -> Bool
var male: Bool { get }
var tournamentPlayed: Int? { get }
var clubName: String? { get }
var ligueName: String? { get }
var assimilation: String? { get }
var computedAge: Int? { get }
func getAssimilatedAsMaleRank() -> Int?
}
extension PlayerHolder {
var isAssimilated: Bool {
assimilation == "Oui"
}
}

@ -17,16 +17,16 @@ class GroupStage: ModelObject, Storable {
var tournament: String
var index: Int
var size: Int
var format: Int?
var format: MatchFormat?
var startDate: Date?
var name: String?
var matchFormat: MatchFormat {
get {
MatchFormat(rawValue: format) ?? .defaultFormatForMatchType(.groupStage)
format ?? .defaultFormatForMatchType(.groupStage)
}
set {
format = newValue.rawValue
format = newValue
}
}
@ -34,7 +34,7 @@ class GroupStage: ModelObject, Storable {
self.tournament = tournament
self.index = index
self.size = size
self.format = matchFormat?.rawValue
self.format = matchFormat
self.startDate = startDate
}
@ -56,10 +56,6 @@ class GroupStage: ModelObject, Storable {
}
}
func isBroadcasted() -> Bool {
false
}
func isRunning() -> Bool { // at least a match has started
_matches().anySatisfy({ $0.isRunning() })
}

@ -19,7 +19,7 @@ class Match: ModelObject, Storable {
var startDate: Date?
var endDate: Date?
var index: Int
var format: Int?
var format: MatchFormat?
//var court: String?
var servingTeamId: String?
var winningTeamId: String?
@ -36,7 +36,7 @@ class Match: ModelObject, Storable {
self.startDate = startDate
self.endDate = endDate
self.index = index
self.format = matchFormat?.rawValue
self.format = matchFormat
//self.court = court
self.servingTeamId = servingTeamId
self.winningTeamId = winningTeamId
@ -320,10 +320,10 @@ class Match: ModelObject, Storable {
var matchFormat: MatchFormat {
get {
MatchFormat(rawValue: format) ?? .defaultFormatForMatchType(.groupStage)
format ?? .defaultFormatForMatchType(.groupStage)
}
set {
format = newValue.rawValue
format = newValue
}
}

@ -16,22 +16,22 @@ class Round: ModelObject, Storable {
var tournament: String
var index: Int
var parent: String?
var format: Int?
var format: MatchFormat?
var startDate: Date?
internal init(tournament: String, index: Int, parent: String? = nil, matchFormat: MatchFormat? = nil) {
self.tournament = tournament
self.index = index
self.parent = parent
self.format = matchFormat?.rawValue
self.format = matchFormat
}
var matchFormat: MatchFormat {
get {
MatchFormat(rawValue: format) ?? .defaultFormatForMatchType(.bracket)
format ?? .defaultFormatForMatchType(.bracket)
}
set {
format = newValue.rawValue
format = newValue
}
}

@ -28,13 +28,13 @@ class TeamRegistration: ModelObject, Storable {
var walkOut: Bool = false
var wildCardBracket: Bool = false
var wildCardGroupStage: Bool = false
var category: Int?
var category: TournamentCategory?
var weight: Int = 0
var lockWeight: Int?
var confirmationDate: Date?
var qualified: Bool = false
internal init(tournament: String, groupStage: String? = nil, registrationDate: Date? = nil, callDate: Date? = nil, bracketPosition: Int? = nil, groupStagePosition: Int? = nil, comment: String? = nil, source: String? = nil, sourceValue: String? = nil, logo: String? = nil, name: String? = nil, category: Int? = nil) {
internal init(tournament: String, groupStage: String? = nil, registrationDate: Date? = nil, callDate: Date? = nil, bracketPosition: Int? = nil, groupStagePosition: Int? = nil, comment: String? = nil, source: String? = nil, sourceValue: String? = nil, logo: String? = nil, name: String? = nil, category: TournamentCategory? = nil) {
self.tournament = tournament
self.groupStage = groupStage
self.registrationDate = registrationDate
@ -102,10 +102,10 @@ class TeamRegistration: ModelObject, Storable {
var tournamentCategory: TournamentCategory {
get {
TournamentCategory(rawValue: category ?? 0) ?? .men
category ?? .men
}
set {
category = newValue.rawValue
category = newValue
}
}

@ -20,18 +20,18 @@ class Tournament : ModelObject, Storable {
var endDate: Date?
private(set) var creationDate: Date
var isPrivate: Bool
var groupStageFormat: Int?
var roundFormat: Int?
var loserRoundFormat: Int?
var groupStageSortMode: Int
var groupStageFormat: MatchFormat?
var roundFormat: MatchFormat?
var loserRoundFormat: MatchFormat?
var groupStageSortMode: GroupStageOrderingMode
var groupStageCount: Int
var rankSourceDate: Date?
var dayDuration: Int
var teamCount: Int
var teamSorting: TeamSortingType
var federalCategory: Int
var federalLevelCategory: Int
var federalAgeCategory: Int
var federalCategory: TournamentCategory
var federalLevelCategory: TournamentLevel
var federalAgeCategory: FederalTournamentAge
var groupStageCourtCount: Int?
var seedCount: Int
var closedRegistrationDate: Date?
@ -47,7 +47,7 @@ class Tournament : ModelObject, Storable {
@ObservationIgnored
var navigationPath: [Screen] = []
internal init(event: String? = nil, creator: String? = nil, name: String? = nil, startDate: Date = Date(), endDate: Date? = nil, creationDate: Date = Date(), isPrivate: Bool = true, groupStageFormat: Int? = nil, roundFormat: Int? = nil, loserRoundFormat: Int? = nil, groupStageSortMode: GroupStageOrderingMode, groupStageCount: Int = 4, rankSourceDate: Date? = nil, dayDuration: Int = 1, teamCount: Int = 24, teamSorting: TeamSortingType? = nil, federalCategory: TournamentCategory, federalLevelCategory: TournamentLevel, federalAgeCategory: FederalTournamentAge, groupStageCourtCount: Int? = nil, seedCount: Int = 8, closedRegistrationDate: Date? = nil, groupStageAdditionalQualified: Int = 0, courtCount: Int = 2, prioritizeClubMembers: Bool = false, qualifiedPerGroupStage: Int = 1, teamsPerGroupStage: Int = 4, entryFee: Double? = nil) {
internal init(event: String? = nil, creator: String? = nil, name: String? = nil, startDate: Date = Date(), endDate: Date? = nil, creationDate: Date = Date(), isPrivate: Bool = true, groupStageFormat: MatchFormat? = nil, roundFormat: MatchFormat? = nil, loserRoundFormat: MatchFormat? = nil, groupStageSortMode: GroupStageOrderingMode, groupStageCount: Int = 4, rankSourceDate: Date? = nil, dayDuration: Int = 1, teamCount: Int = 24, teamSorting: TeamSortingType? = nil, federalCategory: TournamentCategory, federalLevelCategory: TournamentLevel, federalAgeCategory: FederalTournamentAge, groupStageCourtCount: Int? = nil, seedCount: Int = 8, closedRegistrationDate: Date? = nil, groupStageAdditionalQualified: Int = 0, courtCount: Int = 2, prioritizeClubMembers: Bool = false, qualifiedPerGroupStage: Int = 1, teamsPerGroupStage: Int = 4, entryFee: Double? = nil) {
self.event = event
self.creator = creator
self.name = name
@ -58,15 +58,15 @@ class Tournament : ModelObject, Storable {
self.groupStageFormat = groupStageFormat
self.roundFormat = roundFormat
self.loserRoundFormat = loserRoundFormat
self.groupStageSortMode = groupStageSortMode.rawValue
self.groupStageSortMode = groupStageSortMode
self.groupStageCount = groupStageCount
self.rankSourceDate = rankSourceDate
self.dayDuration = dayDuration
self.teamCount = teamCount
//self.teamSorting = teamSorting.rawValue
self.federalCategory = federalCategory.rawValue
self.federalLevelCategory = federalLevelCategory.rawValue
self.federalAgeCategory = federalAgeCategory.rawValue
self.teamSorting = teamSorting ?? federalLevelCategory.defaultTeamSortingType
self.federalCategory = federalCategory
self.federalLevelCategory = federalLevelCategory
self.federalAgeCategory = federalAgeCategory
self.groupStageCourtCount = groupStageCourtCount
self.seedCount = seedCount
self.closedRegistrationDate = closedRegistrationDate
@ -76,7 +76,6 @@ class Tournament : ModelObject, Storable {
self.qualifiedPerGroupStage = qualifiedPerGroupStage
self.teamsPerGroupStage = teamsPerGroupStage
self.entryFee = entryFee
self.teamSorting = teamSorting ?? federalLevelCategory.defaultTeamSortingType
}
enum TournamentPayment: Int {
@ -933,60 +932,60 @@ class Tournament : ModelObject, Storable {
var matchFormat: MatchFormat {
get {
MatchFormat(rawValue: roundFormat) ?? .defaultFormatForMatchType(.bracket)
roundFormat ?? .defaultFormatForMatchType(.bracket)
}
set {
roundFormat = newValue.rawValue
roundFormat = newValue
}
}
var groupStageMatchFormat: MatchFormat {
get {
MatchFormat(rawValue: groupStageFormat) ?? .defaultFormatForMatchType(.groupStage)
groupStageFormat ?? .defaultFormatForMatchType(.groupStage)
}
set {
groupStageFormat = newValue.rawValue
groupStageFormat = newValue
}
}
var loserBracketMatchFormat: MatchFormat {
get {
MatchFormat(rawValue: loserRoundFormat) ?? .defaultFormatForMatchType(.loserBracket)
loserRoundFormat ?? .defaultFormatForMatchType(.loserBracket)
}
set {
loserRoundFormat = newValue.rawValue
loserRoundFormat = newValue
}
}
var groupStageOrderingMode: GroupStageOrderingMode {
get {
GroupStageOrderingMode(rawValue: groupStageSortMode) ?? .random
groupStageSortMode ?? .random
}
set {
groupStageSortMode = newValue.rawValue
groupStageSortMode = newValue
}
}
var tournamentCategory: TournamentCategory {
get {
TournamentCategory(rawValue: federalCategory) ?? .men
federalCategory ?? .men
}
set {
if federalCategory != newValue.rawValue {
federalCategory = newValue.rawValue
if federalCategory != newValue {
federalCategory = newValue
updateWeights()
} else {
federalCategory = newValue.rawValue
federalCategory = newValue
}
}
}
var tournamentLevel: TournamentLevel {
get {
TournamentLevel(rawValue: federalLevelCategory) ?? .p100
federalLevelCategory ?? .p100
}
set {
federalLevelCategory = newValue.rawValue
federalLevelCategory = newValue
teamSorting = newValue.defaultTeamSortingType
groupStageMatchFormat = groupStageSmartMatchFormat()
loserBracketMatchFormat = loserBracketSmartMatchFormat(1)
@ -997,10 +996,10 @@ class Tournament : ModelObject, Storable {
var federalTournamentAge: FederalTournamentAge {
get {
FederalTournamentAge(rawValue: federalAgeCategory) ?? .senior
federalAgeCategory ?? .senior
}
set {
federalAgeCategory = newValue.rawValue
federalAgeCategory = newValue
}
}

@ -158,6 +158,11 @@ enum FederalTournamentAge: Int, Hashable, Codable, CaseIterable, Identifiable {
case senior = 200
case a45 = 450
case a55 = 550
init?(rawValue: Int?) {
guard let value = rawValue else { return nil }
self.init(rawValue: value)
}
static func mostRecent(inTournaments tournaments: [Tournament]) -> Self {
return tournaments.first?.federalTournamentAge ?? .senior
@ -233,6 +238,11 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
case p1000 = 1000
case p1500 = 1500
case p2000 = 2000
init?(rawValue: Int?) {
guard let value = rawValue else { return nil }
self.init(rawValue: value)
}
static func mostRecent(inTournaments tournaments: [Tournament]) -> Self {
return tournaments.first?.tournamentLevel ?? .p100
@ -617,6 +627,11 @@ enum TournamentCategory: Int, Hashable, Codable, CaseIterable, Identifiable {
case men
case women
case mix
init?(rawValue: Int?) {
guard let value = rawValue else { return nil }
self.init(rawValue: value)
}
var localizedPlayerLabel: String {
switch self {
@ -636,6 +651,19 @@ enum TournamentCategory: Int, Hashable, Codable, CaseIterable, Identifiable {
}
}
func femaleInMaleAssimilationAddition(_ rank: Int) -> Int {
switch rank {
case 1...10: return 400
case 11...30: return 1000
case 31...60: return 2000
case 61...100: return 3000
case 101...200: return 8000
case 201...500: return 12000
default:
return 15000
}
}
static func mostRecent(inTournaments tournaments: [Tournament]) -> Self {
return tournaments.first?.tournamentCategory ?? .men
}
@ -757,6 +785,11 @@ enum GroupStageOrderingMode: Int, Hashable, Codable, CaseIterable, Identifiable
case random
case snake
case swiss
init?(rawValue: Int?) {
guard let value = rawValue else { return nil }
self.init(rawValue: value)
}
var id: Int { self.rawValue }
func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String {
@ -1026,11 +1059,11 @@ enum MatchFormat: Int, Hashable, Codable, CaseIterable {
static func defaultFormatForMatchType(_ matchType: MatchType) -> MatchFormat {
switch matchType {
case .bracket:
MatchFormat(rawValue: DataStore.shared.appSettings.bracketMatchFormatPreference) ?? .nineGamesDecisivePoint
DataStore.shared.appSettings.bracketMatchFormatPreference ?? .nineGamesDecisivePoint
case .groupStage:
MatchFormat(rawValue: DataStore.shared.appSettings.groupStageMatchFormatPreference) ?? .nineGamesDecisivePoint
DataStore.shared.appSettings.groupStageMatchFormatPreference ?? .nineGamesDecisivePoint
case .loserBracket:
MatchFormat(rawValue: DataStore.shared.appSettings.loserBracketMatchFormatPreference) ?? .nineGamesDecisivePoint
DataStore.shared.appSettings.loserBracketMatchFormatPreference ?? .nineGamesDecisivePoint
}
}
@ -1357,6 +1390,12 @@ enum TeamSortingType: Int, Identifiable, CaseIterable, Hashable, Codable {
case inscriptionDate = 2
var id: Int { rawValue }
init?(rawValue: Int?) {
guard let value = rawValue else { return nil }
self.init(rawValue: value)
}
func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String {
switch self {
case .rank:

@ -22,17 +22,17 @@ struct TournamentConfigurationView: View {
var body: some View {
Picker(selection: $tournament.federalCategory, label: Text("Catégorie")) {
ForEach(TournamentCategory.allCases) { type in
Text(type.localizedLabel()).tag(type.rawValue)
Text(type.localizedLabel()).tag(type)
}
}
Picker(selection: $tournament.federalLevelCategory, label: Text("Niveau")) {
ForEach(TournamentLevel.allCases) { type in
Text(type.localizedLabel()).tag(type.rawValue)
Text(type.localizedLabel()).tag(type)
}
}
Picker(selection: $tournament.federalAgeCategory, label: Text("Limite d'âge")) {
ForEach(FederalTournamentAge.allCases) { type in
Text(type.localizedLabel()).tag(type.rawValue)
Text(type.localizedLabel()).tag(type)
}
}
LabeledContent {

@ -15,9 +15,9 @@ struct GlobalSettingsView: View {
List {
Section {
Picker(selection: $appSettings.groupStageMatchFormatPreference) {
Text("Automatique").tag(nil as Int?)
Text("Automatique").tag(nil as MatchFormat?)
ForEach(MatchFormat.allCases, id: \.self) { format in
Text(format.format).tag(format.rawValue as Int?)
Text(format.format).tag(format as MatchFormat?)
}
} label: {
HStack {
@ -26,9 +26,9 @@ struct GlobalSettingsView: View {
}
}
Picker(selection: $appSettings.bracketMatchFormatPreference) {
Text("Automatique").tag(nil as Int?)
Text("Automatique").tag(nil as MatchFormat?)
ForEach(MatchFormat.allCases, id: \.self) { format in
Text(format.format).tag(format.rawValue as Int?)
Text(format.format).tag(format as MatchFormat?)
}
} label: {
HStack {
@ -37,9 +37,9 @@ struct GlobalSettingsView: View {
}
}
Picker(selection: $appSettings.loserBracketMatchFormatPreference) {
Text("Automatique").tag(nil as Int?)
Text("Automatique").tag(nil as MatchFormat?)
ForEach(MatchFormat.allCases, id: \.self) { format in
Text(format.format).tag(format.rawValue as Int?)
Text(format.format).tag(format as MatchFormat?)
}
} label: {
HStack {

@ -75,11 +75,25 @@ struct TournamentGeneralSettingsView: View {
.onChange(of: tournament.name) {
_save()
}
.onChange(of: tournament.dayDuration) {
_save()
}
.onChange(of: [
tournament.dayDuration,
tournament.federalCategory,
]) {
_save()
}
.onChange(of: [
tournament.federalLevelCategory,
]) {
_save()
}
.onChange(of: [
tournament.federalAgeCategory,
]) {
_save()
}
.onChange(of: [
tournament.groupStageSortMode,
]) {
_save()

Loading…
Cancel
Save