VCMI_Lib.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. class CConsoleHandler;
  13. class CArtHandler;
  14. class CHeroHandler;
  15. class CCreatureHandler;
  16. class CSpellHandler;
  17. class CSkillHandler;
  18. class CBuildingHandler;
  19. class CObjectHandler;
  20. class CObjectClassesHandler;
  21. class CTownHandler;
  22. class CGeneralTextHandler;
  23. class CModHandler;
  24. class CContentHandler;
  25. class BattleFieldHandler;
  26. class IBonusTypeHandler;
  27. class CBonusTypeHandler;
  28. class TerrainTypeHandler;
  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. TerrainTypeHandler * terrainTypeHandler;
  76. CTerrainViewPatternConfig * terviewh;
  77. CRmgTemplateStorage * tplh;
  78. BattleFieldHandler * battlefieldsHandler;
  79. ObstacleHandler * obstacleHandler;
  80. #if SCRIPTING_ENABLED
  81. scripting::ScriptHandler * scriptHandler;
  82. #endif
  83. LibClasses(); //c-tor, loads .lods and NULLs handlers
  84. ~LibClasses();
  85. void init(bool onlyEssential); //uses standard config file
  86. void clear(); //deletes all handlers and its data
  87. void loadFilesystem(bool onlyEssential);// basic initialization. should be called before init()
  88. #if SCRIPTING_ENABLED
  89. void scriptsLoaded();
  90. #endif
  91. template <typename Handler> void serialize(Handler &h, const int version)
  92. {
  93. #if SCRIPTING_ENABLED
  94. h & scriptHandler;//must be first (or second after modh), it can modify factories other handlers depends on
  95. if(!h.saving)
  96. {
  97. scriptsLoaded();
  98. }
  99. #endif
  100. h & heroh;
  101. h & arth;
  102. h & creh;
  103. h & townh;
  104. h & objh;
  105. h & objtypeh;
  106. h & spellh;
  107. h & skillh;
  108. h & battlefieldsHandler;
  109. h & obstacleHandler;
  110. h & terrainTypeHandler;
  111. if(!h.saving)
  112. {
  113. //modh will be changed and modh->content will be empty after deserialization
  114. auto content = getContent();
  115. h & modh;
  116. setContent(content);
  117. }
  118. else
  119. h & modh;
  120. h & IS_AI_ENABLED;
  121. h & bth;
  122. if(!h.saving)
  123. {
  124. callWhenDeserializing();
  125. }
  126. }
  127. };
  128. extern DLL_LINKAGE LibClasses * VLC;
  129. DLL_LINKAGE void preinitDLL(CConsoleHandler * Console, bool onlyEssential = false);
  130. DLL_LINKAGE void loadDLLClasses(bool onlyEssential = false);