Skip to content

Commit

Permalink
Merge branch 'isrunning' into 'master'
Browse files Browse the repository at this point in the history
add world.mwscript.isRunning

See merge request OpenMW/openmw!4181
  • Loading branch information
psi29a committed Jun 18, 2024
2 parents 02bcd17 + ecb07c9 commit 6653502
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/openmw/mwlua/mwscriptbindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../mwbase/world.hpp"
#include "../mwscript/globalscripts.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwworld/worldimp.hpp"

#include "object.hpp"

Expand All @@ -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
{
Expand Down Expand Up @@ -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> {
Expand Down
5 changes: 5 additions & 0 deletions apps/openmw/mwworld/localscripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
3 changes: 3 additions & 0 deletions apps/openmw/mwworld/localscripts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?.
};
}

Expand Down
1 change: 1 addition & 0 deletions files/lua_api/openmw/world.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6653502

Please sign in to comment.