using System;
using System.Collections.Generic;
using System.IO;
using Robust.Shared.Timing;
namespace Robust.Shared.Configuration
{
///
/// Additional information about a CVar change.
///
public readonly struct CVarChangeInfo
{
///
/// The tick this CVar changed at.
///
///
/// Nominally this should always be the current tick,
/// however due to poor network conditions it is possible for CVars to get applied late.
/// In this case, this is effectively "this is the tick it was SUPPOSED to have been applied at".
///
public readonly GameTick TickChanged;
internal CVarChangeInfo(GameTick tickChanged)
{
TickChanged = tickChanged;
}
}
public delegate void CVarChanged(T newValue, in CVarChangeInfo info);
///
/// Stores and manages global configuration variables.
///
///
///
/// Accessing (getting/setting) main CVars is thread safe.
/// Note that value-changed callbacks are ran synchronously from the thread using ,
/// so it is not recommended to modify CVars from other threads.
///
///
public interface IConfigurationManager
{
///
/// Saves the configuration file to disk.
///
void SaveToFile();
///
/// Serializes a list of cvars to a toml.
///
void SaveToTomlStream(Stream stream, IEnumerable cvars);
HashSet LoadFromTomlStream(Stream stream);
///
/// Load a TOML config file and use the CVar values specified as an .
///
///
/// All CVars in the TOML file must be registered when this function is called.
///
/// A set of all CVars touched.
HashSet LoadDefaultsFromTomlStream(Stream stream);
///
/// Register a CVar with the system. This must be done before the CVar is accessed.
///
/// The name of the CVar. This needs to contain only printable characters.
/// Periods '.' are reserved. Everything before the last period is a nested table identifier,
/// everything after is the CVar name in the TOML document.
/// The default Value of the CVar.
/// Optional flags to change behavior of the CVar.
/// Invoked whenever the CVar value changes.
void RegisterCVar(string name, T defaultValue, CVar flags = CVar.NONE, Action? onValueChanged = null)
where T : notnull;
///
/// Is the named CVar already registered?
///
/// The name of the CVar.
///
bool IsCVarRegistered(string name);
///
/// Get the CVar flags of a registered cvar.
///
CVar GetCVarFlags(string name);
///
/// Gets a list of all registered cvars
///
///
IEnumerable GetRegisteredCVars();
///
/// Sets a CVars value.
///
/// The name of the CVar.
/// The value to set.
/// If true, this will set the cvar even if it should not be settable (e.g., server
/// authoritative cvars being set by clients).
void SetCVar(string name, object value, bool force = false);
void SetCVar(CVarDef def, T value, bool force = false) where T : notnull;
///
/// Change the default value for a CVar.
/// This means the CVar value is changed *only* if it has not been changed by config file or OverrideConVars.
///
/// The name of the CVar to change the default for.
/// The new default value of the CVar.
void OverrideDefault(string name, object value);
///
/// Change the default value for a CVar.
/// This means the CVar value is changed *only* if it has not been changed by config file or OverrideConVars.
///
/// The definition of the CVar to change the default for.
/// The new default value of the CVar.
void OverrideDefault(CVarDef def, T value) where T : notnull;
///
/// Get the value of a CVar.
///
/// The Type of the CVar value.
/// The name of the CVar.
///
T GetCVar(string name);
T GetCVar(CVarDef def) where T : notnull;
///
/// Gets the type of a value stored in a CVar.
///
/// The name of the CVar
Type GetCVarType(string name);
///
/// Listen for an event for if the config value changes.
///
///
/// This is an O(n) operation.
///
/// 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.
///
void OnValueChanged(CVarDef cVar, Action onValueChanged, bool invokeImmediately = false)
where T : notnull;
///
/// Listen for an event for if the config value changes.
///
///
/// This is an O(n) operation.
///
/// 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.
///
void OnValueChanged(string name, Action onValueChanged, bool invokeImmediately = false)
where T : notnull;
///
/// Unsubscribe an event previously registered with .
///
///
/// This is an O(n) operation.
///
/// The CVar to unsubscribe from.
/// The delegate to unsubscribe.
/// The type of value contained in this CVar.
void UnsubValueChanged(CVarDef cVar, Action onValueChanged)
where T : notnull;
///
/// Unsubscribe an event previously registered with .
///
///
/// This is an O(n) operation.
///
/// The name of the CVar to unsubscribe from.
/// The delegate to unsubscribe.
/// The type of value contained in this CVar.
void UnsubValueChanged(string name, Action onValueChanged)
where T : notnull;
///
/// Listen for an event for if the config value changes.
///
///
/// This is an O(n) operation.
///
/// 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.
///
void OnValueChanged(CVarDef cVar, CVarChanged onValueChanged, bool invokeImmediately = false)
where T : notnull;
///
/// Listen for an event for if the config value changes.
///
///
/// This is an O(n) operation.
///
/// 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.
///
void OnValueChanged(string name, CVarChanged onValueChanged, bool invokeImmediately = false)
where T : notnull;
///
/// Unsubscribe an event previously registered with .
///
///
/// This is an O(n) operation.
///
/// The CVar to unsubscribe from.
/// The delegate to unsubscribe.
/// The type of value contained in this CVar.
void UnsubValueChanged(CVarDef cVar, CVarChanged onValueChanged)
where T : notnull;
///
/// Unsubscribe an event previously registered with .
///
///
/// This is an O(n) operation.
///
/// The name of the CVar to unsubscribe from.
/// The delegate to unsubscribe.
/// The type of value contained in this CVar.
void UnsubValueChanged(string name, CVarChanged onValueChanged)
where T : notnull;
}
}