mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -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
|
|
@ -579,16 +579,30 @@ bool DeckList::loadFromFile_Plain(QIODevice *device)
|
|||
return loadFromStream_Plain(in);
|
||||
}
|
||||
|
||||
struct WriteToStream {
|
||||
QTextStream &stream;
|
||||
|
||||
WriteToStream(QTextStream &_stream) : stream(_stream) {}
|
||||
|
||||
void operator()(
|
||||
const InnerDecklistNode *node,
|
||||
const DecklistCardNode *card
|
||||
) {
|
||||
if (node->getName() == "side") {
|
||||
stream << "SB: ";
|
||||
}
|
||||
stream << QString("%1 %2\n").arg(
|
||||
card->getNumber()
|
||||
).arg(
|
||||
card->getName()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
bool DeckList::saveToStream_Plain(QTextStream &out)
|
||||
{
|
||||
// Support for this is only possible if the internal structure doesn't get more complicated.
|
||||
for (int i = 0; i < root->size(); i++) {
|
||||
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
|
||||
for (int j = 0; j < node->size(); j++) {
|
||||
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
|
||||
out << QString("%1%2 %3\n").arg(node->getName() == "side" ? "SB: " : "").arg(card->getNumber()).arg(card->getName());
|
||||
}
|
||||
}
|
||||
WriteToStream writeToStream(out);
|
||||
forEachCard(writeToStream);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ public:
|
|||
QString getName() const { return name; }
|
||||
void setName(const QString &_name) { name = _name; }
|
||||
float getPrice() const { return price; }
|
||||
|
||||
void setPrice(const float _price) { price = _price; }
|
||||
};
|
||||
|
||||
|
|
@ -169,6 +170,28 @@ public:
|
|||
InnerDecklistNode *getRoot() const { return root; }
|
||||
DecklistCardNode *addCard(const QString &cardName, const QString &zoneName);
|
||||
bool deleteNode(AbstractDecklistNode *node, InnerDecklistNode *rootNode = 0);
|
||||
|
||||
/**
|
||||
* Calls a given function object for each card in the deck. It must
|
||||
* take a InnerDecklistNode* as its first argument and a
|
||||
* DecklistCardNode* as its second.
|
||||
*/
|
||||
template <typename Callback>
|
||||
void forEachCard(Callback &callback) const {
|
||||
// Support for this is only possible if the internal structure
|
||||
// doesn't get more complicated.
|
||||
for (int i = 0; i < root->size(); i++) {
|
||||
const InnerDecklistNode *node =
|
||||
dynamic_cast<InnerDecklistNode *>(root->at(i));
|
||||
for (int j = 0; j < node->size(); j++) {
|
||||
const DecklistCardNode *card =
|
||||
dynamic_cast<DecklistCardNode *>(
|
||||
node->at(j)
|
||||
);
|
||||
callback(node, card);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue