v0.13.0.11
This commit is contained in:
+27
-11
@@ -1,13 +1,11 @@
|
||||
using Barotrauma.Networking;
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class MemoryComponent : ItemComponent, IServerSerializable
|
||||
{
|
||||
const int MaxValueLength = ChatMessage.MaxLength;
|
||||
|
||||
|
||||
private string value;
|
||||
|
||||
[InGameEditable, Serialize("", true, description: "The currently stored signal the item outputs.", alwaysUseInstanceValues: true)]
|
||||
@@ -17,10 +15,25 @@ namespace Barotrauma.Items.Components
|
||||
set
|
||||
{
|
||||
if (value == null) { return; }
|
||||
this.value = value.Length <= MaxValueLength ? value : value.Substring(0, MaxValueLength);
|
||||
this.value = value;
|
||||
if (this.value.Length > MaxValueLength && (item.Submarine == null || !item.Submarine.Loading))
|
||||
{
|
||||
this.value = this.value.Substring(0, MaxValueLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int maxValueLength;
|
||||
[Editable, Serialize(200, false, description: "The maximum length of the stored value. Warning: Large values can lead to large memory usage or networking issues.")]
|
||||
public int MaxValueLength
|
||||
{
|
||||
get { return maxValueLength; }
|
||||
set
|
||||
{
|
||||
maxValueLength = Math.Max(value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected bool writeable = true;
|
||||
|
||||
public MemoryComponent(Item item, XElement element)
|
||||
@@ -31,26 +44,29 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
item.SendSignal(0, Value, "signal_out", null);
|
||||
item.SendSignal(Value, "signal_out");
|
||||
}
|
||||
|
||||
partial void OnStateChanged();
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
|
||||
public override void ReceiveSignal(Signal signal, Connection connection)
|
||||
{
|
||||
switch (connection.Name)
|
||||
{
|
||||
case "signal_in":
|
||||
if (writeable)
|
||||
{
|
||||
if (Value == signal) { return; }
|
||||
Value = signal;
|
||||
OnStateChanged();
|
||||
string prevValue = Value;
|
||||
Value = signal.value;
|
||||
if (Value != prevValue)
|
||||
{
|
||||
OnStateChanged();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "signal_store":
|
||||
case "lock_state":
|
||||
writeable = signal == "1";
|
||||
writeable = signal.value == "1";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user