mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Merge pull request #1972 from gnumast/master
Text Import should detect sideboard after a single blank line
This commit is contained in:
commit
086d69c200
4 changed files with 62 additions and 11 deletions
|
@ -27,9 +27,10 @@
|
||||||
*/
|
*/
|
||||||
package mage.sets.eternalmasters;
|
package mage.sets.eternalmasters;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.constants.Rarity;
|
import mage.constants.Rarity;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author fireshoes
|
* @author fireshoes
|
||||||
|
|
6
Mage.Tests/JustLands.txt
Normal file
6
Mage.Tests/JustLands.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
1 Forest
|
||||||
|
1 Plains
|
||||||
|
1 Island
|
||||||
|
|
||||||
|
1 Swamp
|
||||||
|
1 Mountain
|
|
@ -0,0 +1,43 @@
|
||||||
|
package org.mage.test.decks.importer;
|
||||||
|
|
||||||
|
import mage.cards.decks.DeckCardInfo;
|
||||||
|
import mage.cards.decks.DeckCardLists;
|
||||||
|
import mage.cards.decks.importer.TxtDeckImporter;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TxtDeckImporterTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportWithBlankLineAboveSideboard() {
|
||||||
|
TxtDeckImporter importer = new TxtDeckImporter();
|
||||||
|
|
||||||
|
CardInfo card;
|
||||||
|
DeckCardLists deck = new DeckCardLists();
|
||||||
|
|
||||||
|
String[] cards = {"Plains", "Forest", "Island"};
|
||||||
|
String[] sideboard = {"Swamp", "Mountain"};
|
||||||
|
|
||||||
|
for (String c : cards) {
|
||||||
|
card = CardRepository.instance.findPreferedCoreExpansionCard(c, true);
|
||||||
|
assert card != null;
|
||||||
|
deck.getCards().add(new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String s : sideboard) {
|
||||||
|
card = CardRepository.instance.findPreferedCoreExpansionCard(s, true);
|
||||||
|
assert card != null;
|
||||||
|
deck.getSideboard().add(new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertEquals("Deck does not contain 3 cards, found " + deck.getCards().size(), 3, deck.getCards().size());
|
||||||
|
Assert.assertEquals("Sideboard does not contain 2 cards, found " + deck.getSideboard().size(), 2, deck.getSideboard().size());
|
||||||
|
|
||||||
|
DeckCardLists imported = importer.importDeck("JustLands.txt");
|
||||||
|
|
||||||
|
Assert.assertEquals("Imported deck does not contain 3 cards, found " + imported.getCards().size(), 3, imported.getCards().size());
|
||||||
|
Assert.assertEquals("Imported sideboard does not contain 2 cards, found " + imported.getSideboard().size(), 2, imported.getSideboard().size());
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,14 +27,15 @@
|
||||||
*/
|
*/
|
||||||
package mage.cards.decks.importer;
|
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.DeckCardInfo;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
import mage.cards.repository.CardInfo;
|
import mage.cards.repository.CardInfo;
|
||||||
import mage.cards.repository.CardRepository;
|
import mage.cards.repository.CardRepository;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @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));
|
public static final Set<String> IGNORE_NAMES = new HashSet<>(Arrays.asList(SET_VALUES));
|
||||||
|
|
||||||
private boolean sideboard = false;
|
private boolean sideboard = false;
|
||||||
private int emptyLinesInARow = 0;
|
private int nonEmptyLinesTotal = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void readLine(String line, DeckCardLists deckList) {
|
protected void readLine(String line, DeckCardLists deckList) {
|
||||||
|
@ -57,14 +58,14 @@ public class TxtDeckImporter extends DeckImporter {
|
||||||
if (line.startsWith("//")) {
|
if (line.startsWith("//")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (line.length() == 0) {
|
|
||||||
emptyLinesInARow++;
|
// Start the sideboard on empty line that follows
|
||||||
if (emptyLinesInARow > 1) {
|
// at least 1 non-empty line
|
||||||
sideboard = true;
|
if (line.length() == 0 && nonEmptyLinesTotal > 0) {
|
||||||
}
|
sideboard = true;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
emptyLinesInARow = 0;
|
nonEmptyLinesTotal++;
|
||||||
}
|
}
|
||||||
|
|
||||||
line = line.replace("\t", " "); // changing tabs to blanks as delimiter
|
line = line.replace("\t", " "); // changing tabs to blanks as delimiter
|
||||||
|
|
Loading…
Reference in a new issue