Schafkopf-Server/Sources/App/Infos/TableInfo.swift
Christoph Hagen 9d9c8ad71f Bug fixing
2021-12-07 09:09:51 +01:00

48 lines
1.2 KiB
Swift

import Foundation
struct TableInfo: Codable {
let id: String
let name: String
let player: PlayerInfo
let playerLeft: PlayerInfo?
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.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 == .bidding || table.phase == .selectGame {
let games = table.minimumPlayableGame?.availableGames ?? GameType.allCases
self.playableGames = games.filter(player.canPlay).map { $0.id }
} else {
self.playableGames = []
}
}
}
extension TableInfo {
}
extension TableInfo: Comparable {
static func < (lhs: TableInfo, rhs: TableInfo) -> Bool {
lhs.name < rhs.name
}
}