Fixed text deck import (empty lines);

This commit is contained in:
Oleg Agafonov 2019-03-22 20:12:35 +04:00
parent a2feda38ce
commit b26132f300

View file

@ -1,28 +1,27 @@
package mage.cards.decks.importer;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import mage.cards.decks.DeckCardInfo;
import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TxtDeckImporter extends PlainTextDeckImporter {
private static final String[] SET_VALUES = new String[]{"lands", "creatures", "planeswalkers", "other spells", "sideboard cards",
"Instant", "Land", "Enchantment", "Artifact", "Sorcery", "Planeswalker", "Creature"};
"Instant", "Land", "Enchantment", "Artifact", "Sorcery", "Planeswalker", "Creature"};
private static final Set<String> IGNORE_NAMES = new HashSet<>(Arrays.asList(SET_VALUES));
private boolean sideboard = false;
private boolean switchSideboardByEmptyLine = true; // all cards after first empty line will be sideboard (like mtgo format)
private int nonEmptyLinesTotal = 0;
private boolean wasCardLines = false;
public TxtDeckImporter(boolean haveSideboardSection) {
if (haveSideboardSection) {
@ -56,19 +55,17 @@ public class TxtDeckImporter extends PlainTextDeckImporter {
}
// switch sideboard by empty line
if (switchSideboardByEmptyLine && line.isEmpty() && nonEmptyLinesTotal > 0) {
if (switchSideboardByEmptyLine && line.isEmpty() && wasCardLines) {
if (!sideboard) {
sideboard = true;
} else {
sbMessage.append("Found empty line at ").append(lineCount).append(", but sideboard already used. Use //sideboard switcher OR one empty line to devide your cards.").append('\n');
sbMessage.append("Found empty line at ").append(lineCount).append(", but sideboard already used. Use //sideboard switcher OR use only one empty line to devide your cards.").append('\n');
}
// skip empty line
return;
}
nonEmptyLinesTotal++;
// single line sideboard card from deckstats.net
// SB: 3 Carnage Tyrant
boolean singleLineSideBoard = false;
@ -98,10 +95,13 @@ public class TxtDeckImporter extends PlainTextDeckImporter {
lineName = lineName.replace("//", " // ");
}
lineName = lineName.replaceFirst("(?<=[^/])\\s*/\\s*(?=[^/])", " // ");
if (IGNORE_NAMES.contains(lineName) || IGNORE_NAMES.contains(lineNum)) {
return;
}
wasCardLines = true;
try {
int num = Integer.parseInt(lineNum.replaceAll("\\D+", ""));
if ((num < 0) || (num > 100)) {