Search in sources :

Example 31 with MagicCard

use of org.magic.api.beans.MagicCard 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 32 with MagicCard

use of org.magic.api.beans.MagicCard 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 33 with MagicCard

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

the class WebsiteImportExport 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 34 with MagicCard

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

the class XMageDeckExport 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();
        while (line != null) {
            if (!line.startsWith("NAME:")) {
                if (!line.startsWith("SB:")) {
                    MagicEdition ed = new MagicEdition();
                    ed.setId(line.substring(line.indexOf('[') + 1, line.indexOf(':')));
                    String cardName = line.substring(line.indexOf(']') + 1, line.length()).trim();
                    int qte = Integer.parseInt(line.substring(0, line.indexOf('[')).trim());
                    MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
                    deck.getMap().put(mc, qte);
                } else {
                    line = line.replace("SB:", "").trim();
                    MagicEdition ed = new MagicEdition();
                    ed.setId(line.substring(line.indexOf('[') + 1, line.indexOf(':')));
                    String cardName = line.substring(line.indexOf(']') + 1, line.length()).trim();
                    int qte = Integer.parseInt(line.substring(0, line.indexOf('[')).trim());
                    MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", cardName, ed, true).get(0);
                    deck.getMap().put(mc, qte);
                }
            } else {
                deck.setName(line.replaceAll("NAME: ", ""));
            }
            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 35 with MagicCard

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

the class AbstractCardExport method export.

@Override
public void export(List<MagicCard> cards, File f) throws IOException {
    MagicDeck d = new MagicDeck();
    d.setName("export " + getName() + " cards");
    d.setDescription(getName() + " export to " + f.getName());
    d.setDateCreation(new Date());
    int i = 0;
    for (MagicCard mc : cards) {
        d.add(mc);
        setChanged();
        notifyObservers(i++);
    }
    export(d, f);
}
Also used : MagicCard(org.magic.api.beans.MagicCard) Date(java.util.Date) MagicDeck(org.magic.api.beans.MagicDeck)

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