mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-17 00:07:41 +02:00
vcmi: modernize rest of lib
This commit is contained in:
@ -10,6 +10,7 @@
|
||||
#include "StdInc.h"
|
||||
#include "CModHandler.h"
|
||||
#include "mapObjects/CObjectClassesHandler.h"
|
||||
#include "rmg/CRmgTemplateStorage.h"
|
||||
#include "filesystem/FileStream.h"
|
||||
#include "filesystem/AdapterLoaders.h"
|
||||
#include "filesystem/CFilesystemLoader.h"
|
||||
@ -42,10 +43,6 @@ CIdentifierStorage::CIdentifierStorage():
|
||||
{
|
||||
}
|
||||
|
||||
CIdentifierStorage::~CIdentifierStorage()
|
||||
{
|
||||
}
|
||||
|
||||
void CIdentifierStorage::checkIdentifier(std::string & ID)
|
||||
{
|
||||
if (boost::algorithm::ends_with(ID, "."))
|
||||
@ -66,15 +63,17 @@ void CIdentifierStorage::checkIdentifier(std::string & ID)
|
||||
}
|
||||
}
|
||||
|
||||
CIdentifierStorage::ObjectCallback::ObjectCallback(
|
||||
std::string localScope, std::string remoteScope, std::string type,
|
||||
std::string name, const std::function<void(si32)> & callback,
|
||||
bool optional):
|
||||
localScope(localScope),
|
||||
remoteScope(remoteScope),
|
||||
type(type),
|
||||
name(name),
|
||||
callback(callback),
|
||||
CIdentifierStorage::ObjectCallback::ObjectCallback(std::string localScope,
|
||||
std::string remoteScope,
|
||||
std::string type,
|
||||
std::string name,
|
||||
std::function<void(si32)> callback,
|
||||
bool optional):
|
||||
localScope(std::move(localScope)),
|
||||
remoteScope(std::move(remoteScope)),
|
||||
type(std::move(type)),
|
||||
name(std::move(name)),
|
||||
callback(std::move(callback)),
|
||||
optional(optional)
|
||||
{}
|
||||
|
||||
@ -91,14 +90,14 @@ void CIdentifierStorage::requestIdentifier(ObjectCallback callback)
|
||||
resolveIdentifier(callback);
|
||||
}
|
||||
|
||||
void CIdentifierStorage::requestIdentifier(std::string scope, std::string type, std::string name, const std::function<void(si32)> & callback)
|
||||
void CIdentifierStorage::requestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name, ':'); // remoteScope:name
|
||||
|
||||
requestIdentifier(ObjectCallback(scope, pair.first, type, pair.second, callback, false));
|
||||
}
|
||||
|
||||
void CIdentifierStorage::requestIdentifier(std::string scope, std::string fullName, const std::function<void(si32)>& callback)
|
||||
void CIdentifierStorage::requestIdentifier(const std::string & scope, const std::string & fullName, const std::function<void(si32)> & callback)
|
||||
{
|
||||
auto scopeAndFullName = vstd::splitStringToPair(fullName, ':');
|
||||
auto typeAndName = vstd::splitStringToPair(scopeAndFullName.second, '.');
|
||||
@ -106,7 +105,7 @@ void CIdentifierStorage::requestIdentifier(std::string scope, std::string fullNa
|
||||
requestIdentifier(ObjectCallback(scope, scopeAndFullName.first, typeAndName.first, typeAndName.second, callback, false));
|
||||
}
|
||||
|
||||
void CIdentifierStorage::requestIdentifier(std::string type, const JsonNode & name, const std::function<void(si32)> & callback)
|
||||
void CIdentifierStorage::requestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name.String(), ':'); // remoteScope:name
|
||||
|
||||
@ -121,21 +120,21 @@ void CIdentifierStorage::requestIdentifier(const JsonNode & name, const std::fun
|
||||
requestIdentifier(ObjectCallback(name.meta, pair.first, pair2.first, pair2.second, callback, false));
|
||||
}
|
||||
|
||||
void CIdentifierStorage::tryRequestIdentifier(std::string scope, std::string type, std::string name, const std::function<void(si32)> & callback)
|
||||
void CIdentifierStorage::tryRequestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name, ':'); // remoteScope:name
|
||||
|
||||
requestIdentifier(ObjectCallback(scope, pair.first, type, pair.second, callback, true));
|
||||
}
|
||||
|
||||
void CIdentifierStorage::tryRequestIdentifier(std::string type, const JsonNode & name, const std::function<void(si32)> & callback)
|
||||
void CIdentifierStorage::tryRequestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name.String(), ':'); // remoteScope:name
|
||||
|
||||
requestIdentifier(ObjectCallback(name.meta, pair.first, type, pair.second, callback, true));
|
||||
}
|
||||
|
||||
boost::optional<si32> CIdentifierStorage::getIdentifier(std::string scope, std::string type, std::string name, bool silent)
|
||||
boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name, ':'); // remoteScope:name
|
||||
auto idList = getPossibleIdentifiers(ObjectCallback(scope, pair.first, type, pair.second, std::function<void(si32)>(), silent));
|
||||
@ -148,7 +147,7 @@ boost::optional<si32> CIdentifierStorage::getIdentifier(std::string scope, std::
|
||||
return boost::optional<si32>();
|
||||
}
|
||||
|
||||
boost::optional<si32> CIdentifierStorage::getIdentifier(std::string type, const JsonNode & name, bool silent)
|
||||
boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & type, const JsonNode & name, bool silent)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(name.String(), ':'); // remoteScope:name
|
||||
auto idList = getPossibleIdentifiers(ObjectCallback(name.meta, pair.first, type, pair.second, std::function<void(si32)>(), silent));
|
||||
@ -175,7 +174,7 @@ 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)
|
||||
boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & fullName, bool silent)
|
||||
{
|
||||
auto pair = vstd::splitStringToPair(fullName, ':'); // remoteScope:<type.name>
|
||||
auto pair2 = vstd::splitStringToPair(pair.second, '.'); // type.name
|
||||
@ -189,7 +188,7 @@ boost::optional<si32> CIdentifierStorage::getIdentifier(std::string scope, std::
|
||||
return boost::optional<si32>();
|
||||
}
|
||||
|
||||
void CIdentifierStorage::registerObject(std::string scope, std::string type, std::string name, si32 identifier)
|
||||
void CIdentifierStorage::registerObject(const std::string & scope, const std::string & type, const std::string & name, si32 identifier)
|
||||
{
|
||||
ObjectData data;
|
||||
data.scope = scope;
|
||||
@ -300,14 +299,14 @@ bool CIdentifierStorage::resolveIdentifier(const ObjectCallback & request)
|
||||
}
|
||||
|
||||
// error found. Try to generate some debug info
|
||||
if (identifiers.size() == 0)
|
||||
if(identifiers.empty())
|
||||
logMod->error("Unknown identifier!");
|
||||
else
|
||||
logMod->error("Ambiguous identifier request!");
|
||||
|
||||
logMod->error("Request for %s.%s from mod %s", request.type, request.name, request.localScope);
|
||||
|
||||
for (auto id : identifiers)
|
||||
for(const auto & id : identifiers)
|
||||
{
|
||||
logMod->error("\tID is available in mod %s", id.scope);
|
||||
}
|
||||
@ -331,7 +330,7 @@ void CIdentifierStorage::finalize()
|
||||
|
||||
if (errorsFound)
|
||||
{
|
||||
for(auto object : registeredObjects)
|
||||
for(const auto & object : registeredObjects)
|
||||
{
|
||||
logMod->trace("%s : %s -> %d", object.second.scope, object.first, object.second.id);
|
||||
}
|
||||
@ -341,10 +340,10 @@ void CIdentifierStorage::finalize()
|
||||
state = FINISHED;
|
||||
}
|
||||
|
||||
ContentTypeHandler::ContentTypeHandler(IHandlerBase * handler, std::string objectName):
|
||||
ContentTypeHandler::ContentTypeHandler(IHandlerBase * handler, const std::string & objectName):
|
||||
handler(handler),
|
||||
objectName(objectName),
|
||||
originalData(handler->loadLegacyData((size_t)VLC->modh->settings.data["textData"][objectName].Float()))
|
||||
originalData(handler->loadLegacyData(static_cast<size_t>(VLC->modh->settings.data["textData"][objectName].Float())))
|
||||
{
|
||||
for(auto & node : originalData)
|
||||
{
|
||||
@ -352,9 +351,9 @@ ContentTypeHandler::ContentTypeHandler(IHandlerBase * handler, std::string objec
|
||||
}
|
||||
}
|
||||
|
||||
bool ContentTypeHandler::preloadModData(std::string modName, std::vector<std::string> fileList, bool validate)
|
||||
bool ContentTypeHandler::preloadModData(const std::string & modName, const std::vector<std::string> & fileList, bool validate)
|
||||
{
|
||||
bool result;
|
||||
bool result = false;
|
||||
JsonNode data = JsonUtils::assembleFromFiles(fileList, result);
|
||||
data.setMeta(modName);
|
||||
|
||||
@ -387,7 +386,7 @@ bool ContentTypeHandler::preloadModData(std::string modName, std::vector<std::st
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ContentTypeHandler::loadMod(std::string modName, bool validate)
|
||||
bool ContentTypeHandler::loadMod(const std::string & modName, bool validate)
|
||||
{
|
||||
ModInfo & modInfo = modData[modName];
|
||||
bool result = true;
|
||||
@ -440,7 +439,6 @@ bool ContentTypeHandler::loadMod(std::string modName, bool validate)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void ContentTypeHandler::loadCustom()
|
||||
{
|
||||
handler->loadCustom();
|
||||
@ -451,10 +449,6 @@ void ContentTypeHandler::afterLoadFinalization()
|
||||
handler->afterLoadFinalization();
|
||||
}
|
||||
|
||||
CContentHandler::CContentHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void CContentHandler::init()
|
||||
{
|
||||
handlers.insert(std::make_pair("heroClasses", ContentTypeHandler(&VLC->heroh->classes, "heroClass")));
|
||||
@ -465,7 +459,7 @@ void CContentHandler::init()
|
||||
handlers.insert(std::make_pair("heroes", ContentTypeHandler(VLC->heroh, "hero")));
|
||||
handlers.insert(std::make_pair("spells", ContentTypeHandler(VLC->spellh, "spell")));
|
||||
handlers.insert(std::make_pair("skills", ContentTypeHandler(VLC->skillh, "skill")));
|
||||
handlers.insert(std::make_pair("templates", ContentTypeHandler((IHandlerBase *)VLC->tplh, "template")));
|
||||
handlers.insert(std::make_pair("templates", ContentTypeHandler(VLC->tplh, "template")));
|
||||
#if SCRIPTING_ENABLED
|
||||
handlers.insert(std::make_pair("scripts", ContentTypeHandler(VLC->scriptHandler, "script")));
|
||||
#endif
|
||||
@ -477,7 +471,7 @@ void CContentHandler::init()
|
||||
//TODO: any other types of moddables?
|
||||
}
|
||||
|
||||
bool CContentHandler::preloadModData(std::string modName, JsonNode modConfig, bool validate)
|
||||
bool CContentHandler::preloadModData(const std::string & modName, JsonNode modConfig, bool validate)
|
||||
{
|
||||
bool result = true;
|
||||
for(auto & handler : handlers)
|
||||
@ -487,7 +481,7 @@ bool CContentHandler::preloadModData(std::string modName, JsonNode modConfig, bo
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CContentHandler::loadMod(std::string modName, bool validate)
|
||||
bool CContentHandler::loadMod(const std::string & modName, bool validate)
|
||||
{
|
||||
bool result = true;
|
||||
for(auto & handler : handlers)
|
||||
@ -552,7 +546,7 @@ const ContentTypeHandler & CContentHandler::operator[](const std::string & name)
|
||||
return handlers.at(name);
|
||||
}
|
||||
|
||||
static JsonNode loadModSettings(std::string path)
|
||||
static JsonNode loadModSettings(const std::string & path)
|
||||
{
|
||||
if (CResourceHandler::get("local")->existsResource(ResourceID(path)))
|
||||
{
|
||||
@ -563,7 +557,7 @@ static JsonNode loadModSettings(std::string path)
|
||||
return JsonNode();
|
||||
}
|
||||
|
||||
JsonNode addMeta(JsonNode config, std::string meta)
|
||||
JsonNode addMeta(JsonNode config, const std::string & meta)
|
||||
{
|
||||
config.setMeta(meta);
|
||||
return config;
|
||||
@ -576,7 +570,9 @@ CModInfo::Version CModInfo::Version::GameVersion()
|
||||
|
||||
CModInfo::Version CModInfo::Version::fromString(std::string from)
|
||||
{
|
||||
int major = 0, minor = 0, patch = 0;
|
||||
int major = 0;
|
||||
int minor = 0;
|
||||
int patch = 0;
|
||||
try
|
||||
{
|
||||
auto pointPos = from.find('.');
|
||||
@ -623,12 +619,12 @@ CModInfo::CModInfo():
|
||||
|
||||
}
|
||||
|
||||
CModInfo::CModInfo(std::string identifier,const JsonNode & local, const JsonNode & config):
|
||||
CModInfo::CModInfo(const std::string & identifier, const JsonNode & local, const JsonNode & config):
|
||||
identifier(identifier),
|
||||
name(config["name"].String()),
|
||||
description(config["description"].String()),
|
||||
dependencies(config["depends"].convertTo<std::set<std::string> >()),
|
||||
conflicts(config["conflicts"].convertTo<std::set<std::string> >()),
|
||||
dependencies(config["depends"].convertTo<std::set<std::string>>()),
|
||||
conflicts(config["conflicts"].convertTo<std::set<std::string>>()),
|
||||
checksum(0),
|
||||
explicitlyEnabled(false),
|
||||
implicitlyEnabled(true),
|
||||
@ -662,12 +658,12 @@ JsonNode CModInfo::saveLocalData() const
|
||||
return conf;
|
||||
}
|
||||
|
||||
std::string CModInfo::getModDir(std::string name)
|
||||
std::string CModInfo::getModDir(const std::string & name)
|
||||
{
|
||||
return "MODS/" + boost::algorithm::replace_all_copy(name, ".", "/MODS/");
|
||||
}
|
||||
|
||||
std::string CModInfo::getModFile(std::string name)
|
||||
std::string CModInfo::getModFile(const std::string & name)
|
||||
{
|
||||
return getModDir(name) + "/mod.json";
|
||||
}
|
||||
@ -749,14 +745,10 @@ CModHandler::CModHandler() : content(std::make_shared<CContentHandler>())
|
||||
}
|
||||
}
|
||||
|
||||
CModHandler::~CModHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void CModHandler::loadConfigFromFile (std::string name)
|
||||
void CModHandler::loadConfigFromFile(const std::string & name)
|
||||
{
|
||||
std::string paths;
|
||||
for(auto& p : CResourceHandler::get()->getResourceNames(ResourceID("config/" + name)))
|
||||
for(const auto & p : CResourceHandler::get()->getResourceNames(ResourceID("config/" + name)))
|
||||
{
|
||||
paths += p.string() + ", ";
|
||||
}
|
||||
@ -820,7 +812,7 @@ void CModHandler::loadConfigFromFile (std::string name)
|
||||
}
|
||||
|
||||
// currentList is passed by value to get current list of depending mods
|
||||
bool CModHandler::hasCircularDependency(TModID modID, std::set <TModID> currentList) const
|
||||
bool CModHandler::hasCircularDependency(const TModID & modID, std::set<TModID> currentList) const
|
||||
{
|
||||
const CModInfo & mod = allMods.at(modID);
|
||||
|
||||
@ -885,7 +877,7 @@ std::vector <TModID> CModHandler::validateAndSortDependencies(std::vector <TModI
|
||||
}
|
||||
it++;
|
||||
}
|
||||
if(resolvedOnCurrentTreeLevel.size())
|
||||
if(!resolvedOnCurrentTreeLevel.empty())
|
||||
{
|
||||
resolvedModIDs.insert(resolvedOnCurrentTreeLevel.begin(), resolvedOnCurrentTreeLevel.end());
|
||||
continue;
|
||||
@ -907,8 +899,7 @@ std::vector <TModID> CModHandler::validateAndSortDependencies(std::vector <TModI
|
||||
return sortedValidMods;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> CModHandler::getModList(std::string path)
|
||||
std::vector<std::string> CModHandler::getModList(const std::string & path) const
|
||||
{
|
||||
std::string modDir = boost::to_upper_copy(path + "MODS/");
|
||||
size_t depth = boost::range::count(modDir, '/');
|
||||
@ -926,7 +917,7 @@ std::vector<std::string> CModHandler::getModList(std::string path)
|
||||
|
||||
//storage for found mods
|
||||
std::vector<std::string> foundMods;
|
||||
for (auto & entry : list)
|
||||
for(const auto & entry : list)
|
||||
{
|
||||
std::string name = entry.getName();
|
||||
name.erase(0, modDir.size()); //Remove path prefix
|
||||
@ -967,13 +958,13 @@ const TModID & CModHandler::scopeMap()
|
||||
return scope;
|
||||
}
|
||||
|
||||
void CModHandler::loadMods(std::string path, std::string parent, const JsonNode & modSettings, bool enableMods)
|
||||
void CModHandler::loadMods(const std::string & path, const std::string & parent, const JsonNode & modSettings, bool enableMods)
|
||||
{
|
||||
for(std::string modName : getModList(path))
|
||||
for(const std::string & modName : getModList(path))
|
||||
loadOneMod(modName, parent, modSettings, enableMods);
|
||||
}
|
||||
|
||||
void CModHandler::loadOneMod(std::string modName, std::string parent, const JsonNode & modSettings, bool enableMods)
|
||||
void CModHandler::loadOneMod(std::string modName, const std::string & parent, const JsonNode & modSettings, bool enableMods)
|
||||
{
|
||||
boost::to_lower(modName);
|
||||
std::string modFullName = parent.empty() ? modName : parent + '.' + modName;
|
||||
@ -1019,6 +1010,7 @@ void CModHandler::loadMods(bool onlyEssential)
|
||||
std::vector<std::string> CModHandler::getAllMods()
|
||||
{
|
||||
std::vector<std::string> modlist;
|
||||
modlist.reserve(allMods.size());
|
||||
for (auto & entry : allMods)
|
||||
modlist.push_back(entry.first);
|
||||
return modlist;
|
||||
@ -1051,7 +1043,7 @@ static ISimpleResourceLoader * genModFilesystem(const std::string & modName, con
|
||||
return CResourceHandler::createFileSystem(CModInfo::getModDir(modName), defaultFS);
|
||||
}
|
||||
|
||||
static ui32 calculateModChecksum(const std::string modName, ISimpleResourceLoader * filesystem)
|
||||
static ui32 calculateModChecksum(const std::string & modName, ISimpleResourceLoader * filesystem)
|
||||
{
|
||||
boost::crc_32_type modChecksum;
|
||||
// first - add current VCMI version into checksum to force re-validation on VCMI updates
|
||||
@ -1121,7 +1113,7 @@ std::string CModHandler::getModLanguage(const TModID& modId) const
|
||||
return allMods.at(modId).baseLanguage;
|
||||
}
|
||||
|
||||
std::set<TModID> CModHandler::getModDependencies(TModID modId, bool & isModFound) const
|
||||
std::set<TModID> CModHandler::getModDependencies(const TModID & modId, bool & isModFound) const
|
||||
{
|
||||
auto it = allMods.find(modId);
|
||||
isModFound = (it != allMods.end());
|
||||
@ -1168,7 +1160,7 @@ bool CModHandler::validateTranslations(TModID modName) const
|
||||
return result;
|
||||
}
|
||||
|
||||
void CModHandler::loadTranslation(TModID modName)
|
||||
void CModHandler::loadTranslation(const TModID & modName)
|
||||
{
|
||||
const auto & mod = allMods[modName];
|
||||
|
||||
@ -1277,7 +1269,7 @@ void CModHandler::parseIdentifier(const std::string & fullIdentifier, std::strin
|
||||
|
||||
auto p2 = vstd::splitStringToPair(p.second, '.');
|
||||
|
||||
if(p2.first != "")
|
||||
if(!p2.first.empty())
|
||||
{
|
||||
type = p2.first;
|
||||
identifier = p2.second;
|
||||
@ -1300,7 +1292,7 @@ std::string CModHandler::makeFullIdentifier(const std::string & scope, const std
|
||||
//ignore scope if identifier is scoped
|
||||
auto scopeAndName = vstd::splitStringToPair(identifier, ':');
|
||||
|
||||
if(scopeAndName.first != "")
|
||||
if(!scopeAndName.first.empty())
|
||||
{
|
||||
actualScope = scopeAndName.first;
|
||||
actualName = scopeAndName.second;
|
||||
|
Reference in New Issue
Block a user