diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 25fa38769aed22267fe68a05eaa6bd59db343905..ed5736fa7f06292be4df17759de81bc2a517ced1 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -2846,6 +2846,22 @@ static int lib_rTextureNumForName(lua_State *L) return 1; } +static int lib_rCheckTextureNameForNum(lua_State *L) +{ + INT32 num = (INT32)luaL_checkinteger(L, 1); + //HUDSAFE + lua_pushstring(L, R_CheckTextureNameForNum(num)); + return 1; +} + +static int lib_rTextureNameForNum(lua_State *L) +{ + INT32 num = (INT32)luaL_checkinteger(L, 1); + //HUDSAFE + lua_pushstring(L, R_TextureNameForNum(num)); + return 1; +} + // R_DRAW //////////// static int lib_rGetColorByName(lua_State *L) @@ -4203,6 +4219,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}, diff --git a/src/r_textures.c b/src/r_textures.c index 69e64074d8acefa5e73e52e6311cc3a776d191da..8b47f455e8bc7e2e3a9cb766fb38b357b96d4091 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -1662,6 +1662,35 @@ INT32 R_CheckTextureNumForName(const char *name) return -1; } +// +// R_CheckTextureNameForNum +// +// because sidedefs use numbers and sometimes you want names +// returns no texture marker if no texture was found +// +const char *R_CheckTextureNameForNum(INT32 num) +{ + if (num > 0 && num < numtextures) + return textures[num]->name; + + return "-"; +} + +// +// R_TextureNameForNum +// +// calls R_CheckTextureNameForNum and returns REDWALL if result is a no texture marker +// +const char *R_TextureNameForNum(INT32 num) +{ + const char *result = R_CheckTextureNameForNum(num); + + if (strcmp(result, "-") == 0) + return "REDWALL"; + + return result; +} + // // R_TextureNumForName // diff --git a/src/r_textures.h b/src/r_textures.h index 4a3c10b9ec999fc133a5f5ffe220f03f86ce2ff6..394b4f8243a7fa7a0de120f2ff893bc1dc9f0702 100644 --- a/src/r_textures.h +++ b/src/r_textures.h @@ -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_CheckTextureNameForNum(INT32 num); +const char *R_TextureNameForNum(INT32 num); + extern INT32 numtextures; #endif