1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-12-01 23:12:49 +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:
Ivan Savenko
2024-11-09 20:29:07 +00:00
parent c22471fd91
commit ba9e3dca9d
25 changed files with 864 additions and 827 deletions

View File

@@ -12,51 +12,26 @@
VCMI_LIB_NAMESPACE_BEGIN
class CModHandler;
class CModIdentifier;
class CModInfo;
struct CModVersion;
class JsonNode;
class IHandlerBase;
class CIdentifierStorage;
class ModDescription;
class CContentHandler;
struct ModVerificationInfo;
class ResourcePath;
class MetaString;
class ModManager;
class ISimpleResourceLoader;
using TModID = std::string;
class DLL_LINKAGE CModHandler final : boost::noncopyable
{
std::map <TModID, CModInfo> allMods;
std::vector <TModID> activeMods;//active mods, in order in which they were loaded
std::unique_ptr<CModInfo> coreMod;
mutable std::unique_ptr<MetaString> modLoadErrors;
std::unique_ptr<ModManager> modManager;
bool hasCircularDependency(const TModID & mod, std::set<TModID> currentList = std::set<TModID>()) const;
/**
* 1. Set apart mods with resolved dependencies from mods which have unresolved dependencies
* 2. Sort resolved mods using topological algorithm
* 3. Log all problem mods and their unresolved dependencies
*
* @param modsToResolve list of valid mod IDs (checkDependencies returned true - TODO: Clarify it.)
* @return a vector of the topologically sorted resolved mods: child nodes (dependent mods) have greater index than parents
*/
std::vector<TModID> validateAndSortDependencies(std::vector <TModID> modsToResolve) const;
std::vector<std::string> getModList(const std::string & path) const;
void loadMods(const std::string & path, const std::string & parent, const JsonNode & modSettings, const std::vector<TModID> & modsToActivate, bool enableMods);
void loadOneMod(std::string modName, const std::string & parent, const JsonNode & modSettings, const std::vector<TModID> & modsToActivate, bool enableMods);
void loadTranslation(const TModID & modName);
CModVersion getModVersion(TModID modName) const;
void checkModFilesystemsConflicts(const std::map<TModID, ISimpleResourceLoader *> & modFilesystems);
public:
std::shared_ptr<CContentHandler> content; //(!)Do not serialize FIXME: make private
std::shared_ptr<CContentHandler> content; //FIXME: make private
/// receives list of available mods and trying to load mod.json from all of them
void initializeConfig();
void loadMods();
void loadModFilesystems();
/// returns ID of mod that provides selected file resource
@@ -82,7 +57,7 @@ public:
/// Returns human-readable string that describes errors encounter during mod loading, such as missing dependencies
std::string getModLoadErrors() const;
const CModInfo & getModInfo(const TModID & modId) const;
const ModDescription & getModInfo(const TModID & modId) const;
/// load content from all available mods
void load();