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.

81 lines
2.2KB

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