mirror of https://github.com/OpenMW/openmw.git
Lua Armor, Static and Light record bindings
parent
59025f2bc9
commit
90a73b39ce
@ -0,0 +1,63 @@
|
||||
#include "types.hpp"
|
||||
|
||||
#include <components/esm3/loadarmo.hpp>
|
||||
#include <components/misc/resourcehelpers.hpp>
|
||||
#include <components/resource/resourcesystem.hpp>
|
||||
#include <components/lua/luastate.hpp>
|
||||
|
||||
#include <apps/openmw/mwworld/esmstore.hpp>
|
||||
#include <apps/openmw/mwbase/environment.hpp>
|
||||
#include <apps/openmw/mwbase/world.hpp>
|
||||
|
||||
namespace sol
|
||||
{
|
||||
template <>
|
||||
struct is_automagical<ESM::Armor> : std::false_type {};
|
||||
}
|
||||
|
||||
namespace MWLua
|
||||
{
|
||||
void addArmorBindings(sol::table armor, const Context& context)
|
||||
{
|
||||
armor["TYPE"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string_view, int>({
|
||||
{"Helmet", ESM::Armor::Helmet},
|
||||
{"Cuirass", ESM::Armor::Cuirass},
|
||||
{"LPauldron", ESM::Armor::LPauldron},
|
||||
{"RPauldron", ESM::Armor::RPauldron},
|
||||
{"Greaves", ESM::Armor::Greaves},
|
||||
{"Boots", ESM::Armor::Boots},
|
||||
{"LGauntlet", ESM::Armor::LGauntlet},
|
||||
{"RGauntlet", ESM::Armor::RGauntlet},
|
||||
{"LBracer", ESM::Armor::LBracer},
|
||||
{"Shield", ESM::Armor::Shield},
|
||||
{"RBracer", ESM::Armor::RBracer},
|
||||
}));
|
||||
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
const MWWorld::Store<ESM::Armor>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Armor>();
|
||||
armor["record"] = sol::overload(
|
||||
[](const Object& obj) -> const ESM::Armor* { return obj.ptr().get<ESM::Armor>()->mBase; },
|
||||
[store](const std::string& recordId) -> const ESM::Armor* { return store->find(recordId); });
|
||||
sol::usertype<ESM::Armor> record = context.mLua->sol().new_usertype<ESM::Armor>("ESM3_Armor");
|
||||
record[sol::meta_function::to_string] = [](const ESM::Armor& rec) -> std::string { return "ESM3_Armor[" + rec.mId + "]"; };
|
||||
record["id"] = sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mId; });
|
||||
record["name"] = sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mName; });
|
||||
record["model"] = sol::readonly_property([vfs](const ESM::Armor& rec) -> std::string
|
||||
{
|
||||
return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs);
|
||||
});
|
||||
record["icon"] = sol::readonly_property([vfs](const ESM::Armor& rec) -> std::string
|
||||
{
|
||||
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
|
||||
});
|
||||
record["enchant"] = sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mEnchant; });
|
||||
record["mwscript"] = sol::readonly_property([](const ESM::Armor& rec) -> std::string { return rec.mScript; });
|
||||
record["weight"] = sol::readonly_property([](const ESM::Armor& rec) -> float { return rec.mData.mWeight; });
|
||||
record["value"] = sol::readonly_property([](const ESM::Armor& rec) -> int { return rec.mData.mValue; });
|
||||
record["type"] = sol::readonly_property([](const ESM::Armor& rec) -> int { return rec.mData.mType; });
|
||||
record["health"] = sol::readonly_property([](const ESM::Armor& rec) -> int { return rec.mData.mHealth; });
|
||||
record["baseArmor"] = sol::readonly_property([](const ESM::Armor& rec) -> int { return rec.mData.mArmor; });
|
||||
record["enchantCapacity"] = sol::readonly_property([](const ESM::Armor& rec) -> float { return rec.mData.mEnchant * 0.1f; });
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
#include "types.hpp"
|
||||
|
||||
#include <components/esm3/loadligh.hpp>
|
||||
#include <components/misc/resourcehelpers.hpp>
|
||||
#include <components/resource/resourcesystem.hpp>
|
||||
#include <components/lua/luastate.hpp>
|
||||
|
||||
#include <apps/openmw/mwworld/esmstore.hpp>
|
||||
#include <apps/openmw/mwbase/environment.hpp>
|
||||
#include <apps/openmw/mwbase/world.hpp>
|
||||
|
||||
namespace sol
|
||||
{
|
||||
template <>
|
||||
struct is_automagical<ESM::Light> : std::false_type {};
|
||||
}
|
||||
|
||||
namespace MWLua
|
||||
{
|
||||
void addLightBindings(sol::table light, const Context& context)
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
const MWWorld::Store<ESM::Light>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Light>();
|
||||
light["record"] = sol::overload(
|
||||
[](const Object& obj) -> const ESM::Light* { return obj.ptr().get<ESM::Light>()->mBase; },
|
||||
[store](const std::string& recordId) -> const ESM::Light* { return store->find(recordId); });
|
||||
sol::usertype<ESM::Light> record = context.mLua->sol().new_usertype<ESM::Light>("ESM3_Light");
|
||||
record[sol::meta_function::to_string] = [](const ESM::Light& rec) -> std::string { return "ESM3_Light[" + rec.mId + "]"; };
|
||||
record["id"] = sol::readonly_property([](const ESM::Light& rec) -> std::string { return rec.mId; });
|
||||
record["name"] = sol::readonly_property([](const ESM::Light& rec) -> std::string { return rec.mName; });
|
||||
record["model"] = sol::readonly_property([vfs](const ESM::Light& rec) -> std::string
|
||||
{
|
||||
return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs);
|
||||
});
|
||||
record["icon"] = sol::readonly_property([vfs](const ESM::Light& rec) -> std::string
|
||||
{
|
||||
return Misc::ResourceHelpers::correctIconPath(rec.mIcon, vfs);
|
||||
});
|
||||
record["sound"] = sol::readonly_property([vfs](const ESM::Light& rec) -> std::string
|
||||
{
|
||||
return Misc::ResourceHelpers::correctSoundPath(rec.mSound, vfs);
|
||||
});
|
||||
record["mwscript"] = sol::readonly_property([](const ESM::Light& rec) -> std::string { return rec.mScript; });
|
||||
record["weight"] = sol::readonly_property([](const ESM::Light& rec) -> float { return rec.mData.mWeight; });
|
||||
record["value"] = sol::readonly_property([](const ESM::Light& rec) -> int { return rec.mData.mValue; });
|
||||
record["duration"] = sol::readonly_property([](const ESM::Light& rec) -> int { return rec.mData.mTime; });
|
||||
record["radius"] = sol::readonly_property([](const ESM::Light& rec) -> int { return rec.mData.mRadius; });
|
||||
record["color"] = sol::readonly_property([](const ESM::Light& rec) -> int { return rec.mData.mColor; });
|
||||
record["isCarriable"] = sol::readonly_property(
|
||||
[](const ESM::Light& rec) -> bool { return rec.mData.mFlags & ESM::Light::Carry; });
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#include "types.hpp"
|
||||
|
||||
#include <components/esm3/loadstat.hpp>
|
||||
#include <components/misc/resourcehelpers.hpp>
|
||||
#include <components/resource/resourcesystem.hpp>
|
||||
#include <components/lua/luastate.hpp>
|
||||
|
||||
#include <apps/openmw/mwworld/esmstore.hpp>
|
||||
#include <apps/openmw/mwbase/environment.hpp>
|
||||
#include <apps/openmw/mwbase/world.hpp>
|
||||
|
||||
namespace sol
|
||||
{
|
||||
template <>
|
||||
struct is_automagical<ESM::Static> : std::false_type {};
|
||||
}
|
||||
|
||||
namespace MWLua
|
||||
{
|
||||
void addStaticBindings(sol::table stat, const Context& context)
|
||||
{
|
||||
auto vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
||||
|
||||
const MWWorld::Store<ESM::Static>* store = &MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>();
|
||||
stat["record"] = sol::overload(
|
||||
[](const Object& obj) -> const ESM::Static* { return obj.ptr().get<ESM::Static>()->mBase; },
|
||||
[store](const std::string& recordId) -> const ESM::Static* { return store->find(recordId); });
|
||||
sol::usertype<ESM::Static> record = context.mLua->sol().new_usertype<ESM::Static>("ESM3_Static");
|
||||
record[sol::meta_function::to_string] = [](const ESM::Static& rec) -> std::string { return "ESM3_Static[" + rec.mId + "]"; };
|
||||
record["id"] = sol::readonly_property([](const ESM::Static& rec) -> std::string { return rec.mId; });
|
||||
record["model"] = sol::readonly_property([vfs](const ESM::Static& rec) -> std::string
|
||||
{
|
||||
return Misc::ResourceHelpers::correctMeshPath(rec.mModel, vfs);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue