Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/Items/Components/Signal/MemoryComponent.cs
2 using System;
3 using System.Xml.Linq;
4 
6 {
8  {
9  private int maxValueLength;
10  [Editable, Serialize(200, IsPropertySaveable.No, description: "The maximum length of the stored value. Warning: Large values can lead to large memory usage or networking issues.")]
11  public int MaxValueLength
12  {
13  get { return maxValueLength; }
14  set
15  {
16  maxValueLength = Math.Max(value, 0);
17  }
18  }
19 
20  private string value;
21 
22  [InGameEditable, Serialize("", IsPropertySaveable.Yes, description: "The currently stored signal the item outputs.", alwaysUseInstanceValues: true)]
23  public string Value
24  {
25  get { return value; }
26  set
27  {
28  if (value == null) { return; }
29  this.value = value;
30  if (this.value.Length > MaxValueLength && (item.Submarine == null || !item.Submarine.Loading))
31  {
32  this.value = this.value.Substring(0, MaxValueLength);
33  }
34  }
35  }
36 
37  [Editable, Serialize(true, IsPropertySaveable.Yes, description: "Can the value stored in the memory component be changed via signals.", alwaysUseInstanceValues: true)]
38  public bool Writeable
39  {
40  get;
41  set;
42  }
43 
45  : base(item, element)
46  {
47  IsActive = true;
48  }
49 
50  public override void Update(float deltaTime, Camera cam)
51  {
52  item.SendSignal(Value, "signal_out");
53  }
54 
55  partial void OnStateChanged();
56 
57  public override void ReceiveSignal(Signal signal, Connection connection)
58  {
59  switch (connection.Name)
60  {
61  case "signal_in":
62  if (Writeable)
63  {
64  string prevValue = Value;
65  Value = signal.value;
66  if (Value != prevValue)
67  {
68  OnStateChanged();
69  }
70  }
71  break;
72  case "signal_store":
73  case "lock_state":
74  Writeable = signal.value == "1";
75  break;
76  }
77  }
78  }
79 }
Submarine Submarine
Definition: Entity.cs:53
void SendSignal(string signal, string connectionName)
The base class for components holding the different functionalities of the item
Interface for entities that the server can send events to the clients