diff --git a/Public/elements.js b/Public/elements.js index 79bd0e5..516385c 100644 --- a/Public/elements.js +++ b/Public/elements.js @@ -26,6 +26,7 @@ const elementIdTableNameField = "table-name-field" const elementIdPublicTableCheckbox = "table-public-checkbox" const elementIdActionBar = "action-bar" const elementIdAvailableGamesList = "available-games-list" +const elementIdGameSummary = "game-summary" const localStorageTokenId = "token" @@ -265,6 +266,20 @@ function updateTableInfo(table) { } else { setEmptyPlayerInfo("right") } + if (table.hasOwnProperty("summary")) { + setGameSummary(table.summary) + } else { + hideGameSummary() + } +} + +function setGameSummary(summary) { + document.getElementById(elementIdGameSummary).innerHTML = summary.text + setDisplayStyle(elementIdGameSummary, "inherit") +} + +function hideGameSummary() { + hide(elementIdGameSummary) } function setInfoForPlayer(player, position, game) { diff --git a/Public/schafkopf.html b/Public/schafkopf.html index 517d8df..176ff51 100644 --- a/Public/schafkopf.html +++ b/Public/schafkopf.html @@ -54,6 +54,7 @@
Offline
+
The game has ended.
diff --git a/Public/style.css b/Public/style.css index 1a08fc6..298ff5c 100644 --- a/Public/style.css +++ b/Public/style.css @@ -386,6 +386,23 @@ body { text-align: center; } +#game-summary { + display: none; + width: 180px; + height: 130px; + text-align: center; + grid-column: 2 / span 5; + grid-row: 2 / span 3; + z-index: 6; + margin: auto; + padding: 10px; + background-color: var(--standard-background); + color: var(--text-color); + border: 2px solid var(--button-color); + border-radius: 5px; + font-size: medium; +} + #player-cards-center { width: 100%; margin-top: 10px; diff --git a/Sources/App/GameSummary/EnglishGameSummarizer.swift b/Sources/App/GameSummary/EnglishGameSummarizer.swift index 1ebb51a..5484949 100644 --- a/Sources/App/GameSummary/EnglishGameSummarizer.swift +++ b/Sources/App/GameSummary/EnglishGameSummarizer.swift @@ -2,7 +2,7 @@ import Foundation struct EnglishGameSummarizer: GameSummarizer { - let game: GameStatistics + let game: GameSummary private var winText: String { game.didWin ? "won" : "lost" diff --git a/Sources/App/GameSummary/GameSummarizer.swift b/Sources/App/GameSummary/GameSummarizer.swift index 7d47328..779bf79 100644 --- a/Sources/App/GameSummary/GameSummarizer.swift +++ b/Sources/App/GameSummary/GameSummarizer.swift @@ -2,7 +2,7 @@ import Foundation protocol GameSummarizer { - init(game: GameStatistics) + init(game: GameSummary) var text: String { get } } diff --git a/Sources/App/GameSummary/GermanGameSummarizer.swift b/Sources/App/GameSummary/GermanGameSummarizer.swift index 0643f7f..14ba19a 100644 --- a/Sources/App/GameSummary/GermanGameSummarizer.swift +++ b/Sources/App/GameSummary/GermanGameSummarizer.swift @@ -2,7 +2,7 @@ import Foundation struct GermanGameSummarizer: GameSummarizer { - let game: GameStatistics + let game: GameSummary var winText: String { game.didWin ? "gewinnt" : "verliert" @@ -56,7 +56,7 @@ struct GermanGameSummarizer: GameSummarizer { } var text: String { - "\(game.leader) \(winText) \(gameText)\(coPlayerNames) mit \(game.leaderPoints) points. " + + "\(game.leader) \(winText) \(gameText)\(coPlayerNames) mit \(game.leaderPoints) Punkten. " + "Das Spiel kostet \(costText)." } } diff --git a/Sources/App/Infos/GameStatistics.swift b/Sources/App/Infos/GameSummary.swift similarity index 87% rename from Sources/App/Infos/GameStatistics.swift rename to Sources/App/Infos/GameSummary.swift index 7df4a01..60a1e2b 100644 --- a/Sources/App/Infos/GameStatistics.swift +++ b/Sources/App/Infos/GameSummary.swift @@ -1,6 +1,6 @@ import Foundation -struct GameStatistics: Codable, Equatable { +struct GameSummary: Codable, Equatable { let leader: PlayerName @@ -27,6 +27,7 @@ struct GameStatistics: Codable, Equatable { self.didWin = table.winners.contains(player: leader.name) self.cost = table.game.basicCost // TODO: Calculate cost correctly + self.text = language.gameSummarizer.init(game: self).text } } diff --git a/Sources/App/Infos/TableInfo.swift b/Sources/App/Infos/TableInfo.swift index 2191841..21841f1 100644 --- a/Sources/App/Infos/TableInfo.swift +++ b/Sources/App/Infos/TableInfo.swift @@ -26,7 +26,7 @@ struct TableInfo: Codable { var game: GameId? = nil - var gameStats: GameStatistics? + var summary: GameSummary? init(id: TableId, name: TableName) { self.id = id diff --git a/Sources/App/Model/Players/PlayingPlayer.swift b/Sources/App/Model/Players/PlayingPlayer.swift index a0c459e..d737c96 100644 --- a/Sources/App/Model/Players/PlayingPlayer.swift +++ b/Sources/App/Model/Players/PlayingPlayer.swift @@ -42,9 +42,9 @@ final class PlayingPlayer: CardHoldingPlayer { guard canStillRaise else { return [] } - if isUnknownCallee && leadsGame { + guard !isUnknownCallee else { // Player belongs to caller, but other side has raised - return [.doubleDuringGame] + return leadsGame ? [.doubleDuringGame] : [] } guard !leadsGame else { return [] @@ -54,6 +54,7 @@ final class PlayingPlayer: CardHoldingPlayer { func play(card: Card) { playedCard = card + canStillRaise = false cards = cards.filter { $0 != card } if card == isCalledWithAce { leadsGame.toggle() diff --git a/Sources/App/Model/Tables/DealingTable.swift b/Sources/App/Model/Tables/DealingTable.swift index c129a8d..a72ed84 100644 --- a/Sources/App/Model/Tables/DealingTable.swift +++ b/Sources/App/Model/Tables/DealingTable.swift @@ -19,7 +19,7 @@ final class DealingTable: AbstractTable { /// At least one player placed a bid var hasDouble: Bool { - players.contains { $0.didDouble == true } + players.contains { $0.didDouble } } override func perform(action: PlayerAction, forPlayer name: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?) { @@ -46,6 +46,7 @@ final class DealingTable: AbstractTable { return (.tableStateInvalid, nil) } player.didDouble = double + player.didDecide = true guard allPlayersActed else { return (.success, nil) } diff --git a/Sources/App/Model/Tables/FinishedTable.swift b/Sources/App/Model/Tables/FinishedTable.swift index 6ec4e64..8228e18 100644 --- a/Sources/App/Model/Tables/FinishedTable.swift +++ b/Sources/App/Model/Tables/FinishedTable.swift @@ -87,7 +87,7 @@ final class FinishedTable: AbstractTable { override func tableInfo(forPlayerAt index: Int) -> TableInfo { var info = super.tableInfo(forPlayerAt: index) - info.gameStats = GameStatistics(table: self, language: language) + info.summary = GameSummary(table: self, language: language) return info } }