1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-29 22:20:33 +00:00

Don't resolve a script's target just to get the ID

This commit is contained in:
Evil Eye 2021-03-11 20:47:26 +01:00
parent 67c8d73fe0
commit 690e5ef757
3 changed files with 26 additions and 3 deletions

@ -92,6 +92,21 @@ namespace
return false;
}
};
struct IdGettingVisitor : public boost::static_visitor<std::string>
{
std::string operator()(const MWWorld::Ptr& ptr) const
{
if(ptr.isEmpty())
return {};
return ptr.mRef->mRef.getRefId();
}
std::string operator()(const std::pair<ESM::RefNum, std::string>& pair) const
{
return pair.second;
}
};
}
namespace MWScript
@ -110,6 +125,11 @@ namespace MWScript
return ptr;
}
std::string GlobalScriptDesc::getId() const
{
return boost::apply_visitor(IdGettingVisitor(), mTarget);
}
GlobalScripts::GlobalScripts (const MWWorld::ESMStore& store)
: mStore (store)

@ -44,6 +44,8 @@ namespace MWScript
const MWWorld::Ptr* getPtrIfPresent() const; // Returns a Ptr if one has been resolved
MWWorld::Ptr getPtr(); // Resolves mTarget to a Ptr and caches the (potentially empty) result
std::string getId() const; // Returns the target's ID -- if any
};
class GlobalScripts

@ -131,9 +131,10 @@ namespace MWScript
std::string InterpreterContext::getTarget() const
{
auto ptr = getReference(false);
if(!ptr.isEmpty())
return ptr.mRef->mRef.getRefId();
if(!mReference.isEmpty())
return mReference.mRef->mRef.getRefId();
else if(mGlobalScriptDesc)
return mGlobalScriptDesc->getId();
return {};
}