CModHandler.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 CModIndentifier;
  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. using TModID = std::string;
  23. class DLL_LINKAGE CModHandler final : boost::noncopyable
  24. {
  25. std::map <TModID, CModInfo> allMods;
  26. std::vector <TModID> activeMods;//active mods, in order in which they were loaded
  27. std::unique_ptr<CModInfo> coreMod;
  28. bool hasCircularDependency(const TModID & mod, std::set<TModID> currentList = std::set<TModID>()) const;
  29. /**
  30. * 1. Set apart mods with resolved dependencies from mods which have unresolved dependencies
  31. * 2. Sort resolved mods using topological algorithm
  32. * 3. Log all problem mods and their unresolved dependencies
  33. *
  34. * @param modsToResolve list of valid mod IDs (checkDependencies returned true - TODO: Clarify it.)
  35. * @return a vector of the topologically sorted resolved mods: child nodes (dependent mods) have greater index than parents
  36. */
  37. std::vector <TModID> validateAndSortDependencies(std::vector <TModID> modsToResolve) const;
  38. std::vector<std::string> getModList(const std::string & path) const;
  39. void loadMods(const std::string & path, const std::string & parent, const JsonNode & modSettings, bool enableMods);
  40. void loadOneMod(std::string modName, const std::string & parent, const JsonNode & modSettings, bool enableMods);
  41. void loadTranslation(const TModID & modName);
  42. bool validateTranslations(TModID modName) const;
  43. CModVersion getModVersion(TModID modName) const;
  44. public:
  45. std::shared_ptr<CContentHandler> content; //(!)Do not serialize FIXME: make private
  46. /// receives list of available mods and trying to load mod.json from all of them
  47. void initializeConfig();
  48. void loadMods(bool onlyEssential = false);
  49. void loadModFilesystems();
  50. /// returns ID of mod that provides selected file resource
  51. TModID findResourceOrigin(const ResourcePath & name);
  52. std::string getModLanguage(const TModID & modId) const;
  53. std::set<TModID> getModDependencies(const TModID & modId, bool & isModFound) const;
  54. /// returns list of all (active) mods
  55. std::vector<std::string> getAllMods();
  56. std::vector<std::string> getActiveMods();
  57. const CModInfo & getModInfo(const TModID & modId) const;
  58. /// load content from all available mods
  59. void load();
  60. void afterLoad(bool onlyEssential);
  61. CModHandler();
  62. ~CModHandler();
  63. };
  64. VCMI_LIB_NAMESPACE_END