Pass an IGameInfo into ToolFormBase and use it in tools

This commit is contained in:
adelikat 2020-06-11 18:25:34 -05:00
parent 109ba1d31a
commit ba939466df
17 changed files with 36 additions and 30 deletions

View File

@ -185,7 +185,7 @@ namespace BizHawk.Client.Common
public static void PopulateWithDefaultHeaderValues(
this IMovie movie,
IEmulator emulator,
GameInfo game,
IGameInfo game,
FirmwareManager firmwareManager,
string author)
{

View File

@ -137,7 +137,7 @@ namespace BizHawk.Client.EmuHawk
private void HideShowGameDbButton()
{
AddToGameDbBtn.Visible = Emulator.CanGenerateGameDBEntries()
&& (GlobalWin.Game.Status == RomStatus.Unknown || GlobalWin.Game.Status == RomStatus.NotInDatabase);
&& (Game.Status == RomStatus.Unknown || Game.Status == RomStatus.NotInDatabase);
}
private void AddToGameDbBtn_Click(object sender, EventArgs e)

View File

@ -299,7 +299,7 @@ namespace BizHawk.Client.EmuHawk
_throttle = new Throttle();
Emulator = new NullEmulator();
GlobalWin.Tools = new ToolManager(this, Config, Emulator, MovieSession);
GlobalWin.Tools = new ToolManager(this, Config, Emulator, MovieSession, Game);
UpdateStatusSlots();
UpdateKeyPriorityIcon();
@ -3786,7 +3786,7 @@ namespace BizHawk.Client.EmuHawk
}
}
Tools.Restart(Emulator);
Tools.Restart(Emulator, Game);
if (Config.Cheats.LoadFileByGame && Emulator.HasMemoryDomains())
{
@ -3950,7 +3950,7 @@ namespace BizHawk.Client.EmuHawk
Emulator = new NullEmulator();
GlobalWin.Game = GameInfo.NullInstance;
CreateRewinder();
Tools.Restart(Emulator);
Tools.Restart(Emulator, Game);
RewireSound();
ClearHolds();
Tools.UpdateCheatRelatedTools(null, null);

View File

@ -481,7 +481,7 @@ namespace BizHawk.Client.EmuHawk
try
{
_autoloading = true;
var autoResumeFile = $"{GlobalWin.Game.FilesystemSafeName()}.cdl";
var autoResumeFile = $"{Game.FilesystemSafeName()}.cdl";
var autoResumeDir = Config.PathEntries.LogAbsolutePath();
var autoResumePath = Path.Combine(autoResumeDir, autoResumeFile);
if (File.Exists(autoResumePath))

View File

@ -118,7 +118,7 @@ namespace BizHawk.Client.EmuHawk
{
var file = SaveFileDialog(
MainForm.CheatList.CurrentFileName,
Config.PathEntries.CheatsAbsolutePath(GlobalWin.Game.System),
Config.PathEntries.CheatsAbsolutePath(Game.System),
"Cheat Files",
"cht");
@ -350,7 +350,7 @@ namespace BizHawk.Client.EmuHawk
{
var file = OpenFileDialog(
MainForm.CheatList.CurrentFileName,
Config.PathEntries.CheatsAbsolutePath(GlobalWin.Game.System),
Config.PathEntries.CheatsAbsolutePath(Game.System),
"Cheat Files",
"cht");

View File

@ -912,7 +912,7 @@ namespace BizHawk.Client.EmuHawk
, FileName =
_domain.Name == "File on Disk"
? RomName
: GlobalWin.Game.FilesystemSafeName()
: Game.FilesystemSafeName()
};
var result = sfd.ShowHawkDialog();
@ -925,7 +925,7 @@ namespace BizHawk.Client.EmuHawk
{
FileName = _domain.Name == "File on Disk"
? $"{Path.GetFileNameWithoutExtension(RomName)}.txt"
: GlobalWin.Game.FilesystemSafeName(),
: Game.FilesystemSafeName(),
Filter = new FilesystemFilterSet(FilesystemFilter.TextFiles).ToString(),
InitialDirectory = RomDirectory,
RestoreDirectory = true

View File

@ -635,9 +635,9 @@ namespace BizHawk.Client.EmuHawk
sfd.FileName = Path.GetFileNameWithoutExtension(LuaImp.ScriptList.Filename);
sfd.InitialDirectory = Path.GetDirectoryName(LuaImp.ScriptList.Filename);
}
else if (GlobalWin.Game != null)
else if (!Game.IsNullInstance())
{
sfd.FileName = GlobalWin.Game.FilesystemSafeName();
sfd.FileName = Game.FilesystemSafeName();
sfd.InitialDirectory = Config.PathEntries.LuaAbsolutePath();
}
else
@ -834,7 +834,7 @@ namespace BizHawk.Client.EmuHawk
DefaultExt = ".lua",
FileName = !string.IsNullOrWhiteSpace(LuaImp.ScriptList.Filename)
? Path.GetFileNameWithoutExtension(LuaImp.ScriptList.Filename)
: Path.GetFileNameWithoutExtension(GlobalWin.Game.Name),
: Path.GetFileNameWithoutExtension(Game.Name),
OverwritePrompt = true,
Filter = new FilesystemFilterSet(FilesystemFilter.LuaScripts).ToString()
};

View File

@ -260,7 +260,7 @@ namespace BizHawk.Client.EmuHawk
{
return Config.PathEntries.AbsolutePathFor(Path.Combine(
Config.PathEntries["Global", "Macros"].Path,
GlobalWin.Game.FilesystemSafeName()), null);
Game.FilesystemSafeName()), null);
}
public bool SaveMacroAs(MovieZone macro)

View File

@ -35,7 +35,7 @@ namespace BizHawk.Client.EmuHawk
AddButton_Click(null, null);
AddButton_Click(null, null);
if (!GlobalWin.Game.IsNullInstance() && !MainForm.CurrentlyOpenRom.EndsWith(".xml"))
if (!Game.IsNullInstance() && !MainForm.CurrentlyOpenRom.EndsWith(".xml"))
{
if (MainForm.CurrentlyOpenRom.Contains("|"))
{
@ -215,12 +215,12 @@ namespace BizHawk.Client.EmuHawk
string filename = "";
string initialDirectory = Config.PathEntries.MultiDiskAbsolutePath();
if (!GlobalWin.Game.IsNullInstance())
if (!Game.IsNullInstance())
{
filename = NameBox.Text;
if (string.IsNullOrWhiteSpace(filename))
{
filename = Path.ChangeExtension(GlobalWin.Game.FilesystemSafeName(), ".xml");
filename = Path.ChangeExtension(Game.FilesystemSafeName(), ".xml");
}
initialDirectory = Path.GetDirectoryName(filename);

View File

@ -186,8 +186,8 @@ namespace BizHawk.Client.EmuHawk
{
using var sfd = new SaveFileDialog
{
FileName = $"{GlobalWin.Game.FilesystemSafeName()}-Nametables",
InitialDirectory = GlobalWin.Config.PathEntries.ScreenshotAbsolutePathFor("NES"),
FileName = $"{Game.FilesystemSafeName()}-Nametables",
InitialDirectory = Config.PathEntries.ScreenshotAbsolutePathFor("NES"),
Filter = FilesystemFilterSet.Screenshots.ToString(),
RestoreDirectory = true
};

View File

@ -314,7 +314,7 @@ namespace BizHawk.Client.EmuHawk
{
var sfd = new SaveFileDialog
{
FileName = $"{GlobalWin.Game.FilesystemSafeName()}-{suffix}",
FileName = $"{Game.FilesystemSafeName()}-{suffix}",
InitialDirectory = Config.PathEntries.ScreenshotAbsolutePathFor("NES"),
Filter = FilesystemFilterSet.Screenshots.ToString(),
RestoreDirectory = true

View File

@ -77,7 +77,7 @@ namespace BizHawk.Client.EmuHawk
if (CurrentTasMovie != null)
{
if (GlobalWin.Game.Hash != CurrentTasMovie.Hash)
if (Game.Hash != CurrentTasMovie.Hash)
{
TastudioStopMovie();
TasView.AllColumns.Clear();

View File

@ -685,7 +685,7 @@ namespace BizHawk.Client.EmuHawk
tasMovie.PopulateWithDefaultHeaderValues(
Emulator,
GlobalWin.Game,
Game,
GlobalWin.FirmwareManager,
Config.DefaultAuthor);
@ -813,7 +813,7 @@ namespace BizHawk.Client.EmuHawk
{
return Path.Combine(
Config.PathEntries.MovieAbsolutePath(),
$"{GlobalWin.Game.FilesystemSafeName()}.{MovieService.TasMovieExtension}");
$"{Game.FilesystemSafeName()}.{MovieService.TasMovieExtension}");
}
private void SaveTas()

View File

@ -15,6 +15,7 @@ namespace BizHawk.Client.EmuHawk
public MainForm MainForm { get; set; }
public IMovieSession MovieSession { get; set; }
public IGameInfo Game { get; set; }
public virtual bool AskSaveChanges() => true;

View File

@ -23,6 +23,7 @@ namespace BizHawk.Client.EmuHawk
private IExternalApiProvider _apiProvider;
private IEmulator _emulator;
private IMovieSession _movieSession;
private IGameInfo _game;
// TODO: merge ToolHelper code where logical
// For instance, add an IToolForm property called UsesCheats, so that a UpdateCheatRelatedTools() method can update all tools of this type
@ -36,12 +37,14 @@ namespace BizHawk.Client.EmuHawk
MainForm owner,
Config config,
IEmulator emulator,
IMovieSession movieSession)
IMovieSession movieSession,
IGameInfo game)
{
_owner = owner;
_config = config;
_emulator = emulator;
_movieSession = movieSession;
_game = game;
_apiProvider = ApiManager.Restart(_emulator.ServiceProvider);
}
@ -74,6 +77,7 @@ namespace BizHawk.Client.EmuHawk
tool.Config = _config;
tool.MainForm = _owner;
tool.MovieSession = _movieSession;
tool.Game = _game;
}
}
@ -479,9 +483,10 @@ namespace BizHawk.Client.EmuHawk
}
}
public void Restart(IEmulator emulator)
public void Restart(IEmulator emulator, IGameInfo game)
{
_emulator = emulator;
_game = game;
_apiProvider = ApiManager.Restart(_emulator.ServiceProvider);
// If Cheat tool is loaded, restarting will restart the list too anyway
if (!Has<Cheats>())

View File

@ -274,12 +274,12 @@ namespace BizHawk.Client.EmuHawk
using var sfd = new SaveFileDialog();
if (LogFile == null)
{
sfd.FileName = GlobalWin.Game.FilesystemSafeName() + _extension;
sfd.FileName = Game.FilesystemSafeName() + _extension;
sfd.InitialDirectory = Config.PathEntries.LogAbsolutePath();
}
else if (!string.IsNullOrWhiteSpace(LogFile.FullName))
{
sfd.FileName = GlobalWin.Game.FilesystemSafeName();
sfd.FileName = Game.FilesystemSafeName();
sfd.InitialDirectory = Path.GetDirectoryName(LogFile.FullName);
}
else
@ -439,7 +439,7 @@ namespace BizHawk.Client.EmuHawk
{
FileBox.Visible = true;
BrowseBox.Visible = true;
var name = GlobalWin.Game.FilesystemSafeName();
var name = Game.FilesystemSafeName();
var filename = Path.Combine(Config.PathEntries.LogAbsolutePath(), name) + _extension;
LogFile = new FileInfo(filename);
if (LogFile.Directory != null && !LogFile.Directory.Exists)

View File

@ -177,12 +177,12 @@ namespace BizHawk.Emulation.Common
public static class GameInfoExtensions
{
public static bool IsNullInstance(this GameInfo game)
public static bool IsNullInstance(this IGameInfo game)
{
return game == null || game.System == "NULL";
}
public static bool IsRomStatusBad(this GameInfo game)
public static bool IsRomStatusBad(this IGameInfo game)
{
return game.Status == RomStatus.BadDump || game.Status == RomStatus.Overdump;
}