mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Add No annotations export option w/ shortcut (#3013)
This commit is contained in:
parent
5757d60b1d
commit
ebec30dd1c
11 changed files with 1777 additions and 1662 deletions
|
|
@ -10,64 +10,64 @@ 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() : 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))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
switch (fmt) {
|
||||
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);
|
||||
fmt = PlainTextFormat;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (result) {
|
||||
|
||||
if (result)
|
||||
{
|
||||
lastFileName = fileName;
|
||||
lastFileFormat = fmt;
|
||||
|
||||
emit deckLoaded();
|
||||
}
|
||||
|
||||
qDebug() << "Deck was loaded -" << result;
|
||||
return result;
|
||||
}
|
||||
|
|
@ -75,7 +75,8 @@ 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,14 +90,19 @@ bool DeckLoader::saveToFile(const QString &fileName, FileFormat fmt)
|
|||
{
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
switch (fmt) {
|
||||
switch (fmt)
|
||||
{
|
||||
case PlainTextFormat: result = saveToFile_Plain(&file); break;
|
||||
case CockatriceFormat: result = saveToFile_Native(&file); break;
|
||||
}
|
||||
if (result) {
|
||||
|
||||
if (result)
|
||||
{
|
||||
lastFileName = fileName;
|
||||
lastFileFormat = fmt;
|
||||
}
|
||||
|
|
@ -112,20 +118,21 @@ struct FormatDeckListForExport
|
|||
QString &mainBoardCards;
|
||||
QString &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{
|
||||
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 (!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){
|
||||
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
|
||||
|
|
@ -135,8 +142,8 @@ struct FormatDeckListForExport
|
|||
//Add a return at the end of the card
|
||||
sideBoardCards+="%0A";
|
||||
}
|
||||
//If it's a mainboard card, do the same thing, but for the mainboard card string
|
||||
else{
|
||||
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();
|
||||
|
|
@ -172,22 +179,26 @@ QString DeckLoader::exportDeckToDecklist()
|
|||
|
||||
DeckLoader::FileFormat DeckLoader::getFormatFromName(const QString &fileName)
|
||||
{
|
||||
if (fileName.endsWith(".cod", Qt::CaseInsensitive)) {
|
||||
if (fileName.endsWith(".cod", Qt::CaseInsensitive))
|
||||
{
|
||||
return CockatriceFormat;
|
||||
}
|
||||
return PlainTextFormat;
|
||||
}
|
||||
|
||||
bool DeckLoader::saveToStream_Plain(QTextStream &out)
|
||||
bool DeckLoader::saveToStream_Plain(QTextStream &out, bool addComments)
|
||||
{
|
||||
saveToStream_DeckHeader(out);
|
||||
if (addComments)
|
||||
{
|
||||
saveToStream_DeckHeader(out);
|
||||
}
|
||||
|
||||
// loop zones
|
||||
for (int i = 0; i < getRoot()->size(); i++) {
|
||||
const InnerDecklistNode *zoneNode =
|
||||
dynamic_cast<InnerDecklistNode *>(getRoot()->at(i));
|
||||
for (int i = 0; i < getRoot()->size(); i++)
|
||||
{
|
||||
const auto *zoneNode = dynamic_cast<InnerDecklistNode *>(getRoot()->at(i));
|
||||
|
||||
saveToStream_DeckZone(out, zoneNode);
|
||||
saveToStream_DeckZone(out, zoneNode, addComments);
|
||||
|
||||
// end of zone
|
||||
out << "\n";
|
||||
|
|
@ -198,88 +209,112 @@ bool DeckLoader::saveToStream_Plain(QTextStream &out)
|
|||
|
||||
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)
|
||||
{
|
||||
out << "// " << row << "\n";
|
||||
}
|
||||
out << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void DeckLoader::saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode)
|
||||
void DeckLoader::saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode, bool addComments)
|
||||
{
|
||||
// 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++) {
|
||||
DecklistCardNode *card =
|
||||
dynamic_cast<DecklistCardNode *>(
|
||||
zoneNode->at(j)
|
||||
);
|
||||
for (int j = 0; j < zoneNode->size(); j++)
|
||||
{
|
||||
auto *card = dynamic_cast<DecklistCardNode *>(zoneNode->at(j));
|
||||
|
||||
CardInfo *info = db->getCard(card->getName());
|
||||
QString cardType = info ? info->getMainCardType() : "unknown";
|
||||
|
||||
cardsByType.insert(cardType, card);
|
||||
|
||||
if(cardTotalByType.contains(cardType))
|
||||
if (cardTotalByType.contains(cardType))
|
||||
{
|
||||
cardTotalByType[cardType] += card->getNumber();
|
||||
}
|
||||
else
|
||||
{
|
||||
cardTotalByType[cardType] = card->getNumber();
|
||||
}
|
||||
|
||||
cardTotal += card->getNumber();
|
||||
}
|
||||
|
||||
out << "// " << cardTotal << " " << zoneNode->getVisibleName() << "\n";
|
||||
if (addComments)
|
||||
{
|
||||
out << "// " << cardTotal << " " << zoneNode->getVisibleName() << "\n";
|
||||
}
|
||||
|
||||
// print cards to stream
|
||||
foreach(QString cardType, cardsByType.uniqueKeys())
|
||||
{
|
||||
if (addComments)
|
||||
{
|
||||
out << "// " << cardTotalByType[cardType] << " " << cardType << "\n";
|
||||
}
|
||||
|
||||
out << "// " << cardTotalByType[cardType] << " " << cardType << "\n";
|
||||
QList <DecklistCardNode*> cards = cardsByType.values(cardType);
|
||||
|
||||
saveToStream_DeckZoneCards(out, zoneNode, cards);
|
||||
saveToStream_DeckZoneCards(out, zoneNode, cards, addComments);
|
||||
|
||||
out << "\n";
|
||||
if (addComments)
|
||||
{
|
||||
out << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeckLoader::saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklistNode *zoneNode, QList <DecklistCardNode*> cards)
|
||||
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)
|
||||
for (int i = cards.size() - 1; i >= 0; --i)
|
||||
{
|
||||
DecklistCardNode* card = cards[i];
|
||||
|
||||
if (zoneNode->getName() == DECK_ZONE_SIDE)
|
||||
if (zoneNode->getName() == DECK_ZONE_SIDE && addComments)
|
||||
{
|
||||
out << "SB: ";
|
||||
}
|
||||
|
||||
out << card->getNumber() << " " << card->getName() << "\n";
|
||||
out << card->getNumber() << " " << card->getName() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
QString DeckLoader::getCardZoneFromName(QString cardName, QString currentZoneName)
|
||||
{
|
||||
CardInfo *card = db->getCard(cardName);
|
||||
|
||||
if (card && card->getIsToken())
|
||||
{
|
||||
return DECK_ZONE_TOKENS;
|
||||
}
|
||||
|
||||
return currentZoneName;
|
||||
}
|
||||
|
||||
QString DeckLoader::getCompleteCardName(const QString cardName) const
|
||||
{
|
||||
if (db) {
|
||||
if (db)
|
||||
{
|
||||
CardInfo *temp = db->getCardBySimpleName(cardName);
|
||||
if (temp)
|
||||
{
|
||||
return temp->getName();
|
||||
}
|
||||
}
|
||||
|
||||
return cardName;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue