mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 14:32:15 -07:00
Simplify guessCard.
Took 2 minutes
This commit is contained in:
parent
a03771d66b
commit
f6f4cb6ffd
2 changed files with 14 additions and 15 deletions
|
|
@ -69,7 +69,6 @@ void CardDatabase::addCard(CardInfoPtr card)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
auto name = card->getName();
|
auto name = card->getName();
|
||||||
|
|
||||||
// If a card already exists, just add the new set property.
|
// If a card already exists, just add the new set property.
|
||||||
|
|
@ -187,6 +186,15 @@ CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
|
||||||
return simpleNameCards.value(CardInfo::simplifyName(cardName));
|
return simpleNameCards.value(CardInfo::simplifyName(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CardInfoPtr CardDatabase::lookupCardByName(const QString &name) const
|
||||||
|
{
|
||||||
|
if (auto info = getCardInfo(name))
|
||||||
|
return info;
|
||||||
|
if (auto info = getCardBySimpleName(name))
|
||||||
|
return info;
|
||||||
|
return getCardBySimpleName(CardInfo::simplifyName(name));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up the card by CardRef, simplifying the name if required.
|
* Looks up the card by CardRef, simplifying the name if required.
|
||||||
* If the providerId is empty, will default to the preferred printing.
|
* If the providerId is empty, will default to the preferred printing.
|
||||||
|
|
@ -197,21 +205,11 @@ CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
|
||||||
*/
|
*/
|
||||||
ExactCard CardDatabase::guessCard(const CardRef &cardRef) const
|
ExactCard CardDatabase::guessCard(const CardRef &cardRef) const
|
||||||
{
|
{
|
||||||
CardInfoPtr temp = getCardInfo(cardRef.name);
|
auto card = lookupCardByName(cardRef.name);
|
||||||
|
auto printing =
|
||||||
|
cardRef.providerId.isEmpty() ? getPreferredPrinting(card) : findPrintingWithId(card, cardRef.providerId);
|
||||||
|
|
||||||
if (temp == nullptr) { // get card by simple name instead
|
return ExactCard(card, printing);
|
||||||
temp = getCardBySimpleName(cardRef.name);
|
|
||||||
if (temp == nullptr) { // still could not find the card, so simplify the cardName too
|
|
||||||
const auto &simpleCardName = CardInfo::simplifyName(cardRef.name);
|
|
||||||
temp = getCardBySimpleName(simpleCardName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cardRef.providerId.isEmpty() || cardRef.providerId.isNull()) {
|
|
||||||
return ExactCard(temp, getPreferredPrinting(temp));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ExactCard(temp, findPrintingWithId(temp, cardRef.providerId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExactCard CardDatabase::getRandomCard()
|
ExactCard CardDatabase::getRandomCard()
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ public:
|
||||||
* function, so you don't need to simplify it beforehand.
|
* function, so you don't need to simplify it beforehand.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] CardInfoPtr getCardBySimpleName(const QString &cardName) const;
|
[[nodiscard]] CardInfoPtr getCardBySimpleName(const QString &cardName) const;
|
||||||
|
CardInfoPtr lookupCardByName(const QString &name) const;
|
||||||
|
|
||||||
CardSetPtr getSet(const QString &setName);
|
CardSetPtr getSet(const QString &setName);
|
||||||
const CardNameMap &getCardList() const
|
const CardNameMap &getCardList() const
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue