2024-11-09 22:29:07 +02:00
|
|
|
/*
|
|
|
|
* ModDescription.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 "ModDescription.h"
|
|
|
|
|
|
|
|
#include "CModVersion.h"
|
|
|
|
#include "ModVerificationInfo.h"
|
|
|
|
|
|
|
|
#include "../json/JsonNode.h"
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
ModDescription::ModDescription(const TModID & fullID, const JsonNode & config)
|
|
|
|
: identifier(fullID)
|
2024-11-12 22:00:21 +02:00
|
|
|
, localConfig(std::make_unique<JsonNode>(config))
|
2024-11-09 22:29:07 +02:00
|
|
|
, dependencies(loadModList(config["depends"]))
|
|
|
|
, softDependencies(loadModList(config["softDepends"]))
|
|
|
|
, conflicts(loadModList(config["conflicts"]))
|
|
|
|
{
|
|
|
|
if(getID() != "core")
|
|
|
|
dependencies.insert("core");
|
|
|
|
}
|
|
|
|
|
|
|
|
ModDescription::~ModDescription() = default;
|
|
|
|
|
|
|
|
TModSet ModDescription::loadModList(const JsonNode & configNode) const
|
|
|
|
{
|
|
|
|
TModSet result;
|
|
|
|
for(const auto & entry : configNode.Vector())
|
|
|
|
result.insert(boost::algorithm::to_lower_copy(entry.String()));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TModID & ModDescription::getID() const
|
|
|
|
{
|
|
|
|
return identifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
TModID ModDescription::getParentID() const
|
|
|
|
{
|
|
|
|
size_t dotPos = identifier.find_last_of('.');
|
|
|
|
|
|
|
|
if(dotPos == std::string::npos)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return identifier.substr(0, dotPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
const TModSet & ModDescription::getDependencies() const
|
|
|
|
{
|
|
|
|
return dependencies;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TModSet & ModDescription::getSoftDependencies() const
|
|
|
|
{
|
|
|
|
return softDependencies;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TModSet & ModDescription::getConflicts() const
|
|
|
|
{
|
|
|
|
return conflicts;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string & ModDescription::getBaseLanguage() const
|
|
|
|
{
|
|
|
|
static const std::string defaultLanguage = "english";
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
return getLocalConfig()["language"].isString() ? getLocalConfig()["language"].String() : defaultLanguage;
|
2024-11-09 22:29:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string & ModDescription::getName() const
|
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
return getLocalConfig()["name"].String();
|
2024-11-09 22:29:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const JsonNode & ModDescription::getFilesystemConfig() const
|
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
return getLocalConfig()["filesystem"];
|
2024-11-09 22:29:07 +02:00
|
|
|
}
|
|
|
|
|
2024-11-12 22:00:21 +02:00
|
|
|
const JsonNode & ModDescription::getLocalConfig() const
|
2024-11-09 22:29:07 +02:00
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
return *localConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
const JsonNode & ModDescription::getValue(const std::string & keyName) const
|
|
|
|
{
|
|
|
|
return getLocalConfig()[keyName];
|
|
|
|
}
|
|
|
|
|
|
|
|
const JsonNode & ModDescription::getLocalValue(const std::string & keyName) const
|
|
|
|
{
|
|
|
|
return getLocalConfig()[keyName];
|
|
|
|
}
|
|
|
|
|
|
|
|
const JsonNode & ModDescription::getRepositoryValue(const std::string & keyName) const
|
|
|
|
{
|
|
|
|
return (*repositoryConfig)[keyName];
|
2024-11-09 22:29:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CModVersion ModDescription::getVersion() const
|
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
return CModVersion::fromString(getLocalConfig()["version"].String());
|
2024-11-09 22:29:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ModVerificationInfo ModDescription::getVerificationInfo() const
|
|
|
|
{
|
|
|
|
ModVerificationInfo result;
|
|
|
|
result.name = getName();
|
|
|
|
result.version = getVersion();
|
|
|
|
result.impactsGameplay = affectsGameplay();
|
|
|
|
result.parent = getParentID();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-11-11 13:19:14 +02:00
|
|
|
bool ModDescription::isCompatibility() const
|
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
return getLocalConfig()["modType"].String() == "Compatibility";
|
2024-11-11 13:19:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ModDescription::isTranslation() const
|
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
return getLocalConfig()["modType"].String() == "Translation";
|
2024-11-11 13:19:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ModDescription::keepDisabled() const
|
|
|
|
{
|
2024-11-12 22:00:21 +02:00
|
|
|
return getLocalConfig()["keepDisabled"].Bool();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ModDescription::isInstalled() const
|
|
|
|
{
|
|
|
|
return !localConfig->isNull();
|
2024-11-11 13:19:14 +02:00
|
|
|
}
|
|
|
|
|
2024-11-09 22:29:07 +02:00
|
|
|
bool ModDescription::affectsGameplay() const
|
|
|
|
{
|
2024-11-11 13:19:14 +02:00
|
|
|
return true; // TODO
|
2024-11-09 22:29:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|