2019-12-15 07:20:20 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2019-12-16 00:35:59 +00:00
|
|
|
|
|
2019-12-15 07:20:20 +00:00
|
|
|
|
using Svelto.ECS;
|
|
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Events
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Convenient factories for mod event engines
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class EventEngineFactory
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Factory method which automatically adds the SimpleEventHandlerEngine to the Manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name of the engine</param>
|
|
|
|
|
/// <param name="type">The type of event to handle</param>
|
|
|
|
|
/// <param name="onActivated">The operation to do when the event is created</param>
|
|
|
|
|
/// <param name="onDestroyed">The operation to do when the event is destroyed (if applicable)</param>
|
|
|
|
|
/// <returns>The created object</returns>
|
2020-04-02 17:08:05 +00:00
|
|
|
|
public static SimpleEventHandlerEngine CreateAddSimpleHandler(string name, int type, Action onActivated, Action onDestroyed)
|
2019-12-15 07:20:20 +00:00
|
|
|
|
{
|
|
|
|
|
var engine = new SimpleEventHandlerEngine(onActivated, onDestroyed, type, name);
|
|
|
|
|
EventManager.AddEventHandler(engine);
|
|
|
|
|
return engine;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Factory method which automatically adds the SimpleEventHandlerEngine to the Manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name of the engine</param>
|
|
|
|
|
/// <param name="type">The type of event to handle</param>
|
|
|
|
|
/// <param name="onActivated">The operation to do when the event is created</param>
|
|
|
|
|
/// <param name="onDestroyed">The operation to do when the event is destroyed (if applicable)</param>
|
|
|
|
|
/// <returns>The created object</returns>
|
2020-04-02 17:08:05 +00:00
|
|
|
|
public static SimpleEventHandlerEngine CreateAddSimpleHandler(string name, int type, Action<EntitiesDB> onActivated, Action<EntitiesDB> onDestroyed)
|
2019-12-15 07:20:20 +00:00
|
|
|
|
{
|
|
|
|
|
var engine = new SimpleEventHandlerEngine(onActivated, onDestroyed, type, name);
|
|
|
|
|
EventManager.AddEventHandler(engine);
|
|
|
|
|
return engine;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Factory method which automatically adds the SimpleEventEmitterEngine to the Manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">The name of the engine</param>
|
|
|
|
|
/// <param name="type">The type of event to emit</param>
|
|
|
|
|
/// <param name="isRemovable">Will removing this engine not break your code?</param>
|
|
|
|
|
/// <returns>The created object</returns>
|
2020-04-02 17:08:05 +00:00
|
|
|
|
public static SimpleEventEmitterEngine CreateAddSimpleEmitter(string name, int type, bool isRemovable = true)
|
2019-12-15 07:20:20 +00:00
|
|
|
|
{
|
|
|
|
|
var engine = new SimpleEventEmitterEngine(type, name, isRemovable);
|
|
|
|
|
EventManager.AddEventEmitter(engine);
|
|
|
|
|
return engine;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|