Schafkopf-Server/Sources/App/Infos/TableInfo.swift

48 lines
1.2 KiB
Swift
Raw Normal View History

2021-11-27 11:59:13 +01:00
import Foundation
2021-12-03 18:03:29 +01:00
struct TableInfo: Codable {
2021-12-01 22:49:54 +01:00
2021-11-27 11:59:13 +01:00
let id: String
let name: String
2021-12-03 18:03:29 +01:00
let player: PlayerInfo
let playerLeft: PlayerInfo?
let playerAcross: PlayerInfo?
let playerRight: PlayerInfo?
let playableGames: [GameId]
2021-12-03 18:03:29 +01:00
init(_ table: Table, forPlayerAt playerIndex: Int) {
let player = table.player(at: playerIndex)!
2021-12-03 18:03:29 +01:00
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)
2021-12-07 09:09:51 +01:00
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 = []
}
2021-12-01 22:49:54 +01:00
}
2021-11-27 11:59:13 +01:00
}
2021-12-03 18:03:29 +01:00
extension TableInfo {
}
2021-11-27 11:59:13 +01:00
extension TableInfo: Comparable {
static func < (lhs: TableInfo, rhs: TableInfo) -> Bool {
lhs.name < rhs.name
}
}