diff --git a/cockatrice/src/game/board/abstract_card_item.cpp b/cockatrice/src/game/board/abstract_card_item.cpp index 48720aa96..d5538011d 100644 --- a/cockatrice/src/game/board/abstract_card_item.cpp +++ b/cockatrice/src/game/board/abstract_card_item.cpp @@ -60,7 +60,8 @@ void AbstractCardItem::refreshCardInfo() exactCard = CardDatabaseManager::query()->getCard(cardRef); if (!exactCard && !cardRef.name.isEmpty()) { - auto info = CardInfo::newInstance(cardRef.name, "", true, {}, {}, {}, {}, false, false, -1, false); + CardInfo::UiAttributes attributes = {.tableRow = -1}; + auto info = CardInfo::newInstance(cardRef.name, "", true, {}, {}, {}, {}, attributes); exactCard = ExactCard(info); } if (exactCard) { diff --git a/cockatrice/src/game/board/arrow_item.cpp b/cockatrice/src/game/board/arrow_item.cpp index fd044d042..22e3ceb50 100644 --- a/cockatrice/src/game/board/arrow_item.cpp +++ b/cockatrice/src/game/board/arrow_item.cpp @@ -238,8 +238,8 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (startZone->getName().compare("hand") == 0) { startCard->playCard(false); CardInfoPtr ci = startCard->getCard().getCardPtr(); - if (ci && ((!SettingsCache::instance().getPlayToStack() && ci->getTableRow() == 3) || - (SettingsCache::instance().getPlayToStack() && ci->getTableRow() != 0 && + if (ci && ((!SettingsCache::instance().getPlayToStack() && ci->getUiAttributes().tableRow == 3) || + (SettingsCache::instance().getPlayToStack() && ci->getUiAttributes().tableRow != 0 && startCard->getZone()->getName().toStdString() != "stack"))) cmd.set_start_zone("stack"); else diff --git a/cockatrice/src/game/player/player_actions.cpp b/cockatrice/src/game/player/player_actions.cpp index 1fc91c492..e6efaf854 100644 --- a/cockatrice/src/game/player/player_actions.cpp +++ b/cockatrice/src/game/player/player_actions.cpp @@ -59,7 +59,7 @@ void PlayerActions::playCard(CardItem *card, bool faceDown) const CardInfo &info = exactCard.getInfo(); - int tableRow = info.getTableRow(); + int tableRow = info.getUiAttributes().tableRow; bool playToStack = SettingsCache::instance().getPlayToStack(); QString currentZone = card->getZone()->getName(); if (currentZone == "stack" && tableRow == 3) { @@ -72,13 +72,13 @@ void PlayerActions::playCard(CardItem *card, bool faceDown) cmd.set_x(-1); cmd.set_y(0); } else { - tableRow = faceDown ? 2 : info.getTableRow(); + tableRow = faceDown ? 2 : info.getUiAttributes().tableRow; QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - tableRow)); cardToMove->set_face_down(faceDown); if (!faceDown) { cardToMove->set_pt(info.getPowTough().toStdString()); } - cardToMove->set_tapped(!faceDown && info.getCipt()); + cardToMove->set_tapped(!faceDown && info.getUiAttributes().cipt); if (tableRow != 3) cmd.set_target_zone("table"); cmd.set_x(gridPoint.x()); @@ -111,7 +111,7 @@ void PlayerActions::playCardToTable(const CardItem *card, bool faceDown) const CardInfo &info = exactCard.getInfo(); - int tableRow = faceDown ? 2 : info.getTableRow(); + int tableRow = faceDown ? 2 : info.getUiAttributes().tableRow; // default instant/sorcery cards to the noncreatures row if (tableRow > 2) { tableRow = 1; @@ -122,7 +122,7 @@ void PlayerActions::playCardToTable(const CardItem *card, bool faceDown) if (!faceDown) { cardToMove->set_pt(info.getPowTough().toStdString()); } - cardToMove->set_tapped(!faceDown && info.getCipt()); + cardToMove->set_tapped(!faceDown && info.getUiAttributes().cipt); cmd.set_target_zone("table"); cmd.set_x(gridPoint.x()); cmd.set_y(gridPoint.y()); @@ -859,7 +859,7 @@ void PlayerActions::actCreateToken() ExactCard correctedCard = CardDatabaseManager::query()->guessCard({lastTokenInfo.name, lastTokenInfo.providerId}); if (correctedCard) { lastTokenInfo.name = correctedCard.getName(); - lastTokenTableRow = TableZone::clampValidTableRow(2 - correctedCard.getInfo().getTableRow()); + lastTokenTableRow = TableZone::clampValidTableRow(2 - correctedCard.getInfo().getUiAttributes().tableRow); if (lastTokenInfo.pt.isEmpty()) { lastTokenInfo.pt = correctedCard.getInfo().getPowTough(); } @@ -910,7 +910,7 @@ void PlayerActions::setLastToken(CardInfoPtr cardInfo) .providerId = SettingsCache::instance().cardOverrides().getCardPreferenceOverride(cardInfo->getName())}; - lastTokenTableRow = TableZone::clampValidTableRow(2 - cardInfo->getTableRow()); + lastTokenTableRow = TableZone::clampValidTableRow(2 - cardInfo->getUiAttributes().tableRow); utilityMenu->setAndEnableCreateAnotherTokenAction(tr("C&reate another %1 token").arg(lastTokenInfo.name)); } @@ -1080,7 +1080,7 @@ void PlayerActions::createCard(const CardItem *sourceCard, // get the target token's location // TODO: Define this QPoint into its own function along with the one below - QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - cardInfo->getTableRow())); + QPoint gridPoint = QPoint(-1, TableZone::clampValidTableRow(2 - cardInfo->getUiAttributes().tableRow)); // create the token for the related card Command_CreateToken cmd; diff --git a/cockatrice/src/game/zones/logic/table_zone_logic.cpp b/cockatrice/src/game/zones/logic/table_zone_logic.cpp index 39e24b5cd..42caf2ec8 100644 --- a/cockatrice/src/game/zones/logic/table_zone_logic.cpp +++ b/cockatrice/src/game/zones/logic/table_zone_logic.cpp @@ -18,7 +18,7 @@ void TableZoneLogic::addCardImpl(CardItem *card, int _x, int _y) if (!card->getFaceDown() && card->getPT().isEmpty()) { card->setPT(card->getCardInfo().getPowTough()); } - if (card->getCardInfo().getCipt() && card->getCardInfo().getLandscapeOrientation()) { + if (card->getCardInfo().getUiAttributes().cipt && card->getCardInfo().getUiAttributes().landscapeOrientation) { card->setDoesntUntap(true); } card->setGridPoint(QPoint(_x, _y)); diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_loader.cpp b/cockatrice/src/interface/card_picture_loader/card_picture_loader.cpp index aebb09f0f..296355940 100644 --- a/cockatrice/src/interface/card_picture_loader/card_picture_loader.cpp +++ b/cockatrice/src/interface/card_picture_loader/card_picture_loader.cpp @@ -154,7 +154,7 @@ void CardPictureLoader::imageLoaded(const ExactCard &card, const QImage &image) qCDebug(CardPictureLoaderLog) << "Caching NULL pixmap for" << card.getName(); QPixmapCache::insert(card.getPixmapCacheKey(), QPixmap()); } else { - if (card.getInfo().getUpsideDownArt()) { + if (card.getInfo().getUiAttributes().upsideDownArt) { #if (QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)) QImage mirrorImage = image.flipped(Qt::Horizontal | Qt::Vertical); #else diff --git a/cockatrice/src/interface/widgets/cards/card_info_picture_widget.cpp b/cockatrice/src/interface/widgets/cards/card_info_picture_widget.cpp index 8ad86eadc..fc1b9ebe2 100644 --- a/cockatrice/src/interface/widgets/cards/card_info_picture_widget.cpp +++ b/cockatrice/src/interface/widgets/cards/card_info_picture_widget.cpp @@ -183,7 +183,7 @@ void CardInfoPictureWidget::paintEvent(QPaintEvent *event) QPixmap transformedPixmap = resizedPixmap; // Default pixmap if (SettingsCache::instance().getAutoRotateSidewaysLayoutCards()) { - if (exactCard.getInfo().getLandscapeOrientation()) { + if (exactCard.getInfo().getUiAttributes().landscapeOrientation) { // Rotate pixmap 90 degrees to the left QTransform transform; transform.rotate(90); diff --git a/cockatrice/src/interface/widgets/dialogs/dlg_edit_tokens.cpp b/cockatrice/src/interface/widgets/dialogs/dlg_edit_tokens.cpp index 479e3b887..a47a8221a 100644 --- a/cockatrice/src/interface/widgets/dialogs/dlg_edit_tokens.cpp +++ b/cockatrice/src/interface/widgets/dialogs/dlg_edit_tokens.cpp @@ -165,8 +165,8 @@ void DlgEditTokens::actAddToken() QString setName = CardSet::TOKENS_SETNAME; SetToPrintingsMap sets; sets[setName].append(PrintingInfo(databaseModel->getDatabase()->getSet(setName))); - CardInfoPtr card = CardInfo::newInstance(name, "", true, QVariantHash(), QList(), - QList(), sets, false, false, -1, false); + CardInfo::UiAttributes attributes = {.tableRow = -1}; + CardInfoPtr card = CardInfo::newInstance(name, "", true, {}, {}, {}, sets, attributes); card->setCardType("Token"); databaseModel->getDatabase()->addCard(card); diff --git a/libcockatrice_card/libcockatrice/card/card_info.cpp b/libcockatrice_card/libcockatrice/card/card_info.cpp index 4f1280d74..58aa83848 100644 --- a/libcockatrice_card/libcockatrice/card/card_info.cpp +++ b/libcockatrice_card/libcockatrice/card/card_info.cpp @@ -26,13 +26,9 @@ CardInfo::CardInfo(const QString &_name, const QList &_relatedCards, const QList &_reverseRelatedCards, SetToPrintingsMap _sets, - bool _cipt, - bool _landscapeOrientation, - int _tableRow, - bool _upsideDownArt) + const UiAttributes _uiAttributes) : name(_name), text(_text), isToken(_isToken), properties(std::move(_properties)), relatedCards(_relatedCards), - reverseRelatedCards(_reverseRelatedCards), setsToPrintings(std::move(_sets)), cipt(_cipt), - landscapeOrientation(_landscapeOrientation), tableRow(_tableRow), upsideDownArt(_upsideDownArt) + reverseRelatedCards(_reverseRelatedCards), setsToPrintings(std::move(_sets)), uiAttributes(_uiAttributes) { simpleName = CardInfo::simplifyName(name); @@ -41,8 +37,7 @@ CardInfo::CardInfo(const QString &_name, CardInfoPtr CardInfo::newInstance(const QString &_name) { - return newInstance(_name, QString(), false, QVariantHash(), QList(), QList(), - SetToPrintingsMap(), false, false, 0, false); + return newInstance(_name, "", false, {}, {}, {}, {}, {}); } CardInfoPtr CardInfo::newInstance(const QString &_name, @@ -52,13 +47,10 @@ CardInfoPtr CardInfo::newInstance(const QString &_name, const QList &_relatedCards, const QList &_reverseRelatedCards, SetToPrintingsMap _sets, - bool _cipt, - bool _landscapeOrientation, - int _tableRow, - bool _upsideDownArt) + const UiAttributes _uiAttributes) { CardInfoPtr ptr(new CardInfo(_name, _text, _isToken, std::move(_properties), _relatedCards, _reverseRelatedCards, - _sets, _cipt, _landscapeOrientation, _tableRow, _upsideDownArt)); + _sets, _uiAttributes)); ptr->setSmartPointer(ptr); for (const auto &printings : _sets) { diff --git a/libcockatrice_card/libcockatrice/card/card_info.h b/libcockatrice_card/libcockatrice/card/card_info.h index b72d1fbbe..a52c0553a 100644 --- a/libcockatrice_card/libcockatrice/card/card_info.h +++ b/libcockatrice_card/libcockatrice/card/card_info.h @@ -47,6 +47,21 @@ class CardInfo : public QObject { Q_OBJECT +public: + /** + * @class CardInfo::UiAttributes + * @ingroup Cards + * + * @brief Attributes of the card that affect display and game logic. + */ + struct UiAttributes + { + bool cipt = false; ///< Positioning flag used by UI. + bool landscapeOrientation = false; ///< Orientation flag for rendering. + int tableRow = 0; ///< Row index in a table or visual representation. + bool upsideDownArt = false; ///< Whether artwork is flipped for visual purposes. + }; + private: /** @name Private Card Properties * @anchor PrivateCardProperties @@ -63,10 +78,7 @@ private: QList reverseRelatedCardsToMe; ///< Cards that consider this card as related. SetToPrintingsMap setsToPrintings; ///< Mapping from set names to printing variations. QString setsNames; ///< Cached, human-readable list of set names. - bool cipt; ///< Positioning flag used by UI. - bool landscapeOrientation; ///< Orientation flag for rendering. - int tableRow; ///< Row index in a table or visual representation. - bool upsideDownArt; ///< Whether artwork is flipped for visual purposes. + UiAttributes uiAttributes; ///< Attributes that affect display and game logic ///@} public: @@ -80,10 +92,7 @@ public: * @param _relatedCards Forward references to related cards. * @param _reverseRelatedCards Backward references to related cards. * @param _sets Map of set names to printing information. - * @param _cipt UI positioning flag. - * @param _landscapeOrientation UI rendering orientation. - * @param _tableRow Row index for table placement. - * @param _upsideDownArt Whether the artwork should be displayed upside down. + * @param _uiAttributes Attributes that affect display and game logic */ explicit CardInfo(const QString &_name, const QString &_text, @@ -92,10 +101,7 @@ public: const QList &_relatedCards, const QList &_reverseRelatedCards, SetToPrintingsMap _sets, - bool _cipt, - bool _landscapeOrientation, - int _tableRow, - bool _upsideDownArt); + UiAttributes _uiAttributes); /** * @brief Copy constructor for CardInfo. @@ -108,8 +114,7 @@ public: : 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) + setsToPrintings(other.setsToPrintings), setsNames(other.setsNames), uiAttributes(other.uiAttributes) { } @@ -133,10 +138,7 @@ public: * @param _relatedCards Forward relationships. * @param _reverseRelatedCards Reverse relationships. * @param _sets Printing information per set. - * @param _cipt UI positioning flag. - * @param _landscapeOrientation UI rendering orientation. - * @param _tableRow Row index for table placement. - * @param _upsideDownArt Artwork orientation flag. + * @param _uiAttributes Attributes that affect display and game logic * @return Shared pointer to the new CardInfo instance. */ static CardInfoPtr newInstance(const QString &_name, @@ -146,10 +148,7 @@ public: const QList &_relatedCards, const QList &_reverseRelatedCards, SetToPrintingsMap _sets, - bool _cipt, - bool _landscapeOrientation, - int _tableRow, - bool _upsideDownArt); + UiAttributes _uiAttributes); /** * @brief Clones the current CardInfo instance. @@ -254,29 +253,14 @@ public: //@} /** @name UI Positioning */ //@{ - bool getCipt() const + const UiAttributes &getUiAttributes() const { - return cipt; + return uiAttributes; } - bool getLandscapeOrientation() const - { - return landscapeOrientation; - } - int getTableRow() const - { - return tableRow; - } - void setTableRow(int _tableRow) - { - tableRow = _tableRow; - } - bool getUpsideDownArt() const - { - return upsideDownArt; - } - const QChar getColorChar() const; //@} + const QChar getColorChar() const; + /** @name Legacy/Convenience Property Accessors */ //@{ const QString getCardType() const; void setCardType(const QString &value); diff --git a/libcockatrice_card/libcockatrice/card/database/parser/cockatrice_xml_3.cpp b/libcockatrice_card/libcockatrice/card/database/parser/cockatrice_xml_3.cpp index c56f24480..35e2f3d83 100644 --- a/libcockatrice_card/libcockatrice/card/database/parser/cockatrice_xml_3.cpp +++ b/libcockatrice_card/libcockatrice/card/database/parser/cockatrice_xml_3.cpp @@ -282,9 +282,13 @@ void CockatriceXml3Parser::loadCardsFromXml(QXmlStreamReader &xml) } properties.insert("colors", colors); - CardInfoPtr newCard = - CardInfo::newInstance(name, text, isToken, properties, relatedCards, reverseRelatedCards, _sets, cipt, - landscapeOrientation, tableRow, upsideDown); + + CardInfo::UiAttributes attributes = {.cipt = cipt, + .landscapeOrientation = landscapeOrientation, + .tableRow = tableRow, + .upsideDownArt = upsideDown}; + CardInfoPtr newCard = CardInfo::newInstance(name, text, isToken, properties, relatedCards, + reverseRelatedCards, _sets, attributes); emit addCard(newCard); } } @@ -417,14 +421,15 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in } // positioning - xml.writeTextElement("tablerow", QString::number(info->getTableRow())); - if (info->getCipt()) { + const CardInfo::UiAttributes &attributes = info->getUiAttributes(); + xml.writeTextElement("tablerow", QString::number(attributes.tableRow)); + if (attributes.cipt) { xml.writeTextElement("cipt", "1"); } - if (info->getLandscapeOrientation()) { + if (attributes.landscapeOrientation) { xml.writeTextElement("landscapeOrientation", "1"); } - if (info->getUpsideDownArt()) { + if (attributes.upsideDownArt) { xml.writeTextElement("upsidedown", "1"); } diff --git a/libcockatrice_card/libcockatrice/card/database/parser/cockatrice_xml_4.cpp b/libcockatrice_card/libcockatrice/card/database/parser/cockatrice_xml_4.cpp index 92525d6e1..ab4c8002d 100644 --- a/libcockatrice_card/libcockatrice/card/database/parser/cockatrice_xml_4.cpp +++ b/libcockatrice_card/libcockatrice/card/database/parser/cockatrice_xml_4.cpp @@ -262,9 +262,12 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml) continue; } - CardInfoPtr newCard = - CardInfo::newInstance(name, text, isToken, properties, relatedCards, reverseRelatedCards, _sets, cipt, - landscapeOrientation, tableRow, upsideDown); + CardInfo::UiAttributes attributes = {.cipt = cipt, + .landscapeOrientation = landscapeOrientation, + .tableRow = tableRow, + .upsideDownArt = upsideDown}; + CardInfoPtr newCard = CardInfo::newInstance(name, text, isToken, properties, relatedCards, + reverseRelatedCards, _sets, attributes); emit addCard(newCard); } } @@ -379,14 +382,15 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in } // positioning - xml.writeTextElement("tablerow", QString::number(info->getTableRow())); - if (info->getCipt()) { + const CardInfo::UiAttributes &attributes = info->getUiAttributes(); + xml.writeTextElement("tablerow", QString::number(attributes.tableRow)); + if (attributes.cipt) { xml.writeTextElement("cipt", "1"); } - if (info->getLandscapeOrientation()) { + if (attributes.landscapeOrientation) { xml.writeTextElement("landscapeOrientation", "1"); } - if (info->getUpsideDownArt()) { + if (attributes.upsideDownArt) { xml.writeTextElement("upsidedown", "1"); } diff --git a/oracle/src/oracleimporter.cpp b/oracle/src/oracleimporter.cpp index 049dbaede..41335d72d 100644 --- a/oracle/src/oracleimporter.cpp +++ b/oracle/src/oracleimporter.cpp @@ -204,11 +204,11 @@ CardInfoPtr OracleImporter::addCard(QString name, bool upsideDown = layout == "flip" && side == "back"; // insert the card and its properties - QList reverseRelatedCards; SetToPrintingsMap setsInfo; setsInfo[printingInfo.getSet()->getShortName()].append(printingInfo); - CardInfoPtr newCard = CardInfo::newInstance(name, text, isToken, properties, relatedCards, reverseRelatedCards, - setsInfo, cipt, landscapeOrientation, tableRow, upsideDown); + CardInfo::UiAttributes attributes = {cipt, landscapeOrientation, tableRow, upsideDown}; + CardInfoPtr newCard = + CardInfo::newInstance(name, text, isToken, properties, relatedCards, {}, setsInfo, attributes); if (name.isEmpty()) { qDebug() << "warning: an empty card was added to set" << printingInfo.getSet()->getShortName();