Files
GoakeFlax/Source/Game/Console/ConsoleAttributes.cs
2025-03-20 23:29:47 +02:00

66 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace Game;
[AttributeUsage(AttributeTargets.All)]
public abstract class ConsoleBaseAttribute : Attribute
{
// 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];
internal string name;
public ConsoleBaseAttribute(string name)
{
this.name = name.ToLowerInvariant();
}
public ConsoleBaseAttribute(params string[] names)
{
name = names[0].ToLowerInvariant();
aliases = new List<string>(names).Skip(1).Select(x => x.ToLowerInvariant()).ToArray();
}
public ConsoleFlags flags { get; private set; }
}
[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)
{
}
}
/// <summary>
/// Constructor for the subsystem, must be called first before registering console commands.
/// </summary>
[AttributeUsage(AttributeTargets.All)]
public class ConsoleSubsystemInitializer : Attribute
{
}