1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-31 06:32:39 +00:00

Revise record store, add specialization function

This commit is contained in:
Zackhasacat 2023-10-25 21:38:42 -05:00
parent 909be9cf35
commit 2f16a104dc
6 changed files with 29 additions and 33 deletions

View File

@ -1,5 +1,6 @@
#include "classbindings.hpp"
#include "stats.hpp"
#include "types/types.hpp"
#include <components/esm3/loadclas.hpp>
#include <components/lua/luastate.hpp>
@ -27,27 +28,12 @@ namespace sol
namespace MWLua
{
using classStore = MWWorld::Store<ESM::Class>;
void initCoreClassBindings(const Context& context)
sol::table initCoreClassBindings(const Context& context)
{
sol::state_view& lua = context.mLua->sol();
sol::usertype<classStore> classStoreT = lua.new_usertype<classStore>("ESM3_ClassStore");
classStoreT[sol::meta_function::to_string] = [](const classStore& store) {
return "ESM3_ClassStore{" + std::to_string(store.getSize()) + " classes}";
};
classStoreT[sol::meta_function::length] = [](const classStore& store) { return store.getSize(); };
classStoreT[sol::meta_function::index] = sol::overload(
[](const classStore& store, size_t index) -> const ESM::Class* {
if (index == 0 || index > store.getSize())
return nullptr;
return store.at(index - 1);
},
[](const classStore& store, std::string_view classId) -> const ESM::Class* {
return store.search(ESM::RefId::deserializeText(classId));
});
classStoreT[sol::meta_function::pairs] = lua["ipairsForArray"].template get<sol::function>();
classStoreT[sol::meta_function::ipairs] = lua["ipairsForArray"].template get<sol::function>();
sol::table classes(context.mLua->sol(), sol::create);
addRecordFunctionBinding<ESM::Class>(classes, context);
// class record
auto classT = lua.new_usertype<ESM::Class>("ESM3_Class");
classT[sol::meta_function::to_string]
@ -92,15 +78,10 @@ namespace MWLua
return res;
});
classT["specialization"] = sol::readonly_property([](const ESM::Class& rec) -> std::string_view {
if (rec.mData.mSpecialization == ESM::Class::Stealth)
return "stealth";
else if (rec.mData.mSpecialization == ESM::Class::Magic)
return "magic";
else
return "combat";
});
classT["specialization"] = sol::readonly_property(
[](const ESM::Class& rec) -> std::string_view { return getSpecialization(rec.mData.mSpecialization); });
classT["isPlayable"]
= sol::readonly_property([](const ESM::Class& rec) -> bool { return rec.mData.mIsPlayable; });
return classes;
}
}

View File

@ -7,7 +7,7 @@
namespace MWLua
{
void initCoreClassBindings(const Context& context);
sol::table initCoreClassBindings(const Context& context);
}
#endif // MWLUA_CLASSBINDINGS_H

View File

@ -162,8 +162,7 @@ namespace MWLua
initCoreFactionBindings(context);
character["factions"] = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>();
initCoreClassBindings(context);
character["classes"] = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>();
character["classes"] = initCoreClassBindings(context);
api["character"] = character;
api["l10n"] = LuaUtil::initL10nLoader(lua->sol(), MWBase::Environment::get().getL10nManager());
const MWWorld::Store<ESM::GameSetting>* gmstStore

View File

@ -60,6 +60,16 @@ namespace
namespace MWLua
{
std::string_view getSpecialization(const int var)
{
if (var == ESM::Class::Stealth)
return "stealth";
else if (var == ESM::Class::Magic)
return "magic";
else
return "combat";
}
static void addStatUpdateAction(MWLua::LuaManager* manager, const SelfObject& obj)
{
if (!obj.mStatsCache.empty())
@ -446,6 +456,8 @@ namespace MWLua
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["specialization"] = sol::readonly_property(
[](const ESM::Skill& rec) -> std::string_view { return getSpecialization(rec.mData.mSpecialization); });
skillT["icon"] = sol::readonly_property([vfs](const ESM::Skill& rec) -> std::string {
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
});

View File

@ -6,7 +6,7 @@
namespace MWLua
{
struct Context;
std::string_view getSpecialization(const int val);
void addActorStatsBindings(sol::table& actor, const Context& context);
void addNpcStatsBindings(sol::table& npc, const Context& context);
sol::table initCoreStatsBindings(const Context& context);

View File

@ -12,14 +12,18 @@
---
-- A read-only list of all @{#FactionRecord}s in the world database.
-- @field [parent=#core] #list<#FactionRecord> factions
-- @field [parent=#Character] #list<#FactionRecord> factions
--- @{#Character}: Class and Character Data
-- @field [parent=#core] #Character character
--- @{#Classes}: Class Data
-- @field [parent=#Character] #Classes classes
---
-- A read-only list of all @{#ClassRecord}s in the world database.
-- @field [parent=#Character] #list<#ClassRecord> classes
-- @field [parent=#Classes] #list<#ClassRecord> records
---
-- Terminates the game and quits to the OS. Should be used only for testing purposes.