From c9edb73751d20bb3c09b406895ca6982b455c9e4 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Sun, 17 Jul 2022 20:17:28 -0400 Subject: Some fixes --- scripts/cards/card.js | 6 +++++- scripts/cards/deck.js | 16 +++++++++++++--- scripts/cards/drag.js | 11 +++++++++-- scripts/client.js | 12 ++++++------ scripts/gui/table.js | 2 +- scripts/theme.js | 22 ++++++++++------------ 6 files changed, 44 insertions(+), 25 deletions(-) diff --git a/scripts/cards/card.js b/scripts/cards/card.js index 9223f14..3ca435c 100644 --- a/scripts/cards/card.js +++ b/scripts/cards/card.js @@ -7,13 +7,17 @@ const CardPos = ["top", "topl", "topr", "mid", "midt", "midb", "bot", "botl", "b // Every card should have a deck. // Use deck.appendCard, deck.prependCard, or deck.addCardAt to make a card visible class Card { - constructor (data) + constructor (id, data) { this.e = document.createElement("card"); this.generateElements(data); this.e.style.left = "0px"; this.e.style.top = "0px"; this.e.card = this; + + this.getID = function() { + return id; + } } // Generate a card with basic text only diff --git a/scripts/cards/deck.js b/scripts/cards/deck.js index 27020f0..941df8c 100644 --- a/scripts/cards/deck.js +++ b/scripts/cards/deck.js @@ -13,7 +13,7 @@ class Deck { y = 0; e = null; - constructor(options = {mode: "stack", smode: "one", sct: 0, pos: [0, 0]}) + constructor(id, options = {mode: "stack", smode: "one", sct: 0, pos: [0, 0]}) { // View mode // infdraw - infinite draw. always appears as if there are multiple cards @@ -54,6 +54,10 @@ class Deck { this.e.setAttribute("mode", options.mode); this.e.deck = this; + + this.getID = function() { + return id; + } } updatePos() @@ -91,8 +95,11 @@ class Deck { } else { let temp = this.cards.slice(0, index); temp[temp.length - 1].e.after(card.e); - temp.push(card); - this.cards.unshift(...temp); + this.cards.unshift(card); + + for(let i = temp.length - 1; i >= 0; i--) + this.cards.unshift(temp[i]); + this.updatePos(); } } @@ -108,6 +115,9 @@ class Deck { this.cards[index1 - 1].e.after(this.cards[index1]); this.cards[index2 - 1].e.after(this.cards[index2]); + + this.cards[index1].setPos(index1); + this.cards[index2].setPos(index2); } removeCard(index) diff --git a/scripts/cards/drag.js b/scripts/cards/drag.js index 1014656..b24ccb1 100644 --- a/scripts/cards/drag.js +++ b/scripts/cards/drag.js @@ -12,6 +12,9 @@ class MultiDrag extends EventTarget { window.addEventListener("mouseup", this.stopDraggingAll.bind(this)); document.body.addEventListener("mouseleave", this.stopDraggingAll.bind(this)); + //window.addEventListener("touchend", this.stopDraggingAll.bind(this)); + //window.addEventListener("touchcancel", this.stopDraggingAll.bind(this)); + this.ret = ret; } @@ -143,10 +146,14 @@ class MultiDrag extends EventTarget { } addTarget(e) { - e.addEventListener("mousedown", this.startDragging.bind(this)); + e.d1 = this.startDragging.bind(this); + //e.d2 = this.startTouchDrag.bind(this); + e.addEventListener("mousedown", e.d1); + //e.addEventListener("touchstart", e.d2); } removeTarget (e) { - e.removeEventListener("mousedown", this.startDragging.bind(this)); + e.removeEventListener("mousedown", e.d1); + e.removeEventListener("touchstart", e.d2); } } \ No newline at end of file diff --git a/scripts/client.js b/scripts/client.js index 21b3157..9ce9a07 100644 --- a/scripts/client.js +++ b/scripts/client.js @@ -48,9 +48,9 @@ class Client{ this.socket.addEventListener("error", this.socketError.bind(this)); this.socket.addEventListener("closed", this.socketClose.bind(this)); this.socket.addEventListener("handshake", this.handshake.bind(this)); - this.socket.addEventListener("menu", this.menu.bind(this)); - this.socket.addEventListener("game", this.game.bind(this)); - this.socket.addEventListener("chat", this.msg.bind(this)); + this.socket.addEventListener("menu", this.menuMsg.bind(this)); + this.socket.addEventListener("game", this.gameMsg.bind(this)); + this.socket.addEventListener("chat", this.chatMsg.bind(this)); this.lobby = new Lobby(document.getElementsByClassName("lobby")[0], this.socket); @@ -128,21 +128,21 @@ class Client{ } // Menu switch, called when in the lobby and a message arrives from the server - menu (e) + menuMsg (e) { let m = e.detail; this.lobby[m.type](m.data); } // Game switch, called when in game and a message arrives from the server - game (e) + gameMsg (e) { let m = e.detail; this.table[m.type](m.data); } // Callback when a chat event is recieved from the server - msg (e) + chatMsg (e) { let m = e.detail; this.chat[m.type](m.data); diff --git a/scripts/gui/table.js b/scripts/gui/table.js index ecdefd7..964f750 100644 --- a/scripts/gui/table.js +++ b/scripts/gui/table.js @@ -91,7 +91,7 @@ class Table{ delete this.cards[this.decks[id].cards[i].getID()]; this.decks[id].removeCard(i); } - //this.deck[] + delete this.deck[id]; } // Delete a card diff --git a/scripts/theme.js b/scripts/theme.js index 78f0149..73d31f7 100644 --- a/scripts/theme.js +++ b/scripts/theme.js @@ -9,13 +9,15 @@ const BASE_THEMES = [[ "Dark" ]]; +const APP_NAME = "WebCards"; + class Theme{ static theme = document.getElementById("theme"); static UserThemes = [[],[]]; static init() { - let uth = Cookies.getCookie("userThemes").split(','); + let uth = Cookies.getCookie("userThemes-" + APP_NAME).split(','); for (let i = 1; i < uth.length; i += 2) { @@ -23,25 +25,21 @@ class Theme{ this.UserThemes[1].push(uth[i]); } - if(Cookies.getCookie("theme") == ""){ - Cookies.setYearCookie("theme", "styles/themes/colors-base.css"); + if(Cookies.getCookie("theme-" + APP_NAME) == ""){ + Cookies.setYearCookie("theme-" + APP_NAME, BASE_THEMES[0][0]); } - } - static restore() - { - Theme.init(); - Theme.theme.setAttribute("href", Cookies.getCookie("theme") + "?v=" + Date.now()); + Theme.theme.setAttribute("href", Cookies.getCookie("theme-" + APP_NAME) + "?v=" + Date.now()); } static set(sheet) { - Cookies.setYearCookie("theme", sheet); + Cookies.setYearCookie("theme-" + APP_NAME, sheet); Theme.theme.setAttribute("href", sheet + "?v=" + Date.now()); } static get() { - return Cookies.getCookie("theme"); + return Cookies.getCookie("theme-" + APP_NAME); } static setUserThemes() { @@ -54,7 +52,7 @@ class Theme{ out = out + this.UserThemes[0][i] + "," + this.UserThemes[1][i]; } - Cookies.setYearCookie("userThemes", out); + Cookies.setYearCookie("userThemes-" + APP_NAME, out); } static removeUserTheme (index) { @@ -70,4 +68,4 @@ class Theme{ } } -Theme.restore(); \ No newline at end of file +Theme.init(); \ No newline at end of file -- cgit v1.2.3