Skip to content

Commit

Permalink
* UI: fixed wrong deck import from cubes and other sources without ca…
Browse files Browse the repository at this point in the history
…rds amount;
  • Loading branch information
JayDi85 committed Jul 1, 2019
1 parent 7f9e259 commit e3f5071
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions Mage/src/main/java/mage/cards/decks/importer/TxtDeckImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ protected void readLine(String line, DeckCardLists deckList) {
line = line.substring(0, commentDelim).trim();
}

// ignore all empty lines until real cards starts
if (line.isEmpty() && !wasCardLines) {
return;
}

// switch sideboard by empty line
if (switchSideboardByEmptyLine && line.isEmpty() && wasCardLines) {
if (switchSideboardByEmptyLine && line.isEmpty()) {
if (!sideboard) {
sideboard = true;
} else {
Expand All @@ -77,29 +82,28 @@ protected void readLine(String line, DeckCardLists deckList) {

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();
if (IGNORE_NAMES.contains(lineNum)) {
return;
String lineNum = "";
if (delim > 0) {
lineNum = line.substring(0, delim).trim();
if (IGNORE_NAMES.contains(lineNum)) {
return;
}
}

// amount
int cardAmount = 0;
boolean haveCardAmout;
try {
cardAmount = Integer.parseInt(lineNum.replaceAll("\\D+", ""));
if ((cardAmount <= 0) || (cardAmount >= 100)) {
sbMessage.append("Invalid number (too small or too big): ").append(lineNum).append(" at line ").append(lineCount).append('\n');
return;
boolean haveCardAmout = false;
if (!lineNum.isEmpty()) {
try {
cardAmount = Integer.parseInt(lineNum.replaceAll("\\D+", ""));
if ((cardAmount <= 0) || (cardAmount >= 100)) {
sbMessage.append("Invalid number (too small or too big): ").append(lineNum).append(" at line ").append(lineCount).append('\n');
return;
}
haveCardAmout = true;
} catch (NumberFormatException nfe) {
// card without amount
}
haveCardAmout = true;
} catch (NumberFormatException nfe) {
haveCardAmout = false;
//sbMessage.append("Invalid number: ").append(lineNum).append(" at line ").append(lineCount).append('\n');
//return;
}

String lineName;
Expand Down

0 comments on commit e3f5071

Please sign in to comment.