Skip to content

Commit 82a4e22

Browse files
committed
Merge branch 'wedonotcondoneburglary' into 'master'
Add lockpicks to openmw.content See merge request OpenMW/openmw!5265
2 parents dbbd945 + 12940ff commit 82a4e22

4 files changed

Lines changed: 77 additions & 23 deletions

File tree

apps/openmw/mwlua/contentbindings.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <components/esm3/loadench.hpp>
88
#include <components/esm3/loadingr.hpp>
99
#include <components/esm3/loadligh.hpp>
10+
#include <components/esm3/loadlock.hpp>
1011
#include <components/esm3/loadmisc.hpp>
1112
#include <components/esm3/loadprob.hpp>
1213
#include <components/esm3/loadsoun.hpp>
@@ -318,6 +319,15 @@ namespace MWLua
318319
return LuaUtil::makeReadOnly(api);
319320
}
320321

322+
sol::table initLockpickBindings(sol::state_view& lua, MWWorld::Store<ESM::Lockpick>& store)
323+
{
324+
addRecordStoreBindings<ESM::Lockpick>(lua, &MWLua::tableToLockpick);
325+
addMutableLockpickType(lua);
326+
sol::table api(lua, sol::create);
327+
api["records"] = MutableStore<ESM::Lockpick>{ store };
328+
return LuaUtil::makeReadOnly(api);
329+
}
330+
321331
sol::table initMagicEffectBindings(sol::state_view& lua, MWWorld::Store<ESM::MagicEffect>& store)
322332
{
323333
addRecordStoreBindings<ESM::MagicEffect>(lua, &MWLua::tableToMagicEffect);
@@ -417,6 +427,7 @@ namespace MWLua
417427
api["globals"] = initGlobalVariableBindings(lua, esmStore.getWritable<ESM::Global>());
418428
api["ingredients"] = initIngredientBindings(lua, esmStore.getWritable<ESM::Ingredient>());
419429
api["lights"] = initLightBindings(lua, esmStore.getWritable<ESM::Light>());
430+
api["lockpicks"] = initLockpickBindings(lua, esmStore.getWritable<ESM::Lockpick>());
420431
api["magicEffects"] = initMagicEffectBindings(lua, esmStore.getWritable<ESM::MagicEffect>());
421432
api["miscs"] = initMiscBindings(lua, esmStore.getWritable<ESM::Miscellaneous>());
422433
api["potions"] = initPotionBindings(lua, esmStore.getWritable<ESM::Potion>());
Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
#include "types.hpp"
22

3-
#include "modelproperty.hpp"
3+
#include "usertypeutil.hpp"
44

55
#include <components/esm3/loadlock.hpp>
66
#include <components/lua/luastate.hpp>
77
#include <components/lua/util.hpp>
88
#include <components/misc/resourcehelpers.hpp>
9-
#include <components/resource/resourcesystem.hpp>
10-
11-
#include "apps/openmw/mwbase/environment.hpp"
129

1310
namespace sol
1411
{
@@ -20,28 +17,63 @@ namespace sol
2017

2118
namespace MWLua
2219
{
23-
void addLockpickBindings(sol::table lockpick, const Context& context)
20+
namespace
2421
{
25-
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
22+
template <class T>
23+
void addUserType(sol::state_view& lua, std::string_view name)
24+
{
25+
sol::usertype<T> record = lua.new_usertype<T>(name);
2626

27+
record[sol::meta_function::to_string]
28+
= [](const T& rec) -> std::string { return "ESM3_Lockpick[" + rec.mId.toDebugString() + "]"; };
29+
record["id"] = sol::readonly_property([](const T& rec) -> ESM::RefId { return rec.mId; });
30+
31+
Types::addProperty(record, "name", &ESM::Lockpick::mName);
32+
Types::addModelProperty(record);
33+
Types::addProperty(record, "mwscript", &ESM::Lockpick::mScript);
34+
Types::addIconProperty(record);
35+
Types::addProperty(record, "maxCondition", &ESM::Lockpick::mData, &ESM::Lockpick::Data::mUses);
36+
Types::addProperty(record, "value", &ESM::Lockpick::mData, &ESM::Lockpick::Data::mValue);
37+
Types::addProperty(record, "weight", &ESM::Lockpick::mData, &ESM::Lockpick::Data::mWeight);
38+
Types::addProperty(record, "quality", &ESM::Lockpick::mData, &ESM::Lockpick::Data::mQuality);
39+
}
40+
}
41+
42+
ESM::Lockpick tableToLockpick(const sol::table& rec)
43+
{
44+
auto pick = Types::initFromTemplate<ESM::Lockpick>(rec);
45+
if (rec["name"] != sol::nil)
46+
pick.mName = rec["name"];
47+
if (rec["model"] != sol::nil)
48+
pick.mModel = Misc::ResourceHelpers::meshPathForESM3(rec["model"].get<std::string_view>());
49+
if (rec["mwscript"] != sol::nil)
50+
{
51+
std::string_view scriptId = rec["mwscript"].get<std::string_view>();
52+
pick.mScript = ESM::RefId::deserializeText(scriptId);
53+
}
54+
if (rec["icon"] != sol::nil)
55+
pick.mIcon = rec["icon"];
56+
if (rec["maxCondition"] != sol::nil)
57+
pick.mData.mUses = rec["maxCondition"];
58+
if (rec["value"] != sol::nil)
59+
pick.mData.mValue = rec["value"];
60+
if (rec["weight"] != sol::nil)
61+
pick.mData.mWeight = rec["weight"].get<Misc::FiniteFloat>();
62+
if (rec["quality"] != sol::nil)
63+
pick.mData.mQuality = rec["quality"].get<Misc::FiniteFloat>();
64+
return pick;
65+
}
66+
67+
void addMutableLockpickType(sol::state_view& lua)
68+
{
69+
addUserType<MutableRecord<ESM::Lockpick>>(lua, "ESM3_MutableLockpick");
70+
}
71+
72+
void addLockpickBindings(sol::table lockpick, const Context& context)
73+
{
2774
addRecordFunctionBinding<ESM::Lockpick>(lockpick, context);
2875

29-
sol::usertype<ESM::Lockpick> record = context.sol().new_usertype<ESM::Lockpick>("ESM3_Lockpick");
30-
record[sol::meta_function::to_string]
31-
= [](const ESM::Lockpick& rec) { return "ESM3_Lockpick[" + rec.mId.toDebugString() + "]"; };
32-
record["id"]
33-
= sol::readonly_property([](const ESM::Lockpick& rec) -> std::string { return rec.mId.serializeText(); });
34-
record["name"] = sol::readonly_property([](const ESM::Lockpick& rec) -> std::string { return rec.mName; });
35-
addModelProperty(record);
36-
record["mwscript"] = sol::readonly_property([](const ESM::Lockpick& rec) -> ESM::RefId { return rec.mScript; });
37-
record["icon"] = sol::readonly_property([vfs](const ESM::Lockpick& rec) -> std::string {
38-
return Misc::ResourceHelpers::correctIconPath(VFS::Path::toNormalized(rec.mIcon), *vfs);
39-
});
40-
record["maxCondition"]
41-
= sol::readonly_property([](const ESM::Lockpick& rec) -> int { return rec.mData.mUses; });
42-
record["value"] = sol::readonly_property([](const ESM::Lockpick& rec) -> int { return rec.mData.mValue; });
43-
record["weight"] = sol::readonly_property([](const ESM::Lockpick& rec) -> float { return rec.mData.mWeight; });
44-
record["quality"]
45-
= sol::readonly_property([](const ESM::Lockpick& rec) -> float { return rec.mData.mQuality; });
76+
sol::state_view lua = context.sol();
77+
addUserType<ESM::Lockpick>(lua, "ESM3_Lockpick");
4678
}
4779
}

apps/openmw/mwlua/types/types.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ namespace MWLua
4545
void addPlayerBindings(sol::table player, const Context& context);
4646
void addCreatureBindings(sol::table creature, const Context& context);
4747
void addLockpickBindings(sol::table lockpick, const Context& context);
48+
ESM::Lockpick tableToLockpick(const sol::table& rec);
49+
void addMutableLockpickType(sol::state_view& lua);
4850
void addProbeBindings(sol::table probe, const Context& context);
4951
ESM::Probe tableToProbe(const sol::table& rec);
5052
void addMutableProbeType(sol::state_view& lua);

files/lua_api/openmw/content.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@
9191
-- @usage
9292
-- content.lights.records.MyLight = { template = content.lights.records['torch'], duration = -1, name = 'Infinite Torch' }
9393

94+
--- @{#LockpickContent}: Lockpick manipulation.
95+
-- @field [parent=#content] #LockpickContent lockpicks
96+
97+
---
98+
-- A mutable list of all @{openmw.types#LockpickRecord}s.
99+
-- @field [parent=#LockpickContent] #list<openmw.types#LockpickRecord> records
100+
-- @usage
101+
-- content.lockpicks.records.MyLockpick = { template = content.lockpicks.records['skeleton_key'], name = 'Digipick' }
102+
94103
--- @{#MagicEffectContent}: Magic effect manipulation.
95104
-- @field [parent=#content] #MagicEffectContent magicEffects
96105

0 commit comments

Comments
 (0)