Merge branch 'statrecords' into 'master'

Expose skill and attribute records to Lua and deprecate their enums

See merge request OpenMW/openmw!3407
macos_ci_fix
psi29a 1 year ago
commit 9791fae2db
No known key found for this signature in database

@ -42,6 +42,7 @@
#include "objectbindings.hpp" #include "objectbindings.hpp"
#include "postprocessingbindings.hpp" #include "postprocessingbindings.hpp"
#include "soundbindings.hpp" #include "soundbindings.hpp"
#include "stats.hpp"
#include "types/types.hpp" #include "types/types.hpp"
#include "uibindings.hpp" #include "uibindings.hpp"
#include "vfsbindings.hpp" #include "vfsbindings.hpp"
@ -151,6 +152,7 @@ namespace MWLua
}; };
addTimeBindings(api, context, false); addTimeBindings(api, context, false);
api["magic"] = initCoreMagicBindings(context); api["magic"] = initCoreMagicBindings(context);
api["stats"] = initCoreStatsBindings(context);
api["l10n"] = LuaUtil::initL10nLoader(lua->sol(), MWBase::Environment::get().getL10nManager()); api["l10n"] = LuaUtil::initL10nLoader(lua->sol(), MWBase::Environment::get().getL10nManager());
const MWWorld::Store<ESM::GameSetting>* gmstStore const MWWorld::Store<ESM::GameSetting>* gmstStore
= &MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>(); = &MWBase::Environment::get().getESMStore()->get<ESM::GameSetting>();

@ -8,6 +8,8 @@
#include <components/esm3/loadclas.hpp> #include <components/esm3/loadclas.hpp>
#include <components/lua/luastate.hpp> #include <components/lua/luastate.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>
#include "context.hpp" #include "context.hpp"
#include "localscripts.hpp" #include "localscripts.hpp"
@ -20,6 +22,7 @@
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "objectvariant.hpp" #include "objectvariant.hpp"
#include "types/types.hpp"
namespace namespace
{ {
@ -336,6 +339,18 @@ namespace sol
struct is_automagical<MWLua::SkillStat> : std::false_type struct is_automagical<MWLua::SkillStat> : std::false_type
{ {
}; };
template <>
struct is_automagical<ESM::Attribute> : std::false_type
{
};
template <>
struct is_automagical<ESM::Skill> : std::false_type
{
};
template <>
struct is_automagical<ESM::MagicSchool> : std::false_type
{
};
} }
namespace MWLua namespace MWLua
@ -393,4 +408,69 @@ namespace MWLua
for (const ESM::Skill& skill : MWBase::Environment::get().getESMStore()->get<ESM::Skill>()) for (const ESM::Skill& skill : MWBase::Environment::get().getESMStore()->get<ESM::Skill>())
skills[ESM::RefId(skill.mId).serializeText()] = addIndexedAccessor<SkillStat>(skill.mId); skills[ESM::RefId(skill.mId).serializeText()] = addIndexedAccessor<SkillStat>(skill.mId);
} }
sol::table initCoreStatsBindings(const Context& context)
{
sol::state_view& lua = context.mLua->sol();
sol::table statsApi(lua, sol::create);
auto* vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
sol::table attributes(lua, sol::create);
addRecordFunctionBinding<ESM::Attribute>(attributes, context);
statsApi["Attribute"] = LuaUtil::makeReadOnly(attributes);
statsApi["Attribute"][sol::metatable_key][sol::meta_function::to_string] = ESM::Attribute::getRecordType;
auto attributeT = context.mLua->sol().new_usertype<ESM::Attribute>("Attribute");
attributeT[sol::meta_function::to_string]
= [](const ESM::Attribute& rec) { return "ESM3_Attribute[" + rec.mId.toDebugString() + "]"; };
attributeT["id"] = sol::readonly_property(
[](const ESM::Attribute& rec) -> std::string { return ESM::RefId{ rec.mId }.serializeText(); });
attributeT["name"]
= sol::readonly_property([](const ESM::Attribute& rec) -> std::string_view { return rec.mName; });
attributeT["description"]
= sol::readonly_property([](const ESM::Attribute& rec) -> std::string_view { return rec.mDescription; });
attributeT["icon"] = sol::readonly_property([vfs](const ESM::Attribute& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
sol::table skills(lua, sol::create);
addRecordFunctionBinding<ESM::Skill>(skills, context);
statsApi["Skill"] = LuaUtil::makeReadOnly(skills);
statsApi["Skill"][sol::metatable_key][sol::meta_function::to_string] = ESM::Skill::getRecordType;
auto skillT = context.mLua->sol().new_usertype<ESM::Skill>("Skill");
skillT[sol::meta_function::to_string]
= [](const ESM::Skill& rec) { return "ESM3_Skill[" + rec.mId.toDebugString() + "]"; };
skillT["id"] = sol::readonly_property(
[](const ESM::Skill& rec) -> std::string { return ESM::RefId{ rec.mId }.serializeText(); });
skillT["name"] = sol::readonly_property([](const ESM::Skill& rec) -> std::string_view { return rec.mName; });
skillT["description"]
= sol::readonly_property([](const ESM::Skill& rec) -> std::string_view { return rec.mDescription; });
skillT["icon"] = sol::readonly_property([vfs](const ESM::Skill& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});
skillT["school"] = sol::readonly_property([](const ESM::Skill& rec) -> const ESM::MagicSchool* {
if (!rec.mSchool)
return nullptr;
return &*rec.mSchool;
});
auto schoolT = context.mLua->sol().new_usertype<ESM::MagicSchool>("MagicSchool");
schoolT[sol::meta_function::to_string]
= [](const ESM::MagicSchool& rec) { return "ESM3_MagicSchool[" + rec.mName + "]"; };
schoolT["name"]
= sol::readonly_property([](const ESM::MagicSchool& rec) -> std::string_view { return rec.mName; });
schoolT["areaSound"] = sol::readonly_property(
[](const ESM::MagicSchool& rec) -> std::string { return rec.mAreaSound.serializeText(); });
schoolT["boltSound"] = sol::readonly_property(
[](const ESM::MagicSchool& rec) -> std::string { return rec.mBoltSound.serializeText(); });
schoolT["castSound"] = sol::readonly_property(
[](const ESM::MagicSchool& rec) -> std::string { return rec.mCastSound.serializeText(); });
schoolT["failureSound"] = sol::readonly_property(
[](const ESM::MagicSchool& rec) -> std::string { return rec.mFailureSound.serializeText(); });
schoolT["hitSound"] = sol::readonly_property(
[](const ESM::MagicSchool& rec) -> std::string { return rec.mHitSound.serializeText(); });
return LuaUtil::makeReadOnly(statsApi);
}
} }

@ -9,6 +9,7 @@ namespace MWLua
void addActorStatsBindings(sol::table& actor, const Context& context); void addActorStatsBindings(sol::table& actor, const Context& context);
void addNpcStatsBindings(sol::table& npc, const Context& context); void addNpcStatsBindings(sol::table& npc, const Context& context);
sol::table initCoreStatsBindings(const Context& context);
} }
#endif #endif

@ -429,9 +429,10 @@
-- @usage for _, item in ipairs(inventory:findAll('common_shirt_01')) do ... end -- @usage for _, item in ipairs(inventory:findAll('common_shirt_01')) do ... end
--- Possible @{#ATTRIBUTE} values --- Possible @{#ATTRIBUTE} values (DEPRECATED use @{#Attribute})
-- @field [parent=#core] #ATTRIBUTE ATTRIBUTE -- @field [parent=#core] #ATTRIBUTE ATTRIBUTE
--- DEPRECATED, use @{#Attribute}
--- `core.ATTRIBUTE` --- `core.ATTRIBUTE`
-- @type ATTRIBUTE -- @type ATTRIBUTE
-- @field #string Strength "strength" -- @field #string Strength "strength"
@ -444,9 +445,10 @@
-- @field #string Luck "luck" -- @field #string Luck "luck"
--- Possible @{#SKILL} values --- Possible @{#SKILL} values (DEPRECATED use @{#Skill})
-- @field [parent=#core] #SKILL SKILL -- @field [parent=#core] #SKILL SKILL
--- DEPRECATED, use @{#Skill}
--- `core.SKILL` --- `core.SKILL`
-- @type SKILL -- @type SKILL
-- @field #string Acrobatics "acrobatics" -- @field #string Acrobatics "acrobatics"
@ -866,4 +868,56 @@
-- print(sound.fileName) -- print(sound.fileName)
-- end -- end
--- @{#Stats}: stats
-- @field [parent=#core] #Stats stats
--- @{#Attribute} functions
-- @field [parent=#Stats] #Attribute Attribute
--- `core.stats.Attribute`
-- @type Attribute
-- @field #list<#AttributeRecord> records A read-only list of all @{#AttributeRecord}s in the world database.
---
-- Returns a read-only @{#AttributeRecord}
-- @function [parent=#Attribute] record
-- @param #string recordId
-- @return #AttributeRecord
--- @{#Skill} functions
-- @field [parent=#Stats] #Skill Skill
--- `core.stats.Skill`
-- @type Skill
-- @field #list<#SkillRecord> records A read-only list of all @{#SkillRecord}s in the world database.
---
-- Returns a read-only @{#SkillRecord}
-- @function [parent=#Skill] record
-- @param #string recordId
-- @return #SkillRecord
-- @type AttributeRecord
-- @field #string id Record id
-- @field #string name Human-readable name
-- @field #string description Human-readable description
-- @field #string icon VFS path to the icon
-- @type SkillRecord
-- @field #string id Record id
-- @field #string name Human-readable name
-- @field #string description Human-readable description
-- @field #string icon VFS path to the icon
-- @field #MagicSchoolData school Optional magic school
-- @type MagicSchoolData
-- @field #string name Human-readable name
-- @field #string areaSound VFS path to the area sound
-- @field #string boltSound VFS path to the bolt sound
-- @field #string castSound VFS path to the cast sound
-- @field #string failureSound VFS path to the failure sound
-- @field #string hitSound VFS path to the hit sound
return nil return nil

@ -919,7 +919,7 @@
-- @field #string speechcraft "speechcraft" -- @field #string speechcraft "speechcraft"
-- @field #string unarmored "unarmored" -- @field #string unarmored "unarmored"
--- DEPRECATED, use @{openmw.core#SKILL} --- DEPRECATED, use @{openmw.core#Skill}
-- @field [parent=#Book] #BookSKILL SKILL -- @field [parent=#Book] #BookSKILL SKILL
--- ---

Loading…
Cancel
Save