diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 0ccb517a33..21fb2a6ca5 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/activator types/book types/lockpick types/probe + types/types types/door types/actor types/container types/weapon types/npc types/creature types/activator types/book types/lockpick types/probe types/apparatus ) add_openmw_dir (mwsound diff --git a/apps/openmw/mwlua/types/apparatus.cpp b/apps/openmw/mwlua/types/apparatus.cpp new file mode 100644 index 0000000000..385040b3d6 --- /dev/null +++ b/apps/openmw/mwlua/types/apparatus.cpp @@ -0,0 +1,42 @@ +#include "types.hpp" + +#include + +#include + +#include "../luabindings.hpp" + +namespace sol +{ + template <> + struct is_automagical : std::false_type {}; +} + +namespace MWLua +{ + void addApparatusBindings(sol::table apparatus, const Context& context) + { + apparatus["TYPE"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs({ + {"MortarPestle", ESM::Apparatus::MortarPestle}, + {"Alembic", ESM::Apparatus::Alembic}, + {"Calcinator", ESM::Apparatus::Calcinator}, + {"Retort", ESM::Apparatus::Retort}, + })); + + const MWWorld::Store* store = &MWBase::Environment::get().getWorld()->getStore().get(); + apparatus["record"] = sol::overload( + [](const Object& obj) -> const ESM::Apparatus* { return obj.ptr().get()->mBase; }, + [store](const std::string& recordId) -> const ESM::Apparatus* { return store->find(recordId); }); + sol::usertype record = context.mLua->sol().new_usertype("ESM3_Apparatus"); + record[sol::meta_function::to_string] = [](const ESM::Apparatus& rec) { return "ESM3_Apparatus[" + rec.mId + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mId; }); + record["name"] = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mName; }); + record["model"] = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mModel; }); + record["mwscript"] = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mScript; }); + record["icon"] = sol::readonly_property([](const ESM::Apparatus& rec) -> std::string { return rec.mIcon; }); + record["type"] = sol::readonly_property([](const ESM::Apparatus& rec) -> int { return rec.mData.mType; }); + record["value"] = sol::readonly_property([](const ESM::Apparatus& rec) -> int { return rec.mData.mValue; }); + record["weight"] = sol::readonly_property([](const ESM::Apparatus& rec) -> float { return rec.mData.mWeight; }); + record["quality"] = sol::readonly_property([](const ESM::Apparatus& rec) -> float { return rec.mData.mQuality; }); + } +} diff --git a/apps/openmw/mwlua/types/types.cpp b/apps/openmw/mwlua/types/types.cpp index f52d09ba7e..a7f2322f20 100644 --- a/apps/openmw/mwlua/types/types.cpp +++ b/apps/openmw/mwlua/types/types.cpp @@ -169,7 +169,7 @@ namespace MWLua addBookBindings(addType(ObjectTypeName::Book, {ESM::REC_BOOK}, ObjectTypeName::Item), context); addLockpickBindings(addType(ObjectTypeName::Lockpick, {ESM::REC_LOCK}, ObjectTypeName::Item), context); addProbeBindings(addType(ObjectTypeName::Probe, {ESM::REC_PROB}, ObjectTypeName::Item), context); - addType(ObjectTypeName::Apparatus, {ESM::REC_APPA}, ObjectTypeName::Item); + addApparatusBindings(addType(ObjectTypeName::Apparatus, {ESM::REC_APPA}, ObjectTypeName::Item), context); addType(ObjectTypeName::Repair, {ESM::REC_REPA}, ObjectTypeName::Item); addActivatorBindings(addType(ObjectTypeName::Activator, {ESM::REC_ACTI}), context); diff --git a/apps/openmw/mwlua/types/types.hpp b/apps/openmw/mwlua/types/types.hpp index 9145752c58..655aca12e6 100644 --- a/apps/openmw/mwlua/types/types.hpp +++ b/apps/openmw/mwlua/types/types.hpp @@ -34,6 +34,7 @@ namespace MWLua void addCreatureBindings(sol::table creature, const Context& context); void addLockpickBindings(sol::table lockpick, const Context& context); void addProbeBindings(sol::table probe, const Context& context); + void addApparatusBindings(sol::table apparatus, const Context& context); } #endif // MWLUA_TYPES_H diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index be022b4ef2..b6a303cd74 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -748,6 +748,34 @@ -- @param openmw.core#GameObject object -- @return #boolean +--- Apparatus.TYPE +-- @type ApparatusTYPE +-- @field #number MortarPestle +-- @field #number Alembic +-- @field #number Calcinator +-- @field #number Retort + +--- @{#ApparatusTYPE} +-- @field [parent=#Apparatus] #ApparatusTYPE TYPE + +--- +-- Returns the read-only @{#ApparatusRecord} of an apparatus +-- @function [parent=#Apparatus] record +-- @param #any objectOrRecordId +-- @return #ApparatusRecord + +--- +-- @type ApparatusRecord +-- @field #string id The record ID of the apparatus +-- @field #string name The name of the apparatus +-- @field #string model VFS path to the model +-- @field #string mwscript MWScript on this apparatus (can be empty) +-- @field #string icon VFS path to the icon +-- @field #number type The type of apparatus. See @{#Apparatus.TYPE} +-- @field #number weight +-- @field #number value +-- @field #number quality The quality of the apparatus + --- @{#Lockpick} functions -- @field [parent=#types] #Lockpick Lockpick