1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Robert 7eadc58bee Nodes - Added node type registration system
Nodes - Moved models and node logic into core
Nodes - Added node service that leverages DI
2021-08-07 21:05:15 +02:00

160 lines
3.6 KiB
C#

using System.Collections;
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes
{
[Node("Greater than", "Checks if the first input is greater than the second.")]
public class GreaterThanNode : Node
{
#region Properties & Fields
public InputPin<object> Input1 { get; }
public InputPin<object> Input2 { get; }
public OutputPin<bool> Result { get; }
#endregion
#region Constructors
public GreaterThanNode()
: base("Greater than", "Checks if the first input is greater than the second.")
{
Input1 = CreateInputPin<object>();
Input2 = CreateInputPin<object>();
Result = CreateOutputPin<bool>();
}
#endregion
#region Methods
public override void Evaluate()
{
try
{
Result.Value = Comparer.DefaultInvariant.Compare(Input1.Value, Input2.Value) == 1;
}
catch
{
Result.Value = false;
}
}
#endregion
}
[Node("Less than", "Checks if the first input is less than the second.")]
public class LessThanNode : Node
{
#region Properties & Fields
public InputPin<object> Input1 { get; }
public InputPin<object> Input2 { get; }
public OutputPin<bool> Result { get; }
#endregion
#region Constructors
public LessThanNode()
: base("Less than", "Checks if the first input is less than the second.")
{
Input1 = CreateInputPin<object>();
Input2 = CreateInputPin<object>();
Result = CreateOutputPin<bool>();
}
#endregion
#region Methods
public override void Evaluate()
{
try
{
Result.Value = Comparer.DefaultInvariant.Compare(Input1.Value, Input2.Value) == -1;
}
catch
{
Result.Value = false;
}
}
#endregion
}
[Node("Equals", "Checks if the two inputs are equals.")]
public class EqualsNode : Node
{
#region Properties & Fields
public InputPin<object> Input1 { get; }
public InputPin<object> Input2 { get; }
public OutputPin<bool> Result { get; }
#endregion
#region Constructors
public EqualsNode()
: base("Equals", "Checks if the two inputs are equals.")
{
Input1 = CreateInputPin<object>();
Input2 = CreateInputPin<object>();
Result = CreateOutputPin<bool>();
}
#endregion
#region Methods
public override void Evaluate()
{
try
{
Result.Value = Equals(Input1.Value, Input2.Value);
}
catch
{
Result.Value = false;
}
}
#endregion
}
[Node("Negate", "Negates the boolean.")]
public class NegateNode : Node
{
#region Properties & Fields
public InputPin<bool> Input { get; }
public OutputPin<bool> Output { get; }
#endregion
#region Constructors
public NegateNode()
: base("Negate", "Negates the boolean.")
{
Input = CreateInputPin<bool>();
Output = CreateOutputPin<bool>();
}
#endregion
#region Methods
public override void Evaluate()
{
Output.Value = !Input.Value;
}
#endregion
}
}