CMapService.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. private:
  64. /**
  65. * Gets a map input stream object specified by a map name.
  66. *
  67. * @param name the name of the map
  68. * @return a unique ptr to the input stream class
  69. */
  70. static std::unique_ptr<CInputStream> getStreamFromFS(const std::string & name);
  71. /**
  72. * Gets a map input stream from a buffer.
  73. *
  74. * @param buffer a pointer to a buffer containing the map data
  75. * @param size the size of the buffer
  76. * @return a unique ptr to the input stream class
  77. */
  78. static std::unique_ptr<CInputStream> getStreamFromMem(const ui8 * buffer, int size);
  79. /**
  80. * Gets a map loader from the given stream. It performs checks to test
  81. * in which map format the map is.
  82. *
  83. * @param stream the input map stream
  84. * @return the constructed map loader
  85. */
  86. static std::unique_ptr<IMapLoader> getMapLoader(std::unique_ptr<CInputStream> & stream);
  87. /**
  88. * Gets a map patcher for specified scenario
  89. *
  90. * @param scenarioName for patcher
  91. * @return the constructed map patcher
  92. */
  93. static std::unique_ptr<IMapPatcher> getMapPatcher(std::string scenarioName);
  94. };
  95. /**
  96. * Interface for loading a map.
  97. */
  98. class DLL_LINKAGE IMapLoader
  99. {
  100. public:
  101. /**
  102. * Loads the VCMI/H3 map file.
  103. *
  104. * @return a unique ptr of the loaded map class
  105. */
  106. virtual std::unique_ptr<CMap> loadMap() = 0;
  107. /**
  108. * Loads the VCMI/H3 map header.
  109. *
  110. * @return a unique ptr of the loaded map header class
  111. */
  112. virtual std::unique_ptr<CMapHeader> loadMapHeader() = 0;
  113. };
  114. class DLL_LINKAGE IMapPatcher
  115. {
  116. public:
  117. /**
  118. * Modifies supplied map header using Json data
  119. *
  120. */
  121. virtual void patchMapHeader(std::unique_ptr<CMapHeader> & header) = 0;
  122. };
  123. /**
  124. * Interface for saving a map.
  125. */
  126. class DLL_LINKAGE IMapSaver
  127. {
  128. public:
  129. /**
  130. * Saves the VCMI/H3 map file.
  131. *
  132. */
  133. virtual void saveMap(const std::unique_ptr<CMap> & map) = 0;
  134. };