logic gate momentary pulse, switch status port (#17198)
* logic gate momentary is now pulse * switch status, minor refactor * filescope namespace * switch * fix ci probably * add auto linking for edge detector and logic gate --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,16 +1,17 @@
|
|||||||
|
using Content.Server.DeviceLinking.Systems;
|
||||||
using Content.Shared.MachineLinking;
|
using Content.Shared.MachineLinking;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
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;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Simple switch that will fire ports when toggled on or off. A button is jsut a switch that signals on the
|
||||||
|
/// same port regardless of its state.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent, Access(typeof(SignalSwitchSystem))]
|
||||||
|
public sealed class SignalSwitchComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Simple switch that will fire ports when toggled on or off. A button is jsut a switch that signals on the
|
|
||||||
/// same port regardless of its state.
|
|
||||||
/// </summary>
|
|
||||||
[RegisterComponent]
|
|
||||||
public sealed class SignalSwitchComponent : Component
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The port that gets signaled when the switch turns on.
|
/// The port that gets signaled when the switch turns on.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -23,10 +24,16 @@ namespace Content.Server.DeviceLinking.Components
|
|||||||
[DataField("offPort", customTypeSerializer: typeof(PrototypeIdSerializer<TransmitterPortPrototype>))]
|
[DataField("offPort", customTypeSerializer: typeof(PrototypeIdSerializer<TransmitterPortPrototype>))]
|
||||||
public string OffPort = "Off";
|
public string OffPort = "Off";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The port that gets signaled with the switch's current status.
|
||||||
|
/// This is only used if OnPort is different from OffPort, not in the case of a toggle switch.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("statusPort", customTypeSerializer: typeof(PrototypeIdSerializer<TransmitterPortPrototype>))]
|
||||||
|
public string StatusPort = "Status";
|
||||||
|
|
||||||
[DataField("state")]
|
[DataField("state")]
|
||||||
public bool State;
|
public bool State;
|
||||||
|
|
||||||
[DataField("clickSound")]
|
[DataField("clickSound")]
|
||||||
public SoundSpecifier ClickSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/lightswitch.ogg");
|
public SoundSpecifier ClickSound = new SoundPathSpecifier("/Audio/Machines/lightswitch.ogg");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,26 @@ public sealed class LogicGateSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<LogicGateComponent, SignalReceivedEvent>(OnSignalReceived);
|
SubscribeLocalEvent<LogicGateComponent, SignalReceivedEvent>(OnSignalReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Update(float deltaTime)
|
||||||
|
{
|
||||||
|
var query = EntityQueryEnumerator<LogicGateComponent>();
|
||||||
|
while (query.MoveNext(out var uid, out var comp))
|
||||||
|
{
|
||||||
|
// handle momentary pulses - high when received then low the next tick
|
||||||
|
if (comp.StateA == SignalState.Momentary)
|
||||||
|
{
|
||||||
|
comp.StateA = SignalState.Low;
|
||||||
|
}
|
||||||
|
if (comp.StateB == SignalState.Momentary)
|
||||||
|
{
|
||||||
|
comp.StateB = SignalState.High;
|
||||||
|
}
|
||||||
|
|
||||||
|
// output most likely changed so update it
|
||||||
|
UpdateOutput(uid, comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnInit(EntityUid uid, LogicGateComponent comp, ComponentInit args)
|
private void OnInit(EntityUid uid, LogicGateComponent comp, ComponentInit args)
|
||||||
{
|
{
|
||||||
_deviceLink.EnsureSinkPorts(uid, comp.InputPortA, comp.InputPortB);
|
_deviceLink.EnsureSinkPorts(uid, comp.InputPortA, comp.InputPortB);
|
||||||
@@ -92,8 +112,9 @@ public sealed class LogicGateSystem : EntitySystem
|
|||||||
private void UpdateOutput(EntityUid uid, LogicGateComponent comp)
|
private void UpdateOutput(EntityUid uid, LogicGateComponent comp)
|
||||||
{
|
{
|
||||||
// get the new output value now that it's changed
|
// get the new output value now that it's changed
|
||||||
var a = comp.StateA == SignalState.High;
|
// momentary is treated as high for the current tick, after updating it will be reset to low
|
||||||
var b = comp.StateB == SignalState.High;
|
var a = comp.StateA != SignalState.Low;
|
||||||
|
var b = comp.StateB != SignalState.Low;
|
||||||
var output = false;
|
var output = false;
|
||||||
switch (comp.Gate)
|
switch (comp.Gate)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
using Content.Server.DeviceLinking.Components;
|
using Content.Server.DeviceLinking.Components;
|
||||||
|
using Content.Server.DeviceNetwork;
|
||||||
using Content.Server.MachineLinking.System;
|
using Content.Server.MachineLinking.System;
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
|
|
||||||
namespace Content.Server.DeviceLinking.Systems
|
namespace Content.Server.DeviceLinking.Systems;
|
||||||
|
|
||||||
|
public sealed class SignalSwitchSystem : EntitySystem
|
||||||
{
|
{
|
||||||
public sealed class SignalSwitchSystem : EntitySystem
|
[Dependency] private readonly DeviceLinkSystem _deviceLink = default!;
|
||||||
{
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
[Dependency] private readonly DeviceLinkSystem _signalSystem = default!;
|
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -19,22 +21,31 @@ namespace Content.Server.DeviceLinking.Systems
|
|||||||
SubscribeLocalEvent<SignalSwitchComponent, ActivateInWorldEvent>(OnActivated);
|
SubscribeLocalEvent<SignalSwitchComponent, ActivateInWorldEvent>(OnActivated);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnInit(EntityUid uid, SignalSwitchComponent component, ComponentInit args)
|
private void OnInit(EntityUid uid, SignalSwitchComponent comp, ComponentInit args)
|
||||||
{
|
{
|
||||||
_signalSystem.EnsureSourcePorts(uid, component.OnPort, component.OffPort);
|
_deviceLink.EnsureSourcePorts(uid, comp.OnPort, comp.OffPort, comp.StatusPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnActivated(EntityUid uid, SignalSwitchComponent component, ActivateInWorldEvent args)
|
private void OnActivated(EntityUid uid, SignalSwitchComponent comp, ActivateInWorldEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled)
|
if (args.Handled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
component.State = !component.State;
|
comp.State = !comp.State;
|
||||||
_signalSystem.InvokePort(uid, component.State ? component.OnPort : component.OffPort);
|
_deviceLink.InvokePort(uid, comp.State ? comp.OnPort : comp.OffPort);
|
||||||
SoundSystem.Play(component.ClickSound.GetSound(), Filter.Pvs(component.Owner), component.Owner,
|
var data = new NetworkPayload
|
||||||
AudioHelpers.WithVariation(0.125f).WithVolume(8f));
|
{
|
||||||
|
[DeviceNetworkConstants.LogicState] = comp.State ? SignalState.High : SignalState.Low
|
||||||
|
};
|
||||||
|
|
||||||
|
// only send status if it's a toggle switch and not a button
|
||||||
|
if (comp.OnPort != comp.OffPort)
|
||||||
|
{
|
||||||
|
_deviceLink.InvokePort(uid, comp.StatusPort, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
_audio.PlayPvs(comp.ClickSound, uid, AudioParams.Default.WithVariation(0.125f).WithVolume(8f));
|
||||||
|
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ signal-port-description-on-transmitter = This port is invoked whenever the trans
|
|||||||
signal-port-name-off-transmitter = Off
|
signal-port-name-off-transmitter = Off
|
||||||
signal-port-description-off-transmitter = This port is invoked whenever the transmitter is turned off.
|
signal-port-description-off-transmitter = This port is invoked whenever the transmitter is turned off.
|
||||||
|
|
||||||
|
signal-port-name-status-transmitter = Status
|
||||||
|
signal-port-description-logic-output = This port is invoked with HIGH or LOW depending on the transmitter status.
|
||||||
|
|
||||||
signal-port-name-left = Left
|
signal-port-name-left = Left
|
||||||
signal-port-description-left = This port is invoked whenever the lever is moved to the leftmost position.
|
signal-port-description-left = This port is invoked whenever the lever is moved to the leftmost position.
|
||||||
|
|
||||||
@@ -14,7 +17,7 @@ signal-port-name-right = Right
|
|||||||
signal-port-description-right = This port is invoked whenever the lever is moved to the rightmost position.
|
signal-port-description-right = This port is invoked whenever the lever is moved to the rightmost position.
|
||||||
|
|
||||||
signal-port-name-doorstatus = Door status
|
signal-port-name-doorstatus = Door status
|
||||||
signal-port-description-doorstatus = This port is invoked with HIGH when the door opens and LOW when the door closes.
|
signal-port-description-doorstatus = This port is invoked with HIGH when the door opens and LOW when the door finishes closing.
|
||||||
|
|
||||||
signal-port-name-middle = Middle
|
signal-port-name-middle = Middle
|
||||||
signal-port-description-middle = This port is invoked whenever the lever is moved to the neutral position.
|
signal-port-description-middle = This port is invoked whenever the lever is moved to the neutral position.
|
||||||
|
|||||||
@@ -16,6 +16,11 @@
|
|||||||
description: signal-port-description-off-transmitter
|
description: signal-port-description-off-transmitter
|
||||||
defaultLinks: [ Off, Close ]
|
defaultLinks: [ Off, Close ]
|
||||||
|
|
||||||
|
- type: sourcePort
|
||||||
|
id: Status
|
||||||
|
name: signal-port-name-status-transmitter
|
||||||
|
description: signal-port-description-status-transmitter
|
||||||
|
|
||||||
- type: sourcePort
|
- type: sourcePort
|
||||||
id: Left
|
id: Left
|
||||||
name: signal-port-name-left
|
name: signal-port-name-left
|
||||||
@@ -78,13 +83,16 @@
|
|||||||
id: Output
|
id: Output
|
||||||
name: signal-port-name-logic-output
|
name: signal-port-name-logic-output
|
||||||
description: signal-port-description-logic-output
|
description: signal-port-description-logic-output
|
||||||
|
defaultLinks: [ Input ]
|
||||||
|
|
||||||
- type: sourcePort
|
- type: sourcePort
|
||||||
id: OutputHigh
|
id: OutputHigh
|
||||||
name: signal-port-name-logic-output-high
|
name: signal-port-name-logic-output-high
|
||||||
description: signal-port-description-logic-output-high
|
description: signal-port-description-logic-output-high
|
||||||
|
defaultLinks: [ On, Open, Forward, Trigger ]
|
||||||
|
|
||||||
- type: sourcePort
|
- type: sourcePort
|
||||||
id: OutputLow
|
id: OutputLow
|
||||||
name: signal-port-name-logic-output-low
|
name: signal-port-name-logic-output-low
|
||||||
description: signal-port-description-logic-output-low
|
description: signal-port-description-logic-output-low
|
||||||
|
defaultLinks: [ Off, Close ]
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
ports:
|
ports:
|
||||||
- On
|
- On
|
||||||
- Off
|
- Off
|
||||||
|
- Status
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: SignalButton
|
id: SignalButton
|
||||||
@@ -56,6 +57,7 @@
|
|||||||
- type: SignalSwitch
|
- type: SignalSwitch
|
||||||
onPort: Pressed
|
onPort: Pressed
|
||||||
offPort: Pressed
|
offPort: Pressed
|
||||||
|
statusPort: Pressed
|
||||||
- type: Rotatable
|
- type: Rotatable
|
||||||
- type: Construction
|
- type: Construction
|
||||||
graph: SignalButtonGraph
|
graph: SignalButtonGraph
|
||||||
|
|||||||
@@ -16,6 +16,11 @@
|
|||||||
description: signal-port-description-off-transmitter
|
description: signal-port-description-off-transmitter
|
||||||
defaultLinks: [ Off, Close ]
|
defaultLinks: [ Off, Close ]
|
||||||
|
|
||||||
|
- type: transmitterPort
|
||||||
|
id: Status
|
||||||
|
name: signal-port-name-status-transmitter
|
||||||
|
description: signal-port-description-status-transmitter
|
||||||
|
|
||||||
- type: transmitterPort
|
- type: transmitterPort
|
||||||
id: Left
|
id: Left
|
||||||
name: signal-port-name-left
|
name: signal-port-name-left
|
||||||
@@ -78,13 +83,16 @@
|
|||||||
id: Output
|
id: Output
|
||||||
name: signal-port-name-logic-output
|
name: signal-port-name-logic-output
|
||||||
description: signal-port-description-logic-output
|
description: signal-port-description-logic-output
|
||||||
|
defaultLinks: [ Input ]
|
||||||
|
|
||||||
- type: transmitterPort
|
- type: transmitterPort
|
||||||
id: OutputHigh
|
id: OutputHigh
|
||||||
name: signal-port-name-logic-output-high
|
name: signal-port-name-logic-output-high
|
||||||
description: signal-port-description-logic-output-high
|
description: signal-port-description-logic-output-high
|
||||||
|
defaultLinks: [ On, Open, Forward, Trigger ]
|
||||||
|
|
||||||
- type: transmitterPort
|
- type: transmitterPort
|
||||||
id: OutputLow
|
id: OutputLow
|
||||||
name: signal-port-name-logic-output-low
|
name: signal-port-name-logic-output-low
|
||||||
description: signal-port-description-logic-output-low
|
description: signal-port-description-logic-output-low
|
||||||
|
defaultLinks: [ Off, Close ]
|
||||||
|
|||||||
Reference in New Issue
Block a user