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

pull/3094/head
Evil Eye 4 years ago
parent 67c8d73fe0
commit 690e5ef757

@ -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 {};
}

Loading…
Cancel
Save