Implement IList on CheatList object
This commit is contained in:
parent
39ca14dda1
commit
a4d3e68f66
|
@ -9,7 +9,7 @@ using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public class CheatList : IEnumerable<Cheat>
|
public class CheatList : ICollection<Cheat>, IEnumerable<Cheat>
|
||||||
{
|
{
|
||||||
private bool _changes;
|
private bool _changes;
|
||||||
public bool Changes
|
public bool Changes
|
||||||
|
@ -111,7 +111,7 @@ namespace BizHawk.Client.Common
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cheat.Changed += CheatChanged;
|
cheat.Changed += CheatChanged;
|
||||||
if (HasCheat(cheat))
|
if (Contains(cheat))
|
||||||
{
|
{
|
||||||
_cheatList.Remove(Global.CheatList.FirstOrDefault(x => x.Domain == cheat.Domain && x.Address == cheat.Address));
|
_cheatList.Remove(Global.CheatList.FirstOrDefault(x => x.Domain == cheat.Domain && x.Address == cheat.Address));
|
||||||
}
|
}
|
||||||
|
@ -136,13 +136,21 @@ namespace BizHawk.Client.Common
|
||||||
Changes = true;
|
Changes = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(Cheat c)
|
public bool Remove(Cheat c)
|
||||||
|
{
|
||||||
|
bool result = _cheatList.Remove(c);
|
||||||
|
if (result)
|
||||||
{
|
{
|
||||||
_cheatList.Remove(c);
|
|
||||||
Changes = true;
|
Changes = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(Watch w)
|
public bool Remove(Watch w)
|
||||||
{
|
{
|
||||||
|
|
||||||
var cheat = _cheatList.FirstOrDefault(x => x.Domain == w.Domain && x.Address == w.Address);
|
var cheat = _cheatList.FirstOrDefault(x => x.Domain == w.Domain && x.Address == w.Address);
|
||||||
|
@ -150,9 +158,26 @@ namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
_cheatList.Remove(cheat);
|
_cheatList.Remove(cheat);
|
||||||
Changes = true;
|
Changes = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Contains(Cheat cheat)
|
||||||
|
{
|
||||||
|
return _cheatList.Any(x => x.Domain == cheat.Domain && x.Address == cheat.Address);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CopyTo(Cheat[] array, int arrayIndex)
|
||||||
|
{
|
||||||
|
_cheatList.CopyTo(array, arrayIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsReadOnly { get { return false; } }
|
||||||
|
|
||||||
public void RemoveRange(IEnumerable<Cheat> cheats)
|
public void RemoveRange(IEnumerable<Cheat> cheats)
|
||||||
{
|
{
|
||||||
foreach (var cheat in cheats)
|
foreach (var cheat in cheats)
|
||||||
|
@ -195,11 +220,6 @@ namespace BizHawk.Client.Common
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasCheat(Cheat cheat)
|
|
||||||
{
|
|
||||||
return _cheatList.Any(x => x.Domain == cheat.Domain && x.Address == cheat.Address);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SaveOnClose()
|
public void SaveOnClose()
|
||||||
{
|
{
|
||||||
if (Global.Config.CheatsAutoSaveOnClose)
|
if (Global.Config.CheatsAutoSaveOnClose)
|
||||||
|
|
Loading…
Reference in New Issue