Added ModulLoader

This commit is contained in:
Mueller Wayan
2025-04-22 20:19:35 +02:00
parent 766b2e414b
commit 47ddfed9bc
43 changed files with 471 additions and 372 deletions
+10 -8
View File
@@ -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;
@@ -10,4 +10,8 @@
<PackageReference Include="SFML.Net" Version="2.6.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FireBird2D.Interfaces\Firebird2D.DataypesAndInterfaces.csproj" />
</ItemGroup>
</Project>
-441
View File
@@ -1,441 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Firebird2D.EventPipelines
{
public enum FirebirdEvent
{
A = 0,
//
// Zusammenfassung:
// The B key
B = 1,
//
// Zusammenfassung:
// The C key
C = 2,
//
// Zusammenfassung:
// The D key
D = 3,
//
// Zusammenfassung:
// The E key
E = 4,
//
// Zusammenfassung:
// The F key
F = 5,
//
// Zusammenfassung:
// The G key
G = 6,
//
// Zusammenfassung:
// The H key
H = 7,
//
// Zusammenfassung:
// The I key
I = 8,
//
// Zusammenfassung:
// The J key
J = 9,
//
// Zusammenfassung:
// The K key
K = 10,
//
// Zusammenfassung:
// The L key
L = 11,
//
// Zusammenfassung:
// The M key
M = 12,
//
// Zusammenfassung:
// The N key
N = 13,
//
// Zusammenfassung:
// The O key
O = 14,
//
// Zusammenfassung:
// The P key
P = 15,
//
// Zusammenfassung:
// The Q key
Q = 16,
//
// Zusammenfassung:
// The R key
R = 17,
//
// Zusammenfassung:
// The S key
S = 18,
//
// Zusammenfassung:
// The T key
T = 19,
//
// Zusammenfassung:
// The U key
U = 20,
//
// Zusammenfassung:
// The V key
V = 21,
//
// Zusammenfassung:
// The W key
W = 22,
//
// Zusammenfassung:
// The X key
X = 23,
//
// Zusammenfassung:
// The Y key
Y = 24,
//
// Zusammenfassung:
// The Z key
Z = 25,
//
// Zusammenfassung:
// The 0 key
Num0 = 26,
//
// Zusammenfassung:
// The 1 key
Num1 = 27,
//
// Zusammenfassung:
// The 2 key
Num2 = 28,
//
// Zusammenfassung:
// The 3 key
Num3 = 29,
//
// Zusammenfassung:
// The 4 key
Num4 = 30,
//
// Zusammenfassung:
// The 5 key
Num5 = 31,
//
// Zusammenfassung:
// The 6 key
Num6 = 32,
//
// Zusammenfassung:
// The 7 key
Num7 = 33,
//
// Zusammenfassung:
// The 8 key
Num8 = 34,
//
// Zusammenfassung:
// The 9 key
Num9 = 35,
//
// Zusammenfassung:
// The Escape key
Escape = 36,
//
// Zusammenfassung:
// The left Control key
LControl = 37,
//
// Zusammenfassung:
// The left Shift key
LShift = 38,
//
// Zusammenfassung:
// The left Alt key
LAlt = 39,
//
// Zusammenfassung:
// The left OS specific key: window (Windows and Linux), apple (macOS), ...
LSystem = 40,
//
// Zusammenfassung:
// The right Control key
RControl = 41,
//
// Zusammenfassung:
// The right Shift key
RShift = 42,
//
// Zusammenfassung:
// The right Alt key
RAlt = 43,
//
// Zusammenfassung:
// The right OS specific key: window (Windows and Linux), apple (macOS), ...
RSystem = 44,
//
// Zusammenfassung:
// The Menu key
Menu = 45,
//
// Zusammenfassung:
// The [ key
LBracket = 46,
//
// Zusammenfassung:
// The ] key
RBracket = 47,
//
// Zusammenfassung:
// The ; key
Semicolon = 48,
//
// Zusammenfassung:
// The , key
Comma = 49,
//
// Zusammenfassung:
// The . key
Period = 50,
//
// Zusammenfassung:
// The ' key
Apostrophe = 51,
//
// Zusammenfassung:
// The / key
Slash = 52,
//
// Zusammenfassung:
// The \ key
Backslash = 53,
//
// Zusammenfassung:
// The ~ key
Grave = 54,
//
// Zusammenfassung:
// The = key
Equal = 55,
//
// Zusammenfassung:
// The - key
Hyphen = 56,
//
// Zusammenfassung:
// The Space key
Space = 57,
//
// Zusammenfassung:
// The Return key
Enter = 58,
//
// Zusammenfassung:
// The Backspace key
Backspace = 59,
//
// Zusammenfassung:
// The Tabulation key
Tab = 60,
//
// Zusammenfassung:
// The Page up key
PageUp = 61,
//
// Zusammenfassung:
// The Page down key
PageDown = 62,
//
// Zusammenfassung:
// The End key
End = 63,
//
// Zusammenfassung:
// The Home key
Home = 64,
//
// Zusammenfassung:
// The Insert key
Insert = 65,
//
// Zusammenfassung:
// The Delete key
Delete = 66,
//
// Zusammenfassung:
// The + key
Add = 67,
//
// Zusammenfassung:
// The - key
Subtract = 68,
//
// Zusammenfassung:
// The * key
Multiply = 69,
//
// Zusammenfassung:
// The / key
Divide = 70,
//
// Zusammenfassung:
// Left arrow
Left = 71,
//
// Zusammenfassung:
// Right arrow
Right = 72,
//
// Zusammenfassung:
// Up arrow
Up = 73,
//
// Zusammenfassung:
// Down arrow
Down = 74,
//
// Zusammenfassung:
// The numpad 0 key
Numpad0 = 75,
//
// Zusammenfassung:
// The numpad 1 key
Numpad1 = 76,
//
// Zusammenfassung:
// The numpad 2 key
Numpad2 = 77,
//
// Zusammenfassung:
// The numpad 3 key
Numpad3 = 78,
//
// Zusammenfassung:
// The numpad 4 key
Numpad4 = 79,
//
// Zusammenfassung:
// The numpad 5 key
Numpad5 = 80,
//
// Zusammenfassung:
// The numpad 6 key
Numpad6 = 81,
//
// Zusammenfassung:
// The numpad 7 key
Numpad7 = 82,
//
// Zusammenfassung:
// The numpad 8 key
Numpad8 = 83,
//
// Zusammenfassung:
// The numpad 9 key
Numpad9 = 84,
//
// Zusammenfassung:
// The F1 key
F1 = 85,
//
// Zusammenfassung:
// The F2 key
F2 = 86,
//
// Zusammenfassung:
// The F3 key
F3 = 87,
//
// Zusammenfassung:
// The F4 key
F4 = 88,
//
// Zusammenfassung:
// The F5 key
F5 = 89,
//
// Zusammenfassung:
// The F6 key
F6 = 90,
//
// Zusammenfassung:
// The F7 key
F7 = 91,
//
// Zusammenfassung:
// The F8 key
F8 = 92,
//
// Zusammenfassung:
// The F9 key
F9 = 93,
//
// Zusammenfassung:
// The F10 key
F10 = 94,
//
// Zusammenfassung:
// The F11 key
F11 = 95,
//
// Zusammenfassung:
// The F12 key
F12 = 96,
//
// Zusammenfassung:
// The F13 key
F13 = 97,
//
// Zusammenfassung:
// The F14 key
F14 = 98,
//
// Zusammenfassung:
// The F15 key
F15 = 99,
//
// Zusammenfassung:
// The Pause key
Pause = 100,
MouseLeft = 101,
//
// Zusammenfassung:
// The right mouse button
MouseRight = 102,
//
// Zusammenfassung:
// The middle (wheel) mouse button
MouseMiddle = 103,
//
// Zusammenfassung:
// The first extra mouse button
MouseXButton1 = 104,
//
// Zusammenfassung:
// The second extra mouse button
MouseXButton2 = 105,
JoystickButton,
JoystickMove,
Tick,
Startup,
ModulesLoading,
SceneLoading,
FullyLoaded,
SceneLoaded,
MouseWheel,
MouseMove
}
}
-35
View File
@@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Firebird2D.EventPipelines
{
/// <summary>
/// Interface for the Firebird event Pipeline
/// </summary>
public interface I_Pipeline
{
/// <summary>
/// Class witch owns the Pipeline and has the right to send events or delete the pipeline
/// </summary>
object PipelineMaster { get; }
/// <summary>
/// Check if no one subscribed to the event
/// </summary>
bool IsEventEmpty { get; }
/// <summary>
/// Subscribe to this event Pipeline
/// </summary>
/// <param name="handler">Handler witch should be Invoked when the event is send</param>
void Subscribe(Delegate handler);
/// <summary>
/// Unsubscribe from this event Pipeline
/// </summary>
/// <param name="handler">Handler witch should be removed from the Pipeline</param>
void Unsubscribe(Delegate handler);
}
}
+2 -1
View File
@@ -1,4 +1,5 @@
using Firebird2D.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -12,7 +13,7 @@ namespace Firebird2D.EventPipelines
/// Eventpypeline which transports an event to every Subscyber
/// </summary>
/// <typeparam name="T">Event Arguments for the Pipeline event</typeparam>
public class Pipeline <T> : I_Pipeline where T : EventArgs
public class Pipeline <T> : IPipeline where T : EventArgs
{
/// <summary>
/// Class witch owns the Pipeline and has the right to send events or delete the pipeline