mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-28 01:23:55 -07:00
Refactor: clean up CardDatabase pt2 (#6042)
* findPrintingWithId * remove a param * cleanup up usage of getCardInfo
This commit is contained in:
parent
95190c321c
commit
70b4843bc4
6 changed files with 39 additions and 39 deletions
|
|
@ -15,7 +15,7 @@ EdhrecCommanderResponseCommanderDetailsDisplayWidget::EdhrecCommanderResponseCom
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
commanderPicture = new CardInfoPictureWidget(this);
|
commanderPicture = new CardInfoPictureWidget(this);
|
||||||
commanderPicture->setCard(CardDatabaseManager::getInstance()->getCardInfo(commanderDetails.getName()));
|
commanderPicture->setCard(CardDatabaseManager::getInstance()->getCard({commanderDetails.getName()}));
|
||||||
|
|
||||||
QWidget *currentParent = parentWidget();
|
QWidget *currentParent = parentWidget();
|
||||||
TabEdhRecMain *parentTab = nullptr;
|
TabEdhRecMain *parentTab = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
CardInfoFrameWidget::CardInfoFrameWidget(const QString &cardName, QWidget *parent)
|
CardInfoFrameWidget::CardInfoFrameWidget(QWidget *parent)
|
||||||
: QTabWidget(parent), info(nullptr), viewTransformationButton(nullptr), cardTextOnly(false)
|
: QTabWidget(parent), info(nullptr), viewTransformationButton(nullptr), cardTextOnly(false)
|
||||||
{
|
{
|
||||||
setContentsMargins(3, 3, 3, 3);
|
setContentsMargins(3, 3, 3, 3);
|
||||||
|
|
@ -60,9 +60,6 @@ CardInfoFrameWidget::CardInfoFrameWidget(const QString &cardName, QWidget *paren
|
||||||
tab3->setLayout(tab3Layout);
|
tab3->setLayout(tab3Layout);
|
||||||
|
|
||||||
setViewMode(SettingsCache::instance().getCardInfoViewMode());
|
setViewMode(SettingsCache::instance().getCardInfoViewMode());
|
||||||
|
|
||||||
// TODO: Change this to be by UUID
|
|
||||||
setCard(CardDatabaseManager::getInstance()->getCardInfo(cardName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfoFrameWidget::retranslateUi()
|
void CardInfoFrameWidget::retranslateUi()
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ public:
|
||||||
ImageAndTextView
|
ImageAndTextView
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit CardInfoFrameWidget(const QString &cardName = QString(), QWidget *parent = nullptr);
|
explicit CardInfoFrameWidget(QWidget *parent = nullptr);
|
||||||
CardInfoPtr getInfo()
|
CardInfoPtr getInfo()
|
||||||
{
|
{
|
||||||
return info;
|
return info;
|
||||||
|
|
|
||||||
|
|
@ -227,8 +227,8 @@ QMap<QString, int> DlgSelectSetForCards::getSetsForCards()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
SetToPrintingsMap setMap = infoPtr->getSets();
|
SetToPrintingsMap setMap = infoPtr->getSets();
|
||||||
for (auto it = setMap.begin(); it != setMap.end(); ++it) {
|
for (auto &setName : setMap.keys()) {
|
||||||
setCounts[it.key()]++;
|
setCounts[setName]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ QList<CardInfoPtr> CardDatabase::getCardInfos(const QStringList &cardNames) cons
|
||||||
/**
|
/**
|
||||||
* Looks up the CardInfoPtrs corresponding to the CardRefs
|
* Looks up the CardInfoPtrs corresponding to the CardRefs
|
||||||
*
|
*
|
||||||
* @param cardRefs The cards to look up. If providerId is null for an entry, will look up the generic CardInfo for that
|
* @param cardRefs The cards to look up. If providerId is empty for an entry, will look up the generic CardInfo for that
|
||||||
* entry's cardName.
|
* entry's cardName.
|
||||||
* @return A list of specific printings of cards. Any failed lookups will be ignored and dropped from the resulting
|
* @return A list of specific printings of cards. Any failed lookups will be ignored and dropped from the resulting
|
||||||
* list.
|
* list.
|
||||||
|
|
@ -162,7 +162,7 @@ QList<CardInfoPtr> CardDatabase::getCards(const QList<CardRef> &cardRefs) const
|
||||||
/**
|
/**
|
||||||
* Looks up the CardInfoPtr corresponding to the CardRef
|
* Looks up the CardInfoPtr corresponding to the CardRef
|
||||||
*
|
*
|
||||||
* @param cardRef The card to look up. If providerId is null, will look up the generic CardInfo for the cardName.
|
* @param cardRef The card to look up. If providerId is empty, will look up the generic CardInfo for the cardName.
|
||||||
* @return A specific printing of a card, or null if not found.
|
* @return A specific printing of a card, or null if not found.
|
||||||
*/
|
*/
|
||||||
CardInfoPtr CardDatabase::getCard(const CardRef &cardRef) const
|
CardInfoPtr CardDatabase::getCard(const CardRef &cardRef) const
|
||||||
|
|
@ -172,17 +172,16 @@ CardInfoPtr CardDatabase::getCard(const CardRef &cardRef) const
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &printings : info->getSets()) {
|
PrintingInfo printing = findPrintingWithId(info, cardRef.providerId);
|
||||||
for (const auto &printing : printings) {
|
|
||||||
if (printing.getProperty("uuid") == cardRef.providerId) {
|
if (!printing.getSet()) {
|
||||||
CardInfoPtr cardFromSpecificSet = info->clone();
|
return {};
|
||||||
cardFromSpecificSet->setPixmapCacheKey(QLatin1String("card_") + QString(info->getName()) +
|
|
||||||
QString("_") + QString(printing.getProperty("uuid")));
|
|
||||||
return cardFromSpecificSet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
|
CardInfoPtr cardFromSpecificSet = info->clone();
|
||||||
|
cardFromSpecificSet->setPixmapCacheKey(QLatin1String("card_") + QString(info->getName()) + QString("_") +
|
||||||
|
QString(printing.getProperty("uuid")));
|
||||||
|
return cardFromSpecificSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
|
CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
|
||||||
|
|
@ -193,7 +192,7 @@ CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
|
||||||
/**
|
/**
|
||||||
* Looks up the CardInfoPtr by CardRef, simplifying the name if required.
|
* Looks up the CardInfoPtr by CardRef, simplifying the name if required.
|
||||||
*
|
*
|
||||||
* @param cardRef The card to look up. If providerId is null, will look up the generic CardInfo for the cardName.
|
* @param cardRef The card to look up. If providerId is empty, will look up the generic CardInfo for the cardName.
|
||||||
* @return A specific printing of a card, or null if not found.
|
* @return A specific printing of a card, or null if not found.
|
||||||
*/
|
*/
|
||||||
CardInfoPtr CardDatabase::guessCard(const CardRef &cardRef) const
|
CardInfoPtr CardDatabase::guessCard(const CardRef &cardRef) const
|
||||||
|
|
@ -330,6 +329,26 @@ void CardDatabase::refreshPreferredPrintings()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the PrintingInfo in the cardInfo that has the given uuid field.
|
||||||
|
*
|
||||||
|
* @param cardInfo The CardInfo to search
|
||||||
|
* @param providerId The uuid to look for
|
||||||
|
* @return The PrintingInfo, or a default-constructed PrintingInfo if not found.
|
||||||
|
*/
|
||||||
|
PrintingInfo CardDatabase::findPrintingWithId(const CardInfoPtr &cardInfo, const QString &providerId)
|
||||||
|
{
|
||||||
|
for (const auto &printings : cardInfo->getSets()) {
|
||||||
|
for (const auto &printing : printings) {
|
||||||
|
if (printing.getProperty("uuid") == providerId) {
|
||||||
|
return printing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return PrintingInfo();
|
||||||
|
}
|
||||||
|
|
||||||
PrintingInfo CardDatabase::getPreferredPrinting(const QString &cardName) const
|
PrintingInfo CardDatabase::getPreferredPrinting(const QString &cardName) const
|
||||||
{
|
{
|
||||||
CardInfoPtr cardInfo = getCardInfo(cardName);
|
CardInfoPtr cardInfo = getCardInfo(cardName);
|
||||||
|
|
@ -375,24 +394,7 @@ PrintingInfo CardDatabase::getSpecificPrinting(const CardRef &cardRef) const
|
||||||
return PrintingInfo(nullptr);
|
return PrintingInfo(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetToPrintingsMap setMap = cardInfo->getSets();
|
return findPrintingWithId(cardInfo, cardRef.providerId);
|
||||||
if (setMap.empty()) {
|
|
||||||
return PrintingInfo(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &printings : setMap) {
|
|
||||||
for (auto &cardInfoForSet : printings) {
|
|
||||||
if (cardInfoForSet.getProperty("uuid") == cardRef.providerId) {
|
|
||||||
return cardInfoForSet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cardRef.providerId.isNull()) {
|
|
||||||
return getPreferredPrinting(cardRef.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return PrintingInfo(nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintingInfo CardDatabase::getSpecificPrinting(const QString &cardName,
|
PrintingInfo CardDatabase::getSpecificPrinting(const QString &cardName,
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ public:
|
||||||
QList<CardInfoPtr> getCards(const QList<CardRef> &cardRefs) const;
|
QList<CardInfoPtr> getCards(const QList<CardRef> &cardRefs) const;
|
||||||
[[nodiscard]] CardInfoPtr getCard(const CardRef &cardRef) const;
|
[[nodiscard]] CardInfoPtr getCard(const CardRef &cardRef) const;
|
||||||
|
|
||||||
|
static PrintingInfo findPrintingWithId(const CardInfoPtr &cardInfo, const QString &providerId);
|
||||||
[[nodiscard]] PrintingInfo getPreferredPrinting(const QString &cardName) const;
|
[[nodiscard]] PrintingInfo getPreferredPrinting(const QString &cardName) const;
|
||||||
[[nodiscard]] PrintingInfo getPreferredPrinting(const CardInfoPtr &cardInfo) const;
|
[[nodiscard]] PrintingInfo getPreferredPrinting(const CardInfoPtr &cardInfo) const;
|
||||||
[[nodiscard]] PrintingInfo getSpecificPrinting(const CardRef &cardRef) const;
|
[[nodiscard]] PrintingInfo getSpecificPrinting(const CardRef &cardRef) const;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue