MapFormatJson.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * MapFormatH3M.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 "CMapService.h"
  12. #include "../JsonNode.h"
  13. class TriggeredEvent;
  14. class CInputStream;
  15. class DLL_LINKAGE CMapFormatJson
  16. {
  17. protected:
  18. /** ptr to the map object which gets filled by data from the buffer or written to buffer */
  19. CMap * map;
  20. /**
  21. * ptr to the map header object which gets filled by data from the buffer or written to buffer.
  22. * (when loading map and mapHeader point to the same object)
  23. */
  24. std::unique_ptr<CMapHeader> mapHeader;
  25. /**
  26. * Reads triggered events, including victory/loss conditions
  27. */
  28. void readTriggeredEvents(const JsonNode & input);
  29. /**
  30. * Reads one of triggered events
  31. */
  32. void readTriggeredEvent(TriggeredEvent & event, const JsonNode & source);
  33. };
  34. class DLL_LINKAGE CMapPatcher : public CMapFormatJson, public IMapPatcher
  35. {
  36. public:
  37. /**
  38. * Default constructor.
  39. *
  40. * @param stream. A stream containing the map data.
  41. */
  42. CMapPatcher(JsonNode stream);
  43. public: //IMapPatcher
  44. /**
  45. * Modifies supplied map header using Json data
  46. *
  47. */
  48. void patchMapHeader(std::unique_ptr<CMapHeader> & header) override;
  49. private:
  50. /**
  51. * Reads subset of header that can be replaced by patching.
  52. */
  53. void readPatchData();
  54. const JsonNode input;
  55. };
  56. class DLL_LINKAGE CMapLoaderJson : public CMapFormatJson, public IMapLoader
  57. {
  58. public:
  59. /**
  60. * Default constructor.
  61. *
  62. * @param stream a stream containing the map data
  63. */
  64. CMapLoaderJson(CInputStream * stream);
  65. /**
  66. * Loads the VCMI/Json map file.
  67. *
  68. * @return a unique ptr of the loaded map class
  69. */
  70. std::unique_ptr<CMap> loadMap() override;
  71. /**
  72. * Loads the VCMI/Json map header.
  73. *
  74. * @return a unique ptr of the loaded map header class
  75. */
  76. std::unique_ptr<CMapHeader> loadMapHeader() override;
  77. private:
  78. /**
  79. * Reads complete map.
  80. */
  81. void readMap();
  82. /**
  83. * Reads the map header.
  84. */
  85. void readHeader();
  86. /**
  87. * Reads player information.
  88. */
  89. void readPlayerInfo();
  90. CInputStream * input;
  91. };
  92. class DLL_LINKAGE CMapSaverJson : public CMapFormatJson, public IMapSaver
  93. {
  94. public:
  95. void saveMap(const std::unique_ptr<CMap> & map) override;
  96. };