Skip to content

Commit bae194b

Browse files
committed
Add types.BodyPart
1 parent 3d0adb9 commit bae194b

5 files changed

Lines changed: 80 additions & 1 deletion

File tree

apps/openmw/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ add_openmw_dir (mwlua
6464
mwscriptbindings camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings dialoguebindings
6565
postprocessingbindings stats recordstore debugbindings corebindings worldbindings worker landbindings magicbindings factionbindings
6666
classbindings itemdata inputprocessor animationbindings birthsignbindings racebindings markupbindings weatherbindings regionbindings
67-
types/types types/door types/item types/actor types/container types/lockable types/weapon types/npc
67+
types/types types/door types/item types/actor types/container types/lockable types/weapon types/npc types/bodypart
6868
types/creature types/player types/activator types/book types/lockpick types/probe types/apparatus
6969
types/potion types/ingredient types/misc types/repair types/armor types/light types/static
7070
types/clothing types/levelledlist types/terminal
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "types.hpp"
2+
3+
#include "modelproperty.hpp"
4+
5+
#include <components/esm3/loadbody.hpp>
6+
#include <components/lua/luastate.hpp>
7+
8+
namespace sol
9+
{
10+
template <>
11+
struct is_automagical<ESM::BodyPart> : std::false_type
12+
{
13+
};
14+
}
15+
16+
namespace MWLua
17+
{
18+
void addBodyPartBindings(sol::table bodypart, const Context& context)
19+
{
20+
addRecordFunctionBinding<ESM::BodyPart>(bodypart, context);
21+
22+
sol::state_view lua = context.sol();
23+
sol::usertype<ESM::BodyPart> record = lua.new_usertype<ESM::BodyPart>("ESM3_BodyPart");
24+
record[sol::meta_function::to_string]
25+
= [](const ESM::BodyPart& rec) { return "ESM3_BodyPart[" + rec.mId.toDebugString() + "]"; };
26+
record["id"] = sol::readonly_property([](const ESM::BodyPart& rec) -> ESM::RefId { return rec.mId; });
27+
record["race"] = sol::readonly_property([](const ESM::BodyPart& rec) -> ESM::RefId { return rec.mRace; });
28+
addModelProperty(record);
29+
record["isFemale"] = sol::readonly_property(
30+
[](const ESM::BodyPart& rec) -> bool { return rec.mData.mFlags & ESM::BodyPart::BPF_Female; });
31+
record["isPlayable"] = sol::readonly_property(
32+
[](const ESM::BodyPart& rec) -> bool { return !(rec.mData.mFlags & ESM::BodyPart::BPF_NotPlayable); });
33+
record["isVampire"]
34+
= sol::readonly_property([](const ESM::BodyPart& rec) -> bool { return rec.mData.mVampire; });
35+
record["type"] = sol::readonly_property([](const ESM::BodyPart& rec) -> std::optional<std::string_view> {
36+
if (rec.mData.mType == ESM::BodyPart::MT_Skin)
37+
return "skin";
38+
else if (rec.mData.mType == ESM::BodyPart::MT_Clothing)
39+
return "clothing";
40+
else if (rec.mData.mType == ESM::BodyPart::MT_Armor)
41+
return "armor";
42+
return {};
43+
});
44+
}
45+
}

apps/openmw/mwlua/types/types.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace MWLua
1515

1616
constexpr std::string_view Activator = "Activator";
1717
constexpr std::string_view Armor = "Armor";
18+
constexpr std::string_view BodyPart = "BodyPart";
1819
constexpr std::string_view Book = "Book";
1920
constexpr std::string_view Clothing = "Clothing";
2021
constexpr std::string_view Container = "Container";
@@ -64,6 +65,7 @@ namespace MWLua
6465
{ ESM::REC_INTERNAL_MARKER, ObjectTypeName::Marker },
6566
{ ESM::REC_ACTI, ObjectTypeName::Activator },
6667
{ ESM::REC_ARMO, ObjectTypeName::Armor },
68+
{ ESM::REC_BODY, ObjectTypeName::BodyPart },
6769
{ ESM::REC_BOOK, ObjectTypeName::Book },
6870
{ ESM::REC_CLOT, ObjectTypeName::Clothing },
6971
{ ESM::REC_CONT, ObjectTypeName::Container },
@@ -205,6 +207,7 @@ namespace MWLua
205207
addLockableBindings(
206208
addType(ObjectTypeName::Lockable, { ESM::REC_CONT, ESM::REC_DOOR, ESM::REC_CONT4, ESM::REC_DOOR4 }));
207209

210+
addBodyPartBindings(addType(ObjectTypeName::BodyPart, { ESM::REC_BODY }), context);
208211
addCreatureBindings(addType(ObjectTypeName::Creature, { ESM::REC_CREA }, ObjectTypeName::Actor), context);
209212
addNpcBindings(
210213
addType(ObjectTypeName::NPC, { ESM::REC_INTERNAL_PLAYER, ESM::REC_NPC_ }, ObjectTypeName::Actor), context);

apps/openmw/mwlua/types/types.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace MWLua
3131
void addActivatorBindings(sol::table activator, const Context& context);
3232
ESM::Activator tableToActivator(const sol::table& rec);
3333
void addMutableActivatorType(sol::state_view& lua);
34+
void addBodyPartBindings(sol::table list, const Context& context);
3435
void addBookBindings(sol::table book, const Context& context);
3536
void addContainerBindings(sol::table container, const Context& context);
3637
void addDoorBindings(sol::table door, const Context& context);

files/lua_api/openmw/types.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,36 @@
15081508
-- world.createObject(newRecord.id):moveInto(playerActor)--Create an instance of this object, and move it into the player's inventory
15091509

15101510

1511+
--- @{#BodyPart} functions
1512+
-- @field [parent=#types] #BodyPart BodyPart
1513+
1514+
---
1515+
-- @type BodyPart
1516+
1517+
---
1518+
-- A read-only list of all @{#BodyPartRecord}s in the world database.
1519+
-- Implements [iterables#List](iterables.html#List) of #BodyPartRecord.
1520+
-- @field [parent=#BodyPart] #list<#BodyPartRecord> records
1521+
-- @usage local record = types.BodyPart.records['example_recordid']
1522+
-- @usage local record = types.BodyPart.records[1]
1523+
1524+
---
1525+
-- Whether the object is a BodyPart.
1526+
-- @function [parent=#BodyPart] objectIsInstance
1527+
-- @param openmw.core#GameObject object
1528+
-- @return #boolean
1529+
1530+
---
1531+
-- @type BodyPartRecord
1532+
-- @field #string id The record ID of the body part
1533+
-- @field #string race The id of the race of the body part
1534+
-- @field #string model VFS path to the model
1535+
-- @field #boolean isFemale Whether the body part only applies to female characters
1536+
-- @field #boolean isPlayable Whether the player can choose this part
1537+
-- @field #boolean isVampire Whether this body part is meant for vampires
1538+
-- @field #string type `armor`, `clothing`, or `skin`
1539+
1540+
15111541
--- @{#Book} functions
15121542
-- @field [parent=#types] #Book Book
15131543

0 commit comments

Comments
 (0)