mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-29 13:20:35 +00:00
Add NPC and Creature record bindings
This commit is contained in:
parent
5d006ef14b
commit
9c5887aab6
@ -60,7 +60,7 @@ add_openmw_dir (mwlua
|
||||
luamanagerimp object worldview userdataserializer eventqueue
|
||||
luabindings localscripts playerscripts objectbindings cellbindings asyncbindings settingsbindings
|
||||
camerabindings uibindings inputbindings nearbybindings stats
|
||||
types/types types/door types/actor types/container types/weapon types/npc
|
||||
types/types types/door types/actor types/container types/weapon types/npc types/creature
|
||||
)
|
||||
|
||||
add_openmw_dir (mwsound
|
||||
|
31
apps/openmw/mwlua/types/creature.cpp
Normal file
31
apps/openmw/mwlua/types/creature.cpp
Normal file
@ -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; });
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ namespace MWLua
|
||||
ESM::REC_LIGH, ESM::REC_MISC, ESM::REC_ALCH, ESM::REC_WEAP,
|
||||
ESM::REC_APPA, ESM::REC_LOCK, ESM::REC_PROB, ESM::REC_REPA});
|
||||
|
||||
addType(ObjectTypeName::Creature, {ESM::REC_CREA}, ObjectTypeName::Actor);
|
||||
addCreatureBindings(addType(ObjectTypeName::Creature, {ESM::REC_CREA}, ObjectTypeName::Actor), context);
|
||||
addNpcBindings(addType(ObjectTypeName::NPC, {ESM::REC_INTERNAL_PLAYER, ESM::REC_NPC_}, ObjectTypeName::Actor), context);
|
||||
addType(ObjectTypeName::Player, {ESM::REC_INTERNAL_PLAYER}, ObjectTypeName::NPC);
|
||||
|
||||
|
@ -29,6 +29,7 @@ namespace MWLua
|
||||
void addActorBindings(sol::table actor, const Context& context);
|
||||
void addWeaponBindings(sol::table weapon, const Context& context);
|
||||
void addNpcBindings(sol::table npc, const Context& context);
|
||||
void addCreatureBindings(sol::table creature, const Context& context);
|
||||
}
|
||||
|
||||
#endif // MWLUA_TYPES_H
|
||||
|
@ -441,6 +441,19 @@
|
||||
-- @param openmw.core#GameObject object
|
||||
-- @return #boolean
|
||||
|
||||
---
|
||||
-- Returns the read-only @{#CreatureRecord} of a creature
|
||||
-- @function [parent=#Creature] record
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #CreatureRecord
|
||||
|
||||
---
|
||||
-- @type CreatureRecord
|
||||
-- @field #string name
|
||||
-- @field #string baseCreature Record id of a base creature, which was modified to create this one
|
||||
-- @field #string model VFS path to the creature's model
|
||||
-- @field #string mwscript
|
||||
|
||||
|
||||
|
||||
--- @{#NPC} functions
|
||||
@ -458,7 +471,20 @@
|
||||
-- @param openmw.core#GameObject object
|
||||
-- @return #boolean
|
||||
|
||||
---
|
||||
-- Returns the read-only @{#NpcRecord} of an NPC
|
||||
-- @function [parent=#NPC] record
|
||||
-- @param #any objectOrRecordId
|
||||
-- @return #NpcRecord
|
||||
|
||||
---
|
||||
-- @type NpcRecord
|
||||
-- @field #string name
|
||||
-- @field #string race
|
||||
-- @field #string class Name of the NPC's class (e. g. Acrobat)
|
||||
-- @field #string mwscript MWScript that is attached to this NPC
|
||||
-- @field #string hair Path to the hair body part model
|
||||
-- @field #string head Path to the head body part model
|
||||
|
||||
--- @{#Player} functions
|
||||
-- @field [parent=#types] #Player Player
|
||||
|
Loading…
x
Reference in New Issue
Block a user