mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-23 10:52:16 -07:00
Support multiple <set> tags per card within the database
This will allow us to show off all different printings for cards that might appear multiple times in a set (alt arts, Secret Lairs, etc.)
This commit is contained in:
parent
7ae1349ac8
commit
db53066d89
12 changed files with 159 additions and 152 deletions
|
|
@ -266,8 +266,11 @@ CardInfoPtr CardInfo::newInstance(const QString &_name,
|
|||
_sets, _cipt, _tableRow, _upsideDownArt));
|
||||
ptr->setSmartPointer(ptr);
|
||||
|
||||
for (const CardInfoPerSet &set : _sets) {
|
||||
set.getPtr()->append(ptr);
|
||||
for (const auto &x : _sets) {
|
||||
for (const CardInfoPerSet &set : x) {
|
||||
set.getPtr()->append(ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ptr;
|
||||
|
|
@ -288,7 +291,7 @@ QString CardInfo::getCorrectedName() const
|
|||
void CardInfo::addToSet(const CardSetPtr &_set, const CardInfoPerSet _info)
|
||||
{
|
||||
_set->append(smartThis);
|
||||
sets.insert(_set->getShortName(), _info);
|
||||
sets[_set->getShortName()].append(_info);
|
||||
|
||||
refreshCachedSetNames();
|
||||
}
|
||||
|
|
@ -297,9 +300,12 @@ void CardInfo::refreshCachedSetNames()
|
|||
{
|
||||
QStringList setList;
|
||||
// update the cached list of set names
|
||||
for (const auto &set : sets) {
|
||||
if (set.getPtr()->getEnabled()) {
|
||||
setList << set.getPtr()->getShortName();
|
||||
for (const auto &x : sets) {
|
||||
for (const auto &set : x) {
|
||||
if (set.getPtr()->getEnabled()) {
|
||||
setList << set.getPtr()->getShortName();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
setsNames = setList.join(", ");
|
||||
|
|
@ -396,8 +402,10 @@ void CardDatabase::addCard(CardInfoPtr card)
|
|||
// if card already exists just add the new set property
|
||||
if (cards.contains(card->getName())) {
|
||||
CardInfoPtr sameCard = cards[card->getName()];
|
||||
for (const CardInfoPerSet &set : card->getSets()) {
|
||||
sameCard->addToSet(set.getPtr(), set);
|
||||
for (const auto &x : card->getSets()) {
|
||||
for (const CardInfoPerSet &set : x) {
|
||||
sameCard->addToSet(set.getPtr(), set);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -456,12 +464,14 @@ CardInfoPtr CardDatabase::getCardByNameAndProviderId(const QString &cardName, co
|
|||
return info;
|
||||
}
|
||||
|
||||
for (const auto &set : info->getSets()) {
|
||||
if (set.getProperty("uuid") == providerId) {
|
||||
CardInfoPtr cardFromSpecificSet = info->clone();
|
||||
cardFromSpecificSet->setPixmapCacheKey(QLatin1String("card_") + QString(info->getName()) + QString("_") +
|
||||
QString(set.getProperty("uuid")));
|
||||
return cardFromSpecificSet;
|
||||
for (const auto &x : info->getSets()) {
|
||||
for (const auto &set : x) {
|
||||
if (set.getProperty("uuid") == providerId) {
|
||||
CardInfoPtr cardFromSpecificSet = info->clone();
|
||||
cardFromSpecificSet->setPixmapCacheKey(QLatin1String("card_") + QString(info->getName()) +
|
||||
QString("_") + QString(set.getProperty("uuid")));
|
||||
return cardFromSpecificSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
|
@ -630,11 +640,13 @@ CardInfoPerSet CardDatabase::getPreferredSetForCard(const QString &cardName) con
|
|||
CardInfoPerSet preferredCard;
|
||||
SetPriorityComparator comparator;
|
||||
|
||||
for (auto &cardInfoForSet : setMap) {
|
||||
CardSetPtr currentSet = cardInfoForSet.getPtr();
|
||||
if (!preferredSet || comparator(currentSet, preferredSet)) {
|
||||
preferredSet = currentSet;
|
||||
preferredCard = cardInfoForSet;
|
||||
for (const auto &x : setMap) {
|
||||
for (auto &cardInfoForSet : x) {
|
||||
CardSetPtr currentSet = cardInfoForSet.getPtr();
|
||||
if (!preferredSet || comparator(currentSet, preferredSet)) {
|
||||
preferredSet = currentSet;
|
||||
preferredCard = cardInfoForSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -657,9 +669,11 @@ CardInfoPerSet CardDatabase::getSpecificSetForCard(const QString &cardName, cons
|
|||
return CardInfoPerSet(nullptr);
|
||||
}
|
||||
|
||||
for (auto &cardInfoForSet : setMap) {
|
||||
if (cardInfoForSet.getProperty("uuid") == providerId) {
|
||||
return cardInfoForSet;
|
||||
for (const auto &x : setMap) {
|
||||
for (auto &cardInfoForSet : x) {
|
||||
if (cardInfoForSet.getProperty("uuid") == providerId) {
|
||||
return cardInfoForSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class ICardDatabaseParser;
|
|||
typedef QMap<QString, QString> QStringMap;
|
||||
typedef QSharedPointer<CardInfo> CardInfoPtr;
|
||||
typedef QSharedPointer<CardSet> CardSetPtr;
|
||||
typedef QMap<QString, CardInfoPerSet> CardInfoPerSetMap;
|
||||
typedef QMap<QString, QList<CardInfoPerSet>> CardInfoPerSetMap;
|
||||
|
||||
Q_DECLARE_METATYPE(CardInfoPtr)
|
||||
|
||||
|
|
@ -306,15 +306,36 @@ public:
|
|||
{
|
||||
if (!sets.contains(setName))
|
||||
return "";
|
||||
return sets[setName].getProperty(propertyName);
|
||||
}
|
||||
void setSetProperty(const QString &setName, const QString &_name, const QString &_value)
|
||||
{
|
||||
if (!sets.contains(setName))
|
||||
return;
|
||||
|
||||
sets[setName].setProperty(_name, _value);
|
||||
emit cardInfoChanged(smartThis);
|
||||
/*
|
||||
for (const auto &x : card->getSets()) {
|
||||
for (const auto &set : x) {
|
||||
if (QLatin1String("card_") + card->getName() + QString("_") + QString(set.getProperty("uuid")) ==
|
||||
card->getPixmapCacheKey()) {
|
||||
long long setIndex = sortedSets.indexOf(set.getPtr());
|
||||
CardSetPtr setForCardProviderID = sortedSets.takeAt(setIndex);
|
||||
sortedSets.prepend(setForCardProviderID);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
for (const auto &set : sets[setName]) {
|
||||
if (QLatin1String("card_") + this->getName() + QString("_") + QString(set.getProperty("uuid")) ==
|
||||
this->getPixmapCacheKey()) {
|
||||
return set.getProperty(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
return sets[setName][0].getProperty(propertyName);
|
||||
}
|
||||
void setSetProperty(const QString &, const QString &, const QString &)
|
||||
{
|
||||
// if (!sets.contains(setName))
|
||||
// return;
|
||||
//
|
||||
// sets[setName].setProperty(_name, _value);
|
||||
// emit cardInfoChanged(smartThis);
|
||||
}
|
||||
|
||||
// related cards
|
||||
|
|
|
|||
|
|
@ -97,9 +97,11 @@ bool CardDatabaseModel::checkCardHasAtLeastOneEnabledSet(CardInfoPtr card)
|
|||
if (!showOnlyCardsFromEnabledSets)
|
||||
return true;
|
||||
|
||||
for (const auto &set : card->getSets()) {
|
||||
if (set.getPtr()->getEnabled())
|
||||
return true;
|
||||
for (const auto &x : card->getSets()) {
|
||||
for (const auto &set : x) {
|
||||
if (set.getPtr()->getEnabled())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ void CockatriceXml3Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
if (attrs.hasAttribute("rarity")) {
|
||||
setInfo.setProperty("rarity", attrs.value("rarity").toString());
|
||||
}
|
||||
_sets.insert(setName, setInfo);
|
||||
_sets[setName].append(setInfo);
|
||||
// related cards
|
||||
} else if (xmlName == "related" || xmlName == "reverse-related") {
|
||||
CardRelation::AttachType attach = CardRelation::DoesNotAttach;
|
||||
|
|
@ -331,24 +331,26 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in
|
|||
|
||||
// sets
|
||||
const CardInfoPerSetMap sets = info->getSets();
|
||||
for (CardInfoPerSet set : sets) {
|
||||
xml.writeStartElement("set");
|
||||
xml.writeAttribute("rarity", set.getProperty("rarity"));
|
||||
xml.writeAttribute("muId", set.getProperty("muid"));
|
||||
xml.writeAttribute("uuId", set.getProperty("uuid"));
|
||||
for (const auto &x : sets) {
|
||||
for (CardInfoPerSet set : x) {
|
||||
xml.writeStartElement("set");
|
||||
xml.writeAttribute("rarity", set.getProperty("rarity"));
|
||||
xml.writeAttribute("muId", set.getProperty("muid"));
|
||||
xml.writeAttribute("uuId", set.getProperty("uuid"));
|
||||
|
||||
tmpString = set.getProperty("num");
|
||||
if (!tmpString.isEmpty()) {
|
||||
xml.writeAttribute("num", tmpString);
|
||||
tmpString = set.getProperty("num");
|
||||
if (!tmpString.isEmpty()) {
|
||||
xml.writeAttribute("num", tmpString);
|
||||
}
|
||||
|
||||
tmpString = set.getProperty("picurl");
|
||||
if (!tmpString.isEmpty()) {
|
||||
xml.writeAttribute("picURL", tmpString);
|
||||
}
|
||||
|
||||
xml.writeCharacters(set.getPtr()->getShortName());
|
||||
xml.writeEndElement();
|
||||
}
|
||||
|
||||
tmpString = set.getProperty("picurl");
|
||||
if (!tmpString.isEmpty()) {
|
||||
xml.writeAttribute("picURL", tmpString);
|
||||
}
|
||||
|
||||
xml.writeCharacters(set.getPtr()->getShortName());
|
||||
xml.writeEndElement();
|
||||
}
|
||||
|
||||
// related cards
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
|||
attrName = "picurl";
|
||||
setInfo.setProperty(attrName, attr.value().toString());
|
||||
}
|
||||
_sets.insert(setName, setInfo);
|
||||
_sets[setName].append(setInfo);
|
||||
}
|
||||
// related cards
|
||||
} else if (xmlName == "related" || xmlName == "reverse-related") {
|
||||
|
|
@ -284,14 +284,16 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in
|
|||
xml.writeEndElement();
|
||||
|
||||
// sets
|
||||
for (CardInfoPerSet set : info->getSets()) {
|
||||
xml.writeStartElement("set");
|
||||
for (QString propName : set.getProperties()) {
|
||||
xml.writeAttribute(propName, set.getProperty(propName));
|
||||
}
|
||||
for (const auto &x : info->getSets()) {
|
||||
for (CardInfoPerSet set : x) {
|
||||
xml.writeStartElement("set");
|
||||
for (QString propName : set.getProperties()) {
|
||||
xml.writeAttribute(propName, set.getProperty(propName));
|
||||
}
|
||||
|
||||
xml.writeCharacters(set.getPtr()->getShortName());
|
||||
xml.writeEndElement();
|
||||
xml.writeCharacters(set.getPtr()->getShortName());
|
||||
xml.writeEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
// related cards
|
||||
|
|
|
|||
|
|
@ -109,9 +109,11 @@ static void setupParserRules()
|
|||
search["RarityQuery"] = [](const peg::SemanticValues &sv) -> Filter {
|
||||
StringMatcher matcher = sv[0].get<StringMatcher>();
|
||||
return [=](CardData x) -> bool {
|
||||
for (const auto &set : x->getSets().values()) {
|
||||
if (matcher(set.getProperty("rarity")))
|
||||
return true;
|
||||
for (const auto &y : x->getSets().values()) {
|
||||
for (const auto &set : y) {
|
||||
if (matcher(set.getProperty("rarity")))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -203,11 +203,13 @@ bool FilterItem::acceptText(const CardInfoPtr info) const
|
|||
bool FilterItem::acceptSet(const CardInfoPtr info) const
|
||||
{
|
||||
bool status = false;
|
||||
for (const auto &set : info->getSets()) {
|
||||
if (set.getPtr()->getShortName().compare(term, Qt::CaseInsensitive) == 0 ||
|
||||
set.getPtr()->getLongName().compare(term, Qt::CaseInsensitive) == 0) {
|
||||
status = true;
|
||||
break;
|
||||
for (const auto &x : info->getSets()) {
|
||||
for (const auto &set : x) {
|
||||
if (set.getPtr()->getShortName().compare(term, Qt::CaseInsensitive) == 0 ||
|
||||
set.getPtr()->getLongName().compare(term, Qt::CaseInsensitive) == 0) {
|
||||
status = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -336,9 +338,11 @@ bool FilterItem::acceptRarity(const CardInfoPtr info) const
|
|||
}
|
||||
}
|
||||
|
||||
for (const auto &set : info->getSets()) {
|
||||
if (set.getProperty("rarity").compare(converted_term, Qt::CaseInsensitive) == 0) {
|
||||
return true;
|
||||
for (const auto &x : info->getSets()) {
|
||||
for (const auto &set : x) {
|
||||
if (set.getProperty("rarity").compare(converted_term, Qt::CaseInsensitive) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue