From fcf7ac1faba2647933c351f7f7dd1efc38a8136c Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sat, 17 Dec 2022 14:54:03 +1000 Subject: [PATCH] Change first param of `{Save,Load}QuickSave` from string to int also swapped bool params of `SaveQuickSave` --- .../Api/Classes/SaveStateApi.cs | 6 ++--- src/BizHawk.Client.Common/ArgParser.cs | 2 +- src/BizHawk.Client.Common/IMainFormForApi.cs | 4 +-- src/BizHawk.Client.Common/ParsedCLIFlags.cs | 5 ++-- .../IMainFormForTools.cs | 2 +- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 25 +++++-------------- src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs | 4 +-- src/BizHawk.Client.EmuHawk/MainForm.cs | 10 ++++---- .../tools/BasicBot/BasicBot.cs | 13 ++-------- 9 files changed, 24 insertions(+), 47 deletions(-) diff --git a/src/BizHawk.Client.Common/Api/Classes/SaveStateApi.cs b/src/BizHawk.Client.Common/Api/Classes/SaveStateApi.cs index a34c1076e0..872e48961d 100644 --- a/src/BizHawk.Client.Common/Api/Classes/SaveStateApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/SaveStateApi.cs @@ -1,8 +1,6 @@ using System; using System.IO; -using BizHawk.Common; - namespace BizHawk.Client.Common { public sealed class SaveStateApi : ISaveStateApi @@ -30,14 +28,14 @@ namespace BizHawk.Client.Common public void LoadSlot(int slotNum, bool suppressOSD) { - if (0.RangeTo(9).Contains(slotNum)) _mainForm.LoadQuickSave($"QuickSave{slotNum}", suppressOSD); + if (slotNum is >= 0 and <= 9) _mainForm.LoadQuickSave(slotNum, suppressOSD: suppressOSD); } public void Save(string path, bool suppressOSD) => _mainForm.SaveState(path, path, true, suppressOSD); public void SaveSlot(int slotNum, bool suppressOSD) { - if (0.RangeTo(9).Contains(slotNum)) _mainForm.SaveQuickSave($"QuickSave{slotNum}", true, suppressOSD); + if (slotNum is >= 0 and <= 9) _mainForm.SaveQuickSave(slotNum, suppressOSD: suppressOSD, fromLua: true); } } } diff --git a/src/BizHawk.Client.Common/ArgParser.cs b/src/BizHawk.Client.Common/ArgParser.cs index 5bff6e25df..d15c0d2f6a 100644 --- a/src/BizHawk.Client.Common/ArgParser.cs +++ b/src/BizHawk.Client.Common/ArgParser.cs @@ -181,7 +181,7 @@ namespace BizHawk.Client.Common } parsed = new ParsedCLIFlags( - cmdLoadSlot: cmdLoadSlot, + cmdLoadSlot: cmdLoadSlot is null ? null : int.Parse(cmdLoadSlot), cmdLoadState: cmdLoadState, cmdConfigFile: cmdConfigFile, cmdMovie: cmdMovie, diff --git a/src/BizHawk.Client.Common/IMainFormForApi.cs b/src/BizHawk.Client.Common/IMainFormForApi.cs index 9a23ee1a12..d5d130f00c 100644 --- a/src/BizHawk.Client.Common/IMainFormForApi.cs +++ b/src/BizHawk.Client.Common/IMainFormForApi.cs @@ -69,7 +69,7 @@ namespace BizHawk.Client.Common bool LoadMovie(string filename, string archive = null); /// only referenced from - void LoadQuickSave(string quickSlotName, bool suppressOSD = false); + void LoadQuickSave(int slot, bool suppressOSD = false); /// only referenced from EmuClientApi bool LoadRom(string path, LoadRomArgs args); @@ -89,7 +89,7 @@ namespace BizHawk.Client.Common bool RestartMovie(); /// only referenced from - void SaveQuickSave(string quickSlotName, bool fromLua = false, bool suppressOSD = false); + void SaveQuickSave(int slot, bool suppressOSD = false, bool fromLua = false); void SaveState(string path, string userFriendlyStateName, bool fromLua = false, bool suppressOSD = false); diff --git a/src/BizHawk.Client.Common/ParsedCLIFlags.cs b/src/BizHawk.Client.Common/ParsedCLIFlags.cs index 93a31febb3..69b2075da5 100644 --- a/src/BizHawk.Client.Common/ParsedCLIFlags.cs +++ b/src/BizHawk.Client.Common/ParsedCLIFlags.cs @@ -6,7 +6,7 @@ namespace BizHawk.Client.Common { public readonly struct ParsedCLIFlags { - public readonly string? cmdLoadSlot; + public readonly int? cmdLoadSlot; public readonly string? cmdLoadState; @@ -46,7 +46,8 @@ namespace BizHawk.Client.Common public readonly string? cmdRom; - public ParsedCLIFlags(string? cmdLoadSlot, + public ParsedCLIFlags( + int? cmdLoadSlot, string? cmdLoadState, string? cmdConfigFile, string? cmdMovie, diff --git a/src/BizHawk.Client.EmuHawk/IMainFormForTools.cs b/src/BizHawk.Client.EmuHawk/IMainFormForTools.cs index d2e6bbdca6..c3da536aeb 100644 --- a/src/BizHawk.Client.EmuHawk/IMainFormForTools.cs +++ b/src/BizHawk.Client.EmuHawk/IMainFormForTools.cs @@ -65,7 +65,7 @@ namespace BizHawk.Client.EmuHawk void FrameBufferResized(); /// only referenced from - void LoadQuickSave(string quickSlotName, bool suppressOSD = false); + void LoadQuickSave(int slot, bool suppressOSD = false); /// only referenced from bool LoadRom(string path, LoadRomArgs args); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 7d08441544..28f33ca41e 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -352,12 +352,12 @@ namespace BizHawk.Client.EmuHawk } private void QuickSavestateMenuItem_Click(object sender, EventArgs e) - => SaveQuickSave($"QuickSave{((MenuItem) sender).Text}"); + => SaveQuickSave(int.Parse(((MenuItem) sender).Text)); private void SaveNamedStateMenuItem_Click(object sender, EventArgs e) => SaveStateAs(); private void QuickLoadstateMenuItem_Click(object sender, EventArgs e) - => LoadQuickSave($"QuickSave{((MenuItem) sender).Text}"); + => LoadQuickSave(int.Parse(((MenuItem) sender).Text)); private void LoadNamedStateMenuItem_Click(object sender, EventArgs e) => LoadStateAs(); @@ -401,17 +401,13 @@ namespace BizHawk.Client.EmuHawk => SavestateCurrentSlot(); private void SavestateCurrentSlot() - { - SaveQuickSave($"QuickSave{Config.SaveSlot}"); - } + => SaveQuickSave(Config.SaveSlot); private void LoadCurrentSlotMenuItem_Click(object sender, EventArgs e) => LoadstateCurrentSlot(); private void LoadstateCurrentSlot() - { - LoadQuickSave($"QuickSave{Config.SaveSlot}"); - } + => LoadQuickSave(Config.SaveSlot); private void FlushSaveRAMMenuItem_Click(object sender, EventArgs e) { @@ -2525,17 +2521,8 @@ namespace BizHawk.Client.EmuHawk if (sender == Slot9StatusButton) slot = 9; if (sender == Slot0StatusButton) slot = 0; - if (e.Button == MouseButtons.Left) - { - if (HasSlot(slot)) - { - LoadQuickSave($"QuickSave{slot}"); - } - } - else if (e.Button == MouseButtons.Right) - { - SaveQuickSave($"QuickSave{slot}"); - } + if (e.Button is MouseButtons.Right) SaveQuickSave(slot); + else if (e.Button is MouseButtons.Left && HasSlot(slot)) LoadQuickSave(slot); } private void KeyPriorityStatusLabel_Click(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs b/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs index 22ebd10a2c..db992f481e 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs @@ -12,13 +12,13 @@ namespace BizHawk.Client.EmuHawk { void SelectAndSaveToSlot(int slot) { - SaveQuickSave($"QuickSave{slot}"); + SaveQuickSave(slot); Config.SaveSlot = slot; UpdateStatusSlots(); } void SelectAndLoadFromSlot(int slot) { - LoadQuickSave($"QuickSave{slot}"); + LoadQuickSave(slot); Config.SaveSlot = slot; UpdateStatusSlots(); } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 8a5990c002..504864ccc7 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -662,7 +662,7 @@ namespace BizHawk.Client.EmuHawk } else if (_argParser.cmdLoadSlot != null) { - LoadQuickSave($"QuickSave{_argParser.cmdLoadSlot}"); + LoadQuickSave(_argParser.cmdLoadSlot.Value); } else if (Config.AutoLoadLastSaveSlot) { @@ -4249,13 +4249,13 @@ namespace BizHawk.Client.EmuHawk } } - public void LoadQuickSave(string quickSlotName, bool suppressOSD = false) + public void LoadQuickSave(int slot, bool suppressOSD = false) { if (!Emulator.HasSavestates()) { return; } - + var quickSlotName = $"QuickSave{slot}"; EmuClient.OnBeforeQuickLoad(this, quickSlotName, out var handled); if (handled) { @@ -4316,13 +4316,13 @@ namespace BizHawk.Client.EmuHawk } // TODO: should backup logic be stuffed in into Client.Common.SaveStateManager? - public void SaveQuickSave(string quickSlotName, bool fromLua = false, bool suppressOSD = false) + public void SaveQuickSave(int slot, bool suppressOSD = false, bool fromLua = false) { if (!Emulator.HasSavestates()) { return; } - + var quickSlotName = $"QuickSave{slot}"; EmuClient.OnBeforeQuickSave(this, quickSlotName, out var handled); if (handled) { diff --git a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs index b1d7205643..0353ce6bea 100644 --- a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs +++ b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs @@ -152,17 +152,8 @@ namespace BizHawk.Client.EmuHawk .OfType() .ToDictionary(tkey => tkey.ButtonName, tvalue => tvalue.Probability); - private string SelectedSlot - { - get - { - char num = StartFromSlotBox.SelectedItem - .ToString() - .Last(); - - return $"QuickSave{num}"; - } - } + private int SelectedSlot + => (1 + StartFromSlotBox.SelectedIndex) % 10; private long Attempts {