cheats code cleanup

This commit is contained in:
adelikat 2019-11-02 11:25:11 -05:00
parent 1239149af5
commit ae7221988b
6 changed files with 41 additions and 50 deletions

View File

@ -16,7 +16,6 @@ namespace BizHawk.Client.Common
}
private readonly Watch _watch;
private readonly CompareType _comparisonType;
private int? _compare;
private int _val;
private bool _enabled;
@ -27,7 +26,7 @@ namespace BizHawk.Client.Common
_watch = watch;
_compare = compare;
_val = value;
_comparisonType = comparisonType;
ComparisonType = comparisonType;
Pulse();
}
@ -131,7 +130,7 @@ namespace BizHawk.Client.Common
}
}
public CompareType ComparisonType => _comparisonType;
public CompareType ComparisonType { get; private set; }
public void Enable(bool handleChange = true)
{
@ -187,7 +186,7 @@ namespace BizHawk.Client.Common
{
if (_compare.HasValue)
{
switch (_comparisonType)
switch (ComparisonType)
{
default:
case CompareType.None: // This should never happen, but it's here just in case. adelikat: And yet it does! Cheat Code converter doesn't do this. Changing this to default to equal since 99.9999% of all cheats are going to be equals
@ -323,12 +322,12 @@ namespace BizHawk.Client.Common
else
{
if (addr == _watch.Address)
{
{
return (byte)(_val & 0xFF);
}
if (addr == _watch.Address + 1)
{
{
return (byte)((_val >> 8) & 0xFF);
}
@ -396,15 +395,13 @@ namespace BizHawk.Client.Common
public override bool Equals(object obj)
{
if (obj is Watch)
if (obj is Watch watch)
{
var watch = obj as Watch;
return Domain == watch.Domain && Address == watch.Address;
}
if (obj is Cheat)
if (obj is Cheat cheat)
{
var cheat = obj as Cheat;
return Domain == cheat.Domain && Address == cheat.Address;
}

View File

@ -25,7 +25,6 @@ namespace BizHawk.Client.Common
private const string ComparisonType = "ComparisonTypeColumn";
private List<Cheat> _cheatList = new List<Cheat>();
private string _currentFileName = "";
private string _defaultFileName = "";
private bool _changes;
@ -51,7 +50,7 @@ namespace BizHawk.Client.Common
}
}
public string CurrentFileName => _currentFileName;
public string CurrentFileName { get; private set; } = "";
public bool IsReadOnly => false;
@ -97,21 +96,26 @@ namespace BizHawk.Client.Common
if (_cheatList.Any() && _changes && autosave)
{
if (string.IsNullOrEmpty(_currentFileName))
if (string.IsNullOrEmpty(CurrentFileName))
{
_currentFileName = _defaultFileName;
CurrentFileName = _defaultFileName;
}
Save();
}
_cheatList.Clear();
_currentFileName = "";
CurrentFileName = "";
Changes = false;
}
public void Add(Cheat cheat)
{
if (cheat is null)
{
throw new ArgumentNullException($"{nameof(cheat)} can not be null");
}
if (cheat.IsSeparator)
{
_cheatList.Add(cheat);
@ -324,28 +328,28 @@ namespace BizHawk.Client.Common
{
if (Changes && _cheatList.Any())
{
if (string.IsNullOrWhiteSpace(_currentFileName))
if (string.IsNullOrWhiteSpace(CurrentFileName))
{
_currentFileName = _defaultFileName;
CurrentFileName = _defaultFileName;
}
SaveFile(_currentFileName);
SaveFile(CurrentFileName);
}
else if (!_cheatList.Any() && !string.IsNullOrWhiteSpace(_currentFileName))
else if (!_cheatList.Any() && !string.IsNullOrWhiteSpace(CurrentFileName))
{
new FileInfo(_currentFileName).Delete();
new FileInfo(CurrentFileName).Delete();
}
}
}
public bool Save()
{
if (string.IsNullOrWhiteSpace(_currentFileName))
if (string.IsNullOrWhiteSpace(CurrentFileName))
{
_currentFileName = _defaultFileName;
CurrentFileName = _defaultFileName;
}
return SaveFile(_currentFileName);
return SaveFile(CurrentFileName);
}
public bool SaveFile(string path)
@ -371,7 +375,7 @@ namespace BizHawk.Client.Common
else
{
// Set to hex for saving
var temp_cheat_type = cheat.Type;
var tempCheatType = cheat.Type;
cheat.SetType(DisplayType.Hex);
@ -388,7 +392,7 @@ namespace BizHawk.Client.Common
.Append(cheat.ComparisonType).Append('\t')
.AppendLine();
cheat.SetType(temp_cheat_type);
cheat.SetType(tempCheatType);
}
}
@ -396,8 +400,8 @@ namespace BizHawk.Client.Common
sw.WriteLine(sb.ToString());
}
_currentFileName = path;
Global.Config.RecentCheats.Add(_currentFileName);
CurrentFileName = path;
Global.Config.RecentCheats.Add(CurrentFileName);
Changes = false;
return true;
}
@ -417,7 +421,7 @@ namespace BizHawk.Client.Common
if (!append)
{
_currentFileName = path;
CurrentFileName = path;
}
using (var sr = file.OpenText())
@ -441,7 +445,7 @@ namespace BizHawk.Client.Common
int? compare;
var size = WatchSize.Byte;
var type = DisplayType.Hex;
var bigendian = false;
var bigEndian = false;
Cheat.CompareType comparisonType = Cheat.CompareType.None;
if (s.Length < 6)
@ -471,13 +475,13 @@ namespace BizHawk.Client.Common
{
size = Watch.SizeFromChar(vals[6][0]);
type = Watch.DisplayTypeFromChar(vals[7][0]);
bigendian = vals[8] == "1";
bigEndian = vals[8] == "1";
}
// For backwards compatibility, don't assume these values exist
if (vals.Length > 9)
{
if (!Enum.TryParse<Cheat.CompareType>(vals[9], out comparisonType))
if (!Enum.TryParse(vals[9], out comparisonType))
{
continue; // Not sure if this is the best answer, could just resort to ==
}
@ -488,7 +492,7 @@ namespace BizHawk.Client.Common
address,
size,
type,
bigendian,
bigEndian,
name);
Add(new Cheat(watch, value, compare, !Global.Config.DisableCheatsOnLoad && enabled, comparisonType));

View File

@ -26,7 +26,7 @@ namespace BizHawk.Client.EmuHawk
private Cheat _cheat;
private bool _loading;
private bool _editmode;
private bool _editMode;
private Action _addCallback;
private Action _editCallback;
@ -215,7 +215,7 @@ namespace BizHawk.Client.EmuHawk
{
var valid = !string.IsNullOrWhiteSpace(AddressBox.Text) && !string.IsNullOrWhiteSpace(ValueBox.Text);
AddButton.Enabled = valid;
EditButton.Enabled = _editmode && valid;
EditButton.Enabled = _editMode && valid;
}
private void SizeDropDown_SelectedIndexChanged(object sender, EventArgs e)
@ -276,7 +276,7 @@ namespace BizHawk.Client.EmuHawk
public void SetCheat(Cheat cheat)
{
_editmode = true;
_editMode = true;
_cheat = cheat;
if (cheat.IsSeparator)
{
@ -291,7 +291,7 @@ namespace BizHawk.Client.EmuHawk
public void ClearForm()
{
_cheat = Cheat.Separator;
_editmode = false;
_editMode = false;
SetFormToDefault();
}

View File

@ -112,7 +112,6 @@
this.CheatListView.UseCustomBackground = true;
this.CheatListView.ColumnClick += new BizHawk.Client.EmuHawk.InputRoll.ColumnClickEventHandler(this.CheatListView_ColumnClick);
this.CheatListView.SelectedIndexChanged += new System.EventHandler(this.CheatListView_SelectedIndexChanged);
this.CheatListView.Click += new System.EventHandler(this.CheatListView_Click);
this.CheatListView.DragDrop += new System.Windows.Forms.DragEventHandler(this.NewCheatForm_DragDrop);
this.CheatListView.DragEnter += new System.Windows.Forms.DragEventHandler(this.NewCheatForm_DragEnter);
this.CheatListView.DoubleClick += new System.EventHandler(this.CheatListView_DoubleClick);

View File

@ -209,7 +209,7 @@ namespace BizHawk.Client.EmuHawk
private void SaveConfigSettings()
{
Settings.Columns =CheatListView.AllColumns;
Settings.Columns = CheatListView.AllColumns;
if (WindowState == FormWindowState.Normal)
{
@ -328,15 +328,9 @@ namespace BizHawk.Client.EmuHawk
private IEnumerable<int> SelectedIndices => CheatListView.SelectedRows;
private IEnumerable<Cheat> SelectedItems
{
get { return SelectedIndices.Select(index => Global.CheatList[index]); }
}
private IEnumerable<Cheat> SelectedItems => SelectedIndices.Select(index => Global.CheatList[index]);
private IEnumerable<Cheat> SelectedCheats
{
get { return SelectedItems.Where(x => !x.IsSeparator); }
}
private IEnumerable<Cheat> SelectedCheats => SelectedItems.Where(x => !x.IsSeparator);
private void DoSelectedIndexChange()
{
@ -639,10 +633,6 @@ namespace BizHawk.Client.EmuHawk
#region ListView and Dialog Events
private void CheatListView_Click(object sender, EventArgs e)
{
}
private void CheatListView_DoubleClick(object sender, EventArgs e)
{
ToggleMenuItem_Click(sender, e);

View File

@ -288,6 +288,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unpausing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unthrottle/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unthrottled/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=vals/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Vectrex/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Virtua/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Virtualpad/@EntryIndexedValue">True</s:Boolean>