using System; using BizHawk.Client.Common; namespace BizHawk.Client.ApiHawk { /// /// This class holds a joypad for any type of console /// public sealed class Joypad { #region Fields private SystemInfo _System; private JoypadButton _PressedButtons; private float _AnalogX; private float _AnalogY; private int _Player; #endregion #region cTor(s) /// /// Initialize a new instance of /// /// What this is used for /// Which player this controller is assigned to internal Joypad(SystemInfo system, int player) { if (player < 1 || player > system.MaxControllers) { throw new InvalidOperationException(string.Format("{0} is invalid for {1}", player, system.DisplayName)); } _System = system; _Player = player; } #endregion #region Methods /// /// Add specified input to current ones /// /// Input to add public void AddInput(JoypadButton input) { input &= _System.AvailableButtons; _PressedButtons |= input; } /// /// Clear inputs /// public void ClearInputs() { _PressedButtons = 0; } /// /// Remove specified input to current ones /// /// Input to remove public void RemoveInput(JoypadButton input) { _PressedButtons ^= input; } #endregion #region Properties /// /// Gets or sets X value for Analog stick /// /// The value you get will aways be rounded to 0 decimal public float AnalogX { get { return (float)Math.Round(_AnalogX, 0); } set { _AnalogX = value; } } /// /// Gets or sets Y value for Analog stick /// /// The value you get will aways be rounded to 0 decimal public float AnalogY { get { return (float)Math.Round(_AnalogY, 0); } set { _AnalogY = value; } } /// /// Gets or sets inputs /// If you pass inputs unavailable for current system, they'll be removed /// /// It overrides all existing inputs public JoypadButton Inputs { get { return _PressedButtons; } set { value &= _System.AvailableButtons; _PressedButtons = value; } } /// /// Gets for current /// public SystemInfo System { get { return _System; } } #endregion } }