Text import will automatically start sideboard after a single blank line. Added a JUnit test for TxtDeckImporter.

This commit is contained in:
Alex Marcotte 2016-05-30 23:01:57 -04:00
parent 2d4ba24dd9
commit 95e4e3ea29
3 changed files with 60 additions and 10 deletions

View file

@ -27,14 +27,15 @@
*/
package mage.cards.decks.importer;
import java.util.Arrays;
import java.util.HashSet;
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.Set;
/**
*
* @author BetaSteward_at_googlemail.com
@ -46,7 +47,7 @@ public class TxtDeckImporter extends DeckImporter {
public static final Set<String> IGNORE_NAMES = new HashSet<>(Arrays.asList(SET_VALUES));
private boolean sideboard = false;
private int emptyLinesInARow = 0;
private int nonEmptyLinesTotal = 0;
@Override
protected void readLine(String line, DeckCardLists deckList) {
@ -57,14 +58,14 @@ public class TxtDeckImporter extends DeckImporter {
if (line.startsWith("//")) {
return;
}
if (line.length() == 0) {
emptyLinesInARow++;
if (emptyLinesInARow > 1) {
sideboard = true;
}
// Start the sideboard on empty line that follows
// at least 1 non-empty line
if (line.length() == 0 && nonEmptyLinesTotal > 0) {
sideboard = true;
return;
} else {
emptyLinesInARow = 0;
nonEmptyLinesTotal++;
}
line = line.replace("\t", " "); // changing tabs to blanks as delimiter