mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Fix #45: don't send tokens to deckstats.
This commit is contained in:
parent
4d6f46b06e
commit
7cbe410172
8 changed files with 105 additions and 47 deletions
|
|
@ -7,8 +7,10 @@
|
|||
#include <QMessageBox>
|
||||
#include <QDesktopServices>
|
||||
|
||||
DeckStatsInterface::DeckStatsInterface(QObject *parent)
|
||||
: QObject(parent)
|
||||
DeckStatsInterface::DeckStatsInterface(
|
||||
CardDatabase &_cardDatabase,
|
||||
QObject *parent
|
||||
) : QObject(parent), cardDatabase(_cardDatabase)
|
||||
{
|
||||
manager = new QNetworkAccessManager(this);
|
||||
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(queryFinished(QNetworkReply *)));
|
||||
|
|
@ -42,7 +44,11 @@ void DeckStatsInterface::queryFinished(QNetworkReply *reply)
|
|||
void DeckStatsInterface::analyzeDeck(DeckList *deck)
|
||||
{
|
||||
QUrl params;
|
||||
params.addQueryItem("deck", deck->writeToString_Plain());
|
||||
|
||||
DeckList deckWithoutTokens;
|
||||
copyDeckWithoutTokens(*deck, deckWithoutTokens);
|
||||
|
||||
params.addQueryItem("deck", deckWithoutTokens.writeToString_Plain());
|
||||
QByteArray data;
|
||||
data.append(params.encodedQuery());
|
||||
|
||||
|
|
@ -51,3 +57,30 @@ void DeckStatsInterface::analyzeDeck(DeckList *deck)
|
|||
|
||||
manager->post(request, data);
|
||||
}
|
||||
|
||||
struct CopyIfNotAToken {
|
||||
CardDatabase &cardDatabase;
|
||||
DeckList &destination;
|
||||
|
||||
CopyIfNotAToken(
|
||||
CardDatabase &_cardDatabase,
|
||||
DeckList &_destination
|
||||
) : cardDatabase(_cardDatabase), destination(_destination) {};
|
||||
|
||||
void operator()(
|
||||
const InnerDecklistNode *node,
|
||||
const DecklistCardNode *card
|
||||
) const {
|
||||
if (!cardDatabase.getCard(card->getName())->getIsToken()) {
|
||||
destination.addCard(card->getName(), node->getName());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void DeckStatsInterface::copyDeckWithoutTokens(
|
||||
const DeckList &source,
|
||||
DeckList &destination
|
||||
) {
|
||||
CopyIfNotAToken copyIfNotAToken(cardDatabase, destination);
|
||||
source.forEachCard(copyIfNotAToken);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue