mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 12:31:59 -08:00
Fixed text deck import (empty lines);
This commit is contained in:
parent
a2feda38ce
commit
b26132f300
1 changed files with 13 additions and 13 deletions
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue