2
0

ModManager.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 getInstalledMods() const;
  27. double getInstalledModSizeMegabytes(const TModID & modName) const;
  28. uint32_t computeChecksum(const TModID & modName) const;
  29. };
  30. /// Provides interface to access or change current mod preset
  31. class ModsPresetState : boost::noncopyable
  32. {
  33. JsonNode modConfig;
  34. void createInitialPreset();
  35. void importInitialPreset();
  36. const JsonNode & getActivePresetConfig() const;
  37. public:
  38. ModsPresetState();
  39. void setSettingActiveInPreset(const TModID & modName, const TModID & settingName, bool isActive);
  40. void eraseModInAllPresets(const TModID & modName);
  41. void eraseModSettingInAllPresets(const TModID & modName, const TModID & settingName);
  42. /// Returns list of all mods active in current preset. Mod order is unspecified
  43. TModList getActiveMods() const;
  44. /// Returns list of currently active root mods (non-submod)
  45. TModList getActiveRootMods() const;
  46. /// Returns list of all known settings (submods) for a specified mod
  47. std::map<TModID, bool> getModSettings(const TModID & modID) const;
  48. std::optional<uint32_t> getValidatedChecksum(const TModID & modName) const;
  49. void setValidatedChecksum(const TModID & modName, std::optional<uint32_t> value);
  50. void saveConfigurationState() const;
  51. };
  52. /// Provides access to mod properties
  53. class ModsStorage : boost::noncopyable
  54. {
  55. std::map<TModID, ModDescription> mods;
  56. public:
  57. ModsStorage(const TModList & modsToLoad, const JsonNode & repositoryList);
  58. const ModDescription & getMod(const TModID & fullID) const;
  59. TModList getAllMods() const;
  60. };
  61. /// Provides public interface to access mod state
  62. class DLL_LINKAGE ModManager : boost::noncopyable
  63. {
  64. /// all currently active mods, in their load order
  65. TModList activeMods;
  66. /// Mods from current preset that failed to load due to invalid dependencies
  67. TModList brokenMods;
  68. std::unique_ptr<ModsState> modsState;
  69. std::unique_ptr<ModsPresetState> modsPreset;
  70. std::unique_ptr<ModsStorage> modsStorage;
  71. void generateLoadOrder(TModList desiredModList);
  72. void eraseMissingModsFromPreset();
  73. void addNewModsToPreset();
  74. public:
  75. ModManager(const JsonNode & repositoryList);
  76. ModManager();
  77. ~ModManager();
  78. const ModDescription & getModDescription(const TModID & modID) const;
  79. const TModList & getActiveMods() const;
  80. TModList getAllMods() const;
  81. bool isModActive(const TModID & modID) const;
  82. uint32_t computeChecksum(const TModID & modName) const;
  83. std::optional<uint32_t> getValidatedChecksum(const TModID & modName) const;
  84. void setValidatedChecksum(const TModID & modName, std::optional<uint32_t> value);
  85. void saveConfigurationState() const;
  86. double getInstalledModSizeMegabytes(const TModID & modName) const;
  87. };
  88. VCMI_LIB_NAMESPACE_END