2012-11-03 16:30:47 +03:00
|
|
|
/*
|
|
|
|
* CMapService.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
class ResourcePath;
|
2017-06-04 21:42:48 +02:00
|
|
|
|
2012-11-03 16:30:47 +03:00
|
|
|
class CMap;
|
|
|
|
class CMapHeader;
|
|
|
|
class CInputStream;
|
2023-05-24 00:14:06 +02:00
|
|
|
struct CModVersion;
|
2013-02-02 20:20:31 +03:00
|
|
|
|
2013-02-04 13:29:59 +03:00
|
|
|
class IMapLoader;
|
2013-12-31 02:09:58 +03:00
|
|
|
class IMapPatcher;
|
2013-02-02 20:20:31 +03:00
|
|
|
|
2023-05-24 00:14:06 +02:00
|
|
|
using ModCompatibilityInfo = std::map<std::string, CModVersion>;
|
2023-04-16 13:38:13 +02:00
|
|
|
|
2012-11-03 16:30:47 +03:00
|
|
|
/**
|
2023-04-25 11:02:31 +02:00
|
|
|
* The map service provides loading of VCMI/H3 map files. It can
|
|
|
|
* be extended to save maps later as well.
|
2012-11-03 16:30:47 +03:00
|
|
|
*/
|
2023-04-25 11:02:31 +02:00
|
|
|
class DLL_LINKAGE IMapService
|
2012-11-03 16:30:47 +03:00
|
|
|
{
|
|
|
|
public:
|
2023-04-25 11:02:31 +02:00
|
|
|
IMapService() = default;
|
|
|
|
virtual ~IMapService() = default;
|
2012-11-11 15:23:31 +03:00
|
|
|
/**
|
|
|
|
* Loads the VCMI/H3 map file specified by the name.
|
|
|
|
*
|
|
|
|
* @param name the name of the map
|
|
|
|
* @return a unique ptr to the loaded map class
|
|
|
|
*/
|
2023-08-23 14:07:50 +02:00
|
|
|
virtual std::unique_ptr<CMap> loadMap(const ResourcePath & name) const = 0;
|
2023-04-25 11:02:31 +02:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
/**
|
|
|
|
* Loads the VCMI/H3 map header specified by the name.
|
|
|
|
*
|
|
|
|
* @param name the name of the map
|
|
|
|
* @return a unique ptr to the loaded map header class
|
|
|
|
*/
|
2023-08-23 14:07:50 +02:00
|
|
|
virtual std::unique_ptr<CMapHeader> loadMapHeader(const ResourcePath & name) const = 0;
|
2023-04-25 11:02:31 +02:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
/**
|
|
|
|
* Loads the VCMI/H3 map file from a buffer. This method is temporarily
|
|
|
|
* in use to ease the transition to use the new map service.
|
2023-04-25 11:02:31 +02:00
|
|
|
@@ -60,8 +60,8 @@ class DLL_LINKAGE CMapService
|
2013-12-31 02:09:58 +03:00
|
|
|
* @param name indicates name of file that will be used during map header patching
|
2012-11-11 15:23:31 +03:00
|
|
|
* @return a unique ptr to the loaded map class
|
|
|
|
*/
|
2023-06-27 15:27:35 +02:00
|
|
|
virtual std::unique_ptr<CMap> loadMap(const uint8_t * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const = 0;
|
2023-04-25 11:02:31 +02:00
|
|
|
|
2012-11-11 15:23:31 +03:00
|
|
|
/**
|
|
|
|
* Loads the VCMI/H3 map header from a buffer. This method is temporarily
|
|
|
|
* in use to ease the transition to use the new map service.
|
2023-04-25 11:02:31 +02:00
|
|
|
@@ -74,7 +74,27 @@ class DLL_LINKAGE CMapService
|
2013-12-31 02:09:58 +03:00
|
|
|
* @param name indicates name of file that will be used during map header patching
|
2012-11-11 15:23:31 +03:00
|
|
|
* @return a unique ptr to the loaded map class
|
|
|
|
*/
|
2023-06-27 15:27:35 +02:00
|
|
|
virtual std::unique_ptr<CMapHeader> loadMapHeader(const uint8_t * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const = 0;
|
2023-04-25 11:02:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves map into VCMI format with name specified
|
|
|
|
* @param map to save
|
|
|
|
* @param fullPath full path to file to write, including extension
|
|
|
|
*/
|
|
|
|
virtual void saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::path fullPath) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_LINKAGE CMapService : public IMapService
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CMapService() = default;
|
|
|
|
virtual ~CMapService() = default;
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
std::unique_ptr<CMap> loadMap(const ResourcePath & name) const override;
|
|
|
|
std::unique_ptr<CMapHeader> loadMapHeader(const ResourcePath & name) const override;
|
2023-06-27 15:27:35 +02:00
|
|
|
std::unique_ptr<CMap> loadMap(const uint8_t * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const override;
|
|
|
|
std::unique_ptr<CMapHeader> loadMapHeader(const uint8_t * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const override;
|
2023-04-25 11:02:31 +02:00
|
|
|
void saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::path fullPath) const override;
|
2023-04-16 12:00:01 +02:00
|
|
|
|
2023-04-16 13:38:13 +02:00
|
|
|
/**
|
|
|
|
* Tests if mods used in the map are currently loaded
|
|
|
|
* @param map const reference to map header
|
|
|
|
* @return data structure representing missing or incompatible mods (those which are needed from map but not loaded)
|
|
|
|
*/
|
|
|
|
static ModCompatibilityInfo verifyMapHeaderMods(const CMapHeader & map);
|
2023-04-25 11:02:31 +02:00
|
|
|
|
2012-11-03 16:30:47 +03:00
|
|
|
private:
|
2012-11-11 15:23:31 +03:00
|
|
|
/**
|
|
|
|
* Gets a map input stream object specified by a map name.
|
|
|
|
*
|
|
|
|
* @param name the name of the map
|
|
|
|
* @return a unique ptr to the input stream class
|
|
|
|
*/
|
2023-08-23 14:07:50 +02:00
|
|
|
static std::unique_ptr<CInputStream> getStreamFromFS(const ResourcePath & name);
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a map input stream from a buffer.
|
|
|
|
*
|
|
|
|
* @param buffer a pointer to a buffer containing the map data
|
|
|
|
* @param size the size of the buffer
|
|
|
|
* @return a unique ptr to the input stream class
|
|
|
|
*/
|
2023-06-27 15:27:35 +02:00
|
|
|
static std::unique_ptr<CInputStream> getStreamFromMem(const uint8_t * buffer, int size);
|
2012-11-11 15:23:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a map loader from the given stream. It performs checks to test
|
|
|
|
* in which map format the map is.
|
|
|
|
*
|
|
|
|
* @param stream the input map stream
|
|
|
|
* @return the constructed map loader
|
|
|
|
*/
|
2023-02-25 17:44:15 +02:00
|
|
|
static std::unique_ptr<IMapLoader> getMapLoader(std::unique_ptr<CInputStream> & stream, std::string mapName, std::string modName, std::string encoding);
|
2013-12-31 02:09:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a map patcher for specified scenario
|
|
|
|
*
|
|
|
|
* @param scenarioName for patcher
|
|
|
|
* @return the constructed map patcher
|
|
|
|
*/
|
|
|
|
static std::unique_ptr<IMapPatcher> getMapPatcher(std::string scenarioName);
|
2012-11-03 16:30:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for loading a map.
|
|
|
|
*/
|
|
|
|
class DLL_LINKAGE IMapLoader
|
|
|
|
{
|
|
|
|
public:
|
2012-11-11 15:23:31 +03:00
|
|
|
/**
|
|
|
|
* Loads the VCMI/H3 map file.
|
|
|
|
*
|
|
|
|
* @return a unique ptr of the loaded map class
|
|
|
|
*/
|
|
|
|
virtual std::unique_ptr<CMap> loadMap() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the VCMI/H3 map header.
|
|
|
|
*
|
|
|
|
* @return a unique ptr of the loaded map header class
|
|
|
|
*/
|
|
|
|
virtual std::unique_ptr<CMapHeader> loadMapHeader() = 0;
|
2016-11-25 16:04:30 +02:00
|
|
|
|
|
|
|
virtual ~IMapLoader(){}
|
2012-11-03 16:30:47 +03:00
|
|
|
};
|
|
|
|
|
2015-08-07 21:33:44 +02:00
|
|
|
class DLL_LINKAGE IMapPatcher
|
2013-12-31 02:09:58 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Modifies supplied map header using Json data
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
virtual void patchMapHeader(std::unique_ptr<CMapHeader> & header) = 0;
|
2016-11-25 16:04:30 +02:00
|
|
|
|
|
|
|
virtual ~IMapPatcher(){}
|
2013-12-31 02:09:58 +03:00
|
|
|
};
|
2015-08-08 16:30:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface for saving a map.
|
|
|
|
*/
|
|
|
|
class DLL_LINKAGE IMapSaver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Saves the VCMI/H3 map file.
|
|
|
|
*
|
2015-11-13 03:01:14 +02:00
|
|
|
*/
|
2015-08-08 16:30:19 +02:00
|
|
|
virtual void saveMap(const std::unique_ptr<CMap> & map) = 0;
|
2016-11-25 16:04:30 +02:00
|
|
|
|
|
|
|
virtual ~IMapSaver(){}
|
2015-08-08 16:30:19 +02:00
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|