Set() private method

private Set ( string value, bool force, bool fromServer ) : void
value string
force bool
fromServer bool
return void
Exemplo n.º 1
0
        /// <summary>
        /// Called by the command system when a command is unrecognized.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public bool Command(idCmdArgs args)
        {
            idInternalCvar intern = FindInternal(args.Get(0));

            if (intern == null)
            {
                return(false);
            }

            if (args.Length == 1)
            {
                // print the variable
                idConsole.WriteLine("\"{0}\" is: \"{1}\" {2} default: \"{3}\"", intern.Name, intern.ToString(), idColorString.White, intern.ResetString);

                if (intern.Description.Length > 0)
                {
                    idConsole.WriteLine("{0}{1}", idColorString.White, intern.Description);
                }
            }
            else
            {
                // set the value
                intern.Set(args.ToString(), false, false);
            }

            return(true);
        }
Exemplo n.º 2
0
        private void Cmd_Toggle(object sender, CommandEventArgs e)
        {
            int argCount = e.Args.Length;

            if (argCount < 2)
            {
                idConsole.WriteLine("usage:");
                idConsole.WriteLine("    toggle <variable> - toggles between 0 and 1");
                idConsole.WriteLine("    toggle <variable> <value> - toggles between 0 and <value>");
                idConsole.WriteLine("    toggle <variable [string 1] [string 2]...[string n] - cycles through all strings");
            }
            else
            {
                idInternalCvar cvar = idE.CvarSystem.FindInternal(e.Args.Get(1));

                if (cvar == null)
                {
                    idConsole.WriteLine("toggle: cvar \"{0}\" not found", e.Args.Get(1));
                }
                else if (argCount > 3)
                {
                    // cycle through multiple values
                    string text = cvar.ToString();
                    int    i    = 0;


                    for (i = 2; i < argCount; i++)
                    {
                        if (StringComparer.CurrentCultureIgnoreCase.Compare(text, e.Args.Get(i)) == 0)
                        {
                            i++;
                            break;
                        }
                    }

                    if (i >= argCount)
                    {
                        i = 2;
                    }

                    idConsole.WriteLine("set {0} = {1}", e.Args.Get(1), e.Args.Get(i));
                    cvar.Set(e.Args.Get(i), false, false);
                }
                else
                {
                    // toggle between 0 and 1
                    float current = cvar.ToFloat();
                    float set     = 0;

                    if (e.Args.Length == 3)
                    {
                        float.TryParse(e.Args.Get(2), out set);
                    }
                    else
                    {
                        set = 1.0f;
                    }

                    if (current == 0.0f)
                    {
                        current = set;
                    }
                    else
                    {
                        current = 0.0f;
                    }

                    idConsole.WriteLine("set {0} = {1}", e.Args.Get(1), current);
                    cvar.Set(current.ToString(), false, false);
                }
            }
        }