Add game summary on client side
This commit is contained in:
parent
941b25346d
commit
b5cc395456
@ -26,6 +26,7 @@ const elementIdTableNameField = "table-name-field"
|
|||||||
const elementIdPublicTableCheckbox = "table-public-checkbox"
|
const elementIdPublicTableCheckbox = "table-public-checkbox"
|
||||||
const elementIdActionBar = "action-bar"
|
const elementIdActionBar = "action-bar"
|
||||||
const elementIdAvailableGamesList = "available-games-list"
|
const elementIdAvailableGamesList = "available-games-list"
|
||||||
|
const elementIdGameSummary = "game-summary"
|
||||||
|
|
||||||
const localStorageTokenId = "token"
|
const localStorageTokenId = "token"
|
||||||
|
|
||||||
@ -265,6 +266,20 @@ function updateTableInfo(table) {
|
|||||||
} else {
|
} else {
|
||||||
setEmptyPlayerInfo("right")
|
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) {
|
function setInfoForPlayer(player, position, game) {
|
||||||
|
@ -54,6 +54,7 @@
|
|||||||
<div id="table-player-state-left" class="player-connection-state">Offline</div>
|
<div id="table-player-state-left" class="player-connection-state">Offline</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="available-games-list"></div>
|
<div id="available-games-list"></div>
|
||||||
|
<div id="game-summary">The game has ended.</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="action-bar-centering">
|
<div id="action-bar-centering">
|
||||||
<div id="action-bar"></div>
|
<div id="action-bar"></div>
|
||||||
|
@ -386,6 +386,23 @@ body {
|
|||||||
text-align: center;
|
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 {
|
#player-cards-center {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
|
@ -2,7 +2,7 @@ import Foundation
|
|||||||
|
|
||||||
struct EnglishGameSummarizer: GameSummarizer {
|
struct EnglishGameSummarizer: GameSummarizer {
|
||||||
|
|
||||||
let game: GameStatistics
|
let game: GameSummary
|
||||||
|
|
||||||
private var winText: String {
|
private var winText: String {
|
||||||
game.didWin ? "won" : "lost"
|
game.didWin ? "won" : "lost"
|
||||||
|
@ -2,7 +2,7 @@ import Foundation
|
|||||||
|
|
||||||
protocol GameSummarizer {
|
protocol GameSummarizer {
|
||||||
|
|
||||||
init(game: GameStatistics)
|
init(game: GameSummary)
|
||||||
|
|
||||||
var text: String { get }
|
var text: String { get }
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import Foundation
|
|||||||
|
|
||||||
struct GermanGameSummarizer: GameSummarizer {
|
struct GermanGameSummarizer: GameSummarizer {
|
||||||
|
|
||||||
let game: GameStatistics
|
let game: GameSummary
|
||||||
|
|
||||||
var winText: String {
|
var winText: String {
|
||||||
game.didWin ? "gewinnt" : "verliert"
|
game.didWin ? "gewinnt" : "verliert"
|
||||||
@ -56,7 +56,7 @@ struct GermanGameSummarizer: GameSummarizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var text: String {
|
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)."
|
"Das Spiel kostet \(costText)."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct GameStatistics: Codable, Equatable {
|
struct GameSummary: Codable, Equatable {
|
||||||
|
|
||||||
let leader: PlayerName
|
let leader: PlayerName
|
||||||
|
|
||||||
@ -27,6 +27,7 @@ struct GameStatistics: Codable, Equatable {
|
|||||||
self.didWin = table.winners.contains(player: leader.name)
|
self.didWin = table.winners.contains(player: leader.name)
|
||||||
self.cost = table.game.basicCost
|
self.cost = table.game.basicCost
|
||||||
// TODO: Calculate cost correctly
|
// TODO: Calculate cost correctly
|
||||||
|
self.text = language.gameSummarizer.init(game: self).text
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -26,7 +26,7 @@ struct TableInfo: Codable {
|
|||||||
|
|
||||||
var game: GameId? = nil
|
var game: GameId? = nil
|
||||||
|
|
||||||
var gameStats: GameStatistics?
|
var summary: GameSummary?
|
||||||
|
|
||||||
init(id: TableId, name: TableName) {
|
init(id: TableId, name: TableName) {
|
||||||
self.id = id
|
self.id = id
|
||||||
|
@ -42,9 +42,9 @@ final class PlayingPlayer: CardHoldingPlayer {
|
|||||||
guard canStillRaise else {
|
guard canStillRaise else {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
if isUnknownCallee && leadsGame {
|
guard !isUnknownCallee else {
|
||||||
// Player belongs to caller, but other side has raised
|
// Player belongs to caller, but other side has raised
|
||||||
return [.doubleDuringGame]
|
return leadsGame ? [.doubleDuringGame] : []
|
||||||
}
|
}
|
||||||
guard !leadsGame else {
|
guard !leadsGame else {
|
||||||
return []
|
return []
|
||||||
@ -54,6 +54,7 @@ final class PlayingPlayer: CardHoldingPlayer {
|
|||||||
|
|
||||||
func play(card: Card) {
|
func play(card: Card) {
|
||||||
playedCard = card
|
playedCard = card
|
||||||
|
canStillRaise = false
|
||||||
cards = cards.filter { $0 != card }
|
cards = cards.filter { $0 != card }
|
||||||
if card == isCalledWithAce {
|
if card == isCalledWithAce {
|
||||||
leadsGame.toggle()
|
leadsGame.toggle()
|
||||||
|
@ -19,7 +19,7 @@ final class DealingTable: AbstractTable<DealingPlayer> {
|
|||||||
|
|
||||||
/// At least one player placed a bid
|
/// At least one player placed a bid
|
||||||
var hasDouble: Bool {
|
var hasDouble: Bool {
|
||||||
players.contains { $0.didDouble == true }
|
players.contains { $0.didDouble }
|
||||||
}
|
}
|
||||||
|
|
||||||
override func perform(action: PlayerAction, forPlayer name: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?) {
|
override func perform(action: PlayerAction, forPlayer name: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?) {
|
||||||
@ -46,6 +46,7 @@ final class DealingTable: AbstractTable<DealingPlayer> {
|
|||||||
return (.tableStateInvalid, nil)
|
return (.tableStateInvalid, nil)
|
||||||
}
|
}
|
||||||
player.didDouble = double
|
player.didDouble = double
|
||||||
|
player.didDecide = true
|
||||||
guard allPlayersActed else {
|
guard allPlayersActed else {
|
||||||
return (.success, nil)
|
return (.success, nil)
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ final class FinishedTable: AbstractTable<FinishedPlayer> {
|
|||||||
|
|
||||||
override func tableInfo(forPlayerAt index: Int) -> TableInfo {
|
override func tableInfo(forPlayerAt index: Int) -> TableInfo {
|
||||||
var info = super.tableInfo(forPlayerAt: index)
|
var info = super.tableInfo(forPlayerAt: index)
|
||||||
info.gameStats = GameStatistics(table: self, language: language)
|
info.summary = GameSummary(table: self, language: language)
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user