use of org.magic.api.beans.MagicRuling in project MtgDesktopCompanion by nicho92.
the class MtgjsonProvider method search.
private List<MagicCard> search(String jsquery, String att, String crit) {
currentSet = new ArrayList<>();
List<MagicCard> listCards = new ArrayList<>();
logger.debug("searchCardByCriteria : " + jsquery);
List<Map<String, Object>> cardsElement = ctx.withListeners(fr -> {
if (fr.path().startsWith("$")) {
currentSet.add(fr.path().substring(fr.path().indexOf("$[") + 3, fr.path().indexOf("]") - 1));
}
return null;
}).read(jsquery, List.class);
int indexSet = 0;
for (Map<String, Object> map : cardsElement) {
MagicCard mc = new MagicCard();
if (map.get("name") != null)
mc.setName(map.get("name").toString());
mc.setFlippable(false);
mc.setTranformable(false);
if (map.get("multiverseid") != null)
mc.setMultiverseid((int) (double) map.get("multiverseid"));
mc.setId(String.valueOf(map.get("id")));
mc.setText(String.valueOf(map.get("text")));
if (map.get("cmc") != null)
mc.setCmc((int) Double.parseDouble(String.valueOf(map.get("cmc"))));
mc.setPower(String.valueOf(map.get("power")));
mc.setToughness(String.valueOf(map.get("toughness")));
mc.setFlavor(String.valueOf(map.get("flavor")));
mc.setArtist(String.valueOf(map.get("artist")));
mc.setLayout(String.valueOf(map.get("layout")));
if (map.get("mciNumber") != null)
mc.setMciNumber(String.valueOf(map.get("mciNumber")));
if (map.get("originalText") != null)
mc.setOriginalText(String.valueOf(map.get("originalText")));
if (map.get("originalType") != null)
mc.setOriginalType(String.valueOf(map.get("originalType")));
if (map.get("supertypes") != null)
mc.getSupertypes().addAll((List<String>) map.get("supertypes"));
if (map.get("types") != null)
mc.getTypes().addAll((List<String>) map.get("types"));
if (map.get("subtypes") != null)
mc.getSubtypes().addAll((List<String>) map.get("subtypes"));
if (map.get("variations") != null)
mc.getVariations().addAll((List<Integer>) map.get("variations"));
if (map.get("colors") != null)
mc.getColors().addAll((List<String>) map.get("colors"));
if (map.get("colorIdentity") != null)
mc.getColorIdentity().addAll((List<String>) map.get("colorIdentity"));
if (map.get("watermark") != null)
mc.setWatermarks(String.valueOf(map.get("watermark")));
if (map.get("number") != null)
mc.setNumber(String.valueOf(map.get("number")));
if (map.get("gathererCode") != null)
mc.setGathererCode(String.valueOf(map.get("gathererCode")));
if (map.get("reserved") != null)
mc.setReserved(Boolean.valueOf(String.valueOf(map.get("reserved"))));
if (map.get("loyalty") != null) {
try {
mc.setLoyalty((int) Double.parseDouble(map.get("loyalty").toString()));
} catch (Exception e) {
mc.setLoyalty(0);
}
}
if (map.get("manaCost") != null)
mc.setCost(String.valueOf(map.get("manaCost")));
else
mc.setCost("");
if (map.get("legalities") != null) {
for (Map<String, Object> mapFormats : (List<Map>) map.get("legalities")) {
MagicFormat mf = new MagicFormat();
mf.setFormat(String.valueOf(mapFormats.get("format")));
mf.setLegality(String.valueOf(mapFormats.get("legality")));
mc.getLegalities().add(mf);
}
}
if (map.get("rulings") != null) {
for (Map<String, Object> mapRules : (List<Map>) map.get("rulings")) {
MagicRuling mr = new MagicRuling();
mr.setDate(String.valueOf(mapRules.get("date")));
mr.setText(String.valueOf(mapRules.get("text")));
mc.getRulings().add(mr);
}
}
String codeEd;
if (currentSet.size() == 1)
codeEd = currentSet.get(0);
else
codeEd = currentSet.get(indexSet++);
MagicEdition me = getSetById(codeEd);
me.setRarity(String.valueOf(map.get("rarity")));
me.setNumber(mc.getNumber());
if (mc.getMultiverseid() != null)
me.setMultiverse_id(String.valueOf(mc.getMultiverseid()));
mc.getEditions().add(me);
if (// mtgjson give null text for basic Land. Modify it for adding mana color
me.getRarity().equals("Basic Land")) {
mc.setText(mc.getOriginalText());
switch(mc.getName()) {
case "Plains":
mc.setText("{T} : Add {W} to your mana pool");
break;
case "Island":
mc.setText("{T} : Add {U} to your mana pool");
break;
case "Swamp":
mc.setText("{T} : Add {B} to your mana pool");
break;
case "Mountain":
mc.setText("{T} : Add {R} to your mana pool");
break;
case "Forest":
mc.setText("{T} : Add {G} to your mana pool");
break;
default:
break;
}
}
/*get other sets*/
if (// too much elements, so, remove all re-printings information for basic lands
!me.getRarity().equals("Basic Land") && map.get("printings") != null) {
for (String print : (List<String>) map.get("printings")) {
if (!print.equalsIgnoreCase(codeEd)) {
MagicEdition meO = getSetById(print);
if (mc.getMultiverseid() == null)
meO.setMultiverse_id(String.valueOf(0));
initOtherEditionCardsVar(mc, meO);
mc.getEditions().add(meO);
}
}
}
MagicCardNames defnames = new MagicCardNames();
defnames.setLanguage("English");
defnames.setName(mc.getName());
if (mc.getMultiverseid() != null)
defnames.setGathererId(mc.getMultiverseid());
mc.getForeignNames().add(defnames);
if (map.get("foreignNames") != null) {
for (Map<String, Object> mapNames : (List<Map>) map.get("foreignNames")) {
MagicCardNames fnames = new MagicCardNames();
fnames.setLanguage(String.valueOf(mapNames.get("language")));
fnames.setName(String.valueOf(mapNames.get("name")));
if (mapNames.get("multiverseid") != null)
fnames.setGathererId((int) (double) mapNames.get("multiverseid"));
mc.getForeignNames().add(fnames);
}
}
if (map.get("names") != null) {
((List) map.get("names")).remove(mc.getName());
String rotateName = ((List) map.get("names")).get(((List) map.get("names")).size() - 1).toString();
mc.setRotatedCardName(rotateName);
if (mc.getLayout().equals("flip"))
mc.setFlippable(true);
}
if (mc.getLayout().equals("double-faced") || mc.getLayout().equals("meld"))
mc.setTranformable(true);
setChanged();
notifyObservers(mc);
listCards.add(mc);
}
currentSet.clear();
if (att.equalsIgnoreCase("set"))
cachedCardEds.put(crit, listCards);
return listCards;
}
use of org.magic.api.beans.MagicRuling 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.MagicRuling in project MtgDesktopCompanion by nicho92.
the class LightDescribeCardPanel method initDataBindings.
protected BindingGroup initDataBindings() {
BeanProperty<MagicCard, String> nameProperty = BeanProperty.create("name");
BeanProperty<JTextField, String> textProperty = BeanProperty.create("text");
AutoBinding<MagicCard, String, JTextField, String> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ, card, nameProperty, txtName, textProperty);
autoBinding.bind();
BeanProperty<MagicCard, String> costProperty = BeanProperty.create("cost");
BeanProperty<ManaPanel, String> textProperty1 = BeanProperty.create("manaCost");
AutoBinding<MagicCard, String, ManaPanel, String> autoBinding1 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, card, costProperty, manaPanel, textProperty1);
autoBinding1.bind();
BeanProperty<MagicCard, String> fullTypeProperty = BeanProperty.create("fullType");
BeanProperty<JTextField, String> textProperty2 = BeanProperty.create("text");
AutoBinding<MagicCard, String, JTextField, String> autoBinding2 = Bindings.createAutoBinding(UpdateStrategy.READ, card, fullTypeProperty, txtType, textProperty2);
autoBinding2.bind();
BeanProperty<MagicCard, Integer> loyaltyProperty = BeanProperty.create("loyalty");
BeanProperty<JTextField, String> textProperty4 = BeanProperty.create("text");
AutoBinding<MagicCard, Integer, JTextField, String> autoBinding4 = Bindings.createAutoBinding(UpdateStrategy.READ, card, loyaltyProperty, txtLoyalty, textProperty4);
autoBinding4.bind();
BeanProperty<MagicCard, String> textProperty8 = BeanProperty.create("text");
BeanProperty<MagicTextPane, String> textProperty9 = BeanProperty.create("text");
AutoBinding<MagicCard, String, MagicTextPane, String> autoBinding8 = Bindings.createAutoBinding(UpdateStrategy.READ, card, textProperty8, magicTextPane, textProperty9);
autoBinding8.bind();
BeanProperty<MagicCard, String> pProperty = BeanProperty.create("power");
BeanProperty<JTextField, String> textPropertyP = BeanProperty.create("text");
AutoBinding<MagicCard, String, JTextField, String> autoBindingP = Bindings.createAutoBinding(UpdateStrategy.READ, card, pProperty, txtPower, textPropertyP);
autoBindingP.bind();
BeanProperty<MagicCard, String> tProperty = BeanProperty.create("toughness");
BeanProperty<JTextField, String> textPropertyT = BeanProperty.create("text");
AutoBinding<MagicCard, String, JTextField, String> autoBindingT = Bindings.createAutoBinding(UpdateStrategy.READ, card, tProperty, txtT, textPropertyT);
autoBindingT.bind();
StringBuilder rules = new StringBuilder();
for (MagicRuling rul : card.getRulings()) rules.append("-").append(rul.getText()).append("\n");
rulesTextPane.setText(rules.toString());
//
BindingGroup bindingGroup = new BindingGroup();
//
bindingGroup.addBinding(autoBinding);
bindingGroup.addBinding(autoBinding1);
bindingGroup.addBinding(autoBinding2);
bindingGroup.addBinding(autoBinding4);
bindingGroup.addBinding(autoBinding8);
bindingGroup.addBinding(autoBindingT);
bindingGroup.addBinding(autoBindingP);
magicTextPane.updateTextWithIcons();
return bindingGroup;
}
use of org.magic.api.beans.MagicRuling in project MtgDesktopCompanion by nicho92.
the class MorphActions method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (!card.isRotated()) {
MagicCard mc = new MagicCard();
mc.setName("Morphed Creature");
mc.setPower("2");
mc.setToughness("2");
mc.getTypes().add("Creature");
mc.setCost("{3}");
mc.setEditions(card.getMagicCard().getEditions());
mc.setRotatedCardName(card.getMagicCard().getName());
MagicRuling r = new MagicRuling();
r.setText(MTGControler.getInstance().getKeyWordManager().generateFromString(k).getDescription());
mc.getRulings().add(r);
mc.setText(k + " " + cost);
mc.setLayout(card.getMagicCard().getLayout());
mc.setId(card.getMagicCard().getId());
card.setMagicCard(mc);
card.setRotated(true);
card.showPT(true);
card.initActions();
try {
card.setImage(new ImageIcon(MTGControler.getInstance().getEnabledPicturesProvider().getBackPicture().getScaledInstance(card.getWidth(), card.getHeight(), BufferedImage.SCALE_SMOOTH)));
} catch (Exception e1) {
logger.error(e1);
}
} else {
try {
MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", card.getMagicCard().getRotatedCardName(), card.getMagicCard().getEditions().get(0), true).get(0);
card.setMagicCard(mc);
card.setRotated(false);
card.removeAllCounters();
card.showPT(false);
card.initActions();
} catch (Exception e1) {
logger.error(e1);
}
}
card.revalidate();
card.repaint();
}
use of org.magic.api.beans.MagicRuling in project MtgDesktopCompanion by nicho92.
the class CardSearchPanel method updateCards.
public void updateCards() {
try {
cboLanguages.removeAllItems();
txtRulesArea.setText("");
((DefaultListModel<MagicEdition>) listEdition.getModel()).removeAllElements();
for (MagicCardNames mcn : selectedCard.getForeignNames()) cboLanguages.addItem(mcn);
for (MagicEdition me : selectedCard.getEditions()) ((DefaultListModel<MagicEdition>) listEdition.getModel()).addElement(me);
detailCardPanel.setMagicCard(selectedCard, true);
magicEditionDetailPanel.setMagicEdition(selectedCard.getEditions().get(0));
for (MagicRuling mr : selectedCard.getRulings()) {
txtRulesArea.append(mr.toString());
txtRulesArea.append("\n");
}
if (tabbedCardsInfo.getSelectedIndex() == INDEX_PRICES)
updatePrices();
panelJson.show(selectedCard);
ThreadManager.getInstance().execute(() -> historyChartPanel.init(selectedCard, selectedEdition, selectedCard.getName()), "load history for " + selectedEdition);
} catch (Exception e1) {
logger.error(e1);
}
}
Aggregations