1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-13 22:06:58 +02:00

Introduced "map" scope for accessing identifier on map loading.

Currently it allows access to all mods, should be restricted to mods
that map depends on
This commit is contained in:
Ivan Savenko 2022-11-29 22:31:33 +02:00
parent a6b92fc152
commit abe11aaf54
4 changed files with 20 additions and 11 deletions

View File

@ -208,8 +208,14 @@ std::vector<CIdentifierStorage::ObjectData> CIdentifierStorage::getPossibleIdent
if (request.remoteScope.empty()) if (request.remoteScope.empty())
{ {
if (request.localScope == "map")
{
for (auto const & modName : VLC->modh->getActiveMods())
allowedScopes.insert(modName);
}
// normally ID's from all required mods, own mod and virtual "core" mod are allowed // normally ID's from all required mods, own mod and virtual "core" mod are allowed
if(request.localScope != "core" && !request.localScope.empty()) else if(request.localScope != "core" && !request.localScope.empty())
{ {
allowedScopes = VLC->modh->getModDependencies(request.localScope, isValidScope); allowedScopes = VLC->modh->getModDependencies(request.localScope, isValidScope);
@ -222,23 +228,26 @@ std::vector<CIdentifierStorage::ObjectData> CIdentifierStorage::getPossibleIdent
else else
{ {
//...unless destination mod was specified explicitly //...unless destination mod was specified explicitly
//note: getModDependencies does not work for "core" by design
//for map format support core mod has access to any mod if(request.remoteScope == "core" )
//TODO: better solution for access from map?
if(request.localScope == "core" || request.localScope.empty())
{ {
//"core" mod is an implicit dependency for all mods, allow access into it
allowedScopes.insert(request.remoteScope);
}
else if(request.remoteScope == request.localScope )
{
// allow self-access
allowedScopes.insert(request.remoteScope); allowedScopes.insert(request.remoteScope);
} }
else else
{ {
// allow only available to all core mod or dependencies // allow access only if mod is in our dependencies
auto myDeps = VLC->modh->getModDependencies(request.localScope, isValidScope); auto myDeps = VLC->modh->getModDependencies(request.localScope, isValidScope);
if(!isValidScope) if(!isValidScope)
return std::vector<ObjectData>(); return std::vector<ObjectData>();
if(request.remoteScope == "core" || request.remoteScope == request.localScope || myDeps.count(request.remoteScope)) if(myDeps.count(request.remoteScope))
allowedScopes.insert(request.remoteScope); allowedScopes.insert(request.remoteScope);
} }
} }

View File

@ -319,9 +319,9 @@ TObjectTypeHandler CObjectClassesHandler::getHandlerFor(si32 type, si32 subtype)
throw std::runtime_error("Object type handler not found"); throw std::runtime_error("Object type handler not found");
} }
TObjectTypeHandler CObjectClassesHandler::getHandlerFor(std::string type, std::string subtype) const TObjectTypeHandler CObjectClassesHandler::getHandlerFor(std::string scope, std::string type, std::string subtype) const
{ {
boost::optional<si32> id = VLC->modh->identifiers.getIdentifier("core", "object", type, false); boost::optional<si32> id = VLC->modh->identifiers.getIdentifier(scope, "object", type, false);
if(id) if(id)
{ {
auto object = objects.at(id.get()); auto object = objects.at(id.get());

View File

@ -303,7 +303,7 @@ public:
/// returns handler for specified object (ID-based). ObjectHandler keeps ownership /// returns handler for specified object (ID-based). ObjectHandler keeps ownership
TObjectTypeHandler getHandlerFor(si32 type, si32 subtype) const; TObjectTypeHandler getHandlerFor(si32 type, si32 subtype) const;
TObjectTypeHandler getHandlerFor(std::string type, std::string subtype) const; TObjectTypeHandler getHandlerFor(std::string scope, std::string type, std::string subtype) const;
TObjectTypeHandler getHandlerFor(CompoundMapObjectID compoundIdentifier) const; TObjectTypeHandler getHandlerFor(CompoundMapObjectID compoundIdentifier) const;
std::string getObjectName(si32 type) const; std::string getObjectName(si32 type) const;

View File

@ -1121,7 +1121,7 @@ void CMapLoaderJson::MapObjectLoader::construct()
return; return;
} }
auto handler = VLC->objtypeh->getHandlerFor(typeName, subtypeName); auto handler = VLC->objtypeh->getHandlerFor( "map", typeName, subtypeName);
auto appearance = new ObjectTemplate; auto appearance = new ObjectTemplate;