mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-27 04:10:24 +00:00
Expose birth signs to Lua
This commit is contained in:
parent
7793a6d0d9
commit
f7aa9f8d94
5 changed files with 94 additions and 1 deletions
|
@ -64,7 +64,7 @@ add_openmw_dir (mwlua
|
||||||
context menuscripts globalscripts localscripts playerscripts luabindings objectbindings cellbindings
|
context menuscripts globalscripts localscripts playerscripts luabindings objectbindings cellbindings
|
||||||
mwscriptbindings camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings
|
mwscriptbindings camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings
|
||||||
postprocessingbindings stats debugbindings corebindings worldbindings worker magicbindings factionbindings
|
postprocessingbindings stats debugbindings corebindings worldbindings worker magicbindings factionbindings
|
||||||
classbindings itemdata inputprocessor animationbindings
|
classbindings itemdata inputprocessor animationbindings birthsignbindings
|
||||||
types/types types/door types/item types/actor types/container types/lockable types/weapon types/npc
|
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/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/potion types/ingredient types/misc types/repair types/armor types/light types/static
|
||||||
|
|
55
apps/openmw/mwlua/birthsignbindings.cpp
Normal file
55
apps/openmw/mwlua/birthsignbindings.cpp
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
#include <components/esm3/loadbsgn.hpp>
|
||||||
|
#include <components/lua/luastate.hpp>
|
||||||
|
#include <components/misc/resourcehelpers.hpp>
|
||||||
|
#include <components/resource/resourcesystem.hpp>
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwworld/class.hpp"
|
||||||
|
#include "../mwworld/esmstore.hpp"
|
||||||
|
|
||||||
|
#include "birthsignbindings.hpp"
|
||||||
|
#include "luamanagerimp.hpp"
|
||||||
|
#include "types/types.hpp"
|
||||||
|
|
||||||
|
namespace sol
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
struct is_automagical<ESM::BirthSign> : std::false_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
struct is_automagical<MWWorld::Store<ESM::BirthSign>> : std::false_type
|
||||||
|
{
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace MWLua
|
||||||
|
{
|
||||||
|
sol::table initCoreBirthSignBindings(const Context& context)
|
||||||
|
{
|
||||||
|
sol::state_view& lua = context.mLua->sol();
|
||||||
|
sol::table birthSigns(context.mLua->sol(), sol::create);
|
||||||
|
addRecordFunctionBinding<ESM::BirthSign>(birthSigns, context);
|
||||||
|
|
||||||
|
auto signT = lua.new_usertype<ESM::BirthSign>("ESM3_BirthSign");
|
||||||
|
signT[sol::meta_function::to_string] = [](const ESM::BirthSign& rec) -> std::string {
|
||||||
|
return "ESM3_BirthSign[" + rec.mId.toDebugString() + "]";
|
||||||
|
};
|
||||||
|
signT["id"] = sol::readonly_property([](const ESM::BirthSign& rec) { return rec.mId.serializeText(); });
|
||||||
|
signT["name"] = sol::readonly_property([](const ESM::BirthSign& rec) -> std::string_view { return rec.mName; });
|
||||||
|
signT["description"]
|
||||||
|
= sol::readonly_property([](const ESM::BirthSign& rec) -> std::string_view { return rec.mDescription; });
|
||||||
|
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||||
|
signT["texture"] = sol::readonly_property([vfs](const ESM::BirthSign& rec) -> std::string {
|
||||||
|
return Misc::ResourceHelpers::correctTexturePath(rec.mTexture, vfs);
|
||||||
|
});
|
||||||
|
signT["spells"] = sol::readonly_property([lua](const ESM::BirthSign& rec) -> sol::table {
|
||||||
|
sol::table res(lua, sol::create);
|
||||||
|
for (size_t i = 0; i < rec.mPowers.mList.size(); ++i)
|
||||||
|
res[i + 1] = rec.mPowers.mList[i].serializeText();
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
|
||||||
|
return LuaUtil::makeReadOnly(birthSigns);
|
||||||
|
}
|
||||||
|
}
|
13
apps/openmw/mwlua/birthsignbindings.hpp
Normal file
13
apps/openmw/mwlua/birthsignbindings.hpp
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#ifndef MWLUA_BIRTHSIGNBINDINGS_H
|
||||||
|
#define MWLUA_BIRTHSIGNBINDINGS_H
|
||||||
|
|
||||||
|
#include <sol/forward.hpp>
|
||||||
|
|
||||||
|
#include "context.hpp"
|
||||||
|
|
||||||
|
namespace MWLua
|
||||||
|
{
|
||||||
|
sol::table initCoreBirthSignBindings(const Context& context);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MWLUA_BIRTHSIGNBINDINGS_H
|
|
@ -1,5 +1,6 @@
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
|
|
||||||
|
#include "../birthsignbindings.hpp"
|
||||||
#include "../luamanagerimp.hpp"
|
#include "../luamanagerimp.hpp"
|
||||||
|
|
||||||
#include "apps/openmw/mwbase/inputmanager.hpp"
|
#include "apps/openmw/mwbase/inputmanager.hpp"
|
||||||
|
@ -170,5 +171,7 @@ namespace MWLua
|
||||||
player["isCharGenFinished"] = [](const Object&) -> bool {
|
player["isCharGenFinished"] = [](const Object&) -> bool {
|
||||||
return MWBase::Environment::get().getWorld()->getGlobalFloat(MWWorld::Globals::sCharGenState) == -1;
|
return MWBase::Environment::get().getWorld()->getGlobalFloat(MWWorld::Globals::sCharGenState) == -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
player["birthSigns"] = initCoreBirthSignBindings(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1045,6 +1045,28 @@
|
||||||
-- Values that can be used with getControlSwitch/setControlSwitch.
|
-- Values that can be used with getControlSwitch/setControlSwitch.
|
||||||
-- @field [parent=#Player] #CONTROL_SWITCH CONTROL_SWITCH
|
-- @field [parent=#Player] #CONTROL_SWITCH CONTROL_SWITCH
|
||||||
|
|
||||||
|
--- @{#BirthSigns}: Birth Sign Data
|
||||||
|
-- @field [parent=#Player] #BirthSigns birthSigns
|
||||||
|
|
||||||
|
---
|
||||||
|
-- A read-only list of all @{#BirthSignRecord}s in the world database.
|
||||||
|
-- @field [parent=#BirthSigns] #list<#BirthSignRecord> records
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Returns a read-only @{#BirthSignRecord}
|
||||||
|
-- @function [parent=#BirthSigns] record
|
||||||
|
-- @param #string recordId
|
||||||
|
-- @return #BirthSignRecord
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Birth sign data record
|
||||||
|
-- @type BirthSignRecord
|
||||||
|
-- @field #string id Birth sign id
|
||||||
|
-- @field #string name Birth sign name
|
||||||
|
-- @field #string description Birth sign description
|
||||||
|
-- @field #string texture Birth sign texture
|
||||||
|
-- @field #list<#string> spells A read-only list containing the ids of all spells gained from this sign.
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Send an event to menu scripts.
|
-- Send an event to menu scripts.
|
||||||
-- @function [parent=#core] sendMenuEvent
|
-- @function [parent=#core] sendMenuEvent
|
||||||
|
|
Loading…
Reference in a new issue