Added ModulLoader
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Firebird2D.Datatypes;
|
||||
using Firebird2D.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -9,15 +11,15 @@ namespace Firebird2D.EventPipelines
|
||||
/// <summary>
|
||||
/// EventBus manages event pipelines and allows registering callbacks (hooks) if a pipeline is not Build Yet, as well as creating, retrieving, and destroying pipelines.
|
||||
/// </summary>
|
||||
public class EventBus
|
||||
public class EventBus : IEventBus
|
||||
{
|
||||
// Dictionary that stores various pipelines for specific FirebirdEvents.
|
||||
// The key is the event, and the value is the corresponding pipeline.
|
||||
private Dictionary<FirebirdEvent, I_Pipeline> pipelines = new();
|
||||
private Dictionary<FirebirdEvent, IPipeline> pipelines = new();
|
||||
|
||||
// Dictionary that stores a list of callbacks for each FirebirdEvent.
|
||||
// These callbacks will be invoked when the event's pipeline is build.
|
||||
private Dictionary<FirebirdEvent, List<Action<I_Pipeline>>> pendingHooks = new();
|
||||
private Dictionary<FirebirdEvent, List<Action<IPipeline>>> pendingHooks = new();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a callback (hook) for a specific event. The callback will be invoked when the pipeline for this event is built.
|
||||
@@ -25,7 +27,7 @@ namespace Firebird2D.EventPipelines
|
||||
/// <param name="callback">The function to be called when the pipeline for the event is built.</param>
|
||||
/// <param name="type">The event for which the callback should be registered.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when the callback is null.</exception>
|
||||
public void OnPipelineIsBuild(Action<I_Pipeline> callback, FirebirdEvent type)
|
||||
public void OnPipelineIsBuild(Action<IPipeline> callback, FirebirdEvent type)
|
||||
{
|
||||
if (callback == null) throw new ArgumentNullException(nameof(callback));
|
||||
|
||||
@@ -47,12 +49,12 @@ namespace Firebird2D.EventPipelines
|
||||
/// <param name="argsType">The type of the arguments to be passed to the pipeline.</param>
|
||||
/// <param name="master">The master object used when creating the pipeline.</param>
|
||||
/// <returns>The pipeline for the given event.</returns>
|
||||
public I_Pipeline GetOrBuildPipeline(FirebirdEvent type, Type argsType, object master)
|
||||
public IPipeline GetOrBuildPipeline(FirebirdEvent type, Type argsType, object master)
|
||||
{
|
||||
if (pipelines.TryGetValue(type, out var pipeline)) return pipeline;
|
||||
|
||||
var genericPipelineType = typeof(Pipeline<>).MakeGenericType(argsType);
|
||||
var pipelineInstance = (I_Pipeline)Activator.CreateInstance(genericPipelineType, master)!;
|
||||
var pipelineInstance = (IPipeline)Activator.CreateInstance(genericPipelineType, master)!;
|
||||
pipelines[type] = pipelineInstance;
|
||||
return pipelineInstance;
|
||||
}
|
||||
@@ -63,7 +65,7 @@ namespace Firebird2D.EventPipelines
|
||||
/// <param name="type">The event for which the pipeline should be retrieved.</param>
|
||||
/// <param name="argsType">The type of the arguments for the pipeline.</param>
|
||||
/// <returns>The pipeline for the event, or null if it does not exist.</returns>
|
||||
public I_Pipeline? GetPipeline(FirebirdEvent type, Type argsType)
|
||||
public IPipeline? GetPipeline(FirebirdEvent type, Type argsType)
|
||||
{
|
||||
if (!pipelines.TryGetValue(type, out var pipeline)) return null;
|
||||
return pipeline;
|
||||
|
||||
Reference in New Issue
Block a user