Skip to content

Commit

Permalink
Make all collections readonly in API surface
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Mar 1, 2022
1 parent 8b07f9e commit 5f3199a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/Api/Classes/EmulationApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ out var l
return null;
}

public Dictionary<string, ulong> GetRegisters()
public IReadOnlyDictionary<string, ulong> GetRegisters()
{
try
{
Expand Down
24 changes: 8 additions & 16 deletions src/BizHawk.Client.Common/Api/Classes/MovieApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Linq;

using BizHawk.Common;
using BizHawk.Emulation.Common;

namespace BizHawk.Client.Common
Expand Down Expand Up @@ -73,23 +72,16 @@ public void Save(string filename = null)
_movieSession.Movie.Save();
}

public Dictionary<string, string> GetHeader()
{
var table = new Dictionary<string, string>();
if (_movieSession.Movie.NotActive())
{
return table;
}
foreach (var (k, v) in _movieSession.Movie.HeaderEntries) table[k] = v;
return table;
}
public IReadOnlyDictionary<string, string> GetHeader()
=> _movieSession.Movie.NotActive()
? new Dictionary<string, string>()
: _movieSession.Movie.HeaderEntries.ToDictionary(static kvp => kvp.Key, static kvp => kvp.Value);

public List<string> GetComments() => _movieSession.Movie.Comments.ToList();
public IReadOnlyList<string> GetComments()
=> _movieSession.Movie.Comments.ToList();

public List<string> GetSubtitles() =>
_movieSession.Movie.Subtitles
.Select(s => s.ToString())
.ToList();
public IReadOnlyList<string> GetSubtitles()
=> _movieSession.Movie.Subtitles.Select(static s => s.ToString()).ToList();

public string Filename() => _movieSession.Movie.Filename;

Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/Api/Interfaces/IEmulationApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IEmulationApi : IExternalApi
int FrameCount();
object Disassemble(uint pc, string name = "");
ulong? GetRegister(string name);
Dictionary<string, ulong> GetRegisters();
IReadOnlyDictionary<string, ulong> GetRegisters();
void SetRegister(string register, int value);
long TotalExecutedCycles();
string GetSystemId();
Expand Down
6 changes: 3 additions & 3 deletions src/BizHawk.Client.Common/Api/Interfaces/IMovieApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public interface IMovieApi : IExternalApi
void SetRerecordCounting(bool counting);
void Stop();
double GetFps();
Dictionary<string, string> GetHeader();
List<string> GetComments();
List<string> GetSubtitles();
IReadOnlyDictionary<string, string> GetHeader();
IReadOnlyList<string> GetComments();
IReadOnlyList<string> GetSubtitles();
}
}
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 @@ -36,7 +36,7 @@ public LuaTable DictToTable<T>(IReadOnlyDictionary<string, T> dictionary)

public IEnumerable<T> EnumerateValues<T>(LuaTable table) => table.Values.Cast<T>();

public LuaTable ListToTable<T>(IList<T> list, int indexFrom = 1)
public LuaTable ListToTable<T>(IReadOnlyList<T> list, int indexFrom = 1)
{
var table = _lua.NewTable();
for (int i = 0, l = list.Count; i != l; i++) table[indexFrom + i] = list[i];
Expand Down

0 comments on commit 5f3199a

Please sign in to comment.