mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Serialize town spells
This commit is contained in:
		| @@ -809,19 +809,3 @@ std::string CTownHandler::encodeFaction(const si32 index) | ||||
| { | ||||
| 	return VLC->townh->factions[index]->identifier; | ||||
| } | ||||
|  | ||||
| si32 CTownHandler::decodeBuilding(const std::string & identifier) | ||||
| { | ||||
| 	//FIXME: CTownHandler::decodeBuilding | ||||
| 	auto rawId = VLC->modh->identifiers.getIdentifier("core", "building", identifier); //??? | ||||
| 	if(rawId) | ||||
| 		return rawId.get(); | ||||
| 	else | ||||
| 		return -1; | ||||
| } | ||||
|  | ||||
| std::string CTownHandler::encodeBuilding(const si32 index) | ||||
| { | ||||
| 	 //FIXME: CTownHandler::encodeBuilding | ||||
| 	 return ""; | ||||
| } | ||||
|   | ||||
| @@ -288,12 +288,6 @@ public: | ||||
| 	//json serialization helper | ||||
| 	static std::string encodeFaction(const si32 index); | ||||
|  | ||||
| 	//json serialization helper | ||||
| 	static si32 decodeBuilding(const std::string & identifier); | ||||
|  | ||||
| 	//json serialization helper | ||||
| 	static std::string encodeBuilding(const si32 index); | ||||
|  | ||||
| 	template <typename Handler> void serialize(Handler &h, const int version) | ||||
| 	{ | ||||
| 		h & factions; | ||||
|   | ||||
| @@ -11,6 +11,7 @@ | ||||
| #include "StdInc.h" | ||||
| #include "CGTownInstance.h" | ||||
| #include "CObjectClassesHandler.h" | ||||
| #include "../spells/CSpellHandler.h" | ||||
|  | ||||
| #include "../NetPacks.h" | ||||
| #include "../CGeneralTextHandler.h" | ||||
| @@ -1137,8 +1138,47 @@ void CGTownInstance::serializeJsonOptions(JsonSerializeFormat & handler) | ||||
| 		builtBuildings.insert(BuildingID::DEFAULT);//just in case | ||||
| 	} | ||||
|  | ||||
| 	//todo: serialize buildings | ||||
| //	{ | ||||
| //		std::vector<bool> standard; | ||||
| //		standard.resize(44, true); | ||||
| // | ||||
| // | ||||
| //		JsonSerializeFormat::LIC buildingsLIC(, CTownHandler::decodeBuilding, CTownHandler::encodeBuilding); | ||||
| //	} | ||||
|  | ||||
| 	//todo: CGTownInstance::serializeJsonOptions | ||||
| 	{ | ||||
| 		JsonSerializeFormat::LIC spellsLIC(VLC->spellh->getDefaultAllowed(), CSpellHandler::decodeSpell, CSpellHandler::encodeSpell); | ||||
|  | ||||
| 		for(SpellID id : possibleSpells) | ||||
| 			spellsLIC.any[id.num] = true; | ||||
|  | ||||
| 		for(SpellID id : obligatorySpells) | ||||
| 			spellsLIC.all[id.num] = true; | ||||
|  | ||||
| 		handler.serializeLIC("spells", spellsLIC); | ||||
|  | ||||
| 		if(!handler.saving) | ||||
| 		{ | ||||
| 			possibleSpells.clear(); | ||||
| 			for(si32 idx = 0; idx < spellsLIC.any.size(); idx++) | ||||
| 			{ | ||||
| 				if(spellsLIC.any[idx]) | ||||
| 				{ | ||||
| 					possibleSpells.push_back(SpellID(idx)); | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			obligatorySpells.clear(); | ||||
| 			for(si32 idx = 0; idx < spellsLIC.all.size(); idx++) | ||||
| 			{ | ||||
| 				if(spellsLIC.all[idx]) | ||||
| 				{ | ||||
| 					obligatorySpells.push_back(SpellID(idx)); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| COPWBonus::COPWBonus (BuildingID index, CGTownInstance *TOWN) | ||||
|   | ||||
| @@ -118,6 +118,25 @@ void JsonDeserializer::serializeLIC(const std::string & fieldName, LIC & value) | ||||
|  | ||||
| 	readLICPart(allOf, value.decoder, true, value.all); | ||||
| 	readLICPart(noneOf, value.decoder, true, value.none); | ||||
|  | ||||
| 	//remove any banned from allowed and required | ||||
| 	for(si32 idx = 0; idx < value.none.size(); idx++) | ||||
| 	{ | ||||
| 		if(value.none[idx]) | ||||
| 		{ | ||||
| 			value.all[idx] = false; | ||||
| 			value.any[idx] = false; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	//add all required to allowed | ||||
| 	for(si32 idx = 0; idx < value.all.size(); idx++) | ||||
| 	{ | ||||
| 		if(value.all[idx]) | ||||
| 		{ | ||||
| 			value.any[idx] = true; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void JsonDeserializer::serializeString(const std::string & fieldName, std::string & value) | ||||
|   | ||||
| @@ -67,7 +67,7 @@ JsonSerializeFormat * JsonStructSerializer::operator->() | ||||
| JsonSerializeFormat::LIC::LIC(const std::vector<bool> & Standard, const TDecoder & Decoder, const TEncoder & Encoder): | ||||
| 	standard(Standard), decoder(Decoder), encoder(Encoder) | ||||
| { | ||||
| 	any = standard; | ||||
| 	any.resize(standard.size(), false); | ||||
| 	all.resize(standard.size(), false); | ||||
| 	none.resize(standard.size(), false); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user