A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Svelto.ECS;
  7. namespace GamecraftModdingAPI.Commands
  8. {
  9. /// <summary>
  10. /// A simple implementation of ICustomCommandEngine sufficient for most commands.
  11. /// This version is for commands which take 1 argument(s)
  12. /// </summary>
  13. public class SimpleCustomCommandEngine<A> : ICustomCommandEngine
  14. {
  15. public string Name { get; }
  16. public string Description { get; }
  17. private Action<A> runCommand;
  18. public EntitiesDB entitiesDB { set; private get; }
  19. public bool isRemovable => true;
  20. public void Dispose()
  21. {
  22. GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
  23. CommandRegistrationHelper.Unregister(this.Name);
  24. }
  25. public void Ready()
  26. {
  27. GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Registering SimpleCustomCommandEngine {this.Name}");
  28. CommandRegistrationHelper.Register<A>(this.Name, this.runCommand, this.Description);
  29. }
  30. /// <summary>
  31. /// Construct the engine
  32. /// </summary>
  33. /// <param name="command">The command's operation</param>
  34. /// <param name="name">The name of the command</param>
  35. /// <param name="description">The command's description, shown in command help messages</param>
  36. public SimpleCustomCommandEngine(Action<A> command, string name, string description)
  37. {
  38. this.runCommand = command;
  39. this.Name = name;
  40. this.Description = description;
  41. }
  42. }
  43. }