do some guesswork if cards can't be found (#4131)
modify up the simplifyCardName function to ignore right halves add guessCard function that prioritises full card names the simple ones fix imports for misformatted split cards or double faced cards introduces a small concession: not completely formatted names with a shared name on the left side will get mixed up, eg "bind" but not "Bind" this should be fine considering how this would fix a lot more cards
This commit is contained in:
parent
d07bf1211a
commit
ca5f1dd434
6 changed files with 30 additions and 13 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
@ -291,22 +292,23 @@ void CardInfo::refreshCachedSetNames()
|
||||||
|
|
||||||
QString CardInfo::simplifyName(const QString &name)
|
QString CardInfo::simplifyName(const QString &name)
|
||||||
{
|
{
|
||||||
QString simpleName(name);
|
static const QRegularExpression spaceOrSplit("(\\s+|\\/\\/.*)");
|
||||||
|
static const QRegularExpression nonAlnum("[^a-z0-9]");
|
||||||
|
|
||||||
|
QString simpleName = name.toLower();
|
||||||
|
|
||||||
|
// remove spaces and right halves of split cards
|
||||||
|
simpleName.remove(spaceOrSplit);
|
||||||
|
|
||||||
// So Aetherling would work, but not Ætherling since 'Æ' would get replaced
|
// So Aetherling would work, but not Ætherling since 'Æ' would get replaced
|
||||||
// with nothing.
|
// with nothing.
|
||||||
simpleName.replace("æ", "ae");
|
simpleName.replace("æ", "ae");
|
||||||
simpleName.replace("Æ", "AE");
|
|
||||||
|
|
||||||
// Replace Jötun Grunt with Jotun Grunt.
|
// Replace Jötun Grunt with Jotun Grunt.
|
||||||
simpleName = simpleName.normalized(QString::NormalizationForm_KD);
|
simpleName = simpleName.normalized(QString::NormalizationForm_KD);
|
||||||
|
|
||||||
// Replace dashes with spaces so that we can say "garruk the veil cursed"
|
// remove all non alphanumeric characters from the name
|
||||||
// instead of the unintuitive "garruk the veilcursed".
|
simpleName.remove(nonAlnum);
|
||||||
simpleName = simpleName.replace("-", " ");
|
|
||||||
|
|
||||||
simpleName.remove(QRegExp("[^a-zA-Z0-9 ]"));
|
|
||||||
simpleName = simpleName.toLower();
|
|
||||||
return simpleName;
|
return simpleName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,6 +439,19 @@ CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
|
||||||
return getCardFromMap(simpleNameCards, CardInfo::simplifyName(cardName));
|
return getCardFromMap(simpleNameCards, CardInfo::simplifyName(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CardInfoPtr CardDatabase::guessCard(const QString &cardName) const
|
||||||
|
{
|
||||||
|
CardInfoPtr temp = getCard(cardName);
|
||||||
|
if (temp == nullptr) { // get card by simple name instead
|
||||||
|
temp = getCardBySimpleName(cardName);
|
||||||
|
if (temp == nullptr) { // still could not find the card, so simplify the cardName too
|
||||||
|
QString simpleCardName = CardInfo::simplifyName(cardName);
|
||||||
|
temp = getCardBySimpleName(simpleCardName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return temp; // returns nullptr if not found
|
||||||
|
}
|
||||||
|
|
||||||
CardSetPtr CardDatabase::getSet(const QString &setName)
|
CardSetPtr CardDatabase::getSet(const QString &setName)
|
||||||
{
|
{
|
||||||
if (sets.contains(setName)) {
|
if (sets.contains(setName)) {
|
||||||
|
|
|
@ -409,6 +409,7 @@ public:
|
||||||
void removeCard(CardInfoPtr card);
|
void removeCard(CardInfoPtr card);
|
||||||
CardInfoPtr getCard(const QString &cardName) const;
|
CardInfoPtr getCard(const QString &cardName) const;
|
||||||
QList<CardInfoPtr> getCards(const QStringList &cardNames) const;
|
QList<CardInfoPtr> getCards(const QStringList &cardNames) const;
|
||||||
|
CardInfoPtr guessCard(const QString &cardName) const;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a card by its simple name. The name will be simplified in this
|
* Get a card by its simple name. The name will be simplified in this
|
||||||
|
|
|
@ -107,7 +107,7 @@ void CardFrame::setCard(CardInfoPtr card)
|
||||||
|
|
||||||
void CardFrame::setCard(const QString &cardName)
|
void CardFrame::setCard(const QString &cardName)
|
||||||
{
|
{
|
||||||
setCard(db->getCardBySimpleName(cardName));
|
setCard(db->guessCard(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardFrame::setCard(AbstractCardItem *card)
|
void CardFrame::setCard(AbstractCardItem *card)
|
||||||
|
|
|
@ -65,9 +65,10 @@ void CardInfoWidget::setCard(CardInfoPtr card)
|
||||||
|
|
||||||
void CardInfoWidget::setCard(const QString &cardName)
|
void CardInfoWidget::setCard(const QString &cardName)
|
||||||
{
|
{
|
||||||
setCard(db->getCardBySimpleName(cardName));
|
setCard(db->guessCard(cardName));
|
||||||
if (!info)
|
if (info == nullptr) {
|
||||||
text->setInvalidCardName(cardName);
|
text->setInvalidCardName(cardName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoWidget::setCard(AbstractCardItem *card)
|
void CardInfoWidget::setCard(AbstractCardItem *card)
|
||||||
|
|
|
@ -291,7 +291,7 @@ QString DeckLoader::getCardZoneFromName(QString cardName, QString currentZoneNam
|
||||||
QString DeckLoader::getCompleteCardName(const QString cardName) const
|
QString DeckLoader::getCompleteCardName(const QString cardName) const
|
||||||
{
|
{
|
||||||
if (db) {
|
if (db) {
|
||||||
CardInfoPtr temp = db->getCardBySimpleName(cardName);
|
CardInfoPtr temp = db->guessCard(cardName);
|
||||||
if (temp) {
|
if (temp) {
|
||||||
return temp->getName();
|
return temp->getName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1242,7 +1242,7 @@ void Player::actCreateToken()
|
||||||
|
|
||||||
lastTokenName = dlg.getName();
|
lastTokenName = dlg.getName();
|
||||||
lastTokenPT = dlg.getPT();
|
lastTokenPT = dlg.getPT();
|
||||||
CardInfoPtr correctedCard = db->getCardBySimpleName(lastTokenName);
|
CardInfoPtr correctedCard = db->guessCard(lastTokenName);
|
||||||
if (correctedCard) {
|
if (correctedCard) {
|
||||||
lastTokenName = correctedCard->getName();
|
lastTokenName = correctedCard->getName();
|
||||||
lastTokenTableRow = TableZone::clampValidTableRow(2 - correctedCard->getTableRow());
|
lastTokenTableRow = TableZone::clampValidTableRow(2 - correctedCard->getTableRow());
|
||||||
|
|
Loading…
Reference in a new issue