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.

62 lines
1.9KB

  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 0 argument(s)
  12. /// </summary>
  13. public class SimpleCustomCommandEngine : ICustomCommandEngine
  14. {
  15. /// <summary>
  16. /// The name of the command
  17. /// </summary>
  18. public string Name { get; }
  19. /// <summary>
  20. /// The command's description, shown in command help messages
  21. /// </summary>
  22. public string Description { get; }
  23. /// <summary>
  24. /// The operation to execute when the command is called by the player
  25. /// </summary>
  26. private Action runCommand;
  27. public EntitiesDB entitiesDB { set; private get; }
  28. public bool isRemovable => true;
  29. public void Dispose()
  30. {
  31. GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
  32. CommandRegistrationHelper.Unregister(this.Name);
  33. }
  34. public void Ready()
  35. {
  36. GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Registering SimpleCustomCommandEngine {this.Name}");
  37. CommandRegistrationHelper.Register(this.Name, this.runCommand, this.Description);
  38. }
  39. /// <summary>
  40. /// Construct the engine
  41. /// </summary>
  42. /// <param name="command">The command's operation</param>
  43. /// <param name="name">The name of the command</param>
  44. /// <param name="description">The command's description, shown in command help messages</param>
  45. public SimpleCustomCommandEngine(Action command, string name, string description)
  46. {
  47. this.runCommand = command;
  48. this.Name = name;
  49. this.Description = description;
  50. }
  51. }
  52. }