mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-12 07:40:30 -08:00
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:
@@ -30,6 +30,7 @@
|
||||
<xs:attribute type="xs:string" name="rarity" use="optional" />
|
||||
<xs:attribute type="xs:boolean" name="isOnlineOnly" use="optional" />
|
||||
<xs:attribute type="xs:boolean" name="isRebalanced" use="optional" />
|
||||
<xs:attribute type="xs:string" name="flavorName" use="optional"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
|
||||
@@ -32,7 +32,7 @@ CardInfo::CardInfo(const QString &_name,
|
||||
{
|
||||
simpleName = CardInfo::simplifyName(name);
|
||||
|
||||
refreshCachedSetNames();
|
||||
refreshCachedSets();
|
||||
}
|
||||
|
||||
CardInfoPtr CardInfo::newInstance(const QString &_name)
|
||||
@@ -84,7 +84,7 @@ void CardInfo::addToSet(const CardSetPtr &_set, const PrintingInfo _info)
|
||||
setsToPrintings[_set->getShortName()].append(_info);
|
||||
}
|
||||
|
||||
refreshCachedSetNames();
|
||||
refreshCachedSets();
|
||||
}
|
||||
|
||||
void CardInfo::combineLegalities(const QVariantHash &props)
|
||||
@@ -98,6 +98,12 @@ void CardInfo::combineLegalities(const QVariantHash &props)
|
||||
}
|
||||
}
|
||||
|
||||
void CardInfo::refreshCachedSets()
|
||||
{
|
||||
refreshCachedSetNames();
|
||||
refreshCachedAltNames();
|
||||
}
|
||||
|
||||
void CardInfo::refreshCachedSetNames()
|
||||
{
|
||||
QStringList setList;
|
||||
@@ -113,6 +119,21 @@ void CardInfo::refreshCachedSetNames()
|
||||
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)
|
||||
{
|
||||
static const QRegularExpression spaceOrSplit("(\\s+|\\/\\/.*)");
|
||||
|
||||
@@ -77,8 +77,9 @@ private:
|
||||
QList<CardRelation *> reverseRelatedCards; ///< Cards that refer back to this card.
|
||||
QList<CardRelation *> 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.
|
||||
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:
|
||||
@@ -114,7 +115,8 @@ 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), uiAttributes(other.uiAttributes)
|
||||
setsToPrintings(other.setsToPrintings), uiAttributes(other.uiAttributes), setsNames(other.setsNames),
|
||||
altNames(other.altNames)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -185,6 +187,10 @@ public:
|
||||
{
|
||||
return simpleName;
|
||||
}
|
||||
const QSet<QString> &getAltNames()
|
||||
{
|
||||
return altNames;
|
||||
};
|
||||
const QString &getText() const
|
||||
{
|
||||
return text;
|
||||
@@ -303,11 +309,11 @@ public:
|
||||
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.
|
||||
@@ -319,6 +325,21 @@ public:
|
||||
*/
|
||||
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:
|
||||
/**
|
||||
* @brief Emitted when a pixmap for this card has been updated or finished loading.
|
||||
|
||||
@@ -194,8 +194,9 @@ void CardDatabase::markAllSetsAsKnown()
|
||||
void CardDatabase::notifyEnabledSetsChanged()
|
||||
{
|
||||
// refresh the list of cached set names
|
||||
for (const CardInfoPtr &card : cards)
|
||||
card->refreshCachedSetNames();
|
||||
for (const CardInfoPtr &card : cards) {
|
||||
card->refreshCachedSets();
|
||||
}
|
||||
|
||||
// inform the carddatabasemodels that they need to re-check their list of cards
|
||||
emit cardDatabaseEnabledSetsChanged();
|
||||
|
||||
@@ -12,4 +12,9 @@ PrintingInfo::PrintingInfo(const CardSetPtr &_set) : set(_set)
|
||||
QString PrintingInfo::getUuid() const
|
||||
{
|
||||
return properties.value("uuid").toString();
|
||||
}
|
||||
|
||||
QString PrintingInfo::getFlavorName() const
|
||||
{
|
||||
return properties.value("flavorName").toString();
|
||||
}
|
||||
@@ -110,6 +110,13 @@ public:
|
||||
* @return A string representing the providerID.
|
||||
*/
|
||||
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
|
||||
|
||||
@@ -293,6 +293,13 @@ int OracleImporter::importCardsFromSet(const CardSetPtr ¤tSet, const QList
|
||||
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
|
||||
for (auto i = identifierProperties.cbegin(), end = identifierProperties.cend(); i != end; ++i) {
|
||||
QString mtgjsonProperty = i.key();
|
||||
|
||||
Reference in New Issue
Block a user