2021-12-03 18:03:29 +01:00
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct PlayerInfo: Codable, Equatable {
|
2021-12-09 11:11:17 +01:00
|
|
|
|
|
|
|
/// The name of the player
|
2021-12-03 18:03:29 +01:00
|
|
|
let name: PlayerName
|
2021-12-06 18:28:35 +01:00
|
|
|
|
2021-12-09 11:11:17 +01:00
|
|
|
/// Indicates that the player is active, i.e. a session is established
|
|
|
|
let isConnected: Bool
|
2021-12-03 18:03:29 +01:00
|
|
|
|
2021-12-09 11:11:17 +01:00
|
|
|
/// The player is the next one to perform an action
|
|
|
|
let isNextActor: Bool
|
2021-12-06 18:28:35 +01:00
|
|
|
|
2021-12-09 11:11:17 +01:00
|
|
|
/// The card which the player added to the current trick
|
2021-12-06 18:28:35 +01:00
|
|
|
let playedCard: CardId?
|
|
|
|
|
|
|
|
/// The height of the player card on the table stack
|
2021-12-09 11:11:17 +01:00
|
|
|
let positionInTrick: Int
|
|
|
|
|
2021-12-18 15:08:43 +01:00
|
|
|
/// 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) {
|
2021-12-03 18:03:29 +01:00
|
|
|
self.name = player.name
|
2021-12-09 11:11:17 +01:00
|
|
|
self.isConnected = player.isConnected
|
2021-12-18 15:08:43 +01:00
|
|
|
self.isNextActor = player.isNextActor
|
2021-12-09 11:11:17 +01:00
|
|
|
self.positionInTrick = position
|
2021-12-06 18:28:35 +01:00
|
|
|
self.playedCard = player.playedCard?.id
|
2021-12-18 15:08:43 +01:00
|
|
|
self.numberOfDoubles = player.numberOfDoubles
|
|
|
|
self.leadsGame = player.leadsGame
|
|
|
|
self.points = player.points
|
2021-12-09 11:11:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Convert the property names into shorter strings for JSON encoding
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
|
|
case name = "name"
|
|
|
|
case isConnected = "connected"
|
|
|
|
case isNextActor = "active"
|
|
|
|
case playedCard = "card"
|
|
|
|
case positionInTrick = "position"
|
2021-12-18 15:08:43 +01:00
|
|
|
case numberOfDoubles = "doubles"
|
|
|
|
case leadsGame = "leads"
|
|
|
|
case points = "points"
|
2021-12-03 18:03:29 +01:00
|
|
|
}
|
|
|
|
}
|