From 9cc4cdb27cbfcd7c496c9cb0eae0e7d220587065 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Sat, 25 Dec 2021 16:53:58 +0100 Subject: [PATCH] Display player state --- Public/api.js | 51 ++++++++++++++++++- Public/elements.js | 26 +++++----- Public/game.js | 9 +++- Sources/App/Management/TableManagement.swift | 3 +- Sources/App/Model/Players/BiddingPlayer.swift | 3 ++ Sources/App/Model/Players/PlayingPlayer.swift | 1 - 6 files changed, 75 insertions(+), 18 deletions(-) diff --git a/Public/api.js b/Public/api.js index 457a647..16432c4 100644 --- a/Public/api.js +++ b/Public/api.js @@ -4,6 +4,8 @@ const apiPath = "/schafkopf" +var useEnglishTexts = false + function webSocketPath() { const prefix = (window.location.protocol === "https:") ? "wss://" : "ws://" return prefix + window.location.host + apiPath + "/session/start" @@ -109,6 +111,53 @@ function convertJsonResponse(text) { if (text == "") { return null; } - console.log(text) return JSON.parse(text); } + +// The state identifiers for all player states +const stateCanDouble = "canDouble" +const stateDidDouble = "doubled" +const stateIsDisconnected = "offline" +const stateMustBid = "bidder" +const stateDidFold = "fold" +const stateDidBid = "bid" +const stateIsGameSelector = "selects" +const stateIsWeddingOfferer = "wedding" +const stateIsCalled = "called" +const stateDidRaise = "raised" +const stateLeadsGame = "leads" +const stateIsWinner = "winner" +const stateIsLooser = "looser" + +function convertStateToString(state) { + switch (state) { + case stateCanDouble: + return useEnglishTexts ? "Can double" : "Kann legen" + case stateDidDouble: + return useEnglishTexts ? "Doubled" : "Leger" + case stateIsDisconnected: + return useEnglishTexts ? "Disconnected" : "Abwesend" + case stateMustBid: + return useEnglishTexts ? "Must bid": "Muss ansagen" + case stateDidFold: + return useEnglishTexts ? "Fold" : "Weg" + case stateDidBid: + return useEnglishTexts ? "Wants to play" : "Spielt" + case stateIsGameSelector: + return useEnglishTexts ? "Selects game" : "Wählt Spiel" + case stateIsWeddingOfferer: + return useEnglishTexts ? "Offers wedding" : "Hochzeit" + case stateIsCalled: + return useEnglishTexts ? "Called" : "Gerufen" + case stateDidRaise: + return useEnglishTexts ? "Raised" : "Schuss" + case stateLeadsGame: + return useEnglishTexts ? "Player" : "Spieler" + case stateIsWinner: + return useEnglishTexts ? "Winner" : "Hat gewonnen" + case stateIsLooser: + return useEnglishTexts ? "Looser" : "Hat verloren" + default: + return state + } +} \ No newline at end of file diff --git a/Public/elements.js b/Public/elements.js index 420214b..8c0dbe6 100644 --- a/Public/elements.js +++ b/Public/elements.js @@ -290,25 +290,25 @@ function setInfoForPlayer(player, position, game) { if (player.hasOwnProperty("card")) { card = player.card } - const leadsGame = player.leads const layer = player.position setTableCard(position, card, layer) setTablePlayerName(position, player.name, player.active) - if (!player.connected) { - showPlayerDisconnected(position) - return - } - var state = [] - if (game != null && leadsGame) { - state.push(game) + // if (!player.connected) { + // showPlayerDisconnected(position) + // return + // } + var state = player.state + if (game != null && state.indexOf("selects") > -1) { + const i = state.indexOf("selects") + state[i] = game } - const double = doubleText(player.doubles) - if (double) { - state.push(double) - } + // const double = doubleText(player.doubles) + // if (double) { + // state.push(double) + // } - const text = state.join(", ") + const text = state.map(x => convertStateToString(x)).join("
") showPlayerState(position, text) } diff --git a/Public/game.js b/Public/game.js index 721362a..ddace46 100644 --- a/Public/game.js +++ b/Public/game.js @@ -4,6 +4,13 @@ var socket = null; var tableId = null; var activePlayer = null; +const createTableRow = '
' ++ '' ++ '' ++ '' ++ 'Public' ++ '
' + function closeSocketIfNeeded() { if (socket) { socket.close() @@ -217,7 +224,7 @@ function refreshTables() { } function processTableList(tables) { - var html = "" + var html = createTableRow for (let i = 0, len = tables.length; i < len; i++) { tableInfo = tables[i] html += "
" diff --git a/Sources/App/Management/TableManagement.swift b/Sources/App/Management/TableManagement.swift index 15aaf13..aefea8e 100644 --- a/Sources/App/Management/TableManagement.swift +++ b/Sources/App/Management/TableManagement.swift @@ -114,8 +114,7 @@ final class TableManagement { guard let table = WaitingTable(oldTable: oldTable, removing: player.name) else { tables[oldTable.id] = nil return player.update(on: database).flatMap { - print("Updating player") - return Table.query(on: database).filter(\.$id == oldTable.id).delete() + Table.query(on: database).filter(\.$id == oldTable.id).delete() } } /// `player.canStartGame` is automatically set to false, because table is not full diff --git a/Sources/App/Model/Players/BiddingPlayer.swift b/Sources/App/Model/Players/BiddingPlayer.swift index b2feef3..f714104 100644 --- a/Sources/App/Model/Players/BiddingPlayer.swift +++ b/Sources/App/Model/Players/BiddingPlayer.swift @@ -51,6 +51,9 @@ final class BiddingPlayer: CardHoldingPlayer { override var states: [PlayerState] { var states = super.states + if selectsGame { + return states + } if !isStillBidding { states.append(.didFold) } else if isNextActor { diff --git a/Sources/App/Model/Players/PlayingPlayer.swift b/Sources/App/Model/Players/PlayingPlayer.swift index 9ca947d..e1e9bca 100644 --- a/Sources/App/Model/Players/PlayingPlayer.swift +++ b/Sources/App/Model/Players/PlayingPlayer.swift @@ -163,7 +163,6 @@ final class PlayingPlayer: CardHoldingPlayer { } override var states: [PlayerState] { - var states = super.states if didPlayCalledAce { states.append(.isCalled) }