MapFormatJson.h 2.7 KB

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