Mixing decks implemented
This commit is contained in:
parent
9b23be4bbb
commit
da8341f08b
@ -25,6 +25,3 @@ A more advanced example uses an array of "decks" to build a single deck.
|
||||
"joker":["joker"]
|
||||
}]
|
||||
```
|
||||
|
||||
Things not yet supported:
|
||||
* Mixing decks
|
31
index.html
31
index.html
@ -48,6 +48,16 @@ function shuffleDeck(deck) {
|
||||
});
|
||||
}
|
||||
|
||||
function deckFromJSON(ourFile) {
|
||||
if ( Array.isArray(ourFile) ) {
|
||||
ourFile.forEach(function (deck) {
|
||||
window.deck = window.deck.concat(generateDeck(deck));
|
||||
});
|
||||
} else {
|
||||
window.deck = window.deck.concat(generateDeck(ourFile));
|
||||
}
|
||||
}
|
||||
|
||||
elementPlace("body","menu",null,"div");
|
||||
buttonAdd("#menu","upload","Upload Deck", function () {
|
||||
popupDialog("deckLoader","Select Deck definition File",true,inputDialog,{"inputType":"file"},function (f) {
|
||||
@ -55,19 +65,24 @@ buttonAdd("#menu","upload","Upload Deck", function () {
|
||||
myFile.onload = function (file) {
|
||||
// Probably validate the file somehow befor eating it
|
||||
var ourFile = JSON.parse(file.target.result);
|
||||
if ( Array.isArray(ourFile) ) {
|
||||
window.deck = [];
|
||||
ourFile.forEach(function (deck) {
|
||||
window.deck = window.deck.concat(generateDeck(deck));
|
||||
});
|
||||
} else {
|
||||
window.deck = generateDeck(JSON.parse(file.target.result));
|
||||
}
|
||||
deckFromJSON(ourFile);
|
||||
window.hand = [];
|
||||
updateEvent();
|
||||
}
|
||||
myFile.readAsText(f[0]);
|
||||
})
|
||||
});
|
||||
},null,"div");
|
||||
buttonAdd("#menu","add","Add Deck", function () {
|
||||
popupDialog("deckLoader","Select Deck definition to add",true,inputDialog,{"inputType":"file"},function (f) {
|
||||
var myFile = new FileReader();
|
||||
myFile.onload = function (file) {
|
||||
var ourFile = JSON.parse(file.target.result);
|
||||
deckFromJSON(ourFile);
|
||||
updateEvent();
|
||||
}
|
||||
myFile.readAsText(f[0]);
|
||||
});
|
||||
}, null, "div");
|
||||
buttonAdd("#menu","shuffle", "Shuffle Deck", function () {
|
||||
shuffleDeck(window.deck);
|
||||
|
Loading…
x
Reference in New Issue
Block a user