Add verbs to Two Way Levers, make some odds and ends recyclable. (#12660)

This commit is contained in:
Mervill
2022-11-19 08:05:44 -08:00
committed by GitHub
parent 6a59e1b376
commit ac828008a3
9 changed files with 81 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
using Content.Server.MachineLinking.Components;
using Content.Shared.Interaction;
using Content.Shared.MachineLinking;
using Content.Shared.Verbs;
namespace Content.Server.MachineLinking.System
{
@@ -8,11 +9,15 @@ namespace Content.Server.MachineLinking.System
{
[Dependency] private readonly SignalLinkerSystem _signalSystem = 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)
@@ -33,6 +38,56 @@ namespace Content.Server.MachineLinking.System
_ => throw new ArgumentOutOfRangeException()
};
StateChanged(uid, component);
args.Handled = true;
}
private void OnGetInteractionVerbs(EntityUid uid, TwoWayLeverComponent component, GetVerbsEvent<InteractionVerb> args)
{
InteractionVerb verbLeft = new()
{
Act = () =>
{
component.State = component.State switch
{
TwoWayLeverState.Middle => TwoWayLeverState.Left,
TwoWayLeverState.Right => TwoWayLeverState.Middle,
_ => throw new ArgumentOutOfRangeException()
};
StateChanged(uid, component);
},
Message = Loc.GetString("two-way-lever-cant"),
Disabled = component.State == TwoWayLeverState.Left,
IconTexture = $"/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);
},
Message = Loc.GetString("two-way-lever-cant"),
Disabled = component.State == TwoWayLeverState.Right,
IconTexture = $"/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;
@@ -48,7 +103,6 @@ namespace Content.Server.MachineLinking.System
};
_signalSystem.InvokePort(uid, port);
args.Handled = true;
}
}
}