Allow custom levels to use any active mod's variables
This commit is contained in:
parent
47d3aa9220
commit
4159b7c5f5
|
@ -861,8 +861,13 @@ static void level_cmd_place_object_ext(void) {
|
||||||
gSmLuaConvertSuccess = true;
|
gSmLuaConvertSuccess = true;
|
||||||
enum BehaviorId behId = smlua_get_mod_variable(modIndex, behStr);
|
enum BehaviorId behId = smlua_get_mod_variable(modIndex, behStr);
|
||||||
|
|
||||||
|
if (!gSmLuaConvertSuccess) {
|
||||||
|
gSmLuaConvertSuccess = true;
|
||||||
|
behId = smlua_get_any_mod_variable(behStr);
|
||||||
|
}
|
||||||
|
|
||||||
if ((gLevelScriptModIndex == -1) || !gSmLuaConvertSuccess) {
|
if ((gLevelScriptModIndex == -1) || !gSmLuaConvertSuccess) {
|
||||||
LOG_ERROR("Failed to place custom object: %u", behId);
|
LOG_ERROR("Failed to place custom object: %u :: %s", behId, behStr);
|
||||||
sCurrentCmd = CMD_NEXT;
|
sCurrentCmd = CMD_NEXT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -904,7 +909,17 @@ static void level_cmd_place_object_ext2(void) {
|
||||||
|
|
||||||
gSmLuaConvertSuccess = true;
|
gSmLuaConvertSuccess = true;
|
||||||
enum ModelExtendedId modelId = smlua_get_mod_variable(modIndex, modelStr);
|
enum ModelExtendedId modelId = smlua_get_mod_variable(modIndex, modelStr);
|
||||||
|
if (!gSmLuaConvertSuccess) {
|
||||||
|
gSmLuaConvertSuccess = true;
|
||||||
|
modelId = smlua_get_any_mod_variable(modelStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
gSmLuaConvertSuccess = true;
|
||||||
enum BehaviorId behId = smlua_get_mod_variable(modIndex, behStr);
|
enum BehaviorId behId = smlua_get_mod_variable(modIndex, behStr);
|
||||||
|
if (!gSmLuaConvertSuccess) {
|
||||||
|
gSmLuaConvertSuccess = true;
|
||||||
|
behId = smlua_get_any_mod_variable(behStr);
|
||||||
|
}
|
||||||
|
|
||||||
if ((gLevelScriptModIndex == -1) || !gSmLuaConvertSuccess) {
|
if ((gLevelScriptModIndex == -1) || !gSmLuaConvertSuccess) {
|
||||||
LOG_ERROR("Failed to place custom object: %u, %u", modelId, behId);
|
LOG_ERROR("Failed to place custom object: %u, %u", modelId, behId);
|
||||||
|
|
|
@ -395,6 +395,29 @@ s64 smlua_get_mod_variable(u16 modIndex, const char* variable) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s64 smlua_get_any_mod_variable(const char* variable) {
|
||||||
|
lua_State* L = gLuaState;
|
||||||
|
|
||||||
|
s64 value = 0;
|
||||||
|
for (s32 i = 0; i < gActiveMods.entryCount; i++) {
|
||||||
|
// figure out entry
|
||||||
|
struct Mod* mod = gActiveMods.entries[i];
|
||||||
|
|
||||||
|
int prevTop = lua_gettop(L);
|
||||||
|
lua_getglobal(L, "_G"); // get global table
|
||||||
|
lua_getfield(L, LUA_REGISTRYINDEX, mod->relativePath); // get the file's "global" table
|
||||||
|
value = smlua_get_integer_field(-1, (char*)variable);
|
||||||
|
lua_settop(L, prevTop);
|
||||||
|
|
||||||
|
if (gSmLuaConvertSuccess) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// return variable
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
char* smlua_lnt_to_str(struct LSTNetworkType* lnt) {
|
char* smlua_lnt_to_str(struct LSTNetworkType* lnt) {
|
||||||
|
|
|
@ -35,6 +35,7 @@ lua_Number smlua_get_number_field(int index, char* name);
|
||||||
char* smlua_lnt_to_str(struct LSTNetworkType* lnt);
|
char* smlua_lnt_to_str(struct LSTNetworkType* lnt);
|
||||||
|
|
||||||
s64 smlua_get_mod_variable(u16 modIndex, const char* variable) ;
|
s64 smlua_get_mod_variable(u16 modIndex, const char* variable) ;
|
||||||
|
s64 smlua_get_any_mod_variable(const char* variable) ;
|
||||||
|
|
||||||
void smlua_logline(void);
|
void smlua_logline(void);
|
||||||
void smlua_dump_stack(void);
|
void smlua_dump_stack(void);
|
||||||
|
|
Loading…
Reference in New Issue