Pass global Config and GameInfo to Emu and GameInfo APIs via ctors

This commit is contained in:
YoshiRulz 2020-11-29 14:25:13 +10:00
parent 85d4d5ed4d
commit 1f9188da5e
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 30 additions and 15 deletions

View File

@ -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<string> LogCallback;
/// <summary>Using this property to get a reference to <see cref="GlobalWin.Config">GlobalWin.Config</see> is a terrible, horrible, no good, very bad idea. That's why it's not in the <see cref="IEmulationApi">interface</see>.</summary>
/// <summary>Using this property to get a reference to the global <see cref="Config"/> instance is a terrible, horrible, no good, very bad idea. That's why it's not in the <see cref="IEmulationApi">interface</see>.</summary>
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<string> logCallback) => LogCallback = logCallback;
public EmulationApi(Action<string> 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();

View File

@ -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<string> 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<string, string> GetOptions()
{
var options = new Dictionary<string, string>();
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;
}
}