| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 | 
							- /*
 
-  * 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"
 
- #include "../filesystem/CZipSaver.h"
 
- #include "../filesystem/CZipLoader.h"
 
- #include "../GameConstants.h"
 
- class TriggeredEvent;
 
- struct TerrainTile;
 
- struct PlayerInfo;
 
- class CGObjectInstance;
 
- class AObjectTypeHandler;
 
- class JsonSerializeFormat;
 
- class JsonDeserializer;
 
- class JsonSerializer;
 
- class DLL_LINKAGE CMapFormatJson
 
- {
 
- public:
 
- 	static const int VERSION_MAJOR;
 
- 	static const int VERSION_MINOR;
 
- 	static const std::string HEADER_FILE_NAME;
 
- 	static const std::string OBJECTS_FILE_NAME;
 
- 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.
 
- 	 * (when loading map and mapHeader point to the same object)
 
- 	 */
 
- 	CMapHeader * mapHeader;
 
- 	void serializeAllowedFactions(JsonSerializeFormat & handler, std::set<TFaction> & value);
 
- 	///common part of header saving/loading
 
- 	void serializeHeader(JsonSerializeFormat & handler);
 
- 	///player information saving/loading
 
- 	void serializePlayerInfo(JsonSerializeFormat & handler);
 
- 	/**
 
- 	 * Reads team settings to header
 
- 	 */
 
- 	void readTeams(JsonDeserializer & handler);
 
- 	/**
 
- 	 * Saves team settings to header
 
- 	 */
 
- 	void writeTeams(JsonSerializer & handler);
 
- 	///common part triggered events of saving/loading
 
- 	void serializeTriggeredEvents(JsonSerializeFormat & handler);
 
- 	/**
 
- 	 * Reads triggered events, including victory/loss conditions
 
- 	 */
 
- 	void readTriggeredEvents(JsonDeserializer & handler);
 
- 	/**
 
- 	 * Writes triggered events, including victory/loss conditions
 
- 	 */
 
- 	void writeTriggeredEvents(JsonSerializer & handler);
 
- 	/**
 
- 	 * Reads one of triggered events
 
- 	 */
 
- 	void readTriggeredEvent(TriggeredEvent & event, const JsonNode & source);
 
- 	/**
 
- 	 * Writes one of triggered events
 
- 	 */
 
- 	void writeTriggeredEvent(const TriggeredEvent & event, JsonNode & dest);
 
- 	///common part of map attributes saving/loading
 
- 	void serializeOptions(JsonSerializeFormat & handler);
 
- 	/**
 
- 	 * Loads map attributes except header ones
 
- 	 */
 
- 	void readOptions(JsonDeserializer & handler);
 
- 	/**
 
- 	 * Saves map attributes except header ones
 
- 	 */
 
- 	void writeOptions(JsonSerializer & handler);
 
- };
 
- 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();
 
- 	JsonNode input;
 
- };
 
- class DLL_LINKAGE CMapLoaderJson : public CMapFormatJson, public IMapLoader
 
- {
 
- public:
 
- 	/**
 
- 	 * Constructor.
 
- 	 *
 
- 	 * @param stream a stream containing the map data
 
- 	 */
 
- 	CMapLoaderJson(CInputStream * 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:
 
- 	struct MapObjectLoader
 
- 	{
 
- 		MapObjectLoader(CMapLoaderJson * _owner, JsonMap::value_type & json);
 
- 		CMapLoaderJson * owner;
 
- 		CGObjectInstance * instance;
 
- 		ObjectInstanceID id;
 
- 		std::string jsonKey;//full id defined by map creator
 
- 		JsonNode & configuration;
 
- 		si32 internalId;//unique part of id defined by map creator (also = quest identifier)
 
- 		///constructs object (without configuration)
 
- 		void construct();
 
- 		///configures object
 
- 		void configure();
 
- 	};
 
- 	si32 getIdentifier(const std::string & type, const std::string & name);
 
- 	/**
 
- 	 * Reads the map header.
 
- 	 */
 
- 	void readHeader(const bool complete);
 
- 	/**
 
- 	 * Reads complete map.
 
- 	 */
 
- 	void readMap();
 
- 	void readTerrainTile(const std::string & src, TerrainTile & tile);
 
- 	void readTerrainLevel(const JsonNode & src, const int index);
 
- 	void readTerrain();
 
- 	/**
 
- 	 * Loads all map objects from zip archive
 
- 	 */
 
- 	void readObjects();
 
- 	JsonNode getFromArchive(const std::string & archiveFilename);
 
- 	CInputStream * buffer;
 
- 	std::shared_ptr<CIOApi> ioApi;
 
- 	CZipLoader loader;///< object to handle zip archive operations
 
- };
 
- class DLL_LINKAGE CMapSaverJson : public CMapFormatJson, public IMapSaver
 
- {
 
- public:
 
- 	/**
 
- 	 * Constructor.
 
- 	 *
 
- 	 * @param stream a stream to save the map to, will contain zip archive
 
- 	 */
 
- 	CMapSaverJson(CInputOutputStream * stream);
 
- 	~CMapSaverJson();
 
- 	/**
 
- 	 * Actually saves the VCMI/Json map into stream.
 
- 	 */
 
- 	void saveMap(const std::unique_ptr<CMap> & map) override;
 
- private:
 
- 	/**
 
- 	 * Saves @data as json file with specified @filename
 
- 	 */
 
- 	void addToArchive(const JsonNode & data, const std::string & filename);
 
- 	/**
 
- 	 * Saves header to zip archive
 
- 	 */
 
- 	void writeHeader();
 
- 	/**
 
- 	 * Encodes one tile into string
 
- 	 * @param tile tile to serialize
 
- 	 */
 
- 	const std::string writeTerrainTile(const TerrainTile & tile);
 
- 	/**
 
- 	 * Saves map level into json
 
- 	 * @param index z coordinate
 
- 	 */
 
- 	JsonNode writeTerrainLevel(const int index);
 
- 	/**
 
- 	 * Saves all terrain into zip archive
 
- 	 */
 
- 	void writeTerrain();
 
- 	/**
 
- 	 * Saves all map objects into zip archive
 
- 	 */
 
- 	void writeObjects();
 
- 	CInputOutputStream * buffer;
 
- 	std::shared_ptr<CIOApi> ioApi;
 
- 	CZipSaver saver;///< object to handle zip archive operations
 
- };
 
 
  |