Nodes - Vein attempt at script changed events

This commit is contained in:
Robert committed 2021-10-05 17:10:58 +02:00
1 parent 245c418b9b
commit 8f990f8f36
19 files changed
+115 -113

No files matched your search

@@ -9,12 +9,12 @@ namespace Artemis.VisualScripting.Nodes.Color
public BrightenSKColorNode() : base("Brighten Color", "Brightens a color by a specified amount in percent")
{
Input = CreateInputPin<SKColor>("Color");
Percentage = CreateInputPin<float>("%");
Percentage = CreateInputPin<Numeric>("%");
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; }
public InputPin<float> Percentage { get; }
public InputPin<Numeric> Percentage { get; }
public OutputPin<SKColor> Output { get; set; }
public override void Evaluate()
@@ -9,12 +9,12 @@ namespace Artemis.VisualScripting.Nodes.Color
public DarkenSKColorNode() : base("Darken Color", "Darkens a color by a specified amount in percent")
{
Input = CreateInputPin<SKColor>("Color");
Percentage = CreateInputPin<float>("%");
Percentage = CreateInputPin<Numeric>("%");
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; }
public InputPin<float> Percentage { get; }
public InputPin<Numeric> Percentage { get; }
public OutputPin<SKColor> Output { get; set; }
public override void Evaluate()
@@ -10,12 +10,12 @@ namespace Artemis.VisualScripting.Nodes.Color
public DesaturateSKColorNode() : base("Desaturate Color", "Desaturates a color by a specified amount in percent")
{
Input = CreateInputPin<SKColor>("Color");
Percentage = CreateInputPin<float>("%");
Percentage = CreateInputPin<Numeric>("%");
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; }
public InputPin<float> Percentage { get; }
public InputPin<Numeric> Percentage { get; }
public OutputPin<SKColor> Output { get; set; }
public override void Evaluate()
@@ -9,12 +9,12 @@ namespace Artemis.VisualScripting.Nodes.Color
public RotateHueSKColorNode() : base("Rotate Color Hue", "Rotates the hue of a color by a specified amount in degrees")
{
Input = CreateInputPin<SKColor>("Color");
Amount = CreateInputPin<float>("Amount");
Amount = CreateInputPin<Numeric>("Amount");
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; }
public InputPin<float> Amount { get; }
public InputPin<Numeric> Amount { get; }
public OutputPin<SKColor> Output { get; set; }
public override void Evaluate()
@@ -10,12 +10,12 @@ namespace Artemis.VisualScripting.Nodes.Color
public SaturateSKColorNode() : base("Saturate Color", "Saturates a color by a specified amount in percent")
{
Input = CreateInputPin<SKColor>("Color");
Percentage = CreateInputPin<float>("%");
Percentage = CreateInputPin<Numeric>("%");
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; }
public InputPin<float> Percentage { get; }
public InputPin<Numeric> Percentage { get; }
public OutputPin<SKColor> Output { get; set; }
public override void Evaluate()
@@ -1,4 +1,6 @@
using Artemis.Core;
using System;
using System.ComponentModel;
using Artemis.Core;
using Stylet;
namespace Artemis.VisualScripting.Nodes.CustomViewModels
@@ -17,11 +19,38 @@ namespace Artemis.VisualScripting.Nodes.CustomViewModels
/// <inheritdoc />
public virtual void OnActivate()
{
Node.PropertyChanged += NodeOnPropertyChanged;
}
/// <inheritdoc />
public virtual void OnDeactivate()
{
Node.PropertyChanged -= NodeOnPropertyChanged;
}
#endregion
#region Events
/// <inheritdoc />
public event EventHandler NodeModified;
/// <summary>
/// Invokes the <see cref="NodeModified"/> event
/// </summary>
protected virtual void OnNodeModified()
{
NodeModified?.Invoke(this, EventArgs.Empty);
}
#endregion
#region Event handlers
private void NodeOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Storage")
OnNodeModified();
}
#endregion
@@ -1,12 +0,0 @@
<UserControl x:Class="Artemis.VisualScripting.Nodes.CustomViews.StaticDoubleValueNodeCustomView"
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.CustomViewModels"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<TextBox VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Text="{Binding Node.Storage}" />
</UserControl>
@@ -1,12 +0,0 @@
<UserControl x:Class="Artemis.VisualScripting.Nodes.CustomViews.StaticIntegerValueNodeCustomView"
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.CustomViewModels"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<TextBox VerticalAlignment="Center"
HorizontalAlignment="Stretch"
Text="{Binding Node.Storage}" />
</UserControl>
@@ -1,68 +0,0 @@
using System;
using Artemis.Core;
namespace Artemis.VisualScripting.Nodes.Easing
{
[Node("Integer Easing", "Outputs an eased integer value", "Easing", InputType = typeof(int), OutputType = typeof(int))]
public class IntEasingNode : Node
{
private DateTime _lastEvaluate = DateTime.MinValue;
private float _progress;
private int _currentValue;
private int _sourceValue;
private int _targetValue;
public IntEasingNode() : base("Integer Easing", "Outputs an eased integer value")
{
Input = CreateInputPin<int>();
EasingTime = CreateInputPin<float>("delay");
EasingFunction = CreateInputPin<Easings.Functions>("function");
Output = CreateOutputPin<int>();
}
public InputPin<int> Input { get; set; }
public InputPin<float> EasingTime { get; set; }
public InputPin<Easings.Functions> EasingFunction { get; set; }
public OutputPin<int> Output { get; set; }
public override void Evaluate()
{
DateTime now = DateTime.Now;
// If the value changed reset progress
if (_targetValue != Input.Value)
{
_sourceValue = _currentValue;
_targetValue = Input.Value;
_progress = 0f;
}
// Update until finished
if (_progress < 1f)
{
Update();
Output.Value = _currentValue;
}
// Stop updating past 1 and use the target value
else
{
Output.Value = _targetValue;
}
_lastEvaluate = now;
}
private void Update()
{
TimeSpan delta = DateTime.Now - _lastEvaluate;
// In case of odd delta's, keep progress between 0f and 1f
_progress = Math.Clamp(_progress + (float) delta.TotalMilliseconds / EasingTime.Value, 0f, 1f);
double eased = _sourceValue + (_targetValue - _sourceValue) * Easings.Interpolate(_progress, EasingFunction.Value);
_currentValue = (int) Math.Round(eased, MidpointRounding.AwayFromZero);
}
}
}
@@ -16,14 +16,14 @@ namespace Artemis.VisualScripting.Nodes.Easing
public SKColorEasingNode() : base("Color Easing", "Outputs an eased color value")
{
Input = CreateInputPin<SKColor>();
EasingTime = CreateInputPin<float>("delay");
EasingTime = CreateInputPin<Numeric>("delay");
EasingFunction = CreateInputPin<Easings.Functions>("function");
Output = CreateOutputPin<SKColor>();
}
public InputPin<SKColor> Input { get; set; }
public InputPin<float> EasingTime { get; set; }
public InputPin<Numeric> EasingTime { get; set; }
public InputPin<Easings.Functions> EasingFunction { get; set; }
public OutputPin<SKColor> Output { get; set; }