mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
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
This commit is contained in:
114
lib/modding/ModDescription.cpp
Normal file
114
lib/modding/ModDescription.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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
|
||||
Reference in New Issue
Block a user