mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Nodes - Changed storage to be based on generics
Nodes - Added XML docs to most types
This commit is contained in:
1 parent
8413b8d6db
commit
c1dab91c16
28 files changed
+522
-347
No files matched your search
@@ -155,10 +155,10 @@ namespace Artemis.VisualScripting.Editor.Controls
|
||||
{
|
||||
CustomViewModel?.OnDeactivate();
|
||||
|
||||
if (Node?.Node is CustomViewModelNode customViewModelNode)
|
||||
if (Node?.Node is Node customViewModelNode)
|
||||
{
|
||||
CustomViewModel = customViewModelNode.GetCustomViewModel();
|
||||
CustomViewModel.OnActivate();
|
||||
CustomViewModel?.OnActivate();
|
||||
}
|
||||
else
|
||||
CustomViewModel = null;
|
||||
|
||||
+1
-28
@@ -1,38 +1,11 @@
|
||||
using System.ComponentModel;
|
||||
using Artemis.VisualScripting.Nodes.CustomViewModels;
|
||||
using SkiaSharp;
|
||||
using Artemis.VisualScripting.Nodes.CustomViewModels;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Color.CustomViewModels
|
||||
{
|
||||
public class StaticSKColorValueNodeCustomViewModel : CustomNodeViewModel
|
||||
{
|
||||
private readonly StaticSKColorValueNode _node;
|
||||
|
||||
public StaticSKColorValueNodeCustomViewModel(StaticSKColorValueNode node) : base(node)
|
||||
{
|
||||
_node = node;
|
||||
}
|
||||
|
||||
public SKColor Input
|
||||
{
|
||||
get => (SKColor) (_node.Storage ?? SKColor.Empty);
|
||||
set => _node.Storage = value;
|
||||
}
|
||||
|
||||
public override void OnActivate()
|
||||
{
|
||||
_node.PropertyChanged += NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
_node.PropertyChanged -= NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
private void NodeOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Node.Storage))
|
||||
OnPropertyChanged(nameof(Input));
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -12,5 +12,5 @@
|
||||
</UserControl.Resources>
|
||||
<shared:ColorPicker VerticalAlignment="Center"
|
||||
HorizontalAlignment="Stretch"
|
||||
Color="{Binding Input, Converter={StaticResource SKColorToColorConverter}}" />
|
||||
Color="{Binding Node.Storage, Converter={StaticResource SKColorToColorConverter}}" />
|
||||
</UserControl>
|
||||
@@ -5,7 +5,7 @@ using SkiaSharp;
|
||||
namespace Artemis.VisualScripting.Nodes.Color
|
||||
{
|
||||
[Node("Color-Value", "Outputs a configurable color value.", "Static", InputType = typeof(SKColor), OutputType = typeof(SKColor))]
|
||||
public class StaticSKColorValueNode : Node<StaticSKColorValueNodeCustomViewModel>
|
||||
public class StaticSKColorValueNode : Node<SKColor, StaticSKColorValueNodeCustomViewModel>
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
@@ -27,17 +27,9 @@ namespace Artemis.VisualScripting.Nodes.Color
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
Output.Value = Storage as SKColor? ?? SKColor.Empty;
|
||||
Output.Value = Storage;
|
||||
}
|
||||
|
||||
public override void Initialize(INodeScript script)
|
||||
{
|
||||
if (Storage is string && SKColor.TryParse(Storage.ToString(), out SKColor parsed))
|
||||
Storage = parsed;
|
||||
else
|
||||
Storage = SKColor.Empty;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+1
-17
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.UI.Shared;
|
||||
using Stylet;
|
||||
@@ -16,19 +14,12 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
||||
_node = node;
|
||||
}
|
||||
|
||||
public Enum Input
|
||||
{
|
||||
get => _node.Storage as Enum;
|
||||
set => _node.Storage = value;
|
||||
}
|
||||
|
||||
public BindableCollection<ValueDescription> EnumValues { get; } = new();
|
||||
|
||||
public override void OnActivate()
|
||||
{
|
||||
_node.InputPin.PinConnected += InputPinOnPinConnected;
|
||||
_node.InputPin.PinDisconnected += InputPinOnPinDisconnected;
|
||||
_node.PropertyChanged += NodeOnPropertyChanged;
|
||||
|
||||
if (_node.InputPin.Value != null && _node.InputPin.Value.GetType().IsEnum)
|
||||
EnumValues.AddRange(EnumUtilities.GetAllValuesAndDescriptions(_node.InputPin.Value.GetType()));
|
||||
@@ -39,7 +30,6 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
||||
{
|
||||
_node.InputPin.PinConnected -= InputPinOnPinConnected;
|
||||
_node.InputPin.PinDisconnected -= InputPinOnPinDisconnected;
|
||||
_node.PropertyChanged -= NodeOnPropertyChanged;
|
||||
|
||||
base.OnDeactivate();
|
||||
}
|
||||
@@ -55,11 +45,5 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
||||
if (_node.InputPin.Value != null && _node.InputPin.Value.GetType().IsEnum)
|
||||
EnumValues.AddRange(EnumUtilities.GetAllValuesAndDescriptions(_node.InputPin.Value.GetType()));
|
||||
}
|
||||
|
||||
private void NodeOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Node.Storage))
|
||||
OnPropertyChanged(nameof(Input));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,132 +1,32 @@
|
||||
using System.ComponentModel;
|
||||
using Artemis.Core;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
||||
{
|
||||
public class StaticDoubleValueNodeCustomViewModel : CustomNodeViewModel
|
||||
{
|
||||
private readonly StaticDoubleValueNode _node;
|
||||
|
||||
public StaticDoubleValueNodeCustomViewModel(StaticDoubleValueNode node) : base(node)
|
||||
public StaticDoubleValueNodeCustomViewModel(INode node) : base(node)
|
||||
{
|
||||
_node = node;
|
||||
}
|
||||
|
||||
public double Input
|
||||
{
|
||||
get => (double) (_node.Storage ?? 0.0);
|
||||
set => _node.Storage = value;
|
||||
}
|
||||
|
||||
public override void OnActivate()
|
||||
{
|
||||
_node.PropertyChanged += NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
_node.PropertyChanged -= NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
private void NodeOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Node.Storage))
|
||||
OnPropertyChanged(nameof(Input));
|
||||
}
|
||||
}
|
||||
|
||||
public class StaticFloatValueNodeCustomViewModel : CustomNodeViewModel
|
||||
{
|
||||
private readonly StaticFloatValueNode _node;
|
||||
|
||||
public StaticFloatValueNodeCustomViewModel(StaticFloatValueNode node) : base(node)
|
||||
public StaticFloatValueNodeCustomViewModel(INode node) : base(node)
|
||||
{
|
||||
_node = node;
|
||||
}
|
||||
|
||||
public float Input
|
||||
{
|
||||
get => (float) (_node.Storage ?? 0f);
|
||||
set => _node.Storage = value;
|
||||
}
|
||||
|
||||
public override void OnActivate()
|
||||
{
|
||||
_node.PropertyChanged += NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
_node.PropertyChanged -= NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
private void NodeOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Node.Storage))
|
||||
OnPropertyChanged(nameof(Input));
|
||||
}
|
||||
}
|
||||
|
||||
public class StaticIntegerValueNodeCustomViewModel : CustomNodeViewModel
|
||||
{
|
||||
private readonly StaticIntegerValueNode _node;
|
||||
|
||||
public StaticIntegerValueNodeCustomViewModel(StaticIntegerValueNode node) : base(node)
|
||||
public StaticIntegerValueNodeCustomViewModel(INode node) : base(node)
|
||||
{
|
||||
_node = node;
|
||||
}
|
||||
|
||||
public int Input
|
||||
{
|
||||
get => _node.Storage is long longInput ? (int) longInput : (int) (_node.Storage ?? 0);
|
||||
set => _node.Storage = value;
|
||||
}
|
||||
|
||||
public override void OnActivate()
|
||||
{
|
||||
_node.PropertyChanged += NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
_node.PropertyChanged -= NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
private void NodeOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Node.Storage))
|
||||
OnPropertyChanged(nameof(Input));
|
||||
}
|
||||
}
|
||||
|
||||
public class StaticStringValueNodeCustomViewModel : CustomNodeViewModel
|
||||
{
|
||||
private readonly StaticStringValueNode _node;
|
||||
|
||||
public StaticStringValueNodeCustomViewModel(StaticStringValueNode node) : base(node)
|
||||
public StaticStringValueNodeCustomViewModel(INode node) : base(node)
|
||||
{
|
||||
_node = node;
|
||||
}
|
||||
|
||||
public string Input
|
||||
{
|
||||
get => (string) _node.Storage;
|
||||
set => _node.Storage = value;
|
||||
}
|
||||
|
||||
public override void OnActivate()
|
||||
{
|
||||
_node.PropertyChanged += NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
_node.PropertyChanged -= NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
private void NodeOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Node.Storage))
|
||||
OnPropertyChanged(nameof(Input));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
materialDesign:ComboBoxAssist.ClassicMode="True"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Stretch"
|
||||
SelectedValue="{Binding Input}"
|
||||
SelectedValue="{Binding Node.Storage}"
|
||||
ItemsSource="{Binding EnumValues}"
|
||||
SelectedValuePath="Value"
|
||||
DisplayMemberPath="Description">
|
||||
|
||||
@@ -8,5 +8,5 @@
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<TextBox VerticalAlignment="Center"
|
||||
HorizontalAlignment="Stretch"
|
||||
Text="{Binding Input}" />
|
||||
Text="{Binding Node.Storage}" />
|
||||
</UserControl>
|
||||
@@ -8,5 +8,5 @@
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<TextBox VerticalAlignment="Center"
|
||||
HorizontalAlignment="Stretch"
|
||||
Text="{Binding Input}" />
|
||||
Text="{Binding Node.Storage}" />
|
||||
</UserControl>
|
||||
@@ -8,5 +8,5 @@
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<TextBox VerticalAlignment="Center"
|
||||
HorizontalAlignment="Stretch"
|
||||
Text="{Binding Input}" />
|
||||
Text="{Binding Node.Storage}" />
|
||||
</UserControl>
|
||||
@@ -8,5 +8,5 @@
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<TextBox VerticalAlignment="Center"
|
||||
HorizontalAlignment="Stretch"
|
||||
Text="{Binding Input}" />
|
||||
Text="{Binding Node.Storage}" />
|
||||
</UserControl>
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Events;
|
||||
@@ -8,19 +9,69 @@ 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
|
||||
public class DataModelEventNode : Node<DataModelPathEntity, DataModelEventNodeCustomViewModel>, IDisposable
|
||||
{
|
||||
private DataModelPath _dataModelPath;
|
||||
private DateTime _lastTrigger;
|
||||
private int _currentIndex;
|
||||
private Type _currentType;
|
||||
private bool _updating;
|
||||
|
||||
public DataModelEventNode() : base("Data Model-Event", "Responds to a data model event trigger")
|
||||
{
|
||||
Input = CreateInputPin<object>();
|
||||
Input.PinConnected += InputOnPinConnected;
|
||||
_currentType = typeof(object);
|
||||
CreateCycleValues(typeof(object), 1);
|
||||
Output = CreateOutputPin(typeof(object));
|
||||
}
|
||||
|
||||
public InputPin<object> Input { get; }
|
||||
private void CreateCycleValues(Type type, int initialCount)
|
||||
{
|
||||
if (CycleValues != null)
|
||||
{
|
||||
CycleValues.PinAdded -= CycleValuesOnPinAdded;
|
||||
CycleValues.PinRemoved -= CycleValuesOnPinRemoved;
|
||||
foreach (IPin pin in CycleValues)
|
||||
{
|
||||
pin.PinConnected -= OnPinConnected;
|
||||
pin.PinDisconnected -= OnPinDisconnected;
|
||||
}
|
||||
|
||||
RemovePinCollection(CycleValues);
|
||||
}
|
||||
|
||||
CycleValues = CreateInputPinCollection(type, "", initialCount);
|
||||
CycleValues.PinAdded += CycleValuesOnPinAdded;
|
||||
CycleValues.PinRemoved += CycleValuesOnPinRemoved;
|
||||
foreach (IPin pin in CycleValues)
|
||||
{
|
||||
pin.PinConnected += OnPinConnected;
|
||||
pin.PinDisconnected += OnPinDisconnected;
|
||||
}
|
||||
}
|
||||
|
||||
private void CycleValuesOnPinAdded(object sender, SingleValueEventArgs<IPin> e)
|
||||
{
|
||||
e.Value.PinConnected += OnPinConnected;
|
||||
e.Value.PinDisconnected += OnPinDisconnected;
|
||||
}
|
||||
|
||||
private void CycleValuesOnPinRemoved(object sender, SingleValueEventArgs<IPin> e)
|
||||
{
|
||||
e.Value.PinConnected -= OnPinConnected;
|
||||
e.Value.PinDisconnected -= OnPinDisconnected;
|
||||
}
|
||||
|
||||
private void OnPinDisconnected(object sender, SingleValueEventArgs<IPin> e)
|
||||
{
|
||||
ProcessPinDisconnected();
|
||||
}
|
||||
|
||||
private void OnPinConnected(object sender, SingleValueEventArgs<IPin> e)
|
||||
{
|
||||
IPin source = e.Value;
|
||||
IPin target = (IPin) sender;
|
||||
ProcessPinConnected(source, target);
|
||||
}
|
||||
|
||||
public InputPinCollection CycleValues { get; set; }
|
||||
public OutputPin Output { get; set; }
|
||||
@@ -35,70 +86,101 @@ namespace Artemis.VisualScripting.Nodes.DataModel
|
||||
public override void Initialize(INodeScript script)
|
||||
{
|
||||
Script = script;
|
||||
CreateCycleValues();
|
||||
CreateOutput();
|
||||
|
||||
if (Storage is not DataModelPathEntity pathEntity)
|
||||
if (Storage == null)
|
||||
return;
|
||||
|
||||
DataModelPath = new DataModelPath(pathEntity);
|
||||
DataModelPath = new DataModelPath(Storage);
|
||||
}
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
object outputValue = null;
|
||||
if (DataModelPath?.GetValue() is DataModelEvent dataModelEvent)
|
||||
if (DataModelPath?.GetValue() is IDataModelEvent dataModelEvent)
|
||||
{
|
||||
if (dataModelEvent.LastTrigger > _lastTrigger)
|
||||
{
|
||||
_lastTrigger = dataModelEvent.LastTrigger;
|
||||
_currentIndex++;
|
||||
|
||||
if (_currentIndex > CycleValues.Count())
|
||||
if (_currentIndex >= CycleValues.Count())
|
||||
_currentIndex = 0;
|
||||
}
|
||||
|
||||
outputValue = _currentIndex == 0
|
||||
? Input.Value
|
||||
: CycleValues.ElementAt(_currentIndex - 1).PinValue;
|
||||
outputValue = CycleValues.ElementAt(_currentIndex).PinValue;
|
||||
}
|
||||
|
||||
Output.Value = outputValue ?? Output.Type.GetDefault();
|
||||
if (Output.Type.IsInstanceOfType(outputValue))
|
||||
Output.Value = outputValue;
|
||||
else if (Output.Type.IsValueType)
|
||||
Output.Value = Output.Type.GetDefault()!;
|
||||
}
|
||||
|
||||
private void InputOnPinConnected(object sender, SingleValueEventArgs<IPin> e)
|
||||
private void ProcessPinConnected(IPin source, IPin target)
|
||||
{
|
||||
CreateCycleValues();
|
||||
CreateOutput();
|
||||
}
|
||||
if (_updating)
|
||||
return;
|
||||
|
||||
private void CreateCycleValues()
|
||||
{
|
||||
int pinCount = CycleValues?.Count() ?? 1;
|
||||
Type inputType = Input.ConnectedTo.FirstOrDefault()?.Type ?? typeof(object);
|
||||
|
||||
if (CycleValues != null)
|
||||
try
|
||||
{
|
||||
if (inputType == CycleValues.Type)
|
||||
return;
|
||||
RemovePinCollection(CycleValues);
|
||||
}
|
||||
_updating = true;
|
||||
|
||||
CycleValues = CreateInputPinCollection(inputType, "", pinCount);
|
||||
// No need to change anything if the types haven't changed
|
||||
if (_currentType == source.Type)
|
||||
return;
|
||||
|
||||
int reconnectIndex = CycleValues.ToList().IndexOf(target);
|
||||
ChangeCurrentType(source.Type);
|
||||
|
||||
if (reconnectIndex != -1)
|
||||
{
|
||||
CycleValues.ToList()[reconnectIndex].ConnectTo(source);
|
||||
source.ConnectTo(CycleValues.ToList()[reconnectIndex]);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_updating = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateOutput()
|
||||
private void ChangeCurrentType(Type type)
|
||||
{
|
||||
Type inputType = Input.ConnectedTo.FirstOrDefault()?.Type ?? typeof(object);
|
||||
|
||||
if (Output != null)
|
||||
CreateCycleValues(type, CycleValues.Count());
|
||||
|
||||
List<IPin> oldOutputConnections = Output.ConnectedTo.ToList();
|
||||
RemovePin(Output);
|
||||
Output = CreateOutputPin(type);
|
||||
foreach (IPin oldOutputConnection in oldOutputConnections.Where(o => o.Type.IsAssignableFrom(Output.Type)))
|
||||
{
|
||||
if (inputType == Output.Type)
|
||||
return;
|
||||
RemovePin(Output);
|
||||
oldOutputConnection.DisconnectAll();
|
||||
oldOutputConnection.ConnectTo(Output);
|
||||
Output.ConnectTo(oldOutputConnection);
|
||||
}
|
||||
|
||||
Output = CreateOutputPin(inputType);
|
||||
_currentType = type;
|
||||
}
|
||||
|
||||
private void ProcessPinDisconnected()
|
||||
{
|
||||
if (_updating)
|
||||
return;
|
||||
try
|
||||
{
|
||||
// If there's still a connected pin, stick to the current type
|
||||
if (CycleValues.Any(v => v.ConnectedTo.Any()))
|
||||
return;
|
||||
|
||||
ChangeCurrentType(typeof(object));
|
||||
}
|
||||
finally
|
||||
{
|
||||
_updating = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePinsType(IPin source)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -7,7 +7,7 @@ using Stylet;
|
||||
namespace Artemis.VisualScripting.Nodes.DataModel
|
||||
{
|
||||
[Node("Data Model-Value", "Outputs a selectable data model value.", "External")]
|
||||
public class DataModelNode : Node<DataModelNodeCustomViewModel>, IDisposable
|
||||
public class DataModelNode : Node<DataModelPathEntity, DataModelNodeCustomViewModel>, IDisposable
|
||||
{
|
||||
private DataModelPath _dataModelPath;
|
||||
|
||||
@@ -28,10 +28,10 @@ namespace Artemis.VisualScripting.Nodes.DataModel
|
||||
{
|
||||
Script = script;
|
||||
|
||||
if (Storage is not DataModelPathEntity pathEntity)
|
||||
if (Storage == null)
|
||||
return;
|
||||
|
||||
DataModelPath = new DataModelPath(pathEntity);
|
||||
DataModelPath = new DataModelPath(Storage);
|
||||
DataModelPath.PathValidated += DataModelPathOnPathValidated;
|
||||
|
||||
UpdateOutputPin(false);
|
||||
|
||||
+9
-6
@@ -15,9 +15,7 @@ namespace Artemis.VisualScripting.Nodes.Easing.CustomViewModels
|
||||
public EasingTypeNodeCustomViewModel(EasingTypeNode node) : base(node)
|
||||
{
|
||||
_node = node;
|
||||
EasingViewModels = new BindableCollection<NodeEasingViewModel>(Enum.GetValues(typeof(Easings.Functions))
|
||||
.Cast<Easings.Functions>()
|
||||
.Select(e => new NodeEasingViewModel(e)));
|
||||
EasingViewModels = new BindableCollection<NodeEasingViewModel>(Enum.GetValues(typeof(Easings.Functions)).Cast<Easings.Functions>().Select(e => new NodeEasingViewModel(e)));
|
||||
}
|
||||
|
||||
public BindableCollection<NodeEasingViewModel> EasingViewModels { get; }
|
||||
@@ -35,7 +33,7 @@ namespace Artemis.VisualScripting.Nodes.Easing.CustomViewModels
|
||||
public override void OnActivate()
|
||||
{
|
||||
_node.PropertyChanged += NodeOnPropertyChanged;
|
||||
SelectedEasingViewModel = EasingViewModels.FirstOrDefault(vm => vm.EasingFunction == _node.EasingFunction);
|
||||
SelectedEasingViewModel = GetNodeEasingViewModel();
|
||||
}
|
||||
|
||||
public override void OnDeactivate()
|
||||
@@ -45,11 +43,16 @@ namespace Artemis.VisualScripting.Nodes.Easing.CustomViewModels
|
||||
|
||||
private void NodeOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Node.Storage))
|
||||
if (e.PropertyName == nameof(_node.Storage))
|
||||
{
|
||||
_selectedEasingViewModel = EasingViewModels.FirstOrDefault(vm => vm.EasingFunction == _node.EasingFunction);
|
||||
_selectedEasingViewModel = GetNodeEasingViewModel();
|
||||
NotifyOfPropertyChange(nameof(SelectedEasingViewModel));
|
||||
}
|
||||
}
|
||||
|
||||
private NodeEasingViewModel GetNodeEasingViewModel()
|
||||
{
|
||||
return EasingViewModels.FirstOrDefault(vm => vm.EasingFunction == _node.Storage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using Artemis.VisualScripting.Nodes.Easing.CustomViewModels;
|
||||
namespace Artemis.VisualScripting.Nodes.Easing
|
||||
{
|
||||
[Node("Easing Type", "Outputs a selectable easing type.", "Easing", OutputType = typeof(Easings.Functions))]
|
||||
public class EasingTypeNode : Node<EasingTypeNodeCustomViewModel>
|
||||
public class EasingTypeNode : Node<Easings.Functions, EasingTypeNodeCustomViewModel>
|
||||
{
|
||||
public EasingTypeNode() : base("Easing Type", "Outputs a selectable easing type.")
|
||||
{
|
||||
@@ -12,11 +12,10 @@ namespace Artemis.VisualScripting.Nodes.Easing
|
||||
}
|
||||
|
||||
public OutputPin<Easings.Functions> Output { get; }
|
||||
public Easings.Functions EasingFunction => Storage as Easings.Functions? ?? Easings.Functions.Linear;
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
Output.Value = EasingFunction;
|
||||
Output.Value = Storage;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.VisualScripting.Nodes.CustomViewModels;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes
|
||||
{
|
||||
[Node("Enum Equals", "Determines the equality between an input and a selected enum value", InputType = typeof(Enum), OutputType = typeof(bool))]
|
||||
public class EnumEqualsNode : Node<EnumEqualsNodeCustomViewModel>
|
||||
public class EnumEqualsNode : Node<Enum, EnumEqualsNodeCustomViewModel>
|
||||
{
|
||||
public EnumEqualsNode() : base("Enum Equals", "Determines the equality between an input and a selected enum value")
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ using Artemis.VisualScripting.Nodes.CustomViewModels;
|
||||
namespace Artemis.VisualScripting.Nodes
|
||||
{
|
||||
[Node("Layer/Folder Property", "Outputs the property of a selected layer or folder", "External")]
|
||||
public class LayerPropertyNode : Node<LayerPropertyNodeCustomViewModel>
|
||||
public class LayerPropertyNode : Node<LayerPropertyNodeEntity, LayerPropertyNodeCustomViewModel>
|
||||
{
|
||||
private readonly object _layerPropertyLock = new();
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Artemis.VisualScripting.Nodes
|
||||
{
|
||||
Script = script;
|
||||
|
||||
if (script.Context is Profile profile)
|
||||
if (script.Context is Profile profile)
|
||||
profile.ChildRemoved += ProfileOnChildRemoved;
|
||||
|
||||
LoadLayerProperty();
|
||||
@@ -54,15 +54,13 @@ namespace Artemis.VisualScripting.Nodes
|
||||
{
|
||||
lock (_layerPropertyLock)
|
||||
{
|
||||
if (Script.Context is not Profile profile)
|
||||
if (Script.Context is not Profile profile || Storage == null)
|
||||
return;
|
||||
if (Storage is not LayerPropertyNodeEntity entity)
|
||||
return;
|
||||
|
||||
RenderProfileElement element = profile.GetAllRenderElements().FirstOrDefault(l => l.EntityId == entity.ElementId);
|
||||
|
||||
RenderProfileElement element = profile.GetAllRenderElements().FirstOrDefault(l => l.EntityId == Storage.ElementId);
|
||||
|
||||
ProfileElement = element;
|
||||
LayerProperty = element?.GetAllLayerProperties().FirstOrDefault(p => p.Path == entity.PropertyPath);
|
||||
LayerProperty = element?.GetAllLayerProperties().FirstOrDefault(p => p.Path == Storage.PropertyPath);
|
||||
CreatePins();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-27
@@ -1,37 +1,12 @@
|
||||
using System.ComponentModel;
|
||||
using Artemis.Core;
|
||||
using Artemis.VisualScripting.Nodes.CustomViewModels;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Maths.CustomViewModels
|
||||
{
|
||||
public class MathExpressionNodeCustomViewModel : CustomNodeViewModel
|
||||
{
|
||||
private readonly MathExpressionNode _node;
|
||||
|
||||
public MathExpressionNodeCustomViewModel(MathExpressionNode node) : base(node)
|
||||
public MathExpressionNodeCustomViewModel(INode node) : base(node)
|
||||
{
|
||||
_node = node;
|
||||
}
|
||||
|
||||
public string Input
|
||||
{
|
||||
get => (string)_node.Storage;
|
||||
set => _node.Storage = value;
|
||||
}
|
||||
|
||||
public override void OnActivate()
|
||||
{
|
||||
_node.PropertyChanged += NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
_node.PropertyChanged -= NodeOnPropertyChanged;
|
||||
}
|
||||
|
||||
private void NodeOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Node.Storage))
|
||||
OnPropertyChanged(nameof(Input));
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -8,5 +8,5 @@
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<TextBox VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
Text="{Binding Input}" />
|
||||
Text="{Binding Node.Storage}" />
|
||||
</UserControl>
|
||||
@@ -9,12 +9,13 @@ using NoStringEvaluating.Models.Values;
|
||||
namespace Artemis.VisualScripting.Nodes.Maths
|
||||
{
|
||||
[Node("Math Expression", "Outputs the result of a math expression.", "Math", OutputType = typeof(int))]
|
||||
public class MathExpressionNode : Node<MathExpressionNodeCustomViewModel>
|
||||
public class MathExpressionNode : Node<string, MathExpressionNodeCustomViewModel>
|
||||
{
|
||||
private readonly INoStringEvaluator _evaluator;
|
||||
private readonly PinsVariablesContainer _variables;
|
||||
|
||||
#region Constructors
|
||||
|
||||
public MathExpressionNode(INoStringEvaluator evaluator)
|
||||
: base("Math Expression", "Outputs the result of a math expression.")
|
||||
{
|
||||
@@ -24,7 +25,7 @@ namespace Artemis.VisualScripting.Nodes.Maths
|
||||
Values.PinAdded += (_, _) => SetPinNames();
|
||||
Values.PinRemoved += (_, _) => SetPinNames();
|
||||
_variables = new PinsVariablesContainer(Values);
|
||||
|
||||
|
||||
SetPinNames();
|
||||
}
|
||||
|
||||
@@ -41,8 +42,8 @@ namespace Artemis.VisualScripting.Nodes.Maths
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
if (Storage is string formula)
|
||||
Output.Value = (float) _evaluator.CalcNumber(formula, _variables);
|
||||
if (Storage != null)
|
||||
Output.Value = (float) _evaluator.CalcNumber(Storage, _variables);
|
||||
}
|
||||
|
||||
private void SetPinNames()
|
||||
|
||||
@@ -4,7 +4,7 @@ using Artemis.VisualScripting.Nodes.CustomViewModels;
|
||||
namespace Artemis.VisualScripting.Nodes
|
||||
{
|
||||
[Node("Integer-Value", "Outputs an configurable integer value.", "Static", OutputType = typeof(int))]
|
||||
public class StaticIntegerValueNode : Node<StaticIntegerValueNodeCustomViewModel>
|
||||
public class StaticIntegerValueNode : Node<int, StaticIntegerValueNodeCustomViewModel>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@@ -26,16 +26,14 @@ namespace Artemis.VisualScripting.Nodes
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
Output.Value = Storage as int? ?? 0;
|
||||
Output.Value = Storage;
|
||||
}
|
||||
|
||||
public override void Initialize(INodeScript script) => Storage ??= 0;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Node("Double-Value", "Outputs a configurable double value.", "Static", OutputType = typeof(double))]
|
||||
public class StaticDoubleValueNode : Node<StaticDoubleValueNodeCustomViewModel>
|
||||
public class StaticDoubleValueNode : Node<double, StaticDoubleValueNodeCustomViewModel>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@@ -60,13 +58,11 @@ namespace Artemis.VisualScripting.Nodes
|
||||
Output.Value = Storage as double? ?? 0.0;
|
||||
}
|
||||
|
||||
public override void Initialize(INodeScript script) => Storage ??= 0.0;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Node("Float-Value", "Outputs a configurable float value.", "Static", OutputType = typeof(float))]
|
||||
public class StaticFloatValueNode : Node<StaticFloatValueNodeCustomViewModel>
|
||||
public class StaticFloatValueNode : Node<float, StaticFloatValueNodeCustomViewModel>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@@ -88,19 +84,14 @@ namespace Artemis.VisualScripting.Nodes
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
if (Storage is double doubleValue)
|
||||
Storage = (float) doubleValue;
|
||||
|
||||
Output.Value = Storage as float? ?? 0.0f;
|
||||
Output.Value = Storage;
|
||||
}
|
||||
|
||||
public override void Initialize(INodeScript script) => Storage ??= 0.0f;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Node("String-Value", "Outputs a configurable string value.", "Static", OutputType = typeof(string))]
|
||||
public class StaticStringValueNode : Node<StaticStringValueNodeCustomViewModel>
|
||||
public class StaticStringValueNode : Node<string, StaticStringValueNodeCustomViewModel>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@@ -122,7 +113,7 @@ namespace Artemis.VisualScripting.Nodes
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
Output.Value = Storage as string;
|
||||
Output.Value = Storage;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in new issue
Block a user