feat(lua): add tunable overloads for getting / setting values through the already joaated tunable value. (#2417)

This commit is contained in:
Quentin
2023-11-14 20:21:03 +01:00
committed by GitHub
parent d2acc65af0
commit 3914ebee72
3 changed files with 132 additions and 7 deletions

View File

@ -7,11 +7,13 @@ namespace lua::tunables
void bind(sol::state& state)
{
auto ns = state["tunables"].get_or_create<sol::table>();
ns["get_int"] = get<int>;
ns["get_float"] = get<float>;
ns["get_bool"] = get<bool>;
ns["set_int"] = set<int>;
ns["set_float"] = set<float>;
ns["set_bool"] = set<bool>;
ns["get_int"] = sol::overload(get<int>, get_already_joaated<int>);
ns["get_float"] = sol::overload(get<float>, get_already_joaated<float>);
ns["get_bool"] = sol::overload(get<bool>, get_already_joaated<bool>);
ns["set_int"] = sol::overload(set<int>, set_already_joaated<int>);
ns["set_float"] = sol::overload(set<float>, set_already_joaated<float>);
ns["set_bool"] = sol::overload(set<bool>, set_already_joaated<bool>);
}
}

View File

@ -34,6 +34,33 @@ namespace lua::tunables
return T();
}
// Lua API: Function
// Table: tunables
// Name: get_int
// Param: tunable_joaated_value: integer: The joaated value of the tunable.
// Returns: integer: The value of the given tunable.
// Lua API: Function
// Table: tunables
// Name: get_float
// Param: tunable_joaated_value: integer: The joaated value of the tunable.
// Returns: float: The value of the given tunable.
// Lua API: Function
// Table: tunables
// Name: get_bool
// Param: tunable_joaated_value: integer: The joaated value of the tunable.
// Returns: boolean: The value of the given tunable.
template<typename T>
T get_already_joaated(rage::joaat_t tunable_joaated_value)
{
if (auto tunable = big::g_tunables_service->get_tunable<T*>(tunable_joaated_value))
return *tunable;
return T();
}
// Lua API: Function
// Table: tunables
// Name: set_int
@ -58,5 +85,29 @@ namespace lua::tunables
big::g_tunables_service->set_tunable<T>(rage::joaat(tunable_name), val);
}
// Lua API: Function
// Table: tunables
// Name: set_int
// Param: tunable_joaated_value: integer: The joaated value of the tunable.
// Param: val: integer: The new value of the given tunable.
// Lua API: Function
// Table: tunables
// Name: set_float
// Param: tunable_joaated_value: integer: The joaated value of the tunable.
// Param: val: float: The new value of the given tunable.
// Lua API: Function
// Table: tunables
// Name: set_bool
// Param: tunable_joaated_value: integer: The joaated value of the tunable.
// Param: val: boolean: The new value of the given tunable.
template<typename T>
void set_already_joaated(rage::joaat_t tunable_joaated_value, T val)
{
big::g_tunables_service->set_tunable<T>(tunable_joaated_value, val);
}
void bind(sol::state& state);
}