From 471a6c8c052596bd41f4ad8b04a39b6f787ea7b8 Mon Sep 17 00:00:00 2001
From: Agent X <44549182+Agent-11@users.noreply.github.com>
Date: Mon, 27 Nov 2023 11:14:36 -0500
Subject: [PATCH] Expose first_person_check_cancels() to Lua
---
autogen/lua_definitions/functions.lua | 6 ++++++
docs/lua/functions-3.md | 20 ++++++++++++++++++++
docs/lua/functions.md | 1 +
src/game/first_person_cam.c | 14 ++++++--------
src/game/first_person_cam.h | 7 ++++---
src/pc/lua/smlua_functions_autogen.c | 18 ++++++++++++++++++
6 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index 20d75b8b..b75cbdff 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -4000,6 +4000,12 @@ function stop_sounds_in_continuous_banks()
-- ...
end
+--- @param m MarioState
+--- @return boolean
+function first_person_check_cancels(m)
+ -- ...
+end
+
--- @return nil
function first_person_reset()
-- ...
diff --git a/docs/lua/functions-3.md b/docs/lua/functions-3.md
index 16c52476..b21fea45 100644
--- a/docs/lua/functions-3.md
+++ b/docs/lua/functions-3.md
@@ -3266,6 +3266,26 @@
+## [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:](#)
+
+
+
## [first_person_reset](#first_person_reset)
### Lua Example
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index b1d6b8c3..ec99518c 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -800,6 +800,7 @@
- first_person_cam.h
+ - [first_person_check_cancels](functions-3.md#first_person_check_cancels)
- [first_person_reset](functions-3.md#first_person_reset)
- [get_first_person_enabled](functions-3.md#get_first_person_enabled)
- [set_first_person_enabled](functions-3.md#set_first_person_enabled)
diff --git a/src/game/first_person_cam.c b/src/game/first_person_cam.c
index 81e5b52a..f5cb268a 100644
--- a/src/game/first_person_cam.c
+++ b/src/game/first_person_cam.c
@@ -30,9 +30,7 @@ struct FirstPersonCamera gFirstPersonCamera = {
extern s16 gMenuMode;
-bool first_person_check_cancels(void) {
- struct MarioState *m = &gMarioStates[0];
-
+bool first_person_check_cancels(struct MarioState *m) {
if (m->action == ACT_FIRST_PERSON || m->action == ACT_IN_CANNON || m->action == ACT_READING_NPC_DIALOG || m->action == ACT_DISAPPEARED) {
return true;
}
@@ -48,7 +46,7 @@ bool first_person_check_cancels(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) {
@@ -144,12 +142,12 @@ void first_person_camera_update(void) {
void first_person_update(void) {
if (gFirstPersonCamera.enabled && !gDjuiInMainMenu) {
- // check cancels
- bool cancel = first_person_check_cancels();
- if (cancel) { return; }
-
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) {
gFirstPersonCamera.yaw = m->faceAngle[1] + 0x8000;
m->area->camera->mode = CAMERA_MODE_FREE_ROAM;
diff --git a/src/game/first_person_cam.h b/src/game/first_person_cam.h
index e91f3e03..4146c6b5 100644
--- a/src/game/first_person_cam.h
+++ b/src/game/first_person_cam.h
@@ -1,8 +1,7 @@
#ifndef FIRST_PERSON_CAM_H
#define FIRST_PERSON_CAM_H
-#include
-#include
+#include "types.h"
#define FIRST_PERSON_DEFAULT_FOV 70
@@ -16,10 +15,12 @@ struct FirstPersonCamera {
extern struct FirstPersonCamera gFirstPersonCamera;
+bool first_person_check_cancels(struct MarioState *m);
+
bool get_first_person_enabled(void);
void set_first_person_enabled(bool enable);
void first_person_update(void);
void first_person_reset(void);
-#endif
\ No newline at end of file
+#endif // FIRST_PERSON_CAM_H
\ No newline at end of file
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index aa2045c2..6e20a5fd 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -13184,6 +13184,23 @@ int smlua_func_stop_sounds_in_continuous_banks(UNUSED lua_State* L) {
// 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) {
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);
// 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, "get_first_person_enabled", smlua_func_get_first_person_enabled);
smlua_bind_function(L, "set_first_person_enabled", smlua_func_set_first_person_enabled);