예제 #1
0
        /// <summary>
        /// Saves a new verse number for the current position, moves back one position, and returns the verse number for the new position.
        /// This method may only be called when <see cref="CanMoveBack"/> is <c>true</c>.
        /// </summary>
        /// <param name="currentAbsoluteVerseNumber">The new verse number for the current position.</param>
        public int MoveBack(int currentAbsoluteVerseNumber)
        {
            if (currentAbsoluteVerseNumber == Bible.InvalidAbsoluteVerseNumber)
            {
                throw new InvalidOperationException("Invalid verse number");
            }
            if (!CanMoveBack)
            {
                throw new InvalidOperationException("Invalid state");
            }
            _history[_currentIndex] = currentAbsoluteVerseNumber;
            var result = _history[--_currentIndex];

            CanMoveChanged?.Invoke();
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Notifies the history stack of a jump.
        /// Saves a new verse number for the current position, inserts a new position in the stack, and moves forward to that position.
        /// After this method is called, <see cref="CurrentAbsoluteVerseNumber"/> is equal to <paramref name="jumpAbsoluteVerseNumber"/>.
        /// </summary>
        /// <param name="currentAbsoluteVerseNumber">The new verse number for the current position.</param>
        /// <param name="jumpAbsoluteVerseNumber">The verse number for the new position.</param>
        public void AddJump(int currentAbsoluteVerseNumber, int jumpAbsoluteVerseNumber)
        {
            if (currentAbsoluteVerseNumber == Bible.InvalidAbsoluteVerseNumber || jumpAbsoluteVerseNumber == Bible.InvalidAbsoluteVerseNumber)
            {
                throw new InvalidOperationException("Invalid verse number");
            }
            _history[_currentIndex] = currentAbsoluteVerseNumber;

            // If the user is jumping from the same location, don't insert a duplicate.
            if (currentAbsoluteVerseNumber == jumpAbsoluteVerseNumber)
            {
                return;
            }

            // If the user is jumping to the same location, don't insert a duplicate.
            var next = (_currentIndex == _history.Count - 1) ? Bible.InvalidAbsoluteVerseNumber : _history[_currentIndex + 1];

            if (next == jumpAbsoluteVerseNumber)
            {
                ++_currentIndex;
                CanMoveChanged?.Invoke();
                return;
            }

            _history.Insert(++_currentIndex, jumpAbsoluteVerseNumber);

            if (_history.Count > MaxHistory)
            {
                if (_currentIndex <= MaxHistory / 2)
                {
                    _history.RemoveAt(_history.Count - 1);
                }
                else
                {
                    _history.RemoveAt(0);
                    --_currentIndex;
                }
            }
            CanMoveChanged?.Invoke();
        }
예제 #3
0
 public void TakeInfoAboutPlayer(bool abilityMove)
 {
     CanMoveChanged?.Invoke(abilityMove);
     _animator.Play("Back_Idle");
 }