CModHandler.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * CModHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. class CModHandler;
  13. class CModIdentifier;
  14. class CModInfo;
  15. struct CModVersion;
  16. class JsonNode;
  17. class IHandlerBase;
  18. class CIdentifierStorage;
  19. class CContentHandler;
  20. struct ModVerificationInfo;
  21. class ResourcePath;
  22. class MetaString;
  23. using TModID = std::string;
  24. class DLL_LINKAGE CModHandler final : boost::noncopyable
  25. {
  26. std::map <TModID, CModInfo> allMods;
  27. std::vector <TModID> activeMods;//active mods, in order in which they were loaded
  28. std::unique_ptr<CModInfo> coreMod;
  29. mutable std::unique_ptr<MetaString> modLoadErrors;
  30. bool hasCircularDependency(const TModID & mod, std::set<TModID> currentList = std::set<TModID>()) const;
  31. /**
  32. * 1. Set apart mods with resolved dependencies from mods which have unresolved dependencies
  33. * 2. Sort resolved mods using topological algorithm
  34. * 3. Log all problem mods and their unresolved dependencies
  35. *
  36. * @param modsToResolve list of valid mod IDs (checkDependencies returned true - TODO: Clarify it.)
  37. * @return a vector of the topologically sorted resolved mods: child nodes (dependent mods) have greater index than parents
  38. */
  39. std::vector <TModID> validateAndSortDependencies(std::vector <TModID> modsToResolve) const;
  40. std::vector<std::string> getModList(const std::string & path) const;
  41. void loadMods(const std::string & path, const std::string & parent, const JsonNode & modSettings, bool enableMods);
  42. void loadOneMod(std::string modName, const std::string & parent, const JsonNode & modSettings, bool enableMods);
  43. void loadTranslation(const TModID & modName);
  44. CModVersion getModVersion(TModID modName) const;
  45. public:
  46. std::shared_ptr<CContentHandler> content; //(!)Do not serialize FIXME: make private
  47. /// receives list of available mods and trying to load mod.json from all of them
  48. void initializeConfig();
  49. void loadMods();
  50. void loadModFilesystems();
  51. /// returns ID of mod that provides selected file resource
  52. TModID findResourceOrigin(const ResourcePath & name) const;
  53. std::string getModLanguage(const TModID & modId) const;
  54. std::set<TModID> getModDependencies(const TModID & modId, bool & isModFound) const;
  55. /// returns list of all (active) mods
  56. std::vector<std::string> getAllMods() const;
  57. std::vector<std::string> getActiveMods() const;
  58. /// Returns human-readable string that describes errors encounter during mod loading, such as missing dependencies
  59. std::string getModLoadErrors() const;
  60. const CModInfo & getModInfo(const TModID & modId) const;
  61. /// load content from all available mods
  62. void load();
  63. void afterLoad(bool onlyEssential);
  64. CModHandler();
  65. ~CModHandler();
  66. };
  67. VCMI_LIB_NAMESPACE_END