makes conveyors to use machine linking & refactors machine linking a bit (#2464)
* makes conveyors to use machine linking & refactors machine linking a bit * nullable errors * temp commit, starting work on construction * working recipies & graphs * fixes crash * makes items gravitate towards the center when on a conveyor * makes conveyors take bool signal too * ignores components clientside * default arm entitymanager maxtransmitters unsubscribe methods * twowayLEVER * _ * componentreference struct * yaml run leverDefinitelyNotCopiedFromGirderNoNoNo dies today :( * nullable * no divide by 0 * making sloth happy * space gone - happy? * final fix * yes * adds item to lathe * conveyor item -> conveyor assembly * technology * reviews ADRESSED * Update Content.Shared/GameObjects/Verbs/VerbUtility.cs Co-authored-by: Paul <ritter.paul1+git@googlemail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -30,11 +30,15 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
return;
|
||||
}
|
||||
|
||||
if (transmitter.TransmitSignal(user, new ToggleSignal()))
|
||||
if (transmitter.TransmitSignal(new ToggleSignal()))
|
||||
{
|
||||
// Since the button doesn't have an animation, I'm going to use a popup message
|
||||
Owner.PopupMessage(user, Loc.GetString("Click."));
|
||||
}
|
||||
else
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("No receivers connected."));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,8 +7,11 @@ using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Serialization;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
{
|
||||
@@ -19,6 +22,8 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
|
||||
private List<SignalTransmitterComponent> _transmitters;
|
||||
|
||||
private int? _maxTransmitters = default;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -26,6 +31,11 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
_transmitters = new List<SignalTransmitterComponent>();
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(this, x=> x._maxTransmitters, "maxTransmitters", null);
|
||||
}
|
||||
|
||||
public void DistributeSignal<T>(T state)
|
||||
{
|
||||
foreach (var comp in Owner.GetAllComponents<ISignalReceiver<T>>())
|
||||
@@ -34,15 +44,18 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
}
|
||||
}
|
||||
|
||||
public void Subscribe(SignalTransmitterComponent transmitter)
|
||||
public bool Subscribe(SignalTransmitterComponent transmitter)
|
||||
{
|
||||
if (_transmitters.Contains(transmitter))
|
||||
{
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_transmitters.Count >= _maxTransmitters) return false;
|
||||
|
||||
transmitter.Subscribe(this);
|
||||
_transmitters.Add(transmitter);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Unsubscribe(SignalTransmitterComponent transmitter)
|
||||
@@ -51,6 +64,20 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
_transmitters.Remove(transmitter);
|
||||
}
|
||||
|
||||
public void UnsubscribeAll()
|
||||
{
|
||||
for (var i = _transmitters.Count-1; i >= 0; i--)
|
||||
{
|
||||
var transmitter = _transmitters[i];
|
||||
if (transmitter.Deleted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
transmitter.Unsubscribe(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes/Unsubscribes a transmitter to this component. Returns whether it was successful.
|
||||
/// </summary>
|
||||
@@ -78,7 +105,11 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
return false;
|
||||
}
|
||||
|
||||
Subscribe(transmitter);
|
||||
if (!Subscribe(transmitter))
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("Max Transmitters reached!"));
|
||||
return false;
|
||||
}
|
||||
Owner.PopupMessage(user, Loc.GetString("Linked!"));
|
||||
return true;
|
||||
}
|
||||
@@ -101,15 +132,8 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
foreach (var transmitter in _transmitters)
|
||||
{
|
||||
if (transmitter.Deleted)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
UnsubscribeAll();
|
||||
|
||||
transmitter.Unsubscribe(this);
|
||||
}
|
||||
_transmitters.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -52,7 +53,10 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
return;
|
||||
}
|
||||
|
||||
transmitter.TransmitSignal(user, _on);
|
||||
if (!transmitter.TransmitSignal(_on))
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("No receivers connected."));
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSprite()
|
||||
|
||||
@@ -10,6 +10,7 @@ using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
@@ -87,11 +88,10 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
}
|
||||
}
|
||||
|
||||
public bool TransmitSignal<T>(IEntity user, T signal)
|
||||
public bool TransmitSignal<T>(T signal)
|
||||
{
|
||||
if (_receivers.Count == 0)
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("No receivers connected."));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -150,8 +150,9 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
foreach (var receiver in _receivers)
|
||||
for (var i = _receivers.Count-1; i >= 0; i++)
|
||||
{
|
||||
var receiver = _receivers[i];
|
||||
if (receiver.Deleted)
|
||||
{
|
||||
continue;
|
||||
@@ -159,6 +160,7 @@ namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
|
||||
receiver.Unsubscribe(this);
|
||||
}
|
||||
|
||||
_receivers.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.MachineLinking.Signals;
|
||||
using Content.Shared.GameObjects.Components.Conveyor;
|
||||
using Content.Shared.GameObjects.Components.MachineLinking;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.MachineLinking
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public class SignalTwoWayLeverComponent : SignalTransmitterComponent, IInteractHand, IActivate
|
||||
{
|
||||
public override string Name => "TwoWayLever";
|
||||
|
||||
private TwoWayLeverSignal _state = TwoWayLeverSignal.Middle;
|
||||
|
||||
private bool _nextForward = true;
|
||||
|
||||
public TwoWayLeverSignal State
|
||||
{
|
||||
get => _state;
|
||||
private set
|
||||
{
|
||||
_state = value;
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(TwoWayLeverVisuals.State, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void NextState(IEntity user)
|
||||
{
|
||||
State = State switch
|
||||
{
|
||||
TwoWayLeverSignal.Left => TwoWayLeverSignal.Middle,
|
||||
TwoWayLeverSignal.Middle => _nextForward ? TwoWayLeverSignal.Right : TwoWayLeverSignal.Left,
|
||||
TwoWayLeverSignal.Right => TwoWayLeverSignal.Middle,
|
||||
_ => TwoWayLeverSignal.Middle
|
||||
};
|
||||
|
||||
if (State == TwoWayLeverSignal.Left || State == TwoWayLeverSignal.Right) _nextForward = !_nextForward;
|
||||
|
||||
if (!TransmitSignal(State))
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("No receivers connected."));
|
||||
}
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
NextState(eventArgs.User);
|
||||
return true;
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
NextState(eventArgs.User);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user