mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2024-12-29 12:21:25 +00:00
63a5a13342
This reverts commit 0fc0715048
.
27 lines
645 B
C#
27 lines
645 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using OWML.Common;
|
|
using QSB.Utility;
|
|
|
|
namespace QSB.API;
|
|
|
|
public static class AddonDataManager
|
|
{
|
|
private static readonly Dictionary<int, Action<uint, object>> _handlers = new();
|
|
|
|
public static void OnReceiveDataMessage(int hash, object data, uint from)
|
|
{
|
|
if (!_handlers.TryGetValue(hash, out var handler))
|
|
{
|
|
DebugLog.DebugWrite($"unknown addon message type with hash {hash}", MessageType.Error);
|
|
return;
|
|
}
|
|
handler(from, data);
|
|
}
|
|
|
|
public static void RegisterHandler<T>(int hash, Action<uint, T> handler)
|
|
{
|
|
_handlers.Add(hash, (from, data) => handler(from, (T)data));
|
|
}
|
|
}
|