Nodes - Added event value cycle node

This commit is contained in:
Robert committed 2021-09-20 22:55:10 +02:00
1 parent 02f4609eae
commit 8413b8d6db
13 files changed
+195 -74

No files matched your search

@@ -3,9 +3,10 @@ using System.ComponentModel;
using Artemis.Core;
using Artemis.Core.Modules;
using Artemis.Core.Services;
using Artemis.VisualScripting.Nodes.CustomViewModels;
using Stylet;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
namespace Artemis.VisualScripting.Nodes.DataModel.CustomViewModels
{
public class DataModelEventNodeCustomViewModel : CustomNodeViewModel
{
@@ -22,7 +23,7 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
public PluginSetting<bool> ShowFullPaths { get; }
public PluginSetting<bool> ShowDataModelValues { get; }
public BindableCollection<Type> FilterTypes { get; } = new() { typeof(DataModelEvent) };
public BindableCollection<Type> FilterTypes { get; } = new() { typeof(IDataModelEvent) };
public BindableCollection<Module> Modules
{
@@ -2,9 +2,10 @@
using Artemis.Core;
using Artemis.Core.Modules;
using Artemis.Core.Services;
using Artemis.VisualScripting.Nodes.CustomViewModels;
using Stylet;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
namespace Artemis.VisualScripting.Nodes.DataModel.CustomViewModels
{
public class DataModelNodeCustomViewModel : CustomNodeViewModel
{
@@ -1,4 +1,4 @@
<UserControl x:Class="Artemis.VisualScripting.Nodes.CustomViews.DataModelEventNodeCustomView"
<UserControl x:Class="Artemis.VisualScripting.Nodes.DataModel.CustomViews.DataModelEventNodeCustomView"
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"
@@ -15,8 +15,7 @@
ShowFullPath="{Binding ShowFullPaths.Value}"
ShowDataModelValues="{Binding ShowDataModelValues.Value}"
FilterTypes="{Binding FilterTypes}"
ButtonBrush="#434343"/>
<editor:VisualScriptPresenter Script="{Binding ChildScript}" IsEnabled="False" ></editor:VisualScriptPresenter>
ButtonBrush="DarkGoldenrod"/>
</StackPanel>
</UserControl>
@@ -1,4 +1,4 @@
<UserControl x:Class="Artemis.VisualScripting.Nodes.CustomViews.DataModelNodeCustomView"
<UserControl x:Class="Artemis.VisualScripting.Nodes.DataModel.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"
@@ -0,0 +1,109 @@
using System;
using System.Linq;
using Artemis.Core;
using Artemis.Core.Events;
using Artemis.Storage.Entities.Profile;
using Artemis.VisualScripting.Nodes.DataModel.CustomViewModels;
namespace Artemis.VisualScripting.Nodes.DataModel
{
[Node("Data Model-Event", "Responds to a data model event trigger", "External", OutputType = typeof(bool))]
public class DataModelEventNode : Node<DataModelEventNodeCustomViewModel>, IDisposable
{
private DataModelPath _dataModelPath;
private DateTime _lastTrigger;
private int _currentIndex;
public DataModelEventNode() : base("Data Model-Event", "Responds to a data model event trigger")
{
Input = CreateInputPin<object>();
Input.PinConnected += InputOnPinConnected;
}
public InputPin<object> Input { get; }
public InputPinCollection CycleValues { get; set; }
public OutputPin Output { get; set; }
public INodeScript Script { get; set; }
public DataModelPath DataModelPath
{
get => _dataModelPath;
set => SetAndNotify(ref _dataModelPath, value);
}
public override void Initialize(INodeScript script)
{
Script = script;
CreateCycleValues();
CreateOutput();
if (Storage is not DataModelPathEntity pathEntity)
return;
DataModelPath = new DataModelPath(pathEntity);
}
public override void Evaluate()
{
object outputValue = null;
if (DataModelPath?.GetValue() is DataModelEvent dataModelEvent)
{
if (dataModelEvent.LastTrigger > _lastTrigger)
{
_lastTrigger = dataModelEvent.LastTrigger;
_currentIndex++;
if (_currentIndex > CycleValues.Count())
_currentIndex = 0;
}
outputValue = _currentIndex == 0
? Input.Value
: CycleValues.ElementAt(_currentIndex - 1).PinValue;
}
Output.Value = outputValue ?? Output.Type.GetDefault();
}
private void InputOnPinConnected(object sender, SingleValueEventArgs<IPin> e)
{
CreateCycleValues();
CreateOutput();
}
private void CreateCycleValues()
{
int pinCount = CycleValues?.Count() ?? 1;
Type inputType = Input.ConnectedTo.FirstOrDefault()?.Type ?? typeof(object);
if (CycleValues != null)
{
if (inputType == CycleValues.Type)
return;
RemovePinCollection(CycleValues);
}
CycleValues = CreateInputPinCollection(inputType, "", pinCount);
}
private void CreateOutput()
{
Type inputType = Input.ConnectedTo.FirstOrDefault()?.Type ?? typeof(object);
if (Output != null)
{
if (inputType == Output.Type)
return;
RemovePin(Output);
}
Output = CreateOutputPin(inputType);
}
/// <inheritdoc />
public void Dispose()
{
}
}
}
@@ -1,11 +1,10 @@
using System;
using System.Linq;
using Artemis.Core;
using Artemis.Storage.Entities.Profile;
using Artemis.VisualScripting.Nodes.CustomViewModels;
using Artemis.VisualScripting.Nodes.DataModel.CustomViewModels;
using Stylet;
namespace Artemis.VisualScripting.Nodes
namespace Artemis.VisualScripting.Nodes.DataModel
{
[Node("Data Model-Value", "Outputs a selectable data model value.", "External")]
public class DataModelNode : Node<DataModelNodeCustomViewModel>, IDisposable
@@ -1,51 +0,0 @@
using System;
using Artemis.Core;
using Artemis.Storage.Entities.Profile;
using Artemis.VisualScripting.Nodes.CustomViewModels;
namespace Artemis.VisualScripting.Nodes
{
[Node("Data Model-Event", "Responds to a data model event trigger", "External", OutputType = typeof(bool))]
public class DataModelEventNode : Node<DataModelEventNodeCustomViewModel>, IDisposable
{
private DataModelPath _dataModelPath;
public DataModelEventNode() : base("Data Model-Event", "Responds to a data model event trigger")
{
Output = CreateOutputPin<bool>();
}
public OutputPin<bool> Output { get; }
public INodeScript Script { get; set; }
public DataModelPath DataModelPath
{
get => _dataModelPath;
set => SetAndNotify(ref _dataModelPath, value);
}
public override void Initialize(INodeScript script)
{
Script = script;
if (Storage is not DataModelPathEntity pathEntity)
return;
DataModelPath = new DataModelPath(pathEntity);
DataModelPath.PathValidated += DataModelPathOnPathValidated;
}
public override void Evaluate()
{
}
private void DataModelPathOnPathValidated(object sender, EventArgs e)
{
}
/// <inheritdoc />
public void Dispose()
{
}
}
}