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.

MenuEngineManager.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.Utility
  8. {
  9. /// <summary>
  10. /// Keeps track of custom menu-modifying engines
  11. /// </summary>
  12. public static class MenuEngineManager
  13. {
  14. private static Dictionary<string, IApiEngine> _menuEngines = new Dictionary<string, IApiEngine>();
  15. private static EnginesRoot _lastEngineRoot;
  16. // menu engine management
  17. public static void AddMenuEngine(IApiEngine engine)
  18. {
  19. _menuEngines[engine.Name] = engine;
  20. if (_lastEngineRoot != null)
  21. {
  22. Logging.MetaDebugLog($"Registering Menu IApiEngine {engine.Name}");
  23. _lastEngineRoot.AddEngine(engine);
  24. }
  25. }
  26. public static bool ExistsMenuEngine(string name)
  27. {
  28. return _menuEngines.ContainsKey(name);
  29. }
  30. public static bool ExistsMenuEngine(IApiEngine engine)
  31. {
  32. return ExistsMenuEngine(engine.Name);
  33. }
  34. public static IApiEngine GetMenuEngine(string name)
  35. {
  36. return _menuEngines[name];
  37. }
  38. public static string[] GetMenuEngineNames()
  39. {
  40. return _menuEngines.Keys.ToArray();
  41. }
  42. public static void RemoveMenuEngine(string name)
  43. {
  44. _menuEngines.Remove(name);
  45. }
  46. public static void RegisterEngines(EnginesRoot enginesRoot)
  47. {
  48. _lastEngineRoot = enginesRoot;
  49. foreach (var key in _menuEngines.Keys)
  50. {
  51. Logging.MetaDebugLog($"Registering Menu IApiEngine {_menuEngines[key].Name}");
  52. enginesRoot.AddEngine(_menuEngines[key]);
  53. }
  54. }
  55. }
  56. }