* 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
73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
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; }
|
|
}
|