2023-11-02 17:08:07 +00:00
|
|
|
#include <components/esm3/loadclas.hpp>
|
|
|
|
#include <components/lua/luastate.hpp>
|
|
|
|
|
2023-11-02 17:21:59 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
2023-10-24 03:19:16 +00:00
|
|
|
#include "classbindings.hpp"
|
2023-11-02 17:08:07 +00:00
|
|
|
#include "luamanagerimp.hpp"
|
2023-10-26 02:38:42 +00:00
|
|
|
#include "stats.hpp"
|
|
|
|
#include "types/types.hpp"
|
2023-10-24 03:19:16 +00:00
|
|
|
|
|
|
|
namespace sol
|
|
|
|
{
|
|
|
|
template <>
|
|
|
|
struct is_automagical<ESM::Class> : std::false_type
|
|
|
|
{
|
|
|
|
};
|
|
|
|
template <>
|
|
|
|
struct is_automagical<MWWorld::Store<ESM::Class>> : std::false_type
|
|
|
|
{
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWLua
|
|
|
|
{
|
|
|
|
|
2023-10-26 02:38:42 +00:00
|
|
|
sol::table initCoreClassBindings(const Context& context)
|
2023-10-24 03:19:16 +00:00
|
|
|
{
|
|
|
|
sol::state_view& lua = context.mLua->sol();
|
2023-10-26 02:38:42 +00:00
|
|
|
sol::table classes(context.mLua->sol(), sol::create);
|
|
|
|
addRecordFunctionBinding<ESM::Class>(classes, context);
|
2023-11-02 17:17:55 +00:00
|
|
|
|
2023-10-24 03:19:16 +00:00
|
|
|
// class record
|
|
|
|
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 17:17:55 +00:00
|
|
|
|
2023-10-24 03:19:16 +00:00
|
|
|
classT["majorSkills"] = sol::readonly_property([lua](const ESM::Class& rec) -> sol::table {
|
|
|
|
sol::table res(lua, sol::create);
|
|
|
|
auto skills = rec.mData.mSkills;
|
|
|
|
for (size_t i = 0; i < skills.size(); ++i)
|
|
|
|
{
|
|
|
|
ESM::RefId skillId = ESM::Skill::indexToRefId(skills[i][1]);
|
|
|
|
res[i + 1] = skillId.serializeText();
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
});
|
|
|
|
classT["attributes"] = sol::readonly_property([lua](const ESM::Class& rec) -> sol::table {
|
|
|
|
sol::table res(lua, sol::create);
|
|
|
|
auto attribute = rec.mData.mAttribute;
|
|
|
|
for (size_t i = 0; i < attribute.size(); ++i)
|
|
|
|
{
|
|
|
|
ESM::RefId attributeId = ESM::Attribute::indexToRefId(attribute[i]);
|
|
|
|
res[i + 1] = attributeId.serializeText();
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
});
|
|
|
|
classT["minorSkills"] = sol::readonly_property([lua](const ESM::Class& rec) -> sol::table {
|
|
|
|
sol::table res(lua, sol::create);
|
|
|
|
auto skills = rec.mData.mSkills;
|
|
|
|
for (size_t i = 0; i < skills.size(); ++i)
|
|
|
|
{
|
|
|
|
ESM::RefId skillId = ESM::Skill::indexToRefId(skills[i][0]);
|
|
|
|
res[i + 1] = skillId.serializeText();
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
});
|
2023-11-02 17:17:55 +00:00
|
|
|
|
2023-11-03 22:19:53 +00:00
|
|
|
classT["specialization"] = sol::readonly_property([](const ESM::Class& rec) -> std::string_view {
|
2023-11-07 18:01:54 +00:00
|
|
|
return ESM::Class::specilizationIndexToLuaId.at(rec.mData.mSpecialization);
|
2023-11-03 22:19:53 +00:00
|
|
|
});
|
2023-10-24 03:19:16 +00:00
|
|
|
classT["isPlayable"]
|
|
|
|
= sol::readonly_property([](const ESM::Class& rec) -> bool { return rec.mData.mIsPlayable; });
|
2023-11-01 18:23:32 +00:00
|
|
|
return LuaUtil::makeReadOnly(classes);
|
2023-10-24 03:19:16 +00:00
|
|
|
}
|
|
|
|
}
|