@@ -21,20 +21,13 @@ public sealed class DeviceNetworkSystem : EntitySystem
2121 [ Dependency ] private readonly IPrototypeManager _protoMan = default ! ;
2222 [ Dependency ] private readonly SharedTransformSystem _transformSystem = default ! ;
2323
24- private readonly DeviceNet [ ] _networks = new DeviceNet [ 4 ] ; // Number of ConnectionType enum values
24+ private readonly Dictionary < int , DeviceNet > _networks = new ( 4 ) ;
2525 private readonly Queue < DeviceNetworkPacketEvent > _packets = new ( ) ;
2626
2727 public override void Initialize ( )
2828 {
29- base . Initialize ( ) ;
30-
3129 SubscribeLocalEvent < DeviceNetworkComponent , MapInitEvent > ( OnMapInit ) ;
3230 SubscribeLocalEvent < DeviceNetworkComponent , ComponentShutdown > ( OnNetworkShutdown ) ;
33-
34- InitNetwork ( ConnectionType . Private ) ;
35- InitNetwork ( ConnectionType . Wired ) ;
36- InitNetwork ( ConnectionType . Wireless ) ;
37- InitNetwork ( ConnectionType . Apc ) ;
3831 }
3932
4033 public override void Update ( float frameTime )
@@ -66,10 +59,6 @@ public void QueuePacket(EntityUid uid, string? address, NetworkPayload data, uin
6659 if ( frequency != null )
6760 _packets . Enqueue ( new DeviceNetworkPacketEvent ( device . DeviceNetId , address , frequency . Value , device . Address , uid , data ) ) ;
6861 }
69-
70- private void InitNetwork ( ConnectionType connectionType ) =>
71- _networks [ ( int ) connectionType ] = new ( connectionType , _random ) ;
72-
7362 /// <summary>
7463 /// Automatically attempt to connect some devices when a map starts.
7564 /// </summary>
@@ -93,8 +82,14 @@ private void OnMapInit(EntityUid uid, DeviceNetworkComponent device, MapInitEven
9382 ConnectDevice ( uid , device ) ;
9483 }
9584
96- private DeviceNet GetNetwork ( ConnectionType connectionType ) =>
97- _networks [ ( int ) connectionType ] ;
85+ private DeviceNet GetNetwork ( int netId )
86+ {
87+ if ( _networks . TryGetValue ( netId , out var deviceNet ) )
88+ return deviceNet ;
89+ var newDeviceNet = new DeviceNet ( netId , _random ) ;
90+ _networks [ netId ] = newDeviceNet ;
91+ return newDeviceNet ;
92+ }
9893
9994 /// <summary>
10095 /// Automatically disconnect when an entity with a DeviceNetworkComponent shuts down.
@@ -191,7 +186,7 @@ public void RandomizeAddress(EntityUid uid, DeviceNetworkComponent? device = nul
191186 /// <summary>
192187 /// Try to find a device on a network using its address.
193188 /// </summary>
194- private bool TryGetDevice ( ConnectionType netId , string address , [ NotNullWhen ( true ) ] out DeviceNetworkComponent ? device ) =>
189+ private bool TryGetDevice ( int netId , string address , [ NotNullWhen ( true ) ] out DeviceNetworkComponent ? device ) =>
195190 GetNetwork ( netId ) . Devices . TryGetValue ( address , out device ) ;
196191
197192 private void SendPacket ( DeviceNetworkPacketEvent packet )
@@ -289,9 +284,9 @@ public BeforePacketSentEvent(EntityUid sender, TransformComponent xform, Vector2
289284 public sealed class DeviceNetworkPacketEvent : EntityEventArgs
290285 {
291286 /// <summary>
292- /// The type of network that this packet is being sent on.
287+ /// The id of the network that this packet is being sent on.
293288 /// </summary>
294- public ConnectionType NetId ;
289+ public int NetId ;
295290
296291 /// <summary>
297292 /// The frequency the packet is sent on.
@@ -318,7 +313,7 @@ public sealed class DeviceNetworkPacketEvent : EntityEventArgs
318313 /// </summary>
319314 public readonly NetworkPayload Data ;
320315
321- public DeviceNetworkPacketEvent ( ConnectionType netId , string ? address , uint frequency , string senderAddress , EntityUid sender , NetworkPayload data )
316+ public DeviceNetworkPacketEvent ( int netId , string ? address , uint frequency , string senderAddress , EntityUid sender , NetworkPayload data )
322317 {
323318 NetId = netId ;
324319 Address = address ;
0 commit comments