|
|
|
|
@ -50,7 +50,7 @@ enum HtmlService { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func html(headName: Bool, withRank: Bool, withScore: Bool) -> String { |
|
|
|
|
func html(headName: Bool, withRank: Bool, withTeamIndex: Bool, withScore: Bool) -> String { |
|
|
|
|
guard let file = Bundle.main.path(forResource: self.fileName, ofType: "html") else { |
|
|
|
|
fatalError() |
|
|
|
|
} |
|
|
|
|
@ -69,12 +69,12 @@ enum HtmlService { |
|
|
|
|
} |
|
|
|
|
template = template.replacingOccurrences(of: "{{tournamentTitle}}", with: bracket.tournamentObject()!.tournamentTitle(.short)) |
|
|
|
|
template = template.replacingOccurrences(of: "{{bracketTitle}}", with: bracket.groupStageTitle()) |
|
|
|
|
|
|
|
|
|
template = template.replacingOccurrences(of: "{{formatLabel}}", with: bracket.matchFormat.formatTitle()) |
|
|
|
|
var col = "" |
|
|
|
|
var row = "" |
|
|
|
|
bracket.teams().forEach { entrant in |
|
|
|
|
col = col.appending(HtmlService.groupstageColumn(entrant: entrant, position: "col").html(headName: headName, withRank: withRank, withScore: withScore)) |
|
|
|
|
row = row.appending(HtmlService.groupstageRow(entrant: entrant, teamsPerBracket: bracket.size).html(headName: headName, withRank: withRank, withScore: withScore)) |
|
|
|
|
col = col.appending(HtmlService.groupstageColumn(entrant: entrant, position: "col").html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
row = row.appending(HtmlService.groupstageRow(entrant: entrant, teamsPerBracket: bracket.size).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
} |
|
|
|
|
template = template.replacingOccurrences(of: "{{teamsCol}}", with: col) |
|
|
|
|
template = template.replacingOccurrences(of: "{{teamsRow}}", with: row) |
|
|
|
|
@ -82,6 +82,12 @@ enum HtmlService { |
|
|
|
|
return template |
|
|
|
|
case .groupstageEntrant(let entrant): |
|
|
|
|
var template = html |
|
|
|
|
if withTeamIndex == false { |
|
|
|
|
template = template.replacingOccurrences(of: #"<div class="player">{{teamIndex}}</div>"#, with: "") |
|
|
|
|
} else { |
|
|
|
|
template = template.replacingOccurrences(of: "{{teamIndex}}", with: entrant.seedIndex() ?? "") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if let playerOne = entrant.players()[safe: 0] { |
|
|
|
|
template = template.replacingOccurrences(of: "{{playerOne}}", with: playerOne.playerLabel()) |
|
|
|
|
if withRank { |
|
|
|
|
@ -108,7 +114,7 @@ enum HtmlService { |
|
|
|
|
return template |
|
|
|
|
case .groupstageRow(let entrant, let teamsPerBracket): |
|
|
|
|
var template = html |
|
|
|
|
template = template.replacingOccurrences(of: "{{team}}", with: HtmlService.groupstageColumn(entrant: entrant, position: "row").html(headName: headName, withRank: withRank, withScore: withScore)) |
|
|
|
|
template = template.replacingOccurrences(of: "{{team}}", with: HtmlService.groupstageColumn(entrant: entrant, position: "row").html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
|
|
|
|
|
var scores = "" |
|
|
|
|
(0..<teamsPerBracket).forEach { index in |
|
|
|
|
@ -117,28 +123,35 @@ enum HtmlService { |
|
|
|
|
if shouldHide == false { |
|
|
|
|
match = entrant.groupStageObject()?.matchPlayed(by: entrant.groupStagePosition!, againstPosition: index) |
|
|
|
|
} |
|
|
|
|
scores.append(HtmlService.groupstageScore(score: match, shouldHide: shouldHide).html(headName: headName, withRank: withRank, withScore: withScore)) |
|
|
|
|
scores.append(HtmlService.groupstageScore(score: match, shouldHide: shouldHide).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
} |
|
|
|
|
template = template.replacingOccurrences(of: "{{scores}}", with: scores) |
|
|
|
|
return template |
|
|
|
|
case .groupstageColumn(let entrant, let position): |
|
|
|
|
var template = html |
|
|
|
|
template = template.replacingOccurrences(of: "{{tablePosition}}", with: position) |
|
|
|
|
template = template.replacingOccurrences(of: "{{team}}", with: HtmlService.groupstageEntrant(entrant: entrant).html(headName: headName, withRank: withRank, withScore: withScore)) |
|
|
|
|
template = template.replacingOccurrences(of: "{{team}}", with: HtmlService.groupstageEntrant(entrant: entrant).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
return template |
|
|
|
|
case .groupstageScore(let match, let shouldHide): |
|
|
|
|
var template = html |
|
|
|
|
if match == nil || withScore == false { |
|
|
|
|
template = template.replacingOccurrences(of: "{{winner}}", with: "") |
|
|
|
|
template = template.replacingOccurrences(of: "{{score}}", with: "") |
|
|
|
|
} else { |
|
|
|
|
template = template.replacingOccurrences(of: "{{winner}}", with: match!.winner()!.teamLabel()) |
|
|
|
|
template = template.replacingOccurrences(of: "{{score}}", with: match!.scoreLabel()) |
|
|
|
|
} else if let match, let winner = match.winner() { |
|
|
|
|
template = template.replacingOccurrences(of: "{{winner}}", with: winner.teamLabel()) |
|
|
|
|
template = template.replacingOccurrences(of: "{{score}}", with: match.scoreLabel()) |
|
|
|
|
} |
|
|
|
|
template = template.replacingOccurrences(of: "{{hide}}", with: shouldHide ? "hide" : "") |
|
|
|
|
return template |
|
|
|
|
case .player(let entrant): |
|
|
|
|
var template = html |
|
|
|
|
if withTeamIndex == false { |
|
|
|
|
template = template.replacingOccurrences(of: #"<div class="player">{{teamIndex}}</div>"#, with: "") |
|
|
|
|
} else { |
|
|
|
|
template = template.replacingOccurrences(of: "{{teamIndex}}", with: entrant.formattedSeed()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let playerOne = entrant.players()[safe: 0] { |
|
|
|
|
template = template.replacingOccurrences(of: "{{playerOne}}", with: playerOne.playerLabel()) |
|
|
|
|
if withRank { |
|
|
|
|
@ -164,18 +177,22 @@ enum HtmlService { |
|
|
|
|
} |
|
|
|
|
return template |
|
|
|
|
case .hiddenPlayer: |
|
|
|
|
return html + html |
|
|
|
|
var template = html + html |
|
|
|
|
if withTeamIndex { |
|
|
|
|
template += html |
|
|
|
|
} |
|
|
|
|
return template |
|
|
|
|
case .match(let match): |
|
|
|
|
var template = html |
|
|
|
|
if let entrantOne = match.team(.one) { |
|
|
|
|
template = template.replacingOccurrences(of: "{{entrantOne}}", with: HtmlService.player(entrant: entrantOne).html(headName: headName, withRank: withRank, withScore: withScore)) |
|
|
|
|
template = template.replacingOccurrences(of: "{{entrantOne}}", with: HtmlService.player(entrant: entrantOne).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
} else { |
|
|
|
|
template = template.replacingOccurrences(of: "{{entrantOne}}", with: HtmlService.hiddenPlayer.html(headName: headName, withRank: withRank, withScore: withScore)) |
|
|
|
|
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, withScore: withScore)) |
|
|
|
|
template = template.replacingOccurrences(of: "{{entrantTwo}}", with: HtmlService.player(entrant: entrantTwo).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
} else { |
|
|
|
|
template = template.replacingOccurrences(of: "{{entrantTwo}}", with: HtmlService.hiddenPlayer.html(headName: headName, withRank: withRank, withScore: withScore)) |
|
|
|
|
template = template.replacingOccurrences(of: "{{entrantTwo}}", with: HtmlService.hiddenPlayer.html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
} |
|
|
|
|
if match.disabled { |
|
|
|
|
template = template.replacingOccurrences(of: "{{hidden}}", with: "hidden") |
|
|
|
|
@ -196,19 +213,20 @@ enum HtmlService { |
|
|
|
|
var template = "" |
|
|
|
|
var bracket = "" |
|
|
|
|
for (_, match) in round._matches().enumerated() { |
|
|
|
|
template = template.appending(HtmlService.match(match: match).html(headName: headName, withRank: withRank, withScore: withScore)) |
|
|
|
|
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): |
|
|
|
|
var template = html |
|
|
|
|
template = template.replacingOccurrences(of: "{{tournamentTitle}}", with: upperRound.correspondingLoserRoundTitle()) |
|
|
|
|
var brackets = "" |
|
|
|
|
for round in upperRound.loserRounds() { |
|
|
|
|
brackets = brackets.appending(HtmlService.bracket(round: round).html(headName: headName, withRank: withRank, withScore: withScore)) |
|
|
|
|
brackets = brackets.appending(HtmlService.bracket(round: round).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
} |
|
|
|
|
var winnerName = "" |
|
|
|
|
let winnerName = "" |
|
|
|
|
let winner = """ |
|
|
|
|
<ul class="round" scope="last"> |
|
|
|
|
<li class="spacer"> </li> |
|
|
|
|
@ -224,15 +242,17 @@ enum HtmlService { |
|
|
|
|
return template |
|
|
|
|
case .template(let tournament): |
|
|
|
|
var template = html |
|
|
|
|
template = template.replacingOccurrences(of: "{{tournamentTitle}}", with: tournament.tournamentTitle(.short)) |
|
|
|
|
template = template.replacingOccurrences(of: "{{minHeight}}", with: withTeamIndex ? "226" : "156") |
|
|
|
|
template = template.replacingOccurrences(of: "{{tournamentTitle}}", with: tournament.tournamentTitle(.title)) |
|
|
|
|
template = template.replacingOccurrences(of: "{{tournamentStartDate}}", with: tournament.formattedDate()) |
|
|
|
|
var brackets = "" |
|
|
|
|
for round in tournament.rounds() { |
|
|
|
|
brackets = brackets.appending(HtmlService.bracket(round: round).html(headName: headName, withRank: withRank, withScore: withScore)) |
|
|
|
|
brackets = brackets.appending(HtmlService.bracket(round: round).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var winnerName = "" |
|
|
|
|
if let tournamentWinner = tournament.tournamentWinner() { |
|
|
|
|
winnerName = HtmlService.player(entrant: tournamentWinner).html(headName: headName, withRank: withRank, withScore: withScore) |
|
|
|
|
winnerName = HtmlService.player(entrant: tournamentWinner).html(headName: headName, withRank: withRank, withTeamIndex: withTeamIndex, withScore: withScore) |
|
|
|
|
} |
|
|
|
|
let winner = """ |
|
|
|
|
<ul class="round" scope="last"> |
|
|
|
|
|