use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class CSVExport method export.
@Override
public void export(MagicDeck deck, File f) throws IOException {
exportedDeckProperties = getString("exportedDeckProperties").split(",");
try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) {
bw.write("Main list\n");
bw.write("Qte;");
for (String k : exportedDeckProperties) bw.write(k + ";");
bw.write("\n");
for (MagicCard mc : deck.getMap().keySet()) {
bw.write(deck.getMap().get(mc) + ";");
for (String k : exportedDeckProperties) {
String val = null;
try {
val = BeanUtils.getProperty(mc, k);
} catch (Exception e) {
logger.error("Error reading bean", e);
}
if (val == null)
val = "";
bw.write(val.replaceAll("\n", "") + ";");
}
bw.write("\n");
}
bw.write("SideBoard\n");
bw.write("Qte;");
for (String k : exportedDeckProperties) bw.write(k + ";");
bw.write("\n");
for (MagicCard mc : deck.getMapSideBoard().keySet()) {
bw.write(deck.getMapSideBoard().get(mc) + ";");
for (String k : exportedDeckProperties) {
String val = null;
try {
val = BeanUtils.getProperty(mc, k);
} catch (Exception e) {
logger.error("Error reading bean ", e);
}
if (val == null)
val = "";
bw.write(val.replaceAll("\n", "") + ";");
}
bw.write("\n");
}
}
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class CSVExport method export.
@Override
public void export(List<MagicCard> cards, File f) throws IOException {
exportedProperties = getString("exportedProperties").split(",");
try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))) {
for (String k : exportedProperties) bw.write(k + ";");
bw.write("\n");
for (MagicCard mc : cards) {
for (String k : exportedProperties) {
String val = BeanUtils.getProperty(mc, k);
if (val == null)
val = "";
bw.write(val.replaceAll("\n", "") + ";");
}
bw.write("\n");
}
} catch (Exception e) {
throw new IOException(e);
}
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class JsonExport method export.
@Override
public void export(MagicDeck deck, File dest) throws IOException {
JsonObject json = new JsonObject();
json.addProperty("name", deck.getName());
json.addProperty("description", deck.getDescription());
json.addProperty("colors", deck.getColors());
json.addProperty("averagePrice", deck.getAveragePrice());
JsonArray tags = new JsonArray();
for (String s : deck.getTags()) tags.add(s);
json.add("tags", tags);
JsonArray main = new JsonArray();
for (MagicCard mc : deck.getMap().keySet()) {
JsonObject card = new JsonObject();
card.addProperty("qty", (Number) deck.getMap().get(mc));
card.add("card", new Gson().toJsonTree(mc));
main.add(card);
}
JsonArray side = new JsonArray();
for (MagicCard mc : deck.getMapSideBoard().keySet()) {
JsonObject card = new JsonObject();
card.addProperty("qty", (Number) deck.getMapSideBoard().get(mc));
card.add("card", new Gson().toJsonTree(mc));
side.add(card);
}
json.add("main", main);
json.add("side", side);
FileUtils.writeStringToFile(dest, json.toString(), "UTF-8");
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class MagicWorkStationDeckExport method export.
@Override
public void export(MagicDeck deck, File dest) throws IOException {
StringBuilder temp = new StringBuilder();
temp.append("// MAIN\n");
for (MagicCard mc : deck.getMap().keySet()) {
temp.append(" ");
temp.append(deck.getMap().get(mc));
temp.append(" ");
temp.append("[").append(mc.getEditions().get(0).getId().toUpperCase()).append("]");
temp.append(mc.getName());
temp.append("\n");
}
temp.append("// Sideboard\n");
for (MagicCard mc : deck.getMapSideBoard().keySet()) {
temp.append("SB: ");
temp.append(deck.getMap().get(mc));
temp.append(" ");
temp.append("[").append(mc.getEditions().get(0).getId()).append("]");
temp.append(mc.getName());
temp.append("\n");
}
try (FileWriter out = new FileWriter(dest)) {
out.write(temp.toString());
}
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class MkmOnlineExport method export.
@Override
public void export(List<MagicCard> cards, File f) throws IOException {
MagicDeck d = new MagicDeck();
for (MagicCard mc : cards) d.getMap().put(mc, Integer.parseInt(getString("DEFAULT_QTE")));
d.setName(f.getName());
export(d, f);
}
Aggregations