TechbloxModdingAPI/GamecraftModdingAPI/Events/SimpleEventEmitterEngine.cs

66 lines
2.1 KiB
C#
Raw Normal View History

2019-12-14 04:42:55 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2019-12-14 04:42:55 +00:00
using Svelto.ECS;
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Events
{
2019-12-14 18:52:24 +00:00
/// <summary>
/// A simple implementation of IEventEmitterEngine sufficient for most uses
/// </summary>
2019-12-15 07:20:20 +00:00
public class SimpleEventEmitterEngine : IEventEmitterEngine
2019-12-14 04:42:55 +00:00
{
public string Name { get; set; }
public int type { get; set; }
2019-12-14 04:42:55 +00:00
2019-12-14 18:52:24 +00:00
public bool isRemovable { get; }
2019-12-14 04:42:55 +00:00
public IEntityFactory Factory { private get; set; }
public EntitiesDB entitiesDB { set; private get; }
2019-12-14 04:42:55 +00:00
public void Ready() { }
2019-12-14 18:52:24 +00:00
/// <summary>
/// Emit the event
/// </summary>
2019-12-14 04:42:55 +00:00
public void Emit()
{
Factory.BuildEntity<ModEventEntityDescriptor>(ApiExclusiveGroups.eventID++, ApiExclusiveGroups.eventsExclusiveGroup)
2019-12-14 18:52:24 +00:00
.Init(new ModEventEntityStruct { type = type });
2019-12-14 04:42:55 +00:00
}
2019-12-14 18:52:24 +00:00
public void Dispose() { }
/// <summary>
/// Construct the engine
/// </summary>
/// <param name="type">The EventType to use for ModEventEntityStruct.type</param>
/// <param name="name">The name of this engine</param>
/// <param name="isRemovable">Will removing this engine not break your code?</param>
public SimpleEventEmitterEngine(EventType type, string name, bool isRemovable = true)
2019-12-14 04:42:55 +00:00
{
this.type = (int)type;
2019-12-14 04:42:55 +00:00
this.Name = name;
2019-12-14 18:52:24 +00:00
this.isRemovable = isRemovable;
2019-12-14 04:42:55 +00:00
}
2019-12-14 18:52:24 +00:00
/// <summary>
/// Construct the engine
/// </summary>
/// <param name="type">The object to use for ModEventEntityStruct.type</param>
/// <param name="name">The name of this engine</param>
/// <param name="isRemovable">Will removing this engine not break your code?</param>
public SimpleEventEmitterEngine(int type, string name, bool isRemovable = true)
2019-12-14 04:42:55 +00:00
{
this.type = type;
this.Name = name;
2019-12-14 18:52:24 +00:00
this.isRemovable = isRemovable;
2019-12-14 04:42:55 +00:00
}
}
}