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"]
|
"joker":["joker"]
|
||||||
}]
|
}]
|
||||||
```
|
```
|
||||||
|
|
||||||
Things not yet supported:
|
|
||||||
* Mixing decks
|
|
33
index.html
33
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");
|
elementPlace("body","menu",null,"div");
|
||||||
buttonAdd("#menu","upload","Upload Deck", function () {
|
buttonAdd("#menu","upload","Upload Deck", function () {
|
||||||
popupDialog("deckLoader","Select Deck definition File",true,inputDialog,{"inputType":"file"},function (f) {
|
popupDialog("deckLoader","Select Deck definition File",true,inputDialog,{"inputType":"file"},function (f) {
|
||||||
@ -55,20 +65,25 @@ buttonAdd("#menu","upload","Upload Deck", function () {
|
|||||||
myFile.onload = function (file) {
|
myFile.onload = function (file) {
|
||||||
// Probably validate the file somehow befor eating it
|
// Probably validate the file somehow befor eating it
|
||||||
var ourFile = JSON.parse(file.target.result);
|
var ourFile = JSON.parse(file.target.result);
|
||||||
if ( Array.isArray(ourFile) ) {
|
window.deck = [];
|
||||||
window.deck = [];
|
deckFromJSON(ourFile);
|
||||||
ourFile.forEach(function (deck) {
|
|
||||||
window.deck = window.deck.concat(generateDeck(deck));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
window.deck = generateDeck(JSON.parse(file.target.result));
|
|
||||||
}
|
|
||||||
window.hand = [];
|
window.hand = [];
|
||||||
updateEvent();
|
updateEvent();
|
||||||
}
|
}
|
||||||
myFile.readAsText(f[0]);
|
myFile.readAsText(f[0]);
|
||||||
})
|
});
|
||||||
},null,"div");
|
},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 () {
|
buttonAdd("#menu","shuffle", "Shuffle Deck", function () {
|
||||||
shuffleDeck(window.deck);
|
shuffleDeck(window.deck);
|
||||||
}, null, "div");
|
}, null, "div");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user