mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* WIP on event condition format
* Hero portrait serialization * Fix town spells serialization * Added support for float exponential part in Json * Added support for int64 in Json * Added basic Hero definitions serialization * Added rumors serialization * Advanced player info serialization. * Added Disposed heroes serialization, (!) not covered with tests yet * Added Local event serialization * Added Pandoras box serialization * Added Seer hut reward serialization * Added CQuest serialization * Added API for map object instance names serialization. * Added random dwelling options serialization * Advanced town options serialization * Advanced hero options serialization * More map format tests * A lot of fixes, cleanup and refactoring
This commit is contained in:
		| @@ -181,6 +181,20 @@ boost::optional<si32> CIdentifierStorage::getIdentifier(const JsonNode & name, b | ||||
| 	return boost::optional<si32>(); | ||||
| } | ||||
|  | ||||
| boost::optional<si32> CIdentifierStorage::getIdentifier(std::string scope, std::string fullName, bool silent) | ||||
| { | ||||
| 	auto pair  = splitString(fullName, ':'); // remoteScope:<type.name> | ||||
| 	auto pair2 = splitString(pair.second,   '.'); // type.name | ||||
| 	auto idList = getPossibleIdentifiers(ObjectCallback(scope, pair.first, pair2.first, pair2.second, std::function<void(si32)>(), silent)); | ||||
|  | ||||
| 	if (idList.size() == 1) | ||||
| 		return idList.front().id; | ||||
| 	if (!silent) | ||||
| 		logGlobal->errorStream() << "Failed to resolve identifier " << fullName << " of type " << pair2.first << " from mod " << scope; | ||||
|  | ||||
| 	return boost::optional<si32>(); | ||||
| } | ||||
|  | ||||
| void CIdentifierStorage::registerObject(std::string scope, std::string type, std::string name, si32 identifier) | ||||
| { | ||||
| 	ObjectData data; | ||||
| @@ -387,6 +401,12 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
|  | ||||
| void CContentHandler::ContentTypeHandler::loadCustom() | ||||
| { | ||||
| 	handler->loadCustom(); | ||||
| } | ||||
|  | ||||
| void CContentHandler::ContentTypeHandler::afterLoadFinalization() | ||||
| { | ||||
| 	handler->afterLoadFinalization(); | ||||
| @@ -426,6 +446,14 @@ bool CContentHandler::loadMod(std::string modName, bool validate) | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
| void CContentHandler::loadCustom() | ||||
| { | ||||
| 	for(auto & handler : handlers) | ||||
| 	{ | ||||
| 		handler.second.loadCustom(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CContentHandler::afterLoadFinalization() | ||||
| { | ||||
| 	for(auto & handler : handlers) | ||||
| @@ -574,8 +602,10 @@ CModHandler::CModHandler() | ||||
| 	} | ||||
|  | ||||
| 	for(int i=0; i<GameConstants::PRIMARY_SKILLS; ++i) | ||||
| 	{ | ||||
| 		identifiers.registerObject("core", "primSkill", PrimarySkill::names[i], i); | ||||
|  | ||||
| 		identifiers.registerObject("core", "primarySkill", PrimarySkill::names[i], i); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| CModHandler::~CModHandler() | ||||
| @@ -918,6 +948,8 @@ void CModHandler::load() | ||||
| 	for(const TModID & modName : activeMods) | ||||
| 		content.load(allMods[modName]); | ||||
|  | ||||
| 	content.loadCustom(); | ||||
|  | ||||
| 	logGlobal->infoStream() << "\tLoading mod data: " << timer.getDiff() << "ms"; | ||||
|  | ||||
| 	VLC->creh->loadCrExpBon(); | ||||
| @@ -946,7 +978,7 @@ void CModHandler::afterLoad() | ||||
| 	file << modSettings; | ||||
| } | ||||
|  | ||||
| std::string CModHandler::normalizeIdentifier(const std::string & scope, const std::string & remoteScope, const std::string & identifier) const | ||||
| std::string CModHandler::normalizeIdentifier(const std::string & scope, const std::string & remoteScope, const std::string & identifier) | ||||
| { | ||||
| 	auto p = splitString(identifier, ':'); | ||||
|  | ||||
| @@ -956,5 +988,35 @@ std::string CModHandler::normalizeIdentifier(const std::string & scope, const st | ||||
| 	if(p.first == remoteScope) | ||||
| 		p.first.clear(); | ||||
|  | ||||
| 	return p.first.empty() ? p.second : p.first +":"+p.second; | ||||
| 	return p.first.empty() ? p.second : p.first + ":" + p.second; | ||||
| } | ||||
|  | ||||
| void CModHandler::parseIdentifier(const std::string & fullIdentifier, std::string & scope, std::string & type, std::string & identifier) | ||||
| { | ||||
| 	auto p = splitString(fullIdentifier, ':'); | ||||
|  | ||||
| 	scope = p.first; | ||||
|  | ||||
| 	auto p2 = splitString(p.second, '.'); | ||||
|  | ||||
| 	if(p2.first != "") | ||||
| 	{ | ||||
| 		type = p2.first; | ||||
| 		identifier = p2.second; | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		type = p.second; | ||||
| 		identifier = ""; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| std::string CModHandler::makeFullIdentifier(const std::string & scope, const std::string & type, const std::string & identifier) | ||||
| { | ||||
| 	auto p = splitString(identifier, ':'); | ||||
|  | ||||
| 	if(p.first != "") | ||||
| 		return p.first + ":" + type + "." + p.second;//ignore type if identifier is scoped | ||||
| 	else | ||||
| 		return scope == "" ? (identifier == "" ? type : type + "." + identifier) : scope + ":" + type + "." + identifier; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user