Add input port of the network system in timer (#20026)
* Add port link sink in timer * Update SignalTimerSystem.cs Moving the trigger so that everything works correctly and does not conflict. Correction of remarks. * Update SignalTimerSystem.cs * a * review --------- Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using Content.Shared.DeviceLinking;
|
using Content.Shared.DeviceLinking;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||||
|
|
||||||
namespace Content.Server.DeviceLinking.Components;
|
namespace Content.Server.DeviceLinking.Components;
|
||||||
@@ -7,36 +8,40 @@ namespace Content.Server.DeviceLinking.Components;
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed partial class SignalTimerComponent : Component
|
public sealed partial class SignalTimerComponent : Component
|
||||||
{
|
{
|
||||||
[DataField("delay"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public double Delay = 5;
|
public double Delay = 5;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This shows the Label: text box in the UI.
|
/// This shows the Label: text box in the UI.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("canEditLabel"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public bool CanEditLabel = true;
|
public bool CanEditLabel = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The label, used for TextScreen visuals currently.
|
/// The label, used for TextScreen visuals currently.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("label"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public string Label = string.Empty;
|
public string Label = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The port that gets signaled when the timer triggers.
|
/// The port that gets signaled when the timer triggers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("triggerPort", customTypeSerializer: typeof(PrototypeIdSerializer<SourcePortPrototype>)), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public string TriggerPort = "Timer";
|
public ProtoId<SourcePortPrototype> TriggerPort = "Timer";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The port that gets signaled when the timer starts.
|
/// The port that gets signaled when the timer starts.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("startPort", customTypeSerializer: typeof(PrototypeIdSerializer<SourcePortPrototype>)), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public string StartPort = "Start";
|
public ProtoId<SourcePortPrototype> StartPort = "Start";
|
||||||
|
|
||||||
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public ProtoId<SinkPortPrototype> Trigger = "Trigger";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If not null, this timer will play this sound when done.
|
/// If not null, this timer will play this sound when done.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("doneSound"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||||
public SoundSpecifier? DoneSound;
|
public SoundSpecifier? DoneSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Server.DeviceLinking.Components;
|
using Content.Server.DeviceLinking.Components;
|
||||||
|
using Content.Server.DeviceLinking.Events;
|
||||||
using Content.Server.UserInterface;
|
using Content.Server.UserInterface;
|
||||||
using Content.Shared.Access.Systems;
|
using Content.Shared.Access.Systems;
|
||||||
using Content.Shared.MachineLinking;
|
using Content.Shared.MachineLinking;
|
||||||
@@ -19,6 +20,11 @@ public sealed class SignalTimerSystem : EntitySystem
|
|||||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||||
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
|
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Per-tick timer cache.
|
||||||
|
/// </summary>
|
||||||
|
private List<Entity<SignalTimerComponent>> _timers = new();
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
@@ -29,11 +35,13 @@ public sealed class SignalTimerSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<SignalTimerComponent, SignalTimerTextChangedMessage>(OnTextChangedMessage);
|
SubscribeLocalEvent<SignalTimerComponent, SignalTimerTextChangedMessage>(OnTextChangedMessage);
|
||||||
SubscribeLocalEvent<SignalTimerComponent, SignalTimerDelayChangedMessage>(OnDelayChangedMessage);
|
SubscribeLocalEvent<SignalTimerComponent, SignalTimerDelayChangedMessage>(OnDelayChangedMessage);
|
||||||
SubscribeLocalEvent<SignalTimerComponent, SignalTimerStartMessage>(OnTimerStartMessage);
|
SubscribeLocalEvent<SignalTimerComponent, SignalTimerStartMessage>(OnTimerStartMessage);
|
||||||
|
SubscribeLocalEvent<SignalTimerComponent, SignalReceivedEvent>(OnSignalReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnInit(EntityUid uid, SignalTimerComponent component, ComponentInit args)
|
private void OnInit(EntityUid uid, SignalTimerComponent component, ComponentInit args)
|
||||||
{
|
{
|
||||||
_appearanceSystem.SetData(uid, TextScreenVisuals.ScreenText, component.Label);
|
_appearanceSystem.SetData(uid, TextScreenVisuals.ScreenText, component.Label);
|
||||||
|
_signalSystem.EnsureSinkPorts(uid, component.Trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAfterActivatableUIOpen(EntityUid uid, SignalTimerComponent component, AfterActivatableUIOpenEvent args)
|
private void OnAfterActivatableUIOpen(EntityUid uid, SignalTimerComponent component, AfterActivatableUIOpenEvent args)
|
||||||
@@ -58,11 +66,13 @@ public sealed class SignalTimerSystem : EntitySystem
|
|||||||
public void Trigger(EntityUid uid, SignalTimerComponent signalTimer)
|
public void Trigger(EntityUid uid, SignalTimerComponent signalTimer)
|
||||||
{
|
{
|
||||||
RemComp<ActiveSignalTimerComponent>(uid);
|
RemComp<ActiveSignalTimerComponent>(uid);
|
||||||
|
|
||||||
if (TryComp<AppearanceComponent>(uid, out var appearance))
|
if (TryComp<AppearanceComponent>(uid, out var appearance))
|
||||||
{
|
{
|
||||||
_appearanceSystem.SetData(uid, TextScreenVisuals.ScreenText, new string?[] { signalTimer.Label }, appearance);
|
_appearanceSystem.SetData(uid, TextScreenVisuals.ScreenText, new[] { signalTimer.Label }, appearance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_audio.PlayPvs(signalTimer.DoneSound, uid);
|
||||||
_signalSystem.InvokePort(uid, signalTimer.TriggerPort);
|
_signalSystem.InvokePort(uid, signalTimer.TriggerPort);
|
||||||
|
|
||||||
if (_ui.TryGetUi(uid, SignalTimerUiKey.Key, out var bui))
|
if (_ui.TryGetUi(uid, SignalTimerUiKey.Key, out var bui))
|
||||||
@@ -80,16 +90,29 @@ public sealed class SignalTimerSystem : EntitySystem
|
|||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
base.Update(frameTime);
|
base.Update(frameTime);
|
||||||
|
UpdateTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateTimer()
|
||||||
|
{
|
||||||
|
_timers.Clear();
|
||||||
|
|
||||||
var query = EntityQueryEnumerator<ActiveSignalTimerComponent, SignalTimerComponent>();
|
var query = EntityQueryEnumerator<ActiveSignalTimerComponent, SignalTimerComponent>();
|
||||||
while (query.MoveNext(out var uid, out var active, out var timer))
|
while (query.MoveNext(out var uid, out var active, out var timer))
|
||||||
{
|
{
|
||||||
if (active.TriggerTime > _gameTiming.CurTime)
|
if (active.TriggerTime > _gameTiming.CurTime)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Trigger(uid, timer);
|
_timers.Add((uid, timer));
|
||||||
|
}
|
||||||
|
|
||||||
if (timer.DoneSound != null)
|
foreach (var timer in _timers)
|
||||||
_audio.PlayPvs(timer.DoneSound, uid);
|
{
|
||||||
|
// Exploded or the likes.
|
||||||
|
if (!Exists(timer.Owner))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Trigger(timer.Owner, timer.Comp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +167,19 @@ public sealed class SignalTimerSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
if (!IsMessageValid(uid, args))
|
if (!IsMessageValid(uid, args))
|
||||||
return;
|
return;
|
||||||
|
OnStartTimer(uid, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSignalReceived(EntityUid uid, SignalTimerComponent component, ref SignalReceivedEvent args)
|
||||||
|
{
|
||||||
|
if (args.Port == component.Trigger)
|
||||||
|
{
|
||||||
|
OnStartTimer(uid, component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnStartTimer(EntityUid uid, SignalTimerComponent component)
|
||||||
|
{
|
||||||
TryComp<AppearanceComponent>(uid, out var appearance);
|
TryComp<AppearanceComponent>(uid, out var appearance);
|
||||||
var timer = EnsureComp<ActiveSignalTimerComponent>(uid);
|
var timer = EnsureComp<ActiveSignalTimerComponent>(uid);
|
||||||
timer.TriggerTime = _gameTiming.CurTime + TimeSpan.FromSeconds(component.Delay);
|
timer.TriggerTime = _gameTiming.CurTime + TimeSpan.FromSeconds(component.Delay);
|
||||||
|
|||||||
@@ -25,6 +25,9 @@
|
|||||||
ports:
|
ports:
|
||||||
- Start
|
- Start
|
||||||
- Timer
|
- Timer
|
||||||
|
- type: DeviceLinkSink
|
||||||
|
ports:
|
||||||
|
- Trigger
|
||||||
- type: ActivatableUI
|
- type: ActivatableUI
|
||||||
key: enum.SignalTimerUiKey.Key
|
key: enum.SignalTimerUiKey.Key
|
||||||
- type: UserInterface
|
- type: UserInterface
|
||||||
|
|||||||
Reference in New Issue
Block a user