Exemple #1
0
 static void OnNextLeftDown(IInputTarget target, InputArgs args)
 {
     if (target.IsLeftDownAvailable())
     {
         target.LeftDown(args);
     }
 }
Exemple #2
0
 /// <summary>
 /// Connects source and target inputs.
 /// </summary>
 /// <param name="source">The input source.</param>
 /// <param name="target">The input target.</param>
 public void Connect(IInputSource source, IInputTarget target)
 {
     _leftDownDisposable  = ConnectLeftDown(source, target);
     _leftUpDisposable    = ConnectLeftUp(source, target);
     _rightDownDisposable = ConnectRightDown(source, target);
     _rightUpDisposable   = ConnectRightUp(source, target);
     _moveDisposable      = ConnectMove(source, target);
 }
        private static IDisposable ConnectLeftDown(IInputSource source, IInputTarget target)
        {
            //var observer = new InputArgsObserver(target, OnNextLeftDown);
            //return source.LeftDown.SubscribeSafe(observer);
            return(source.LeftDown.Subscribe(OnNextLeftDown));

            void OnNextLeftDown(InputArgs args)
            {
                if (target.IsLeftDownAvailable())
                {
                    target.LeftDown(args);
                }
            }
        }
        private static IDisposable ConnectMove(IInputSource source, IInputTarget target)
        {
            //var observer = new InputArgsObserver(target, OnNextMove);
            //return source.Move.SubscribeSafe(observer);
            return(source.Move.Subscribe(OnNextMove));

            void OnNextMove(InputArgs args)
            {
                if (target.IsMoveAvailable())
                {
                    target.Move(args);
                }
            }
        }
        private static IDisposable ConnectRightUp(IInputSource source, IInputTarget target)
        {
            //var observer = new InputArgsObserver(target, OnNextRightUp);
            //return source.RightUp.SubscribeSafe(observer);
            return(source.RightUp.Subscribe(OnNextRightUp));

            void OnNextRightUp(InputArgs args)
            {
                if (target.IsRightUpAvailable())
                {
                    target.RightUp(args);
                }
            }
        }
    private void HandleInputTargetFound(IInputTarget inputTarget)
    {
        var movable = inputTarget as MovableItem;

        if (movable != null)
        {
            HandleMovableFound(movable);
        }
        var target = inputTarget as TargetObject;

        if (target != null)
        {
            HandleTargetFound(target);
        }
    }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InputProcessor"/> class.
        /// </summary>
        /// <param name="source">The input source.</param>
        /// <param name="target">The input target.</param>
        public InputProcessor(IInputSource source, IInputTarget target)
        {
            _leftDownDisposable = source.LeftDown.Subscribe(
                (v) =>
                {
                    if (target.IsLeftDownAvailable())
                    {
                        target.LeftDown(v.X, v.Y);
                    }
                });

            _leftUpDisposable = source.LeftUp.Subscribe(
                (v) =>
                {
                    if (target.IsLeftUpAvailable())
                    {
                        target.LeftUp(v.X, v.Y);
                    }
                });

            _rightDownDisposable = source.RightDown.Subscribe(
                (v) =>
                {
                    if (target.IsRightDownAvailable())
                    {
                        target.RightDown(v.X, v.Y);
                    }
                });

            _rightUpDisposable = source.RightUp.Subscribe(
                (v) =>
                {
                    if (target.IsRightUpAvailable())
                    {
                        target.RightUp(v.X, v.Y);
                    }
                });

            _moveDisposable = source.Move.Subscribe(
                (v) =>
                {
                    if (target.IsMoveAvailable())
                    {
                        target.Move(v.X, v.Y);
                    }
                });
        }
Exemple #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InputProcessor"/> class.
        /// </summary>
        /// <param name="source">The input source.</param>
        /// <param name="target">The input target.</param>
        public InputProcessor(IInputSource source, IInputTarget target)
        {
            _leftDownDisposable = source.LeftDown.Subscribe(
                (args) =>
            {
                if (target.IsLeftDownAvailable())
                {
                    target.LeftDown(args);
                }
            });

            _leftUpDisposable = source.LeftUp.Subscribe(
                (args) =>
            {
                if (target.IsLeftUpAvailable())
                {
                    target.LeftUp(args);
                }
            });

            _rightDownDisposable = source.RightDown.Subscribe(
                (args) =>
            {
                if (target.IsRightDownAvailable())
                {
                    target.RightDown(args);
                }
            });

            _rightUpDisposable = source.RightUp.Subscribe(
                (args) =>
            {
                if (target.IsRightUpAvailable())
                {
                    target.RightUp(args);
                }
            });

            _moveDisposable = source.Move.Subscribe(
                (args) =>
            {
                if (target.IsMoveAvailable())
                {
                    target.Move(args);
                }
            });
        }
Exemple #9
0
        private static IDisposable ConnectRightDown(IInputSource source, IInputTarget target)
        {
#if USE_CUSTOM_OBSERVER
            var observer = new InputArgsObserver(target, OnNextRightDown);
            return(source.RightDown.Subscribe(observer));

            void OnNextRightDown(IInputTarget target, InputArgs args)
#else
            return(source.RightDown.Subscribe(OnNextRightDown));

            void OnNextRightDown(InputArgs args)
#endif
            {
                if (target.IsRightDownAvailable())
                {
                    target.RightDown(args);
                }
            }
        }
Exemple #10
0
        private static IDisposable ConnectLeftUp(IInputSource source, IInputTarget target)
        {
#if USE_CUSTOM_OBSERVER
            var observer = new InputArgsObserver(target, OnNextLeftUp);
            return(source.LeftUp.Subscribe(observer));

            void OnNextLeftUp(IInputTarget target, InputArgs args)
#else
            return(source.LeftUp.Subscribe(OnNextLeftUp));

            void OnNextLeftUp(InputArgs args)
#endif
            {
                if (target.IsLeftUpAvailable())
                {
                    target.LeftUp(args);
                }
            }
        }
Exemple #11
0
 /// <summary>
 /// Sends the input to the target.
 /// </summary>
 /// <param name="target">The input target.</param>
 public override void SendTo(IInputTarget target)
 {
     base.SendTo(target);
     target.OnInputDeviceButton(this);
 }
Exemple #12
0
        private static IDisposable ConnectLeftDown(IInputSource source, IInputTarget target)
        {
            var observer = new InputArgsObserver(target, OnNextLeftDown);

            return(source.LeftDown.Subscribe(observer));
Exemple #13
0
 public InputArgsObserver(IInputTarget target, Action <IInputTarget, InputArgs> onNext)
 {
     _target = target;
     _onNext = onNext;
 }
Exemple #14
0
 /// <summary>
 /// Sends the input to the target.
 /// </summary>
 /// <param name="target">The input target.</param>
 public override void SendTo(IInputTarget target)
 {
     base.SendTo(target);
     target.OnGamepadAxis(this);
 }
Exemple #15
0
 /// <summary>
 /// Sends the input to the target.
 /// </summary>
 /// <param name="target">The input target.</param>
 public override void SendTo(IInputTarget target)
 {
     base.SendTo(target);
     target.OnKey(this);
 }
Exemple #16
0
 /// <summary>
 /// Sends the input to the target.
 /// </summary>
 /// <param name="target">The input target.</param>
 public override void SendTo(IInputTarget target)
 {
     base.SendTo(target);
     target.OnJoystickButton(this);
 }
Exemple #17
0
 /// <summary>
 /// Sends the input to the target.
 /// </summary>
 /// <param name="target">The input target.</param>
 public override void SendTo(IInputTarget target) => target.OnButton(this);
Exemple #18
0
 /// <summary>
 /// Sends the input to the target.
 /// </summary>
 /// <param name="target">The input target.</param>
 public override void SendTo(IInputTarget target) => target.OnMouseMove(this);
Exemple #19
0
 /// <summary>
 /// Sends the input to the target.
 /// </summary>
 /// <param name="target">The input target.</param>
 public override void SendTo(IInputTarget target) => target.OnCharacter(this);
Exemple #20
0
 /// <summary>
 /// Sends the input to the target.
 /// </summary>
 /// <param name="target">The input target.</param>
 public abstract void SendTo(IInputTarget target);