From 003136db4f1676875ba70929aa4bd2b5f656ed37 Mon Sep 17 00:00:00 2001
From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com>
Date: Sat, 22 Jun 2024 02:14:59 +1000
Subject: [PATCH] add get_surface_from_wcd_index (#75)
---
autogen/lua_definitions/functions.lua | 7 +++++++
docs/lua/functions-5.md | 21 +++++++++++++++++++++
docs/lua/functions.md | 1 +
src/pc/lua/smlua_functions_autogen.c | 20 ++++++++++++++++++++
src/pc/lua/utils/smlua_collision_utils.c | 5 +++++
src/pc/lua/utils/smlua_collision_utils.h | 2 ++
6 files changed, 56 insertions(+)
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index 6fa4e36f..2381b511 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -7615,6 +7615,13 @@ function collision_get_temp_wall_collision_data()
-- ...
end
+--- @param wcd WallCollisionData
+--- @param index integer
+--- @return Surface
+function get_surface_from_wcd_index(wcd, index)
+ -- ...
+end
+
--- @return Surface
function get_water_surface_pseudo_floor()
-- ...
diff --git a/docs/lua/functions-5.md b/docs/lua/functions-5.md
index 74120dd8..1786e256 100644
--- a/docs/lua/functions-5.md
+++ b/docs/lua/functions-5.md
@@ -468,6 +468,27 @@
+## [get_surface_from_wcd_index](#get_surface_from_wcd_index)
+
+### Lua Example
+`local SurfaceValue = get_surface_from_wcd_index(wcd, index)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| wcd | [WallCollisionData](structs.md#WallCollisionData) |
+| index | `integer` |
+
+### Returns
+[Surface](structs.md#Surface)
+
+### C Prototype
+`struct Surface* get_surface_from_wcd_index(struct WallCollisionData* wcd, s8 index);`
+
+[:arrow_up_small:](#)
+
+
+
## [get_water_surface_pseudo_floor](#get_water_surface_pseudo_floor)
### Lua Example
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index 84763c0f..2ded0dc6 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -1598,6 +1598,7 @@
- [collision_find_ceil](functions-5.md#collision_find_ceil)
- [collision_find_floor](functions-5.md#collision_find_floor)
- [collision_get_temp_wall_collision_data](functions-5.md#collision_get_temp_wall_collision_data)
+ - [get_surface_from_wcd_index](functions-5.md#get_surface_from_wcd_index)
- [get_water_surface_pseudo_floor](functions-5.md#get_water_surface_pseudo_floor)
- [smlua_collision_util_get](functions-5.md#smlua_collision_util_get)
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index 8fdd2f51..32502ce5 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -28398,6 +28398,25 @@ int smlua_func_collision_get_temp_wall_collision_data(UNUSED lua_State* L) {
return 1;
}
+int smlua_func_get_surface_from_wcd_index(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_surface_from_wcd_index", 2, top);
+ return 0;
+ }
+
+ struct WallCollisionData* wcd = (struct WallCollisionData*)smlua_to_cobject(L, 1, LOT_WALLCOLLISIONDATA);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "get_surface_from_wcd_index"); return 0; }
+ s8 index = smlua_to_integer(L, 2);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "get_surface_from_wcd_index"); return 0; }
+
+ smlua_push_object(L, LOT_SURFACE, get_surface_from_wcd_index(wcd, index));
+
+ return 1;
+}
+
int smlua_func_get_water_surface_pseudo_floor(UNUSED lua_State* L) {
if (L == NULL) { return 0; }
@@ -34135,6 +34154,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "collision_find_ceil", smlua_func_collision_find_ceil);
smlua_bind_function(L, "collision_find_floor", smlua_func_collision_find_floor);
smlua_bind_function(L, "collision_get_temp_wall_collision_data", smlua_func_collision_get_temp_wall_collision_data);
+ smlua_bind_function(L, "get_surface_from_wcd_index", smlua_func_get_surface_from_wcd_index);
smlua_bind_function(L, "get_water_surface_pseudo_floor", smlua_func_get_water_surface_pseudo_floor);
smlua_bind_function(L, "smlua_collision_util_get", smlua_func_smlua_collision_util_get);
diff --git a/src/pc/lua/utils/smlua_collision_utils.c b/src/pc/lua/utils/smlua_collision_utils.c
index d8834e4b..8be738c4 100644
--- a/src/pc/lua/utils/smlua_collision_utils.c
+++ b/src/pc/lua/utils/smlua_collision_utils.c
@@ -190,3 +190,8 @@ struct WallCollisionData* collision_get_temp_wall_collision_data(void) {
memset(&sTmpWcd, 0, sizeof(struct WallCollisionData));
return &sTmpWcd;
}
+
+struct Surface* get_surface_from_wcd_index(struct WallCollisionData* wcd, s8 index) {
+ if (index < 0 || index >= 4) { return NULL; }
+ return wcd->walls[index];
+}
diff --git a/src/pc/lua/utils/smlua_collision_utils.h b/src/pc/lua/utils/smlua_collision_utils.h
index 3dbc8244..fe4af6ad 100644
--- a/src/pc/lua/utils/smlua_collision_utils.h
+++ b/src/pc/lua/utils/smlua_collision_utils.h
@@ -124,4 +124,6 @@ Collision* smlua_collision_util_get(const char* name);
struct WallCollisionData* collision_get_temp_wall_collision_data(void);
+struct Surface* get_surface_from_wcd_index(struct WallCollisionData* wcd, s8 index);
+
#endif