Schafkopf-Server/Sources/App/GameSummary/EnglishGameSummarizer.swift

89 lines
2.5 KiB
Swift
Raw Normal View History

import Foundation
struct EnglishGameSummarizer: GameSummarizer {
2021-12-21 14:24:53 +01:00
let table: FinishedTable
private var winText: String {
2021-12-21 14:24:53 +01:00
table.selectorDidWin ? "won" : "lost"
}
private var gameText: String {
2021-12-21 14:24:53 +01:00
switch table.game {
case .rufBlatt:
return "the call of Blatt"
case .rufEichel:
return "the call of Eichel"
case .rufSchelln:
return "the call of Schelln"
case .bettel:
return "the Bettel"
case .geier:
return "the Geier"
case .wenz:
return "the Wenz"
case .hochzeit:
return "the wedding"
case .soloBlatt:
return "the Solo Blatt"
case .soloEichel:
return "the Solo Eichel"
case .soloHerz:
return "the Solo Herz"
case .soloSchelln:
return "the Solo Schelln"
}
}
private var coPlayerNames: String {
2021-12-21 14:24:53 +01:00
let coPlayers = table.coPlayers
switch coPlayers.count {
case 0:
return ""
case 1:
2021-12-21 14:24:53 +01:00
return " with \(coPlayers[0].name)"
case 2:
2021-12-21 14:24:53 +01:00
return " with \(coPlayers[0].name) and \(coPlayers[1].name)"
default:
return ""
}
}
private var costText: String {
2021-12-21 14:24:53 +01:00
let cost = table.cost
guard cost >= 100 else {
return "\(cost) cents"
}
2021-12-21 14:24:53 +01:00
return String(format: "%d.%02d €", cost / 100, cost % 100)
}
private var costExplanation: String {
var components = [String]()
components.append("Game \(table.game.basicCost)")
if !table.isBettel {
2021-12-22 14:54:31 +01:00
if table.isHochzeit {
components.append("wedding")
}
2021-12-21 14:24:53 +01:00
if table.isSchwarz {
components.append("Schwarz")
} else if table.isSchneider {
components.append("Schneider")
}
if table.leadingTrumps > 0 {
components.append("\(table.leadingTrumps) Laufende")
}
}
components.append("\(table.totalNumberOfDoubles)x doubled")
return components.joined(separator: ", ")
}
var text: String {
2021-12-21 14:24:53 +01:00
let start = "\(table.gameSelector.name) \(winText) the \(gameText)"
let cost = " The game costs \(costText) (\(costExplanation))."
guard table.game != .bettel else {
return start + cost
}
return start + "\(coPlayerNames) with \(table.selectorTeamPoints) points." + cost
}
}