Topic: Inventory Draft
Inventory Draft is a JavaScript program you can copy and run in your browser.
EDIT: Visual guide: http://imgur.com/a/dbNaz#0
EDIT: You can now generate pauper drafts!
EDIT: You can now generate rares-only drafts!
EDIT: You can now specify how many of each rarity you want per pack!
How to "install"
Copy all of the code below
Open your favorite text editor (e.g. Notepad, Wordpad, GEdit, etc.)
Paste the code you copied into the editor
Save the file as "InventoryDraft.html" wherever you want on your computer
Open the file in your browser (e.g. right-click -> Open with Chrome)
In Deckbox, click inventory, hover over View and Hit Export
Make sure you select Rarity and Image URL options
How to run
Choose the number of players you want to generate packs for. There are 15 cards per pack and 3 packs per player.
Upload your CSV file you saved from Deckbox.
As soon as the file is chosen, the packs are created and displayed.
If you do not like what was picked, refresh the page and repeat the steps.
How to save
Once you have found a configuration you like, you may wish to save the file because it was randomly generated and cannot be reproduced
Right-click the page in your browser and select "Save As"
Name the file whatever you wish but make sure the file extension is ".html"
Here's the code:
<!DOCTYPE HTML>
<html>
<head>
<title>Inventory Draft</title>
<script src="InventoryDraft.js" ></script>
</head>
<body>
<p><a href="http://deckbox.org/forum/viewtopic.php?id=9790">More detailed instructions here</a></p>
<p><b>Number of players (3 packs per player):</b> <input type="number" id="numPlayers" min="1" max="8" value="1" /></p>
<p><b>Commons:</b><input type="number" id="numcommons" min="0" max="15" value="11" />
<b>Uncommons:</b><input type="number" id="numuncommons" min="0" max="15" value="3" />
<b>Rares:</b><input type="number" id="numrares" min="0" max="15" value="1" /></p>
<p><b>Upload your Inventory CSV file here:</b> <input type="file" id="files" name="files[]" /></p>
<output id="out"></output>
<script>
function CSVToArray(strData) {
strDelimiter = ",";
var objPattern = new RegExp(
(
"(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
"(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
"([^\"\\" + strDelimiter + "\\r\\n]*))"
),
"gi"
);
var arrData = [[]];
var arrMatches = null;
while (arrMatches = objPattern.exec( strData )){
var strMatchedDelimiter = arrMatches[ 1 ];
if (
strMatchedDelimiter.length &&
(strMatchedDelimiter != strDelimiter)
){
arrData.push( [] );
}
if (arrMatches[ 2 ]){
var strMatchedValue = arrMatches[ 2 ].replace(
new RegExp( "\"\"", "g" ),
"\""
);
} else {
var strMatchedValue = arrMatches[ 3 ];
}
arrData[ arrData.length - 1 ].push( strMatchedValue );
}
return( arrData );
}
function handleFileSelect(opt_startByte, opt_stopByte) {
var commons = [];
var uncommons = [];
var rares = [];
var mythics = [];
var commonsi = [];
var uncommonsi = [];
var raresi = [];
var mythicsi = [];
var numUn = document.getElementById('numuncommons').value;
var numC = document.getElementById('numcommons').value;
var numR = document.getElementById('numrares').value;
var nameCol = "Name";
var rarityCol = "Rarity";
var imageURLCol = "Image URL";
var common = "Common";
var uncommon = "Uncommon";
var rare = "Rare";
var mythic = "MythicRare";
var nameIndex, rarityIndex, imageURLIndex;
var numPlayers = document.getElementById('numPlayers').value;
var files = document.getElementById('files').files;
if (!files.length) {
alert('Please select a file!');
return;
}
var file = files[0];
var start = 0;
var stop = file.size - 1;
var reader = new FileReader();
reader.onload = function(evt) {
var contents = evt.target.result;
var lines = CSVToArray(contents);
var header = lines[0];
nameIndex = header.indexOf(nameCol);
rarityIndex = header.indexOf(rarityCol);
imageURLIndex = header.indexOf(imageURLCol);
for (var i = 1; i < lines.length; i++) {
var line = lines[i];
if (line[rarityIndex] == common) {
commons.push(line[nameIndex]);
commonsi.push(line[imageURLIndex]);
} else if (line[rarityIndex] == uncommon) {
uncommons.push(line[nameIndex]);
uncommonsi.push(line[imageURLIndex]);
} else if (line[rarityIndex] == rare) {
rares.push(line[nameIndex]);
raresi.push(line[imageURLIndex]);
} else if (line[rarityIndex] == mythic) {
mythics.push(line[nameIndex]);
mythicsi.push(line[imageURLIndex]);
} else {
}
}
var output = [];
var chosenc = [];
var chosenu = [];
var chosenr = [];
var chosenm = [];
var rand = 0;
var count = 0;
output.push('<p><i>', commons.length, ' - Number of commons<br>',
uncommons.length, ' - Number of uncommons<br>',
rares.length, ' - Number of rares<br>',
mythics.length, ' - Number of mythics</i></p>');
for (var j = 1; j <= numPlayers; j++) {
for (var k = 1; k <=3; k++) {
count = 0;
output.push('<p><strong>Player ', j, ', Pack ', k, '</strong></p>',
'<table><tr>');
for(var l = 0; l < numC; l++) {
while(true) {
rand = Math.floor(Math.random()*commons.length);
if (chosenc.indexOf(rand) == -1) {
chosenc.push(rand);
break;
}
}
output.push('<td><a target="_blank" href="http://deckbox.org/mtg/',
commons[rand].replace(" ", "%20"), '"><img src="',
commonsi[rand],'"></a></td>');
count = count + 1;
if (count % 5 == 0) { output.push('</tr><tr>'); }
}
for (var m = 0; m < numUn; m++) {
while(true) {
rand = Math.floor(Math.random()*uncommons.length);
if (chosenu.indexOf(rand) == -1) {
chosenu.push(rand);
break;
}
}
output.push('<td><a target="_blank" href="http://deckbox.org/mtg/',
uncommons[rand].replace(" ", "%20"), '"><img src="',
uncommonsi[rand],'"></a></td>');
count = count + 1;
if (count % 5 == 0) { output.push('</tr><tr>'); }
}
for (var n = 0; n < numR; n++) {
if (Math.floor(Math.random()*8 != 1)) {
while(true) {
rand = Math.floor(Math.random()*rares.length);
if (chosenr.indexOf(rand) == -1) {
chosenr.push(rand);
break;
}
}
output.push('<td><a target="_blank" href="http://deckbox.org/mtg/',
rares[rand].replace(" ", "%20"), '"><img src="',
raresi[rand],'"></a></td>');
} else {
while(true) {
rand = Math.floor(Math.random()*mythics.length);
if (chosenm.indexOf(rand) == -1) {
chosenm.push(rand);
break;
}
}
output.push('<td><a target="_blank" href="http://deckbox.org/mtg/',
mythics[rand].replace(" ", "%20"), '"><img src="',
mythicsi[rand],'"></a></td>');
}
count = count + 1;
if (count % 5 == 0) { output.push('</tr><tr>'); }
}
output.push('</tr></table>');
}
}
document.getElementById('out').innerHTML = output.join('');
};
reader.readAsText(file);
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
</body>
</html>
Last edited by Avon (2013-06-28 17:14:19)