use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class MagicTheGatheringIOProvider method generateCard.
private MagicCard generateCard(JsonObject obj) throws IOException {
MagicCard mc = new MagicCard();
if (obj.get("name") != null)
mc.setName(obj.get("name").getAsString());
if (obj.get("manaCost") != null)
mc.setCost(obj.get("manaCost").getAsString());
if (obj.get("text") != null)
mc.setText(obj.get("text").getAsString());
if (obj.get("originalText") != null)
mc.setOriginalText(obj.get("originalText").getAsString());
if (obj.get("id") != null)
mc.setId(obj.get("id").getAsString());
if (obj.get("artist") != null)
mc.setArtist(obj.get("artist").getAsString());
if (obj.get("cmc") != null)
mc.setCmc(obj.get("cmc").getAsInt());
if (obj.get("layout") != null)
mc.setLayout(obj.get("layout").getAsString());
if (obj.get("number") != null)
mc.setNumber(obj.get("number").getAsString());
if (obj.get("power") != null)
mc.setPower(obj.get("power").getAsString());
if (obj.get("toughness") != null)
mc.setToughness(obj.get("toughness").getAsString());
if (obj.get("loyalty") != null)
mc.setLoyalty(obj.get("loyalty").getAsInt());
if (obj.get("mciNumber") != null)
mc.setMciNumber(String.valueOf(obj.get("mciNumber")));
if (obj.get("colors") != null) {
Iterator<JsonElement> it = obj.get("colors").getAsJsonArray().iterator();
while (it.hasNext()) mc.getColors().add(it.next().getAsString());
}
if (obj.get("types") != null) {
Iterator<JsonElement> it = obj.get("types").getAsJsonArray().iterator();
while (it.hasNext()) mc.getTypes().add(it.next().getAsString());
}
if (obj.get("supertypes") != null) {
Iterator<JsonElement> it = obj.get("supertypes").getAsJsonArray().iterator();
while (it.hasNext()) mc.getSupertypes().add(it.next().getAsString());
}
if (obj.get("subtypes") != null) {
Iterator<JsonElement> it = obj.get("subtypes").getAsJsonArray().iterator();
while (it.hasNext()) mc.getSubtypes().add(it.next().getAsString());
}
if (obj.get("legalities") != null) {
JsonArray arr = obj.get("legalities").getAsJsonArray();
for (int i = 0; i < arr.size(); i++) {
JsonObject k = arr.get(i).getAsJsonObject();
MagicFormat format = new MagicFormat();
format.setFormat(k.get("format").getAsString());
format.setLegality(k.get("legality").getAsString());
mc.getLegalities().add(format);
}
}
if (obj.get("rulings") != null) {
JsonArray arr = obj.get("rulings").getAsJsonArray();
for (int i = 0; i < arr.size(); i++) {
JsonObject k = arr.get(i).getAsJsonObject();
MagicRuling rule = new MagicRuling();
rule.setDate(k.get("date").getAsString());
rule.setText(k.get("text").getAsString());
mc.getRulings().add(rule);
}
}
if (obj.get("names") != null) {
JsonArray arr = obj.get("names").getAsJsonArray();
List<String> list = new ArrayList<>();
for (int i = 0; i < arr.size(); list.add(arr.get(i++).getAsString())) {
// TODO complete this function
}
list.remove(mc.getName());
String rotateName = (list.get(list.size() - 1));
mc.setRotatedCardName(rotateName);
if (mc.getLayout().equals("flip"))
mc.setFlippable(true);
if (mc.getLayout().equals("double-faced") || mc.getLayout().equals("meld"))
mc.setTranformable(true);
}
String currentSet = obj.get("set").getAsString();
MagicEdition currentEd = getSetById(currentSet);
if (obj.get("multiverseid") != null)
currentEd.setMultiverse_id(obj.get("multiverseid").getAsString());
if (obj.get("rarity") != null)
currentEd.setRarity(obj.get("rarity").getAsString());
currentEd.setNumber(mc.getNumber());
mc.getEditions().add(0, currentEd);
if (obj.get("printings") != null) {
JsonArray arr = obj.get("printings").getAsJsonArray();
for (int i = 0; i < arr.size(); i++) {
String k = arr.get(i).getAsString();
if (!k.equals(currentSet)) {
MagicEdition ed = getSetById(k);
initOtherEdVariable(mc, ed);
mc.getEditions().add(ed);
}
}
}
MagicCardNames defaultMcn = new MagicCardNames();
defaultMcn.setName(mc.getName());
defaultMcn.setLanguage("English");
try {
defaultMcn.setGathererId(Integer.parseInt(currentEd.getMultiverse_id()));
} catch (Exception e) {
defaultMcn.setGathererId(0);
}
mc.getForeignNames().add(defaultMcn);
if (obj.get("foreignNames") != null) {
JsonArray arr = obj.get("foreignNames").getAsJsonArray();
for (int i = 0; i < arr.size(); i++) {
JsonObject lang = arr.get(i).getAsJsonObject();
MagicCardNames mcn = new MagicCardNames();
mcn.setName(lang.get("name").getAsString());
mcn.setLanguage(lang.get("language").getAsString());
if (lang.get("multiverseid") != null)
mcn.setGathererId(lang.get("multiverseid").getAsInt());
mc.getForeignNames().add(mcn);
}
}
setChanged();
notifyObservers(mc);
return mc;
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class Search method run.
@Override
public void run(String[] args, IoSession session, MTGConsoleHandler mtgConsoleHandler) throws ParseException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
CommandLine cl = parser.parse(opts, args);
this.session = session;
if (cl.hasOption("c")) {
String att = cl.getOptionValue("c").split("=")[0];
String val = cl.getOptionValue("c").split("=")[1];
List<MagicCard> list = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria(att, val, null, false);
session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttCards())));
}
if (cl.hasOption("s")) {
List<MagicEdition> list = MTGControler.getInstance().getEnabledProviders().loadEditions();
session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttSet())));
}
if (cl.hasOption("col")) {
List<MagicCollection> list;
try {
list = MTGControler.getInstance().getEnabledDAO().getCollections();
} catch (SQLException e) {
throw new IOException(e);
}
session.write(showList(list, Arrays.asList(MTGConsoleHandler.getAttCols())));
}
if (cl.hasOption("?")) {
usage();
}
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class CopyFromActions method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
CardChooseDialog diag = new CardChooseDialog();
diag.setVisible(true);
if (diag.getSelected() != null)
try {
mc.setMagicCard((MagicCard) BeanUtils.cloneBean(diag.getSelected().getMagicCard()));
} catch (Exception e1) {
logger.error(e1);
}
mc.validate();
mc.repaint();
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class EmblemActions method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
try {
MagicCard tok = GamePanelGUI.getInstance().getTokenGenerator().generateEmblemFor(card.getMagicCard());
DisplayableCard dc = new DisplayableCard(tok, MTGControler.getInstance().getCardsDimension(), true);
dc.setMagicCard(tok);
GamePanelGUI.getInstance().getPanelBattleField().addComponent(dc);
GamePanelGUI.getInstance().getPanelBattleField().revalidate();
GamePanelGUI.getInstance().getPanelBattleField().repaint();
GamePanelGUI.getInstance().getPlayer().logAction("generate " + tok + " emblem");
} catch (Exception ex) {
logger.error(ex);
}
}
use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.
the class TransformActions method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
GamePanelGUI.getInstance().getPlayer().logAction("Transform " + card.getMagicCard());
try {
card.removeAllCounters();
MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", card.getMagicCard().getRotatedCardName(), card.getMagicCard().getEditions().get(0), true).get(0);
mc.setRulings(card.getMagicCard().getRulings());
card.setMagicCard(mc);
card.revalidate();
card.repaint();
card.initActions();
} catch (Exception ex) {
logger.error(ex);
}
}
Aggregations