using System.Linq; using Robust.Shared.GameStates; namespace Content.Shared.DeviceNetwork; public abstract class SharedDeviceListSystem : EntitySystem { public override void Initialize() { SubscribeLocalEvent(GetDeviceListState); SubscribeLocalEvent(HandleDeviceListState); } /// /// Updates the device list stored on this entity. /// /// The entity to update. /// The devices to store. /// Whether to merge or replace the devices stored. /// Device list component public void UpdateDeviceList(EntityUid uid, IEnumerable 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 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 devices) { Devices = devices; } public List Devices { get; } }