Refactor: use ExactCard to represent specific printings (#6049)

* Create new class

* Update CardInfo and CardDatabase

* Use new class instead of CardInfoPtr

* fix cmake
This commit is contained in:
RickyRister 2025-07-28 18:04:45 -07:00 committed by GitHub
parent 4a2a646943
commit ae2c55c33b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
79 changed files with 715 additions and 642 deletions

View file

@ -57,22 +57,29 @@ void AbstractCardItem::pixmapUpdated()
void AbstractCardItem::refreshCardInfo()
{
info = CardDatabaseManager::getInstance()->getCard(cardRef);
exactCard = CardDatabaseManager::getInstance()->getCard(cardRef);
if (!info && !cardRef.name.isEmpty()) {
QVariantHash properties = QVariantHash();
info = CardInfo::newInstance(cardRef.name, "", true, QVariantHash(), QList<CardRelation *>(),
QList<CardRelation *>(), SetToPrintingsMap(), false, false, -1, false);
if (!exactCard && !cardRef.name.isEmpty()) {
auto info = CardInfo::newInstance(cardRef.name, "", true, {}, {}, {}, {}, false, false, -1, false);
exactCard = ExactCard(info);
}
if (info.data()) {
connect(info.data(), &CardInfo::pixmapUpdated, this, &AbstractCardItem::pixmapUpdated);
if (exactCard) {
connect(exactCard.getCardPtr().data(), &CardInfo::pixmapUpdated, this, &AbstractCardItem::pixmapUpdated);
}
cacheBgColor();
update();
}
/**
* Convenience method to get the CardInfo of the exactCard
* @return A const reference to the CardInfo, or an empty CardInfo if card was null
*/
const CardInfo &AbstractCardItem::getCardInfo() const
{
return exactCard.getInfo();
}
void AbstractCardItem::setRealZValue(qreal _zValue)
{
realZValue = _zValue;
@ -116,7 +123,7 @@ void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedS
} else {
// don't even spend time trying to load the picture if our size is too small
if (translatedSize.width() > 10) {
PictureLoader::getPixmap(translatedPixmap, info, translatedSize.toSize());
PictureLoader::getPixmap(translatedPixmap, exactCard, translatedSize.toSize());
if (translatedPixmap.isNull())
paintImage = false;
} else {
@ -191,8 +198,8 @@ void AbstractCardItem::setCardRef(const CardRef &_cardRef)
}
emit deleteCardInfoPopup(cardRef.name);
if (info) {
disconnect(info.data(), nullptr, this, nullptr);
if (exactCard) {
disconnect(exactCard.getCardPtr().data(), nullptr, this, nullptr);
}
cardRef = _cardRef;
@ -224,8 +231,7 @@ void AbstractCardItem::cacheBgColor()
{
QChar colorChar;
if (color.isEmpty()) {
if (info)
colorChar = info->getColorChar();
colorChar = exactCard.getInfo().getColorChar();
} else {
colorChar = color.at(0);
}

View file

@ -1,7 +1,7 @@
#ifndef ABSTRACTCARDITEM_H
#define ABSTRACTCARDITEM_H
#include "../cards/card_info.h"
#include "../cards/exact_card.h"
#include "arrow_target.h"
#include "card_ref.h"
@ -14,7 +14,7 @@ class AbstractCardItem : public ArrowTarget
{
Q_OBJECT
protected:
CardInfoPtr info;
ExactCard exactCard;
int id;
CardRef cardRef;
bool tapped;
@ -58,10 +58,11 @@ public:
QSizeF getTranslatedSize(QPainter *painter) const;
void paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
CardInfoPtr getInfo() const
ExactCard getCard() const
{
return info;
return exactCard;
}
const CardInfo &getCardInfo() const;
int getId() const
{
return id;

View file

@ -237,10 +237,10 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
}
if (startZone->getName().compare("hand") == 0) {
startCard->playCard(false);
CardInfoPtr ci = startCard->getInfo();
if (ci && (((!SettingsCache::instance().getPlayToStack() && ci->getTableRow() == 3) ||
((SettingsCache::instance().getPlayToStack() && ci->getTableRow() != 0) &&
startCard->getZone()->getName().toStdString() != "stack"))))
CardInfoPtr ci = startCard->getCard().getCardPtr();
if (ci && ((!SettingsCache::instance().getPlayToStack() && ci->getTableRow() == 3) ||
(SettingsCache::instance().getPlayToStack() && ci->getTableRow() != 0 &&
startCard->getZone()->getName().toStdString() != "stack")))
cmd.set_start_zone("stack");
else
cmd.set_start_zone(SettingsCache::instance().getPlayToStack() ? "stack" : "table");

View file

@ -107,7 +107,7 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
painter->save();
transformPainter(painter, translatedSize, tapAngle);
if (!getFaceDown() && info && pt == info->getPowTough()) {
if (!getFaceDown() && pt == exactCard.getInfo().getPowTough()) {
painter->setPen(Qt::white);
} else {
painter->setPen(QColor(255, 150, 0)); // dark orange

View file

@ -77,12 +77,12 @@ void CardList::sortBy(const QList<SortOption> &option)
* @param c The card info
* @param appendAtEnd For multicolor cards, whether to also append the entire color string at the end.
*/
static QString getColorSortString(CardInfoPtr c, bool appendAtEnd)
static QString getColorSortString(const CardInfo &c, bool appendAtEnd)
{
QString colors = c->getColors();
QString colors = c.getColors();
switch (colors.size()) {
case 0: {
if (c->getCardType().contains("Land")) {
if (c.getCardType().contains("Land")) {
return "a_land";
} else {
return "b_colorless";
@ -119,33 +119,36 @@ std::function<QString(CardItem *)> CardList::getExtractorFor(SortOption option)
case NoSort:
return [](CardItem *) { return ""; };
case SortByMainType:
return [](CardItem *c) { return c->getInfo() ? c->getInfo()->getMainCardType() : ""; };
return [](CardItem *c) { return c->getCardInfo().getMainCardType(); };
case SortByManaValue:
// getCmc returns the int as a string. We pad with 0's so that string comp also works on it
return [](CardItem *c) { return c->getInfo() ? c->getInfo()->getCmc().rightJustified(4, '0') : ""; };
return [](CardItem *c) { return c->getCard() ? c->getCardInfo().getCmc().rightJustified(4, '0') : ""; };
case SortByColorGrouping:
return [](CardItem *c) { return c->getInfo() ? getColorSortString(c->getInfo(), false) : ""; };
return [](CardItem *c) { return c->getCard() ? getColorSortString(c->getCardInfo(), false) : ""; };
case SortByName:
return [](CardItem *c) { return c->getName(); };
case SortByType:
return [](CardItem *c) { return c->getInfo() ? c->getInfo()->getCardType() : ""; };
return [](CardItem *c) { return c->getCardInfo().getCardType(); };
case SortByManaCost:
return [](CardItem *c) {
auto info = c->getInfo();
if (!info)
return QString("");
if (!c->getCard()) {
return QString();
}
auto info = c->getCardInfo();
// calculation copied from CardDatabaseModel.
// we pad the cmc and also append the mana cost to the end so same cmc cards still have a sort order
return QString("%1%2").arg(info->getCmc(), 4, QChar('0')).arg(info->getManaCost());
return QString("%1%2").arg(info.getCmc(), 4, QChar('0')).arg(info.getManaCost());
};
case SortByColors:
return [](CardItem *c) { return c->getInfo() ? getColorSortString(c->getInfo(), true) : ""; };
return [](CardItem *c) { return c->getCard() ? getColorSortString(c->getCardInfo(), true) : ""; };
case SortByPt:
// do the same padding trick as above
return [](CardItem *c) { return c->getInfo() ? c->getInfo()->getPowTough().rightJustified(10, '0') : ""; };
return
[](CardItem *c) { return c->getCard() ? c->getCardInfo().getPowTough().rightJustified(10, '0') : ""; };
case SortBySet:
return [](CardItem *c) { return c->getInfo() ? c->getInfo()->getSetsNames() : ""; };
return [](CardItem *c) { return c->getCardInfo().getSetsNames(); };
case SortByPrinting:
return [](CardItem *c) { return c->getProviderId(); };
}

View file

@ -110,11 +110,10 @@ void CardDatabase::removeCard(CardInfoPtr card)
}
/**
* Looks up the generic cardInfo (the CardInfoPtr that does not refer to a specific printing) corresponding to the
* cardName.
* Looks up the cardInfo corresponding to the cardName.
*
* @param cardName The card name to look up
* @return A generic CardInfoPtr, or null if not corresponding CardInfo is found.
* @return A CardInfoPtr, or null if not corresponding CardInfo is found.
*/
CardInfoPtr CardDatabase::getCardInfo(const QString &cardName) const
{
@ -122,10 +121,10 @@ CardInfoPtr CardDatabase::getCardInfo(const QString &cardName) const
}
/**
* Looks up the generic cardInfos (the CardInfoPtr that does not refer to a specific printing) for a list of card names.
* Looks up the cardInfos for a list of card names.
*
* @param cardNames The card names to look up
* @return A List of generic CardInfoPtr. Any failed lookups will be ignored and dropped from the resulting list
* @return A List of CardInfoPtr. Any failed lookups will be ignored and dropped from the resulting list
*/
QList<CardInfoPtr> CardDatabase::getCardInfos(const QStringList &cardNames) const
{
@ -140,48 +139,46 @@ QList<CardInfoPtr> CardDatabase::getCardInfos(const QStringList &cardNames) cons
}
/**
* Looks up the CardInfoPtrs corresponding to the CardRefs
* Looks up the cards corresponding to the CardRefs.
* If the providerId is empty, will default to the preferred printing.
* If providerId is given but not found, the PrintingInfo will be empty.
*
* @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.
* @return A list of specific printings of cards. Any failed lookups will be ignored and dropped from the resulting
* list.
* @param cardRefs The cards to look up. If providerId is empty for an entry, will default to the preferred printing for
* that entry. If providerId is given but not found, the PrintingInfo will be empty for that entry.
* @return A list of cards. Any failed lookups will be ignored and dropped from the resulting list.
*/
QList<CardInfoPtr> CardDatabase::getCards(const QList<CardRef> &cardRefs) const
QList<ExactCard> CardDatabase::getCards(const QList<CardRef> &cardRefs) const
{
QList<CardInfoPtr> cardInfos;
QList<ExactCard> cards;
for (const auto &cardRef : cardRefs) {
CardInfoPtr ptr = getCard(cardRef);
if (ptr)
cardInfos.append(ptr);
ExactCard card = getCard(cardRef);
if (card)
cards.append(card);
}
return cardInfos;
return cards;
}
/**
* Looks up the CardInfoPtr corresponding to the CardRef
* Looks up the card corresponding to the CardRef.
* If the providerId is empty, will default to the preferred printing.
* If providerId is given but not found, the PrintingInfo will be empty.
*
* @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.
* @param cardRef The card to look up.
* @return A specific printing of a card, or empty if not found.
*/
CardInfoPtr CardDatabase::getCard(const CardRef &cardRef) const
ExactCard CardDatabase::getCard(const CardRef &cardRef) const
{
auto info = getCardInfo(cardRef.name);
if (cardRef.providerId.isNull() || cardRef.providerId.isEmpty() || info.isNull()) {
return info;
}
PrintingInfo printing = findPrintingWithId(info, cardRef.providerId);
if (!printing.getSet()) {
if (info.isNull()) {
return {};
}
CardInfoPtr cardFromSpecificSet = info->clone();
cardFromSpecificSet->setPixmapCacheKey(QLatin1String("card_") + QString(info->getName()) + QString("_") +
QString(printing.getProperty("uuid")));
return cardFromSpecificSet;
if (cardRef.providerId.isEmpty() || cardRef.providerId.isNull()) {
return ExactCard(info, getPreferredPrinting(info));
}
return ExactCard(info, findPrintingWithId(info, cardRef.providerId));
}
CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
@ -190,14 +187,16 @@ CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
}
/**
* Looks up the CardInfoPtr 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 providerId is given but not found, the PrintingInfo will be empty.
*
* @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.
* @param cardRef The card to look up.
* @return A specific printing of a card, or empty if not found.
*/
CardInfoPtr CardDatabase::guessCard(const CardRef &cardRef) const
ExactCard CardDatabase::guessCard(const CardRef &cardRef) const
{
CardInfoPtr temp = getCard(cardRef);
CardInfoPtr temp = getCardInfo(cardRef.name);
if (temp == nullptr) { // get card by simple name instead
temp = getCardBySimpleName(cardRef.name);
@ -206,7 +205,12 @@ CardInfoPtr CardDatabase::guessCard(const CardRef &cardRef) const
temp = getCardBySimpleName(simpleCardName);
}
}
return temp; // returns nullptr if not found
if (cardRef.providerId.isEmpty() || cardRef.providerId.isNull()) {
return ExactCard(temp, getPreferredPrinting(temp));
}
return ExactCard(temp, findPrintingWithId(temp, cardRef.providerId));
}
CardSetPtr CardDatabase::getSet(const QString &setName)
@ -303,8 +307,6 @@ LoadStatus CardDatabase::loadCardDatabases()
// AFTER all the cards have been loaded
// Refresh the pixmap cache keys for all cards by setting them to the UUID of the preferred printing
refreshPreferredPrintings();
// resolve the reverse-related tags
refreshCachedReverseRelatedCards();
@ -321,12 +323,25 @@ LoadStatus CardDatabase::loadCardDatabases()
return loadStatus;
}
void CardDatabase::refreshPreferredPrintings()
/**
* Gets the card representing the preferred printing of the cardInfo
*
* @param cardInfo The cardInfo to find the preferred printing for
* @return A specific printing of a card
*/
ExactCard CardDatabase::getPreferredCard(const CardInfoPtr &cardInfo) const
{
for (const CardInfoPtr &card : cards) {
card->setPixmapCacheKey(QLatin1String("card_") + QString(card->getName()) + QString("_") +
QString(getPreferredPrintingProviderId(card->getName())));
return ExactCard(cardInfo, getPreferredPrinting(cardInfo));
}
PrintingInfo CardDatabase::getSpecificPrinting(const CardRef &cardRef) const
{
CardInfoPtr cardInfo = getCardInfo(cardRef.name);
if (!cardInfo) {
return PrintingInfo(nullptr);
}
return findPrintingWithId(cardInfo, cardRef.providerId);
}
/**
@ -387,16 +402,6 @@ PrintingInfo CardDatabase::getPreferredPrinting(const CardInfoPtr &cardInfo) con
return PrintingInfo(nullptr);
}
PrintingInfo CardDatabase::getSpecificPrinting(const CardRef &cardRef) const
{
CardInfoPtr cardInfo = getCardInfo(cardRef.name);
if (!cardInfo) {
return PrintingInfo(nullptr);
}
return findPrintingWithId(cardInfo, cardRef.providerId);
}
PrintingInfo CardDatabase::getSpecificPrinting(const QString &cardName,
const QString &setShortName,
const QString &collectorNumber) const
@ -453,25 +458,6 @@ bool CardDatabase::isPreferredPrinting(const CardRef &cardRef) const
return cardRef.providerId == getPreferredPrintingProviderId(cardRef.name);
}
PrintingInfo CardDatabase::getSetInfoForCard(const CardInfoPtr &_card)
{
const SetToPrintingsMap &setMap = _card->getSets();
if (setMap.empty()) {
return PrintingInfo(nullptr);
}
for (const auto &printings : setMap) {
for (const auto &cardInfoForSet : printings) {
if (QLatin1String("card_") + _card->getName() + QString("_") + cardInfoForSet.getUuid() ==
_card->getPixmapCacheKey()) {
return cardInfoForSet;
}
}
}
return PrintingInfo(nullptr);
}
void CardDatabase::refreshCachedReverseRelatedCards()
{
for (const CardInfoPtr &card : cards)

View file

@ -2,7 +2,7 @@
#define CARDDATABASE_H
#include "../common/card_ref.h"
#include "card_info.h"
#include "exact_card.h"
#include <QBasicMutex>
#include <QDate>
@ -69,8 +69,10 @@ public:
[[nodiscard]] CardInfoPtr getCardInfo(const QString &cardName) const;
[[nodiscard]] QList<CardInfoPtr> getCardInfos(const QStringList &cardNames) const;
QList<CardInfoPtr> getCards(const QList<CardRef> &cardRefs) const;
[[nodiscard]] CardInfoPtr getCard(const CardRef &cardRef) const;
QList<ExactCard> getCards(const QList<CardRef> &cardRefs) const;
[[nodiscard]] ExactCard getCard(const CardRef &cardRef) const;
[[nodiscard]] ExactCard getPreferredCard(const CardInfoPtr &cardInfo) const;
static PrintingInfo findPrintingWithId(const CardInfoPtr &cardInfo, const QString &providerId);
[[nodiscard]] PrintingInfo getPreferredPrinting(const QString &cardName) const;
@ -81,7 +83,7 @@ public:
QString getPreferredPrintingProviderId(const QString &cardName) const;
bool isPreferredPrinting(const CardRef &cardRef) const;
[[nodiscard]] CardInfoPtr guessCard(const CardRef &cardRef) const;
[[nodiscard]] ExactCard guessCard(const CardRef &cardRef) const;
/*
* Get a card by its simple name. The name will be simplified in this
@ -90,7 +92,6 @@ public:
[[nodiscard]] CardInfoPtr getCardBySimpleName(const QString &cardName) const;
CardSetPtr getSet(const QString &setName);
static PrintingInfo getSetInfoForCard(const CardInfoPtr &_card);
const CardNameMap &getCardList() const
{
return cards;
@ -111,7 +112,6 @@ public:
public slots:
LoadStatus loadCardDatabases();
void refreshPreferredPrintings();
void addCard(CardInfoPtr card);
void addSet(CardSetPtr set);
protected slots:

View file

@ -242,17 +242,11 @@ CardInfo::CardInfo(const QString &_name,
reverseRelatedCards(_reverseRelatedCards), setsToPrintings(std::move(_sets)), cipt(_cipt),
landscapeOrientation(_landscapeOrientation), tableRow(_tableRow), upsideDownArt(_upsideDownArt)
{
pixmapCacheKey = QLatin1String("card_") + name;
simpleName = CardInfo::simplifyName(name);
refreshCachedSetNames();
}
CardInfo::~CardInfo()
{
PictureLoader::clearPixmapCache(smartThis);
}
CardInfoPtr CardInfo::newInstance(const QString &_name)
{
return newInstance(_name, QString(), false, QVariantHash(), QList<CardRelation *>(), QList<CardRelation *>(),

View file

@ -148,7 +148,7 @@ public:
class PrintingInfo
{
public:
explicit PrintingInfo(const CardSetPtr &_set = QSharedPointer<CardSet>(nullptr));
explicit PrintingInfo(const CardSetPtr &_set = nullptr);
~PrintingInfo() = default;
bool operator==(const PrintingInfo &other) const
@ -191,8 +191,6 @@ private:
QString name;
// The name without punctuation or capitalization, for better card name recognition.
QString simpleName;
// The key used to identify this card in the cache
QString pixmapCacheKey;
// card text
QString text;
// whether this is not a "real" card but a token
@ -228,14 +226,13 @@ public:
int _tableRow,
bool _upsideDownArt);
CardInfo(const CardInfo &other)
: QObject(other.parent()), name(other.name), simpleName(other.simpleName), pixmapCacheKey(other.pixmapCacheKey),
text(other.text), isToken(other.isToken), properties(other.properties), relatedCards(other.relatedCards),
: QObject(other.parent()), name(other.name), simpleName(other.simpleName), text(other.text),
isToken(other.isToken), properties(other.properties), relatedCards(other.relatedCards),
reverseRelatedCards(other.reverseRelatedCards), reverseRelatedCardsToMe(other.reverseRelatedCardsToMe),
setsToPrintings(other.setsToPrintings), setsNames(other.setsNames), cipt(other.cipt),
landscapeOrientation(other.landscapeOrientation), tableRow(other.tableRow), upsideDownArt(other.upsideDownArt)
{
}
~CardInfo() override;
static CardInfoPtr newInstance(const QString &_name);
@ -273,14 +270,6 @@ public:
{
return simpleName;
}
void setPixmapCacheKey(QString _pixmapCacheKey)
{
pixmapCacheKey = _pixmapCacheKey;
}
const QString &getPixmapCacheKey() const
{
return pixmapCacheKey;
}
const QString &getText() const
{
@ -321,20 +310,6 @@ public:
{
return setsNames;
}
QString getSetProperty(const QString &setName, const QString &propertyName) const
{
if (!setsToPrintings.contains(setName))
return "";
for (const auto &set : setsToPrintings[setName]) {
if (QLatin1String("card_") + this->getName() + QString("_") + QString(set.getProperty("uuid")) ==
this->getPixmapCacheKey()) {
return set.getProperty(propertyName);
}
}
return setsToPrintings[setName][0].getProperty(propertyName);
}
// related cards
const QList<CardRelation *> &getRelatedCards() const
@ -397,18 +372,9 @@ public:
const QString getPowTough() const;
void setPowTough(const QString &value);
// methods using per-set properties
QString getCustomPicURL(const QString &set) const
{
return getSetProperty(set, "picurl");
}
QString getCorrectedName() const;
void addToSet(const CardSetPtr &_set, PrintingInfo _info = PrintingInfo());
void combineLegalities(const QVariantHash &props);
void emitPixmapUpdated()
{
emit pixmapUpdated();
}
void refreshCachedSetNames();
/**
@ -418,7 +384,11 @@ public:
static QString simplifyName(const QString &name);
signals:
void pixmapUpdated();
/**
* Emit this when a pixmap for this card finishes loading.
* @param printing The specific printing the pixmap is for.
*/
void pixmapUpdated(const PrintingInfo &printing);
void cardInfoChanged(CardInfoPtr card);
};

View file

@ -0,0 +1,79 @@
#include "exact_card.h"
/**
* Default constructor.
* This will set the CardInfoPtr to null.
* The printing will be the default-constructed PrintingInfo.
*/
ExactCard::ExactCard()
{
}
/**
* @param _card The card. Can be null.
* @param _printing The printing. Can be empty.
*/
ExactCard::ExactCard(const CardInfoPtr &_card, const PrintingInfo &_printing) : card(_card), printing(_printing)
{
}
bool ExactCard::operator==(const ExactCard &other) const
{
return this->card == other.card && this->printing == other.printing;
}
/**
* Convenience method to safely get the card's name.
* @return The name in the CardInfo, or an empty string if card is null
*/
QString ExactCard::getName() const
{
return card.isNull() ? "" : card->getName();
}
/**
* Gets a view of the underlying cardInfoPtr.
* @return A const reference to the CardInfo, or an empty CardInfo if card is null
*/
const CardInfo &ExactCard::getInfo() const
{
if (card.isNull()) {
static CardInfoPtr emptyCard = CardInfo::newInstance("");
return *emptyCard;
}
return *card;
}
/**
* The key used to identify this exact printing in the cache
*/
QString ExactCard::getPixmapCacheKey() const
{
QString uuid = printing.getUuid();
QString suffix = uuid.isEmpty() ? "" : "_" + uuid;
return QLatin1String("card_") + card->getName() + suffix;
}
/**
* Checks if the card is null or empty.
*/
bool ExactCard::isEmpty() const
{
return card.isNull() || card->getName().isEmpty();
}
/**
* Returns true if isEmpty() is false
*/
ExactCard::operator bool() const
{
return !isEmpty();
}
/**
* Gets the CardInfo to emit the pixmapUpdated signal
*/
void ExactCard::emitPixmapUpdated() const
{
emit card->pixmapUpdated(printing);
}

View file

@ -0,0 +1,46 @@
#ifndef EXACT_CARD_H
#define EXACT_CARD_H
#include "card_info.h"
/**
* Identifies the card along with its exact printing
*/
class ExactCard
{
CardInfoPtr card;
PrintingInfo printing;
public:
ExactCard();
explicit ExactCard(const CardInfoPtr &_card, const PrintingInfo &_printing = PrintingInfo());
/**
* Gets the CardInfoPtr. Can be null.
*/
CardInfoPtr getCardPtr() const
{
return card;
}
/**
* Gets the PrintingInfo. Can be empty.
*/
PrintingInfo getPrinting() const
{
return printing;
}
bool operator==(const ExactCard &other) const;
QString getName() const;
const CardInfo &getInfo() const;
QString getPixmapCacheKey() const;
bool isEmpty() const;
explicit operator bool() const;
void emitPixmapUpdated() const;
};
#endif // EXACT_CARD_H

View file

@ -217,13 +217,13 @@ void DeckViewCardContainer::paint(QPainter *painter, const QStyleOptionGraphicsI
void DeckViewCardContainer::addCard(DeckViewCard *card)
{
cards.append(card);
cardsByType.insert(card->getInfo() ? card->getInfo()->getMainCardType() : "", card);
cardsByType.insert(card->getCard().isEmpty() ? "" : card->getCardInfo().getMainCardType(), card);
}
void DeckViewCardContainer::removeCard(DeckViewCard *card)
{
cards.removeOne(card);
cardsByType.remove(card->getInfo() ? card->getInfo()->getMainCardType() : "", card);
cardsByType.remove(card->getCard().isEmpty() ? "" : card->getCardInfo().getMainCardType(), card);
}
QList<QPair<int, int>> DeckViewCardContainer::getRowsAndCols() const

View file

@ -1488,7 +1488,7 @@ void Player::moveOneCardUntil(CardItem *card)
{
moveTopCardTimer->stop();
const bool isMatch = card && movingCardsUntilFilter.check(card->getInfo());
const bool isMatch = card && movingCardsUntilFilter.check(card->getCard().getCardPtr());
if (isMatch && movingCardsUntilAutoPlay) {
// Directly calling playCard will deadlock, since we are already in the middle of processing an event.
@ -1849,12 +1849,12 @@ void Player::actCreateToken()
lastTokenInfo = dlg.getTokenInfo();
CardInfoPtr correctedCard = CardDatabaseManager::getInstance()->guessCard({lastTokenInfo.name});
ExactCard correctedCard = CardDatabaseManager::getInstance()->guessCard({lastTokenInfo.name});
if (correctedCard) {
lastTokenInfo.name = correctedCard->getName();
lastTokenTableRow = TableZone::clampValidTableRow(2 - correctedCard->getTableRow());
lastTokenInfo.name = correctedCard.getName();
lastTokenTableRow = TableZone::clampValidTableRow(2 - correctedCard.getInfo().getTableRow());
if (lastTokenInfo.pt.isEmpty()) {
lastTokenInfo.pt = correctedCard->getPowTough();
lastTokenInfo.pt = correctedCard.getInfo().getPowTough();
}
}
@ -1904,7 +1904,7 @@ void Player::actCreateRelatedCard()
}
auto *action = static_cast<QAction *>(sender());
// If there is a better way of passing a CardRelation through a QAction, please add it here.
auto relatedCards = sourceCard->getInfo()->getAllRelatedCards();
auto relatedCards = sourceCard->getCardInfo().getAllRelatedCards();
CardRelation *cardRelation = relatedCards.at(action->data().toInt());
/*
@ -1912,9 +1912,9 @@ void Player::actCreateRelatedCard()
* then let's allow it to be created via "create another token"
*/
if (createRelatedFromRelation(sourceCard, cardRelation) && cardRelation->getCanCreateAnother()) {
CardInfoPtr cardInfo =
ExactCard cardInfo =
CardDatabaseManager::getInstance()->getCard({cardRelation->getName(), sourceCard->getProviderId()});
setLastToken(cardInfo);
setLastToken(cardInfo.getCardPtr());
}
}
@ -1925,7 +1925,7 @@ void Player::actCreateAllRelatedCards()
return;
}
auto relatedCards = sourceCard->getInfo()->getAllRelatedCards();
auto relatedCards = sourceCard->getCardInfo().getAllRelatedCards();
if (relatedCards.isEmpty()) {
return;
}
@ -2259,9 +2259,9 @@ void Player::eventCreateToken(const Event_CreateToken &event)
if (!QString::fromStdString(event.pt()).isEmpty()) {
card->setPT(QString::fromStdString(event.pt()));
} else if (!event.face_down()) {
CardInfoPtr dbCard = card->getInfo();
ExactCard dbCard = card->getCard();
if (dbCard) {
card->setPT(dbCard->getPowTough());
card->setPT(dbCard.getInfo().getPowTough());
}
}
card->setColor(QString::fromStdString(event.color()));
@ -2895,12 +2895,14 @@ void Player::playCard(CardItem *card, bool faceDown)
CardToMove *cardToMove = cmd.mutable_cards_to_move()->add_card();
cardToMove->set_card_id(card->getId());
CardInfoPtr info = card->getInfo();
if (!info) {
ExactCard exactCard = card->getCard();
if (!exactCard) {
return;
}
int tableRow = info->getTableRow();
const CardInfo &info = exactCard.getInfo();
int tableRow = info.getTableRow();
bool playToStack = SettingsCache::instance().getPlayToStack();
QString currentZone = card->getZone()->getName();
if (currentZone == "stack" && tableRow == 3) {
@ -2913,13 +2915,13 @@ void Player::playCard(CardItem *card, bool faceDown)
cmd.set_x(-1);
cmd.set_y(0);
} else {
tableRow = faceDown ? 2 : info->getTableRow();
tableRow = faceDown ? 2 : info.getTableRow();
QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - tableRow));
cardToMove->set_face_down(faceDown);
if (!faceDown) {
cardToMove->set_pt(info->getPowTough().toStdString());
cardToMove->set_pt(info.getPowTough().toStdString());
}
cardToMove->set_tapped(!faceDown && info->getCipt());
cardToMove->set_tapped(!faceDown && info.getCipt());
if (tableRow != 3)
cmd.set_target_zone("table");
cmd.set_x(gridPoint.x());
@ -2945,12 +2947,14 @@ void Player::playCardToTable(const CardItem *card, bool faceDown)
CardToMove *cardToMove = cmd.mutable_cards_to_move()->add_card();
cardToMove->set_card_id(card->getId());
CardInfoPtr info = card->getInfo();
if (!info) {
ExactCard exactCard = card->getCard();
if (!exactCard) {
return;
}
int tableRow = faceDown ? 2 : info->getTableRow();
const CardInfo &info = exactCard.getInfo();
int tableRow = faceDown ? 2 : info.getTableRow();
// default instant/sorcery cards to the noncreatures row
if (tableRow > 2) {
tableRow = 1;
@ -2959,9 +2963,9 @@ void Player::playCardToTable(const CardItem *card, bool faceDown)
QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - tableRow));
cardToMove->set_face_down(faceDown);
if (!faceDown) {
cardToMove->set_pt(info->getPowTough().toStdString());
cardToMove->set_pt(info.getPowTough().toStdString());
}
cardToMove->set_tapped(!faceDown && info->getCipt());
cardToMove->set_tapped(!faceDown && info.getCipt());
cmd.set_target_zone("table");
cmd.set_x(gridPoint.x());
cmd.set_y(gridPoint.y());
@ -3280,9 +3284,9 @@ void Player::cardMenuAction()
cmd->set_card_id(card->getId());
cmd->set_face_down(!card->getFaceDown());
if (card->getFaceDown()) {
CardInfoPtr ci = card->getInfo();
if (ci) {
cmd->set_pt(ci->getPowTough().toStdString());
ExactCard ec = card->getCard();
if (ec) {
cmd->set_pt(ec.getInfo().getPowTough().toStdString());
}
}
commandList.append(cmd);
@ -3468,9 +3472,9 @@ void Player::actResetPT()
auto *card = static_cast<CardItem *>(item);
QString ptString;
if (!card->getFaceDown()) { // leave the pt empty if the card is face down
CardInfoPtr info = card->getInfo();
if (info) {
ptString = info->getPowTough();
ExactCard ec = card->getCard();
if (ec) {
ptString = ec.getInfo().getPowTough();
}
}
if (ptString == card->getPT()) {
@ -4077,13 +4081,13 @@ void Player::addRelatedCardView(const CardItem *card, QMenu *cardMenu)
if (!card || !cardMenu) {
return;
}
auto cardInfo = card->getInfo();
if (!cardInfo) {
auto exactCard = card->getCard();
if (!exactCard) {
return;
}
bool atLeastOneGoodRelationFound = false;
QList<CardRelation *> relatedCards = cardInfo->getAllRelatedCards();
QList<CardRelation *> relatedCards = exactCard.getInfo().getAllRelatedCards();
for (const CardRelation *cardRelation : relatedCards) {
CardInfoPtr relatedCard = CardDatabaseManager::getInstance()->getCardInfo(cardRelation->getName());
if (relatedCard != nullptr) {
@ -4096,17 +4100,14 @@ void Player::addRelatedCardView(const CardItem *card, QMenu *cardMenu)
return;
}
const auto &currentCardSet = CardDatabase::getSetInfoForCard(cardInfo);
cardMenu->addSeparator();
auto viewRelatedCards = new QMenu(tr("View related cards"));
cardMenu->addMenu(viewRelatedCards);
for (const CardRelation *relatedCard : relatedCards) {
QString relatedCardName = relatedCard->getName();
CardRef cardRef = {relatedCardName, exactCard.getPrinting().getUuid()};
QAction *viewCard = viewRelatedCards->addAction(relatedCardName);
connect(viewCard, &QAction::triggered, game, [this, relatedCardName, currentCardSet] {
game->viewCardInfo({relatedCardName, currentCardSet.getUuid()});
});
connect(viewCard, &QAction::triggered, game, [this, cardRef] { game->viewCardInfo(cardRef); });
}
}
@ -4115,36 +4116,34 @@ void Player::addRelatedCardActions(const CardItem *card, QMenu *cardMenu)
if (!card || !cardMenu) {
return;
}
auto cardInfo = card->getInfo();
if (!cardInfo) {
auto exactCard = card->getCard();
if (!exactCard) {
return;
}
QList<CardRelation *> relatedCards = cardInfo->getAllRelatedCards();
QList<CardRelation *> relatedCards = exactCard.getInfo().getAllRelatedCards();
if (relatedCards.isEmpty()) {
return;
}
const auto &currentCardSet = CardDatabase::getSetInfoForCard(cardInfo);
cardMenu->addSeparator();
int index = 0;
QAction *createRelatedCards = nullptr;
for (const CardRelation *cardRelation : relatedCards) {
CardInfoPtr relatedCard =
CardDatabaseManager::getInstance()->getCard({cardRelation->getName(), currentCardSet.getUuid()});
if (relatedCard == nullptr) {
relatedCard = CardDatabaseManager::getInstance()->getCardInfo(cardRelation->getName());
ExactCard relatedCard =
CardDatabaseManager::getInstance()->getCard({cardRelation->getName(), exactCard.getPrinting().getUuid()});
if (!relatedCard) {
relatedCard = CardDatabaseManager::getInstance()->getCard({cardRelation->getName()});
}
if (relatedCard == nullptr) {
if (!relatedCard) {
continue;
}
QString relatedCardName;
if (relatedCard->getPowTough().size() > 0) {
relatedCardName = relatedCard->getPowTough() + " " + relatedCard->getName(); // "n/n name"
if (relatedCard.getInfo().getPowTough().size() > 0) {
relatedCardName = relatedCard.getInfo().getPowTough() + " " + relatedCard.getName(); // "n/n name"
} else {
relatedCardName = relatedCard->getName(); // "name"
relatedCardName = relatedCard.getName(); // "name"
}
QString text = tr("Token: ");

View file

@ -140,9 +140,9 @@ void TableZone::handleDropEventByGrid(const QList<CardDragItem *> &dragItems,
ctm->set_card_id(item->getId());
ctm->set_face_down(item->getFaceDown());
if (startZone->getName() != name && !item->getFaceDown()) {
const auto &info = item->getItem()->getInfo();
if (info) {
ctm->set_pt(info->getPowTough().toStdString());
const auto &card = item->getItem()->getCard();
if (card) {
ctm->set_pt(card.getInfo().getPowTough().toStdString());
}
}
}

View file

@ -152,7 +152,7 @@ void ZoneViewZone::reorganizeCards()
// filter cards
CardList cardsToDisplay = CardList(cards.getContentsKnown());
for (auto card : cards) {
if (filterString.check(card->getInfo())) {
if (filterString.check(card->getCard().getCardPtr())) {
card->show();
cardsToDisplay.append(card);
} else {