First working version
This commit is contained in:
@ -17,12 +17,22 @@ struct PlayerInfo: Codable, Equatable {
|
||||
/// The height of the player card on the table stack
|
||||
let positionInTrick: Int
|
||||
|
||||
init(player: Player, isNextActor: Bool, position: Int) {
|
||||
/// The number of times the player doubled the game cost (initial double and raises)
|
||||
let numberOfDoubles: Int
|
||||
|
||||
let leadsGame: Bool
|
||||
|
||||
let points: Int?
|
||||
|
||||
init(player: Player, position: Int) {
|
||||
self.name = player.name
|
||||
self.isConnected = player.isConnected
|
||||
self.isNextActor = isNextActor
|
||||
self.isNextActor = player.isNextActor
|
||||
self.positionInTrick = position
|
||||
self.playedCard = player.playedCard?.id
|
||||
self.numberOfDoubles = player.numberOfDoubles
|
||||
self.leadsGame = player.leadsGame
|
||||
self.points = player.points
|
||||
}
|
||||
|
||||
/// Convert the property names into shorter strings for JSON encoding
|
||||
@ -32,5 +42,8 @@ struct PlayerInfo: Codable, Equatable {
|
||||
case isNextActor = "active"
|
||||
case playedCard = "card"
|
||||
case positionInTrick = "position"
|
||||
case numberOfDoubles = "doubles"
|
||||
case leadsGame = "leads"
|
||||
case points = "points"
|
||||
}
|
||||
}
|
||||
|
@ -23,23 +23,22 @@ struct TableInfo: Codable {
|
||||
let actions: [ActionId]
|
||||
|
||||
let playerSelectsGame: Bool
|
||||
|
||||
let game: GameId?
|
||||
|
||||
init(id: String, name: String,
|
||||
own: PlayerInfo, left: PlayerInfo?,
|
||||
across: PlayerInfo?, right: PlayerInfo?,
|
||||
games: [GameType] = [], actions: [PlayerAction],
|
||||
cards: [PlayableCard],
|
||||
selectGame: Bool = false) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.player = own
|
||||
self.playerLeft = left
|
||||
self.playerAcross = across
|
||||
self.playerRight = right
|
||||
self.playableGames = games.map { $0.id }
|
||||
self.actions = actions.map { $0.id }
|
||||
self.cards = cards.map { $0.cardInfo }
|
||||
self.playerSelectsGame = selectGame
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user