Client LuaCsForBarotrauma
SignalCheckComponent.cs
1 using System;
2 using System.Xml.Linq;
3 
5 {
7  {
8  private int maxOutputLength;
9  [Editable, Serialize(200, IsPropertySaveable.No, description: "The maximum length of the output strings. Warning: Large values can lead to large memory usage or networking issues.")]
10  public int MaxOutputLength
11  {
12  get { return maxOutputLength; }
13  set
14  {
15  maxOutputLength = Math.Max(value, 0);
16  }
17  }
18 
19  private string output;
20  [InGameEditable, Serialize("1", IsPropertySaveable.Yes, description: "The signal this item outputs when the received signal matches the target signal.", alwaysUseInstanceValues: true)]
21  public string Output
22  {
23  get { return output; }
24  set
25  {
26  if (value == null) { return; }
27  output = value;
28  if (output.Length > MaxOutputLength && (item.Submarine == null || !item.Submarine.Loading))
29  {
30  output = output.Substring(0, MaxOutputLength);
31  }
32  }
33  }
34 
35  private string falseOutput;
36  [InGameEditable, Serialize("0", IsPropertySaveable.Yes, description: "The signal this item outputs when the received signal does not match the target signal.", alwaysUseInstanceValues: true)]
37  public string FalseOutput
38  {
39  get { return falseOutput; }
40  set
41  {
42  if (value == null) { return; }
43  falseOutput = value;
44  if (falseOutput.Length > MaxOutputLength && (item.Submarine == null || !item.Submarine.Loading))
45  {
46  falseOutput = falseOutput.Substring(0, MaxOutputLength);
47  }
48  }
49  }
50 
51  [InGameEditable, Serialize("", IsPropertySaveable.Yes, description: "The value to compare the received signals against.", alwaysUseInstanceValues: true)]
52  public string TargetSignal { get; set; }
53 
55  : base(item, element)
56  {
57  }
58 
59  public override void ReceiveSignal(Signal signal, Connection connection)
60  {
61  switch (connection.Name)
62  {
63  case "signal_in":
64  string signalOut = (signal.value == TargetSignal) ? Output : FalseOutput;
65  if (string.IsNullOrEmpty(signalOut)) { return; }
66  signal.value = signalOut;
67  item.SendSignal(signal, "signal_out");
68  break;
69  case "set_output":
70  Output = signal.value;
71  break;
72  case "set_targetsignal":
73  TargetSignal = signal.value;
74  break;
75  }
76  }
77  }
78 }
Submarine Submarine
Definition: Entity.cs:53
void SendSignal(string signal, string connectionName)
The base class for components holding the different functionalities of the item
override void ReceiveSignal(Signal signal, Connection connection)
SignalCheckComponent(Item item, ContentXElement element)