Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
card_info.h
Go to the documentation of this file.
1#ifndef CARD_INFO_H
2#define CARD_INFO_H
3
5
6#include <QDate>
7#include <QHash>
8#include <QList>
9#include <QLoggingCategory>
10#include <QMap>
11#include <QMetaType>
12#include <QSharedPointer>
13#include <QVariant>
14#include <utility>
15
16inline Q_LOGGING_CATEGORY(CardInfoLog, "card_info");
17
18class CardInfo;
19class CardSet;
20class CardRelation;
22
23typedef QSharedPointer<CardInfo> CardInfoPtr;
24typedef QSharedPointer<CardSet> CardSetPtr;
25typedef QMap<QString, QList<PrintingInfo>> SetToPrintingsMap;
26
27typedef QHash<QString, CardInfoPtr> CardNameMap;
28typedef QHash<QString, CardSetPtr> SetNameMap;
29
30Q_DECLARE_METATYPE(CardInfoPtr)
31
32
45class CardInfo : public QObject
46{
47 Q_OBJECT
48
49public:
57 {
58 bool cipt = false;
59 bool landscapeOrientation = false;
60 int tableRow = 0;
61 bool upsideDownArt = false;
62 };
63
64private:
70 QString name;
71 QString simpleName;
72 QString text;
73 bool isToken;
74 QVariantHash properties;
75 QList<CardRelation *> relatedCards;
76 QList<CardRelation *> reverseRelatedCards;
77 QList<CardRelation *> reverseRelatedCardsToMe;
80 QString setsNames;
81 QSet<QString> altNames;
83
84public:
97 explicit CardInfo(const QString &_name,
98 const QString &_text,
99 bool _isToken,
100 QVariantHash _properties,
101 const QList<CardRelation *> &_relatedCards,
102 const QList<CardRelation *> &_reverseRelatedCards,
103 SetToPrintingsMap _sets,
104 UiAttributes _uiAttributes);
105
113 CardInfo(const CardInfo &other)
114 : QObject(other.parent()), name(other.name), simpleName(other.simpleName), text(other.text),
118 altNames(other.altNames)
119 {
120 }
121
130 static CardInfoPtr newInstance(const QString &_name);
131
145 static CardInfoPtr newInstance(const QString &_name,
146 const QString &_text,
147 bool _isToken,
148 QVariantHash _properties,
149 const QList<CardRelation *> &_relatedCards,
150 const QList<CardRelation *> &_reverseRelatedCards,
151 SetToPrintingsMap _sets,
152 UiAttributes _uiAttributes);
153
161 [[nodiscard]] CardInfoPtr clone() const
162 {
163 auto newCardInfo = CardInfoPtr(new CardInfo(*this));
164 newCardInfo->setSmartPointer(newCardInfo); // Set the smart pointer for the new instance
165 return newCardInfo;
166 }
167
176 {
177 smartThis = std::move(_ptr);
178 }
179 //@{
181 [[nodiscard]] inline const QString &getName() const
182 {
183 return name;
184 }
185 [[nodiscard]] const QString &getSimpleName() const
186 {
187 return simpleName;
188 }
189 const QSet<QString> &getAltNames()
190 {
191 return altNames;
192 }
193 [[nodiscard]] const QString &getText() const
194 {
195 return text;
196 }
197 void setText(const QString &_text)
198 {
199 text = _text;
201 }
202 [[nodiscard]] bool getIsToken() const
203 {
204 return isToken;
205 }
206 [[nodiscard]] QStringList getProperties() const
207 {
208 return properties.keys();
209 }
210 [[nodiscard]] QString getProperty(const QString &propertyName) const
211 {
212 return properties.value(propertyName).toString();
213 }
214 void setProperty(const QString &_name, const QString &_value)
215 {
216 properties.insert(_name, _value);
218 }
219 [[nodiscard]] bool hasProperty(const QString &propertyName) const
220 {
221 return properties.contains(propertyName);
222 }
223 [[nodiscard]] const SetToPrintingsMap &getSets() const
224 {
225 return setsToPrintings;
226 }
227 [[nodiscard]] const QString &getSetsNames() const
228 {
229 return setsNames;
230 }
231
232 //@{
234 [[nodiscard]] const QList<CardRelation *> &getRelatedCards() const
235 {
236 return relatedCards;
237 }
238 [[nodiscard]] const QList<CardRelation *> &getReverseRelatedCards() const
239 {
240 return reverseRelatedCards;
241 }
242 [[nodiscard]] const QList<CardRelation *> &getReverseRelatedCards2Me() const
243 {
245 }
246 [[nodiscard]] QList<CardRelation *> getAllRelatedCards() const
247 {
248 QList<CardRelation *> result;
249 result.append(getRelatedCards());
250 result.append(getReverseRelatedCards2Me());
251 return result;
252 }
253 void resetReverseRelatedCards2Me();
255 {
256 reverseRelatedCardsToMe.append(cardRelation);
257 }
258
259 //@{
261 [[nodiscard]] const UiAttributes &getUiAttributes() const
262 {
263 return uiAttributes;
264 }
265
266
267 [[nodiscard]] const QChar getColorChar() const;
268 //@{
270 [[nodiscard]] const QString getCardType() const;
271 void setCardType(const QString &value);
272 [[nodiscard]] const QString getCmc() const;
273 [[nodiscard]] const QString getColors() const;
274 void setColors(const QString &value);
275 [[nodiscard]] const QString getLoyalty() const;
276 [[nodiscard]] const QString getMainCardType() const;
277 [[nodiscard]] const QString getManaCost() const;
278 [[nodiscard]] const QString getPowTough() const;
279 void setPowTough(const QString &value);
281
289 [[nodiscard]] QString getCorrectedName() const;
290
299 void addToSet(const CardSetPtr &_set, PrintingInfo _info = PrintingInfo());
300
308 void combineLegalities(const QVariantHash &props);
309
315 void refreshCachedSets();
316
325 static QString simplifyName(const QString &name);
326
327private:
333 void refreshCachedSetNames();
334
340 void refreshCachedAltNames();
341
342signals:
348 void pixmapUpdated(const PrintingInfo &printing);
349
356};
357#endif
QSharedPointer< CardInfo > CardInfoPtr
Definition card_info.cpp:20
QMap< QString, QList< PrintingInfo > > SetToPrintingsMap
Definition card_info.h:25
QSharedPointer< CardSet > CardSetPtr
Definition card_info.h:24
QHash< QString, CardSetPtr > SetNameMap
Definition card_info.h:28
QSharedPointer< CardInfo > CardInfoPtr
Definition card_info.h:23
Q_LOGGING_CATEGORY(CardInfoLog, "card_info")
QHash< QString, CardInfoPtr > CardNameMap
Definition card_info.h:27
Represents a card and its associated metadata, properties, and relationships.
Definition card_info.h:46
bool hasProperty(const QString &propertyName) const
Definition card_info.h:219
QString simpleName
Simplified name for fuzzy matching.
Definition card_info.h:71
void setSmartPointer(CardInfoPtr _ptr)
Sets the internal smart pointer to self.
Definition card_info.h:175
const SetToPrintingsMap & getSets() const
Definition card_info.h:223
void setText(const QString &_text)
Definition card_info.h:197
UiAttributes uiAttributes
Attributes that affect display and game logic.
Definition card_info.h:79
const QList< CardRelation * > & getReverseRelatedCards() const
Definition card_info.h:238
const QString & getSimpleName() const
Definition card_info.h:185
const QList< CardRelation * > & getRelatedCards() const
Definition card_info.h:234
QList< CardRelation * > reverseRelatedCards
Cards that refer back to this card.
Definition card_info.h:76
const UiAttributes & getUiAttributes() const
Definition card_info.h:261
CardInfoPtr smartThis
Smart pointer to self for safe cross-references.
Definition card_info.h:69
const QList< CardRelation * > & getReverseRelatedCards2Me() const
Definition card_info.h:242
QSet< QString > altNames
Cached set of alternate names, used when searching.
Definition card_info.h:81
const QString & getSetsNames() const
Definition card_info.h:227
QString name
Full name of the card.
Definition card_info.h:70
QList< CardRelation * > relatedCards
Forward references to related cards.
Definition card_info.h:75
SetToPrintingsMap setsToPrintings
Mapping from set names to printing variations.
Definition card_info.h:78
void setProperty(const QString &_name, const QString &_value)
Definition card_info.h:214
QVariantHash properties
Key-value store of dynamic card properties.
Definition card_info.h:74
CardInfo(const QString &_name, const QString &_text, bool _isToken, QVariantHash _properties, const QList< CardRelation * > &_relatedCards, const QList< CardRelation * > &_reverseRelatedCards, SetToPrintingsMap _sets, UiAttributes _uiAttributes)
Constructs a CardInfo with full initialization.
Definition card_info.cpp:22
const QSet< QString > & getAltNames()
Definition card_info.h:189
QString getProperty(const QString &propertyName) const
Definition card_info.h:210
CardInfo(const CardInfo &other)
Copy constructor for CardInfo.
Definition card_info.h:113
QList< CardRelation * > reverseRelatedCardsToMe
Cards that consider this card as related.
Definition card_info.h:77
void addReverseRelatedCards2Me(CardRelation *cardRelation)
Definition card_info.h:254
CardInfoPtr clone() const
Clones the current CardInfo instance.
Definition card_info.h:161
void cardInfoChanged(CardInfoPtr card)
Emitted when card properties or state have changed.
const QString & getText() const
Definition card_info.h:193
QString setsNames
Cached, human-readable list of set names.
Definition card_info.h:80
bool getIsToken() const
Definition card_info.h:202
void pixmapUpdated(const PrintingInfo &printing)
Emitted when a pixmap for this card has been updated or finished loading.
QList< CardRelation * > getAllRelatedCards() const
Definition card_info.h:246
bool isToken
Whether this card is a token or not.
Definition card_info.h:73
QStringList getProperties() const
Definition card_info.h:206
QString text
Text description or rules text of the card.
Definition card_info.h:72
const QString & getName() const
Definition card_info.h:181
Represents a relationship between two cards.
Definition card_relation.h:24
A collection of cards grouped under a common identifier.
Definition card_set.h:35
Defines the base parser interface (ICardDatabaseParser) for all card database parsers.
Definition card_database_parser.h:20
Represents metadata for a specific variation of a card within a set.
Definition printing_info.h:27
static QString getMainCardType(const QStringList &typeList)
Definition oracleimporter.cpp:92
Attributes of the card that affect display and game logic.
Definition card_info.h:57
int tableRow
Row index in a table or visual representation.
Definition card_info.h:60
bool landscapeOrientation
Orientation flag for rendering.
Definition card_info.h:59
bool cipt
Positioning flag used by UI.
Definition card_info.h:58
bool upsideDownArt
Whether artwork is flipped for visual purposes.
Definition card_info.h:61