Device Linking and better linking ui (#13645)
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com> Co-authored-by: Visne <39844191+Visne@users.noreply.github.com> Co-authored-by: ElectroJr <leonsfriedrich@gmail.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
namespace Content.Server.MachineLinking.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This is used for automatic linkage with buttons and other transmitters.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class AutoLinkReceiverComponent : Component
|
||||
{
|
||||
[DataField("channel", required: true, readOnly: true)]
|
||||
public string AutoLinkChannel = default!;
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace Content.Server.MachineLinking.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This is used for automatic linkage with various receivers, like shutters.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class AutoLinkTransmitterComponent : Component
|
||||
{
|
||||
[DataField("channel", required: true, readOnly: true)]
|
||||
public string AutoLinkChannel = default!;
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using Content.Shared.MachineLinking;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.MachineLinking.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class DoorSignalControlComponent : Component
|
||||
{
|
||||
[DataField("openPort", customTypeSerializer: typeof(PrototypeIdSerializer<ReceiverPortPrototype>))]
|
||||
public string OpenPort = "Open";
|
||||
|
||||
[DataField("closePort", customTypeSerializer: typeof(PrototypeIdSerializer<ReceiverPortPrototype>))]
|
||||
public string ClosePort = "Close";
|
||||
|
||||
[DataField("togglePort", customTypeSerializer: typeof(PrototypeIdSerializer<ReceiverPortPrototype>))]
|
||||
public string TogglePort = "Toggle";
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using Content.Shared.MachineLinking;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.MachineLinking.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple switch that will fire ports when toggled on or off. A button is jsut a switch that signals on the
|
||||
/// same port regardless of its state.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class SignalSwitchComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The port that gets signaled when the switch turns on.
|
||||
/// </summary>
|
||||
[DataField("onPort", customTypeSerializer: typeof(PrototypeIdSerializer<TransmitterPortPrototype>))]
|
||||
public string OnPort = "On";
|
||||
|
||||
/// <summary>
|
||||
/// The port that gets signaled when the switch turns off.
|
||||
/// </summary>
|
||||
[DataField("offPort", customTypeSerializer: typeof(PrototypeIdSerializer<TransmitterPortPrototype>))]
|
||||
public string OffPort = "Off";
|
||||
|
||||
[DataField("state")]
|
||||
public bool State;
|
||||
|
||||
[DataField("clickSound")]
|
||||
public SoundSpecifier ClickSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/lightswitch.ogg");
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,13 @@ using Content.Server.MachineLinking.System;
|
||||
namespace Content.Server.MachineLinking.Components
|
||||
{
|
||||
[DataDefinition]
|
||||
public struct PortIdentifier
|
||||
public readonly struct PortIdentifier
|
||||
{
|
||||
[DataField("uid")]
|
||||
public EntityUid Uid;
|
||||
public readonly EntityUid Uid;
|
||||
|
||||
[DataField("port")]
|
||||
public string Port;
|
||||
public readonly string Port;
|
||||
|
||||
public PortIdentifier(EntityUid uid, string port)
|
||||
{
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using Content.Shared.MachineLinking;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.MachineLinking.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends out a signal to machine linked objects.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class SignallerComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The port that gets signaled when the switch turns on.
|
||||
/// </summary>
|
||||
[DataField("port", customTypeSerializer: typeof(PrototypeIdSerializer<TransmitterPortPrototype>))]
|
||||
public string Port = "Pressed";
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using Content.Shared.MachineLinking;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.MachineLinking.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class TwoWayLeverComponent : Component
|
||||
{
|
||||
[DataField("state")]
|
||||
public TwoWayLeverState State;
|
||||
|
||||
[DataField("nextSignalLeft")]
|
||||
public bool NextSignalLeft;
|
||||
|
||||
[DataField("leftPort", customTypeSerializer: typeof(PrototypeIdSerializer<TransmitterPortPrototype>))]
|
||||
public string LeftPort = "Left";
|
||||
|
||||
[DataField("rightPort", customTypeSerializer: typeof(PrototypeIdSerializer<TransmitterPortPrototype>))]
|
||||
public string RightPort = "Right";
|
||||
|
||||
[DataField("middlePort", customTypeSerializer: typeof(PrototypeIdSerializer<TransmitterPortPrototype>))]
|
||||
public string MiddlePort = "Middle";
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace Content.Server.MachineLinking.Events
|
||||
{
|
||||
public sealed class PortDisconnectedEvent : EntityEventArgs
|
||||
{
|
||||
public readonly string Port;
|
||||
|
||||
public PortDisconnectedEvent(string port)
|
||||
{
|
||||
Port = port;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
namespace Content.Server.MachineLinking.Events
|
||||
{
|
||||
public sealed class SignalReceivedEvent : EntityEventArgs
|
||||
{
|
||||
public readonly string Port;
|
||||
public readonly EntityUid? Trigger;
|
||||
|
||||
public SignalReceivedEvent(string port, EntityUid? trigger)
|
||||
{
|
||||
Port = port;
|
||||
Trigger = trigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
using Content.Server.MachineLinking.Components;
|
||||
|
||||
namespace Content.Server.MachineLinking.System;
|
||||
|
||||
/// <summary>
|
||||
/// This handles automatically linking autolinked entities at round-start.
|
||||
/// </summary>
|
||||
public sealed class AutoLinkSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SignalLinkerSystem _signalLinkerSystem = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<AutoLinkTransmitterComponent, MapInitEvent>(OnAutoLinkMapInit);
|
||||
}
|
||||
|
||||
private void OnAutoLinkMapInit(EntityUid uid, AutoLinkTransmitterComponent component, MapInitEvent args)
|
||||
{
|
||||
var xform = Transform(uid);
|
||||
|
||||
foreach (var receiver in EntityQuery<AutoLinkReceiverComponent>())
|
||||
{
|
||||
if (receiver.AutoLinkChannel != component.AutoLinkChannel)
|
||||
continue; // Not ours.
|
||||
|
||||
var rxXform = Transform(receiver.Owner);
|
||||
|
||||
if (rxXform.GridUid != xform.GridUid)
|
||||
continue;
|
||||
|
||||
_signalLinkerSystem.TryLinkDefaults(receiver.Owner, uid, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
using Content.Server.MachineLinking.Components;
|
||||
using Content.Server.MachineLinking.Events;
|
||||
using Content.Server.Doors.Systems;
|
||||
using Content.Shared.Doors.Components;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Content.Server.MachineLinking.System
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class DoorSignalControlSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly DoorSystem _doorSystem = default!;
|
||||
[Dependency] private readonly SignalLinkerSystem _signalSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<DoorSignalControlComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<DoorSignalControlComponent, SignalReceivedEvent>(OnSignalReceived);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, DoorSignalControlComponent component, ComponentInit args)
|
||||
{
|
||||
_signalSystem.EnsureReceiverPorts(uid, component.OpenPort, component.ClosePort, component.TogglePort);
|
||||
}
|
||||
|
||||
private void OnSignalReceived(EntityUid uid, DoorSignalControlComponent component, SignalReceivedEvent args)
|
||||
{
|
||||
if (!TryComp(uid, out DoorComponent? door))
|
||||
return;
|
||||
|
||||
if (args.Port == component.OpenPort)
|
||||
{
|
||||
if (door.State != DoorState.Open)
|
||||
_doorSystem.TryOpen(uid, door);
|
||||
}
|
||||
else if (args.Port == component.ClosePort)
|
||||
{
|
||||
if (door.State != DoorState.Closed)
|
||||
_doorSystem.TryClose(uid, door);
|
||||
}
|
||||
else if (args.Port == component.TogglePort)
|
||||
{
|
||||
_doorSystem.TryToggleDoor(uid, door);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,16 @@
|
||||
using System.Linq;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.DeviceLinking.Events;
|
||||
using Content.Server.MachineLinking.Components;
|
||||
using Content.Server.MachineLinking.Events;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Tools;
|
||||
using Content.Shared.DeviceLinking.Events;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.MachineLinking;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Shared.MachineLinking.Events;
|
||||
using Content.Server.Database;
|
||||
|
||||
namespace Content.Server.MachineLinking.System
|
||||
{
|
||||
@@ -140,7 +138,10 @@ namespace Content.Server.MachineLinking.System
|
||||
return;
|
||||
|
||||
foreach (var receiver in receivers)
|
||||
RaiseLocalEvent(receiver.Uid, new SignalReceivedEvent(receiver.Port, uid), false);
|
||||
{
|
||||
var eventArgs = new SignalReceivedEvent(receiver.Port, uid);
|
||||
RaiseLocalEvent(receiver.Uid, ref eventArgs);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTransmitterStartup(EntityUid uid, SignalTransmitterComponent transmitter, ComponentStartup args)
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
using Content.Server.MachineLinking.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.MachineLinking.System
|
||||
{
|
||||
public sealed class SignalSwitchSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SignalLinkerSystem _signalSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SignalSwitchComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<SignalSwitchComponent, ActivateInWorldEvent>(OnActivated);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, SignalSwitchComponent component, ComponentInit args)
|
||||
{
|
||||
_signalSystem.EnsureTransmitterPorts(uid, component.OnPort, component.OffPort);
|
||||
}
|
||||
|
||||
private void OnActivated(EntityUid uid, SignalSwitchComponent component, ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
component.State = !component.State;
|
||||
_signalSystem.InvokePort(uid, component.State ? component.OnPort : component.OffPort);
|
||||
SoundSystem.Play(component.ClickSound.GetSound(), Filter.Pvs(component.Owner), component.Owner,
|
||||
AudioHelpers.WithVariation(0.125f).WithVolume(8f));
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
using Content.Server.Explosion.EntitySystems;
|
||||
using Content.Server.MachineLinking.Components;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Timing;
|
||||
|
||||
namespace Content.Server.MachineLinking.System;
|
||||
|
||||
public sealed class SignallerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SignalLinkerSystem _signal = default!;
|
||||
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SignallerComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<SignallerComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<SignallerComponent, TriggerEvent>(OnTrigger);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, SignallerComponent component, ComponentInit args)
|
||||
{
|
||||
_signal.EnsureTransmitterPorts(uid, component.Port);
|
||||
}
|
||||
|
||||
private void OnUseInHand(EntityUid uid, SignallerComponent component, UseInHandEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
_signal.InvokePort(uid, component.Port);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnTrigger(EntityUid uid, SignallerComponent component, TriggerEvent args)
|
||||
{
|
||||
// if on cooldown, do nothing
|
||||
var hasUseDelay = TryComp<UseDelayComponent>(uid, out var useDelay);
|
||||
if (hasUseDelay && _useDelay.ActiveDelay(uid, useDelay))
|
||||
return;
|
||||
|
||||
// set cooldown to prevent clocks
|
||||
if (hasUseDelay)
|
||||
_useDelay.BeginDelay(uid, useDelay);
|
||||
|
||||
_signal.InvokePort(uid, component.Port);
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
using Content.Server.MachineLinking.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.MachineLinking;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.MachineLinking.System
|
||||
{
|
||||
public sealed class TwoWayLeverSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SignalLinkerSystem _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.EnsureTransmitterPorts(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;
|
||||
|
||||
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 = Loc.GetString("two-way-lever-cant"),
|
||||
Disabled = component.State == TwoWayLeverState.Left,
|
||||
Icon = new SpriteSpecifier.Texture(new ($"/Textures/Interface/VerbIcons/{_leftToggleImage}")),
|
||||
Text = Loc.GetString("two-way-lever-left"),
|
||||
};
|
||||
|
||||
args.Verbs.Add(verbLeft);
|
||||
|
||||
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 = Loc.GetString("two-way-lever-cant"),
|
||||
Disabled = component.State == TwoWayLeverState.Right,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user