Update trivial components to use auto comp states (#20539)

This commit is contained in:
DrSmugleaf
2023-09-28 16:20:29 -07:00
committed by GitHub
parent 14cfe44ece
commit a44fa86b68
158 changed files with 806 additions and 2866 deletions

View File

@@ -1,53 +1,36 @@
using Content.Shared.DeviceNetwork.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.DeviceNetwork.Components;
[RegisterComponent]
[NetworkedComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedDeviceListSystem))]
public sealed partial class DeviceListComponent : Component
{
/// <summary>
/// The list of devices can or can't connect to, depending on the <see cref="IsAllowList"/> field.
/// </summary>
[DataField("devices")]
[DataField, AutoNetworkedField]
public HashSet<EntityUid> Devices = new();
/// <summary>
/// The limit of devices that can be linked to this device list.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("deviceLimit")]
[DataField]
public int DeviceLimit = 32;
/// <summary>
/// Whether the device list is used as an allow or deny list
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("isAllowList")]
[DataField, AutoNetworkedField]
public bool IsAllowList = true;
/// <summary>
/// Whether this device list also handles incoming device net packets
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("handleIncoming")]
public bool HandleIncomingPackets = false;
}
[Serializable, NetSerializable]
public sealed class DeviceListComponentState : ComponentState
{
public readonly HashSet<NetEntity> Devices;
public readonly bool IsAllowList;
public readonly bool HandleIncomingPackets;
public DeviceListComponentState(HashSet<NetEntity> devices, bool isAllowList, bool handleIncomingPackets)
{
Devices = devices;
IsAllowList = isAllowList;
HandleIncomingPackets = handleIncomingPackets;
}
[DataField, AutoNetworkedField]
public bool HandleIncomingPackets;
}

View File

@@ -2,72 +2,57 @@ using Content.Shared.DeviceLinking;
using Content.Shared.DeviceNetwork.Systems;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.DeviceNetwork.Components;
[RegisterComponent]
[NetworkedComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedNetworkConfiguratorSystem))]
public sealed partial class NetworkConfiguratorComponent : Component
{
/// <summary>
/// Determines whether the configurator is in linking mode or list mode
/// </summary>
[DataField("linkModeActive")]
[DataField, AutoNetworkedField]
[ViewVariables(VVAccess.ReadWrite)]
public bool LinkModeActive = true;
/// <summary>
/// The entity containing a <see cref="DeviceListComponent"/> this configurator is currently interacting with
/// </summary>
[DataField("activeDeviceList")]
public EntityUid? ActiveDeviceList = null;
[DataField, AutoNetworkedField]
public EntityUid? ActiveDeviceList;
/// <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("activeDeviceLink")]
public EntityUid? ActiveDeviceLink = null;
[DataField]
public EntityUid? ActiveDeviceLink;
/// <summary>
/// The target device this configurator is currently linking with the <see cref="ActiveDeviceLink"/>
/// </summary>
[DataField("deviceLinkTarget")]
public EntityUid? DeviceLinkTarget = null;
[DataField]
public EntityUid? DeviceLinkTarget;
/// <summary>
/// The list of devices stored in the configurator
/// </summary>
[DataField("devices")]
[DataField]
public Dictionary<string, EntityUid> Devices = new();
[DataField("useDelay")]
[DataField]
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan UseDelay = TimeSpan.FromSeconds(0.5);
[DataField("lastUseAttempt", customTypeSerializer:typeof(TimeOffsetSerializer))]
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan LastUseAttempt;
[DataField("soundNoAccess")]
[DataField]
public SoundSpecifier SoundNoAccess = new SoundPathSpecifier("/Audio/Machines/custom_deny.ogg");
[DataField("soundSwitchMode")]
[DataField]
public SoundSpecifier SoundSwitchMode = new SoundPathSpecifier("/Audio/Machines/quickbeep.ogg");
}
[Serializable, NetSerializable]
public sealed class NetworkConfiguratorComponentState : ComponentState
{
public readonly NetEntity? ActiveDeviceList;
public readonly bool LinkModeActive;
public NetworkConfiguratorComponentState(NetEntity? activeDeviceList, bool linkModeActive)
{
ActiveDeviceList = activeDeviceList;
LinkModeActive = linkModeActive;
}
}

View File

@@ -1,17 +1,10 @@
using System.Linq;
using Content.Shared.DeviceNetwork.Components;
using Robust.Shared.GameStates;
namespace Content.Shared.DeviceNetwork.Systems;
public abstract class SharedDeviceListSystem : EntitySystem
{
public override void Initialize()
{
SubscribeLocalEvent<DeviceListComponent, ComponentGetState>(GetDeviceListState);
SubscribeLocalEvent<DeviceListComponent, ComponentHandleState>(HandleDeviceListState);
}
/// <summary>
/// Updates the device list stored on this entity.
/// </summary>
@@ -57,23 +50,6 @@ public abstract class SharedDeviceListSystem : EntitySystem
protected virtual void UpdateShutdownSubscription(EntityUid uid, List<EntityUid> devicesList, List<EntityUid> oldDevices)
{
}
private void GetDeviceListState(EntityUid uid, DeviceListComponent comp, ref ComponentGetState args)
{
args.State = new DeviceListComponentState(GetNetEntitySet(comp.Devices), comp.IsAllowList, comp.HandleIncomingPackets);
}
private void HandleDeviceListState(EntityUid uid, DeviceListComponent comp, ref ComponentHandleState args)
{
if (args.Current is not DeviceListComponentState state)
{
return;
}
comp.Devices = EnsureEntitySet<DeviceListComponent>(state.Devices, uid);
comp.HandleIncomingPackets = state.HandleIncomingPackets;
comp.IsAllowList = state.IsAllowList;
}
}
public sealed class DeviceListUpdateEvent : EntityEventArgs

View File

@@ -1,37 +1,10 @@
using Content.Shared.Actions;
using Content.Shared.DeviceNetwork.Components;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.DeviceNetwork.Systems;
public abstract class SharedNetworkConfiguratorSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NetworkConfiguratorComponent, ComponentGetState>(GetNetworkConfiguratorState);
SubscribeLocalEvent<NetworkConfiguratorComponent, ComponentHandleState>(HandleNetworkConfiguratorState);
}
private void GetNetworkConfiguratorState(EntityUid uid, NetworkConfiguratorComponent comp,
ref ComponentGetState args)
{
args.State = new NetworkConfiguratorComponentState(GetNetEntity(comp.ActiveDeviceList), comp.LinkModeActive);
}
private void HandleNetworkConfiguratorState(EntityUid uid, NetworkConfiguratorComponent comp,
ref ComponentHandleState args)
{
if (args.Current is not NetworkConfiguratorComponentState state)
{
return;
}
comp.ActiveDeviceList = EnsureEntity<NetworkConfiguratorComponent>(state.ActiveDeviceList, uid);
comp.LinkModeActive = state.LinkModeActive;
}
}
public sealed partial class ClearAllOverlaysEvent : InstantActionEvent