MapFormatJson.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 DLL_LINKAGE CMapLoaderJson : public IMapPatcher
  15. {
  16. public:
  17. /**
  18. * Default constructor.
  19. *
  20. * @param stream a stream containing the map data
  21. */
  22. CMapLoaderJson(JsonNode stream);
  23. /**
  24. * Loads the VCMI/Json map file.
  25. *
  26. * @return a unique ptr of the loaded map class
  27. */
  28. std::unique_ptr<CMap> loadMap() override;
  29. /**
  30. * Loads the VCMI/Json map header.
  31. *
  32. * @return a unique ptr of the loaded map header class
  33. */
  34. std::unique_ptr<CMapHeader> loadMapHeader() override;
  35. /**
  36. * Modifies supplied map header using Json data
  37. *
  38. */
  39. void patchMapHeader(std::unique_ptr<CMapHeader> & header) override;
  40. private:
  41. /**
  42. * Reads complete map.
  43. */
  44. void readMap();
  45. /**
  46. * Reads the map header.
  47. */
  48. void readHeader();
  49. /**
  50. * Reads subset of header that can be replaced by patching.
  51. */
  52. void readPatchData();
  53. /**
  54. * Reads player information.
  55. */
  56. void readPlayerInfo();
  57. /**
  58. * Reads triggered events, including victory/loss conditions
  59. */
  60. void readTriggeredEvents();
  61. /**
  62. * Reads one of triggered events
  63. */
  64. void readTriggeredEvent(TriggeredEvent & event, const JsonNode & source);
  65. /** ptr to the map object which gets filled by data from the buffer */
  66. CMap * map;
  67. /**
  68. * ptr to the map header object which gets filled by data from the buffer.
  69. * (when loading map and mapHeader point to the same object)
  70. */
  71. std::unique_ptr<CMapHeader> mapHeader;
  72. const JsonNode input;
  73. };