From c4c2967065c5a25a7604391b9bcf9e18121f8da2 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 15 Nov 2018 20:52:15 +0200 Subject: [PATCH] Option to make RegEx component only send a signal when it receives a signal (not continuously according to the last received signal), added FalseOutput property to RegEx component. Closes #846, Closes #911 --- .../Components/Signal/RegExFindComponent.cs | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RegExFindComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RegExFindComponent.cs index 262a45d85..81f1b1f53 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RegExFindComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/RegExFindComponent.cs @@ -5,23 +5,25 @@ namespace Barotrauma.Items.Components { class RegExFindComponent : ItemComponent { - private string output; - private string expression; private string receivedSignal; private string previousReceivedSignal; - bool previousResult; + private bool previousResult; private Regex regex; + private bool nonContinuousOutputSent; + [InGameEditable, Serialize("1", true)] - public string Output - { - get { return output; } - set { output = value; } - } + public string Output { get; set; } + + [InGameEditable, Serialize("0", true)] + public string FalseOutput { get; set; } + + [Serialize(true, true), InGameEditable(ToolTip = "Should the component keep sending the output even after it stops receiving a signal, or only send an output when it receives a signal.")] + public bool ContinuousOutput { get; set; } [InGameEditable, Serialize("", true)] public string Expression @@ -73,8 +75,15 @@ namespace Barotrauma.Items.Components } } - - item.SendSignal(0, previousResult ? output : "0", "signal_out", null); + if (ContinuousOutput) + { + item.SendSignal(0, previousResult ? Output : FalseOutput, "signal_out", null); + } + else if (!nonContinuousOutputSent) + { + item.SendSignal(0, previousResult ? Output : FalseOutput, "signal_out", null); + nonContinuousOutputSent = true; + } } public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f) @@ -85,7 +94,7 @@ namespace Barotrauma.Items.Components receivedSignal = signal; break; case "set_output": - output = signal; + Output = signal; break; } }