Add third argument to getColormap that accepts a translation name

Delete 'translations' Lua global
This commit is contained in:
Lactozilla 2024-01-19 20:50:36 -03:00
parent 4e818b87fd
commit 712c274988
2 changed files with 18 additions and 29 deletions

View file

@ -14,6 +14,7 @@
#include "fastcmp.h"
#include "r_defs.h"
#include "r_local.h"
#include "r_translation.h"
#include "st_stuff.h" // hudinfo[]
#include "g_game.h"
#include "i_video.h" // rendermode
@ -1125,7 +1126,10 @@ static int libd_getColormap(lua_State *L)
INT32 skinnum = TC_DEFAULT;
skincolornum_t color = luaL_optinteger(L, 2, 0);
UINT8* colormap = NULL;
int translation_id = -1;
HUDONLY
if (lua_isnoneornil(L, 1))
; // defaults to TC_DEFAULT
else if (lua_type(L, 1) == LUA_TNUMBER) // skin number
@ -1144,9 +1148,21 @@ static int libd_getColormap(lua_State *L)
skinnum = i;
}
// all was successful above, now we generate the colormap at last!
if (!lua_isnoneornil(L, 3))
{
const char *translation_name = luaL_checkstring(L, 3);
translation_id = R_FindCustomTranslation(translation_name);
if (translation_id == -1)
return luaL_error(L, "invalid translation '%s'.", translation_name);
}
// all was successful above, now we generate the colormap at last!
if (translation_id != -1)
colormap = R_GetTranslationRemap(translation_id, color, skinnum);
if (colormap == NULL)
colormap = R_GetTranslationColormap(skinnum, color, GTC_CACHE);
colormap = R_GetTranslationColormap(skinnum, color, GTC_CACHE);
LUA_PushUserdata(L, colormap, META_COLORMAP); // push as META_COLORMAP userdata, specifically for patches to use!
return 1;
}

View file

@ -1900,32 +1900,6 @@ static int colorramp_len(lua_State *L)
return 1;
}
//////////////////////
// TRANSLATION INFO //
//////////////////////
// Arbitrary translations[] table index -> colormap_t *
static int lib_getTranslation(lua_State *L)
{
lua_remove(L, 1);
const char *name = luaL_checkstring(L, 1);
remaptable_t *tr = R_GetTranslationByID(R_FindCustomTranslation(name));
if (tr)
LUA_PushUserdata(L, &tr->remap, META_COLORMAP);
else
lua_pushnil(L);
return 1;
}
// #translations -> R_NumCustomTranslations()
static int lib_translationslen(lua_State *L)
{
lua_pushinteger(L, R_NumCustomTranslations());
return 1;
}
//////////////////////////////
//
// Now push all these functions into the Lua state!
@ -1958,7 +1932,6 @@ int LUA_InfoLib(lua_State *L)
LUA_RegisterGlobalUserdata(L, "spr2defaults", lib_getSpr2default, lib_setSpr2default, lib_spr2namelen);
LUA_RegisterGlobalUserdata(L, "states", lib_getState, lib_setState, lib_statelen);
LUA_RegisterGlobalUserdata(L, "mobjinfo", lib_getMobjInfo, lib_setMobjInfo, lib_mobjinfolen);
LUA_RegisterGlobalUserdata(L, "translations", lib_getTranslation, NULL, lib_translationslen);
LUA_RegisterGlobalUserdata(L, "skincolors", lib_getSkinColor, lib_setSkinColor, lib_skincolorslen);
LUA_RegisterGlobalUserdata(L, "spriteinfo", lib_getSpriteInfo, lib_setSpriteInfo, lib_spriteinfolen);
LUA_RegisterGlobalUserdata(L, "sfxinfo", lib_getSfxInfo, lib_setSfxInfo, lib_sfxlen);