From 81b562233188569b66fc2fb2a7ff952bdae0a4ec Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Thu, 28 Jul 2022 01:32:49 -0400 Subject: Sending user options to the server --- scripts/gui/input.js | 13 +++++++++++-- scripts/gui/lobby.js | 28 +++++++++++----------------- scripts/gui/table.js | 2 +- 3 files changed, 23 insertions(+), 20 deletions(-) (limited to 'scripts/gui') 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}); } -- cgit v1.2.3