1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

vcmi: modernize rest of lib

This commit is contained in:
Konstantin
2023-03-14 00:26:44 +03:00
parent 17520b70ce
commit 4c4498b22a
70 changed files with 1278 additions and 1463 deletions

View File

@@ -50,7 +50,7 @@ class DLL_LINKAGE CIdentifierStorage
ObjectCallback(std::string localScope, std::string remoteScope,
std::string type, std::string name,
const std::function<void(si32)> & callback,
std::function<void(si32)> callback,
bool optional);
};
@@ -77,34 +77,34 @@ class DLL_LINKAGE CIdentifierStorage
ELoadingState state;
/// Check if identifier can be valid (camelCase, point as separator)
void checkIdentifier(std::string & ID);
static void checkIdentifier(std::string & ID);
void requestIdentifier(ObjectCallback callback);
bool resolveIdentifier(const ObjectCallback & callback);
std::vector<ObjectData> getPossibleIdentifiers(const ObjectCallback & callback);
public:
CIdentifierStorage();
virtual ~CIdentifierStorage();
virtual ~CIdentifierStorage() = default;
/// request identifier for specific object name.
/// Function callback will be called during ID resolution phase of loading
void requestIdentifier(std::string scope, std::string type, std::string name, const std::function<void(si32)> & callback);
void requestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback);
///fullName = [remoteScope:]type.name
void requestIdentifier(std::string scope, std::string fullName, const std::function<void(si32)> & callback);
void requestIdentifier(std::string type, const JsonNode & name, const std::function<void(si32)> & callback);
void requestIdentifier(const std::string & scope, const std::string & fullName, const std::function<void(si32)> & callback);
void requestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback);
void requestIdentifier(const JsonNode & name, const std::function<void(si32)> & callback);
/// try to request ID. If ID with such name won't be loaded, callback function will not be called
void tryRequestIdentifier(std::string scope, std::string type, std::string name, const std::function<void(si32)> & callback);
void tryRequestIdentifier(std::string type, const JsonNode & name, const std::function<void(si32)> & callback);
void tryRequestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback);
void tryRequestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback);
/// get identifier immediately. If identifier is not know and not silent call will result in error message
boost::optional<si32> getIdentifier(std::string scope, std::string type, std::string name, bool silent = false);
boost::optional<si32> getIdentifier(std::string type, const JsonNode & name, bool silent = false);
boost::optional<si32> getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent = false);
boost::optional<si32> getIdentifier(const std::string & type, const JsonNode & name, bool silent = false);
boost::optional<si32> getIdentifier(const JsonNode & name, bool silent = false);
boost::optional<si32> getIdentifier(std::string scope, std::string fullName, bool silent = false);
boost::optional<si32> getIdentifier(const std::string & scope, const std::string & fullName, bool silent = false);
/// registers new object
void registerObject(std::string scope, std::string type, std::string name, si32 identifier);
void registerObject(const std::string & scope, const std::string & type, const std::string & name, si32 identifier);
/// called at the very end of loading to check for any missing ID's
void finalize();
@@ -135,12 +135,12 @@ public:
std::vector<JsonNode> originalData;
std::map<std::string, ModInfo> modData;
ContentTypeHandler(IHandlerBase * handler, std::string objectName);
ContentTypeHandler(IHandlerBase * handler, const std::string & objectName);
/// local version of methods in ContentHandler
/// returns true if loading was successful
bool preloadModData(std::string modName, std::vector<std::string> fileList, bool validate);
bool loadMod(std::string modName, bool validate);
bool preloadModData(const std::string & modName, const std::vector<std::string> & fileList, bool validate);
bool loadMod(const std::string & modName, bool validate);
void loadCustom();
void afterLoadFinalization();
};
@@ -149,15 +149,14 @@ public:
class DLL_LINKAGE CContentHandler
{
/// preloads all data from fileList as data from modName.
bool preloadModData(std::string modName, JsonNode modConfig, bool validate);
bool preloadModData(const std::string & modName, JsonNode modConfig, bool validate);
/// actually loads data in mod
bool loadMod(std::string modName, bool validate);
bool loadMod(const std::string & modName, bool validate);
std::map<std::string, ContentTypeHandler> handlers;
public:
CContentHandler();
public:
void init();
/// preloads all data from fileList as data from modName.
@@ -241,7 +240,7 @@ public:
JsonNode config;
CModInfo();
CModInfo(std::string identifier, const JsonNode & local, const JsonNode & config);
CModInfo(const std::string & identifier, const JsonNode & local, const JsonNode & config);
JsonNode saveLocalData() const;
void updateChecksum(ui32 newChecksum);
@@ -249,8 +248,8 @@ public:
bool isEnabled() const;
void setEnabled(bool on);
static std::string getModDir(std::string name);
static std::string getModFile(std::string name);
static std::string getModDir(const std::string & name);
static std::string getModFile(const std::string & name);
private:
/// true if mod is enabled by user, e.g. in Launcher UI
@@ -268,9 +267,9 @@ class DLL_LINKAGE CModHandler
std::vector <TModID> activeMods;//active mods, in order in which they were loaded
CModInfo coreMod;
void loadConfigFromFile(std::string name);
void loadConfigFromFile(const std::string & name);
bool hasCircularDependency(TModID mod, std::set <TModID> currentList = std::set <TModID>()) const;
bool hasCircularDependency(const TModID & mod, std::set<TModID> currentList = std::set<TModID>()) const;
/**
* 1. Set apart mods with resolved dependencies from mods which have unresolved dependencies
@@ -282,10 +281,10 @@ class DLL_LINKAGE CModHandler
*/
std::vector <TModID> validateAndSortDependencies(std::vector <TModID> modsToResolve) const;
std::vector<std::string> getModList(std::string path);
void loadMods(std::string path, std::string parent, const JsonNode & modSettings, bool enableMods);
void loadOneMod(std::string modName, std::string parent, const JsonNode & modSettings, bool enableMods);
void loadTranslation(TModID modName);
std::vector<std::string> getModList(const std::string & path) const;
void loadMods(const std::string & path, const std::string & parent, const JsonNode & modSettings, bool enableMods);
void loadOneMod(std::string modName, const std::string & parent, const JsonNode & modSettings, bool enableMods);
void loadTranslation(const TModID & modName);
bool validateTranslations(TModID modName) const;
public:
@@ -342,9 +341,9 @@ public:
/// returns ID of mod that provides selected file resource
TModID findResourceOrigin(const ResourceID & name);
std::string getModLanguage(const TModID& modId) const;
std::string getModLanguage(const TModID & modId) const;
std::set<TModID> getModDependencies(TModID modId, bool & isModFound) const;
std::set<TModID> getModDependencies(const TModID & modId, bool & isModFound) const;
/// returns list of all (active) mods
std::vector<std::string> getAllMods();
@@ -421,7 +420,7 @@ public:
} modules;
CModHandler();
virtual ~CModHandler();
virtual ~CModHandler() = default;
static std::string normalizeIdentifier(const std::string & scope, const std::string & remoteScope, const std::string & identifier);