mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-06 00:40:04 +00:00
Merge branch 'isrunning' into 'master'
add world.mwscript.isRunning See merge request OpenMW/openmw!4181
This commit is contained in:
commit
6653502567
@ -8,6 +8,7 @@
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwscript/globalscripts.hpp"
|
||||
#include "../mwworld/esmstore.hpp"
|
||||
#include "../mwworld/worldimp.hpp"
|
||||
|
||||
#include "object.hpp"
|
||||
|
||||
@ -27,6 +28,16 @@ namespace MWLua
|
||||
else
|
||||
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().getLocals(mId);
|
||||
}
|
||||
bool isRunning() const
|
||||
{
|
||||
if (mObj.has_value()) // local script
|
||||
{
|
||||
MWWorld::LocalScripts& localScripts = MWBase::Environment::get().getWorld()->getLocalScripts();
|
||||
return localScripts.isRunning(mId, mObj->ptr());
|
||||
}
|
||||
|
||||
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().isRunning(mId);
|
||||
}
|
||||
};
|
||||
struct MWScriptVariables
|
||||
{
|
||||
@ -114,6 +125,7 @@ namespace MWLua
|
||||
= context.mLua->sol().new_usertype<MWScriptVariables>("MWScriptVariables");
|
||||
mwscript[sol::meta_function::to_string]
|
||||
= [](const MWScriptRef& s) { return std::string("MWScript{") + s.mId.toDebugString() + "}"; };
|
||||
mwscript["isRunning"] = sol::readonly_property([](const MWScriptRef& s) { return s.isRunning(); });
|
||||
mwscript["recordId"] = sol::readonly_property([](const MWScriptRef& s) { return s.mId.serializeText(); });
|
||||
mwscript["variables"] = sol::readonly_property([](const MWScriptRef& s) { return MWScriptVariables{ s }; });
|
||||
mwscript["object"] = sol::readonly_property([](const MWScriptRef& s) -> sol::optional<GObject> {
|
||||
|
@ -177,3 +177,8 @@ void MWWorld::LocalScripts::remove(const Ptr& ptr)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool MWWorld::LocalScripts::isRunning(const ESM::RefId& scriptName, const Ptr& ptr) const
|
||||
{
|
||||
return std::ranges::find(mScripts, std::pair(scriptName, ptr)) != mScripts.end();
|
||||
}
|
||||
|
@ -45,6 +45,9 @@ namespace MWWorld
|
||||
|
||||
void remove(const Ptr& ptr);
|
||||
///< Remove script for given reference (ignored if reference does not have a script listed).
|
||||
|
||||
bool isRunning(const ESM::RefId&, const Ptr&) const;
|
||||
///< Is the local script running?.
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@
|
||||
-- @field #string recordId Id of the script
|
||||
-- @field openmw.core#GameObject object The object the script is attached to.
|
||||
-- @field openmw.core#GameObject player The player the script refers to.
|
||||
-- @field #boolean isRunning Whether the script is currently running
|
||||
-- @field #MWScriptVariables variables Local variables of the script (mutable)
|
||||
-- @usage
|
||||
-- for _, script in ipairs(world.mwscript.getLocalScripts(object)) do
|
||||
|
Loading…
x
Reference in New Issue
Block a user