using Godot; using Rokojori; using System.Collections.Generic; using System; namespace Rokojori { [Tool] public class ActiveStyleTransition { public V value; public P propertyType; public RJTimeLine timeLine; public float start; public float end; public Curve curve; public bool transitioning; public static O ProcessTransition( UIStylePropertyContainer container, O computedValue, List> activeTransitions, V activeValue, P property, Func getTransitionSettings, Func computeValue, Func lerpValue ) { var propertyTransition = activeTransitions.Find( t => t != null && EqualityComparer

.Default.Equals( t.propertyType, property ) ); if ( propertyTransition == null ) { propertyTransition = new ActiveStyleTransition(); propertyTransition.propertyType = property; propertyTransition.value = activeValue; propertyTransition.transitioning = false; activeTransitions.Add( propertyTransition ); return computedValue; } else { if ( ! EqualityComparer.Default.Equals( propertyTransition.value, activeValue ) && ! propertyTransition.transitioning && getTransitionSettings() != null ) { var transitionSettings = getTransitionSettings(); propertyTransition.timeLine = transitionSettings.timeLine; propertyTransition.start = TimeLineManager.GetPosition( transitionSettings.timeLine ); propertyTransition.end = propertyTransition.start + transitionSettings.duration; propertyTransition.transitioning = true; propertyTransition.curve = transitionSettings.curve; } } if ( EqualityComparer.Default.Equals( propertyTransition.value, activeValue ) ) { propertyTransition.transitioning = false; return computedValue; } var computedTransitionValue = computeValue( propertyTransition.value ); var transitionPhase = TimeLineManager.GetRangePhase( propertyTransition.timeLine, propertyTransition.start, propertyTransition.end ); if ( transitionPhase >= 1 ) { activeTransitions.Remove( propertyTransition ); } var amount = MathX.Clamp01( transitionPhase ); var curveAmount = amount; if ( propertyTransition.curve != null ) { curveAmount = propertyTransition.curve.Sample( curveAmount ); } return lerpValue( computedTransitionValue, computedValue, curveAmount ); } } }