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;
}
}
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;
}
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;
}
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;
}
}
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);
}
Aggregations