From 1f9188da5e5d01e33224ef62f655f69dc4fda0d0 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 29 Nov 2020 14:25:13 +1000 Subject: [PATCH] Pass global Config and GameInfo to Emu and GameInfo APIs via ctors --- .../Api/Libraries/EmulationApi.cs | 23 +++++++++++++------ .../Api/Libraries/GameInfoApi.cs | 22 +++++++++++------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/Api/Libraries/EmulationApi.cs b/src/BizHawk.Client.EmuHawk/Api/Libraries/EmulationApi.cs index 3b63892bc7..2f7809488a 100644 --- a/src/BizHawk.Client.EmuHawk/Api/Libraries/EmulationApi.cs +++ b/src/BizHawk.Client.EmuHawk/Api/Libraries/EmulationApi.cs @@ -37,15 +37,19 @@ namespace BizHawk.Client.EmuHawk [OptionalService] private IRegionable RegionableCore { get; set; } + private readonly Config _config; + + private readonly IGameInfo _game; + private readonly Action LogCallback; - /// Using this property to get a reference to GlobalWin.Config is a terrible, horrible, no good, very bad idea. That's why it's not in the interface. + /// Using this property to get a reference to the global instance is a terrible, horrible, no good, very bad idea. That's why it's not in the interface. public Config ForbiddenConfigReference { get { ForbiddenConfigReferenceUsed = true; - return GlobalWin.Config; + return _config; } } @@ -55,9 +59,14 @@ namespace BizHawk.Client.EmuHawk public Action YieldCallback { get; set; } - public EmulationApi(Action logCallback) => LogCallback = logCallback; + public EmulationApi(Action logCallback, IMainFormForApi mainForm, DisplayManager displayManager, InputManager inputManager, Config config, IEmulator emulator, IGameInfo game) + { + _config = config; + _game = game; + LogCallback = logCallback; + } - public void DisplayVsync(bool enabled) => GlobalWin.Config.VSync = enabled; + public void DisplayVsync(bool enabled) => _config.VSync = enabled; public void FrameAdvance() => FrameAdvanceCallback(); @@ -140,7 +149,7 @@ namespace BizHawk.Client.EmuHawk return default; } - public string GetSystemId() => GlobalWin.Game.System; + public string GetSystemId() => _game.System; public bool IsLagged() { @@ -168,9 +177,9 @@ namespace BizHawk.Client.EmuHawk else LogCallback($"Can not set lag information, {Emulator.Attributes().CoreName} does not implement {nameof(IInputPollable)}"); } - public void LimitFramerate(bool enabled) => GlobalWin.Config.ClockThrottle = enabled; + public void LimitFramerate(bool enabled) => _config.ClockThrottle = enabled; - public void MinimizeFrameskip(bool enabled) => GlobalWin.Config.AutoMinimizeSkipping = enabled; + public void MinimizeFrameskip(bool enabled) => _config.AutoMinimizeSkipping = enabled; public void Yield() => YieldCallback(); diff --git a/src/BizHawk.Client.EmuHawk/Api/Libraries/GameInfoApi.cs b/src/BizHawk.Client.EmuHawk/Api/Libraries/GameInfoApi.cs index 1556fe78cb..b16d14ef36 100644 --- a/src/BizHawk.Client.EmuHawk/Api/Libraries/GameInfoApi.cs +++ b/src/BizHawk.Client.EmuHawk/Api/Libraries/GameInfoApi.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using BizHawk.Client.Common; using BizHawk.Emulation.Common; @@ -9,23 +10,28 @@ namespace BizHawk.Client.EmuHawk [OptionalService] private IBoardInfo BoardInfo { get; set; } - public string GetRomName() => GlobalWin.Game?.Name ?? ""; + private readonly IGameInfo _game; - public string GetRomHash() => GlobalWin.Game?.Hash ?? ""; + public GameInfoApi(Action logCallback, IMainFormForApi mainForm, DisplayManager displayManager, InputManager inputManager, Config config, IEmulator emulator, IGameInfo game) + => _game = game; - public bool InDatabase() => GlobalWin.Game?.NotInDatabase == false; + public string GetRomName() => _game?.Name ?? ""; - public string GetStatus() => GlobalWin.Game?.Status.ToString(); + public string GetRomHash() => _game?.Hash ?? ""; - public bool IsStatusBad() => GlobalWin.Game?.IsRomStatusBad() != false; + public bool InDatabase() => _game?.NotInDatabase == false; + + public string GetStatus() => _game?.Status.ToString(); + + public bool IsStatusBad() => _game?.IsRomStatusBad() != false; public string GetBoardType() => BoardInfo?.BoardName ?? ""; public Dictionary GetOptions() { var options = new Dictionary(); - if (GlobalWin.Game == null) return options; - foreach (var option in GlobalWin.Game.GetOptions()) options[option.Key] = option.Value; + if (_game == null) return options; + foreach (var option in ((GameInfo) _game).GetOptions()) options[option.Key] = option.Value; return options; } }