1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/lib/modding/ModDescription.cpp
Ivan Savenko ba9e3dca9d Mod management rework, part 1
- Replaced CModInfo class with constant ModDescription class
- Simplified mod loading logic
- Extracted some functionality from ModHandler into separate classes for
future reuse by Launcher
2024-11-26 13:55:46 +00:00

115 lines
2.4 KiB
C++

/*
* 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)
, config(std::make_unique<JsonNode>(config))
, 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";
return getConfig()["language"].isString() ? getConfig()["language"].String() : defaultLanguage;
}
const std::string & ModDescription::getName() const
{
return getConfig()["name"].String();
}
const JsonNode & ModDescription::getFilesystemConfig() const
{
return getConfig()["filesystem"];
}
const JsonNode & ModDescription::getConfig() const
{
return *config;
}
CModVersion ModDescription::getVersion() const
{
return CModVersion::fromString(getConfig()["version"].String());
}
ModVerificationInfo ModDescription::getVerificationInfo() const
{
ModVerificationInfo result;
result.name = getName();
result.version = getVersion();
result.impactsGameplay = affectsGameplay();
result.parent = getParentID();
return result;
}
bool ModDescription::affectsGameplay() const
{
return false; // TODO
}
VCMI_LIB_NAMESPACE_END