mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Spell configuration: introduce simplifaction mechanism for level conficuration
* also aviable for other handlers
This commit is contained in:
		| @@ -231,20 +231,25 @@ | |||||||
| 			 "additionalProperties" : false, | 			 "additionalProperties" : false, | ||||||
| 			 "required" : ["none", "basic", "advanced", "expert"], | 			 "required" : ["none", "basic", "advanced", "expert"], | ||||||
|  |  | ||||||
| 			 "properties":{ | 			 "properties":{	 | ||||||
| 				 "none":{ | 				"base":{ | ||||||
| 					  "$ref" : "#/definitions/levelInfo" | 					"type": "object", | ||||||
| 				 }, | 					"description": "will be merged with all levels", | ||||||
| 				 "basic":{ | 					"additionalProperties": true | ||||||
| 					  "$ref" : "#/definitions/levelInfo" | 				}, | ||||||
| 				 }, | 				"none":{ | ||||||
| 				 "advanced":{ | 					"$ref" : "#/definitions/levelInfo" | ||||||
| 					  "$ref" : "#/definitions/levelInfo" | 				}, | ||||||
| 				 }, | 				"basic":{ | ||||||
| 				 "expert":{ | 					"$ref" : "#/definitions/levelInfo" | ||||||
| 					  "$ref" : "#/definitions/levelInfo" | 				}, | ||||||
| 				 } | 				"advanced":{ | ||||||
| 			 } | 					"$ref" : "#/definitions/levelInfo" | ||||||
|  | 				}, | ||||||
|  | 				"expert":{ | ||||||
|  | 					"$ref" : "#/definitions/levelInfo" | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
| @@ -296,6 +296,12 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali | |||||||
| { | { | ||||||
| 	ModInfo & modInfo = modData[modName]; | 	ModInfo & modInfo = modData[modName]; | ||||||
| 	bool result = true; | 	bool result = true; | ||||||
|  | 	 | ||||||
|  | 	auto performValidate = [&,this](JsonNode & data, const std::string & name){ | ||||||
|  | 		handler->beforeValidate(data); | ||||||
|  | 		if (validate) | ||||||
|  | 			result &= JsonUtils::validate(data, "vcmi:" + objectName, name);	 | ||||||
|  | 	}; | ||||||
|  |  | ||||||
| 	// apply patches | 	// apply patches | ||||||
| 	if (!modInfo.patches.isNull()) | 	if (!modInfo.patches.isNull()) | ||||||
| @@ -314,8 +320,8 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali | |||||||
| 			if (originalData.size() > index) | 			if (originalData.size() > index) | ||||||
| 			{ | 			{ | ||||||
| 				JsonUtils::merge(originalData[index], data); | 				JsonUtils::merge(originalData[index], data); | ||||||
| 				if (validate) | 				 | ||||||
| 					result &= JsonUtils::validate(originalData[index], "vcmi:" + objectName, name); | 				performValidate(originalData[index],name); | ||||||
| 				handler->loadObject(modName, name, originalData[index], index); | 				handler->loadObject(modName, name, originalData[index], index); | ||||||
|  |  | ||||||
| 				originalData[index].clear(); // do not use same data twice (same ID) | 				originalData[index].clear(); // do not use same data twice (same ID) | ||||||
| @@ -324,8 +330,7 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		// normal new object or one with index bigger that data size | 		// normal new object or one with index bigger that data size | ||||||
| 		if (validate) | 		performValidate(data,name); | ||||||
| 			result &= JsonUtils::validate(data, "vcmi:" + objectName, name); |  | ||||||
| 		handler->loadObject(modName, name, data); | 		handler->loadObject(modName, name, data); | ||||||
| 	} | 	} | ||||||
| 	return result; | 	return result; | ||||||
|   | |||||||
| @@ -864,6 +864,22 @@ void CSpellHandler::afterLoadFinalization() | |||||||
| 				bonus.sid = spell->id; | 				bonus.sid = spell->id; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void CSpellHandler::beforeValidate(JsonNode & object) | ||||||
|  | { | ||||||
|  | 	//handle "base" level info | ||||||
|  | 	 | ||||||
|  | 	JsonNode levels = object["levels"]; | ||||||
|  | 	 | ||||||
|  | 	if(levels["base"].getType() == JsonNode::DATA_STRUCT) | ||||||
|  | 	{ | ||||||
|  | 		JsonUtils::mergeCopy(levels["none"],levels["base"]); | ||||||
|  | 		JsonUtils::mergeCopy(levels["basic"],levels["base"]); | ||||||
|  | 		JsonUtils::mergeCopy(levels["advanced"],levels["base"]); | ||||||
|  | 		JsonUtils::mergeCopy(levels["expert"],levels["base"]); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| CSpellHandler::~CSpellHandler() | CSpellHandler::~CSpellHandler() | ||||||
|   | |||||||
| @@ -205,6 +205,7 @@ public: | |||||||
|  |  | ||||||
| 	std::vector<JsonNode> loadLegacyData(size_t dataSize) override; | 	std::vector<JsonNode> loadLegacyData(size_t dataSize) override; | ||||||
| 	void afterLoadFinalization() override; | 	void afterLoadFinalization() override; | ||||||
|  | 	void beforeValidate(JsonNode & object) override; | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Gets a list of default allowed spells. OH3 spells are all allowed by default. | 	 * Gets a list of default allowed spells. OH3 spells are all allowed by default. | ||||||
|   | |||||||
| @@ -32,6 +32,9 @@ public: | |||||||
| 	virtual void loadObject(std::string scope, std::string name, const JsonNode & data) = 0; | 	virtual void loadObject(std::string scope, std::string name, const JsonNode & data) = 0; | ||||||
| 	virtual void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) = 0; | 	virtual void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) = 0; | ||||||
|  |  | ||||||
|  | 	/// allows handlers to alter object configuration before validation and actual load | ||||||
|  | 	virtual void beforeValidate(JsonNode & object){}; | ||||||
|  |  | ||||||
| 	/// allows handler to do post-loading step for validation or integration of loaded data | 	/// allows handler to do post-loading step for validation or integration of loaded data | ||||||
| 	virtual void afterLoadFinalization(){}; | 	virtual void afterLoadFinalization(){}; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user