|
|
|
@ -184,15 +184,27 @@ class Match: ModelObject, Storable { |
|
|
|
func teamWillBeWalkOut(_ team: TeamRegistration) { |
|
|
|
func teamWillBeWalkOut(_ team: TeamRegistration) { |
|
|
|
resetMatch() |
|
|
|
resetMatch() |
|
|
|
let previousScores = teamScores.filter({ $0.luckyLoser != nil }) |
|
|
|
let previousScores = teamScores.filter({ $0.luckyLoser != nil }) |
|
|
|
try? DataStore.shared.teamScores.delete(contentOfs: previousScores) |
|
|
|
do { |
|
|
|
|
|
|
|
try DataStore.shared.teamScores.delete(contentOfs: previousScores) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if let existingTeamScore = teamScore(ofTeam: team) { |
|
|
|
if let existingTeamScore = teamScore(ofTeam: team) { |
|
|
|
try? DataStore.shared.teamScores.delete(instance: existingTeamScore) |
|
|
|
do { |
|
|
|
|
|
|
|
try DataStore.shared.teamScores.delete(instance: existingTeamScore) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let teamScoreWalkout = TeamScore(match: id, team: team) |
|
|
|
let teamScoreWalkout = TeamScore(match: id, team: team) |
|
|
|
teamScoreWalkout.walkOut = 1 |
|
|
|
teamScoreWalkout.walkOut = 1 |
|
|
|
try? DataStore.shared.teamScores.addOrUpdate(instance: teamScoreWalkout) |
|
|
|
do { |
|
|
|
|
|
|
|
try DataStore.shared.teamScores.addOrUpdate(instance: teamScoreWalkout) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func luckyLosers() -> [TeamRegistration] { |
|
|
|
func luckyLosers() -> [TeamRegistration] { |
|
|
|
@ -206,17 +218,29 @@ class Match: ModelObject, Storable { |
|
|
|
func setLuckyLoser(team: TeamRegistration, teamPosition: TeamPosition) { |
|
|
|
func setLuckyLoser(team: TeamRegistration, teamPosition: TeamPosition) { |
|
|
|
resetMatch() |
|
|
|
resetMatch() |
|
|
|
let previousScores = teamScores.filter({ $0.luckyLoser != nil }) |
|
|
|
let previousScores = teamScores.filter({ $0.luckyLoser != nil }) |
|
|
|
try? DataStore.shared.teamScores.delete(contentOfs: previousScores) |
|
|
|
do { |
|
|
|
|
|
|
|
try DataStore.shared.teamScores.delete(contentOfs: previousScores) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if let existingTeamScore = teamScore(ofTeam: team) { |
|
|
|
if let existingTeamScore = teamScore(ofTeam: team) { |
|
|
|
try? DataStore.shared.teamScores.delete(instance: existingTeamScore) |
|
|
|
do { |
|
|
|
|
|
|
|
try DataStore.shared.teamScores.delete(instance: existingTeamScore) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let matchIndex = index |
|
|
|
let matchIndex = index |
|
|
|
let position = matchIndex * 2 + teamPosition.rawValue |
|
|
|
let position = matchIndex * 2 + teamPosition.rawValue |
|
|
|
let teamScoreLuckyLoser = TeamScore(match: id, team: team) |
|
|
|
let teamScoreLuckyLoser = TeamScore(match: id, team: team) |
|
|
|
teamScoreLuckyLoser.luckyLoser = position |
|
|
|
teamScoreLuckyLoser.luckyLoser = position |
|
|
|
try? DataStore.shared.teamScores.addOrUpdate(instance: teamScoreLuckyLoser) |
|
|
|
do { |
|
|
|
|
|
|
|
try DataStore.shared.teamScores.addOrUpdate(instance: teamScoreLuckyLoser) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func disableMatch() { |
|
|
|
func disableMatch() { |
|
|
|
@ -299,8 +323,12 @@ class Match: ModelObject, Storable { |
|
|
|
//if disabled == state { return } |
|
|
|
//if disabled == state { return } |
|
|
|
disabled = state |
|
|
|
disabled = state |
|
|
|
//byeState = false |
|
|
|
//byeState = false |
|
|
|
//try? DataStore.shared.matches.addOrUpdate(instance: self) |
|
|
|
do { |
|
|
|
|
|
|
|
try DataStore.shared.matches.addOrUpdate(instance: self) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_toggleLoserMatchDisableState(state) |
|
|
|
_toggleLoserMatchDisableState(state) |
|
|
|
if forward { |
|
|
|
if forward { |
|
|
|
_toggleForwardMatchDisableState(state) |
|
|
|
_toggleForwardMatchDisableState(state) |
|
|
|
@ -403,7 +431,11 @@ class Match: ModelObject, Storable { |
|
|
|
teamScoreWalkout.walkOut = 0 |
|
|
|
teamScoreWalkout.walkOut = 0 |
|
|
|
let teamScoreWinning = teamScore(teamPosition.otherTeam) ?? TeamScore(match: id, team: team(teamPosition.otherTeam)) |
|
|
|
let teamScoreWinning = teamScore(teamPosition.otherTeam) ?? TeamScore(match: id, team: team(teamPosition.otherTeam)) |
|
|
|
teamScoreWinning.walkOut = nil |
|
|
|
teamScoreWinning.walkOut = nil |
|
|
|
try? DataStore.shared.teamScores.addOrUpdate(contentOfs: [teamScoreWalkout, teamScoreWinning]) |
|
|
|
do { |
|
|
|
|
|
|
|
try DataStore.shared.teamScores.addOrUpdate(contentOfs: [teamScoreWalkout, teamScoreWinning]) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if endDate == nil { |
|
|
|
if endDate == nil { |
|
|
|
endDate = Date() |
|
|
|
endDate = Date() |
|
|
|
@ -433,7 +465,11 @@ class Match: ModelObject, Storable { |
|
|
|
teamScoreOne.score = matchDescriptor.teamOneScores.joined(separator: ",") |
|
|
|
teamScoreOne.score = matchDescriptor.teamOneScores.joined(separator: ",") |
|
|
|
let teamScoreTwo = teamScore(.two) ?? TeamScore(match: id, team: team(.two)) |
|
|
|
let teamScoreTwo = teamScore(.two) ?? TeamScore(match: id, team: team(.two)) |
|
|
|
teamScoreTwo.score = matchDescriptor.teamTwoScores.joined(separator: ",") |
|
|
|
teamScoreTwo.score = matchDescriptor.teamTwoScores.joined(separator: ",") |
|
|
|
try? DataStore.shared.teamScores.addOrUpdate(contentOfs: [teamScoreOne, teamScoreTwo]) |
|
|
|
do { |
|
|
|
|
|
|
|
try DataStore.shared.teamScores.addOrUpdate(contentOfs: [teamScoreOne, teamScoreTwo]) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
Logger.error(error) |
|
|
|
|
|
|
|
} |
|
|
|
matchFormat = matchDescriptor.matchFormat |
|
|
|
matchFormat = matchDescriptor.matchFormat |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|