1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 12:32:36 +00:00
OpenMW/apps/openmw/mwlua/classbindings.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
2.4 KiB
C++
Raw Normal View History

2023-11-02 12:08:07 -05:00
#include <components/esm3/loadclas.hpp>
#include <components/lua/luastate.hpp>
2023-11-02 12:21:59 -05:00
#include "../mwbase/environment.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp"
2023-10-23 22:19:16 -05:00
#include "classbindings.hpp"
2024-02-28 17:20:46 +01:00
#include "idcollectionbindings.hpp"
2023-11-02 12:08:07 -05:00
#include "luamanagerimp.hpp"
#include "stats.hpp"
#include "types/types.hpp"
2023-10-23 22:19:16 -05:00
namespace sol
{
template <>
struct is_automagical<ESM::Class> : std::false_type
{
};
}
namespace MWLua
{
sol::table initClassRecordBindings(const Context& context)
2023-10-23 22:19:16 -05:00
{
sol::state_view& lua = context.mLua->sol();
sol::table classes(context.mLua->sol(), sol::create);
addRecordFunctionBinding<ESM::Class>(classes, context);
2023-11-02 12:17:55 -05:00
2023-10-23 22:19:16 -05:00
auto classT = lua.new_usertype<ESM::Class>("ESM3_Class");
classT[sol::meta_function::to_string]
= [](const ESM::Class& rec) -> std::string { return "ESM3_Class[" + rec.mId.toDebugString() + "]"; };
classT["id"] = sol::readonly_property([](const ESM::Class& rec) { return rec.mId.serializeText(); });
classT["name"] = sol::readonly_property([](const ESM::Class& rec) -> std::string_view { return rec.mName; });
classT["description"]
= sol::readonly_property([](const ESM::Class& rec) -> std::string_view { return rec.mDescription; });
2023-11-02 12:17:55 -05:00
2023-10-23 22:19:16 -05:00
classT["attributes"] = sol::readonly_property([lua](const ESM::Class& rec) -> sol::table {
2024-02-28 17:20:46 +01:00
return createReadOnlyRefIdTable(lua, rec.mData.mAttribute, ESM::Attribute::indexToRefId);
2023-10-23 22:19:16 -05:00
});
2023-11-17 14:51:19 -06:00
classT["majorSkills"] = sol::readonly_property([lua](const ESM::Class& rec) -> sol::table {
2024-02-28 17:20:46 +01:00
return createReadOnlyRefIdTable(
lua, rec.mData.mSkills, [](const auto& pair) { return ESM::Skill::indexToRefId(pair[1]); });
2023-11-17 14:51:19 -06:00
});
2023-10-23 22:19:16 -05:00
classT["minorSkills"] = sol::readonly_property([lua](const ESM::Class& rec) -> sol::table {
2024-02-28 17:20:46 +01:00
return createReadOnlyRefIdTable(
lua, rec.mData.mSkills, [](const auto& pair) { return ESM::Skill::indexToRefId(pair[0]); });
2023-10-23 22:19:16 -05:00
});
2023-11-02 12:17:55 -05:00
2023-11-03 17:19:53 -05:00
classT["specialization"] = sol::readonly_property([](const ESM::Class& rec) -> std::string_view {
2023-11-16 07:36:40 -06:00
return ESM::Class::specializationIndexToLuaId.at(rec.mData.mSpecialization);
2023-11-03 17:19:53 -05:00
});
2023-10-23 22:19:16 -05:00
classT["isPlayable"]
= sol::readonly_property([](const ESM::Class& rec) -> bool { return rec.mData.mIsPlayable; });
2023-11-01 13:23:32 -05:00
return LuaUtil::makeReadOnly(classes);
2023-10-23 22:19:16 -05:00
}
}