mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Advance map header serialization
This commit is contained in:
		| @@ -612,7 +612,21 @@ std::vector<bool> CHeroHandler::getDefaultAllowedAbilities() const | ||||
| 	return allowedAbilities; | ||||
| } | ||||
|  | ||||
| si32 CHeroHandler::decodeSkill(const std::string& identifier) | ||||
| si32 CHeroHandler::decodeHero(const std::string & identifier) | ||||
| { | ||||
| 	auto rawId = VLC->modh->identifiers.getIdentifier("core", "hero", identifier); | ||||
| 	if(rawId) | ||||
| 		return rawId.get(); | ||||
| 	else | ||||
| 		return -1; | ||||
| } | ||||
|  | ||||
| std::string CHeroHandler::encodeHero(const si32 index) | ||||
| { | ||||
| 	return VLC->heroh->heroes.at(index)->identifier; | ||||
| } | ||||
|  | ||||
| si32 CHeroHandler::decodeSkill(const std::string & identifier) | ||||
| { | ||||
| 	auto rawId = VLC->modh->identifiers.getIdentifier("core", "skill", identifier); | ||||
| 	if(rawId) | ||||
|   | ||||
| @@ -257,6 +257,12 @@ public: | ||||
| 	 */ | ||||
| 	std::vector<bool> getDefaultAllowedAbilities() const; | ||||
|  | ||||
| 	///json serialization helper | ||||
| 	static si32 decodeHero(const std::string & identifier); | ||||
|  | ||||
| 	///json serialization helper | ||||
| 	static std::string encodeHero(const si32 index); | ||||
|  | ||||
| 	///json serialization helper | ||||
| 	static si32 decodeSkill(const std::string & identifier); | ||||
|  | ||||
|   | ||||
| @@ -208,6 +208,8 @@ void CMapFormatJson::serializeHeader(JsonSerializeFormat & handler) | ||||
| 	handler.serializeNumericEnum("difficulty", HeaderDetail::difficultyMap, HeaderDetail::difficultyDefault, mapHeader->difficulty); | ||||
|  | ||||
| 	serializePlayerInfo(handler); | ||||
|  | ||||
| 	handler.serializeLIC("allowedHeroes", &CHeroHandler::decodeHero, &CHeroHandler::encodeHero, VLC->heroh->getDefaultAllowed(), mapHeader->allowedHeroes); | ||||
| } | ||||
|  | ||||
| void CMapFormatJson::serializePlayerInfo(JsonSerializeFormat & handler) | ||||
| @@ -447,7 +449,6 @@ void CMapFormatJson::serializeOptions(JsonSerializeFormat & handler) | ||||
|  | ||||
| 	handler.serializeLIC("allowedSpells", &CSpellHandler::decodeSpell, &CSpellHandler::encodeSpell, VLC->spellh->getDefaultAllowed(), map->allowedSpell); | ||||
|  | ||||
|  | ||||
| 	//events | ||||
| } | ||||
|  | ||||
| @@ -596,10 +597,6 @@ void CMapLoaderJson::readHeader(const bool complete) | ||||
|  | ||||
| 	serializeHeader(handler); | ||||
|  | ||||
|  | ||||
| //	std::vector<bool> allowedHeroes; | ||||
| //	std::vector<ui16> placeholdedHeroes; | ||||
|  | ||||
| 	readTriggeredEvents(handler); | ||||
|  | ||||
|  | ||||
| @@ -930,9 +927,6 @@ void CMapSaverJson::writeHeader() | ||||
|  | ||||
| 	writeTeams(handler); | ||||
|  | ||||
| 	//todo:	allowedHeroes; | ||||
| 	//todo: placeholdedHeroes; | ||||
|  | ||||
| 	writeOptions(handler); | ||||
|  | ||||
| 	addToArchive(header, HEADER_FILE_NAME); | ||||
|   | ||||
| @@ -60,8 +60,6 @@ void JsonDeserializer::serializeLIC(const std::string & fieldName, const TDecode | ||||
| 		{ | ||||
| 			const std::string & identifier = part[index].String(); | ||||
|  | ||||
| 			logGlobal->debugStream() << "serializeLIC: " << fieldName << " " << identifier; | ||||
|  | ||||
| 			si32 rawId = decoder(identifier); | ||||
| 			if(rawId >= 0) | ||||
| 			{ | ||||
|   | ||||
| @@ -35,8 +35,8 @@ public: | ||||
| 	{ | ||||
| 		CMapGenOptions opt; | ||||
|  | ||||
| 		opt.setHeight(CMapHeader::MAP_SIZE_LARGE); | ||||
| 		opt.setWidth(CMapHeader::MAP_SIZE_LARGE); | ||||
| 		opt.setHeight(CMapHeader::MAP_SIZE_MIDDLE); | ||||
| 		opt.setWidth(CMapHeader::MAP_SIZE_MIDDLE); | ||||
| 		opt.setHasTwoLevels(true); | ||||
| 		opt.setPlayerCount(4); | ||||
|  | ||||
|   | ||||
| @@ -144,8 +144,7 @@ void MapComparer::compareHeader() | ||||
|  | ||||
| 	checkEqual(actual->players, expected->players); | ||||
|  | ||||
| 	//todo: allowedHeroes, placeholdedHeroes | ||||
|  | ||||
| 	checkEqual(actual->allowedHeroes, expected->allowedHeroes); | ||||
|  | ||||
| 	std::vector<TriggeredEvent> actualEvents = actual->triggeredEvents; | ||||
| 	std::vector<TriggeredEvent> expectedEvents = expected->triggeredEvents; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user