CMapService.h 4.1 KB

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