mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:23:53 +00:00
Don't resolve a script's target just to get the ID
This commit is contained in:
parent
67c8d73fe0
commit
690e5ef757
3 changed files with 26 additions and 3 deletions
|
@ -92,6 +92,21 @@ namespace
|
||||||
return false;
|
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
|
namespace MWScript
|
||||||
|
@ -110,6 +125,11 @@ namespace MWScript
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string GlobalScriptDesc::getId() const
|
||||||
|
{
|
||||||
|
return boost::apply_visitor(IdGettingVisitor(), mTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
GlobalScripts::GlobalScripts (const MWWorld::ESMStore& store)
|
GlobalScripts::GlobalScripts (const MWWorld::ESMStore& store)
|
||||||
: mStore (store)
|
: mStore (store)
|
||||||
|
|
|
@ -44,6 +44,8 @@ namespace MWScript
|
||||||
const MWWorld::Ptr* getPtrIfPresent() const; // Returns a Ptr if one has been resolved
|
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
|
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
|
class GlobalScripts
|
||||||
|
|
|
@ -131,9 +131,10 @@ namespace MWScript
|
||||||
|
|
||||||
std::string InterpreterContext::getTarget() const
|
std::string InterpreterContext::getTarget() const
|
||||||
{
|
{
|
||||||
auto ptr = getReference(false);
|
if(!mReference.isEmpty())
|
||||||
if(!ptr.isEmpty())
|
return mReference.mRef->mRef.getRefId();
|
||||||
return ptr.mRef->mRef.getRefId();
|
else if(mGlobalScriptDesc)
|
||||||
|
return mGlobalScriptDesc->getId();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue