VCMI_Lib.h 3.8 KB

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