1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-29 10:41:34 +00:00

Merge branch 'lua-api-containers' into 'master'

Add bindings for container record

See merge request OpenMW/openmw!1932
This commit is contained in:
psi29a 2022-05-28 08:03:13 +00:00
commit f84be8c3f9
2 changed files with 55 additions and 1 deletions

View file

@ -1,7 +1,18 @@
#include "types.hpp"
#include <components/esm3/loadcont.hpp>
#include <apps/openmw/mwworld/esmstore.hpp>
#include <apps/openmw/mwworld/class.hpp>
#include "../luabindings.hpp"
namespace sol
{
template <>
struct is_automagical<ESM::Container> : std::false_type {};
}
namespace MWLua
{
@ -13,6 +24,25 @@ namespace MWLua
[](const LObject& o) { containerPtr(o); return Inventory<LObject>{o}; },
[](const GObject& o) { containerPtr(o); return Inventory<GObject>{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<ESM::Container>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Container>();
container["record"] = sol::overload(
[](const Object& obj) -> const ESM::Container* { return obj.ptr().get<ESM::Container>()->mBase; },
[store](const std::string& recordId) -> const ESM::Container* { return store->find(recordId); });
sol::usertype<ESM::Container> record = context.mLua->sol().new_usertype<ESM::Container>("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; });
}
}

View file

@ -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