56 lines
1.3 KiB
Swift
56 lines
1.3 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]
|
|
|
|
/// The cards in the hand of the player
|
|
let cards: [CardInfo]
|
|
|
|
/// The action the player can perform
|
|
let actions: [ActionId]
|
|
|
|
let playerSelectsGame: Bool
|
|
|
|
let game: GameId?
|
|
|
|
init<T>(table: AbstractTable<T>, index: Int) {
|
|
self.id = table.id
|
|
self.name = table.name
|
|
self.player = table.playerInfo(forIndex: index)!
|
|
self.playerLeft = table.playerInfo(forIndex: (index + 1) % 4)
|
|
self.playerAcross = table.playerInfo(forIndex: (index + 2) % 4)
|
|
self.playerRight = table.playerInfo(forIndex: (index + 3) % 4)
|
|
let data = table.playerData(at: index)
|
|
self.playableGames = data.games.map { $0.id }
|
|
self.actions = data.actions.map { $0.id }
|
|
self.cards = data.cards.map { $0.cardInfo }
|
|
self.playerSelectsGame = data.selectsGame
|
|
self.game = table.playedGame?.id
|
|
}
|
|
}
|
|
|
|
extension TableInfo {
|
|
|
|
|
|
}
|
|
|
|
extension TableInfo: Comparable {
|
|
|
|
static func < (lhs: TableInfo, rhs: TableInfo) -> Bool {
|
|
lhs.name < rhs.name
|
|
}
|
|
}
|