Add CV_TrueFalse as possible value types for console variables

This also adds support for using true/false as value aliases for On/Off, Yes/No or 1/0

# Conflicts:
#	src/command.c
This commit is contained in:
SteelT 2023-07-13 01:02:15 -04:00 committed by toaster
parent ea53197084
commit 05b130b422
3 changed files with 12 additions and 6 deletions

View file

@ -78,6 +78,7 @@ CV_PossibleValue_t CV_OnOff[] = {{0, "Off"}, {1, "On"}, {0, NULL}};
CV_PossibleValue_t CV_YesNo[] = {{0, "No"}, {1, "Yes"}, {0, NULL}};
CV_PossibleValue_t CV_Unsigned[] = {{0, "MIN"}, {999999999, "MAX"}, {0, NULL}};
CV_PossibleValue_t CV_Natural[] = {{1, "MIN"}, {999999999, "MAX"}, {0, NULL}};
CV_PossibleValue_t CV_TrueFalse[] = {{0, "False"}, {1, "True"}, {0, NULL}};
// Cheats
#ifdef DEVELOP
@ -909,9 +910,11 @@ static void COM_Help_f(void)
{
CONS_Printf(" Possible values:\n");
if (cvar->PossibleValue == CV_YesNo)
CONS_Printf(" Yes or No (On or Off, 1 or 0)\n");
CONS_Printf(" Yes or No (On or Off, True or False, 1 or 0)\n");
else if (cvar->PossibleValue == CV_OnOff)
CONS_Printf(" On or Off (Yes or No, 1 or 0)\n");
CONS_Printf(" On or Off (Yes or No, True or False, 1 or 0)\n");
else if (cvar->PossibleValue == CV_TrueFalse)
CONS_Printf(" True or False (On or Off, Yes or No, 1 or 0)\n");
else if (cvar->PossibleValue == Color_cons_t || cvar->PossibleValue == Followercolor_cons_t)
{
boolean follower = (cvar->PossibleValue == Followercolor_cons_t);
@ -1565,12 +1568,12 @@ boolean CV_CompleteValue(consvar_t *var, const char **valstrp, INT32 *intval)
goto found;
}
// Not found ... but wait, there's hope!
if (var->PossibleValue == CV_OnOff || var->PossibleValue == CV_YesNo)
if (var->PossibleValue == CV_OnOff || var->PossibleValue == CV_YesNo || var->PossibleValue == CV_TrueFalse)
{
overrideval = -1;
if (!stricmp(valstr, "on") || !stricmp(valstr, "yes"))
if (!stricmp(valstr, "on") || !stricmp(valstr, "yes") || !stricmp(valstr, "true"))
overrideval = 1;
else if (!stricmp(valstr, "off") || !stricmp(valstr, "no"))
else if (!stricmp(valstr, "off") || !stricmp(valstr, "no") || !stricmp(valstr, "false"))
overrideval = 0;
if (overrideval != -1)

View file

@ -172,6 +172,7 @@ extern CV_PossibleValue_t CV_OnOff[];
extern CV_PossibleValue_t CV_YesNo[];
extern CV_PossibleValue_t CV_Unsigned[];
extern CV_PossibleValue_t CV_Natural[];
extern CV_PossibleValue_t CV_TrueFalse[];
// SRB2kart
// the KARTSPEED and KARTGP were previously defined here, but moved to doomstat to avoid circular dependencies

View file

@ -341,7 +341,7 @@ static int lib_cvRegisterVar(lua_State *L)
} else if (i == 4 || (k && fasticmp(k, "PossibleValue"))) {
if (lua_islightuserdata(L, 4)) {
CV_PossibleValue_t *pv = lua_touserdata(L, 4);
if (pv == CV_OnOff || pv == CV_YesNo || pv == CV_Unsigned || pv == CV_Natural)
if (pv == CV_OnOff || pv == CV_YesNo || pv == CV_Unsigned || pv == CV_Natural || pv == CV_TrueFalse)
cvar->PossibleValue = pv;
else
FIELDERROR("PossibleValue", "CV_PossibleValue_t expected, got unrecognised pointer")
@ -577,6 +577,8 @@ int LUA_ConsoleLib(lua_State *L)
lua_setglobal(L, "CV_Unsigned");
lua_pushlightuserdata(L, CV_Natural);
lua_setglobal(L, "CV_Natural");
lua_pushlightuserdata(L, CV_TrueFalse);
lua_setglobal(L, "CV_TrueFalse");
// Set global functions
lua_pushvalue(L, LUA_GLOBALSINDEX);