Pass more things through to ApiManager
This commit is contained in:
parent
4c9c985eed
commit
9fc853d404
|
@ -32,15 +32,20 @@ namespace BizHawk.Client.EmuHawk
|
||||||
private static ApiContainer? _luaContainer;
|
private static ApiContainer? _luaContainer;
|
||||||
|
|
||||||
private static ApiContainer Register(
|
private static ApiContainer Register(
|
||||||
IMainFormForApi mainForm,
|
|
||||||
IEmulatorServiceProvider serviceProvider,
|
IEmulatorServiceProvider serviceProvider,
|
||||||
Action<string> logCallback)
|
Action<string> logCallback,
|
||||||
|
IMainFormForApi mainForm,
|
||||||
|
DisplayManager displayManager,
|
||||||
|
InputManager inputManager,
|
||||||
|
Config config,
|
||||||
|
IEmulator emulator,
|
||||||
|
IGameInfo game)
|
||||||
{
|
{
|
||||||
var libDict = _apiTypes.Keys.Where(t => ServiceInjector.IsAvailable(serviceProvider, t))
|
var libDict = _apiTypes.Keys.Where(t => ServiceInjector.IsAvailable(serviceProvider, t))
|
||||||
.ToDictionary(
|
.ToDictionary(
|
||||||
t => _apiTypes[t],
|
t => _apiTypes[t],
|
||||||
t => (IExternalApi) (
|
t => (IExternalApi) (
|
||||||
t.GetConstructor(_ctorParamTypesC)?.Invoke(new object[] { logCallback, mainForm, GlobalWin.DisplayManager, GlobalWin.InputManager, GlobalWin.Config, GlobalWin.Emulator, GlobalWin.Game })
|
t.GetConstructor(_ctorParamTypesC)?.Invoke(new object[] { logCallback, mainForm, displayManager, inputManager, config, emulator, game })
|
||||||
?? t.GetConstructor(_ctorParamTypesB)?.Invoke(new object[] { logCallback, mainForm })
|
?? t.GetConstructor(_ctorParamTypesB)?.Invoke(new object[] { logCallback, mainForm })
|
||||||
?? t.GetConstructor(_ctorParamTypesA)?.Invoke(new object[] { logCallback })
|
?? t.GetConstructor(_ctorParamTypesA)?.Invoke(new object[] { logCallback })
|
||||||
?? Activator.CreateInstance(t)
|
?? Activator.CreateInstance(t)
|
||||||
|
@ -50,15 +55,30 @@ namespace BizHawk.Client.EmuHawk
|
||||||
return new ApiContainer(libDict);
|
return new ApiContainer(libDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IExternalApiProvider Restart(IMainFormForApi mainForm, IEmulatorServiceProvider newServiceProvider)
|
public static IExternalApiProvider Restart(
|
||||||
|
IEmulatorServiceProvider serviceProvider,
|
||||||
|
IMainFormForApi mainForm,
|
||||||
|
DisplayManager displayManager,
|
||||||
|
InputManager inputManager,
|
||||||
|
Config config,
|
||||||
|
IEmulator emulator,
|
||||||
|
IGameInfo game)
|
||||||
{
|
{
|
||||||
GlobalWin.ClientApi = null;
|
GlobalWin.ClientApi = null;
|
||||||
_container = Register(mainForm, newServiceProvider, Console.WriteLine);
|
_container = Register(serviceProvider, Console.WriteLine, mainForm, displayManager, inputManager, config, emulator, game);
|
||||||
GlobalWin.ClientApi = _container.EmuClient as EmuClientApi;
|
GlobalWin.ClientApi = _container.EmuClient as EmuClientApi;
|
||||||
return new BasicApiProvider(_container);
|
return new BasicApiProvider(_container);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ApiContainer RestartLua(IMainFormForApi mainForm, IEmulatorServiceProvider newServiceProvider, Action<string> logCallback)
|
public static ApiContainer RestartLua(
|
||||||
=> _luaContainer = Register(mainForm, newServiceProvider, logCallback);
|
IEmulatorServiceProvider serviceProvider,
|
||||||
|
Action<string> logCallback,
|
||||||
|
IMainFormForApi mainForm,
|
||||||
|
DisplayManager displayManager,
|
||||||
|
InputManager inputManager,
|
||||||
|
Config config,
|
||||||
|
IEmulator emulator,
|
||||||
|
IGameInfo game
|
||||||
|
) => _luaContainer = Register(serviceProvider, logCallback, mainForm, displayManager, inputManager, config, emulator, game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,7 +234,9 @@ namespace BizHawk.Client.EmuHawk
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentScripts = LuaImp?.ScriptList; // Temp fix for now
|
var currentScripts = LuaImp?.ScriptList; // Temp fix for now
|
||||||
LuaImp = OSTailoredCode.IsUnixHost ? (LuaLibraries) new UnixLuaLibraries() : new Win32LuaLibraries((MainForm) MainForm, Emulator.ServiceProvider);
|
LuaImp = OSTailoredCode.IsUnixHost
|
||||||
|
? new UnixLuaLibraries()
|
||||||
|
: new Win32LuaLibraries(Emulator.ServiceProvider, (MainForm) MainForm, GlobalWin.DisplayManager, InputManager, Config, Emulator, Game);
|
||||||
LuaImp.ScriptList.AddRange(currentScripts ?? Enumerable.Empty<LuaFile>());
|
LuaImp.ScriptList.AddRange(currentScripts ?? Enumerable.Empty<LuaFile>());
|
||||||
|
|
||||||
InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => $"{a.Library}.{a.Name}").ToArray());
|
InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => $"{a.Library}.{a.Name}").ToArray());
|
||||||
|
|
|
@ -20,8 +20,15 @@ namespace BizHawk.Client.EmuHawk
|
||||||
_lua["keepalives"] = _lua.NewTable();
|
_lua["keepalives"] = _lua.NewTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Win32LuaLibraries(IMainFormForApi mainForm, IEmulatorServiceProvider serviceProvider)
|
public Win32LuaLibraries(
|
||||||
: this()
|
IEmulatorServiceProvider serviceProvider,
|
||||||
|
IMainFormForApi mainForm,
|
||||||
|
DisplayManager displayManager,
|
||||||
|
InputManager inputManager,
|
||||||
|
Config config,
|
||||||
|
IEmulator emulator,
|
||||||
|
IGameInfo game
|
||||||
|
) : this()
|
||||||
{
|
{
|
||||||
void EnumerateLuaFunctions(string name, Type type, LuaLibraryBase instance)
|
void EnumerateLuaFunctions(string name, Type type, LuaLibraryBase instance)
|
||||||
{
|
{
|
||||||
|
@ -42,7 +49,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
LuaWait = new AutoResetEvent(false);
|
LuaWait = new AutoResetEvent(false);
|
||||||
Docs.Clear();
|
Docs.Clear();
|
||||||
var apiContainer = ApiManager.RestartLua(mainForm, serviceProvider, ConsoleLuaLibrary.LogOutput);
|
var apiContainer = ApiManager.RestartLua(serviceProvider, ConsoleLuaLibrary.LogOutput, mainForm, displayManager, inputManager, config, emulator, game);
|
||||||
|
|
||||||
// Register lua libraries
|
// Register lua libraries
|
||||||
foreach (var lib in Client.Common.ReflectionCache.Types.Concat(EmuHawk.ReflectionCache.Types)
|
foreach (var lib in Client.Common.ReflectionCache.Types.Concat(EmuHawk.ReflectionCache.Types)
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
_emulator = emulator;
|
_emulator = emulator;
|
||||||
_movieSession = movieSession;
|
_movieSession = movieSession;
|
||||||
_game = game;
|
_game = game;
|
||||||
_apiProvider = ApiManager.Restart(_owner, _emulator.ServiceProvider);
|
_apiProvider = ApiManager.Restart(_emulator.ServiceProvider, _owner, GlobalWin.DisplayManager, _inputManager, _config, _emulator, _game);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -499,7 +499,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
{
|
{
|
||||||
_emulator = emulator;
|
_emulator = emulator;
|
||||||
_game = game;
|
_game = game;
|
||||||
_apiProvider = ApiManager.Restart(_owner, _emulator.ServiceProvider);
|
_apiProvider = ApiManager.Restart(_emulator.ServiceProvider, _owner, GlobalWin.DisplayManager, _inputManager, _config, _emulator, _game);
|
||||||
// If Cheat tool is loaded, restarting will restart the list too anyway
|
// If Cheat tool is loaded, restarting will restart the list too anyway
|
||||||
if (!Has<Cheats>())
|
if (!Has<Cheats>())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue