Nodes - Support dynamic children in data model node

This commit is contained in:
Robert committed 2021-08-25 20:40:24 +02:00
1 parent bd3bf20d92
commit 4fbd229846
9 files changed
+165 -76

No files matched your search

@@ -11,10 +11,12 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
private readonly DataModelNode _node;
private BindableCollection<Module> _modules;
public DataModelNodeCustomViewModel(DataModelNode node, ISettingsService settingsService) : base(node)
public DataModelNodeCustomViewModel(DataModelNode node, ISettingsService settingsService, IPluginManagementService test) : base(node)
{
_node = node;
var tessst = test.GetFeaturesOfType<Module>();
ShowFullPaths = settingsService.GetSetting("ProfileEditor.ShowFullPaths", true);
ShowDataModelValues = settingsService.GetSetting("ProfileEditor.ShowDataModelValues", false);
}
@@ -33,19 +35,15 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
get => _node.DataModelPath;
set
{
if (ReferenceEquals(_node.DataModelPath, value))
return;
_node.DataModelPath.Dispose();
_node.DataModelPath = value;
_node.DataModelPath.Save();
if (_node.DataModelPath != null)
{
_node.DataModelPath.Save();
_node.Storage = _node.DataModelPath.Entity;
}
else
{
_node.Storage = null;
}
_node.UpdateOutputPin();
_node.Storage = _node.DataModelPath.Entity;
_node.UpdateOutputPin(false);
}
}
@@ -3,11 +3,12 @@ using System.Linq;
using Artemis.Core;
using Artemis.Storage.Entities.Profile;
using Artemis.VisualScripting.Nodes.CustomViewModels;
using Stylet;
namespace Artemis.VisualScripting.Nodes
{
[Node("Data Model-Value", "Outputs a selectable data model value.")]
public class DataModelNode : Node<DataModelNodeCustomViewModel>
public class DataModelNode : Node<DataModelNodeCustomViewModel>, IDisposable
{
private DataModelPath _dataModelPath;
@@ -21,7 +22,7 @@ namespace Artemis.VisualScripting.Nodes
public DataModelPath DataModelPath
{
get => _dataModelPath;
set => SetAndNotify(ref _dataModelPath , value);
set => SetAndNotify(ref _dataModelPath, value);
}
public override void Initialize(INodeScript script)
@@ -32,29 +33,58 @@ namespace Artemis.VisualScripting.Nodes
return;
DataModelPath = new DataModelPath(null, pathEntity);
UpdateOutputPin();
DataModelPath.PathValidated += DataModelPathOnPathValidated;
UpdateOutputPin(false);
}
public override void Evaluate()
{
if (DataModelPath.IsValid && Output != null)
Output.Value = DataModelPath.GetValue()!;
}
public void UpdateOutputPin()
{
if (Output != null && Output.Type == DataModelPath?.GetPropertyType())
return;
if (Output != null && Pins.Contains(Output))
if (DataModelPath.IsValid)
{
RemovePin(Output);
Output = null;
}
if (Output == null)
UpdateOutputPin(false);
Type type = DataModelPath?.GetPropertyType();
if (type != null)
Output = CreateOutputPin(type);
Output.Value = DataModelPath.GetValue() ?? Output.Type.GetDefault();
}
}
public void UpdateOutputPin(bool loadConnections)
{
Execute.OnUIThread(() =>
{
if (Output != null && Output.Type == DataModelPath?.GetPropertyType())
return;
if (Output != null)
{
RemovePin(Output);
Output = null;
}
Type type = DataModelPath?.GetPropertyType();
if (type != null)
Output = CreateOutputPin(type);
if (loadConnections && Script is NodeScript nodeScript)
nodeScript.LoadConnections();
});
}
private void DataModelPathOnPathValidated(object sender, EventArgs e)
{
UpdateOutputPin(true);
}
#region IDisposable
/// <inheritdoc />
public void Dispose()
{
DataModelPath.Dispose();
}
#endregion
}
}