]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add "interpretboolean" function to read "yes" and "no" and such as 1/0
authorSamual <samual@xonotic.org>
Mon, 19 Dec 2011 18:19:27 +0000 (13:19 -0500)
committerSamual <samual@xonotic.org>
Mon, 19 Dec 2011 18:19:27 +0000 (13:19 -0500)
qcsrc/client/command/cl_cmd.qc
qcsrc/common/util.qc
qcsrc/common/util.qh

index a48a542adc9e05a92405022986200e0121438df7..fc1e762b75a273375c9d447cfebb2e88af94cf43 100644 (file)
@@ -138,11 +138,15 @@ void LocalCommand_handlevote(float request, float argc)
                        float vote_selection;
                        string vote_string;
                        
-                       switch(argv(1))
+                       if(InterpretBoolean(argv(1)))
+                       {
+                               vote_selection = 2; 
+                               vote_string = "yes";
+                       }
+                       else
                        {
-                               case "yes": vote_selection = 2; vote_string = "yes"; break;
-                               case "no": vote_selection = 1; vote_string = "no"; break;
-                               default: break;
+                               vote_selection = 1; 
+                               vote_string = "no"; 
                        }
                        
                        if(vote_selection)
@@ -172,7 +176,7 @@ void LocalCommand_handlevote(float request, float argc)
        }
 }
 
-void LocalCommand_hud(float request, float argc) // TODO: Add aliases in commands.cfg
+void LocalCommand_hud(float request, float argc)
 {
        switch(request)
        {
@@ -202,24 +206,18 @@ void LocalCommand_hud(float request, float argc) // TODO: Add aliases in command
                                case "scoreboard_columns_set":
                                {
                                        Cmd_HUD_SetFields(argc); 
-                                       
                                        return;
                                }
 
                                case "scoreboard_columns_help":
                                {
                                        Cmd_HUD_Help();
-                                       
                                        return;
                                }
                                
                                case "radar":
                                {
-                                       if(argv(2))
-                                               hud_panel_radar_maximized = (stof(argv(2)) != 0);
-                                       else
-                                               hud_panel_radar_maximized = !hud_panel_radar_maximized;
-                                       
+                                       hud_panel_radar_maximized = (argv(2) ? InterpretBoolean(argv(2)) : !hud_panel_radar_maximized);
                                        return;
                                }
                        }
@@ -271,7 +269,6 @@ void LocalCommand_mv_download(float request, float argc)
                case CMD_REQUEST_COMMAND:
                {
                        Cmd_MapVote_MapDownload(argc);
-                       
                        return; 
                }
                        
@@ -302,7 +299,6 @@ void LocalCommand_sendcvar(float request, float argc)
                                
                        localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
                        strunzone(thiscvar);
-                       
                        return; 
                }
                        
@@ -322,7 +318,7 @@ void LocalCommand_settemp(float request, float argc)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if((argv(1) == "restore") && (argc == 2))
+                       if((argv(1) == "restore") && argv(2))
                        {
                                float i = cvar_clientsettemp_restore();
                                
@@ -348,7 +344,7 @@ void LocalCommand_settemp(float request, float argc)
                        print("Incorrect parameters for ^2settemp^7\n");
                case CMD_REQUEST_USAGE:
                {
-                       print("\nUsage:^3 cl_cmd settemp <cvar> | [restore]\n");
+                       print("\nUsage:^3 cl_cmd settemp \"cvar\" | [restore]\n");
                        print("  Where 'cvar' is the cvar plus arguments to send to the server,\n");
                        print("  or 'restore' allows you to restore all of the original temporary cvar values.\n");
                        return;
index a609827cf9a3d6eef93f247e11ab13559282a30a..72a93d4a7100879ad9121bd81fe5a56b334ec3fc 100644 (file)
@@ -2137,3 +2137,24 @@ string MakeConsoleSafe(string input)
        input = strreplace("\"", "\\\"", input);
        return input;
 }
+
+#ifndef MENUQC
+// get true/false value of a string with multiple different inputs
+float InterpretBoolean(string input)
+{
+       switch(strtolower(input))
+       {
+               case "yes":
+               case "true":
+               case "on":
+                       return TRUE;
+               
+               case "no":
+               case "false":
+               case "off":
+                       return FALSE;
+               
+               default: return stof(input);
+       }
+}
+#endif
\ No newline at end of file
index e2dfcb3b86b1257c7b440837e7714fc78a1e48ff..a371218819df33f20edd9ff0f05a9f3986c819f2 100644 (file)
@@ -274,3 +274,7 @@ float xdecode(string s);
 #ifdef CSQC
 entity ReadCSQCEntity()
 #endif
+
+#ifndef MENUQC
+string strtolower(string s);
+#endif
\ No newline at end of file