From 7c999e0dfdc56cc21ee92696472736261aa39b7e Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 12 Oct 2017 03:39:38 -0400 Subject: [PATCH] Allow for tap to "flip" cards with two states --- js/playfield.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/js/playfield.js b/js/playfield.js index 6a657c4..6051de7 100644 --- a/js/playfield.js +++ b/js/playfield.js @@ -58,6 +58,30 @@ let cardInteract = interact('.card', {ignoreFrom: '.in-list'}) let scale = parseFloat(event.target.getAttribute('data-scale')) === 2 ? 1 : 2; event.target.setAttribute('data-scale', scale); dragMoveListener({target: event.target, dx: 0, dy: 0}); + }) + .on('tap', event => { + let card = event.target; + let cardNum = parseInt(card.getAttribute('data-num')); + if (card.dataset.flipped === "true") { + card.dataset.flipped = false; + let style = window.getComputedStyle(card); + card.style.backgroundPositionX = + -(cardNum % deckWidth) * parseInt(style.getPropertyValue("width")) + "px"; + card.style.backgroundPositionY = + -Math.floor(cardNum/deckWidth) * parseInt(style.getPropertyValue("height")) + "px"; + return; + } + + let cardData = deckJSON.ContainedObjects.find(c => c.CardID === (cardNum + deckNum * 100)); + let backNum = cardData.States && cardData.States["2"].CardID; + if (backNum) { + card.dataset.flipped = true; + let style = window.getComputedStyle(card); + card.style.backgroundPositionX = + -(backNum % deckWidth) * parseInt(style.getPropertyValue("width")) + "px"; + card.style.backgroundPositionY = + -Math.floor(backNum/deckWidth) * parseInt(style.getPropertyValue("height")) + "px"; + } }); interact('.card.in-list')