mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-21 07:09:42 +00:00
Merge branch 'lua_records' into 'master'
Lua Armor, Static and Light record bindings See merge request OpenMW/openmw!2341
This commit is contained in:
commit
fdf1577918
7 changed files with 239 additions and 9 deletions
|
@ -62,7 +62,7 @@ add_openmw_dir (mwlua
|
|||
luamanagerimp object worldview userdataserializer eventqueue
|
||||
luabindings localscripts playerscripts objectbindings cellbindings asyncbindings
|
||||
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/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
|
||||
worker
|
||||
)
|
||||
|
||||
|
|
65
apps/openmw/mwlua/types/armor.cpp
Normal file
65
apps/openmw/mwlua/types/armor.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include "types.hpp"
|
||||
|
||||
#include <components/esm3/loadarmo.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::Armor> : std::false_type
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
namespace MWLua
|
||||
{
|
||||
void addArmorBindings(sol::table armor, const Context& context)
|
||||
{
|
||||
armor["TYPE"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, int>({
|
||||
{ "Helmet", ESM::Armor::Helmet },
|
||||
{ "Cuirass", ESM::Armor::Cuirass },
|
||||
{ "LPauldron", ESM::Armor::LPauldron },
|
||||
{ "RPauldron", ESM::Armor::RPauldron },
|
||||
{ "Greaves", ESM::Armor::Greaves },
|
||||
{ "Boots", ESM::Armor::Boots },
|
||||
{ "LGauntlet", ESM::Armor::LGauntlet },
|
||||
{ "RGauntlet", ESM::Armor::RGauntlet },
|
||||
{ "Shield", ESM::Armor::Shield },
|
||||
{ "LBracer", ESM::Armor::LBracer },
|
||||
{ "RBracer", ESM::Armor::RBracer },
|
||||
}));
|
||||
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
const MWWorld::Store<ESM::Armor>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Armor>();
|
||||
armor["record"]
|
||||
= sol::overload([](const Object& obj) -> const ESM::Armor* { return obj.ptr().get<ESM::Armor>()->mBase; },
|
||||
[store](const std::string& recordId) -> const ESM::Armor* { return store->find(recordId); });
|
||||
sol::usertype<ESM::Armor> record = context.mLua->sol().new_usertype<ESM::Armor>("ESM3_Armor");
|
||||
record[sol::meta_function::to_string]
|
||||
= [](const ESM::Armor& rec) -> std::string { return "ESM3_Armor[" + rec.mId + "]"; };
|
||||
record["id"] = sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mId; });
|
||||
record["name"] = sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mName; });
|
||||
record["model"] = sol::readonly_property([vfs](const ESM::Armor& rec) -> std::string {
|
||||
return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs);
|
||||
});
|
||||
record["icon"] = sol::readonly_property([vfs](const ESM::Armor& rec) -> std::string {
|
||||
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
|
||||
});
|
||||
record["enchant"] = sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mEnchant; });
|
||||
record["mwscript"] = sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mScript; });
|
||||
record["weight"] = sol::readonly_property([](const ESM::Armor& rec) -> float { return rec.mData.mWeight; });
|
||||
record["value"] = sol::readonly_property([](const ESM::Armor& rec) -> int { return rec.mData.mValue; });
|
||||
record["type"] = sol::readonly_property([](const ESM::Armor& rec) -> int { return rec.mData.mType; });
|
||||
record["health"] = sol::readonly_property([](const ESM::Armor& rec) -> int { return rec.mData.mHealth; });
|
||||
record["baseArmor"] = sol::readonly_property([](const ESM::Armor& rec) -> int { return rec.mData.mArmor; });
|
||||
record["enchantCapacity"]
|
||||
= sol::readonly_property([](const ESM::Armor& rec) -> float { return rec.mData.mEnchant * 0.1f; });
|
||||
}
|
||||
}
|
53
apps/openmw/mwlua/types/light.cpp
Normal file
53
apps/openmw/mwlua/types/light.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include "types.hpp"
|
||||
|
||||
#include <components/esm3/loadligh.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::Light> : std::false_type
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
namespace MWLua
|
||||
{
|
||||
void addLightBindings(sol::table light, const Context& context)
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
const MWWorld::Store<ESM::Light>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Light>();
|
||||
light["record"]
|
||||
= sol::overload([](const Object& obj) -> const ESM::Light* { return obj.ptr().get<ESM::Light>()->mBase; },
|
||||
[store](const std::string& recordId) -> const ESM::Light* { return store->find(recordId); });
|
||||
sol::usertype<ESM::Light> record = context.mLua->sol().new_usertype<ESM::Light>("ESM3_Light");
|
||||
record[sol::meta_function::to_string]
|
||||
= [](const ESM::Light& rec) -> std::string { return "ESM3_Light[" + rec.mId + "]"; };
|
||||
record["id"] = sol::readonly_property([](const ESM::Light& rec) -> std::string { return rec.mId; });
|
||||
record["name"] = sol::readonly_property([](const ESM::Light& rec) -> std::string { return rec.mName; });
|
||||
record["model"] = sol::readonly_property([vfs](const ESM::Light& rec) -> std::string {
|
||||
return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs);
|
||||
});
|
||||
record["icon"] = sol::readonly_property([vfs](const ESM::Light& rec) -> std::string {
|
||||
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
|
||||
});
|
||||
record["sound"] = sol::readonly_property([vfs](const ESM::Light& rec) -> std::string {
|
||||
return Misc::ResourceHelpers::correctSoundPath(rec.mSound, vfs);
|
||||
});
|
||||
record["mwscript"] = sol::readonly_property([](const ESM::Light& rec) -> std::string { return rec.mScript; });
|
||||
record["weight"] = sol::readonly_property([](const ESM::Light& rec) -> float { return rec.mData.mWeight; });
|
||||
record["value"] = sol::readonly_property([](const ESM::Light& rec) -> int { return rec.mData.mValue; });
|
||||
record["duration"] = sol::readonly_property([](const ESM::Light& rec) -> int { return rec.mData.mTime; });
|
||||
record["radius"] = sol::readonly_property([](const ESM::Light& rec) -> int { return rec.mData.mRadius; });
|
||||
record["color"] = sol::readonly_property([](const ESM::Light& rec) -> int { return rec.mData.mColor; });
|
||||
record["isCarriable"] = sol::readonly_property(
|
||||
[](const ESM::Light& rec) -> bool { return rec.mData.mFlags & ESM::Light::Carry; });
|
||||
}
|
||||
}
|
39
apps/openmw/mwlua/types/static.cpp
Normal file
39
apps/openmw/mwlua/types/static.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "types.hpp"
|
||||
|
||||
#include <components/esm3/loadstat.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::Static> : std::false_type
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
namespace MWLua
|
||||
{
|
||||
void addStaticBindings(sol::table stat, const Context& context)
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
const MWWorld::Store<ESM::Static>* store
|
||||
= &MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>();
|
||||
stat["record"]
|
||||
= sol::overload([](const Object& obj) -> const ESM::Static* { return obj.ptr().get<ESM::Static>()->mBase; },
|
||||
[store](const std::string& recordId) -> const ESM::Static* { return store->find(recordId); });
|
||||
sol::usertype<ESM::Static> record = context.mLua->sol().new_usertype<ESM::Static>("ESM3_Static");
|
||||
record[sol::meta_function::to_string]
|
||||
= [](const ESM::Static& rec) -> std::string { return "ESM3_Static[" + rec.mId + "]"; };
|
||||
record["id"] = sol::readonly_property([](const ESM::Static& rec) -> std::string { return rec.mId; });
|
||||
record["model"] = sol::readonly_property([vfs](const ESM::Static& rec) -> std::string {
|
||||
return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -158,10 +158,10 @@ namespace MWLua
|
|||
addType(ObjectTypeName::NPC, { ESM::REC_INTERNAL_PLAYER, ESM::REC_NPC_ }, ObjectTypeName::Actor), context);
|
||||
addType(ObjectTypeName::Player, { ESM::REC_INTERNAL_PLAYER }, ObjectTypeName::NPC);
|
||||
|
||||
addType(ObjectTypeName::Armor, { ESM::REC_ARMO }, ObjectTypeName::Item);
|
||||
addArmorBindings(addType(ObjectTypeName::Armor, { ESM::REC_ARMO }, ObjectTypeName::Item), context);
|
||||
addType(ObjectTypeName::Clothing, { ESM::REC_CLOT }, ObjectTypeName::Item);
|
||||
addIngredientBindings(addType(ObjectTypeName::Ingredient, { ESM::REC_INGR }, ObjectTypeName::Item), context);
|
||||
addType(ObjectTypeName::Light, { ESM::REC_LIGH }, ObjectTypeName::Item);
|
||||
addLightBindings(addType(ObjectTypeName::Light, { ESM::REC_LIGH }, ObjectTypeName::Item), context);
|
||||
addMiscellaneousBindings(addType(ObjectTypeName::MiscItem, { ESM::REC_MISC }, ObjectTypeName::Item), context);
|
||||
addPotionBindings(addType(ObjectTypeName::Potion, { ESM::REC_ALCH }, ObjectTypeName::Item), context);
|
||||
addWeaponBindings(addType(ObjectTypeName::Weapon, { ESM::REC_WEAP }, ObjectTypeName::Item), context);
|
||||
|
@ -174,7 +174,7 @@ namespace MWLua
|
|||
addActivatorBindings(addType(ObjectTypeName::Activator, { ESM::REC_ACTI }), context);
|
||||
addContainerBindings(addType(ObjectTypeName::Container, { ESM::REC_CONT }), context);
|
||||
addDoorBindings(addType(ObjectTypeName::Door, { ESM::REC_DOOR }), context);
|
||||
addType(ObjectTypeName::Static, { ESM::REC_STAT });
|
||||
addStaticBindings(addType(ObjectTypeName::Static, { ESM::REC_STAT }), context);
|
||||
|
||||
sol::table typeToPackage = getTypeToPackageTable(context.mLua->sol());
|
||||
sol::table packageToType = getPackageToTypeTable(context.mLua->sol());
|
||||
|
|
|
@ -41,6 +41,9 @@ namespace MWLua
|
|||
void addMiscellaneousBindings(sol::table miscellaneous, const Context& context);
|
||||
void addPotionBindings(sol::table potion, const Context& context);
|
||||
void addIngredientBindings(sol::table Ingredient, const Context& context);
|
||||
void addArmorBindings(sol::table armor, const Context& context);
|
||||
void addStaticBindings(sol::table stat, const Context& context);
|
||||
void addLightBindings(sol::table light, const Context& context);
|
||||
}
|
||||
|
||||
#endif // MWLUA_TYPES_H
|
||||
|
|
|
@ -114,10 +114,10 @@
|
|||
|
||||
---
|
||||
-- Get equipment.
|
||||
-- Has two overloads:
|
||||
-- Has two overloads:
|
||||
-- 1) With single argument: returns a table `slot` -> @{openmw.core#GameObject} of currently equipped items.
|
||||
-- See @{#EQUIPMENT_SLOT}. Returns empty table if the actor doesn't have
|
||||
-- equipment slots.
|
||||
-- equipment slots.
|
||||
-- 2) With two arguments: returns an item equipped to the given slot.
|
||||
-- @function [parent=#Actor] equipment
|
||||
-- @param openmw.core#GameObject actor
|
||||
|
@ -522,6 +522,44 @@
|
|||
-- @param openmw.core#GameObject object
|
||||
-- @return #boolean
|
||||
|
||||
--- Armor.TYPE
|
||||
-- @type ArmorTYPE
|
||||
-- @field #number Helmet
|
||||
-- @field #number Cuirass
|
||||
-- @field #number LPauldron
|
||||
-- @field #number RPauldron
|
||||
-- @field #number Greaves
|
||||
-- @field #number Boots
|
||||
-- @field #number LGauntlet
|
||||
-- @field #number RGauntlet
|
||||
-- @field #number Shield
|
||||
-- @field #number LBracer
|
||||
-- @field #number RBracer
|
||||
|
||||
--- @{#ArmorTYPE}
|
||||
-- @field [parent=#Armor] #ArmorTYPE TYPE
|
||||
|
||||
---
|
||||
-- Returns the read-only @{#ArmorRecord} of an Armor
|
||||
-- @function [parent=#Armor] record
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #ArmorRecord
|
||||
|
||||
---
|
||||
-- @type ArmorRecord
|
||||
-- @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 armor (can be empty)
|
||||
-- @field #string icon VFS path to the icon
|
||||
-- @field #string enchant The enchantment ID of this armor (can be empty)
|
||||
-- @field #number weight
|
||||
-- @field #number value
|
||||
-- @field #number type See @{#Armor.TYPE}
|
||||
-- @field #number health
|
||||
-- @field #number baseArmor The base armor rating of this armor
|
||||
-- @field #number enchantCapacity
|
||||
|
||||
|
||||
|
||||
--- @{#Book} functions
|
||||
|
@ -588,8 +626,8 @@
|
|||
-- @field #string text The text content of the book
|
||||
-- @field #number weight
|
||||
-- @field #number value
|
||||
-- @field #string skill The skill that this book teaches. See @{#Book.SKILL}
|
||||
-- @field #boolean isScroll
|
||||
-- @field #string skill The skill that this book teaches. See @{#Book.SKILL}
|
||||
-- @field #boolean isScroll
|
||||
-- @field #number enchantCapacity
|
||||
|
||||
--- @{#Clothing} functions
|
||||
|
@ -656,6 +694,27 @@
|
|||
-- @param openmw.core#GameObject object
|
||||
-- @return #boolean
|
||||
|
||||
---
|
||||
-- Returns the read-only @{#LightRecord} of a Light
|
||||
-- @function [parent=#Light] record
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #LightRecord
|
||||
|
||||
---
|
||||
-- @type LightRecord
|
||||
-- @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 light (can be empty)
|
||||
-- @field #string icon VFS path to the icon
|
||||
-- @field #string sound VFS path to the sound
|
||||
-- @field #number weight
|
||||
-- @field #number value
|
||||
-- @field #number duration
|
||||
-- @field #number radius
|
||||
-- @field #number color
|
||||
-- @field #boolean isCarriable
|
||||
|
||||
|
||||
|
||||
--- Functions for @{#Miscellaneous} objects
|
||||
|
@ -824,7 +883,7 @@
|
|||
-- @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 type The type of apparatus. See @{#Apparatus.TYPE}
|
||||
-- @field #number weight
|
||||
-- @field #number value
|
||||
-- @field #number quality The quality of the apparatus
|
||||
|
@ -1059,5 +1118,16 @@
|
|||
-- @param openmw.core#GameObject object
|
||||
-- @return #boolean
|
||||
|
||||
---
|
||||
-- Returns the read-only @{#StaticRecord} of a Static
|
||||
-- @function [parent=#Static] record
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #StaticRecord
|
||||
|
||||
---
|
||||
-- @type StaticRecord
|
||||
-- @field #string id Record id
|
||||
-- @field #string model VFS path to the model
|
||||
|
||||
return nil
|
||||
|
||||
|
|
Loading…
Reference in a new issue