Change first param of `{Save,Load}QuickSave` from string to int

also swapped bool params of `SaveQuickSave`
This commit is contained in:
YoshiRulz 2022-12-17 14:54:03 +10:00
parent 22ba0d5c25
commit fcf7ac1fab
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
9 changed files with 24 additions and 47 deletions

View File

@ -1,8 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using BizHawk.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
public sealed class SaveStateApi : ISaveStateApi public sealed class SaveStateApi : ISaveStateApi
@ -30,14 +28,14 @@ namespace BizHawk.Client.Common
public void LoadSlot(int slotNum, bool suppressOSD) 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 Save(string path, bool suppressOSD) => _mainForm.SaveState(path, path, true, suppressOSD);
public void SaveSlot(int slotNum, bool 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);
} }
} }
} }

View File

@ -181,7 +181,7 @@ namespace BizHawk.Client.Common
} }
parsed = new ParsedCLIFlags( parsed = new ParsedCLIFlags(
cmdLoadSlot: cmdLoadSlot, cmdLoadSlot: cmdLoadSlot is null ? null : int.Parse(cmdLoadSlot),
cmdLoadState: cmdLoadState, cmdLoadState: cmdLoadState,
cmdConfigFile: cmdConfigFile, cmdConfigFile: cmdConfigFile,
cmdMovie: cmdMovie, cmdMovie: cmdMovie,

View File

@ -69,7 +69,7 @@ namespace BizHawk.Client.Common
bool LoadMovie(string filename, string archive = null); bool LoadMovie(string filename, string archive = null);
/// <remarks>only referenced from <see cref="SaveStateApi"/></remarks> /// <remarks>only referenced from <see cref="SaveStateApi"/></remarks>
void LoadQuickSave(string quickSlotName, bool suppressOSD = false); void LoadQuickSave(int slot, bool suppressOSD = false);
/// <remarks>only referenced from <c>EmuClientApi</c></remarks> /// <remarks>only referenced from <c>EmuClientApi</c></remarks>
bool LoadRom(string path, LoadRomArgs args); bool LoadRom(string path, LoadRomArgs args);
@ -89,7 +89,7 @@ namespace BizHawk.Client.Common
bool RestartMovie(); bool RestartMovie();
/// <remarks>only referenced from <see cref="SaveStateApi"/></remarks> /// <remarks>only referenced from <see cref="SaveStateApi"/></remarks>
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); void SaveState(string path, string userFriendlyStateName, bool fromLua = false, bool suppressOSD = false);

View File

@ -6,7 +6,7 @@ namespace BizHawk.Client.Common
{ {
public readonly struct ParsedCLIFlags public readonly struct ParsedCLIFlags
{ {
public readonly string? cmdLoadSlot; public readonly int? cmdLoadSlot;
public readonly string? cmdLoadState; public readonly string? cmdLoadState;
@ -46,7 +46,8 @@ namespace BizHawk.Client.Common
public readonly string? cmdRom; public readonly string? cmdRom;
public ParsedCLIFlags(string? cmdLoadSlot, public ParsedCLIFlags(
int? cmdLoadSlot,
string? cmdLoadState, string? cmdLoadState,
string? cmdConfigFile, string? cmdConfigFile,
string? cmdMovie, string? cmdMovie,

View File

@ -65,7 +65,7 @@ namespace BizHawk.Client.EmuHawk
void FrameBufferResized(); void FrameBufferResized();
/// <remarks>only referenced from <see cref="BasicBot"/></remarks> /// <remarks>only referenced from <see cref="BasicBot"/></remarks>
void LoadQuickSave(string quickSlotName, bool suppressOSD = false); void LoadQuickSave(int slot, bool suppressOSD = false);
/// <remarks>only referenced from <see cref="MultiDiskBundler"/></remarks> /// <remarks>only referenced from <see cref="MultiDiskBundler"/></remarks>
bool LoadRom(string path, LoadRomArgs args); bool LoadRom(string path, LoadRomArgs args);

View File

@ -352,12 +352,12 @@ namespace BizHawk.Client.EmuHawk
} }
private void QuickSavestateMenuItem_Click(object sender, EventArgs e) 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 SaveNamedStateMenuItem_Click(object sender, EventArgs e) => SaveStateAs();
private void QuickLoadstateMenuItem_Click(object sender, EventArgs e) 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(); private void LoadNamedStateMenuItem_Click(object sender, EventArgs e) => LoadStateAs();
@ -401,17 +401,13 @@ namespace BizHawk.Client.EmuHawk
=> SavestateCurrentSlot(); => SavestateCurrentSlot();
private void SavestateCurrentSlot() private void SavestateCurrentSlot()
{ => SaveQuickSave(Config.SaveSlot);
SaveQuickSave($"QuickSave{Config.SaveSlot}");
}
private void LoadCurrentSlotMenuItem_Click(object sender, EventArgs e) private void LoadCurrentSlotMenuItem_Click(object sender, EventArgs e)
=> LoadstateCurrentSlot(); => LoadstateCurrentSlot();
private void LoadstateCurrentSlot() private void LoadstateCurrentSlot()
{ => LoadQuickSave(Config.SaveSlot);
LoadQuickSave($"QuickSave{Config.SaveSlot}");
}
private void FlushSaveRAMMenuItem_Click(object sender, EventArgs e) private void FlushSaveRAMMenuItem_Click(object sender, EventArgs e)
{ {
@ -2525,17 +2521,8 @@ namespace BizHawk.Client.EmuHawk
if (sender == Slot9StatusButton) slot = 9; if (sender == Slot9StatusButton) slot = 9;
if (sender == Slot0StatusButton) slot = 0; if (sender == Slot0StatusButton) slot = 0;
if (e.Button == MouseButtons.Left) if (e.Button is MouseButtons.Right) SaveQuickSave(slot);
{ else if (e.Button is MouseButtons.Left && HasSlot(slot)) LoadQuickSave(slot);
if (HasSlot(slot))
{
LoadQuickSave($"QuickSave{slot}");
}
}
else if (e.Button == MouseButtons.Right)
{
SaveQuickSave($"QuickSave{slot}");
}
} }
private void KeyPriorityStatusLabel_Click(object sender, EventArgs e) private void KeyPriorityStatusLabel_Click(object sender, EventArgs e)

View File

@ -12,13 +12,13 @@ namespace BizHawk.Client.EmuHawk
{ {
void SelectAndSaveToSlot(int slot) void SelectAndSaveToSlot(int slot)
{ {
SaveQuickSave($"QuickSave{slot}"); SaveQuickSave(slot);
Config.SaveSlot = slot; Config.SaveSlot = slot;
UpdateStatusSlots(); UpdateStatusSlots();
} }
void SelectAndLoadFromSlot(int slot) void SelectAndLoadFromSlot(int slot)
{ {
LoadQuickSave($"QuickSave{slot}"); LoadQuickSave(slot);
Config.SaveSlot = slot; Config.SaveSlot = slot;
UpdateStatusSlots(); UpdateStatusSlots();
} }

View File

@ -662,7 +662,7 @@ namespace BizHawk.Client.EmuHawk
} }
else if (_argParser.cmdLoadSlot != null) else if (_argParser.cmdLoadSlot != null)
{ {
LoadQuickSave($"QuickSave{_argParser.cmdLoadSlot}"); LoadQuickSave(_argParser.cmdLoadSlot.Value);
} }
else if (Config.AutoLoadLastSaveSlot) 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()) if (!Emulator.HasSavestates())
{ {
return; return;
} }
var quickSlotName = $"QuickSave{slot}";
EmuClient.OnBeforeQuickLoad(this, quickSlotName, out var handled); EmuClient.OnBeforeQuickLoad(this, quickSlotName, out var handled);
if (handled) if (handled)
{ {
@ -4316,13 +4316,13 @@ namespace BizHawk.Client.EmuHawk
} }
// TODO: should backup logic be stuffed in into Client.Common.SaveStateManager? // 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()) if (!Emulator.HasSavestates())
{ {
return; return;
} }
var quickSlotName = $"QuickSave{slot}";
EmuClient.OnBeforeQuickSave(this, quickSlotName, out var handled); EmuClient.OnBeforeQuickSave(this, quickSlotName, out var handled);
if (handled) if (handled)
{ {

View File

@ -152,17 +152,8 @@ namespace BizHawk.Client.EmuHawk
.OfType<BotControlsRow>() .OfType<BotControlsRow>()
.ToDictionary(tkey => tkey.ButtonName, tvalue => tvalue.Probability); .ToDictionary(tkey => tkey.ButtonName, tvalue => tvalue.Probability);
private string SelectedSlot private int SelectedSlot
{ => (1 + StartFromSlotBox.SelectedIndex) % 10;
get
{
char num = StartFromSlotBox.SelectedItem
.ToString()
.Last();
return $"QuickSave{num}";
}
}
private long Attempts private long Attempts
{ {