Play cards, select game, player actions

This commit is contained in:
Christoph Hagen
2021-12-06 18:28:35 +01:00
parent ca7fc858c2
commit fa3aaadef8
11 changed files with 304 additions and 128 deletions

View File

@ -8,17 +8,27 @@ struct PlayerInfo: Codable, Equatable {
/// The player is the next one to perform an action
let active: Bool
let selectsGame: Bool
/// The cards in the hand of the player
let cards: [CardInfo]
/// The action the player can perform
let actions: [String]
let playedCard: CardId?
/// The height of the player card on the table stack
let position: Int
init(player: Player, isMasked: Bool) {
init(player: Player, isMasked: Bool, trickPosition: Int) {
self.name = player.name
self.connected = player.isConnected
self.active = player.isNextActor
self.selectsGame = player.selectsGame
self.playedCard = player.playedCard?.id
self.position = trickPosition
if isMasked {
self.cards = []
self.actions = []

View File

@ -13,14 +13,24 @@ struct TableInfo: Codable {
let playerAcross: PlayerInfo?
let playerRight: PlayerInfo?
let playableGames: [GameId]
init(_ table: Table, forPlayerAt playerIndex: Int) {
let player = table.player(at: playerIndex)!
self.id = table.id
self.name = table.name
self.player = table.player(at: playerIndex)!.info(masked: false)
self.playerLeft = table.player(leftOf: playerIndex)?.info(masked: true)
self.playerAcross = table.player(acrossOf: playerIndex)?.info(masked: true)
self.playerRight = table.player(rightOf: playerIndex)?.info(masked: true)
self.player = table.playerInfo(at: playerIndex, masked: false)!
self.playerLeft = table.playerInfo(leftOf: playerIndex, masked: true)
self.playerAcross = table.playerInfo(acrossOf: playerIndex, masked: true)
self.playerRight = table.playerInfo(rightOf: playerIndex, masked: true)
if table.phase == .selectGame, player.selectsGame {
let games = table.minimumPlayableGame?.availableGames ?? GameType.allCases
self.playableGames = games.filter(player.canPlay).map { $0.id }
} else {
self.playableGames = []
}
}
}