2023-07-29 01:26:12 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using QSB.Utility;
|
|
|
|
|
|
|
|
|
|
namespace QSB.API;
|
|
|
|
|
|
|
|
|
|
public static class AddonDataManager
|
|
|
|
|
{
|
2023-07-29 16:53:02 -07:00
|
|
|
|
private static readonly Dictionary<string, Action<object>> _handlers = new();
|
2023-07-29 01:26:12 +01:00
|
|
|
|
|
|
|
|
|
public static void OnReceiveDataMessage(string messageType, object data)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"Received data message of message type \"{messageType}\"!");
|
2023-07-29 16:53:02 -07:00
|
|
|
|
if (!_handlers.TryGetValue(messageType, out var handler))
|
2023-07-29 01:26:12 +01:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-29 16:53:02 -07:00
|
|
|
|
handler(data);
|
2023-07-29 01:26:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RegisterHandler<T>(string messageType, Action<T> handler)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"Registering handler for \"{messageType}\" with type of {typeof(T).Name}");
|
2023-07-29 16:54:56 -07:00
|
|
|
|
_handlers.Add(messageType, data => handler((T)data));
|
2023-07-29 01:26:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|