use of mage.cards.decks.DeckCardLists in project mage by magefree.
the class JsonDeckImporter method importDeck.
/**
* @param fileName file to import
* @param errorMessages you can setup output messages to showup to user
* @param saveAutoFixedFile do not supported for that format
* @return decks list
*/
public DeckCardLists importDeck(String fileName, StringBuilder errorMessages, boolean saveAutoFixedFile) {
File f = new File(fileName);
DeckCardLists deckList = new DeckCardLists();
if (!f.exists()) {
logger.warn("Deckfile " + fileName + " not found.");
return deckList;
}
sbMessage.setLength(0);
try {
try (FileReader reader = new FileReader(f)) {
try {
JsonObject json = JsonParser.parseReader(reader).getAsJsonObject();
readJson(json, deckList);
if (sbMessage.length() > 0) {
if (errorMessages != null) {
// normal output for user
errorMessages.append(sbMessage);
} else {
// fatal error
logger.fatal(sbMessage);
}
}
} catch (JsonParseException ex) {
logger.fatal("Can't parse json-deck: " + fileName, ex);
}
} catch (Exception ex) {
logger.fatal(null, ex);
}
} catch (Exception ex) {
logger.fatal(null, ex);
}
return deckList;
}
use of mage.cards.decks.DeckCardLists in project mage by magefree.
the class JumpstartPoolGenerator method doGeneratePool.
private static Set<Card> doGeneratePool(List<JumpstartPack> packs) {
try {
DeckCardLists list = new DeckCardLists();
SecureRandom random = new SecureRandom();
for (int i = 0; i < 2; i++) {
int index = random.nextInt(packs.size());
list.getCards().addAll(packs.get(index).getCards());
}
return Deck.load(list, false, false).getCards();
} catch (GameException e) {
throw new RuntimeException(e);
}
}
use of mage.cards.decks.DeckCardLists in project mage by magefree.
the class MtgaImporterTest method testImport.
@Test
public void testImport() {
MtgaImporter importer = new MtgaImporter() {
@Override
public CardLookup getCardLookup() {
return LOOKUP;
}
};
StringBuilder errors = new StringBuilder();
DeckCardLists deck = importer.importDeck(Paths.get("src", "test", "data", "importer", "testdeck.mtga").toString(), errors, false);
TestDeckChecker.checker().addMain("Niv-Mizzet Reborn", 1).addMain("Teferi, Time Raveler", 1).addMain("Dovin's Veto", 1).addMain("Knight of Autumn", 1).addMain("Expansion // Explosion", 1).addMain("Forest", 1).addMain("Teferi, Hero of Dominaria", 1).addSide("Unmoored Ego", 1).addSide("Beacon Bolt", 1).verify(deck, 7, 2);
assertEquals("", errors.toString());
}
use of mage.cards.decks.DeckCardLists in project mage by magefree.
the class MwsDeckImportTest method testImport.
@Test
public void testImport() {
MWSDeckImporter importer = new MWSDeckImporter() {
@Override
public CardLookup getCardLookup() {
return LOOKUP;
}
};
StringBuilder errors = new StringBuilder();
DeckCardLists deck = importer.importDeck(Paths.get("src", "test", "data", "importer", "testdeck.mwDeck").toString(), errors, false);
TestDeckChecker.checker().addMain("Mutavault", 4).addMain("Plains", 18).addMain("Daring Skyjek", 2).addMain("Azorius Arrester", 4).addMain("Banisher Priest", 4).addMain("Boros Elite", 4).addMain("Dryad Militant", 4).addMain("Imposing Sovereign", 4).addMain("Precinct Captain", 4).addMain("Soldier of the Pantheon", 4).addMain("Spear of Heliod", 3).addMain("Rootborn Defenses", 1).addMain("Brave the Elements", 4).addSide("Wear/Tear", 1).addSide("Glare of Heresy", 2).addSide("Fiendslayer Paladin", 3).addSide("Riot Control", 3).addSide("Ajani, Caller of the Pride", 3).addSide("Rootborn Defenses", 3).verify(deck, 60, 15);
assertEquals("", errors.toString());
}
use of mage.cards.decks.DeckCardLists in project mage by magefree.
the class MtgOnlineDeckExporterTest method writeDeck.
@Test
public void writeDeck() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DeckCardLists deck = new DeckCardLists();
deck.getCards().add(new DeckCardInfo("Forest", "1", "RNA", 2));
deck.getCards().add(new DeckCardInfo("Plains", "2", "RNA", 3));
// must combine
deck.getCards().add(new DeckCardInfo("Plains", "2", "RNA", 5));
deck.getCards().add(new DeckCardInfo("Mountain", "3", "RNA", 1));
deck.getSideboard().add(new DeckCardInfo("Island", "1", "RNA", 2));
// must combine
deck.getSideboard().add(new DeckCardInfo("Island", "1", "RNA", 5));
deck.getSideboard().add(new DeckCardInfo("Mountain", "2", "RNA", 3));
DeckExporter exporter = new MtgOnlineDeckExporter();
exporter.writeDeck(baos, deck);
assertEquals("2 Forest" + System.lineSeparator() + "8 Plains" + System.lineSeparator() + "1 Mountain" + System.lineSeparator() + System.lineSeparator() + "7 Island" + System.lineSeparator() + "3 Mountain" + System.lineSeparator(), baos.toString());
}
Aggregations