VCMI_Lib.h 3.6 KB

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