Files
RobustToolbox/Robust.Shared/Input/PlayerCommandStates.cs
T
SilverandGitHub 25926a17b7 Renames SS14.* to Robust.* (#793)
RobustToolbox projects should be named Robust.* 

This PR changes the RobustToolbox projects from SS14.* to Robust.*

Updates SS14.* prefixes/namespaces to Robust.*
Updates SpaceStation14.sln to RobustToolbox.sln
Updates MSBUILD/SS14.* to MSBUILD/Robust.*
Updates CSProject and MSBuild references for the above
Updates git_helper.py
Removes Runserver and Runclient as they are unusable
2019-04-15 20:24:59 -06:00

58 lines
1.9 KiB
C#

using System.Collections.Generic;
namespace Robust.Shared.Input
{
/// <summary>
/// Contains a mapping of <see cref="BoundKeyFunction"/> to their current <see cref="BoundKeyState"/>.
/// </summary>
public interface IPlayerCommandStates
{
/// <summary>
/// Indexer access to the Get/Set functions.
/// </summary>
BoundKeyState this[BoundKeyFunction function] { get; set; }
/// <summary>
/// Gets the current state of a function.
/// </summary>
/// <param name="function">Function to get the state of.</param>
/// <returns>Current state of the function.</returns>
BoundKeyState GetState(BoundKeyFunction function);
/// <summary>
/// Sets the current state of a function.
/// </summary>
/// <param name="function">Function to change.</param>
/// <param name="state">State value to set.</param>
void SetState(BoundKeyFunction function, BoundKeyState state);
}
/// <inheritdoc />
public class PlayerCommandStates : IPlayerCommandStates
{
private readonly Dictionary<BoundKeyFunction, BoundKeyState> _functionStates = new Dictionary<BoundKeyFunction, BoundKeyState>();
/// <inheritdoc />
public BoundKeyState this[BoundKeyFunction function]
{
get => GetState(function);
set => SetState(function, value);
}
/// <inheritdoc />
public BoundKeyState GetState(BoundKeyFunction function)
{
return _functionStates.TryGetValue(function, out var state) ? state : BoundKeyState.Up;
}
/// <inheritdoc />
public void SetState(BoundKeyFunction function, BoundKeyState state)
{
if (_functionStates.ContainsKey(function))
_functionStates[function] = state;
else
_functionStates.Add(function, state);
}
}
}