Nodes - Implemented saving/loading

Nodes - Added data model node
This commit is contained in:
Robert committed 2021-08-10 16:52:24 +02:00
1 parent 61d7f1e1fb
commit afc4bee7ac
29 files changed
+730 -157

No files matched your search

@@ -0,0 +1,42 @@
using Artemis.Core;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Input;
using Artemis.UI.Shared.Services;
using Stylet;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
{
public class DataModelNodeCustomViewModel : CustomNodeViewModel
{
private readonly DataModelNode _node;
public DataModelNodeCustomViewModel(DataModelNode node, IDataModelUIService dataModelUIService) : base(node)
{
_node = node;
Execute.OnUIThreadSync(() =>
{
SelectionViewModel = dataModelUIService.GetDynamicSelectionViewModel(module: null);
SelectionViewModel.PropertySelected += SelectionViewModelOnPropertySelected;
});
}
public DataModelDynamicViewModel SelectionViewModel { get; set; }
private void SelectionViewModelOnPropertySelected(object? sender, DataModelInputDynamicEventArgs e)
{
_node.DataModelPath = SelectionViewModel.DataModelPath;
if (_node.DataModelPath != null)
{
_node.DataModelPath.Save();
_node.Storage = _node.DataModelPath.Entity;
}
else
{
_node.Storage = null;
}
_node.UpdateOutputPin();
}
}
}
@@ -1,15 +1,24 @@
using Stylet;
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
{
public class StaticDoubleValueNodeCustomViewModel : PropertyChangedBase
public class StaticDoubleValueNodeCustomViewModel : CustomNodeViewModel
{
private double _input;
private readonly StaticDoubleValueNode _node;
public StaticDoubleValueNodeCustomViewModel(StaticDoubleValueNode node) : base(node)
{
_node = node;
}
public double Input
{
get => _input;
set => SetAndNotify(ref _input, value);
get => (double) _node.Storage;
set
{
_node.Storage = value;
OnPropertyChanged(nameof(Input));
}
}
}
}
@@ -1,15 +1,24 @@
using Stylet;
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
{
public class StaticIntegerValueNodeCustomViewModel : PropertyChangedBase
public class StaticIntegerValueNodeCustomViewModel : CustomNodeViewModel
{
private int _input;
private readonly StaticIntegerValueNode _node;
public StaticIntegerValueNodeCustomViewModel(StaticIntegerValueNode node) : base(node)
{
_node = node;
}
public int Input
{
get => _input;
set => SetAndNotify(ref _input, value);
get => (int)(long) _node.Storage;
set
{
_node.Storage = value;
OnPropertyChanged(nameof(Input));
}
}
}
}
@@ -1,15 +1,24 @@
using Stylet;
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
{
public class StaticStringValueNodeCustomViewModel : PropertyChangedBase
public class StaticStringValueNodeCustomViewModel : CustomNodeViewModel
{
private string _input;
private readonly StaticStringValueNode _node;
public StaticStringValueNodeCustomViewModel(StaticStringValueNode node) : base(node)
{
_node = node;
}
public string Input
{
get => _input;
set => SetAndNotify(ref _input, value);
get => (string) _node.Storage;
set
{
_node.Storage = value;
OnPropertyChanged(nameof(Input));
}
}
}
}
@@ -0,0 +1,11 @@
<UserControl x:Class="Artemis.VisualScripting.Nodes.CustomViews.DataModelNodeCustomView"
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.CustomViews"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<ContentControl s:View.Model="{Binding SelectionViewModel}"></ContentControl>
</UserControl>
@@ -0,0 +1,48 @@
using System;
using System.Linq;
using Artemis.Core;
using Artemis.Storage.Entities.Profile;
using Artemis.VisualScripting.Nodes.CustomViewModels;
namespace Artemis.VisualScripting.Nodes
{
[Node("Data Model-Value", "Outputs a selectable data model value.")]
public class DataModelNode : Node<DataModelNodeCustomViewModel>
{
public DataModelNode() : base("Data Model", "Outputs a selectable data model value")
{
}
public OutputPin Output { get; private set; }
public DataModelPath DataModelPath { get; set; }
public override void Initialize()
{
if (Storage is not DataModelPathEntity pathEntity)
return;
DataModelPath = new DataModelPath(null, pathEntity);
CustomViewModel.SelectionViewModel.ChangeDataModelPath(DataModelPath);
UpdateOutputPin();
}
public override void Evaluate()
{
if (DataModelPath.IsValid && Output != null)
Output.Value = DataModelPath.GetValue()!;
}
public void UpdateOutputPin()
{
if (Pins.Contains(Output))
{
RemovePin(Output);
Output = null;
}
Type type = DataModelPath?.GetPropertyType();
if (type != null)
Output = CreateOutputPin(type);
}
}
}
@@ -26,9 +26,11 @@ namespace Artemis.VisualScripting.Nodes
public override void Evaluate()
{
Output.Value = CustomViewModel.Input;
Output.Value = (int) (Storage as long? ?? 0);
}
public override void Initialize() => Storage ??= 0;
#endregion
}
@@ -55,9 +57,11 @@ namespace Artemis.VisualScripting.Nodes
public override void Evaluate()
{
Output.Value = CustomViewModel.Input;
Output.Value = Storage as double? ?? 0.0;
}
public override void Initialize() => Storage ??= 0.0;
#endregion
}
@@ -84,9 +88,9 @@ namespace Artemis.VisualScripting.Nodes
public override void Evaluate()
{
Output.Value = CustomViewModel.Input;
Output.Value = Storage as string;
}
#endregion
}