use of org.magic.api.beans.MagicDeck in project MtgDesktopCompanion by nicho92.
the class CSVExport method importDeck.
@Override
public MagicDeck importDeck(File f) throws IOException {
try (BufferedReader read = new BufferedReader(new FileReader(f))) {
MagicDeck deck = new MagicDeck();
deck.setName(f.getName().substring(0, f.getName().indexOf('.')));
String line = read.readLine();
line = read.readLine();
while (line != null) {
String[] part = line.split(getString("importDeckCharSeparator"));
String name = part[0];
String qte = part[1];
String set = part[2];
MagicEdition ed = new MagicEdition();
ed.setId(set);
List<MagicCard> list = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", name, ed, true);
deck.getMap().put(list.get(0), Integer.parseInt(qte));
line = read.readLine();
}
return deck;
}
}
use of org.magic.api.beans.MagicDeck in project MtgDesktopCompanion by nicho92.
the class CocatriceDeckExport method importDeck.
@Override
public MagicDeck importDeck(File f) throws IOException {
MagicDeck deck = new MagicDeck();
try {
Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new FileReader(f)));
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("//cockatrice_deck/deckname");
NodeList result = (NodeList) expr.evaluate(d, XPathConstants.NODESET);
deck.setName(result.item(0).getTextContent());
expr = xpath.compile("//cockatrice_deck/comments");
result = (NodeList) expr.evaluate(d, XPathConstants.NODESET);
deck.setDescription(result.item(0).getTextContent());
expr = xpath.compile("//cockatrice_deck/zone[contains(@name,'main')]/card");
result = ((NodeList) expr.evaluate(d, XPathConstants.NODESET));
int c = 0;
for (int i = 0; i < result.getLength(); i++) {
String name = result.item(i).getAttributes().getNamedItem("name").getTextContent();
Integer qte = Integer.parseInt(result.item(i).getAttributes().getNamedItem("number").getTextContent());
deck.getMap().put(MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", name, null, true).get(0), qte);
setChanged();
notifyObservers(c++);
}
expr = xpath.compile("//cockatrice_deck/zone[contains(@name,'side')]/card");
result = ((NodeList) expr.evaluate(d, XPathConstants.NODESET));
for (int i = 0; i < result.getLength(); i++) {
String name = result.item(i).getAttributes().getNamedItem("name").getTextContent();
Integer qte = Integer.parseInt(result.item(i).getAttributes().getNamedItem("number").getTextContent());
deck.getMapSideBoard().put(MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", name, null, true).get(0), qte);
setChanged();
notifyObservers(c++);
}
} catch (Exception e) {
throw new IOException(e);
}
return deck;
}
use of org.magic.api.beans.MagicDeck in project MtgDesktopCompanion by nicho92.
the class CocatriceDeckExport method exportStock.
@Override
public void exportStock(List<MagicCardStock> stock, File f) throws IOException {
MagicDeck d = new MagicDeck();
d.setName(f.getName());
for (MagicCardStock mcs : stock) {
d.getMap().put(mcs.getMagicCard(), mcs.getQte());
}
export(d, f);
}
use of org.magic.api.beans.MagicDeck in project MtgDesktopCompanion by nicho92.
the class DCIDeckSheetExport method exportStock.
@Override
public void exportStock(List<MagicCardStock> stock, File f) throws IOException {
MagicDeck d = new MagicDeck();
d.setName(f.getName());
for (MagicCardStock mcs : stock) {
d.getMap().put(mcs.getMagicCard(), mcs.getQte());
}
export(d, f);
}
use of org.magic.api.beans.MagicDeck in project MtgDesktopCompanion by nicho92.
the class JsonExport method importDeck.
@Override
public MagicDeck importDeck(File f) throws IOException {
JsonReader reader = new JsonReader(new FileReader(f));
JsonObject root = new JsonParser().parse(reader).getAsJsonObject();
MagicDeck deck = new MagicDeck();
deck.setDateCreation(new Date());
if (!root.get("name").isJsonNull())
deck.setName(root.get("name").getAsString());
if (!root.get("description").isJsonNull())
deck.setDescription(root.get("description").getAsString());
if (!root.get("tags").isJsonNull()) {
JsonArray arr = root.get("tags").getAsJsonArray();
for (int i = 0; i < arr.size(); i++) deck.getTags().add(arr.get(i).getAsString());
}
JsonArray main = root.get("main").getAsJsonArray();
for (int i = 0; i < main.size(); i++) {
JsonObject line = main.get(i).getAsJsonObject();
int qte = line.get("qty").getAsInt();
MagicCard mc = new Gson().fromJson(line.get("card"), MagicCard.class);
deck.getMap().put(mc, qte);
}
JsonArray side = root.get("side").getAsJsonArray();
for (int i = 0; i < side.size(); i++) {
JsonObject line = side.get(i).getAsJsonObject();
int qte = line.get("qty").getAsInt();
MagicCard mc = new Gson().fromJson(line.get("card"), MagicCard.class);
deck.getMapSideBoard().put(mc, qte);
}
return deck;
}
Aggregations