Use read-only dict type in .NET API

This commit is contained in:
YoshiRulz 2021-10-10 18:40:26 +10:00
parent 47c5fcc39e
commit fcd7a47435
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
9 changed files with 17 additions and 17 deletions

View File

@ -25,7 +25,7 @@ namespace BizHawk.Client.Common
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;

View File

@ -20,17 +20,17 @@ namespace BizHawk.Client.Common
_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);
}
@ -51,7 +51,7 @@ namespace BizHawk.Client.Common
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
@ -88,7 +88,7 @@ namespace BizHawk.Client.Common
}
}
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);
}

View File

@ -23,7 +23,7 @@ namespace BizHawk.Client.Common
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())
{

View File

@ -10,6 +10,6 @@ namespace BizHawk.Client.Common
string GetStatus();
bool IsStatusBad();
string GetBoardType();
Dictionary<string, string> GetOptions();
IReadOnlyDictionary<string, string> GetOptions();
}
}

View File

@ -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);
}
}

View File

@ -7,7 +7,7 @@ namespace BizHawk.Client.Common
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();

View File

@ -32,7 +32,7 @@ namespace BizHawk.Client.Common
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();

View File

@ -22,7 +22,7 @@ namespace BizHawk.Client.Common
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();

View File

@ -390,7 +390,7 @@ namespace BizHawk.Emulation.Common
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>();