add R_TextureNameForNum and expose to lua

This commit is contained in:
ashifolfi 2022-11-20 15:25:53 -05:00
parent e6780f2bee
commit 3a2834e781
3 changed files with 42 additions and 0 deletions

View file

@ -2832,6 +2832,22 @@ static int lib_rTextureNumForName(lua_State *L)
return 1;
}
static int lib_rCheckTextureNameForNum(lua_State *L)
{
INT32 num = luaL_checkstring(L, 1);
//HUDSAFE
lua_pushstring(L, R_CheckTextureNameForNum(num));
return 1;
}
static int lib_rTextureNameForNum(lua_State *L)
{
INT32 num = luaL_checkstring(L, 1);
//HUDSAFE
lua_pushstring(L, R_TextureNameForNum(num));
return 1;
}
// R_DRAW
////////////
static int lib_rGetColorByName(lua_State *L)
@ -4174,6 +4190,8 @@ static luaL_Reg lib[] = {
// r_data
{"R_CheckTextureNumForName",lib_rCheckTextureNumForName},
{"R_TextureNumForName",lib_rTextureNumForName},
{"R_CheckTextureNameForNum", lib_rCheckTextureNameForNum},
{"R_TextureNameForNum", lib_rTextureNameForNum},
// r_draw
{"R_GetColorByName", lib_rGetColorByName},

View file

@ -1662,6 +1662,26 @@ INT32 R_CheckTextureNumForName(const char *name)
return -1;
}
// i was fully expecting this to take like an hour to figure out not 2 mintues and 5 lines of c - ashi
const char *R_CheckTextureNameForNum(INT32 num)
{
if (textures[num] && textures[num]->name)
{
return textures[num]->name;
}
return "-";
}
const char *R_TextureNameForNum(INT32 num)
{
const char *result = R_CheckTextureNameForNum(num);
if (strcmp(result, "-"))
return "REDWALL";
return result;
}
//
// R_TextureNumForName
//

View file

@ -104,6 +104,10 @@ INT32 R_TextureNumForName(const char *name);
INT32 R_CheckTextureNumForName(const char *name);
lumpnum_t R_GetFlatNumForName(const char *name);
// Returns the texture name for the texture number (in case you ever needed it)
const char *R_TextureNumForName(INT32 num);
const char *R_CheckTextureNumForName(INT32 num);
extern INT32 numtextures;
#endif