Example #1
0
    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.
            return;
        }

        //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
        {
            mainBoardCards+=QString::number(card->getNumber());
            mainBoardCards+="%20";
            mainBoardCards+=card->getName();
            mainBoardCards+="%0A";
        }
    }
bool CardDatabase::saveToFile(const QString &fileName, bool tokens)
{
    QFile file(fileName);
    if (!file.open(QIODevice::WriteOnly))
        return false;
    QXmlStreamWriter xml(&file);

    xml.setAutoFormatting(true);
    xml.writeStartDocument();
    xml.writeStartElement("cockatrice_carddatabase");
    xml.writeAttribute("version", QString::number(versionNeeded));

    if (!tokens) {
        xml.writeStartElement("sets");
        QHashIterator<QString, CardSet *> setIterator(sets);
        while (setIterator.hasNext())
            xml << setIterator.next().value();
        xml.writeEndElement(); // sets
    }

    xml.writeStartElement("cards");
    QHashIterator<QString, CardInfo *> cardIterator(cards);
    while (cardIterator.hasNext()) {
        CardInfo *card = cardIterator.next().value();
        if (tokens == card->getIsToken()) {
            xml << card;
        }
    }
    xml.writeEndElement(); // cards

    xml.writeEndElement(); // cockatrice_carddatabase
    xml.writeEndDocument();

    return true;
}