From 05a2ddff1cc415c3bdf1e15ef3a2c953bcb5384b Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 11 Feb 2024 14:19:45 +1100 Subject: [PATCH] Predict two-way levers (#25043) * Predict two-way levers Annoys me the rare occasions I touch cargo. Doesn't predict the signal but at least the lever responds immediately. * space * a --- .../DeviceNetworkingBenchmark.cs | 2 +- .../DeviceLinking/DeviceLinkSystem.cs | 8 ++++++ .../Tests/DeviceNetwork/DeviceNetworkTest.cs | 1 + .../DeviceNetwork/DeviceNetworkTestSystem.cs | 3 +-- .../Atmos/Monitor/Systems/AirAlarmSystem.cs | 1 + .../Monitor/Systems/AtmosAlarmableSystem.cs | 1 + .../Monitor/Systems/AtmosDeviceNetwork.cs | 1 + .../Monitor/Systems/AtmosMonitoringSystem.cs | 1 + .../EntitySystems/GasVolumePumpSystem.cs | 1 + .../EntitySystems/GasThermoMachineSystem.cs | 1 + .../Unary/EntitySystems/GasVentPumpSystem.cs | 1 + .../EntitySystems/GasVentScrubberSystem.cs | 1 + .../CommunicationsConsoleSystem.cs | 1 + .../Components/TwoWayLeverComponent.cs | 24 ----------------- .../Events/SignalReceivedEvent.cs | 1 + .../DeviceLinking/Systems/DeviceLinkSystem.cs | 11 ++------ .../Systems/DoorSignalControlSystem.cs | 1 + .../DeviceNetwork/NetworkPayload.cs | 26 ------------------- .../Systems/Devices/ApcNetSwitchSystem.cs | 1 + .../Disposal/Mailing/MailingUnitSystem.cs | 1 + Content.Server/Fax/FaxSystem.cs | 1 + .../CrewMonitoringServerSystem.cs | 1 + .../Medical/SuitSensors/SuitSensorSystem.cs | 1 + .../Power/Generation/Teg/TegSystem.cs | 1 + Content.Server/RoundEnd/RoundEndSystem.cs | 1 + .../SensorMonitoring/BatterySensorSystem.cs | 1 + .../SensorMonitoringConsoleSystem.cs | 2 +- .../Shuttles/Systems/ArrivalsSystem.cs | 1 + .../Systems/EmergencyShuttleSystem.Console.cs | 1 + .../Systems/EmergencyShuttleSystem.cs | 2 +- .../SurveillanceCameraMonitorSystem.cs | 1 + .../Components/TwoWayLeverComponent.cs | 26 +++++++++++++++++++ .../DeviceLinking/SharedDeviceLinkSystem.cs | 23 ++++++++++++++++ .../Systems/TwoWayLeverSystem.cs | 8 +++--- .../DeviceNetwork/NetworkPayload.cs | 24 +++++++++++++++++ 35 files changed, 114 insertions(+), 68 deletions(-) create mode 100644 Content.Client/DeviceLinking/DeviceLinkSystem.cs delete mode 100644 Content.Server/DeviceLinking/Components/TwoWayLeverComponent.cs delete mode 100644 Content.Server/DeviceNetwork/NetworkPayload.cs create mode 100644 Content.Shared/DeviceLinking/Components/TwoWayLeverComponent.cs rename {Content.Server => Content.Shared}/DeviceLinking/Systems/TwoWayLeverSystem.cs (95%) create mode 100644 Content.Shared/DeviceNetwork/NetworkPayload.cs diff --git a/Content.Benchmarks/DeviceNetworkingBenchmark.cs b/Content.Benchmarks/DeviceNetworkingBenchmark.cs index 16805c2684f..bb2a22312ea 100644 --- a/Content.Benchmarks/DeviceNetworkingBenchmark.cs +++ b/Content.Benchmarks/DeviceNetworkingBenchmark.cs @@ -4,8 +4,8 @@ using Content.IntegrationTests; using Content.IntegrationTests.Pair; using Content.IntegrationTests.Tests.DeviceNetwork; -using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Systems; +using Content.Shared.DeviceNetwork; using Robust.Shared; using Robust.Shared.Analyzers; using Robust.Shared.GameObjects; diff --git a/Content.Client/DeviceLinking/DeviceLinkSystem.cs b/Content.Client/DeviceLinking/DeviceLinkSystem.cs new file mode 100644 index 00000000000..3356e346f6a --- /dev/null +++ b/Content.Client/DeviceLinking/DeviceLinkSystem.cs @@ -0,0 +1,8 @@ +using Content.Shared.DeviceLinking; + +namespace Content.Client.DeviceLinking; + +public sealed class DeviceLinkSystem : SharedDeviceLinkSystem +{ + +} diff --git a/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs b/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs index 1d994624a6d..26ea726211b 100644 --- a/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs +++ b/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTest.cs @@ -2,6 +2,7 @@ using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Systems; +using Content.Shared.DeviceNetwork; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; diff --git a/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTestSystem.cs b/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTestSystem.cs index 6e3db254047..400d85f2ccb 100644 --- a/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTestSystem.cs +++ b/Content.IntegrationTests/Tests/DeviceNetwork/DeviceNetworkTestSystem.cs @@ -1,7 +1,6 @@ - -using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Systems; +using Content.Shared.DeviceNetwork; using Robust.Shared.GameObjects; using Robust.Shared.Reflection; diff --git a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs index b346fd63b0d..2922d0796a9 100644 --- a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs @@ -15,6 +15,7 @@ using Content.Shared.Atmos.Monitor.Components; using Content.Shared.Atmos.Piping.Unary.Components; using Content.Shared.DeviceLinking; +using Content.Shared.DeviceNetwork; using Content.Shared.DeviceNetwork.Systems; using Content.Shared.Interaction; using Content.Shared.Wires; diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs b/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs index 27e64a9956d..2875d4a3d5d 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs @@ -6,6 +6,7 @@ using Content.Server.DeviceNetwork.Systems; using Content.Server.Power.Components; using Content.Shared.Atmos.Monitor; +using Content.Shared.DeviceNetwork; using Content.Shared.Tag; using Robust.Server.Audio; using Robust.Server.GameObjects; diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosDeviceNetwork.cs b/Content.Server/Atmos/Monitor/Systems/AtmosDeviceNetwork.cs index 0b73ea5f351..33e4eafc741 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosDeviceNetwork.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosDeviceNetwork.cs @@ -1,6 +1,7 @@ using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Systems; using Content.Shared.Atmos.Monitor.Components; +using Content.Shared.DeviceNetwork; namespace Content.Server.Atmos.Monitor.Systems; diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs index 1fcb7734d8b..28a0a01c99a 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs @@ -8,6 +8,7 @@ using Content.Server.Power.EntitySystems; using Content.Shared.Atmos; using Content.Shared.Atmos.Monitor; +using Content.Shared.DeviceNetwork; using Content.Shared.Tag; using Robust.Shared.Prototypes; diff --git a/Content.Server/Atmos/Piping/Binary/EntitySystems/GasVolumePumpSystem.cs b/Content.Server/Atmos/Piping/Binary/EntitySystems/GasVolumePumpSystem.cs index 4ae0d70f5e7..10b9cccc099 100644 --- a/Content.Server/Atmos/Piping/Binary/EntitySystems/GasVolumePumpSystem.cs +++ b/Content.Server/Atmos/Piping/Binary/EntitySystems/GasVolumePumpSystem.cs @@ -13,6 +13,7 @@ using Content.Shared.Atmos.Visuals; using Content.Shared.Audio; using Content.Shared.Database; +using Content.Shared.DeviceNetwork; using Content.Shared.Examine; using Content.Shared.Interaction; using Content.Shared.Popups; diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs index ee0dca0fb0a..645b2ecc459 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs @@ -17,6 +17,7 @@ using Content.Shared.UserInterface; using Content.Shared.Administration.Logs; using Content.Shared.Database; +using Content.Shared.DeviceNetwork; using Content.Shared.Examine; namespace Content.Server.Atmos.Piping.Unary.EntitySystems diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs index a35c6b1aa6e..3a3ccf75234 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs @@ -16,6 +16,7 @@ using Content.Shared.Atmos.Piping.Unary.Components; using Content.Shared.Atmos.Visuals; using Content.Shared.Audio; +using Content.Shared.DeviceNetwork; using Content.Shared.Examine; using Content.Shared.Tools.Systems; using JetBrains.Annotations; diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs index ecf7d1d0b45..32591e9c540 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs @@ -15,6 +15,7 @@ using Content.Shared.Atmos.Monitor; using Content.Shared.Atmos.Piping.Unary.Components; using Content.Shared.Audio; +using Content.Shared.DeviceNetwork; using Content.Shared.Tools.Systems; using JetBrains.Annotations; using Robust.Server.GameObjects; diff --git a/Content.Server/Communications/CommunicationsConsoleSystem.cs b/Content.Server/Communications/CommunicationsConsoleSystem.cs index 4fa60563bdd..6b0b13c410e 100644 --- a/Content.Server/Communications/CommunicationsConsoleSystem.cs +++ b/Content.Server/Communications/CommunicationsConsoleSystem.cs @@ -19,6 +19,7 @@ using Content.Shared.Chat; using Content.Shared.Communications; using Content.Shared.Database; +using Content.Shared.DeviceNetwork; using Content.Shared.Emag.Components; using Content.Shared.Popups; using Robust.Server.GameObjects; diff --git a/Content.Server/DeviceLinking/Components/TwoWayLeverComponent.cs b/Content.Server/DeviceLinking/Components/TwoWayLeverComponent.cs deleted file mode 100644 index bbf78b6876b..00000000000 --- a/Content.Server/DeviceLinking/Components/TwoWayLeverComponent.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Content.Shared.DeviceLinking; -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; - -namespace Content.Server.DeviceLinking.Components -{ - [RegisterComponent] - public sealed partial class TwoWayLeverComponent : Component - { - [DataField("state")] - public TwoWayLeverState State; - - [DataField("nextSignalLeft")] - public bool NextSignalLeft; - - [DataField("leftPort", customTypeSerializer: typeof(PrototypeIdSerializer))] - public string LeftPort = "Left"; - - [DataField("rightPort", customTypeSerializer: typeof(PrototypeIdSerializer))] - public string RightPort = "Right"; - - [DataField("middlePort", customTypeSerializer: typeof(PrototypeIdSerializer))] - public string MiddlePort = "Middle"; - } -} diff --git a/Content.Server/DeviceLinking/Events/SignalReceivedEvent.cs b/Content.Server/DeviceLinking/Events/SignalReceivedEvent.cs index c1928575feb..c8c611103d9 100644 --- a/Content.Server/DeviceLinking/Events/SignalReceivedEvent.cs +++ b/Content.Server/DeviceLinking/Events/SignalReceivedEvent.cs @@ -1,4 +1,5 @@ using Content.Server.DeviceNetwork; +using Content.Shared.DeviceNetwork; namespace Content.Server.DeviceLinking.Events; diff --git a/Content.Server/DeviceLinking/Systems/DeviceLinkSystem.cs b/Content.Server/DeviceLinking/Systems/DeviceLinkSystem.cs index 47f632843d3..e54e21316f2 100644 --- a/Content.Server/DeviceLinking/Systems/DeviceLinkSystem.cs +++ b/Content.Server/DeviceLinking/Systems/DeviceLinkSystem.cs @@ -4,6 +4,7 @@ using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Systems; using Content.Shared.DeviceLinking; +using Content.Shared.DeviceNetwork; namespace Content.Server.DeviceLinking.Systems; @@ -35,15 +36,7 @@ public override void Update(float frameTime) } #region Sending & Receiving - /// - /// Sends a network payload directed at the sink entity. - /// Just raises a without data if the source or the sink doesn't have a - /// - /// The source uid that invokes the port - /// The port to invoke - /// Optional data to send along - /// - public void InvokePort(EntityUid uid, string port, NetworkPayload? data = null, DeviceLinkSourceComponent? sourceComponent = null) + public override void InvokePort(EntityUid uid, string port, NetworkPayload? data = null, DeviceLinkSourceComponent? sourceComponent = null) { if (!Resolve(uid, ref sourceComponent) || !sourceComponent.Outputs.TryGetValue(port, out var sinks)) return; diff --git a/Content.Server/DeviceLinking/Systems/DoorSignalControlSystem.cs b/Content.Server/DeviceLinking/Systems/DoorSignalControlSystem.cs index 90623dbae37..40feda32f2b 100644 --- a/Content.Server/DeviceLinking/Systems/DoorSignalControlSystem.cs +++ b/Content.Server/DeviceLinking/Systems/DoorSignalControlSystem.cs @@ -1,6 +1,7 @@ using Content.Server.DeviceLinking.Components; using Content.Server.DeviceNetwork; using Content.Server.Doors.Systems; +using Content.Shared.DeviceNetwork; using Content.Shared.Doors.Components; using Content.Shared.Doors; using JetBrains.Annotations; diff --git a/Content.Server/DeviceNetwork/NetworkPayload.cs b/Content.Server/DeviceNetwork/NetworkPayload.cs deleted file mode 100644 index eefbaa6eea5..00000000000 --- a/Content.Server/DeviceNetwork/NetworkPayload.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Robust.Shared.Utility; -using System.Diagnostics.CodeAnalysis; - -namespace Content.Server.DeviceNetwork -{ - public sealed class NetworkPayload : Dictionary - { - /// - /// Tries to get a value from the payload and checks if that value is of type T. - /// - /// The type that should be casted to - /// Whether the value was present in the payload and of the required type - public bool TryGetValue(string key, [NotNullWhen(true)] out T? value) - { - if (this.TryCastValue(key, out T? result)) - { - value = result; - return true; - } - - value = default; - return false; - } - } - -} diff --git a/Content.Server/DeviceNetwork/Systems/Devices/ApcNetSwitchSystem.cs b/Content.Server/DeviceNetwork/Systems/Devices/ApcNetSwitchSystem.cs index 11dc628df1c..9a4a81a4c0a 100644 --- a/Content.Server/DeviceNetwork/Systems/Devices/ApcNetSwitchSystem.cs +++ b/Content.Server/DeviceNetwork/Systems/Devices/ApcNetSwitchSystem.cs @@ -1,5 +1,6 @@ using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Components.Devices; +using Content.Shared.DeviceNetwork; using Content.Shared.Interaction; namespace Content.Server.DeviceNetwork.Systems.Devices diff --git a/Content.Server/Disposal/Mailing/MailingUnitSystem.cs b/Content.Server/Disposal/Mailing/MailingUnitSystem.cs index 1a819ab0fb1..001abad3dcd 100644 --- a/Content.Server/Disposal/Mailing/MailingUnitSystem.cs +++ b/Content.Server/Disposal/Mailing/MailingUnitSystem.cs @@ -4,6 +4,7 @@ using Content.Server.DeviceNetwork.Systems; using Content.Server.Disposal.Unit.EntitySystems; using Content.Server.Power.Components; +using Content.Shared.DeviceNetwork; using Content.Shared.Disposal; using Content.Shared.Interaction; using Robust.Server.GameObjects; diff --git a/Content.Server/Fax/FaxSystem.cs b/Content.Server/Fax/FaxSystem.cs index f25fb625425..5fee750c1d9 100644 --- a/Content.Server/Fax/FaxSystem.cs +++ b/Content.Server/Fax/FaxSystem.cs @@ -12,6 +12,7 @@ using Content.Shared.Administration.Logs; using Content.Shared.Containers.ItemSlots; using Content.Shared.Database; +using Content.Shared.DeviceNetwork; using Content.Shared.Emag.Components; using Content.Shared.Emag.Systems; using Content.Shared.Fax; diff --git a/Content.Server/Medical/CrewMonitoring/CrewMonitoringServerSystem.cs b/Content.Server/Medical/CrewMonitoring/CrewMonitoringServerSystem.cs index 785ef60af90..bff7f1565a1 100644 --- a/Content.Server/Medical/CrewMonitoring/CrewMonitoringServerSystem.cs +++ b/Content.Server/Medical/CrewMonitoring/CrewMonitoringServerSystem.cs @@ -4,6 +4,7 @@ using Content.Server.Medical.SuitSensors; using Content.Server.Power.Components; using Content.Server.Station.Systems; +using Content.Shared.DeviceNetwork; using Content.Shared.Medical.SuitSensor; using Robust.Shared.Timing; diff --git a/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs b/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs index aa6dca718d5..38a7b0a4517 100644 --- a/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs +++ b/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs @@ -8,6 +8,7 @@ using Content.Server.Popups; using Content.Server.Station.Systems; using Content.Shared.Damage; +using Content.Shared.DeviceNetwork; using Content.Shared.Emp; using Content.Shared.Examine; using Content.Shared.Inventory.Events; diff --git a/Content.Server/Power/Generation/Teg/TegSystem.cs b/Content.Server/Power/Generation/Teg/TegSystem.cs index 54f40a1bf34..3510a3da45d 100644 --- a/Content.Server/Power/Generation/Teg/TegSystem.cs +++ b/Content.Server/Power/Generation/Teg/TegSystem.cs @@ -7,6 +7,7 @@ using Content.Server.NodeContainer; using Content.Server.NodeContainer.Nodes; using Content.Server.Power.Components; +using Content.Shared.DeviceNetwork; using Content.Shared.Examine; using Content.Shared.Power.Generation.Teg; using Content.Shared.Rounding; diff --git a/Content.Server/RoundEnd/RoundEndSystem.cs b/Content.Server/RoundEnd/RoundEndSystem.cs index 10d4bea8b54..3a8331f3f7a 100644 --- a/Content.Server/RoundEnd/RoundEndSystem.cs +++ b/Content.Server/RoundEnd/RoundEndSystem.cs @@ -14,6 +14,7 @@ using Content.Server.Station.Components; using Content.Server.Station.Systems; using Content.Shared.Database; +using Content.Shared.DeviceNetwork; using Content.Shared.GameTicking; using Robust.Shared.Audio.Systems; using Robust.Shared.Configuration; diff --git a/Content.Server/SensorMonitoring/BatterySensorSystem.cs b/Content.Server/SensorMonitoring/BatterySensorSystem.cs index 20e990b14c3..eb2ab21075c 100644 --- a/Content.Server/SensorMonitoring/BatterySensorSystem.cs +++ b/Content.Server/SensorMonitoring/BatterySensorSystem.cs @@ -1,6 +1,7 @@ using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Systems; using Content.Server.Power.Components; +using Content.Shared.DeviceNetwork; namespace Content.Server.SensorMonitoring; diff --git a/Content.Server/SensorMonitoring/SensorMonitoringConsoleSystem.cs b/Content.Server/SensorMonitoring/SensorMonitoringConsoleSystem.cs index fdd340ba0ae..ddd7812394e 100644 --- a/Content.Server/SensorMonitoring/SensorMonitoringConsoleSystem.cs +++ b/Content.Server/SensorMonitoring/SensorMonitoringConsoleSystem.cs @@ -10,13 +10,13 @@ using Content.Shared.Atmos.Monitor; using Content.Shared.Atmos.Piping.Binary.Components; using Content.Shared.Atmos.Piping.Unary.Components; +using Content.Shared.DeviceNetwork; using Content.Shared.DeviceNetwork.Components; using Content.Shared.DeviceNetwork.Systems; using Content.Shared.SensorMonitoring; using Robust.Server.GameObjects; using Robust.Shared.Timing; using Robust.Shared.Utility; -using ConsoleUIState = Content.Shared.SensorMonitoring.SensorMonitoringConsoleBoundInterfaceState; namespace Content.Server.SensorMonitoring; diff --git a/Content.Server/Shuttles/Systems/ArrivalsSystem.cs b/Content.Server/Shuttles/Systems/ArrivalsSystem.cs index 6503e4bf517..08f3481cd72 100644 --- a/Content.Server/Shuttles/Systems/ArrivalsSystem.cs +++ b/Content.Server/Shuttles/Systems/ArrivalsSystem.cs @@ -16,6 +16,7 @@ using Content.Server.Station.Systems; using Content.Shared.Administration; using Content.Shared.CCVar; +using Content.Shared.DeviceNetwork; using Content.Shared.Mobs.Components; using Content.Shared.Movement.Components; using Content.Shared.Parallax.Biomes; diff --git a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs index 37c70c4e486..b589a526403 100644 --- a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs +++ b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.Console.cs @@ -8,6 +8,7 @@ using Content.Shared.Access; using Content.Shared.CCVar; using Content.Shared.Database; +using Content.Shared.DeviceNetwork; using Content.Shared.Popups; using Content.Shared.Shuttles.BUIStates; using Content.Shared.Shuttles.Events; diff --git a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs index d984c727376..d9ba2de3e59 100644 --- a/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs +++ b/Content.Server/Shuttles/Systems/EmergencyShuttleSystem.cs @@ -5,7 +5,6 @@ using Content.Server.Administration.Managers; using Content.Server.Chat.Systems; using Content.Server.Communications; -using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Systems; using Content.Server.GameTicking.Events; @@ -19,6 +18,7 @@ using Content.Shared.Access.Systems; using Content.Shared.CCVar; using Content.Shared.Database; +using Content.Shared.DeviceNetwork; using Content.Shared.Shuttles.Components; using Content.Shared.Shuttles.Events; using Content.Shared.Tag; diff --git a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraMonitorSystem.cs b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraMonitorSystem.cs index cbc2f6d31ec..f258fbe89cf 100644 --- a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraMonitorSystem.cs +++ b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraMonitorSystem.cs @@ -2,6 +2,7 @@ using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Systems; using Content.Server.Power.Components; +using Content.Shared.DeviceNetwork; using Content.Shared.UserInterface; using Content.Shared.SurveillanceCamera; using Robust.Server.GameObjects; diff --git a/Content.Shared/DeviceLinking/Components/TwoWayLeverComponent.cs b/Content.Shared/DeviceLinking/Components/TwoWayLeverComponent.cs new file mode 100644 index 00000000000..6dfc25582a3 --- /dev/null +++ b/Content.Shared/DeviceLinking/Components/TwoWayLeverComponent.cs @@ -0,0 +1,26 @@ +using Robust.Shared.GameStates; +using Robust.Shared.Prototypes; + +namespace Content.Shared.DeviceLinking.Components; + +/// +/// Simple ternary state for device linking. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class TwoWayLeverComponent : Component +{ + [DataField, AutoNetworkedField] + public TwoWayLeverState State; + + [DataField, AutoNetworkedField] + public bool NextSignalLeft; + + [DataField] + public ProtoId LeftPort = "Left"; + + [DataField] + public ProtoId RightPort = "Right"; + + [DataField] + public ProtoId MiddlePort = "Middle"; +} diff --git a/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs b/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs index 02c0f608532..9610e2e6065 100644 --- a/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs +++ b/Content.Shared/DeviceLinking/SharedDeviceLinkSystem.cs @@ -1,6 +1,7 @@ using Content.Shared.Administration.Logs; using Content.Shared.Database; using Content.Shared.DeviceLinking.Events; +using Content.Shared.DeviceNetwork; using Content.Shared.Popups; using Robust.Shared.Prototypes; using Robust.Shared.Utility; @@ -148,6 +149,9 @@ private void OnSinkRemoved(EntityUid sinkUid, DeviceLinkSinkComponent sinkCompon /// public void EnsureSourcePorts(EntityUid uid, params string[] ports) { + if (ports.Length == 0) + return; + var comp = EnsureComp(uid); comp.Ports ??= new HashSet(); @@ -163,6 +167,9 @@ public void EnsureSourcePorts(EntityUid uid, params string[] ports) /// public void EnsureSinkPorts(EntityUid uid, params string[] ports) { + if (ports.Length == 0) + return; + var comp = EnsureComp(uid); comp.Ports ??= new HashSet(); @@ -550,4 +557,20 @@ private void CreateLinkPopup(EntityUid? userId, EntityUid sourceUid, string sour ("machine2", sinkUid), ("port2", PortName(sink))), userId.Value, PopupType.Medium); } #endregion + + #region Sending & Receiving + /// + /// Sends a network payload directed at the sink entity. + /// Just raises a without data if the source or the sink doesn't have a + /// + /// The source uid that invokes the port + /// The port to invoke + /// Optional data to send along + /// + public virtual void InvokePort(EntityUid uid, string port, NetworkPayload? data = null, + DeviceLinkSourceComponent? sourceComponent = null) + { + // NOOP on client for the moment. + } + #endregion } diff --git a/Content.Server/DeviceLinking/Systems/TwoWayLeverSystem.cs b/Content.Shared/DeviceLinking/Systems/TwoWayLeverSystem.cs similarity index 95% rename from Content.Server/DeviceLinking/Systems/TwoWayLeverSystem.cs rename to Content.Shared/DeviceLinking/Systems/TwoWayLeverSystem.cs index 7d351dcac56..c8783b05fc7 100644 --- a/Content.Server/DeviceLinking/Systems/TwoWayLeverSystem.cs +++ b/Content.Shared/DeviceLinking/Systems/TwoWayLeverSystem.cs @@ -1,14 +1,13 @@ -using Content.Server.DeviceLinking.Components; -using Content.Shared.DeviceLinking; +using Content.Shared.DeviceLinking.Components; using Content.Shared.Interaction; using Content.Shared.Verbs; using Robust.Shared.Utility; -namespace Content.Server.DeviceLinking.Systems +namespace Content.Shared.DeviceLinking.Systems { public sealed class TwoWayLeverSystem : EntitySystem { - [Dependency] private readonly DeviceLinkSystem _signalSystem = default!; + [Dependency] private readonly SharedDeviceLinkSystem _signalSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; const string _leftToggleImage = "rotate_ccw.svg.192dpi.png"; @@ -111,6 +110,7 @@ private void StateChanged(EntityUid uid, TwoWayLeverComponent component) _ => throw new ArgumentOutOfRangeException() }; + Dirty(uid, component); _signalSystem.InvokePort(uid, port); } } diff --git a/Content.Shared/DeviceNetwork/NetworkPayload.cs b/Content.Shared/DeviceNetwork/NetworkPayload.cs new file mode 100644 index 00000000000..32393740213 --- /dev/null +++ b/Content.Shared/DeviceNetwork/NetworkPayload.cs @@ -0,0 +1,24 @@ +using System.Diagnostics.CodeAnalysis; +using Robust.Shared.Utility; + +namespace Content.Shared.DeviceNetwork; + +public sealed class NetworkPayload : Dictionary +{ + /// + /// Tries to get a value from the payload and checks if that value is of type T. + /// + /// The type that should be casted to + /// Whether the value was present in the payload and of the required type + public bool TryGetValue(string key, [NotNullWhen(true)] out T? value) + { + if (this.TryCastValue(key, out T? result)) + { + value = result; + return true; + } + + value = default; + return false; + } +}