From 274d308d9a0f2dddcd1e2b9469bc8f707f7c54c0 Mon Sep 17 00:00:00 2001 From: Emerald Lockdown <86802223+EmeraldLoc@users.noreply.github.com> Date: Sun, 7 Aug 2022 22:52:51 -0500 Subject: [PATCH] Exposed save_file_erase and save_file_reload to lua (#137) --- autogen/convert_functions.py | 4 +-- autogen/lua_definitions/functions.lua | 11 ++++++++ docs/lua/functions-4.md | 38 +++++++++++++++++++++++++++ docs/lua/functions.md | 2 ++ src/pc/lua/smlua_functions_autogen.c | 22 ++++++++++++++++ 5 files changed, 75 insertions(+), 2 deletions(-) diff --git a/autogen/convert_functions.py b/autogen/convert_functions.py index 7327aca7..00f7e2e7 100644 --- a/autogen/convert_functions.py +++ b/autogen/convert_functions.py @@ -58,7 +58,7 @@ override_allowed_functions = { "src/audio/external.h": [ " play_", "fade", "current_background" ], "src/game/rumble_init.c": [ "queue_rumble_", "reset_rumble_timers" ], "src/pc/djui/djui_popup.h" : [ "create" ], - "src/game/save_file.h": [ "save_file_get_", "save_file_set_flags", "save_file_clear_flags" ], + "src/game/save_file.h": [ "save_file_get_", "save_file_set_flags", "save_file_clear_flags", "save_file_erase", "save_file_reload" ], "src/pc/lua/utils/smlua_model_utils.h": [ "smlua_model_util_get_id" ], "src/game/object_list_processor.h": [ "set_object_respawn_info_bits" ], "src/game/mario_misc.h": [ "bhv_toad.*", "bhv_unlock_door.*" ], @@ -878,4 +878,4 @@ def main(): print('Total functions: ' + str(total_functions)) if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index f3675afa..40a6b340 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -7203,6 +7203,12 @@ function save_file_clear_flags(flags) -- ... end +--- @param fileIndex integer +--- @return nil +function save_file_erase(fileIndex) + -- ... +end + --- @param capPos Vec3s --- @return integer function save_file_get_cap_pos(capPos) @@ -7254,6 +7260,11 @@ function save_file_get_total_star_count(fileIndex, minCourse, maxCourse) -- ... end +--- @return nil +function save_file_reload() + -- ... +end + --- @param flags integer --- @return nil function save_file_set_flags(flags) diff --git a/docs/lua/functions-4.md b/docs/lua/functions-4.md index f93f794d..7692f56a 100644 --- a/docs/lua/functions-4.md +++ b/docs/lua/functions-4.md @@ -5364,6 +5364,26 @@
+## [save_file_erase](#save_file_erase) + +### Lua Example +`save_file_erase(fileIndex)` + +### Parameters +| Field | Type | +| ----- | ---- | +| fileIndex | `integer` | + +### Returns +- None + +### C Prototype +`void save_file_erase(s32 fileIndex);` + +[:arrow_up_small:](#) + +
+ ## [save_file_get_cap_pos](#save_file_get_cap_pos) ### Lua Example @@ -5525,6 +5545,24 @@
+## [save_file_reload](#save_file_reload) + +### Lua Example +`save_file_reload()` + +### Parameters +- None + +### Returns +- None + +### C Prototype +`void save_file_reload(void);` + +[:arrow_up_small:](#) + +
+ ## [save_file_set_flags](#save_file_set_flags) ### Lua Example diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 597a95cc..38833551 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1339,6 +1339,7 @@ - save_file.h - [save_file_clear_flags](functions-4.md#save_file_clear_flags) + - [save_file_erase](functions-4.md#save_file_erase) - [save_file_get_cap_pos](functions-4.md#save_file_get_cap_pos) - [save_file_get_course_coin_score](functions-4.md#save_file_get_course_coin_score) - [save_file_get_course_star_count](functions-4.md#save_file_get_course_star_count) @@ -1347,6 +1348,7 @@ - [save_file_get_sound_mode](functions-4.md#save_file_get_sound_mode) - [save_file_get_star_flags](functions-4.md#save_file_get_star_flags) - [save_file_get_total_star_count](functions-4.md#save_file_get_total_star_count) + - [save_file_reload](functions-4.md#save_file_reload) - [save_file_set_flags](functions-4.md#save_file_set_flags)
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 5fe676e6..95d04e79 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -15992,6 +15992,17 @@ int smlua_func_save_file_clear_flags(lua_State* L) { return 1; } +int smlua_func_save_file_erase(lua_State* L) { + if(!smlua_functions_valid_param_count(L, 1)) { return 0; } + + s32 fileIndex = smlua_to_integer(L, 1); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1"); return 0; } + + save_file_erase(fileIndex); + + return 1; +} + int smlua_func_save_file_get_cap_pos(lua_State* L) { if(!smlua_functions_valid_param_count(L, 1)) { return 0; } @@ -16094,6 +16105,15 @@ int smlua_func_save_file_get_total_star_count(lua_State* L) { return 1; } +int smlua_func_save_file_reload(UNUSED lua_State* L) { + if(!smlua_functions_valid_param_count(L, 0)) { return 0; } + + + save_file_reload(); + + return 1; +} + int smlua_func_save_file_set_flags(lua_State* L) { if(!smlua_functions_valid_param_count(L, 1)) { return 0; } @@ -19256,6 +19276,7 @@ void smlua_bind_functions_autogen(void) { // save_file.h smlua_bind_function(L, "save_file_clear_flags", smlua_func_save_file_clear_flags); + smlua_bind_function(L, "save_file_erase", smlua_func_save_file_erase); smlua_bind_function(L, "save_file_get_cap_pos", smlua_func_save_file_get_cap_pos); smlua_bind_function(L, "save_file_get_course_coin_score", smlua_func_save_file_get_course_coin_score); smlua_bind_function(L, "save_file_get_course_star_count", smlua_func_save_file_get_course_star_count); @@ -19264,6 +19285,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "save_file_get_sound_mode", smlua_func_save_file_get_sound_mode); smlua_bind_function(L, "save_file_get_star_flags", smlua_func_save_file_get_star_flags); smlua_bind_function(L, "save_file_get_total_star_count", smlua_func_save_file_get_total_star_count); + smlua_bind_function(L, "save_file_reload", smlua_func_save_file_reload); smlua_bind_function(L, "save_file_set_flags", smlua_func_save_file_set_flags); // smlua_audio_utils.h