added all functionality

This commit is contained in:
bluesaxman 2020-05-20 10:20:41 -06:00
parent ea37f2f436
commit 49eedf8442

View File

@ -8,6 +8,21 @@
Welcome to Deckcard
</body>
<script>
window.deck = [];
window.hand = [];
function updateEvent() {
window.UI.deck.innerHTML = "";
window.UI.hand.innerHTML = "";
var theDeck = elementPlace("#deck","deckDisp",null,"div");
theDeck.innerHTML = "<div>"+window.deck.length+"</div>";
window.hand.forEach(function (card) {
var currentCard = elementPlace("#hand",null,"card","li");
currentCard.innerText = card;
});
}
function generateDeck(DDF) {
var cards = [""];
for (var attribute in DDF) {
@ -22,25 +37,46 @@ function generateDeck(DDF) {
return cards;
}
var menu = elementPlace("body","menu",null,"div");
function shuffleDeck(deck) {
deck.forEach(function (card,index) {
var swapCardIndex = Math.floor( Math.random() * deck.length );
var swapCard = deck[swapCardIndex];
deck[swapCardIndex] = card;
deck[index] = swapCard;
});
}
elementPlace("body","menu",null,"div");
buttonAdd("#menu","upload","Upload Deck", function () {
popupDialog("deckLoader","Select Deck definition File",true,inputDialog,{"inputType":"file"},function (f) {
var myFile = new FileReader();
myFile.onload = function (file) {
// Probably validate the file somehow befor eating it
window.deck = generateDeck(JSON.parse(file.target.result));
window.hand = [];
updateEvent();
}
myFile.readAsText(f[0]);
})
},null,"div");
buttonAdd("#menu","shuffle", "Shuffle Deck", function () {
console.log("clicked shuffle");
shuffleDeck(window.deck);
}, null, "div");
buttonAdd("#menu","shuffleAll", "Shuffle Whole Deck", function () {
console.log("clicked shuffle all");
window.deck = window.deck.concat(window.hand);
window.hand = [];
shuffleDeck(window.deck);
updateEvent();
}, null, "div");
buttonAdd("#menu","draw", "Draw Card", function () {
console.log("clicked draw");
if (window.deck.length > 0) {
window.hand.unshift(window.deck.shift());
updateEvent();
}
}, null, "div");
var display = elementPlace("body","display",null,"div");
elementPlace("body","display",null,"div");
window.UI = {};
window.UI.deck = elementPlace("#display","deck",null,"div");
window.UI.hand = elementPlace("#display","hand",null,"ol");
</script>
</html>