Improved token loading
This commit is contained in:
parent
339945e089
commit
36f6907fa3
10 changed files with 79 additions and 53 deletions
|
@ -190,9 +190,19 @@ void DeckLoader::saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklis
|
||||||
{
|
{
|
||||||
DecklistCardNode* card = cards[i];
|
DecklistCardNode* card = cards[i];
|
||||||
|
|
||||||
if (zoneNode->getName() == "side")
|
if (zoneNode->getName() == DECK_ZONE_SIDE)
|
||||||
out << "SB: ";
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ protected:
|
||||||
void saveToStream_DeckHeader(QTextStream &out);
|
void saveToStream_DeckHeader(QTextStream &out);
|
||||||
void saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode);
|
void saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode);
|
||||||
void saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklistNode *zoneNode, QList <DecklistCardNode*> cards);
|
void saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklistNode *zoneNode, QList <DecklistCardNode*> cards);
|
||||||
|
virtual QString getCardZoneFromName(QString cardName, QString currentZoneName);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -82,7 +82,7 @@ void DeckViewCard::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setWidth(3);
|
pen.setWidth(3);
|
||||||
pen.setJoinStyle(Qt::MiterJoin);
|
pen.setJoinStyle(Qt::MiterJoin);
|
||||||
pen.setColor(originZone == "main" ? Qt::green : Qt::red);
|
pen.setColor(originZone == DECK_ZONE_MAIN ? Qt::green : Qt::red);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2.5));
|
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2.5));
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
@ -134,10 +134,10 @@ void DeckView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
m.set_card_name(c->getName().toStdString());
|
m.set_card_name(c->getName().toStdString());
|
||||||
m.set_start_zone(zone->getName().toStdString());
|
m.set_start_zone(zone->getName().toStdString());
|
||||||
|
|
||||||
if (zone->getName() == "main")
|
if (zone->getName() == DECK_ZONE_MAIN)
|
||||||
m.set_target_zone("side");
|
m.set_target_zone(DECK_ZONE_SIDE);
|
||||||
else if (zone->getName() == "side")
|
else if (zone->getName() == DECK_ZONE_SIDE)
|
||||||
m.set_target_zone("main");
|
m.set_target_zone(DECK_ZONE_MAIN);
|
||||||
else // Trying to move from another zone
|
else // Trying to move from another zone
|
||||||
m.set_target_zone(zone->getName().toStdString());
|
m.set_target_zone(zone->getName().toStdString());
|
||||||
|
|
||||||
|
|
|
@ -857,7 +857,7 @@ void Player::setDeck(const DeckLoader &_deck)
|
||||||
|
|
||||||
createPredefinedTokenMenu->clear();
|
createPredefinedTokenMenu->clear();
|
||||||
predefinedTokens.clear();
|
predefinedTokens.clear();
|
||||||
InnerDecklistNode *tokenZone = dynamic_cast<InnerDecklistNode *>(deck->getRoot()->findChild("tokens"));
|
InnerDecklistNode *tokenZone = dynamic_cast<InnerDecklistNode *>(deck->getRoot()->findChild(DECK_ZONE_TOKENS));
|
||||||
|
|
||||||
if (tokenZone)
|
if (tokenZone)
|
||||||
for (int i = 0; i < tokenZone->size(); ++i) {
|
for (int i = 0; i < tokenZone->size(); ++i) {
|
||||||
|
|
|
@ -821,7 +821,7 @@ void TabDeckEditor::addCardHelper(QString zoneName)
|
||||||
if(!info)
|
if(!info)
|
||||||
return;
|
return;
|
||||||
if (info->getIsToken())
|
if (info->getIsToken())
|
||||||
zoneName = "tokens";
|
zoneName = DECK_ZONE_TOKENS;
|
||||||
|
|
||||||
QModelIndex newCardIndex = deckModel->addCard(info->getName(), zoneName);
|
QModelIndex newCardIndex = deckModel->addCard(info->getName(), zoneName);
|
||||||
recursiveExpand(newCardIndex);
|
recursiveExpand(newCardIndex);
|
||||||
|
@ -843,7 +843,7 @@ void TabDeckEditor::actSwapCard()
|
||||||
const QString zoneName = gparent.sibling(gparent.row(), 1).data().toString();
|
const QString zoneName = gparent.sibling(gparent.row(), 1).data().toString();
|
||||||
actDecrement();
|
actDecrement();
|
||||||
|
|
||||||
const QString otherZoneName = zoneName == "Maindeck" ? "side" : "main";
|
const QString otherZoneName = zoneName == "Maindeck" ? DECK_ZONE_SIDE : DECK_ZONE_MAIN;
|
||||||
|
|
||||||
QModelIndex newCardIndex = deckModel->addCard(cardName, otherZoneName);
|
QModelIndex newCardIndex = deckModel->addCard(cardName, otherZoneName);
|
||||||
recursiveExpand(newCardIndex);
|
recursiveExpand(newCardIndex);
|
||||||
|
@ -856,12 +856,12 @@ void TabDeckEditor::actAddCard()
|
||||||
if(QApplication::keyboardModifiers() & Qt::ControlModifier)
|
if(QApplication::keyboardModifiers() & Qt::ControlModifier)
|
||||||
actAddCardToSideboard();
|
actAddCardToSideboard();
|
||||||
else
|
else
|
||||||
addCardHelper("main");
|
addCardHelper(DECK_ZONE_MAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckEditor::actAddCardToSideboard()
|
void TabDeckEditor::actAddCardToSideboard()
|
||||||
{
|
{
|
||||||
addCardHelper("side");
|
addCardHelper(DECK_ZONE_SIDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckEditor::actRemoveCard()
|
void TabDeckEditor::actRemoveCard()
|
||||||
|
@ -898,7 +898,7 @@ void TabDeckEditor::decrementCardHelper(QString zoneName)
|
||||||
if(!info)
|
if(!info)
|
||||||
return;
|
return;
|
||||||
if (info->getIsToken())
|
if (info->getIsToken())
|
||||||
zoneName = "tokens";
|
zoneName = DECK_ZONE_TOKENS;
|
||||||
|
|
||||||
idx = deckModel->findCard(info->getName(), zoneName);
|
idx = deckModel->findCard(info->getName(), zoneName);
|
||||||
offsetCountAtIndex(idx, -1);
|
offsetCountAtIndex(idx, -1);
|
||||||
|
@ -906,12 +906,12 @@ void TabDeckEditor::decrementCardHelper(QString zoneName)
|
||||||
|
|
||||||
void TabDeckEditor::actDecrementCard()
|
void TabDeckEditor::actDecrementCard()
|
||||||
{
|
{
|
||||||
decrementCardHelper("main");
|
decrementCardHelper(DECK_ZONE_MAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckEditor::actDecrementCardFromSideboard()
|
void TabDeckEditor::actDecrementCardFromSideboard()
|
||||||
{
|
{
|
||||||
decrementCardHelper("side");
|
decrementCardHelper(DECK_ZONE_SIDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckEditor::actIncrement()
|
void TabDeckEditor::actIncrement()
|
||||||
|
|
|
@ -109,7 +109,7 @@ struct CopyMainOrSide {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DecklistCardNode *addedCard;
|
DecklistCardNode *addedCard;
|
||||||
if(node->getName() == "side")
|
if(node->getName() == DECK_ZONE_SIDE)
|
||||||
addedCard = sideboard.addCard(card->getName(), node->getName());
|
addedCard = sideboard.addCard(card->getName(), node->getName());
|
||||||
else
|
else
|
||||||
addedCard = mainboard.addCard(card->getName(), node->getName());
|
addedCard = mainboard.addCard(card->getName(), node->getName());
|
||||||
|
|
|
@ -95,11 +95,11 @@ InnerDecklistNode::~InnerDecklistNode()
|
||||||
|
|
||||||
QString InnerDecklistNode::visibleNameFromName(const QString &_name)
|
QString InnerDecklistNode::visibleNameFromName(const QString &_name)
|
||||||
{
|
{
|
||||||
if (_name == "main")
|
if (_name == DECK_ZONE_MAIN)
|
||||||
return QObject::tr("Maindeck");
|
return QObject::tr("Maindeck");
|
||||||
else if (_name == "side")
|
else if (_name == DECK_ZONE_SIDE)
|
||||||
return QObject::tr("Sideboard");
|
return QObject::tr("Sideboard");
|
||||||
else if (_name == "tokens")
|
else if (_name == DECK_ZONE_TOKENS)
|
||||||
return QObject::tr("Tokens");
|
return QObject::tr("Tokens");
|
||||||
else
|
else
|
||||||
return _name;
|
return _name;
|
||||||
|
@ -414,7 +414,7 @@ bool DeckList::readElement(QXmlStreamReader *xml)
|
||||||
else if (childName == "comments")
|
else if (childName == "comments")
|
||||||
comments = xml->readElementText();
|
comments = xml->readElementText();
|
||||||
else if (childName == "zone") {
|
else if (childName == "zone") {
|
||||||
InnerDecklistNode *newZone = new InnerDecklistNode(xml->attributes().value("name").toString(), root);
|
InnerDecklistNode *newZone = getZoneObjFromName(xml->attributes().value("name").toString());
|
||||||
newZone->readElement(xml);
|
newZone->readElement(xml);
|
||||||
} else if (childName == "sideboard_plan") {
|
} else if (childName == "sideboard_plan") {
|
||||||
SideboardPlan *newSideboardPlan = new SideboardPlan;
|
SideboardPlan *newSideboardPlan = new SideboardPlan;
|
||||||
|
@ -510,13 +510,14 @@ bool DeckList::loadFromStream_Plain(QTextStream &in)
|
||||||
{
|
{
|
||||||
cleanList();
|
cleanList();
|
||||||
|
|
||||||
InnerDecklistNode *main = 0, *side = 0;
|
bool inSideboard = false, isSideboard = false;
|
||||||
bool inSideboard = false;
|
|
||||||
|
|
||||||
int okRows = 0;
|
int okRows = 0;
|
||||||
bool titleFound = false;
|
bool titleFound = false;
|
||||||
while (!in.atEnd()) {
|
while (!in.atEnd()) {
|
||||||
QString line = in.readLine().simplified();
|
QString line = in.readLine().simplified();
|
||||||
|
|
||||||
|
// skip comments
|
||||||
if (line.startsWith("//"))
|
if (line.startsWith("//"))
|
||||||
{
|
{
|
||||||
if(!titleFound)
|
if(!titleFound)
|
||||||
|
@ -529,23 +530,17 @@ bool DeckList::loadFromStream_Plain(QTextStream &in)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
InnerDecklistNode *zone;
|
// check for sideboard prefix
|
||||||
if (line.startsWith("Sideboard", Qt::CaseInsensitive)) {
|
if (line.startsWith("Sideboard", Qt::CaseInsensitive)) {
|
||||||
inSideboard = true;
|
inSideboard = true;
|
||||||
continue;
|
continue;
|
||||||
} else if (line.startsWith("SB:", Qt::CaseInsensitive)) {
|
}
|
||||||
|
|
||||||
|
isSideboard = inSideboard;
|
||||||
|
|
||||||
|
if (line.startsWith("SB:", Qt::CaseInsensitive)) {
|
||||||
line = line.mid(3).trimmed();
|
line = line.mid(3).trimmed();
|
||||||
if (!side)
|
isSideboard = true;
|
||||||
side = new InnerDecklistNode("side", root);
|
|
||||||
zone = side;
|
|
||||||
} else if (inSideboard) {
|
|
||||||
if (!side)
|
|
||||||
side = new InnerDecklistNode("side", root);
|
|
||||||
zone = side;
|
|
||||||
} else {
|
|
||||||
if (!main)
|
|
||||||
main = new InnerDecklistNode("main", root);
|
|
||||||
zone = main;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter out MWS edition symbols and basic land extras
|
// Filter out MWS edition symbols and basic land extras
|
||||||
|
@ -593,13 +588,27 @@ bool DeckList::loadFromStream_Plain(QTextStream &in)
|
||||||
cardName.replace(rx, QString("%1 // ").arg(rx.cap(1)));
|
cardName.replace(rx, QString("%1 // ").arg(rx.cap(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Look for the correct card zone
|
||||||
|
QString zoneName = getCardZoneFromName(cardName, isSideboard ? DECK_ZONE_SIDE: DECK_ZONE_MAIN);
|
||||||
|
|
||||||
++okRows;
|
++okRows;
|
||||||
new DecklistCardNode(cardName, number, 0, zone);
|
new DecklistCardNode(cardName, number, 0, getZoneObjFromName(zoneName));
|
||||||
}
|
}
|
||||||
updateDeckHash();
|
updateDeckHash();
|
||||||
return (okRows > 0);
|
return (okRows > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InnerDecklistNode * DeckList::getZoneObjFromName(const QString zoneName)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < root->size(); i++) {
|
||||||
|
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
|
||||||
|
if(node->getName() == zoneName)
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new InnerDecklistNode(zoneName, root);
|
||||||
|
}
|
||||||
|
|
||||||
bool DeckList::loadFromFile_Plain(QIODevice *device)
|
bool DeckList::loadFromFile_Plain(QIODevice *device)
|
||||||
{
|
{
|
||||||
QTextStream in(device);
|
QTextStream in(device);
|
||||||
|
@ -616,7 +625,7 @@ struct WriteToStream {
|
||||||
const InnerDecklistNode *node,
|
const InnerDecklistNode *node,
|
||||||
const DecklistCardNode *card
|
const DecklistCardNode *card
|
||||||
) {
|
) {
|
||||||
if (prefixSideboardCards && node->getName() == "side") {
|
if (prefixSideboardCards && node->getName() == DECK_ZONE_SIDE) {
|
||||||
stream << "SB: ";
|
stream << "SB: ";
|
||||||
}
|
}
|
||||||
stream << QString("%1 %2\n").arg(
|
stream << QString("%1 %2\n").arg(
|
||||||
|
@ -680,7 +689,7 @@ int DeckList::getSideboardSize() const
|
||||||
int size = 0;
|
int size = 0;
|
||||||
for (int i = 0; i < root->size(); ++i) {
|
for (int i = 0; i < root->size(); ++i) {
|
||||||
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
|
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
|
||||||
if (node->getName() != "side")
|
if (node->getName() != DECK_ZONE_SIDE)
|
||||||
continue;
|
continue;
|
||||||
for (int j = 0; j < node->size(); j++) {
|
for (int j = 0; j < node->size(); j++) {
|
||||||
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
|
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
|
||||||
|
@ -738,8 +747,8 @@ void DeckList::updateDeckHash()
|
||||||
bool isValidDeckList = true;
|
bool isValidDeckList = true;
|
||||||
QSet<QString> hashZones, optionalZones;
|
QSet<QString> hashZones, optionalZones;
|
||||||
|
|
||||||
hashZones << "main" << "side"; // Zones in deck to be included in hashing process
|
hashZones << DECK_ZONE_MAIN << DECK_ZONE_SIDE; // Zones in deck to be included in hashing process
|
||||||
optionalZones << "tokens"; // Optional zones in deck not included in hashing process
|
optionalZones << DECK_ZONE_TOKENS; // Optional zones in deck not included in hashing process
|
||||||
|
|
||||||
for (int i = 0; i < root->size(); i++)
|
for (int i = 0; i < root->size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -750,7 +759,7 @@ void DeckList::updateDeckHash()
|
||||||
{
|
{
|
||||||
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
|
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
|
||||||
for (int k = 0; k < card->getNumber(); ++k)
|
for (int k = 0; k < card->getNumber(); ++k)
|
||||||
cardList.append((node->getName() == "side" ? "SB:" : "") + card->getName().toLower());
|
cardList.append((node->getName() == DECK_ZONE_SIDE ? "SB:" : "") + card->getName().toLower());
|
||||||
}
|
}
|
||||||
else if (!optionalZones.contains(node->getName())) // Not a valid zone -> cheater?
|
else if (!optionalZones.contains(node->getName())) // Not a valid zone -> cheater?
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,10 @@ class QTextStream;
|
||||||
|
|
||||||
class InnerDecklistNode;
|
class InnerDecklistNode;
|
||||||
|
|
||||||
|
#define DECK_ZONE_MAIN "main"
|
||||||
|
#define DECK_ZONE_SIDE "side"
|
||||||
|
#define DECK_ZONE_TOKENS "tokens"
|
||||||
|
|
||||||
class SideboardPlan {
|
class SideboardPlan {
|
||||||
private:
|
private:
|
||||||
QString name;
|
QString name;
|
||||||
|
@ -116,7 +120,6 @@ public:
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
void setName(const QString &_name) { name = _name; }
|
void setName(const QString &_name) { name = _name; }
|
||||||
float getPrice() const { return price; }
|
float getPrice() const { return price; }
|
||||||
|
|
||||||
void setPrice(const float _price) { price = _price; }
|
void setPrice(const float _price) { price = _price; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -128,6 +131,9 @@ private:
|
||||||
QMap<QString, SideboardPlan *> sideboardPlans;
|
QMap<QString, SideboardPlan *> sideboardPlans;
|
||||||
InnerDecklistNode *root;
|
InnerDecklistNode *root;
|
||||||
void getCardListHelper(InnerDecklistNode *node, QSet<QString> &result) const;
|
void getCardListHelper(InnerDecklistNode *node, QSet<QString> &result) const;
|
||||||
|
InnerDecklistNode *getZoneObjFromName(const QString zoneName);
|
||||||
|
protected:
|
||||||
|
virtual QString getCardZoneFromName(QString /* cardName */, QString currentZoneName) { return currentZoneName; };
|
||||||
signals:
|
signals:
|
||||||
void deckHashChanged();
|
void deckHashChanged();
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -170,9 +170,9 @@ void Server_Player::setupZones()
|
||||||
for (int i = 0; i < listRoot->size(); ++i) {
|
for (int i = 0; i < listRoot->size(); ++i) {
|
||||||
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||||
Server_CardZone *z;
|
Server_CardZone *z;
|
||||||
if (currentZone->getName() == "main")
|
if (currentZone->getName() == DECK_ZONE_MAIN)
|
||||||
z = deckZone;
|
z = deckZone;
|
||||||
else if (currentZone->getName() == "side")
|
else if (currentZone->getName() == DECK_ZONE_SIDE)
|
||||||
z = sbZone;
|
z = sbZone;
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
@ -193,15 +193,15 @@ void Server_Player::setupZones()
|
||||||
const QString targetZone = QString::fromStdString(m.target_zone());
|
const QString targetZone = QString::fromStdString(m.target_zone());
|
||||||
|
|
||||||
Server_CardZone *start, *target;
|
Server_CardZone *start, *target;
|
||||||
if (startZone == "main")
|
if (startZone == DECK_ZONE_MAIN)
|
||||||
start = deckZone;
|
start = deckZone;
|
||||||
else if (startZone == "side")
|
else if (startZone == DECK_ZONE_SIDE)
|
||||||
start = sbZone;
|
start = sbZone;
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
if (targetZone == "main")
|
if (targetZone == DECK_ZONE_MAIN)
|
||||||
target = deckZone;
|
target = deckZone;
|
||||||
else if (targetZone == "side")
|
else if (targetZone == DECK_ZONE_SIDE)
|
||||||
target = sbZone;
|
target = sbZone;
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -20,9 +20,9 @@ struct DecklistBuilder {
|
||||||
explicit DecklistBuilder() : actualMainboard({}), actualSideboard({}) {}
|
explicit DecklistBuilder() : actualMainboard({}), actualSideboard({}) {}
|
||||||
|
|
||||||
void operator()(const InnerDecklistNode *innerDecklistNode, const DecklistCardNode *card) {
|
void operator()(const InnerDecklistNode *innerDecklistNode, const DecklistCardNode *card) {
|
||||||
if (innerDecklistNode->getName() == "main") {
|
if (innerDecklistNode->getName() == DECK_ZONE_MAIN) {
|
||||||
actualMainboard[card->getName()] += card->getNumber();
|
actualMainboard[card->getName()] += card->getNumber();
|
||||||
} else if (innerDecklistNode->getName() == "side") {
|
} else if (innerDecklistNode->getName() == DECK_ZONE_SIDE) {
|
||||||
actualSideboard[card->getName()] += card->getNumber();
|
actualSideboard[card->getName()] += card->getNumber();
|
||||||
} else {
|
} else {
|
||||||
FAIL();
|
FAIL();
|
||||||
|
|
Loading…
Reference in a new issue