Update player points when game ends
This commit is contained in:
@ -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() {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user