示例#1
0
        /// <summary>
        /// Checks the current gamestate and checks if the animation layer should be triggered.
        /// Note will also have the side-effect of updating _previousTriggerValue so this should not be called
        /// more than once per frame.
        /// </summary>
        private void CheckTriggers(IGameState gamestate)
        {
            if (Properties.TriggerMode == AnimationTriggerMode.AlwaysOn)
            {
                // Should return true if it has not already been played OR it is allowed to repeat indefinately
                // Should also not try to get a value from the state
                if (Properties.AnimationRepeat == 0)
                {
                    StartAnimation(); // Always true if infinite repeats
                }
                else if (!_alwaysOnHasPlayed)
                {
                    _alwaysOnHasPlayed = true; // True if it has not been played
                    StartAnimation();
                }

                // Handling for key-based triggers
            }
            else if (Properties.TriggerMode == AnimationTriggerMode.WhileKeyHeld)
            {
                // If we are in "while held down" mode, check to see if any of the keys pressed do not currently
                // have an animation with them as the assigned key. If not, create trigger it
                foreach (var key in _pressedKeys.Where(k => !runningAnimations.Any(a => a.assignedKey == k)))
                {
                    StartAnimation(key);
                }

                // Handling for numeric value change based triggers
            }
            else if (IsTriggerNumericValueBased(Properties.TriggerMode))
            {
                // Check to see if a gamestate value change should trigger the animation
                double resolvedTriggerValue = GameStateUtils.TryGetDoubleFromState(gamestate, Properties.TriggerPath);
                switch (Properties.TriggerMode)
                {
                case AnimationTriggerMode.OnChange:
                    if (resolvedTriggerValue != _previousTriggerDoubleValue)
                    {
                        StartAnimation();
                    }
                    break;

                case AnimationTriggerMode.OnHigh:
                    if (resolvedTriggerValue > _previousTriggerDoubleValue)
                    {
                        StartAnimation();
                    }
                    break;

                case AnimationTriggerMode.OnLow:
                    if (resolvedTriggerValue < _previousTriggerDoubleValue)
                    {
                        StartAnimation();
                    }
                    break;
                }
                _previousTriggerDoubleValue = resolvedTriggerValue;

                // Handling for boolean value based triggers
            }
            else
            {
                bool resolvedTriggerValue = GameStateUtils.TryGetBoolFromState(gamestate, Properties.TriggerPath);
                switch (Properties.TriggerMode)
                {
                case AnimationTriggerMode.OnTrue:
                    if (resolvedTriggerValue && !_previousTriggerBoolValue)
                    {
                        StartAnimation();
                    }
                    break;

                case AnimationTriggerMode.OnFalse:
                    if (!resolvedTriggerValue && _previousTriggerBoolValue)
                    {
                        StartAnimation();
                    }
                    break;

                case AnimationTriggerMode.WhileTrue:
                    if (resolvedTriggerValue && runningAnimations.Count == 0)
                    {
                        StartAnimation();
                    }
                    break;
                }
                _previousTriggerBoolValue = resolvedTriggerValue;
            }
        }
示例#2
0
 /// <summary>Parses the numbers, compares the result, and returns the result.</summary>
 public double Evaluate(IGameState gameState) => GameStateUtils.TryGetDoubleFromState(gameState, VariablePath);