Display player state

This commit is contained in:
Christoph Hagen 2021-12-25 16:53:58 +01:00
parent 1d1044c3f8
commit 9cc4cdb27c
6 changed files with 75 additions and 18 deletions

View File

@ -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
}
}

View File

@ -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("<br>")
showPlayerState(position, text)
}

View File

@ -4,6 +4,13 @@ var socket = null;
var tableId = null;
var activePlayer = null;
const createTableRow = '<div class="table-row">'
+ '<button class="table-join-btn" onclick="createTable()">Create</button>'
+ '<input type="text" id="table-name-field" name="tablename" placeholder="Create new table..." required>'
+ '<input type="checkbox" id="table-public-checkbox" name="public-table" checked="checked">'
+ '<span id="table-public-label">Public</span>'
+ '</div>'
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 += "<div class=\"table-row\">"

View File

@ -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

View File

@ -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 {

View File

@ -163,7 +163,6 @@ final class PlayingPlayer: CardHoldingPlayer {
}
override var states: [PlayerState] {
var states = super.states
if didPlayCalledAce {
states.append(.isCalled)
}