Nodes - Lock nodes while resetting

Nodes - Added more boolean operators
Nodes - Fix number comparisons
This commit is contained in:
Robert committed 2021-09-29 21:43:12 +02:00
1 parent 43b7b8345c
commit 0058322936
13 files changed
+218 -253

No files matched your search

@@ -1,4 +1,6 @@
using System.Collections;
using System;
using System.Collections;
using System.Linq;
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes
@@ -31,6 +33,12 @@ namespace Artemis.VisualScripting.Nodes
public override void Evaluate()
{
if (Input2.Value != null && Input1.Value != null && Input1.Value.IsNumber() && Input2.Value.IsNumber())
{
Result.Value = Convert.ToSingle(Input1.Value) > Convert.ToSingle(Input2.Value);
return;
}
try
{
Result.Value = Comparer.DefaultInvariant.Compare(Input1.Value, Input2.Value) == 1;
@@ -72,6 +80,12 @@ namespace Artemis.VisualScripting.Nodes
public override void Evaluate()
{
if (Input2.Value != null && Input1.Value != null && Input1.Value.IsNumber() && Input2.Value.IsNumber())
{
Result.Value = Convert.ToSingle(Input1.Value) < Convert.ToSingle(Input2.Value);
return;
}
try
{
Result.Value = Comparer.DefaultInvariant.Compare(Input1.Value, Input2.Value) == -1;
@@ -156,4 +170,97 @@ namespace Artemis.VisualScripting.Nodes
#endregion
}
}
[Node("And", "Checks if all inputs are true.", "Operators", InputType = typeof(bool), OutputType = typeof(bool))]
public class AndNode : Node
{
#region Properties & Fields
public InputPinCollection<bool> Input { get; set; }
public OutputPin<bool> Result { get; }
#endregion
#region Constructors
public AndNode()
: base("And", "Checks if all inputs are true.")
{
Input = CreateInputPinCollection<bool>();
Result = CreateOutputPin<bool>();
}
#endregion
#region Methods
public override void Evaluate()
{
Result.Value = Input.Values.All(v => v);
}
#endregion
}
[Node("Or", "Checks if any inputs are true.", "Operators", InputType = typeof(bool), OutputType = typeof(bool))]
public class OrNode : Node
{
#region Properties & Fields
public InputPinCollection<bool> Input { get; set; }
public OutputPin<bool> Result { get; }
#endregion
#region Constructors
public OrNode()
: base("Or", "Checks if any inputs are true.")
{
Input = CreateInputPinCollection<bool>();
Result = CreateOutputPin<bool>();
}
#endregion
#region Methods
public override void Evaluate()
{
Result.Value = Input.Values.Any(v => v);
}
#endregion
}
[Node("Exclusive Or", "Checks if one of the inputs is true.", "Operators", InputType = typeof(bool), OutputType = typeof(bool))]
public class XorNode : Node
{
#region Properties & Fields
public InputPinCollection<bool> Input { get; set; }
public OutputPin<bool> Result { get; }
#endregion
#region Constructors
public XorNode()
: base("Exclusive Or", "Checks if one of the inputs is true.")
{
Input = CreateInputPinCollection<bool>();
Result = CreateOutputPin<bool>();
}
#endregion
#region Methods
public override void Evaluate()
{
Result.Value = Input.Values.Count(v => v) == 1;
}
#endregion
}
}
@@ -79,53 +79,7 @@ namespace Artemis.VisualScripting.Nodes
#endregion
}
[Node("To Double", "Converts the input to a double.", "Conversion", InputType = typeof(object), OutputType = typeof(double))]
public class ConvertToDoubleNode : Node
{
#region Properties & Fields
public InputPin<object> Input { get; }
public OutputPin<double> Double { get; }
#endregion
#region Constructors
public ConvertToDoubleNode()
: base("To Double", "Converts the input to a double.")
{
Input = CreateInputPin<object>();
Double = CreateOutputPin<double>();
}
#endregion
#region Methods
public override void Evaluate()
{
Double.Value = Input.Value switch
{
int input => input,
double input => input,
float input => input,
_ => TryParse(Input.Value)
};
}
private double TryParse(object input)
{
if (!double.TryParse(input?.ToString(), out double value))
value = 0.0;
return value;
}
#endregion
}
[Node("To Float", "Converts the input to a float.", "Conversion", InputType = typeof(object), OutputType = typeof(float))]
public class ConvertToFloatNode : Node
{
@@ -8,7 +8,7 @@ using Artemis.VisualScripting.Nodes.DataModel.CustomViewModels;
namespace Artemis.VisualScripting.Nodes.DataModel
{
[Node("Data Model-Event", "Responds to a data model event trigger", "External", OutputType = typeof(bool))]
[Node("Data Model-Event", "Responds to a data model event trigger", "Data Model", OutputType = typeof(bool))]
public class DataModelEventNode : Node<DataModelPathEntity, DataModelEventNodeCustomViewModel>, IDisposable
{
private DataModelPath _dataModelPath;
@@ -5,7 +5,7 @@ using Artemis.VisualScripting.Nodes.DataModel.CustomViewModels;
namespace Artemis.VisualScripting.Nodes.DataModel
{
[Node("Data Model-Value", "Outputs a selectable data model value.", "External")]
[Node("Data Model-Value", "Outputs a selectable data model value.", "Data Model")]
public class DataModelNode : Node<DataModelPathEntity, DataModelNodeCustomViewModel>, IDisposable
{
private DataModelPath _dataModelPath;
@@ -44,14 +44,29 @@ namespace Artemis.VisualScripting.Nodes.DataModel
UpdateOutputPin(false);
object pathValue = DataModelPath.GetValue();
if (pathValue != null)
Output.Value = pathValue;
if (pathValue == null)
{
if (!Output.Type.IsValueType)
Output.Value = null;
}
else
{
if (pathValue is double doublePathValue)
Output.Value = (float) doublePathValue;
else
Output.Value = pathValue;
}
}
}
public void UpdateOutputPin(bool loadConnections)
{
if (Output != null && Output.Type == DataModelPath?.GetPropertyType())
Type type = DataModelPath?.GetPropertyType();
if (type == typeof(double))
type = typeof(float);
if (Output != null && Output.Type == type)
return;
if (Output != null)
@@ -60,8 +75,7 @@ namespace Artemis.VisualScripting.Nodes.DataModel
Output = null;
}
Type type = DataModelPath?.GetPropertyType();
if (type != null)
if (type != null)
Output = CreateOutputPin(type);
if (loadConnections && Script is NodeScript nodeScript)
@@ -1,68 +0,0 @@
using System;
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes.Easing
{
[Node("Double Easing", "Outputs an eased double value", "Easing", InputType = typeof(double), OutputType = typeof(double))]
public class DoubleEasingNode : Node
{
private DateTime _lastEvaluate = DateTime.MinValue;
private float _progress;
private double _currentValue;
private double _sourceValue;
private double _targetValue;
public DoubleEasingNode() : base("Double Easing", "Outputs an eased double value")
{
Input = CreateInputPin<double>();
EasingTime = CreateInputPin<float>("delay");
EasingFunction = CreateInputPin<Easings.Functions>("function");
Output = CreateOutputPin<double>();
}
public InputPin<double> Input { get; set; }
public InputPin<float> EasingTime { get; set; }
public InputPin<Easings.Functions> EasingFunction { get; set; }
public OutputPin<double> Output { get; set; }
public override void Evaluate()
{
DateTime now = DateTime.Now;
// If the value changed reset progress
if (Math.Abs(_targetValue - Input.Value) > 0.001f)
{
_sourceValue = _currentValue;
_targetValue = Input.Value;
_progress = 0f;
}
// Update until finished
if (_progress < 1f)
{
Update();
Output.Value = _currentValue;
}
// Stop updating past 1 and use the target value
else
{
Output.Value = _targetValue;
}
_lastEvaluate = now;
}
private void Update()
{
TimeSpan delta = DateTime.Now - _lastEvaluate;
// In case of odd delta's, keep progress between 0f and 1f
_progress = Math.Clamp(_progress + (float)delta.TotalMilliseconds / EasingTime.Value, 0f, 1f);
double eased = _sourceValue + (_targetValue - _sourceValue) * Easings.Interpolate(_progress, EasingFunction.Value);
_currentValue = eased;
}
}
}
@@ -8,7 +8,7 @@ using NoStringEvaluating.Models.Values;
namespace Artemis.VisualScripting.Nodes.Maths
{
[Node("Math Expression", "Outputs the result of a math expression.", "Math", InputType = typeof(float), OutputType = typeof(float))]
[Node("Math Expression", "Outputs the result of a math expression.", "Mathematics", InputType = typeof(float), OutputType = typeof(float))]
public class MathExpressionNode : Node<string, MathExpressionNodeCustomViewModel>
{
private readonly INoStringEvaluator _evaluator;
@@ -42,7 +42,6 @@ namespace Artemis.VisualScripting.Nodes.Maths
public override void Evaluate()
{
var test = _evaluator.ToString();
if (Storage != null)
Output.Value = (float) _evaluator.CalcNumber(Storage, _variables);
}
@@ -3,7 +3,7 @@ using Artemis.VisualScripting.Nodes.CustomViewModels;
namespace Artemis.VisualScripting.Nodes
{
[Node("Integer-Value", "Outputs an configurable integer value.", "Static", OutputType = typeof(int))]
[Node("Integer-Value", "Outputs a configurable static integer value.", "Static", OutputType = typeof(int))]
public class StaticIntegerValueNode : Node<int, StaticIntegerValueNodeCustomViewModel>
{
#region Properties & Fields
@@ -32,36 +32,7 @@ namespace Artemis.VisualScripting.Nodes
#endregion
}
[Node("Double-Value", "Outputs a configurable double value.", "Static", OutputType = typeof(double))]
public class StaticDoubleValueNode : Node<double, StaticDoubleValueNodeCustomViewModel>
{
#region Properties & Fields
public OutputPin<double> Output { get; }
#endregion
#region Constructors
public StaticDoubleValueNode()
: base("Double", "Outputs a configurable double value.")
{
Output = CreateOutputPin<double>();
}
#endregion
#region Methods
public override void Evaluate()
{
Output.Value = Storage as double? ?? 0.0;
}
#endregion
}
[Node("Float-Value", "Outputs a configurable float value.", "Static", OutputType = typeof(float))]
[Node("Float-Value", "Outputs a configurable static float value.", "Static", OutputType = typeof(float))]
public class StaticFloatValueNode : Node<float, StaticFloatValueNodeCustomViewModel>
{
#region Properties & Fields
@@ -90,7 +61,7 @@ namespace Artemis.VisualScripting.Nodes
#endregion
}
[Node("String-Value", "Outputs a configurable string value.", "Static", OutputType = typeof(string))]
[Node("String-Value", "Outputs a configurable static string value.", "Static", OutputType = typeof(string))]
public class StaticStringValueNode : Node<string, StaticStringValueNodeCustomViewModel>
{
#region Properties & Fields
@@ -66,36 +66,4 @@ namespace Artemis.VisualScripting.Nodes
#endregion
}
[Node("Sum (Double)", "Sums the connected double values.", "Mathematics", InputType = typeof(double), OutputType = typeof(double))]
public class SumDoublesNode : Node
{
#region Properties & Fields
public InputPinCollection<double> Values { get; }
public OutputPin<double> Sum { get; }
#endregion
#region Constructors
public SumDoublesNode()
: base("Sum", "Sums the connected double values.")
{
Values = CreateInputPinCollection<double>("Values", 2);
Sum = CreateOutputPin<double>("Sum");
}
#endregion
#region Methods
public override void Evaluate()
{
Sum.Value = Values.Values.Sum();
}
#endregion
}
}