From 577a60c1d1367c5faf6268dfcfe58bd73da7beb7 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Thu, 9 Dec 2021 11:18:26 +0100 Subject: [PATCH] Clarify action id --- Sources/App/Infos/TableInfo.swift | 4 ++-- Sources/App/Management/TableManagement.swift | 2 +- Sources/App/Model/OldTable.swift | 2 +- Sources/App/Model/PlayerAction.swift | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Sources/App/Infos/TableInfo.swift b/Sources/App/Infos/TableInfo.swift index f598fb2..fcf5840 100644 --- a/Sources/App/Infos/TableInfo.swift +++ b/Sources/App/Infos/TableInfo.swift @@ -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 } diff --git a/Sources/App/Management/TableManagement.swift b/Sources/App/Management/TableManagement.swift index 9a04c66..a94af6b 100644 --- a/Sources/App/Management/TableManagement.swift +++ b/Sources/App/Management/TableManagement.swift @@ -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) diff --git a/Sources/App/Model/OldTable.swift b/Sources/App/Model/OldTable.swift index 34cf67d..826ec9a 100644 --- a/Sources/App/Model/OldTable.swift +++ b/Sources/App/Model/OldTable.swift @@ -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() } diff --git a/Sources/App/Model/PlayerAction.swift b/Sources/App/Model/PlayerAction.swift index 0dc3f6d..1d182d0 100644 --- a/Sources/App/Model/PlayerAction.swift +++ b/Sources/App/Model/PlayerAction.swift @@ -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 } }