mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 03:28:49 -07:00
feat: set prioritization by set type (#5097)
* feat: prefer 'Core' and 'Expansion' sets for prioritization * rework set prioritization * clean up priority enum * formatting * revert changes to CockatriceXml3Parser * re-add missing null check * remove priority fallback ternary from CardSet model * make defaultSort logic easier to follow * revert changes to v3 card database xsd * remove unused invisible priority col from sets dialog * move draft innovation and duel deck sets to secondary prio * minor fixes * change PriorityFallback to 1 * make priority optional in xml * remove PriorityUndefined and set PriorityFallback to 0 * set priority when not found to PriorityOther in case a new set type is added it's unlikey we want it sorted first, it'll probably be a new product so it's probably best to sort it with the funny things * simplify sort function --------- Co-authored-by: tooomm <tooomm@users.noreply.github.com> Co-authored-by: ebbit1q <ebbit1q@gmail.com>
This commit is contained in:
parent
5156495b47
commit
b9ed9a6c0b
11 changed files with 128 additions and 36 deletions
|
|
@ -19,6 +19,18 @@ OracleImporter::OracleImporter(const QString &_dataDir, QObject *parent) : CardD
|
|||
{
|
||||
}
|
||||
|
||||
CardSet::Priority OracleImporter::getSetPriority(QString &setType, QString &shortName)
|
||||
{
|
||||
if (!setTypePriorities.contains(setType.toLower())) {
|
||||
qDebug() << "warning: Set type" << setType << "unrecognized for prioritization";
|
||||
}
|
||||
CardSet::Priority priority = setTypePriorities.value(setType.toLower(), CardSet::PriorityOther);
|
||||
if (nonEnglishSets.contains(shortName)) {
|
||||
priority = CardSet::PriorityLowest;
|
||||
}
|
||||
return priority;
|
||||
}
|
||||
|
||||
bool OracleImporter::readSetsFromByteArray(const QByteArray &data)
|
||||
{
|
||||
QList<SetToDownload> newSetList;
|
||||
|
|
@ -38,6 +50,7 @@ bool OracleImporter::readSetsFromByteArray(const QByteArray &data)
|
|||
QList<QVariant> setCards;
|
||||
QString setType;
|
||||
QDate releaseDate;
|
||||
CardSet::Priority priority;
|
||||
|
||||
while (it.hasNext()) {
|
||||
map = it.next().toMap();
|
||||
|
|
@ -45,6 +58,8 @@ bool OracleImporter::readSetsFromByteArray(const QByteArray &data)
|
|||
longName = map.value("name").toString();
|
||||
setCards = map.value("cards").toList();
|
||||
setType = map.value("type").toString();
|
||||
releaseDate = map.value("releaseDate").toDate();
|
||||
priority = getSetPriority(setType, shortName);
|
||||
// capitalize set type
|
||||
if (setType.length() > 0) {
|
||||
// basic grammar for words that aren't capitalized, like in "From the Vault"
|
||||
|
|
@ -62,12 +77,7 @@ bool OracleImporter::readSetsFromByteArray(const QByteArray &data)
|
|||
}
|
||||
setType = setType.trimmed();
|
||||
}
|
||||
if (!nonEnglishSets.contains(shortName)) {
|
||||
releaseDate = map.value("releaseDate").toDate();
|
||||
} else {
|
||||
releaseDate = QDate();
|
||||
}
|
||||
newSetList.append(SetToDownload(shortName, longName, setCards, setType, releaseDate));
|
||||
newSetList.append(SetToDownload(shortName, longName, setCards, priority, setType, releaseDate));
|
||||
}
|
||||
|
||||
std::sort(newSetList.begin(), newSetList.end());
|
||||
|
|
@ -493,8 +503,9 @@ int OracleImporter::startImport()
|
|||
sets.insert(TOKENS_SETNAME, tokenSet);
|
||||
|
||||
for (const SetToDownload &curSetToParse : allSets) {
|
||||
CardSetPtr newSet = CardSet::newInstance(curSetToParse.getShortName(), curSetToParse.getLongName(),
|
||||
curSetToParse.getSetType(), curSetToParse.getReleaseDate());
|
||||
CardSetPtr newSet =
|
||||
CardSet::newInstance(curSetToParse.getShortName(), curSetToParse.getLongName(), curSetToParse.getSetType(),
|
||||
curSetToParse.getReleaseDate(), curSetToParse.getPriority());
|
||||
if (!sets.contains(newSet->getShortName()))
|
||||
sets.insert(newSet->getShortName(), newSet);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,36 @@
|
|||
#include <utility>
|
||||
|
||||
// many users prefer not to see these sets with non english arts
|
||||
// as a solution we remove the date property on these sets
|
||||
// that way they will be sorted last by default
|
||||
// this will cause their art to not get priority over english cards
|
||||
// users will still be able to find these sets and prioritize them manually
|
||||
// they will given priority PriorityLowest
|
||||
const QStringList nonEnglishSets = {"4BB", "FBB", "PS11", "PSAL", "REN", "RIN"};
|
||||
const QMap<QString, CardSet::Priority> setTypePriorities{
|
||||
{"core", CardSet::PriorityPrimary},
|
||||
{"expansion", CardSet::PriorityPrimary},
|
||||
|
||||
{"commander", CardSet::PrioritySecondary},
|
||||
{"starter", CardSet::PrioritySecondary},
|
||||
{"draft_innovation", CardSet::PrioritySecondary},
|
||||
{"duel_deck", CardSet::PrioritySecondary},
|
||||
|
||||
{"archenemy", CardSet::PriorityReprint},
|
||||
{"arsenal", CardSet::PriorityReprint},
|
||||
{"box", CardSet::PriorityReprint},
|
||||
{"from_the_vault", CardSet::PriorityReprint},
|
||||
{"masterpiece", CardSet::PriorityReprint},
|
||||
{"masters", CardSet::PriorityReprint},
|
||||
{"memorabilia", CardSet::PriorityReprint},
|
||||
{"planechase", CardSet::PriorityReprint},
|
||||
{"premium_deck", CardSet::PriorityReprint},
|
||||
{"promo", CardSet::PriorityReprint},
|
||||
{"spellbook", CardSet::PriorityReprint},
|
||||
{"token", CardSet::PriorityReprint},
|
||||
{"treasure_chest", CardSet::PriorityReprint},
|
||||
|
||||
{"alchemy", CardSet::PriorityOther},
|
||||
{"funny", CardSet::PriorityOther},
|
||||
{"minigame", CardSet::PriorityOther},
|
||||
{"vanguard", CardSet::PriorityOther},
|
||||
};
|
||||
|
||||
class SetToDownload
|
||||
{
|
||||
|
|
@ -20,6 +45,7 @@ private:
|
|||
QList<QVariant> cards;
|
||||
QDate releaseDate;
|
||||
QString setType;
|
||||
CardSet::Priority priority;
|
||||
|
||||
public:
|
||||
const QString &getShortName() const
|
||||
|
|
@ -42,13 +68,18 @@ public:
|
|||
{
|
||||
return releaseDate;
|
||||
}
|
||||
CardSet::Priority getPriority() const
|
||||
{
|
||||
return priority;
|
||||
}
|
||||
SetToDownload(QString _shortName,
|
||||
QString _longName,
|
||||
QList<QVariant> _cards,
|
||||
CardSet::Priority _priority,
|
||||
QString _setType = QString(),
|
||||
const QDate &_releaseDate = QDate())
|
||||
: shortName(std::move(_shortName)), longName(std::move(_longName)), cards(std::move(_cards)),
|
||||
releaseDate(_releaseDate), setType(std::move(_setType))
|
||||
releaseDate(_releaseDate), setType(std::move(_setType)), priority(_priority)
|
||||
{
|
||||
}
|
||||
bool operator<(const SetToDownload &set) const
|
||||
|
|
@ -108,6 +139,7 @@ signals:
|
|||
|
||||
public:
|
||||
explicit OracleImporter(const QString &_dataDir, QObject *parent = nullptr);
|
||||
CardSet::Priority getSetPriority(QString &setType, QString &shortName);
|
||||
bool readSetsFromByteArray(const QByteArray &data);
|
||||
int startImport();
|
||||
bool saveToFile(const QString &fileName, const QString &sourceUrl, const QString &sourceVersion);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue