bool CIdentifierStorage::resolveIdentifier(const ObjectCallback & request) { std::set<std::string> allowedScopes; if (request.remoteScope.empty()) { // normally ID's from all required mods, own mod and virtual "core" mod are allowed if (request.localScope != "core") allowedScopes = VLC->modh->getModData(request.localScope).dependencies; allowedScopes.insert(request.localScope); allowedScopes.insert("core"); } else { //...unless destination mod was specified explicitly auto myDeps = VLC->modh->getModData(request.localScope).dependencies; if (request.remoteScope == "core" || // allow only available to all core mod myDeps.count(request.remoteScope)) // or dependencies allowedScopes.insert(request.remoteScope); } std::string fullID = request.type + '.' + request.name; auto entries = registeredObjects.equal_range(fullID); if (entries.first != entries.second) { for (auto it = entries.first; it != entries.second; it++) { if (vstd::contains(allowedScopes, it->second.scope)) { request.callback(it->second.id); return true; } } // error found. Try to generate some debug info logGlobal->errorStream() << "Unknown identifier " << request.type << "." << request.name << " from mod " << request.localScope; for (auto it = entries.first; it != entries.second; it++) { logGlobal->errorStream() << "\tID is available in mod " << it->second.scope; } // temporary code to smooth 0.92->0.93 transition request.callback(entries.first->second.id); return true; } logGlobal->errorStream() << "Unknown identifier " << request.type << "." << request.name << " from mod " << request.localScope; return false; }
bool CIdentifierStorage::resolveIdentifier(const ObjectCallback & request) { auto identifiers = getPossibleIdentifiers(request); if (identifiers.size() == 1) // normally resolved ID { request.callback(identifiers.front().id); return true; } if (request.optional && identifiers.empty()) // failed to resolve optinal ID { return true; } // error found. Try to generate some debug info if (identifiers.size() == 0) logGlobal->errorStream() << "Unknown identifier!"; else logGlobal->errorStream() << "Ambiguous identifier request!"; logGlobal->errorStream() << "Request for " << request.type << "." << request.name << " from mod " << request.localScope; for (auto id : identifiers) { logGlobal->errorStream() << "\tID is available in mod " << id.scope; } return false; }