quantum-space-buddies/QSB/API/AddonDataManager.cs

27 lines
645 B
C#
Raw Normal View History

2023-07-29 00:26:12 +00:00
using System;
using System.Collections.Generic;
using OWML.Common;
2023-07-29 00:26:12 +00:00
using QSB.Utility;
namespace QSB.API;
public static class AddonDataManager
{
private static readonly Dictionary<int, Action<uint, object>> _handlers = new();
2023-07-29 00:26:12 +00:00
public static void OnReceiveDataMessage(int hash, object data, uint from)
2023-07-29 00:26:12 +00:00
{
if (!_handlers.TryGetValue(hash, out var handler))
2023-07-29 00:26:12 +00:00
{
DebugLog.DebugWrite($"unknown addon message type with hash {hash}", MessageType.Error);
return;
2023-07-29 00:26:12 +00:00
}
handler(from, data);
2023-07-29 00:26:12 +00:00
}
public static void RegisterHandler<T>(int hash, Action<uint, T> handler)
2023-07-29 00:26:12 +00:00
{
_handlers.Add(hash, (from, data) => handler(from, (T)data));
2023-07-29 00:26:12 +00:00
}
}