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
This commit is contained in:
@@ -15,6 +15,7 @@ using Content.Shared.Atmos.Monitor;
|
||||
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;
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Server.DeviceNetwork.Components;
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using Content.Server.Power.Components;
|
||||
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;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ using Content.Shared.Atmos.Piping.Binary.Components;
|
||||
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;
|
||||
|
||||
@@ -17,6 +17,7 @@ using Content.Server.Power.EntitySystems;
|
||||
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
|
||||
|
||||
@@ -16,6 +16,7 @@ using Content.Shared.Atmos.Monitor;
|
||||
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;
|
||||
|
||||
@@ -15,6 +15,7 @@ using Content.Shared.Atmos.Piping.Unary.Visuals;
|
||||
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;
|
||||
|
||||
@@ -19,6 +19,7 @@ using Content.Shared.CCVar;
|
||||
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;
|
||||
|
||||
@@ -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<SourcePortPrototype>))]
|
||||
public string LeftPort = "Left";
|
||||
|
||||
[DataField("rightPort", customTypeSerializer: typeof(PrototypeIdSerializer<SourcePortPrototype>))]
|
||||
public string RightPort = "Right";
|
||||
|
||||
[DataField("middlePort", customTypeSerializer: typeof(PrototypeIdSerializer<SourcePortPrototype>))]
|
||||
public string MiddlePort = "Middle";
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Server.DeviceNetwork;
|
||||
using Content.Shared.DeviceNetwork;
|
||||
|
||||
namespace Content.Server.DeviceLinking.Events;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Server.DeviceNetwork;
|
||||
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 sealed class DeviceLinkSystem : SharedDeviceLinkSystem
|
||||
}
|
||||
|
||||
#region Sending & Receiving
|
||||
/// <summary>
|
||||
/// Sends a network payload directed at the sink entity.
|
||||
/// Just raises a <see cref="SignalReceivedEvent"/> without data if the source or the sink doesn't have a <see cref="DeviceNetworkComponent"/>
|
||||
/// </summary>
|
||||
/// <param name="uid">The source uid that invokes the port</param>
|
||||
/// <param name="port">The port to invoke</param>
|
||||
/// <param name="data">Optional data to send along</param>
|
||||
/// <param name="sourceComponent"></param>
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
using Content.Server.DeviceLinking.Components;
|
||||
using Content.Shared.DeviceLinking;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.DeviceLinking.Systems
|
||||
{
|
||||
public sealed class TwoWayLeverSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly DeviceLinkSystem _signalSystem = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
|
||||
const string _leftToggleImage = "rotate_ccw.svg.192dpi.png";
|
||||
const string _rightToggleImage = "rotate_cw.svg.192dpi.png";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<TwoWayLeverComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<TwoWayLeverComponent, ActivateInWorldEvent>(OnActivated);
|
||||
SubscribeLocalEvent<TwoWayLeverComponent, GetVerbsEvent<InteractionVerb>>(OnGetInteractionVerbs);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, TwoWayLeverComponent component, ComponentInit args)
|
||||
{
|
||||
_signalSystem.EnsureSourcePorts(uid, component.LeftPort, component.RightPort, component.MiddlePort);
|
||||
}
|
||||
|
||||
private void OnActivated(EntityUid uid, TwoWayLeverComponent component, ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
component.State = component.State switch
|
||||
{
|
||||
TwoWayLeverState.Middle => component.NextSignalLeft ? TwoWayLeverState.Left : TwoWayLeverState.Right,
|
||||
TwoWayLeverState.Right => TwoWayLeverState.Middle,
|
||||
TwoWayLeverState.Left => TwoWayLeverState.Middle,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
StateChanged(uid, component);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnGetInteractionVerbs(EntityUid uid, TwoWayLeverComponent component, GetVerbsEvent<InteractionVerb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || (args.Hands == null))
|
||||
return;
|
||||
|
||||
var disabled = component.State == TwoWayLeverState.Left;
|
||||
InteractionVerb verbLeft = new()
|
||||
{
|
||||
Act = () =>
|
||||
{
|
||||
component.State = component.State switch
|
||||
{
|
||||
TwoWayLeverState.Middle => TwoWayLeverState.Left,
|
||||
TwoWayLeverState.Right => TwoWayLeverState.Middle,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
StateChanged(uid, component);
|
||||
},
|
||||
Category = VerbCategory.Lever,
|
||||
Message = disabled ? Loc.GetString("two-way-lever-cant") : null,
|
||||
Disabled = disabled,
|
||||
Icon = new SpriteSpecifier.Texture(new ($"/Textures/Interface/VerbIcons/{_leftToggleImage}")),
|
||||
Text = Loc.GetString("two-way-lever-left"),
|
||||
};
|
||||
|
||||
args.Verbs.Add(verbLeft);
|
||||
|
||||
disabled = component.State == TwoWayLeverState.Right;
|
||||
InteractionVerb verbRight = new()
|
||||
{
|
||||
Act = () =>
|
||||
{
|
||||
component.State = component.State switch
|
||||
{
|
||||
TwoWayLeverState.Left => TwoWayLeverState.Middle,
|
||||
TwoWayLeverState.Middle => TwoWayLeverState.Right,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
StateChanged(uid, component);
|
||||
},
|
||||
Category = VerbCategory.Lever,
|
||||
Message = disabled ? Loc.GetString("two-way-lever-cant") : null,
|
||||
Disabled = disabled,
|
||||
Icon = new SpriteSpecifier.Texture(new ($"/Textures/Interface/VerbIcons/{_rightToggleImage}")),
|
||||
Text = Loc.GetString("two-way-lever-right"),
|
||||
};
|
||||
|
||||
args.Verbs.Add(verbRight);
|
||||
}
|
||||
|
||||
private void StateChanged(EntityUid uid, TwoWayLeverComponent component)
|
||||
{
|
||||
if (component.State == TwoWayLeverState.Middle)
|
||||
component.NextSignalLeft = !component.NextSignalLeft;
|
||||
|
||||
if (TryComp(uid, out AppearanceComponent? appearance))
|
||||
_appearance.SetData(uid, TwoWayLeverVisuals.State, component.State, appearance);
|
||||
|
||||
var port = component.State switch
|
||||
{
|
||||
TwoWayLeverState.Left => component.LeftPort,
|
||||
TwoWayLeverState.Right => component.RightPort,
|
||||
TwoWayLeverState.Middle => component.MiddlePort,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
_signalSystem.InvokePort(uid, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using Robust.Shared.Utility;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Server.DeviceNetwork
|
||||
{
|
||||
public sealed class NetworkPayload : Dictionary<string, object?>
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to get a value from the payload and checks if that value is of type T.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type that should be casted to</typeparam>
|
||||
/// <returns>Whether the value was present in the payload and of the required type</returns>
|
||||
public bool TryGetValue<T>(string key, [NotNullWhen(true)] out T? value)
|
||||
{
|
||||
if (this.TryCastValue(key, out T? result))
|
||||
{
|
||||
value = result;
|
||||
return true;
|
||||
}
|
||||
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Server.DeviceNetwork.Components;
|
||||
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;
|
||||
|
||||
@@ -12,6 +12,7 @@ using Content.Shared.UserInterface;
|
||||
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;
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Server.DeviceNetwork.Systems;
|
||||
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;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using Content.Server.Medical.CrewMonitoring;
|
||||
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;
|
||||
|
||||
@@ -7,6 +7,7 @@ using Content.Server.DeviceNetwork.Systems;
|
||||
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;
|
||||
|
||||
@@ -14,6 +14,7 @@ using Content.Server.Shuttles.Systems;
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ using Content.Server.Power.Generation.Teg;
|
||||
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;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ using Content.Server.Station.Components;
|
||||
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;
|
||||
|
||||
@@ -8,6 +8,7 @@ using Content.Shared.UserInterface;
|
||||
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;
|
||||
|
||||
@@ -5,7 +5,6 @@ using Content.Server.Administration.Logs;
|
||||
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.Server.Station.Systems;
|
||||
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;
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Linq;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user