Cockatrice 2026-10-19-Development-3.1.2-beta.2
A 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
7
8#include <QByteArray>
9#include <QChar>
10#include <QHash>
11#include <QList>
12#include <QLoggingCategory>
13#include <QMap>
14#include <QMetaType>
15#include <QObject>
16#include <QSet>
17#include <QSharedPointer>
18#include <QString>
19#include <QStringList>
20#include <qtmetamacros.h>
21#include <utility>
22
23inline Q_LOGGING_CATEGORY(CardInfoLog, "card_info");
24
25class CardInfo;
26class CardSet;
27class CardRelation;
28
33
37
38Q_DECLARE_METATYPE(CardInfoPtr)
39
40
53class CardInfo : public QObject
54{
55 Q_OBJECT
56
57public:
65 {
66 bool cipt = false;
67 bool landscapeOrientation = false;
68 int tableRow = 0;
69 bool upsideDownArt = false;
70 };
71
72private:
78 QString name;
79 QString simpleName;
80 QString text;
81 bool isToken;
82
85
87
93 QString setsNames;
96
97public:
112 explicit CardInfo(const QString &_name,
113 const QString &_text,
114 bool _isToken,
115 const QHash<QString, QString> &_properties,
116 const QList<CardRelation *> &_relatedCards,
117 const QList<CardRelation *> &_reverseRelatedCards,
118 SetToPrintingsMap _sets,
119 UiAttributes _uiAttributes,
120 QMap<QString, QString> _localizedNames = {},
121 QMap<QString, QString> _localizedTexts = {});
122
146 explicit CardInfo(const QString &_name,
147 const QString &_text,
148 bool _isToken,
149 const QByteArray &_propertiesBlob,
150 const QList<CardRelation *> &_relatedCards,
151 const QList<CardRelation *> &_reverseRelatedCards,
152 SetToPrintingsMap _sets,
153 UiAttributes _uiAttributes,
154 QString _simpleName,
155 QSet<QString> _altNames,
156 QMap<QString, QString> _localizedNames = {},
157 QMap<QString, QString> _localizedTexts = {});
158
175
184 static CardInfoPtr newInstance(const QString &_name);
185
201 static CardInfoPtr newInstance(const QString &_name,
202 const QString &_text,
203 bool _isToken,
204 const QHash<QString, QString> &_properties,
205 const QList<CardRelation *> &_relatedCards,
206 const QList<CardRelation *> &_reverseRelatedCards,
207 SetToPrintingsMap _sets,
208 UiAttributes _uiAttributes,
209 QMap<QString, QString> _localizedNames = {},
210 QMap<QString, QString> _localizedTexts = {});
211
234 static CardInfoPtr newInstance(const QString &_name,
235 const QString &_text,
236 bool _isToken,
237 QByteArray _propertiesBlob,
238 const QList<CardRelation *> &_relatedCards,
239 const QList<CardRelation *> &_reverseRelatedCards,
240 SetToPrintingsMap _sets,
241 UiAttributes _uiAttributes,
242 QString _simpleName,
243 QSet<QString> _altNames,
244 bool _appendToSets = true,
245 QMap<QString, QString> _localizedNames = {},
246 QMap<QString, QString> _localizedTexts = {});
247
255 [[nodiscard]] CardInfoPtr clone() const
256 {
257 auto newCardInfo = CardInfoPtr(new CardInfo(*this));
258 newCardInfo->setSmartPointer(newCardInfo); // Set the smart pointer for the new instance
259 return newCardInfo;
260 }
261
270 {
271 smartThis = std::move(_ptr);
272 }
273 //@{
275 [[nodiscard]] inline const QString &getName() const
276 {
277 return name;
278 }
279 [[nodiscard]] const QString &getSimpleName() const
280 {
281 return simpleName;
282 }
284 {
285 return altNames;
286 }
287 [[nodiscard]] const QString &getText() const
288 {
289 return text;
290 }
291 void setText(const QString &_text)
292 {
293 text = _text;
295 }
296
304 [[nodiscard]] const QString &getLocalizedName(const QString &lang) const
305 {
306 const auto it = localizedNames.constFind(lang);
307 return it != localizedNames.constEnd() ? it.value() : name;
308 }
309
317 [[nodiscard]] const QString &getLocalizedText(const QString &lang) const
318 {
319 const auto it = localizedTexts.constFind(lang);
320 return it != localizedTexts.constEnd() ? it.value() : text;
321 }
322
329 [[nodiscard]] const QMap<QString, QString> &getLocalizedNames() const
330 {
331 return localizedNames;
332 }
333
340 [[nodiscard]] const QMap<QString, QString> &getLocalizedTexts() const
341 {
342 return localizedTexts;
343 }
344
351 void setLocalizedName(const QString &lang, const QString &_localizedName)
352 {
353 if (localizedNames.value(lang) == _localizedName) {
354 return;
355 }
356 localizedNames.insert(lang, _localizedName);
358 }
359
366 void setLocalizedText(const QString &lang, const QString &_localizedText)
367 {
368 if (localizedTexts.value(lang) == _localizedText) {
369 return;
370 }
371 localizedTexts.insert(lang, _localizedText);
373 }
374
379 [[nodiscard]] QStringList localizationLanguages() const
380 {
381 QStringList languages = localizedNames.keys();
382 languages.append(localizedTexts.keys());
383 languages.removeDuplicates();
384 return languages;
385 }
386 [[nodiscard]] bool getIsToken() const
387 {
388 return isToken;
389 }
390 [[nodiscard]] QStringList getProperties() const
391 {
392 return getPropertiesHash().keys();
393 }
394 [[nodiscard]] const QHash<QString, QString> &getPropertiesHash() const;
395
396 [[nodiscard]] QString getProperty(const QString &propertyName) const
397 {
398 return getPropertiesHash().value(propertyName);
399 }
400 void setProperty(const QString &_name, const QString &_value);
401 [[nodiscard]] bool hasProperty(const QString &propertyName) const
402 {
403 return getPropertiesHash().contains(propertyName);
404 }
405 [[nodiscard]] const SetToPrintingsMap &getSets() const
406 {
407 return setsToPrintings;
408 }
409 [[nodiscard]] const QString &getSetsNames() const
410 {
411 return setsNames;
412 }
413
414 //@{
416 [[nodiscard]] const QList<CardRelation *> &getRelatedCards() const
417 {
418 return relatedCards;
419 }
421 {
422 return reverseRelatedCards;
423 }
425 {
427 }
429 {
431 result.append(getRelatedCards());
432 result.append(getReverseRelatedCards2Me());
433 return result;
434 }
435 void resetReverseRelatedCards2Me();
437 {
438 reverseRelatedCardsToMe.append(cardRelation);
439 }
440
441 //@{
443 [[nodiscard]] const UiAttributes &getUiAttributes() const
444 {
445 return uiAttributes;
446 }
447
448
449 [[nodiscard]] QChar getColorChar() const;
450 //@{
452 [[nodiscard]] QString getCardType() const;
453 void setCardType(const QString &value);
454 [[nodiscard]] QString getCmc() const;
455 [[nodiscard]] QString getColors() const;
456 void setColors(const QString &value);
457 [[nodiscard]] QString getLoyalty() const;
458 [[nodiscard]] QString getMainCardType() const;
459 [[nodiscard]] QString getManaCost() const;
460 [[nodiscard]] QString getPowTough() const;
461 void setPowTough(const QString &value);
463
471 [[nodiscard]] QString getCorrectedName() const;
472
479 [[nodiscard]] QString getLegalityProp(const QString &format) const;
480
488 [[nodiscard]] bool isLegalInFormat(const QString &format) const;
489
498 void addToSet(const CardSetPtr &_set, const PrintingInfo &_info = PrintingInfo());
499
507 void combineLegalities(const QHash<QString, QString> &props);
508
514 void refreshCachedSets();
515
524 static QString simplifyName(const QString &name);
525
526private:
532 void refreshCachedSetNames();
533
539 void refreshCachedAltNames();
540
541signals:
547 void pixmapUpdated(const PrintingInfo &printing);
548
555};
556#endif
QSharedPointer< CardInfo > CardInfoPtr
Definition card_info.cpp:15
QMap< QString, QList< PrintingInfo > > SetToPrintingsMap
Definition card_info.h:32
QHash< QString, FormatRulesPtr > FormatRulesNameMap
Definition card_info.h:36
QSharedPointer< FormatRules > FormatRulesPtr
Definition card_info.h:31
QSharedPointer< CardSet > CardSetPtr
Definition card_info.h:30
QHash< QString, CardSetPtr > SetNameMap
Definition card_info.h:35
QSharedPointer< CardInfo > CardInfoPtr
Definition card_info.h:29
QHash< QString, CardInfoPtr > CardNameMap
Definition card_info.h:34
Represents a card and its associated metadata, properties, and relationships.
Definition card_info.h:54
bool hasProperty(const QString &propertyName) const
Definition card_info.h:401
const QString & getLocalizedText(const QString &lang) const
Returns the rules text in the given language, falling back to the English text when no localization i...
Definition card_info.h:317
void setLocalizedName(const QString &lang, const QString &_localizedName)
Sets the card name for the given language.
Definition card_info.h:351
const QMap< QString, QString > & getLocalizedTexts() const
Returns the localized rules text keyed by language code.
Definition card_info.h:340
QString simpleName
Simplified name for fuzzy matching.
Definition card_info.h:79
void setSmartPointer(CardInfoPtr _ptr)
Sets the internal smart pointer to self.
Definition card_info.h:269
const SetToPrintingsMap & getSets() const
Definition card_info.h:405
void setText(const QString &_text)
Definition card_info.h:291
QMap< QString, QString > localizedTexts
Localized rules text, keyed by language code.
Definition card_info.h:84
const QMap< QString, QString > & getLocalizedNames() const
Returns the localized card names keyed by language code.
Definition card_info.h:329
UiAttributes uiAttributes
Attributes that affect display and game logic.
Definition card_info.h:92
const QList< CardRelation * > & getReverseRelatedCards() const
Definition card_info.h:420
const QString & getSimpleName() const
Definition card_info.h:279
const QList< CardRelation * > & getRelatedCards() const
Definition card_info.h:416
QList< CardRelation * > reverseRelatedCards
Cards that refer back to this card.
Definition card_info.h:89
const UiAttributes & getUiAttributes() const
Definition card_info.h:443
CardInfoPtr smartThis
Smart pointer to self for safe cross-references.
Definition card_info.h:77
QMap< QString, QString > localizedNames
Localized card names, keyed by language code.
Definition card_info.h:83
const QList< CardRelation * > & getReverseRelatedCards2Me() const
Definition card_info.h:424
QSet< QString > altNames
Cached set of alternate names, used when searching.
Definition card_info.h:94
const QString & getSetsNames() const
Definition card_info.h:409
QString name
Full name of the card.
Definition card_info.h:78
QList< CardRelation * > relatedCards
Forward references to related cards.
Definition card_info.h:88
SetToPrintingsMap setsToPrintings
Mapping from set names to printing variations.
Definition card_info.h:91
void setLocalizedText(const QString &lang, const QString &_localizedText)
Sets the rules text for the given language.
Definition card_info.h:366
const QSet< QString > & getAltNames()
Definition card_info.h:283
QString getProperty(const QString &propertyName) const
Definition card_info.h:396
CardInfo(const CardInfo &other)
Copy constructor for CardInfo.
Definition card_info.h:166
LazyPropertiesHash properties
Key-value store of dynamic card properties.
Definition card_info.h:86
QList< CardRelation * > reverseRelatedCardsToMe
Cards that consider this card as related.
Definition card_info.h:90
void addReverseRelatedCards2Me(CardRelation *cardRelation)
Definition card_info.h:436
CardInfoPtr clone() const
Clones the current CardInfo instance.
Definition card_info.h:255
void cardInfoChanged(CardInfoPtr card)
Emitted when card properties or state have changed.
const QString & getText() const
Definition card_info.h:287
QString setsNames
Cached, human-readable list of set names.
Definition card_info.h:93
bool getIsToken() const
Definition card_info.h:386
const QString & getLocalizedName(const QString &lang) const
Returns the card name in the given language, falling back to the English name when no localization is...
Definition card_info.h:304
CardInfo(const QString &_name, const QString &_text, bool _isToken, const QHash< QString, QString > &_properties, const QList< CardRelation * > &_relatedCards, const QList< CardRelation * > &_reverseRelatedCards, SetToPrintingsMap _sets, UiAttributes _uiAttributes, QMap< QString, QString > _localizedNames={}, QMap< QString, QString > _localizedTexts={})
Constructs a CardInfo with full initialization.
Definition card_info.cpp:32
const QHash< QString, QString > & getPropertiesHash() const
Definition card_info.cpp:17
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:428
bool isToken
Whether this card is a token or not.
Definition card_info.h:81
QStringList getProperties() const
Definition card_info.h:390
QString text
Text description or rules text of the card.
Definition card_info.h:80
QStringList localizationLanguages() const
Returns the language codes for which this card has a localized name or rules text.
Definition card_info.h:379
const QString & getName() const
Definition card_info.h:275
Represents a relationship between two cards.
Definition card_relation.h:25
A collection of cards grouped under a common identifier.
Definition card_set.h:37
A property map that can lazily deserialize blobs to avoid loading overhead.
Definition lazy_properties_hash.h:19
Represents metadata for a specific variation of a card within a set.
Definition printing_info.h:31
PrintingInfo(const CardSetPtr &_set=nullptr, const LazyPropertiesHash &_properties={})
Constructs a PrintingInfo associated with a specific set.
Definition printing_info.cpp:5
Definition mana_curve_category_widget.h:11
Definition remote_connection_controller.h:20
Definition game.h:18
Definition dlg_manage_sets.h:29
Definition arrow_registry.h:10
Q_LOGGING_CATEGORY(CrashReportLog, "crash_report")
Attributes of the card that affect display and game logic.
Definition card_info.h:65
int tableRow
Row index in a table or visual representation.
Definition card_info.h:68
bool landscapeOrientation
Orientation flag for rendering.
Definition card_info.h:67
bool cipt
Positioning flag used by UI.
Definition card_info.h:66
bool upsideDownArt
Whether artwork is flipped for visual purposes.
Definition card_info.h:69