Pass global Config and GameInfo to Emu and GameInfo APIs via ctors
This commit is contained in:
parent
85d4d5ed4d
commit
1f9188da5e
|
@ -37,15 +37,19 @@ namespace BizHawk.Client.EmuHawk
|
||||||
[OptionalService]
|
[OptionalService]
|
||||||
private IRegionable RegionableCore { get; set; }
|
private IRegionable RegionableCore { get; set; }
|
||||||
|
|
||||||
|
private readonly Config _config;
|
||||||
|
|
||||||
|
private readonly IGameInfo _game;
|
||||||
|
|
||||||
private readonly Action<string> LogCallback;
|
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
|
public Config ForbiddenConfigReference
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
ForbiddenConfigReferenceUsed = true;
|
ForbiddenConfigReferenceUsed = true;
|
||||||
return GlobalWin.Config;
|
return _config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,9 +59,14 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public Action YieldCallback { get; set; }
|
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();
|
public void FrameAdvance() => FrameAdvanceCallback();
|
||||||
|
|
||||||
|
@ -140,7 +149,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetSystemId() => GlobalWin.Game.System;
|
public string GetSystemId() => _game.System;
|
||||||
|
|
||||||
public bool IsLagged()
|
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)}");
|
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();
|
public void Yield() => YieldCallback();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
|
@ -9,23 +10,28 @@ namespace BizHawk.Client.EmuHawk
|
||||||
[OptionalService]
|
[OptionalService]
|
||||||
private IBoardInfo BoardInfo { get; set; }
|
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 string GetBoardType() => BoardInfo?.BoardName ?? "";
|
||||||
|
|
||||||
public Dictionary<string, string> GetOptions()
|
public Dictionary<string, string> GetOptions()
|
||||||
{
|
{
|
||||||
var options = new Dictionary<string, string>();
|
var options = new Dictionary<string, string>();
|
||||||
if (GlobalWin.Game == null) return options;
|
if (_game == null) return options;
|
||||||
foreach (var option in GlobalWin.Game.GetOptions()) options[option.Key] = option.Value;
|
foreach (var option in ((GameInfo) _game).GetOptions()) options[option.Key] = option.Value;
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue