mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
Merge pull request #2254 from royk/add-deck-support
Add support for .dek files
This commit is contained in:
commit
5e7a4d265e
3 changed files with 54 additions and 2 deletions
|
@ -925,7 +925,7 @@ class ImportFilter extends FileFilter {
|
||||||
ext = s.substring(i + 1).toLowerCase();
|
ext = s.substring(i + 1).toLowerCase();
|
||||||
}
|
}
|
||||||
if (ext != null) {
|
if (ext != null) {
|
||||||
if (ext.toLowerCase().equals("dec") || ext.toLowerCase().equals("mwdeck") || ext.toLowerCase().equals("txt")) {
|
if (ext.toLowerCase().equals("dec") || ext.toLowerCase().equals("mwdeck") || ext.toLowerCase().equals("txt") || ext.toLowerCase().equals("dek")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -934,7 +934,7 @@ class ImportFilter extends FileFilter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return "*.dec | *.mwDeck | *.txt";
|
return "*.dec | *.mwDeck | *.txt | *.dek";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,8 @@ public class DeckImporterUtil {
|
||||||
return new TxtDeckImporter();
|
return new TxtDeckImporter();
|
||||||
} else if (file.toLowerCase().endsWith("dck")) {
|
} else if (file.toLowerCase().endsWith("dck")) {
|
||||||
return new DckDeckImporter();
|
return new DckDeckImporter();
|
||||||
|
} else if (file.toLowerCase().endsWith("dek")) {
|
||||||
|
return new DekDeckImporter();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package mage.cards.decks.importer;
|
||||||
|
|
||||||
|
import mage.cards.decks.DeckCardInfo;
|
||||||
|
import mage.cards.decks.DeckCardLists;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by royk on 11-Sep-16.
|
||||||
|
*/
|
||||||
|
public class DekDeckImporter extends DeckImporter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void readLine(String line, DeckCardLists deckList) {
|
||||||
|
|
||||||
|
if (line.length() == 0 || line.startsWith("#") || !line.contains("<Cards CatID")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// e.g. <Cards CatID="61202" Quantity="1" Sideboard="false" Name="Vildin-Pack Outcast" />
|
||||||
|
Integer cardCount = Integer.parseInt(extractAttribute(line, "Quantity"));
|
||||||
|
String cardName = extractAttribute(line, "Name");
|
||||||
|
Boolean isSideboard = "true".equals(extractAttribute(line, "Sideboard"));
|
||||||
|
CardInfo cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(cardName, true);
|
||||||
|
if (cardInfo == null) {
|
||||||
|
sbMessage.append("Could not find card: '").append(cardName).append("' at line ").append(lineCount).append("\n");
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < cardCount; i++) {
|
||||||
|
DeckCardInfo deckCardInfo = new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode());
|
||||||
|
if(isSideboard) {
|
||||||
|
deckList.getSideboard().add(deckCardInfo);
|
||||||
|
} else {
|
||||||
|
deckList.getCards().add(deckCardInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (NumberFormatException nfe) {
|
||||||
|
sbMessage.append("Invalid number: ").append(extractAttribute(line, "Quantity")).append(" at line ").append(lineCount).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String extractAttribute(String line, String name) {
|
||||||
|
String searchString = name+"=\"";
|
||||||
|
int startDelim = line.indexOf(searchString)+searchString.length();
|
||||||
|
int endDelim = line.substring(startDelim).indexOf("\"");
|
||||||
|
return line.substring(startDelim, startDelim+endDelim);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue