Nodes - Provide scripts with a context

Nodes - Inform nodes about the script they're being initialized for
Nodes - Added float nodes matching the existing other number types
Core - Add API for retrieving data binding values via the interface
This commit is contained in:
Robert committed 2021-08-21 12:15:01 +02:00
1 parent 3ed3cd1b1e
commit 836e979991
26 files changed
+305 -122

No files matched your search

@@ -50,6 +50,9 @@
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Nodes\CustomViews\StaticFloatValueNodeCustomView.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
<Page Update="ResourceDictionaries\DataModelConditions.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
@@ -383,7 +383,8 @@ namespace Artemis.VisualScripting.Editor.Controls
if (_creationBoxParent.ContextMenu != null)
_creationBoxParent.ContextMenu.IsOpen = false;
INode node = nodeData.CreateNode(null);
INode node = nodeData.CreateNode(Script, null);
node.Initialize(Script);
Script.AddNode(node);
InitializeNode(node, _lastRightClickLocation);
@@ -0,0 +1,34 @@
using System.Windows;
using Artemis.Core;
using Stylet;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
{
public abstract class CustomNodeViewModel : PropertyChangedBase, IViewAware, ICustomNodeViewModel
{
protected CustomNodeViewModel(INode node)
{
Node = node;
}
public INode Node { get; }
#region Implementation of IViewAware
/// <inheritdoc />
public void AttachView(UIElement view)
{
View = view;
OnDisplay();
}
protected virtual void OnDisplay()
{
}
/// <inheritdoc />
public UIElement View { get; private set; }
#endregion
}
}
@@ -1,16 +1,25 @@
using Artemis.Core;
using Artemis.Core.Modules;
using Stylet;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
{
public class DataModelNodeCustomViewModel : CustomNodeViewModel
{
private readonly DataModelNode _node;
private BindableCollection<Module> _modules;
public DataModelNodeCustomViewModel(DataModelNode node) : base(node)
{
_node = node;
}
public BindableCollection<Module> Modules
{
get => _modules;
set => SetAndNotify(ref _modules, value);
}
public DataModelPath DataModelPath
{
get => _node.DataModelPath;
@@ -32,5 +41,28 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
_node.UpdateOutputPin();
}
}
public void Initialize()
{
if (Modules != null)
return;
Modules = new BindableCollection<Module>();
if (_node.Script.Context is Profile scriptProfile && scriptProfile.Configuration.Module != null)
Modules.Add(scriptProfile.Configuration.Module);
else if (_node.Script.Context is ProfileConfiguration profileConfiguration && profileConfiguration.Module != null)
Modules.Add(profileConfiguration.Module);
}
#region Overrides of CustomNodeViewModel
/// <inheritdoc />
protected override void OnDisplay()
{
Initialize();
base.OnDisplay();
}
#endregion
}
}
@@ -1,24 +0,0 @@
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
{
public class StaticDoubleValueNodeCustomViewModel : CustomNodeViewModel
{
private readonly StaticDoubleValueNode _node;
public StaticDoubleValueNodeCustomViewModel(StaticDoubleValueNode node) : base(node)
{
_node = node;
}
public double Input
{
get => (double) _node.Storage;
set
{
_node.Storage = value;
OnPropertyChanged(nameof(Input));
}
}
}
}
@@ -1,29 +0,0 @@
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
{
public class StaticIntegerValueNodeCustomViewModel : CustomNodeViewModel
{
private readonly StaticIntegerValueNode _node;
public StaticIntegerValueNodeCustomViewModel(StaticIntegerValueNode node) : base(node)
{
_node = node;
}
public int Input
{
get
{
if (_node.Storage is long longInput)
return (int) longInput;
return (int) _node.Storage;
}
set
{
_node.Storage = value;
OnPropertyChanged(nameof(Input));
}
}
}
}
@@ -1,24 +0,0 @@
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
{
public class StaticStringValueNodeCustomViewModel : CustomNodeViewModel
{
private readonly StaticStringValueNode _node;
public StaticStringValueNodeCustomViewModel(StaticStringValueNode node) : base(node)
{
_node = node;
}
public string Input
{
get => (string) _node.Storage;
set
{
_node.Storage = value;
OnPropertyChanged(nameof(Input));
}
}
}
}
@@ -0,0 +1,89 @@
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
{
public class StaticDoubleValueNodeCustomViewModel : CustomNodeViewModel
{
private readonly StaticDoubleValueNode _node;
public StaticDoubleValueNodeCustomViewModel(StaticDoubleValueNode node) : base(node)
{
_node = node;
}
public double Input
{
get => (double) _node.Storage;
set
{
_node.Storage = value;
OnPropertyChanged(nameof(Input));
}
}
}
public class StaticFloatValueNodeCustomViewModel : CustomNodeViewModel
{
private readonly StaticFloatValueNode _node;
public StaticFloatValueNodeCustomViewModel(StaticFloatValueNode node) : base(node)
{
_node = node;
}
public float Input
{
get => (float)_node.Storage;
set
{
_node.Storage = value;
OnPropertyChanged(nameof(Input));
}
}
}
public class StaticIntegerValueNodeCustomViewModel : CustomNodeViewModel
{
private readonly StaticIntegerValueNode _node;
public StaticIntegerValueNodeCustomViewModel(StaticIntegerValueNode node) : base(node)
{
_node = node;
}
public int Input
{
get
{
if (_node.Storage is long longInput)
return (int)longInput;
return (int)_node.Storage;
}
set
{
_node.Storage = value;
OnPropertyChanged(nameof(Input));
}
}
}
public class StaticStringValueNodeCustomViewModel : CustomNodeViewModel
{
private readonly StaticStringValueNode _node;
public StaticStringValueNodeCustomViewModel(StaticStringValueNode node) : base(node)
{
_node = node;
}
public string Input
{
get => (string)_node.Storage;
set
{
_node.Storage = value;
OnPropertyChanged(nameof(Input));
}
}
}
}
@@ -8,5 +8,5 @@
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<controls:DataModelPicker DataModelPath="{Binding DataModelPath}" ButtonBrush="#434343"/>
<controls:DataModelPicker DataModelPath="{Binding DataModelPath}" Modules="{Binding Modules}" ButtonBrush="#434343"/>
</UserControl>
@@ -0,0 +1,12 @@
<UserControl x:Class="Artemis.VisualScripting.Nodes.CustomViews.StaticFloatValueNodeCustomView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.VisualScripting.Nodes.CustomViewModels"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<TextBox VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Text="{Binding Input}" />
</UserControl>
@@ -13,18 +13,21 @@ namespace Artemis.VisualScripting.Nodes
{
}
public INodeScript Script { get; private set; }
public OutputPin Output { get; private set; }
public DataModelPath DataModelPath { get; set; }
public override void Initialize()
public override void Initialize(INodeScript script)
{
if (Storage is not DataModelPathEntity pathEntity)
Script = script;
if (Storage is not DataModelPathEntity pathEntity)
return;
DataModelPath = new DataModelPath(null, pathEntity);
UpdateOutputPin();
}
public override void Evaluate()
{
if (DataModelPath.IsValid && Output != null)
@@ -29,7 +29,7 @@ namespace Artemis.VisualScripting.Nodes
Output.Value = Storage as int? ?? 0;
}
public override void Initialize() => Storage ??= 0;
public override void Initialize(INodeScript script) => Storage ??= 0;
#endregion
}
@@ -60,7 +60,38 @@ namespace Artemis.VisualScripting.Nodes
Output.Value = Storage as double? ?? 0.0;
}
public override void Initialize() => Storage ??= 0.0;
public override void Initialize(INodeScript script) => Storage ??= 0.0;
#endregion
}
[Node("Float-Value", "Outputs a configurable float value.")]
public class StaticFloatValueNode : Node<StaticFloatValueNodeCustomViewModel>
{
#region Properties & Fields
public OutputPin<float> Output { get; }
#endregion
#region Constructors
public StaticFloatValueNode()
: base("Float", "Outputs a configurable float value.")
{
Output = CreateOutputPin<float>();
}
#endregion
#region Methods
public override void Evaluate()
{
Output.Value = Storage as float? ?? 0.0f;
}
public override void Initialize(INodeScript script) => Storage ??= 0.0f;
#endregion
}
@@ -35,6 +35,38 @@ namespace Artemis.VisualScripting.Nodes
#endregion
}
[Node("Sum (Float)", "Sums the connected float values.")]
public class SumFloatsNode : Node
{
#region Properties & Fields
public InputPinCollection<float> Values { get; }
public OutputPin<float> Sum { get; }
#endregion
#region Constructors
public SumFloatsNode()
: base("Sum", "Sums the connected float values.")
{
Values = CreateInputPinCollection<float>("Values", 2);
Sum = CreateOutputPin<float>("Sum");
}
#endregion
#region Methods
public override void Evaluate()
{
Sum.Value = Values.Values.Sum();
}
#endregion
}
[Node("Sum (Double)", "Sums the connected double values.")]
public class SumDoublesNode : Node
{