Search in sources :

Example 21 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class MTGTop8DeckSniffer method getDeck.

@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
    Document root = Jsoup.connect(info.getUrl().toString()).userAgent(getString("USER_AGENT")).timeout(0).get();
    MagicDeck d = new MagicDeck();
    d.setDescription(info.getUrl().toString());
    d.setName(info.getName());
    d.setDateCreation(new Date());
    Elements doc = root.select("table.Stable").get(1).select("td table").select(MTGConstants.HTML_TAG_TD);
    boolean side = false;
    for (Element e : doc.select("td table td")) {
        if (e.hasClass("O13")) {
            if (e.text().equalsIgnoreCase("SIDEBOARD"))
                side = true;
        } else {
            int qte = Integer.parseInt(e.text().substring(0, e.text().indexOf(' ')));
            String name = e.select("span.L14").text();
            if (!name.equals("")) {
                MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", name, null, true).get(0);
                if (!side)
                    d.getMap().put(mc, qte);
                else
                    d.getMapSideBoard().put(mc, qte);
            }
        }
    }
    return d;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Date(java.util.Date) MagicDeck(org.magic.api.beans.MagicDeck)

Example 22 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class TCGPlayerDeckSniffer method getDeck.

@Override
public MagicDeck getDeck(RetrievableDeck info) throws IOException {
    logger.debug("get deck at " + info.getUrl());
    MagicDeck deck = new MagicDeck();
    deck.setName(info.getName());
    deck.setDescription(info.getUrl().toString());
    deck.setDateCreation(new Date());
    Document d = Jsoup.connect(info.getUrl().toString()).userAgent(getString("USER_AGENT")).get();
    for (Element e : d.select("span.singleTag")) {
        deck.getTags().add(e.text());
    }
    Elements main = d.getElementsByClass("subdeck");
    int taille = main.get(0).getElementsByClass("subdeck-group__card-qty").size();
    for (int i = 0; i < taille; i++) {
        int qte = Integer.parseInt(main.get(0).getElementsByClass("subdeck-group__card-qty").get(i).text());
        String cardName = main.get(0).getElementsByClass("subdeck-group__card-name").get(i).text();
        MagicEdition ed = null;
        if (cardName.trim().equalsIgnoreCase("Plains") || cardName.trim().equalsIgnoreCase("Island") || cardName.trim().equalsIgnoreCase("Swamp") || cardName.trim().equalsIgnoreCase("Mountain") || cardName.trim().equalsIgnoreCase("Forest")) {
            ed = new MagicEdition();
            ed.setId(MTGControler.getInstance().get("default-land-deck"));
        }
        if (cardName.contains("//"))
            cardName = cardName.substring(0, cardName.indexOf("//")).trim();
        MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
        deck.getMap().put(mc, qte);
    }
    if (main.size() > 1) {
        int tailleSide = main.get(1).getElementsByClass("subdeck-group__card-qty").size();
        for (int i = 0; i < tailleSide; i++) {
            int qte = Integer.parseInt(main.get(1).getElementsByClass("subdeck-group__card-qty").get(i).text());
            String cardName = main.get(1).getElementsByClass("subdeck-group__card-name").get(i).text();
            MagicEdition ed = null;
            if (cardName.trim().equalsIgnoreCase("Plains") || cardName.trim().equalsIgnoreCase("Island") || cardName.trim().equalsIgnoreCase("Swamp") || cardName.trim().equalsIgnoreCase("Mountain") || cardName.trim().equalsIgnoreCase("Forest")) {
                ed = new MagicEdition();
                ed.setId(MTGControler.getInstance().get("default-land-deck"));
            }
            if (cardName.contains("//"))
                cardName = cardName.substring(0, cardName.indexOf("//")).trim();
            MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
            deck.getMapSideBoard().put(mc, qte);
        }
    }
    return deck;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) Element(org.jsoup.nodes.Element) MagicEdition(org.magic.api.beans.MagicEdition) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Date(java.util.Date) MagicDeck(org.magic.api.beans.MagicDeck)

Example 23 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class Apprentice2DeckExport 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();
        int ecart = 0;
        while (line != null) {
            line = line.trim();
            if (!line.startsWith("//")) {
                String[] elements = line.split(getString("SEPARATOR"));
                MagicEdition ed = null;
                try {
                    ed = new MagicEdition();
                    ed.setId(elements[3]);
                } catch (Exception e) {
                    ed = null;
                    ecart = 1;
                }
                String name = elements[2 - ecart].replaceAll("\"", "");
                MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", name, ed, true).get(0);
                Integer qte = Integer.parseInt(elements[1 - ecart]);
                if (line.startsWith("SB"))
                    deck.getMapSideBoard().put(mc, qte);
                else
                    deck.getMap().put(mc, qte);
            }
            line = read.readLine();
        }
        return deck;
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) BufferedReader(java.io.BufferedReader) MagicEdition(org.magic.api.beans.MagicEdition) FileReader(java.io.FileReader) IOException(java.io.IOException) MagicDeck(org.magic.api.beans.MagicDeck)

Example 24 with MagicCard

use of org.magic.api.beans.MagicCard 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;
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) BufferedReader(java.io.BufferedReader) MagicEdition(org.magic.api.beans.MagicEdition) FileReader(java.io.FileReader) MagicDeck(org.magic.api.beans.MagicDeck)

Example 25 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class CocatriceDeckExport method export.

public void export(MagicDeck deck, File dest) throws IOException {
    StringBuilder temp = new StringBuilder();
    int c = 0;
    String endZoneTag = "</zone>";
    temp.append("<?xml version='1.0' encoding='UTF-8'?>");
    temp.append("<cockatrice_deck version='" + getString("VERSION") + "'>");
    temp.append("<deckname>").append(deck.getName()).append("</deckname>");
    temp.append("<comments>").append(deck.getDescription()).append("</comments>");
    temp.append("<zone name='main'>");
    for (MagicCard mc : deck.getMap().keySet()) {
        temp.append("<card number='").append(deck.getMap().get(mc)).append("' price='" + getString("DEFAULT_PRICE") + "' name=\"").append(mc.getName()).append("\"/>");
        setChanged();
        notifyObservers(c++);
    }
    temp.append(endZoneTag);
    temp.append("<zone name='side'>");
    for (MagicCard mc : deck.getMapSideBoard().keySet()) {
        temp.append("<card number='").append(deck.getMapSideBoard().get(mc)).append("' price='" + getString("DEFAULT_PRICE") + "' name=\"").append(mc.getName()).append("\"/>");
    }
    temp.append(endZoneTag);
    temp.append("</cockatrice_deck>");
    FileUtils.writeStringToFile(dest, temp.toString(), "UTF-8");
}
Also used : MagicCard(org.magic.api.beans.MagicCard)

Aggregations

MagicCard (org.magic.api.beans.MagicCard)106 MagicEdition (org.magic.api.beans.MagicEdition)40 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 MagicDeck (org.magic.api.beans.MagicDeck)21 MagicCollection (org.magic.api.beans.MagicCollection)14 SQLException (java.sql.SQLException)12 Date (java.util.Date)11 MagicCardStock (org.magic.api.beans.MagicCardStock)10 DisplayableCard (org.magic.game.gui.components.DisplayableCard)10 JsonArray (com.google.gson.JsonArray)8 List (java.util.List)8 FileReader (java.io.FileReader)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 File (java.io.File)6 FileWriter (java.io.FileWriter)6 MalformedURLException (java.net.MalformedURLException)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6