From 345b628dad78761b0dffbc80c1f8da60d8d0b97c Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 25 Nov 2013 00:55:56 +0000 Subject: [PATCH] Some more misc code cleanup --- BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs | 88 ++++++------------- .../tools/Lua/Libraries/EmuLuaLibrary.cs | 28 +++--- .../tools/Lua/LuaConsole.cs | 4 +- 3 files changed, 44 insertions(+), 76 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 9f9cc7433c..ce6da5f129 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Data; using System.Drawing; using System.IO; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows.Forms; using BizHawk.Client.Common; @@ -28,7 +25,7 @@ namespace BizHawk.Client.EmuHawk public const string ENDIAN = "EndianColumn"; public const string TYPE = "DisplayTypeColumn"; - private readonly Dictionary DefaultColumnWidths = new Dictionary + private readonly Dictionary _defaultColumnWidths = new Dictionary { { NAME, 128 }, { ADDRESS, 60 }, @@ -41,10 +38,10 @@ namespace BizHawk.Client.EmuHawk { TYPE, 55 }, }; - private int defaultWidth; - private int defaultHeight; + private int _defaultWidth; + private int _defaultHeight; private string _sortedColumn = String.Empty; - private bool _sortReverse = false; + private bool _sortReverse; public bool UpdateBefore { get { return false; } } @@ -119,7 +116,7 @@ namespace BizHawk.Client.EmuHawk private void UpdateMessageLabel(bool saved = false) { - string message = String.Empty; + string message; if (saved) { @@ -235,8 +232,8 @@ namespace BizHawk.Client.EmuHawk private void LoadConfigSettings() { //Size and Positioning - defaultWidth = Size.Width; //Save these first so that the user can restore to its original size - defaultHeight = Size.Height; + _defaultWidth = Size.Width; //Save these first so that the user can restore to its original size + _defaultHeight = Size.Height; if (Global.Config.CheatsSaveWindowPosition && Global.Config.CheatsWndx >= 0 && Global.Config.CheatsWndy >= 0) { @@ -270,7 +267,7 @@ namespace BizHawk.Client.EmuHawk var width = Global.Config.CheatsColumnWidths[columnName]; if (width == -1) { - width = DefaultColumnWidths[columnName]; + width = _defaultColumnWidths[columnName]; } return width; @@ -310,7 +307,7 @@ namespace BizHawk.Client.EmuHawk text = Global.CheatList[index].Size.ToString(); break; case ENDIAN: - text = Global.CheatList[index].BigEndian.Value ? "Big" : "Little"; + text = (Global.CheatList[index].BigEndian ?? false) ? "Big" : "Little"; break; case TYPE: text = Watch.DisplayTypeToString(Global.CheatList[index].Type); @@ -333,45 +330,19 @@ namespace BizHawk.Client.EmuHawk } } - private List SelectedIndices + private IEnumerable SelectedIndices { - get - { - var selected = new List(); - ListView.SelectedIndexCollection indices = CheatListView.SelectedIndices; - foreach (int index in indices) - { - selected.Add(index); - } - return selected; - } + get { return CheatListView.SelectedIndices.Cast().ToList(); } } - private List SelectedItems + private IEnumerable SelectedItems { - get - { - var selected = new List(); - if (SelectedIndices.Any()) - { - foreach (int index in SelectedIndices) - { - if (!Global.CheatList[index].IsSeparator) - { - selected.Add(Global.CheatList[index]); - } - } - } - return selected; - } + get { return SelectedIndices.Select(index => Global.CheatList[index]); } } - private List SelectedCheats + private IEnumerable SelectedCheats { - get - { - return SelectedItems.Where(x => !x.IsSeparator).ToList(); - } + get { return SelectedItems.Where(x => !x.IsSeparator).ToList(); } } private void MoveUp() @@ -444,21 +415,21 @@ namespace BizHawk.Client.EmuHawk private void Remove() { - if (SelectedIndices.Any()) + if (SelectedItems.Any()) { - foreach (int index in SelectedIndices) + foreach (var item in SelectedItems) { - Global.CheatList.Remove(Global.CheatList[SelectedIndices[0]]); //SelectedIndices[0] used since each iteration will make this the correct list index + Global.CheatList.Remove(item); } - CheatListView.SelectedIndices.Clear(); - } - UpdateDialog(); + CheatListView.SelectedIndices.Clear(); + UpdateDialog(); + } } private void Toggle() { - SelectedCheats.ForEach(x => x.Toggle()); + SelectedCheats.ToList().ForEach(x => x.Toggle()); } private void SaveColumnInfo() @@ -529,7 +500,7 @@ namespace BizHawk.Client.EmuHawk { if (SelectedCheats.Any()) { - var cheat = SelectedCheats[0]; + var cheat = SelectedCheats.First(); CheatEditor.SetCheat(cheat); CheatGroupBox.Text = "Editing Cheat " + cheat.Name + " - " + cheat.AddressStr; } @@ -564,11 +535,8 @@ namespace BizHawk.Client.EmuHawk public string GenerateDefaultCheatFilename() { - PathEntry pathEntry = Global.Config.PathEntries[Global.Emulator.SystemId, "Cheats"]; - if (pathEntry == null) - { - pathEntry = Global.Config.PathEntries[Global.Emulator.SystemId, "Base"]; - } + PathEntry pathEntry = Global.Config.PathEntries[Global.Emulator.SystemId, "Cheats"] ?? + Global.Config.PathEntries[Global.Emulator.SystemId, "Base"]; string path = PathManager.MakeAbsolutePath(pathEntry.Path, Global.Emulator.SystemId); var f = new FileInfo(path); @@ -772,7 +740,7 @@ namespace BizHawk.Client.EmuHawk private void RestoreWindowSizeMenuItem_Click(object sender, EventArgs e) { - Size = new Size(defaultWidth, defaultHeight); + Size = new Size(_defaultWidth, _defaultHeight); Global.Config.CheatsSaveWindowPosition = true; Global.Config.CheatsAlwaysOnTop = TopMost = false; Global.Config.DisableCheatsOnLoad = false; @@ -805,8 +773,8 @@ namespace BizHawk.Client.EmuHawk { "DisplayTypeColumn", 8 }, }; - Global.Config.CheatsColumnShow = new Dictionary() - { + Global.Config.CheatsColumnShow = new Dictionary + { { "NamesColumn", true }, { "AddressColumn", true }, { "ValueColumn", true }, diff --git a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs index 8e65a0697a..bf87230d49 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/Libraries/EmuLuaLibrary.cs @@ -6,14 +6,14 @@ using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk { - public partial class EmuLuaLibrary + public class EmuLuaLibrary { private Lua _lua = new Lua(); private readonly LuaConsole _caller; - private Lua currThread; - private FormsLuaLibrary _formsLibrary = new FormsLuaLibrary(); - private EventLuaLibrary _eventLibrary = new EventLuaLibrary(ConsoleLuaLibrary.console_log); - private GuiLuaLibrary _guiLibrary = new GuiLuaLibrary(); + private Lua _currThread; + private readonly FormsLuaLibrary _formsLibrary = new FormsLuaLibrary(); + private readonly EventLuaLibrary _eventLibrary = new EventLuaLibrary(ConsoleLuaLibrary.console_log); + private readonly GuiLuaLibrary _guiLibrary = new GuiLuaLibrary(); public LuaDocumentation Docs = new LuaDocumentation(); public bool IsRunning; @@ -79,8 +79,8 @@ namespace BizHawk.Client.EmuHawk new EmulatorLuaLibrary( _lua, - new Action(Frameadvance), - new Action(EmuYield) + Frameadvance, + EmuYield ).LuaRegister(lua, Docs); _eventLibrary.LuaRegister(lua, Docs); @@ -98,10 +98,10 @@ namespace BizHawk.Client.EmuHawk Docs.Sort(); } - public Lua SpawnCoroutine(string File) + public Lua SpawnCoroutine(string file) { Lua lua = _lua.NewThread(); - var main = lua.LoadFile(File); + var main = lua.LoadFile(file); lua.Push(main); //push main function on to stack for subsequent resuming return lua; } @@ -114,9 +114,9 @@ namespace BizHawk.Client.EmuHawk public ResumeResult ResumeScript(Lua script) { - currThread = script; + _currThread = script; int execResult = script.Resume(0); - currThread = null; + _currThread = null; var result = new ResumeResult(); if (execResult == 0) { @@ -132,7 +132,7 @@ namespace BizHawk.Client.EmuHawk return result; } - public void print(string s) + public void Print(string s) { _caller.AddText(s); } @@ -140,13 +140,13 @@ namespace BizHawk.Client.EmuHawk private void Frameadvance() { FrameAdvanceRequested = true; - currThread.Yield(0); + _currThread.Yield(0); } private void EmuYield() { GlobalWin.DisplayManager.NeedsToPaint = true; - currThread.Yield(0); + _currThread.Yield(0); } } } diff --git a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 629fe06842..7ff22acdc8 100644 --- a/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -639,12 +639,12 @@ namespace BizHawk.Client.EmuHawk private IEnumerable SelectedIndices { - get { return LuaListView.SelectedIndices.Cast().ToList(); } + get { return LuaListView.SelectedIndices.Cast(); } } private IEnumerable SelectedItems { - get { return SelectedIndices.Select(index => _luaList[index]).ToList(); } + get { return SelectedIndices.Select(index => _luaList[index]); } } private IEnumerable SelectedFiles