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.

SimpleCustomCommandEngine2.cs 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 2 argument(s)
  12. /// </summary>
  13. public class SimpleCustomCommandEngine<A,B> : ICustomCommandEngine
  14. {
  15. public string Name { get; }
  16. public string Description { get; }
  17. private Action<A,B> runCommand;
  18. public EntitiesDB entitiesDB { set; private get; }
  19. public void Dispose()
  20. {
  21. GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Unregistering SimpleCustomCommandEngine {this.Name}");
  22. CommandRegistrationHelper.Unregister(this.Name);
  23. }
  24. public void Ready()
  25. {
  26. GamecraftModdingAPI.Utility.Logging.MetaDebugLog($"Registering SimpleCustomCommandEngine {this.Name}");
  27. CommandRegistrationHelper.Register<A,B>(this.Name, this.runCommand, this.Description);
  28. }
  29. /// <summary>
  30. /// Construct the engine
  31. /// </summary>
  32. /// <param name="command">The command's operation</param>
  33. /// <param name="name">The name of the command</param>
  34. /// <param name="description">The command's description, shown in command help messages</param>
  35. public SimpleCustomCommandEngine(Action<A,B> command, string name, string description)
  36. {
  37. this.runCommand = command;
  38. this.Name = name;
  39. this.Description = description;
  40. }
  41. }
  42. }