From 87ce9d1c162ac9606a9b4d817a5f3b486889a46f Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Thu, 27 Feb 2020 18:06:56 -0500 Subject: Initialize Client repo with predone work --- scripts/client/lobby.js | 102 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 scripts/client/lobby.js (limited to 'scripts/client/lobby.js') diff --git a/scripts/client/lobby.js b/scripts/client/lobby.js new file mode 100644 index 0000000..8d46352 --- /dev/null +++ b/scripts/client/lobby.js @@ -0,0 +1,102 @@ +// Lobby manages the players and games provided by the server and allows users to join or create their own games. +function Lobby(el){ + this.root = el; + + this.elements = { + status: this.root.getElementsByClassName("status")[0], + addr: this.root.getElementsByClassName("addr")[0], + + stats: { + game: document.getElementById("game"), + packs: document.getElementById("packs"), + online: document.getElementById("online"), + ingame: document.getElementById("ingame"), + pubgame: document.getElementById("pubgame") + }, + + settings: { + name: document.getElementById("name"), + color: document.getElementById("usercolor") + } + }; + + this.top = new TopBar(document.getElementsByClassName("topbar")[0]); + + this.init = false; + this.online = []; + this.games = []; + this.packs = []; + this.players = []; +} + +Lobby.prototype = { + packList: function(data){ + + this.elements.stats.packs.innerText = this.packs.length(); + }, + + gameList: function(data, game){ + + this.elements.stats.pubgame.innerText = this.games.length(); + }, + + players: function(data) { + + this.elements.stats.online.innerText = this.players.length(); + this.init = true; + }, + + addGame: function(data){ + + }, + + removeGame: function(data){ + + }, + + addPlayer: function(data){ + + }, + + movePlayer: function(data){ + + }, + + removePlayer: function(data){ + + }, + + newGameScreen: function(){ + if(this.init) return; + }, + + setState: function(text, color, server){ + this.elements.status.style.backgroundColor = color; + this.elements.status.innerText = text; + this.elements.addr.innerText = server; + this.top.setColor(color); + }, + + reset: function(){ + this.setState("Connecting", "#DA0", this.elements.addr.innerText); + this.init = false; + } +}; + +// ############### +// # TopBar Code # +// ############### + +function TopBar(el) { + this.root = el; + + this.newGame = el.getElementsByClassName("new-game")[0]; + this.mobileSettings = el.getElementsByClassName("mobile-settings")[0]; + this.status = el.getElementsByClassName("status")[0]; +} + +TopBar.prototype = { + setColor: function(color) { + this.status.style.backgroundColor = color; + } +}; -- cgit v1.2.3