diff --git a/apps/openmw/mwlua/types/container.cpp b/apps/openmw/mwlua/types/container.cpp index b603b6d3f4..729363435b 100644 --- a/apps/openmw/mwlua/types/container.cpp +++ b/apps/openmw/mwlua/types/container.cpp @@ -1,7 +1,18 @@ #include "types.hpp" +#include + +#include +#include + #include "../luabindings.hpp" +namespace sol +{ + template <> + struct is_automagical : std::false_type {}; +} + namespace MWLua { @@ -13,6 +24,25 @@ namespace MWLua [](const LObject& o) { containerPtr(o); return Inventory{o}; }, [](const GObject& o) { containerPtr(o); return Inventory{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( + [](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; }); + } } 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