summaryrefslogtreecommitdiff
path: root/scripts/cards
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-07-17 20:17:28 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-07-17 20:17:28 -0400
commitc9edb73751d20bb3c09b406895ca6982b455c9e4 (patch)
treec6cca364d2612db9bda4776ea19d8856fa29c92d /scripts/cards
parent0e010b53fbaa243760f5aabd8ad5ed85c87243fd (diff)
Some fixes
Diffstat (limited to 'scripts/cards')
-rw-r--r--scripts/cards/card.js6
-rw-r--r--scripts/cards/deck.js16
-rw-r--r--scripts/cards/drag.js11
3 files changed, 27 insertions, 6 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