diff options
author | Kyle Gunger <corechg@gmail.com> | 2020-09-15 20:03:52 -0400 |
---|---|---|
committer | Kyle Gunger <corechg@gmail.com> | 2020-09-15 20:03:52 -0400 |
commit | 2ce432034eb35f763182de03fb7b42d2a07afc4b (patch) | |
tree | e57d7bc40d12c32c79f1f16ba669a5426ae80525 /webcards/scripts/gui/table.js | |
parent | 20201f77b5cf5cbb1c70b1cc51c4108d620a3202 (diff) |
Webcards update from local git server
Diffstat (limited to 'webcards/scripts/gui/table.js')
-rw-r--r-- | webcards/scripts/gui/table.js | 75 |
1 files changed, 61 insertions, 14 deletions
diff --git a/webcards/scripts/gui/table.js b/webcards/scripts/gui/table.js index 2776f80..c4878a0 100644 --- a/webcards/scripts/gui/table.js +++ b/webcards/scripts/gui/table.js @@ -1,32 +1,79 @@ // Table represents and manages the actual game. It accepts inputs from the server and tries to query the server when the player makes a move. -function Table(el, soc) { - this.root = el; - this.soc = soc; -} +class Table{ + constructor(e, drag, socket) { + this.root = e; + this.drag = drag; + + this.root.addEventListener("mouseup", drag.stopDraggingAll.bind(drag)); + + //drag.addEventListener("dragstop", ); + + this.socket = socket; + + this.decks = []; + } -Table.prototype = { - - openTable: function(){ + openTable () + { let state = this.root.getAttribute("state") if((state == "close" || state == "closed") && state != "") { this.root.setAttribute("state", "closed"); setTimeout(this.root.setAttribute.bind(this.root), 50, "state", "open"); } - }, + } - closeTable: function(){ + closeTable () + { let state = this.root.getAttribute("state") if(state != "close" && state != "closed") { this.root.setAttribute("state", ""); setTimeout(this.root.setAttribute.bind(this.root), 50, "state", "close"); } - }, + } - handleClose: function() { + handleClose () + { this.reset(); - }, + } + + reset () + { + while(this.root.firstElementChild != null) + this.root.firstElementChild.remove(); + + this.decks = []; - reset: function() { this.closeTable(); + this.drag.stopDraggingAll(); } -}
\ No newline at end of file + + /* Deck and card functions */ + newDeck(options) + { + var d = new Deck(options); + this.decks.push(d); + this.root.appendChild(d.e); + } + + newCard(data, deck = 0) + { + var c = new Card(data); + this.decks[deck].appendCard(c); + this.drag.addTarget(c.e); + } + + checkDeck(x, y) + { + for(let d of this.decks) + { + if(d.isInside(x, y)) + return true; + } + return false; + } + + dragCheck(cap) + { + console.log(cap); + } +} |