1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-19 00:17:56 +02:00
Files
.github
AI
CI
Mods
android
client
cmake_modules
config
debian
docs
include
ios
launcher
lib
battle
bonuses
campaign
events
filesystem
gameState
logging
mapObjectConstructors
mapObjects
mapping
CDrawRoadsOperation.cpp
CDrawRoadsOperation.h
CMap.cpp
CMap.h
CMapDefines.h
CMapEditManager.cpp
CMapEditManager.h
CMapHeader.cpp
CMapHeader.h
CMapInfo.cpp
CMapInfo.h
CMapOperation.cpp
CMapOperation.h
CMapService.cpp
CMapService.h
MapEditUtils.cpp
MapEditUtils.h
MapFeaturesH3M.cpp
MapFeaturesH3M.h
MapFormat.h
MapFormatH3M.cpp
MapFormatH3M.h
MapFormatJson.cpp
MapFormatJson.h
MapIdentifiersH3M.cpp
MapIdentifiersH3M.h
MapReaderH3M.cpp
MapReaderH3M.h
ObstacleProxy.cpp
ObstacleProxy.h
minizip
pathfinder
registerTypes
rewardable
rmg
serializer
spells
vstd
AI_Base.h
ArtifactUtils.cpp
ArtifactUtils.h
BasicTypes.cpp
BattleFieldHandler.cpp
BattleFieldHandler.h
CAndroidVMHelper.cpp
CAndroidVMHelper.h
CArtHandler.cpp
CArtHandler.h
CArtifactInstance.cpp
CArtifactInstance.h
CBonusTypeHandler.cpp
CBonusTypeHandler.h
CBuildingHandler.cpp
CBuildingHandler.h
CConfigHandler.cpp
CConfigHandler.h
CConsoleHandler.cpp
CConsoleHandler.h
CCreatureHandler.cpp
CCreatureHandler.h
CCreatureSet.cpp
CCreatureSet.h
CGameInfoCallback.cpp
CGameInfoCallback.h
CGameInterface.cpp
CGameInterface.h
CGeneralTextHandler.cpp
CGeneralTextHandler.h
CHeroHandler.cpp
CHeroHandler.h
CMakeLists.txt
CModHandler.cpp
CModHandler.h
CModVersion.cpp
CModVersion.h
CPlayerState.cpp
CPlayerState.h
CRandomGenerator.cpp
CRandomGenerator.h
CScriptingModule.cpp
CScriptingModule.h
CSkillHandler.cpp
CSkillHandler.h
CSoundBase.h
CStack.cpp
CStack.h
CStopWatch.h
CThreadHelper.cpp
CThreadHelper.h
CTownHandler.cpp
CTownHandler.h
Color.h
CondSh.h
ConstTransitivePtr.h
FunctionList.h
GameConstants.cpp
GameConstants.h
GameSettings.cpp
GameSettings.h
IBonusTypeHandler.h
IGameCallback.cpp
IGameCallback.h
IGameEventsReceiver.h
IHandlerBase.cpp
IHandlerBase.h
Interprocess.h
JsonDetail.cpp
JsonDetail.h
JsonNode.cpp
JsonNode.h
JsonRandom.cpp
JsonRandom.h
Languages.h
LoadProgress.cpp
LoadProgress.h
LogicalExpression.cpp
LogicalExpression.h
MetaString.cpp
MetaString.h
NetPackVisitor.h
NetPacks.h
NetPacksBase.h
NetPacksLib.cpp
NetPacksLobby.h
ObstacleHandler.cpp
ObstacleHandler.h
Point.h
Rect.cpp
Rect.h
ResourceSet.cpp
ResourceSet.h
RiverHandler.cpp
RiverHandler.h
RoadHandler.cpp
RoadHandler.h
ScopeGuard.h
ScriptHandler.cpp
ScriptHandler.h
StartInfo.cpp
StartInfo.h
StdInc.cpp
StdInc.h
StringConstants.h
TerrainHandler.cpp
TerrainHandler.h
TextOperations.cpp
TextOperations.h
UnlockGuard.h
VCMIDirs.cpp
VCMIDirs.h
VCMI_Lib.cpp
VCMI_Lib.h
VCMI_lib.cbp
VCMI_lib.vcxproj
VCMI_lib.vcxproj.filters
int3.h
vcmi_endian.h
lib_server
mapeditor
osx
rpm
scripting
scripts
server
test
win
.gitignore
.gitmodules
.travis.yml
AUTHORS
CCallback.cpp
CCallback.h
CMakeLists.txt
CMakePresets.json
ChangeLog.md
Global.h
README.md
VCMI_VS15.sln
VCMI_global.props
VCMI_global_debug.props
VCMI_global_release.props
VCMI_global_user.props
Version.cpp.in
Version.h
conanfile.py
fuzzylite.pc.in
license.txt
vcmi.workspace
vcmibuilder
vcmimanual.tex
vcmi/lib/mapping/CMapService.h

184 lines
5.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 22:42:48 +03:00
class ResourceID;
class CMap;
class CMapHeader;
class CInputStream;
2023-05-24 01:14:06 +03:00
struct CModVersion;
2013-02-02 17:20:31 +00:00
class IMapLoader;
class IMapPatcher;
2013-02-02 17:20:31 +00:00
2023-05-24 01:14:06 +03:00
using ModCompatibilityInfo = std::map<std::string, CModVersion>;
2023-04-16 15:38:13 +04:00
/**
2023-04-25 12:02:31 +03:00
* The map service provides loading of VCMI/H3 map files. It can
* be extended to save maps later as well.
*/
2023-04-25 12:02:31 +03:00
class DLL_LINKAGE IMapService
{
public:
2023-04-25 12:02:31 +03:00
IMapService() = default;
virtual ~IMapService() = 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-25 12:02:31 +03:00
virtual std::unique_ptr<CMap> loadMap(const ResourceID & name) const = 0;
/**
* 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-25 12:02:31 +03:00
virtual std::unique_ptr<CMapHeader> loadMapHeader(const ResourceID & name) const = 0;
/**
* 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 12:02:31 +03:00
@@ -60,8 +60,8 @@ class DLL_LINKAGE CMapService
* @param name indicates name of file that will be used during map header patching
* @return a unique ptr to the loaded map class
*/
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 12:02: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 12:02:31 +03:00
@@ -74,7 +74,27 @@ class DLL_LINKAGE CMapService
* @param name indicates name of file that will be used during map header patching
* @return a unique ptr to the loaded map class
*/
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 12:02:31 +03: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;
std::unique_ptr<CMap> loadMap(const ResourceID & name) const override;
std::unique_ptr<CMapHeader> loadMapHeader(const ResourceID & name) const override;
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 12:02:31 +03:00
void saveMap(const std::unique_ptr<CMap> & map, boost::filesystem::path fullPath) const override;
2023-04-16 14:00:01 +04:00
2023-04-16 15:38:13 +04: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 12:02:31 +03:00
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 22:42:48 +03: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 uint8_t * 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 17:04:30 +03: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 17:04:30 +03:00
virtual ~IMapPatcher(){}
};
2015-08-08 17:30:19 +03:00
/**
* Interface for saving a map.
*/
class DLL_LINKAGE IMapSaver
{
public:
/**
* Saves the VCMI/H3 map file.
*
*/
2015-08-08 17:30:19 +03:00
virtual void saveMap(const std::unique_ptr<CMap> & map) = 0;
2016-11-25 17:04:30 +03:00
virtual ~IMapSaver(){}
2015-08-08 17:30:19 +03:00
};
VCMI_LIB_NAMESPACE_END