CMapService.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * CMapService.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. class CMap;
  12. class CMapHeader;
  13. class CInputStream;
  14. class IMapLoader;
  15. class IMapPatcher;
  16. /**
  17. * The map service provides loading of VCMI/H3 map files. It can
  18. * be extended to save maps later as well.
  19. */
  20. class DLL_LINKAGE CMapService
  21. {
  22. public:
  23. /**
  24. * Loads the VCMI/H3 map file specified by the name.
  25. *
  26. * @param name the name of the map
  27. * @return a unique ptr to the loaded map class
  28. */
  29. static std::unique_ptr<CMap> loadMap(const std::string & name);
  30. /**
  31. * Loads the VCMI/H3 map header specified by the name.
  32. *
  33. * @param name the name of the map
  34. * @return a unique ptr to the loaded map header class
  35. */
  36. static std::unique_ptr<CMapHeader> loadMapHeader(const std::string & name);
  37. /**
  38. * Loads the VCMI/H3 map file from a buffer. This method is temporarily
  39. * in use to ease the transition to use the new map service.
  40. *
  41. * TODO Replace method params with a CampaignMapInfo struct which contains
  42. * a campaign loading object + name of map.
  43. *
  44. * @param buffer a pointer to a buffer containing the map data
  45. * @param size the size of the buffer
  46. * @param name indicates name of file that will be used during map header patching
  47. * @return a unique ptr to the loaded map class
  48. */
  49. static std::unique_ptr<CMap> loadMap(const ui8 * buffer, int size, const std::string & name);
  50. /**
  51. * Loads the VCMI/H3 map header from a buffer. This method is temporarily
  52. * in use to ease the transition to use the new map service.
  53. *
  54. * TODO Replace method params with a CampaignMapInfo struct which contains
  55. * a campaign loading object + name of map.
  56. *
  57. * @param buffer a pointer to a buffer containing the map header data
  58. * @param size the size of the buffer
  59. * @param name indicates name of file that will be used during map header patching
  60. * @return a unique ptr to the loaded map class
  61. */
  62. static std::unique_ptr<CMapHeader> loadMapHeader(const ui8 * buffer, int size, const std::string & name);
  63. static void saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::path fullPath);
  64. private:
  65. /**
  66. * Gets a map input stream object specified by a map name.
  67. *
  68. * @param name the name of the map
  69. * @return a unique ptr to the input stream class
  70. */
  71. static std::unique_ptr<CInputStream> getStreamFromFS(const std::string & name);
  72. /**
  73. * Gets a map input stream from a buffer.
  74. *
  75. * @param buffer a pointer to a buffer containing the map data
  76. * @param size the size of the buffer
  77. * @return a unique ptr to the input stream class
  78. */
  79. static std::unique_ptr<CInputStream> getStreamFromMem(const ui8 * buffer, int size);
  80. /**
  81. * Gets a map loader from the given stream. It performs checks to test
  82. * in which map format the map is.
  83. *
  84. * @param stream the input map stream
  85. * @return the constructed map loader
  86. */
  87. static std::unique_ptr<IMapLoader> getMapLoader(std::unique_ptr<CInputStream> & stream);
  88. /**
  89. * Gets a map patcher for specified scenario
  90. *
  91. * @param scenarioName for patcher
  92. * @return the constructed map patcher
  93. */
  94. static std::unique_ptr<IMapPatcher> getMapPatcher(std::string scenarioName);
  95. };
  96. /**
  97. * Interface for loading a map.
  98. */
  99. class DLL_LINKAGE IMapLoader
  100. {
  101. public:
  102. /**
  103. * Loads the VCMI/H3 map file.
  104. *
  105. * @return a unique ptr of the loaded map class
  106. */
  107. virtual std::unique_ptr<CMap> loadMap() = 0;
  108. /**
  109. * Loads the VCMI/H3 map header.
  110. *
  111. * @return a unique ptr of the loaded map header class
  112. */
  113. virtual std::unique_ptr<CMapHeader> loadMapHeader() = 0;
  114. virtual ~IMapLoader(){}
  115. };
  116. class DLL_LINKAGE IMapPatcher
  117. {
  118. public:
  119. /**
  120. * Modifies supplied map header using Json data
  121. *
  122. */
  123. virtual void patchMapHeader(std::unique_ptr<CMapHeader> & header) = 0;
  124. virtual ~IMapPatcher(){}
  125. };
  126. /**
  127. * Interface for saving a map.
  128. */
  129. class DLL_LINKAGE IMapSaver
  130. {
  131. public:
  132. /**
  133. * Saves the VCMI/H3 map file.
  134. *
  135. */
  136. virtual void saveMap(const std::unique_ptr<CMap> & map) = 0;
  137. virtual ~IMapSaver(){}
  138. };