mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-01-05 07:01:18 +00:00
Expose some painting functions to Lua (#357)
* Expose some painting functions to Lua get_painting_warp_node initiate_painting_warp * Change initiate_painting_warp u8 to s16 In initiate_painting_warp, pass in -1 to not override the painting index. * Add sanity checks to get_painting_warp_node * Add requested changes
This commit is contained in:
parent
dedf75e87a
commit
52d70e33a5
9 changed files with 100 additions and 7 deletions
|
@ -72,7 +72,7 @@ override_allowed_functions = {
|
|||
"src/game/object_list_processor.h": [ "set_object_respawn_info_bits" ],
|
||||
"src/game/mario_misc.h": [ "bhv_toad.*", "bhv_unlock_door.*" ],
|
||||
"src/pc/utils/misc.h": [ "update_all_mario_stars" ],
|
||||
"src/game/level_update.h": [ "level_trigger_warp" ],
|
||||
"src/game/level_update.h": [ "level_trigger_warp", "get_painting_warp_node", "initiate_painting_warp" ],
|
||||
"src/game/area.h": [ "area_get_warp_node" ],
|
||||
"src/engine/level_script.h": [ "area_create_warp_node" ]
|
||||
}
|
||||
|
|
|
@ -4101,6 +4101,17 @@ function area_create_warp_node(id, destLevel, destArea, destNode, checkpoint, o)
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @return WarpNode
|
||||
function get_painting_warp_node()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param paintingIndex integer
|
||||
--- @return nil
|
||||
function initiate_painting_warp(paintingIndex)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param m MarioState
|
||||
--- @param warpOp integer
|
||||
--- @return integer
|
||||
|
|
|
@ -3567,6 +3567,44 @@
|
|||
<br />
|
||||
|
||||
|
||||
## [get_painting_warp_node](#get_painting_warp_node)
|
||||
|
||||
### Lua Example
|
||||
`local WarpNodeValue = get_painting_warp_node()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
[WarpNode](structs.md#WarpNode)
|
||||
|
||||
### C Prototype
|
||||
`struct WarpNode *get_painting_warp_node(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [initiate_painting_warp](#initiate_painting_warp)
|
||||
|
||||
### Lua Example
|
||||
`initiate_painting_warp(paintingIndex)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| paintingIndex | `integer` |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void initiate_painting_warp(s16 paintingIndex);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [level_trigger_warp](#level_trigger_warp)
|
||||
|
||||
### Lua Example
|
||||
|
|
|
@ -816,6 +816,8 @@
|
|||
<br />
|
||||
|
||||
- level_update.h
|
||||
- [get_painting_warp_node](functions-3.md#get_painting_warp_node)
|
||||
- [initiate_painting_warp](functions-3.md#initiate_painting_warp)
|
||||
- [level_trigger_warp](functions-3.md#level_trigger_warp)
|
||||
|
||||
<br />
|
||||
|
|
|
@ -626,9 +626,9 @@ static void level_cmd_create_painting_warp_node(void) {
|
|||
if (sCurrAreaIndex != -1) {
|
||||
if (gAreas[sCurrAreaIndex].paintingWarpNodes == NULL) {
|
||||
gAreas[sCurrAreaIndex].paintingWarpNodes =
|
||||
alloc_only_pool_alloc(sLevelPool, 45 * sizeof(struct WarpNode));
|
||||
alloc_only_pool_alloc(sLevelPool, MAX_PAINTING_WARP_NODES * sizeof(struct WarpNode));
|
||||
|
||||
for (i = 0; i < 45; i++) {
|
||||
for (i = 0; i < MAX_PAINTING_WARP_NODES; i++) {
|
||||
gAreas[sCurrAreaIndex].paintingWarpNodes[i].id = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <PR/ultratypes.h>
|
||||
|
||||
#define MAX_PAINTING_WARP_NODES 45
|
||||
|
||||
struct LevelCommand;
|
||||
|
||||
extern s32 gLevelScriptModIndex;
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
|
||||
#include "game/screen_transition.h"
|
||||
|
||||
#include "engine/level_script.h"
|
||||
|
||||
#define WARP_NODE_F0 0xF0
|
||||
#define WARP_NODE_DEATH 0xF1
|
||||
#define WARP_NODE_F2 0xF2
|
||||
|
@ -748,6 +750,8 @@ void initiate_warp(s16 destLevel, s16 destArea, s16 destWarpNode, s32 arg3) {
|
|||
* corresponding warp node.
|
||||
*/
|
||||
struct WarpNode *get_painting_warp_node(void) {
|
||||
if (!gMarioState || !gMarioState->floor || !gCurrentArea || !gCurrentArea->paintingWarpNodes) { return NULL; }
|
||||
|
||||
struct WarpNode *warpNode = NULL;
|
||||
s32 paintingIndex = gMarioState->floor->type - SURFACE_PAINTING_WARP_D3;
|
||||
|
||||
|
@ -783,9 +787,9 @@ static void initiate_painting_warp_node(struct WarpNode *pWarpNode) {
|
|||
/**
|
||||
* Check is Mario has entered a painting, and if so, initiate a warp.
|
||||
*/
|
||||
void initiate_painting_warp(void) {
|
||||
if (gCurrentArea != NULL && gCurrentArea->paintingWarpNodes != NULL && gMarioState->floor != NULL) {
|
||||
struct WarpNode *pWarpNode = get_painting_warp_node();
|
||||
void initiate_painting_warp(s16 paintingIndex) {
|
||||
if (gCurrentArea && gCurrentArea->paintingWarpNodes && gMarioState && gMarioState->floor && paintingIndex >= 0 && paintingIndex < MAX_PAINTING_WARP_NODES) {
|
||||
struct WarpNode *pWarpNode = paintingIndex == -1 ? get_painting_warp_node() : &gCurrentArea->paintingWarpNodes[paintingIndex];
|
||||
|
||||
if (pWarpNode != NULL) {
|
||||
if (gMarioState->action & ACT_FLAG_INTANGIBLE) {
|
||||
|
@ -1229,7 +1233,7 @@ s32 play_mode_normal(void) {
|
|||
update_camera(gCurrentArea->camera);
|
||||
}
|
||||
|
||||
initiate_painting_warp();
|
||||
initiate_painting_warp(-1);
|
||||
initiate_delayed_warp();
|
||||
|
||||
// If either initiate_painting_warp or initiate_delayed_warp initiated a
|
||||
|
|
|
@ -151,6 +151,8 @@ u8 level_control_timer_running(void);
|
|||
u16 level_control_timer(s32 timerOp);
|
||||
void fade_into_special_warp(u32 arg, u32 color);
|
||||
void load_level_init_text(u32 arg);
|
||||
struct WarpNode *get_painting_warp_node(void);
|
||||
void initiate_painting_warp(s16 paintingIndex);
|
||||
s16 level_trigger_warp(struct MarioState *m, s32 warpOp);
|
||||
void level_set_transition(s16 length, void (*updateFunction)(s16 *));
|
||||
|
||||
|
|
|
@ -12899,6 +12899,38 @@ int smlua_func_area_create_warp_node(lua_State* L) {
|
|||
// level_update.h //
|
||||
////////////////////
|
||||
|
||||
int smlua_func_get_painting_warp_node(UNUSED lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
int top = lua_gettop(L);
|
||||
if (top != 0) {
|
||||
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "get_painting_warp_node", 0, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
smlua_push_object(L, LOT_WARPNODE, get_painting_warp_node());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_initiate_painting_warp(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", "initiate_painting_warp", 1, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s16 paintingIndex = smlua_to_integer(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "initiate_painting_warp"); return 0; }
|
||||
|
||||
initiate_painting_warp(paintingIndex);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_level_trigger_warp(lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
|
@ -30135,6 +30167,8 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "area_create_warp_node", smlua_func_area_create_warp_node);
|
||||
|
||||
// level_update.h
|
||||
smlua_bind_function(L, "get_painting_warp_node", smlua_func_get_painting_warp_node);
|
||||
smlua_bind_function(L, "initiate_painting_warp", smlua_func_initiate_painting_warp);
|
||||
smlua_bind_function(L, "level_trigger_warp", smlua_func_level_trigger_warp);
|
||||
|
||||
// mario.h
|
||||
|
|
Loading…
Reference in a new issue