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;
|
private bool _changes;
|
||||||
|
|
||||||
public Action ChangedCallback { get; set; }
|
private readonly Action ChangedCallback;
|
||||||
|
|
||||||
public bool Changes
|
public bool Changes
|
||||||
{
|
{
|
||||||
get => _changes;
|
get => _changes;
|
||||||
|
@ -25,6 +26,13 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public string Filename { get; set; } = "";
|
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()
|
public void StopAllScripts()
|
||||||
{
|
{
|
||||||
ForEach(lf => lf.State = LuaFile.RunState.Disabled);
|
ForEach(lf => lf.State = LuaFile.RunState.Disabled);
|
||||||
|
|
|
@ -10,10 +10,12 @@ namespace BizHawk.Client.Common
|
||||||
public class LuaFunctionList : IEnumerable<NamedLuaFunction>
|
public class LuaFunctionList : IEnumerable<NamedLuaFunction>
|
||||||
{
|
{
|
||||||
private readonly List<NamedLuaFunction> _functions = new List<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);
|
_functions.FirstOrDefault(nlf => nlf.Guid.ToString() == guid);
|
||||||
|
|
||||||
public void Add(NamedLuaFunction nlf)
|
public void Add(NamedLuaFunction nlf)
|
||||||
|
@ -77,7 +79,5 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public IEnumerator<NamedLuaFunction> GetEnumerator() => _functions.GetEnumerator();
|
public IEnumerator<NamedLuaFunction> GetEnumerator() => _functions.GetEnumerator();
|
||||||
IEnumerator IEnumerable.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
|
LuaImp = OSTailoredCode.IsUnixHost
|
||||||
? new UnixLuaLibraries()
|
? new UnixLuaLibraries(
|
||||||
: new Win32LuaLibraries(Emulator.ServiceProvider, (MainForm) MainForm, DisplayManager, InputManager, Config, Emulator, Game);
|
newScripts,
|
||||||
LuaImp.ScriptList.AddRange(currentScripts ?? Enumerable.Empty<LuaFile>());
|
registeredFuncList)
|
||||||
LuaImp.ScriptList.ChangedCallback = SessionChangedCallback;
|
: new Win32LuaLibraries(
|
||||||
LuaImp.RegisteredFunctions.ChangedCallback = UpdateRegisteredFunctionsDialog;
|
newScripts,
|
||||||
|
registeredFuncList,
|
||||||
|
Emulator.ServiceProvider,
|
||||||
|
(MainForm) MainForm, //HACK
|
||||||
|
DisplayManager,
|
||||||
|
InputManager,
|
||||||
|
Config,
|
||||||
|
Emulator,
|
||||||
|
Game);
|
||||||
|
|
||||||
InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => $"{a.Library}.{a.Name}").ToArray());
|
InputBox.AutoCompleteCustomSource.AddRange(LuaImp.Docs.Select(a => $"{a.Library}.{a.Name}").ToArray());
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,6 @@ namespace BizHawk.Client.EmuHawk
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class UnixLuaLibraries : IPlatformLuaLibEnv
|
public sealed class UnixLuaLibraries : IPlatformLuaLibEnv
|
||||||
{
|
{
|
||||||
private static readonly LuaFunctionList EmptyLuaFunList = new LuaFunctionList();
|
|
||||||
|
|
||||||
public LuaDocumentation Docs { get; } = new LuaDocumentation();
|
public LuaDocumentation Docs { get; } = new LuaDocumentation();
|
||||||
|
|
||||||
public string EngineName => null;
|
public string EngineName => null;
|
||||||
|
@ -21,9 +19,15 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public bool IsUpdateSupressed { get; set; }
|
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) {}
|
public void CallLoadStateEvent(string name) {}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
public class Win32LuaLibraries : IPlatformLuaLibEnv
|
public class Win32LuaLibraries : IPlatformLuaLibEnv
|
||||||
{
|
{
|
||||||
public Win32LuaLibraries(
|
public Win32LuaLibraries(
|
||||||
|
LuaFileList scriptList,
|
||||||
|
LuaFunctionList registeredFuncList,
|
||||||
IEmulatorServiceProvider serviceProvider,
|
IEmulatorServiceProvider serviceProvider,
|
||||||
MainForm mainForm,
|
MainForm mainForm,
|
||||||
IDisplayManagerForApi displayManager,
|
IDisplayManagerForApi displayManager,
|
||||||
|
@ -47,6 +49,8 @@ namespace BizHawk.Client.EmuHawk
|
||||||
_inputManager = inputManager;
|
_inputManager = inputManager;
|
||||||
_mainForm = mainForm;
|
_mainForm = mainForm;
|
||||||
LuaWait = new AutoResetEvent(false);
|
LuaWait = new AutoResetEvent(false);
|
||||||
|
RegisteredFunctions = registeredFuncList;
|
||||||
|
ScriptList = scriptList;
|
||||||
Docs.Clear();
|
Docs.Clear();
|
||||||
_apiContainer = ApiManager.RestartLua(serviceProvider, LogToLuaConsole, _mainForm, _displayManager, _inputManager, _mainForm.MovieSession, _mainForm.Tools, config, emulator, game);
|
_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;
|
private EventWaitHandle LuaWait;
|
||||||
|
|
||||||
public LuaFileList ScriptList { get; } = new LuaFileList();
|
public LuaFileList ScriptList { get; }
|
||||||
|
|
||||||
private static void LogToLuaConsole(object outputs) => _logToLuaConsoleCallback(new[] { outputs });
|
private static void LogToLuaConsole(object outputs) => _logToLuaConsoleCallback(new[] { outputs });
|
||||||
|
|
||||||
|
@ -159,7 +163,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
public bool FrameAdvanceRequested { get; private set; }
|
public bool FrameAdvanceRequested { get; private set; }
|
||||||
|
|
||||||
public LuaFunctionList RegisteredFunctions { get; } = new LuaFunctionList();
|
public LuaFunctionList RegisteredFunctions { get; }
|
||||||
|
|
||||||
public void CallSaveStateEvent(string name)
|
public void CallSaveStateEvent(string name)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue