mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
Some improvements to deck text import (ignore more group names also on other order, ignore x after number e.g. 2x = 2).
This commit is contained in:
parent
9cc9d25944
commit
1ec6e139e1
1 changed files with 22 additions and 20 deletions
|
@ -1,16 +1,16 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
|
@ -20,12 +20,11 @@
|
|||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.cards.decks.importer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -48,13 +47,13 @@ import mage.constants.SetType;
|
|||
*/
|
||||
public class TxtDeckImporter extends DeckImporter {
|
||||
|
||||
public static final String[] SET_VALUES = new String[] { "lands", "creatures", "planeswalkers","other spells","sideboard cards" };
|
||||
public static final String[] SET_VALUES = new String[]{"lands", "creatures", "planeswalkers", "other spells", "sideboard cards",
|
||||
"Instant", "Land", "Enchantment", "Artifact", "Sorcery", "Planeswalker", "Creature"};
|
||||
public static final Set<String> IGNORE_NAMES = new HashSet<>(Arrays.asList(SET_VALUES));
|
||||
|
||||
|
||||
private boolean sideboard = false;
|
||||
private int emptyLinesInARow = 0;
|
||||
|
||||
|
||||
@Override
|
||||
protected void readLine(String line, DeckCardLists deckList) {
|
||||
if (line.startsWith("//")) {
|
||||
|
@ -75,22 +74,25 @@ public class TxtDeckImporter extends DeckImporter {
|
|||
return;
|
||||
}
|
||||
|
||||
line = line.replace("\t"," "); // changing tabs to blanks as delimiter
|
||||
line = line.replace("\t", " "); // changing tabs to blanks as delimiter
|
||||
int delim = line.indexOf(' ');
|
||||
if (delim < 0) {
|
||||
return;
|
||||
}
|
||||
String lineNum = line.substring(0, delim).trim();
|
||||
String lineName = line.substring(delim).replace("’","\'").trim();
|
||||
lineName = lineName.replace("&","//").replace("Æ", "AE").replace("ö", "ö");
|
||||
String lineName = line.substring(delim).replace("’", "\'").trim();
|
||||
lineName = lineName.replace("&", "//").replace("Æ", "AE").replace("ö", "ö");
|
||||
if (lineName.contains("//") && !lineName.contains(" // ")) {
|
||||
lineName = lineName.replace("//"," // ");
|
||||
lineName = lineName.replace("//", " // ");
|
||||
}
|
||||
if (IGNORE_NAMES.contains(lineName)) {
|
||||
if (lineName.contains(" / ")) {
|
||||
lineName = lineName.replace(" / ", " // ");
|
||||
}
|
||||
if (IGNORE_NAMES.contains(lineName) || IGNORE_NAMES.contains(lineNum)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
int num = Integer.parseInt(lineNum);
|
||||
int num = Integer.parseInt(lineNum.replaceAll("\\D+", ""));
|
||||
List<CardInfo> cards = CardRepository.instance.findCards(lineName);
|
||||
if (cards.isEmpty()) {
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
|
@ -99,11 +101,11 @@ public class TxtDeckImporter extends DeckImporter {
|
|||
Date lastReleaseDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||
Date lastExpansionDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||
CardInfo cardToUse = null;
|
||||
for (CardInfo cardinfo: cards) {
|
||||
for (CardInfo cardinfo : cards) {
|
||||
ExpansionInfo set = ExpansionRepository.instance.getSetByCode(cardinfo.getSetCode());
|
||||
if (set != null) {
|
||||
if ((set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.CORE)) &&
|
||||
(lastExpansionDate == null || set.getReleaseDate().after(lastExpansionDate))) {
|
||||
if ((set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.CORE))
|
||||
&& (lastExpansionDate == null || set.getReleaseDate().after(lastExpansionDate))) {
|
||||
cardToUse = cardinfo;
|
||||
lastExpansionDate = set.getReleaseDate();
|
||||
}
|
||||
|
@ -118,9 +120,9 @@ public class TxtDeckImporter extends DeckImporter {
|
|||
}
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (!sideboard) {
|
||||
deckList.getCards().add(new DeckCardInfo(cardToUse.getName(),cardToUse.getCardNumber(), cardToUse.getSetCode()));
|
||||
deckList.getCards().add(new DeckCardInfo(cardToUse.getName(), cardToUse.getCardNumber(), cardToUse.getSetCode()));
|
||||
} else {
|
||||
deckList.getSideboard().add(new DeckCardInfo(cardToUse.getName(),cardToUse.getCardNumber(), cardToUse.getSetCode()));
|
||||
deckList.getSideboard().add(new DeckCardInfo(cardToUse.getName(), cardToUse.getCardNumber(), cardToUse.getSetCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue