-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathCustomUpdateData.cs
132 lines (104 loc) · 3.47 KB
/
CustomUpdateData.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
namespace RGB.NET.Core;
/// <summary>
/// Represents an index used to identify data in the <see cref="CustomUpdateData"/>.
/// </summary>
public static class CustomUpdateDataIndex
{
/// <summary>
/// Checked by the <see cref="RGBSurface"/> to see if all LEDs needs to be flushed even if they aren't changed in this update.
/// default: false
/// </summary>
public const string FLUSH_LEDS = "flushLeds";
/// <summary>
/// Checked by the <see cref="RGBSurface"/> to see if the surface should be rendered in this update.
/// default: true
/// </summary>
public const string RENDER = "render";
/// <summary>
/// Checked by the <see cref="RGBSurface"/> to see if devies should be updated after rendering.
/// default: true
/// </summary>
public const string UPDATE_DEVICES = "updateDevices";
/// <summary>
/// Used by <see cref="DeviceUpdateTrigger"/> to indicate heatbeat updates.
/// </summary>
public const string HEARTBEAT = "heartbeat";
}
/// <summary>
/// Represents a set of custom data, each indexed by a string-key.
/// </summary>
public interface ICustomUpdateData
{
/// <summary>
/// Gets the value for a specific key.
/// </summary>
/// <param name="key">The key of the value.</param>
/// <returns>The value represented by the specified key.</returns>
object? this[string key] { get; }
}
/// <summary>
/// Represents a set of custom data, each indexed by a string-key.
/// </summary>
public sealed class CustomUpdateData : ICustomUpdateData
{
#region Properties & Fields
// ReSharper disable once InconsistentNaming
public static readonly CustomUpdateData Empty = new();
private readonly Dictionary<string, object?> _data = [];
#endregion
#region Indexer
/// <summary>
/// Gets or sets the value for a specific key.
/// </summary>
/// <param name="key">The key of the value.</param>
/// <returns>The value represented by the specified key.</returns>
public object? this[string key]
{
get => _data.GetValueOrDefault(key);
set => _data[key] = value;
}
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="CustomUpdateData"/> class.
/// </summary>
public CustomUpdateData()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="CustomUpdateData"/> class.
/// </summary>
/// <param name="values">A params-list of tuples containing the key (string) and the value of a specific custom-data.</param>
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
}