Expose o->collidedObjs to Lua via obj_get_collided_object function (#362)

* The function

* Autogen

* Add index parameter
This commit is contained in:
SMS Alfredo 2023-04-25 20:43:07 -05:00 committed by GitHub
parent 03ddc00525
commit 57ceb6543f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 0 deletions

View File

@ -8594,6 +8594,13 @@ function obj_count_objects_with_behavior_id(behaviorId)
-- ...
end
--- @param o Object
--- @param index integer
--- @return Object
function obj_get_collided_object(o, index)
-- ...
end
--- @param objList ObjectList
--- @return Object
function obj_get_first(objList)

View File

@ -116,6 +116,27 @@
<br />
## [obj_get_collided_object](#obj_get_collided_object)
### Lua Example
`local ObjectValue = obj_get_collided_object(o, index)`
### Parameters
| Field | Type |
| ----- | ---- |
| o | [Object](structs.md#Object) |
| index | `integer` |
### Returns
[Object](structs.md#Object)
### C Prototype
`struct Object *obj_get_collided_object(struct Object *o, s16 index);`
[:arrow_up_small:](#)
<br />
## [obj_get_first](#obj_get_first)
### Lua Example

View File

@ -1601,6 +1601,7 @@
- [obj_check_hitbox_overlap](functions-5.md#obj_check_hitbox_overlap)
- [obj_check_overlap_with_hitbox_params](functions-5.md#obj_check_overlap_with_hitbox_params)
- [obj_count_objects_with_behavior_id](functions-5.md#obj_count_objects_with_behavior_id)
- [obj_get_collided_object](functions-5.md#obj_get_collided_object)
- [obj_get_first](functions-5.md#obj_get_first)
- [obj_get_first_with_behavior_id](functions-5.md#obj_get_first_with_behavior_id)
- [obj_get_first_with_behavior_id_and_field_f32](functions-5.md#obj_get_first_with_behavior_id_and_field_f32)

View File

@ -27912,6 +27912,25 @@ int smlua_func_obj_count_objects_with_behavior_id(lua_State* L) {
return 1;
}
int smlua_func_obj_get_collided_object(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", "obj_get_collided_object", 2, top);
return 0;
}
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "obj_get_collided_object"); return 0; }
s16 index = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "obj_get_collided_object"); return 0; }
smlua_push_object(L, LOT_OBJECT, obj_get_collided_object(o, index));
return 1;
}
int smlua_func_obj_get_first(lua_State* L) {
if (L == NULL) { return 0; }
@ -30798,6 +30817,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "obj_check_hitbox_overlap", smlua_func_obj_check_hitbox_overlap);
smlua_bind_function(L, "obj_check_overlap_with_hitbox_params", smlua_func_obj_check_overlap_with_hitbox_params);
smlua_bind_function(L, "obj_count_objects_with_behavior_id", smlua_func_obj_count_objects_with_behavior_id);
smlua_bind_function(L, "obj_get_collided_object", smlua_func_obj_get_collided_object);
smlua_bind_function(L, "obj_get_first", smlua_func_obj_get_first);
smlua_bind_function(L, "obj_get_first_with_behavior_id", smlua_func_obj_get_first_with_behavior_id);
smlua_bind_function(L, "obj_get_first_with_behavior_id_and_field_f32", smlua_func_obj_get_first_with_behavior_id_and_field_f32);

View File

@ -244,6 +244,13 @@ struct Object *obj_get_next_with_same_behavior_id_and_field_f32(struct Object *o
return NULL;
}
struct Object *obj_get_collided_object(struct Object *o, s16 index) {
if (o && o->numCollidedObjs != 0 && o->numCollidedObjs > index) {
return o->collidedObjs[index];
}
return NULL;
}
struct SpawnParticlesInfo* obj_get_temp_spawn_particles_info(enum ModelExtendedId modelId) {
static struct SpawnParticlesInfo sTmpSpi = { 0 };
memset(&sTmpSpi, 0, sizeof(struct SpawnParticlesInfo));

View File

@ -32,6 +32,8 @@ struct Object *obj_get_nearest_object_with_behavior_id(struct Object *o, enum Be
s32 obj_count_objects_with_behavior_id(enum BehaviorId behaviorId);
struct Object *obj_get_collided_object(struct Object *o, s16 index);
// misc obj helpers
struct SpawnParticlesInfo* obj_get_temp_spawn_particles_info(enum ModelExtendedId modelId);