2013-12-30 23:09:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* MapFormatH3M.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"
|
|
|
|
|
|
|
|
class TriggeredEvent;
|
2015-08-07 22:33:44 +03:00
|
|
|
class CInputStream;
|
2015-08-08 18:35:54 +03:00
|
|
|
class COutputStream;
|
2013-12-30 23:09:58 +00:00
|
|
|
|
2015-08-07 22:33:44 +03:00
|
|
|
class DLL_LINKAGE CMapFormatJson
|
|
|
|
{
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/** ptr to the map object which gets filled by data from the buffer or written to buffer */
|
|
|
|
CMap * map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ptr to the map header object which gets filled by data from the buffer or written to 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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads one of triggered events
|
|
|
|
*/
|
|
|
|
void readTriggeredEvent(TriggeredEvent & event, const JsonNode & source);
|
|
|
|
};
|
|
|
|
|
|
|
|
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-08 17:30:19 +03:00
|
|
|
class DLL_LINKAGE CMapLoaderJson : public CMapFormatJson, public IMapLoader
|
2013-12-30 23:09:58 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Default constructor.
|
|
|
|
*
|
|
|
|
* @param stream a stream containing the map data
|
|
|
|
*/
|
2015-08-07 22:33:44 +03:00
|
|
|
CMapLoaderJson(CInputStream * stream);
|
2013-12-30 23:09:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the VCMI/Json map file.
|
|
|
|
*
|
|
|
|
* @return a unique ptr of the loaded map class
|
|
|
|
*/
|
2015-10-12 16:47:10 +03:00
|
|
|
std::unique_ptr<CMap> loadMap() override;
|
2013-12-30 23:09:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the VCMI/Json map header.
|
|
|
|
*
|
|
|
|
* @return a unique ptr of the loaded map header class
|
|
|
|
*/
|
2015-10-12 16:47:10 +03:00
|
|
|
std::unique_ptr<CMapHeader> loadMapHeader() override;
|
2013-12-30 23:09:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Reads complete map.
|
|
|
|
*/
|
|
|
|
void readMap();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the map header.
|
|
|
|
*/
|
|
|
|
void readHeader();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads player information.
|
|
|
|
*/
|
|
|
|
void readPlayerInfo();
|
|
|
|
|
|
|
|
|
2015-08-07 22:33:44 +03:00
|
|
|
CInputStream * input;
|
2013-12-30 23:09:58 +00:00
|
|
|
};
|
2015-08-08 17:30:19 +03:00
|
|
|
|
|
|
|
class DLL_LINKAGE CMapSaverJson : public CMapFormatJson, public IMapSaver
|
|
|
|
{
|
|
|
|
public:
|
2015-08-08 18:35:54 +03:00
|
|
|
/**
|
|
|
|
* Default constructor.
|
|
|
|
*
|
|
|
|
* @param stream a stream to save the map to
|
|
|
|
*/
|
|
|
|
CMapSaverJson(COutputStream * stream);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actually saves the VCMI/Json map into stream.
|
|
|
|
*
|
|
|
|
*/
|
2015-08-08 17:30:19 +03:00
|
|
|
void saveMap(const std::unique_ptr<CMap> & map) override;
|
2015-08-08 18:35:54 +03:00
|
|
|
private:
|
|
|
|
COutputStream * output;
|
2015-08-08 17:30:19 +03:00
|
|
|
};
|