diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 2985d89579..925dbdef49 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/apparatus types/misc + types/types types/door types/actor types/container types/weapon types/npc types/creature types/activator types/book types/lockpick types/probe types/apparatus types/potion types/misc ) add_openmw_dir (mwsound diff --git a/apps/openmw/mwlua/types/potion.cpp b/apps/openmw/mwlua/types/potion.cpp new file mode 100644 index 0000000000..0d1b7e202e --- /dev/null +++ b/apps/openmw/mwlua/types/potion.cpp @@ -0,0 +1,34 @@ +#include "types.hpp" + +#include + +#include + +#include "../luabindings.hpp" + +namespace sol +{ + template <> + struct is_automagical : std::false_type {}; +} + +namespace MWLua +{ + void addPotionBindings(sol::table potion, const Context& context) + { + const MWWorld::Store* store = &MWBase::Environment::get().getWorld()->getStore().get(); + potion["record"] = sol::overload( + [](const Object& obj) -> const ESM::Potion* { return obj.ptr().get()->mBase; }, + [store](const std::string& recordId) -> const ESM::Potion* { return store->find(recordId); }); + + sol::usertype record = context.mLua->sol().new_usertype("ESM3_Potion"); + record[sol::meta_function::to_string] = [](const ESM::Potion& rec) { return "ESM3_Potion[" + rec.mId + "]"; }; + record["id"] = sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mId; }); + record["name"] = sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mName; }); + record["model"] = sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mModel; }); + record["icon"] = sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mIcon; }); + record["mwscript"] = sol::readonly_property([](const ESM::Potion& rec) -> std::string { return rec.mScript; }); + record["weight"] = sol::readonly_property([](const ESM::Potion& rec) -> float { return rec.mData.mWeight; }); + record["value"] = sol::readonly_property([](const ESM::Potion& rec) -> int { return rec.mData.mValue; }); + } +} diff --git a/apps/openmw/mwlua/types/types.cpp b/apps/openmw/mwlua/types/types.cpp index 23ce976d4f..6533696896 100644 --- a/apps/openmw/mwlua/types/types.cpp +++ b/apps/openmw/mwlua/types/types.cpp @@ -164,7 +164,7 @@ namespace MWLua addType(ObjectTypeName::Ingredient, {ESM::REC_INGR}, ObjectTypeName::Item); addType(ObjectTypeName::Light, {ESM::REC_LIGH}, ObjectTypeName::Item); addMiscellaneousBindings(addType(ObjectTypeName::MiscItem, {ESM::REC_MISC}, ObjectTypeName::Item), context); - addType(ObjectTypeName::Potion, {ESM::REC_ALCH}, ObjectTypeName::Item); + addPotionBindings(addType(ObjectTypeName::Potion, {ESM::REC_ALCH}, ObjectTypeName::Item), context); addWeaponBindings(addType(ObjectTypeName::Weapon, {ESM::REC_WEAP}, ObjectTypeName::Item), context); addBookBindings(addType(ObjectTypeName::Book, {ESM::REC_BOOK}, ObjectTypeName::Item), context); addLockpickBindings(addType(ObjectTypeName::Lockpick, {ESM::REC_LOCK}, ObjectTypeName::Item), context); diff --git a/apps/openmw/mwlua/types/types.hpp b/apps/openmw/mwlua/types/types.hpp index 464359152e..63df9a37f1 100644 --- a/apps/openmw/mwlua/types/types.hpp +++ b/apps/openmw/mwlua/types/types.hpp @@ -36,6 +36,7 @@ namespace MWLua void addProbeBindings(sol::table probe, const Context& context); void addApparatusBindings(sol::table apparatus, const Context& context); void addMiscellaneousBindings(sol::table miscellaneous, const Context& context); + void addPotionBindings(sol::table potion, const Context& context); } #endif // MWLUA_TYPES_H diff --git a/files/lua_api/openmw/types.lua b/files/lua_api/openmw/types.lua index 3504c0dcd0..b7a5948d56 100644 --- a/files/lua_api/openmw/types.lua +++ b/files/lua_api/openmw/types.lua @@ -681,6 +681,22 @@ -- @param openmw.core#GameObject object -- @return #boolean +--- +-- Returns the read-only @{#PotionRecord} of a potion +-- @function [parent=#Potion] record +-- @param #any objectOrRecordId +-- @return #PotionRecord + +--- +-- @type PotionRecord +-- @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 potion (can be empty) +-- @field #string icon VFS path to the icon +-- @field #number weight +-- @field #number value + --- @{#Weapon} functions