mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-22 01:52:43 +00:00
Display a message on screen when script errors are found
This commit is contained in:
parent
ef5d1b222b
commit
12ea360360
7 changed files with 48 additions and 2 deletions
|
|
@ -23,7 +23,7 @@ void DynOS_Actor_AddCustom(const SysPath &aFilename, const char *aActorName) {
|
|||
|
||||
GfxData *_GfxData = DynOS_Actor_LoadFromBinary(aFilename, actorName, aFilename);
|
||||
if (!_GfxData) {
|
||||
Print(" ERROR: Couldn't load Actor Binary \"%s\" from \"%s\"", actorName, aPackFolder.c_str());
|
||||
Print(" ERROR: Couldn't load Actor Binary \"%s\" from \"%s\"", actorName, aFilename.c_str());
|
||||
free(actorName);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ static Gfx* sSavedDisplayListHead = NULL;
|
|||
|
||||
struct DjuiRoot* gDjuiRoot = NULL;
|
||||
static struct DjuiText* sDjuiPauseOptions = NULL;
|
||||
static struct DjuiText* sDjuiLuaError = NULL;
|
||||
static u32 sDjuiLuaErrorTimeout = 0;
|
||||
bool gDjuiInMainMenu = true;
|
||||
bool gDjuiDisabled = false;
|
||||
|
||||
|
|
@ -24,6 +26,15 @@ void djui_init(void) {
|
|||
djui_text_set_alignment(sDjuiPauseOptions, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
|
||||
djui_base_set_visible(&sDjuiPauseOptions->base, false);
|
||||
|
||||
sDjuiLuaError = djui_text_create(&gDjuiRoot->base, "");
|
||||
djui_base_set_size_type(&sDjuiLuaError->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_base_set_size(&sDjuiLuaError->base, 1.0f, 32);
|
||||
djui_base_set_location(&sDjuiLuaError->base, 0, 64);
|
||||
djui_text_set_drop_shadow(sDjuiLuaError, 0, 0, 0, 255);
|
||||
djui_text_set_alignment(sDjuiLuaError, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
|
||||
djui_base_set_visible(&sDjuiLuaError->base, false);
|
||||
djui_base_set_color(&sDjuiLuaError->base, 255, 0, 0, 255);
|
||||
|
||||
djui_panel_playerlist_create(NULL);
|
||||
|
||||
if (gCLIOpts.Network != NT_SERVER) {
|
||||
|
|
@ -41,6 +52,12 @@ void djui_connect_menu_open(void) {
|
|||
djui_panel_join_message_create(NULL);
|
||||
}
|
||||
|
||||
void djui_lua_error(char* text) {
|
||||
djui_text_set_text(sDjuiLuaError, text);
|
||||
djui_base_set_visible(&sDjuiLuaError->base, true);
|
||||
sDjuiLuaErrorTimeout = 30 * 5;
|
||||
}
|
||||
|
||||
void djui_render_patch(void) {
|
||||
// reset the head and re-render DJUI
|
||||
if (sSavedDisplayListHead == NULL) { return; }
|
||||
|
|
@ -67,6 +84,13 @@ void djui_render(void) {
|
|||
djui_base_render(&gDjuiRoot->base);
|
||||
}
|
||||
|
||||
if (sDjuiLuaErrorTimeout > 0) {
|
||||
sDjuiLuaErrorTimeout--;
|
||||
if (sDjuiLuaErrorTimeout == 0) {
|
||||
djui_base_set_visible(&sDjuiLuaError->base, false);
|
||||
}
|
||||
}
|
||||
|
||||
djui_cursor_update();
|
||||
djui_interactable_update();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,5 +65,6 @@ extern bool gDjuiDisabled;
|
|||
|
||||
void djui_init(void);
|
||||
void djui_connect_menu_open(void);
|
||||
void djui_lua_error(char* text);
|
||||
void djui_render_patch(void);
|
||||
void djui_render(void);
|
||||
|
|
|
|||
|
|
@ -4,11 +4,22 @@
|
|||
#include "pc/crash_handler.h"
|
||||
#include "pc/lua/utils/smlua_text_utils.h"
|
||||
#include "pc/lua/utils/smlua_audio_utils.h"
|
||||
#include "pc/djui/djui.h"
|
||||
|
||||
lua_State* gLuaState = NULL;
|
||||
u8 gLuaInitializingScript = 0;
|
||||
struct Mod* gLuaLoadingMod = NULL;
|
||||
struct Mod* gLuaActiveMod = NULL;
|
||||
struct Mod* gLuaLastHookMod = NULL;
|
||||
|
||||
void smlua_mod_error(void) {
|
||||
struct Mod* mod = gLuaActiveMod;
|
||||
if (mod == NULL) { mod = gLuaLastHookMod; }
|
||||
if (mod == NULL) { return; }
|
||||
char txt[255] = { 0 };
|
||||
snprintf(txt, 254, "%s has lua script errors!", mod->name);
|
||||
djui_lua_error(txt);
|
||||
}
|
||||
|
||||
static void smlua_exec_file(char* path) {
|
||||
lua_State* L = gLuaState;
|
||||
|
|
@ -124,6 +135,7 @@ void smlua_init(void) {
|
|||
LOG_INFO(" %s", mod->relativePath);
|
||||
gLuaLoadingMod = mod;
|
||||
gLuaActiveMod = mod;
|
||||
gLuaLastHookMod = mod;
|
||||
gPcDebug.lastModRun = gLuaActiveMod;
|
||||
for (int j = 0; j < mod->fileCount; j++) {
|
||||
struct ModFile* file = &mod->files[j];
|
||||
|
|
@ -153,4 +165,7 @@ void smlua_shutdown(void) {
|
|||
lua_close(L);
|
||||
gLuaState = NULL;
|
||||
}
|
||||
gLuaLoadingMod = NULL;
|
||||
gLuaActiveMod = NULL;
|
||||
gLuaLastHookMod = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "pc/debuglog.h"
|
||||
|
||||
#define LOG_LUA(...) ( _debuglog_print_log("LUA ", __FILE__), printf(__VA_ARGS__), printf("\n") )
|
||||
#define LOG_LUA(...) ( _debuglog_print_log("LUA ", __FILE__), printf(__VA_ARGS__), printf("\n"), smlua_mod_error() )
|
||||
|
||||
#ifdef DEVELOPMENT
|
||||
#define LUA_STACK_CHECK_BEGIN() int __LUA_STACK_TOP = lua_gettop(gLuaState)
|
||||
|
|
@ -33,6 +33,9 @@ extern lua_State* gLuaState;
|
|||
extern u8 gLuaInitializingScript;
|
||||
extern struct Mod* gLuaLoadingMod;
|
||||
extern struct Mod* gLuaActiveMod;
|
||||
extern struct Mod* gLuaLastHookMod;
|
||||
|
||||
void smlua_mod_error(void);
|
||||
|
||||
void smlua_init(void);
|
||||
void smlua_update(void);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ static struct LuaHookedEvent sHookedEvents[HOOK_MAX] = { 0 };
|
|||
static int smlua_call_hook(lua_State* L, int nargs, int nresults, int errfunc, struct Mod* activeMod) {
|
||||
struct Mod* prev = gLuaActiveMod;
|
||||
gLuaActiveMod = activeMod;
|
||||
gLuaLastHookMod = activeMod;
|
||||
int rc = lua_pcall(L, nargs, nresults, errfunc);
|
||||
gLuaActiveMod = prev;
|
||||
return rc;
|
||||
|
|
@ -440,6 +441,7 @@ bool smlua_call_action_hook(struct MarioState* m, s32* returnValue) {
|
|||
}
|
||||
|
||||
// output the return value
|
||||
*returnValue = false;
|
||||
if (lua_type(L, -1) == LUA_TBOOLEAN || lua_type(L, -1) == LUA_TNUMBER) {
|
||||
*returnValue = smlua_to_integer(L, -1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,6 +145,7 @@ static void smlua_sync_table_call_hook(int syncTableIndex, int keyIndex, int pre
|
|||
// call hook
|
||||
struct Mod* prev = gLuaActiveMod;
|
||||
gLuaActiveMod = mod;
|
||||
gLuaLastHookMod = mod;
|
||||
gPcDebug.lastModRun = gLuaActiveMod;
|
||||
if (0 != lua_pcall(L, 3, 0, 0)) {
|
||||
LOG_LUA("Failed to call the hook_on_changed callback: %s", lua_tostring(L, -1));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue