2024-11-12 22:00:21 +02:00
|
|
|
/*
|
|
|
|
* modstate.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "modstate.h"
|
|
|
|
|
|
|
|
#include "../../lib/modding/ModDescription.h"
|
|
|
|
#include "../../lib/json/JsonNode.h"
|
|
|
|
#include "../../lib/texts/CGeneralTextHandler.h"
|
2024-11-14 20:01:49 +02:00
|
|
|
#include "../../lib/texts/Languages.h"
|
2024-11-12 22:00:21 +02:00
|
|
|
|
|
|
|
ModState::ModState(const ModDescription & impl)
|
|
|
|
: impl(impl)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getName() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(impl.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getType() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(impl.getValue("modType").String());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getDescription() const
|
|
|
|
{
|
2024-11-15 13:54:43 +02:00
|
|
|
return QString::fromStdString(impl.getLocalizedValue("description").String());
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getID() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(impl.getID());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getParentID() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(impl.getParentID());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getTopParentID() const
|
|
|
|
{
|
2024-11-15 13:54:43 +02:00
|
|
|
return QString::fromStdString(impl.getTopParentID());
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Container>
|
|
|
|
QStringList stringListStdToQt(const Container & container)
|
|
|
|
{
|
|
|
|
QStringList result;
|
|
|
|
for (const auto & str : container)
|
|
|
|
result.push_back(QString::fromStdString(str));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList ModState::getDependencies() const
|
|
|
|
{
|
|
|
|
return stringListStdToQt(impl.getDependencies());
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList ModState::getConflicts() const
|
|
|
|
{
|
|
|
|
return stringListStdToQt(impl.getConflicts());
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList ModState::getScreenshots() const
|
|
|
|
{
|
2024-11-15 13:54:43 +02:00
|
|
|
return stringListStdToQt(impl.getLocalizedValue("screenshots").convertTo<std::vector<std::string>>());
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getBaseLanguage() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(impl.getBaseLanguage());
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList ModState::getSupportedLanguages() const
|
|
|
|
{
|
2024-11-14 20:01:49 +02:00
|
|
|
QStringList result;
|
|
|
|
result.push_back(getBaseLanguage());
|
|
|
|
|
|
|
|
for (const auto & language : Languages::getLanguageList())
|
|
|
|
{
|
|
|
|
QString languageID = QString::fromStdString(language.identifier);
|
|
|
|
|
|
|
|
if (languageID != getBaseLanguage() && !impl.getValue(language.identifier).isNull())
|
|
|
|
result.push_back(languageID);
|
|
|
|
}
|
|
|
|
return result;
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QMap<QString, QStringList> ModState::getChangelog() const
|
|
|
|
{
|
2024-11-14 20:01:49 +02:00
|
|
|
QMap<QString, QStringList> result;
|
2024-11-15 13:54:43 +02:00
|
|
|
const JsonNode & changelog = impl.getLocalizedValue("changelog");
|
2024-11-14 20:01:49 +02:00
|
|
|
|
|
|
|
for (const auto & entry : changelog.Struct())
|
|
|
|
{
|
|
|
|
QString version = QString::fromStdString(entry.first);
|
|
|
|
QStringList changes = stringListStdToQt(entry.second.convertTo<std::vector<std::string>>());
|
|
|
|
|
|
|
|
result[version] = changes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getInstalledVersion() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(impl.getLocalValue("version").String());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getRepositoryVersion() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(impl.getRepositoryValue("version").String());
|
|
|
|
}
|
|
|
|
|
2024-11-14 20:01:49 +02:00
|
|
|
QString ModState::getVersion() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(impl.getValue("version").String());
|
|
|
|
}
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
double ModState::getDownloadSizeMegabytes() const
|
|
|
|
{
|
|
|
|
return impl.getRepositoryValue("downloadSize").Float();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t ModState::getDownloadSizeBytes() const
|
|
|
|
{
|
|
|
|
return getDownloadSizeMegabytes() * 1024 * 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getDownloadSizeFormatted() const
|
|
|
|
{
|
2024-11-14 20:01:49 +02:00
|
|
|
return QCoreApplication::translate("File size", "%1 MiB").arg(QString::number(getDownloadSizeMegabytes(), 'f', 1));
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getAuthors() const
|
|
|
|
{
|
2024-11-15 13:54:43 +02:00
|
|
|
return QString::fromStdString(impl.getLocalizedValue("author").String());
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getContact() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(impl.getValue("contact").String());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getLicenseUrl() const
|
|
|
|
{
|
2024-11-13 19:25:59 +02:00
|
|
|
return QString::fromStdString(impl.getValue("licenseURL").String());
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getLicenseName() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(impl.getValue("licenseName").String());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ModState::getDownloadUrl() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(impl.getRepositoryValue("download").String());
|
|
|
|
}
|
|
|
|
|
|
|
|
QPair<QString, QString> ModState::getCompatibleVersionRange() const
|
|
|
|
{
|
2024-11-14 20:01:49 +02:00
|
|
|
const JsonNode & compatibility = impl.getValue("compatibility");
|
|
|
|
|
|
|
|
if (compatibility.isNull())
|
|
|
|
return {};
|
|
|
|
|
|
|
|
auto min = QString::fromStdString(compatibility["min"].String());
|
|
|
|
auto max = QString::fromStdString(compatibility["max"].String());
|
|
|
|
return { min, max};
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ModState::isSubmod() const
|
|
|
|
{
|
|
|
|
return !getParentID().isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModState::isCompatibility() const
|
|
|
|
{
|
|
|
|
return impl.isCompatibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModState::isTranslation() const
|
|
|
|
{
|
|
|
|
return impl.isTranslation();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModState::isVisible() const
|
|
|
|
{
|
|
|
|
return !isHidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModState::isHidden() const
|
|
|
|
{
|
|
|
|
if (isTranslation() && !isInstalled())
|
2024-11-15 18:43:28 +02:00
|
|
|
return impl.getBaseLanguage() != CGeneralTextHandler::getPreferredLanguage();
|
2024-11-12 22:00:21 +02:00
|
|
|
|
2024-11-13 19:25:59 +02:00
|
|
|
return isCompatibility() || getID() == "vcmi" || getID() == "core";
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ModState::isAvailable() const
|
|
|
|
{
|
|
|
|
return !isInstalled();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModState::isInstalled() const
|
|
|
|
{
|
|
|
|
return impl.isInstalled();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModState::isUpdateAvailable() const
|
|
|
|
{
|
2024-11-26 23:05:18 +02:00
|
|
|
return impl.isUpdateAvailable();
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ModState::isCompatible() const
|
|
|
|
{
|
2024-11-14 20:01:49 +02:00
|
|
|
return impl.isCompatible();
|
2024-11-12 22:00:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ModState::isKeptDisabled() const
|
|
|
|
{
|
|
|
|
return impl.keepDisabled();
|
|
|
|
}
|