TechbloxModdingAPI/GamecraftModdingAPI/Commands/SimpleCustomCommandEngine.cs

60 lines
1.9 KiB
C#
Raw Normal View History

using System;
2019-12-15 07:20:20 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Svelto.ECS;
2019-12-15 07:20:20 +00:00
namespace GamecraftModdingAPI.Commands
{
/// <summary>
/// A simple implementation of ICustomCommandEngine sufficient for most commands.
/// This version is for commands which take 0 argument(s)
/// </summary>
2019-12-19 20:42:50 +00:00
public class SimpleCustomCommandEngine : ICustomCommandEngine
2019-12-15 07:20:20 +00:00
{
/// <summary>
/// The name of the command
/// </summary>
public string Name { get; }
/// <summary>
/// The command's description, shown in command help messages
/// </summary>
public string Description { get; }
/// <summary>
/// The operation to execute when the command is called by the player
/// </summary>
private Action runCommand;
public EntitiesDB entitiesDB { set; private get; }
2019-12-15 07:20:20 +00:00
public void Dispose()
{
GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
2019-12-15 07:20:20 +00:00
CommandRegistrationHelper.Unregister(this.Name);
}
public void Ready()
{
GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Registering SimpleCustomCommandEngine {this.Name}");
2019-12-15 07:20:20 +00:00
CommandRegistrationHelper.Register(this.Name, this.runCommand, this.Description);
}
/// <summary>
/// Construct the engine
/// </summary>
/// <param name="command">The command's operation</param>
/// <param name="name">The name of the command</param>
/// <param name="description">The command's description, shown in command help messages</param>
public SimpleCustomCommandEngine(Action command, string name, string description)
{
this.runCommand = command;
this.Name = name;
this.Description = description;
}
}
}