From 3f7f5da50e4d4ce5bb1be8caa954f0d485d2e464 Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Sun, 19 Feb 2023 07:23:51 +1000 Subject: [PATCH] expose course_is_main_course() to Lua (#282) --- autogen/lua_definitions/functions.lua | 6 ++++++ docs/lua/functions-4.md | 20 ++++++++++++++++++++ docs/lua/functions.md | 1 + src/pc/lua/smlua_functions_autogen.c | 18 ++++++++++++++++++ src/pc/lua/utils/smlua_misc_utils.c | 7 +++++++ src/pc/lua/utils/smlua_misc_utils.h | 2 ++ 6 files changed, 54 insertions(+) diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 78bdadc5..5ba825e8 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -8196,6 +8196,12 @@ function camera_unfreeze() -- ... end +--- @param levelNum integer +--- @return boolean +function course_is_main_course(levelNum) + -- ... +end + --- @param pointer Pointer_integer --- @return integer function deref_s32_pointer(pointer) diff --git a/docs/lua/functions-4.md b/docs/lua/functions-4.md index 148ed34f..dfe35d88 100644 --- a/docs/lua/functions-4.md +++ b/docs/lua/functions-4.md @@ -8084,6 +8084,26 @@
+## [course_is_main_course](#course_is_main_course) + +### Lua Example +`local booleanValue = course_is_main_course(levelNum)` + +### Parameters +| Field | Type | +| ----- | ---- | +| levelNum | `integer` | + +### Returns +- `boolean` + +### C Prototype +`bool course_is_main_course(u16 levelNum);` + +[:arrow_up_small:](#) + +
+ ## [deref_s32_pointer](#deref_s32_pointer) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index c12df4ef..8762e901 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1516,6 +1516,7 @@ - [camera_config_set_y_sensitivity](functions-4.md#camera_config_set_y_sensitivity) - [camera_freeze](functions-4.md#camera_freeze) - [camera_unfreeze](functions-4.md#camera_unfreeze) + - [course_is_main_course](functions-4.md#course_is_main_course) - [deref_s32_pointer](functions-4.md#deref_s32_pointer) - [get_current_save_file_num](functions-4.md#get_current_save_file_num) - [get_dialog_box_state](functions-4.md#get_dialog_box_state) diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index fc30a97d..ba681439 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -26777,6 +26777,23 @@ int smlua_func_camera_unfreeze(UNUSED lua_State* L) { return 1; } +int smlua_func_course_is_main_course(lua_State* L) { + if (L == NULL) { return 0; } + + int top = lua_gettop(L); + if (top != 1) { + LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "course_is_main_course", 1, top); + return 0; + } + + u16 levelNum = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "course_is_main_course"); return 0; } + + lua_pushboolean(L, course_is_main_course(levelNum)); + + return 1; +} + int smlua_func_deref_s32_pointer(lua_State* L) { if (L == NULL) { return 0; } @@ -30152,6 +30169,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "camera_config_set_y_sensitivity", smlua_func_camera_config_set_y_sensitivity); smlua_bind_function(L, "camera_freeze", smlua_func_camera_freeze); smlua_bind_function(L, "camera_unfreeze", smlua_func_camera_unfreeze); + smlua_bind_function(L, "course_is_main_course", smlua_func_course_is_main_course); smlua_bind_function(L, "deref_s32_pointer", smlua_func_deref_s32_pointer); smlua_bind_function(L, "get_current_save_file_num", smlua_func_get_current_save_file_num); smlua_bind_function(L, "get_dialog_box_state", smlua_func_get_dialog_box_state); diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c index 1e2aba10..1aaad9c5 100644 --- a/src/pc/lua/utils/smlua_misc_utils.c +++ b/src/pc/lua/utils/smlua_misc_utils.c @@ -17,6 +17,7 @@ #include "game/rendering_graph_node.h" #include "game/level_update.h" #include "pc/djui/djui_hud_utils.h" +#include "include/course_table.h" u32 get_network_area_timer(void) { return gNetworkAreaTimer; @@ -373,3 +374,9 @@ void set_override_far(f32 far) { void add_scroll_target(u32 index, const char* name, u32 offset, u32 size) { dynos_add_scroll_target(index, name, offset, size); } + +/// + +bool course_is_main_course(u16 levelNum) { + return COURSE_IS_MAIN_COURSE(levelNum); +} diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h index 45ed1df3..0f1f86d5 100644 --- a/src/pc/lua/utils/smlua_misc_utils.h +++ b/src/pc/lua/utils/smlua_misc_utils.h @@ -90,4 +90,6 @@ void add_scroll_target(u32 index, const char* name, u32 offset, u32 size); void play_transition(s16 transType, s16 time, u8 red, u8 green, u8 blue); +bool course_is_main_course(u16 levelNum); + #endif