|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System;
-
- using Svelto.ECS;
-
- namespace GamecraftModdingAPI.Events
- {
- [Obsolete]
- public class EmitterBuilder
- {
- private string name;
-
- private int? type;
-
- /// <summary>
- /// Create a new event emitter builder.
- /// </summary>
- public EmitterBuilder()
- {
- }
-
- /// <summary>
- /// Create a new event emitter builder.
- /// This is equivalent to new <code>EmitterBuilder().Name(name)</code>
- /// </summary>
- /// <param name="name">The emitter name.</param>
- public EmitterBuilder(string name)
- {
- this.name = name;
- }
-
- /// <summary>
- /// Create and return an event emitter builder.
- /// </summary>
- /// <returns>The builder.</returns>
- public static EmitterBuilder Builder()
- {
- return new EmitterBuilder();
- }
-
- /// <summary>
- /// Create and return an event emitter builder.
- /// This is equivalent to <code>Builder().Name(name)</code>
- /// </summary>
- /// <returns>The builder.</returns>
- /// <param name="name">The emitter name.</param>
- public static EmitterBuilder Builder(string name)
- {
- return new EmitterBuilder(name);
- }
-
- /// <summary>
- /// Name the event emitter.
- /// </summary>
- /// <returns>The builder.</returns>
- /// <param name="name">The event emitter name.</param>
- public EmitterBuilder Name(string name)
- {
- this.name = name;
- return this;
- }
-
- /// <summary>
- /// Set the type of event to handle.
- /// </summary>
- /// <returns>The builder.</returns>
- /// <param name="eventType">The event type.</param>
- public EmitterBuilder Handle(EventType eventType)
- {
- return Handle((int)eventType);
- }
-
- /// <summary>
- /// Set the type of event to handle.
- /// </summary>
- /// <returns>The builder.</returns>
- /// <param name="eventType">The event type.</param>
- public EmitterBuilder Handle(int eventType)
- {
- this.type = eventType;
- return this;
- }
-
- /// <summary>
- /// Build the event emitter.
- /// </summary>
- /// <returns>The event emitter.</returns>
- /// <param name="register">Automatically register the event emitter with EventManager.AddEventemitter().</param>
- public IEventEmitterEngine Build(bool register = true)
- {
- if (string.IsNullOrWhiteSpace(name))
- {
- throw new EventParameterMissingException("Event emitter name must be defined before Build() is called");
- }
- if (!type.HasValue)
- {
- throw new EventParameterMissingException("Event emitter event type must be defined before Build() is called");
- }
- SimpleEventEmitterEngine result = new SimpleEventEmitterEngine(type.Value, name);
- if (register)
- {
- EventManager.AddEventEmitter(result);
- }
- return result;
- }
- }
- }
|