VCMI_Lib.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * VCMI_Lib.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 <vcmi/Services.h>
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class CConsoleHandler;
  14. class CArtHandler;
  15. class CHeroHandler;
  16. class CCreatureHandler;
  17. class CSpellHandler;
  18. class CSkillHandler;
  19. class CBuildingHandler;
  20. class CObjectHandler;
  21. class CObjectClassesHandler;
  22. class CTownHandler;
  23. class CGeneralTextHandler;
  24. class CModHandler;
  25. class CContentHandler;
  26. class BattleFieldHandler;
  27. class IBonusTypeHandler;
  28. class CBonusTypeHandler;
  29. class ObstacleHandler;
  30. class CTerrainViewPatternConfig;
  31. class CRmgTemplateStorage;
  32. class IHandlerBase;
  33. #if SCRIPTING_ENABLED
  34. namespace scripting
  35. {
  36. class ScriptHandler;
  37. }
  38. #endif
  39. /// Loads and constructs several handlers
  40. class DLL_LINKAGE LibClasses : public Services
  41. {
  42. CBonusTypeHandler * bth;
  43. void callWhenDeserializing(); //should be called only by serialize !!!
  44. void makeNull(); //sets all handler pointers to null
  45. std::shared_ptr<CContentHandler> getContent() const;
  46. void setContent(std::shared_ptr<CContentHandler> content);
  47. public:
  48. bool IS_AI_ENABLED; //unused?
  49. const ArtifactService * artifacts() const override;
  50. const CreatureService * creatures() const override;
  51. const FactionService * factions() const override;
  52. const HeroClassService * heroClasses() const override;
  53. const HeroTypeService * heroTypes() const override;
  54. #if SCRIPTING_ENABLED
  55. const scripting::Service * scripts() const override;
  56. #endif
  57. const spells::Service * spells() const override;
  58. const SkillService * skills() const override;
  59. const BattleFieldService * battlefields() const override;
  60. const ObstacleService * obstacles() const override;
  61. void updateEntity(Metatype metatype, int32_t index, const JsonNode & data) override;
  62. const spells::effects::Registry * spellEffects() const override;
  63. spells::effects::Registry * spellEffects() override;
  64. const IBonusTypeHandler * getBth() const; //deprecated
  65. CArtHandler * arth;
  66. CHeroHandler * heroh;
  67. CCreatureHandler * creh;
  68. CSpellHandler * spellh;
  69. CSkillHandler * skillh;
  70. CObjectHandler * objh;
  71. CObjectClassesHandler * objtypeh;
  72. CTownHandler * townh;
  73. CGeneralTextHandler * generaltexth;
  74. CModHandler * modh;
  75. CTerrainViewPatternConfig * terviewh;
  76. CRmgTemplateStorage * tplh;
  77. BattleFieldHandler * battlefieldsHandler;
  78. ObstacleHandler * obstacleHandler;
  79. #if SCRIPTING_ENABLED
  80. scripting::ScriptHandler * scriptHandler;
  81. #endif
  82. LibClasses(); //c-tor, loads .lods and NULLs handlers
  83. ~LibClasses();
  84. void init(bool onlyEssential); //uses standard config file
  85. void clear(); //deletes all handlers and its data
  86. void loadFilesystem(bool onlyEssential);// basic initialization. should be called before init()
  87. #if SCRIPTING_ENABLED
  88. void scriptsLoaded();
  89. #endif
  90. template <typename Handler> void serialize(Handler &h, const int version)
  91. {
  92. #if SCRIPTING_ENABLED
  93. h & scriptHandler;//must be first (or second after modh), it can modify factories other handlers depends on
  94. if(!h.saving)
  95. {
  96. scriptsLoaded();
  97. }
  98. #endif
  99. h & heroh;
  100. h & arth;
  101. h & creh;
  102. h & townh;
  103. h & objh;
  104. h & objtypeh;
  105. h & spellh;
  106. h & skillh;
  107. h & battlefieldsHandler;
  108. h & obstacleHandler;
  109. if(!h.saving)
  110. {
  111. //modh will be changed and modh->content will be empty after deserialization
  112. auto content = getContent();
  113. h & modh;
  114. setContent(content);
  115. }
  116. else
  117. h & modh;
  118. h & IS_AI_ENABLED;
  119. h & bth;
  120. if(!h.saving)
  121. {
  122. callWhenDeserializing();
  123. }
  124. }
  125. };
  126. extern DLL_LINKAGE LibClasses * VLC;
  127. DLL_LINKAGE void preinitDLL(CConsoleHandler * Console, bool onlyEssential = false);
  128. DLL_LINKAGE void loadDLLClasses(bool onlyEssential = false);
  129. VCMI_LIB_NAMESPACE_END