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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user