ModManager.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. public:
  36. ModsPresetState();
  37. /// Returns true if mod is active in current preset
  38. bool isModActive(const TModID & modName) const;
  39. void activateModInPreset(const TModID & modName);
  40. void dectivateModInAllPresets(const TModID & modName);
  41. /// Returns list of all mods active in current preset. Mod order is unspecified
  42. TModList getActiveMods() const;
  43. };
  44. /// Provides access to mod properties
  45. class ModsStorage : boost::noncopyable
  46. {
  47. std::map<TModID, ModDescription> mods;
  48. public:
  49. ModsStorage(const TModList & modsToLoad);
  50. const ModDescription & getMod(const TModID & fullID) const;
  51. };
  52. /// Provides public interface to access mod state
  53. class ModManager : boost::noncopyable
  54. {
  55. /// all currently active mods, in their load order
  56. TModList activeMods;
  57. /// Mods from current preset that failed to load due to invalid dependencies
  58. TModList brokenMods;
  59. std::unique_ptr<ModsState> modsState;
  60. std::unique_ptr<ModsPresetState> modsPreset;
  61. std::unique_ptr<ModsStorage> modsStorage;
  62. void generateLoadOrder(TModList desiredModList);
  63. public:
  64. ModManager();
  65. ~ModManager();
  66. const ModDescription & getModDescription(const TModID & modID) const;
  67. const TModList & getActiveMods() const;
  68. bool isModActive(const TModID & modID) const;
  69. };
  70. VCMI_LIB_NAMESPACE_END