mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-27 00:14:40 -07:00
[Card] Add a Tags filter to the visual card database
This commit is contained in:
parent
0ea0e231bf
commit
ea38af774a
9 changed files with 288 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "card_database_querier.h"
|
||||
|
||||
#include "../card_info.h"
|
||||
#include "../game_specific_terms.h"
|
||||
#include "../printing/exact_card.h"
|
||||
#include "../set/card_set_comparator.h"
|
||||
#include "card_database.h"
|
||||
|
|
@ -23,6 +24,7 @@ void CardDatabaseQuerier::invalidateCaches()
|
|||
mainCardTypeCountsCache.clear();
|
||||
subCardTypeCountsCache.clear();
|
||||
formatsCountCache.clear();
|
||||
tagCountsCache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -359,6 +361,21 @@ FormatRulesPtr CardDatabaseQuerier::getFormat(const QString &formatName) const
|
|||
return db->formats.value(formatName.toLower());
|
||||
}
|
||||
|
||||
QMap<QString, int> CardDatabaseQuerier::getAllTagsWithCount() const
|
||||
{
|
||||
if (tagCountsCache.isEmpty()) {
|
||||
for (const auto &card : db->cards.values()) {
|
||||
const QStringList tags = card->getProperty(Mtg::Tags).split(" ", Qt::SkipEmptyParts);
|
||||
|
||||
for (const QString &tag : tags) {
|
||||
tagCountsCache[tag]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tagCountsCache;
|
||||
}
|
||||
|
||||
QMap<QString, int> CardDatabaseQuerier::getAllFormatsWithCount() const
|
||||
{
|
||||
if (formatsCountCache.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -214,6 +214,16 @@ public:
|
|||
* @return Map of subtype string to count.
|
||||
*/
|
||||
[[nodiscard]] QMap<QString, int> getAllSubCardTypesWithCount() const;
|
||||
|
||||
/**
|
||||
* @brief Returns a mapping of Scryfall Tagger tag slugs to their occurrence counts.
|
||||
*
|
||||
* Tags are stored space-separated in the `tags` card property, so a card
|
||||
* tagged "ramp" and "removal" contributes one to each slug's count.
|
||||
*
|
||||
* @return Map of tag slug to count.
|
||||
*/
|
||||
[[nodiscard]] QMap<QString, int> getAllTagsWithCount() const;
|
||||
FormatRulesPtr getFormat(const QString &formatName) const;
|
||||
QMap<QString, int> getAllFormatsWithCount() const;
|
||||
|
||||
|
|
@ -227,6 +237,7 @@ private:
|
|||
mutable QMap<QString, int> mainCardTypeCountsCache;
|
||||
mutable QMap<QString, int> subCardTypeCountsCache;
|
||||
mutable QMap<QString, int> formatsCountCache;
|
||||
mutable QMap<QString, int> tagCountsCache;
|
||||
|
||||
private slots:
|
||||
void invalidateCaches();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue