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

@@ -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));
}
}
}
}