1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-29 08:45:36 +00:00

Merge branch 'luaclothingbinds' into 'master'

Lua API for Clothing records

See merge request OpenMW/openmw!2723
This commit is contained in:
psi29a 2023-02-12 09:47:53 +00:00
commit bfb6bab33b
5 changed files with 109 additions and 4 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 luabindings localscripts playerscripts objectbindings cellbindings asyncbindings
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/potion types/ingredient types/misc types/repair types/armor types/light types/static 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/ingredient types/misc types/repair types/armor types/light types/static types/clothing
worker worker
) )

View file

@ -0,0 +1,68 @@
#include "types.hpp"
#include <components/esm3/loadclot.hpp>
#include <components/lua/luastate.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>
#include <apps/openmw/mwbase/environment.hpp>
#include <apps/openmw/mwbase/world.hpp>
#include <apps/openmw/mwworld/esmstore.hpp>
namespace sol
{
template <>
struct is_automagical<ESM::Clothing> : std::false_type
{
};
}
namespace MWLua
{
void addClothingBindings(sol::table clothing, const Context& context)
{
clothing["TYPE"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, int>({
{ "Amulet", ESM::Clothing::Amulet },
{ "Belt", ESM::Clothing::Belt },
{ "LGlove", ESM::Clothing::LGlove },
{ "Pants", ESM::Clothing::Pants },
{ "RGlove", ESM::Clothing::RGlove },
{ "Ring", ESM::Clothing::Ring },
{ "Robe", ESM::Clothing::Robe },
{ "Shirt", ESM::Clothing::Shirt },
{ "Shoes", ESM::Clothing::Shoes },
{ "Skirt", ESM::Clothing::Skirt },
}));
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
const MWWorld::Store<ESM::Clothing>* store
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Clothing>();
clothing["record"] = sol::overload(
[](const Object& obj) -> const ESM::Clothing* { return obj.ptr().get<ESM::Clothing>()->mBase; },
[store](const std::string& recordId) -> const ESM::Clothing* {
return store->find(ESM::RefId::stringRefId(recordId));
});
sol::usertype<ESM::Clothing> record = context.mLua->sol().new_usertype<ESM::Clothing>("ESM3_Clothing");
record[sol::meta_function::to_string]
= [](const ESM::Clothing& rec) -> std::string { return "ESM3_Clothing[" + rec.mId.getRefIdString() + "]"; };
record["id"]
= sol::readonly_property([](const ESM::Clothing& rec) -> std::string { return rec.mId.getRefIdString(); });
record["name"] = sol::readonly_property([](const ESM::Clothing& rec) -> std::string { return rec.mName; });
record["model"] = sol::readonly_property([vfs](const ESM::Clothing& rec) -> std::string {
return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs);
});
record["icon"] = sol::readonly_property([vfs](const ESM::Clothing& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
record["enchant"] = sol::readonly_property(
[](const ESM::Clothing& rec) -> std::string { return rec.mEnchant.getRefIdString(); });
record["mwscript"] = sol::readonly_property(
[](const ESM::Clothing& rec) -> std::string { return rec.mScript.getRefIdString(); });
record["weight"] = sol::readonly_property([](const ESM::Clothing& rec) -> float { return rec.mData.mWeight; });
record["value"] = sol::readonly_property([](const ESM::Clothing& rec) -> int { return rec.mData.mValue; });
record["type"] = sol::readonly_property([](const ESM::Clothing& rec) -> int { return rec.mData.mType; });
record["enchantCapacity"]
= sol::readonly_property([](const ESM::Clothing& rec) -> float { return rec.mData.mEnchant * 0.1f; });
}
}

View file

@ -159,7 +159,7 @@ namespace MWLua
addType(ObjectTypeName::Player, { ESM::REC_INTERNAL_PLAYER }, ObjectTypeName::NPC); addType(ObjectTypeName::Player, { ESM::REC_INTERNAL_PLAYER }, ObjectTypeName::NPC);
addArmorBindings(addType(ObjectTypeName::Armor, { ESM::REC_ARMO }, ObjectTypeName::Item), context); addArmorBindings(addType(ObjectTypeName::Armor, { ESM::REC_ARMO }, ObjectTypeName::Item), context);
addType(ObjectTypeName::Clothing, { ESM::REC_CLOT }, ObjectTypeName::Item); addClothingBindings(addType(ObjectTypeName::Clothing, { ESM::REC_CLOT }, ObjectTypeName::Item), context);
addIngredientBindings(addType(ObjectTypeName::Ingredient, { ESM::REC_INGR }, ObjectTypeName::Item), context); addIngredientBindings(addType(ObjectTypeName::Ingredient, { ESM::REC_INGR }, ObjectTypeName::Item), context);
addLightBindings(addType(ObjectTypeName::Light, { ESM::REC_LIGH }, ObjectTypeName::Item), context); addLightBindings(addType(ObjectTypeName::Light, { ESM::REC_LIGH }, ObjectTypeName::Item), context);
addMiscellaneousBindings(addType(ObjectTypeName::MiscItem, { ESM::REC_MISC }, ObjectTypeName::Item), context); addMiscellaneousBindings(addType(ObjectTypeName::MiscItem, { ESM::REC_MISC }, ObjectTypeName::Item), context);

View file

@ -42,6 +42,7 @@ namespace MWLua
void addPotionBindings(sol::table potion, const Context& context); void addPotionBindings(sol::table potion, const Context& context);
void addIngredientBindings(sol::table Ingredient, const Context& context); void addIngredientBindings(sol::table Ingredient, const Context& context);
void addArmorBindings(sol::table armor, const Context& context); void addArmorBindings(sol::table armor, const Context& context);
void addClothingBindings(sol::table clothing, const Context& context);
void addStaticBindings(sol::table stat, const Context& context); void addStaticBindings(sol::table stat, const Context& context);
void addLightBindings(sol::table light, const Context& context); void addLightBindings(sol::table light, const Context& context);
} }

View file

@ -649,9 +649,9 @@
-- @field #boolean isScroll -- @field #boolean isScroll
-- @field #number enchantCapacity -- @field #number enchantCapacity
--- @{#Clothing} functions --- @{#Clothing} functions
-- @field [parent=#types] #Clothing Clothing -- @field [parent=#types] #Clothing Clothing
--- ---
@ -665,6 +665,42 @@
-- @param openmw.core#GameObject object -- @param openmw.core#GameObject object
-- @return #boolean -- @return #boolean
--- Clothing.TYPE
-- @type ClothingTYPE
-- @field #number Amulet
-- @field #number Belt
-- @field #number LGlove
-- @field #number Pants
-- @field #number RGlove
-- @field #number Ring
-- @field #number Robe
-- @field #number Shirt
-- @field #number Shoes
-- @field #number Skirt
--- @{#ClothingTYPE}
-- @field [parent=#Clothing] #ClothingTYPE TYPE
---
-- Returns the read-only @{#ClothingRecord} of a Clothing
-- @function [parent=#Clothing] record
-- @param #any objectOrRecordId
-- @return #ClothingRecord
---
-- @type ClothingRecord
-- @field #string id Record id
-- @field #string name Name of the clothing
-- @field #string model VFS path to the model
-- @field #string mwscript MWScript on this clothing (can be empty)
-- @field #string icon VFS path to the icon
-- @field #string enchant The enchantment ID of this clothing (can be empty)
-- @field #number weight
-- @field #number value
-- @field #number type See @{#Clothing.TYPE}
-- @field #number enchantCapacity
--- @{#Ingredient} functions --- @{#Ingredient} functions