mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	fixed crash when loading neutral faction; skills.json no longer requires index values
This commit is contained in:
		| @@ -29,10 +29,6 @@ | ||||
|         "required" : ["basic", "advanced", "expert"], | ||||
|  | ||||
|         "properties": { | ||||
|             "index":{ | ||||
|                 "type": "number", | ||||
|                 "description": "numeric id of skill required only for original skills, prohibited for new skills" | ||||
|             }, | ||||
|             "basic":{ | ||||
|                 "$ref" : "#/definitions/skillBonus" | ||||
|             }, | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| { | ||||
|     "estates" : { | ||||
|         "index" : 13, | ||||
|         "basic" : { | ||||
|             "description" : "Hero generates 250 gold each day.", | ||||
|             "effects" : [ | ||||
|   | ||||
| @@ -398,8 +398,14 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				// trace only name field of original data - I miss list comprehension | ||||
| 				std::vector<std::string> originalNames; | ||||
| 				for (const JsonNode & orgElem : originalData) | ||||
| 					originalNames.push_back(orgElem["name"].String()); | ||||
| 				logger->debugStream() << "no original data in loadMod(" << name << ") at index " << index; | ||||
| 				logger->traceStream() << data; | ||||
| 				logger->traceStream() << "originalData: " << originalNames; | ||||
| 				logger->traceStream() << "new data: " << data; | ||||
|  | ||||
| 				performValidate(data, name); | ||||
| 				handler->loadObject(modName, name, data, index); | ||||
| 			} | ||||
|   | ||||
| @@ -150,6 +150,34 @@ CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string & | ||||
|     return skill; | ||||
| } | ||||
|  | ||||
| void CSkillHandler::loadObject(std::string scope, std::string name, const JsonNode & data) | ||||
| { | ||||
| 	auto type_name = getTypeName(); | ||||
| 	auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name)); | ||||
|  | ||||
| 	if(object->id == SecondarySkill::DEFAULT) // new skill - no index identified | ||||
| 	{ | ||||
| 		object->id = SecondarySkill(objects.size()); | ||||
| 		objects.push_back(object); | ||||
| 	} | ||||
| 	else | ||||
| 		objects[object->id] = object; | ||||
|  | ||||
| 	registerObject(scope, type_name, name, object->id); | ||||
| } | ||||
|  | ||||
| void CSkillHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) | ||||
| { | ||||
| 	auto type_name = getTypeName(); | ||||
| 	auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name)); | ||||
|  | ||||
| 	assert(object->id == index); | ||||
| 	objects[index] = object; | ||||
|  | ||||
| 	registerObject(scope,type_name, name, object->id); | ||||
| } | ||||
|  | ||||
|  | ||||
| void CSkillHandler::afterLoadFinalization() | ||||
| { | ||||
|     CLogger * logger = CLogger::getLogger(CLoggerDomain(getTypeName())); | ||||
|   | ||||
| @@ -73,6 +73,8 @@ public: | ||||
|  | ||||
|     std::vector<bool> getDefaultAllowed() const override; | ||||
|     const std::string getTypeName() const override; | ||||
|     void loadObject(std::string scope, std::string name, const JsonNode & data) override; | ||||
|     void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override; | ||||
|  | ||||
|     template <typename Handler> void serialize(Handler &h, const int version) | ||||
|     { | ||||
|   | ||||
| @@ -763,7 +763,10 @@ void CTownHandler::loadObject(std::string scope, std::string name, const JsonNod | ||||
| { | ||||
| 	auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name)); | ||||
| 	object->index = index; | ||||
| 	assert(factions[index] == nullptr); // ensure that this id was not loaded before | ||||
| 	if (factions.size() > index) | ||||
| 		assert(factions[index] == nullptr); // ensure that this id was not loaded before | ||||
| 	else | ||||
| 		factions.resize(index + 1); | ||||
| 	factions[index] = object; | ||||
|  | ||||
| 	if (object->town) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user