From e3f50717384ecc34e6272b30a093d17eeacb26e8 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Mon, 1 Jul 2019 12:40:34 +0400 Subject: [PATCH] * UI: fixed wrong deck import from cubes and other sources without cards amount; --- .../cards/decks/importer/TxtDeckImporter.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/Mage/src/main/java/mage/cards/decks/importer/TxtDeckImporter.java b/Mage/src/main/java/mage/cards/decks/importer/TxtDeckImporter.java index e38a19e6eb..831b09f364 100644 --- a/Mage/src/main/java/mage/cards/decks/importer/TxtDeckImporter.java +++ b/Mage/src/main/java/mage/cards/decks/importer/TxtDeckImporter.java @@ -55,8 +55,13 @@ public class TxtDeckImporter extends PlainTextDeckImporter { 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 { @@ -77,29 +82,28 @@ public class TxtDeckImporter extends PlainTextDeckImporter { 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;