Refactor event management: remove old EventManager and EventExample scripts, add new Core/EventManager as singleton

This commit is contained in:
Will Stuckey
2025-10-28 13:02:48 -05:00
parent 3deeb42403
commit 873cc7dd17
8 changed files with 81 additions and 198 deletions

View File

@@ -0,0 +1,78 @@
using Godot;
using EinSoftworks.Events;
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);
}
}

View File

@@ -0,0 +1 @@
uid://yt5e67nfdc6y