Clarify action id
This commit is contained in:
parent
445363307b
commit
577a60c1d1
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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() }
|
||||
|
@ -1,5 +1,7 @@
|
||||
import Foundation
|
||||
|
||||
typealias ActionId = String
|
||||
|
||||
enum PlayerAction: String, Codable {
|
||||
/// The player can request cards to be dealt
|
||||
case deal = "deal"
|
||||
@ -26,7 +28,7 @@ enum PlayerAction: String, Codable {
|
||||
case doubleDuringGame = "raise"
|
||||
|
||||
/// The url path for the client to call (e.g. /player/deal)
|
||||
var path: String {
|
||||
var id: ActionId {
|
||||
rawValue
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user