diff --git a/BizHawk.Client.Common/SaveSlotManager.cs b/BizHawk.Client.Common/SaveSlotManager.cs index 2e4bcdfef7..2edf5ce5a9 100644 --- a/BizHawk.Client.Common/SaveSlotManager.cs +++ b/BizHawk.Client.Common/SaveSlotManager.cs @@ -10,9 +10,9 @@ namespace BizHawk.Client.Common private readonly bool[] _slots = new bool[10]; private readonly bool[] _redo = new bool[10]; - public void Update(string saveStatePrefix) + public void Update(IEmulator emulator, IMovie movie, string saveStatePrefix) { - if (Global.Game == null || Global.Emulator == null) + if (!emulator.HasSavestates()) { for (int i = 0; i < 10; i++) { @@ -24,7 +24,7 @@ namespace BizHawk.Client.Common for (int i = 0; i < 10; i++) { - if (Global.MovieSession.Movie is TasMovie tasMovie) + if (movie is TasMovie tasMovie) { _slots[i] = i < tasMovie.Branches.Count; } @@ -41,9 +41,9 @@ namespace BizHawk.Client.Common } } - public bool HasSlot(int slot, string savestatePrefix) + public bool HasSlot(IEmulator emulator, IMovie movie, int slot, string savestatePrefix) { - if (!Global.Emulator.HasSavestates()) + if (!emulator.HasSavestates()) { return false; } @@ -53,7 +53,7 @@ namespace BizHawk.Client.Common return false; } - Update(savestatePrefix); + Update(emulator, movie, savestatePrefix); return _slots[slot]; } @@ -65,14 +65,14 @@ namespace BizHawk.Client.Common } } - public void ToggleRedo(int slot) + public void ToggleRedo(IMovie movie, int slot) { - if (0.RangeTo(9).Contains(slot) && !(Global.MovieSession.Movie is TasMovie)) _redo[slot] ^= true; + if (0.RangeTo(9).Contains(slot) && !(movie is TasMovie)) _redo[slot] ^= true; } - public bool IsRedo(int slot) => 0.RangeTo(9).Contains(slot) && !(Global.MovieSession.Movie is TasMovie) && _redo[slot]; + public bool IsRedo(IMovie movie, int slot) => 0.RangeTo(9).Contains(slot) && !(movie is TasMovie) && _redo[slot]; - public void SwapBackupSavestate(string path) + public void SwapBackupSavestate(IMovie movie, string path, int currentSlot) { // Takes the .state and .bak files and swaps them var state = new FileInfo(path); @@ -96,7 +96,7 @@ namespace BizHawk.Client.Common temp.CopyTo(path); temp.Delete(); - ToggleRedo(Global.Config.SaveSlot); + ToggleRedo(movie, currentSlot); } } } diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index 20481565af..cbe876fb0b 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -69,7 +69,7 @@ namespace BizHawk.Client.EmuHawk RecentRomSubMenu.DropDownItems.AddRange(Config.RecentRoms.RecentMenu(LoadRomFromRecent, "ROM", romLoading: true)); } - private bool HasSlot(int slot) => _stateSlots.HasSlot(slot, SaveStatePrefix()); + private bool HasSlot(int slot) => _stateSlots.HasSlot(Emulator, MovieSession.Movie, slot, SaveStatePrefix()); private void SaveStateSubMenu_DropDownOpened(object sender, EventArgs e) { @@ -2893,7 +2893,7 @@ namespace BizHawk.Client.EmuHawk if (file.Exists) { UndoSavestateContextMenuItem.Enabled = true; - if (_stateSlots.IsRedo(Config.SaveSlot)) + if (_stateSlots.IsRedo(MovieSession.Movie, Config.SaveSlot)) { UndoSavestateContextMenuItem.Text = $"Redo Save to slot {Config.SaveSlot}"; UndoSavestateContextMenuItem.Image = Properties.Resources.redo; @@ -3011,7 +3011,7 @@ namespace BizHawk.Client.EmuHawk private void UndoSavestateContextMenuItem_Click(object sender, EventArgs e) { - _stateSlots.SwapBackupSavestate($"{SaveStatePrefix()}.QuickSave{Config.SaveSlot}.State"); + _stateSlots.SwapBackupSavestate(MovieSession.Movie, $"{SaveStatePrefix()}.QuickSave{Config.SaveSlot}.State", Config.SaveSlot); AddOnScreenMessage($"Save slot {Config.SaveSlot} restored."); } diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 00c73dddf5..d906adadd6 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -62,7 +62,7 @@ namespace BizHawk.Client.EmuHawk HandleToggleLightAndLink(); SetStatusBar(); - _stateSlots.Update(SaveStatePrefix()); + _stateSlots.Update(Emulator, MovieSession.Movie, SaveStatePrefix()); // New version notification UpdateChecker.CheckComplete += (s2, e2) => @@ -2456,7 +2456,7 @@ namespace BizHawk.Client.EmuHawk public void UpdateStatusSlots() { - _stateSlots.Update(SaveStatePrefix()); + _stateSlots.Update(Emulator, MovieSession.Movie, SaveStatePrefix()); Slot0StatusButton.ForeColor = SlotForeColor(0); Slot1StatusButton.ForeColor = SlotForeColor(1);