mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Formatting
This commit is contained in:
		| @@ -17,95 +17,95 @@ | ||||
| #include "../CModHandler.h" | ||||
| #include "../VCMI_Lib.h" | ||||
|  | ||||
| namespace TriggeredEventsDetail{ | ||||
|  | ||||
| static const std::array<std::string, 12> conditionNames = { | ||||
| "haveArtifact", "haveCreatures",   "haveResources",   "haveBuilding", | ||||
| "control",      "destroy",         "transport",       "daysPassed", | ||||
| "isHuman",      "daysWithoutTown", "standardWin",     "constValue" | ||||
| }; | ||||
|  | ||||
| static const std::array<std::string, 2> typeNames = { "victory", "defeat" }; | ||||
|  | ||||
| static EventCondition JsonToCondition(const JsonNode & node) | ||||
| namespace TriggeredEventsDetail | ||||
| { | ||||
| 	EventCondition event; | ||||
| 	event.condition = EventCondition::EWinLoseType(vstd::find_pos(conditionNames, node.Vector()[0].String())); | ||||
| 	if (node.Vector().size() > 1) | ||||
| 	static const std::array<std::string, 12> conditionNames = | ||||
| 	{ | ||||
| 		const JsonNode & data = node.Vector()[1]; | ||||
| 		if (data["type"].getType() == JsonNode::DATA_STRING) | ||||
| 			event.objectType = VLC->modh->identifiers.getIdentifier(data["type"]).get(); | ||||
| 		if (data["type"].getType() == JsonNode::DATA_FLOAT) | ||||
| 			event.objectType = data["type"].Float(); | ||||
| 		"haveArtifact", "haveCreatures",   "haveResources",   "haveBuilding", | ||||
| 		"control",      "destroy",         "transport",       "daysPassed", | ||||
| 		"isHuman",      "daysWithoutTown", "standardWin",     "constValue" | ||||
| 	}; | ||||
|  | ||||
| 		if (!data["value"].isNull()) | ||||
| 			event.value = data["value"].Float(); | ||||
| 	static const std::array<std::string, 2> typeNames = { "victory", "defeat" }; | ||||
|  | ||||
| 		if (!data["position"].isNull()) | ||||
| 	static EventCondition JsonToCondition(const JsonNode & node) | ||||
| 	{ | ||||
| 		EventCondition event; | ||||
| 		event.condition = EventCondition::EWinLoseType(vstd::find_pos(conditionNames, node.Vector()[0].String())); | ||||
| 		if (node.Vector().size() > 1) | ||||
| 		{ | ||||
| 			auto & position = data["position"].Vector();			 | ||||
| 			event.position.x = position.at(0).Float(); | ||||
| 			event.position.y = position.at(1).Float(); | ||||
| 			event.position.z = position.at(2).Float(); | ||||
| 			const JsonNode & data = node.Vector()[1]; | ||||
| 			if (data["type"].getType() == JsonNode::DATA_STRING) | ||||
| 				event.objectType = VLC->modh->identifiers.getIdentifier(data["type"]).get(); | ||||
| 			if (data["type"].getType() == JsonNode::DATA_FLOAT) | ||||
| 				event.objectType = data["type"].Float(); | ||||
|  | ||||
| 			if (!data["value"].isNull()) | ||||
| 				event.value = data["value"].Float(); | ||||
|  | ||||
| 			if (!data["position"].isNull()) | ||||
| 			{ | ||||
| 				auto & position = data["position"].Vector(); | ||||
| 				event.position.x = position.at(0).Float(); | ||||
| 				event.position.y = position.at(1).Float(); | ||||
| 				event.position.z = position.at(2).Float(); | ||||
| 			} | ||||
| 		} | ||||
| 		return event; | ||||
| 	} | ||||
| 	return event; | ||||
| } | ||||
|  | ||||
| static JsonNode ConditionToJson(const EventCondition& event) | ||||
| { | ||||
| 	JsonNode json; | ||||
| 	 | ||||
| 	JsonVector& asVector = json.Vector(); | ||||
| 	 | ||||
| 	JsonNode condition; | ||||
| 	condition.String() = conditionNames.at(event.condition); | ||||
| 	asVector.push_back(condition); | ||||
| 	 | ||||
| 	JsonNode data; | ||||
| 	 | ||||
| 	//todo: save identifier | ||||
| 	 | ||||
| 	if(event.value != -1) | ||||
| 		data["value"].Float() = event.value; | ||||
| 	 | ||||
| 	if(event.position != int3(-1,-1,-1)) | ||||
| 	static JsonNode ConditionToJson(const EventCondition& event) | ||||
| 	{ | ||||
| 		auto & position = data["position"].Vector(); | ||||
| 		position.resize(3); | ||||
| 		position[0].Float() = event.position.x;  | ||||
| 		position[1].Float() = event.position.y;  | ||||
| 		position[2].Float() = event.position.z;	 | ||||
| 	}		 | ||||
| 	 | ||||
| 	asVector.push_back(data); | ||||
| 			 | ||||
| 	return std::move(json); | ||||
| } | ||||
| 		JsonNode json; | ||||
|  | ||||
| 		JsonVector& asVector = json.Vector(); | ||||
|  | ||||
| 		JsonNode condition; | ||||
| 		condition.String() = conditionNames.at(event.condition); | ||||
| 		asVector.push_back(condition); | ||||
|  | ||||
| 		JsonNode data; | ||||
|  | ||||
| 		//todo: save identifier | ||||
|  | ||||
| 		if(event.value != -1) | ||||
| 			data["value"].Float() = event.value; | ||||
|  | ||||
| 		if(event.position != int3(-1,-1,-1)) | ||||
| 		{ | ||||
| 			auto & position = data["position"].Vector(); | ||||
| 			position.resize(3); | ||||
| 			position[0].Float() = event.position.x; | ||||
| 			position[1].Float() = event.position.y; | ||||
| 			position[2].Float() = event.position.z; | ||||
| 		} | ||||
|  | ||||
| 		asVector.push_back(data); | ||||
|  | ||||
| 		return std::move(json); | ||||
| 	} | ||||
| }//namespace TriggeredEventsDetail | ||||
|  | ||||
| namespace TerrainDetail{ | ||||
| 	static const std::array<std::string, 10> terrainCodes =  | ||||
| namespace TerrainDetail | ||||
| { | ||||
| 	static const std::array<std::string, 10> terrainCodes = | ||||
| 	{ | ||||
| 		"dt", "sa", "gr", "sn", "sw", "rg", "sb", "lv", "wt", "rc" | ||||
| 	}; | ||||
| 	static const std::array<std::string, 4> roadCodes =  | ||||
| 	static const std::array<std::string, 4> roadCodes = | ||||
| 	{ | ||||
| 		"", "pd", "pg", "pc" | ||||
| 	}; | ||||
| 	 | ||||
| 	static const std::array<std::string, 5> riverCodes =  | ||||
|  | ||||
| 	static const std::array<std::string, 5> riverCodes = | ||||
| 	{ | ||||
| 		"", "rw", "ri", "rm", "rl" | ||||
| 	}; | ||||
| 	 | ||||
| 	static const std::array<char, 10> flipCodes =  | ||||
|  | ||||
| 	static const std::array<char, 10> flipCodes = | ||||
| 	{ | ||||
| 		'_', '-', '|', '+' | ||||
| 	};	 | ||||
|   | ||||
| 	}; | ||||
| } | ||||
|  | ||||
| ///CMapFormatJson | ||||
| @@ -120,8 +120,8 @@ void CMapFormatJson::readTriggeredEvents(const JsonNode & input) | ||||
| 	mapHeader->victoryIconIndex = input["victoryIconIndex"].Float(); | ||||
|  | ||||
| 	mapHeader->defeatMessage = input["defeatString"].String(); | ||||
| 	mapHeader->defeatIconIndex = input["defeatIconIndex"].Float();	 | ||||
| 	 | ||||
| 	mapHeader->defeatIconIndex = input["defeatIconIndex"].Float(); | ||||
|  | ||||
| 	mapHeader->triggeredEvents.clear(); | ||||
|  | ||||
| 	for (auto & entry : input["triggeredEvents"].Struct()) | ||||
| @@ -151,9 +151,9 @@ void CMapFormatJson::writeTriggeredEvents(JsonNode& output) | ||||
|  | ||||
| 	output["defeatString"].String() = map->defeatMessage; | ||||
| 	output["defeatIconIndex"].Float() = map->defeatIconIndex; | ||||
| 	 | ||||
|  | ||||
| 	JsonMap & triggeredEvents = output["triggeredEvents"].Struct(); | ||||
| 	 | ||||
|  | ||||
| 	for(auto event : map->triggeredEvents) | ||||
| 		writeTriggeredEvent(event, triggeredEvents[event.identifier]); | ||||
| } | ||||
| @@ -164,10 +164,10 @@ void CMapFormatJson::writeTriggeredEvent(const TriggeredEvent& event, JsonNode& | ||||
|  | ||||
| 	dest["message"].String() = event.onFulfill; | ||||
| 	dest["description"].String() = event.description; | ||||
| 	 | ||||
|  | ||||
| 	dest["effect"]["type"].String() = typeNames.at(size_t(event.effect.type)); | ||||
| 	dest["effect"]["messageToSend"].String() = event.effect.toOtherMessage; | ||||
| 	 | ||||
|  | ||||
| 	dest["condition"] = event.trigger.toJson(ConditionToJson); | ||||
| } | ||||
|  | ||||
| @@ -197,16 +197,16 @@ CMapFormatZip::CMapFormatZip(CInputOutputStream * stream): | ||||
| 	buffer(stream), | ||||
| 	ioApi(new CProxyIOApi(buffer)) | ||||
| { | ||||
| 	 | ||||
|  | ||||
| } | ||||
|  | ||||
|  | ||||
| ///CMapLoaderJson | ||||
| CMapLoaderJson::CMapLoaderJson(CInputOutputStream * stream): | ||||
| 	CMapFormatZip(stream), | ||||
| 	loader("", "_", ioApi)	 | ||||
| 	loader("", "_", ioApi) | ||||
| { | ||||
| 	 | ||||
|  | ||||
| } | ||||
|  | ||||
| std::unique_ptr<CMap> CMapLoaderJson::loadMap() | ||||
| @@ -227,14 +227,14 @@ std::unique_ptr<CMapHeader> CMapLoaderJson::loadMapHeader() | ||||
| const JsonNode CMapLoaderJson::readJson(const std::string & archiveFilename) | ||||
| { | ||||
| 	ResourceID resource(archiveFilename, EResType::TEXT); | ||||
| 	 | ||||
|  | ||||
| 	if(!loader.existsResource(resource)) | ||||
| 		throw new std::runtime_error(archiveFilename+" not found"); | ||||
| 	 | ||||
|  | ||||
| 	auto data = loader.load(resource)->readAll(); | ||||
| 	 | ||||
|  | ||||
| 	JsonNode res(reinterpret_cast<char*>(data.first.get()), data.second); | ||||
| 	 | ||||
|  | ||||
| 	return std::move(res); | ||||
| } | ||||
|  | ||||
| @@ -255,34 +255,34 @@ void CMapLoaderJson::readHeader() | ||||
| 	//TODO: read such data like map name & size | ||||
| 	//mapHeader->version = ??? //todo: new version field | ||||
|  | ||||
| 	//todo: multilevel map load support	 | ||||
| 	const JsonNode levels = header["mapLevels"];	 | ||||
| 	//todo: multilevel map load support | ||||
| 	const JsonNode levels = header["mapLevels"]; | ||||
| 	mapHeader->height = levels["surface"]["height"].Float(); | ||||
| 	mapHeader->width = levels["surface"]["width"].Float();	 | ||||
| 	mapHeader->width = levels["surface"]["width"].Float(); | ||||
| 	mapHeader->twoLevel = !levels["underground"].isNull(); | ||||
|  | ||||
| 	mapHeader->name = header["name"].String(); | ||||
| 	mapHeader->description = header["description"].String(); | ||||
| 	 | ||||
|  | ||||
| 	//todo: support arbitrary percentage | ||||
| 	 | ||||
|  | ||||
| 	static const std::map<std::string, ui8> difficultyMap = | ||||
| 	{ | ||||
| 		{"", 1}, | ||||
| 		{"EASY", 0}, | ||||
| 		{"NORMAL", 1},  | ||||
| 		{"HARD", 2},  | ||||
| 		{"NORMAL", 1}, | ||||
| 		{"HARD", 2}, | ||||
| 		{"EXPERT", 3}, | ||||
| 		{"IMPOSSIBLE", 4}		 | ||||
| 		{"IMPOSSIBLE", 4} | ||||
| 	}; | ||||
| 	 | ||||
| 	mapHeader->difficulty = difficultyMap.at(header["difficulty"].String());  | ||||
|  | ||||
| 	mapHeader->difficulty = difficultyMap.at(header["difficulty"].String()); | ||||
| 	mapHeader->levelLimit = header["levelLimit"].Float(); | ||||
| 	 | ||||
|  | ||||
|  | ||||
| //	std::vector<bool> allowedHeroes; | ||||
| //	std::vector<ui16> placeholdedHeroes;	 | ||||
| 	 | ||||
| //	std::vector<ui16> placeholdedHeroes; | ||||
|  | ||||
| 	readTriggeredEvents(header); | ||||
| 	readPlayerInfo(); | ||||
| 	//TODO: readHeader | ||||
| @@ -306,26 +306,26 @@ void CMapLoaderJson::readTerrainTile(const std::string& src, TerrainTile& tile) | ||||
| 			throw new std::runtime_error("Invalid terrain type code in "+src); | ||||
|  | ||||
| 		tile.terType = ETerrainType(rawType); | ||||
| 	}	 | ||||
| 	} | ||||
| 	int startPos = 2; //0+typeCode fixed length | ||||
| 	{//terrain view | ||||
| 		int pos = startPos;			 | ||||
| 		int pos = startPos; | ||||
| 		while(isdigit(src.at(pos))) | ||||
| 			pos++;		 | ||||
| 		int len = pos - startPos;		 | ||||
| 			pos++; | ||||
| 		int len = pos - startPos; | ||||
| 		if(len<=0) | ||||
| 			throw new std::runtime_error("Invalid terrain view in "+src);		 | ||||
| 		const std::string rawCode = src.substr(startPos,len);		 | ||||
| 		tile.terView = atoi(rawCode.c_str());		 | ||||
| 		startPos+=len;		 | ||||
| 			throw new std::runtime_error("Invalid terrain view in "+src); | ||||
| 		const std::string rawCode = src.substr(startPos,len); | ||||
| 		tile.terView = atoi(rawCode.c_str()); | ||||
| 		startPos+=len; | ||||
| 	} | ||||
| 	{//terrain flip | ||||
| 		int terrainFlip = vstd::find_pos(flipCodes, src.at(startPos++));		 | ||||
| 		int terrainFlip = vstd::find_pos(flipCodes, src.at(startPos++)); | ||||
| 		if(terrainFlip < 0) | ||||
| 			throw new std::runtime_error("Invalid terrain flip in "+src); | ||||
| 		else | ||||
| 			tile.extTileFlags = terrainFlip;		 | ||||
| 	}	 | ||||
| 			tile.extTileFlags = terrainFlip; | ||||
| 	} | ||||
| 	if(startPos >= src.size()) | ||||
| 		return; | ||||
| 	bool hasRoad = true; | ||||
| @@ -342,81 +342,81 @@ void CMapLoaderJson::readTerrainTile(const std::string& src, TerrainTile& tile) | ||||
| 			{ | ||||
| 				tile.riverType = ERiverType::ERiverType(rawType); | ||||
| 				hasRoad = false; | ||||
| 			}				 | ||||
| 		}			 | ||||
| 		else	 | ||||
| 			tile.roadType = ERoadType::ERoadType(rawType);			 | ||||
| 			} | ||||
| 		} | ||||
| 		else | ||||
| 			tile.roadType = ERoadType::ERoadType(rawType); | ||||
| 	} | ||||
| 	if(hasRoad) | ||||
| 	{//road dir | ||||
| 		int pos = startPos; | ||||
| 		while(isdigit(src.at(pos))) | ||||
| 			pos++;		 | ||||
| 		int len = pos - startPos;		 | ||||
| 			pos++; | ||||
| 		int len = pos - startPos; | ||||
| 		if(len<=0) | ||||
| 			throw new std::runtime_error("Invalid road dir in "+src);		 | ||||
| 		const std::string rawCode = src.substr(startPos,len);		 | ||||
| 		tile.roadDir = atoi(rawCode.c_str());		 | ||||
| 		startPos+=len;		 | ||||
| 			throw new std::runtime_error("Invalid road dir in "+src); | ||||
| 		const std::string rawCode = src.substr(startPos,len); | ||||
| 		tile.roadDir = atoi(rawCode.c_str()); | ||||
| 		startPos+=len; | ||||
| 	} | ||||
| 	if(hasRoad) | ||||
| 	{//road flip | ||||
| 		int flip = vstd::find_pos(flipCodes, src.at(startPos++));		 | ||||
| 		int flip = vstd::find_pos(flipCodes, src.at(startPos++)); | ||||
| 		if(flip < 0) | ||||
| 			throw new std::runtime_error("Invalid road flip in "+src); | ||||
| 		else | ||||
| 			tile.extTileFlags |= (flip<<4);		 | ||||
| 			tile.extTileFlags |= (flip<<4); | ||||
| 	} | ||||
| 	if(startPos >= src.size()) | ||||
| 		return;	 | ||||
| 		return; | ||||
| 	if(hasRoad) | ||||
| 	{//river type | ||||
| 		const std::string typeCode = src.substr(startPos,2); | ||||
| 		startPos+=2;		 | ||||
| 		startPos+=2; | ||||
| 		int rawType = vstd::find_pos(riverCodes, typeCode); | ||||
| 		if(rawType < 0) | ||||
| 			throw new std::runtime_error("Invalid river type in "+src); | ||||
| 		tile.riverType = ERiverType::ERiverType(rawType);					 | ||||
| 		tile.riverType = ERiverType::ERiverType(rawType); | ||||
| 	} | ||||
| 	{//river dir | ||||
| 		int pos = startPos; | ||||
| 		while(isdigit(src.at(pos))) | ||||
| 			pos++;		 | ||||
| 		int len = pos - startPos;		 | ||||
| 			pos++; | ||||
| 		int len = pos - startPos; | ||||
| 		if(len<=0) | ||||
| 			throw new std::runtime_error("Invalid river dir in "+src);		 | ||||
| 		const std::string rawCode = src.substr(startPos,len);		 | ||||
| 		tile.riverDir = atoi(rawCode.c_str());		 | ||||
| 		startPos+=len;		 | ||||
| 			throw new std::runtime_error("Invalid river dir in "+src); | ||||
| 		const std::string rawCode = src.substr(startPos,len); | ||||
| 		tile.riverDir = atoi(rawCode.c_str()); | ||||
| 		startPos+=len; | ||||
| 	} | ||||
| 	{//river flip | ||||
| 		int flip = vstd::find_pos(flipCodes, src.at(startPos++)); | ||||
| 		if(flip < 0) | ||||
| 			throw new std::runtime_error("Invalid road flip in "+src); | ||||
| 		else | ||||
| 			tile.extTileFlags |= (flip<<2);		 | ||||
| 	}	 | ||||
| 			tile.extTileFlags |= (flip<<2); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CMapLoaderJson::readTerrainLevel(const JsonNode& src, const int index) | ||||
| { | ||||
| 	int3 pos(0,0,index); | ||||
| 	 | ||||
|  | ||||
| 	const JsonVector & rows = src.Vector(); | ||||
| 	 | ||||
|  | ||||
| 	if(rows.size() != map->height) | ||||
| 		throw new std::runtime_error("Invalid terrain data"); | ||||
| 	 | ||||
|  | ||||
| 	for(pos.y = 0; pos.y < map->height; pos.y++) | ||||
| 	{ | ||||
| 		const JsonVector & tiles = rows[pos.y].Vector(); | ||||
| 		 | ||||
|  | ||||
| 		if(tiles.size() != map->width) | ||||
| 			throw new std::runtime_error("Invalid terrain data");		 | ||||
| 		 | ||||
| 			throw new std::runtime_error("Invalid terrain data"); | ||||
|  | ||||
| 		for(pos.x = 0; pos.x < map->width; pos.x++) | ||||
| 			readTerrainTile(tiles[pos.x].String(), map->getTile(pos)); | ||||
| 	}	 | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -424,14 +424,14 @@ void CMapLoaderJson::readTerrain() | ||||
| { | ||||
| 	{ | ||||
| 		const JsonNode surface = readJson("surface.json"); | ||||
| 		readTerrainLevel(surface, 0);		 | ||||
| 		readTerrainLevel(surface, 0); | ||||
| 	} | ||||
| 	if(map->twoLevel) | ||||
| 	{ | ||||
| 		const JsonNode underground = readJson("underground.json"); | ||||
| 		readTerrainLevel(underground, 1);			 | ||||
| 		readTerrainLevel(underground, 1); | ||||
| 	} | ||||
| 		 | ||||
|  | ||||
| } | ||||
|  | ||||
| ///CMapSaverJson | ||||
| @@ -439,12 +439,12 @@ CMapSaverJson::CMapSaverJson(CInputOutputStream * stream): | ||||
| 	CMapFormatZip(stream), | ||||
| 	saver(ioApi, "_") | ||||
| { | ||||
| 	 | ||||
|  | ||||
| } | ||||
|  | ||||
| CMapSaverJson::~CMapSaverJson() | ||||
| { | ||||
| 	 | ||||
|  | ||||
| } | ||||
|  | ||||
| void CMapSaverJson::addToArchive(const JsonNode& data, const std::string& filename) | ||||
| @@ -452,21 +452,21 @@ void CMapSaverJson::addToArchive(const JsonNode& data, const std::string& filena | ||||
| 	std::ostringstream out; | ||||
| 	out << data; | ||||
| 	out.flush(); | ||||
| 	 | ||||
|  | ||||
| 	{ | ||||
| 		auto s = out.str(); | ||||
| 		std::unique_ptr<COutputStream> stream = saver.addFile(filename); | ||||
| 		 | ||||
|  | ||||
| 		if (stream->write((const ui8*)s.c_str(), s.size()) != s.size()) | ||||
| 			throw new std::runtime_error("CMapSaverJson::saveHeader() zip compression failed."); | ||||
| 	}		 | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CMapSaverJson::saveMap(const std::unique_ptr<CMap>& map) | ||||
| { | ||||
| 	//TODO: saveMap | ||||
| 	this->map = map.get(); | ||||
| 	writeHeader();	 | ||||
| 	writeHeader(); | ||||
| 	writeTerrain(); | ||||
| } | ||||
|  | ||||
| @@ -474,26 +474,26 @@ void CMapSaverJson::writeHeader() | ||||
| { | ||||
| 	JsonNode header; | ||||
| 	header["versionMajor"].Float() = VERSION_MAJOR; | ||||
| 	header["versionMinor"].Float() = VERSION_MINOR;	 | ||||
| 	 | ||||
| 	//todo: multilevel map save support	 | ||||
| 	header["versionMinor"].Float() = VERSION_MINOR; | ||||
|  | ||||
| 	//todo: multilevel map save support | ||||
| 	JsonNode & levels = header["mapLevels"]; | ||||
| 	levels["surface"]["height"].Float() = map->height;	 | ||||
| 	levels["surface"]["height"].Float() = map->height; | ||||
| 	levels["surface"]["width"].Float() = map->width; | ||||
| 	levels["surface"]["index"].Float() = 0; | ||||
| 	 | ||||
|  | ||||
| 	if(map->twoLevel) | ||||
| 	{ | ||||
| 		levels["underground"]["height"].Float() = map->height;	 | ||||
| 		levels["underground"]["width"].Float() = map->width;	 | ||||
| 		levels["underground"]["height"].Float() = map->height; | ||||
| 		levels["underground"]["width"].Float() = map->width; | ||||
| 		levels["underground"]["index"].Float() = 1; | ||||
| 	} | ||||
| 	 | ||||
|  | ||||
| 	header["name"].String() = map->name; | ||||
| 	header["description"].String() = map->description; | ||||
| 	 | ||||
| 	 | ||||
| 	//todo: support arbitrary percentage	 | ||||
|  | ||||
|  | ||||
| 	//todo: support arbitrary percentage | ||||
| 	static const std::map<ui8, std::string> difficultyMap = | ||||
| 	{ | ||||
| 		{0, "EASY"}, | ||||
| @@ -502,17 +502,17 @@ void CMapSaverJson::writeHeader() | ||||
| 		{3, "EXPERT"}, | ||||
| 		{4, "IMPOSSIBLE"} | ||||
| 	}; | ||||
| 	 | ||||
| 	header["difficulty"].String() = difficultyMap.at(map->difficulty);	 | ||||
|  | ||||
| 	header["difficulty"].String() = difficultyMap.at(map->difficulty); | ||||
| 	header["levelLimit"].Float() = map->levelLimit; | ||||
| 	 | ||||
|  | ||||
| 	writeTriggeredEvents(header); | ||||
| 	 | ||||
|  | ||||
| 	//todo: player info | ||||
| 	 | ||||
|  | ||||
| 	//todo:	allowedHeroes; | ||||
| 	//todo: placeholdedHeroes;	 | ||||
| 	 | ||||
| 	//todo: placeholdedHeroes; | ||||
|  | ||||
| 	addToArchive(header, HEADER_FILE_NAME); | ||||
| } | ||||
|  | ||||
| @@ -543,32 +543,32 @@ JsonNode CMapSaverJson::writeTerrainLevel(const int index) | ||||
| { | ||||
| 	JsonNode data; | ||||
| 	int3 pos(0,0,index); | ||||
| 	 | ||||
|  | ||||
| 	data.Vector().resize(map->height); | ||||
| 	 | ||||
|  | ||||
| 	for(pos.y = 0; pos.y < map->height; pos.y++) | ||||
| 	{ | ||||
| 		JsonNode & row = data.Vector()[pos.y]; | ||||
| 		 | ||||
|  | ||||
| 		row.Vector().resize(map->width); | ||||
| 		 | ||||
|  | ||||
| 		for(pos.x = 0; pos.x < map->width; pos.x++) | ||||
| 			row.Vector()[pos.x].String() = writeTerrainTile(map->getTile(pos)); | ||||
| 	} | ||||
| 	 | ||||
|  | ||||
| 	return std::move(data); | ||||
| } | ||||
|  | ||||
| void CMapSaverJson::writeTerrain() | ||||
| { | ||||
| 	//todo: multilevel map save support	 | ||||
| 	 | ||||
| 	//todo: multilevel map save support | ||||
|  | ||||
| 	JsonNode surface = writeTerrainLevel(0); | ||||
| 	addToArchive(surface, "surface.json"); | ||||
| 	 | ||||
|  | ||||
| 	if(map->twoLevel) | ||||
| 	{ | ||||
| 		JsonNode underground = writeTerrainLevel(1); | ||||
| 		addToArchive(underground, "underground.json");		 | ||||
| 		addToArchive(underground, "underground.json"); | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user