VCMI_Lib.h 3.6 KB

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