예제 #1
0
        /// <summary>
        /// Processes the value changes and emits the appropriate events.
        /// </summary>
        public virtual void Process()
        {
            if (!isActiveAndEnabled)
            {
                return;
            }

            if (!Value.ApproxEquals(previousValue))
            {
                previousValue = Value;
                EmitValueChanged();
                EmitNormalizedValueChanged();
            }

            if (!StepValue.ApproxEquals(previousStepValue))
            {
                previousStepValue = StepValue;
                EmitStepValueChanged();
            }

            float targetValue        = GetTargetValue();
            bool  targetValueReached = NormalizedValue.ApproxEquals(targetValue, targetValueReachedThreshold);
            bool  shouldEmitEvent    = !previousTargetValueReached && targetValueReached;

            previousTargetValueReached = targetValueReached;

            if (CanMoveToTargetValue() && shouldEmitEvent)
            {
                EmitTargetValueReached();
            }
        }
예제 #2
0
        private IEnumerable <Token> Tokenize(string input)
        {
            var tokens = _lexPattern.Matches(input);

            return(tokens.Select(t =>
            {
                TokenType type;
                if (_numberValidationPattern.IsMatch(t.Value))
                {
                    type = TokenType.Number;
                }
                else if (_symbolValidationPattern.IsMatch(t.Value))
                {
                    type = TokenType.Symbol;
                }
                else
                {
                    type = TokenType.Word;
                }

                NormalizedValue normalized = null;
                _normalizationMapping.TryGetValue(t.Value, out normalized);

                return new Token(
                    normalized == null ? type : normalized.Type,
                    normalized == null ? t.Value : normalized.Value,
                    t.Value);
            }));
        }
예제 #3
0
        /// <summary>
        /// Checks if the target value has been reached.
        /// </summary>
        protected virtual void CheckTargetValueReached()
        {
            float targetValue        = GetTargetValue();
            bool  targetValueReached = NormalizedValue.ApproxEquals(targetValue, TargetValueReachedThreshold);
            bool  shouldEmitEvent    = !previousTargetValueReached && targetValueReached;

            previousTargetValueReached = targetValueReached;

            if (CanMoveToTargetValue() && shouldEmitEvent)
            {
                EmitTargetValueReached();
            }
        }
예제 #4
0
        /// <summary>
        /// Emits the NormalizedValueChanged event.
        /// </summary>
        protected virtual void EmitNormalizedValueChanged()
        {
            if (isMovingToInitialTargetValue && NormalizedValue.ApproxEquals(Facade.InitialTargetValue, TargetValueReachedThreshold))
            {
                ResetToCacheAfterReachedInitialTargetValue();
                return;
            }

            if (!EmitEvents)
            {
                return;
            }

            Facade.NormalizedValueChanged?.Invoke(NormalizedValue);
        }
예제 #5
0
        public virtual void Process()
        {
            if (wasDisabled || !Value.ApproxEquals(previousValue))
            {
                if (!isMoving && previousValue < float.MaxValue)
                {
                    EmitStartedMoving();
                    isMoving = true;
                }
                previousValue = Value;
                EmitValueChanged();
                EmitNormalizedValueChanged();
            }
            else
            {
                if (isMoving)
                {
                    EmitStoppedMoving();
                    isMoving = false;
                }
            }

            if (!StepValue.ApproxEquals(previousStepValue))
            {
                previousStepValue = StepValue;
                EmitStepValueChanged();
            }

            float targetValue        = GetTargetValue();
            bool  targetValueReached = NormalizedValue.ApproxEquals(targetValue, TargetValueReachedThreshold);
            bool  shouldEmitEvent    = !previousTargetValueReached && targetValueReached;

            previousTargetValueReached = targetValueReached;

            if (CanMoveToTargetValue() && shouldEmitEvent)
            {
                EmitTargetValueReached();
            }

            wasDisabled = false;
        }
예제 #6
0
 /// <summary>
 /// Returns a formatted string representing the percentage.
 /// </summary>
 /// <param name="format">The format of the number.</param>
 /// <param name="formatProvider">The provider to use.</param>
 /// <returns>The unit string.</returns>
 public String ToString(String format, IFormatProvider formatProvider)
 {
     return(NormalizedValue.ToString(format, formatProvider));
 }
예제 #7
0
 /// <summary>
 /// Returns a string representing the percentage.
 /// </summary>
 /// <returns>The string.</returns>
 public override String ToString()
 {
     return(NormalizedValue.ToString());
 }