Browse Source

Advance map header serialization

AlexVinS 9 years ago
parent
commit
a4b6d34ebe

+ 15 - 1
lib/CHeroHandler.cpp

@@ -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)

+ 6 - 0
lib/CHeroHandler.h

@@ -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);
 

+ 2 - 8
lib/mapping/MapFormatJson.cpp

@@ -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);

+ 0 - 2
lib/serializer/JsonDeserializer.cpp

@@ -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)
 			{

+ 2 - 2
test/CMapFormatTest.cpp

@@ -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);
 

+ 1 - 2
test/MapComparer.cpp

@@ -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;