Add "-- pausable" field for mods and function so mods can make themselves pausable in singleplayer

This commit is contained in:
Agent X 2024-03-04 19:25:09 -05:00
parent fe75dbfa28
commit 89e9bcdcec
17 changed files with 75 additions and 7 deletions

View file

@ -5885,6 +5885,11 @@ function network_player_set_description(np, description, r, g, b, a)
-- ...
end
--- @return boolean
function network_check_singleplayer_pause()
-- ...
end
--- @param localIndex integer
--- @return string
function network_get_player_text_color_string(localIndex)

View file

@ -1061,6 +1061,7 @@
--- @field public index integer
--- @field public isDirectory boolean
--- @field public name string
--- @field public pausable boolean
--- @field public relativePath string
--- @field public renderBehindHud boolean
--- @field public selectable boolean

View file

@ -354,6 +354,24 @@
<br />
## [network_check_singleplayer_pause](#network_check_singleplayer_pause)
### Lua Example
`local booleanValue = network_check_singleplayer_pause()`
### Parameters
- None
### Returns
- `boolean`
### C Prototype
`bool network_check_singleplayer_pause(void);`
[:arrow_up_small:](#)
<br />
## [network_get_player_text_color_string](#network_get_player_text_color_string)
### Lua Example

View file

@ -1155,6 +1155,7 @@
<br />
- network_utils.h
- [network_check_singleplayer_pause](functions-4.md#network_check_singleplayer_pause)
- [network_get_player_text_color_string](functions-4.md#network_get_player_text_color_string)
- [network_global_index_from_local](functions-4.md#network_global_index_from_local)
- [network_is_moderator](functions-4.md#network_is_moderator)

View file

@ -1435,6 +1435,7 @@
| index | `integer` | read-only |
| isDirectory | `boolean` | read-only |
| name | `string` | read-only |
| pausable | `boolean` | read-only |
| relativePath | `string` | read-only |
| renderBehindHud | `boolean` | read-only |
| selectable | `boolean` | read-only |

View file

@ -1275,7 +1275,6 @@ static BhvCommandProc BehaviorCmdTable[BEHAVIOR_CMD_TABLE_MAX] = {
bhv_cmd_load_collision_data_ext, //41
};
extern s16 gMenuMode;
// Execute the behavior script of the current object, process the object flags, and other miscellaneous code for updating objects.
void cur_obj_update(void) {
if (!gCurrentObject) { return; }
@ -1287,7 +1286,7 @@ void cur_obj_update(void) {
}
// handle network area timer
if (gCurrentObject->areaTimerType != AREA_TIMER_TYPE_NONE && !(gMenuMode != -1 && network_player_connected_count() == 1 && gActiveMods.entryCount == 0)) {
if (gCurrentObject->areaTimerType != AREA_TIMER_TYPE_NONE && !network_check_singleplayer_pause()) {
// make sure the area is valid
if (gNetworkPlayerLocal == NULL || !gNetworkPlayerLocal->currAreaSyncValid) {
goto cur_obj_update_end;
@ -1437,7 +1436,7 @@ cur_obj_update_begin:;
}
// update network area timer
if (gCurrentObject->areaTimerType != AREA_TIMER_TYPE_NONE && !(gMenuMode != -1 && network_player_connected_count() == 1 && gActiveMods.entryCount == 0)) {
if (gCurrentObject->areaTimerType != AREA_TIMER_TYPE_NONE && !network_check_singleplayer_pause()) {
gCurrentObject->areaTimer++;
if (gCurrentObject->areaTimer < gNetworkAreaTimer) {
goto cur_obj_update_begin;

View file

@ -1669,7 +1669,7 @@ s32 update_level(void) {
changeLevel = play_mode_normal();
break;
case PLAY_MODE_PAUSED:
if (!(network_player_connected_count() == 1 && gActiveMods.entryCount == 0)) {
if (!network_check_singleplayer_pause()) {
changeLevel = play_mode_normal();
}

View file

@ -1177,7 +1177,7 @@ static struct LuaObjectField sMarioStateFields[LUA_MARIO_STATE_FIELD_COUNT] = {
{ "waterLevel", LVT_S16, offsetof(struct MarioState, waterLevel), false, LOT_NONE },
};
#define LUA_MOD_FIELD_COUNT 13
#define LUA_MOD_FIELD_COUNT 14
static struct LuaObjectField sModFields[LUA_MOD_FIELD_COUNT] = {
{ "basePath", LVT_STRING, offsetof(struct Mod, basePath), true, LOT_NONE },
{ "customBehaviorIndex", LVT_U8, offsetof(struct Mod, customBehaviorIndex), true, LOT_NONE },
@ -1189,6 +1189,7 @@ static struct LuaObjectField sModFields[LUA_MOD_FIELD_COUNT] = {
{ "index", LVT_S32, offsetof(struct Mod, index), true, LOT_NONE },
{ "isDirectory", LVT_BOOL, offsetof(struct Mod, isDirectory), true, LOT_NONE },
{ "name", LVT_STRING_P, offsetof(struct Mod, name), true, LOT_NONE },
{ "pausable", LVT_BOOL, offsetof(struct Mod, pausable), true, LOT_NONE },
{ "relativePath", LVT_STRING, offsetof(struct Mod, relativePath), true, LOT_NONE },
{ "renderBehindHud", LVT_BOOL, offsetof(struct Mod, renderBehindHud), true, LOT_NONE },
{ "selectable", LVT_BOOL, offsetof(struct Mod, selectable), true, LOT_NONE },

View file

@ -20003,6 +20003,21 @@ int smlua_func_network_player_set_description(lua_State* L) {
// network_utils.h //
/////////////////////
int smlua_func_network_check_singleplayer_pause(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", "network_check_singleplayer_pause", 0, top);
return 0;
}
lua_pushboolean(L, network_check_singleplayer_pause());
return 1;
}
int smlua_func_network_get_player_text_color_string(lua_State* L) {
if (L == NULL) { return 0; }
@ -32586,6 +32601,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "network_player_set_description", smlua_func_network_player_set_description);
// network_utils.h
smlua_bind_function(L, "network_check_singleplayer_pause", smlua_func_network_check_singleplayer_pause);
smlua_bind_function(L, "network_get_player_text_color_string", smlua_func_network_get_player_text_color_string);
smlua_bind_function(L, "network_global_index_from_local", smlua_func_network_global_index_from_local);
smlua_bind_function(L, "network_is_moderator", smlua_func_network_is_moderator);

View file

@ -434,6 +434,8 @@ static void mod_extract_fields(struct Mod* mod) {
}
} else if (!mod->deluxe && (extracted = extract_lua_field("-- deluxe:", buffer))) {
mod->deluxe = !strcmp(extracted, "true");
} else if (!mod->pausable && (extracted = extract_lua_field("-- pausable:", buffer))) {
mod->pausable = !strcmp(extracted, "true");
}
}

View file

@ -35,6 +35,7 @@ struct Mod {
bool selectable;
bool renderBehindHud;
bool deluxe;
bool pausable;
size_t size;
u8 customBehaviorIndex;
};

View file

@ -61,6 +61,19 @@ u16 mods_get_character_select_count(void) {
return enabled;
}
bool mods_get_all_pausable(void) {
bool pausable = true;
for (u16 i = 0; i < gActiveMods.entryCount; i++) {
if (!gActiveMods.entries[i]->pausable) {
pausable = false;
break;
}
}
return pausable;
}
static void mods_local_store_enabled(void) {
assert(sLocalEnabledPaths == NULL);
struct LocalEnabledPath* prev = NULL;

View file

@ -25,6 +25,7 @@ extern char gRemoteModsBasePath[];
void mods_get_main_mod_name(char* destination, u32 maxSize);
u16 mods_get_enabled_count(void);
u16 mods_get_character_select_count(void);
bool mods_get_all_pausable(void);
bool mods_generate_remote_base_path(void);
void mods_activate(struct Mods* mods);
void mods_clear(struct Mods* mods);

View file

@ -502,7 +502,6 @@ static void network_rehost_update(void) {
djui_panel_do_host(true);
}
extern s16 gMenuMode;
static void network_update_area_timer(void) {
bool brokenClock = false;
#ifdef DEVELOPMENT
@ -523,7 +522,7 @@ static void network_update_area_timer(void) {
//brokenClock = (skipClockCount > 0);
#endif
if (!brokenClock) {
if (gMenuMode != -1 && network_player_connected_count() == 1 && gActiveMods.entryCount == 0) {
if (network_check_singleplayer_pause()) {
gNetworkAreaTimerClock++;
}
// update network area timer

View file

@ -1,6 +1,7 @@
#include <stdio.h>
#include "network_utils.h"
#include "game/mario_misc.h"
#include "pc/mods/mods.h"
u8 network_global_index_from_local(u8 localIndex) {
if (gNetworkType == NT_SERVER) { return localIndex; }
@ -49,3 +50,8 @@ const char* network_get_player_text_color_string(u8 localIndex) {
snprintf(sColorString, 10, "\\#%02x%02x%02x\\", rgb[0], rgb[1], rgb[2]);
return sColorString;
}
extern s16 gMenuMode;
bool network_check_singleplayer_pause(void) {
return gMenuMode != -1 && network_player_connected_count() == 1 && mods_get_all_pausable();
}

View file

@ -13,4 +13,6 @@ bool network_is_moderator(void);
u8* network_get_player_text_color(u8 localIndex);
const char* network_get_player_text_color_string(u8 localIndex);
bool network_check_singleplayer_pause(void);
#endif

View file

@ -86,6 +86,7 @@ void network_send_mod_list(void) {
packet_write(&p, &mod->isDirectory, sizeof(u8));
if (!configCoopCompatibility) {
packet_write(&p, &mod->deluxe, sizeof(u8));
packet_write(&p, &mod->pausable, sizeof(u8));
}
packet_write(&p, &mod->fileCount, sizeof(u16));
network_send_to(0, &p);
@ -227,6 +228,7 @@ void network_receive_mod_list_entry(struct Packet* p) {
packet_read(p, &mod->isDirectory, sizeof(u8));
if (!configCoopCompatibility) {
packet_read(p, &mod->deluxe, sizeof(u8));
packet_read(p, &mod->pausable, sizeof(u8));
}
normalize_path(mod->relativePath);
LOG_INFO(" '%s': %llu", mod->name, (u64)mod->size);