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.

EmitterBuilder.cs 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using Svelto.ECS;
  3. namespace GamecraftModdingAPI.Events
  4. {
  5. [Obsolete]
  6. public class EmitterBuilder
  7. {
  8. private string name;
  9. private int? type;
  10. /// <summary>
  11. /// Create a new event emitter builder.
  12. /// </summary>
  13. public EmitterBuilder()
  14. {
  15. }
  16. /// <summary>
  17. /// Create a new event emitter builder.
  18. /// This is equivalent to new <code>EmitterBuilder().Name(name)</code>
  19. /// </summary>
  20. /// <param name="name">The emitter name.</param>
  21. public EmitterBuilder(string name)
  22. {
  23. this.name = name;
  24. }
  25. /// <summary>
  26. /// Create and return an event emitter builder.
  27. /// </summary>
  28. /// <returns>The builder.</returns>
  29. public static EmitterBuilder Builder()
  30. {
  31. return new EmitterBuilder();
  32. }
  33. /// <summary>
  34. /// Create and return an event emitter builder.
  35. /// This is equivalent to <code>Builder().Name(name)</code>
  36. /// </summary>
  37. /// <returns>The builder.</returns>
  38. /// <param name="name">The emitter name.</param>
  39. public static EmitterBuilder Builder(string name)
  40. {
  41. return new EmitterBuilder(name);
  42. }
  43. /// <summary>
  44. /// Name the event emitter.
  45. /// </summary>
  46. /// <returns>The builder.</returns>
  47. /// <param name="name">The event emitter name.</param>
  48. public EmitterBuilder Name(string name)
  49. {
  50. this.name = name;
  51. return this;
  52. }
  53. /// <summary>
  54. /// Set the type of event to handle.
  55. /// </summary>
  56. /// <returns>The builder.</returns>
  57. /// <param name="eventType">The event type.</param>
  58. public EmitterBuilder Handle(EventType eventType)
  59. {
  60. return Handle((int)eventType);
  61. }
  62. /// <summary>
  63. /// Set the type of event to handle.
  64. /// </summary>
  65. /// <returns>The builder.</returns>
  66. /// <param name="eventType">The event type.</param>
  67. public EmitterBuilder Handle(int eventType)
  68. {
  69. this.type = eventType;
  70. return this;
  71. }
  72. /// <summary>
  73. /// Build the event emitter.
  74. /// </summary>
  75. /// <returns>The event emitter.</returns>
  76. /// <param name="register">Automatically register the event emitter with EventManager.AddEventemitter().</param>
  77. public IEventEmitterEngine Build(bool register = true)
  78. {
  79. if (string.IsNullOrWhiteSpace(name))
  80. {
  81. throw new EventParameterMissingException("Event emitter name must be defined before Build() is called");
  82. }
  83. if (!type.HasValue)
  84. {
  85. throw new EventParameterMissingException("Event emitter event type must be defined before Build() is called");
  86. }
  87. SimpleEventEmitterEngine result = new SimpleEventEmitterEngine(type.Value, name);
  88. if (register)
  89. {
  90. EventManager.AddEventEmitter(result);
  91. }
  92. return result;
  93. }
  94. }
  95. }