using System; using System.Collections.Generic; namespace RGB.NET.Core; /// /// Represents an index used to identify data in the . /// public static class CustomUpdateDataIndex { /// /// Checked by the to see if all LEDs needs to be flushed even if they aren't changed in this update. /// default: false /// public const string FLUSH_LEDS = "flushLeds"; /// /// Checked by the to see if the surface should be rendered in this update. /// default: true /// public const string RENDER = "render"; /// /// Checked by the to see if devies should be updated after rendering. /// default: true /// public const string UPDATE_DEVICES = "updateDevices"; /// /// Used by to indicate heatbeat updates. /// public const string HEARTBEAT = "heartbeat"; } /// /// Represents a set of custom data, each indexed by a string-key. /// public interface ICustomUpdateData { /// /// Gets the value for a specific key. /// /// The key of the value. /// The value represented by the specified key. object? this[string key] { get; } } /// /// Represents a set of custom data, each indexed by a string-key. /// public sealed class CustomUpdateData : ICustomUpdateData { #region Properties & Fields private readonly Dictionary _data = []; #endregion #region Indexer /// /// Gets or sets the value for a specific key. /// /// The key of the value. /// The value represented by the specified key. public object? this[string key] { get => _data.TryGetValue(key, out object? data) ? data : default; set => _data[key] = value; } #endregion #region Constructors /// /// Initializes a new instance of the class. /// public CustomUpdateData() { } /// /// Initializes a new instance of the class. /// /// A params-list of tuples containing the key (string) and the value of a specific custom-data. public CustomUpdateData(params (string key, object value)[] values) { foreach ((string key, object value) in values) this[key] = value; } #endregion } internal sealed class DefaultCustomUpdateData : ICustomUpdateData { #region Constants public static readonly DefaultCustomUpdateData FLUSH = new(true); public static readonly DefaultCustomUpdateData NO_FLUSH = new(false); #endregion #region Properties & Fields private readonly bool _flushLeds; public object? this[string key] { get { if (string.Equals(key, CustomUpdateDataIndex.FLUSH_LEDS, StringComparison.Ordinal)) return _flushLeds; return null; } } #endregion #region Constructors private DefaultCustomUpdateData(bool flushLeds) { this._flushLeds = flushLeds; } #endregion }