using System; using Svelto.ECS; namespace GamecraftModdingAPI.Events { public class EmitterBuilder { private string name; private int? type; /// /// Create a new event emitter builder. /// public EmitterBuilder() { } /// /// Create a new event emitter builder. /// This is equivalent to new EmitterBuilder().Name(name) /// /// The emitter name. public EmitterBuilder(string name) { this.name = name; } /// /// Create and return an event emitter builder. /// /// The builder. public static EmitterBuilder Builder() { return new EmitterBuilder(); } /// /// Create and return an event emitter builder. /// This is equivalent to Builder().Name(name) /// /// The builder. /// The emitter name. public static EmitterBuilder Builder(string name) { return new EmitterBuilder(name); } /// /// Name the event emitter. /// /// The builder. /// The event emitter name. public EmitterBuilder Name(string name) { this.name = name; return this; } /// /// Set the type of event to handle. /// /// The builder. /// The event type. public EmitterBuilder Handle(EventType eventType) { return Handle((int)eventType); } /// /// Set the type of event to handle. /// /// The builder. /// The event type. public EmitterBuilder Handle(int eventType) { this.type = eventType; return this; } /// /// Build the event emitter. /// /// The event emitter. /// Automatically register the event emitter with EventManager.AddEventemitter(). 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; } } }