mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
* Fixed a bug of deck import not finding cards that were never included in regular core or expansion sets (e.g. Command Tower). The deck imports are now case insensitive (and also a little bit slower).
This commit is contained in:
parent
9a22cd2068
commit
c0c7dc5900
5 changed files with 32 additions and 10 deletions
|
@ -55,7 +55,7 @@ public class DecDeckImporter extends DeckImporter {
|
|||
String lineName = line.substring(delim).trim();
|
||||
try {
|
||||
int num = Integer.parseInt(lineNum);
|
||||
CardInfo cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName);
|
||||
CardInfo cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName, true);
|
||||
if (cardInfo == null) {
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
} else {
|
||||
|
|
|
@ -74,7 +74,7 @@ public class MWSDeckImporter extends DeckImporter {
|
|||
cardInfo = cards.get(new Random().nextInt(cards.size()));
|
||||
}
|
||||
} else {
|
||||
cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName);
|
||||
cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName, true);
|
||||
}
|
||||
|
||||
if (cardInfo == null) {
|
||||
|
|
|
@ -74,7 +74,7 @@ public class TxtDeckImporter extends DeckImporter {
|
|||
}
|
||||
String lineNum = line.substring(0, delim).trim();
|
||||
String lineName = line.substring(delim).replace("’", "\'").trim();
|
||||
lineName = lineName.replace("&", "//").replace("Æ", "AE").replace("ö", "ö");
|
||||
lineName = lineName.replace("&", "//").replace("Æ", "AE").replace("ö", "ö").replace("û", "u").replace("\"", "'");
|
||||
if (lineName.contains("//") && !lineName.contains(" // ")) {
|
||||
lineName = lineName.replace("//", " // ");
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public class TxtDeckImporter extends DeckImporter {
|
|||
}
|
||||
try {
|
||||
int num = Integer.parseInt(lineNum.replaceAll("\\D+", ""));
|
||||
CardInfo cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName);
|
||||
CardInfo cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(lineName, true);
|
||||
if (cardInfo == null) {
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
} else {
|
||||
|
|
|
@ -29,6 +29,7 @@ package mage.cards.repository;
|
|||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.dao.GenericRawResults;
|
||||
import com.j256.ormlite.jdbc.JdbcConnectionSource;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.SelectArg;
|
||||
|
@ -40,7 +41,6 @@ import java.io.File;
|
|||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
@ -318,11 +318,16 @@ public enum CardRepository {
|
|||
return null;
|
||||
}
|
||||
|
||||
public CardInfo findPreferedCoreExpansionCard(String name) {
|
||||
List<CardInfo> cards = findCards(name);
|
||||
public CardInfo findPreferedCoreExpansionCard(String name, boolean caseInsensitive) {
|
||||
List<CardInfo> cards;
|
||||
if (caseInsensitive) {
|
||||
cards = findCardsCaseInsensitive(name);
|
||||
} else {
|
||||
cards = findCards(name);
|
||||
}
|
||||
if (!cards.isEmpty()) {
|
||||
Date lastReleaseDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||
Date lastExpansionDate = new GregorianCalendar(1900, 1, 1).getTime();
|
||||
Date lastReleaseDate = null;
|
||||
Date lastExpansionDate = null;
|
||||
CardInfo cardToUse = null;
|
||||
for (CardInfo cardinfo : cards) {
|
||||
ExpansionInfo set = ExpansionRepository.instance.getSetByCode(cardinfo.getSetCode());
|
||||
|
@ -353,6 +358,23 @@ public enum CardRepository {
|
|||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<CardInfo> findCardsCaseInsensitive(String name) {
|
||||
try {
|
||||
String sqlName = name.toLowerCase().replaceAll("\'", "\'\'");
|
||||
GenericRawResults<CardInfo> rawResults = cardDao.queryRaw(
|
||||
"select * from " + CardRepository.VERSION_ENTITY_NAME + " where lower(name) = '" + sqlName + "'",
|
||||
cardDao.getRawRowMapper());
|
||||
List<CardInfo> result = new ArrayList<>();
|
||||
for (CardInfo cardinfo : rawResults) {
|
||||
result.add(cardinfo);
|
||||
}
|
||||
return result;
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(CardRepository.class).error("Error during execution of raw sql statement", ex);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<CardInfo> findCards(CardCriteria criteria) {
|
||||
try {
|
||||
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
||||
|
|
|
@ -112,7 +112,7 @@ public abstract class DraftCube {
|
|||
cardInfo = cardList.get(0);
|
||||
}
|
||||
} else {
|
||||
cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(cardId.getName());
|
||||
cardInfo = CardRepository.instance.findPreferedCoreExpansionCard(cardId.getName(), false);
|
||||
}
|
||||
|
||||
if (cardInfo != null) {
|
||||
|
|
Loading…
Reference in a new issue