From fcf01353f94b11b8ca6db8ead14d2ec89a0275f4 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Mon, 15 Feb 2021 14:55:16 -0500 Subject: Get on track for moving cards around --- scripts/cards/deck.js | 24 ++++++++++++++++++++++++ scripts/client.js | 31 ++++++++++++++++++++++++++++--- scripts/gui/chat.js | 17 +++++++++++++---- scripts/gui/table.js | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 98 insertions(+), 8 deletions(-) diff --git a/scripts/cards/deck.js b/scripts/cards/deck.js index dcfa1e9..4800e54 100644 --- a/scripts/cards/deck.js +++ b/scripts/cards/deck.js @@ -46,8 +46,11 @@ class Deck { this.sct = options.sct > 0 ? options.sct : 0; this.e = document.createElement("deck"); + + // x and y values are on a scale from 0 to 1, 0 being top left, 1 being bottom right. this.e.style.setProperty("--x", options.pos[0]); this.e.style.setProperty("--y", options.pos[1]); + this.e.setAttribute("mode", options.mode); this.getID = function() { @@ -121,6 +124,17 @@ class Deck { return c; } + removeCardByID(id) + { + for(let i in this.cards) + { + if(this.cards[i].getID() == id) + return this.removeCard(i); + } + + return null; + } + removeFront() { return this.removeCard(this.cards.length - 1); @@ -151,4 +165,14 @@ class Deck { } return null; } + + hasCard(id) + { + for(let c of this.cards) + { + if(c.getID() === id) + return c; + } + return null; + } } diff --git a/scripts/client.js b/scripts/client.js index 904e299..7f98c7b 100644 --- a/scripts/client.js +++ b/scripts/client.js @@ -1,7 +1,7 @@ 'use strict'; const VERSION = "1.0.0"; -const DefaultSettings = { +const DefaultUserOps = { a: { type: "color", title: "Player Color", @@ -24,6 +24,24 @@ const DefaultSettings = { } } +const DefaultGameOps = { + a: { + type: "checkbox", + title: "Unlisted", + args: [] + }, + b: { + type: "checkbox", + title: "Use Password", + args: [] + }, + c: { + type: "text", + title: "Set Password", + args: [Math.floor(Math.random() * 10000), ""] + } +} + // Client acts as the message hub for the whole game. // WebSocket messages come into Client and Client redirects them to the lobby or table based on the state of the game. // Client also performs the handshake for first starting the connection and messages everyone if the connection errors or closes. @@ -48,9 +66,12 @@ class Client{ this.chat.addChannel("global"); this.chat.switchChannel("global"); - this.settings = new Settings(DefaultSettings); + this.settings = new Settings(DefaultUserOps); this.settings.putSettings(this.lobby.e.settings); + this.gameOptions = new Settings(DefaultGameOps); + this.gameOptions.putSettings(this.lobby.top.newGame); + this.game = game; } @@ -89,8 +110,12 @@ class Client{ case "ready": this.settings.cleanup(); + this.gameOptions.cleanup(); - this.settings = new Settings(m.data); + this.settings = new Settings(m.data.user); + this.gameOptions = new Settings(m.data.game); + + this.gameOptions.putSettings(this.lobby.top.newGame); if(this.lobby.top.mobileSettingsOpen()) this.settings.putSettings(this.lobby.top.mobileSettings); diff --git a/scripts/gui/chat.js b/scripts/gui/chat.js index 68b8f5d..fa4b88d 100644 --- a/scripts/gui/chat.js +++ b/scripts/gui/chat.js @@ -101,11 +101,20 @@ class Chat { let autoscroll = c.e.scrollTop == c.e.scrollTopMax; - let csp = document.createElement("span"); - csp.style.color = msg.color; - csp.innerText = msg.user + ": "; + let csp = document.createElement("span") let tsp = document.createElement("span"); - tsp.innerText = msg.text; + + if(msg.server === true){ + csp.style.color = "white"; + csp.style.backgroundColor = "black"; + csp.innerText = "[SERVER]"; + tsp.innerText = " " + msg.text; + } else { + csp.style.color = msg.color; + csp.innerText = msg.user + ": "; + tsp.innerText = msg.text; + } + let d = document.createElement("div"); d.appendChild(csp); d.appendChild(tsp); diff --git a/scripts/gui/table.js b/scripts/gui/table.js index 8fc1ea0..0d21262 100644 --- a/scripts/gui/table.js +++ b/scripts/gui/table.js @@ -83,6 +83,38 @@ class Table{ return null; } + moveCard(card, newDeck) + { + for(let d of this.decks) + { + if (d.removeCardByID(card.getID()) !== null) + break; + } + card.resetPos(); + newDeck.appendCard(card); + } + + moveByID(cardID, deckID) + { + let card, deck; + for(let d of this.decks) + { + let c = d.hasCard(cardID) + if(c !== null) + card = c; + + if(d.getID() == deckID) + deck = d; + } + + this.moveCard(card, deck); + } + + checkMove(cardID, deckID) + { + this.socket.send("game", {}); + } + dragCheck(cap) { console.log(cap); @@ -99,7 +131,7 @@ class Table{ if(c !== null) { if(d !== null) - console.log({card: c.getID(), deck: d.getID()}); + this.moveCard(c, d); else c.resetPos(); } -- cgit v1.2.3