2021-12-18 15:08:43 +01:00
|
|
|
import Foundation
|
|
|
|
import WebSocketKit
|
|
|
|
|
|
|
|
protocol ManageableTable {
|
|
|
|
|
|
|
|
/// The unique id of the table
|
2021-12-22 22:13:09 +01:00
|
|
|
var id: UUID { get }
|
2021-12-18 15:08:43 +01:00
|
|
|
|
|
|
|
/// The name of the table
|
|
|
|
var name: TableName { get }
|
|
|
|
|
|
|
|
/// The table is visible in the list of tables and can be joined by anyone
|
|
|
|
var isPublic: Bool { get }
|
|
|
|
|
2021-12-22 22:13:09 +01:00
|
|
|
var leavePenalty: Int { get }
|
|
|
|
|
2021-12-18 15:08:43 +01:00
|
|
|
var playerNames: [PlayerName] { get }
|
|
|
|
|
|
|
|
var allPlayers: [Player] { get }
|
|
|
|
|
|
|
|
var publicInfo: PublicTableInfo { get }
|
|
|
|
|
|
|
|
func tableInfo(forPlayer player: PlayerName) -> TableInfo
|
|
|
|
|
|
|
|
func perform(action: PlayerAction, forPlayer: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?)
|
|
|
|
|
|
|
|
func play(card: Card, player name: PlayerName) -> (result: PlayerActionResult, table: ManageableTable?)
|
|
|
|
|
|
|
|
func connect(player name: PlayerName, using socket: WebSocket) -> Bool
|
|
|
|
|
|
|
|
func disconnect(player name: PlayerName)
|
|
|
|
|
|
|
|
func sendUpdateToAllPlayers()
|
2022-01-24 17:15:11 +01:00
|
|
|
|
|
|
|
func disconnectAllPlayers()
|
2021-12-18 15:08:43 +01:00
|
|
|
}
|
2023-02-01 16:44:07 +01:00
|
|
|
|
|
|
|
extension ManageableTable {
|
|
|
|
|
|
|
|
var numberOfConnectedPlayers: Int {
|
|
|
|
allPlayers.count { $0.isConnected }
|
|
|
|
}
|
|
|
|
|
|
|
|
var playerCount: Int {
|
|
|
|
allPlayers.count
|
|
|
|
}
|
|
|
|
}
|