Example #1
0
        public void Update(CVar cvar)
        {
            // if this is a statically declared variable
            if ((cvar.Flags & CVAR.STATIC) != 0)
            {
                if ((flags & CVAR.STATIC) != 0)
                {
                    // the code has more than one static declaration of the same variable, make sure they have the same properties
                    if (!string.Equals(resetString, cvar.String, StringComparison.OrdinalIgnoreCase))
                    {
                        Warning($"CVar '{nameString}' declared multiple times with different initial value");
                    }
                    if ((flags & (CVAR.BOOL | CVAR.INTEGER | CVAR.FLOAT)) != (cvar.Flags & (CVAR.BOOL | CVAR.INTEGER | CVAR.FLOAT)))
                    {
                        Warning($"CVar '{nameString}' declared multiple times with different type");
                    }
                    if (valueMin != cvar.MinValue || valueMax != cvar.MaxValue)
                    {
                        Warning($"CVar '{nameString}' declared multiple times with different minimum/maximum");
                    }
                }

                // the code is now specifying a variable that the user already set a value for, take the new value as the reset value
                resetString       = cvar.String;
                descriptionString = cvar.Description;
                description       = descriptionString;
                valueMin          = cvar.MinValue;
                valueMax          = cvar.MaxValue;
                valueStrings      = cvar.ValueStrings;
                valueCompletion   = cvar.GetValueCompletion();
                UpdateValue();
                cvarSystem.SetModifiedFlags(cvar.Flags);
            }

            flags |= cvar.Flags;

            UpdateCheat();

            // only allow one non-empty reset string without a warning
            if (resetString.Length == 0)
            {
                resetString = cvar.String;
            }
            else if (cvar.String.Length != 0 && resetString != cvar.String)
            {
                Warning($"cvar \"{nameString}\" given initial values: \"{resetString}\" and \"{cvar.String}\"\n");
            }
        }
Example #2
0
 public CVarLocal(CVar cvar)
 {
     nameString        = cvar.Name;
     name              = nameString;
     valueString       = cvar.String;
     value             = valueString;
     resetString       = cvar.String;
     descriptionString = cvar.Description;
     description       = descriptionString;
     flags             = cvar.Flags | CVAR.MODIFIED;
     valueMin          = cvar.MinValue;
     valueMax          = cvar.MaxValue;
     valueStrings      = cvar.ValueStrings;
     valueCompletion   = cvar.GetValueCompletion();
     UpdateValue();
     UpdateCheat();
     internalVar = this;
 }