|
|
|
|
@ -12,7 +12,7 @@ enum HtmlService { |
|
|
|
|
|
|
|
|
|
case template(tournament: Tournament) |
|
|
|
|
case bracket(round: Round) |
|
|
|
|
case loserBracket(upperRound: Round) |
|
|
|
|
case loserBracket(upperRound: Round, hideTitle: Bool) |
|
|
|
|
case match(match: Match) |
|
|
|
|
case player(entrant: TeamRegistration) |
|
|
|
|
case hiddenPlayer |
|
|
|
|
@ -187,11 +187,17 @@ enum HtmlService { |
|
|
|
|
var template = html |
|
|
|
|
if let entrantOne = match.team(.one) { |
|
|
|
|
template = template.replacingOccurrences(of: "{{entrantOne}}", with: HtmlService.player(entrant: entrantOne).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
if withScore, let top = match.topPreviousRoundMatch(), top.hasEnded() { |
|
|
|
|
template = template.replacingOccurrences(of: "{{matchDescriptionTop}}", with: [top.scoreLabel(winnerFirst:true)].compactMap({ $0 }).joined(separator: "\n")) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
template = template.replacingOccurrences(of: "{{entrantOne}}", with: HtmlService.hiddenPlayer.html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
} |
|
|
|
|
if let entrantTwo = match.team(.two) { |
|
|
|
|
template = template.replacingOccurrences(of: "{{entrantTwo}}", with: HtmlService.player(entrant: entrantTwo).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
if withScore, let bottom = match.bottomPreviousRoundMatch(), bottom.hasEnded() { |
|
|
|
|
template = template.replacingOccurrences(of: "{{matchDescriptionBottom}}", with: [bottom.scoreLabel(winnerFirst:true)].compactMap({ $0 }).joined(separator: "\n")) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
template = template.replacingOccurrences(of: "{{entrantTwo}}", with: HtmlService.hiddenPlayer.html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
} |
|
|
|
|
@ -206,9 +212,10 @@ enum HtmlService { |
|
|
|
|
} else if match.teamWon(atPosition: .two) == true { |
|
|
|
|
template = template.replacingOccurrences(of: "{{entrantTwoWon}}", with: "winner") |
|
|
|
|
} |
|
|
|
|
template = template.replacingOccurrences(of: "{{matchDescription}}", with: [match.localizedStartDate(), match.scoreLabel()].joined(separator: "\n")) |
|
|
|
|
// template = template.replacingOccurrences(of: "{{matchDescription}}", with: [match.localizedStartDate(), match.scoreLabel()].joined(separator: "\n")) |
|
|
|
|
} |
|
|
|
|
template = template.replacingOccurrences(of: "{{matchDescription}}", with: "") |
|
|
|
|
template = template.replacingOccurrences(of: "{{matchDescriptionTop}}", with: "") |
|
|
|
|
template = template.replacingOccurrences(of: "{{matchDescriptionBottom}}", with: "") |
|
|
|
|
return template |
|
|
|
|
case .bracket(let round): |
|
|
|
|
var template = "" |
|
|
|
|
@ -216,16 +223,31 @@ enum HtmlService { |
|
|
|
|
for (_, match) in round._matches().enumerated() { |
|
|
|
|
template = template.appending(HtmlService.match(match: match).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bracket = html.replacingOccurrences(of: "{{match-template}}", with: template) |
|
|
|
|
bracket = bracket.replacingOccurrences(of: "{{roundLabel}}", with: round.roundTitle()) |
|
|
|
|
bracket = bracket.replacingOccurrences(of: "{{formatLabel}}", with: round.matchFormat.formatTitle()) |
|
|
|
|
return bracket |
|
|
|
|
case .loserBracket(let upperRound): |
|
|
|
|
case .loserBracket(let upperRound, let hideTitle): |
|
|
|
|
var template = html |
|
|
|
|
template = template.replacingOccurrences(of: "{{minHeight}}", with: withTeamIndex ? "226" : "156") |
|
|
|
|
template = template.replacingOccurrences(of: "{{tournamentTitle}}", with: upperRound.correspondingLoserRoundTitle()) |
|
|
|
|
if let tournamentStartDate = upperRound.initialStartDate()?.localizedDate() { |
|
|
|
|
template = template.replacingOccurrences(of: "{{tournamentStartDate}}", with: tournamentStartDate) |
|
|
|
|
} else { |
|
|
|
|
template = template.replacingOccurrences(of: "{{tournamentStartDate}}", with: "") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template = template.replacingOccurrences(of: "{{titleHidden}}", with: hideTitle ? "hidden" : "") |
|
|
|
|
|
|
|
|
|
var brackets = "" |
|
|
|
|
for round in upperRound.loserRounds() { |
|
|
|
|
brackets = brackets.appending(HtmlService.bracket(round: round).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
|
|
|
|
|
if round.index == 1 { |
|
|
|
|
let sub = HtmlService.loserBracket(upperRound: round, hideTitle: true).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore) |
|
|
|
|
template = template.appending(sub) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
let winnerName = "" |
|
|
|
|
let winner = """ |
|
|
|
|
@ -240,6 +262,14 @@ enum HtmlService { |
|
|
|
|
brackets = brackets.appending(winner) |
|
|
|
|
|
|
|
|
|
template = template.replacingOccurrences(of: "{{brackets}}", with: brackets) |
|
|
|
|
|
|
|
|
|
for round in upperRound.loserRounds() { |
|
|
|
|
if round.index > 1 { |
|
|
|
|
let sub = HtmlService.loserBracket(upperRound: round, hideTitle: true).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore) |
|
|
|
|
template = template.appending(sub) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return template |
|
|
|
|
case .template(let tournament): |
|
|
|
|
var template = html |
|
|
|
|
|