Files
voider/Scripts/Core/EventManager.cs
William Stuckey 79bf76ee33 Csharpier cleanup
2025-12-29 14:33:39 -06:00

79 lines
2.0 KiB
C#

using EinSoftworks.Events;
using Godot;
namespace Voider;
/// <summary>
/// Autoload singleton that provides access to the ConfigurableEventManager
/// </summary>
public partial class EventManager : Node
{
private static EventManager _instance;
public static EventManager Instance => _instance;
private ConfigurableEventManager _eventManager;
public override void _Ready()
{
_instance = this;
_eventManager = new ConfigurableEventManager();
}
/// <summary>
/// Raise a game event using the resource's EventName
/// </summary>
public void RaiseEvent(GameEventResource eventResource)
{
if (eventResource?.EventName != null)
{
_eventManager.Raise(eventResource.EventName);
}
}
/// <summary>
/// Raise a game event by name
/// </summary>
public void RaiseEvent(string eventName)
{
_eventManager.Raise(eventName);
}
/// <summary>
/// Subscribe to a game event using the resource's EventName
/// </summary>
public void Subscribe(GameEventResource eventResource, System.Action callback)
{
if (eventResource?.EventName != null)
{
_eventManager.Subscribe(eventResource.EventName, callback);
}
}
/// <summary>
/// Subscribe to a game event by name
/// </summary>
public void Subscribe(string eventName, System.Action callback)
{
_eventManager.Subscribe(eventName, callback);
}
/// <summary>
/// Unsubscribe from a game event using the resource's EventName
/// </summary>
public void Unsubscribe(GameEventResource eventResource, System.Action callback)
{
if (eventResource?.EventName != null)
{
_eventManager.Unsubscribe(eventResource.EventName, callback);
}
}
/// <summary>
/// Unsubscribe from a game event by name
/// </summary>
public void Unsubscribe(string eventName, System.Action callback)
{
_eventManager.Unsubscribe(eventName, callback);
}
}