mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
i dont think we need ChangeType
This commit is contained in:
parent
4d545d12f3
commit
d48a1e33fe
@ -6,22 +6,22 @@ namespace QSB.API;
|
||||
|
||||
public static class AddonDataManager
|
||||
{
|
||||
private static readonly Dictionary<string, (Type objectType, Action<object> action)> _handlerDict = new();
|
||||
private static readonly Dictionary<string, Action<object>> _handlers = new();
|
||||
|
||||
public static void OnReceiveDataMessage(string messageType, object data)
|
||||
{
|
||||
DebugLog.DebugWrite($"Received data message of message type \"{messageType}\"!");
|
||||
if (!_handlerDict.TryGetValue(messageType, out var handler))
|
||||
if (!_handlers.TryGetValue(messageType, out var handler))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
handler.action(Convert.ChangeType(data, handler.objectType));
|
||||
handler(data);
|
||||
}
|
||||
|
||||
public static void RegisterHandler<T>(string messageType, Action<T> handler)
|
||||
{
|
||||
DebugLog.DebugWrite($"Registering handler for \"{messageType}\" with type of {typeof(T).Name}");
|
||||
_handlerDict.Add(messageType, (typeof(T), o => handler((T)o)));
|
||||
_handlers.Add(messageType, o => handler((T)o));
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,5 @@ public interface IQSBAPI
|
||||
T GetCustomData<T>(uint playerId, string key);
|
||||
|
||||
void SendMessage<T>(string messageType, T data);
|
||||
void RegisterHandler<T>(string messageType, Action<T> action);
|
||||
void RegisterHandler<T>(string messageType, Action<T> handler);
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ public class QSBAPI : IQSBAPI
|
||||
new AddonDataMessage(messageType, data).Send();
|
||||
}
|
||||
|
||||
public void RegisterHandler<T>(string messageType, Action<T> action)
|
||||
public void RegisterHandler<T>(string messageType, Action<T> handler)
|
||||
{
|
||||
AddonDataManager.RegisterHandler(messageType, action);
|
||||
AddonDataManager.RegisterHandler(messageType, handler);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user