Skip to content

Commit 0156fd2

Browse files
committed
Merge branch 'hammertime' into 'master'
Add repair items to openmw.content See merge request OpenMW/openmw!5266
2 parents 82a4e22 + 1b37079 commit 0156fd2

5 files changed

Lines changed: 78 additions & 22 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
8282
set(OPENMW_VERSION_MAJOR 0)
8383
set(OPENMW_VERSION_MINOR 52)
8484
set(OPENMW_VERSION_RELEASE 0)
85-
set(OPENMW_LUA_API_REVISION 129)
85+
set(OPENMW_LUA_API_REVISION 130)
8686
set(OPENMW_POSTPROCESSING_API_REVISION 5)
8787

8888
set(OPENMW_VERSION_COMMITHASH "")

apps/openmw/mwlua/contentbindings.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <components/esm3/loadlock.hpp>
1111
#include <components/esm3/loadmisc.hpp>
1212
#include <components/esm3/loadprob.hpp>
13+
#include <components/esm3/loadrepa.hpp>
1314
#include <components/esm3/loadsoun.hpp>
1415
#include <components/esm3/loadspel.hpp>
1516
#include <components/esm3/loadstat.hpp>
@@ -376,6 +377,15 @@ namespace MWLua
376377
return LuaUtil::makeReadOnly(api);
377378
}
378379

380+
sol::table initRepairBindings(sol::state_view& lua, MWWorld::Store<ESM::Repair>& store)
381+
{
382+
addRecordStoreBindings<ESM::Repair>(lua, &MWLua::tableToRepair);
383+
addMutableRepairType(lua);
384+
sol::table api(lua, sol::create);
385+
api["records"] = MutableStore<ESM::Repair>{ store };
386+
return LuaUtil::makeReadOnly(api);
387+
}
388+
379389
sol::table initSpellBindings(sol::state_view& lua, MWWorld::Store<ESM::Spell>& store)
380390
{
381391
addRecordStoreBindings<ESM::Spell>(lua, &MWLua::tableToSpell);
@@ -432,6 +442,7 @@ namespace MWLua
432442
api["miscs"] = initMiscBindings(lua, esmStore.getWritable<ESM::Miscellaneous>());
433443
api["potions"] = initPotionBindings(lua, esmStore.getWritable<ESM::Potion>());
434444
api["probes"] = initProbeBindings(lua, esmStore.getWritable<ESM::Probe>());
445+
api["repairs"] = initRepairBindings(lua, esmStore.getWritable<ESM::Repair>());
435446
api["spells"] = initSpellBindings(lua, esmStore.getWritable<ESM::Spell>());
436447
api["statics"] = initStaticBindings(lua, esmStore.getWritable<ESM::Static>());
437448
api["sounds"] = initSoundBindings(lua, esmStore.getWritable<ESM::Sound>());

apps/openmw/mwlua/types/repair.cpp

Lines changed: 55 additions & 21 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/loadrepa.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,26 +17,63 @@ namespace sol
2017

2118
namespace MWLua
2219
{
23-
void addRepairBindings(sol::table repair, 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_Repair[" + rec.mId.toDebugString() + "]"; };
29+
record["id"] = sol::readonly_property([](const T& rec) -> ESM::RefId { return rec.mId; });
30+
31+
Types::addProperty(record, "name", &ESM::Repair::mName);
32+
Types::addModelProperty(record);
33+
Types::addProperty(record, "mwscript", &ESM::Repair::mScript);
34+
Types::addIconProperty(record);
35+
Types::addProperty(record, "maxCondition", &ESM::Repair::mData, &ESM::Repair::Data::mUses);
36+
Types::addProperty(record, "value", &ESM::Repair::mData, &ESM::Repair::Data::mValue);
37+
Types::addProperty(record, "weight", &ESM::Repair::mData, &ESM::Repair::Data::mWeight);
38+
Types::addProperty(record, "quality", &ESM::Repair::mData, &ESM::Repair::Data::mQuality);
39+
}
40+
}
41+
42+
ESM::Repair tableToRepair(const sol::table& rec)
43+
{
44+
auto repair = Types::initFromTemplate<ESM::Repair>(rec);
45+
if (rec["name"] != sol::nil)
46+
repair.mName = rec["name"];
47+
if (rec["model"] != sol::nil)
48+
repair.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+
repair.mScript = ESM::RefId::deserializeText(scriptId);
53+
}
54+
if (rec["icon"] != sol::nil)
55+
repair.mIcon = rec["icon"];
56+
if (rec["maxCondition"] != sol::nil)
57+
repair.mData.mUses = rec["maxCondition"];
58+
if (rec["value"] != sol::nil)
59+
repair.mData.mValue = rec["value"];
60+
if (rec["weight"] != sol::nil)
61+
repair.mData.mWeight = rec["weight"].get<Misc::FiniteFloat>();
62+
if (rec["quality"] != sol::nil)
63+
repair.mData.mQuality = rec["quality"].get<Misc::FiniteFloat>();
64+
return repair;
65+
}
66+
67+
void addMutableRepairType(sol::state_view& lua)
68+
{
69+
addUserType<MutableRecord<ESM::Repair>>(lua, "ESM3_MutableRepair");
70+
}
71+
72+
void addRepairBindings(sol::table repair, const Context& context)
73+
{
2774
addRecordFunctionBinding<ESM::Repair>(repair, context);
2875

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

apps/openmw/mwlua/types/types.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ namespace MWLua
5252
void addMutableProbeType(sol::state_view& lua);
5353
void addApparatusBindings(sol::table apparatus, const Context& context);
5454
void addRepairBindings(sol::table repair, const Context& context);
55+
ESM::Repair tableToRepair(const sol::table& rec);
56+
void addMutableRepairType(sol::state_view& lua);
5557
void addMiscellaneousBindings(sol::table miscellaneous, const Context& context);
5658
ESM::Miscellaneous tableToMisc(const sol::table& rec);
5759
void addMutableMiscType(sol::state_view& lua);

files/lua_api/openmw/content.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@
136136
-- @usage
137137
-- content.probes.records.MyProbe = { template = content.probes.records['probe_bent'], quality = 5, name = 'Alien Probe' }
138138

139+
--- @{#RepairContent}: Repair item manipulation.
140+
-- @field [parent=#content] #RepairContent repairs
141+
142+
---
143+
-- A mutable list of all @{openmw.types#RepairRecord}s.
144+
-- @field [parent=#RepairContent] #list<openmw.types#RepairRecord> records
145+
-- @usage
146+
-- content.repairs.records.MyRepair = { template = content.repairs.records['hammer_repair'], name = 'Hammer Time' }
147+
139148
--- @{#SpellContent}: Spell manipulation.
140149
-- @field [parent=#content] #SpellContent spells
141150

0 commit comments

Comments
 (0)