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.

58 lines
1.5KB

  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. /// Keeps track of custom commands
  11. /// This is used to add, remove and get command engines
  12. /// </summary>
  13. public static class CommandManager
  14. {
  15. private static Dictionary<string, ICustomCommandEngine> _customCommands = new Dictionary<string, ICustomCommandEngine>();
  16. public static void AddCommand(ICustomCommandEngine engine)
  17. {
  18. _customCommands[engine.Name] = engine;
  19. }
  20. public static bool ExistsCommand(string name)
  21. {
  22. return _customCommands.ContainsKey(name);
  23. }
  24. public static bool ExistsCommand(ICustomCommandEngine engine)
  25. {
  26. return ExistsCommand(engine.Name);
  27. }
  28. public static ICustomCommandEngine GetCommand(string name)
  29. {
  30. return _customCommands[name];
  31. }
  32. public static string[] GetCommandNames()
  33. {
  34. return _customCommands.Keys.ToArray();
  35. }
  36. public static void RemoveCommand(string name)
  37. {
  38. _customCommands.Remove(name);
  39. }
  40. public static void RegisterEngines(EnginesRoot enginesRoot)
  41. {
  42. foreach (var key in _customCommands.Keys)
  43. {
  44. enginesRoot.AddEngine(_customCommands[key]);
  45. }
  46. }
  47. }
  48. }