namespace Sandbox;
///
/// Console variable
///
[AttributeUsage( AttributeTargets.Property )]
[CodeGenerator( CodeGeneratorFlags.Static | CodeGeneratorFlags.WrapPropertySet, "Sandbox.ConsoleSystem.OnWrappedSet" )]
[CodeGenerator( CodeGeneratorFlags.Static | CodeGeneratorFlags.WrapPropertyGet, "Sandbox.ConsoleSystem.OnWrappedGet" )]
public class ConVarAttribute : Attribute
{
///
/// If unset the name will be set to the name of the method/property
///
public string Name { get; set; }
///
/// Describes why this command exists
///
public string Help { get; set; }
///
/// Minimum value for this command
///
public float Min
{
get => MinValue ?? 0.0f;
set => MinValue = value;
}
///
/// Maximum value for this command
///
public float Max
{
get => MaxValue ?? 0.0f;
set => MaxValue = value;
}
///
/// If true this variable is saved
///
public bool Saved
{
get => Flags.Contains( ConVarFlags.Saved );
set => Flags = Flags.WithFlag( ConVarFlags.Saved, value );
}
///
/// Describes the kind of convar this is
///
public ConVarFlags Flags { get; set; }
// Nullables cannot be used as attributes
internal float? MinValue;
internal float? MaxValue;
///
/// If set to "menu" then this is a menu convar
///
internal string Context { get; set; }
public ConVarAttribute( string name = null, ConVarFlags flags = default )
{
Name = name;
Flags = flags;
}
public ConVarAttribute( ConVarFlags flags )
{
Flags = flags;
}
}
[Flags]
public enum ConVarFlags
{
None = 0,
///
/// Saved and restored between sessions
///
Saved = 1,
///
/// The value of this is synced on a server. Only the server or server admins may change the value.
///
Replicated = 2,
///
/// This is a cheat command, don't run it unless cheats are enabled
///
Cheat = 4,
///
/// Adds to userinfo - making it accessible via the connection class on other clients
///
UserInfo = 8,
///
/// Hide in find and autocomplete
///
Hidden = 16,
///
/// Tell clients when the value changes
///
ChangeNotice = 32,
///
/// Can't be accessed via game code (can be changed manually via console, or tools)
///
Protected = 64,
///
/// This command will be run on the server in a multiplayer game
///
Server = 128,
///
/// Only an admin of the server can run this command
///
Admin = 256,
///
/// A game setting that is exposed to the platform for UI editing
///
GameSetting = 512,
}