using Ryujinx.Common.Memory;
using System.Runtime.CompilerServices;
namespace Ryujinx.Input
{
    /// 
    /// A snapshot of a .
    /// 
    public struct GamepadStateSnapshot
    {
        // NOTE: Update Array size if JoystickInputId is changed.
        private Array3> _joysticksState;
        // NOTE: Update Array size if GamepadInputId is changed.
        private Array28 _buttonsState;
        /// 
        /// Create a new instance of .
        /// 
        /// The joysticks state
        /// The buttons state
        public GamepadStateSnapshot(Array3> joysticksState, Array28 buttonsState)
        {
            _joysticksState = joysticksState;
            _buttonsState = buttonsState;
        }
        /// 
        /// Check if a given input button is pressed.
        /// 
        /// The button id
        /// True if the given button is pressed
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool IsPressed(GamepadButtonInputId inputId) => _buttonsState[(int)inputId];
        /// 
        /// Set the state of a given button.
        /// 
        /// The button id
        /// The state to assign for the given button.
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void SetPressed(GamepadButtonInputId inputId, bool value) => _buttonsState[(int)inputId] = value;
        /// 
        /// Get the values of a given input joystick.
        /// 
        /// The stick id
        /// The values of the given input joystick
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public (float, float) GetStick(StickInputId inputId)
        {
            var result = _joysticksState[(int)inputId];
            return (result[0], result[1]);
        }
        /// 
        /// Set the values of a given input joystick.
        /// 
        /// The stick id
        /// The x axis value
        /// The y axis value
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void SetStick(StickInputId inputId, float x, float y)
        {
            _joysticksState[(int)inputId][0] = x;
            _joysticksState[(int)inputId][1] = y;
        }
    }
}