/* * 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 * */ #pragma once #include "CModInfo.h" VCMI_LIB_NAMESPACE_BEGIN class CModHandler; class CModIndentifier; class JsonNode; class IHandlerBase; class CIdentifierStorage; class CContentHandler; class ResourcePath; using TModID = std::string; class DLL_LINKAGE CModHandler : boost::noncopyable { std::map allMods; std::vector activeMods;//active mods, in order in which they were loaded std::unique_ptr coreMod; bool hasCircularDependency(const TModID & mod, std::set currentList = std::set()) 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 validateAndSortDependencies(std::vector modsToResolve) const; std::vector 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); bool validateTranslations(TModID modName) const; CModVersion getModVersion(TModID modName) const; /// Attempt to set active mods according to provided list of mods from save, throws on failure void trySetActiveMods(const std::vector> & modList); public: std::shared_ptr content; //(!)Do not serialize FIXME: make private /// receives list of available mods and trying to load mod.json from all of them void initializeConfig(); void loadMods(bool onlyEssential = false); void loadModFilesystems(); /// returns ID of mod that provides selected file resource TModID findResourceOrigin(const ResourcePath & name); std::string getModLanguage(const TModID & modId) const; std::set getModDependencies(const TModID & modId, bool & isModFound) const; /// returns list of all (active) mods std::vector getAllMods(); std::vector getActiveMods(); const CModInfo & getModInfo(const TModID & modId) const; /// load content from all available mods void load(); void afterLoad(bool onlyEssential); CModHandler(); virtual ~CModHandler(); template void serialize(Handler &h, const int version) { if(h.saving) { h & activeMods; for(const auto & m : activeMods) h & getModInfo(m).getVerificationInfo(); } else { loadMods(); std::vector saveActiveMods; h & saveActiveMods; std::vector> saveModInfos(saveActiveMods.size()); for(int i = 0; i < saveActiveMods.size(); ++i) { saveModInfos[i].first = saveActiveMods[i]; h & saveModInfos[i].second; } trySetActiveMods(saveModInfos); } } }; VCMI_LIB_NAMESPACE_END