@@ -12,23 +12,6 @@ namespace MLAPI.Data.NetworkedCollections
1212 /// <typeparam name="T">The type for the list</typeparam>
1313 public class NetworkedList < T > : IList < T > , INetworkedVar
1414 {
15- internal struct NetworkedListEvent < T >
16- {
17- internal enum NetworkedListEventType
18- {
19- Add ,
20- Insert ,
21- Remove ,
22- RemoveAt ,
23- Value ,
24- Clear
25- }
26-
27- internal NetworkedListEventType eventType ;
28- internal T value ;
29- internal int index ;
30- }
31-
3215 private readonly IList < T > list = new List < T > ( ) ;
3316 private List < NetworkedListEvent < T > > dirtyEvents = new List < NetworkedListEvent < T > > ( ) ;
3417 private NetworkedBehaviour networkedBehaviour ;
@@ -40,24 +23,39 @@ internal enum NetworkedListEventType
4023 /// The settings for this container
4124 /// </summary>
4225 public readonly NetworkedVarSettings Settings = new NetworkedVarSettings ( ) ;
43-
44-
26+
27+ /// <summary>
28+ /// Creates a NetworkedList with the default value and settings
29+ /// </summary>
4530 public NetworkedList ( )
4631 {
4732
4833 }
49-
34+
35+ /// <summary>
36+ /// Creates a NetworkedList with the default value and custom settings
37+ /// </summary>
38+ /// <param name="settings">The settings to use for the NetworkedList</param>
5039 public NetworkedList ( NetworkedVarSettings settings )
5140 {
5241 this . Settings = settings ;
5342 }
54-
43+
44+ /// <summary>
45+ /// Creates a NetworkedList with a custom value and custom settings
46+ /// </summary>
47+ /// <param name="settings">The settings to use for the NetworkedList</param>
48+ /// <param name="value">The initial value to use for the NetworkedList</param>
5549 public NetworkedList ( NetworkedVarSettings settings , IList < T > value )
5650 {
5751 this . Settings = settings ;
5852 this . list = value ;
5953 }
60-
54+
55+ /// <summary>
56+ /// Creates a NetworkedList with a custom value and the default settings
57+ /// </summary>
58+ /// <param name="value">The initial value to use for the NetworkedList</param>
6159 public NetworkedList ( IList < T > value )
6260 {
6361 this . list = value ;
@@ -137,35 +135,35 @@ public void WriteDelta(Stream stream)
137135 switch ( dirtyEvents [ i ] . eventType )
138136 {
139137 //Fuck me these signatures are proper aids
140- case NetworkedList < T > . NetworkedListEvent < T > . NetworkedListEventType . Add :
138+ case NetworkedListEvent < T > . NetworkedListEventType . Add :
141139 {
142140 writer . WriteObjectPacked ( dirtyEvents [ i ] . value ) ; //BOX
143141 }
144142 break ;
145- case NetworkedList < T > . NetworkedListEvent < T > . NetworkedListEventType . Insert :
143+ case NetworkedListEvent < T > . NetworkedListEventType . Insert :
146144 {
147145 writer . WriteInt32Packed ( dirtyEvents [ i ] . index ) ;
148146 writer . WriteObjectPacked ( dirtyEvents [ i ] . value ) ; //BOX
149147 }
150148 break ;
151- case NetworkedList < T > . NetworkedListEvent < T > . NetworkedListEventType . Remove :
149+ case NetworkedListEvent < T > . NetworkedListEventType . Remove :
152150 {
153151 writer . WriteObjectPacked ( dirtyEvents [ i ] . value ) ; //BOX
154152 }
155153 break ;
156- case NetworkedList < T > . NetworkedListEvent < T > . NetworkedListEventType . RemoveAt :
154+ case NetworkedListEvent < T > . NetworkedListEventType . RemoveAt :
157155 {
158156 writer . WriteInt32Packed ( dirtyEvents [ i ] . index ) ;
159157 }
160158 break ;
161- case NetworkedList < T > . NetworkedListEvent < T > . NetworkedListEventType . Value :
159+ case NetworkedListEvent < T > . NetworkedListEventType . Value :
162160 {
163161 writer . WriteInt32Packed ( dirtyEvents [ i ] . index ) ;
164162 writer . WriteObjectPacked ( dirtyEvents [ i ] . value ) ; //BOX
165163 }
166164
167165 break ;
168- case NetworkedList < T > . NetworkedListEvent < T > . NetworkedListEventType . Clear :
166+ case NetworkedListEvent < T > . NetworkedListEventType . Clear :
169167 {
170168 //Nothing has to be written
171169 }
@@ -212,30 +210,30 @@ public void ReadDelta(Stream stream)
212210 list . Add ( ( T ) reader . ReadObjectPacked ( typeof ( T ) ) ) ; //BOX
213211 }
214212 break ;
215- case NetworkedList < T > . NetworkedListEvent < T > . NetworkedListEventType . Insert :
213+ case NetworkedListEvent < T > . NetworkedListEventType . Insert :
216214 {
217215 int index = reader . ReadInt32Packed ( ) ;
218216 list . Insert ( index , ( T ) reader . ReadObjectPacked ( typeof ( T ) ) ) ; //BOX
219217 }
220218 break ;
221- case NetworkedList < T > . NetworkedListEvent < T > . NetworkedListEventType . Remove :
219+ case NetworkedListEvent < T > . NetworkedListEventType . Remove :
222220 {
223221 list . Remove ( ( T ) reader . ReadObjectPacked ( typeof ( T ) ) ) ; //BOX
224222 }
225223 break ;
226- case NetworkedList < T > . NetworkedListEvent < T > . NetworkedListEventType . RemoveAt :
224+ case NetworkedListEvent < T > . NetworkedListEventType . RemoveAt :
227225 {
228226 int index = reader . ReadInt32Packed ( ) ;
229227 list . RemoveAt ( index ) ;
230228 }
231229 break ;
232- case NetworkedList < T > . NetworkedListEvent < T > . NetworkedListEventType . Value :
230+ case NetworkedListEvent < T > . NetworkedListEventType . Value :
233231 {
234232 int index = reader . ReadInt32Packed ( ) ;
235233 if ( index < list . Count ) list [ index ] = ( T ) reader . ReadObjectPacked ( typeof ( T ) ) ; //BOX
236234 }
237235 break ;
238- case NetworkedList < T > . NetworkedListEvent < T > . NetworkedListEventType . Clear :
236+ case NetworkedListEvent < T > . NetworkedListEventType . Clear :
239237 {
240238 //Read nothing
241239 list . Clear ( ) ;
@@ -364,4 +362,21 @@ public T this[int index]
364362 }
365363 }
366364 }
365+
366+ internal struct NetworkedListEvent < T >
367+ {
368+ internal enum NetworkedListEventType
369+ {
370+ Add ,
371+ Insert ,
372+ Remove ,
373+ RemoveAt ,
374+ Value ,
375+ Clear
376+ }
377+
378+ internal NetworkedListEventType eventType ;
379+ internal T value ;
380+ internal int index ;
381+ }
367382}
0 commit comments