From 93aae5e116b8ef3abacf0f9bddde8f14dba7ea72 Mon Sep 17 00:00:00 2001 From: kuyondo Date: Thu, 19 May 2022 04:23:22 +0800 Subject: [PATCH] Add lua binding for activators --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwlua/types/activator.cpp | 30 +++++++++++++++++++++++++++ apps/openmw/mwlua/types/types.cpp | 2 +- apps/openmw/mwlua/types/types.hpp | 1 + files/lua_api/openmw/types.lua | 13 ++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 apps/openmw/mwlua/types/activator.cpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index f0ee1639a1..b4a8bdac80 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -62,7 +62,7 @@ add_openmw_dir (mwlua luamanagerimp object worldview userdataserializer eventqueue luabindings localscripts playerscripts objectbindings cellbindings asyncbindings settingsbindings camerabindings uibindings inputbindings nearbybindings postprocessingbindings stats debugbindings - types/types types/door types/actor types/container types/weapon types/npc types/creature + types/types types/door types/actor types/container types/weapon types/npc types/creature types/activator ) add_openmw_dir (mwsound diff --git a/apps/openmw/mwlua/types/activator.cpp b/apps/openmw/mwlua/types/activator.cpp new file mode 100644 index 0000000000..825a464878 --- /dev/null +++ b/apps/openmw/mwlua/types/activator.cpp @@ -0,0 +1,30 @@ +#include "types.hpp" + +#include + +#include + +#include "../luabindings.hpp" + +namespace sol +{ + template <> + struct is_automagical : std::false_type {}; +} + +namespace MWLua +{ + void addActivatorBindings(sol::table activator, const Context& context) + { + const MWWorld::Store* store = &MWBase::Environment::get().getWorld()->getStore().get(); + activator["record"] = sol::overload( + [](const Object& obj) -> const ESM::Activator* { return obj.ptr().get()->mBase; }, + [store](const std::string& recordId) -> const ESM::Activator* { return store->find(recordId); }); + sol::usertype record = context.mLua->sol().new_usertype("ESM3_Activator"); + record[sol::meta_function::to_string] = [](const ESM::Activator& rec) { return "ESM3_Activator[" + rec.mId + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Activator& rec) -> std::string { return rec.mId; }); + record["name"] = sol::readonly_property([](const ESM::Activator& rec) -> std::string { return rec.mName; }); + record["model"] = sol::readonly_property([](const ESM::Activator& rec) -> std::string { return rec.mModel; }); + record["mwscript"] = sol::readonly_property([](const ESM::Activator& rec) -> std::string { return rec.mScript; }); + } +} diff --git a/apps/openmw/mwlua/types/types.cpp b/apps/openmw/mwlua/types/types.cpp index f8b20ea59c..bc707059e8 100644 --- a/apps/openmw/mwlua/types/types.cpp +++ b/apps/openmw/mwlua/types/types.cpp @@ -172,7 +172,7 @@ namespace MWLua addType(ObjectTypeName::Probe, {ESM::REC_PROB}, ObjectTypeName::Item); addType(ObjectTypeName::Repair, {ESM::REC_REPA}, ObjectTypeName::Item); - addType(ObjectTypeName::Activator, {ESM::REC_ACTI}); + addActivatorBindings(addType(ObjectTypeName::Activator, {ESM::REC_ACTI}), context); addContainerBindings(addType(ObjectTypeName::Container, {ESM::REC_CONT}), context); addDoorBindings(addType(ObjectTypeName::Door, {ESM::REC_DOOR}), context); addType(ObjectTypeName::Static, {ESM::REC_STAT}); diff --git a/apps/openmw/mwlua/types/types.hpp b/apps/openmw/mwlua/types/types.hpp index bd4cb5e384..8373162995 100644 --- a/apps/openmw/mwlua/types/types.hpp +++ b/apps/openmw/mwlua/types/types.hpp @@ -24,6 +24,7 @@ namespace MWLua sol::table initTypesPackage(const Context& context); // used in initTypesPackage + void addActivatorBindings(sol::table activator, const Context& context); void addContainerBindings(sol::table container, const Context& context); void addDoorBindings(sol::table door, const Context& context); void addActorBindings(sol::table actor, const Context& context); diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index 93498dab06..257d926b50 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -748,6 +748,19 @@ -- @param openmw.core#GameObject object -- @return #boolean +--- +-- Returns the read-only @{#ActivatorRecord} of an activator +-- @function [parent=#Activator] record +-- @param #any objectOrRecordId +-- @return #ActivatorRecord + +--- +-- @type ActivatorRecord +-- @field #string id Record id +-- @field #string name Human-readable name +-- @field #string model VFS path to the model +-- @field #string mwscript MWScript on this activator (can be empty) + --- @{#Container} functions -- @field [parent=#types] #Container Container