Removes hacky behavior from DeviceListSystem (#11255)

This commit is contained in:
Flipp Syder
2022-09-13 23:09:43 -07:00
committed by GitHub
parent 737002248b
commit ec6cdbd51a
5 changed files with 8 additions and 64 deletions

View File

@@ -55,20 +55,7 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface
private void OnShowPressed(BaseButton.ButtonEventArgs args) private void OnShowPressed(BaseButton.ButtonEventArgs args)
{ {
if (!args.Button.Pressed) _netConfig.ToggleVisualization(Owner.Owner, args.Button.Pressed);
{
_netConfig.ToggleVisualization(Owner.Owner, false);
return;
}
if (_entityManager.GetComponent<MetaDataComponent>(Owner.Owner).EntityLifeStage == EntityLifeStage.Initialized)
{
// We're in mapping mode. Do something hacky.
SendMessage(new ManualDeviceListSyncMessage(null, null));
return;
}
_netConfig.ToggleVisualization(Owner.Owner, true);
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -86,25 +73,6 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface
} }
} }
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{
base.ReceiveMessage(message);
if (_configurationMenu == null
|| _entityManager.GetComponent<MetaDataComponent>(Owner.Owner).EntityLifeStage > EntityLifeStage.Initialized
|| message is not ManualDeviceListSyncMessage cast
|| cast.Device == null
|| cast.Devices == null)
{
return;
}
_netConfig.SetActiveDeviceList(Owner.Owner, cast.Device.Value);
_deviceList.UpdateDeviceList(cast.Device.Value, cast.Devices);
_netConfig.ToggleVisualization(Owner.Owner, true);
_configurationMenu.Show.Pressed = true;
}
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); base.Dispose(disposing);

View File

@@ -12,10 +12,16 @@ public sealed class DeviceListSystem : SharedDeviceListSystem
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<DeviceListComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<DeviceListComponent, BeforeBroadcastAttemptEvent>(OnBeforeBroadcast); SubscribeLocalEvent<DeviceListComponent, BeforeBroadcastAttemptEvent>(OnBeforeBroadcast);
SubscribeLocalEvent<DeviceListComponent, BeforePacketSentEvent>(OnBeforePacketSent); SubscribeLocalEvent<DeviceListComponent, BeforePacketSentEvent>(OnBeforePacketSent);
} }
public void OnInit(EntityUid uid, DeviceListComponent component, ComponentInit args)
{
Dirty(component);
}
/// <summary> /// <summary>
/// Gets the given device list as a dictionary /// Gets the given device list as a dictionary
/// </summary> /// </summary>

View File

@@ -46,7 +46,6 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorRemoveDeviceMessage>(OnRemoveDevice); SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorRemoveDeviceMessage>(OnRemoveDevice);
SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorClearDevicesMessage>(OnClearDevice); SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorClearDevicesMessage>(OnClearDevice);
SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorButtonPressedMessage>(OnConfigButtonPressed); SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorButtonPressedMessage>(OnConfigButtonPressed);
SubscribeLocalEvent<NetworkConfiguratorComponent, ManualDeviceListSyncMessage>(ManualDeviceListSync);
SubscribeLocalEvent<DeviceListComponent, ComponentRemove>(OnComponentRemoved); SubscribeLocalEvent<DeviceListComponent, ComponentRemove>(OnComponentRemoved);
} }
@@ -330,20 +329,5 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
_deviceListSystem.GetDeviceList(component.ActiveDeviceList.Value) _deviceListSystem.GetDeviceList(component.ActiveDeviceList.Value)
.Select(v => (v.Key, MetaData(v.Value).EntityName)).ToHashSet())); .Select(v => (v.Key, MetaData(v.Value).EntityName)).ToHashSet()));
} }
// hacky solution related to mapping
private void ManualDeviceListSync(EntityUid uid, NetworkConfiguratorComponent comp,
ManualDeviceListSyncMessage args)
{
if (comp.ActiveDeviceList == null || args.Session is not IPlayerSession player)
{
return;
}
var devices = _deviceListSystem.GetAllDevices(comp.ActiveDeviceList.Value).ToHashSet();
_uiSystem.TrySendUiMessage(uid, NetworkConfiguratorUiKey.Configure, new ManualDeviceListSyncMessage(comp.ActiveDeviceList.Value, devices), player);
}
#endregion #endregion
} }

View File

@@ -17,6 +17,7 @@ public abstract class SharedDeviceListSystem : EntitySystem
/// <param name="uid">The entity to update.</param> /// <param name="uid">The entity to update.</param>
/// <param name="devices">The devices to store.</param> /// <param name="devices">The devices to store.</param>
/// <param name="merge">Whether to merge or replace the devices stored.</param> /// <param name="merge">Whether to merge or replace the devices stored.</param>
/// <param name="dirty">If the component should be dirtied upon this call.</param>
/// <param name="deviceList">Device list component</param> /// <param name="deviceList">Device list component</param>
public DeviceListUpdateResult UpdateDeviceList(EntityUid uid, IEnumerable<EntityUid> devices, bool merge = false, DeviceListComponent? deviceList = null) public DeviceListUpdateResult UpdateDeviceList(EntityUid uid, IEnumerable<EntityUid> devices, bool merge = false, DeviceListComponent? deviceList = null)
{ {

View File

@@ -14,8 +14,6 @@ public abstract class SharedNetworkConfiguratorSystem : EntitySystem
SubscribeLocalEvent<NetworkConfiguratorComponent, ComponentHandleState>(HandleNetworkConfiguratorState); SubscribeLocalEvent<NetworkConfiguratorComponent, ComponentHandleState>(HandleNetworkConfiguratorState);
} }
private void GetNetworkConfiguratorState(EntityUid uid, NetworkConfiguratorComponent comp, private void GetNetworkConfiguratorState(EntityUid uid, NetworkConfiguratorComponent comp,
ref ComponentGetState args) ref ComponentGetState args)
{ {
@@ -34,19 +32,6 @@ public abstract class SharedNetworkConfiguratorSystem : EntitySystem
} }
} }
[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 public sealed class ClearAllOverlaysEvent : InstantActionEvent
{ {
} }