Initial commit of mtgonline project

This commit is contained in:
2026-07-18 04:57:40 +00:00
commit 86c12376f8
1870 changed files with 547994 additions and 0 deletions
@@ -0,0 +1,82 @@
#include "exact_card.h"
#include "../card_info.h"
#include "printing_info.h"
/**
* Default constructor.
* This will set the CardInfoPtr to null.
* The printing will be the default-constructed PrintingInfo.
*/
ExactCard::ExactCard()
{
}
/**
* @param _card The card. Can be null.
* @param _printing The printing. Can be empty.
*/
ExactCard::ExactCard(const CardInfoPtr &_card, const PrintingInfo &_printing) : card(_card), printing(_printing)
{
}
bool ExactCard::operator==(const ExactCard &other) const
{
return this->card == other.card && this->printing == other.printing;
}
/**
* Convenience method to safely get the card's name.
* @return The name in the CardInfo, or an empty string if card is null
*/
QString ExactCard::getName() const
{
return card.isNull() ? "" : card->getName();
}
/**
* Gets a view of the underlying cardInfoPtr.
* @return A const reference to the CardInfo, or an empty CardInfo if card is null
*/
const CardInfo &ExactCard::getInfo() const
{
if (card.isNull()) {
static CardInfoPtr emptyCard = CardInfo::newInstance("");
return *emptyCard;
}
return *card;
}
/**
* The key used to identify this exact printing in the cache
*/
QString ExactCard::getPixmapCacheKey() const
{
QString uuid = printing.getUuid();
QString suffix = uuid.isEmpty() ? "" : "_" + uuid;
return QLatin1String("card_") + card->getName() + suffix;
}
/**
* Checks if the card is null or empty.
*/
bool ExactCard::isEmpty() const
{
return card.isNull() || card->getName().isEmpty();
}
/**
* Returns true if isEmpty() is false
*/
ExactCard::operator bool() const
{
return !isEmpty();
}
/**
* Gets the CardInfo to emit the pixmapUpdated signal
*/
void ExactCard::emitPixmapUpdated() const
{
emit card->pixmapUpdated(printing);
}
@@ -0,0 +1,119 @@
#ifndef EXACT_CARD_H
#define EXACT_CARD_H
#include "../card_info.h"
/**
* @class ExactCard
* @ingroup CardPrintings
*
* @brief Represents a specific card instance, defined by its CardInfo
* and a particular printing.
*
* An ExactCard identifies a card not only by its underlying CardInfoPtr
* (which may be null), but also by its PrintingInfo, which specifies the
* exact printing/variant. This allows distinguishing between different
* printings of the same logical card (e.g., different sets, promos, foils).
*/
class ExactCard
{
CardInfoPtr card;
PrintingInfo printing;
public:
/**
* @brief Constructs an empty ExactCard.
*
* The CardInfoPtr will be null, and PrintingInfo will be default-constructed.
* An empty ExactCard represents "no card".
*/
ExactCard();
/**
* @brief Constructs an ExactCard from a card and printing.
*
* @param _card The card info pointer. May be null.
* @param _printing The printing details. Defaults to an empty PrintingInfo.
*/
explicit ExactCard(const CardInfoPtr &_card, const PrintingInfo &_printing = PrintingInfo());
/**
* @brief Returns the underlying CardInfoPtr.
*
* May be null if the ExactCard is empty.
*/
[[nodiscard]] CardInfoPtr getCardPtr() const
{
return card;
}
/**
* @brief Returns the printing information associated with this card.
*
* May be empty if no specific printing was assigned.
*/
[[nodiscard]] PrintingInfo getPrinting() const
{
return printing;
}
/**
* @brief Compares both card pointer and printing for equality.
*
* Two ExactCard objects are equal only if both their CardInfoPtr and
* PrintingInfo values are equal.
*/
bool operator==(const ExactCard &other) const;
/**
* @brief Convenience helper to get the card's display name.
*
* @return The card's name, or an empty string if the CardInfoPtr is null.
*/
[[nodiscard]] QString getName() const;
/**
* @brief Returns a reference to the underlying CardInfo object.
*
* If the CardInfoPtr is null, returns a reference to a static empty CardInfo
* instance instead. This avoids null-dereferencing but means modifications
* to the returned object do not affect the ExactCard.
*
* @return A const reference to the CardInfo object.
*/
[[nodiscard]] const CardInfo &getInfo() const;
/**
* @brief Generates a stable cache key for pixmap caching.
*
* The key includes the card's name and (if present) the printing UUID,
* allowing different printings of the same card to map to different cache entries.
*/
[[nodiscard]] QString getPixmapCacheKey() const;
/**
* @brief Indicates whether this ExactCard represents no valid card.
*
* An ExactCard is considered empty if the CardInfoPtr is null or the
* card's name is empty.
*/
[[nodiscard]] bool isEmpty() const;
/**
* @brief Boolean conversion indicating whether the card is valid (non-empty).
*
* @return true if not empty, false otherwise.
*/
explicit operator bool() const;
/**
* @brief Emits the pixmapUpdated signal on the underlying CardInfo.
*
* Assumes CardInfoPtr is non-null. If called on an empty ExactCard,
* the behavior is undefined.
*/
void emitPixmapUpdated() const;
};
Q_DECLARE_METATYPE(ExactCard)
#endif // EXACT_CARD_H
@@ -0,0 +1,20 @@
#include "printing_info.h"
#include "../set/card_set.h"
PrintingInfo::PrintingInfo(const CardSetPtr &_set) : set(_set)
{
}
/**
* Gets the uuid property of the printing, or an empty string if the property isn't present
*/
QString PrintingInfo::getUuid() const
{
return properties.value("uuid").toString();
}
QString PrintingInfo::getFlavorName() const
{
return properties.value("flavorName").toString();
}
@@ -0,0 +1,131 @@
#ifndef COCKATRICE_PRINTING_INFO_H
#define COCKATRICE_PRINTING_INFO_H
#include "../set/card_set.h"
#include <QList>
#include <QMap>
#include <QVariant>
class PrintingInfo;
using SetToPrintingsMap = QMap<QString, QList<PrintingInfo>>;
/**
* @class PrintingInfo
* @ingroup CardPrintings
*
* @brief Represents metadata for a specific variation of a card within a set.
*
* A card can have multiple variations across sets. PrintingInfo associates
* a card with one such variation, and provides per-printing attributes
* such as identifiers or additional properties.
*
* Equality is defined as both the set and the property values being equal.
*/
class PrintingInfo
{
public:
/**
* @brief Constructs a PrintingInfo associated with a specific set.
*
* @param _set The set this printing belongs to (defaults to null).
*/
explicit PrintingInfo(const CardSetPtr &_set = nullptr);
/**
* @brief Destroys the PrintingInfo.
*
* Defaulted since no special cleanup is required.
*/
~PrintingInfo() = default;
/**
* @brief Equality operator.
*
* Two PrintingInfo objects are equal if they refer to the same set
* and contain the exact same property key/value pairs.
*
* @param other Another PrintingInfo to compare against.
* @return True if both set and properties are equal, otherwise false.
*/
bool operator==(const PrintingInfo &other) const
{
return this->set == other.set && this->properties == other.properties;
}
/**
* @brief check if the info is empty, as if default constructed.
*
* @return True if both set and properties are empty, otherwise false.
*/
bool isEmpty() const
{
return set == nullptr && properties.isEmpty();
}
private:
CardSetPtr set; ///< The set this variation belongs to.
QVariantHash properties; ///< Key-value store for variation-specific attributes.
public:
/**
* @brief Returns the set this printing belongs to.
*
* @return Pointer to the associated CardSet.
*/
[[nodiscard]] CardSetPtr getSet() const
{
return set;
}
/**
* @brief Returns the list of property names defined for this printing.
*
* @return List of keys stored in the properties map.
*/
[[nodiscard]] QStringList getProperties() const
{
return properties.keys();
}
/**
* @brief Retrieves the value of a specific property.
*
* @param propertyName The key name of the property to query.
* @return The property value as a string, or an empty string if not set.
*/
[[nodiscard]] QString getProperty(const QString &propertyName) const
{
return properties.value(propertyName).toString();
}
/**
* @brief Sets or updates the value of a specific property.
*
* If the property already exists, its value is replaced.
*
* @param _name The name of the property.
* @param _value The string value to assign.
*/
void setProperty(const QString &_name, const QString &_value)
{
properties.insert(_name, _value);
}
/**
* @brief Returns the providerID for this printing.
*
* @return A string representing the providerID.
*/
[[nodiscard]] QString getUuid() const;
/**
* @brief Returns the flavorName for this printing.
*
* @return The flavorName, or empty if it isn't present.
*/
[[nodiscard]] QString getFlavorName() const;
};
#endif // COCKATRICE_PRINTING_INFO_H