Set correct name when updating pile text

This commit is contained in:
Adam Goldsmith 2017-09-20 18:12:16 -04:00
parent 26849affc9
commit 345a86bfa6

View File

@ -58,18 +58,19 @@ interact('.card-pile')
.dropzone({ .dropzone({
accept: '.card', accept: '.card',
ondrop: event => { ondrop: event => {
let pile = piles[event.target.getAttribute('data-pile')]; let pileName = event.target.getAttribute('data-pile');
pile.push(event.relatedTarget.getAttribute('data-num')); piles[pileName].push(event.relatedTarget.getAttribute('data-num'));
event.relatedTarget.parentElement.removeChild(event.relatedTarget); event.relatedTarget.parentElement.removeChild(event.relatedTarget);
// update deck text // update deck text
event.target.innerHTML = `DECK<br>${pile.length}/${cardCount}`; event.target.innerHTML = `${pileName.toUpperCase()}<br>${piles[pileName].length}/${cardCount}`;
} }
}) })
.draggable({manualStart: true}) .draggable({manualStart: true})
.on('move', event => { .on('move', event => {
let interaction = event.interaction; let interaction = event.interaction;
let pile = piles[event.target.getAttribute('data-pile')]; let pileName = event.target.getAttribute('data-pile');
let pile = piles[pileName];
// if the pointer was moved while being held down // if the pointer was moved while being held down
// and an interaction hasn't started yet // and an interaction hasn't started yet
@ -92,7 +93,7 @@ interact('.card-pile')
document.querySelector("#card-container").appendChild(newCard); document.querySelector("#card-container").appendChild(newCard);
// update deck text // update deck text
event.target.innerHTML = `DECK<br>${pile.length}/${cardCount}`; event.target.innerHTML = `${pileName.toUpperCase()}<br>${pile.length}/${cardCount}`;
// start a drag interaction targeting the clone // start a drag interaction targeting the clone
interaction.start({name: 'drag'}, cardInteract, newCard); interaction.start({name: 'drag'}, cardInteract, newCard);