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.

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