2012-08-10 16:07:53 +03:00
|
|
|
/*
|
|
|
|
* CModHandler.h, 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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
2023-05-24 00:14:06 +02:00
|
|
|
#include "CModVersion.h"
|
2012-08-10 16:07:53 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2012-08-10 16:07:53 +03:00
|
|
|
class CModHandler;
|
|
|
|
class CModIndentifier;
|
|
|
|
class CModInfo;
|
2012-11-13 14:52:23 +03:00
|
|
|
class JsonNode;
|
2013-04-21 15:49:26 +03:00
|
|
|
class IHandlerBase;
|
2023-07-30 19:12:25 +02:00
|
|
|
class CIdentifierStorage;
|
|
|
|
class CContentHandler;
|
|
|
|
class ResourceID;
|
2012-12-03 19:00:17 +03:00
|
|
|
|
2023-04-16 13:38:13 +02:00
|
|
|
using TModID = std::string;
|
2012-08-10 16:07:53 +03:00
|
|
|
|
2023-07-30 19:12:25 +02:00
|
|
|
class DLL_LINKAGE CModHandler : boost::noncopyable
|
2012-08-10 16:07:53 +03:00
|
|
|
{
|
2012-11-13 14:52:23 +03:00
|
|
|
std::map <TModID, CModInfo> allMods;
|
2012-12-12 14:13:57 +03:00
|
|
|
std::vector <TModID> activeMods;//active mods, in order in which they were loaded
|
2023-07-30 19:12:25 +02:00
|
|
|
std::unique_ptr<CModInfo> coreMod;
|
2012-08-10 16:07:53 +03:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
bool hasCircularDependency(const TModID & mod, std::set<TModID> currentList = std::set<TModID>()) const;
|
2013-01-10 21:53:49 +03:00
|
|
|
|
2021-04-10 17:23:58 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
2014-03-15 13:57:34 +03:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
std::vector<std::string> getModList(const std::string & path) const;
|
|
|
|
void loadMods(const std::string & path, const std::string & parent, const JsonNode & modSettings, bool enableMods);
|
|
|
|
void loadOneMod(std::string modName, const std::string & parent, const JsonNode & modSettings, bool enableMods);
|
|
|
|
void loadTranslation(const TModID & modName);
|
2023-02-09 19:15:39 +02:00
|
|
|
|
|
|
|
bool validateTranslations(TModID modName) const;
|
2022-12-07 15:18:19 +02:00
|
|
|
|
2023-07-30 19:12:25 +02:00
|
|
|
CModVersion getModVersion(TModID modName) const;
|
2022-12-07 15:18:19 +02:00
|
|
|
|
2023-07-30 19:12:25 +02:00
|
|
|
/// Attempt to set active mods according to provided list of mods from save, throws on failure
|
2023-08-18 14:08:23 +02:00
|
|
|
void trySetActiveMods(std::vector<TModID> saveActiveMods, const std::map<TModID, CModVersion> & modList);
|
2022-12-07 15:18:19 +02:00
|
|
|
|
2023-07-30 19:12:25 +02:00
|
|
|
std::unique_ptr<CIdentifierStorage> identifiers;
|
2022-12-07 15:18:19 +02:00
|
|
|
|
2023-07-30 19:12:25 +02:00
|
|
|
public:
|
|
|
|
std::shared_ptr<CContentHandler> content; //(!)Do not serialize FIXME: make private
|
2012-12-03 19:00:17 +03:00
|
|
|
|
2023-07-30 19:12:25 +02:00
|
|
|
CIdentifierStorage & getIdentifiers();
|
2017-07-20 06:08:49 +02:00
|
|
|
|
2012-12-12 14:13:57 +03:00
|
|
|
/// receives list of available mods and trying to load mod.json from all of them
|
2013-11-09 22:10:16 +03:00
|
|
|
void initializeConfig();
|
2017-07-20 06:08:49 +02:00
|
|
|
void loadMods(bool onlyEssential = false);
|
2014-03-15 13:57:34 +03:00
|
|
|
void loadModFilesystems();
|
2012-11-13 14:52:23 +03:00
|
|
|
|
2023-02-24 22:38:12 +02:00
|
|
|
/// returns ID of mod that provides selected file resource
|
|
|
|
TModID findResourceOrigin(const ResourceID & name);
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
std::string getModLanguage(const TModID & modId) const;
|
2023-02-09 15:03:49 +02:00
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
std::set<TModID> getModDependencies(const TModID & modId, bool & isModFound) const;
|
2013-04-25 17:03:35 +03:00
|
|
|
|
2014-03-15 13:57:34 +03:00
|
|
|
/// returns list of all (active) mods
|
|
|
|
std::vector<std::string> getAllMods();
|
|
|
|
std::vector<std::string> getActiveMods();
|
2023-04-16 13:38:13 +02:00
|
|
|
|
|
|
|
const CModInfo & getModInfo(const TModID & modId) const;
|
2014-03-15 13:57:34 +03:00
|
|
|
|
2012-11-13 14:52:23 +03:00
|
|
|
/// load content from all available mods
|
2013-11-09 22:10:16 +03:00
|
|
|
void load();
|
2017-07-20 06:08:49 +02:00
|
|
|
void afterLoad(bool onlyEssential);
|
2012-11-13 14:52:23 +03:00
|
|
|
|
2012-08-10 16:07:53 +03:00
|
|
|
CModHandler();
|
2023-07-30 19:12:25 +02:00
|
|
|
virtual ~CModHandler();
|
2015-11-16 16:38:42 +02:00
|
|
|
|
2012-08-10 16:07:53 +03:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2022-09-17 15:43:59 +02:00
|
|
|
if(h.saving)
|
|
|
|
{
|
|
|
|
h & activeMods;
|
2022-09-18 23:18:17 +02:00
|
|
|
for(const auto & m : activeMods)
|
2023-07-30 19:12:25 +02:00
|
|
|
{
|
|
|
|
CModVersion version = getModVersion(m);
|
|
|
|
h & version;
|
|
|
|
}
|
2022-09-17 15:43:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-23 10:34:44 +02:00
|
|
|
loadMods();
|
2023-08-18 14:08:23 +02:00
|
|
|
std::vector<TModID> saveActiveMods;
|
2023-07-30 19:12:25 +02:00
|
|
|
std::map<TModID, CModVersion> modVersions;
|
2023-08-18 14:08:23 +02:00
|
|
|
h & saveActiveMods;
|
2023-07-30 19:12:25 +02:00
|
|
|
|
2023-08-18 14:08:23 +02:00
|
|
|
for(const auto & m : saveActiveMods)
|
2023-07-30 19:12:25 +02:00
|
|
|
h & modVersions[m];
|
|
|
|
|
2023-08-18 14:08:23 +02:00
|
|
|
trySetActiveMods(saveActiveMods, modVersions);
|
2022-09-17 15:43:59 +02:00
|
|
|
}
|
2023-03-15 21:34:29 +02:00
|
|
|
|
2017-07-31 15:35:42 +02:00
|
|
|
h & identifiers;
|
2012-08-10 16:07:53 +03:00
|
|
|
}
|
2012-08-10 18:16:42 +03:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|