Add get_mod_files

This commit is contained in:
EmeraldLockdown 2026-01-24 17:10:54 -06:00
parent d53338f2b8
commit 08b977f645
6 changed files with 95 additions and 1 deletions

View file

@ -11604,6 +11604,14 @@ function get_active_mod()
-- ...
end
--- @param mod Mod
--- @param subDirectory string
--- @return table
--- Gets all files a mod contains
function get_mod_files(mod, subDirectory)
-- ...
end
--- @param title string
--- Sets the window title to a custom title
function set_window_title(title)

View file

@ -2086,6 +2086,30 @@ Gets the mod currently being processed
<br />
## [get_mod_files](#get_mod_files)
### Description
Gets all files a mod contains
### Lua Example
`local tableValue = get_mod_files(mod, subDirectory)`
### Parameters
| Field | Type |
| ----- | ---- |
| mod | [Mod](structs.md#Mod) |
| subDirectory | `string` |
### Returns
- `table`
### C Prototype
`LuaTable get_mod_files(struct Mod* mod, const char* subDirectory);`
[:arrow_up_small:](#)
<br />
## [set_window_title](#set_window_title)
### Description

View file

@ -2061,6 +2061,7 @@
- [set_environment_region](functions-7.md#set_environment_region)
- [mod_file_exists](functions-7.md#mod_file_exists)
- [get_active_mod](functions-7.md#get_active_mod)
- [get_mod_files](functions-7.md#get_mod_files)
- [set_window_title](functions-7.md#set_window_title)
- [reset_window_title](functions-7.md#reset_window_title)
- [get_os_name](functions-7.md#get_os_name)

View file

@ -34629,6 +34629,25 @@ int smlua_func_get_active_mod(UNUSED lua_State* L) {
return 1;
}
int smlua_func_get_mod_files(lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 2) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "get_mod_files", 2, top);
return 0;
}
struct Mod* mod = (struct Mod*)smlua_to_cobject(L, 1, LOT_MOD);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "get_mod_files"); return 0; }
const char* subDirectory = smlua_to_string(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "get_mod_files"); return 0; }
smlua_push_lua_table(L, get_mod_files(mod, subDirectory));
return 1;
}
int smlua_func_set_window_title(lua_State* L) {
if (L == NULL) { return 0; }
@ -38971,6 +38990,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "set_environment_region", smlua_func_set_environment_region);
smlua_bind_function(L, "mod_file_exists", smlua_func_mod_file_exists);
smlua_bind_function(L, "get_active_mod", smlua_func_get_active_mod);
smlua_bind_function(L, "get_mod_files", smlua_func_get_mod_files);
smlua_bind_function(L, "set_window_title", smlua_func_set_window_title);
smlua_bind_function(L, "reset_window_title", smlua_func_reset_window_title);
smlua_bind_function(L, "get_os_name", smlua_func_get_os_name);

View file

@ -601,6 +601,45 @@ struct Mod* get_active_mod(void) {
return gLuaActiveMod;
}
LuaTable get_mod_files(struct Mod* mod, const char* subDirectory) {
char* normalizedSubDir = malloc(strlen(subDirectory) + 2);
strcpy(normalizedSubDir, subDirectory);
normalize_path(normalizedSubDir);
size_t subDirLen = strlen(normalizedSubDir);
if (subDirLen > 0 && normalizedSubDir[subDirLen - 1] != '/') {
strcat(normalizedSubDir, "/");
subDirLen = strlen(normalizedSubDir);
}
struct lua_State *L = gLuaState;
if (!L) { return 0; }
LUA_STACK_CHECK_BEGIN_NUM(L, 1);
lua_newtable(L);
int luaTableIndex = 1;
for (int i = 0; i < mod->fileCount; i++) {
struct ModFile* file = &mod->files[i];
char* normalizedPath = strdup(file->relativePath);
normalize_path(normalizedPath);
if (strncmp(normalizedPath, normalizedSubDir, subDirLen) == 0) {
lua_pushstring(L, file->relativePath);
lua_rawseti(L, -2, luaTableIndex++);
}
free(normalizedPath);
}
LUA_STACK_CHECK_END(L);
free(normalizedSubDir);
return smlua_to_lua_table(L, -1);
}
///
void set_window_title(const char* title) {

View file

@ -37,7 +37,7 @@ enum ActSelectHudPart {
ACT_SELECT_HUD_ACT_NAME = 1 << 3,
ACT_SELECT_HUD_STAR_NUM = 1 << 4,
ACT_SELECT_HUD_PLAYERS_IN_LEVEL = 1 << 5,
ACT_SELECT_HUD_NONE = 0,
ACT_SELECT_HUD_ALL = ACT_SELECT_HUD_SCORE | ACT_SELECT_HUD_LEVEL_NAME | ACT_SELECT_HUD_COURSE_NUM | ACT_SELECT_HUD_ACT_NAME |ACT_SELECT_HUD_STAR_NUM | ACT_SELECT_HUD_PLAYERS_IN_LEVEL
};
@ -243,6 +243,8 @@ void set_environment_region(u8 index, s16 value);
bool mod_file_exists(const char* filename);
/* |description|Gets the mod currently being processed|descriptionEnd| */
struct Mod* get_active_mod(void);
/* |description|Gets all files a mod contains|descriptionEnd| */
LuaTable get_mod_files(struct Mod* mod, const char* subDirectory);
/* |description|Sets the window title to a custom title|descriptionEnd| */
void set_window_title(const char* title);