From 1ec6e139e1fa0339ab906fb46ff45757a5bb444b Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 12 Jul 2015 09:01:06 +0200 Subject: [PATCH] Some improvements to deck text import (ignore more group names also on other order, ignore x after number e.g. 2x = 2). --- .../cards/decks/importer/TxtDeckImporter.java | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/Mage/src/mage/cards/decks/importer/TxtDeckImporter.java b/Mage/src/mage/cards/decks/importer/TxtDeckImporter.java index 20a0a050b4e..0c0589baf73 100644 --- a/Mage/src/mage/cards/decks/importer/TxtDeckImporter.java +++ b/Mage/src/mage/cards/decks/importer/TxtDeckImporter.java @@ -1,16 +1,16 @@ /* * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR @@ -20,12 +20,11 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.cards.decks.importer; import java.util.Arrays; @@ -48,13 +47,13 @@ import mage.constants.SetType; */ public class TxtDeckImporter extends DeckImporter { - public static final String[] SET_VALUES = new String[] { "lands", "creatures", "planeswalkers","other spells","sideboard cards" }; + public static final String[] SET_VALUES = new String[]{"lands", "creatures", "planeswalkers", "other spells", "sideboard cards", + "Instant", "Land", "Enchantment", "Artifact", "Sorcery", "Planeswalker", "Creature"}; public static final Set IGNORE_NAMES = new HashSet<>(Arrays.asList(SET_VALUES)); - + private boolean sideboard = false; private int emptyLinesInARow = 0; - @Override protected void readLine(String line, DeckCardLists deckList) { if (line.startsWith("//")) { @@ -75,22 +74,25 @@ public class TxtDeckImporter extends DeckImporter { return; } - line = line.replace("\t"," "); // changing tabs to blanks as delimiter + 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(); - String lineName = line.substring(delim).replace("’","\'").trim(); - lineName = lineName.replace("&","//").replace("Æ", "AE").replace("ö", "ö"); + String lineName = line.substring(delim).replace("’", "\'").trim(); + lineName = lineName.replace("&", "//").replace("Æ", "AE").replace("ö", "ö"); if (lineName.contains("//") && !lineName.contains(" // ")) { - lineName = lineName.replace("//"," // "); + lineName = lineName.replace("//", " // "); } - if (IGNORE_NAMES.contains(lineName)) { + if (lineName.contains(" / ")) { + lineName = lineName.replace(" / ", " // "); + } + if (IGNORE_NAMES.contains(lineName) || IGNORE_NAMES.contains(lineNum)) { return; } try { - int num = Integer.parseInt(lineNum); + int num = Integer.parseInt(lineNum.replaceAll("\\D+", "")); List cards = CardRepository.instance.findCards(lineName); if (cards.isEmpty()) { sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n"); @@ -99,11 +101,11 @@ public class TxtDeckImporter extends DeckImporter { Date lastReleaseDate = new GregorianCalendar(1900, 1, 1).getTime(); Date lastExpansionDate = new GregorianCalendar(1900, 1, 1).getTime(); CardInfo cardToUse = null; - for (CardInfo cardinfo: cards) { + for (CardInfo cardinfo : cards) { ExpansionInfo set = ExpansionRepository.instance.getSetByCode(cardinfo.getSetCode()); if (set != null) { - if ((set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.CORE)) && - (lastExpansionDate == null || set.getReleaseDate().after(lastExpansionDate))) { + if ((set.getType().equals(SetType.EXPANSION) || set.getType().equals(SetType.CORE)) + && (lastExpansionDate == null || set.getReleaseDate().after(lastExpansionDate))) { cardToUse = cardinfo; lastExpansionDate = set.getReleaseDate(); } @@ -118,9 +120,9 @@ public class TxtDeckImporter extends DeckImporter { } for (int i = 0; i < num; i++) { if (!sideboard) { - deckList.getCards().add(new DeckCardInfo(cardToUse.getName(),cardToUse.getCardNumber(), cardToUse.getSetCode())); + deckList.getCards().add(new DeckCardInfo(cardToUse.getName(), cardToUse.getCardNumber(), cardToUse.getSetCode())); } else { - deckList.getSideboard().add(new DeckCardInfo(cardToUse.getName(),cardToUse.getCardNumber(), cardToUse.getSetCode())); + deckList.getSideboard().add(new DeckCardInfo(cardToUse.getName(), cardToUse.getCardNumber(), cardToUse.getSetCode())); } } }