2013-12-31 02:09:58 +03:00
|
|
|
/*
|
2015-08-08 18:16:33 +02:00
|
|
|
* MapFormatJSON.h, part of VCMI engine
|
2013-12-31 02:09:58 +03:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2013-12-31 02:09:58 +03:00
|
|
|
class TriggeredEvent;
|
2015-08-11 20:20:13 +02:00
|
|
|
|
2013-12-31 02:09:58 +03:00
|
|
|
|
2015-08-07 21:33:44 +02:00
|
|
|
class DLL_LINKAGE CMapFormatJson
|
|
|
|
{
|
2015-08-11 20:20:13 +02:00
|
|
|
public:
|
2015-08-12 02:31:06 +02:00
|
|
|
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;
|
2015-08-07 21:33:44 +02:00
|
|
|
|
|
|
|
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.
|
2015-08-07 21:33:44 +02:00
|
|
|
* (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);
|
|
|
|
|
2015-08-07 21:33:44 +02:00
|
|
|
/**
|
|
|
|
* 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);
|
2015-08-07 21:33:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2015-08-12 02:31:06 +02:00
|
|
|
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
|
2013-12-31 02:09:58 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor.
|
|
|
|
*
|
|
|
|
* @param stream a stream containing the map data
|
|
|
|
*/
|
2015-08-12 02:31:06 +02:00
|
|
|
CMapLoaderJson(CInputOutputStream * stream);
|
2013-12-31 02:09:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the VCMI/Json map file.
|
|
|
|
*
|
|
|
|
* @return a unique ptr of the loaded map class
|
|
|
|
*/
|
2015-10-12 15:47:10 +02:00
|
|
|
std::unique_ptr<CMap> loadMap() override;
|
2013-12-31 02:09:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the VCMI/Json map header.
|
|
|
|
*
|
|
|
|
* @return a unique ptr of the loaded map header class
|
|
|
|
*/
|
2015-10-12 15:47:10 +02:00
|
|
|
std::unique_ptr<CMapHeader> loadMapHeader() override;
|
2013-12-31 02:09:58 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Reads complete map.
|
|
|
|
*/
|
|
|
|
void readMap();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the map header.
|
|
|
|
*/
|
|
|
|
void readHeader();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads player information.
|
|
|
|
*/
|
|
|
|
void readPlayerInfo();
|
2015-08-12 02:31:06 +02:00
|
|
|
|
|
|
|
CZipLoader loader;
|
2013-12-31 02:09:58 +03:00
|
|
|
};
|
2015-08-08 16:30:19 +02:00
|
|
|
|
2015-08-12 02:31:06 +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-12 02:31:06 +02:00
|
|
|
|
2015-08-11 20:20:13 +02:00
|
|
|
CZipSaver saver;
|
2015-08-08 16:30:19 +02:00
|
|
|
};
|