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:
deltanedas
2023-06-12 22:43:59 +00:00
committed by GitHub
parent 263890ff64
commit 7cbf08ea9e
7 changed files with 109 additions and 49 deletions

View File

@@ -32,6 +32,26 @@ public sealed class LogicGateSystem : EntitySystem
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)
{
_deviceLink.EnsureSinkPorts(uid, comp.InputPortA, comp.InputPortB);
@@ -92,8 +112,9 @@ public sealed class LogicGateSystem : EntitySystem
private void UpdateOutput(EntityUid uid, LogicGateComponent comp)
{
// get the new output value now that it's changed
var a = comp.StateA == SignalState.High;
var b = comp.StateB == SignalState.High;
// momentary is treated as high for the current tick, after updating it will be reset to low
var a = comp.StateA != SignalState.Low;
var b = comp.StateB != SignalState.Low;
var output = false;
switch (comp.Gate)
{