Lua API for Apparatus records

fix/shrink_builds
Kindi 3 years ago committed by Petr Mikheev
parent f84be8c3f9
commit 3d0adf259b

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

@ -0,0 +1,42 @@
#include "types.hpp"
#include <components/esm3/loadappa.hpp>
#include <apps/openmw/mwworld/esmstore.hpp>
#include "../luabindings.hpp"
namespace sol
{
template <>
struct is_automagical<ESM::Apparatus> : std::false_type {};
}
namespace MWLua
{
void addApparatusBindings(sol::table apparatus, const Context& context)
{
apparatus["TYPE"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, int>({
{"MortarPestle", ESM::Apparatus::MortarPestle},
{"Alembic", ESM::Apparatus::Alembic},
{"Calcinator", ESM::Apparatus::Calcinator},
{"Retort", ESM::Apparatus::Retort},
}));
const MWWorld::Store<ESM::Apparatus>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Apparatus>();
apparatus["record"] = sol::overload(
[](const Object& obj) -> const ESM::Apparatus* { return obj.ptr().get<ESM::Apparatus>()->mBase; },
[store](const std::string& recordId) -> const ESM::Apparatus* { return store->find(recordId); });
sol::usertype<ESM::Apparatus> record = context.mLua->sol().new_usertype<ESM::Apparatus>("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; });
}
}

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

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

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

Loading…
Cancel
Save