Support flavorName in PrintingInfo and cache the altNames in CardInfo (#6335)

* Support flavorName property and cache altNames

* update oracleimporter

* update cards.xsd
This commit is contained in:
RickyRister
2025-11-20 05:54:23 -08:00
committed by GitHub
parent ab5d6db8a2
commit c46f6d1178
7 changed files with 72 additions and 9 deletions

View File

@@ -30,6 +30,7 @@
<xs:attribute type="xs:string" name="rarity" use="optional" /> <xs:attribute type="xs:string" name="rarity" use="optional" />
<xs:attribute type="xs:boolean" name="isOnlineOnly" use="optional" /> <xs:attribute type="xs:boolean" name="isOnlineOnly" use="optional" />
<xs:attribute type="xs:boolean" name="isRebalanced" use="optional" /> <xs:attribute type="xs:boolean" name="isRebalanced" use="optional" />
<xs:attribute type="xs:string" name="flavorName" use="optional"/>
</xs:extension> </xs:extension>
</xs:simpleContent> </xs:simpleContent>
</xs:complexType> </xs:complexType>

View File

@@ -32,7 +32,7 @@ CardInfo::CardInfo(const QString &_name,
{ {
simpleName = CardInfo::simplifyName(name); simpleName = CardInfo::simplifyName(name);
refreshCachedSetNames(); refreshCachedSets();
} }
CardInfoPtr CardInfo::newInstance(const QString &_name) CardInfoPtr CardInfo::newInstance(const QString &_name)
@@ -84,7 +84,7 @@ void CardInfo::addToSet(const CardSetPtr &_set, const PrintingInfo _info)
setsToPrintings[_set->getShortName()].append(_info); setsToPrintings[_set->getShortName()].append(_info);
} }
refreshCachedSetNames(); refreshCachedSets();
} }
void CardInfo::combineLegalities(const QVariantHash &props) void CardInfo::combineLegalities(const QVariantHash &props)
@@ -98,6 +98,12 @@ void CardInfo::combineLegalities(const QVariantHash &props)
} }
} }
void CardInfo::refreshCachedSets()
{
refreshCachedSetNames();
refreshCachedAltNames();
}
void CardInfo::refreshCachedSetNames() void CardInfo::refreshCachedSetNames()
{ {
QStringList setList; QStringList setList;
@@ -113,6 +119,21 @@ void CardInfo::refreshCachedSetNames()
setsNames = setList.join(", "); setsNames = setList.join(", ");
} }
void CardInfo::refreshCachedAltNames()
{
altNames.clear();
// update the altNames with the flavorNames
for (const auto &printings : setsToPrintings) {
for (const auto &printing : printings) {
QString flavorName = printing.getFlavorName();
if (!flavorName.isEmpty()) {
altNames.insert(flavorName);
}
}
}
}
QString CardInfo::simplifyName(const QString &name) QString CardInfo::simplifyName(const QString &name)
{ {
static const QRegularExpression spaceOrSplit("(\\s+|\\/\\/.*)"); static const QRegularExpression spaceOrSplit("(\\s+|\\/\\/.*)");

View File

@@ -77,8 +77,9 @@ private:
QList<CardRelation *> reverseRelatedCards; ///< Cards that refer back to this card. QList<CardRelation *> reverseRelatedCards; ///< Cards that refer back to this card.
QList<CardRelation *> reverseRelatedCardsToMe; ///< Cards that consider this card as related. QList<CardRelation *> reverseRelatedCardsToMe; ///< Cards that consider this card as related.
SetToPrintingsMap setsToPrintings; ///< Mapping from set names to printing variations. SetToPrintingsMap setsToPrintings; ///< Mapping from set names to printing variations.
QString setsNames; ///< Cached, human-readable list of set names.
UiAttributes uiAttributes; ///< Attributes that affect display and game logic UiAttributes uiAttributes; ///< Attributes that affect display and game logic
QString setsNames; ///< Cached, human-readable list of set names.
QSet<QString> altNames; ///< Cached set of alternate names, used when searching
///@} ///@}
public: public:
@@ -114,7 +115,8 @@ public:
: QObject(other.parent()), name(other.name), simpleName(other.simpleName), text(other.text), : QObject(other.parent()), name(other.name), simpleName(other.simpleName), text(other.text),
isToken(other.isToken), properties(other.properties), relatedCards(other.relatedCards), isToken(other.isToken), properties(other.properties), relatedCards(other.relatedCards),
reverseRelatedCards(other.reverseRelatedCards), reverseRelatedCardsToMe(other.reverseRelatedCardsToMe), reverseRelatedCards(other.reverseRelatedCards), reverseRelatedCardsToMe(other.reverseRelatedCardsToMe),
setsToPrintings(other.setsToPrintings), setsNames(other.setsNames), uiAttributes(other.uiAttributes) setsToPrintings(other.setsToPrintings), uiAttributes(other.uiAttributes), setsNames(other.setsNames),
altNames(other.altNames)
{ {
} }
@@ -185,6 +187,10 @@ public:
{ {
return simpleName; return simpleName;
} }
const QSet<QString> &getAltNames()
{
return altNames;
};
const QString &getText() const const QString &getText() const
{ {
return text; return text;
@@ -303,11 +309,11 @@ public:
void combineLegalities(const QVariantHash &props); void combineLegalities(const QVariantHash &props);
/** /**
* @brief Refreshes the cached, human-readable list of set names. * @brief Refreshes all cached fields that are calculated from the contained sets and printings.
* *
* Typically called after adding or modifying set memberships. * Typically called after adding or modifying set memberships or printings.
*/ */
void refreshCachedSetNames(); void refreshCachedSets();
/** /**
* @brief Simplifies a name for fuzzy matching. * @brief Simplifies a name for fuzzy matching.
@@ -319,6 +325,21 @@ public:
*/ */
static QString simplifyName(const QString &name); static QString simplifyName(const QString &name);
private:
/**
* @brief Refreshes the cached, human-readable list of set names.
*
* Typically called after adding or modifying set memberships.
*/
void refreshCachedSetNames();
/**
* @brief Refreshes the cached list of alt names for the card.
*
* Typically called after adding or modifying the contained printings.
*/
void refreshCachedAltNames();
signals: signals:
/** /**
* @brief Emitted when a pixmap for this card has been updated or finished loading. * @brief Emitted when a pixmap for this card has been updated or finished loading.

View File

@@ -194,8 +194,9 @@ void CardDatabase::markAllSetsAsKnown()
void CardDatabase::notifyEnabledSetsChanged() void CardDatabase::notifyEnabledSetsChanged()
{ {
// refresh the list of cached set names // refresh the list of cached set names
for (const CardInfoPtr &card : cards) for (const CardInfoPtr &card : cards) {
card->refreshCachedSetNames(); card->refreshCachedSets();
}
// inform the carddatabasemodels that they need to re-check their list of cards // inform the carddatabasemodels that they need to re-check their list of cards
emit cardDatabaseEnabledSetsChanged(); emit cardDatabaseEnabledSetsChanged();

View File

@@ -12,4 +12,9 @@ PrintingInfo::PrintingInfo(const CardSetPtr &_set) : set(_set)
QString PrintingInfo::getUuid() const QString PrintingInfo::getUuid() const
{ {
return properties.value("uuid").toString(); return properties.value("uuid").toString();
}
QString PrintingInfo::getFlavorName() const
{
return properties.value("flavorName").toString();
} }

View File

@@ -110,6 +110,13 @@ public:
* @return A string representing the providerID. * @return A string representing the providerID.
*/ */
QString getUuid() const; QString getUuid() const;
/**
* @brief Returns the flavorName for this printing.
*
* @return The flavorName, or empty if it isn't present.
*/
QString getFlavorName() const;
}; };
#endif // COCKATRICE_PRINTING_INFO_H #endif // COCKATRICE_PRINTING_INFO_H

View File

@@ -293,6 +293,13 @@ int OracleImporter::importCardsFromSet(const CardSetPtr &currentSet, const QList
printingInfo.setProperty(xmlPropertyName, propertyValue); printingInfo.setProperty(xmlPropertyName, propertyValue);
} }
// handle flavorNames specially due to double-faced cards
QString faceFlavorName = getStringPropertyFromMap(card, "faceFlavorName");
QString flavorName = !faceFlavorName.isEmpty() ? faceFlavorName : getStringPropertyFromMap(card, "flavorName");
if (!flavorName.isEmpty()) {
printingInfo.setProperty("flavorName", flavorName);
}
// Identifiers // Identifiers
for (auto i = identifierProperties.cbegin(), end = identifierProperties.cend(); i != end; ++i) { for (auto i = identifierProperties.cbegin(), end = identifierProperties.cend(); i != end; ++i) {
QString mtgjsonProperty = i.key(); QString mtgjsonProperty = i.key();