From 0aa515ea9fde6f82856adbe32328767b3e4c5f71 Mon Sep 17 00:00:00 2001 From: Raz Date: Tue, 20 May 2025 11:36:21 +0200 Subject: [PATCH] add loser bracket in pdf --- PadelClubData/Data/Match.swift | 17 +++++++++++++++-- PadelClubData/Data/Round.swift | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/PadelClubData/Data/Match.swift b/PadelClubData/Data/Match.swift index 4cdb3ec..4c27dd1 100644 --- a/PadelClubData/Data/Match.swift +++ b/PadelClubData/Data/Match.swift @@ -191,13 +191,22 @@ defer { } } - public func scoreLabel() -> String { + public func scoreLabel(winnerFirst: Bool = false) -> String { if hasWalkoutTeam() == true { return "WO" } + let scoreOne = teamScore(.one)?.score?.components(separatedBy: ",") ?? [] let scoreTwo = teamScore(.two)?.score?.components(separatedBy: ",") ?? [] - let tuples = zip(scoreOne, scoreTwo).map { ($0, $1) } + var tuples = zip(scoreOne, scoreTwo).map { ($0, $1) } + + if winnerFirst { + if teamWon(atPosition: .one) { + + } else { + tuples = zip(scoreTwo, scoreOne).map { ($0, $1) } + } + } let scores = tuples.map { $0 + "/" + $1 }.joined(separator: " ") return scores } @@ -1066,6 +1075,10 @@ defer { [MatchSpot(match: self, teamPosition: .one), MatchSpot(match: self, teamPosition: .two)] } + public func initialStartDate() -> Date? { + plannedStartDate ?? startDate + } + func insertOnServer() { self.tournamentStore?.matches.writeChangeAndInsertOnServer(instance: self) for teamScore in self.teamScores { diff --git a/PadelClubData/Data/Round.swift b/PadelClubData/Data/Round.swift index 2f57d41..b77df39 100644 --- a/PadelClubData/Data/Round.swift +++ b/PadelClubData/Data/Round.swift @@ -907,6 +907,10 @@ defer { _cachedLoserRoundsAndChildren = nil } + public func initialStartDate() -> Date? { + plannedStartDate ?? startDate ?? playedMatches().first?.initialStartDate() + } + public override func deleteDependencies(store: Store, shouldBeSynchronized: Bool) { store.deleteDependencies(type: Match.self, shouldBeSynchronized: shouldBeSynchronized) { $0.round == self.id }