VCMI_Lib.h 3.9 KB

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