mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-09 23:11:39 +00:00
Add 2+3 arg forms of the toggle command.
This commit is contained in:
parent
b5deda6b75
commit
980ab70765
1 changed files with 27 additions and 10 deletions
37
Quake/cvar.c
37
Quake/cvar.c
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue