Update player points when game ends

This commit is contained in:
Christoph Hagen
2022-10-18 11:40:08 +02:00
parent df97271987
commit 3c4d1f0e29
5 changed files with 29 additions and 8 deletions

View File

@ -266,11 +266,11 @@ final class SQLiteDatabase {
return tables.select(game: game, player: player)
}
func play(card: Card, playerToken: SessionToken) -> PlayerActionResult {
func play(card: Card, playerToken: SessionToken, in database: Database) async throws -> PlayerActionResult {
guard let player = playerNameForToken[playerToken] else {
return .invalidToken
}
return tables.play(card: card, player: player)
return try await tables.play(card: card, player: player, in: database)
}
func disconnectAllSockets() {

View File

@ -114,8 +114,8 @@ final class TableManagement {
}
/// `player.canStartGame` is automatically set to false, because table is not full
tables[table.id] = table
#warning("Update points for all players, add penalty if running game")
table.sendUpdateToAllPlayers()
// TODO: Update points for all players
try await player.update(on: database)
}
@ -177,7 +177,7 @@ final class TableManagement {
return .success
}
func play(card: Card, player: PlayerName) -> PlayerActionResult {
func play(card: Card, player: PlayerName, in database: Database) async throws -> PlayerActionResult {
guard let table = currentTable(for: player) else {
return .noTableJoined
}
@ -190,8 +190,10 @@ final class TableManagement {
return .success
}
tables[newTable.id] = newTable
if let finished = newTable as? FinishedTable {
try await finished.updatePlayerPoints(in: database)
}
newTable.sendUpdateToAllPlayers()
// TODO: Save new table
return .success
}