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.

EventEngineFactory.cs 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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.Events
  8. {
  9. /// <summary>
  10. /// Convenient factories for mod event engines
  11. /// </summary>
  12. public static class EventEngineFactory
  13. {
  14. /// <summary>
  15. /// Factory method which automatically adds the SimpleEventHandlerEngine to the Manager
  16. /// </summary>
  17. /// <param name="name">The name of the engine</param>
  18. /// <param name="type">The type of event to handle</param>
  19. /// <param name="onActivated">The operation to do when the event is created</param>
  20. /// <param name="onDestroyed">The operation to do when the event is destroyed (if applicable)</param>
  21. /// <returns>The created object</returns>
  22. public static SimpleEventHandlerEngine CreateAddSimpleHandler(string name, int type, Action onActivated, Action onDestroyed)
  23. {
  24. var engine = new SimpleEventHandlerEngine(onActivated, onDestroyed, type, name);
  25. EventManager.AddEventHandler(engine);
  26. return engine;
  27. }
  28. /// <summary>
  29. /// Factory method which automatically adds the SimpleEventHandlerEngine to the Manager
  30. /// </summary>
  31. /// <param name="name">The name of the engine</param>
  32. /// <param name="type">The type of event to handle</param>
  33. /// <param name="onActivated">The operation to do when the event is created</param>
  34. /// <param name="onDestroyed">The operation to do when the event is destroyed (if applicable)</param>
  35. /// <returns>The created object</returns>
  36. public static SimpleEventHandlerEngine CreateAddSimpleHandler(string name, int type, Action<EntitiesDB> onActivated, Action<EntitiesDB> onDestroyed)
  37. {
  38. var engine = new SimpleEventHandlerEngine(onActivated, onDestroyed, type, name);
  39. EventManager.AddEventHandler(engine);
  40. return engine;
  41. }
  42. /// <summary>
  43. /// Factory method which automatically adds the SimpleEventEmitterEngine to the Manager
  44. /// </summary>
  45. /// <param name="name">The name of the engine</param>
  46. /// <param name="type">The type of event to emit</param>
  47. /// <param name="isRemovable">Will removing this engine not break your code?</param>
  48. /// <returns>The created object</returns>
  49. public static SimpleEventEmitterEngine CreateAddSimpleEmitter(string name, int type, bool isRemovable = true)
  50. {
  51. var engine = new SimpleEventEmitterEngine(type, name, isRemovable);
  52. EventManager.AddEventEmitter(engine);
  53. return engine;
  54. }
  55. }
  56. }