mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Clang-format (#3028)
* 1/3 Add .clang-format file and travis compilation check * 2/3 Run clang-format * 3/3 Fix compilation problems due to include reordering * 3bis/3 AfterControlStatement: false
This commit is contained in:
parent
8dbdd24c8e
commit
b29bd9e070
272 changed files with 13378 additions and 9535 deletions
|
|
@ -1,26 +1,25 @@
|
|||
#include "oracleimporter.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <QDebug>
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "qt-json/json.h"
|
||||
|
||||
OracleImporter::OracleImporter(const QString &_dataDir, QObject *parent)
|
||||
: CardDatabase(parent), dataDir(_dataDir)
|
||||
OracleImporter::OracleImporter(const QString &_dataDir, QObject *parent) : CardDatabase(parent), dataDir(_dataDir)
|
||||
{
|
||||
}
|
||||
|
||||
bool OracleImporter::readSetsFromByteArray(const QByteArray &data)
|
||||
{
|
||||
QList<SetToDownload> newSetList;
|
||||
|
||||
|
||||
bool ok;
|
||||
setsMap = QtJson::Json::parse(QString(data), ok).toMap();
|
||||
if (!ok) {
|
||||
qDebug() << "error: QtJson::Json::parse()";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
QListIterator<QVariant> it(setsMap.values());
|
||||
QVariantMap map;
|
||||
|
||||
|
|
@ -37,7 +36,7 @@ bool OracleImporter::readSetsFromByteArray(const QByteArray &data)
|
|||
editionCards = map.value("cards");
|
||||
setType = map.value("type").toString();
|
||||
// capitalize set type
|
||||
if(setType.length() > 0)
|
||||
if (setType.length() > 0)
|
||||
setType[0] = setType[0].toUpper();
|
||||
releaseDate = map.value("releaseDate").toDate();
|
||||
|
||||
|
|
@ -63,12 +62,11 @@ CardInfo *OracleImporter::addCard(const QString &setName,
|
|||
const QString &cardPT,
|
||||
int cardLoyalty,
|
||||
const QString &cardText,
|
||||
const QStringList & colors,
|
||||
const QList<CardRelation *> & relatedCards,
|
||||
const QList<CardRelation *> & reverseRelatedCards,
|
||||
const QStringList &colors,
|
||||
const QList<CardRelation *> &relatedCards,
|
||||
const QList<CardRelation *> &reverseRelatedCards,
|
||||
bool upsideDown,
|
||||
QString &rarity
|
||||
)
|
||||
QString &rarity)
|
||||
{
|
||||
QStringList cardTextRows = cardText.split("\n");
|
||||
|
||||
|
|
@ -76,7 +74,7 @@ CardInfo *OracleImporter::addCard(const QString &setName,
|
|||
cardName = cardName.replace("Æ", "AE");
|
||||
cardName = cardName.replace("’", "'");
|
||||
|
||||
CardInfo * card;
|
||||
CardInfo *card;
|
||||
if (cards.contains(cardName)) {
|
||||
card = cards.value(cardName);
|
||||
} else {
|
||||
|
|
@ -92,10 +90,13 @@ CardInfo *OracleImporter::addCard(const QString &setName,
|
|||
mArtifact = true;
|
||||
|
||||
// detect cards that enter the field tapped
|
||||
bool cipt = cardText.contains("Hideaway") || (cardText.contains(cardName + " enters the battlefield tapped") && !cardText.contains(cardName + " enters the battlefield tapped unless"));
|
||||
|
||||
bool cipt =
|
||||
cardText.contains("Hideaway") || (cardText.contains(cardName + " enters the battlefield tapped") &&
|
||||
!cardText.contains(cardName + " enters the battlefield tapped unless"));
|
||||
|
||||
// insert the card and its properties
|
||||
card = new CardInfo(cardName, isToken, cardCost, cmc, cardType, cardPT, cardText, colors, relatedCards, reverseRelatedCards, upsideDown, cardLoyalty, cipt);
|
||||
card = new CardInfo(cardName, isToken, cardCost, cmc, cardType, cardPT, cardText, colors, relatedCards,
|
||||
reverseRelatedCards, upsideDown, cardLoyalty, cipt);
|
||||
int tableRow = 1;
|
||||
QString mainCardType = card->getMainCardType();
|
||||
if ((mainCardType == "Land") || mArtifact)
|
||||
|
|
@ -105,7 +106,7 @@ CardInfo *OracleImporter::addCard(const QString &setName,
|
|||
else if (mainCardType == "Creature")
|
||||
tableRow = 2;
|
||||
card->setTableRow(tableRow);
|
||||
|
||||
|
||||
cards.insert(cardName, card);
|
||||
}
|
||||
card->setMuId(setName, cardId);
|
||||
|
|
@ -115,10 +116,9 @@ CardInfo *OracleImporter::addCard(const QString &setName,
|
|||
return card;
|
||||
}
|
||||
|
||||
void OracleImporter::extractColors(const QStringList & in, QStringList & out)
|
||||
void OracleImporter::extractColors(const QStringList &in, QStringList &out)
|
||||
{
|
||||
foreach(QString c, in)
|
||||
{
|
||||
foreach (QString c, in) {
|
||||
if (c == "White")
|
||||
out << "W";
|
||||
else if (c == "Blue")
|
||||
|
|
@ -137,7 +137,7 @@ void OracleImporter::extractColors(const QStringList & in, QStringList & out)
|
|||
int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data)
|
||||
{
|
||||
int cards = 0;
|
||||
|
||||
|
||||
QListIterator<QVariant> it(data.toList());
|
||||
QVariantMap map;
|
||||
QString cardName;
|
||||
|
|
@ -156,21 +156,19 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data)
|
|||
bool upsideDown = false;
|
||||
QMap<int, QVariantMap> splitCards;
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
while (it.hasNext()) {
|
||||
map = it.next().toMap();
|
||||
|
||||
QString layout = map.value("layout").toString();
|
||||
|
||||
if(layout == "token")
|
||||
if (layout == "token")
|
||||
continue;
|
||||
|
||||
if(layout == "split" || layout == "aftermath")
|
||||
{
|
||||
if (layout == "split" || layout == "aftermath") {
|
||||
// Enqueue split card for later handling
|
||||
cardId = map.contains("multiverseid") ? map.value("multiverseid").toInt() : 0;
|
||||
if (cardId)
|
||||
splitCards.insertMulti(cardId, map);
|
||||
splitCards.insertMulti(cardId, map);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -179,21 +177,22 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data)
|
|||
cardCost = map.contains("manaCost") ? map.value("manaCost").toString() : QString("");
|
||||
cmc = map.contains("cmc") ? map.value("cmc").toString() : QString("0");
|
||||
cardType = map.contains("type") ? map.value("type").toString() : QString("");
|
||||
cardPT = map.contains("power") || map.contains("toughness") ? map.value("power").toString() + QString('/') + map.value("toughness").toString() : QString("");
|
||||
cardPT = map.contains("power") || map.contains("toughness")
|
||||
? map.value("power").toString() + QString('/') + map.value("toughness").toString()
|
||||
: QString("");
|
||||
cardText = map.contains("text") ? map.value("text").toString() : QString("");
|
||||
cardId = map.contains("multiverseid") ? map.value("multiverseid").toInt() : 0;
|
||||
setNumber = map.contains("number") ? map.value("number").toString() : QString("");
|
||||
rarity = map.contains("rarity") ? map.value("rarity").toString() : QString("");
|
||||
cardLoyalty = map.contains("loyalty") ? map.value("loyalty").toInt() : 0;
|
||||
relatedCards = QList<CardRelation *>();
|
||||
if(map.contains("names"))
|
||||
foreach(const QString & name, map.value("names").toStringList()) {
|
||||
if(name != cardName)
|
||||
if (map.contains("names"))
|
||||
foreach (const QString &name, map.value("names").toStringList()) {
|
||||
if (name != cardName)
|
||||
relatedCards.append(new CardRelation(name, true));
|
||||
}
|
||||
|
||||
if(0 == QString::compare(map.value("layout").toString(), QString("flip"), Qt::CaseInsensitive))
|
||||
{
|
||||
if (0 == QString::compare(map.value("layout").toString(), QString("flip"), Qt::CaseInsensitive)) {
|
||||
QStringList cardNames = map.contains("names") ? map.value("names").toStringList() : QStringList();
|
||||
upsideDown = (cardNames.indexOf(cardName) > 0);
|
||||
} else {
|
||||
|
|
@ -203,26 +202,26 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data)
|
|||
colors.clear();
|
||||
extractColors(map.value("colors").toStringList(), colors);
|
||||
|
||||
CardInfo *card = addCard(set->getShortName(), cardName, false, cardId, setNumber, cardCost, cmc, cardType, cardPT, cardLoyalty, cardText, colors, relatedCards, reverseRelatedCards, upsideDown, rarity);
|
||||
CardInfo *card =
|
||||
addCard(set->getShortName(), cardName, false, cardId, setNumber, cardCost, cmc, cardType, cardPT,
|
||||
cardLoyalty, cardText, colors, relatedCards, reverseRelatedCards, upsideDown, rarity);
|
||||
|
||||
if (!set->contains(card)) {
|
||||
card->addToSet(set);
|
||||
cards++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// split cards handling - get all unique card muids
|
||||
QList<int> muids = splitCards.uniqueKeys();
|
||||
foreach(int muid, muids)
|
||||
{
|
||||
foreach (int muid, muids) {
|
||||
// get all cards for this specific muid
|
||||
QList<QVariantMap> maps = splitCards.values(muid);
|
||||
QStringList names;
|
||||
// now, reorder the cards using the ordered list of names
|
||||
QMap<int, QVariantMap> orderedMaps;
|
||||
foreach(QVariantMap map, maps)
|
||||
{
|
||||
if(names.isEmpty())
|
||||
foreach (QVariantMap map, maps) {
|
||||
if (names.isEmpty())
|
||||
names = map.contains("names") ? map.value("names").toStringList() : QStringList();
|
||||
QString name = map.value("name").toString();
|
||||
int index = names.indexOf(name);
|
||||
|
|
@ -236,7 +235,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data)
|
|||
cardType = "";
|
||||
cardPT = "";
|
||||
cardText = "";
|
||||
setNumber = "";
|
||||
setNumber = "";
|
||||
rarity = "";
|
||||
colors.clear();
|
||||
// this is currently an integer; can't accept 2 values
|
||||
|
|
@ -245,47 +244,39 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data)
|
|||
// loop cards and merge their contents
|
||||
QString prefix = QString(" // ");
|
||||
QString prefix2 = QString("\n\n---\n\n");
|
||||
foreach(QVariantMap map, orderedMaps.values())
|
||||
{
|
||||
if(map.contains("name"))
|
||||
{
|
||||
if(!cardName.isEmpty())
|
||||
cardName += (orderedMaps.count() > 2) ? QString("/") : prefix;
|
||||
foreach (QVariantMap map, orderedMaps.values()) {
|
||||
if (map.contains("name")) {
|
||||
if (!cardName.isEmpty())
|
||||
cardName += (orderedMaps.count() > 2) ? QString("/") : prefix;
|
||||
cardName += map.value("name").toString();
|
||||
}
|
||||
if(map.contains("manaCost"))
|
||||
{
|
||||
if(!cardCost.isEmpty())
|
||||
if (map.contains("manaCost")) {
|
||||
if (!cardCost.isEmpty())
|
||||
cardCost += prefix;
|
||||
cardCost += map.value("manaCost").toString();
|
||||
}
|
||||
if(map.contains("cmc"))
|
||||
{
|
||||
if(!cmc.isEmpty())
|
||||
if (map.contains("cmc")) {
|
||||
if (!cmc.isEmpty())
|
||||
cmc += prefix;
|
||||
cmc += map.value("cmc").toString();
|
||||
}
|
||||
if(map.contains("type"))
|
||||
{
|
||||
if(!cardType.isEmpty())
|
||||
if (map.contains("type")) {
|
||||
if (!cardType.isEmpty())
|
||||
cardType += prefix;
|
||||
cardType += map.value("type").toString();
|
||||
}
|
||||
if(map.contains("power") || map.contains("toughness"))
|
||||
{
|
||||
if(!cardPT.isEmpty())
|
||||
if (map.contains("power") || map.contains("toughness")) {
|
||||
if (!cardPT.isEmpty())
|
||||
cardPT += prefix;
|
||||
cardPT += map.value("power").toString() + QString('/') + map.value("toughness").toString();
|
||||
}
|
||||
if(map.contains("text"))
|
||||
{
|
||||
if(!cardText.isEmpty())
|
||||
if (map.contains("text")) {
|
||||
if (!cardText.isEmpty())
|
||||
cardText += prefix2;
|
||||
cardText += map.value("text").toString();
|
||||
}
|
||||
if(map.contains("number"))
|
||||
{
|
||||
if(setNumber.isEmpty())
|
||||
if (map.contains("number")) {
|
||||
if (setNumber.isEmpty())
|
||||
setNumber = map.value("number").toString();
|
||||
}
|
||||
|
||||
|
|
@ -293,19 +284,19 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data)
|
|||
}
|
||||
|
||||
colors.removeDuplicates();
|
||||
//Fortunately, there are no split cards that flip, transform or meld.
|
||||
// Fortunately, there are no split cards that flip, transform or meld.
|
||||
relatedCards = QList<CardRelation *>();
|
||||
reverseRelatedCards = QList<CardRelation *>();
|
||||
upsideDown = false;
|
||||
|
||||
// add the card
|
||||
CardInfo *card = addCard(set->getShortName(), cardName, false, muid, setNumber, cardCost, cmc, cardType, cardPT, cardLoyalty, cardText, colors, relatedCards, reverseRelatedCards, upsideDown, rarity);
|
||||
CardInfo *card = addCard(set->getShortName(), cardName, false, muid, setNumber, cardCost, cmc, cardType, cardPT,
|
||||
cardLoyalty, cardText, colors, relatedCards, reverseRelatedCards, upsideDown, rarity);
|
||||
|
||||
if (!set->contains(card)) {
|
||||
card->addToSet(set);
|
||||
cards++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return cards;
|
||||
|
|
@ -315,28 +306,28 @@ int OracleImporter::startImport()
|
|||
{
|
||||
clear();
|
||||
|
||||
int setCards = 0, setIndex= 0;
|
||||
int setCards = 0, setIndex = 0;
|
||||
QListIterator<SetToDownload> it(allSets);
|
||||
const SetToDownload * curSet;
|
||||
const SetToDownload *curSet;
|
||||
|
||||
// add an empty set for tokens
|
||||
CardSet *tokenSet = new CardSet(TOKENS_SETNAME, tr("Dummy set containing tokens"), "Tokens");
|
||||
sets.insert(TOKENS_SETNAME, tokenSet);
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
curSet = & it.next();
|
||||
CardSet *set = new CardSet(curSet->getShortName(), curSet->getLongName(), curSet->getSetType(), curSet->getReleaseDate());
|
||||
while (it.hasNext()) {
|
||||
curSet = &it.next();
|
||||
CardSet *set =
|
||||
new CardSet(curSet->getShortName(), curSet->getLongName(), curSet->getSetType(), curSet->getReleaseDate());
|
||||
if (!sets.contains(set->getShortName()))
|
||||
sets.insert(set->getShortName(), set);
|
||||
|
||||
int setCards = importTextSpoiler(set, curSet->getCards());
|
||||
|
||||
++setIndex;
|
||||
|
||||
|
||||
emit setIndexChanged(setCards, setIndex, curSet->getLongName());
|
||||
}
|
||||
|
||||
|
||||
emit setIndexChanged(setCards, setIndex, QString());
|
||||
|
||||
// total number of sets
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue