Try fix invalid entities in device networks (#22845)
* Try fix invalid entities in device networks * more fixes * a * fix device merging
This commit is contained in:
@@ -33,4 +33,7 @@ public sealed partial class DeviceListComponent : Component
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool HandleIncomingPackets;
|
||||
|
||||
[DataField, Access(typeof(SharedNetworkConfiguratorSystem))]
|
||||
public HashSet<EntityUid> Configurators = new();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Content.Shared.DeviceNetwork.Components;
|
||||
[Access(typeof(SharedNetworkConfiguratorSystem))]
|
||||
public sealed partial class NetworkConfiguratorComponent : Component
|
||||
{
|
||||
// AAAAA ALL OF THESE FAA
|
||||
/// <summary>
|
||||
/// Determines whether the configurator is in linking mode or list mode
|
||||
/// </summary>
|
||||
@@ -21,19 +22,19 @@ public sealed partial class NetworkConfiguratorComponent : Component
|
||||
/// The entity containing a <see cref="DeviceListComponent"/> this configurator is currently interacting with
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public EntityUid? ActiveDeviceList;
|
||||
public EntityUid? ActiveDeviceList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The entity containing a <see cref="DeviceLinkSourceComponent"/> or <see cref="DeviceLinkSinkComponent"/> this configurator is currently interacting with.<br/>
|
||||
/// If this is set the configurator is in linking mode.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
// TODO handle device deletion
|
||||
public EntityUid? ActiveDeviceLink;
|
||||
|
||||
/// <summary>
|
||||
/// The target device this configurator is currently linking with the <see cref="ActiveDeviceLink"/>
|
||||
/// </summary>
|
||||
[DataField]
|
||||
// TODO handle device deletion
|
||||
public EntityUid? DeviceLinkTarget;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,39 +5,6 @@ namespace Content.Shared.DeviceNetwork.Systems;
|
||||
|
||||
public abstract class SharedDeviceListSystem : EntitySystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Updates the device list stored on this entity.
|
||||
/// </summary>
|
||||
/// <param name="uid">The entity to update.</param>
|
||||
/// <param name="devices">The devices to store.</param>
|
||||
/// <param name="merge">Whether to merge or replace the devices stored.</param>
|
||||
/// <param name="deviceList">Device list component</param>
|
||||
public DeviceListUpdateResult UpdateDeviceList(EntityUid uid, IEnumerable<EntityUid> devices, bool merge = false, DeviceListComponent? deviceList = null)
|
||||
{
|
||||
if (!Resolve(uid, ref deviceList))
|
||||
return DeviceListUpdateResult.NoComponent;
|
||||
|
||||
var oldDevices = deviceList.Devices.ToList();
|
||||
var newDevices = merge ? new HashSet<EntityUid>(deviceList.Devices) : new();
|
||||
var devicesList = devices.ToList();
|
||||
|
||||
newDevices.UnionWith(devicesList);
|
||||
if (newDevices.Count > deviceList.DeviceLimit)
|
||||
{
|
||||
return DeviceListUpdateResult.TooManyDevices;
|
||||
}
|
||||
|
||||
deviceList.Devices = newDevices;
|
||||
|
||||
UpdateShutdownSubscription(uid, devicesList, oldDevices);
|
||||
|
||||
RaiseLocalEvent(uid, new DeviceListUpdateEvent(oldDevices, devicesList));
|
||||
|
||||
Dirty(deviceList);
|
||||
|
||||
return DeviceListUpdateResult.UpdateOk;
|
||||
}
|
||||
|
||||
public IEnumerable<EntityUid> GetAllDevices(EntityUid uid, DeviceListComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
@@ -46,10 +13,6 @@ public abstract class SharedDeviceListSystem : EntitySystem
|
||||
}
|
||||
return component.Devices;
|
||||
}
|
||||
|
||||
protected virtual void UpdateShutdownSubscription(EntityUid uid, List<EntityUid> devicesList, List<EntityUid> oldDevices)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DeviceListUpdateEvent : EntityEventArgs
|
||||
|
||||
Reference in New Issue
Block a user