Search in sources :

Example 21 with MagicDeck

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

the class MagicWorkStationDeckExport 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);
}
Also used : MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 22 with MagicDeck

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

the class MagicWorkStationDeckExport 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("//")) {
                int qte = 0;
                MagicCard mc = null;
                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) FileReader(java.io.FileReader) MagicDeck(org.magic.api.beans.MagicDeck)

Example 23 with MagicDeck

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

the class ManualImportExport method importStock.

@Override
public List<MagicCardStock> importStock(File f) throws IOException {
    MagicDeck d = importDeck(f);
    List<MagicCardStock> ret = new ArrayList<>();
    for (MagicCard mc : d.getMap().keySet()) {
        MagicCardStock stock = new MagicCardStock();
        stock.setMagicCard(mc);
        stock.setQte(d.getMap().get(mc));
        stock.setUpdate(true);
        stock.setIdstock(-1);
        ret.add(stock);
    }
    return ret;
}
Also used : MagicCard(org.magic.api.beans.MagicCard) ArrayList(java.util.ArrayList) MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Example 24 with MagicDeck

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

the class MkmOnlineExport method importDeck.

@Override
public MagicDeck importDeck(File f) throws IOException {
    WantsService service = new WantsService();
    MagicDeck d = new MagicDeck();
    d.setName(f.getName());
    Wantslist list = null;
    for (Wantslist l : service.getWantList()) if (l.getName().equalsIgnoreCase(d.getName()))
        list = l;
    if (list == null)
        throw new NullPointerException(getName() + " can't import deck for " + f.getName());
    service.loadItems(list);
    for (WantItem w : list.getItem()) {
        try {
            Product p = w.getProduct();
            if (p.getEnName().contains("(Version "))
                p.setEnName(p.getEnName().substring(0, p.getEnName().indexOf("(Version")));
            d.getMap().put(MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", p.getEnName().trim(), null, true).get(0), w.getCount());
        } catch (Exception e) {
            logger.error("could not import " + w);
        }
    }
    return d;
}
Also used : WantsService(org.api.mkm.services.WantsService) Product(org.api.mkm.modele.Product) Wantslist(org.api.mkm.modele.Wantslist) WantItem(org.api.mkm.modele.WantItem) IOException(java.io.IOException) MkmException(org.api.mkm.exceptions.MkmException) MagicDeck(org.magic.api.beans.MagicDeck)

Example 25 with MagicDeck

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

the class MkmOnlineExport method exportStock.

@Override
public void exportStock(List<MagicCardStock> stock, File f) throws IOException {
    if (!getString("STOCK_USE").equals("true")) {
        MagicDeck d = new MagicDeck();
        d.setName(f.getName());
        for (MagicCardStock mcs : stock) {
            d.getMap().put(mcs.getMagicCard(), mcs.getQte());
        }
        export(d, f);
    } else {
        StockService serv = new StockService();
        ProductServices prods = new ProductServices();
        EnumMap<PRODUCT_ATTS, String> enumAtts = new EnumMap<>(PRODUCT_ATTS.class);
        enumAtts.put(PRODUCT_ATTS.idGame, "1");
        enumAtts.put(PRODUCT_ATTS.exact, "true");
        List<Article> list = new ArrayList<>();
        for (MagicCardStock mcs : stock) {
            Product p = MagicCardMarketPricer2.getProductFromCard(mcs.getMagicCard(), prods.findProduct(mcs.getMagicCard().getName(), enumAtts));
            Article a = new Article();
            a.setAltered(mcs.isAltered());
            a.setSigned(mcs.isSigned());
            a.setCount(mcs.getQte());
            a.setFoil(mcs.isFoil());
            a.setPrice(mcs.getPrice());
            a.setCondition(convert(mcs.getCondition()));
            a.setLanguage(convertLang(mcs.getLanguage()));
            a.setProduct(p);
            a.setIdProduct(p.getIdProduct());
            list.add(a);
        }
        serv.addArticles(list);
    }
}
Also used : PRODUCT_ATTS(org.api.mkm.modele.Product.PRODUCT_ATTS) Article(org.api.mkm.modele.Article) ArrayList(java.util.ArrayList) Product(org.api.mkm.modele.Product) ProductServices(org.api.mkm.services.ProductServices) StockService(org.api.mkm.services.StockService) EnumMap(java.util.EnumMap) MagicDeck(org.magic.api.beans.MagicDeck) MagicCardStock(org.magic.api.beans.MagicCardStock)

Aggregations

MagicDeck (org.magic.api.beans.MagicDeck)40 MagicCard (org.magic.api.beans.MagicCard)21 MagicCardStock (org.magic.api.beans.MagicCardStock)14 Date (java.util.Date)12 MagicEdition (org.magic.api.beans.MagicEdition)10 FileReader (java.io.FileReader)9 IOException (java.io.IOException)8 Document (org.jsoup.nodes.Document)7 Element (org.jsoup.nodes.Element)7 BufferedReader (java.io.BufferedReader)6 ArrayList (java.util.ArrayList)6 Elements (org.jsoup.select.Elements)6 BorderLayout (java.awt.BorderLayout)3 File (java.io.File)3 JsonArray (com.google.gson.JsonArray)2 JsonParser (com.google.gson.JsonParser)2 Dimension (java.awt.Dimension)2 SQLException (java.sql.SQLException)2 JButton (javax.swing.JButton)2 JFileChooser (javax.swing.JFileChooser)2