1
+ #nullable enable
2
+
1
3
using System ;
2
4
using System . Collections . Generic ;
3
5
using System . Runtime . CompilerServices ;
@@ -13,21 +15,21 @@ public sealed class Props : Disposable, IComparable<Props>
13
15
private static uint _idCounter = 0 ;
14
16
private static uint _nextId ( ) => _idCounter ++ ;
15
17
16
- public readonly uint UniqueId = _nextId ( ) ;
18
+ public uint UniqueId { get ; } = _nextId ( ) ;
17
19
18
- public readonly int Priority ;
20
+ public int Priority { get ; }
19
21
20
22
private readonly Dictionary < int , Prop > props = [ ] ;
21
23
22
24
internal IEnumerable < int > ManagedIds => props . Keys ;
23
25
24
26
internal delegate void EntriesChangedHandler ( Props props ) ;
25
27
26
- internal EntriesChangedHandler OnEntriesChanged = null ;
28
+ internal EntriesChangedHandler ? OnEntriesChanged = null ;
27
29
28
30
internal delegate void ValueChangedHandler ( Props props , int ? id ) ;
29
31
30
- internal ValueChangedHandler OnValueChanged = null ;
32
+ internal ValueChangedHandler ? OnValueChanged = null ;
31
33
32
34
internal bool SuppressEagerUpdate = false ;
33
35
internal bool NeedsEntriesUpdate = false ;
@@ -43,10 +45,10 @@ public Props(int priority)
43
45
}
44
46
45
47
/// Ordered by lowest to highest priority. Equal priority is disambiguated by unique IDs.
46
- public int CompareTo ( Props other )
48
+ public int CompareTo ( Props ? other )
47
49
{
48
50
if ( ReferenceEquals ( this , other ) ) return 0 ;
49
- if ( other is null ) return 1 ;
51
+ if ( other == null ) return 1 ;
50
52
var priorityCmp = Priority . CompareTo ( other . Priority ) ;
51
53
return priorityCmp != 0 ? priorityCmp : UniqueId . CompareTo ( other . UniqueId ) ;
52
54
}
@@ -137,7 +139,7 @@ public bool Remove(int id)
137
139
138
140
#endregion
139
141
140
- #region Has
142
+ #region Has/Get
141
143
142
144
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
143
145
private bool _internalHas < T > ( int id ) => props . TryGetValue ( id , out var prop ) && prop is Prop < T > ;
@@ -148,6 +150,18 @@ public bool Remove(int id)
148
150
public bool HasTexture ( int id ) => _internalHas < Texture > ( id ) ;
149
151
public bool HasVector ( int id ) => _internalHas < Vector4 > ( id ) ;
150
152
153
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
154
+ private T ? _internalGet < T , TProp > ( int id ) where TProp : Prop < T > =>
155
+ props . TryGetValue ( id , out var prop ) && prop is TProp typedProp
156
+ ? typedProp . Value
157
+ : default ;
158
+
159
+ public Color GetColorOrDefault ( int id ) => _internalGet < Color , PropColor > ( id ) ;
160
+ public float GetFloatOrDefault ( int id ) => _internalGet < float , PropFloat > ( id ) ;
161
+ public int GetIntOrDefault ( int id ) => _internalGet < int , PropInt > ( id ) ;
162
+ public Texture ? GetTextureOrDefault ( int id ) => _internalGet < Texture , PropTexture > ( id ) ;
163
+ public Vector4 GetVectorOrDefault ( int id ) => _internalGet < Vector4 , PropVector > ( id ) ;
164
+
151
165
#endregion
152
166
153
167
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
0 commit comments