CModInfo.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * CModInfo.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 "../JsonNode.h"
  12. #include "CModVersion.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. using TModID = std::string;
  15. class DLL_LINKAGE CModInfo
  16. {
  17. /// cached result of checkModGameplayAffecting() call
  18. /// Do not serialize - depends on local mod version, not server/save mod version
  19. mutable std::optional<bool> modGameplayAffecting;
  20. public:
  21. enum EValidationStatus
  22. {
  23. PENDING,
  24. FAILED,
  25. PASSED
  26. };
  27. /// identifier, identical to name of folder with mod
  28. std::string identifier;
  29. /// human-readable strings
  30. std::string name;
  31. std::string description;
  32. /// version of the mod
  33. CModVersion version;
  34. /// Base language of mod, all mod strings are assumed to be in this language
  35. std::string baseLanguage;
  36. /// vcmi versions compatible with the mod
  37. CModVersion vcmiCompatibleMin, vcmiCompatibleMax;
  38. /// list of mods that should be loaded before this one
  39. std::set <TModID> dependencies;
  40. /// list of mods that can't be used in the same time as this one
  41. std::set <TModID> conflicts;
  42. /// CRC-32 checksum of the mod
  43. ui32 checksum;
  44. EValidationStatus validation;
  45. JsonNode config;
  46. CModInfo();
  47. CModInfo(const std::string & identifier, const JsonNode & local, const JsonNode & config);
  48. JsonNode saveLocalData() const;
  49. void updateChecksum(ui32 newChecksum);
  50. bool isEnabled() const;
  51. void setEnabled(bool on);
  52. static std::string getModDir(const std::string & name);
  53. static JsonPath getModFile(const std::string & name);
  54. /// return true if this mod can affect gameplay, e.g. adds or modifies any game objects
  55. bool checkModGameplayAffecting() const;
  56. private:
  57. /// true if mod is enabled by user, e.g. in Launcher UI
  58. bool explicitlyEnabled;
  59. /// true if mod can be loaded - compatible and has no missing deps
  60. bool implicitlyEnabled;
  61. void loadLocalData(const JsonNode & data);
  62. };
  63. VCMI_LIB_NAMESPACE_END