From e1943317f2e346847c5a0df7f0bb8c5a23d859ce Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Tue, 30 Nov 2021 11:29:41 +0100 Subject: [PATCH] Add connection state to table info --- Sources/App/Model/{Table.swift => ClientInfos.swift} | 4 +++- Sources/App/Model/TableManagement.swift | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) rename Sources/App/Model/{Table.swift => ClientInfos.swift} (78%) diff --git a/Sources/App/Model/Table.swift b/Sources/App/Model/ClientInfos.swift similarity index 78% rename from Sources/App/Model/Table.swift rename to Sources/App/Model/ClientInfos.swift index 6652d08..f396f82 100644 --- a/Sources/App/Model/Table.swift +++ b/Sources/App/Model/ClientInfos.swift @@ -6,7 +6,9 @@ struct TableInfo: Codable { let name: String - var players: [String] + var players: [PlayerName] + + var connected: [Bool] } extension TableInfo: Comparable { diff --git a/Sources/App/Model/TableManagement.swift b/Sources/App/Model/TableManagement.swift index 761d240..00ad2f3 100644 --- a/Sources/App/Model/TableManagement.swift +++ b/Sources/App/Model/TableManagement.swift @@ -48,7 +48,13 @@ final class TableManagement { func getPublicTableInfos() -> [TableInfo] { publicTables.map { tableId in - TableInfo(id: tableId, name: tableNames[tableId]!, players: tablePlayers[tableId]!) + let players = tablePlayers[tableId]! + let connected = players.map { playerConnections[$0] != nil } + return TableInfo( + id: tableId, + name: tableNames[tableId]!, + players: players, + connected: connected) }.sorted() }