mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 12:39:55 +00:00
Add class bindings
This commit is contained in:
parent
a08ca11c34
commit
611f96ce65
@ -64,7 +64,7 @@ add_openmw_dir (mwlua
|
|||||||
context globalscripts localscripts playerscripts luabindings objectbindings cellbindings mwscriptbindings
|
context globalscripts localscripts playerscripts luabindings objectbindings cellbindings mwscriptbindings
|
||||||
camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings postprocessingbindings stats debugbindings
|
camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings postprocessingbindings stats debugbindings
|
||||||
types/types types/door types/item types/actor types/container types/lockable types/weapon types/npc types/creature types/player types/activator types/book types/lockpick types/probe types/apparatus types/potion types/ingredient types/misc types/repair types/armor types/light types/static types/clothing types/levelledlist types/terminal
|
types/types types/door types/item types/actor types/container types/lockable types/weapon types/npc types/creature types/player types/activator types/book types/lockpick types/probe types/apparatus types/potion types/ingredient types/misc types/repair types/armor types/light types/static types/clothing types/levelledlist types/terminal
|
||||||
worker magicbindings factionbindings
|
worker magicbindings factionbindings classbindings
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwsound
|
add_openmw_dir (mwsound
|
||||||
|
106
apps/openmw/mwlua/classbindings.cpp
Normal file
106
apps/openmw/mwlua/classbindings.cpp
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
#include "classbindings.hpp"
|
||||||
|
|
||||||
|
#include <components/esm3/loadclas.hpp>
|
||||||
|
#include <components/lua/luastate.hpp>
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwworld/class.hpp"
|
||||||
|
#include "../mwworld/esmstore.hpp"
|
||||||
|
|
||||||
|
#include "luamanagerimp.hpp"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace sol
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
struct is_automagical<ESM::Class> : std::false_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
struct is_automagical<MWWorld::Store<ESM::Class>> : std::false_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace MWLua
|
||||||
|
{
|
||||||
|
using classStore = MWWorld::Store<ESM::Class>;
|
||||||
|
|
||||||
|
void 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>();
|
||||||
|
// 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; });
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
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["isPlayable"]
|
||||||
|
= sol::readonly_property([](const ESM::Class& rec) -> bool { return rec.mData.mIsPlayable; });
|
||||||
|
}
|
||||||
|
}
|
13
apps/openmw/mwlua/classbindings.hpp
Normal file
13
apps/openmw/mwlua/classbindings.hpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef MWLUA_CLASSBINDINGS_H
|
||||||
|
#define MWLUA_CLASSBINDINGS_H
|
||||||
|
|
||||||
|
#include <sol/forward.hpp>
|
||||||
|
|
||||||
|
#include "context.hpp"
|
||||||
|
|
||||||
|
namespace MWLua
|
||||||
|
{
|
||||||
|
void initCoreClassBindings(const Context& context);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MWLUA_CLASSBINDINGS_H
|
@ -7,6 +7,7 @@
|
|||||||
#include <components/esm3/loadalch.hpp>
|
#include <components/esm3/loadalch.hpp>
|
||||||
#include <components/esm3/loadarmo.hpp>
|
#include <components/esm3/loadarmo.hpp>
|
||||||
#include <components/esm3/loadbook.hpp>
|
#include <components/esm3/loadbook.hpp>
|
||||||
|
#include <components/esm3/loadclas.hpp>
|
||||||
#include <components/esm3/loadclot.hpp>
|
#include <components/esm3/loadclot.hpp>
|
||||||
#include <components/esm3/loadfact.hpp>
|
#include <components/esm3/loadfact.hpp>
|
||||||
#include <components/esm3/loadmisc.hpp>
|
#include <components/esm3/loadmisc.hpp>
|
||||||
@ -36,6 +37,7 @@
|
|||||||
|
|
||||||
#include "camerabindings.hpp"
|
#include "camerabindings.hpp"
|
||||||
#include "cellbindings.hpp"
|
#include "cellbindings.hpp"
|
||||||
|
#include "classbindings.hpp"
|
||||||
#include "debugbindings.hpp"
|
#include "debugbindings.hpp"
|
||||||
#include "factionbindings.hpp"
|
#include "factionbindings.hpp"
|
||||||
#include "inputbindings.hpp"
|
#include "inputbindings.hpp"
|
||||||
@ -159,6 +161,9 @@ namespace MWLua
|
|||||||
initCoreFactionBindings(context);
|
initCoreFactionBindings(context);
|
||||||
api["factions"] = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>();
|
api["factions"] = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Faction>();
|
||||||
|
|
||||||
|
initCoreClassBindings(context);
|
||||||
|
api["class"] = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Class>();
|
||||||
|
|
||||||
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>();
|
||||||
|
@ -14,6 +14,10 @@
|
|||||||
-- A read-only list of all @{#FactionRecord}s in the world database.
|
-- A read-only list of all @{#FactionRecord}s in the world database.
|
||||||
-- @field [parent=#core] #list<#FactionRecord> factions
|
-- @field [parent=#core] #list<#FactionRecord> factions
|
||||||
|
|
||||||
|
---
|
||||||
|
-- A read-only list of all @{#ClassRecord}s in the world database.
|
||||||
|
-- @field [parent=#core] #list<#ClassRecord> class
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Terminates the game and quits to the OS. Should be used only for testing purposes.
|
-- Terminates the game and quits to the OS. Should be used only for testing purposes.
|
||||||
-- @function [parent=#core] quit
|
-- @function [parent=#core] quit
|
||||||
@ -868,6 +872,18 @@
|
|||||||
-- @field #string failureSound VFS path to the failure sound
|
-- @field #string failureSound VFS path to the failure sound
|
||||||
-- @field #string hitSound VFS path to the hit sound
|
-- @field #string hitSound VFS path to the hit sound
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Class data record
|
||||||
|
-- @type ClassRecord
|
||||||
|
-- @field #string id Class id
|
||||||
|
-- @field #string name Class name
|
||||||
|
-- @field #list<#string> attributes A read-only list containing the specialized attributes of the class.
|
||||||
|
-- @field #list<#string> majorSkills A read-only list containing the major skills of the class.
|
||||||
|
-- @field #list<#string> minorSkills A read-only list containing the minor skills of the class.
|
||||||
|
-- @field #string description Class description
|
||||||
|
-- @field #string specialization Class specialization. Either combat, magic, or stealth.
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Faction data record
|
-- Faction data record
|
||||||
-- @type FactionRecord
|
-- @type FactionRecord
|
||||||
|
Loading…
x
Reference in New Issue
Block a user