mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-02 06:23:03 +00:00
Make translation field return the name of the translation
This commit is contained in:
parent
803fe613d2
commit
6c1b9b8678
4 changed files with 45 additions and 21 deletions
|
@ -587,13 +587,11 @@ static int ScanConstants(lua_State *L, boolean mathlib, const char *word)
|
||||||
else if (mathlib && fastncmp("TRANSLATION_",word,12))
|
else if (mathlib && fastncmp("TRANSLATION_",word,12))
|
||||||
{
|
{
|
||||||
p = word+12;
|
p = word+12;
|
||||||
for (i = 0; i < (signed)numcustomtranslations; i++)
|
int id = R_FindCustomTranslation_CaseInsensitive(p);
|
||||||
|
if (id != -1)
|
||||||
{
|
{
|
||||||
if (fasticmp(p, customtranslations[i].name))
|
lua_pushinteger(L, id);
|
||||||
{
|
return 1;
|
||||||
lua_pushinteger(L, (int)customtranslations[i].id);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return luaL_error(L, "translation '%s' could not be found.\n", word);
|
return luaL_error(L, "translation '%s' could not be found.\n", word);
|
||||||
}
|
}
|
||||||
|
|
|
@ -343,9 +343,13 @@ static int mobj_get(lua_State *L)
|
||||||
break;
|
break;
|
||||||
case mobj_translation:
|
case mobj_translation:
|
||||||
if (mo->translation)
|
if (mo->translation)
|
||||||
lua_pushinteger(L, mo->translation);
|
{
|
||||||
else
|
const char *name = R_GetCustomTranslationName(mo->translation);
|
||||||
lua_pushnil(L);
|
if (name)
|
||||||
|
lua_pushstring(L, name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
lua_pushnil(L);
|
||||||
break;
|
break;
|
||||||
case mobj_blendmode:
|
case mobj_blendmode:
|
||||||
lua_pushinteger(L, mo->blendmode);
|
lua_pushinteger(L, mo->blendmode);
|
||||||
|
|
|
@ -819,8 +819,15 @@ fail:
|
||||||
Z_Free(text);
|
Z_Free(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
customtranslation_t *customtranslations = NULL;
|
typedef struct CustomTranslation
|
||||||
unsigned numcustomtranslations = 0;
|
{
|
||||||
|
char *name;
|
||||||
|
unsigned id;
|
||||||
|
UINT32 hash;
|
||||||
|
} customtranslation_t;
|
||||||
|
|
||||||
|
static customtranslation_t *customtranslations = NULL;
|
||||||
|
static unsigned numcustomtranslations = 0;
|
||||||
|
|
||||||
int R_FindCustomTranslation(const char *name)
|
int R_FindCustomTranslation(const char *name)
|
||||||
{
|
{
|
||||||
|
@ -835,6 +842,18 @@ int R_FindCustomTranslation(const char *name)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is needed for SOC (which is case insensitive)
|
||||||
|
int R_FindCustomTranslation_CaseInsensitive(const char *name)
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < numcustomtranslations; i++)
|
||||||
|
{
|
||||||
|
if (stricmp(name, customtranslations[i].name) == 0)
|
||||||
|
return (int)customtranslations[i].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void R_AddCustomTranslation(const char *name, int trnum)
|
void R_AddCustomTranslation(const char *name, int trnum)
|
||||||
{
|
{
|
||||||
customtranslation_t *tr = NULL;
|
customtranslation_t *tr = NULL;
|
||||||
|
@ -862,6 +881,17 @@ void R_AddCustomTranslation(const char *name, int trnum)
|
||||||
tr->hash = quickncasehash(name, strlen(name));
|
tr->hash = quickncasehash(name, strlen(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *R_GetCustomTranslationName(unsigned id)
|
||||||
|
{
|
||||||
|
for (unsigned i = 0; i < numcustomtranslations; i++)
|
||||||
|
{
|
||||||
|
if (id == customtranslations[i].id)
|
||||||
|
return customtranslations[i].name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned R_NumCustomTranslations(void)
|
unsigned R_NumCustomTranslations(void)
|
||||||
{
|
{
|
||||||
return numcustomtranslations;
|
return numcustomtranslations;
|
||||||
|
|
|
@ -82,18 +82,10 @@ struct PaletteRemapParseResult *PaletteRemap_ParseTranslation(const char *transl
|
||||||
|
|
||||||
void PaletteRemap_ApplyResult(remaptable_t *tr, struct PaletteRemapParseResult *data);
|
void PaletteRemap_ApplyResult(remaptable_t *tr, struct PaletteRemapParseResult *data);
|
||||||
|
|
||||||
typedef struct CustomTranslation
|
|
||||||
{
|
|
||||||
char *name;
|
|
||||||
unsigned id;
|
|
||||||
UINT32 hash;
|
|
||||||
} customtranslation_t;
|
|
||||||
|
|
||||||
extern customtranslation_t *customtranslations;
|
|
||||||
extern unsigned numcustomtranslations;
|
|
||||||
|
|
||||||
int R_FindCustomTranslation(const char *name);
|
int R_FindCustomTranslation(const char *name);
|
||||||
|
int R_FindCustomTranslation_CaseInsensitive(const char *name);
|
||||||
void R_AddCustomTranslation(const char *name, int trnum);
|
void R_AddCustomTranslation(const char *name, int trnum);
|
||||||
|
const char *R_GetCustomTranslationName(unsigned id);
|
||||||
unsigned R_NumCustomTranslations(void);
|
unsigned R_NumCustomTranslations(void);
|
||||||
remaptable_t *R_GetTranslationByID(int id);
|
remaptable_t *R_GetTranslationByID(int id);
|
||||||
boolean R_TranslationIsValid(int id);
|
boolean R_TranslationIsValid(int id);
|
||||||
|
|
Loading…
Reference in a new issue