mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-29 18:32:36 +00:00
Refactor Lua properties
This commit is contained in:
parent
78d8cf86c3
commit
e67d6c6ebf
@ -76,13 +76,18 @@ namespace MWLua
|
||||
inputActions[sol::meta_function::pairs] = pairs;
|
||||
}
|
||||
|
||||
context.mLua->sol().new_usertype<LuaUtil::InputAction::Info>("ActionInfo", "key",
|
||||
sol::property([](const LuaUtil::InputAction::Info& info) { return info.mKey; }), "name",
|
||||
sol::property([](const LuaUtil::InputAction::Info& info) { return info.mName; }), "description",
|
||||
sol::property([](const LuaUtil::InputAction::Info& info) { return info.mDescription; }), "type",
|
||||
sol::property([](const LuaUtil::InputAction::Info& info) { return info.mType; }), "l10n",
|
||||
sol::property([](const LuaUtil::InputAction::Info& info) { return info.mL10n; }), "defaultValue",
|
||||
sol::property([](const LuaUtil::InputAction::Info& info) { return info.mDefaultValue; }));
|
||||
auto actionInfo = context.mLua->sol().new_usertype<LuaUtil::InputAction::Info>("ActionInfo");
|
||||
actionInfo["key"] = sol::readonly_property(
|
||||
[](const LuaUtil::InputAction::Info& info) -> std::string_view { return info.mKey; });
|
||||
actionInfo["name"] = sol::readonly_property(
|
||||
[](const LuaUtil::InputAction::Info& info) -> std::string_view { return info.mName; });
|
||||
actionInfo["description"] = sol::readonly_property(
|
||||
[](const LuaUtil::InputAction::Info& info) -> std::string_view { return info.mDescription; });
|
||||
actionInfo["l10n"] = sol::readonly_property(
|
||||
[](const LuaUtil::InputAction::Info& info) -> std::string_view { return info.mL10n; });
|
||||
actionInfo["type"] = sol::readonly_property([](const LuaUtil::InputAction::Info& info) { return info.mType; });
|
||||
actionInfo["defaultValue"]
|
||||
= sol::readonly_property([](const LuaUtil::InputAction::Info& info) { return info.mDefaultValue; });
|
||||
|
||||
auto inputTriggers = context.mLua->sol().new_usertype<LuaUtil::InputTrigger::Registry>("InputTriggers");
|
||||
inputTriggers[sol::meta_function::index]
|
||||
@ -102,11 +107,15 @@ namespace MWLua
|
||||
inputTriggers[sol::meta_function::pairs] = pairs;
|
||||
}
|
||||
|
||||
context.mLua->sol().new_usertype<LuaUtil::InputTrigger::Info>("TriggerInfo", "key",
|
||||
sol::property([](const LuaUtil::InputTrigger::Info& info) { return info.mKey; }), "name",
|
||||
sol::property([](const LuaUtil::InputTrigger::Info& info) { return info.mName; }), "description",
|
||||
sol::property([](const LuaUtil::InputTrigger::Info& info) { return info.mDescription; }), "l10n",
|
||||
sol::property([](const LuaUtil::InputTrigger::Info& info) { return info.mL10n; }));
|
||||
auto triggerInfo = context.mLua->sol().new_usertype<LuaUtil::InputTrigger::Info>("TriggerInfo");
|
||||
triggerInfo["key"] = sol::readonly_property(
|
||||
[](const LuaUtil::InputTrigger::Info& info) -> std::string_view { return info.mKey; });
|
||||
triggerInfo["name"] = sol::readonly_property(
|
||||
[](const LuaUtil::InputTrigger::Info& info) -> std::string_view { return info.mName; });
|
||||
triggerInfo["description"] = sol::readonly_property(
|
||||
[](const LuaUtil::InputTrigger::Info& info) -> std::string_view { return info.mDescription; });
|
||||
triggerInfo["l10n"] = sol::readonly_property(
|
||||
[](const LuaUtil::InputTrigger::Info& info) -> std::string_view { return info.mL10n; });
|
||||
|
||||
MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
|
||||
sol::table api(context.mLua->sol(), sol::create);
|
||||
|
@ -380,7 +380,7 @@ namespace MWLua
|
||||
addProp(context, attributeStatT, "base", &MWMechanics::AttributeValue::getBase);
|
||||
addProp(context, attributeStatT, "damage", &MWMechanics::AttributeValue::getDamage);
|
||||
attributeStatT["modified"]
|
||||
= sol::property([=](const AttributeStat& stat) { return stat.getModified(context); });
|
||||
= sol::readonly_property([=](const AttributeStat& stat) { return stat.getModified(context); });
|
||||
addProp(context, attributeStatT, "modifier", &MWMechanics::AttributeValue::getModifier);
|
||||
sol::table attributes(context.mLua->sol(), sol::create);
|
||||
stats["attributes"] = LuaUtil::makeReadOnly(attributes);
|
||||
@ -399,7 +399,8 @@ namespace MWLua
|
||||
auto skillStatT = context.mLua->sol().new_usertype<SkillStat>("SkillStat");
|
||||
addProp(context, skillStatT, "base", &MWMechanics::SkillValue::getBase);
|
||||
addProp(context, skillStatT, "damage", &MWMechanics::SkillValue::getDamage);
|
||||
skillStatT["modified"] = sol::property([=](const SkillStat& stat) { return stat.getModified(context); });
|
||||
skillStatT["modified"]
|
||||
= sol::readonly_property([=](const SkillStat& stat) { return stat.getModified(context); });
|
||||
addProp(context, skillStatT, "modifier", &MWMechanics::SkillValue::getModifier);
|
||||
skillStatT["progress"] = sol::property([context](const SkillStat& stat) { return stat.getProgress(context); },
|
||||
[context](const SkillStat& stat, const sol::object& value) { stat.cache(context, "progress", value); });
|
||||
|
@ -161,8 +161,8 @@ namespace MWLua
|
||||
api["_getMenuTransparency"] = []() -> float { return Settings::gui().mMenuTransparency; };
|
||||
|
||||
auto uiLayer = context.mLua->sol().new_usertype<LuaUi::Layer>("UiLayer");
|
||||
uiLayer["name"] = sol::property([](LuaUi::Layer& self) { return self.name(); });
|
||||
uiLayer["size"] = sol::property([](LuaUi::Layer& self) { return self.size(); });
|
||||
uiLayer["name"] = sol::readonly_property([](LuaUi::Layer& self) -> std::string_view { return self.name(); });
|
||||
uiLayer["size"] = sol::readonly_property([](LuaUi::Layer& self) { return self.size(); });
|
||||
uiLayer[sol::meta_function::to_string]
|
||||
= [](LuaUi::Layer& self) { return Misc::StringUtils::format("UiLayer(%s)", self.name()); };
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user