2 using System.Text.RegularExpressions;
8 private static readonly TimeSpan timeout = TimeSpan.FromMilliseconds(1);
10 private string expression;
12 private string receivedSignal;
13 private string previousReceivedSignal;
15 private bool previousResult;
16 private GroupCollection previousGroups;
20 private bool nonContinuousOutputSent;
22 private int maxOutputLength;
23 [
Editable,
Serialize(200,
IsPropertySaveable.No, description:
"The maximum length of the output string. Warning: Large values can lead to large memory usage or networking issues.")]
26 get {
return maxOutputLength; }
29 maxOutputLength = Math.Max(value, 0);
33 private string output;
38 get {
return output; }
41 if (value ==
null) {
return; }
59 [
InGameEditable,
Serialize(
true,
IsPropertySaveable.Yes, description:
"Should the component keep sending the output even after it stops receiving a signal, or only send an output when it receives a signal.", alwaysUseInstanceValues:
true)]
65 get {
return expression; }
68 if (expression == value) {
return; }
70 previousReceivedSignal =
"";
75 options: RegexOptions.None,
76 matchTimeout: timeout);
90 nonContinuousOutputSent =
true;
96 if (
string.IsNullOrWhiteSpace(expression) || regex ==
null) {
return; }
99 if (receivedSignal != previousReceivedSignal && receivedSignal !=
null)
103 Match match = regex.Match(receivedSignal);
104 previousResult = match.Success;
105 previousGroups =
UseCaptureGroup && previousResult ? match.Groups :
null;
106 previousReceivedSignal = receivedSignal;
110 if (e is RegexMatchTimeoutException)
120 previousResult =
false;
126 bool allowEmptyStringOutput =
false;
131 if (previousGroups !=
null && previousGroups.TryGetValue(
Output, out Group group))
133 signalOut = group.Value;
151 if (!
string.IsNullOrEmpty(signalOut) || (allowEmptyStringOutput && signalOut ==
string.Empty)) {
item.
SendSignal(signalOut,
"signal_out"); }
154 nonContinuousOutputSent =
true;
160 switch (connection.
Name)
163 receivedSignal = signal.
value;
164 nonContinuousOutputSent =
false;
void SendSignal(string signal, string connectionName)
The base class for components holding the different functionalities of the item
RegExFindComponent(Item item, ContentXElement element)
override void ReceiveSignal(Signal signal, Connection connection)
bool OutputEmptyCaptureGroup
override void Update(float deltaTime, Camera cam)