Add 2+3 arg forms of the toggle command.

This commit is contained in:
Shpoike 2023-07-25 14:37:25 +01:00
parent b5deda6b75
commit 980ab70765

View file

@ -149,18 +149,35 @@ Cvar_Toggle_f -- johnfitz
*/
void Cvar_Toggle_f (void)
{
switch (Cmd_Argc())
cvar_t *v;
if (Cmd_Argc()<2)
{
default:
case 1:
Con_Printf("toggle <cvar> : toggle cvar\n");
break;
case 2:
if (Cvar_VariableValue(Cmd_Argv(1)))
Cvar_Set (Cmd_Argv(1), "0");
Con_Printf("toggle <cvar> [value] [altvalue]: toggle cvar\n");
return;
}
v = Cvar_FindVar(Cmd_Argv(1));
if (!v)
{
Con_Printf ("variable \"%s\" not found\n", Cmd_Argv(1));
return;
}
if (Cmd_Argc() >= 3)
{
const char *newval = Cmd_Argv(2);
const char *defval = (Cmd_Argc()>3)?Cmd_Argv(3):v->default_string;
if (!defval) defval = "0";
if (!strcmp(newval, v->string))
Cvar_SetQuick(v, defval);
else
Cvar_Set (Cmd_Argv(1), "1");
break;
Cvar_SetQuick(v, newval);
}
else
{
if (v->value)
Cvar_SetQuick(v, "0");
else
Cvar_SetQuick(v, "1");
}
}