Device link visualizer (#11054)

* shuffles devicelist to shared, adds an overlay for devicelist

* adds space property to overlay

* moves networkconfigurator to shared, makes devicelistsystem clientside check activedevicelist

* dirties components upon change, adds networkedcomponent to sharednetworkconfigurator

* state handlers for networked components

* whoops

* lots of shuffling, renaming, and access changes

* randomizes color for every new entity added to the overlay

* adds a client-side action to clear all network overlays if they're active

* clones action (oops)

* localization, adds a command for clearing network link overlays (in case the action disappears)

* moves the entity manager up into the bui fields

* makes that a dependency

* attempts to just directly get the color from the dict when drawing, now

* fixes up a few comments

* adds dirty on init to devicelistcomponent

* hacky solution related to mapping with a networkconfigurator

* more stricter bound on that hacky solution

* just checks if the life stage is initialized instead of if the entity was initialized

* moves getalldevices to shared

* readds linq import

* tries to ensure that the show button is toggled on if the device we're trying to configure is currently being tracked by the overlay

* some reorganization
This commit is contained in:
Flipp Syder
2022-09-05 17:55:44 -07:00
committed by GitHub
parent 6301ac5147
commit 9ace52a6c1
16 changed files with 454 additions and 55 deletions

View File

@@ -0,0 +1,45 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.DeviceNetwork;
[RegisterComponent]
[NetworkedComponent]
[Access(typeof(SharedDeviceListSystem))]
public sealed class DeviceListComponent : Component
{
/// <summary>
/// The list of devices can or can't connect to, depending on the <see cref="IsAllowList"/> field.
/// </summary>
[DataField("devices")]
public HashSet<EntityUid> Devices = new();
/// <summary>
/// Whether the device list is used as an allow or deny list
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("isAllowList")]
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<EntityUid> Devices;
public readonly bool IsAllowList;
public readonly bool HandleIncomingPackets;
public DeviceListComponentState(HashSet<EntityUid> devices, bool isAllowList, bool handleIncomingPackets)
{
Devices = devices;
IsAllowList = isAllowList;
HandleIncomingPackets = handleIncomingPackets;
}
}

View File

@@ -0,0 +1,37 @@
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.DeviceNetwork;
[RegisterComponent]
[NetworkedComponent]
[Access(typeof(SharedNetworkConfiguratorSystem))]
public sealed class NetworkConfiguratorComponent : Component
{
/// <summary>
/// The entity containing a <see cref="DeviceListComponent"/> this configurator is currently interacting with
/// </summary>
[DataField("activeDeviceList")]
public EntityUid? ActiveDeviceList = null;
/// <summary>
/// The list of devices stored in the configurator-
/// </summary>
[DataField("devices")]
public Dictionary<string, EntityUid> Devices = new();
[DataField("soundNoAccess")]
public SoundSpecifier SoundNoAccess = new SoundPathSpecifier("/Audio/Machines/custom_deny.ogg");
}
[Serializable, NetSerializable]
public sealed class NetworkConfiguratorComponentState : ComponentState
{
public readonly EntityUid? ActiveDeviceList;
public NetworkConfiguratorComponentState(EntityUid? activeDeviceList)
{
ActiveDeviceList = activeDeviceList;
}
}

View File

@@ -0,0 +1,72 @@
using System.Linq;
using Robust.Shared.GameStates;
namespace Content.Shared.DeviceNetwork;
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>
/// <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 void UpdateDeviceList(EntityUid uid, IEnumerable<EntityUid> devices, bool merge = false, DeviceListComponent? deviceList = null)
{
if (!Resolve(uid, ref deviceList))
return;
if (!merge)
deviceList.Devices.Clear();
var devicesList = devices.ToList();
deviceList.Devices.UnionWith(devicesList);
RaiseLocalEvent(uid, new DeviceListUpdateEvent(devicesList));
Dirty(deviceList);
}
public IEnumerable<EntityUid> GetAllDevices(EntityUid uid, DeviceListComponent? component = null)
{
if (!Resolve(uid, ref component))
{
return new EntityUid[] { };
}
return component.Devices;
}
private void GetDeviceListState(EntityUid uid, DeviceListComponent comp, ref ComponentGetState args)
{
args.State = new DeviceListComponentState(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 = state.Devices;
comp.HandleIncomingPackets = state.HandleIncomingPackets;
comp.IsAllowList = state.IsAllowList;
}
}
public sealed class DeviceListUpdateEvent : EntityEventArgs
{
public DeviceListUpdateEvent(List<EntityUid> devices)
{
Devices = devices;
}
public List<EntityUid> Devices { get; }
}

View File

@@ -0,0 +1,52 @@
using Content.Shared.Actions;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.DeviceNetwork;
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(comp.ActiveDeviceList);
}
private void HandleNetworkConfiguratorState(EntityUid uid, NetworkConfiguratorComponent comp,
ref ComponentHandleState args)
{
if (args.Current is not NetworkConfiguratorComponentState state)
{
return;
}
comp.ActiveDeviceList = state.ActiveDeviceList;
}
}
[Serializable, NetSerializable]
public sealed class ManualDeviceListSyncMessage : BoundUserInterfaceMessage
{
public ManualDeviceListSyncMessage(EntityUid? device, HashSet<EntityUid>? devices)
{
Device = device;
Devices = devices;
}
public EntityUid? Device { get; }
public HashSet<EntityUid>? Devices { get; }
}
public sealed class ClearAllOverlaysEvent : InstantActionEvent
{
}