Lua Armor, Static and Light record bindings

7098-improve-post-process-behavior-with-transparent-objects
mpeco 2 years ago
parent 59025f2bc9
commit 90a73b39ce

@ -62,7 +62,7 @@ add_openmw_dir (mwlua
luamanagerimp object worldview userdataserializer eventqueue
luabindings localscripts playerscripts objectbindings cellbindings asyncbindings
camerabindings uibindings inputbindings nearbybindings postprocessingbindings stats debugbindings
types/types types/door types/actor types/container types/weapon types/npc types/creature types/activator types/book types/lockpick types/probe types/apparatus types/potion types/ingredient types/misc types/repair
types/types types/door types/actor types/container types/weapon types/npc types/creature types/activator types/book types/lockpick types/probe types/apparatus types/potion types/ingredient types/misc types/repair types/armor types/light types/static
worker
)

@ -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);
});
}
}

@ -158,10 +158,10 @@ namespace MWLua
addType(ObjectTypeName::NPC, { ESM::REC_INTERNAL_PLAYER, ESM::REC_NPC_ }, ObjectTypeName::Actor), context);
addType(ObjectTypeName::Player, { ESM::REC_INTERNAL_PLAYER }, ObjectTypeName::NPC);
addType(ObjectTypeName::Armor, { ESM::REC_ARMO }, ObjectTypeName::Item);
addArmorBindings(addType(ObjectTypeName::Armor, { ESM::REC_ARMO }, ObjectTypeName::Item), context);
addType(ObjectTypeName::Clothing, { ESM::REC_CLOT }, ObjectTypeName::Item);
addIngredientBindings(addType(ObjectTypeName::Ingredient, { ESM::REC_INGR }, ObjectTypeName::Item), context);
addType(ObjectTypeName::Light, { ESM::REC_LIGH }, ObjectTypeName::Item);
addLightBindings(addType(ObjectTypeName::Light, { ESM::REC_LIGH }, ObjectTypeName::Item), context);
addMiscellaneousBindings(addType(ObjectTypeName::MiscItem, { ESM::REC_MISC }, ObjectTypeName::Item), context);
addPotionBindings(addType(ObjectTypeName::Potion, { ESM::REC_ALCH }, ObjectTypeName::Item), context);
addWeaponBindings(addType(ObjectTypeName::Weapon, { ESM::REC_WEAP }, ObjectTypeName::Item), context);
@ -174,7 +174,7 @@ namespace MWLua
addActivatorBindings(addType(ObjectTypeName::Activator, { ESM::REC_ACTI }), context);
addContainerBindings(addType(ObjectTypeName::Container, { ESM::REC_CONT }), context);
addDoorBindings(addType(ObjectTypeName::Door, { ESM::REC_DOOR }), context);
addType(ObjectTypeName::Static, { ESM::REC_STAT });
addStaticBindings(addType(ObjectTypeName::Static, { ESM::REC_STAT }), context);
sol::table typeToPackage = getTypeToPackageTable(context.mLua->sol());
sol::table packageToType = getPackageToTypeTable(context.mLua->sol());

@ -41,6 +41,9 @@ namespace MWLua
void addMiscellaneousBindings(sol::table miscellaneous, const Context& context);
void addPotionBindings(sol::table potion, const Context& context);
void addIngredientBindings(sol::table Ingredient, const Context& context);
void addArmorBindings(sol::table armor, const Context& context);
void addStaticBindings(sol::table stat, const Context& context);
void addLightBindings(sol::table light, const Context& context);
}
#endif // MWLUA_TYPES_H

Loading…
Cancel
Save