mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
Extract helper.
This commit is contained in:
parent
ef19ac8a69
commit
331fb24125
1 changed files with 25 additions and 9 deletions
|
|
@ -96,16 +96,34 @@ bool OracleImporter::readSetsFromByteArray(QByteArray data)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The priority order used to pick a card's main type when a card has multiple
|
||||||
|
* types (e.g. "Artifact Creature") or multiple faces (e.g. split/adventure cards).
|
||||||
|
* A lower index means a higher priority.
|
||||||
|
*/
|
||||||
|
static const QStringList &mainCardTypePriority()
|
||||||
|
{
|
||||||
|
static const QStringList priority = {"Planeswalker", "Creature", "Land", "Sorcery",
|
||||||
|
"Instant", "Artifact", "Enchantment"};
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the priority (index) of the given main card type. Known types map to their
|
||||||
|
* position in {@link mainCardTypePriority()}, unknown types map to -1 (lowest priority).
|
||||||
|
*/
|
||||||
|
static int mainCardTypePriority(const QString &mainCardType)
|
||||||
|
{
|
||||||
|
return mainCardTypePriority().indexOf(mainCardType);
|
||||||
|
}
|
||||||
|
|
||||||
static QString getMainCardType(const QStringList &typeList)
|
static QString getMainCardType(const QStringList &typeList)
|
||||||
{
|
{
|
||||||
if (typeList.isEmpty()) {
|
if (typeList.isEmpty()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static const QStringList typePriority = {"Planeswalker", "Creature", "Land", "Sorcery",
|
for (const auto &type : mainCardTypePriority()) {
|
||||||
"Instant", "Artifact", "Enchantment"};
|
|
||||||
|
|
||||||
for (const auto &type : typePriority) {
|
|
||||||
if (typeList.contains(type)) {
|
if (typeList.contains(type)) {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
@ -463,11 +481,9 @@ int OracleImporter::importCardsFromSet(const CardSetPtr ¤tSet, const QJson
|
||||||
} else if (prop == "maintype") {
|
} else if (prop == "maintype") {
|
||||||
// Use the same priority as getMainCardType() to pick the
|
// Use the same priority as getMainCardType() to pick the
|
||||||
// "best" type across faces — e.g. Creature over Instant
|
// "best" type across faces — e.g. Creature over Instant
|
||||||
// for adventure cards.
|
// for adventure cards like Bonecrusher Giant.
|
||||||
static const QStringList typePriority = {
|
int currentPriority = mainCardTypePriority(originalPropertyValue);
|
||||||
"Planeswalker", "Creature", "Land", "Sorcery", "Instant", "Artifact", "Enchantment"};
|
int newPriority = mainCardTypePriority(thisCardPropertyValue);
|
||||||
int currentPriority = typePriority.indexOf(originalPropertyValue);
|
|
||||||
int newPriority = typePriority.indexOf(thisCardPropertyValue);
|
|
||||||
if (newPriority >= 0 && (currentPriority < 0 || newPriority < currentPriority)) {
|
if (newPriority >= 0 && (currentPriority < 0 || newPriority < currentPriority)) {
|
||||||
properties.insert(prop, thisCardPropertyValue);
|
properties.insert(prop, thisCardPropertyValue);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue