#nullable disable
using System;
using StardewModdingAPI.Framework.Input;
using StardewModdingAPI.Utilities;
namespace StardewModdingAPI.Framework.ModHelpers
{
/// Provides an API for checking and changing input state.
internal class InputHelper : BaseHelper, IInputHelper
{
/*********
** Accessors
*********/
/// Manages the game's input state for the current player instance. That may not be the main player in split-screen mode.
private readonly Func CurrentInputState;
/*********
** Public methods
*********/
/// Construct an instance.
/// The unique ID of the relevant mod.
/// Manages the game's input state for the current player instance. That may not be the main player in split-screen mode.
public InputHelper(string modID, Func currentInputState)
: base(modID)
{
this.CurrentInputState = currentInputState;
}
///
public ICursorPosition GetCursorPosition()
{
return this.CurrentInputState().CursorPosition;
}
///
public bool IsDown(SButton button)
{
return this.CurrentInputState().IsDown(button);
}
///
public bool IsSuppressed(SButton button)
{
return this.CurrentInputState().IsSuppressed(button);
}
///
public void Suppress(SButton button)
{
this.CurrentInputState().OverrideButton(button, setDown: false);
}
///
public void SuppressActiveKeybinds(KeybindList keybindList)
{
foreach (Keybind keybind in keybindList.Keybinds)
{
if (!keybind.GetState().IsDown())
continue;
foreach (SButton button in keybind.Buttons)
this.Suppress(button);
}
}
///
public SButtonState GetState(SButton button)
{
return this.CurrentInputState().GetState(button);
}
}
}