Display player state
This commit is contained in:
parent
1d1044c3f8
commit
9cc4cdb27c
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
const apiPath = "/schafkopf"
|
const apiPath = "/schafkopf"
|
||||||
|
|
||||||
|
var useEnglishTexts = false
|
||||||
|
|
||||||
function webSocketPath() {
|
function webSocketPath() {
|
||||||
const prefix = (window.location.protocol === "https:") ? "wss://" : "ws://"
|
const prefix = (window.location.protocol === "https:") ? "wss://" : "ws://"
|
||||||
return prefix + window.location.host + apiPath + "/session/start"
|
return prefix + window.location.host + apiPath + "/session/start"
|
||||||
@ -109,6 +111,53 @@ function convertJsonResponse(text) {
|
|||||||
if (text == "") {
|
if (text == "") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
console.log(text)
|
|
||||||
return JSON.parse(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
|
||||||
|
}
|
||||||
|
}
|
@ -290,25 +290,25 @@ function setInfoForPlayer(player, position, game) {
|
|||||||
if (player.hasOwnProperty("card")) {
|
if (player.hasOwnProperty("card")) {
|
||||||
card = player.card
|
card = player.card
|
||||||
}
|
}
|
||||||
const leadsGame = player.leads
|
|
||||||
const layer = player.position
|
const layer = player.position
|
||||||
setTableCard(position, card, layer)
|
setTableCard(position, card, layer)
|
||||||
setTablePlayerName(position, player.name, player.active)
|
setTablePlayerName(position, player.name, player.active)
|
||||||
if (!player.connected) {
|
// if (!player.connected) {
|
||||||
showPlayerDisconnected(position)
|
// showPlayerDisconnected(position)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
var state = []
|
var state = player.state
|
||||||
if (game != null && leadsGame) {
|
if (game != null && state.indexOf("selects") > -1) {
|
||||||
state.push(game)
|
const i = state.indexOf("selects")
|
||||||
|
state[i] = game
|
||||||
}
|
}
|
||||||
|
|
||||||
const double = doubleText(player.doubles)
|
// const double = doubleText(player.doubles)
|
||||||
if (double) {
|
// if (double) {
|
||||||
state.push(double)
|
// state.push(double)
|
||||||
}
|
// }
|
||||||
|
|
||||||
const text = state.join(", ")
|
const text = state.map(x => convertStateToString(x)).join("<br>")
|
||||||
showPlayerState(position, text)
|
showPlayerState(position, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,13 @@ var socket = null;
|
|||||||
var tableId = null;
|
var tableId = null;
|
||||||
var activePlayer = 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() {
|
function closeSocketIfNeeded() {
|
||||||
if (socket) {
|
if (socket) {
|
||||||
socket.close()
|
socket.close()
|
||||||
@ -217,7 +224,7 @@ function refreshTables() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function processTableList(tables) {
|
function processTableList(tables) {
|
||||||
var html = ""
|
var html = createTableRow
|
||||||
for (let i = 0, len = tables.length; i < len; i++) {
|
for (let i = 0, len = tables.length; i < len; i++) {
|
||||||
tableInfo = tables[i]
|
tableInfo = tables[i]
|
||||||
html += "<div class=\"table-row\">"
|
html += "<div class=\"table-row\">"
|
||||||
|
@ -114,8 +114,7 @@ final class TableManagement {
|
|||||||
guard let table = WaitingTable(oldTable: oldTable, removing: player.name) else {
|
guard let table = WaitingTable(oldTable: oldTable, removing: player.name) else {
|
||||||
tables[oldTable.id] = nil
|
tables[oldTable.id] = nil
|
||||||
return player.update(on: database).flatMap {
|
return player.update(on: database).flatMap {
|
||||||
print("Updating player")
|
Table.query(on: database).filter(\.$id == oldTable.id).delete()
|
||||||
return Table.query(on: database).filter(\.$id == oldTable.id).delete()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// `player.canStartGame` is automatically set to false, because table is not full
|
/// `player.canStartGame` is automatically set to false, because table is not full
|
||||||
|
@ -51,6 +51,9 @@ final class BiddingPlayer: CardHoldingPlayer {
|
|||||||
|
|
||||||
override var states: [PlayerState] {
|
override var states: [PlayerState] {
|
||||||
var states = super.states
|
var states = super.states
|
||||||
|
if selectsGame {
|
||||||
|
return states
|
||||||
|
}
|
||||||
if !isStillBidding {
|
if !isStillBidding {
|
||||||
states.append(.didFold)
|
states.append(.didFold)
|
||||||
} else if isNextActor {
|
} else if isNextActor {
|
||||||
|
@ -163,7 +163,6 @@ final class PlayingPlayer: CardHoldingPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var states: [PlayerState] {
|
override var states: [PlayerState] {
|
||||||
var states = super.states
|
|
||||||
if didPlayCalledAce {
|
if didPlayCalledAce {
|
||||||
states.append(.isCalled)
|
states.append(.isCalled)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user