Added first visual-scripting draft [WIP]

This commit is contained in:
DarthAffe committed 2021-07-15 00:20:08 +02:00
1 parent 719d95bd33
commit a45dd094a0
56 files changed
+5139 -21

No files matched your search

@@ -0,0 +1,160 @@
using System.Collections;
using Artemis.VisualScripting.Attributes;
using Artemis.VisualScripting.Model;
namespace Artemis.VisualScripting.Nodes
{
[UI("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
}
[UI("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
}
[UI("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
}
[UI("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
}
}
@@ -0,0 +1,107 @@
using Artemis.VisualScripting.Attributes;
using Artemis.VisualScripting.Model;
namespace Artemis.VisualScripting.Nodes
{
[UI("To String", "Converts the input to a string.")]
public class ConvertToStringNode : Node
{
#region Properties & Fields
public InputPin<object> Input { get; }
public OutputPin<string> String { get; }
#endregion
#region Constructors
public ConvertToStringNode()
: base("To String", "Converts the input to a string.")
{
Input = CreateInputPin<object>();
String = CreateOutputPin<string>();
}
#endregion
#region Methods
public override void Evaluate()
{
String.Value = Input.Value?.ToString();
}
#endregion
}
[UI("To Integer", "Converts the input to an integer.")]
public class ConvertToIntegerNode : Node
{
#region Properties & Fields
public InputPin<object> Input { get; }
public OutputPin<int> Integer { get; }
#endregion
#region Constructors
public ConvertToIntegerNode()
: base("To Integer", "Converts the input to an integer.")
{
Input = CreateInputPin<object>();
Integer = CreateOutputPin<int>();
}
#endregion
#region Methods
public override void Evaluate()
{
if (!int.TryParse(Input.Value?.ToString(), out int value))
value = 0;
Integer.Value = value;
}
#endregion
}
[UI("To Double", "Converts the input to a 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()
{
if (!double.TryParse(Input.Value?.ToString(), out double value))
value = 0;
Double.Value = value;
}
#endregion
}
}
@@ -0,0 +1,121 @@
using System.Windows;
using Artemis.VisualScripting.Attributes;
using Artemis.VisualScripting.Model;
namespace Artemis.VisualScripting.Nodes
{
[UI("Integer-Value", "Outputs an configurable integer value.")]
public class StaticIntegerValueNode : Node
{
#region Properties & Fields
private StaticIntegerValueNodeCustomViewModel _customViewModel = new();
public OutputPin<int> Output { get; }
#endregion
#region Constructors
public StaticIntegerValueNode()
: base("Integer", "Outputs an configurable integer value.")
{
Output = CreateOutputPin<int>();
RegisterCustomView(Application.Current.FindResource("StaticValueCustomViewTemplate") as DataTemplate, _customViewModel);
}
#endregion
#region Methods
public override void Evaluate()
{
Output.Value = _customViewModel.Input;
}
#endregion
}
[UI("Double-Value", "Outputs a configurable double value.")]
public class StaticDoubleValueNode : Node
{
#region Properties & Fields
private StaticDoubleValueNodeCustomViewModel _customViewModel = new();
public OutputPin<double> Output { get; }
#endregion
#region Constructors
public StaticDoubleValueNode()
: base("Double", "Outputs a configurable double value.")
{
Output = CreateOutputPin<double>();
RegisterCustomView(Application.Current.FindResource("StaticValueCustomViewTemplate") as DataTemplate, _customViewModel);
}
#endregion
#region Methods
public override void Evaluate()
{
Output.Value = _customViewModel.Input;
}
#endregion
}
[UI("String-Value", "Outputs a configurable string value.")]
public class StaticStringValueNode : Node
{
#region Properties & Fields
private StaticStringValueNodeCustomViewModel _customViewModel = new();
public OutputPin<string> Output { get; }
#endregion
#region Constructors
public StaticStringValueNode()
: base("String", "Outputs a configurable string value.")
{
Output = CreateOutputPin<string>();
RegisterCustomView(Application.Current.FindResource("StaticValueCustomViewTemplate") as DataTemplate, _customViewModel);
}
#endregion
#region Methods
public override void Evaluate()
{
Output.Value = _customViewModel.Input;
}
#endregion
}
#region CustomViewModels
public class StaticIntegerValueNodeCustomViewModel
{
public int Input { get; set; }
}
public class StaticDoubleValueNodeCustomViewModel
{
public double Input { get; set; }
}
public class StaticStringValueNodeCustomViewModel
{
public string Input { get; set; }
}
#endregion
}
@@ -0,0 +1,40 @@
using System.Linq;
using Artemis.VisualScripting.Attributes;
using Artemis.VisualScripting.Model;
namespace Artemis.VisualScripting.Nodes
{
[UI("Format", "Formats the input string.")]
public class StringFormatNode : Node
{
#region Properties & Fields
public InputPin<string> Format { get; }
public InputPinCollection<object> Values { get; }
public OutputPin<string> Output { get; }
#endregion
#region Constructors
public StringFormatNode()
: base("Format", "Formats the input string.")
{
Format = CreateInputPin<string>("Format");
Values = CreateInputPinCollection<object>("Values", 1);
Output = CreateOutputPin<string>("Result");
}
#endregion
#region Methods
public override void Evaluate()
{
Output.Value = string.Format(Format.Value ?? string.Empty, Values.Values.ToArray());
}
#endregion
}
}
@@ -0,0 +1,12 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:nodes="clr-namespace:Artemis.VisualScripting.Nodes">
<DataTemplate x:Key="StaticValueCustomViewTemplate"
DataType="{x:Type nodes:StaticIntegerValueNodeCustomViewModel}">
<TextBox VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Text="{Binding Input}" />
</DataTemplate>
</ResourceDictionary>
@@ -0,0 +1,70 @@
using System.Linq;
using Artemis.VisualScripting.Attributes;
using Artemis.VisualScripting.Model;
namespace Artemis.VisualScripting.Nodes
{
[UI("Sum (Integer)", "Sums the connected integer values.")]
public class SumIntegersNode : Node
{
#region Properties & Fields
public InputPinCollection<int> Values { get; }
public OutputPin<int> Sum { get; }
#endregion
#region Constructors
public SumIntegersNode()
: base("Sum", "Sums the connected integer values.")
{
Values = CreateInputPinCollection<int>("Values", 2);
Sum = CreateOutputPin<int>("Sum");
}
#endregion
#region Methods
public override void Evaluate()
{
Sum.Value = Values.Values.Sum();
}
#endregion
}
[UI("Sum (Double)", "Sums the connected double values.")]
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
}
}