From e56a6fd38fa8abfebe2b7ab6fd2b606f50aaa493 Mon Sep 17 00:00:00 2001 From: Quentin Date: Tue, 14 Nov 2023 20:21:03 +0100 Subject: [PATCH] feat(lua): add tunable overloads for getting / setting values through the already joaated tunable value. (#2417) --- docs/lua/tables/tunables.md | 74 ++++++++++++++++++++++++++++++++++- src/lua/bindings/tunables.cpp | 14 ++++--- src/lua/bindings/tunables.hpp | 51 ++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 7 deletions(-) diff --git a/docs/lua/tables/tunables.md b/docs/lua/tables/tunables.md index ae8a5bce..e79caeee 100644 --- a/docs/lua/tables/tunables.md +++ b/docs/lua/tables/tunables.md @@ -2,7 +2,7 @@ Table for manipulating gta tunables. -## Functions (6) +## Functions (12) ### `get_int(tunable_name)` @@ -43,6 +43,45 @@ float = tunables.get_float(tunable_name) boolean = tunables.get_bool(tunable_name) ``` +### `get_int(tunable_joaated_value)` + +- **Parameters:** + - `tunable_joaated_value` (integer): The joaated value of the tunable. + +- **Returns:** + - `integer`: The value of the given tunable. + +**Example Usage:** +```lua +integer = tunables.get_int(tunable_joaated_value) +``` + +### `get_float(tunable_joaated_value)` + +- **Parameters:** + - `tunable_joaated_value` (integer): The joaated value of the tunable. + +- **Returns:** + - `float`: The value of the given tunable. + +**Example Usage:** +```lua +float = tunables.get_float(tunable_joaated_value) +``` + +### `get_bool(tunable_joaated_value)` + +- **Parameters:** + - `tunable_joaated_value` (integer): The joaated value of the tunable. + +- **Returns:** + - `boolean`: The value of the given tunable. + +**Example Usage:** +```lua +boolean = tunables.get_bool(tunable_joaated_value) +``` + ### `set_int(tunable_name, val)` - **Parameters:** @@ -76,4 +115,37 @@ tunables.set_float(tunable_name, val) tunables.set_bool(tunable_name, val) ``` +### `set_int(tunable_joaated_value, val)` + +- **Parameters:** + - `tunable_joaated_value` (integer): The joaated value of the tunable. + - `val` (integer): The new value of the given tunable. + +**Example Usage:** +```lua +tunables.set_int(tunable_joaated_value, val) +``` + +### `set_float(tunable_joaated_value, val)` + +- **Parameters:** + - `tunable_joaated_value` (integer): The joaated value of the tunable. + - `val` (float): The new value of the given tunable. + +**Example Usage:** +```lua +tunables.set_float(tunable_joaated_value, val) +``` + +### `set_bool(tunable_joaated_value, val)` + +- **Parameters:** + - `tunable_joaated_value` (integer): The joaated value of the tunable. + - `val` (boolean): The new value of the given tunable. + +**Example Usage:** +```lua +tunables.set_bool(tunable_joaated_value, val) +``` + diff --git a/src/lua/bindings/tunables.cpp b/src/lua/bindings/tunables.cpp index 48e6b17f..13e55e61 100644 --- a/src/lua/bindings/tunables.cpp +++ b/src/lua/bindings/tunables.cpp @@ -7,11 +7,13 @@ namespace lua::tunables void bind(sol::state& state) { auto ns = state["tunables"].get_or_create(); - ns["get_int"] = get; - ns["get_float"] = get; - ns["get_bool"] = get; - ns["set_int"] = set; - ns["set_float"] = set; - ns["set_bool"] = set; + + ns["get_int"] = sol::overload(get, get_already_joaated); + ns["get_float"] = sol::overload(get, get_already_joaated); + ns["get_bool"] = sol::overload(get, get_already_joaated); + + ns["set_int"] = sol::overload(set, set_already_joaated); + ns["set_float"] = sol::overload(set, set_already_joaated); + ns["set_bool"] = sol::overload(set, set_already_joaated); } } \ No newline at end of file diff --git a/src/lua/bindings/tunables.hpp b/src/lua/bindings/tunables.hpp index d9c6b0c0..8c3b83e5 100644 --- a/src/lua/bindings/tunables.hpp +++ b/src/lua/bindings/tunables.hpp @@ -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 + T get_already_joaated(rage::joaat_t tunable_joaated_value) + { + if (auto tunable = big::g_tunables_service->get_tunable(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(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 + void set_already_joaated(rage::joaat_t tunable_joaated_value, T val) + { + big::g_tunables_service->set_tunable(tunable_joaated_value, val); + } + void bind(sol::state& state); } \ No newline at end of file