Skip to content

Commit 0490c93

Browse files
committed
Merge branch 'bodily' into 'master'
Add types.BodyPart See merge request OpenMW/openmw!5208
2 parents 0156fd2 + bae194b commit 0490c93

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 magictypebindings
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
ESM::Book tableToBook(const sol::table& rec);
3637
void addMutableBookType(sol::state_view& lua);

files/lua_api/openmw/types.lua

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

15151515

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

0 commit comments

Comments
 (0)