mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 20:06:33 +00:00
Nodes - Added event value cycle node
This commit is contained in:
1 parent
02f4609eae
commit
8413b8d6db
13 files changed
+195
-74
No files matched your search
+3
-2
@@ -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
-1
@@ -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
|
||||
{
|
||||
|
||||
+2
-3
@@ -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
-1
@@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using Artemis.Core;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.VisualScripting.Nodes.DataModel.CustomViewModels;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.DataModel
|
||||
{
|
||||
[Node("Data Model-Value", "Outputs a selectable data model value.", "External")]
|
||||
public class DataModelNode : Node<DataModelNodeCustomViewModel>, IDisposable
|
||||
{
|
||||
private DataModelPath _dataModelPath;
|
||||
|
||||
public DataModelNode() : base("Data Model", "Outputs a selectable data model value")
|
||||
{
|
||||
}
|
||||
|
||||
public INodeScript Script { get; private set; }
|
||||
public OutputPin Output { get; private 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;
|
||||
|
||||
UpdateOutputPin(false);
|
||||
}
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
if (DataModelPath.IsValid)
|
||||
{
|
||||
if (Output == null)
|
||||
UpdateOutputPin(false);
|
||||
|
||||
object pathValue = DataModelPath.GetValue();
|
||||
if (pathValue != null)
|
||||
Output.Value = pathValue;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user