a0d606ef5f
- Add support for some of the most common types (vectors, colors, rects) so there's no need to parse the values in the setters of the serializable properties (see Holdable.HoldPos for example). - Make a generic version of the item editing HUD that can be used on any IPropertyObject. Should make it easier to implement things like the character editor, editing structure properties, particle editor, etc. - Improve the interface of the editing HUD. Instead of having to type in a string value into a textbox, there should be number input fields for numeric properties, sliders for properties that only accept a range of values, a color picker, etc. And tooltips.
94 lines
2.4 KiB
C#
94 lines
2.4 KiB
C#
using System.Text.RegularExpressions;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Barotrauma.Items.Components
|
|
{
|
|
class RegExFindComponent : ItemComponent
|
|
{
|
|
private string output;
|
|
|
|
private string expression;
|
|
|
|
private string receivedSignal;
|
|
private string previousReceivedSignal;
|
|
|
|
bool previousResult;
|
|
|
|
private Regex regex;
|
|
|
|
[InGameEditable, SerializableProperty("1", true)]
|
|
public string Output
|
|
{
|
|
get { return output; }
|
|
set { output = value; }
|
|
}
|
|
|
|
[InGameEditable, SerializableProperty("", true)]
|
|
public string Expression
|
|
{
|
|
get { return expression; }
|
|
set
|
|
{
|
|
if (expression == value) return;
|
|
expression = value;
|
|
previousReceivedSignal = "";
|
|
|
|
try
|
|
{
|
|
regex = new Regex(@expression);
|
|
}
|
|
|
|
catch
|
|
{
|
|
item.SendSignal(0, "ERROR", "signal_out", null);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public RegExFindComponent(Item item, XElement element)
|
|
: base(item, element)
|
|
{
|
|
IsActive = true;
|
|
}
|
|
|
|
public override void Update(float deltaTime, Camera cam)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(expression) || regex==null) return;
|
|
|
|
if (receivedSignal != previousReceivedSignal)
|
|
{
|
|
try
|
|
{
|
|
Match match = regex.Match(receivedSignal);
|
|
previousResult = match.Success;
|
|
previousReceivedSignal = receivedSignal;
|
|
|
|
}
|
|
catch
|
|
{
|
|
item.SendSignal(0, "ERROR", "signal_out", null);
|
|
previousResult = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
item.SendSignal(0, previousResult ? output : "0", "signal_out", null);
|
|
}
|
|
|
|
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f)
|
|
{
|
|
switch (connection.Name)
|
|
{
|
|
case "signal_in":
|
|
receivedSignal = signal;
|
|
break;
|
|
case "set_output":
|
|
output = signal;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|