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

This commit is contained in:
Joonas Rikkonen
2018-11-15 20:52:15 +02:00
parent df202d5a18
commit c4c2967065
@@ -5,23 +5,25 @@ namespace Barotrauma.Items.Components
{ {
class RegExFindComponent : ItemComponent class RegExFindComponent : ItemComponent
{ {
private string output;
private string expression; private string expression;
private string receivedSignal; private string receivedSignal;
private string previousReceivedSignal; private string previousReceivedSignal;
bool previousResult; private bool previousResult;
private Regex regex; private Regex regex;
private bool nonContinuousOutputSent;
[InGameEditable, Serialize("1", true)] [InGameEditable, Serialize("1", true)]
public string Output public string Output { get; set; }
{
get { return output; } [InGameEditable, Serialize("0", true)]
set { output = value; } 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)] [InGameEditable, Serialize("", true)]
public string Expression public string Expression
@@ -73,8 +75,15 @@ namespace Barotrauma.Items.Components
} }
} }
if (ContinuousOutput)
item.SendSignal(0, previousResult ? output : "0", "signal_out", null); {
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) 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; receivedSignal = signal;
break; break;
case "set_output": case "set_output":
output = signal; Output = signal;
break; break;
} }
} }