Cheats - fix bug where compare is 0 when clicking a cheat with a null compare value, refactor CheatList.Add() to be upsert logic
This commit is contained in:
parent
92f8f9982c
commit
6f29976e9d
|
@ -106,23 +106,19 @@ namespace BizHawk.Client.Common
|
|||
if (cheat.IsSeparator)
|
||||
{
|
||||
_cheatList.Add(cheat);
|
||||
Changes = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
cheat.Changed += CheatChanged;
|
||||
if (_cheatList.Any(x => x.Domain == cheat.Domain && x.Address == cheat.Address))
|
||||
if (HasCheat(cheat))
|
||||
{
|
||||
_cheatList.FirstOrDefault(x => x.Domain == cheat.Domain && x.Address == cheat.Address).Enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
_cheatList.Add(cheat);
|
||||
Changes = true;
|
||||
_cheatList.Remove(Global.CheatList.FirstOrDefault(x => x.Domain == cheat.Domain && x.Address == cheat.Address));
|
||||
}
|
||||
_cheatList.Add(cheat);
|
||||
}
|
||||
|
||||
|
||||
Changes = true;
|
||||
}
|
||||
|
||||
public void Insert(int index, Cheat c)
|
||||
|
@ -201,7 +197,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public bool HasCheat(Cheat cheat)
|
||||
{
|
||||
return _cheatList.FirstOrDefault(x => x.Domain == cheat.Domain && x.Address == cheat.Address) != null;
|
||||
return _cheatList.Any(x => x.Domain == cheat.Domain && x.Address == cheat.Address);
|
||||
}
|
||||
|
||||
public void SaveOnClose()
|
||||
|
|
|
@ -71,6 +71,10 @@ namespace BizHawk.Client.EmuHawk
|
|||
BigEndianCheckBox.Checked = _cheat.BigEndian.Value;
|
||||
|
||||
CheckFormState();
|
||||
if (!_cheat.Compare.HasValue)
|
||||
{
|
||||
CompareBox.Text = String.Empty; //Necessary hack until WatchValueBox.ToRawInt() becomes nullable
|
||||
}
|
||||
_loading = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
LoadConfigSettings();
|
||||
ToggleGameGenieButton();
|
||||
CheatEditor.SetAddEvent(AddCheat);
|
||||
CheatEditor.SetEditEvent(EditCheat);
|
||||
CheatEditor.SetEditEvent(AddCheat); //CheatList.Add is already an upsert, so there is nothing different to handle here
|
||||
UpdateValues();
|
||||
}
|
||||
|
||||
|
@ -222,23 +222,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void AddCheat()
|
||||
{
|
||||
if (Global.CheatList.HasCheat(CheatEditor.Cheat))
|
||||
{
|
||||
EditCheat();
|
||||
}
|
||||
else
|
||||
{
|
||||
Global.CheatList.Add(CheatEditor.Cheat);
|
||||
UpdateListView();
|
||||
UpdateMessageLabel();
|
||||
}
|
||||
}
|
||||
|
||||
private void EditCheat()
|
||||
{
|
||||
var cheat = CheatEditor.Cheat;
|
||||
Global.CheatList.Remove(Global.CheatList.FirstOrDefault(x => x.Domain == cheat.Domain && x.Address == cheat.Address));
|
||||
Global.CheatList.Add(cheat);
|
||||
Global.CheatList.Add(CheatEditor.Cheat);
|
||||
UpdateListView();
|
||||
UpdateMessageLabel();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue