Skip to content

Commit

Permalink
Use read-only dict type in .NET API
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Nov 12, 2021
1 parent 47c5fcc commit fcd7a47
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/Api/Classes/GameInfoApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class GameInfoApi : IGameInfoApi

public string GetBoardType() => BoardInfo?.BoardName ?? "";

public Dictionary<string, string> GetOptions()
public IReadOnlyDictionary<string, string> GetOptions()
{
var options = new Dictionary<string, string>();
if (_game == null) return options;
Expand Down
10 changes: 5 additions & 5 deletions src/BizHawk.Client.Common/Api/Classes/JoypadApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public JoypadApi(Action<string> logCallback, InputManager inputManager, IMovieSe
_movieSession = movieSession;
}

public IDictionary<string, object> Get(int? controller = null)
public IReadOnlyDictionary<string, object> Get(int? controller = null)
{
return _inputManager.AutofireStickyXorAdapter.ToDictionary(controller);
}

public IDictionary<string, object> GetWithMovie(int? controller = null)
public IReadOnlyDictionary<string, object> GetWithMovie(int? controller = null)
{
return _inputManager.ControllerOutput.ToDictionary(controller);
}

public IDictionary<string, object> GetImmediate(int? controller = null)
public IReadOnlyDictionary<string, object> GetImmediate(int? controller = null)
{
return _inputManager.ActiveController.ToDictionary(controller);
}
Expand All @@ -51,7 +51,7 @@ public void SetFromMnemonicStr(string inputLogEntry)
foreach (var axis in controller.Definition.Axes.Keys) _inputManager.ButtonOverrideAdapter.SetAxis(axis, controller.AxisValue(axis));
}

public void Set(IDictionary<string, bool> buttons, int? controller = null)
public void Set(IReadOnlyDictionary<string, bool> buttons, int? controller = null)
{
// If a controller is specified, we need to iterate over unique button names. If not, we iterate over
// ALL button names with P{controller} prefixes
Expand Down Expand Up @@ -88,7 +88,7 @@ public void Set(string button, bool? state = null, int? controller = null)
}
}

public void SetAnalog(IDictionary<string, int?> controls, object controller = null)
public void SetAnalog(IReadOnlyDictionary<string, int?> controls, object controller = null)
{
foreach (var kvp in controls) SetAnalog(kvp.Key, kvp.Value, controller);
}
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/Api/Classes/MovieApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public MovieApi(Action<string> logCallback, IMovieSession movieSession)

public bool StartsFromSaveram() => _movieSession.Movie.IsActive() && _movieSession.Movie.StartsFromSaveRam;

public IDictionary<string, object> GetInput(int frame, int? controller = null)
public IReadOnlyDictionary<string, object> GetInput(int frame, int? controller = null)
{
if (_movieSession.Movie.NotActive())
{
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/Api/Interfaces/IGameInfoApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public interface IGameInfoApi : IExternalApi
string GetStatus();
bool IsStatusBad();
string GetBoardType();
Dictionary<string, string> GetOptions();
IReadOnlyDictionary<string, string> GetOptions();
}
}
10 changes: 5 additions & 5 deletions src/BizHawk.Client.Common/Api/Interfaces/IJoypadApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ namespace BizHawk.Client.Common
{
public interface IJoypadApi : IExternalApi
{
IDictionary<string, object> Get(int? controller = null);
IDictionary<string, object> GetWithMovie(int? controller = null);
IDictionary<string, object> GetImmediate(int? controller = null);
IReadOnlyDictionary<string, object> Get(int? controller = null);
IReadOnlyDictionary<string, object> GetWithMovie(int? controller = null);
IReadOnlyDictionary<string, object> GetImmediate(int? controller = null);
void SetFromMnemonicStr(string inputLogEntry);
void Set(IDictionary<string, bool> buttons, int? controller = null);
void Set(IReadOnlyDictionary<string, bool> buttons, int? controller = null);
void Set(string button, bool? state = null, int? controller = null);
void SetAnalog(IDictionary<string, int?> controls, object controller = null);
void SetAnalog(IReadOnlyDictionary<string, int?> controls, object controller = null);
void SetAnalog(string control, int? value = null, object controller = null);
}
}
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/Api/Interfaces/IMovieApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface IMovieApi : IExternalApi
bool StartsFromSavestate();
bool StartsFromSaveram();
string Filename();
IDictionary<string, object> GetInput(int frame, int? controller = null);
IReadOnlyDictionary<string, object> GetInput(int frame, int? controller = null);
string GetInputAsMnemonic(int frame);
bool GetReadOnly();
ulong GetRerecordCount();
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/inputAdapters/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class InputManager
public StickyXorAdapter StickyXorAdapter { get; } = new StickyXorAdapter();

/// <summary>
/// Used to AND to another controller, used for <see cref="IJoypadApi.Set(IDictionary{string, bool}, int?)">JoypadApi.Set</see>
/// Used to AND to another controller, used for <see cref="IJoypadApi.Set(IReadOnlyDictionary{string, bool}, int?)">JoypadApi.Set</see>
/// </summary>
public OverrideAdapter ButtonOverrideAdapter { get; } = new OverrideAdapter();

Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/lua/NLuaTableHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public NLuaTableHelper(Lua lua, Action<string> logCallback)

public LuaTable CreateTable() => _lua.NewTable();

public LuaTable DictToTable<T>(IDictionary<string, T> dictionary)
public LuaTable DictToTable<T>(IReadOnlyDictionary<string, T> dictionary)
{
var table = _lua.NewTable();

Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Emulation.Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private static List<string> ToControlNameList(IEnumerable<string> buttonList, in
return buttons;
}

public static IDictionary<string, object> ToDictionary(this IController controller, int? controllerNum = null)
public static IReadOnlyDictionary<string, object> ToDictionary(this IController controller, int? controllerNum = null)
{
var buttons = new Dictionary<string, object>();

Expand Down

0 comments on commit fcd7a47

Please sign in to comment.