1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/lib/mapping/CMapService.h

165 lines
4.3 KiB
C
Raw Normal View History

/*
* 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
VCMI_LIB_NAMESPACE_BEGIN
2017-06-04 21:42:48 +02:00
class ResourceID;
class CMap;
class CMapHeader;
class CInputStream;
2013-02-02 20:20:31 +03:00
class IMapLoader;
class IMapPatcher;
2013-02-02 20:20:31 +03:00
/**
2023-04-16 12:00:01 +02:00
* The map service provides loading and saving of VCMI/H3 map files.
*/
2023-04-16 12:00:01 +02:00
class DLL_LINKAGE CMapService
{
public:
2023-04-16 12:00:01 +02:00
CMapService() = default;
virtual ~CMapService() = default;
/**
* 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-04-16 12:00:01 +02:00
std::unique_ptr<CMap> loadMap(const ResourceID & name) const;
/**
* 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-04-16 12:00:01 +02:00
std::unique_ptr<CMapHeader> loadMapHeader(const ResourceID & name) const;
/**
* 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.
*
* TODO Replace method params with a CampaignMapInfo struct which contains
* a campaign loading object + name of map.
*
* @param buffer a pointer to a buffer containing the map data
* @param size the size of the buffer
* @param name indicates name of file that will be used during map header patching
* @return a unique ptr to the loaded map class
*/
2023-04-16 12:00:01 +02:00
std::unique_ptr<CMap> loadMap(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const;
/**
* 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.
*
* TODO Replace method params with a CampaignMapInfo struct which contains
* a campaign loading object + name of map.
*
* @param buffer a pointer to a buffer containing the map header data
* @param size the size of the buffer
* @param name indicates name of file that will be used during map header patching
* @return a unique ptr to the loaded map class
*/
2023-04-16 12:00:01 +02:00
std::unique_ptr<CMapHeader> loadMapHeader(const ui8 * buffer, int size, const std::string & name, const std::string & modName, const std::string & encoding) const;
void saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::path fullPath) const;
private:
/**
* 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
*/
2017-06-04 21:42:48 +02:00
static std::unique_ptr<CInputStream> getStreamFromFS(const ResourceID & name);
/**
* 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
*/
static std::unique_ptr<CInputStream> getStreamFromMem(const ui8 * buffer, int size);
/**
* 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);
/**
* 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);
};
/**
* Interface for loading a map.
*/
class DLL_LINKAGE IMapLoader
{
public:
/**
* 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(){}
};
class DLL_LINKAGE IMapPatcher
{
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(){}
};
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-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
};
VCMI_LIB_NAMESPACE_END