1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00
vcmi/lib/mapping/MapFormatJson.h

163 lines
3.3 KiB
C
Raw Normal View History

/*
2015-08-08 18:16:33 +02:00
* MapFormatJSON.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
#include "CMapService.h"
#include "../JsonNode.h"
2015-08-11 20:20:13 +02:00
#include "../filesystem/CZipSaver.h"
#include "../filesystem/CZipLoader.h"
class TriggeredEvent;
2015-08-11 20:20:13 +02:00
class DLL_LINKAGE CMapFormatJson
{
2015-08-11 20:20:13 +02:00
public:
static const int VERSION_MAJOR;
static const int VERSION_MINOR;
2015-08-11 20:20:13 +02:00
static const std::string HEADER_FILE_NAME;
protected:
/** ptr to the map object which gets filled by data from the buffer or written to buffer */
CMap * map;
/**
2015-08-14 04:22:24 +02:00
* ptr to the map header object which gets filled by data from the buffer.
* (when loading map and mapHeader point to the same object)
*/
std::unique_ptr<CMapHeader> mapHeader;
/**
* Reads triggered events, including victory/loss conditions
*/
void readTriggeredEvents(const JsonNode & input);
2015-08-14 04:22:24 +02:00
/**
* Writes triggered events, including victory/loss conditions
*/
void writeTriggeredEvents(JsonNode & output);
/**
* Reads one of triggered events
*/
2015-08-14 04:22:24 +02:00
void readTriggeredEvent(TriggeredEvent & event, const JsonNode & source);
/**
* Writes one of triggered events
*/
void writeTriggeredEvent(const TriggeredEvent & event, JsonNode & dest);
};
class DLL_LINKAGE CMapPatcher : public CMapFormatJson, public IMapPatcher
{
public:
/**
* Default constructor.
*
* @param stream. A stream containing the map data.
*/
CMapPatcher(JsonNode stream);
public: //IMapPatcher
/**
* Modifies supplied map header using Json data
*
*/
void patchMapHeader(std::unique_ptr<CMapHeader> & header) override;
private:
/**
* Reads subset of header that can be replaced by patching.
*/
void readPatchData();
const JsonNode input;
};
class DLL_LINKAGE CMapFormatZip : public CMapFormatJson
{
public:
CMapFormatZip(CInputOutputStream * stream);
protected:
CInputOutputStream * buffer;
std::shared_ptr<CIOApi> ioApi;
};
class DLL_LINKAGE CMapLoaderJson : public CMapFormatZip, public IMapLoader
{
public:
/**
* Default constructor.
*
* @param stream a stream containing the map data
*/
CMapLoaderJson(CInputOutputStream * stream);
/**
* Loads the VCMI/Json map file.
*
* @return a unique ptr of the loaded map class
*/
std::unique_ptr<CMap> loadMap() override;
/**
* Loads the VCMI/Json map header.
*
* @return a unique ptr of the loaded map header class
*/
std::unique_ptr<CMapHeader> loadMapHeader() override;
private:
/**
* Reads complete map.
*/
void readMap();
/**
* Reads the map header.
*/
void readHeader();
/**
* Reads player information.
*/
void readPlayerInfo();
CZipLoader loader;
};
2015-08-08 16:30:19 +02:00
class DLL_LINKAGE CMapSaverJson : public CMapFormatZip, public IMapSaver
2015-08-08 16:30:19 +02:00
{
public:
2015-08-08 17:35:54 +02:00
/**
* Default constructor.
*
* @param stream a stream to save the map to
*/
2015-08-11 20:20:13 +02:00
CMapSaverJson(CInputOutputStream * stream);
~CMapSaverJson();
2015-08-08 17:35:54 +02:00
/**
* Actually saves the VCMI/Json map into stream.
*
*/
2015-08-08 16:30:19 +02:00
void saveMap(const std::unique_ptr<CMap> & map) override;
2015-08-08 17:35:54 +02:00
private:
2015-08-11 20:20:13 +02:00
void saveHeader();
2015-08-11 20:20:13 +02:00
CZipSaver saver;
2015-08-08 16:30:19 +02:00
};