CModInfo.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. struct VerificationInfo
  28. {
  29. /// human-readable mod name
  30. std::string name;
  31. /// version of the mod
  32. CModVersion version;
  33. /// CRC-32 checksum of the mod
  34. ui32 checksum = 0;
  35. /// parent mod ID, empty if root-level mod
  36. TModID parent;
  37. /// for serialization purposes
  38. bool impactsGameplay = true;
  39. template <typename Handler>
  40. void serialize(Handler & h, const int v)
  41. {
  42. h & name;
  43. h & version;
  44. h & checksum;
  45. h & parent;
  46. h & impactsGameplay;
  47. }
  48. };
  49. /// identifier, identical to name of folder with mod
  50. std::string identifier;
  51. /// detailed mod description
  52. std::string description;
  53. /// Base language of mod, all mod strings are assumed to be in this language
  54. std::string baseLanguage;
  55. /// vcmi versions compatible with the mod
  56. CModVersion vcmiCompatibleMin, vcmiCompatibleMax;
  57. /// list of mods that should be loaded before this one
  58. std::set <TModID> dependencies;
  59. /// list of mods that can't be used in the same time as this one
  60. std::set <TModID> conflicts;
  61. EValidationStatus validation;
  62. JsonNode config;
  63. CModInfo();
  64. CModInfo(const std::string & identifier, const JsonNode & local, const JsonNode & config);
  65. JsonNode saveLocalData() const;
  66. void updateChecksum(ui32 newChecksum);
  67. bool isEnabled() const;
  68. void setEnabled(bool on);
  69. static std::string getModDir(const std::string & name);
  70. static JsonPath getModFile(const std::string & name);
  71. /// return true if this mod can affect gameplay, e.g. adds or modifies any game objects
  72. bool checkModGameplayAffecting() const;
  73. const VerificationInfo & getVerificationInfo() const;
  74. private:
  75. /// true if mod is enabled by user, e.g. in Launcher UI
  76. bool explicitlyEnabled;
  77. /// true if mod can be loaded - compatible and has no missing deps
  78. bool implicitlyEnabled;
  79. VerificationInfo verificationInfo;
  80. void loadLocalData(const JsonNode & data);
  81. };
  82. VCMI_LIB_NAMESPACE_END