Files
GoakeFlax/Source/Game/Cabrito/Console/ConsoleAttributes.cs
2021-06-28 16:22:20 +03:00

59 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cabrito
{
[AttributeUsage(AttributeTargets.All)]
public abstract class ConsoleBaseAttribute : Attribute
{
internal string name;
// Additional aliases for this command, these should only be used with user interaction.
// Commands such as 'cvarlist' should not list these in order to avoid clutter.
internal string[] aliases = new string[0];
public ConsoleFlags flags { get; private set; }
public ConsoleBaseAttribute(string name)
{
this.name = name.ToLowerInvariant();
}
public ConsoleBaseAttribute(params string[] names)
{
this.name = names[0].ToLowerInvariant();
aliases = new List<string>(names).Skip(1).Select(x => x.ToLowerInvariant()).ToArray();
}
}
[AttributeUsage(AttributeTargets.All)]
public class ConsoleVariableAttribute : ConsoleBaseAttribute
{
public ConsoleVariableAttribute(string name) : base(name)
{
}
}
[AttributeUsage(AttributeTargets.All)]
public class ConsoleCommandAttribute : ConsoleBaseAttribute
{
/// <summary>
/// Registers a command to Console system.
/// </summary>
/// <param name="name">Name used for calling this command.</param>
public ConsoleCommandAttribute(string name) : base(name)
{
}
/// <summary>
/// Registers a command to Console system.
/// </summary>
/// <param name="names">Names used for calling this command. First name is the main name for this command, rest of the names are aliases.</param>
public ConsoleCommandAttribute(params string[] names) : base(names)
{
}
}
}