summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/client.js2
-rw-r--r--scripts/gui/input.js13
-rw-r--r--scripts/gui/lobby.js28
-rw-r--r--scripts/gui/table.js2
4 files changed, 25 insertions, 20 deletions
diff --git a/scripts/client.js b/scripts/client.js
index dba8630..e158cef 100644
--- a/scripts/client.js
+++ b/scripts/client.js
@@ -115,6 +115,8 @@ class Client{
this.gameOptions.cleanup();
this.settings = new Settings(m.data.user);
+ this.settings.addEventListener("change", (() => {this.socket.send("options", this.settings.getSettings())}).bind(this));
+
this.gameOptions = new Settings(m.data.game);
this.gameOptions.putSettings(this.lobby.top.newGame);
diff --git a/scripts/gui/input.js b/scripts/gui/input.js
index da19d95..24450f0 100644
--- a/scripts/gui/input.js
+++ b/scripts/gui/input.js
@@ -48,6 +48,13 @@ class MakeInput {
return el;
}
+ static buttonInput (text)
+ {
+ let el = MakeInput.createInput("button", false, false);
+ el.textContent = text;
+ return el;
+ }
+
static passwordInput (value, placeholder)
{
let el = MakeInput.createInput("password");
@@ -302,8 +309,10 @@ class Settings extends EventTarget {
applyEvents (template) {
for(let key in template)
{
- if(typeof MakeInput[template[key].type+"Input"] != null)
- this.settings[key].el.onchange = (function () {this.dispatchEvent(new CustomEvent("change"));}).bind(this);
+ if (template[key].type == "button")
+ this.settings[key].el.onclick = (function() {this.dispatchEvent(new CustomEvent("click", {detail: key}))}).bind(this);
+ else if(typeof MakeInput[template[key].type+"Input"] != null)
+ this.settings[key].el.onchange = (function () {this.dispatchEvent(new CustomEvent("change", {detail: key}));}).bind(this);
}
}
diff --git a/scripts/gui/lobby.js b/scripts/gui/lobby.js
index c625420..34fa9a7 100644
--- a/scripts/gui/lobby.js
+++ b/scripts/gui/lobby.js
@@ -1,6 +1,6 @@
'use strict';
-const LOBBY_RPC = ["packList", "gameList", "players", "addGame", "deleteGame"]
+const LOBBY_RPC = ["gameList", "stats", "addGame", "deleteGame"]
// ###############
// # TopBar Code #
@@ -54,7 +54,7 @@ class TopBar{
// Game represents a single game in the lobby view. It has methods for setting up the elements and such.
class Game {
- constructor(options = {id: 0, name: "", packs: [], pass: false}, el)
+ constructor(options = {id: "", name: "", packs: 0, pass: false}, el)
{
this.getName = () => {
return options.name;
@@ -83,12 +83,12 @@ class Game {
e.appendChild(pid);
// Join/password
- let jap = document.createElement("div");
+ let joindiv = document.createElement("div");
let join = document.createElement("button");
join.textContent = "Join";
join.addEventListener("click", game.joinGame.bind(game, options.id));
- jap.appendChild(join);
+ joindiv.appendChild(join);
this.getPass = () => {
return "";
@@ -96,11 +96,11 @@ class Game {
if(options.pass) {
let pass = MakeInput.passwordInput("", "Game password");
- jap.appendChild(pass);
+ joindiv.appendChild(pass);
this.getPass = pass.getValue.bind(pass);
}
- e.appendChild(jap);
+ e.appendChild(joindiv);
el.appendChild(e);
this.remove = function () {
@@ -145,17 +145,9 @@ class Lobby {
this.packs = [];
}
- // Set initial pack list
- // {data array} array of strings representing pack names
- packList (data) {
- this.packs = data;
- this.top.setPacks(this.packs)
- this.e.stats.packs.innerText = this.packs.length();
- }
-
// Set initial game list.
// { data object } object containing {games} and {name}
- // { data.name string } name of the game the server runs
+ // { data.game string } name of the game the server runs
// { data.games array } array of public games the server is running
// { data.games[n].name } room name
// { data.games[n].packs } number of extra packs used by this game
@@ -175,7 +167,8 @@ class Lobby {
}
}
- this.e.stats.game.innerText = data.name;
+ this.e.stats.game.innerText = data.game;
+ this.e.stats.packs.innerText = data.packs;
this.e.stats.pubgame.innerText = this.games.length();
}
@@ -183,9 +176,10 @@ class Lobby {
// { data object } player statistics from the server
// { data.online number } players on server
// { data.ingame number } players on server and in game
- players (data) {
+ stats (data) {
this.e.stats.online.innerText = data.online;
this.e.stats.ingame.innerText = data.ingame;
+ this.e.stats.pubgame.innerText = data.pubgame;
}
// Called when a new public game is created on the server
diff --git a/scripts/gui/table.js b/scripts/gui/table.js
index e4d6770..87120e3 100644
--- a/scripts/gui/table.js
+++ b/scripts/gui/table.js
@@ -150,7 +150,7 @@ class Table{
// Function to query the server about a player's move
checkMove(cardID, deckID, index = -1)
{
- this.socket.send("game", {type: "move", card: cardID, deck: deckID, pos: index});
+ this.socket.send("move", {card: cardID, deck: deckID, index: index});
}