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.

69 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. 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. private static EnginesRoot _lastEngineRoot;
  18. public static void AddCommand(ICustomCommandEngine engine)
  19. {
  20. _customCommands[engine.Name] = engine;
  21. if (_lastEngineRoot != null)
  22. {
  23. Logging.MetaDebugLog($"Registering ICustomCommandEngine {engine.Name}");
  24. _lastEngineRoot.AddEngine(engine);
  25. }
  26. }
  27. public static bool ExistsCommand(string name)
  28. {
  29. return _customCommands.ContainsKey(name);
  30. }
  31. public static bool ExistsCommand(ICustomCommandEngine engine)
  32. {
  33. return ExistsCommand(engine.Name);
  34. }
  35. public static ICustomCommandEngine GetCommand(string name)
  36. {
  37. return _customCommands[name];
  38. }
  39. public static string[] GetCommandNames()
  40. {
  41. return _customCommands.Keys.ToArray();
  42. }
  43. public static void RemoveCommand(string name)
  44. {
  45. _customCommands.Remove(name);
  46. }
  47. public static void RegisterEngines(EnginesRoot enginesRoot)
  48. {
  49. _lastEngineRoot = enginesRoot;
  50. foreach (var key in _customCommands.Keys)
  51. {
  52. Logging.MetaDebugLog($"Registering ICustomCommandEngine {_customCommands[key].Name}");
  53. enginesRoot.AddEngine(_customCommands[key]);
  54. }
  55. }
  56. }
  57. }