1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-04-16 17:42:31 +00:00

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

Lua api for potion records

See merge request OpenMW/openmw!1961
This commit is contained in:
psi29a 2022-06-01 13:19:03 +00:00
commit 1a9fe98764
5 changed files with 53 additions and 2 deletions

View File

@ -62,7 +62,7 @@ add_openmw_dir (mwlua
luamanagerimp object worldview userdataserializer eventqueue luamanagerimp object worldview userdataserializer eventqueue
luabindings localscripts playerscripts objectbindings cellbindings asyncbindings settingsbindings luabindings localscripts playerscripts objectbindings cellbindings asyncbindings settingsbindings
camerabindings uibindings inputbindings nearbybindings postprocessingbindings stats debugbindings 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 add_openmw_dir (mwsound

View File

@ -0,0 +1,34 @@
#include "types.hpp"
#include <components/esm3/loadalch.hpp>
#include <apps/openmw/mwworld/esmstore.hpp>
#include "../luabindings.hpp"
namespace sol
{
template <>
struct is_automagical<ESM::Potion> : std::false_type {};
}
namespace MWLua
{
void addPotionBindings(sol::table potion, const Context& context)
{
const MWWorld::Store<ESM::Potion>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Potion>();
potion["record"] = sol::overload(
[](const Object& obj) -> const ESM::Potion* { return obj.ptr().get<ESM::Potion>()->mBase; },
[store](const std::string& recordId) -> const ESM::Potion* { return store->find(recordId); });
sol::usertype<ESM::Potion> record = context.mLua->sol().new_usertype<ESM::Potion>("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; });
}
}

View File

@ -164,7 +164,7 @@ namespace MWLua
addType(ObjectTypeName::Ingredient, {ESM::REC_INGR}, ObjectTypeName::Item); addType(ObjectTypeName::Ingredient, {ESM::REC_INGR}, ObjectTypeName::Item);
addType(ObjectTypeName::Light, {ESM::REC_LIGH}, ObjectTypeName::Item); addType(ObjectTypeName::Light, {ESM::REC_LIGH}, ObjectTypeName::Item);
addMiscellaneousBindings(addType(ObjectTypeName::MiscItem, {ESM::REC_MISC}, ObjectTypeName::Item), context); 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); addWeaponBindings(addType(ObjectTypeName::Weapon, {ESM::REC_WEAP}, ObjectTypeName::Item), context);
addBookBindings(addType(ObjectTypeName::Book, {ESM::REC_BOOK}, ObjectTypeName::Item), context); addBookBindings(addType(ObjectTypeName::Book, {ESM::REC_BOOK}, ObjectTypeName::Item), context);
addLockpickBindings(addType(ObjectTypeName::Lockpick, {ESM::REC_LOCK}, ObjectTypeName::Item), context); addLockpickBindings(addType(ObjectTypeName::Lockpick, {ESM::REC_LOCK}, ObjectTypeName::Item), context);

View File

@ -36,6 +36,7 @@ namespace MWLua
void addProbeBindings(sol::table probe, const Context& context); void addProbeBindings(sol::table probe, const Context& context);
void addApparatusBindings(sol::table apparatus, const Context& context); void addApparatusBindings(sol::table apparatus, const Context& context);
void addMiscellaneousBindings(sol::table miscellaneous, const Context& context); void addMiscellaneousBindings(sol::table miscellaneous, const Context& context);
void addPotionBindings(sol::table potion, const Context& context);
} }
#endif // MWLUA_TYPES_H #endif // MWLUA_TYPES_H

View File

@ -681,6 +681,22 @@
-- @param openmw.core#GameObject object -- @param openmw.core#GameObject object
-- @return #boolean -- @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 --- @{#Weapon} functions