machine linking refactor to ecs (#4323)

* started work

* some more work, ui working (somewhat)

* stuff

* reorganization

* some more reorg

* conveyors

* conveyors working

* finalized (dis)connection
added linkattempt
added feedback text
work on conveyors

* removed command
add rangecheck

* fixed inrange check

* handling

* ui no longer kanser, ship it

* adresses reviews

* reformats file

* reformats file

Co-authored-by: Paul <ritter.paul1+git@googlemail.com>
This commit is contained in:
Paul Ritter
2021-08-27 17:46:02 +02:00
committed by GitHub
parent 4a68032ea1
commit e11a9b282a
47 changed files with 1059 additions and 633 deletions

View File

@@ -1,86 +1,12 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.MachineLinking;
using Content.Shared.Notification.Managers;
using Content.Shared.Verbs;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.MachineLinking.Components
{
[RegisterComponent]
public class SignalSwitchComponent : Component, IInteractHand, IActivate
public class SignalSwitchComponent : Component
{
public override string Name => "SignalSwitch";
[DataField("on")]
private bool _on;
protected override void Initialize()
{
base.Initialize();
UpdateSprite();
}
void IActivate.Activate(ActivateEventArgs eventArgs)
{
TransmitSignal(eventArgs.User);
}
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
TransmitSignal(eventArgs.User);
return true;
}
public void TransmitSignal(IEntity user)
{
_on = !_on;
UpdateSprite();
if (!Owner.TryGetComponent<SignalTransmitterComponent>(out var transmitter))
{
return;
}
if (!transmitter.TransmitSignal(_on))
{
Owner.PopupMessage(user, Loc.GetString("signal-switch-component-transmit-no-receivers-connected"));
}
}
private void UpdateSprite()
{
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(SignalSwitchVisuals.On, _on);
}
}
[Verb]
private sealed class ToggleSwitchVerb : Verb<SignalSwitchComponent>
{
protected override void Activate(IEntity user, SignalSwitchComponent component)
{
component.TransmitSignal(user);
}
protected override void GetData(IEntity user, SignalSwitchComponent component, VerbData data)
{
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("toggle-switch-verb-get-data-text");
data.Visibility = VerbVisibility.Visible;
}
}
public bool State;
}
}