From aa56e40bc31e787de994a3144c07d4aafbe4505c Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 26 May 2022 01:11:22 +0000 Subject: [PATCH 1/3] Add bindings for container record --- apps/openmw/mwlua/types/container.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwlua/types/container.cpp b/apps/openmw/mwlua/types/container.cpp index b603b6d3f4..ccbbc74625 100644 --- a/apps/openmw/mwlua/types/container.cpp +++ b/apps/openmw/mwlua/types/container.cpp @@ -1,5 +1,9 @@ #include "types.hpp" +#include + +#include + #include "../luabindings.hpp" namespace MWLua @@ -13,6 +17,21 @@ namespace MWLua [](const LObject& o) { containerPtr(o); return Inventory{o}; }, [](const GObject& o) { containerPtr(o); return Inventory{o}; } ); - } + //container["capacity"] = [](const Object& o) { + //const MWWorld::Class& cls = o.ptr().getClass(); + //return cls.getCapacity(o); + //}; + const MWWorld::Store* store = &MWBase::Environment::get().getWorld()->getStore().get(); + container["record"] = sol::overload( + [](const Object& obj) -> const ESM::Container* { return obj.ptr().get()->mBase; }, + [store](const std::string& recordId) -> const ESM::Container* { return store->find(recordId); }); + sol::usertype record = context.mLua->sol().new_usertype("ESM3_Container"); + record[sol::meta_function::to_string] = [](const ESM::Container& rec) -> std::string { return "ESM3_Container[" + rec.mId + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Container& rec) -> std::string { return rec.mId; }); + record["name"] = sol::readonly_property([](const ESM::Container& rec) -> std::string { return rec.mName; }); + record["model"] = sol::readonly_property([](const ESM::Container& rec) -> std::string { return rec.mModel; }); + record["mwscript"] = sol::readonly_property([](const ESM::Container& rec) -> std::string { return rec.mScript; }); + record["weight"] = sol::readonly_property([](const ESM::Container& rec) -> float { return rec.mWeight; }); + } } From dddc1dc2bbb6e1cb3e72d498ffb4262a3f0e6ac6 Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 26 May 2022 06:41:53 +0000 Subject: [PATCH 2/3] Add bindings for capacity and encumbrance --- apps/openmw/mwlua/types/container.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwlua/types/container.cpp b/apps/openmw/mwlua/types/container.cpp index ccbbc74625..5dc7e70e6c 100644 --- a/apps/openmw/mwlua/types/container.cpp +++ b/apps/openmw/mwlua/types/container.cpp @@ -4,6 +4,9 @@ #include +//#include "../mwworld/class.hpp" +#include "apps/openmw/mwworld/class.hpp" + #include "../luabindings.hpp" namespace MWLua @@ -17,10 +20,14 @@ namespace MWLua [](const LObject& o) { containerPtr(o); return Inventory{o}; }, [](const GObject& o) { containerPtr(o); return Inventory{o}; } ); - //container["capacity"] = [](const Object& o) { - //const MWWorld::Class& cls = o.ptr().getClass(); - //return cls.getCapacity(o); - //}; + container["encumbrance"] = [](const Object& obj) -> float { + const MWWorld::Ptr& ptr = containerPtr(obj); + return ptr.getClass().getEncumbrance(ptr); + }; + container["capacity"] = [](const Object& obj) -> float { + const MWWorld::Ptr& ptr = containerPtr(obj); + return ptr.getClass().getCapacity(ptr); + }; const MWWorld::Store* store = &MWBase::Environment::get().getWorld()->getStore().get(); container["record"] = sol::overload( From e2528a1562949923c89bb5be0494f9082e32502c Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 26 May 2022 07:20:50 +0000 Subject: [PATCH 3/3] Add docs and automagical declaration --- apps/openmw/mwlua/types/container.cpp | 10 +++++++--- files/lua_api/openmw/types.lua | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwlua/types/container.cpp b/apps/openmw/mwlua/types/container.cpp index 5dc7e70e6c..729363435b 100644 --- a/apps/openmw/mwlua/types/container.cpp +++ b/apps/openmw/mwlua/types/container.cpp @@ -3,12 +3,16 @@ #include #include - -//#include "../mwworld/class.hpp" -#include "apps/openmw/mwworld/class.hpp" +#include #include "../luabindings.hpp" +namespace sol +{ + template <> + struct is_automagical : std::false_type {}; +} + namespace MWLua { diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index b77c3ec054..be022b4ef2 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -869,7 +869,31 @@ -- @param openmw.core#GameObject object -- @return #boolean +--- +-- Returns the total weight of everything in a container +-- @function [parent=#Container] encumbrance +-- @param openmw.core#GameObject object +-- @return #number +--- +-- Returns the capacity of a container +-- @function [parent=#Container] capacity +-- @param openmw.core#GameObject object +-- @return #number + +--- +-- Returns the read-only @{#ContainerRecord} of a container +-- @function [parent=#Container] record +-- @param #any objectOrRecordId +-- @return #ContainerRecord + +--- +-- @type ContainerRecord +-- @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 container (can be empty) +-- @field #number weight capacity of this container (can be empty) --- @{#Door} functions -- @field [parent=#types] #Door Door