Clarify action id

This commit is contained in:
Christoph Hagen 2021-12-09 11:18:26 +01:00
parent 445363307b
commit 577a60c1d1
4 changed files with 8 additions and 6 deletions

View File

@ -20,7 +20,7 @@ struct TableInfo: Codable {
let cards: [CardInfo]
/// The action the player can perform
let actions: [String]
let actions: [ActionId]
let playerSelectsGame: Bool
@ -37,7 +37,7 @@ struct TableInfo: Codable {
self.playerAcross = across
self.playerRight = right
self.playableGames = games.map { $0.id }
self.actions = actions.map { $0.path }
self.actions = actions.map { $0.id }
self.cards = cards.map { $0.cardInfo }
self.playerSelectsGame = selectGame
}

View File

@ -176,7 +176,7 @@ final class TableManagement: DiskWriter {
func performAction(player: PlayerName, action: PlayerAction) -> PlayerActionResult {
guard let table = currentTable(for: player) else {
print("Player \(player) wants to \(action.path), but no table joined")
print("Player \(player) wants to \(action.id), but no table joined")
return .noTableJoined
}
let (result, newTable) = table.perform(action: action, forPlayer: player)

View File

@ -269,7 +269,7 @@ final class OldTable {
func perform(action: PlayerAction, forPlayer player: PlayerName) -> PlayerActionResult {
let player = select(player: player)!
guard player.canPerform(action) else {
print("Player \(player) wants to \(action.path), but only allowed: \(player.actions)")
print("Player \(player) wants to \(action.id), but only allowed: \(player.actions)")
return .tableStateInvalid
}
defer { sendUpdateToAllPlayers() }

View File

@ -1,5 +1,7 @@
import Foundation
typealias ActionId = String
enum PlayerAction: String, Codable {
/// The player can request cards to be dealt
case deal = "deal"
@ -24,9 +26,9 @@ enum PlayerAction: String, Codable {
/// The player claims to win and doubles the game cost ("schießen")
case doubleDuringGame = "raise"
/// The url path for the client to call (e.g. /player/deal)
var path: String {
var id: ActionId {
rawValue
}
}