mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 14:32:15 -07:00
card_ref.h
This commit is contained in:
parent
e05dad4267
commit
47c9a03bee
9 changed files with 66 additions and 45 deletions
|
|
@ -162,7 +162,7 @@ void AbstractTabDeckEditor::setDeck(DeckLoader *_deck)
|
||||||
{
|
{
|
||||||
deckDockWidget->setDeck(_deck);
|
deckDockWidget->setDeck(_deck);
|
||||||
PictureLoader::cacheCardPixmaps(
|
PictureLoader::cacheCardPixmaps(
|
||||||
CardDatabaseManager::getInstance()->getCardsByNameAndProviderId(getDeckList()->getCardListWithProviderId()));
|
CardDatabaseManager::getInstance()->getCardsByNameAndProviderId(getDeckList()->getCardRefList()));
|
||||||
setModified(false);
|
setModified(false);
|
||||||
|
|
||||||
// If they load a deck, make the deck list appear
|
// If they load a deck, make the deck list appear
|
||||||
|
|
|
||||||
|
|
@ -930,7 +930,7 @@ void TabGame::eventGameStateChanged(const Event_GameStateChanged &event,
|
||||||
if (playerInfo.has_deck_list()) {
|
if (playerInfo.has_deck_list()) {
|
||||||
DeckLoader newDeck(QString::fromStdString(playerInfo.deck_list()));
|
DeckLoader newDeck(QString::fromStdString(playerInfo.deck_list()));
|
||||||
PictureLoader::cacheCardPixmaps(CardDatabaseManager::getInstance()->getCardsByNameAndProviderId(
|
PictureLoader::cacheCardPixmaps(CardDatabaseManager::getInstance()->getCardsByNameAndProviderId(
|
||||||
newDeck.getCardListWithProviderId()));
|
newDeck.getCardRefList()));
|
||||||
deckViewContainer->setDeck(newDeck);
|
deckViewContainer->setDeck(newDeck);
|
||||||
player->setDeck(newDeck);
|
player->setDeck(newDeck);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -333,7 +333,7 @@ void DeckViewContainer::deckSelectFinished(const Response &r)
|
||||||
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
|
const Response_DeckDownload &resp = r.GetExtension(Response_DeckDownload::ext);
|
||||||
DeckLoader newDeck(QString::fromStdString(resp.deck()));
|
DeckLoader newDeck(QString::fromStdString(resp.deck()));
|
||||||
PictureLoader::cacheCardPixmaps(
|
PictureLoader::cacheCardPixmaps(
|
||||||
CardDatabaseManager::getInstance()->getCardsByNameAndProviderId(newDeck.getCardListWithProviderId()));
|
CardDatabaseManager::getInstance()->getCardsByNameAndProviderId(newDeck.getCardRefList()));
|
||||||
setDeck(newDeck);
|
setDeck(newDeck);
|
||||||
switchToDeckLoadedView();
|
switchToDeckLoadedView();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
common/card_ref.h
Normal file
24
common/card_ref.h
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef CARD_REF_H
|
||||||
|
#define CARD_REF_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The information passed over the server that is required to identify the exact card to display.
|
||||||
|
*
|
||||||
|
* @param name The name of the card. Should not be empty, unless to indicate the lack of a card.
|
||||||
|
* @param providerId Determines which printing of the card to use. Can be empty, in which case Cockatrice should default
|
||||||
|
* to using the preferred set.
|
||||||
|
*/
|
||||||
|
struct CardRef
|
||||||
|
{
|
||||||
|
QString name;
|
||||||
|
QString providerId = QString();
|
||||||
|
|
||||||
|
bool operator==(const CardRef &other) const
|
||||||
|
{
|
||||||
|
return name == other.name && providerId == other.providerId;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CARD_REF_H
|
||||||
|
|
@ -424,7 +424,7 @@ bool DeckList::readElement(QXmlStreamReader *xml)
|
||||||
} else if (childName == "bannerCard") {
|
} else if (childName == "bannerCard") {
|
||||||
QString providerId = xml->attributes().value("providerId").toString();
|
QString providerId = xml->attributes().value("providerId").toString();
|
||||||
QString cardName = xml->readElementText();
|
QString cardName = xml->readElementText();
|
||||||
bannerCard = QPair<QString, QString>(cardName, providerId);
|
bannerCard = {cardName, providerId};
|
||||||
} else if (childName == "tags") {
|
} else if (childName == "tags") {
|
||||||
tags.clear(); // Clear existing tags
|
tags.clear(); // Clear existing tags
|
||||||
while (xml->readNextStartElement()) {
|
while (xml->readNextStartElement()) {
|
||||||
|
|
@ -456,8 +456,8 @@ void DeckList::write(QXmlStreamWriter *xml) const
|
||||||
xml->writeTextElement("lastLoadedTimestamp", lastLoadedTimestamp);
|
xml->writeTextElement("lastLoadedTimestamp", lastLoadedTimestamp);
|
||||||
xml->writeTextElement("deckname", name);
|
xml->writeTextElement("deckname", name);
|
||||||
xml->writeStartElement("bannerCard");
|
xml->writeStartElement("bannerCard");
|
||||||
xml->writeAttribute("providerId", bannerCard.second);
|
xml->writeAttribute("providerId", bannerCard.providerId);
|
||||||
xml->writeCharacters(bannerCard.first);
|
xml->writeCharacters(bannerCard.name);
|
||||||
xml->writeEndElement();
|
xml->writeEndElement();
|
||||||
xml->writeTextElement("comments", comments);
|
xml->writeTextElement("comments", comments);
|
||||||
|
|
||||||
|
|
@ -805,7 +805,7 @@ void DeckList::cleanList(bool preserveMetadata)
|
||||||
refreshDeckHash();
|
refreshDeckHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckList::getCardListHelper(InnerDecklistNode *item, QSet<QString> &result) const
|
void DeckList::getCardListHelper(InnerDecklistNode *item, QSet<QString> &result)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < item->size(); ++i) {
|
for (int i = 0; i < item->size(); ++i) {
|
||||||
auto *node = dynamic_cast<DecklistCardNode *>(item->at(i));
|
auto *node = dynamic_cast<DecklistCardNode *>(item->at(i));
|
||||||
|
|
@ -818,15 +818,15 @@ void DeckList::getCardListHelper(InnerDecklistNode *item, QSet<QString> &result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckList::getCardListWithProviderIdHelper(InnerDecklistNode *item, QMap<QString, QString> &result) const
|
void DeckList::getCardRefListHelper(InnerDecklistNode *item, QList<CardRef> &result)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < item->size(); ++i) {
|
for (int i = 0; i < item->size(); ++i) {
|
||||||
auto *node = dynamic_cast<DecklistCardNode *>(item->at(i));
|
auto *node = dynamic_cast<DecklistCardNode *>(item->at(i));
|
||||||
|
|
||||||
if (node) {
|
if (node) {
|
||||||
result.insert(node->getName(), node->getCardProviderId());
|
result.append(node->toCardRef());
|
||||||
} else {
|
} else {
|
||||||
getCardListWithProviderIdHelper(dynamic_cast<InnerDecklistNode *>(item->at(i)), result);
|
getCardRefListHelper(dynamic_cast<InnerDecklistNode *>(item->at(i)), result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -838,10 +838,10 @@ QStringList DeckList::getCardList() const
|
||||||
return result.values();
|
return result.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, QString> DeckList::getCardListWithProviderId() const
|
QList<CardRef> DeckList::getCardRefList() const
|
||||||
{
|
{
|
||||||
QMap<QString, QString> result;
|
QList<CardRef> result;
|
||||||
getCardListWithProviderIdHelper(root, result);
|
getCardRefListHelper(root, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef DECKLIST_H
|
#ifndef DECKLIST_H
|
||||||
#define DECKLIST_H
|
#define DECKLIST_H
|
||||||
|
|
||||||
|
#include "card_ref.h"
|
||||||
|
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
|
@ -246,6 +248,10 @@ public:
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
CardRef toCardRef() const
|
||||||
|
{
|
||||||
|
return {name, cardProviderId};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeckList : public QObject
|
class DeckList : public QObject
|
||||||
|
|
@ -253,13 +259,13 @@ class DeckList : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QString name, comments;
|
QString name, comments;
|
||||||
QPair<QString, QString> bannerCard;
|
CardRef bannerCard;
|
||||||
QString lastLoadedTimestamp;
|
QString lastLoadedTimestamp;
|
||||||
QStringList tags;
|
QStringList tags;
|
||||||
QMap<QString, SideboardPlan *> sideboardPlans;
|
QMap<QString, SideboardPlan *> sideboardPlans;
|
||||||
InnerDecklistNode *root;
|
InnerDecklistNode *root;
|
||||||
void getCardListHelper(InnerDecklistNode *node, QSet<QString> &result) const;
|
static void getCardListHelper(InnerDecklistNode *node, QSet<QString> &result);
|
||||||
void getCardListWithProviderIdHelper(InnerDecklistNode *item, QMap<QString, QString> &result) const;
|
static void getCardRefListHelper(InnerDecklistNode *item, QList<CardRef> &result);
|
||||||
InnerDecklistNode *getZoneObjFromName(const QString &zoneName);
|
InnerDecklistNode *getZoneObjFromName(const QString &zoneName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -305,7 +311,7 @@ public slots:
|
||||||
tags.clear();
|
tags.clear();
|
||||||
emit deckTagsChanged();
|
emit deckTagsChanged();
|
||||||
}
|
}
|
||||||
void setBannerCard(const QPair<QString, QString> &_bannerCard = QPair<QString, QString>())
|
void setBannerCard(const CardRef &_bannerCard = {})
|
||||||
{
|
{
|
||||||
bannerCard = _bannerCard;
|
bannerCard = _bannerCard;
|
||||||
}
|
}
|
||||||
|
|
@ -331,7 +337,7 @@ public:
|
||||||
{
|
{
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
QPair<QString, QString> getBannerCard() const
|
CardRef getBannerCard() const
|
||||||
{
|
{
|
||||||
return bannerCard;
|
return bannerCard;
|
||||||
}
|
}
|
||||||
|
|
@ -365,7 +371,7 @@ public:
|
||||||
return root->isEmpty() && name.isEmpty() && comments.isEmpty() && sideboardPlans.isEmpty();
|
return root->isEmpty() && name.isEmpty() && comments.isEmpty() && sideboardPlans.isEmpty();
|
||||||
}
|
}
|
||||||
QStringList getCardList() const;
|
QStringList getCardList() const;
|
||||||
QMap<QString, QString> getCardListWithProviderId() const;
|
QList<CardRef> getCardRefList() const;
|
||||||
|
|
||||||
int getSideboardSize() const;
|
int getSideboardSize() const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,15 +27,9 @@
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
Server_Card::Server_Card(QString _name,
|
Server_Card::Server_Card(const CardRef &cardRef, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone)
|
||||||
QString _provider_id,
|
: zone(_zone), id(_id), coord_x(_coord_x), coord_y(_coord_y), cardRef(cardRef), tapped(false), attacking(false),
|
||||||
int _id,
|
facedown(false), destroyOnZoneChange(false), doesntUntap(false), parentCard(0), stashedCard(nullptr)
|
||||||
int _coord_x,
|
|
||||||
int _coord_y,
|
|
||||||
Server_CardZone *_zone)
|
|
||||||
: zone(_zone), id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), provider_id(_provider_id), tapped(false),
|
|
||||||
attacking(false), facedown(false), color(), ptString(), annotation(), destroyOnZoneChange(false),
|
|
||||||
doesntUntap(false), parentCard(0), stashedCard(nullptr)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,10 +128,10 @@ void Server_Card::setParentCard(Server_Card *_parentCard)
|
||||||
|
|
||||||
void Server_Card::getInfo(ServerInfo_Card *info)
|
void Server_Card::getInfo(ServerInfo_Card *info)
|
||||||
{
|
{
|
||||||
QString displayedName = facedown ? QString() : name;
|
QString displayedName = facedown ? QString() : cardRef.name;
|
||||||
|
|
||||||
info->set_id(id);
|
info->set_id(id);
|
||||||
info->set_provider_id(provider_id.toStdString());
|
info->set_provider_id(cardRef.providerId.toStdString());
|
||||||
info->set_name(displayedName.toStdString());
|
info->set_name(displayedName.toStdString());
|
||||||
info->set_x(coord_x);
|
info->set_x(coord_x);
|
||||||
info->set_y(coord_y);
|
info->set_y(coord_y);
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
#ifndef SERVER_CARD_H
|
#ifndef SERVER_CARD_H
|
||||||
#define SERVER_CARD_H
|
#define SERVER_CARD_H
|
||||||
|
|
||||||
|
#include "card_ref.h"
|
||||||
#include "pb/card_attributes.pb.h"
|
#include "pb/card_attributes.pb.h"
|
||||||
#include "pb/serverinfo_card.pb.h"
|
#include "pb/serverinfo_card.pb.h"
|
||||||
#include "server_arrowtarget.h"
|
#include "server_arrowtarget.h"
|
||||||
|
|
@ -38,8 +39,7 @@ private:
|
||||||
Server_CardZone *zone;
|
Server_CardZone *zone;
|
||||||
int id;
|
int id;
|
||||||
int coord_x, coord_y;
|
int coord_x, coord_y;
|
||||||
QString name;
|
CardRef cardRef;
|
||||||
QString provider_id;
|
|
||||||
QMap<int, int> counters;
|
QMap<int, int> counters;
|
||||||
bool tapped;
|
bool tapped;
|
||||||
bool attacking;
|
bool attacking;
|
||||||
|
|
@ -55,12 +55,7 @@ private:
|
||||||
Server_Card *stashedCard;
|
Server_Card *stashedCard;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Server_Card(QString _name,
|
Server_Card(const CardRef &cardRef, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone = nullptr);
|
||||||
QString _provider_id,
|
|
||||||
int _id,
|
|
||||||
int _coord_x,
|
|
||||||
int _coord_y,
|
|
||||||
Server_CardZone *_zone = nullptr);
|
|
||||||
~Server_Card() override;
|
~Server_Card() override;
|
||||||
|
|
||||||
Server_CardZone *getZone() const
|
Server_CardZone *getZone() const
|
||||||
|
|
@ -76,9 +71,13 @@ public:
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
CardRef getCardRef() const
|
||||||
|
{
|
||||||
|
return cardRef;
|
||||||
|
}
|
||||||
QString getProviderId() const
|
QString getProviderId() const
|
||||||
{
|
{
|
||||||
return provider_id;
|
return cardRef.providerId;
|
||||||
}
|
}
|
||||||
int getX() const
|
int getX() const
|
||||||
{
|
{
|
||||||
|
|
@ -90,7 +89,7 @@ public:
|
||||||
}
|
}
|
||||||
QString getName() const
|
QString getName() const
|
||||||
{
|
{
|
||||||
return name;
|
return cardRef.name;
|
||||||
}
|
}
|
||||||
const QMap<int, int> &getCounters() const
|
const QMap<int, int> &getCounters() const
|
||||||
{
|
{
|
||||||
|
|
@ -152,7 +151,7 @@ public:
|
||||||
}
|
}
|
||||||
void setName(const QString &_name)
|
void setName(const QString &_name)
|
||||||
{
|
{
|
||||||
name = _name;
|
cardRef.name = _name;
|
||||||
}
|
}
|
||||||
void setCounter(int _id, int value, Event_SetCardCounter *event = nullptr);
|
void setCounter(int _id, int value, Event_SetCardCounter *event = nullptr);
|
||||||
void setTapped(bool _tapped)
|
void setTapped(bool _tapped)
|
||||||
|
|
|
||||||
|
|
@ -210,9 +210,7 @@ void Server_Player::setupZones()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
||||||
z->insertCard(
|
z->insertCard(new Server_Card(currentCard->toCardRef(), nextCardId++, 0, 0, z), -1, 0);
|
||||||
new Server_Card(currentCard->getName(), currentCard->getCardProviderId(), nextCardId++, 0, 0, z),
|
|
||||||
-1, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1517,7 +1515,7 @@ Server_Player::cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer
|
||||||
yCoord = 0;
|
yCoord = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *card = new Server_Card(cardName, cardProviderId, newCardId(), xCoord, yCoord);
|
auto *card = new Server_Card({cardName, cardProviderId}, newCardId(), xCoord, yCoord);
|
||||||
card->moveToThread(thread());
|
card->moveToThread(thread());
|
||||||
// Client should already prevent face-down tokens from having attributes; this just an extra server-side check
|
// Client should already prevent face-down tokens from having attributes; this just an extra server-side check
|
||||||
if (!cmd.face_down()) {
|
if (!cmd.face_down()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue