mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 01:01:33 +00:00
Add translations[] to Lua
This commit is contained in:
parent
799bbe62ee
commit
4545f954e7
3 changed files with 43 additions and 0 deletions
|
@ -22,6 +22,7 @@
|
||||||
#include "r_patch.h"
|
#include "r_patch.h"
|
||||||
#include "r_picformats.h"
|
#include "r_picformats.h"
|
||||||
#include "r_things.h"
|
#include "r_things.h"
|
||||||
|
#include "r_translation.h"
|
||||||
#include "r_draw.h" // R_GetColorByName
|
#include "r_draw.h" // R_GetColorByName
|
||||||
#include "doomstat.h" // luabanks[]
|
#include "doomstat.h" // luabanks[]
|
||||||
|
|
||||||
|
@ -1899,6 +1900,32 @@ static int colorramp_len(lua_State *L)
|
||||||
return 1;
|
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_GetNumTranslations()
|
||||||
|
static int lib_translationslen(lua_State *L)
|
||||||
|
{
|
||||||
|
lua_pushinteger(L, R_NumCustomTranslations());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
//
|
//
|
||||||
// Now push all these functions into the Lua state!
|
// Now push all these functions into the Lua state!
|
||||||
|
@ -2076,6 +2103,16 @@ int LUA_InfoLib(lua_State *L)
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
lua_setglobal(L, "skincolors");
|
lua_setglobal(L, "skincolors");
|
||||||
|
|
||||||
|
lua_newuserdata(L, 0);
|
||||||
|
lua_createtable(L, 0, 2);
|
||||||
|
lua_pushcfunction(L, lib_getTranslation);
|
||||||
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
|
lua_pushcfunction(L, lib_translationslen);
|
||||||
|
lua_setfield(L, -2, "__len");
|
||||||
|
lua_setmetatable(L, -2);
|
||||||
|
lua_setglobal(L, "translations");
|
||||||
|
|
||||||
lua_newuserdata(L, 0);
|
lua_newuserdata(L, 0);
|
||||||
lua_createtable(L, 0, 2);
|
lua_createtable(L, 0, 2);
|
||||||
lua_pushcfunction(L, lib_getSfxInfo);
|
lua_pushcfunction(L, lib_getSfxInfo);
|
||||||
|
|
|
@ -689,6 +689,11 @@ void R_AddCustomTranslation(const char *name, int trnum)
|
||||||
tr->hash = quickncasehash(name, strlen(name));
|
tr->hash = quickncasehash(name, strlen(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned R_NumCustomTranslations(void)
|
||||||
|
{
|
||||||
|
return numcustomtranslations;
|
||||||
|
}
|
||||||
|
|
||||||
remaptable_t *R_GetTranslationByID(int id)
|
remaptable_t *R_GetTranslationByID(int id)
|
||||||
{
|
{
|
||||||
if (id < 0 || id >= (signed)numpaletteremaps)
|
if (id < 0 || id >= (signed)numpaletteremaps)
|
||||||
|
|
|
@ -43,6 +43,7 @@ struct PaletteRemapParseResult *PaletteRemap_ParseTranslation(remaptable_t *tr,
|
||||||
|
|
||||||
int R_FindCustomTranslation(const char *name);
|
int R_FindCustomTranslation(const char *name);
|
||||||
void R_AddCustomTranslation(const char *name, int trnum);
|
void R_AddCustomTranslation(const char *name, int trnum);
|
||||||
|
unsigned R_NumCustomTranslations(void);
|
||||||
remaptable_t *R_GetTranslationByID(int id);
|
remaptable_t *R_GetTranslationByID(int id);
|
||||||
|
|
||||||
void R_LoadTrnslateLumps(void);
|
void R_LoadTrnslateLumps(void);
|
||||||
|
|
Loading…
Reference in a new issue