Expose first_person_check_cancels() to Lua

This commit is contained in:
Agent X 2023-11-27 11:14:36 -05:00
parent 632d8de0b2
commit 471a6c8c05
6 changed files with 55 additions and 11 deletions

View file

@ -4000,6 +4000,12 @@ function stop_sounds_in_continuous_banks()
-- ... -- ...
end end
--- @param m MarioState
--- @return boolean
function first_person_check_cancels(m)
-- ...
end
--- @return nil --- @return nil
function first_person_reset() function first_person_reset()
-- ... -- ...

View file

@ -3266,6 +3266,26 @@
<br /> <br />
## [first_person_check_cancels](#first_person_check_cancels)
### Lua Example
`local booleanValue = first_person_check_cancels(m)`
### Parameters
| Field | Type |
| ----- | ---- |
| m | [MarioState](structs.md#MarioState) |
### Returns
- `boolean`
### C Prototype
`bool first_person_check_cancels(struct MarioState *m);`
[:arrow_up_small:](#)
<br />
## [first_person_reset](#first_person_reset) ## [first_person_reset](#first_person_reset)
### Lua Example ### Lua Example

View file

@ -800,6 +800,7 @@
<br /> <br />
- first_person_cam.h - first_person_cam.h
- [first_person_check_cancels](functions-3.md#first_person_check_cancels)
- [first_person_reset](functions-3.md#first_person_reset) - [first_person_reset](functions-3.md#first_person_reset)
- [get_first_person_enabled](functions-3.md#get_first_person_enabled) - [get_first_person_enabled](functions-3.md#get_first_person_enabled)
- [set_first_person_enabled](functions-3.md#set_first_person_enabled) - [set_first_person_enabled](functions-3.md#set_first_person_enabled)

View file

@ -30,9 +30,7 @@ struct FirstPersonCamera gFirstPersonCamera = {
extern s16 gMenuMode; extern s16 gMenuMode;
bool first_person_check_cancels(void) { bool first_person_check_cancels(struct MarioState *m) {
struct MarioState *m = &gMarioStates[0];
if (m->action == ACT_FIRST_PERSON || m->action == ACT_IN_CANNON || m->action == ACT_READING_NPC_DIALOG || m->action == ACT_DISAPPEARED) { if (m->action == ACT_FIRST_PERSON || m->action == ACT_IN_CANNON || m->action == ACT_READING_NPC_DIALOG || m->action == ACT_DISAPPEARED) {
return true; return true;
} }
@ -48,7 +46,7 @@ bool first_person_check_cancels(void) {
} }
bool get_first_person_enabled(void) { bool get_first_person_enabled(void) {
return gFirstPersonCamera.enabled && !first_person_check_cancels(); return gFirstPersonCamera.enabled && !first_person_check_cancels(&gMarioStates[0]);
} }
void set_first_person_enabled(bool enable) { void set_first_person_enabled(bool enable) {
@ -144,12 +142,12 @@ void first_person_camera_update(void) {
void first_person_update(void) { void first_person_update(void) {
if (gFirstPersonCamera.enabled && !gDjuiInMainMenu) { if (gFirstPersonCamera.enabled && !gDjuiInMainMenu) {
// check cancels
bool cancel = first_person_check_cancels();
if (cancel) { return; }
struct MarioState *m = &gMarioStates[0]; struct MarioState *m = &gMarioStates[0];
// check cancels
bool cancel = first_person_check_cancels(m);
if (cancel) { return; }
if (m->action == ACT_SHOT_FROM_CANNON && m->area->camera->mode == CAMERA_MODE_INSIDE_CANNON) { if (m->action == ACT_SHOT_FROM_CANNON && m->area->camera->mode == CAMERA_MODE_INSIDE_CANNON) {
gFirstPersonCamera.yaw = m->faceAngle[1] + 0x8000; gFirstPersonCamera.yaw = m->faceAngle[1] + 0x8000;
m->area->camera->mode = CAMERA_MODE_FREE_ROAM; m->area->camera->mode = CAMERA_MODE_FREE_ROAM;

View file

@ -1,8 +1,7 @@
#ifndef FIRST_PERSON_CAM_H #ifndef FIRST_PERSON_CAM_H
#define FIRST_PERSON_CAM_H #define FIRST_PERSON_CAM_H
#include <stdbool.h> #include "types.h"
#include <PR/ultratypes.h>
#define FIRST_PERSON_DEFAULT_FOV 70 #define FIRST_PERSON_DEFAULT_FOV 70
@ -16,10 +15,12 @@ struct FirstPersonCamera {
extern struct FirstPersonCamera gFirstPersonCamera; extern struct FirstPersonCamera gFirstPersonCamera;
bool first_person_check_cancels(struct MarioState *m);
bool get_first_person_enabled(void); bool get_first_person_enabled(void);
void set_first_person_enabled(bool enable); void set_first_person_enabled(bool enable);
void first_person_update(void); void first_person_update(void);
void first_person_reset(void); void first_person_reset(void);
#endif #endif // FIRST_PERSON_CAM_H

View file

@ -13184,6 +13184,23 @@ int smlua_func_stop_sounds_in_continuous_banks(UNUSED lua_State* L) {
// first_person_cam.h // // first_person_cam.h //
//////////////////////// ////////////////////////
int smlua_func_first_person_check_cancels(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", "first_person_check_cancels", 1, top);
return 0;
}
struct MarioState* m = (struct MarioState*)smlua_to_cobject(L, 1, LOT_MARIOSTATE);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "first_person_check_cancels"); return 0; }
lua_pushboolean(L, first_person_check_cancels(m));
return 1;
}
int smlua_func_first_person_reset(UNUSED lua_State* L) { int smlua_func_first_person_reset(UNUSED lua_State* L) {
if (L == NULL) { return 0; } if (L == NULL) { return 0; }
@ -32039,6 +32056,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "stop_sounds_in_continuous_banks", smlua_func_stop_sounds_in_continuous_banks); smlua_bind_function(L, "stop_sounds_in_continuous_banks", smlua_func_stop_sounds_in_continuous_banks);
// first_person_cam.h // first_person_cam.h
smlua_bind_function(L, "first_person_check_cancels", smlua_func_first_person_check_cancels);
smlua_bind_function(L, "first_person_reset", smlua_func_first_person_reset); smlua_bind_function(L, "first_person_reset", smlua_func_first_person_reset);
smlua_bind_function(L, "get_first_person_enabled", smlua_func_get_first_person_enabled); smlua_bind_function(L, "get_first_person_enabled", smlua_func_get_first_person_enabled);
smlua_bind_function(L, "set_first_person_enabled", smlua_func_set_first_person_enabled); smlua_bind_function(L, "set_first_person_enabled", smlua_func_set_first_person_enabled);