ModManager.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * ModManager.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. #include "../json/JsonNode.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class JsonNode;
  14. class ModDescription;
  15. struct CModVersion;
  16. using TModID = std::string;
  17. using TModList = std::vector<TModID>;
  18. using TModSet = std::set<TModID>;
  19. /// Provides interface to access list of locally installed mods
  20. class ModsState : boost::noncopyable
  21. {
  22. TModList modList;
  23. TModList scanModsDirectory(const std::string & modDir) const;
  24. public:
  25. ModsState();
  26. TModList getAllMods() const;
  27. };
  28. /// Provides interface to access or change current mod preset
  29. class ModsPresetState : boost::noncopyable
  30. {
  31. JsonNode modConfig;
  32. void saveConfiguration(const JsonNode & config);
  33. void createInitialPreset();
  34. void importInitialPreset();
  35. const JsonNode & getActivePresetConfig() const;
  36. public:
  37. ModsPresetState();
  38. void setSettingActiveInPreset(const TModID & modName, const TModID & settingName, bool isActive);
  39. void eraseModInAllPresets(const TModID & modName);
  40. void eraseModSettingInAllPresets(const TModID & modName, const TModID & settingName);
  41. /// Returns list of all mods active in current preset. Mod order is unspecified
  42. TModList getActiveMods() const;
  43. /// Returns list of currently active root mods (non-submod)
  44. TModList getActiveRootMods() const;
  45. /// Returns list of all known settings (submods) for a specified mod
  46. std::map<TModID, bool> getModSettings(const TModID & modID) const;
  47. };
  48. /// Provides access to mod properties
  49. class ModsStorage : boost::noncopyable
  50. {
  51. std::map<TModID, ModDescription> mods;
  52. public:
  53. ModsStorage(const TModList & modsToLoad, const JsonNode & repositoryList);
  54. const ModDescription & getMod(const TModID & fullID) const;
  55. TModList getAllMods() const;
  56. };
  57. /// Provides public interface to access mod state
  58. class DLL_LINKAGE ModManager : boost::noncopyable
  59. {
  60. /// all currently active mods, in their load order
  61. TModList activeMods;
  62. /// Mods from current preset that failed to load due to invalid dependencies
  63. TModList brokenMods;
  64. std::unique_ptr<ModsState> modsState;
  65. std::unique_ptr<ModsPresetState> modsPreset;
  66. std::unique_ptr<ModsStorage> modsStorage;
  67. void generateLoadOrder(TModList desiredModList);
  68. void eraseMissingModsFromPreset();
  69. void addNewModsToPreset();
  70. public:
  71. ModManager(const JsonNode & repositoryList);
  72. ModManager();
  73. ~ModManager();
  74. const ModDescription & getModDescription(const TModID & modID) const;
  75. const TModList & getActiveMods() const;
  76. TModList getAllMods() const;
  77. bool isModActive(const TModID & modID) const;
  78. };
  79. VCMI_LIB_NAMESPACE_END