Clarify action id
This commit is contained in:
parent
445363307b
commit
577a60c1d1
@ -20,7 +20,7 @@ struct TableInfo: Codable {
|
|||||||
let cards: [CardInfo]
|
let cards: [CardInfo]
|
||||||
|
|
||||||
/// The action the player can perform
|
/// The action the player can perform
|
||||||
let actions: [String]
|
let actions: [ActionId]
|
||||||
|
|
||||||
let playerSelectsGame: Bool
|
let playerSelectsGame: Bool
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ struct TableInfo: Codable {
|
|||||||
self.playerAcross = across
|
self.playerAcross = across
|
||||||
self.playerRight = right
|
self.playerRight = right
|
||||||
self.playableGames = games.map { $0.id }
|
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.cards = cards.map { $0.cardInfo }
|
||||||
self.playerSelectsGame = selectGame
|
self.playerSelectsGame = selectGame
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ final class TableManagement: DiskWriter {
|
|||||||
|
|
||||||
func performAction(player: PlayerName, action: PlayerAction) -> PlayerActionResult {
|
func performAction(player: PlayerName, action: PlayerAction) -> PlayerActionResult {
|
||||||
guard let table = currentTable(for: player) else {
|
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
|
return .noTableJoined
|
||||||
}
|
}
|
||||||
let (result, newTable) = table.perform(action: action, forPlayer: player)
|
let (result, newTable) = table.perform(action: action, forPlayer: player)
|
||||||
|
@ -269,7 +269,7 @@ final class OldTable {
|
|||||||
func perform(action: PlayerAction, forPlayer player: PlayerName) -> PlayerActionResult {
|
func perform(action: PlayerAction, forPlayer player: PlayerName) -> PlayerActionResult {
|
||||||
let player = select(player: player)!
|
let player = select(player: player)!
|
||||||
guard player.canPerform(action) else {
|
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
|
return .tableStateInvalid
|
||||||
}
|
}
|
||||||
defer { sendUpdateToAllPlayers() }
|
defer { sendUpdateToAllPlayers() }
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
typealias ActionId = String
|
||||||
|
|
||||||
enum PlayerAction: String, Codable {
|
enum PlayerAction: String, Codable {
|
||||||
/// The player can request cards to be dealt
|
/// The player can request cards to be dealt
|
||||||
case deal = "deal"
|
case deal = "deal"
|
||||||
@ -24,9 +26,9 @@ enum PlayerAction: String, Codable {
|
|||||||
|
|
||||||
/// The player claims to win and doubles the game cost ("schießen")
|
/// The player claims to win and doubles the game cost ("schießen")
|
||||||
case doubleDuringGame = "raise"
|
case doubleDuringGame = "raise"
|
||||||
|
|
||||||
/// The url path for the client to call (e.g. /player/deal)
|
/// The url path for the client to call (e.g. /player/deal)
|
||||||
var path: String {
|
var id: ActionId {
|
||||||
rawValue
|
rawValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user