using System;
using Robust.Shared.Configuration;
namespace Robust.Shared.GameObjects;
///
/// Extra subscription helpers for that are not part of the core entity system behavior.
///
public static class EntitySystemSubscriptionExt
{
///
/// Listen for an event for if the config value changes.
///
///
/// This is an O(n) operation.
///
///
/// The entity system subscriptions.
/// Call this with .
///
/// The configuration manager.
/// The name of the CVar to listen for.
/// The delegate to run when the value was changed.
///
/// Whether to run the callback immediately inw this method. Can help reduce boilerplate
///
/// The type of value contained in this CVar.
public static void CVar(
this EntitySystem.Subscriptions subs,
IConfigurationManager cfg,
string name,
Action onValueChanged,
bool invokeImmediately = false)
where T : notnull
{
cfg.OnValueChanged(name, onValueChanged, invokeImmediately);
subs.RegisterUnsubscription(() => cfg.UnsubValueChanged(name, onValueChanged));
}
///
/// Listen for an event for if the config value changes.
///
///
/// This is an O(n) operation.
///
///
/// The entity system subscriptions.
/// Call this with .
///
/// The configuration manager.
/// The CVar to listen for.
/// The delegate to run when the value was changed.
///
/// Whether to run the callback immediately in this method. Can help reduce boilerplate
///
/// The type of value contained in this CVar.
public static void CVar(
this EntitySystem.Subscriptions subs,
IConfigurationManager cfg,
CVarDef cVar,
Action onValueChanged,
bool invokeImmediately = false)
where T : notnull
{
cfg.OnValueChanged(cVar, onValueChanged, invokeImmediately);
subs.RegisterUnsubscription(() => cfg.UnsubValueChanged(cVar, onValueChanged));
}
///
/// Listen for an event for if the config value changes.
///
///
/// This is an O(n) operation.
///
///
/// The entity system subscriptions.
/// Call this with .
///
/// The configuration manager.
/// The name of the CVar to listen for.
/// The delegate to run when the value was changed.
///
/// Whether to run the callback immediately in this method. Can help reduce boilerplate
///
/// The type of value contained in this CVar.
public static void CVar(
this EntitySystem.Subscriptions subs,
IConfigurationManager cfg,
string name,
CVarChanged onValueChanged,
bool invokeImmediately = false)
where T : notnull
{
cfg.OnValueChanged(name, onValueChanged, invokeImmediately);
subs.RegisterUnsubscription(() => cfg.UnsubValueChanged(name, onValueChanged));
}
///
/// Listen for an event for if the config value changes.
///
///
/// This is an O(n) operation.
///
///
/// The entity system subscriptions.
/// Call this with .
///
/// The configuration manager.
/// The CVar to listen for.
/// The delegate to run when the value was changed.
///
/// Whether to run the callback immediately in this method. Can help reduce boilerplate
///
/// The type of value contained in this CVar.
public static void CVar(
this EntitySystem.Subscriptions subs,
IConfigurationManager cfg,
CVarDef cVar,
CVarChanged onValueChanged,
bool invokeImmediately = false)
where T : notnull
{
cfg.OnValueChanged(cVar, onValueChanged, invokeImmediately);
subs.RegisterUnsubscription(() => cfg.UnsubValueChanged(cVar, onValueChanged));
}
}