mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-06 00:40:04 +00:00
add mwscript.isRunning
This commit is contained in:
parent
cb14af943d
commit
ecb07c9bc7
@ -8,6 +8,7 @@
|
|||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
#include "../mwscript/globalscripts.hpp"
|
#include "../mwscript/globalscripts.hpp"
|
||||||
#include "../mwworld/esmstore.hpp"
|
#include "../mwworld/esmstore.hpp"
|
||||||
|
#include "../mwworld/worldimp.hpp"
|
||||||
|
|
||||||
#include "object.hpp"
|
#include "object.hpp"
|
||||||
|
|
||||||
@ -27,6 +28,16 @@ namespace MWLua
|
|||||||
else
|
else
|
||||||
return MWBase::Environment::get().getScriptManager()->getGlobalScripts().getLocals(mId);
|
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
|
struct MWScriptVariables
|
||||||
{
|
{
|
||||||
@ -114,6 +125,7 @@ namespace MWLua
|
|||||||
= context.mLua->sol().new_usertype<MWScriptVariables>("MWScriptVariables");
|
= context.mLua->sol().new_usertype<MWScriptVariables>("MWScriptVariables");
|
||||||
mwscript[sol::meta_function::to_string]
|
mwscript[sol::meta_function::to_string]
|
||||||
= [](const MWScriptRef& s) { return std::string("MWScript{") + s.mId.toDebugString() + "}"; };
|
= [](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["recordId"] = sol::readonly_property([](const MWScriptRef& s) { return s.mId.serializeText(); });
|
||||||
mwscript["variables"] = sol::readonly_property([](const MWScriptRef& s) { return MWScriptVariables{ s }; });
|
mwscript["variables"] = sol::readonly_property([](const MWScriptRef& s) { return MWScriptVariables{ s }; });
|
||||||
mwscript["object"] = sol::readonly_property([](const MWScriptRef& s) -> sol::optional<GObject> {
|
mwscript["object"] = sol::readonly_property([](const MWScriptRef& s) -> sol::optional<GObject> {
|
||||||
|
@ -177,3 +177,8 @@ void MWWorld::LocalScripts::remove(const Ptr& ptr)
|
|||||||
break;
|
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);
|
void remove(const Ptr& ptr);
|
||||||
///< Remove script for given reference (ignored if reference does not have a script listed).
|
///< 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 #string recordId Id of the script
|
||||||
-- @field openmw.core#GameObject object The object the script is attached to.
|
-- @field openmw.core#GameObject object The object the script is attached to.
|
||||||
-- @field openmw.core#GameObject player The player the script refers 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)
|
-- @field #MWScriptVariables variables Local variables of the script (mutable)
|
||||||
-- @usage
|
-- @usage
|
||||||
-- for _, script in ipairs(world.mwscript.getLocalScripts(object)) do
|
-- for _, script in ipairs(world.mwscript.getLocalScripts(object)) do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user