diff --git a/src/Artemis.Core/VisualScripting/CustomNodeViewModel.cs b/src/Artemis.Core/VisualScripting/CustomNodeViewModel.cs
index 5975ed806..7efc9956e 100644
--- a/src/Artemis.Core/VisualScripting/CustomNodeViewModel.cs
+++ b/src/Artemis.Core/VisualScripting/CustomNodeViewModel.cs
@@ -1,9 +1,23 @@
-using Newtonsoft.Json;
-
-namespace Artemis.Core
+namespace Artemis.Core
{
+ ///
+ /// Represents a custom view model for a
+ ///
public interface ICustomNodeViewModel
{
+ ///
+ /// Gets the node the view models belongs to
+ ///
public INode Node { get; }
+
+ ///
+ /// Called whenever the custom view model is activated
+ ///
+ void OnActivate();
+
+ ///
+ /// Called whenever the custom view model is closed
+ ///
+ void OnDeactivate();
}
}
\ No newline at end of file
diff --git a/src/Artemis.VisualScripting/Editor/Controls/VisualScriptNodePresenter.cs b/src/Artemis.VisualScripting/Editor/Controls/VisualScriptNodePresenter.cs
index cc88904df..4532b9d8b 100644
--- a/src/Artemis.VisualScripting/Editor/Controls/VisualScriptNodePresenter.cs
+++ b/src/Artemis.VisualScripting/Editor/Controls/VisualScriptNodePresenter.cs
@@ -50,6 +50,15 @@ namespace Artemis.VisualScripting.Editor.Controls
#endregion
+ #region Constructors
+
+ public VisualScriptNodePresenter()
+ {
+ Unloaded += OnUnloaded;
+ }
+
+ #endregion
+
#region Methods
protected override Size MeasureOverride(Size constraint)
@@ -144,8 +153,13 @@ namespace Artemis.VisualScripting.Editor.Controls
private void GetCustomViewModel()
{
+ CustomViewModel?.OnDeactivate();
+
if (Node?.Node is CustomViewModelNode customViewModelNode)
+ {
CustomViewModel = customViewModelNode.GetCustomViewModel();
+ CustomViewModel.OnActivate();
+ }
else
CustomViewModel = null;
}
@@ -156,6 +170,12 @@ namespace Artemis.VisualScripting.Editor.Controls
presenter.GetCustomViewModel();
}
+ private void OnUnloaded(object sender, RoutedEventArgs e)
+ {
+ CustomViewModel?.OnDeactivate();
+ CustomViewModel = null;
+ }
+
#endregion
}
}
\ No newline at end of file
diff --git a/src/Artemis.VisualScripting/Nodes/ConvertNodes.cs b/src/Artemis.VisualScripting/Nodes/ConvertNodes.cs
index f9d52f8dd..29215d8d1 100644
--- a/src/Artemis.VisualScripting/Nodes/ConvertNodes.cs
+++ b/src/Artemis.VisualScripting/Nodes/ConvertNodes.cs
@@ -60,10 +60,21 @@ namespace Artemis.VisualScripting.Nodes
public override void Evaluate()
{
- if (!int.TryParse(Input.Value?.ToString(), out int value))
+ Integer.Value = Input.Value switch
+ {
+ int input => input,
+ double input => (int) input,
+ float input => (int) input,
+ _ => TryParse(Input.Value)
+ };
+ }
+
+ private int TryParse(object input)
+ {
+ if (!int.TryParse(input?.ToString(), out int value))
value = 0;
- Integer.Value = value;
+ return value;
}
#endregion
@@ -95,12 +106,69 @@ namespace Artemis.VisualScripting.Nodes
public override void Evaluate()
{
- if (!double.TryParse(Input.Value?.ToString(), out double value))
- value = 0;
+ Double.Value = Input.Value switch
+ {
+ int input => input,
+ double input => input,
+ float input => input,
+ _ => TryParse(Input.Value)
+ };
+ }
- Double.Value = 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.")]
+ public class ConvertToFloatNode : Node
+ {
+ #region Properties & Fields
+
+ public InputPin