|
@@ -123,7 +123,7 @@ CIdentifierStorage::ObjectCallback CIdentifierStorage::ObjectCallback::fromNameW
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-CIdentifierStorage::ObjectCallback CIdentifierStorage::ObjectCallback::fromNameAndType(const std::string & scope, const std::string & type, const std::string & fullName, const std::function<void(si32)> & callback, bool optional)
|
|
|
+CIdentifierStorage::ObjectCallback CIdentifierStorage::ObjectCallback::fromNameAndType(const std::string & scope, const std::string & type, const std::string & fullName, const std::function<void(si32)> & callback, bool optional, bool bypassDependenciesCheck)
|
|
|
{
|
|
|
assert(!scope.empty());
|
|
|
|
|
@@ -148,13 +148,14 @@ CIdentifierStorage::ObjectCallback CIdentifierStorage::ObjectCallback::fromNameA
|
|
|
result.name = typeAndName.second;
|
|
|
result.callback = callback;
|
|
|
result.optional = optional;
|
|
|
+ result.bypassDependenciesCheck = bypassDependenciesCheck;
|
|
|
result.dynamicType = false;
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
void CIdentifierStorage::requestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback) const
|
|
|
{
|
|
|
- requestIdentifier(ObjectCallback::fromNameAndType(scope, type, name, callback, false));
|
|
|
+ requestIdentifier(ObjectCallback::fromNameAndType(scope, type, name, callback, false, false));
|
|
|
}
|
|
|
|
|
|
void CIdentifierStorage::requestIdentifier(const std::string & scope, const std::string & fullName, const std::function<void(si32)> & callback) const
|
|
@@ -164,7 +165,7 @@ void CIdentifierStorage::requestIdentifier(const std::string & scope, const std:
|
|
|
|
|
|
void CIdentifierStorage::requestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback) const
|
|
|
{
|
|
|
- requestIdentifier(ObjectCallback::fromNameAndType(name.getModScope(), type, name.String(), callback, false));
|
|
|
+ requestIdentifier(ObjectCallback::fromNameAndType(name.getModScope(), type, name.String(), callback, false, false));
|
|
|
}
|
|
|
|
|
|
void CIdentifierStorage::requestIdentifier(const JsonNode & name, const std::function<void(si32)> & callback) const
|
|
@@ -172,27 +173,37 @@ void CIdentifierStorage::requestIdentifier(const JsonNode & name, const std::fun
|
|
|
requestIdentifier(ObjectCallback::fromNameWithType(name.getModScope(), name.String(), callback, false));
|
|
|
}
|
|
|
|
|
|
-void CIdentifierStorage::requestIdentifierOptional(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback) const
|
|
|
+void CIdentifierStorage::requestIdentifierIfNotNull(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback) const
|
|
|
{
|
|
|
if (!name.isNull())
|
|
|
requestIdentifier(type, name, callback);
|
|
|
}
|
|
|
|
|
|
+void CIdentifierStorage::requestIdentifierIfFound(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback) const
|
|
|
+{
|
|
|
+ requestIdentifier(ObjectCallback::fromNameAndType(name.getModScope(), type, name.String(), callback, false, true));
|
|
|
+}
|
|
|
+
|
|
|
+void CIdentifierStorage::requestIdentifierIfFound(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback) const
|
|
|
+{
|
|
|
+ requestIdentifier(ObjectCallback::fromNameAndType(scope, type, name, callback, false, true));
|
|
|
+}
|
|
|
+
|
|
|
void CIdentifierStorage::tryRequestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback) const
|
|
|
{
|
|
|
- requestIdentifier(ObjectCallback::fromNameAndType(scope, type, name, callback, true));
|
|
|
+ requestIdentifier(ObjectCallback::fromNameAndType(scope, type, name, callback, true, false));
|
|
|
}
|
|
|
|
|
|
void CIdentifierStorage::tryRequestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback) const
|
|
|
{
|
|
|
- requestIdentifier(ObjectCallback::fromNameAndType(name.getModScope(), type, name.String(), callback, true));
|
|
|
+ requestIdentifier(ObjectCallback::fromNameAndType(name.getModScope(), type, name.String(), callback, true, false));
|
|
|
}
|
|
|
|
|
|
std::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent) const
|
|
|
{
|
|
|
//assert(state != ELoadingState::LOADING);
|
|
|
|
|
|
- auto options = ObjectCallback::fromNameAndType(scope, type, name, std::function<void(si32)>(), silent);
|
|
|
+ auto options = ObjectCallback::fromNameAndType(scope, type, name, std::function<void(si32)>(), silent, false);
|
|
|
return getIdentifierImpl(options, silent);
|
|
|
}
|
|
|
|
|
@@ -200,7 +211,7 @@ std::optional<si32> CIdentifierStorage::getIdentifier(const std::string & type,
|
|
|
{
|
|
|
assert(state != ELoadingState::LOADING);
|
|
|
|
|
|
- auto options = ObjectCallback::fromNameAndType(name.getModScope(), type, name.String(), std::function<void(si32)>(), silent);
|
|
|
+ auto options = ObjectCallback::fromNameAndType(name.getModScope(), type, name.String(), std::function<void(si32)>(), silent, false);
|
|
|
|
|
|
return getIdentifierImpl(options, silent);
|
|
|
}
|
|
@@ -269,26 +280,28 @@ void CIdentifierStorage::showIdentifierResolutionErrorDetails(const ObjectCallba
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // such identifiers exists, but were not picked for some reason
|
|
|
- if (options.remoteScope.empty())
|
|
|
+ // such identifier(s) exists, but were not picked for some reason
|
|
|
+ for (auto const & testOption : testList)
|
|
|
{
|
|
|
// attempt to access identifier from mods that is not dependency
|
|
|
- for (auto const & testOption : testList)
|
|
|
+ bool isValidScope = true;
|
|
|
+ const auto & dependencies = LIBRARY->modh->getModDependencies(options.localScope, isValidScope);
|
|
|
+ if (!vstd::contains(dependencies, testOption.scope))
|
|
|
{
|
|
|
logMod->error("Identifier '%s' exists in mod %s", options.name, testOption.scope);
|
|
|
logMod->error("Please add mod '%s' as dependency of mod '%s' to access this identifier", testOption.scope, options.localScope);
|
|
|
+ continue;
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+
|
|
|
// attempt to access identifier in form 'modName:object', but identifier is only present in different mod
|
|
|
- for (auto const & testOption : testList)
|
|
|
+ if (options.remoteScope.empty())
|
|
|
{
|
|
|
logMod->error("Identifier '%s' exists in mod '%s' but identifier was explicitly requested from mod '%s'!", options.name, testOption.scope, options.remoteScope);
|
|
|
if (options.dynamicType)
|
|
|
logMod->error("Please use form '%s.%s' or '%s:%s.%s' to access this identifier", options.type, options.name, testOption.scope, options.type, options.name);
|
|
|
else
|
|
|
logMod->error("Please use form '%s' or '%s:%s' to access this identifier", options.name, testOption.scope, options.name);
|
|
|
+ continue;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -377,6 +390,11 @@ std::vector<CIdentifierStorage::ObjectData> CIdentifierStorage::getPossibleIdent
|
|
|
// allow self-access
|
|
|
allowedScopes.insert(request.remoteScope);
|
|
|
}
|
|
|
+ else if (request.bypassDependenciesCheck)
|
|
|
+ {
|
|
|
+ // this is request for an identifier that bypasses mod dependencies check
|
|
|
+ allowedScopes.insert(request.remoteScope);
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
// allow access only if mod is in our dependencies
|
|
@@ -423,6 +441,15 @@ bool CIdentifierStorage::resolveIdentifier(const ObjectCallback & request) const
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ if (request.bypassDependenciesCheck)
|
|
|
+ {
|
|
|
+ if (!vstd::contains(LIBRARY->modh->getActiveMods(), request.remoteScope))
|
|
|
+ {
|
|
|
+ logMod->debug("Mod '%s' requested identifier '%s' from not loaded mod '%s'. Ignoring.", request.localScope, request.remoteScope, request.name);
|
|
|
+ return true; // mod was not loaded - ignore
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// error found. Try to generate some debug info
|
|
|
failedRequests.push_back(request);
|
|
|
showIdentifierResolutionErrorDetails(request);
|