Init LuaFileList/LuaFunctionList outside platform impl. and pass in
now init'ing the lists at construction instead of mutating them afterwards
This commit is contained in:
parent
ddef661eb2
commit
3da01dbfce
|
@ -9,7 +9,8 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
private bool _changes;
|
||||
|
||||
public Action ChangedCallback { get; set; }
|
||||
private readonly Action ChangedCallback;
|
||||
|
||||
public bool Changes
|
||||
{
|
||||
get => _changes;
|
||||
|
@ -25,6 +26,13 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public string Filename { get; set; } = "";
|
||||
|
||||
/// <remarks><paramref name="onChanged"/> will not be called when initialising from given <paramref name="collection"/>, only on subsequent mutations</remarks>
|
||||
public LuaFileList(IReadOnlyCollection<LuaFile> collection, Action onChanged)
|
||||
{
|
||||
ChangedCallback = onChanged;
|
||||
if (collection != null) AddRange(collection); // doesn't actually trigger callback as the superclass' Add is called; if this class is rewritten without `new` methods, something clever will need to be done, like a bool field _initialised
|
||||
}
|
||||
|
||||
public void StopAllScripts()
|
||||
{
|
||||
ForEach(lf => lf.State = LuaFile.RunState.Disabled);
|
||||
|
|
|
@ -10,10 +10,12 @@ namespace BizHawk.Client.Common
|
|||
public class LuaFunctionList : IEnumerable<NamedLuaFunction>
|
||||
{
|
||||
private readonly List<NamedLuaFunction> _functions = new List<NamedLuaFunction>();
|
||||
|
||||
public Action ChangedCallback { get; set; }
|
||||
|
||||
public NamedLuaFunction this[string guid] =>
|
||||
private readonly Action Changed;
|
||||
|
||||
public LuaFunctionList(Action onChanged) => Changed = onChanged;
|
||||
|
||||
public NamedLuaFunction this[string guid] =>
|
||||
_functions.FirstOrDefault(nlf => nlf.Guid.ToString() == guid);
|
||||
|
||||
public void Add(NamedLuaFunction nlf)
|
||||
|
@ -77,7 +79,5 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public IEnumerator<NamedLuaFunction> GetEnumerator() => _functions.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => _functions.GetEnumerator();
|
||||
|
||||
private void Changed() => ChangedCallback?.Invoke();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -224,13 +224,22 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
var currentScripts = LuaImp?.ScriptList; // Temp fix for now
|
||||
LuaFileList newScripts = new(LuaImp?.ScriptList, onChanged: SessionChangedCallback);
|
||||
LuaFunctionList registeredFuncList = new(onChanged: UpdateRegisteredFunctionsDialog);
|
||||
LuaImp = OSTailoredCode.IsUnixHost
|
||||
? new UnixLuaLibraries()
|
||||
: new Win32LuaLibraries(Emulator.ServiceProvider, (MainForm) MainForm, DisplayManager, InputManager, Config, Emulator, Game);
|
||||
LuaImp.ScriptList.AddRange(currentScripts ?? Enumerable.Empty<LuaFile>());
|
||||
LuaImp.ScriptList.ChangedCallback = SessionChangedCallback;
|
||||
LuaImp.RegisteredFunctions.ChangedCallback = UpdateRegisteredFunctionsDialog;
|
||||
? new UnixLuaLibraries(
|
||||
newScripts,
|
||||
registeredFuncList)
|
||||
: new Win32LuaLibraries(
|
||||
newScripts,
|
||||
registeredFuncList,
|
||||
Emulator.ServiceProvider,
|
||||
(MainForm) MainForm, //HACK
|
||||
DisplayManager,
|
||||
InputManager,
|
||||
Config,
|
||||
Emulator,
|
||||
Game);
|
||||
|
||||
InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => $"{a.Library}.{a.Name}").ToArray());
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// </summary>
|
||||
public sealed class UnixLuaLibraries : IPlatformLuaLibEnv
|
||||
{
|
||||
private static readonly LuaFunctionList EmptyLuaFunList = new LuaFunctionList();
|
||||
|
||||
public LuaDocumentation Docs { get; } = new LuaDocumentation();
|
||||
|
||||
public string EngineName => null;
|
||||
|
@ -21,9 +19,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public bool IsUpdateSupressed { get; set; }
|
||||
|
||||
public LuaFunctionList RegisteredFunctions => EmptyLuaFunList;
|
||||
public LuaFunctionList RegisteredFunctions { get; }
|
||||
|
||||
public LuaFileList ScriptList { get; } = new LuaFileList();
|
||||
public LuaFileList ScriptList { get; }
|
||||
|
||||
public UnixLuaLibraries(LuaFileList scriptList, LuaFunctionList registeredFuncList)
|
||||
{
|
||||
RegisteredFunctions = registeredFuncList;
|
||||
ScriptList = scriptList;
|
||||
}
|
||||
|
||||
public void CallLoadStateEvent(string name) {}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
public class Win32LuaLibraries : IPlatformLuaLibEnv
|
||||
{
|
||||
public Win32LuaLibraries(
|
||||
LuaFileList scriptList,
|
||||
LuaFunctionList registeredFuncList,
|
||||
IEmulatorServiceProvider serviceProvider,
|
||||
MainForm mainForm,
|
||||
IDisplayManagerForApi displayManager,
|
||||
|
@ -47,6 +49,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
_inputManager = inputManager;
|
||||
_mainForm = mainForm;
|
||||
LuaWait = new AutoResetEvent(false);
|
||||
RegisteredFunctions = registeredFuncList;
|
||||
ScriptList = scriptList;
|
||||
Docs.Clear();
|
||||
_apiContainer = ApiManager.RestartLua(serviceProvider, LogToLuaConsole, _mainForm, _displayManager, _inputManager, _mainForm.MovieSession, _mainForm.Tools, config, emulator, game);
|
||||
|
||||
|
@ -137,7 +141,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private EventWaitHandle LuaWait;
|
||||
|
||||
public LuaFileList ScriptList { get; } = new LuaFileList();
|
||||
public LuaFileList ScriptList { get; }
|
||||
|
||||
private static void LogToLuaConsole(object outputs) => _logToLuaConsoleCallback(new[] { outputs });
|
||||
|
||||
|
@ -159,7 +163,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
public bool FrameAdvanceRequested { get; private set; }
|
||||
|
||||
public LuaFunctionList RegisteredFunctions { get; } = new LuaFunctionList();
|
||||
public LuaFunctionList RegisteredFunctions { get; }
|
||||
|
||||
public void CallSaveStateEvent(string name)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue