1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Advance map header serialization

This commit is contained in:
AlexVinS 2016-02-21 22:13:20 +03:00
parent 4ebafa17b4
commit a4b6d34ebe
6 changed files with 26 additions and 15 deletions

View File

@ -612,6 +612,20 @@ std::vector<bool> CHeroHandler::getDefaultAllowedAbilities() const
return allowedAbilities;
}
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);

View File

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

View File

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

View File

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

View File

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

View File

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