mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Easing nodes - Fixed going into a broken state when delay is 0
Numeric easing node - Fixed node not functioning at all Event cycle node - Fixed node not functioning at all
This commit is contained in:
parent
6638eae126
commit
cf58acc7d2
@ -121,9 +121,9 @@ internal class ScriptingService : IScriptingService
|
|||||||
throw new ArtemisCoreException("Scripts must have exactly one constructor");
|
throw new ArtemisCoreException("Scripts must have exactly one constructor");
|
||||||
|
|
||||||
// Find the ScriptConfiguration parameter, it is required by the base constructor so its there for sure
|
// Find the ScriptConfiguration parameter, it is required by the base constructor so its there for sure
|
||||||
ParameterInfo configurationParameter = constructors.First().GetParameters().First(p => value.GetType().IsAssignableFrom(p.ParameterType));
|
ParameterInfo? configurationParameter = constructors.First().GetParameters().FirstOrDefault(p => value.GetType().IsAssignableFrom(p.ParameterType));
|
||||||
|
|
||||||
if (configurationParameter.Name == null)
|
if (configurationParameter?.Name == null)
|
||||||
throw new ArtemisCoreException($"Couldn't find a valid constructor argument on {scriptType.Name} with type {value.GetType().Name}");
|
throw new ArtemisCoreException($"Couldn't find a valid constructor argument on {scriptType.Name} with type {value.GetType().Name}");
|
||||||
return new ConstructorArgument(configurationParameter.Name, value);
|
return new ConstructorArgument(configurationParameter.Name, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using Ninject.Parameters;
|
using Ninject.Parameters;
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ public abstract class Node : CorePropertyChanged, INode
|
|||||||
public event EventHandler? Resetting;
|
public event EventHandler? Resetting;
|
||||||
|
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private readonly List<OutputPin> _outputPinBucket = new();
|
private readonly List<OutputPin> _outputPinBucket = new();
|
||||||
private readonly List<InputPin> _inputPinBucket = new();
|
private readonly List<InputPin> _inputPinBucket = new();
|
||||||
|
|
||||||
@ -164,7 +165,7 @@ public abstract class Node : CorePropertyChanged, INode
|
|||||||
OnPropertyChanged(nameof(Pins));
|
OnPropertyChanged(nameof(Pins));
|
||||||
return pin;
|
return pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates or adds an output pin to the node using a bucket.
|
/// Creates or adds an output pin to the node using a bucket.
|
||||||
/// The bucket might grow a bit over time as the user edits the node but pins won't get lost, enabling undo/redo in the
|
/// The bucket might grow a bit over time as the user edits the node but pins won't get lost, enabling undo/redo in the
|
||||||
@ -194,7 +195,7 @@ public abstract class Node : CorePropertyChanged, INode
|
|||||||
|
|
||||||
return pin;
|
return pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates or adds an input pin to the node using a bucket.
|
/// Creates or adds an input pin to the node using a bucket.
|
||||||
/// The bucket might grow a bit over time as the user edits the node but pins won't get lost, enabling undo/redo in the
|
/// The bucket might grow a bit over time as the user edits the node but pins won't get lost, enabling undo/redo in the
|
||||||
@ -447,7 +448,17 @@ public abstract class Node<TStorage, TViewModel> : Node<TStorage> where TViewMod
|
|||||||
/// <param name="nodeScript"></param>
|
/// <param name="nodeScript"></param>
|
||||||
public virtual TViewModel GetViewModel(NodeScript nodeScript)
|
public virtual TViewModel GetViewModel(NodeScript nodeScript)
|
||||||
{
|
{
|
||||||
return Kernel.Get<TViewModel>(new ConstructorArgument("node", this), new ConstructorArgument("script", nodeScript));
|
// Limit to one constructor, there's no need to have more and it complicates things anyway
|
||||||
|
ConstructorInfo[] constructors = typeof(TViewModel).GetConstructors();
|
||||||
|
if (constructors.Length != 1)
|
||||||
|
throw new ArtemisCoreException("Node VMs must have exactly one constructor");
|
||||||
|
|
||||||
|
// Find the ScriptConfiguration parameter, it is required by the base constructor so its there for sure
|
||||||
|
ParameterInfo? configurationParameter = constructors.First().GetParameters().FirstOrDefault(p => GetType().IsAssignableFrom(p.ParameterType));
|
||||||
|
|
||||||
|
if (configurationParameter?.Name == null)
|
||||||
|
throw new ArtemisCoreException($"Couldn't find a valid constructor argument on {typeof(TViewModel).Name} with type {GetType().Name}");
|
||||||
|
return Kernel.Get<TViewModel>(new ConstructorArgument(configurationParameter.Name, this), new ConstructorArgument("script", nodeScript));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="nodeScript"></param>
|
/// <param name="nodeScript"></param>
|
||||||
|
|||||||
@ -29,9 +29,10 @@ public class NumericEasingNode : Node
|
|||||||
public override void Evaluate()
|
public override void Evaluate()
|
||||||
{
|
{
|
||||||
DateTime now = DateTime.Now;
|
DateTime now = DateTime.Now;
|
||||||
|
float inputValue = Input.Value;
|
||||||
|
|
||||||
// If the value changed reset progress
|
// If the value changed reset progress
|
||||||
if (Math.Abs(_targetValue - Input.Value) > 0.001f)
|
if (Math.Abs(_targetValue - inputValue) > 0.001f)
|
||||||
{
|
{
|
||||||
_sourceValue = _currentValue;
|
_sourceValue = _currentValue;
|
||||||
_targetValue = Input.Value;
|
_targetValue = Input.Value;
|
||||||
@ -55,10 +56,11 @@ public class NumericEasingNode : Node
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
float easingTime = EasingTime.Value != 0f ? EasingTime.Value : 1f;
|
||||||
TimeSpan delta = DateTime.Now - _lastEvaluate;
|
TimeSpan delta = DateTime.Now - _lastEvaluate;
|
||||||
|
|
||||||
// In case of odd delta's, keep progress between 0f and 1f
|
// In case of odd delta's, keep progress between 0f and 1f
|
||||||
_progress = Math.Clamp(_progress + (float) delta.TotalMilliseconds / EasingTime.Value, 0f, 1f);
|
_progress = Math.Clamp(_progress + (float) delta.TotalMilliseconds / easingTime, 0f, 1f);
|
||||||
|
|
||||||
double eased = _sourceValue + (_targetValue - _sourceValue) * Easings.Interpolate(_progress, EasingFunction.Value);
|
double eased = _sourceValue + (_targetValue - _sourceValue) * Easings.Interpolate(_progress, EasingFunction.Value);
|
||||||
_currentValue = (float) eased;
|
_currentValue = (float) eased;
|
||||||
|
|||||||
@ -56,10 +56,11 @@ public class SKColorEasingNode : Node
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
float easingTime = EasingTime.Value != 0f ? EasingTime.Value : 1f;
|
||||||
TimeSpan delta = DateTime.Now - _lastEvaluate;
|
TimeSpan delta = DateTime.Now - _lastEvaluate;
|
||||||
|
|
||||||
// In case of odd delta's, keep progress between 0f and 1f
|
// In case of odd delta's, keep progress between 0f and 1f
|
||||||
_progress = Math.Clamp(_progress + (float) delta.TotalMilliseconds / EasingTime.Value, 0f, 1f);
|
_progress = Math.Clamp(_progress + (float) delta.TotalMilliseconds / easingTime, 0f, 1f);
|
||||||
_currentValue = _sourceValue.Interpolate(_targetValue, (float) Easings.Interpolate(_progress, EasingFunction.Value));
|
_currentValue = _sourceValue.Interpolate(_targetValue, (float) Easings.Interpolate(_progress, EasingFunction.Value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user