mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 00:55:09 -07:00
[CardInfo] Refactor: remove properties setters (#7070)
This commit is contained in:
parent
32619f4d55
commit
0d14fb77a0
8 changed files with 22 additions and 61 deletions
|
|
@ -64,14 +64,6 @@ void CardInfo::setProperty(const QString &_name, const QString &_value)
|
||||||
emit cardInfoChanged(smartThis);
|
emit cardInfoChanged(smartThis);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardInfo::setProperties(const QHash<QString, QString> &_props)
|
|
||||||
{
|
|
||||||
ensurePropertiesLoaded();
|
|
||||||
propertiesCache = _props;
|
|
||||||
propertiesBlob = serializeProperties(propertiesCache);
|
|
||||||
emit cardInfoChanged(smartThis);
|
|
||||||
}
|
|
||||||
|
|
||||||
CardInfo::CardInfo(const QString &_name,
|
CardInfo::CardInfo(const QString &_name,
|
||||||
const QString &_text,
|
const QString &_text,
|
||||||
bool _isToken,
|
bool _isToken,
|
||||||
|
|
|
||||||
|
|
@ -290,25 +290,11 @@ public:
|
||||||
}
|
}
|
||||||
[[nodiscard]] const QHash<QString, QString> &getPropertiesHash() const;
|
[[nodiscard]] const QHash<QString, QString> &getPropertiesHash() const;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Stores the pre-serialized properties blob and invalidates the
|
|
||||||
* materialized cache. Used by the binary cache reader so the
|
|
||||||
* QHash<QString, QString> is not built at load time.
|
|
||||||
* @param _blob The serialized properties (as written by the cache writer).
|
|
||||||
*/
|
|
||||||
void setPropertiesBlob(QByteArray _blob) const
|
|
||||||
{
|
|
||||||
QMutexLocker lock(&propertiesMutex);
|
|
||||||
propertiesBlob = std::move(_blob);
|
|
||||||
propertiesLoaded = false;
|
|
||||||
propertiesCache.clear();
|
|
||||||
}
|
|
||||||
[[nodiscard]] QString getProperty(const QString &propertyName) const
|
[[nodiscard]] QString getProperty(const QString &propertyName) const
|
||||||
{
|
{
|
||||||
return getPropertiesHash().value(propertyName);
|
return getPropertiesHash().value(propertyName);
|
||||||
}
|
}
|
||||||
void setProperty(const QString &_name, const QString &_value);
|
void setProperty(const QString &_name, const QString &_value);
|
||||||
void setProperties(const QHash<QString, QString> &_props);
|
|
||||||
[[nodiscard]] bool hasProperty(const QString &propertyName) const
|
[[nodiscard]] bool hasProperty(const QString &propertyName) const
|
||||||
{
|
{
|
||||||
return getPropertiesHash().contains(propertyName);
|
return getPropertiesHash().contains(propertyName);
|
||||||
|
|
|
||||||
|
|
@ -117,12 +117,9 @@ PrintingInfo readPrinting(QDataStream &in, const SetNameMap &sets)
|
||||||
{
|
{
|
||||||
QString setName = readString(in);
|
QString setName = readString(in);
|
||||||
QByteArray propsBlob = readHashBlob(in);
|
QByteArray propsBlob = readHashBlob(in);
|
||||||
PrintingInfo p;
|
auto set = sets.value(setName);
|
||||||
if (auto set = sets.value(setName)) {
|
|
||||||
p = PrintingInfo(set);
|
return PrintingInfo(set, propsBlob);
|
||||||
}
|
|
||||||
p.setPropertiesBlob(propsBlob);
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- CardSet ---------------------------------------------------------------
|
// ---- CardSet ---------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,6 @@ void CockatriceXml3Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
||||||
// Only load printings from sets the user has enabled, matching the v4 loader's
|
// Only load printings from sets the user has enabled, matching the v4 loader's
|
||||||
// behaviour. Without this check, disabling a set has no effect on v3 databases.
|
// behaviour. Without this check, disabling a set has no effect on v3 databases.
|
||||||
if (set->getEnabled()) {
|
if (set->getEnabled()) {
|
||||||
PrintingInfo setInfo(set);
|
|
||||||
QHash<QString, QString> printingProps;
|
QHash<QString, QString> printingProps;
|
||||||
if (attrs.hasAttribute("muId")) {
|
if (attrs.hasAttribute("muId")) {
|
||||||
printingProps.insert("muid", attrs.value("muId").toString());
|
printingProps.insert("muid", attrs.value("muId").toString());
|
||||||
|
|
@ -249,7 +248,7 @@ void CockatriceXml3Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
||||||
if (attrs.hasAttribute("rarity")) {
|
if (attrs.hasAttribute("rarity")) {
|
||||||
printingProps.insert("rarity", attrs.value("rarity").toString());
|
printingProps.insert("rarity", attrs.value("rarity").toString());
|
||||||
}
|
}
|
||||||
setInfo.setProperties(printingProps);
|
PrintingInfo setInfo(set, printingProps);
|
||||||
_sets[setName].append(setInfo);
|
_sets[setName].append(setInfo);
|
||||||
}
|
}
|
||||||
// related cards
|
// related cards
|
||||||
|
|
|
||||||
|
|
@ -314,7 +314,6 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
||||||
QString setName = xml.readElementText(QXmlStreamReader::IncludeChildElements);
|
QString setName = xml.readElementText(QXmlStreamReader::IncludeChildElements);
|
||||||
auto set = internalAddSet(setName);
|
auto set = internalAddSet(setName);
|
||||||
if (set->getEnabled()) {
|
if (set->getEnabled()) {
|
||||||
PrintingInfo printingInfo(set);
|
|
||||||
QHash<QString, QString> printingProps;
|
QHash<QString, QString> printingProps;
|
||||||
for (QXmlStreamAttribute attr : attrs) {
|
for (QXmlStreamAttribute attr : attrs) {
|
||||||
QString attrName = attr.name().toString();
|
QString attrName = attr.name().toString();
|
||||||
|
|
@ -323,7 +322,7 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml)
|
||||||
}
|
}
|
||||||
printingProps.insert(attrName, attr.value().toString());
|
printingProps.insert(attrName, attr.value().toString());
|
||||||
}
|
}
|
||||||
printingInfo.setProperties(printingProps);
|
PrintingInfo printingInfo(set, printingProps);
|
||||||
|
|
||||||
// This is very much a hack and not the right place to
|
// This is very much a hack and not the right place to
|
||||||
// put this check, as it requires a reload of Cockatrice
|
// put this check, as it requires a reload of Cockatrice
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,12 @@
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
|
|
||||||
PrintingInfo::PrintingInfo(const CardSetPtr &_set) : set(_set)
|
PrintingInfo::PrintingInfo(const CardSetPtr &_set, const QHash<QString, QString> &_properties)
|
||||||
|
: set(_set), propertiesCache(_properties), propertiesLoaded(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintingInfo::PrintingInfo(const CardSetPtr &_set, const QByteArray &_blob) : set(_set), propertiesBlob(_blob)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,16 +36,6 @@ void PrintingInfo::setProperty(const QString &_name, const QString &_value)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
propertiesCache.insert(_name, _value);
|
propertiesCache.insert(_name, _value);
|
||||||
setProperties(propertiesCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintingInfo::setProperties(const QHash<QString, QString> &_props)
|
|
||||||
{
|
|
||||||
ensurePropertiesLoaded();
|
|
||||||
propertiesCache = _props;
|
|
||||||
QDataStream out(&propertiesBlob, QIODevice::WriteOnly);
|
|
||||||
out.setVersion(QDataStream::Qt_6_4);
|
|
||||||
out << propertiesCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,17 @@ public:
|
||||||
* @brief Constructs a PrintingInfo associated with a specific set.
|
* @brief Constructs a PrintingInfo associated with a specific set.
|
||||||
*
|
*
|
||||||
* @param _set The set this printing belongs to (defaults to null).
|
* @param _set The set this printing belongs to (defaults to null).
|
||||||
|
* @param _properties The printing properties (defaults to empty)
|
||||||
*/
|
*/
|
||||||
explicit PrintingInfo(const CardSetPtr &_set = nullptr);
|
explicit PrintingInfo(const CardSetPtr &_set = nullptr, const QHash<QString, QString> &_properties = {});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructs a PrintingInfo associated with a specific set.
|
||||||
|
*
|
||||||
|
* @param _set The set this printing belongs to (defaults to null).
|
||||||
|
* @param _blob The serialized properties (as written by the cache writer).
|
||||||
|
*/
|
||||||
|
explicit PrintingInfo(const CardSetPtr &_set, const QByteArray &_blob);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroys the PrintingInfo.
|
* @brief Destroys the PrintingInfo.
|
||||||
|
|
@ -127,21 +136,6 @@ public:
|
||||||
* @param _value The string value to assign.
|
* @param _value The string value to assign.
|
||||||
*/
|
*/
|
||||||
void setProperty(const QString &_name, const QString &_value);
|
void setProperty(const QString &_name, const QString &_value);
|
||||||
void setProperties(const QHash<QString, QString> &_props);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Stores the pre-serialized properties blob and marks the materialized
|
|
||||||
* cache as invalid. Used by the binary cache reader to avoid building a
|
|
||||||
* QHash<QString, QString> at load time.
|
|
||||||
* @param _blob The serialized properties (as written by the cache writer).
|
|
||||||
*/
|
|
||||||
void setPropertiesBlob(QByteArray _blob) const
|
|
||||||
{
|
|
||||||
QMutexLocker lock(propertiesMutex.data());
|
|
||||||
propertiesBlob = std::move(_blob);
|
|
||||||
propertiesLoaded = false;
|
|
||||||
propertiesCache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the providerID for this printing.
|
* @brief Returns the providerID for this printing.
|
||||||
|
|
|
||||||
|
|
@ -289,7 +289,6 @@ int OracleImporter::importCardsFromSet(const CardSetPtr ¤tSet, const QList
|
||||||
}
|
}
|
||||||
|
|
||||||
// per-set properties
|
// per-set properties
|
||||||
PrintingInfo printingInfo = PrintingInfo(currentSet);
|
|
||||||
QHash<QString, QString> printingProps;
|
QHash<QString, QString> printingProps;
|
||||||
for (auto i = setInfoProperties.cbegin(), end = setInfoProperties.cend(); i != end; ++i) {
|
for (auto i = setInfoProperties.cbegin(), end = setInfoProperties.cend(); i != end; ++i) {
|
||||||
QString mtgjsonProperty = i.key();
|
QString mtgjsonProperty = i.key();
|
||||||
|
|
@ -317,7 +316,7 @@ int OracleImporter::importCardsFromSet(const CardSetPtr ¤tSet, const QList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printingInfo.setProperties(printingProps);
|
PrintingInfo printingInfo(currentSet, printingProps);
|
||||||
|
|
||||||
QString numComponent;
|
QString numComponent;
|
||||||
const QString numProperty = printingInfo.getProperty("num");
|
const QString numProperty = printingInfo.getProperty("num");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue