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,53 +1,50 @@
|
|||
#include <QStringList>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include "deck_loader.h"
|
||||
#include "decklist.h"
|
||||
#include "carddatabase.h"
|
||||
#include "decklist.h"
|
||||
#include "main.h"
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QStringList>
|
||||
|
||||
const QStringList DeckLoader::fileNameFilters = QStringList()
|
||||
<< QObject::tr("Common deck formats (*.cod *.dec *.txt *.mwDeck)")
|
||||
<< QObject::tr("All files (*.*)");
|
||||
const QStringList DeckLoader::fileNameFilters =
|
||||
QStringList() << QObject::tr("Common deck formats (*.cod *.dec *.txt *.mwDeck)") << QObject::tr("All files (*.*)");
|
||||
|
||||
DeckLoader::DeckLoader() : DeckList(), lastFileName(QString()), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DeckLoader::DeckLoader(const QString &nativeString) : DeckList(nativeString), lastFileName(QString()), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
||||
DeckLoader::DeckLoader(const QString &nativeString)
|
||||
: DeckList(nativeString), lastFileName(QString()), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DeckLoader::DeckLoader(const DeckList &other) : DeckList(other), lastFileName(QString()), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
||||
DeckLoader::DeckLoader(const DeckList &other)
|
||||
: DeckList(other), lastFileName(QString()), lastFileFormat(CockatriceFormat), lastRemoteDeckId(-1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DeckLoader::DeckLoader(const DeckLoader &other) : DeckList(other), lastFileName(other.lastFileName), lastFileFormat(other.lastFileFormat), lastRemoteDeckId(other.lastRemoteDeckId)
|
||||
DeckLoader::DeckLoader(const DeckLoader &other)
|
||||
: DeckList(other), lastFileName(other.lastFileName), lastFileFormat(other.lastFileFormat),
|
||||
lastRemoteDeckId(other.lastRemoteDeckId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
switch (fmt)
|
||||
{
|
||||
case PlainTextFormat: result = loadFromFile_Plain(&file); break;
|
||||
case CockatriceFormat:
|
||||
{
|
||||
switch (fmt) {
|
||||
case PlainTextFormat:
|
||||
result = loadFromFile_Plain(&file);
|
||||
break;
|
||||
case CockatriceFormat: {
|
||||
result = loadFromFile_Native(&file);
|
||||
qDebug() << "Loaded from" << fileName << "-" << result;
|
||||
if (!result)
|
||||
{
|
||||
if (!result) {
|
||||
qDebug() << "Retying as plain format";
|
||||
file.seek(0);
|
||||
result = loadFromFile_Plain(&file);
|
||||
|
|
@ -60,8 +57,7 @@ bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
|
|||
break;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (result) {
|
||||
lastFileName = fileName;
|
||||
lastFileFormat = fmt;
|
||||
|
||||
|
|
@ -75,8 +71,7 @@ bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
|
|||
bool DeckLoader::loadFromRemote(const QString &nativeString, int remoteDeckId)
|
||||
{
|
||||
bool result = loadFromString_Native(nativeString);
|
||||
if (result)
|
||||
{
|
||||
if (result) {
|
||||
lastFileName = QString();
|
||||
lastFileFormat = CockatriceFormat;
|
||||
lastRemoteDeckId = remoteDeckId;
|
||||
|
|
@ -89,98 +84,96 @@ bool DeckLoader::loadFromRemote(const QString &nativeString, int remoteDeckId)
|
|||
bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
switch (fmt)
|
||||
{
|
||||
case PlainTextFormat: result = saveToFile_Plain(&file); break;
|
||||
case CockatriceFormat: result = saveToFile_Native(&file); break;
|
||||
switch (fmt) {
|
||||
case PlainTextFormat:
|
||||
result = saveToFile_Plain(&file);
|
||||
break;
|
||||
case CockatriceFormat:
|
||||
result = saveToFile_Native(&file);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (result) {
|
||||
lastFileName = fileName;
|
||||
lastFileFormat = fmt;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//This struct is here to support the forEachCard function call, defined in decklist. It
|
||||
//requires a function to be called for each card, and passes an inner node and a card for
|
||||
//each card in the decklist.
|
||||
// This struct is here to support the forEachCard function call, defined in decklist. It
|
||||
// requires a function to be called for each card, and passes an inner node and a card for
|
||||
// each card in the decklist.
|
||||
struct FormatDeckListForExport
|
||||
{
|
||||
//Create refrences for the strings that will be passed in.
|
||||
// Create refrences for the strings that will be passed in.
|
||||
QString &mainBoardCards;
|
||||
QString &sideBoardCards;
|
||||
//create main operator for struct, allowing the foreachcard to work.
|
||||
FormatDeckListForExport(QString &_mainBoardCards, QString &_sideBoardCards) : mainBoardCards(_mainBoardCards), sideBoardCards(_sideBoardCards){};
|
||||
// create main operator for struct, allowing the foreachcard to work.
|
||||
FormatDeckListForExport(QString &_mainBoardCards, QString &_sideBoardCards)
|
||||
: mainBoardCards(_mainBoardCards), sideBoardCards(_sideBoardCards){};
|
||||
|
||||
void operator()(const InnerDecklistNode *node, const DecklistCardNode *card) const
|
||||
{
|
||||
//Get the card name
|
||||
CardInfo * dbCard = db->getCard(card->getName());
|
||||
if (!dbCard || dbCard->getIsToken())
|
||||
{
|
||||
//If it's a token, we don't care about the card.
|
||||
// Get the card name
|
||||
CardInfo *dbCard = db->getCard(card->getName());
|
||||
if (!dbCard || dbCard->getIsToken()) {
|
||||
// If it's a token, we don't care about the card.
|
||||
return;
|
||||
}
|
||||
|
||||
//Check if it's a sideboard card.
|
||||
if (node->getName() == DECK_ZONE_SIDE)
|
||||
// Check if it's a sideboard card.
|
||||
if (node->getName() == DECK_ZONE_SIDE) {
|
||||
// Get the number of cards and add the card name
|
||||
sideBoardCards += QString::number(card->getNumber());
|
||||
// Add a space between card num and name
|
||||
sideBoardCards += "%20";
|
||||
// Add card name
|
||||
sideBoardCards += card->getName();
|
||||
// Add a return at the end of the card
|
||||
sideBoardCards += "%0A";
|
||||
} else // If it's a mainboard card, do the same thing, but for the mainboard card string
|
||||
{
|
||||
//Get the number of cards and add the card name
|
||||
sideBoardCards+=QString::number(card->getNumber());
|
||||
//Add a space between card num and name
|
||||
sideBoardCards+="%20";
|
||||
//Add card name
|
||||
sideBoardCards+=card->getName();
|
||||
//Add a return at the end of the card
|
||||
sideBoardCards+="%0A";
|
||||
}
|
||||
else //If it's a mainboard card, do the same thing, but for the mainboard card string
|
||||
{
|
||||
mainBoardCards+=QString::number(card->getNumber());
|
||||
mainBoardCards+="%20";
|
||||
mainBoardCards+=card->getName();
|
||||
mainBoardCards+="%0A";
|
||||
mainBoardCards += QString::number(card->getNumber());
|
||||
mainBoardCards += "%20";
|
||||
mainBoardCards += card->getName();
|
||||
mainBoardCards += "%0A";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Export deck to decklist function, called to format the deck in a way to be sent to a server
|
||||
// Export deck to decklist function, called to format the deck in a way to be sent to a server
|
||||
QString DeckLoader::exportDeckToDecklist()
|
||||
{
|
||||
//Add the base url
|
||||
// Add the base url
|
||||
QString deckString = "https://www.decklist.org/?";
|
||||
//Create two strings to pass to function
|
||||
// Create two strings to pass to function
|
||||
QString mainBoardCards, sideBoardCards;
|
||||
//Set up the struct to call.
|
||||
// Set up the struct to call.
|
||||
FormatDeckListForExport formatDeckListForExport(mainBoardCards, sideBoardCards);
|
||||
//call our struct function for each card in the deck
|
||||
// call our struct function for each card in the deck
|
||||
forEachCard(formatDeckListForExport);
|
||||
//Remove the extra return at the end of the last cards
|
||||
// Remove the extra return at the end of the last cards
|
||||
mainBoardCards.chop(3);
|
||||
sideBoardCards.chop(3);
|
||||
//if after we've called it for each card, and the strings are empty, we know that
|
||||
//there were no non-token cards in the deck, so show an error message.
|
||||
if((QString::compare(mainBoardCards, "", Qt::CaseInsensitive) == 0) &&
|
||||
(QString::compare(sideBoardCards, "", Qt::CaseInsensitive) == 0)) {
|
||||
// if after we've called it for each card, and the strings are empty, we know that
|
||||
// there were no non-token cards in the deck, so show an error message.
|
||||
if ((QString::compare(mainBoardCards, "", Qt::CaseInsensitive) == 0) &&
|
||||
(QString::compare(sideBoardCards, "", Qt::CaseInsensitive) == 0)) {
|
||||
return "";
|
||||
}
|
||||
//return a string with the url for decklist export
|
||||
deckString+="deckmain="+mainBoardCards+"&deckside="+sideBoardCards;
|
||||
// return a string with the url for decklist export
|
||||
deckString += "deckmain=" + mainBoardCards + "&deckside=" + sideBoardCards;
|
||||
return deckString;
|
||||
}
|
||||
|
||||
DeckLoader::FileFormat DeckLoader::getFormatFromName(const QString &fileName)
|
||||
{
|
||||
if (fileName.endsWith(".cod", Qt::CaseInsensitive))
|
||||
{
|
||||
if (fileName.endsWith(".cod", Qt::CaseInsensitive)) {
|
||||
return CockatriceFormat;
|
||||
}
|
||||
return PlainTextFormat;
|
||||
|
|
@ -188,14 +181,12 @@ DeckLoader::FileFormat DeckLoader::getFormatFromName(const QString &fileName)
|
|||
|
||||
bool DeckLoader::saveToStream_Plain(QTextStream &out, bool addComments)
|
||||
{
|
||||
if (addComments)
|
||||
{
|
||||
if (addComments) {
|
||||
saveToStream_DeckHeader(out);
|
||||
}
|
||||
|
||||
// loop zones
|
||||
for (int i = 0; i < getRoot()->size(); i++)
|
||||
{
|
||||
for (int i = 0; i < getRoot()->size(); i++) {
|
||||
const auto *zoneNode = dynamic_cast<InnerDecklistNode *>(getRoot()->at(i));
|
||||
|
||||
saveToStream_DeckZone(out, zoneNode, addComments);
|
||||
|
|
@ -209,16 +200,13 @@ bool DeckLoader::saveToStream_Plain(QTextStream &out, bool addComments)
|
|||
|
||||
void DeckLoader::saveToStream_DeckHeader(QTextStream &out)
|
||||
{
|
||||
if (!getName().isEmpty())
|
||||
{
|
||||
if (!getName().isEmpty()) {
|
||||
out << "// " << getName() << "\n\n";
|
||||
}
|
||||
|
||||
if (!getComments().isEmpty())
|
||||
{
|
||||
if (!getComments().isEmpty()) {
|
||||
QStringList commentRows = getComments().split(QRegExp("\n|\r\n|\r"));
|
||||
foreach(QString row, commentRows)
|
||||
{
|
||||
foreach (QString row, commentRows) {
|
||||
out << "// " << row << "\n";
|
||||
}
|
||||
out << "\n";
|
||||
|
|
@ -227,13 +215,12 @@ void DeckLoader::saveToStream_DeckHeader(QTextStream &out)
|
|||
|
||||
void DeckLoader::saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode, bool addComments)
|
||||
{
|
||||
// group cards by card type and count the subtotals
|
||||
QMultiMap<QString, DecklistCardNode*> cardsByType;
|
||||
// group cards by card type and count the subtotals
|
||||
QMultiMap<QString, DecklistCardNode *> cardsByType;
|
||||
QMap<QString, int> cardTotalByType;
|
||||
int cardTotal = 0;
|
||||
|
||||
for (int j = 0; j < zoneNode->size(); j++)
|
||||
{
|
||||
for (int j = 0; j < zoneNode->size(); j++) {
|
||||
auto *card = dynamic_cast<DecklistCardNode *>(zoneNode->at(j));
|
||||
|
||||
CardInfo *info = db->getCard(card->getName());
|
||||
|
|
@ -241,51 +228,45 @@ void DeckLoader::saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode
|
|||
|
||||
cardsByType.insert(cardType, card);
|
||||
|
||||
if (cardTotalByType.contains(cardType))
|
||||
{
|
||||
if (cardTotalByType.contains(cardType)) {
|
||||
cardTotalByType[cardType] += card->getNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
cardTotalByType[cardType] = card->getNumber();
|
||||
}
|
||||
|
||||
cardTotal += card->getNumber();
|
||||
}
|
||||
|
||||
if (addComments)
|
||||
{
|
||||
if (addComments) {
|
||||
out << "// " << cardTotal << " " << zoneNode->getVisibleName() << "\n";
|
||||
}
|
||||
|
||||
// print cards to stream
|
||||
foreach(QString cardType, cardsByType.uniqueKeys())
|
||||
{
|
||||
if (addComments)
|
||||
{
|
||||
foreach (QString cardType, cardsByType.uniqueKeys()) {
|
||||
if (addComments) {
|
||||
out << "// " << cardTotalByType[cardType] << " " << cardType << "\n";
|
||||
}
|
||||
|
||||
QList <DecklistCardNode*> cards = cardsByType.values(cardType);
|
||||
QList<DecklistCardNode *> cards = cardsByType.values(cardType);
|
||||
|
||||
saveToStream_DeckZoneCards(out, zoneNode, cards, addComments);
|
||||
|
||||
if (addComments)
|
||||
{
|
||||
if (addComments) {
|
||||
out << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeckLoader::saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklistNode *zoneNode, QList <DecklistCardNode*> cards, bool addComments)
|
||||
void DeckLoader::saveToStream_DeckZoneCards(QTextStream &out,
|
||||
const InnerDecklistNode *zoneNode,
|
||||
QList<DecklistCardNode *> cards,
|
||||
bool addComments)
|
||||
{
|
||||
// QMultiMap sorts values in reverse order
|
||||
for (int i = cards.size() - 1; i >= 0; --i)
|
||||
{
|
||||
DecklistCardNode* card = cards[i];
|
||||
for (int i = cards.size() - 1; i >= 0; --i) {
|
||||
DecklistCardNode *card = cards[i];
|
||||
|
||||
if (zoneNode->getName() == DECK_ZONE_SIDE && addComments)
|
||||
{
|
||||
if (zoneNode->getName() == DECK_ZONE_SIDE && addComments) {
|
||||
out << "SB: ";
|
||||
}
|
||||
|
||||
|
|
@ -297,8 +278,7 @@ QString DeckLoader::getCardZoneFromName(QString cardName, QString currentZoneNam
|
|||
{
|
||||
CardInfo *card = db->getCard(cardName);
|
||||
|
||||
if (card && card->getIsToken())
|
||||
{
|
||||
if (card && card->getIsToken()) {
|
||||
return DECK_ZONE_TOKENS;
|
||||
}
|
||||
|
||||
|
|
@ -307,11 +287,9 @@ QString DeckLoader::getCardZoneFromName(QString cardName, QString currentZoneNam
|
|||
|
||||
QString DeckLoader::getCompleteCardName(const QString cardName) const
|
||||
{
|
||||
if (db)
|
||||
{
|
||||
if (db) {
|
||||
CardInfo *temp = db->getCardBySimpleName(cardName);
|
||||
if (temp)
|
||||
{
|
||||
if (temp) {
|
||||
return temp->getName();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue