mirror of https://github.com/OpenMW/openmw.git
Merge branch 'lua_record_types' into 'master'
Lua API for NPC and Creature records See merge request OpenMW/openmw!1823pull/3227/head
commit
45161d91c9
@ -0,0 +1,31 @@
|
||||
#include "types.hpp"
|
||||
|
||||
#include <components/esm3/loadcrea.hpp>
|
||||
|
||||
#include <apps/openmw/mwworld/esmstore.hpp>
|
||||
|
||||
#include "../stats.hpp"
|
||||
#include "../luabindings.hpp"
|
||||
|
||||
namespace sol
|
||||
{
|
||||
template <>
|
||||
struct is_automagical<ESM::Creature> : std::false_type {};
|
||||
}
|
||||
|
||||
namespace MWLua
|
||||
{
|
||||
void addCreatureBindings(sol::table creature, const Context& context)
|
||||
{
|
||||
const MWWorld::Store<ESM::Creature>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>();
|
||||
creature["record"] = sol::overload(
|
||||
[](const Object& obj) -> const ESM::Creature* { return obj.ptr().get<ESM::Creature>()->mBase; },
|
||||
[store](const std::string& recordId) -> const ESM::Creature* { return store->find(recordId); });
|
||||
sol::usertype<ESM::Creature> record = context.mLua->sol().new_usertype<ESM::Creature>("ESM3_Creature");
|
||||
record[sol::meta_function::to_string] = [](const ESM::Creature& rec) { return "ESM3_Creature[" + rec.mId + "]"; };
|
||||
record["name"] = sol::readonly_property([](const ESM::Creature& rec) -> std::string { return rec.mName; });
|
||||
record["model"] = sol::readonly_property([](const ESM::Creature& rec) -> std::string { return rec.mModel; });
|
||||
record["mwscript"] = sol::readonly_property([](const ESM::Creature& rec) -> std::string { return rec.mScript; });
|
||||
record["baseCreature"] = sol::readonly_property([](const ESM::Creature& rec) -> std::string { return rec.mOriginal; });
|
||||
}
|
||||
}
|
@ -1,11 +1,35 @@
|
||||
#include "types.hpp"
|
||||
|
||||
#include <components/esm3/loadnpc.hpp>
|
||||
|
||||
#include <apps/openmw/mwworld/esmstore.hpp>
|
||||
|
||||
#include "../stats.hpp"
|
||||
#include "../luabindings.hpp"
|
||||
|
||||
namespace sol
|
||||
{
|
||||
template <>
|
||||
struct is_automagical<ESM::NPC> : std::false_type {};
|
||||
}
|
||||
|
||||
namespace MWLua
|
||||
{
|
||||
void addNpcBindings(sol::table npc, const Context& context)
|
||||
{
|
||||
addNpcStatsBindings(npc, context);
|
||||
|
||||
const MWWorld::Store<ESM::NPC>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::NPC>();
|
||||
npc["record"] = sol::overload(
|
||||
[](const Object& obj) -> const ESM::NPC* { return obj.ptr().get<ESM::NPC>()->mBase; },
|
||||
[store](const std::string& recordId) -> const ESM::NPC* { return store->find(recordId); });
|
||||
sol::usertype<ESM::NPC> record = context.mLua->sol().new_usertype<ESM::NPC>("ESM3_NPC");
|
||||
record[sol::meta_function::to_string] = [](const ESM::NPC& rec) { return "ESM3_NPC[" + rec.mId + "]"; };
|
||||
record["name"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mName; });
|
||||
record["race"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mRace; });
|
||||
record["class"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mClass; });
|
||||
record["mwscript"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mScript; });
|
||||
record["hair"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHair; });
|
||||
record["head"] = sol::readonly_property([](const ESM::NPC& rec) -> std::string { return rec.mHead; });
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue